Decompiled source of BepInExPack CrabGame v6.0.577

BepInExPack/BepInEx/core/0Harmony.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.ExceptionServices;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Cryptography;
using System.Security.Permissions;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using HarmonyLib.Internal.Patching;
using HarmonyLib.Internal.RuntimeFixes;
using HarmonyLib.Internal.Util;
using HarmonyLib.Public.Patching;
using HarmonyLib.Tools;
using JetBrains.Annotations;
using Mono.Cecil;
using Mono.Cecil.Cil;
using Mono.Collections.Generic;
using MonoMod.Cil;
using MonoMod.RuntimeDetour;
using MonoMod.Utils;
using MonoMod.Utils.Cil;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: ComVisible(false)]
[assembly: InternalsVisibleTo("HarmonyTests")]
[assembly: InternalsVisibleTo("MonoMod.Utils.Cil.ILGeneratorProxy")]
[assembly: Guid("69aee16a-b6e7-4642-8081-3928b32455df")]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("BepInEx")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyCopyright("Copyright © BepInEx 2022")]
[assembly: AssemblyDescription("A library for patching, replacing and decorating .NET and Mono methods during runtime powered by MonoMod.")]
[assembly: AssemblyFileVersion("2.10.0.0")]
[assembly: AssemblyInformationalVersion("2.10.0")]
[assembly: AssemblyProduct("HarmonyX")]
[assembly: AssemblyTitle("0Harmony")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("2.10.0.0")]
[module: UnverifiableCode]
namespace JetBrains.Annotations
{
	[AttributeUsage(AttributeTargets.All)]
	internal sealed class UsedImplicitlyAttribute : Attribute
	{
		public ImplicitUseKindFlags UseKindFlags { get; }

		public ImplicitUseTargetFlags TargetFlags { get; }

		public UsedImplicitlyAttribute()
			: this(ImplicitUseKindFlags.Default, ImplicitUseTargetFlags.Default)
		{
		}

		public UsedImplicitlyAttribute(ImplicitUseKindFlags useKindFlags)
			: this(useKindFlags, ImplicitUseTargetFlags.Default)
		{
		}

		public UsedImplicitlyAttribute(ImplicitUseTargetFlags targetFlags)
			: this(ImplicitUseKindFlags.Default, targetFlags)
		{
		}

		public UsedImplicitlyAttribute(ImplicitUseKindFlags useKindFlags, ImplicitUseTargetFlags targetFlags)
		{
			UseKindFlags = useKindFlags;
			TargetFlags = targetFlags;
		}
	}
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Parameter | AttributeTargets.GenericParameter)]
	internal sealed class MeansImplicitUseAttribute : Attribute
	{
		[UsedImplicitly]
		public ImplicitUseKindFlags UseKindFlags { get; }

		[UsedImplicitly]
		public ImplicitUseTargetFlags TargetFlags { get; }

		public MeansImplicitUseAttribute()
			: this(ImplicitUseKindFlags.Default, ImplicitUseTargetFlags.Default)
		{
		}

		public MeansImplicitUseAttribute(ImplicitUseKindFlags useKindFlags)
			: this(useKindFlags, ImplicitUseTargetFlags.Default)
		{
		}

		public MeansImplicitUseAttribute(ImplicitUseTargetFlags targetFlags)
			: this(ImplicitUseKindFlags.Default, targetFlags)
		{
		}

		public MeansImplicitUseAttribute(ImplicitUseKindFlags useKindFlags, ImplicitUseTargetFlags targetFlags)
		{
			UseKindFlags = useKindFlags;
			TargetFlags = targetFlags;
		}
	}
	[Flags]
	internal enum ImplicitUseKindFlags
	{
		Default = 7,
		Access = 1,
		Assign = 2,
		InstantiatedWithFixedConstructorSignature = 4,
		InstantiatedNoFixedConstructorSignature = 8
	}
	[Flags]
	internal enum ImplicitUseTargetFlags
	{
		Default = 1,
		Itself = 1,
		Members = 2,
		WithInheritors = 4,
		WithMembers = 3
	}
}
namespace HarmonyLib
{
	public class DelegateTypeFactory
	{
		private class DelegateEntry
		{
			public CallingConvention? callingConvention;

			public Type delegateType;
		}

		private static int counter;

		private static readonly Dictionary<MethodInfo, List<DelegateEntry>> TypeCache = new Dictionary<MethodInfo, List<DelegateEntry>>();

		private static readonly MethodBase CallingConvAttr = AccessTools.Constructor(typeof(UnmanagedFunctionPointerAttribute), new Type[1] { typeof(CallingConvention) });

		public static readonly DelegateTypeFactory instance = new DelegateTypeFactory();

		public Type CreateDelegateType(Type returnType, Type[] argTypes)
		{
			return CreateDelegateType(returnType, argTypes, null);
		}

		public Type CreateDelegateType(Type returnType, Type[] argTypes, CallingConvention? convention)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Expected O, but got Unknown
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Expected O, but got Unknown
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Expected O, but got Unknown
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Expected O, but got Unknown
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Expected O, but got Unknown
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Expected O, but got Unknown
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Expected O, but got Unknown
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			counter++;
			AssemblyDefinition val = AssemblyDefinition.CreateAssembly(new AssemblyNameDefinition($"HarmonyDTFAssembly{counter}", new Version(1, 0)), $"HarmonyDTFModule{counter}", (ModuleKind)0);
			ModuleDefinition module = val.MainModule;
			TypeDefinition val2 = new TypeDefinition("", $"HarmonyDTFType{counter}", (TypeAttributes)257)
			{
				BaseType = module.ImportReference(typeof(MulticastDelegate))
			};
			module.Types.Add(val2);
			if (convention.HasValue)
			{
				CustomAttribute val3 = new CustomAttribute(module.ImportReference(CallingConvAttr));
				val3.ConstructorArguments.Add(new CustomAttributeArgument(module.ImportReference(typeof(CallingConvention)), (object)convention.Value));
				val2.CustomAttributes.Add(val3);
			}
			MethodDefinition val4 = new MethodDefinition(".ctor", (MethodAttributes)4230, module.ImportReference(typeof(void)))
			{
				ImplAttributes = (MethodImplAttributes)3
			};
			Extensions.AddRange<ParameterDefinition>(((MethodReference)val4).Parameters, (IEnumerable<ParameterDefinition>)(object)new ParameterDefinition[2]
			{
				new ParameterDefinition(module.ImportReference(typeof(object))),
				new ParameterDefinition(module.ImportReference(typeof(IntPtr)))
			});
			val2.Methods.Add(val4);
			MethodDefinition val5 = new MethodDefinition("Invoke", (MethodAttributes)198, module.ImportReference(returnType))
			{
				ImplAttributes = (MethodImplAttributes)3
			};
			Extensions.AddRange<ParameterDefinition>(((MethodReference)val5).Parameters, ((IEnumerable<Type>)argTypes).Select((Func<Type, ParameterDefinition>)((Type t) => new ParameterDefinition(module.ImportReference(t)))));
			val2.Methods.Add(val5);
			return ReflectionHelper.Load(val.MainModule).GetType($"HarmonyDTFType{counter}");
		}

		public Type CreateDelegateType(MethodInfo method)
		{
			return CreateDelegateType(method, null);
		}

		public Type CreateDelegateType(MethodInfo method, CallingConvention? convention)
		{
			DelegateEntry delegateEntry;
			if (TypeCache.TryGetValue(method, out var value) && (delegateEntry = value.FirstOrDefault((DelegateEntry e) => e.callingConvention == convention)) != null)
			{
				return delegateEntry.delegateType;
			}
			if (value == null)
			{
				value = (TypeCache[method] = new List<DelegateEntry>());
			}
			delegateEntry = new DelegateEntry
			{
				delegateType = CreateDelegateType(method.ReturnType, method.GetParameters().Types().ToArray(), convention),
				callingConvention = convention
			};
			value.Add(delegateEntry);
			return delegateEntry.delegateType;
		}
	}
	[Obsolete("Use AccessTools.FieldRefAccess<T, S> for fields and AccessTools.MethodDelegate<Func<T, S>> for property getters")]
	public delegate S GetterHandler<in T, out S>(T source);
	[Obsolete("Use AccessTools.FieldRefAccess<T, S> for fields and AccessTools.MethodDelegate<Action<T, S>> for property setters")]
	public delegate void SetterHandler<in T, in S>(T source, S value);
	public delegate T InstantiationHandler<out T>();
	public static class FastAccess
	{
		public static InstantiationHandler<T> CreateInstantiationHandler<T>()
		{
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			ConstructorInfo constructor = typeof(T).GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[0], null);
			if ((object)constructor == null)
			{
				throw new ApplicationException($"The type {typeof(T)} must declare an empty constructor (the constructor may be private, internal, protected, protected internal, or public).");
			}
			DynamicMethodDefinition val = new DynamicMethodDefinition("InstantiateObject_" + typeof(T).Name, typeof(T), (Type[])null);
			ILGenerator iLGenerator = val.GetILGenerator();
			iLGenerator.Emit(OpCodes.Newobj, constructor);
			iLGenerator.Emit(OpCodes.Ret);
			return (InstantiationHandler<T>)val.Generate().CreateDelegate(typeof(InstantiationHandler<T>));
		}

		[Obsolete("Use AccessTools.MethodDelegate<Func<T, S>>(PropertyInfo.GetGetMethod(true))")]
		public static GetterHandler<T, S> CreateGetterHandler<T, S>(PropertyInfo propertyInfo)
		{
			MethodInfo getMethod = propertyInfo.GetGetMethod(nonPublic: true);
			DynamicMethodDefinition obj = CreateGetDynamicMethod<T, S>(propertyInfo.DeclaringType);
			ILGenerator iLGenerator = obj.GetILGenerator();
			iLGenerator.Emit(OpCodes.Ldarg_0);
			iLGenerator.Emit(OpCodes.Call, getMethod);
			iLGenerator.Emit(OpCodes.Ret);
			return (GetterHandler<T, S>)obj.Generate().CreateDelegate(typeof(GetterHandler<T, S>));
		}

		[Obsolete("Use AccessTools.FieldRefAccess<T, S>(fieldInfo)")]
		public static GetterHandler<T, S> CreateGetterHandler<T, S>(FieldInfo fieldInfo)
		{
			DynamicMethodDefinition obj = CreateGetDynamicMethod<T, S>(fieldInfo.DeclaringType);
			ILGenerator iLGenerator = obj.GetILGenerator();
			iLGenerator.Emit(OpCodes.Ldarg_0);
			iLGenerator.Emit(OpCodes.Ldfld, fieldInfo);
			iLGenerator.Emit(OpCodes.Ret);
			return (GetterHandler<T, S>)obj.Generate().CreateDelegate(typeof(GetterHandler<T, S>));
		}

		[Obsolete("Use AccessTools.FieldRefAccess<T, S>(name) for fields and AccessTools.MethodDelegate<Func<T, S>>(AccessTools.PropertyGetter(typeof(T), name)) for properties")]
		public static GetterHandler<T, S> CreateFieldGetter<T, S>(params string[] names)
		{
			foreach (string name in names)
			{
				FieldInfo field = typeof(T).GetField(name, AccessTools.all);
				if ((object)field != null)
				{
					return CreateGetterHandler<T, S>(field);
				}
				PropertyInfo property = typeof(T).GetProperty(name, AccessTools.all);
				if ((object)property != null)
				{
					return CreateGetterHandler<T, S>(property);
				}
			}
			return null;
		}

		[Obsolete("Use AccessTools.MethodDelegate<Action<T, S>>(PropertyInfo.GetSetMethod(true))")]
		public static SetterHandler<T, S> CreateSetterHandler<T, S>(PropertyInfo propertyInfo)
		{
			MethodInfo setMethod = propertyInfo.GetSetMethod(nonPublic: true);
			DynamicMethodDefinition obj = CreateSetDynamicMethod<T, S>(propertyInfo.DeclaringType);
			ILGenerator iLGenerator = obj.GetILGenerator();
			iLGenerator.Emit(OpCodes.Ldarg_0);
			iLGenerator.Emit(OpCodes.Ldarg_1);
			iLGenerator.Emit(OpCodes.Call, setMethod);
			iLGenerator.Emit(OpCodes.Ret);
			return (SetterHandler<T, S>)obj.Generate().CreateDelegate(typeof(SetterHandler<T, S>));
		}

		[Obsolete("Use AccessTools.FieldRefAccess<T, S>(fieldInfo)")]
		public static SetterHandler<T, S> CreateSetterHandler<T, S>(FieldInfo fieldInfo)
		{
			DynamicMethodDefinition obj = CreateSetDynamicMethod<T, S>(fieldInfo.DeclaringType);
			ILGenerator iLGenerator = obj.GetILGenerator();
			iLGenerator.Emit(OpCodes.Ldarg_0);
			iLGenerator.Emit(OpCodes.Ldarg_1);
			iLGenerator.Emit(OpCodes.Stfld, fieldInfo);
			iLGenerator.Emit(OpCodes.Ret);
			return (SetterHandler<T, S>)obj.Generate().CreateDelegate(typeof(SetterHandler<T, S>));
		}

		private static DynamicMethodDefinition CreateGetDynamicMethod<T, S>(Type type)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			return new DynamicMethodDefinition("DynamicGet_" + type.Name, typeof(S), new Type[1] { typeof(T) });
		}

		private static DynamicMethodDefinition CreateSetDynamicMethod<T, S>(Type type)
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Expected O, but got Unknown
			return new DynamicMethodDefinition("DynamicSet_" + type.Name, typeof(void), new Type[2]
			{
				typeof(T),
				typeof(S)
			});
		}
	}
	public delegate object FastInvokeHandler(object target, params object[] parameters);
	public static class MethodInvoker
	{
		public static FastInvokeHandler GetHandler(MethodInfo methodInfo, bool directBoxValueAccess = false)
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Expected O, but got Unknown
			DynamicMethodDefinition val = new DynamicMethodDefinition("FastInvoke_" + methodInfo.Name + "_" + (directBoxValueAccess ? "direct" : "indirect"), typeof(object), new Type[2]
			{
				typeof(object),
				typeof(object[])
			});
			ILGenerator iLGenerator = val.GetILGenerator();
			if (!methodInfo.IsStatic)
			{
				Emit(iLGenerator, OpCodes.Ldarg_0);
				EmitUnboxIfNeeded(iLGenerator, methodInfo.DeclaringType);
			}
			bool flag = true;
			ParameterInfo[] parameters = methodInfo.GetParameters();
			for (int i = 0; i < parameters.Length; i++)
			{
				Type type = parameters[i].ParameterType;
				bool isByRef = type.IsByRef;
				if (isByRef)
				{
					type = type.GetElementType();
				}
				bool isValueType = type.IsValueType;
				if (isByRef && isValueType && !directBoxValueAccess)
				{
					Emit(iLGenerator, OpCodes.Ldarg_1);
					EmitFastInt(iLGenerator, i);
				}
				Emit(iLGenerator, OpCodes.Ldarg_1);
				EmitFastInt(iLGenerator, i);
				if (isByRef && !isValueType)
				{
					Emit(iLGenerator, OpCodes.Ldelema, typeof(object));
					continue;
				}
				Emit(iLGenerator, OpCodes.Ldelem_Ref);
				if (!isValueType)
				{
					continue;
				}
				if (!isByRef || !directBoxValueAccess)
				{
					Emit(iLGenerator, OpCodes.Unbox_Any, type);
					if (isByRef)
					{
						Emit(iLGenerator, OpCodes.Box, type);
						Emit(iLGenerator, OpCodes.Dup);
						if (flag)
						{
							flag = false;
							iLGenerator.DeclareLocal(typeof(object), pinned: false);
						}
						Emit(iLGenerator, OpCodes.Stloc_0);
						Emit(iLGenerator, OpCodes.Stelem_Ref);
						Emit(iLGenerator, OpCodes.Ldloc_0);
						Emit(iLGenerator, OpCodes.Unbox, type);
					}
				}
				else
				{
					Emit(iLGenerator, OpCodes.Unbox, type);
				}
			}
			if (methodInfo.IsStatic)
			{
				EmitCall(iLGenerator, OpCodes.Call, methodInfo);
			}
			else
			{
				EmitCall(iLGenerator, OpCodes.Callvirt, methodInfo);
			}
			if (methodInfo.ReturnType == typeof(void))
			{
				Emit(iLGenerator, OpCodes.Ldnull);
			}
			else
			{
				EmitBoxIfNeeded(iLGenerator, methodInfo.ReturnType);
			}
			Emit(iLGenerator, OpCodes.Ret);
			return (FastInvokeHandler)val.Generate().CreateDelegate(typeof(FastInvokeHandler));
		}

		internal static void Emit(ILGenerator il, OpCode opcode)
		{
			il.Emit(opcode);
		}

		internal static void Emit(ILGenerator il, OpCode opcode, Type type)
		{
			il.Emit(opcode, type);
		}

		internal static void EmitCall(ILGenerator il, OpCode opcode, MethodInfo methodInfo)
		{
			il.EmitCall(opcode, methodInfo, null);
		}

		private static void EmitUnboxIfNeeded(ILGenerator il, Type type)
		{
			if (type.IsValueType)
			{
				Emit(il, OpCodes.Unbox_Any, type);
			}
		}

		private static void EmitBoxIfNeeded(ILGenerator il, Type type)
		{
			if (type.IsValueType)
			{
				Emit(il, OpCodes.Box, type);
			}
		}

		internal static void EmitFastInt(ILGenerator il, int value)
		{
			switch (value)
			{
			case -1:
				il.Emit(OpCodes.Ldc_I4_M1);
				return;
			case 0:
				il.Emit(OpCodes.Ldc_I4_0);
				return;
			case 1:
				il.Emit(OpCodes.Ldc_I4_1);
				return;
			case 2:
				il.Emit(OpCodes.Ldc_I4_2);
				return;
			case 3:
				il.Emit(OpCodes.Ldc_I4_3);
				return;
			case 4:
				il.Emit(OpCodes.Ldc_I4_4);
				return;
			case 5:
				il.Emit(OpCodes.Ldc_I4_5);
				return;
			case 6:
				il.Emit(OpCodes.Ldc_I4_6);
				return;
			case 7:
				il.Emit(OpCodes.Ldc_I4_7);
				return;
			case 8:
				il.Emit(OpCodes.Ldc_I4_8);
				return;
			}
			if (value > -129 && value < 128)
			{
				il.Emit(OpCodes.Ldc_I4_S, (sbyte)value);
			}
			else
			{
				il.Emit(OpCodes.Ldc_I4, value);
			}
		}
	}
	internal class AccessCache
	{
		internal enum MemberType
		{
			Any,
			Static,
			Instance
		}

		private const BindingFlags BasicFlags = BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.SetField | BindingFlags.GetProperty | BindingFlags.SetProperty;

		private static readonly Dictionary<MemberType, BindingFlags> declaredOnlyBindingFlags = new Dictionary<MemberType, BindingFlags>
		{
			{
				MemberType.Any,
				BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.SetField | BindingFlags.GetProperty | BindingFlags.SetProperty
			},
			{
				MemberType.Instance,
				BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.SetField | BindingFlags.GetProperty | BindingFlags.SetProperty
			},
			{
				MemberType.Static,
				BindingFlags.DeclaredOnly | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.SetField | BindingFlags.GetProperty | BindingFlags.SetProperty
			}
		};

		private readonly Dictionary<Type, Dictionary<string, FieldInfo>> declaredFields = new Dictionary<Type, Dictionary<string, FieldInfo>>();

		private readonly Dictionary<Type, Dictionary<string, PropertyInfo>> declaredProperties = new Dictionary<Type, Dictionary<string, PropertyInfo>>();

		private readonly Dictionary<Type, Dictionary<string, Dictionary<int, MethodBase>>> declaredMethods = new Dictionary<Type, Dictionary<string, Dictionary<int, MethodBase>>>();

		private readonly Dictionary<Type, Dictionary<string, FieldInfo>> inheritedFields = new Dictionary<Type, Dictionary<string, FieldInfo>>();

		private readonly Dictionary<Type, Dictionary<string, PropertyInfo>> inheritedProperties = new Dictionary<Type, Dictionary<string, PropertyInfo>>();

		private readonly Dictionary<Type, Dictionary<string, Dictionary<int, MethodBase>>> inheritedMethods = new Dictionary<Type, Dictionary<string, Dictionary<int, MethodBase>>>();

		private static T Get<T>(Dictionary<Type, Dictionary<string, T>> dict, Type type, string name, Func<T> fetcher)
		{
			lock (dict)
			{
				if (!dict.TryGetValue(type, out var value))
				{
					value = (dict[type] = new Dictionary<string, T>());
				}
				if (!value.TryGetValue(name, out var value2))
				{
					value2 = (value[name] = fetcher());
				}
				return value2;
			}
		}

		private static T Get<T>(Dictionary<Type, Dictionary<string, Dictionary<int, T>>> dict, Type type, string name, Type[] arguments, Func<T> fetcher)
		{
			lock (dict)
			{
				if (!dict.TryGetValue(type, out var value))
				{
					value = (dict[type] = new Dictionary<string, Dictionary<int, T>>());
				}
				if (!value.TryGetValue(name, out var value2))
				{
					value2 = (value[name] = new Dictionary<int, T>());
				}
				int key = AccessTools.CombinedHashCode(arguments);
				if (!value2.TryGetValue(key, out var value3))
				{
					value3 = (value2[key] = fetcher());
				}
				return value3;
			}
		}

		internal FieldInfo GetFieldInfo(Type type, string name, MemberType memberType = MemberType.Any, bool declaredOnly = false)
		{
			FieldInfo fieldInfo = Get(declaredFields, type, name, () => type.GetField(name, declaredOnlyBindingFlags[memberType]));
			if ((object)fieldInfo == null && !declaredOnly)
			{
				fieldInfo = Get(inheritedFields, type, name, () => AccessTools.FindIncludingBaseTypes(type, (Type t) => t.GetField(name, AccessTools.all)));
			}
			return fieldInfo;
		}

		internal PropertyInfo GetPropertyInfo(Type type, string name, MemberType memberType = MemberType.Any, bool declaredOnly = false)
		{
			PropertyInfo propertyInfo = Get(declaredProperties, type, name, () => type.GetProperty(name, declaredOnlyBindingFlags[memberType]));
			if ((object)propertyInfo == null && !declaredOnly)
			{
				propertyInfo = Get(inheritedProperties, type, name, () => AccessTools.FindIncludingBaseTypes(type, (Type t) => t.GetProperty(name, AccessTools.all)));
			}
			return propertyInfo;
		}

		internal MethodBase GetMethodInfo(Type type, string name, Type[] arguments, MemberType memberType = MemberType.Any, bool declaredOnly = false)
		{
			MethodBase methodBase = Get(declaredMethods, type, name, arguments, () => type.GetMethod(name, declaredOnlyBindingFlags[memberType], null, arguments, null));
			if ((object)methodBase == null && !declaredOnly)
			{
				methodBase = Get(inheritedMethods, type, name, arguments, () => AccessTools.Method(type, name, arguments));
			}
			return methodBase;
		}
	}
	internal static class PatchArgumentExtensions
	{
		private static HarmonyArgument[] AllHarmonyArguments(object[] attributes)
		{
			return (from attr in attributes
				select (attr.GetType().Name != "HarmonyArgument") ? null : AccessTools.MakeDeepCopy<HarmonyArgument>(attr) into harg
				where harg != null
				select harg).ToArray();
		}

		private static HarmonyArgument GetArgumentAttribute(this ParameterInfo parameter)
		{
			return AllHarmonyArguments(parameter.GetCustomAttributes(inherit: false)).FirstOrDefault();
		}

		private static HarmonyArgument[] GetArgumentAttributes(this MethodInfo method)
		{
			if ((object)method == null || method is DynamicMethod)
			{
				return null;
			}
			return AllHarmonyArguments(method.GetCustomAttributes(inherit: false));
		}

		private static HarmonyArgument[] GetArgumentAttributes(this Type type)
		{
			return AllHarmonyArguments(type.GetCustomAttributes(inherit: false));
		}

		private static string GetOriginalArgumentName(this ParameterInfo parameter, string[] originalParameterNames)
		{
			HarmonyArgument argumentAttribute = parameter.GetArgumentAttribute();
			if (argumentAttribute == null)
			{
				return null;
			}
			if (!string.IsNullOrEmpty(argumentAttribute.OriginalName))
			{
				return argumentAttribute.OriginalName;
			}
			if (argumentAttribute.Index >= 0 && argumentAttribute.Index < originalParameterNames.Length)
			{
				return originalParameterNames[argumentAttribute.Index];
			}
			return null;
		}

		private static string GetOriginalArgumentName(HarmonyArgument[] attributes, string name, string[] originalParameterNames)
		{
			if (((attributes != null && attributes.Length != 0) ? 1 : 0) <= (false ? 1 : 0))
			{
				return null;
			}
			HarmonyArgument harmonyArgument = attributes.SingleOrDefault((HarmonyArgument p) => p.NewName == name);
			if (harmonyArgument == null)
			{
				return null;
			}
			if (!string.IsNullOrEmpty(harmonyArgument.OriginalName))
			{
				return harmonyArgument.OriginalName;
			}
			if (originalParameterNames != null && harmonyArgument.Index >= 0 && harmonyArgument.Index < originalParameterNames.Length)
			{
				return originalParameterNames[harmonyArgument.Index];
			}
			return null;
		}

		private static string GetOriginalArgumentName(this MethodInfo method, string[] originalParameterNames, string name)
		{
			string originalArgumentName = GetOriginalArgumentName(((object)method != null) ? method.GetArgumentAttributes() : null, name, originalParameterNames);
			if (originalArgumentName != null)
			{
				return originalArgumentName;
			}
			object attributes;
			if ((object)method == null)
			{
				attributes = null;
			}
			else
			{
				Type? declaringType = method.DeclaringType;
				attributes = (((object)declaringType != null) ? declaringType.GetArgumentAttributes() : null);
			}
			originalArgumentName = GetOriginalArgumentName((HarmonyArgument[])attributes, name, originalParameterNames);
			if (originalArgumentName != null)
			{
				return originalArgumentName;
			}
			return name;
		}

		internal static int GetArgumentIndex(this MethodInfo patch, string[] originalParameterNames, ParameterInfo patchParam)
		{
			if (patch is DynamicMethod)
			{
				return Array.IndexOf<string>(originalParameterNames, patchParam.Name);
			}
			string originalArgumentName = patchParam.GetOriginalArgumentName(originalParameterNames);
			if (originalArgumentName != null)
			{
				return Array.IndexOf(originalParameterNames, originalArgumentName);
			}
			originalArgumentName = patch.GetOriginalArgumentName(originalParameterNames, patchParam.Name);
			if (originalArgumentName != null)
			{
				return Array.IndexOf(originalParameterNames, originalArgumentName);
			}
			return -1;
		}
	}
	internal static class PatchFunctions
	{
		internal static List<MethodInfo> GetSortedPatchMethods(MethodBase original, Patch[] patches, bool debug)
		{
			return new PatchSorter(patches, debug).Sort(original);
		}

		internal static Patch[] GetSortedPatchMethodsAsPatches(MethodBase original, Patch[] patches, bool debug)
		{
			return new PatchSorter(patches, debug).SortAsPatches(original);
		}

		internal static MethodInfo UpdateWrapper(MethodBase original, PatchInfo patchInfo)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected O, but got Unknown
			MethodPatcher methodPatcher = original.GetMethodPatcher();
			DynamicMethodDefinition val = methodPatcher.PrepareOriginal();
			if (val != null)
			{
				ILContext ctx = new ILContext(val.Definition);
				HarmonyManipulator.Manipulate(original, patchInfo, ctx);
			}
			try
			{
				return methodPatcher.DetourTo((val != null) ? val.Generate() : null) as MethodInfo;
			}
			catch (Exception ex)
			{
				object body;
				if (val == null)
				{
					body = null;
				}
				else
				{
					MethodDefinition definition = val.Definition;
					body = ((definition != null) ? definition.Body : null);
				}
				throw HarmonyException.Create(ex, (MethodBody)body);
			}
		}

		internal static MethodInfo ReversePatch(HarmonyMethod standin, MethodBase original, MethodInfo postTranspiler, MethodInfo postManipulator)
		{
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Expected O, but got Unknown
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Expected O, but got Unknown
			if (standin == null)
			{
				throw new ArgumentNullException("standin");
			}
			if ((object)standin.method == null)
			{
				throw new ArgumentNullException("standin", "standin.method is NULL");
			}
			if (!standin.method.IsStatic)
			{
				throw new ArgumentException("standin", "standin.method is not static");
			}
			bool debug = standin.debug.GetValueOrDefault();
			List<MethodInfo> transpilers = new List<MethodInfo>();
			List<MethodInfo> ilmanipulators = new List<MethodInfo>();
			if (standin.reversePatchType == HarmonyReversePatchType.Snapshot)
			{
				Patches patchInfo = Harmony.GetPatchInfo(original);
				transpilers.AddRange(GetSortedPatchMethods(original, patchInfo.Transpilers.ToArray(), debug));
				ilmanipulators.AddRange(GetSortedPatchMethods(original, patchInfo.ILManipulators.ToArray(), debug));
			}
			if ((object)postTranspiler != null)
			{
				transpilers.Add(postTranspiler);
			}
			if ((object)postManipulator != null)
			{
				ilmanipulators.Add(postManipulator);
			}
			Logger.Log(Logger.LogChannel.Info, delegate
			{
				StringBuilder stringBuilder = new StringBuilder();
				stringBuilder.AppendLine("Reverse patching " + standin.method.FullDescription() + " with " + original.FullDescription());
				PrintInfo(stringBuilder, transpilers, "Transpiler");
				PrintInfo(stringBuilder, ilmanipulators, "Manipulators");
				return stringBuilder.ToString();
			}, debug);
			MethodBody patchBody = null;
			ILHook val = new ILHook((MethodBase)standin.method, (Manipulator)delegate(ILContext ctx)
			{
				//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
				//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
				//IL_00fb: Expected O, but got Unknown
				//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
				//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
				if (original is MethodInfo methodInfo2)
				{
					patchBody = ctx.Body;
					MethodPatcher methodPatcher = methodInfo2.GetMethodPatcher();
					DynamicMethodDefinition val2 = methodPatcher.CopyOriginal();
					if (val2 == null)
					{
						throw new NullReferenceException("Cannot reverse patch " + methodInfo2.FullDescription() + ": method patcher (" + methodPatcher.GetType().FullDescription() + ") can't copy original method body");
					}
					ILManipulator iLManipulator = new ILManipulator(val2.Definition.Body, debug);
					ctx.Body.Variables.Clear();
					Enumerator<VariableDefinition> enumerator2 = iLManipulator.Body.Variables.GetEnumerator();
					try
					{
						while (enumerator2.MoveNext())
						{
							VariableDefinition current2 = enumerator2.Current;
							ctx.Body.Variables.Add(new VariableDefinition(ctx.Module.ImportReference(((VariableReference)current2).VariableType)));
						}
					}
					finally
					{
						((IDisposable)enumerator2).Dispose();
					}
					foreach (MethodInfo item in transpilers)
					{
						iLManipulator.AddTranspiler(item);
					}
					iLManipulator.WriteTo(ctx.Body, standin.method);
					HarmonyManipulator.ApplyManipulators(ctx, original, ilmanipulators, null);
					Instruction val3 = null;
					foreach (Instruction item2 in ((IEnumerable<Instruction>)ctx.Instrs).Where((Instruction i) => i.OpCode == OpCodes.Ret))
					{
						if (val3 == null)
						{
							val3 = ctx.IL.Create(OpCodes.Ret);
						}
						item2.OpCode = OpCodes.Br;
						item2.Operand = val3;
					}
					if (val3 != null)
					{
						ctx.IL.Append(val3);
					}
					Logger.Log(Logger.LogChannel.IL, () => "Generated reverse patcher (" + ((MemberReference)ctx.Method).FullName + "):\n" + ctx.Body.ToILDasmString(), debug);
				}
			}, new ILHookConfig
			{
				ManualApply = true
			});
			try
			{
				val.Apply();
			}
			catch (Exception ex)
			{
				throw HarmonyException.Create(ex, patchBody);
			}
			MethodInfo methodInfo = val.GetCurrentTarget() as MethodInfo;
			PatchTools.RememberObject(standin.method, methodInfo);
			return methodInfo;
			static void PrintInfo(StringBuilder sb, ICollection<MethodInfo> methods, string name)
			{
				if (methods.Count <= 0)
				{
					return;
				}
				sb.AppendLine(name + ":");
				foreach (MethodInfo method in methods)
				{
					sb.AppendLine("  * " + method.FullDescription());
				}
			}
		}

		internal static IEnumerable<CodeInstruction> ApplyTranspilers(MethodBase methodBase, ILGenerator generator, int maxTranspilers = 0)
		{
			MethodPatcher methodPatcher = methodBase.GetMethodPatcher();
			DynamicMethodDefinition val = methodPatcher.CopyOriginal();
			if (val == null)
			{
				throw new NullReferenceException("Cannot reverse patch " + methodBase.FullDescription() + ": method patcher (" + methodPatcher.GetType().FullDescription() + ") can't copy original method body");
			}
			ILManipulator iLManipulator = new ILManipulator(val.Definition.Body, debug: false);
			PatchInfo patchInfo = methodBase.GetPatchInfo();
			if (patchInfo != null)
			{
				List<MethodInfo> sortedPatchMethods = GetSortedPatchMethods(methodBase, patchInfo.transpilers, debug: false);
				for (int i = 0; i < maxTranspilers && i < sortedPatchMethods.Count; i++)
				{
					iLManipulator.AddTranspiler(sortedPatchMethods[i]);
				}
			}
			return iLManipulator.GetInstructions(generator, methodBase);
		}

		internal static void UnpatchConditional(Func<Patch, bool> executionCondition)
		{
			foreach (MethodBase item in PatchProcessor.GetAllPatchedMethods().ToList())
			{
				bool num = item.HasMethodBody();
				Patches patchInfo2 = PatchProcessor.GetPatchInfo(item);
				PatchProcessor patchProcessor = new PatchProcessor(null, item);
				if (num)
				{
					patchInfo2.Postfixes.DoIf(executionCondition, delegate(Patch patchInfo)
					{
						patchProcessor.Unpatch(patchInfo.PatchMethod);
					});
					patchInfo2.Prefixes.DoIf(executionCondition, delegate(Patch patchInfo)
					{
						patchProcessor.Unpatch(patchInfo.PatchMethod);
					});
				}
				patchInfo2.ILManipulators.DoIf(executionCondition, delegate(Patch patchInfo)
				{
					patchProcessor.Unpatch(patchInfo.PatchMethod);
				});
				patchInfo2.Transpilers.DoIf(executionCondition, delegate(Patch patchInfo)
				{
					patchProcessor.Unpatch(patchInfo.PatchMethod);
				});
				if (num)
				{
					patchInfo2.Finalizers.DoIf(executionCondition, delegate(Patch patchInfo)
					{
						patchProcessor.Unpatch(patchInfo.PatchMethod);
					});
				}
			}
		}
	}
	internal class PatchJobs<T>
	{
		internal class Job
		{
			internal MethodBase original;

			internal T replacement;

			internal List<HarmonyMethod> prefixes = new List<HarmonyMethod>();

			internal List<HarmonyMethod> postfixes = new List<HarmonyMethod>();

			internal List<HarmonyMethod> transpilers = new List<HarmonyMethod>();

			internal List<HarmonyMethod> finalizers = new List<HarmonyMethod>();

			internal List<HarmonyMethod> ilmanipulators = new List<HarmonyMethod>();

			internal void AddPatch(AttributePatch patch)
			{
				HarmonyPatchType? type = patch.type;
				if (type.HasValue)
				{
					switch (type.GetValueOrDefault())
					{
					case HarmonyPatchType.Prefix:
						prefixes.Add(patch.info);
						break;
					case HarmonyPatchType.Postfix:
						postfixes.Add(patch.info);
						break;
					case HarmonyPatchType.Transpiler:
						transpilers.Add(patch.info);
						break;
					case HarmonyPatchType.Finalizer:
						finalizers.Add(patch.info);
						break;
					case HarmonyPatchType.ILManipulator:
						ilmanipulators.Add(patch.info);
						break;
					case HarmonyPatchType.ReversePatch:
						break;
					}
				}
			}
		}

		internal Dictionary<MethodBase, Job> state = new Dictionary<MethodBase, Job>();

		internal Job GetJob(MethodBase method)
		{
			if ((object)method == null)
			{
				return null;
			}
			if (!state.TryGetValue(method, out var value))
			{
				value = new Job
				{
					original = method
				};
				state[method] = value;
			}
			return value;
		}

		internal List<Job> GetJobs()
		{
			return state.Values.Where((Job job) => job.prefixes.Count + job.postfixes.Count + job.transpilers.Count + job.finalizers.Count + job.ilmanipulators.Count > 0).ToList();
		}

		internal List<T> GetReplacements()
		{
			return state.Values.Select((Job job) => job.replacement).ToList();
		}
	}
	internal class AttributePatch
	{
		private static readonly HarmonyPatchType[] allPatchTypes = new HarmonyPatchType[6]
		{
			HarmonyPatchType.Prefix,
			HarmonyPatchType.Postfix,
			HarmonyPatchType.Transpiler,
			HarmonyPatchType.Finalizer,
			HarmonyPatchType.ReversePatch,
			HarmonyPatchType.ILManipulator
		};

		internal HarmonyMethod info;

		internal HarmonyPatchType? type;

		private static readonly string harmonyAttributeName = typeof(HarmonyAttribute).FullName;

		internal static IEnumerable<AttributePatch> Create(MethodInfo patch, bool collectIncomplete = false)
		{
			if ((object)patch == null)
			{
				throw new NullReferenceException("Patch method cannot be null");
			}
			object[] customAttributes = patch.GetCustomAttributes(inherit: true);
			string name = patch.Name;
			HarmonyPatchType? type = GetPatchType(name, customAttributes);
			if (!type.HasValue)
			{
				return Enumerable.Empty<AttributePatch>();
			}
			if (type != HarmonyPatchType.ReversePatch && !patch.IsStatic)
			{
				throw new ArgumentException("Patch method " + patch.FullDescription() + " must be static");
			}
			List<HarmonyMethod> list = (from attr in customAttributes
				where attr.GetType().BaseType.FullName == harmonyAttributeName
				select AccessTools.Field(attr.GetType(), "info").GetValue(attr) into harmonyInfo
				select AccessTools.MakeDeepCopy<HarmonyMethod>(harmonyInfo)).ToList();
			List<HarmonyMethod> list2 = new List<HarmonyMethod>();
			ILookup<bool, HarmonyMethod> lookup = list.ToLookup((HarmonyMethod m) => IsComplete(m, collectIncomplete));
			List<HarmonyMethod> incomplete = lookup[false].ToList();
			HarmonyMethod info = HarmonyMethod.Merge(incomplete);
			List<HarmonyMethod> list3 = lookup[true].Where((HarmonyMethod m) => !Same(m, info)).ToList();
			if (list3.Count > 1)
			{
				list2.AddRange(list3.Select((HarmonyMethod m) => HarmonyMethod.Merge(incomplete.AddItem(m))));
			}
			else
			{
				list2.Add(HarmonyMethod.Merge(list));
			}
			foreach (HarmonyMethod item in list2)
			{
				item.method = patch;
			}
			return list2.Select((HarmonyMethod i) => new AttributePatch
			{
				info = i,
				type = type
			}).ToList();
			static bool IsComplete(HarmonyMethod m, bool collectIncomplete)
			{
				if (collectIncomplete || m.GetDeclaringType() != null)
				{
					return m.methodName != null;
				}
				return false;
			}
			static bool Same(HarmonyMethod m1, HarmonyMethod m2)
			{
				if (m1.GetDeclaringType() == m2.GetDeclaringType() && m1.methodName == m2.methodName)
				{
					return m1.GetArgumentList().SequenceEqual(m2.GetArgumentList());
				}
				return false;
			}
		}

		private static HarmonyPatchType? GetPatchType(string methodName, object[] allAttributes)
		{
			HashSet<string> hashSet = new HashSet<string>(from attr in allAttributes
				select attr.GetType().FullName into name
				where name.StartsWith("Harmony")
				select name);
			HarmonyPatchType? result = null;
			HarmonyPatchType[] array = allPatchTypes;
			for (int i = 0; i < array.Length; i++)
			{
				HarmonyPatchType value = array[i];
				string text = value.ToString();
				if (text == methodName || hashSet.Contains("HarmonyLib.Harmony" + text))
				{
					result = value;
					break;
				}
			}
			return result;
		}
	}
	internal class PatchSorter
	{
		private class PatchSortingWrapper : IComparable
		{
			internal readonly HashSet<PatchSortingWrapper> after;

			internal readonly HashSet<PatchSortingWrapper> before;

			internal readonly Patch innerPatch;

			internal PatchSortingWrapper(Patch patch)
			{
				innerPatch = patch;
				before = new HashSet<PatchSortingWrapper>();
				after = new HashSet<PatchSortingWrapper>();
			}

			public int CompareTo(object obj)
			{
				return PatchInfoSerialization.PriorityComparer((obj as PatchSortingWrapper)?.innerPatch, innerPatch.index, innerPatch.priority);
			}

			public override bool Equals(object obj)
			{
				if (obj is PatchSortingWrapper patchSortingWrapper)
				{
					return innerPatch.PatchMethod == patchSortingWrapper.innerPatch.PatchMethod;
				}
				return false;
			}

			public override int GetHashCode()
			{
				return innerPatch.PatchMethod.GetHashCode();
			}

			internal void AddBeforeDependency(IEnumerable<PatchSortingWrapper> dependencies)
			{
				foreach (PatchSortingWrapper dependency in dependencies)
				{
					before.Add(dependency);
					dependency.after.Add(this);
				}
			}

			internal void AddAfterDependency(IEnumerable<PatchSortingWrapper> dependencies)
			{
				foreach (PatchSortingWrapper dependency in dependencies)
				{
					after.Add(dependency);
					dependency.before.Add(this);
				}
			}

			internal void RemoveAfterDependency(PatchSortingWrapper afterNode)
			{
				after.Remove(afterNode);
				afterNode.before.Remove(this);
			}

			internal void RemoveBeforeDependency(PatchSortingWrapper beforeNode)
			{
				before.Remove(beforeNode);
				beforeNode.after.Remove(this);
			}
		}

		internal class PatchDetailedComparer : IEqualityComparer<Patch>
		{
			public bool Equals(Patch x, Patch y)
			{
				if (y != null && x != null && x.owner == y.owner && x.PatchMethod == y.PatchMethod && x.index == y.index && x.priority == y.priority && x.before.Length == y.before.Length && x.after.Length == y.after.Length && x.before.All(((IEnumerable<string>)y.before).Contains<string>))
				{
					return x.after.All(((IEnumerable<string>)y.after).Contains<string>);
				}
				return false;
			}

			public int GetHashCode(Patch obj)
			{
				return obj.GetHashCode();
			}
		}

		private List<PatchSortingWrapper> patches;

		private HashSet<PatchSortingWrapper> handledPatches;

		private List<PatchSortingWrapper> result;

		private List<PatchSortingWrapper> waitingList;

		internal Patch[] sortedPatchArray;

		private readonly bool debug;

		internal PatchSorter(Patch[] patches, bool debug = false)
		{
			this.patches = patches.Select((Patch x) => new PatchSortingWrapper(x)).ToList();
			this.debug = debug;
			foreach (PatchSortingWrapper node in this.patches)
			{
				node.AddBeforeDependency(this.patches.Where((PatchSortingWrapper x) => node.innerPatch.before.Contains(x.innerPatch.owner)));
				node.AddAfterDependency(this.patches.Where((PatchSortingWrapper x) => node.innerPatch.after.Contains(x.innerPatch.owner)));
			}
			this.patches.Sort();
		}

		internal List<MethodInfo> Sort(MethodBase original)
		{
			return (from x in SortAsPatches(original)
				select x.GetMethod(original)).ToList();
		}

		internal Patch[] SortAsPatches(MethodBase original)
		{
			if (sortedPatchArray != null)
			{
				return sortedPatchArray;
			}
			handledPatches = new HashSet<PatchSortingWrapper>();
			waitingList = new List<PatchSortingWrapper>();
			result = new List<PatchSortingWrapper>(patches.Count);
			Queue<PatchSortingWrapper> queue = new Queue<PatchSortingWrapper>(patches);
			while (queue.Count != 0)
			{
				foreach (PatchSortingWrapper item in queue)
				{
					if (item.after.All((PatchSortingWrapper x) => handledPatches.Contains(x)))
					{
						AddNodeToResult(item);
						if (item.before.Count != 0)
						{
							ProcessWaitingList();
						}
					}
					else
					{
						waitingList.Add(item);
					}
				}
				CullDependency();
				queue = new Queue<PatchSortingWrapper>(waitingList);
				waitingList.Clear();
			}
			sortedPatchArray = result.Select((PatchSortingWrapper x) => x.innerPatch).ToArray();
			handledPatches = null;
			waitingList = null;
			patches = null;
			return sortedPatchArray;
		}

		internal bool ComparePatchLists(Patch[] patches)
		{
			if (sortedPatchArray == null)
			{
				Sort(null);
			}
			if (patches != null && sortedPatchArray.Length == patches.Length)
			{
				return sortedPatchArray.All((Patch x) => patches.Contains(x, new PatchDetailedComparer()));
			}
			return false;
		}

		private void CullDependency()
		{
			for (int i = waitingList.Count - 1; i >= 0; i--)
			{
				foreach (PatchSortingWrapper afterNode in waitingList[i].after)
				{
					if (!handledPatches.Contains(afterNode))
					{
						waitingList[i].RemoveAfterDependency(afterNode);
						Logger.Log(Logger.LogChannel.Debug, delegate
						{
							string text = afterNode.innerPatch.PatchMethod.FullDescription();
							string text2 = waitingList[i].innerPatch.PatchMethod.FullDescription();
							return "Breaking dependence between " + text + " and " + text2;
						}, debug);
						return;
					}
				}
			}
		}

		private void ProcessWaitingList()
		{
			int num = waitingList.Count;
			int num2 = 0;
			while (num2 < num)
			{
				PatchSortingWrapper patchSortingWrapper = waitingList[num2];
				if (patchSortingWrapper.after.All(handledPatches.Contains))
				{
					waitingList.Remove(patchSortingWrapper);
					AddNodeToResult(patchSortingWrapper);
					num--;
					num2 = 0;
				}
				else
				{
					num2++;
				}
			}
		}

		private void AddNodeToResult(PatchSortingWrapper node)
		{
			result.Add(node);
			handledPatches.Add(node);
		}
	}
	internal static class PatchTools
	{
		[ThreadStatic]
		private static Dictionary<object, object> objectReferences;

		internal static void RememberObject(object key, object value)
		{
			if (objectReferences == null)
			{
				objectReferences = new Dictionary<object, object>();
			}
			objectReferences[key] = value;
		}

		internal static MethodInfo GetPatchMethod(Type patchType, string attributeName)
		{
			MethodInfo methodInfo = patchType.GetMethods(AccessTools.all).FirstOrDefault((MethodInfo m) => m.GetCustomAttributes(inherit: true).Any((object a) => a.GetType().FullName == attributeName));
			if ((object)methodInfo == null)
			{
				string name = attributeName.Replace("HarmonyLib.Harmony", "");
				methodInfo = patchType.GetMethod(name, AccessTools.all);
			}
			return methodInfo;
		}

		internal static AssemblyBuilder DefineDynamicAssembly(string name)
		{
			return AssemblyBuilder.DefineDynamicAssembly(new AssemblyName(name), AssemblyBuilderAccess.Run);
		}

		internal static List<AttributePatch> GetPatchMethods(Type type, bool collectIncomplete = false)
		{
			return (from attributePatch in AccessTools.GetDeclaredMethods(type).SelectMany((MethodInfo m) => AttributePatch.Create(m, collectIncomplete))
				where attributePatch != null
				select attributePatch).ToList();
		}

		internal static MethodBase GetOriginalMethod(this HarmonyMethod attr)
		{
			try
			{
				MethodType? methodType = attr.methodType;
				if (methodType.HasValue)
				{
					switch (methodType.GetValueOrDefault())
					{
					case MethodType.Normal:
						if (attr.methodName == null)
						{
							return null;
						}
						return AccessTools.DeclaredMethod(attr.GetDeclaringType(), attr.methodName, attr.argumentTypes);
					case MethodType.Getter:
						if (attr.methodName == null)
						{
							return null;
						}
						return AccessTools.DeclaredProperty(attr.GetDeclaringType(), attr.methodName).GetGetMethod(nonPublic: true);
					case MethodType.Setter:
						if (attr.methodName == null)
						{
							return null;
						}
						return AccessTools.DeclaredProperty(attr.GetDeclaringType(), attr.methodName).GetSetMethod(nonPublic: true);
					case MethodType.Constructor:
						return AccessTools.DeclaredConstructor(attr.GetDeclaringType(), attr.argumentTypes);
					case MethodType.StaticConstructor:
						return AccessTools.GetDeclaredConstructors(attr.GetDeclaringType()).FirstOrDefault((ConstructorInfo c) => c.IsStatic);
					case MethodType.Enumerator:
						if (attr.methodName == null)
						{
							return null;
						}
						return AccessTools.EnumeratorMoveNext(AccessTools.DeclaredMethod(attr.GetDeclaringType(), attr.methodName, attr.argumentTypes));
					}
				}
			}
			catch (AmbiguousMatchException ex)
			{
				throw new HarmonyException("Ambiguous match for HarmonyMethod[" + attr.Description() + "]", ex.InnerException ?? ex);
			}
			return null;
		}
	}
	public enum MethodType
	{
		Normal,
		Getter,
		Setter,
		Constructor,
		StaticConstructor,
		Enumerator
	}
	public enum ArgumentType
	{
		Normal,
		Ref,
		Out,
		Pointer
	}
	public enum HarmonyPatchType
	{
		All,
		Prefix,
		Postfix,
		Transpiler,
		Finalizer,
		ReversePatch,
		ILManipulator
	}
	public enum HarmonyReversePatchType
	{
		Original,
		Snapshot
	}
	public enum MethodDispatchType
	{
		VirtualCall,
		Call
	}
	[MeansImplicitUse]
	public class HarmonyAttribute : Attribute
	{
		public HarmonyMethod info = new HarmonyMethod();
	}
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method | AttributeTargets.Delegate, AllowMultiple = true)]
	public class HarmonyPatch : HarmonyAttribute
	{
		public HarmonyPatch()
		{
		}

		public HarmonyPatch(Type declaringType)
		{
			info.declaringType = declaringType;
		}

		public HarmonyPatch(Type declaringType, Type[] argumentTypes)
		{
			info.declaringType = declaringType;
			info.argumentTypes = argumentTypes;
		}

		public HarmonyPatch(Type declaringType, string methodName)
		{
			info.declaringType = declaringType;
			info.methodName = methodName;
		}

		public HarmonyPatch(Type declaringType, string methodName, params Type[] argumentTypes)
		{
			info.declaringType = declaringType;
			info.methodName = methodName;
			info.argumentTypes = argumentTypes;
		}

		public HarmonyPatch(Type declaringType, string methodName, Type[] argumentTypes, ArgumentType[] argumentVariations)
		{
			info.declaringType = declaringType;
			info.methodName = methodName;
			ParseSpecialArguments(argumentTypes, argumentVariations);
		}

		public HarmonyPatch(string typeName, string methodName)
		{
			info.declaringType = AccessTools.TypeByName(typeName);
			info.methodName = methodName;
		}

		public HarmonyPatch(string typeName, string methodName, MethodType methodType, Type[] argumentTypes = null, ArgumentType[] argumentVariations = null)
		{
			info.declaringType = AccessTools.TypeByName(typeName);
			info.methodName = methodName;
			info.methodType = methodType;
			if (argumentTypes != null)
			{
				ParseSpecialArguments(argumentTypes, argumentVariations);
			}
		}

		public HarmonyPatch(Type declaringType, MethodType methodType)
		{
			info.declaringType = declaringType;
			info.methodType = methodType;
		}

		public HarmonyPatch(Type declaringType, MethodType methodType, params Type[] argumentTypes)
		{
			info.declaringType = declaringType;
			info.methodType = methodType;
			info.argumentTypes = argumentTypes;
		}

		public HarmonyPatch(Type declaringType, MethodType methodType, Type[] argumentTypes, ArgumentType[] argumentVariations)
		{
			info.declaringType = declaringType;
			info.methodType = methodType;
			ParseSpecialArguments(argumentTypes, argumentVariations);
		}

		public HarmonyPatch(Type declaringType, string methodName, MethodType methodType)
		{
			info.declaringType = declaringType;
			info.methodName = methodName;
			info.methodType = methodType;
		}

		public HarmonyPatch(string methodName)
		{
			info.methodName = methodName;
		}

		public HarmonyPatch(string methodName, params Type[] argumentTypes)
		{
			info.methodName = methodName;
			info.argumentTypes = argumentTypes;
		}

		public HarmonyPatch(string methodName, Type[] argumentTypes, ArgumentType[] argumentVariations)
		{
			info.methodName = methodName;
			ParseSpecialArguments(argumentTypes, argumentVariations);
		}

		public HarmonyPatch(string methodName, MethodType methodType)
		{
			info.methodName = methodName;
			info.methodType = methodType;
		}

		public HarmonyPatch(MethodType methodType)
		{
			info.methodType = methodType;
		}

		public HarmonyPatch(MethodType methodType, params Type[] argumentTypes)
		{
			info.methodType = methodType;
			info.argumentTypes = argumentTypes;
		}

		public HarmonyPatch(MethodType methodType, Type[] argumentTypes, ArgumentType[] argumentVariations)
		{
			info.methodType = methodType;
			ParseSpecialArguments(argumentTypes, argumentVariations);
		}

		public HarmonyPatch(Type[] argumentTypes)
		{
			info.argumentTypes = argumentTypes;
		}

		public HarmonyPatch(Type[] argumentTypes, ArgumentType[] argumentVariations)
		{
			ParseSpecialArguments(argumentTypes, argumentVariations);
		}

		public HarmonyPatch(string typeName, string methodName, MethodType methodType = MethodType.Normal)
		{
			info.declaringType = AccessTools.TypeByName(typeName);
			info.methodName = methodName;
			info.methodType = methodType;
		}

		private void ParseSpecialArguments(Type[] argumentTypes, ArgumentType[] argumentVariations)
		{
			if (argumentVariations == null || argumentVariations.Length == 0)
			{
				info.argumentTypes = argumentTypes;
				return;
			}
			if (argumentTypes.Length < argumentVariations.Length)
			{
				throw new ArgumentException("argumentVariations contains more elements than argumentTypes", "argumentVariations");
			}
			List<Type> list = new List<Type>();
			for (int i = 0; i < argumentTypes.Length; i++)
			{
				Type type = argumentTypes[i];
				switch (argumentVariations[i])
				{
				case ArgumentType.Ref:
				case ArgumentType.Out:
					type = type.MakeByRefType();
					break;
				case ArgumentType.Pointer:
					type = type.MakePointerType();
					break;
				}
				list.Add(type);
			}
			info.argumentTypes = list.ToArray();
		}
	}
	[AttributeUsage(AttributeTargets.Delegate, AllowMultiple = true)]
	public class HarmonyDelegate : HarmonyPatch
	{
		public HarmonyDelegate(Type declaringType)
			: base(declaringType)
		{
		}

		public HarmonyDelegate(Type declaringType, Type[] argumentTypes)
			: base(declaringType, argumentTypes)
		{
		}

		public HarmonyDelegate(Type declaringType, string methodName)
			: base(declaringType, methodName)
		{
		}

		public HarmonyDelegate(Type declaringType, string methodName, params Type[] argumentTypes)
			: base(declaringType, methodName, argumentTypes)
		{
		}

		public HarmonyDelegate(Type declaringType, string methodName, Type[] argumentTypes, ArgumentType[] argumentVariations)
			: base(declaringType, methodName, argumentTypes, argumentVariations)
		{
		}

		public HarmonyDelegate(Type declaringType, MethodDispatchType methodDispatchType)
			: base(declaringType, MethodType.Normal)
		{
			info.nonVirtualDelegate = methodDispatchType == MethodDispatchType.Call;
		}

		public HarmonyDelegate(Type declaringType, MethodDispatchType methodDispatchType, params Type[] argumentTypes)
			: base(declaringType, MethodType.Normal, argumentTypes)
		{
			info.nonVirtualDelegate = methodDispatchType == MethodDispatchType.Call;
		}

		public HarmonyDelegate(Type declaringType, MethodDispatchType methodDispatchType, Type[] argumentTypes, ArgumentType[] argumentVariations)
			: base(declaringType, MethodType.Normal, argumentTypes, argumentVariations)
		{
			info.nonVirtualDelegate = methodDispatchType == MethodDispatchType.Call;
		}

		public HarmonyDelegate(Type declaringType, string methodName, MethodDispatchType methodDispatchType)
			: base(declaringType, methodName, MethodType.Normal)
		{
			info.nonVirtualDelegate = methodDispatchType == MethodDispatchType.Call;
		}

		public HarmonyDelegate(string methodName)
			: base(methodName)
		{
		}

		public HarmonyDelegate(string methodName, params Type[] argumentTypes)
			: base(methodName, argumentTypes)
		{
		}

		public HarmonyDelegate(string methodName, Type[] argumentTypes, ArgumentType[] argumentVariations)
			: base(methodName, argumentTypes, argumentVariations)
		{
		}

		public HarmonyDelegate(string methodName, MethodDispatchType methodDispatchType)
			: base(methodName, MethodType.Normal)
		{
			info.nonVirtualDelegate = methodDispatchType == MethodDispatchType.Call;
		}

		public HarmonyDelegate(MethodDispatchType methodDispatchType)
		{
			info.nonVirtualDelegate = methodDispatchType == MethodDispatchType.Call;
		}

		public HarmonyDelegate(MethodDispatchType methodDispatchType, params Type[] argumentTypes)
			: base(MethodType.Normal, argumentTypes)
		{
			info.nonVirtualDelegate = methodDispatchType == MethodDispatchType.Call;
		}

		public HarmonyDelegate(MethodDispatchType methodDispatchType, Type[] argumentTypes, ArgumentType[] argumentVariations)
			: base(MethodType.Normal, argumentTypes, argumentVariations)
		{
			info.nonVirtualDelegate = methodDispatchType == MethodDispatchType.Call;
		}

		public HarmonyDelegate(Type[] argumentTypes)
			: base(argumentTypes)
		{
		}

		public HarmonyDelegate(Type[] argumentTypes, ArgumentType[] argumentVariations)
			: base(argumentTypes, argumentVariations)
		{
		}
	}
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true)]
	public class HarmonyReversePatch : HarmonyAttribute
	{
		public HarmonyReversePatch(HarmonyReversePatchType type = HarmonyReversePatchType.Original)
		{
			info.reversePatchType = type;
		}
	}
	[AttributeUsage(AttributeTargets.Class)]
	public class HarmonyPatchAll : HarmonyAttribute
	{
	}
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
	public class HarmonyPriority : HarmonyAttribute
	{
		public HarmonyPriority(int priority)
		{
			info.priority = priority;
		}
	}
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
	public class HarmonyBefore : HarmonyAttribute
	{
		public HarmonyBefore(params string[] before)
		{
			info.before = before;
		}
	}
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
	public class HarmonyAfter : HarmonyAttribute
	{
		public HarmonyAfter(params string[] after)
		{
			info.after = after;
		}
	}
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
	public class HarmonyDebug : HarmonyAttribute
	{
		public HarmonyDebug()
		{
			info.debug = true;
		}
	}
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
	public class HarmonyEmitIL : HarmonyAttribute
	{
		public HarmonyEmitIL()
		{
			info.debugEmitPath = "./";
		}

		public HarmonyEmitIL(string dir)
		{
			info.debugEmitPath = dir;
		}
	}
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
	public class HarmonyWrapSafe : HarmonyAttribute
	{
		public HarmonyWrapSafe()
		{
			info.wrapTryCatch = true;
		}
	}
	[AttributeUsage(AttributeTargets.Method)]
	public class HarmonyPrepare : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Method)]
	public class HarmonyCleanup : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Method)]
	public class HarmonyTargetMethod : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Method)]
	public class HarmonyTargetMethods : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Method)]
	public class HarmonyPrefix : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Method)]
	public class HarmonyPostfix : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Method)]
	public class HarmonyTranspiler : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Method)]
	public class HarmonyILManipulator : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Method)]
	public class HarmonyFinalizer : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method | AttributeTargets.Parameter, AllowMultiple = true)]
	public class HarmonyArgument : Attribute
	{
		public string OriginalName { get; private set; }

		public int Index { get; private set; }

		public string NewName { get; private set; }

		public HarmonyArgument(string originalName)
			: this(originalName, null)
		{
		}

		public HarmonyArgument(int index)
			: this(index, null)
		{
		}

		public HarmonyArgument(string originalName, string newName)
		{
			OriginalName = originalName;
			Index = -1;
			NewName = newName;
		}

		public HarmonyArgument(int index, string name)
		{
			OriginalName = null;
			Index = index;
			NewName = name;
		}
	}
	public class CodeInstruction
	{
		public OpCode opcode;

		public object operand;

		public List<Label> labels = new List<Label>();

		public List<ExceptionBlock> blocks = new List<ExceptionBlock>();

		internal CodeInstruction()
		{
		}

		public CodeInstruction(OpCode opcode, object operand = null)
		{
			this.opcode = opcode;
			this.operand = operand;
		}

		public CodeInstruction(CodeInstruction instruction)
		{
			opcode = instruction.opcode;
			operand = instruction.operand;
			labels = instruction.labels.ToList();
			blocks = instruction.blocks.ToList();
		}

		public CodeInstruction Clone()
		{
			return new CodeInstruction(this)
			{
				labels = new List<Label>(),
				blocks = new List<ExceptionBlock>()
			};
		}

		public CodeInstruction Clone(OpCode opcode)
		{
			CodeInstruction codeInstruction = Clone();
			codeInstruction.opcode = opcode;
			return codeInstruction;
		}

		public CodeInstruction Clone(object operand)
		{
			CodeInstruction codeInstruction = Clone();
			codeInstruction.operand = operand;
			return codeInstruction;
		}

		public static CodeInstruction Call(Type type, string name, Type[] parameters = null, Type[] generics = null)
		{
			MethodInfo methodInfo = AccessTools.Method(type, name, parameters, generics);
			if ((object)methodInfo == null)
			{
				throw new ArgumentException($"No method found for type={type}, name={name}, parameters={parameters.Description()}, generics={generics.Description()}");
			}
			return new CodeInstruction(OpCodes.Call, methodInfo);
		}

		public static CodeInstruction Call(string typeColonMethodname, Type[] parameters = null, Type[] generics = null)
		{
			MethodInfo methodInfo = AccessTools.Method(typeColonMethodname, parameters, generics);
			if ((object)methodInfo == null)
			{
				throw new ArgumentException("No method found for " + typeColonMethodname + ", parameters=" + parameters.Description() + ", generics=" + generics.Description());
			}
			return new CodeInstruction(OpCodes.Call, methodInfo);
		}

		public static CodeInstruction Call(Expression<Action> expression)
		{
			return new CodeInstruction(OpCodes.Call, SymbolExtensions.GetMethodInfo(expression));
		}

		public static CodeInstruction Call<T>(Expression<Action<T>> expression)
		{
			return new CodeInstruction(OpCodes.Call, SymbolExtensions.GetMethodInfo(expression));
		}

		public static CodeInstruction Call<T, TResult>(Expression<Func<T, TResult>> expression)
		{
			return new CodeInstruction(OpCodes.Call, SymbolExtensions.GetMethodInfo(expression));
		}

		public static CodeInstruction Call(LambdaExpression expression)
		{
			return new CodeInstruction(OpCodes.Call, SymbolExtensions.GetMethodInfo(expression));
		}

		public static CodeInstruction CallClosure<T>(T closure) where T : Delegate
		{
			return Transpilers.EmitDelegate(closure);
		}

		public static CodeInstruction LoadField(Type type, string name, bool useAddress = false)
		{
			FieldInfo fieldInfo = AccessTools.Field(type, name);
			if ((object)fieldInfo == null)
			{
				throw new ArgumentException($"No field found for {type} and {name}");
			}
			return new CodeInstruction((!useAddress) ? (fieldInfo.IsStatic ? OpCodes.Ldsfld : OpCodes.Ldfld) : (fieldInfo.IsStatic ? OpCodes.Ldsflda : OpCodes.Ldflda), fieldInfo);
		}

		public static CodeInstruction StoreField(Type type, string name)
		{
			FieldInfo fieldInfo = AccessTools.Field(type, name);
			if ((object)fieldInfo == null)
			{
				throw new ArgumentException($"No field found for {type} and {name}");
			}
			return new CodeInstruction(fieldInfo.IsStatic ? OpCodes.Stsfld : OpCodes.Stfld, fieldInfo);
		}

		public override string ToString()
		{
			List<string> list = new List<string>();
			foreach (Label label in labels)
			{
				list.Add($"Label{label.GetHashCode()}");
			}
			foreach (ExceptionBlock block in blocks)
			{
				list.Add("EX_" + block.blockType.ToString().Replace("Block", ""));
			}
			string text = ((list.Count > 0) ? (" [" + string.Join(", ", list.ToArray()) + "]") : "");
			string text2 = FormatArgument(operand);
			if (text2.Length > 0)
			{
				text2 = " " + text2;
			}
			OpCode opCode = opcode;
			return opCode.ToString() + text2 + text;
		}

		internal static string FormatArgument(object argument, string extra = null)
		{
			if (argument == null)
			{
				return "NULL";
			}
			Type type = argument.GetType();
			if (argument is MethodBase member)
			{
				return member.FullDescription() + ((extra != null) ? (" " + extra) : "");
			}
			if (argument is FieldInfo fieldInfo)
			{
				return fieldInfo.FieldType.FullDescription() + " " + fieldInfo.DeclaringType.FullDescription() + "::" + fieldInfo.Name;
			}
			if (type == typeof(Label))
			{
				return $"Label{((Label)argument).GetHashCode()}";
			}
			if (type == typeof(Label[]))
			{
				return "Labels" + string.Join(",", ((Label[])argument).Select((Label l) => l.GetHashCode().ToString()).ToArray());
			}
			if (type == typeof(LocalBuilder))
			{
				return $"{((LocalBuilder)argument).LocalIndex} ({((LocalBuilder)argument).LocalType})";
			}
			if (type == typeof(string))
			{
				return argument.ToString().ToLiteral();
			}
			return argument.ToString().Trim();
		}
	}
	public enum ExceptionBlockType
	{
		BeginExceptionBlock,
		BeginCatchBlock,
		BeginExceptFilterBlock,
		BeginFaultBlock,
		BeginFinallyBlock,
		EndExceptionBlock
	}
	public class ExceptionBlock
	{
		public ExceptionBlockType blockType;

		public Type catchType;

		public ExceptionBlock(ExceptionBlockType blockType, Type catchType = null)
		{
			this.blockType = blockType;
			this.catchType = catchType ?? typeof(object);
		}
	}
	public class InvalidHarmonyPatchArgumentException : Exception
	{
		public MethodBase Original { get; }

		public MethodInfo Patch { get; }

		public override string Message => "(" + Patch.FullDescription() + "): " + base.Message;

		public InvalidHarmonyPatchArgumentException(string message, MethodBase original, MethodInfo patch)
			: base(message)
		{
			Original = original;
			Patch = patch;
		}
	}
	public class MemberNotFoundException : Exception
	{
		public MemberNotFoundException(string message)
			: base(message)
		{
		}
	}
	public class Harmony : IDisposable
	{
		[Obsolete("Use HarmonyFileLog.Enabled instead")]
		public static bool DEBUG;

		public string Id { get; }

		static Harmony()
		{
			StackTraceFixes.Install();
		}

		public Harmony(string id)
		{
			if (string.IsNullOrEmpty(id))
			{
				throw new ArgumentException("id cannot be null or empty");
			}
			try
			{
				string environmentVariable = Environment.GetEnvironmentVariable("HARMONY_DEBUG");
				if (environmentVariable != null && environmentVariable.Length > 0)
				{
					environmentVariable = environmentVariable.Trim();
					DEBUG = environmentVariable == "1" || bool.Parse(environmentVariable);
				}
			}
			catch
			{
			}
			if (DEBUG)
			{
				HarmonyFileLog.Enabled = true;
			}
			MethodBase callingMethod = (Logger.IsEnabledFor(Logger.LogChannel.Info) ? AccessTools.GetOutsideCaller() : null);
			Logger.Log(Logger.LogChannel.Info, delegate
			{
				//IL_0070: Unknown result type (might be due to invalid IL or missing references)
				//IL_0075: Unknown result type (might be due to invalid IL or missing references)
				//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
				StringBuilder stringBuilder = new StringBuilder();
				Assembly assembly = typeof(Harmony).Assembly;
				Version version = assembly.GetName().Version;
				string text = assembly.Location;
				string text2 = Environment.Version.ToString();
				string text3 = Environment.OSVersion.Platform.ToString();
				if (string.IsNullOrEmpty(text))
				{
					text = new Uri(assembly.CodeBase).LocalPath;
				}
				int size = IntPtr.Size;
				Platform current = PlatformHelper.Current;
				stringBuilder.AppendLine($"### Harmony id={id}, version={version}, location={text}, env/clr={text2}, platform={text3}, ptrsize:runtime/env={size}/{current}");
				if ((object)callingMethod?.DeclaringType != null)
				{
					Assembly assembly2 = callingMethod.DeclaringType.Assembly;
					text = assembly2.Location;
					if (string.IsNullOrEmpty(text))
					{
						text = new Uri(assembly2.CodeBase).LocalPath;
					}
					stringBuilder.AppendLine("### Started from " + callingMethod.FullDescription() + ", location " + text);
					stringBuilder.Append($"### At {DateTime.Now:yyyy-MM-dd hh.mm.ss}");
				}
				return stringBuilder.ToString();
			});
			Id = id;
		}

		public void PatchAll()
		{
			Assembly assembly = new StackTrace().GetFrame(1).GetMethod().ReflectedType.Assembly;
			PatchAll(assembly);
		}

		public PatchProcessor CreateProcessor(MethodBase original)
		{
			return new PatchProcessor(this, original);
		}

		public PatchClassProcessor CreateClassProcessor(Type type)
		{
			return new PatchClassProcessor(this, type);
		}

		public PatchClassProcessor CreateClassProcessor(Type type, bool allowUnannotatedType)
		{
			return new PatchClassProcessor(this, type, allowUnannotatedType);
		}

		public ReversePatcher CreateReversePatcher(MethodBase original, HarmonyMethod standin)
		{
			return new ReversePatcher(this, original, standin);
		}

		public void PatchAll(Assembly assembly)
		{
			AccessTools.GetTypesFromAssembly(assembly).Do(delegate(Type type)
			{
				CreateClassProcessor(type).Patch();
			});
		}

		public void PatchAll(Type type)
		{
			CreateClassProcessor(type, allowUnannotatedType: true).Patch();
		}

		public MethodInfo Patch(MethodBase original, HarmonyMethod prefix = null, HarmonyMethod postfix = null, HarmonyMethod transpiler = null, HarmonyMethod finalizer = null, HarmonyMethod ilmanipulator = null)
		{
			PatchProcessor patchProcessor = CreateProcessor(original);
			patchProcessor.AddPrefix(prefix);
			patchProcessor.AddPostfix(postfix);
			patchProcessor.AddTranspiler(transpiler);
			patchProcessor.AddFinalizer(finalizer);
			patchProcessor.AddILManipulator(ilmanipulator);
			return patchProcessor.Patch();
		}

		[Obsolete("Use newer Patch() instead", true)]
		public MethodInfo Patch(MethodBase original, HarmonyMethod prefix, HarmonyMethod postfix, HarmonyMethod transpiler, HarmonyMethod finalizer)
		{
			return Patch(original, prefix, postfix, transpiler, finalizer, null);
		}

		public static MethodInfo ReversePatch(MethodBase original, HarmonyMethod standin, MethodInfo transpiler = null, MethodInfo ilmanipulator = null)
		{
			return PatchFunctions.ReversePatch(standin, original, transpiler, ilmanipulator);
		}

		[Obsolete("Use newer ReversePatch() instead", true)]
		public static MethodInfo ReversePatch(MethodBase original, HarmonyMethod standin, MethodInfo transpiler)
		{
			return PatchFunctions.ReversePatch(standin, original, transpiler, null);
		}

		public static void UnpatchID(string harmonyID)
		{
			if (string.IsNullOrEmpty(harmonyID))
			{
				throw new ArgumentNullException("harmonyID", "UnpatchID was called with a null or empty harmonyID.");
			}
			PatchFunctions.UnpatchConditional((Patch patchInfo) => patchInfo.owner == harmonyID);
		}

		void IDisposable.Dispose()
		{
			UnpatchSelf();
		}

		public void UnpatchSelf()
		{
			UnpatchID(Id);
		}

		public static void UnpatchAll()
		{
			Logger.Log(Logger.LogChannel.Warn, () => "UnpatchAll has been called - This will remove ALL HARMONY PATCHES.");
			PatchFunctions.UnpatchConditional((Patch _) => true);
		}

		[Obsolete("Use UnpatchSelf() to unpatch the current instance. The functionality to unpatch either other ids or EVERYTHING has been moved the static methods UnpatchID() and UnpatchAll() respectively", true)]
		public void UnpatchAll(string harmonyID = null)
		{
			if (harmonyID == null)
			{
				if (HarmonyGlobalSettings.DisallowLegacyGlobalUnpatchAll)
				{
					Logger.Log(Logger.LogChannel.Warn, () => "Legacy UnpatchAll has been called AND DisallowLegacyGlobalUnpatchAll=true. Skipping execution of UnpatchAll");
				}
				else
				{
					UnpatchAll();
				}
			}
			else if (harmonyID.Length == 0)
			{
				Logger.Log(Logger.LogChannel.Warn, () => "Legacy UnpatchAll was called with harmonyID=\"\" which is an invalid id. Skipping execution of UnpatchAll");
			}
			else
			{
				UnpatchID(harmonyID);
			}
		}

		public void Unpatch(MethodBase original, HarmonyPatchType type, string harmonyID = "*")
		{
			CreateProcessor(original).Unpatch(type, harmonyID);
		}

		public void Unpatch(MethodBase original, MethodInfo patch)
		{
			CreateProcessor(original).Unpatch(patch);
		}

		public static bool HasAnyPatches(string harmonyID)
		{
			return (from original in GetAllPatchedMethods()
				select GetPatchInfo(original)).Any((Patches info) => info.Owners.Contains(harmonyID));
		}

		public static Patches GetPatchInfo(MethodBase method)
		{
			return PatchProcessor.GetPatchInfo(method);
		}

		public IEnumerable<MethodBase> GetPatchedMethods()
		{
			return from original in GetAllPatchedMethods()
				where GetPatchInfo(original).Owners.Contains(Id)
				select original;
		}

		public static IEnumerable<MethodBase> GetAllPatchedMethods()
		{
			return PatchProcessor.GetAllPatchedMethods();
		}

		public static MethodBase GetOriginalMethod(MethodInfo replacement)
		{
			if (replacement == null)
			{
				throw new ArgumentNullException("replacement");
			}
			return PatchManager.GetOriginal(replacement);
		}

		public static MethodBase GetMethodFromStackframe(StackFrame frame)
		{
			if (frame == null)
			{
				throw new ArgumentNullException("frame");
			}
			return PatchManager.FindReplacement(frame) ?? frame.GetMethod();
		}

		public static MethodBase GetOriginalMethodFromStackframe(StackFrame frame)
		{
			MethodBase methodBase = GetMethodFromStackframe(frame);
			if (methodBase is MethodInfo replacement)
			{
				methodBase = GetOriginalMethod(replacement) ?? methodBase;
			}
			return methodBase;
		}

		public static Dictionary<string, Version> VersionInfo(out Version currentVersion)
		{
			return PatchProcessor.VersionInfo(out currentVersion);
		}

		public static Harmony CreateAndPatchAll(Type type, string harmonyInstanceId = null)
		{
			Harmony harmony = new Harmony(harmonyInstanceId ?? $"harmony-auto-{Guid.NewGuid()}");
			harmony.PatchAll(type);
			return harmony;
		}

		public static Harmony CreateAndPatchAll(Assembly assembly, string harmonyInstanceId = null)
		{
			Harmony harmony = new Harmony(harmonyInstanceId ?? $"harmony-auto-{Guid.NewGuid()}");
			harmony.PatchAll(assembly);
			return harmony;
		}
	}
	[Serializable]
	public class HarmonyException : Exception
	{
		private Dictionary<int, CodeInstruction> instructions = new Dictionary<int, CodeInstruction>();

		private int errorOffset = -1;

		internal HarmonyException()
		{
		}

		internal HarmonyException(string message)
			: base(message)
		{
		}

		internal HarmonyException(string message, Exception innerException)
			: base(message, innerException)
		{
		}

		protected HarmonyException(SerializationInfo serializationInfo, StreamingContext streamingContext)
		{
			throw new NotImplementedException();
		}

		internal HarmonyException(Exception innerException, Dictionary<int, CodeInstruction> instructions, int errorOffset)
			: base("IL Compile Error", innerException)
		{
			this.instructions = instructions;
			this.errorOffset = errorOffset;
		}

		internal static Exception Create(Exception ex, MethodBody body)
		{
			if (ex is HarmonyException ex2)
			{
				Dictionary<int, CodeInstruction> dictionary = ex2.instructions;
				if (dictionary != null && dictionary.Count > 0 && ex2.errorOffset >= 0)
				{
					return ex;
				}
			}
			Match match = Regex.Match(ex.Message.TrimEnd(Array.Empty<char>()), "(?:Reason: )?Invalid IL code in.+: IL_(\\d{4}): (.+)$");
			if (!match.Success)
			{
				return new HarmonyException("IL Compile Error (unknown location)", ex);
			}
			Dictionary<int, CodeInstruction> dictionary2 = ILManipulator.GetInstructions(body) ?? new Dictionary<int, CodeInstruction>();
			int num = int.Parse(match.Groups[1].Value, NumberStyles.HexNumber);
			Regex.Replace(match.Groups[2].Value, " {2,}", " ");
			if (ex is HarmonyException ex3)
			{
				if (dictionary2.Count != 0)
				{
					ex3.instructions = dictionary2;
					ex3.errorOffset = num;
				}
				return ex3;
			}
			return new HarmonyException(ex, dictionary2, num);
		}

		public List<KeyValuePair<int, CodeInstruction>> GetInstructionsWithOffsets()
		{
			return instructions.OrderBy((KeyValuePair<int, CodeInstruction> ins) => ins.Key).ToList();
		}

		public List<CodeInstruction> GetInstructions()
		{
			return (from ins in instructions
				orderby ins.Key
				select ins.Value).ToList();
		}

		public int GetErrorOffset()
		{
			return errorOffset;
		}

		public int GetErrorIndex()
		{
			if (instructions.TryGetValue(errorOffset, out var value))
			{
				return GetInstructions().IndexOf(value);
			}
			return -1;
		}
	}
	public static class HarmonyGlobalSettings
	{
		public static bool DisallowLegacyGlobalUnpatchAll { get; set; }
	}
	public class HarmonyMethod
	{
		public MethodInfo method;

		public Type declaringType;

		public string methodName;

		public MethodType? methodType;

		public Type[] argumentTypes;

		public int priority = -1;

		public string[] before;

		public string[] after;

		public HarmonyReversePatchType? reversePatchType;

		public bool? debug;

		public string debugEmitPath;

		public bool nonVirtualDelegate;

		public bool? wrapTryCatch;

		public HarmonyMethod()
		{
		}

		private void ImportMethod(MethodInfo theMethod)
		{
			if ((object)theMethod == null)
			{
				throw new ArgumentNullException("theMethod", "Harmony method is null (did you target a wrong or missing method?)");
			}
			if (!theMethod.IsStatic)
			{
				throw new ArgumentException("Harmony method must be static", "theMethod");
			}
			method = theMethod;
			List<HarmonyMethod> fromMethod = HarmonyMethodExtensions.GetFromMethod(method);
			if (fromMethod != null)
			{
				Merge(fromMethod).CopyTo(this);
			}
		}

		public HarmonyMethod(MethodInfo method)
		{
			if ((object)method == null)
			{
				throw new ArgumentNullException("method");
			}
			ImportMethod(method);
		}

		public HarmonyMethod(MethodInfo method, int priority = -1, string[] before = null, string[] after = null, bool? debug = null)
		{
			if ((object)method == null)
			{
				throw new ArgumentNullException("method");
			}
			ImportMethod(method);
			this.priority = priority;
			this.before = before;
			this.after = after;
			this.debug = debug;
		}

		public HarmonyMethod(Type methodType, string methodName, Type[] argumentTypes = null)
		{
			MethodInfo methodInfo = AccessTools.Method(methodType, methodName, argumentTypes);
			if ((object)methodInfo == null)
			{
				throw new ArgumentException($"Cannot not find method for type {methodType} and name {methodName} and parameters {argumentTypes?.Description()}");
			}
			ImportMethod(methodInfo);
		}

		public static List<string> HarmonyFields()
		{
			return (from s in AccessTools.GetFieldNames(typeof(HarmonyMethod))
				where s != "method"
				select s).ToList();
		}

		public static HarmonyMethod Merge(List<HarmonyMethod> attributes)
		{
			return Merge((IEnumerable<HarmonyMethod>)attributes);
		}

		internal static HarmonyMethod Merge(IEnumerable<HarmonyMethod> attributes)
		{
			HarmonyMethod harmonyMethod = new HarmonyMethod();
			if (attributes == null)
			{
				return harmonyMethod;
			}
			Traverse resultTrv = Traverse.Create(harmonyMethod);
			attributes.Do(delegate(HarmonyMethod attribute)
			{
				Traverse trv = Traverse.Create(attribute);
				HarmonyFields().ForEach(delegate(string f)
				{
					object value = trv.Field(f).GetValue();
					if (value != null && (f != "priority" || (int)value != -1))
					{
						HarmonyMethodExtensions.SetValue(resultTrv, f, value);
					}
				});
			});
			return harmonyMethod;
		}

		public override string ToString()
		{
			string result = "";
			Traverse trv = Traverse.Create(this);
			HarmonyFields().ForEach(delegate(string f)
			{
				if (result.Length > 0)
				{
					result += ", ";
				}
				result += $"{f}={trv.Field(f).GetValue()}";
			});
			return "HarmonyMethod[" + result + "]";
		}

		internal string Description()
		{
			string text = (((object)declaringType != null) ? declaringType.FullDescription() : "undefined");
			string text2 = methodName ?? "undefined";
			string text3 = (methodType.HasValue ? methodType.Value.ToString() : "undefined");
			string text4 = ((argumentTypes != null) ? argumentTypes.Description() : "undefined");
			return "(class=" + text + ", methodname=" + text2 + ", type=" + text3 + ", args=" + text4 + ")";
		}

		internal Type GetDeclaringType()
		{
			return declaringType;
		}

		internal Type[] GetArgumentList()
		{
			return argumentTypes ?? EmptyType.NoArgs;
		}
	}
	internal static class EmptyType
	{
		internal static readonly Type[] NoArgs = new Type[0];
	}
	public static class HarmonyMethodExtensions
	{
		internal static void SetValue(Traverse trv, string name, object val)
		{
			if (val != null)
			{
				Traverse traverse = trv.Field(name);
				if (name == "methodType" || name == "reversePatchType")
				{
					val = Enum.ToObject(Nullable.GetUnderlyingType(traverse.GetValueType()), (int)val);
				}
				traverse.SetValue(val);
			}
		}

		public static void CopyTo(this HarmonyMethod from, HarmonyMethod to)
		{
			if (to == null)
			{
				return;
			}
			Traverse fromTrv = Traverse.Create(from);
			Traverse toTrv = Traverse.Create(to);
			HarmonyMethod.HarmonyFields().ForEach(delegate(string f)
			{
				object value = fromTrv.Field(f).GetValue();
				if (value != null)
				{
					SetValue(toTrv, f, value);
				}
			});
		}

		public static HarmonyMethod Clone(this HarmonyMethod original)
		{
			HarmonyMethod harmonyMethod = new HarmonyMethod();
			original.CopyTo(harmonyMethod);
			return harmonyMethod;
		}

		public static HarmonyMethod Merge(this HarmonyMethod master, HarmonyMethod detail)
		{
			if (detail == null)
			{
				return master;
			}
			HarmonyMethod harmonyMethod = new HarmonyMethod();
			Traverse resultTrv = Traverse.Create(harmonyMethod);
			Traverse masterTrv = Traverse.Create(master);
			Traverse detailTrv = Traverse.Create(detail);
			HarmonyMethod.HarmonyFields().ForEach(delegate(string f)
			{
				object value = masterTrv.Field(f).GetValue();
				object value2 = detailTrv.Field(f).GetValue();
				if (f != "priority" || (int)value2 != -1)
				{
					SetValue(resultTrv, f, value2 ?? value);
				}
			});
			return harmonyMethod;
		}

		private static HarmonyMethod GetHarmonyMethodInfo(object attribute)
		{
			FieldInfo field = attribute.GetType().GetField("info", AccessTools.all);
			if ((object)field == null)
			{
				return null;
			}
			if (field.FieldType.FullName != typeof(HarmonyMethod).FullName)
			{
				return null;
			}
			return AccessTools.MakeDeepCopy<HarmonyMethod>(field.GetValue(attribute));
		}

		public static List<HarmonyMethod> GetFromType(Type type)
		{
			return (from attr in type.GetCustomAttributes(inherit: true)
				select GetHarmonyMethodInfo(attr) into info
				where info != null
				select info).ToList();
		}

		public static HarmonyMethod GetMergedFromType(Type type)
		{
			return HarmonyMethod.Merge(GetFromType(type));
		}

		public static List<HarmonyMethod> GetFromMethod(MethodBase method)
		{
			return (from attr in method.GetCustomAttributes(inherit: true)
				select GetHarmonyMethodInfo(attr) into info
				where info != null
				select info).ToList();
		}

		public static HarmonyMethod GetMergedFromMethod(MethodBase method)
		{
			return HarmonyMethod.Merge(GetFromMethod(method));
		}
	}
	public class InlineSignature : ICallSiteGenerator
	{
		public class ModifierType
		{
			public bool IsOptional;

			public Type Modifier;

			public object Type;

			public override string ToString()
			{
				return ((Type is Type type) ? type.FullDescription() : Type?.ToString()) + " mod" + (IsOptional ? "opt" : "req") + "(" + Modifier?.FullDescription() + ")";
			}

			internal TypeReference ToTypeReference(ModuleDefinition module)
			{
				//IL_003e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0044: Expected O, but got Unknown
				//IL_0020: Unknown result type (might be due to invalid IL or missing references)
				//IL_0026: Expected O, but got Unknown
				if (!IsOptional)
				{
					return (TypeReference)new RequiredModifierType(module.ImportReference(Modifier), GetTypeReference(module, Type));
				}
				return (TypeReference)new OptionalModifierType(module.ImportReference(Modifier), GetTypeReference(module, Type));
			}
		}

		public bool HasThis { get; set; }

		public bool ExplicitThis { get; set; }

		public CallingConvention CallingConvention { get; set; } = CallingConvention.Winapi;


		public List<object> Parameters { get; set; } = new List<object>();


		public object ReturnType { get; set; } = typeof(void);


		public override string ToString()
		{
			return ((ReturnType is Type type) ? type.FullDescription() : ReturnType?.ToString()) + " (" + Parameters.Join((object p) => (!(p is Type type2)) ? p?.ToString() : type2.FullDescription()) + ")";
		}

		internal static TypeReference GetTypeReference(ModuleDefinition module, object param)
		{
			if (!(param is Type type))
			{
				if (!(param is InlineSignature inlineSignature))
				{
					if (param is ModifierType modifierType)
					{
						return modifierType.ToTypeReference(module);
					}
					throw new NotSupportedException($"Unsupported inline signature parameter type: {param} ({param?.GetType().FullDescription()})");
				}
				return (TypeReference)(object)inlineSignature.ToFunctionPointer(module);
			}
			return module.ImportReference(type);
		}

		CallSite ICallSiteGenerator.ToCallSite(ModuleDefinition module)
		{
			//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_001d: 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_003a: Expected O, but got Unknown
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Expected O, but got Unknown
			CallSite val = new CallSite(GetTypeReference(module, ReturnType))
			{
				HasThis = HasThis,
				ExplicitThis = ExplicitThis,
				CallingConvention = (MethodCallingConvention)(byte)((byte)CallingConvention - 1)
			};
			foreach (object parameter in Parameters)
			{
				val.Parameters.Add(new ParameterDefinition(GetTypeReference(module, parameter)));
			}
			return val;
		}

		private FunctionPointerType ToFunctionPointer(ModuleDefinition module)
		{
			//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_0017: 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_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Expected O, but got Unknown
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Expected O, but got Unknown
			FunctionPointerType val = new FunctionPointerType
			{
				ReturnType = GetTypeReference(module, ReturnType),
				HasThis = HasThis,
				ExplicitThis = ExplicitThis,
				CallingConvention = (MethodCallingConvention)(byte)((byte)CallingConvention - 1)
			};
			foreach (object parameter in Parameters)
			{
				val.Parameters.Add(new ParameterDefinition(GetTypeReference(module, parameter)));
			}
			return val;
		}
	}
	internal static class PatchInfoSerialization
	{
		private class Binder : SerializationBinder
		{
			public override Type BindToType(string assemblyName, string typeName)
			{
				Type[] array = new Type[3]
				{
					typeof(PatchInfo),
					typeof(Patch[]),
					typeof(Patch)
				};
				foreach (Type type in array)
				{
					if (typeName == type.FullName)
					{
						return type;
					}
				}
				return Type.GetType($"{typeName}, {assemblyName}");
			}
		}

		internal static byte[] Serialize(this PatchInfo patchInfo)
		{
			using MemoryStream memoryStream = new MemoryStream();
			new BinaryFormatter().Serialize(memoryStream, patchInfo);
			return memoryStream.GetBuffer();
		}

		internal static PatchInfo Deserialize(byte[] bytes)
		{
			BinaryFormatter obj = new BinaryFormatter
			{
				Binder = new Binder()
			};
			MemoryStream serializationStream = new MemoryStream(bytes);
			return (PatchInfo)obj.Deserialize(serializationStream);
		}

		internal static int PriorityComparer(object obj, int index, int priority)
		{
			Traverse traverse = Traverse.Create(obj);
			int value = traverse.Field("priority").GetValue<int>();
			int value2 = traverse.Field("index").GetValue<int>();
			if (priority != value)
			{
				return -priority.CompareTo(value);
			}
			return index.CompareTo(value2);
		}
	}
	[Serializable]
	public class PatchInfo
	{
		public Patch[] prefixes = new Patch[0];

		public Patch[] postfixes = new Patch[0];

		public Patch[] transpilers = new Patch[0];

		public Patch[] finalizers = new Patch[0];

		public Patch[] ilmanipulators = new Patch[0];

		public bool Debugging
		{
			get
			{
				if (!prefixes.Any((Patch p) => p.debug) && !postfixes.Any((Patch p) => p.debug) && !transpilers.Any((Patch p) => p.debug) && !finalizers.Any((Patch p) => p.debug))
				{
					return ilmanipulators.Any((Patch p) => p.debug);
				}
				return true;
			}
		}

		public string[] DebugEmitPaths => (from p in prefixes.Concat(postfixes).Concat(transpilers).Concat(finalizers)
				.Concat(ilmanipulators)
			select p.debugEmitPath into p
			where p != null
			select p).ToArray();

		internal void AddPrefixes(string owner, params HarmonyMethod[] methods)
		{
			prefixes = Add(owner, methods, prefixes);
		}

		[Obsolete("This method only exists for backwards compatibility since the class is public.")]
		public void AddPrefix(MethodInfo patch, string owner, int priority, string[] before, string[] after, bool debug)
		{
			AddPrefixes(owner, new HarmonyMethod(patch, priority, before, after, debug));
		}

		public void RemovePrefix(string owner)
		{
			prefixes = Remove(owner, prefixes);
		}

		internal void AddPostfixes(string owner, params HarmonyMethod[] methods)
		{
			postfixes = Add(owner, methods, postfixes);
		}

		[Obsolete("This method only exists for backwards compatibility since the class is public.")]
		public void AddPostfix(MethodInfo patch, string owner, int priority, string[] before, string[] after, bool debug)
		{
			AddPostfixes(owner, new HarmonyMethod(patch, priority, before, after, debug));
		}

		public void RemovePostfix(string owner)
		{
			postfixes = Remove(owner, postfixes);
		}

		internal void AddTranspilers(string owner, params HarmonyMethod[] methods)
		{
			transpilers = Add(owner, methods, transpilers);
		}

		[Obsolete("This method only exists for backwards compatibility since the class is public.")]
		public void AddTranspiler(MethodInfo patch, string owner, int priority, string[] before, string[] after, bool debug)
		{
			AddTranspilers(owner, new HarmonyMethod(patch, priority, before, after, debug));
		}

		public void RemoveTranspiler(string owner)
		{
			transpilers = Remove(owner, transpilers);
		}

		internal void AddFinalizers(string owner, params HarmonyMethod[] methods)
		{
			finalizers = Add(owner, methods, finalizers);
		}

		[Obsolete("This method only exists for backwards compatibility since the class is public.")]
		public void AddFinalizer(MethodInfo patch, string owner, int priority, string[] before, string[] after, bool debug)
		{
			AddFinalizers(owner, new HarmonyMethod(patch, priority, before, after, debug));
		}

		public void RemoveFinalizer(string owner)
		{
			finalizers = Remove(owner, finalizers);
		}

		internal void AddILManipulators(string owner, params HarmonyMethod[] methods)
		{
			ilmanipulators = Add(owner, methods, ilmanipulators);
		}

		public void RemoveILManipulator(string owner)
		{
			ilmanipulators = Remove(owner, ilmanipulators);
		}

		public void RemovePatch(MethodInfo patch)
		{
			prefixes = prefixes.Where((Patch p) => p.PatchMethod != patch).ToArray();
			postfixes = postfixes.Where((Patch p) => p.PatchMethod != patch).ToArray();
			transpilers = transpilers.Where((Patch p) => p.PatchMethod != patch).ToArray();
			finalizers = finalizers.Where((Patch p) => p.PatchMethod != patch).ToArray();
			ilmanipulators = ilmanipulators.Where((Patch p) => p.PatchMethod != patch).ToArray();
		}

		private static Patch[] Add(string owner, HarmonyMethod[] add, Patch[] current)
		{
			if (add.Length == 0)
			{
				return current;
			}
			int initialIndex = current.Length;
			return current.Concat(add.Where((HarmonyMethod method) => method != null).Select((HarmonyMethod method, int i) => new Patch(method, i + initialIndex, owner))).ToArray();
		}

		private static Patch[] Remove(string owner, Patch[] current)
		{
			if (!(owner == "*"))
			{
				return current.Where((Patch patch) => patch.owner != owner).ToArray();
			}
			return new Patch[0];
		}
	}
	[Serializable]
	public class Patch : IComparable
	{
		public readonly int index;

		public readonly string owner;

		public readonly int priority;

		public readonly string[] before;

		public readonly string[] after;

		public readonly bool debug;

		public readonly string debugEmitPath;

		public readonly bool wrapTryCatch;

		[NonSerialized]
		private MethodInfo patchMethod;

		private int methodToken;

		private string moduleGUID;

		public MethodInfo PatchMethod
		{
			get
			{
				if ((object)patchMethod == null)
				{
					Module module = (from a in AppDomain.CurrentDomain.GetAssemblies()
						where !a.FullName.StartsWith("Microsoft.VisualStudio")
						select a).SelectMany((Assembly a) => a.GetLoadedModules()).First((Module m) => m.ModuleVersionId.ToString() == moduleGUID);
					patchMethod = (MethodInfo)module.ResolveMethod(methodToken);
				}
				return patchMethod;
			}
			set
			{
				patchMethod = value;
				methodToken = patchMethod.MetadataToken;
				moduleGUID = patchMethod.Module.ModuleVersionId.ToString();
			}
		}

		public Patch(MethodInfo patch, int index, string owner, int priority, string[] before, string[] after, bool debug)
		{
			if (patch is DynamicMethod)
			{
				throw new Exception("Cannot directly reference dynamic method \"" + patch.FullDescription() + "\" in Harmony. Use a factory method instead that will return the dynamic method.");
			}
			this.index = index;
			this.owner = owner;
			this.priority = ((priority == -1) ? 400 : priority);
			this.before = before ?? new string[0];
			this.after = after ?? new string[0];
			this.debug = debug;
			PatchMethod = patch;
		}

		public Patch(MethodInfo patch, int index, string owner, int priority, string[] before, string[] after, bool debug, bool wrapTryCatch)
		{
			if (patch is DynamicMethod)
			{
				throw new Exception("Cannot directly reference dynamic method \"" + patch.FullDescription() + "\" in Harmony. Use a factory method instead that will return the dynamic method.");
			}
			this.index = index;
			this.owner = owner;
			this.priority = ((priority == -1) ? 400 : priority);
			this.before = before ?? new string[0];
			this.after = after ?? new string[0];
			this.debug = debug;
			this.wrapTryCatch = wrapTryCatch;
			PatchMethod = patch;
		}

		public Patch(MethodInfo patch, int index, string owner, int priority, string[] before, string[] after, bool debug, bool wrapTryCatch, string debugEmitPath)
		{
			if (patch is DynamicMethod)
			{
				throw new Exception("Cannot directly reference dynamic method \"" + patch.FullDescription() + "\" in Harmony. Use a factory method instead that will return the dynamic method.");
			}
			this.index = index;
			this.owner = owner;
			this.priority = ((priority == -1) ? 400 : priority);
			this.before = before ?? new string[0];
			this.after = after ?? new string[0];
			this.debug = debug;
			this.debugEmitPath = debugEmitPath;
			this.wrapTryCatch = wrapTryCatch;
			PatchMethod = patch;
		}

		public Patch(HarmonyMethod method, int index, string owner)
			: this(method.method, index, owner, method.priority, method.before, method.after, method.debug.GetValueOrDefault(), method.wrapTryCatch.GetValueOrDefault(), method.debugEmitPath)
		{
		}

		public MethodInfo GetMethod(MethodBase original)
		{
			MethodInfo methodInfo = PatchMethod;
			if (methodInfo.ReturnType != typeof(DynamicMethod) && methodInfo.ReturnType != typeof(MethodInfo))
			{
				return methodInfo;
			}
			if (!methodInfo.IsStatic)
			{
				return methodInfo;
			}
			ParameterInfo[] parameters = methodInfo.GetParameters();
			if (parameters.Length != 1)
			{
				return methodInfo;
			}
			if (parameters[0].ParameterType != typeof(MethodBase))
			{
				return methodInfo;
			}
			return methodInfo.Invoke(null, new object[1] { original }) as MethodInfo;
		}

		public override bool Equals(object obj)
		{
			if (obj != null && obj is Patch)
			{
				return PatchMethod == ((Patch)obj).PatchMethod;
			}
			return false;
		}

		public int CompareTo(object obj)
		{
			return PatchInfoSerialization.PriorityComparer(obj, index, priority);
		}

		public override int GetHashCode()
		{
			return PatchMethod.GetHashCode();
		}
	}
	public class PatchClassProcessor
	{
		private readonly Harmony instance;

		private readonly Type containerType;

		private readonly HarmonyMethod containerAttributes;

		private readonly Dictionary<Type, MethodInfo> auxilaryMethods;

		private readonly List<AttributePatch> patchMethods;

		private static readonly List<Type> auxilaryTypes = new List<Type>
		{
			typeof(HarmonyPrepare),
			typeof(HarmonyCleanup),
			typeof(HarmonyTargetMethod),
			typeof(HarmonyTargetMethods)
		};

		public PatchClassProcessor(Harmony instance, Type type)
			: this(instance, type, allowUnannotatedType: false)
		{
		}

		public PatchClassProcessor(Harmony instance, Type type, bool allowUnannotatedType)
		{
			if (instance == null)
			{
				throw new ArgumentNullException("instance");
			}
			if ((object)type == null)
			{
				throw new ArgumentNullException("type");
			}
			this.instance = instance;
			containerType = type;
			List<HarmonyMethod> fromType = HarmonyMethodExtensions.GetFromType(type);
			if (!allowUnannotatedType && (fromType == null || fromType.Count == 0))
			{
				return;
			}
			containerAttributes = HarmonyMethod.Merge(fromType);
			MethodType? methodType = containerAttributes.methodType;
			if (!methodType.HasValue)
			{
				containerAttributes.methodType = MethodType.Normal;
			}
			auxilaryMethods = new Dictionary<Type, MethodInfo>();
			foreach (Type auxilaryType in auxilaryTypes)
			{
				MethodInfo patchMethod = PatchTools.GetPatchMethod(containerType, auxilaryType.FullName);
				if ((object)patchMethod != null)
				{
					auxilaryMethods[auxilaryType] = patchMethod;
				}
			}
			patchMethods = PatchTools.GetPatchMethods(containerType, containerAttributes.GetDeclaringType() != null);
			foreach (AttributePatch patchMethod2 in patchMethods)
			{
				MethodInfo method = patchMethod2.info.method;
				patchMethod2.info = containerAttributes.Merge(patchMethod2.info);
				patchMethod2.info.method = method;
			}
		}

		public List<MethodInfo> Patch()
		{
			if (containerAttributes == null)
			{
				return null;
			}
			Exception exception = null;
			if (!RunMethod<HarmonyPrepare, bool>(defaultIfNotExisting: true, defaultIfFailing: false, null, Array.Empty<object>()))
			{
				RunMethod<HarmonyCleanup>(ref exception, Array.Empty<object>());
				ReportException(exception, null);
				return new List<MethodInfo>();
			}
			List<MethodInfo> result = new List<MethodInfo>();
			MethodBase lastOriginal = null;
			try
			{
				List<MethodBase> bulkMethods = GetBulkMethods();
				if (bulkMethods.Count == 1)
				{
					lastOriginal = bulkMethods[0];
				}
				ReversePatch(ref lastOriginal);
				result = ((bulkMethods.Count > 0) ? BulkPatch(bulkMethods, ref lastOriginal) : PatchWithAttributes(ref lastOriginal));
			}
			catch (Exception ex)
			{
				exception = ex;
			}
			RunMethod<HarmonyCleanup>(ref exception, new object[1] { exception });
			ReportException(exception, lastOriginal);
			return result;
		}

		private void ReversePatch(ref MethodBase lastOriginal)
		{
			for (int i = 0; i < patchMethods.Count; i++)
			{
				AttributePatch attributePatch = patchMethods[i];
				if (attributePatch.type == HarmonyPatchType.ReversePatch)
				{
					MethodBase originalMethod = attributePatch.info.GetOriginalMethod();
					if ((object)originalMethod != null)
					{
						lastOriginal = originalMethod;
					}
					ReversePatcher reversePatcher = instance.CreateReversePatcher(lastOriginal, attributePatch.info);
					lock (PatchProcessor.locker)
					{
						reversePatcher.Patch();
					}
				}
			}
		}

		private List<MethodInfo> BulkPatch(List<MethodBase> originals, ref MethodBase lastOriginal)
		{
			PatchJobs<MethodInfo> patchJobs = new PatchJobs<MethodInfo>();
			for (int i = 0; i < originals.Count; i++)
			{
				lastOriginal = originals[i];
				PatchJobs<MethodInfo>.Job job = patchJobs.GetJob(lastOriginal);
				foreach (AttributePatch patchMethod in patchMethods)
				{
					string text = "You cannot combine TargetMethod, TargetMethods or [HarmonyPatchAll] with individual annotations";
					HarmonyMethod info = patchMethod.info;
					if (info.methodName != null)
					{
						throw new ArgumentException(text + " [" + info.methodName + "]");
					}
					if (info.methodType.HasValue && info.methodType.Value != 0)
					{
						throw new ArgumentException($"{text} [{info.methodType}]");
					}
					if (info.argumentTypes != null)
					{
						throw new ArgumentException(text + " [" + info.argumentTypes.Description() + "]");
					}
					job.AddPatch(patchMethod);
				}
			}
			foreach (PatchJobs<MethodInfo>.Job job2 in patchJobs.GetJobs())
			{
				lastOriginal = job2.original;
				ProcessPatchJob(job2);
			}
			return patchJobs.GetReplacements();
		}

		private List<MethodInfo> PatchWithAttributes(ref MethodBase lastOriginal)
		{
			PatchJobs<MethodInfo> patchJobs = new PatchJobs<MethodInfo>();
			foreach (AttributePatch patchMethod in patchMethods)
			{
				lastOriginal = patchMethod.info.GetOriginalMethod();
				if ((object)lastOriginal == null)
				{
					throw new ArgumentException("Undefined targ

BepInExPack/BepInEx/core/BepInEx.Core.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.ConsoleUtil;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Shared;
using BepInEx.Unix;
using HarmonyLib;
using HarmonyLib.Tools;
using Microsoft.Win32.SafeHandles;
using Mono.Cecil;
using Mono.Collections.Generic;
using MonoMod.Utils;
using SemanticVersioning;
using UnityInjector.ConsoleUtil;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: InternalsVisibleTo("BepInEx.Preloader.Core")]
[assembly: InternalsVisibleTo("BepInEx.Unity")]
[assembly: InternalsVisibleTo("BepInEx.NetLauncher")]
[assembly: InternalsVisibleTo("BepInEx.NetCore")]
[assembly: InternalsVisibleTo("BepInEx.IL2CPP")]
[assembly: InternalsVisibleTo("BepInExTests")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = "")]
[assembly: BuildInfo("BLEEDING EDGE Build #577 from ec79ad057b20c302c17b34e63906ee398352d852 at master")]
[assembly: AssemblyCompany("BepInEx")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyCopyright("Copyright © 2021 BepInEx Team")]
[assembly: AssemblyDescription("Unity plugin injection framework")]
[assembly: AssemblyFileVersion("6.0.0.577")]
[assembly: AssemblyInformationalVersion("6.0.0-be.577")]
[assembly: AssemblyProduct("BepInEx")]
[assembly: AssemblyTitle("BepInEx")]
[assembly: AssemblyVersion("6.0.0.577")]
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false)]
	internal sealed class InterpolatedStringHandlerAttribute : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Parameter)]
	internal sealed class InterpolatedStringHandlerArgumentAttribute : Attribute
	{
		public string[] Arguments { get; }

		public InterpolatedStringHandlerArgumentAttribute(string argument)
		{
			Arguments = new string[1] { argument };
		}

		public InterpolatedStringHandlerArgumentAttribute(params string[] arguments)
		{
			Arguments = arguments;
		}
	}
}
namespace UnityInjector.ConsoleUtil
{
	internal static class SafeConsole
	{
		private delegate ConsoleColor GetColorDelegate();

		private delegate void SetColorDelegate(ConsoleColor value);

		private delegate string GetStringDelegate();

		private delegate void SetStringDelegate(string value);

		private static GetColorDelegate _getBackgroundColor;

		private static SetColorDelegate _setBackgroundColor;

		private static GetColorDelegate _getForegroundColor;

		private static SetColorDelegate _setForegroundColor;

		private static GetStringDelegate _getTitle;

		private static SetStringDelegate _setTitle;

		public static bool BackgroundColorExists { get; private set; }

		public static ConsoleColor BackgroundColor
		{
			get
			{
				return _getBackgroundColor();
			}
			set
			{
				_setBackgroundColor(value);
			}
		}

		public static bool ForegroundColorExists { get; private set; }

		public static ConsoleColor ForegroundColor
		{
			get
			{
				return _getForegroundColor();
			}
			set
			{
				_setForegroundColor(value);
			}
		}

		public static bool TitleExists { get; private set; }

		public static string Title
		{
			get
			{
				return _getTitle();
			}
			set
			{
				_setTitle(value);
			}
		}

		static SafeConsole()
		{
			InitColors(typeof(Console));
		}

		private static void InitColors(Type tConsole)
		{
			MethodInfo method = tConsole.GetMethod("get_ForegroundColor", BindingFlags.Static | BindingFlags.Public);
			MethodInfo method2 = tConsole.GetMethod("set_ForegroundColor", BindingFlags.Static | BindingFlags.Public);
			MethodInfo method3 = tConsole.GetMethod("get_BackgroundColor", BindingFlags.Static | BindingFlags.Public);
			MethodInfo method4 = tConsole.GetMethod("set_BackgroundColor", BindingFlags.Static | BindingFlags.Public);
			MethodInfo method5 = tConsole.GetMethod("get_Title", BindingFlags.Static | BindingFlags.Public);
			MethodInfo method6 = tConsole.GetMethod("set_Title", BindingFlags.Static | BindingFlags.Public);
			_setForegroundColor = ((method2 != null) ? ((SetColorDelegate)Delegate.CreateDelegate(typeof(SetColorDelegate), method2)) : ((SetColorDelegate)delegate
			{
			}));
			_setBackgroundColor = ((method4 != null) ? ((SetColorDelegate)Delegate.CreateDelegate(typeof(SetColorDelegate), method4)) : ((SetColorDelegate)delegate
			{
			}));
			_getForegroundColor = ((method != null) ? ((GetColorDelegate)Delegate.CreateDelegate(typeof(GetColorDelegate), method)) : ((GetColorDelegate)(() => ConsoleColor.Gray)));
			_getBackgroundColor = ((method3 != null) ? ((GetColorDelegate)Delegate.CreateDelegate(typeof(GetColorDelegate), method3)) : ((GetColorDelegate)(() => ConsoleColor.Black)));
			_getTitle = ((method5 != null) ? ((GetStringDelegate)Delegate.CreateDelegate(typeof(GetStringDelegate), method5)) : ((GetStringDelegate)(() => string.Empty)));
			_setTitle = ((method6 != null) ? ((SetStringDelegate)Delegate.CreateDelegate(typeof(SetStringDelegate), method6)) : ((SetStringDelegate)delegate
			{
			}));
			BackgroundColorExists = _setBackgroundColor != null && _getBackgroundColor != null;
			ForegroundColorExists = _setForegroundColor != null && _getForegroundColor != null;
			TitleExists = _setTitle != null && _getTitle != null;
		}
	}
	internal class ConsoleEncoding : Encoding
	{
		private readonly byte[] _zeroByte = new byte[0];

		private readonly char[] _zeroChar = new char[0];

		private byte[] _byteBuffer = new byte[256];

		private char[] _charBuffer = new char[256];

		private readonly uint _codePage;

		public override int CodePage => (int)_codePage;

		public static Encoding OutputEncoding => new ConsoleEncoding(ConsoleCodePage);

		public static uint ConsoleCodePage
		{
			get
			{
				return GetConsoleOutputCP();
			}
			set
			{
				SetConsoleOutputCP(value);
			}
		}

		private void ExpandByteBuffer(int count)
		{
			if (_byteBuffer.Length < count)
			{
				_byteBuffer = new byte[count];
			}
		}

		private void ExpandCharBuffer(int count)
		{
			if (_charBuffer.Length < count)
			{
				_charBuffer = new char[count];
			}
		}

		private void ReadByteBuffer(byte[] bytes, int index, int count)
		{
			for (int i = 0; i < count; i++)
			{
				bytes[index + i] = _byteBuffer[i];
			}
		}

		private void ReadCharBuffer(char[] chars, int index, int count)
		{
			for (int i = 0; i < count; i++)
			{
				chars[index + i] = _charBuffer[i];
			}
		}

		private void WriteByteBuffer(byte[] bytes, int index, int count)
		{
			ExpandByteBuffer(count);
			for (int i = 0; i < count; i++)
			{
				_byteBuffer[i] = bytes[index + i];
			}
		}

		private void WriteCharBuffer(char[] chars, int index, int count)
		{
			ExpandCharBuffer(count);
			for (int i = 0; i < count; i++)
			{
				_charBuffer[i] = chars[index + i];
			}
		}

		private ConsoleEncoding(uint codePage)
		{
			_codePage = codePage;
		}

		public static uint GetActiveCodePage()
		{
			return GetACP();
		}

		public static ConsoleEncoding GetEncoding(uint codePage)
		{
			return new ConsoleEncoding(codePage);
		}

		public override int GetByteCount(char[] chars, int index, int count)
		{
			WriteCharBuffer(chars, index, count);
			return WideCharToMultiByte(_codePage, 0u, chars, count, _zeroByte, 0, IntPtr.Zero, IntPtr.Zero);
		}

		public override int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex)
		{
			int byteCount = GetByteCount(chars, charIndex, charCount);
			WriteCharBuffer(chars, charIndex, charCount);
			ExpandByteBuffer(byteCount);
			WideCharToMultiByte(_codePage, 0u, chars, charCount, _byteBuffer, byteCount, IntPtr.Zero, IntPtr.Zero);
			int num = Math.Min(bytes.Length, byteCount);
			ReadByteBuffer(bytes, byteIndex, num);
			return num;
		}

		public override int GetCharCount(byte[] bytes, int index, int count)
		{
			WriteByteBuffer(bytes, index, count);
			return MultiByteToWideChar(_codePage, 0u, bytes, count, _zeroChar, 0);
		}

		public override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex)
		{
			int charCount = GetCharCount(bytes, byteIndex, byteCount);
			WriteByteBuffer(bytes, byteIndex, byteCount);
			ExpandCharBuffer(charCount);
			MultiByteToWideChar(_codePage, 0u, bytes, byteCount, _charBuffer, charCount);
			int num = Math.Min(chars.Length, charCount);
			ReadCharBuffer(chars, charIndex, num);
			return num;
		}

		public override int GetMaxByteCount(int charCount)
		{
			return charCount * 4;
		}

		public override int GetMaxCharCount(int byteCount)
		{
			return byteCount;
		}

		[DllImport("kernel32.dll")]
		private static extern uint GetConsoleOutputCP();

		[DllImport("kernel32.dll")]
		private static extern uint GetACP();

		[DllImport("kernel32.dll", SetLastError = true)]
		private static extern int MultiByteToWideChar(uint codePage, uint dwFlags, [In][MarshalAs(UnmanagedType.LPArray)] byte[] lpMultiByteStr, int cbMultiByte, [Out][MarshalAs(UnmanagedType.LPWStr)] char[] lpWideCharStr, int cchWideChar);

		[DllImport("kernel32.dll")]
		private static extern IntPtr SetConsoleOutputCP(uint codepage);

		[DllImport("kernel32.dll", SetLastError = true)]
		private static extern int WideCharToMultiByte(uint codePage, uint dwFlags, [In][MarshalAs(UnmanagedType.LPWStr)] char[] lpWideCharStr, int cchWideChar, [Out][MarshalAs(UnmanagedType.LPArray)] byte[] lpMultiByteStr, int cbMultiByte, IntPtr lpDefaultChar, IntPtr lpUsedDefaultChar);
	}
	internal class ConsoleWindow
	{
		[UnmanagedFunctionPointer(CallingConvention.Winapi)]
		[return: MarshalAs(UnmanagedType.Bool)]
		private delegate bool SetForegroundWindowDelegate(IntPtr hWnd);

		[UnmanagedFunctionPointer(CallingConvention.Winapi)]
		private delegate IntPtr GetForegroundWindowDelegate();

		[UnmanagedFunctionPointer(CallingConvention.Winapi)]
		private delegate IntPtr GetSystemMenuDelegate(IntPtr hwnd, bool bRevert);

		[UnmanagedFunctionPointer(CallingConvention.Winapi)]
		private delegate bool DeleteMenuDelegate(IntPtr hMenu, uint uPosition, uint uFlags);

		private const uint SC_CLOSE = 61536u;

		private const uint MF_BYCOMMAND = 0u;

		private const uint LOAD_LIBRARY_SEARCH_SYSTEM32 = 2048u;

		public static IntPtr ConsoleOutHandle;

		public static IntPtr OriginalStdoutHandle;

		private static bool methodsInited;

		private static SetForegroundWindowDelegate setForeground;

		private static GetForegroundWindowDelegate getForeground;

		private static GetSystemMenuDelegate getSystemMenu;

		private static DeleteMenuDelegate deleteMenu;

		public static bool IsAttached { get; private set; }

		public static string Title
		{
			set
			{
				if (IsAttached)
				{
					if (value == null)
					{
						throw new ArgumentNullException("value");
					}
					if (value.Length > 24500)
					{
						throw new InvalidOperationException("Console title too long");
					}
					if (!SetConsoleTitle(value))
					{
						throw new InvalidOperationException("Console title invalid");
					}
				}
			}
		}

		public static void Attach()
		{
			if (!IsAttached)
			{
				Initialize();
				if (OriginalStdoutHandle == IntPtr.Zero)
				{
					OriginalStdoutHandle = GetStdHandle(-11);
				}
				IntPtr hWnd = getForeground();
				GetConsoleWindow();
				if (GetConsoleWindow() == IntPtr.Zero && !AllocConsole())
				{
					throw new Exception("AllocConsole() failed");
				}
				setForeground(hWnd);
				ConsoleOutHandle = CreateFile("CONOUT$", 3221225472u, 2, IntPtr.Zero, 3, 0, IntPtr.Zero);
				Kon.conOut = ConsoleOutHandle;
				if (!SetStdHandle(-11, ConsoleOutHandle))
				{
					throw new Exception("SetStdHandle() failed");
				}
				if (OriginalStdoutHandle != IntPtr.Zero && ConsoleManager.ConfigConsoleOutRedirectType.Value == ConsoleManager.ConsoleOutRedirectType.ConsoleOut)
				{
					CloseHandle(OriginalStdoutHandle);
				}
				IsAttached = true;
			}
		}

		public static void PreventClose()
		{
			if (IsAttached)
			{
				Initialize();
				IntPtr consoleWindow = GetConsoleWindow();
				IntPtr intPtr = getSystemMenu(consoleWindow, bRevert: false);
				if (intPtr != IntPtr.Zero)
				{
					deleteMenu(intPtr, 61536u, 0u);
				}
			}
		}

		public static void Detach()
		{
			if (IsAttached)
			{
				if (!CloseHandle(ConsoleOutHandle))
				{
					throw new Exception("CloseHandle() failed");
				}
				ConsoleOutHandle = IntPtr.Zero;
				if (!FreeConsole())
				{
					throw new Exception("FreeConsole() failed");
				}
				if (!SetStdHandle(-11, OriginalStdoutHandle))
				{
					throw new Exception("SetStdHandle() failed");
				}
				IsAttached = false;
			}
		}

		private static void Initialize()
		{
			if (!methodsInited)
			{
				methodsInited = true;
				IntPtr hModule = LoadLibraryEx("user32.dll", IntPtr.Zero, 2048u);
				setForeground = DynDll.AsDelegate<SetForegroundWindowDelegate>(GetProcAddress(hModule, "SetForegroundWindow"));
				getForeground = DynDll.AsDelegate<GetForegroundWindowDelegate>(GetProcAddress(hModule, "GetForegroundWindow"));
				getSystemMenu = DynDll.AsDelegate<GetSystemMenuDelegate>(GetProcAddress(hModule, "GetSystemMenu"));
				deleteMenu = DynDll.AsDelegate<DeleteMenuDelegate>(GetProcAddress(hModule, "DeleteMenu"));
			}
		}

		[DllImport("kernel32.dll", SetLastError = true)]
		private static extern IntPtr GetProcAddress(IntPtr hModule, string procName);

		[DllImport("kernel32.dll", SetLastError = true)]
		private static extern bool AllocConsole();

		[DllImport("kernel32.dll")]
		private static extern IntPtr GetConsoleWindow();

		[DllImport("kernel32.dll", ExactSpelling = true, SetLastError = true)]
		private static extern bool CloseHandle(IntPtr handle);

		[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
		private static extern IntPtr CreateFile(string fileName, uint desiredAccess, int shareMode, IntPtr securityAttributes, int creationDisposition, int flagsAndAttributes, IntPtr templateFile);

		[DllImport("kernel32.dll")]
		private static extern bool FreeConsole();

		[DllImport("kernel32.dll", SetLastError = true)]
		private static extern IntPtr GetStdHandle(int nStdHandle);

		[DllImport("kernel32.dll", SetLastError = true)]
		private static extern bool SetStdHandle(int nStdHandle, IntPtr hConsoleOutput);

		[DllImport("kernel32.dll", BestFitMapping = true, CharSet = CharSet.Auto, SetLastError = true)]
		private static extern bool SetConsoleTitle(string title);

		[DllImport("kernel32.dll", SetLastError = true)]
		private static extern IntPtr LoadLibraryEx(string lpLibFileName, IntPtr hFile, uint dwFlags);
	}
}
namespace BepInEx
{
	public static class ConsoleManager
	{
		public enum ConsoleOutRedirectType
		{
			[Description("Auto")]
			Auto,
			[Description("Console Out")]
			ConsoleOut,
			[Description("Standard Out")]
			StandardOut
		}

		private const uint SHIFT_JIS_CP = 932u;

		private const string ENABLE_CONSOLE_ARG = "--enable-console";

		public static readonly ConfigEntry<bool> ConfigConsoleEnabled;

		public static readonly ConfigEntry<bool> ConfigPreventClose;

		public static readonly ConfigEntry<bool> ConfigConsoleShiftJis;

		public static readonly ConfigEntry<ConsoleOutRedirectType> ConfigConsoleOutRedirectType;

		private static readonly bool? EnableConsoleArgOverride;

		public static bool ConsoleEnabled => EnableConsoleArgOverride ?? ConfigConsoleEnabled.Value;

		internal static IConsoleDriver Driver { get; set; }

		public static bool ConsoleActive => Driver?.ConsoleActive ?? false;

		public static TextWriter StandardOutStream => Driver?.StandardOut;

		public static TextWriter ConsoleStream => Driver?.ConsoleOut;

		static ConsoleManager()
		{
			ConfigConsoleEnabled = ConfigFile.CoreConfig.Bind("Logging.Console", "Enabled", defaultValue: false, "Enables showing a console for log output.");
			ConfigPreventClose = ConfigFile.CoreConfig.Bind("Logging.Console", "PreventClose", defaultValue: false, "If enabled, will prevent closing the console (either by deleting the close button or in other platform-specific way).");
			ConfigConsoleShiftJis = ConfigFile.CoreConfig.Bind("Logging.Console", "ShiftJisEncoding", defaultValue: false, "If true, console is set to the Shift-JIS encoding, otherwise UTF-8 encoding.");
			ConfigConsoleOutRedirectType = ConfigFile.CoreConfig.Bind("Logging.Console", "StandardOutType", ConsoleOutRedirectType.Auto, new StringBuilder().AppendLine("Hints console manager on what handle to assign as StandardOut. Possible values:").AppendLine("Auto - lets BepInEx decide how to redirect console output").AppendLine("ConsoleOut - prefer redirecting to console output; if possible, closes original standard output")
				.AppendLine("StandardOut - prefer redirecting to standard output; if possible, closes console out")
				.ToString());
			try
			{
				string[] commandLineArgs = Environment.GetCommandLineArgs();
				for (int i = 0; i < commandLineArgs.Length; i++)
				{
					if (commandLineArgs[i] == "--enable-console" && i + 1 < commandLineArgs.Length && bool.TryParse(commandLineArgs[i + 1], out var result))
					{
						EnableConsoleArgOverride = result;
					}
				}
			}
			catch (Exception)
			{
			}
		}

		public static void Initialize(bool alreadyActive, bool useWinApiEncoder)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			if (PlatformHelper.Is((Platform)8))
			{
				Driver = new LinuxConsoleDriver();
			}
			else
			{
				if (!PlatformHelper.Is((Platform)37))
				{
					Platform current = PlatformHelper.Current;
					throw new PlatformNotSupportedException("Was unable to determine console driver for platform " + ((object)(Platform)(ref current)).ToString());
				}
				Driver = new WindowsConsoleDriver();
			}
			Driver.Initialize(alreadyActive, useWinApiEncoder);
		}

		private static void DriverCheck()
		{
			if (Driver == null)
			{
				throw new InvalidOperationException("Driver has not been initialized");
			}
		}

		public static void CreateConsole()
		{
			if (!ConsoleActive)
			{
				DriverCheck();
				uint codepage = (ConfigConsoleShiftJis.Value ? 932u : ((uint)Encoding.UTF8.CodePage));
				Driver.CreateConsole(codepage);
				if (ConfigPreventClose.Value)
				{
					Driver.PreventClose();
				}
			}
		}

		public static void DetachConsole()
		{
			if (ConsoleActive)
			{
				DriverCheck();
				Driver.DetachConsole();
			}
		}

		public static void SetConsoleTitle(string title)
		{
			DriverCheck();
			Driver.SetConsoleTitle(title);
		}

		public static void SetConsoleColor(ConsoleColor color)
		{
			DriverCheck();
			Driver.SetConsoleColor(color);
		}
	}
	internal interface IConsoleDriver
	{
		TextWriter StandardOut { get; }

		TextWriter ConsoleOut { get; }

		bool ConsoleActive { get; }

		bool ConsoleIsExternal { get; }

		void PreventClose();

		void Initialize(bool alreadyActive, bool useWinApiEncoder);

		void CreateConsole(uint codepage);

		void DetachConsole();

		void SetConsoleColor(ConsoleColor color);

		void SetConsoleTitle(string title);
	}
	internal class WindowsConsoleDriver : IConsoleDriver
	{
		private static readonly ConstructorInfo FileStreamCtor = new ConstructorInfo[2]
		{
			AccessTools.Constructor(typeof(FileStream), new Type[2]
			{
				typeof(SafeFileHandle),
				typeof(FileAccess)
			}, false),
			AccessTools.Constructor(typeof(FileStream), new Type[2]
			{
				typeof(IntPtr),
				typeof(FileAccess)
			}, false)
		}.FirstOrDefault((ConstructorInfo m) => m != null);

		private readonly Func<int> getWindowHeight;

		private readonly Func<int> getWindowWidth;

		private bool useWinApiEncoder;

		private int ConsoleWidth => getWindowWidth?.Invoke() ?? 0;

		private int ConsoleHeight => getWindowHeight?.Invoke() ?? 0;

		public TextWriter StandardOut { get; private set; }

		public TextWriter ConsoleOut { get; private set; }

		public bool ConsoleActive { get; private set; }

		public bool ConsoleIsExternal => true;

		public void Initialize(bool alreadyActive, bool useWinApiEncoder)
		{
			ConsoleActive = alreadyActive || TryCheckConsoleExists();
			this.useWinApiEncoder = useWinApiEncoder;
			if (ConsoleActive)
			{
				ConsoleOut = Console.Out;
				StandardOut = new StreamWriter(Console.OpenStandardOutput());
			}
			else
			{
				StandardOut = Console.Out;
			}
		}

		public void CreateConsole(uint codepage)
		{
			try
			{
				ConsoleWindow.Attach();
			}
			catch (Exception)
			{
			}
			ConsoleEncoding.ConsoleCodePage = codepage;
			IntPtr outHandle = GetOutHandle();
			if (outHandle == IntPtr.Zero)
			{
				StandardOut = TextWriter.Null;
				ConsoleOut = TextWriter.Null;
				return;
			}
			FileStream stream = OpenFileStream(outHandle);
			StandardOut = new StreamWriter(stream, Utility.UTF8NoBom)
			{
				AutoFlush = true
			};
			FileStream stream2 = OpenFileStream((ConsoleWindow.ConsoleOutHandle != IntPtr.Zero) ? ConsoleWindow.ConsoleOutHandle : outHandle);
			ConsoleOut = new StreamWriter(stream2, useWinApiEncoder ? ConsoleEncoding.OutputEncoding : Utility.UTF8NoBom)
			{
				AutoFlush = true
			};
			ConsoleActive = true;
		}

		public void PreventClose()
		{
			ConsoleWindow.PreventClose();
		}

		public void DetachConsole()
		{
			ConsoleWindow.Detach();
			ConsoleOut.Close();
			ConsoleOut = null;
			ConsoleActive = false;
		}

		public void SetConsoleColor(ConsoleColor color)
		{
			SafeConsole.ForegroundColor = color;
			Kon.ForegroundColor = color;
		}

		public void SetConsoleTitle(string title)
		{
			ConsoleWindow.Title = title;
		}

		private bool TryCheckConsoleExists()
		{
			try
			{
				return ConsoleWidth != 0 && ConsoleHeight != 0;
			}
			catch (IOException)
			{
				return false;
			}
		}

		private static FileStream OpenFileStream(IntPtr handle)
		{
			SafeFileHandle safeFileHandle = new SafeFileHandle(handle, ownsHandle: false);
			object[] args = AccessTools.ActualParameters((MethodBase)FileStreamCtor, new object[3]
			{
				safeFileHandle,
				safeFileHandle.DangerousGetHandle(),
				FileAccess.Write
			});
			return (FileStream)Activator.CreateInstance(typeof(FileStream), args);
		}

		private IntPtr GetOutHandle()
		{
			switch (ConsoleManager.ConfigConsoleOutRedirectType.Value)
			{
			case ConsoleManager.ConsoleOutRedirectType.ConsoleOut:
				return ConsoleWindow.ConsoleOutHandle;
			case ConsoleManager.ConsoleOutRedirectType.StandardOut:
				return ConsoleWindow.OriginalStdoutHandle;
			default:
				if (!(ConsoleWindow.OriginalStdoutHandle != IntPtr.Zero))
				{
					return ConsoleWindow.ConsoleOutHandle;
				}
				return ConsoleWindow.OriginalStdoutHandle;
			}
		}

		public WindowsConsoleDriver()
		{
			MethodInfo methodInfo = AccessTools.PropertyGetter(typeof(Console), "WindowHeight");
			getWindowHeight = (((object)methodInfo != null) ? Extensions.CreateDelegate<Func<int>>((MethodBase)methodInfo) : null);
			MethodInfo methodInfo2 = AccessTools.PropertyGetter(typeof(Console), "WindowWidth");
			getWindowWidth = (((object)methodInfo2 != null) ? Extensions.CreateDelegate<Func<int>>((MethodBase)methodInfo2) : null);
			base..ctor();
		}
	}
	[AttributeUsage(AttributeTargets.Class)]
	public class BepInPlugin : Attribute
	{
		public string GUID { get; protected set; }

		public string Name { get; protected set; }

		public Version Version { get; protected set; }

		public BepInPlugin(string GUID, string Name, string Version)
		{
			this.GUID = GUID;
			this.Name = Name;
			this.Version = TryParseLongVersion(Version);
		}

		private static Version TryParseLongVersion(string version)
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Expected O, but got Unknown
			Version result = default(Version);
			if (Version.TryParse(version, ref result))
			{
				return result;
			}
			try
			{
				Version version2 = new Version(version);
				return new Version(version2.Major, version2.Minor, (version2.Build != -1) ? version2.Build : 0, (string)null, (string)null);
			}
			catch
			{
			}
			return null;
		}

		internal static BepInPlugin FromCecilType(TypeDefinition td)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			CustomAttribute val = MetadataHelper.GetCustomAttributes<BepInPlugin>(td, inherit: false).FirstOrDefault();
			if (val == null)
			{
				return null;
			}
			CustomAttributeArgument val2 = val.ConstructorArguments[0];
			string gUID = (string)((CustomAttributeArgument)(ref val2)).Value;
			val2 = val.ConstructorArguments[1];
			string name = (string)((CustomAttributeArgument)(ref val2)).Value;
			val2 = val.ConstructorArguments[2];
			return new BepInPlugin(gUID, name, (string)((CustomAttributeArgument)(ref val2)).Value);
		}
	}
	[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
	public class BepInDependency : Attribute, ICacheable
	{
		[Flags]
		public enum DependencyFlags
		{
			HardDependency = 1,
			SoftDependency = 2
		}

		public string DependencyGUID { get; protected set; }

		public DependencyFlags Flags { get; protected set; }

		public Range VersionRange { get; protected set; }

		public BepInDependency(string DependencyGUID, DependencyFlags Flags = DependencyFlags.HardDependency)
		{
			this.DependencyGUID = DependencyGUID;
			this.Flags = Flags;
			VersionRange = null;
		}

		public BepInDependency(string guid, string version)
			: this(guid)
		{
			VersionRange = Range.Parse(version, false);
		}

		void ICacheable.Save(BinaryWriter bw)
		{
			bw.Write(DependencyGUID);
			bw.Write((int)Flags);
			bw.Write(((object)VersionRange)?.ToString() ?? string.Empty);
		}

		void ICacheable.Load(BinaryReader br)
		{
			DependencyGUID = br.ReadString();
			Flags = (DependencyFlags)br.ReadInt32();
			string text = br.ReadString();
			VersionRange = ((text == string.Empty) ? null : Range.Parse(text, false));
		}

		internal static IEnumerable<BepInDependency> FromCecilType(TypeDefinition td)
		{
			return MetadataHelper.GetCustomAttributes<BepInDependency>(td, inherit: true).Select(delegate(CustomAttribute customAttribute)
			{
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				//IL_000c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0021: Unknown result type (might be due to invalid IL or missing references)
				//IL_0026: Unknown result type (might be due to invalid IL or missing references)
				CustomAttributeArgument val = customAttribute.ConstructorArguments[0];
				string text = (string)((CustomAttributeArgument)(ref val)).Value;
				val = customAttribute.ConstructorArguments[1];
				object value = ((CustomAttributeArgument)(ref val)).Value;
				return (value is string version) ? new BepInDependency(text, version) : new BepInDependency(text, (DependencyFlags)value);
			}).ToList();
		}
	}
	[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
	public class BepInIncompatibility : Attribute, ICacheable
	{
		public string IncompatibilityGUID { get; protected set; }

		public BepInIncompatibility(string IncompatibilityGUID)
		{
			this.IncompatibilityGUID = IncompatibilityGUID;
		}

		void ICacheable.Save(BinaryWriter bw)
		{
			bw.Write(IncompatibilityGUID);
		}

		void ICacheable.Load(BinaryReader br)
		{
			IncompatibilityGUID = br.ReadString();
		}

		internal static IEnumerable<BepInIncompatibility> FromCecilType(TypeDefinition td)
		{
			return MetadataHelper.GetCustomAttributes<BepInIncompatibility>(td, inherit: true).Select(delegate(CustomAttribute customAttribute)
			{
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				//IL_000c: Unknown result type (might be due to invalid IL or missing references)
				CustomAttributeArgument val = customAttribute.ConstructorArguments[0];
				return new BepInIncompatibility((string)((CustomAttributeArgument)(ref val)).Value);
			}).ToList();
		}
	}
	[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
	public class BepInProcess : Attribute
	{
		public string ProcessName { get; protected set; }

		public BepInProcess(string ProcessName)
		{
			this.ProcessName = ProcessName;
		}

		internal static List<BepInProcess> FromCecilType(TypeDefinition td)
		{
			return MetadataHelper.GetCustomAttributes<BepInProcess>(td, inherit: true).Select(delegate(CustomAttribute customAttribute)
			{
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				//IL_000c: Unknown result type (might be due to invalid IL or missing references)
				CustomAttributeArgument val = customAttribute.ConstructorArguments[0];
				return new BepInProcess((string)((CustomAttributeArgument)(ref val)).Value);
			}).ToList();
		}
	}
	public static class MetadataHelper
	{
		internal static IEnumerable<CustomAttribute> GetCustomAttributes<T>(TypeDefinition td, bool inherit) where T : Attribute
		{
			List<CustomAttribute> list = new List<CustomAttribute>();
			Type type = typeof(T);
			TypeDefinition val = td;
			do
			{
				list.AddRange(((IEnumerable<CustomAttribute>)val.CustomAttributes).Where((CustomAttribute ca) => ((MemberReference)ca.AttributeType).FullName == type.FullName));
				TypeReference baseType = val.BaseType;
				val = ((baseType != null) ? baseType.Resolve() : null);
			}
			while (inherit && ((val != null) ? ((MemberReference)val).FullName : null) != "System.Object");
			return list;
		}

		public static BepInPlugin GetMetadata(Type pluginType)
		{
			object[] customAttributes = pluginType.GetCustomAttributes(typeof(BepInPlugin), inherit: false);
			if (customAttributes.Length == 0)
			{
				return null;
			}
			return (BepInPlugin)customAttributes[0];
		}

		public static BepInPlugin GetMetadata(object plugin)
		{
			return GetMetadata(plugin.GetType());
		}

		public static T[] GetAttributes<T>(Type pluginType) where T : Attribute
		{
			return (T[])pluginType.GetCustomAttributes(typeof(T), inherit: true);
		}

		public static T[] GetAttributes<T>(Assembly assembly) where T : Attribute
		{
			return (T[])assembly.GetCustomAttributes(typeof(T), inherit: true);
		}

		public static IEnumerable<T> GetAttributes<T>(object plugin) where T : Attribute
		{
			return GetAttributes<T>(plugin.GetType());
		}

		public static T[] GetAttributes<T>(MemberInfo member) where T : Attribute
		{
			return (T[])member.GetCustomAttributes(typeof(T), inherit: true);
		}

		public static IEnumerable<BepInDependency> GetDependencies(Type plugin)
		{
			return plugin.GetCustomAttributes(typeof(BepInDependency), inherit: true).Cast<BepInDependency>();
		}
	}
	public class PluginInfo : ICacheable
	{
		public BepInPlugin Metadata { get; internal set; }

		public IEnumerable<BepInProcess> Processes { get; internal set; }

		public IEnumerable<BepInDependency> Dependencies { get; internal set; }

		public IEnumerable<BepInIncompatibility> Incompatibilities { get; internal set; }

		public string Location { get; internal set; }

		public object Instance { get; internal set; }

		public string TypeName { get; internal set; }

		internal Version TargettedBepInExVersion { get; set; }

		void ICacheable.Save(BinaryWriter bw)
		{
			bw.Write(TypeName);
			bw.Write(Location);
			bw.Write(Metadata.GUID);
			bw.Write(Metadata.Name);
			bw.Write(((object)Metadata.Version).ToString());
			List<BepInProcess> list = Processes.ToList();
			bw.Write(list.Count);
			foreach (BepInProcess item in list)
			{
				bw.Write(item.ProcessName);
			}
			List<BepInDependency> list2 = Dependencies.ToList();
			bw.Write(list2.Count);
			foreach (BepInDependency item2 in list2)
			{
				((ICacheable)item2).Save(bw);
			}
			List<BepInIncompatibility> list3 = Incompatibilities.ToList();
			bw.Write(list3.Count);
			foreach (BepInIncompatibility item3 in list3)
			{
				((ICacheable)item3).Save(bw);
			}
			bw.Write(TargettedBepInExVersion.ToString(4));
		}

		void ICacheable.Load(BinaryReader br)
		{
			TypeName = br.ReadString();
			Location = br.ReadString();
			Metadata = new BepInPlugin(br.ReadString(), br.ReadString(), br.ReadString());
			int num = br.ReadInt32();
			List<BepInProcess> list = new List<BepInProcess>(num);
			for (int i = 0; i < num; i++)
			{
				list.Add(new BepInProcess(br.ReadString()));
			}
			Processes = list;
			int num2 = br.ReadInt32();
			List<BepInDependency> list2 = new List<BepInDependency>(num2);
			for (int j = 0; j < num2; j++)
			{
				BepInDependency bepInDependency = new BepInDependency("");
				((ICacheable)bepInDependency).Load(br);
				list2.Add(bepInDependency);
			}
			Dependencies = list2;
			int num3 = br.ReadInt32();
			List<BepInIncompatibility> list3 = new List<BepInIncompatibility>(num3);
			for (int k = 0; k < num3; k++)
			{
				BepInIncompatibility bepInIncompatibility = new BepInIncompatibility("");
				((ICacheable)bepInIncompatibility).Load(br);
				list3.Add(bepInIncompatibility);
			}
			Incompatibilities = list3;
			TargettedBepInExVersion = new Version(br.ReadString());
		}

		public override string ToString()
		{
			return $"{Metadata?.Name} {Metadata?.Version}";
		}
	}
	public static class Paths
	{
		public static Version BepInExVersion { get; } = Version.Parse(MetadataHelper.GetAttributes<AssemblyInformationalVersionAttribute>(typeof(Paths).Assembly)[0].InformationalVersion, false);


		public static string ManagedPath { get; private set; }

		public static string BepInExAssemblyDirectory { get; private set; }

		public static string BepInExAssemblyPath { get; private set; }

		public static string BepInExRootPath { get; private set; }

		public static string ExecutablePath { get; private set; }

		public static string GameRootPath { get; private set; }

		public static string ConfigPath { get; private set; }

		public static string BepInExConfigPath { get; private set; }

		public static string CachePath { get; private set; }

		public static string PatcherPluginPath { get; private set; }

		public static string PluginPath { get; private set; }

		public static string ProcessName { get; private set; }

		public static string[] DllSearchPaths { get; private set; }

		public static void SetExecutablePath(string executablePath, string bepinRootPath = null, string managedPath = null, string[] dllSearchPath = null)
		{
			ExecutablePath = executablePath;
			ProcessName = Path.GetFileNameWithoutExtension(executablePath);
			GameRootPath = (PlatformHelper.Is((Platform)73) ? Utility.ParentDirectory(executablePath, 4) : Path.GetDirectoryName(executablePath));
			ManagedPath = managedPath ?? Utility.CombinePaths(GameRootPath, ProcessName + "_Data", "Managed");
			BepInExRootPath = bepinRootPath ?? Path.Combine(GameRootPath, "BepInEx");
			ConfigPath = Path.Combine(BepInExRootPath, "config");
			BepInExConfigPath = Path.Combine(ConfigPath, "BepInEx.cfg");
			PluginPath = Path.Combine(BepInExRootPath, "plugins");
			PatcherPluginPath = Path.Combine(BepInExRootPath, "patchers");
			BepInExAssemblyDirectory = Path.Combine(BepInExRootPath, "core");
			BepInExAssemblyPath = Path.Combine(BepInExAssemblyDirectory, Assembly.GetExecutingAssembly().GetName().Name + ".dll");
			CachePath = Path.Combine(BepInExRootPath, "cache");
			DllSearchPaths = (dllSearchPath ?? new string[0]).Concat(new string[1] { ManagedPath }).Distinct().ToArray();
		}

		internal static void SetPluginPath(string pluginPath)
		{
			PluginPath = Utility.CombinePaths(BepInExRootPath, pluginPath);
		}
	}
	public static class Utility
	{
		private const string TRUSTED_PLATFORM_ASSEMBLIES = "TRUSTED_PLATFORM_ASSEMBLIES";

		private static bool? sreEnabled;

		public static bool CLRSupportsDynamicAssemblies => CheckSRE();

		public static Encoding UTF8NoBom { get; } = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false);


		private static bool CheckSRE()
		{
			try
			{
				if (sreEnabled.HasValue)
				{
					return sreEnabled.Value;
				}
				new CustomAttributeBuilder(null, new object[0]);
			}
			catch (PlatformNotSupportedException)
			{
				sreEnabled = false;
				return sreEnabled.Value;
			}
			catch (ArgumentNullException)
			{
			}
			sreEnabled = true;
			return sreEnabled.Value;
		}

		public static bool TryDo(Action action, out Exception exception)
		{
			exception = null;
			try
			{
				action();
				return true;
			}
			catch (Exception ex)
			{
				exception = ex;
				return false;
			}
		}

		public static string CombinePaths(params string[] parts)
		{
			return parts.Aggregate(Path.Combine);
		}

		public static string ParentDirectory(string path, int levels = 1)
		{
			for (int i = 0; i < levels; i++)
			{
				path = Path.GetDirectoryName(path);
			}
			return path;
		}

		public static bool SafeParseBool(string input, bool defaultValue = false)
		{
			if (!bool.TryParse(input, out var result))
			{
				return defaultValue;
			}
			return result;
		}

		public static string ConvertToWWWFormat(string path)
		{
			return "file://" + path.Replace('\\', '/');
		}

		public static bool IsNullOrWhiteSpace(this string self)
		{
			return self?.All(char.IsWhiteSpace) ?? true;
		}

		public static IEnumerable<TNode> TopologicalSort<TNode>(IEnumerable<TNode> nodes, Func<TNode, IEnumerable<TNode>> dependencySelector)
		{
			List<TNode> sorted_list = new List<TNode>();
			HashSet<TNode> visited = new HashSet<TNode>();
			HashSet<TNode> sorted = new HashSet<TNode>();
			foreach (TNode node in nodes)
			{
				Stack<TNode> stack2 = new Stack<TNode>();
				if (!Visit(node, stack2))
				{
					throw new Exception("Cyclic Dependency:\r\n" + stack2.Select((TNode x) => $" - {x}").Aggregate((string a, string b) => a + "\r\n" + b));
				}
			}
			return sorted_list;
			bool Visit(TNode node, Stack<TNode> stack)
			{
				if (visited.Contains(node))
				{
					if (!sorted.Contains(node))
					{
						return false;
					}
				}
				else
				{
					visited.Add(node);
					stack.Push(node);
					if (dependencySelector(node).Any((TNode dep) => !Visit(dep, stack)))
					{
						return false;
					}
					sorted.Add(node);
					sorted_list.Add(node);
					stack.Pop();
				}
				return true;
			}
		}

		private static bool TryResolveDllAssembly<T>(AssemblyName assemblyName, string directory, Func<string, T> loader, out T assembly) where T : class
		{
			assembly = null;
			List<string> list = new List<string> { directory };
			if (!Directory.Exists(directory))
			{
				return false;
			}
			list.AddRange(Directory.GetDirectories(directory, "*", SearchOption.AllDirectories));
			foreach (string item in list)
			{
				string[] array = new string[2]
				{
					assemblyName.Name + ".dll",
					assemblyName.Name + ".exe"
				};
				foreach (string path in array)
				{
					string text = Path.Combine(item, path);
					if (File.Exists(text))
					{
						try
						{
							assembly = loader(text);
						}
						catch (Exception)
						{
							continue;
						}
						return true;
					}
				}
			}
			return false;
		}

		public static bool IsSubtypeOf(this TypeDefinition self, Type td)
		{
			if (((MemberReference)self).FullName == td.FullName)
			{
				return true;
			}
			if (((MemberReference)self).FullName != "System.Object")
			{
				TypeReference baseType = self.BaseType;
				return ((baseType == null) ? null : baseType.Resolve()?.IsSubtypeOf(td)).GetValueOrDefault();
			}
			return false;
		}

		public static bool TryResolveDllAssembly(AssemblyName assemblyName, string directory, out Assembly assembly)
		{
			return TryResolveDllAssembly(assemblyName, directory, (Func<string, Assembly>)Assembly.LoadFile, out assembly);
		}

		public static bool TryResolveDllAssembly(AssemblyName assemblyName, string directory, ReaderParameters readerParameters, out AssemblyDefinition assembly)
		{
			return TryResolveDllAssembly(assemblyName, directory, (Func<string, AssemblyDefinition>)((string s) => AssemblyDefinition.ReadAssembly(s, readerParameters)), out assembly);
		}

		public static bool TryOpenFileStream(string path, FileMode mode, out FileStream fileStream, FileAccess access = FileAccess.ReadWrite, FileShare share = FileShare.Read)
		{
			try
			{
				fileStream = new FileStream(path, mode, access, share);
				return true;
			}
			catch (IOException)
			{
				fileStream = null;
				return false;
			}
		}

		public static IEnumerable<MethodDefinition> EnumerateAllMethods(this TypeDefinition type)
		{
			TypeDefinition currentType = type;
			while (currentType != null)
			{
				Enumerator<MethodDefinition> enumerator = currentType.Methods.GetEnumerator();
				try
				{
					while (enumerator.MoveNext())
					{
						yield return enumerator.Current;
					}
				}
				finally
				{
					((IDisposable)enumerator).Dispose();
				}
				TypeReference baseType = currentType.BaseType;
				currentType = ((baseType != null) ? baseType.Resolve() : null);
			}
		}

		public static string HashStream(Stream stream)
		{
			using MD5 mD = MD5.Create();
			byte[] array = new byte[4096];
			int inputCount;
			while ((inputCount = stream.Read(array, 0, array.Length)) > 0)
			{
				mD.TransformBlock(array, 0, inputCount, array, 0);
			}
			mD.TransformFinalBlock(new byte[0], 0, 0);
			return ByteArrayToString(mD.Hash);
		}

		public static string ByteArrayToString(byte[] data)
		{
			StringBuilder stringBuilder = new StringBuilder(data.Length * 2);
			foreach (byte b in data)
			{
				stringBuilder.AppendFormat("{0:x2}", b);
			}
			return stringBuilder.ToString();
		}

		public static string GetCommandLineArgValue(string arg)
		{
			string[] commandLineArgs = Environment.GetCommandLineArgs();
			for (int i = 1; i < commandLineArgs.Length; i++)
			{
				if (commandLineArgs[i] == arg && i + 1 < commandLineArgs.Length)
				{
					return commandLineArgs[i + 1];
				}
			}
			return null;
		}

		public static bool TryParseAssemblyName(string fullName, out AssemblyName assemblyName)
		{
			try
			{
				assemblyName = new AssemblyName(fullName);
				return true;
			}
			catch (Exception)
			{
				assemblyName = null;
				return false;
			}
		}

		internal static void AddCecilPlatformAssemblies(this AppDomain appDomain, string assemblyDir)
		{
			if (Directory.Exists(assemblyDir))
			{
				string text = appDomain.GetData("TRUSTED_PLATFORM_ASSEMBLIES") as string;
				string text2 = string.Join(Path.PathSeparator.ToString(), Directory.GetFiles(assemblyDir, "*.dll", SearchOption.TopDirectoryOnly));
				string data = ((text == null) ? text2 : $"{text}{Path.PathSeparator}{text2}");
				appDomain.SetData("TRUSTED_PLATFORM_ASSEMBLIES", data);
			}
		}

		public static IEnumerable<string> GetUniqueFilesInDirectories(IEnumerable<string> directories, string pattern = "*")
		{
			Dictionary<string, string> dictionary = new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase);
			foreach (string directory in directories)
			{
				string[] files = Directory.GetFiles(directory, pattern);
				foreach (string text in files)
				{
					string fileName = Path.GetFileName(text);
					if (!dictionary.ContainsKey(fileName))
					{
						dictionary[fileName] = text;
					}
				}
			}
			return dictionary.Values;
		}
	}
}
namespace BepInEx.Shared
{
	[AttributeUsage(AttributeTargets.Assembly)]
	public class BuildInfoAttribute : Attribute
	{
		public string Info { get; }

		public BuildInfoAttribute(string info)
		{
			Info = info;
		}
	}
}
namespace BepInEx.Logging
{
	public class ConsoleLogListener : ILogListener, IDisposable
	{
		protected static readonly ConfigEntry<LogLevel> ConfigConsoleDisplayedLevel = ConfigFile.CoreConfig.Bind("Logging.Console", "LogLevels", LogLevel.Fatal | LogLevel.Error | LogLevel.Warning | LogLevel.Message | LogLevel.Info, "Only displays the specified log levels in the console output.");

		public LogLevel LogLevelFilter => ConfigConsoleDisplayedLevel.Value;

		public void LogEvent(object sender, LogEventArgs eventArgs)
		{
			ConsoleManager.SetConsoleColor(eventArgs.Level.GetConsoleColor());
			ConsoleManager.ConsoleStream?.Write(eventArgs.ToStringLine());
			ConsoleManager.SetConsoleColor(ConsoleColor.Gray);
		}

		public void Dispose()
		{
		}
	}
	public class DiskLogListener : ILogListener, IDisposable
	{
		public static HashSet<string> BlacklistedSources = new HashSet<string>();

		public LogLevel DisplayedLogLevel { get; }

		public TextWriter LogWriter { get; protected set; }

		private Timer FlushTimer { get; }

		private bool InstantFlushing { get; }

		public LogLevel LogLevelFilter => DisplayedLogLevel;

		public DiskLogListener(string localPath, LogLevel displayedLogLevel = LogLevel.Info, bool appendLog = false, bool delayedFlushing = true, int fileLimit = 5)
		{
			DisplayedLogLevel = displayedLogLevel;
			int num = 1;
			FileStream fileStream;
			while (!Utility.TryOpenFileStream(Path.Combine(Paths.BepInExRootPath, localPath), appendLog ? FileMode.Append : FileMode.Create, out fileStream, FileAccess.Write))
			{
				if (num == fileLimit)
				{
					Logger.Log(LogLevel.Error, "Couldn't open a log file for writing. Skipping log file creation");
					return;
				}
				LogLevel logLevel = LogLevel.Warning;
				bool isEnabled;
				BepInExLogInterpolatedStringHandler bepInExLogInterpolatedStringHandler = new BepInExLogInterpolatedStringHandler(56, 1, logLevel, out isEnabled);
				if (isEnabled)
				{
					bepInExLogInterpolatedStringHandler.AppendLiteral("Couldn't open log file '");
					bepInExLogInterpolatedStringHandler.AppendFormatted(localPath);
					bepInExLogInterpolatedStringHandler.AppendLiteral("' for writing, trying another...");
				}
				Logger.Log(logLevel, bepInExLogInterpolatedStringHandler);
				localPath = $"LogOutput.{num++}.log";
			}
			LogWriter = TextWriter.Synchronized(new StreamWriter(fileStream, Utility.UTF8NoBom));
			if (delayedFlushing)
			{
				FlushTimer = new Timer(delegate
				{
					LogWriter?.Flush();
				}, null, 2000, 2000);
			}
			InstantFlushing = !delayedFlushing;
		}

		public void LogEvent(object sender, LogEventArgs eventArgs)
		{
			if (LogWriter != null && !BlacklistedSources.Contains(eventArgs.Source.SourceName))
			{
				LogWriter.WriteLine(eventArgs.ToString());
				if (InstantFlushing)
				{
					LogWriter.Flush();
				}
			}
		}

		public void Dispose()
		{
			FlushTimer?.Dispose();
			try
			{
				LogWriter?.Flush();
				LogWriter?.Dispose();
			}
			catch (ObjectDisposedException)
			{
			}
		}

		~DiskLogListener()
		{
			Dispose();
		}
	}
	public class HarmonyLogSource : ILogSource, IDisposable
	{
		private static readonly ConfigEntry<LogChannel> LogChannels = ConfigFile.CoreConfig.Bind<LogChannel>("Harmony.Logger", "LogChannels", (LogChannel)24, "Specifies which Harmony log channels to listen to.\nNOTE: IL channel dumps the whole patch methods, use only when needed!");

		private static readonly Dictionary<LogChannel, LogLevel> LevelMap = new Dictionary<LogChannel, LogLevel>
		{
			[(LogChannel)2] = LogLevel.Info,
			[(LogChannel)8] = LogLevel.Warning,
			[(LogChannel)16] = LogLevel.Error,
			[(LogChannel)4] = LogLevel.Debug
		};

		public string SourceName { get; } = "HarmonyX";


		public event EventHandler<LogEventArgs> LogEvent;

		public HarmonyLogSource()
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			Logger.ChannelFilter = LogChannels.Value;
			Logger.MessageReceived += HandleHarmonyMessage;
		}

		public void Dispose()
		{
			Logger.MessageReceived -= HandleHarmonyMessage;
		}

		private void HandleHarmonyMessage(object sender, LogEventArgs e)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			if (LevelMap.TryGetValue(e.LogChannel, out var value))
			{
				this.LogEvent?.Invoke(this, new LogEventArgs(e.Message, value, this));
			}
		}
	}
	public interface ILogListener : IDisposable
	{
		LogLevel LogLevelFilter { get; }

		void LogEvent(object sender, LogEventArgs eventArgs);
	}
	public interface ILogSource : IDisposable
	{
		string SourceName { get; }

		event EventHandler<LogEventArgs> LogEvent;
	}
	public class LogEventArgs : EventArgs
	{
		public object Data { get; }

		public LogLevel Level { get; }

		public ILogSource Source { get; }

		public LogEventArgs(object data, LogLevel level, ILogSource source)
		{
			Data = data;
			Level = level;
			Source = source;
		}

		public override string ToString()
		{
			return $"[{Level,-7}:{Source.SourceName,10}] {Data}";
		}

		public string ToStringLine()
		{
			return $"[{Level,-7}:{Source.SourceName,10}] {Data}{Environment.NewLine}";
		}
	}
	public static class Logger
	{
		private class LogListenerCollection : List<ILogListener>, ICollection<ILogListener>, IEnumerable<ILogListener>, IEnumerable
		{
			public LogLevel activeLogLevels;

			void ICollection<ILogListener>.Add(ILogListener item)
			{
				if (item == null)
				{
					throw new ArgumentNullException("item");
				}
				activeLogLevels |= item.LogLevelFilter;
				Add(item);
			}

			void ICollection<ILogListener>.Clear()
			{
				activeLogLevels = LogLevel.None;
				Clear();
			}

			bool ICollection<ILogListener>.Remove(ILogListener item)
			{
				if (item == null || !Remove(item))
				{
					return false;
				}
				activeLogLevels = LogLevel.None;
				using (Enumerator enumerator = GetEnumerator())
				{
					while (enumerator.MoveNext())
					{
						ILogListener current = enumerator.Current;
						activeLogLevels |= current.LogLevelFilter;
					}
				}
				return true;
			}
		}

		private class LogSourceCollection : List<ILogSource>, ICollection<ILogSource>, IEnumerable<ILogSource>, IEnumerable
		{
			void ICollection<ILogSource>.Add(ILogSource item)
			{
				if (item == null)
				{
					throw new ArgumentNullException("item", "Log sources cannot be null when added to the source list.");
				}
				item.LogEvent += InternalLogEvent;
				Add(item);
			}

			void ICollection<ILogSource>.Clear()
			{
				using (Enumerator enumerator = GetEnumerator())
				{
					while (enumerator.MoveNext())
					{
						enumerator.Current.LogEvent -= InternalLogEvent;
					}
				}
				Clear();
			}

			bool ICollection<ILogSource>.Remove(ILogSource item)
			{
				if (item == null || !Remove(item))
				{
					return false;
				}
				item.LogEvent -= InternalLogEvent;
				return true;
			}
		}

		private static readonly ManualLogSource InternalLogSource;

		private static readonly LogListenerCollection listeners;

		public static LogLevel ListenedLogLevels => listeners.activeLogLevels;

		public static ICollection<ILogListener> Listeners => listeners;

		public static ICollection<ILogSource> Sources { get; }

		static Logger()
		{
			Sources = new LogSourceCollection();
			listeners = new LogListenerCollection();
			InternalLogSource = CreateLogSource("BepInEx");
		}

		internal static void InternalLogEvent(object sender, LogEventArgs eventArgs)
		{
			foreach (ILogListener listener in listeners)
			{
				if ((eventArgs.Level & listener.LogLevelFilter) != 0)
				{
					listener?.LogEvent(sender, eventArgs);
				}
			}
		}

		internal static void Log(LogLevel level, object data)
		{
			InternalLogSource.Log(level, data);
		}

		internal static void Log(LogLevel level, [InterpolatedStringHandlerArgument("level")] BepInExLogInterpolatedStringHandler logHandler)
		{
			InternalLogSource.Log(level, logHandler);
		}

		public static ManualLogSource CreateLogSource(string sourceName)
		{
			ManualLogSource manualLogSource = new ManualLogSource(sourceName);
			Sources.Add(manualLogSource);
			return manualLogSource;
		}
	}
	[Flags]
	public enum LogLevel
	{
		None = 0,
		Fatal = 1,
		Error = 2,
		Warning = 4,
		Message = 8,
		Info = 0x10,
		Debug = 0x20,
		All = 0x3F
	}
	public static class LogLevelExtensions
	{
		public static LogLevel GetHighestLevel(this LogLevel levels)
		{
			Array values = Enum.GetValues(typeof(LogLevel));
			Array.Sort(values);
			foreach (LogLevel item in values)
			{
				if ((levels & item) != 0)
				{
					return item;
				}
			}
			return LogLevel.None;
		}

		public static ConsoleColor GetConsoleColor(this LogLevel level)
		{
			level = level.GetHighestLevel();
			return level switch
			{
				LogLevel.Fatal => ConsoleColor.Red, 
				LogLevel.Error => ConsoleColor.DarkRed, 
				LogLevel.Warning => ConsoleColor.Yellow, 
				LogLevel.Message => ConsoleColor.White, 
				LogLevel.Info => ConsoleColor.DarkGray, 
				LogLevel.Debug => ConsoleColor.DarkGray, 
				_ => ConsoleColor.Gray, 
			};
		}
	}
	public class ManualLogSource : ILogSource, IDisposable
	{
		public string SourceName { get; }

		public event EventHandler<LogEventArgs> LogEvent;

		public ManualLogSource(string sourceName)
		{
			SourceName = sourceName;
		}

		public void Dispose()
		{
		}

		public void Log(LogLevel level, object data)
		{
			this.LogEvent?.Invoke(this, new LogEventArgs(data, level, this));
		}

		public void Log(LogLevel level, [InterpolatedStringHandlerArgument("level")] BepInExLogInterpolatedStringHandler logHandler)
		{
			if (logHandler.Enabled)
			{
				this.LogEvent?.Invoke(this, new LogEventArgs(logHandler.ToString(), level, this));
			}
		}

		public void LogFatal(object data)
		{
			Log(LogLevel.Fatal, data);
		}

		public void LogFatal(BepInExFatalLogInterpolatedStringHandler logHandler)
		{
			Log(LogLevel.Fatal, logHandler);
		}

		public void LogError(object data)
		{
			Log(LogLevel.Error, data);
		}

		public void LogError(BepInExErrorLogInterpolatedStringHandler logHandler)
		{
			Log(LogLevel.Error, logHandler);
		}

		public void LogWarning(object data)
		{
			Log(LogLevel.Warning, data);
		}

		public void LogWarning(BepInExWarningLogInterpolatedStringHandler logHandler)
		{
			Log(LogLevel.Warning, logHandler);
		}

		public void LogMessage(object data)
		{
			Log(LogLevel.Message, data);
		}

		public void LogMessage(BepInExMessageLogInterpolatedStringHandler logHandler)
		{
			Log(LogLevel.Message, logHandler);
		}

		public void LogInfo(object data)
		{
			Log(LogLevel.Info, data);
		}

		public void LogInfo(BepInExInfoLogInterpolatedStringHandler logHandler)
		{
			Log(LogLevel.Info, logHandler);
		}

		public void LogDebug(object data)
		{
			Log(LogLevel.Debug, data);
		}

		public void LogDebug(BepInExDebugLogInterpolatedStringHandler logHandler)
		{
			Log(LogLevel.Debug, logHandler);
		}
	}
	public class TraceLogSource : TraceListener
	{
		private static TraceLogSource traceListener;

		public static bool IsListening { get; private set; }

		protected ManualLogSource LogSource { get; }

		protected TraceLogSource()
		{
			LogSource = new ManualLogSource("Trace");
		}

		public static ILogSource CreateSource()
		{
			if (traceListener == null)
			{
				traceListener = new TraceLogSource();
				Trace.Listeners.Add(traceListener);
				IsListening = true;
			}
			return traceListener.LogSource;
		}

		public override void Write(string message)
		{
			LogSource.Log(LogLevel.Info, message);
		}

		public override void WriteLine(string message)
		{
			LogSource.Log(LogLevel.Info, message);
		}

		public override void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id, string format, params object[] args)
		{
			TraceEvent(eventCache, source, eventType, id, string.Format(format, args));
		}

		public override void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id, string message)
		{
			LogSource.Log(eventType switch
			{
				TraceEventType.Critical => LogLevel.Fatal, 
				TraceEventType.Error => LogLevel.Error, 
				TraceEventType.Warning => LogLevel.Warning, 
				TraceEventType.Information => LogLevel.Info, 
				_ => LogLevel.Debug, 
			}, (message ?? "").Trim());
		}
	}
}
namespace BepInEx.Core.Logging.Interpolation
{
	[InterpolatedStringHandler]
	public class BepInExLogInterpolatedStringHandler
	{
		private const int GUESSED_LENGTH_PER_HOLE = 11;

		private readonly StringBuilder sb;

		public bool Enabled { get; }

		public BepInExLogInterpolatedStringHandler(int literalLength, int formattedCount, LogLevel logLevel, out bool isEnabled)
		{
			Enabled = (logLevel & Logger.ListenedLogLevels) != 0;
			isEnabled = Enabled;
			sb = (Enabled ? new StringBuilder(literalLength + formattedCount * 11) : null);
		}

		public void AppendLiteral(string s)
		{
			if (Enabled)
			{
				sb.Append(s);
			}
		}

		public void AppendFormatted<T>(T t)
		{
			if (Enabled)
			{
				sb.Append(t);
			}
		}

		public void AppendFormatted<T>(T t, string format) where T : IFormattable
		{
			if (Enabled)
			{
				sb.Append(t?.ToString(format, null));
			}
		}

		public void AppendFormatted(IntPtr t, string format)
		{
			if (Enabled)
			{
				sb.Append(t.ToString(format));
			}
		}

		public override string ToString()
		{
			return sb?.ToString() ?? string.Empty;
		}
	}
	[InterpolatedStringHandler]
	public class BepInExFatalLogInterpolatedStringHandler : BepInExLogInterpolatedStringHandler
	{
		public BepInExFatalLogInterpolatedStringHandler(int literalLength, int formattedCount, out bool isEnabled)
			: base(literalLength, formattedCount, LogLevel.Fatal, out isEnabled)
		{
		}
	}
	[InterpolatedStringHandler]
	public class BepInExErrorLogInterpolatedStringHandler : BepInExLogInterpolatedStringHandler
	{
		public BepInExErrorLogInterpolatedStringHandler(int literalLength, int formattedCount, out bool isEnabled)
			: base(literalLength, formattedCount, LogLevel.Error, out isEnabled)
		{
		}
	}
	[InterpolatedStringHandler]
	public class BepInExWarningLogInterpolatedStringHandler : BepInExLogInterpolatedStringHandler
	{
		public BepInExWarningLogInterpolatedStringHandler(int literalLength, int formattedCount, out bool isEnabled)
			: base(literalLength, formattedCount, LogLevel.Warning, out isEnabled)
		{
		}
	}
	[InterpolatedStringHandler]
	public class BepInExMessageLogInterpolatedStringHandler : BepInExLogInterpolatedStringHandler
	{
		public BepInExMessageLogInterpolatedStringHandler(int literalLength, int formattedCount, out bool isEnabled)
			: base(literalLength, formattedCount, LogLevel.Message, out isEnabled)
		{
		}
	}
	[InterpolatedStringHandler]
	public class BepInExInfoLogInterpolatedStringHandler : BepInExLogInterpolatedStringHandler
	{
		public BepInExInfoLogInterpolatedStringHandler(int literalLength, int formattedCount, out bool isEnabled)
			: base(literalLength, formattedCount, LogLevel.Info, out isEnabled)
		{
		}
	}
	[InterpolatedStringHandler]
	public class BepInExDebugLogInterpolatedStringHandler : BepInExLogInterpolatedStringHandler
	{
		public BepInExDebugLogInterpolatedStringHandler(int literalLength, int formattedCount, out bool isEnabled)
			: base(literalLength, formattedCount, LogLevel.Debug, out isEnabled)
		{
		}
	}
}
namespace BepInEx.ConsoleUtil
{
	internal class Kon
	{
		private struct CONSOLE_SCREEN_BUFFER_INFO
		{
			internal COORD dwSize;

			internal COORD dwCursorPosition;

			internal short wAttributes;

			internal SMALL_RECT srWindow;

			internal COORD dwMaximumWindowSize;
		}

		private struct COORD
		{
			internal short X;

			internal short Y;
		}

		private struct SMALL_RECT
		{
			internal short Left;

			internal short Top;

			internal short Right;

			internal short Bottom;
		}

		private static readonly IntPtr INVALID_HANDLE_VALUE = new IntPtr(-1);

		internal static IntPtr conOut = IntPtr.Zero;

		public static ConsoleColor ForegroundColor
		{
			get
			{
				return GetConsoleColor(isBackground: false);
			}
			set
			{
				SetConsoleColor(isBackground: false, value);
			}
		}

		public static ConsoleColor BackgroundColor
		{
			get
			{
				return GetConsoleColor(isBackground: true);
			}
			set
			{
				SetConsoleColor(isBackground: true, value);
			}
		}

		[DllImport("kernel32.dll", SetLastError = true)]
		private static extern bool GetConsoleScreenBufferInfo(IntPtr hConsoleOutput, out CONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo);

		[DllImport("kernel32.dll", SetLastError = true)]
		private static extern bool SetConsoleTextAttribute(IntPtr hConsoleOutput, short attributes);

		[DllImport("kernel32.dll", SetLastError = true)]
		private static extern IntPtr GetStdHandle(int nStdHandle);

		private static short ConsoleColorToColorAttribute(short color, bool isBackground)
		{
			if (((uint)color & 0xFFFFFFF0u) != 0)
			{
				throw new ArgumentException("Arg_InvalidConsoleColor");
			}
			if (isBackground)
			{
				color <<= 4;
			}
			return color;
		}

		private static CONSOLE_SCREEN_BUFFER_INFO GetBufferInfo(bool throwOnNoConsole, out bool succeeded)
		{
			succeeded = false;
			if (!(conOut == INVALID_HANDLE_VALUE))
			{
				if (!GetConsoleScreenBufferInfo(conOut, out var lpConsoleScreenBufferInfo))
				{
					bool consoleScreenBufferInfo = GetConsoleScreenBufferInfo(GetStdHandle(-12), out lpConsoleScreenBufferInfo);
					if (!consoleScreenBufferInfo)
					{
						consoleScreenBufferInfo = GetConsoleScreenBufferInfo(GetStdHandle(-10), out lpConsoleScreenBufferInfo);
					}
					if (!consoleScreenBufferInfo && Marshal.GetLastWin32Error() == 6 && !throwOnNoConsole)
					{
						return default(CONSOLE_SCREEN_BUFFER_INFO);
					}
				}
				succeeded = true;
				return lpConsoleScreenBufferInfo;
			}
			if (!throwOnNoConsole)
			{
				return default(CONSOLE_SCREEN_BUFFER_INFO);
			}
			throw new Exception("IO.IO_NoConsole");
		}

		private static void SetConsoleColor(bool isBackground, ConsoleColor c)
		{
			short num = ConsoleColorToColorAttribute((short)c, isBackground);
			bool succeeded;
			CONSOLE_SCREEN_BUFFER_INFO bufferInfo = GetBufferInfo(throwOnNoConsole: false, out succeeded);
			if (succeeded)
			{
				short wAttributes = bufferInfo.wAttributes;
				wAttributes &= (short)(isBackground ? (-241) : (-16));
				wAttributes = (short)((ushort)wAttributes | (ushort)num);
				SetConsoleTextAttribute(conOut, wAttributes);
			}
		}

		private static ConsoleColor GetConsoleColor(bool isBackground)
		{
			bool succeeded;
			CONSOLE_SCREEN_BUFFER_INFO bufferInfo = GetBufferInfo(throwOnNoConsole: false, out succeeded);
			if (!succeeded)
			{
				if (!isBackground)
				{
					return ConsoleColor.Gray;
				}
				return ConsoleColor.Black;
			}
			return ColorAttributeToConsoleColor((short)(bufferInfo.wAttributes & 0xF0));
		}

		private static ConsoleColor ColorAttributeToConsoleColor(short c)
		{
			if ((short)((uint)c & 0xFFu) != 0)
			{
				c >>= 4;
			}
			return (ConsoleColor)c;
		}

		public static void ResetConsoleColor()
		{
			SetConsoleColor(isBackground: true, ConsoleColor.Black);
			SetConsoleColor(isBackground: false, ConsoleColor.Gray);
		}
	}
}
namespace BepInEx.Unix
{
	internal static class ConsoleWriter
	{
		private static Func<Stream, Encoding, bool, StreamWriter> cStreamWriterConstructor;

		private static Func<Stream, Encoding, bool, StreamWriter> CStreamWriterConstructor
		{
			get
			{
				if (cStreamWriterConstructor != null)
				{
					return cStreamWriterConstructor;
				}
				Type cStreamWriter = AccessTools.TypeByName("System.IO.CStreamWriter");
				cStreamWriterConstructor = new int[2][]
				{
					new int[3] { 0, 1, 2 },
					new int[2] { 0, 1 }
				}.Select(GetCtor).FirstOrDefault((Func<Stream, Encoding, bool, StreamWriter> f) => f != null);
				if (cStreamWriterConstructor == null)
				{
					throw new AmbiguousMatchException("Failed to find suitable constructor for CStreamWriter");
				}
				return cStreamWriterConstructor;
				Func<Stream, Encoding, bool, StreamWriter> GetCtor(int[] perm)
				{
					Type[] parameters = new Type[3]
					{
						typeof(Stream),
						typeof(Encoding),
						typeof(bool)
					};
					ConstructorInfo ctor = AccessTools.Constructor(cStreamWriter, perm.Select((int i) => parameters[i]).ToArray(), false);
					if (ctor != null)
					{
						return delegate(Stream stream, Encoding encoding, bool l)
						{
							object[] vals = new object[3] { stream, encoding, l };
							return (StreamWriter)ctor.Invoke(perm.Select((int i) => vals[i]).ToArray());
						};
					}
					return null;
				}
			}
		}

		public static TextWriter CreateConsoleStreamWriter(Stream stream, Encoding encoding, bool leaveOpen)
		{
			StreamWriter streamWriter = CStreamWriterConstructor(stream, encoding, leaveOpen);
			streamWriter.AutoFlush = true;
			return streamWriter;
		}
	}
	internal class LinuxConsoleDriver : IConsoleDriver
	{
		private static readonly ConfigEntry<bool> ForceCustomTtyDriverConfig;

		public static bool UseMonoTtyDriver { get; }

		public bool StdoutRedirected { get; private set; }

		public TtyInfo TtyInfo { get; private set; }

		public TextWriter StandardOut { get; private set; }

		public TextWriter ConsoleOut { get; private set; }

		public bool ConsoleActive { get; private set; }

		public bool ConsoleIsExternal => false;

		static LinuxConsoleDriver()
		{
			ForceCustomTtyDriverConfig = ConfigFile.CoreConfig.Bind("Logging.Console", "ForceBepInExTTYDriver", defaultValue: false, "If enabled, forces to use custom BepInEx TTY driver for handling terminal output on unix.");
			UseMonoTtyDriver = false;
			if (!ForceCustomTtyDriverConfig.Value && typeof(Console).Assembly.GetType("System.ConsoleDriver") != null)
			{
				UseMonoTtyDriver = typeof(Console).Assembly.GetType("System.ParameterizedStrings") != null;
			}
		}

		public void PreventClose()
		{
		}

		public void Initialize(bool alreadyActive, bool useWinApiEncoder)
		{
			ConsoleActive = true;
			StdoutRedirected = UnixStreamHelper.isatty(1) != 1;
			Stream stream = UnixStreamHelper.CreateDuplicateStream(1);
			if (UseMonoTtyDriver && !StdoutRedirected)
			{
				TextWriter textWriter = ConsoleWriter.CreateConsoleStreamWriter(stream, Console.Out.Encoding, leaveOpen: true);
				StandardOut = TextWriter.Synchronized(textWriter);
				object value = AccessTools.Field(AccessTools.TypeByName("System.ConsoleDriver"), "driver").GetValue(null);
				AccessTools.Field(AccessTools.TypeByName("System.TermInfoDriver"), "stdout").SetValue(value, textWriter);
			}
			else
			{
				StreamWriter streamWriter = new StreamWriter(stream, Console.Out.Encoding);
				streamWriter.AutoFlush = true;
				StandardOut = TextWriter.Synchronized(streamWriter);
				TtyInfo = TtyHandler.GetTtyInfo();
			}
			ConsoleOut = StandardOut;
		}

		public void CreateConsole(uint codepage)
		{
			Logger.Log(LogLevel.Warning, "An external console currently cannot be spawned on a Unix platform.");
		}

		public void DetachConsole()
		{
			throw new PlatformNotSupportedException("Cannot detach console on a Unix platform");
		}

		public void SetConsoleColor(ConsoleColor color)
		{
			if (!StdoutRedirected)
			{
				if (UseMonoTtyDriver)
				{
					SafeConsole.ForegroundColor = color;
				}
				else
				{
					ConsoleOut.Write(TtyInfo.GetAnsiCode(color));
				}
			}
		}

		public void SetConsoleTitle(string title)
		{
			if (!StdoutRedirected)
			{
				if (UseMonoTtyDriver && SafeConsole.TitleExists)
				{
					SafeConsole.Title = title;
				}
				else
				{
					ConsoleOut.Write("\u001b]2;" + title.Replace("\\", "\\\\") + "\a");
				}
			}
		}
	}
	internal class TtyInfo
	{
		public string TerminalType { get; set; } = "default";


		public int MaxColors { get; set; }

		public string[] ForegroundColorStrings { get; set; }

		public static TtyInfo Default { get; } = new TtyInfo
		{
			MaxColors = 0
		};


		public string GetAnsiCode(ConsoleColor color)
		{
			if (MaxColors <= 0 || ForegroundColorStrings == null)
			{
				return string.Empty;
			}
			int num = (int)color % MaxColors;
			return ForegroundColorStrings[num];
		}
	}
	internal static class TtyHandler
	{
		private static readonly string[] ncursesLocations = new string[4] { "/usr/share/terminfo", "/etc/terminfo", "/usr/lib/terminfo", "/lib/terminfo" };

		private static string TryTermInfoDir(string dir, string term)
		{
			string text = $"{dir}/{(int)term[0]:x}/{term}";
			if (File.Exists(text))
			{
				return text;
			}
			text = Utility.CombinePaths(dir, term.Substring(0, 1), term);
			if (File.Exists(text))
			{
				return text;
			}
			return null;
		}

		private static string FindTermInfoPath(string term)
		{
			if (string.IsNullOrEmpty(term))
			{
				return null;
			}
			string environmentVariable = Environment.GetEnvironmentVariable("TERMINFO");
			if (environmentVariable != null && Directory.Exists(environmentVariable))
			{
				string text = TryTermInfoDir(environmentVariable, term);
				if (text != null)
				{
					return text;
				}
			}
			string[] array = ncursesLocations;
			foreach (string text2 in array)
			{
				if (Directory.Exists(text2))
				{
					string text3 = TryTermInfoDir(text2, term);
					if (text3 != null)
					{
						return text3;
					}
				}
			}
			return null;
		}

		public static TtyInfo GetTtyInfo(string terminal = null)
		{
			terminal = terminal ?? Environment.GetEnvironmentVariable("TERM");
			string text = FindTermInfoPath(terminal);
			if (text == null)
			{
				return TtyInfo.Default;
			}
			TtyInfo ttyInfo = TtyInfoParser.Parse(File.ReadAllBytes(text));
			ttyInfo.TerminalType = terminal;
			return ttyInfo;
		}
	}
	internal static class TtyInfoParser
	{
		internal enum TermInfoNumbers
		{
			MaxColors = 13
		}

		internal enum TermInfoStrings
		{
			SetAForeground = 359
		}

		private static readonly int[] ansiColorMapping = new int[16]
		{
			0, 4, 2, 6, 1, 5, 3, 7, 8, 12,
			10, 14, 9, 13, 11, 15
		};

		public static TtyInfo Parse(byte[] buffer)
		{
			int num;
			switch (GetInt16(buffer, 0))
			{
			case 282:
				num = 2;
				break;
			case 542:
				num = 4;
				break;
			default:
				return TtyInfo.Default;
			}
			int @int = GetInt16(buffer, 4);
			GetInt16(buffer, 6);
			GetInt16(buffer, 8);
			int num2 = 12 + GetString(buffer, 12).Length + 1 + @int;
			int offset = num2 + num2 % 2 + num * 13;
			return new TtyInfo
			{
				MaxColors = GetInteger(num, buffer, offset),
				ForegroundColorStrings = ansiColorMapping.Select((int x) => $"\u001b[{((x > 7) ? (82 + x) : (30 + x))}m").ToArray()
			};
		}

		private static int GetInt32(byte[] buffer, int offset)
		{
			return buffer[offset] | (buffer[offset + 1] << 8) | (buffer[offset + 2] << 16) | (buffer[offset + 3] << 24);
		}

		private static short GetInt16(byte[] buffer, int offset)
		{
			return (short)(buffer[offset] | (buffer[offset + 1] << 8));
		}

		private static int GetInteger(int intSize, byte[] buffer, int offset)
		{
			if (intSize != 2)
			{
				return GetInt32(buffer, offset);
			}
			return GetInt16(buffer, offset);
		}

		private static string GetString(byte[] buffer, int offset)
		{
			int i;
			for (i = 0; buffer[offset + i] != 0; i++)
			{
			}
			return Encoding.ASCII.GetString(buffer, offset, i);
		}
	}
	internal class UnixStream : Stream
	{
		public override bool CanRead
		{
			get
			{
				if (Access != FileAccess.Read)
				{
					return Access == FileAccess.ReadWrite;
				}
				return true;
			}
		}

		public override bool CanSeek => false;

		public override bool CanWrite
		{
			get
			{
				if (Access != FileAccess.Write)
				{
					return Access == FileAccess.ReadWrite;
				}
				return true;
			}
		}

		public override long Length
		{
			get
			{
				throw new InvalidOperationException();
			}
		}

		public override long Position
		{
			get
			{
				throw new InvalidOperationException();
			}
			set
			{
				throw new InvalidOperationException();
			}
		}

		public FileAccess Access { get; }

		public IntPtr FileHandle { get; }

		public UnixStream(int fileDescriptor, FileAccess access)
		{
			Access = access;
			int fd = UnixStreamHelper.dup(fileDescriptor);
			FileHandle = UnixStreamHelper.fdopen(fd, (access == FileAccess.Write) ? "w" : "r");
		}

		public override void Flush()
		{
			UnixStreamHelper.fflush(FileHandle);
		}

		public override long Seek(long offset, SeekOrigin origin)
		{
			throw new InvalidOperationException();
		}

		public override void SetLength(long value)
		{
			throw new InvalidOperationException();
		}

		public override int Read(byte[] buffer, int offset, int count)
		{
			GCHandle gCHandle = GCHandle.Alloc(buffer, GCHandleType.Pinned);
			IntPtr intPtr = UnixStreamHelper.fread(new IntPtr(gCHandle.AddrOfPinnedObject().ToInt64() + offset), (IntPtr)count, (IntPtr)1, FileHandle);
			gCHandle.Free();
			return intPtr.ToInt32();
		}

		public override void Write(byte[] buffer, int offset, int count)
		{
			GCHandle gCHandle = GCHandle.Alloc(buffer, GCHandleType.Pinned);
			UnixStreamHelper.fwrite(new IntPtr(gCHandle.AddrOfPinnedObject().ToInt64() + offset), (IntPtr)count, (IntPtr)1, FileHandle);
			gCHandle.Free();
		}

		private void ReleaseUnmanagedResources()
		{
			UnixStreamHelper.fclose(FileHandle);
		}

		protected override void Dispose(bool disposing)
		{
			ReleaseUnmanagedResources();
			base.Dispose(disposing);
		}

		~UnixStream()
		{
			Dispose(disposing: false);
		}
	}
	internal static class UnixStreamHelper
	{
		public delegate int dupDelegate(int fd);

		public delegate int fcloseDelegate(IntPtr stream);

		public delegate IntPtr fdopenDelegate(int fd, string mode);

		public delegate int fflushDelegate(IntPtr stream);

		public delegate IntPtr freadDelegate(IntPtr ptr, IntPtr size, IntPtr nmemb, IntPtr stream);

		public delegate int fwriteDelegate(IntPtr ptr, IntPtr size, IntPtr nmemb, IntPtr stream);

		public delegate int isattyDelegate(int fd);

		[DynDllImport("libc", new string[] { })]
		public static dupDelegate dup;

		[DynDllImport("libc", new string[] { })]
		public static fdopenDelegate fdopen;

		[DynDllImport("libc", new string[] { })]
		public static freadDelegate fread;

		[DynDllImport("libc", new string[] { })]
		public static fwriteDelegate fwrite;

		[DynDllImport("libc", new string[] { })]
		public static fcloseDelegate fclose;

		[DynDllImport("libc", new string[] { })]
		public static fflushDelegate fflush;

		[DynDllImport("libc", new string[] { })]
		public static isattyDelegate isatty;

		static UnixStreamHelper()
		{
			Dictionary<string, List<DynDllMapping>> dictionary = new Dictionary<string, List<DynDllMapping>> { ["libc"] = new List<DynDllMapping>
			{
				DynDllMapping.op_Implicit("libc.so.6"),
				DynDllMapping.op_Implicit("libc"),
				DynDllMapping.op_Implicit("/usr/lib/libSystem.dylib")
			} };
			DynDll.ResolveDynDllImports(typeof(UnixStreamHelper), dictionary);
		}

		public static Stream CreateDuplicateStream(int fileDescriptor)
		{
			return new UnixStream(dup(fileDescriptor), FileAccess.Write);
		}
	}
}
namespace BepInEx.Configuration
{
	public abstract class AcceptableValueBase
	{
		public Type ValueType { get; }

		protected AcceptableValueBase(Type valueType)
		{
			ValueType = valueType;
		}

		public abstract object Clamp(object value);

		public abstract bool IsValid(object value);

		public abstract string ToDescriptionString();
	}
	public class AcceptableValueList<T> : AcceptableValueBase where T : IEquatable<T>
	{
		public virtual T[] AcceptableValues { get; }

		public AcceptableValueList(params T[] acceptableValues)
			: base(typeof(T))
		{
			if (acceptableValues == null)
			{
				throw new ArgumentNullException("acceptableValues");
			}
			if (acceptableValues.Length == 0)
			{
				throw new ArgumentException("At least one acceptable value is needed", "acceptableValues");
			}
			AcceptableValues = acceptableValues;
		}

		public override object Clamp(object value)
		{
			if (IsValid(value))
			{
				return value;
			}
			return AcceptableValues[0];
		}

		public override bool IsValid(object value)
		{
			if (value is T)
			{
				T v = (T)value;
				return AcceptableValues.Any((T x) => x.Equals(v));
			}
			return false;
		}

		public override string ToDescriptionString()
		{
			return "# Acceptable values: " + string.Join(", ", AcceptableValues.Select((T x) => x.ToString()).ToArray());
		}
	}
	public class AcceptableValueRange<T> : AcceptableValueBase where T : IComparable
	{
		public virtual T MinValue { get; }

		public virtual T MaxValue { get; }

		public AcceptableValueRange(T minValue, T maxValue)
			: base(typeof(T))
		{
			if (maxValue == null)
			{
				throw new ArgumentNullException("maxValue");
			}
			if (minValue == null)
			{
				throw new ArgumentNullException("minValue");
			}
			if (minValue.CompareTo(maxValue) >= 0)
			{
				throw new ArgumentException("minValue has to be lower than maxValue");
			}
			MinValue = minValue;
			MaxValue = maxValue;
		}

		public override object Clamp(object value)
		{
			if (MinValue.CompareTo(value) > 0)
			{
				return MinValue;
			}
			if (MaxValue.CompareTo(value) < 0)
			{
				return MaxValue;
			}
			return value;
		}

		public override bool IsValid(object value)
		{
			if (MinValue.CompareTo(value) <= 0)
			{
				return MaxValue.CompareTo(value) >= 0;
			}
			return false;
		}

		public override string ToDescriptionString()
		{
			return $"# Acceptable value range: From {MinValue} to {MaxValue}";
		}
	}
	public class ConfigDefinition : IEquatable<ConfigDefinition>
	{
		private static readonly char[] _invalidConfigChars = new char[8] { '=', '\n', '\t', '\\', '"', '\'', '[', ']' };

		public string Section { get; }

		public string Key { get; }

		public ConfigDefinition(string section, string key)
		{
			CheckInvalidConfigChars(section, "section");
			CheckInvalidConfigChars(key, "key");
			Key = key;
			Section = section;
		}

		[Obsolete("description argument is no longer used, put it in a ConfigDescription instead")]
		public ConfigDefinition(string section, string key, string description)
		{
			Key = key ?? "";
			Section = section ?? "";
		}

		public bool Equals(ConfigDefinition other)
		{
			if (other == null)
			{
				return false;
			}
			if (string.Equals(Key, other.Key))
			{
				return string.Equals(Section, other.Section);
			}
			return false;
		}

		private static void CheckInvalidConfigChars(string val, string name)
		{
			if (val == null)
			{
				throw new ArgumentNullException(name);
			}
			if (val != val.Trim())
			{
				throw new ArgumentException("Cannot use whitespace characters at start or end of section and key names", name);
			}
			if (val.Any((char c) => _invalidConfigChars.Contains(c)))
			{
				throw new ArgumentException("Cannot use any of the following characters in section and key names: = \\n \\t \\ \" ' [ ]", name);
			}
		}

		public override bool Equals(object obj)
		{
			if (obj == null)
			{
				return false;
			}
			if (this == obj)
			{
				return true;
			}
			return Equals(obj as ConfigDefinition);
		}

		public override int GetHashCode()
		{
			return (((Key != null) ? Key.GetHashCode() : 0) * 397) ^ ((Section != null) ? Section.GetHashCode() : 0);
		}

		public static bool operator ==(ConfigDefinition left, ConfigDefinition right)
		{
			return object.Equals(left, right);
		}

		public static bool operator !=(ConfigDefinition left, ConfigDefinition right)
		{
			return !object.Equals(left, right);
		}

		public override string ToString()
		{
			return Section + "." + Key;
		}
	}
	public class ConfigDescription
	{
		public string Description { get; }

		public AcceptableValueBase AcceptableValues { get; }

		public object[] Tags { get; }

		public static ConfigDescription Empty { get; } = new ConfigDescription("", null);


		public ConfigDescription(string description, AcceptableValueBase acceptableValues = null, params object[] tags)
		{
			AcceptableValues = acceptableValues;
			Tags = tags;
			Description = description ?? throw new ArgumentNullException("description");
		}
	}
	public sealed class ConfigEntry<T> : ConfigEntryBase
	{
		private T _typedValue;

		public T Value
		{
			get
			{
				return _typedValue;
			}
			set
			{
				value = ClampValue(value);
				if (!object.Equals(_typedValue, value))
				{
					_typedValue = value;
					OnSettingChanged(this);
				}
			}
		}

		public override object BoxedValue
		{
			get
			{
				return Value;
			}
			set
			{
				Value = (T)value;
			}
		}

		public event EventHandler SettingChanged;

		internal ConfigEntry(ConfigFile configFile, ConfigDefinition definition, T defaultValue, ConfigDescription configDescription)
			: base(configFile, definition, typeof(T), defaultValue, configDescription)
		{
			configFile.SettingChanged += delegate(object sender, SettingChangedEventArgs args)
			{
				if (args.ChangedSetting == this)
				{
					this.SettingChanged?.Invoke(sender, args);
				}
			};
		}
	}
	public abstract class ConfigEntryBase
	{
		public ConfigFile ConfigFile { get; }

		public ConfigDefinition Definition { get; }

		public ConfigDescription Description { get; }

		public Type SettingType { get; }

		public object DefaultValue { get; }

		public abstract object BoxedValue { get; set; }

		protected internal ConfigEntryBase(ConfigFile configFile, ConfigDefinition definition, Type settingType, object defaultValue, ConfigDescription configDescription)
		{
			ConfigFile = configFile ?? throw new ArgumentNullException("configFile");
			Definition = definition ?? throw new ArgumentNullException("definition");
			SettingType = settingType ?? throw new ArgumentNullException("settingType");
			Description = configDescription ?? ConfigDescription.Empty;
			if (Description.AcceptableValues != null && !SettingType.IsAssignableFrom(Description.AcceptableValues.ValueType))
			{
				throw new ArgumentException("configDescription.AcceptableValues is for a different type than the type of this setting");
			}
			DefaultValue = defaultValue;
			BoxedValue = defaultValue;
		}

		public string GetSerializedValue()
		{
			return TomlTypeConverter.ConvertToString(BoxedValue, SettingType);
		}

		public void SetSerializedValue(string value)
		{
			try
			{
				object boxedValue = TomlTypeConverter.ConvertToValue(value, SettingType);
				BoxedValue = boxedValue;
			}
			catch (Exception ex)
			{
				LogLevel logLevel = LogLevel.Warning;
				bool isEnabled;
				BepInExLogInterpolatedStringHandler bepInExLogInterpolatedStringHandler = new BepInExLogInterpolatedStringHandler(85, 3, logLevel, out isEnabled);
				if (isEnabled)
				{
					bepInExLogInterpolatedStringHandler.AppendLiteral("Config value of setting \"");
					bepInExLogInterpolatedStringHandler.AppendFormatted(Definition);
					bepInExLogInterpolatedStringHandler.AppendLiteral("\" could not be parsed and will be ignored. Reason: ");
					bepInExLogInterpolatedStringHandler.AppendFormatted(ex.Message);
					bepInExLogInterpolatedStringHandler.AppendLiteral("; Value: ");
					bepInExLogInterpolatedStringHandler.AppendFormatted(value);
				}
				Logger.Log(logLevel, bepInExLogInterpolatedStringHandler);
			}
		}

		protected T ClampValue<T>(T value)
		{
			if (Description.AcceptableValues != null)
			{
				return (T)Description.AcceptableValues.Clamp(value);
			}
			return value;
		}

		protected void OnSettingChanged(object sender)
		{
			ConfigFile.OnSettingChanged(sender, this);
		}

		public void WriteDescription(StreamWriter writer)
		{
			if (!string.IsNullOrEmpty(Description.Description))
			{
				writer.WriteLine("## " + Description.Description.Replace("\n", "\n## "));
			}
			writer.WriteLine("# Setting type: " + SettingType.Name);
			writer.WriteLine("# Default value: " + TomlTypeConverter.ConvertToString(DefaultValue, SettingType));
			if (Description.AcceptableValues != null)
			{
				writer.WriteLine(Description.AcceptableValues.ToDescriptionString());
			}
			else if (SettingType.IsEnum)
			{
				writer.WriteLine("# Acceptable values: " + string.Join(", ", Enum.GetNames(SettingType)));
				if (SettingType.GetCustomAttributes(typeof(FlagsAttribute), inherit: true).Any())
				{
					writer.WriteLine("# Multiple values can be set at the same time by separating them with , (e.g. Debug, Warning)");
				}
			}
		}
	}
	public class ConfigFile : IDictionary<ConfigDefinition, ConfigEntryBase>, ICollection<KeyValuePair<ConfigDefinition, ConfigEntryBase>>, IEnumerable<KeyValuePair<ConfigDefinition, ConfigEntryBase>>, IEnumerable
	{
		private readonly BepInPlugin _ownerMetadata;

		private readonly object _ioLock = new object();

		public static ConfigFile CoreConfig { get; } = new ConfigFile(Paths.BepInExConfigPath, saveOnInit: true);


		protected Dictionary<ConfigDefinition, ConfigEntryBase> Entries { get; } = new Dictionary<ConfigDefinition, ConfigEntryBase>();


		private Dictionary<ConfigDefinition, string> OrphanedEntries { get; } = new Dictionary<ConfigDefinition, string>();


		[Obsolete("Use Keys instead")]
		public ReadOnlyCollection<ConfigDefinition> ConfigDefinitions
		{
			get
			{
				lock (_ioLock)
				{
					return Entries.Keys.ToList().AsReadOnly();
				}
			}
		}

		public string ConfigFilePath { get; }

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


		public ConfigEntryBase this[ConfigDefinition key]
		{
			get
			{
				lock (_ioLock)
				{
					return Entries[key];
				}
			}
		}

		public ConfigEntryBase this[string section, string key] => this[new ConfigDefinition(section, key)];

		public int Count
		{
			get
			{
				lock (_ioLock)
				{
					return Entries.Count;
				}
			}
		}

		public bool IsReadOnly => false;

		ConfigEntryBase IDictionary<ConfigDefinition, ConfigEntryBase>.this[ConfigDefinition key]
		{
			get
			{
				lock (_ioLock)
				{
					return Entries[key];
				}
			}
			set
			{
				throw new InvalidOperationException("Directly setting a config entry is not supported");
			}
		}

		public ICollection<ConfigDefinition> Keys
		{
			get
			{
				lock (_ioLock)
				{
					return Entries.Keys.ToArray();
				}
			}
		}

		public ICollection<ConfigEntryBase> Values
		{
			get
			{
				lock (_ioLock)
				{
					return Entries.Values.ToArray();
				}
			}
		}

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


		public event EventHandler ConfigReloaded;

		public event EventHandler<SettingChangedEventArgs> SettingChanged;

		public ConfigFile(string configPath, bool saveOnInit)
			: this(configPath, saveOnInit, null)
		{
		}

		public ConfigFile(string configPath, bool saveOnInit, BepInPlugin ownerMetadata)
		{
			_ownerMetadata = ownerMetadata;
			if (configPath == null)
			{
				throw new ArgumentNullException("configPath");
			}
			configPath = Path.GetFullPath(configPath);
			ConfigFilePath = configPath;
			if (File.Exists(ConfigFilePath))
			{
				Reload();
			}
			else if (saveOnInit)
			{
				Save();
			}
		}

		public IEnumerator<KeyValuePair<ConfigDefinition, ConfigEntryBase>> GetEnumerator()
		{
			return Entries.GetEnumerator();
		}

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

		void ICollection<KeyValuePair<ConfigDefinition, ConfigEntryBase>>.Add(KeyValuePair<ConfigDefinition, ConfigEntryBase> item)
		{
			lock (_ioLock)
			{
				Entries.Add(item.Key, item.Value);
			}
		}

		public bool Contains(KeyValuePair<ConfigDefinition, ConfigEntryBase> item)
		{
			lock (_ioLock)
			{
				return ((ICollection<KeyValuePair<ConfigDefinition, ConfigEntryBase>>)Entries).Contains(item);
			}
		}

		void ICollection<KeyValuePair<ConfigDefinition, ConfigEntryBase>>.CopyTo(KeyValuePair<ConfigDefinition, ConfigEntryBase>[] array, int arrayIndex)
		{
			lock (_ioLock)
			{
				((ICollection<KeyValuePair<ConfigDefinition, ConfigEntryBase>>)Entries).CopyTo(array, arrayIndex);
			}
		}

		bool ICollection<KeyValuePair<ConfigDefinition, ConfigEntryBase>>.Remove(KeyValuePair<ConfigDefinition, ConfigEntryBase> item)
		{
			lock (_ioLock)
			{
				return Entries.Remove(item.Key);
			}
		}

		public bool ContainsKey(ConfigDefinition key)
		{
			lock (_ioLock)
			{
				return Entries.ContainsKey(key);
			}
		}

		public void Add(ConfigDefinition key, ConfigEntryBase value)
		{
			throw new InvalidOperationException("Directly adding a config entry is not supported");
		}

		public bool Remove(ConfigDefinition key)
		{
			lock (_ioLock)
			{
				return Entries.Remove(key);
			}
		}

		public void Clear()
		{
			lock (_ioLock)
			{
				Entries.Clear();
			}
		}

		bool IDictionary<ConfigDefinition, ConfigEntryBase>.TryGetValue(ConfigDefinition key, out ConfigEntryBase value)
		{
			lock (_ioLock)
			{
				return Entries.TryGetValue(key, out value);
			}
		}

		[Obsolete("Use Values instead")]
		public ConfigEntryBase[] GetConfigEntries()
		{
			lock (_ioLock)
			{
				return Entries.Values.ToArray();
			}
		}

		public void Reload()
		{
			lock (_ioLock)
			{
				OrphanedEntries.Clear();
				string section = string.Empty;
				string[] array = File.ReadAllLines(ConfigFilePath);
				for (int i = 0; i < array.Length; i++)
				{
					string text = array[i].Trim();
					if (text.StartsWith("#"))
					{
						continue;
					}
					if (text.StartsWith("[") && text.EndsWith("]"))
					{
						section = text.Substring(1, text.Length - 2);
						continue;
					}
					string[] array2 = text.Split(new char[1] { '=' }, 2);
					if (array2.Length == 2)
					{
						string key = array2[0].Trim();
						string text2 = array2[1].Trim();
						ConfigDefinition key2 = new ConfigDefinition(section, key);
						Entries.TryGetValue(key2, out var value);
						if (value != null)
						{
							value.SetSerializedValue(text2);
						}
						else
						{
							OrphanedEntries[key2] = text2;
						}
					}
				}
			}
			OnConfigReloaded();
		}

		public void Save()
		{
			lock (_ioLock)
			{
				string directoryName = Path.GetDirectoryName(ConfigFilePath);
				if (directoryName != null)
				{
					Directory.CreateDirectory(directoryName);
				}
				using StreamWriter streamWriter = new StreamWriter(ConfigFilePath, append: false, Utility.UTF8NoBom);
				if (_ownerMetadata != null)
				{
					streamWriter.WriteLine($"## Settings file was created by plugin {_ownerMetadata.Name} v{_ownerMetadata.Version}");
					streamWriter.WriteLine("## Plugin GUID: " + _ownerMetadata.GUID);
					streamWriter.WriteLine();
				}
				foreach (var item in from x in Entries.Select((KeyValuePair<ConfigDefinition, ConfigEntryBase> x) => new
					{
						Key = x.Key,
						entry = x.Value,
						value = x.Value.GetSerializedValue()
					}).Concat(OrphanedEntries.Select((KeyValuePair<ConfigDefinition, string> x) => new
					{
						Key = x.Key,
						entry = (ConfigEntryBase)null,
						value = x.Value
					}))
					group x by x.Key.Section into x
					orderby x.Key
					select x)
				{
					streamWriter.WriteLine("[" + item.Key + "]");
					foreach (var item2 in item)
					{
						if (GenerateSettingDescriptions)
						{
							streamWriter.WriteLine();
							item2.entry?.WriteDescription(streamWriter);
						}
						streamWriter.WriteLine(item2.Key.Key + " = " + item2.value);
					}
					streamWriter.WriteLine();
				}
			}
		}

		[Obsolete("Use ConfigFile[key] or TryGetEntry instead")]
		public ConfigEntry<T> GetSetting<T>(ConfigDefinition configDefinition)
		{
			if (!TryGetEntry(configDefinition, out ConfigEntry<T> entry))
			{
				return null;
			}
			return entry;
		}

		[Obsolete("Use ConfigFile[key] or TryGetEntry instead")]
		public ConfigEntry<T> GetSetting<T>(string section, string key)
		{
			if (!TryGetEntry(section, key, out ConfigEntry<T> entry))
			{
				return null;
			}
			return entry;
		}

		public bool TryGetEntry<T>(ConfigDefinition configDefinition, out ConfigEntry<T> entry)
		{
			lock (_ioLock)
			{
				if (Entries.TryGetValue(configDefinition, out var value))
				{
					entry = (ConfigEntry<T>)value;
					return true;
				}
				entry = null;
				return false;
			}
		}

		public bool TryGetEntry<T>(string section, string key, out ConfigEntry<T> entry)
		{
			return TryGetEntry(new ConfigDefinition(section, key), out entry);
		}

		public ConfigEntry<T> Bind<T>(ConfigDefinition configDefinition, T defaultValue, ConfigDescription configDescription = null)
		{
			if (!TomlTypeConverter.CanConvert(typeof(T)))
			{
				throw new ArgumentException(string.Format("Type {0} is not supported by the config system. Supported types: {1}", typeof(T), string.Join(", ", (from x in TomlTypeConverter.GetSupportedTypes()
					select x.Name).ToArray())));
			}
			lock (_ioLock)
			{
				if (Entries.TryGetValue(configDefinition, out var value))
				{
					return (ConfigEntry<T>)value;
				}
				ConfigEntry<T> configEntry = new ConfigEntry<T>(this, configDefinition, defaultValue, configDescription);
				Entries[configDefinition] = configEntry;
				if (OrphanedEntries.TryGetValue(configDefinition, out var value2))
				{
					configEntry.SetSerializedValue(value2);
					OrphanedEntries.Remove(configDefinition);
				}
				if (SaveOnConfigSet)
				{
					Save();
				}
				return configEntry;
			}
		}

		public ConfigEntry<T> Bind<T>(string section, string key, T defaultValue, ConfigDescription configDescription = null)
		{
			return Bind(new ConfigDefinition(section, key), defaultValue, configDescription);
		}

		public ConfigEntry<T> Bind<T>(string section, string key, T defaultValue, string description)
		{
			return Bind(new ConfigDefinition(section, key), defaultValue, new ConfigDescription(description, null));
		}

		[Obsolete("Use Bind instead")]
		public ConfigEntry<T> AddSetting<T>(ConfigDefinition configDefinition, T defaultValue, ConfigDescription configDescription = null)
		{
			return Bind(configDefinition, defaultValue, configDescription);
		}

		[Obsolete("Use Bind instead")]
		public ConfigEntry<T> AddSetting<T>(string section, string key, T defaultValue, ConfigDescription configDescription = null)
		{
			return Bind(new ConfigDefinition(section, key), defaultValue, configDescription);
		}

		[Obsolete("Use Bind instead")]
		public ConfigEntry<T> AddSetting<T>(string section, string key, T defaultValue, string description)
		{
			return Bind(new ConfigDefinition(section, key), defaultValue, new ConfigDescription(description, null));
		}

		[Obsolete("Use Bind instead")]
		public ConfigWrapper<T> Wrap<T>(string section, string key, string description = null, T defaultValue = default(T))
		{
			lock (_ioLock)
			{
				ConfigDefinition configDefinition = new ConfigDefinition(section, key, description);
				return new ConfigWrapper<T>(Bind(configDefinition, defaultValue, string.IsNullOrEmpty(description) ? null : new ConfigDescription(description, null)));
			}
		}

		[Obsolete("Use Bind instead")]
		public ConfigWrapper<T> Wrap<T>(ConfigDefinition configDefinition, T defaultValue = default(T))
		{
			return Wrap(configDefinition.Section, configDefinition.Key, null, defaultValue);
		}

		internal void OnSettingChanged(object sender, ConfigEntryBase changedEntryBase)
		{
			if (changedEntryBase == null)
			{
				throw new ArgumentNullException("changedEntryBase");
			}
			if (SaveOnConfigSet)
			{
				Save();
			}
			EventHandler<SettingChangedEventArgs> settingChanged = this.SettingChanged;
			if (settingChanged == null)
			{
				return;
			}
			SettingChangedEventArgs e = new SettingChangedEventArgs(changedEntryBase);
			Delegate[] invocationList = settingChanged.GetInvocationList();
			for (int i = 0; i < invocationList.Length; i++)
			{
				EventHandler<SettingChangedEventArgs> eventHandler = (EventHandler<SettingChangedEventArgs>)invocationList[i];
				try
				{
					eventHandler(sender, e);
				}
				catch (Exception data)
				{
					Logger.Log(LogLevel.Error, data);
				}
			}
		}

		private void OnConfigReloaded()
		{
			EventHandler configReloaded = this.ConfigReloaded;
			if (configReloaded == null)
			{
				return;
			}
			Delegate[] invocationList = configReloaded.GetInvocationList();
			for (int i = 0; i < invocationList.Length; i++)
			{
				EventHandler eventHandler = (EventHandler)invocationList[i];
				try
				{
					eventHandler(this, EventArgs.Empty);
				}
				catch (Exception data)
				{
					Logger.Log(LogLevel.Error, data);
				}
			}
		}
	}
	[Obsolete("Use ConfigFile from new Bind overloads instead")]
	public sealed class ConfigWrapper<T>
	{
		public ConfigEntry<T> ConfigEntry { get; }

		public ConfigDefinition Definition => ConfigEntry.Definition;

		public ConfigFile ConfigFile => ConfigEntry.ConfigFile;

		public T Value
		{
			get
			{
				return ConfigEntry.Value;
			}
			set
			{
				ConfigEntry.Value = value;
			}
		}

		public event EventHandler SettingChanged;

		internal ConfigWrapper(ConfigEntry<T> configEntry)
		{
			ConfigWrapper<T> configWrapper = this;
			ConfigEntry = configEntry ?? throw new ArgumentNullException("configEntry");
			configEntry.ConfigFile.SettingChanged += delegate(object sender, SettingChangedEventArgs args)
			{
				if (args.ChangedSetting == configEntry)
				{
					configWrapper.SettingChanged?.Invoke(sender, args);
				}
			};
		}
	}
	public sealed class SettingChangedEventArgs : EventArgs
	{
		public ConfigEntryBase ChangedSetting { get; }

		public SettingChangedEventArgs(ConfigEntryBase changedSetting)
		{
			ChangedSetting = changedSetting;
		}
	}
	public static class TomlTypeConverter
	{
		private static Dictionary<Type, TypeConverter> TypeConverters { get; } = new Dictionary<Type, TypeConverter>
		{
			[typeof(string)] = new TypeConverter
			{
				ConvertToString = (object obj, Type type) => ((string)obj).Escape(),
				ConvertToObject = (string str, Type type) => Regex.IsMatch(str, "^\"?\\w:\\\\(?!\\\\)(?!.+\\\\\\\\)") ? str : str.Unescape()
			},
			[typeof(bool)] = new TypeConverter
			{
				ConvertToString = (object obj, Type type) => obj.ToString().ToLowerInvariant(),
				ConvertToObject = (string str, Type type) => bool.Parse(str)
			},
			[typeof(byte)] = new TypeConverter
			{
				ConvertToString = (object obj, Type type) => obj.ToString(),
				ConvertToObject = (string str, Type type) => byte.Parse(str)
			},
			[typeof(sbyte)] = new TypeConverter
			{
				ConvertToString = (object obj, Type type) => obj.ToString(),
				ConvertToObject = (string str, Type type) => sbyte.Parse(str)
			},
			[typeof(byte)] = new TypeConverter
			{
				ConvertToString = (object obj, Type type) => obj.ToString(),
				ConvertToObject = (string str, Type type) => byte.Parse(str)
			},
			[typeof(short)] = new TypeConverter
			{
				ConvertToString = (object obj, Type type) => obj.ToString(),
				ConvertToObject = (string str, Type type) => short.Parse(str)
			},
			[typeof(ushort)] = new TypeConverter
			{
				ConvertToString = (object obj, Type type) => obj.ToString(),
				ConvertToObject = (string str, Type type) => ushort.Parse(str)
			},
			[typeof(int)] = new TypeConverter
			{
				ConvertToString = (object obj, Type type) => obj.ToString(),
				ConvertToObject = (string str, Type type) => int.Parse(str)
			},
			[typeof(uint)] = new TypeConverter
			{
				ConvertToString = (object obj, Type type) => obj.ToString(),
				ConvertToObject = (string str, Type type) => uint.Parse(str)
			},
			[typeof(long)] = new TypeConverter
			{
				ConvertToString = (object obj, Type type) => obj.ToString(),
				ConvertToObject = (string str, Type type) => long.Parse(str)
			},
			[typeof(ulong)] = new TypeConverter
			{
				ConvertToString = (object obj, Type type) => obj.ToString(),
				ConvertToObject = (string str, Type type) => ulong.Parse(str)
			},
			[typeof(float)] = new TypeConverter
			{
				ConvertToString = (object obj, Type type) => ((float)obj).ToString(NumberFormatInfo.InvariantInfo),
				ConvertToObject = (string str, Type type) => float.Parse(str, NumberFormatInfo.InvariantInfo)
			},
			[typeof(double)] = new TypeConverter
			{
				ConvertToString = (object obj, Type type) => ((double)obj).ToString(NumberFormatInfo.InvariantInfo),
				ConvertToObject = (string str, Type type) => double.Parse(str, NumberFormatInfo.InvariantInfo)
			},
			[typeof(decimal)] = new TypeConverter
			{
				ConvertToString = (object obj, Type type) => ((decimal)obj).ToString(NumberFormatInfo.InvariantInfo),
				ConvertToObject = (string str, Type type) => decimal.Parse(str, NumberFormatInfo.InvariantInfo)
			},
			[typeof(Enum)] = new TypeConverter
			{
				ConvertToString = (object obj, Type type) => obj.ToString(),
				ConvertToObject = (string str, Type type) => Enum.Parse(type, str, ignoreCase: true)
			}
		};


		public static string ConvertToString(object value, Type valueType)
		{
			return (GetConverter(valueType) ?? throw new InvalidOperationException($"Cannot convert from type {valueType}")).ConvertToString(value, valueType);
		}

		public static T ConvertToValue<T>(string value)
		{
			return (T)ConvertToValue(value, typeof(T));
		}

		public static object ConvertToValue(string value, Type valueType)
		{
			return (GetConverter(valueType) ?? throw new InvalidOperationException("Cannot convert to type " + valueType.Name)).ConvertToObject(value, valueType);
		}

		public static TypeConverter GetConverter(Type valueType)
		{
			if (valueType == null)
			{
				throw new ArgumentNullException("valueType");
			}
			if (valueType.IsEnum)
			{
				return TypeConverters[typeof(Enum)];
			}
			TypeConverters.TryGetValue(valueType, out var value);
			return value;
		}

		public static bool AddConverter(Type type, TypeConverter converter)
		{
			if (type == null)
			{
				throw new ArgumentNullException("type");
			}
			if (converter == null)
			{
				throw new ArgumentNullException("converter");
			}
			if (CanConvert(type))
			{
				Logger.Log(LogLevel.Warning, "Tried to add a TomlConverter when one already exists for type " + type.FullName);
				return false;
			}
			TypeConverters.Add(type, converter);
			return true;
		}

		public static bool CanConvert(Type type)
		{
			return GetConverter(type) != null;
		}

		public static IEnumerable<Type> GetSupportedTypes()
		{
			return TypeConverters.Keys;
		}

		private static string Escape(this string txt)
		{
			if (string.IsNullOrEmpty(txt))
			{
				return string.Empty;
			}
			StringBuilder stringBuilder = new StringBuilder(txt.Length + 2);
			foreach (char c in txt)
			{
				switch (c)
				{
				case '\0':
					stringBuilder.Append("\\0");
					break;
				case '\a':
					stringBuilder.Append("\\a");
					break;
				case '\b':
					stringBuilder.Append("\\b");
					break;
				case '\t':
					stringBuilder.Append("\\t");
					break;
		

BepInExPack/BepInEx/core/BepInEx.IL2CPP.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Net.Http;
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.Cryptography;
using System.Security.Permissions;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using AssemblyUnhollower;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.IL2CPP.Hook;
using BepInEx.IL2CPP.Hook.Allocator;
using BepInEx.IL2CPP.Logging;
using BepInEx.IL2CPP.Utils;
using BepInEx.IL2CPP.Utils.Collections;
using BepInEx.Logging;
using BepInEx.Preloader.Core;
using BepInEx.Preloader.Core.Logging;
using BepInEx.Preloader.Core.Patching;
using BepInEx.Preloader.RuntimeFixes;
using BepInEx.Shared;
using Cpp2IL.Core;
using HarmonyLib;
using HarmonyLib.Public.Patching;
using Iced.Intel;
using Il2Cpp.TlsAdapter;
using Il2CppDumper;
using Il2CppSystem;
using Il2CppSystem.Collections;
using LibCpp2IL;
using Microsoft.CodeAnalysis;
using Mono.Cecil;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using MonoMod.RuntimeDetour;
using MonoMod.Utils;
using UnhollowerBaseLib;
using UnhollowerBaseLib.Runtime;
using UnhollowerBaseLib.Runtime.VersionSpecific.MethodInfo;
using UnhollowerRuntimeLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = "")]
[assembly: BuildInfo("BLEEDING EDGE Build #577 from ec79ad057b20c302c17b34e63906ee398352d852 at master")]
[assembly: AssemblyCompany("BepInEx")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyCopyright("Copyright © 2021 BepInEx Team")]
[assembly: AssemblyDescription("BepInEx support library for Il2Cpp games")]
[assembly: AssemblyFileVersion("6.0.0.577")]
[assembly: AssemblyInformationalVersion("6.0.0-be.577")]
[assembly: AssemblyProduct("BepInEx.IL2CPP")]
[assembly: AssemblyTitle("BepInEx.IL2CPP")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("6.0.0.577")]
[module: UnverifiableCode]
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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NativeIntegerAttribute : Attribute
	{
		public readonly bool[] TransformFlags;

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

		public NativeIntegerAttribute(bool[] P_0)
		{
			TransformFlags = P_0;
		}
	}
}
namespace BepInEx
{
	public static class MonoExtensions
	{
		[MethodImpl(MethodImplOptions.InternalCall)]
		private static extern IntPtr GetFunctionPointerForDelegateInternal2(Delegate d, CallingConvention conv);

		public static IntPtr GetFunctionPointerForDelegate(Delegate d, CallingConvention conv)
		{
			if ((object)d == null)
			{
				throw new ArgumentNullException("d");
			}
			return GetFunctionPointerForDelegateInternal2(d, conv);
		}
	}
}
namespace BepInEx.Shared
{
	[AttributeUsage(AttributeTargets.Assembly)]
	public class BuildInfoAttribute : Attribute
	{
		public string Info { get; }

		public BuildInfoAttribute(string info)
		{
			Info = info;
		}
	}
}
namespace BepInEx.IL2CPP
{
	public abstract class BasePlugin
	{
		public ManualLogSource Log { get; }

		public ConfigFile Config { get; }

		protected BasePlugin()
		{
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Expected O, but got Unknown
			BepInPlugin metadata = MetadataHelper.GetMetadata((object)this);
			Log = Logger.CreateLogSource(metadata.Name);
			Config = new ConfigFile(Utility.CombinePaths(new string[2]
			{
				Paths.ConfigPath,
				metadata.GUID + ".cfg"
			}), false, metadata);
		}

		public abstract void Load();

		public virtual bool Unload()
		{
			return false;
		}

		public T AddComponent<T>() where T : Il2CppObjectBase
		{
			return IL2CPPChainloader.AddUnityComponent<T>();
		}
	}
	internal static class UnityPreloaderRunner
	{
		public static void PreloaderMain(string[] args)
		{
			string directoryName = Path.GetDirectoryName(Path.GetDirectoryName(Path.GetFullPath(EnvVars.DOORSTOP_INVOKE_DLL_PATH)));
			PlatformUtils.SetPlatform();
			Paths.SetExecutablePath(EnvVars.DOORSTOP_PROCESS_PATH, directoryName, EnvVars.DOORSTOP_MANAGED_FOLDER_DIR, EnvVars.DOORSTOP_DLL_SEARCH_DIRS);
			Utility.AddCecilPlatformAssemblies(AppDomain.CurrentDomain, Paths.ManagedPath);
			AppDomain.CurrentDomain.AssemblyResolve += LocalResolve;
			AppDomain.CurrentDomain.AssemblyResolve -= DoorstopEntrypoint.ResolveCurrentDirectory;
			Preloader.Run();
		}

		internal static Assembly LocalResolve(object sender, ResolveEventArgs args)
		{
			AssemblyName assemblyName = new AssemblyName(args.Name);
			Assembly assembly = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault((Assembly x) => x.GetName().Name == assemblyName.Name);
			if (assembly != null)
			{
				return assembly;
			}
			if (Utility.TryResolveDllAssembly(assemblyName, Paths.BepInExAssemblyDirectory, ref assembly) || Utility.TryResolveDllAssembly(assemblyName, Paths.PatcherPluginPath, ref assembly) || Utility.TryResolveDllAssembly(assemblyName, Paths.PluginPath, ref assembly) || Utility.TryResolveDllAssembly(assemblyName, Preloader.IL2CPPUnhollowedPath, ref assembly))
			{
				return assembly;
			}
			return null;
		}
	}
	internal static class DoorstopEntrypoint
	{
		private static string preloaderPath;

		public static void Main(string[] args)
		{
			string text = $"preloader_{DateTime.Now:yyyyMMdd_HHmmss_fff}.log";
			Mutex mutex = null;
			try
			{
				EnvVars.LoadVars();
				text = Path.Combine(Path.GetDirectoryName(EnvVars.DOORSTOP_PROCESS_PATH), text);
				preloaderPath = Path.GetDirectoryName(Path.GetFullPath(EnvVars.DOORSTOP_INVOKE_DLL_PATH));
				mutex = new Mutex(initiallyOwned: false, Process.GetCurrentProcess().ProcessName + EnvVars.DOORSTOP_PROCESS_PATH + typeof(DoorstopEntrypoint).FullName);
				mutex.WaitOne();
				AppDomain.CurrentDomain.AssemblyResolve += ResolveCurrentDirectory;
				UnityPreloaderRunner.PreloaderMain(args);
			}
			catch (Exception ex)
			{
				File.WriteAllText(text, ex.ToString());
			}
			finally
			{
				mutex?.ReleaseMutex();
			}
		}

		public static Assembly ResolveCurrentDirectory(object sender, ResolveEventArgs args)
		{
			AssemblyName assemblyName = new AssemblyName(args.Name);
			try
			{
				return Assembly.LoadFile(Path.Combine(preloaderPath, assemblyName.Name + ".dll"));
			}
			catch (Exception)
			{
				return null;
			}
		}
	}
	public static class DetourGenerator
	{
		private sealed class CodeWriterImpl : CodeWriter
		{
			private readonly List<byte> allBytes = new List<byte>();

			public override void WriteByte(byte value)
			{
				allBytes.Add(value);
			}

			public byte[] ToArray()
			{
				return allBytes.ToArray();
			}
		}

		private static ManualLogSource logger = Logger.CreateLogSource("DetourGen");

		public static void Disassemble(ManualLogSource logSource, IntPtr memoryPtr, int size)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Expected O, but got Unknown
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Invalid comparison between Unknown and I4
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Expected O, but got Unknown
			byte[] array = new byte[size];
			Marshal.Copy(memoryPtr, array, 0, size);
			NasmFormatter val = new NasmFormatter();
			StringOutput val2 = new StringOutput();
			ByteArrayCodeReader val3 = new ByteArrayCodeReader(array);
			Decoder val4 = Decoder.Create(64, (CodeReader)(object)val3, (DecoderOptions)0);
			val4.IP = (ulong)memoryPtr.ToInt64();
			Instruction val5 = default(Instruction);
			bool flag = default(bool);
			while (val3.CanReadByte)
			{
				val4.Decode(ref val5);
				((Formatter)val).Format(ref val5, (FormatterOutput)(object)val2);
				BepInExDebugLogInterpolatedStringHandler val6 = new BepInExDebugLogInterpolatedStringHandler(1, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val6).AppendFormatted<ulong>(((Instruction)(ref val5)).IP, "X16");
					((BepInExLogInterpolatedStringHandler)val6).AppendLiteral(" ");
					((BepInExLogInterpolatedStringHandler)val6).AppendFormatted<string>(val2.ToStringAndReset());
				}
				logSource.LogDebug(val6);
				if ((int)((Instruction)(ref val5)).Code == 765 && ((Instruction)(ref val5)).Immediate32 == 0)
				{
					byte[] array2 = new byte[8];
					for (int i = 0; i < 8; i++)
					{
						array2[i] = (byte)((CodeReader)val3).ReadByte();
					}
					val6 = new BepInExDebugLogInterpolatedStringHandler(6, 2, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val6).AppendFormatted<ulong>(((Instruction)(ref val5)).IP + (ulong)((Instruction)(ref val5)).Length, "X16");
						((BepInExLogInterpolatedStringHandler)val6).AppendLiteral(" db 0x");
						((BepInExLogInterpolatedStringHandler)val6).AppendFormatted<ulong>(BitConverter.ToUInt64(array2, 0), "X16");
					}
					logSource.LogDebug(val6);
					val4.IP += 8;
				}
			}
		}

		public static int GetDetourLength(Architecture arch)
		{
			if (arch != Architecture.X64)
			{
				return 5;
			}
			return 14;
		}

		public static void ApplyDetour(IntPtr functionPtr, IntPtr detourPtr, Architecture architecture, int minimumLength = 0)
		{
			byte[] array = GenerateAbsoluteJump(detourPtr, functionPtr, architecture);
			Marshal.Copy(array, 0, functionPtr, array.Length);
			for (int i = array.Length; i < minimumLength; i++)
			{
				Marshal.WriteByte(functionPtr + i, 144);
			}
		}

		public static IntPtr CreateTrampolineFromFunction(IntPtr originalFuncPointer, out int trampolineLength, out int jmpLength)
		{
			byte[] array = new byte[32];
			Marshal.Copy(originalFuncPointer, array, 0, 32);
			nint num = PageAllocator.Instance.Allocate(originalFuncPointer);
			DetourHelper.Native.MakeWritable((IntPtr)num, 4096u);
			Architecture arch = ((IntPtr.Size == 8) ? Architecture.X64 : Architecture.X86);
			int detourLength = GetDetourLength(arch);
			CreateTrampolineFromFunction(array, originalFuncPointer, num, detourLength, arch, out trampolineLength, out jmpLength);
			DetourHelper.Native.MakeExecutable(originalFuncPointer, 32u);
			DetourHelper.Native.MakeExecutable((IntPtr)num, 4096u);
			return num;
		}

		public static void CreateTrampolineFromFunction(byte[] instructionBuffer, IntPtr functionPtr, IntPtr trampolinePtr, int minimumTrampolineLength, Architecture arch, out int trampolineLength, out int jmpLength)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Expected O, but got Unknown
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Invalid comparison between Unknown and I4
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Expected I4, but got Unknown
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Invalid comparison between Unknown and I4
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Invalid comparison between Unknown and I4
			ByteArrayCodeReader val = new ByteArrayCodeReader(instructionBuffer);
			Decoder val2 = Decoder.Create((arch == Architecture.X64) ? 64 : 32, (CodeReader)(object)val, (DecoderOptions)0);
			val2.IP = (ulong)functionPtr.ToInt64();
			uint num = 0u;
			InstructionList val3 = new InstructionList();
			bool flag = false;
			Instruction val4 = default(Instruction);
			while (val.CanReadByte)
			{
				val2.Decode(ref val4);
				((object)(Instruction)(ref val4)).ToString();
				if (!flag)
				{
					val3.Add(ref val4);
				}
				num += (uint)((Instruction)(ref val4)).Length;
				if ((int)((Instruction)(ref val4)).Code == 0)
				{
					throw new Exception("Found garbage");
				}
				if (num >= minimumTrampolineLength)
				{
					break;
				}
				if (flag)
				{
					if ((int)((Instruction)(ref val4)).Mnemonic != 1620 && (int)((Instruction)(ref val4)).Mnemonic != 465)
					{
						throw new Exception("Function is too short to hook");
					}
					continue;
				}
				FlowControl flowControl = ((Instruction)(ref val4)).FlowControl;
				switch ((int)flowControl)
				{
				case 4:
					flag = true;
					break;
				default:
				{
					FlowControl flowControl2 = ((Instruction)(ref val4)).FlowControl;
					throw new Exception("Not supported yet - " + ((object)(FlowControl)(ref flowControl2)).ToString());
				}
				case 0:
				case 1:
				case 2:
				case 3:
				case 7:
					break;
				}
			}
			if (num < minimumTrampolineLength)
			{
				throw new Exception("Not enough bytes!");
			}
			if (val3.Count == 0)
			{
				throw new Exception("Not enough instructions!");
			}
			ref Instruction reference = ref val3[val3.Count - 1];
			if ((int)((Instruction)(ref reference)).FlowControl != 4)
			{
				Instruction val5 = ((arch != Architecture.X64) ? Instruction.CreateBranch((Code)695, ((Instruction)(ref reference)).NextIP) : Instruction.CreateBranch((Code)696, ((Instruction)(ref reference)).NextIP));
				val3.Add(ref val5);
			}
			CodeWriterImpl codeWriterImpl = new CodeWriterImpl();
			ulong num2 = (ulong)(long)trampolinePtr;
			InstructionBlock val6 = default(InstructionBlock);
			((InstructionBlock)(ref val6))..ctor((CodeWriter)(object)codeWriterImpl, (IList<Instruction>)val3, num2);
			string message = default(string);
			BlockEncoderResult val7 = default(BlockEncoderResult);
			if (!BlockEncoder.TryEncode(val2.Bitness, val6, ref message, ref val7, (BlockEncoderOptions)0))
			{
				throw new Exception(message);
			}
			byte[] array = codeWriterImpl.ToArray();
			Marshal.Copy(array, 0, trampolinePtr, array.Length);
			jmpLength = array.Length - (int)num;
			trampolineLength = array.Length;
		}

		public static byte[] GenerateAbsoluteJump(IntPtr targetAddress, IntPtr currentAddress, Architecture arch)
		{
			byte[] array;
			if (arch == Architecture.X64)
			{
				array = new byte[14]
				{
					255, 37, 0, 0, 0, 0, 0, 0, 0, 0,
					0, 0, 0, 0
				};
				Array.Copy(BitConverter.GetBytes(targetAddress.ToInt64()), 0, array, 6, 8);
			}
			else
			{
				array = new byte[5] { 233, 0, 0, 0, 0 };
				Array.Copy(BitConverter.GetBytes(targetAddress.ToInt32() - (currentAddress.ToInt32() + 5)), 0, array, 1, 4);
			}
			return array;
		}
	}
	public class IL2CPPChainloader : BaseChainloader<BasePlugin>
	{
		[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
		private delegate IntPtr RuntimeInvokeDetourDelegate(IntPtr method, IntPtr obj, IntPtr parameters, IntPtr exc);

		[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
		private delegate void InstallUnityTlsInterfaceDelegate(IntPtr unityTlsInterfaceStruct);

		private static RuntimeInvokeDetourDelegate originalInvoke;

		private static InstallUnityTlsInterfaceDelegate originalInstallUnityTlsInterface;

		private static readonly ConfigEntry<bool> ConfigUnityLogging = ConfigFile.CoreConfig.Bind<bool>("Logging", "UnityLogListening", true, "Enables showing unity log messages in the BepInEx logging system.");

		private static readonly ConfigEntry<bool> ConfigDiskWriteUnityLog = ConfigFile.CoreConfig.Bind<bool>("Logging.Disk", "WriteUnityLog", false, "Include unity log messages in log file output.");

		private static FastNativeDetour RuntimeInvokeDetour { get; set; }

		private static FastNativeDetour InstallUnityTlsInterfaceDetour { get; set; }

		public static IL2CPPChainloader Instance { get; set; }

		public static T AddUnityComponent<T>() where T : Il2CppObjectBase
		{
			return AddUnityComponent(typeof(T)).Cast<T>();
		}

		public static Il2CppObjectBase AddUnityComponent(Type t)
		{
			return Il2CppUtils.AddComponent(t);
		}

		public override void Initialize(string gameExePath = null)
		{
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Expected O, but got Unknown
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			GeneratedDatabasesUtil.DatabasesLocationOverride = Preloader.IL2CPPUnhollowedPath;
			PatchManager.ResolvePatcher += IL2CPPDetourMethodPatcher.TryResolve;
			base.Initialize(gameExePath);
			Instance = this;
			ClassInjector.Detour = (IManagedDetour)(object)new UnhollowerDetourHandler();
			ProcessModule processModule = Process.GetCurrentProcess().Modules.Cast<ProcessModule>().FirstOrDefault((ProcessModule x) => x.ModuleName.Contains("GameAssembly") || x.ModuleName.Contains("UserAssembly"));
			if (processModule == null)
			{
				Logger.Log((LogLevel)1, (object)"Could not locate Il2Cpp game assembly (GameAssembly.dll) or (UserAssembly.dll). The game might be obfuscated or use a yet unsupported build of Unity.");
				return;
			}
			IntPtr from = default(IntPtr);
			DynDll.TryGetFunction(processModule.BaseAddress, "il2cpp_runtime_invoke", ref from);
			ManualLogSource log = PreloaderLogger.Log;
			LogLevel val = (LogLevel)32;
			LogLevel val2 = val;
			bool flag = default(bool);
			BepInExLogInterpolatedStringHandler val3 = new BepInExLogInterpolatedStringHandler(26, 1, val, ref flag);
			if (flag)
			{
				val3.AppendLiteral("Runtime invoke pointer: 0x");
				val3.AppendFormatted<long>(from.ToInt64(), "X");
			}
			log.Log(val2, val3);
			RuntimeInvokeDetour = FastNativeDetour.CreateAndApply<RuntimeInvokeDetourDelegate>(from, OnInvokeMethod, out originalInvoke, CallingConvention.Cdecl);
			IntPtr from2 = default(IntPtr);
			if (DynDll.TryGetFunction(processModule.BaseAddress, "il2cpp_unity_install_unitytls_interface", ref from2))
			{
				InstallUnityTlsInterfaceDetour = FastNativeDetour.CreateAndApply<InstallUnityTlsInterfaceDelegate>(from2, OnInstallUnityTlsInterface, out originalInstallUnityTlsInterface, CallingConvention.Cdecl);
			}
			Logger.Log((LogLevel)32, (object)"Initializing TLS adapters");
			Il2CppTlsAdapter.Initialize();
			PreloaderLogger.Log.Log((LogLevel)32, (object)"Runtime invoke patched");
		}

		private static void OnInstallUnityTlsInterface(IntPtr unityTlsInterfaceStruct)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			LogLevel val = (LogLevel)32;
			bool flag = default(bool);
			BepInExLogInterpolatedStringHandler val2 = new BepInExLogInterpolatedStringHandler(31, 1, val, ref flag);
			if (flag)
			{
				val2.AppendLiteral("Captured UnityTls interface at ");
				val2.AppendFormatted<long>(unityTlsInterfaceStruct.ToInt64(), "x8");
			}
			Logger.Log(val, val2);
			Il2CppTlsAdapter.Options.UnityTlsInterface = unityTlsInterfaceStruct;
			originalInstallUnityTlsInterface(unityTlsInterfaceStruct);
			InstallUnityTlsInterfaceDetour.Dispose();
			InstallUnityTlsInterfaceDetour = null;
		}

		private static IntPtr OnInvokeMethod(IntPtr method, IntPtr obj, IntPtr parameters, IntPtr exc)
		{
			string? text = Marshal.PtrToStringAnsi(IL2CPP.il2cpp_method_get_name(method));
			bool flag = false;
			if (text == "Internal_ActiveSceneChanged")
			{
				try
				{
					if (ConfigUnityLogging.Value)
					{
						Logger.Sources.Add((ILogSource)(object)new IL2CPPUnityLogSource());
						Application.CallLogCallback("Test call after applying unity logging hook", "", (LogType)1, true);
					}
					flag = true;
					((BaseChainloader<BasePlugin>)Instance).Execute();
				}
				catch (Exception ex)
				{
					Logger.Log((LogLevel)1, (object)"Unable to execute IL2CPP chainloader");
					Logger.Log((LogLevel)2, (object)ex);
				}
			}
			IntPtr result = originalInvoke(method, obj, parameters, exc);
			if (flag)
			{
				RuntimeInvokeDetour.Dispose();
				PreloaderLogger.Log.Log((LogLevel)32, (object)"Runtime invoke unpatched");
			}
			return result;
		}

		protected override void InitializeLoggers()
		{
			base.InitializeLoggers();
			if (!ConfigDiskWriteUnityLog.Value)
			{
				DiskLogListener.BlacklistedSources.Add("Unity");
			}
			ChainloaderLogHelper.RewritePreloaderLogs();
			Logger.Sources.Add((ILogSource)(object)new IL2CPPLogSource());
		}

		public override BasePlugin LoadPlugin(PluginInfo pluginInfo, Assembly pluginAssembly)
		{
			BasePlugin obj = (BasePlugin)Activator.CreateInstance(pluginAssembly.GetType(pluginInfo.TypeName));
			obj.Load();
			return obj;
		}
	}
	public static class Preloader
	{
		private static readonly ConfigEntry<string> ConfigUnityVersion = ConfigFile.CoreConfig.Bind<string>("IL2CPP", "UnityVersion", string.Empty, "Unity version to report to Il2CppUnhollower. If empty, version is automatically determined from the game process.");

		public static string IL2CPPUnhollowedPath => ProxyAssemblyGenerator.IL2CPPUnhollowedPath;

		private static PreloaderConsoleListener PreloaderLog { get; set; }

		internal static ManualLogSource Log => PreloaderLogger.Log;

		internal static ManualLogSource UnhollowerLog { get; set; }

		private static IL2CPPChainloader Chainloader { get; set; }

		public static Version UnityVersion { get; private set; }

		public static void Run()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Expected O, but got Unknown
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Expected O, but got Unknown
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Expected O, but got Unknown
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Expected O, but got Unknown
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Expected O, but got Unknown
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Expected O, but got Unknown
			//IL_0227: Unknown result type (might be due to invalid IL or missing references)
			//IL_022e: Expected O, but got Unknown
			try
			{
				HarmonyBackendFix.Initialize();
				ConsoleManager.Initialize(false, false);
				PreloaderLog = new PreloaderConsoleListener();
				Logger.Listeners.Add((ILogListener)(object)PreloaderLog);
				if (ConsoleManager.ConsoleEnabled)
				{
					ConsoleManager.CreateConsole();
					Logger.Listeners.Add((ILogListener)new ConsoleLogListener());
				}
				ChainloaderLogHelper.PrintLogInfo(Log);
				ManualLogSource log = Log;
				LogLevel val = (LogLevel)32;
				LogLevel val2 = val;
				bool flag = default(bool);
				BepInExLogInterpolatedStringHandler val3 = new BepInExLogInterpolatedStringHandler(22, 1, val, ref flag);
				if (flag)
				{
					val3.AppendLiteral("Game executable path: ");
					val3.AppendFormatted<string>(Paths.ExecutablePath);
				}
				log.Log(val2, val3);
				ManualLogSource log2 = Log;
				val2 = (LogLevel)32;
				val = val2;
				val3 = new BepInExLogInterpolatedStringHandler(31, 1, val2, ref flag);
				if (flag)
				{
					val3.AppendLiteral("Unhollowed assembly directory: ");
					val3.AppendFormatted<string>(IL2CPPUnhollowedPath);
				}
				log2.Log(val, val3);
				ManualLogSource log3 = Log;
				val = (LogLevel)32;
				val2 = val;
				val3 = new BepInExLogInterpolatedStringHandler(19, 1, val, ref flag);
				if (flag)
				{
					val3.AppendLiteral("BepInEx root path: ");
					val3.AppendFormatted<string>(Paths.BepInExRootPath);
				}
				log3.Log(val2, val3);
				UnhollowerLog = Logger.CreateLogSource("Unhollower");
				LogSupport.InfoHandler += UnhollowerLog.LogInfo;
				LogSupport.WarningHandler += UnhollowerLog.LogWarning;
				LogSupport.TraceHandler += UnhollowerLog.LogDebug;
				LogSupport.ErrorHandler += UnhollowerLog.LogError;
				InitializeUnityVersion();
				if (ProxyAssemblyGenerator.CheckIfGenerationRequired())
				{
					ProxyAssemblyGenerator.GenerateAssemblies();
				}
				UnityVersionHandler.Initialize(UnityVersion.Major, UnityVersion.Minor, UnityVersion.Build);
				AssemblyPatcher val4 = new AssemblyPatcher();
				try
				{
					val4.AddPatchersFromDirectory(Paths.PatcherPluginPath);
					ManualLogSource log4 = Log;
					BepInExInfoLogInterpolatedStringHandler val5 = new BepInExInfoLogInterpolatedStringHandler(22, 2, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val5).AppendFormatted<int>(val4.PatcherContext.PatcherPlugins.Count);
						((BepInExLogInterpolatedStringHandler)val5).AppendLiteral(" patcher plugin");
						((BepInExLogInterpolatedStringHandler)val5).AppendFormatted<string>((val4.PatcherContext.PatcherPlugins.Count == 1) ? "" : "s");
						((BepInExLogInterpolatedStringHandler)val5).AppendLiteral(" loaded");
					}
					log4.LogInfo(val5);
					val4.LoadAssemblyDirectories(new string[1] { IL2CPPUnhollowedPath });
					ManualLogSource log5 = Log;
					val5 = new BepInExInfoLogInterpolatedStringHandler(22, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val5).AppendFormatted<int>(val4.PatcherContext.PatcherPlugins.Count);
						((BepInExLogInterpolatedStringHandler)val5).AppendLiteral(" assemblies discovered");
					}
					log5.LogInfo(val5);
					val4.PatchAndLoad();
				}
				finally
				{
					((IDisposable)val4)?.Dispose();
				}
				Logger.Listeners.Remove((ILogListener)(object)PreloaderLog);
				Chainloader = new IL2CPPChainloader();
				((BaseChainloader<BasePlugin>)Chainloader).Initialize((string)null);
			}
			catch (Exception ex)
			{
				Log.Log((LogLevel)1, (object)ex);
				throw;
			}
		}

		private static void InitializeUnityVersion()
		{
			if (TryInitializeUnityVersion(ConfigUnityVersion.Value))
			{
				Log.Log((LogLevel)4, (object)"Unity version obtained from the config.");
			}
			else if (TryInitializeUnityVersion(Process.GetCurrentProcess().MainModule.FileVersionInfo.FileVersion))
			{
				Log.Log((LogLevel)32, (object)"Unity version obtained from main application module.");
			}
			else
			{
				Log.Log((LogLevel)2, (object)"Running under default Unity version. UnityVersionHandler is not initialized.");
			}
		}

		private static bool TryInitializeUnityVersion(string version)
		{
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Expected O, but got Unknown
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Expected O, but got Unknown
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Expected O, but got Unknown
			bool flag2 = default(bool);
			try
			{
				if (string.IsNullOrWhiteSpace(version))
				{
					return false;
				}
				string[] array = version.Split('.');
				int result = 0;
				int result2 = 0;
				int result3 = 0;
				bool flag = int.TryParse(array[0], NumberStyles.Integer, CultureInfo.InvariantCulture, out result);
				if (flag && array.Length > 1)
				{
					flag = int.TryParse(array[1], NumberStyles.Integer, CultureInfo.InvariantCulture, out result2);
				}
				if (flag && array.Length > 2)
				{
					flag = int.TryParse(array[2], NumberStyles.Integer, CultureInfo.InvariantCulture, out result3);
				}
				if (!flag)
				{
					ManualLogSource log = Log;
					BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(31, 1, ref flag2);
					if (flag2)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Failed to parse Unity version: ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(version);
					}
					log.LogError(val);
					return false;
				}
				UnityVersion = new Version(result, result2, result3);
				ManualLogSource log2 = Log;
				BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(21, 1, ref flag2);
				if (flag2)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Running under Unity v");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<Version>(UnityVersion);
				}
				log2.LogInfo(val2);
				return true;
			}
			catch (Exception ex)
			{
				ManualLogSource log3 = Log;
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(31, 1, ref flag2);
				if (flag2)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Failed to parse Unity version: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
				}
				log3.LogError(val);
				return false;
			}
		}
	}
	internal static class ProxyAssemblyGenerator
	{
		internal enum IL2CPPDumperType
		{
			Il2CppDumper,
			Cpp2IL
		}

		private static class AppDomainHelper
		{
			public class AppDomainSetup
			{
				public string ApplicationBase { get; set; }
			}

			public static Func<AppDomain, string, string, object> CreateInstanceAndUnwrap { get; }

			private static FastInvokeHandler CreateDomainInternal { get; }

			private static Type AppDomainSetupType { get; }

			static AppDomainHelper()
			{
				Type typeFromHandle = typeof(AppDomain);
				Type type = typeof(AppDomain).Assembly.GetType("System.Security.Policy.Evidence");
				AppDomainSetupType = typeof(AppDomain).Assembly.GetType("System.AppDomainSetup");
				CreateDomainInternal = MethodInvoker.GetHandler(AccessTools.Method(typeFromHandle, "CreateDomain", new Type[3]
				{
					typeof(string),
					type,
					AppDomainSetupType
				}, (Type[])null), false);
				CreateInstanceAndUnwrap = AccessTools.MethodDelegate<Func<AppDomain, string, string, object>>(AccessTools.Method(typeFromHandle, "CreateInstanceAndUnwrap", new Type[2]
				{
					typeof(string),
					typeof(string)
				}, (Type[])null), (object)null, true);
			}

			public static AppDomain CreateDomain(string name, AppDomainSetup setup)
			{
				object obj = AccessTools.CreateInstance(AppDomainSetupType);
				Traverse.IterateProperties((object)setup, obj, (Action<Traverse, Traverse>)delegate(Traverse pSrc, Traverse pTgt)
				{
					pTgt.SetValue(pSrc.GetValue());
				});
				return CreateDomainInternal.Invoke((object)null, new object[3] { name, null, obj }) as AppDomain;
			}
		}

		[Serializable]
		private class AppDomainListener : MarshalByRefObject
		{
			public void DoPreloaderLog(object data, LogLevel level)
			{
				//IL_0005: Unknown result type (might be due to invalid IL or missing references)
				Preloader.Log.Log(level, data);
			}

			public void DoDumperLog(object data, LogLevel level)
			{
				//IL_0005: Unknown result type (might be due to invalid IL or missing references)
				Il2cppDumperLogger.Log(level, data);
			}

			public void DoUnhollowerLog(object data, LogLevel level)
			{
				//IL_0005: Unknown result type (might be due to invalid IL or missing references)
				Preloader.UnhollowerLog.Log(level, data);
			}
		}

		[Serializable]
		private class AppDomainRunner : MarshalByRefObject
		{
			public void Setup(string executablePath, string bepinPath, string managedPath)
			{
				Paths.SetExecutablePath(executablePath, bepinPath, managedPath, (string[])null);
				Utility.AddCecilPlatformAssemblies(AppDomain.CurrentDomain, Paths.ManagedPath);
				Utility.AddCecilPlatformAssemblies(AppDomain.CurrentDomain, UnityBaseLibsDirectory);
			}

			public bool GenerateAssemblies(AppDomainListener listener, string unityVersion, IL2CPPDumperType dumperType)
			{
				try
				{
					GenerateAssembliesInternal(listener, unityVersion, dumperType);
					return true;
				}
				catch (Exception arg)
				{
					listener.DoUnhollowerLog($"Failed to generate unhollowed assemblies: {arg}", (LogLevel)1);
					return false;
				}
			}

			private void GenerateAssembliesInternal(AppDomainListener listener, string unityVersion, IL2CPPDumperType dumperType)
			{
				//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
				//IL_01cc: Expected O, but got Unknown
				//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
				//IL_01dd: Expected O, but got Unknown
				//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
				//IL_01ee: Expected O, but got Unknown
				//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
				//IL_01ff: Expected O, but got Unknown
				//IL_0179: Unknown result type (might be due to invalid IL or missing references)
				//IL_017e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0185: Unknown result type (might be due to invalid IL or missing references)
				//IL_01a1: Expected O, but got Unknown
				//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
				//IL_01b0: Expected O, but got Unknown
				//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
				//IL_024b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0250: Unknown result type (might be due to invalid IL or missing references)
				//IL_0252: Unknown result type (might be due to invalid IL or missing references)
				//IL_0256: Unknown result type (might be due to invalid IL or missing references)
				//IL_0259: Invalid comparison between Unknown and I4
				//IL_031a: Unknown result type (might be due to invalid IL or missing references)
				//IL_031f: Unknown result type (might be due to invalid IL or missing references)
				//IL_032a: Unknown result type (might be due to invalid IL or missing references)
				//IL_033f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0346: Unknown result type (might be due to invalid IL or missing references)
				//IL_0351: Unknown result type (might be due to invalid IL or missing references)
				//IL_036b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0372: Unknown result type (might be due to invalid IL or missing references)
				//IL_039d: Expected O, but got Unknown
				string text = ConfigUnityBaseLibrariesSource.Value.Replace("{VERSION}", unityVersion);
				if (!string.IsNullOrEmpty(text))
				{
					listener.DoPreloaderLog("Downloading unity base libraries", (LogLevel)8);
					Directory.CreateDirectory(UnityBaseLibsDirectory);
					CollectionExtensions.Do<string>(Directory.EnumerateFiles(UnityBaseLibsDirectory, "*.dll"), (Action<string>)File.Delete);
					using HttpClient httpClient = new HttpClient();
					using Stream stream = httpClient.GetStreamAsync(text).GetAwaiter().GetResult();
					using ZipArchive source = new ZipArchive(stream, ZipArchiveMode.Read);
					listener.DoPreloaderLog("Extracting downloaded unity base libraries", (LogLevel)8);
					source.ExtractToDirectory(UnityBaseLibsDirectory);
				}
				listener.DoPreloaderLog("Generating Il2CppUnhollower assemblies", (LogLevel)8);
				Directory.CreateDirectory(Preloader.IL2CPPUnhollowedPath);
				CollectionExtensions.Do<string>(Directory.EnumerateFiles(Preloader.IL2CPPUnhollowedPath, "*.dll"), (Action<string>)File.Delete);
				string text2 = Path.Combine(Paths.GameRootPath, Paths.ProcessName + "_Data", "il2cpp_data", "Metadata", "global-metadata.dat");
				Stopwatch stopwatch = new Stopwatch();
				stopwatch.Start();
				List<AssemblyDefinition> list;
				if (dumperType == IL2CPPDumperType.Il2CppDumper)
				{
					listener.DoPreloaderLog("Generating Il2CppDumper intermediate assemblies", (LogLevel)16);
					Metadata val = default(Metadata);
					Il2Cpp val2 = default(Il2Cpp);
					Il2CppDumper.Init(GameAssemblyPath, text2, new Config
					{
						GenerateStruct = false,
						GenerateDummyDll = true
					}, (Action<string>)delegate(string s)
					{
						listener.DoDumperLog(s, (LogLevel)32);
					}, ref val, ref val2);
					list = new DummyAssemblyGenerator(new Il2CppExecutor(val, val2), true).Assemblies;
				}
				else
				{
					Logger.VerboseLog += (LogEvent)delegate(string message, string s)
					{
						listener.DoDumperLog("[" + s + "] " + message.Trim(), (LogLevel)32);
					};
					Logger.InfoLog += (LogEvent)delegate(string message, string s)
					{
						listener.DoDumperLog("[" + s + "] " + message.Trim(), (LogLevel)16);
					};
					Logger.WarningLog += (LogEvent)delegate(string message, string s)
					{
						listener.DoDumperLog("[" + s + "] " + message.Trim(), (LogLevel)4);
					};
					Logger.ErrorLog += (LogEvent)delegate(string message, string s)
					{
						listener.DoDumperLog("[" + s + "] " + message.Trim(), (LogLevel)2);
					};
					int[] array = Cpp2IlApi.DetermineUnityVersion(Paths.ExecutablePath, Path.Combine(Paths.GameRootPath, Paths.ProcessName + "_Data"));
					Cpp2IlApi.InitializeLibCpp2Il(GameAssemblyPath, text2, array, false);
					list = Cpp2IlApi.MakeDummyDLLs(false);
					int num;
					if (!(LibCpp2IlMain.MetadataVersion >= 29f))
					{
						InstructionSet instructionSet = LibCpp2IlMain.Binary.InstructionSet;
						num = (((int)instructionSet == 0 || (int)instructionSet == 1) ? 1 : 0);
					}
					else
					{
						num = 1;
					}
					Cpp2IlApi.RunAttributeRestorationForAllAssemblies((BaseKeyFunctionAddresses)null, (byte)num != 0);
					Cpp2IlApi.DisposeAndCleanupAll();
				}
				stopwatch.Stop();
				listener.DoDumperLog("Total time: " + stopwatch.Elapsed, (LogLevel)16);
				if (ConfigDumpDummyAssemblies.Value)
				{
					string text3 = Path.Combine(Paths.BepInExRootPath, "dummy");
					Directory.CreateDirectory(text3);
					foreach (AssemblyDefinition item in list)
					{
						item.Write(Path.Combine(text3, ((AssemblyNameReference)item.Name).Name + ".dll"));
					}
				}
				UnhollowerOptions val3 = new UnhollowerOptions
				{
					GameAssemblyPath = GameAssemblyPath,
					MscorlibPath = Path.Combine(Paths.ManagedPath, "mscorlib.dll"),
					Source = list,
					OutputDir = Preloader.IL2CPPUnhollowedPath,
					UnityBaseLibsDir = (Directory.Exists(UnityBaseLibsDirectory) ? UnityBaseLibsDirectory : null),
					NoCopyUnhollowerLibs = true,
					ObfuscatedNamesRegex = ((!string.IsNullOrEmpty(ConfigUnhollowerDeobfuscationRegex.Value)) ? new Regex(ConfigUnhollowerDeobfuscationRegex.Value) : null)
				};
				string text4 = Path.Combine(Paths.BepInExRootPath, "DeobfuscationMap.csv.gz");
				if (File.Exists(text4))
				{
					listener.DoPreloaderLog("Parsing deobfuscation rename mappings", (LogLevel)16);
					val3.ReadRenameMap(text4);
				}
				listener.DoPreloaderLog("Executing Il2CppUnhollower generator", (LogLevel)16);
				LogSupport.InfoHandler += delegate(string s)
				{
					listener.DoUnhollowerLog(s.Trim(), (LogLevel)16);
				};
				LogSupport.WarningHandler += delegate(string s)
				{
					listener.DoUnhollowerLog(s.Trim(), (LogLevel)4);
				};
				LogSupport.TraceHandler += delegate(string s)
				{
					listener.DoUnhollowerLog(s.Trim(), (LogLevel)32);
				};
				LogSupport.ErrorHandler += delegate(string s)
				{
					listener.DoUnhollowerLog(s.Trim(), (LogLevel)2);
				};
				try
				{
					UnhollowedAssemblyGenerator.GenerateUnhollowedAssemblies(val3);
				}
				catch (Exception arg)
				{
					listener.DoUnhollowerLog($"Exception while unhollowing: {arg}", (LogLevel)2);
				}
				CollectionExtensions.Do<AssemblyDefinition>((IEnumerable<AssemblyDefinition>)list, (Action<AssemblyDefinition>)delegate(AssemblyDefinition x)
				{
					x.Dispose();
				});
			}
		}

		private static readonly ConfigEntry<bool> ConfigUpdateUnhollowedAssemblies = ConfigFile.CoreConfig.Bind<bool>("IL2CPP", "UpdateUnhollowedAssemblies", true, new StringBuilder().AppendLine("Whether to run Il2CppAssemblyUnhollower automatically to generate Il2Cpp support assemblies when they are outdated.").AppendLine("If disabled assemblies in `BepInEx/unhollowed` won't be updated between game or BepInEx updates!").ToString());

		private static readonly ConfigEntry<string> ConfigUnityBaseLibrariesSource = ConfigFile.CoreConfig.Bind<string>("IL2CPP", "UnityBaseLibrariesSource", "http://unity.bepinex.dev/libraries/{VERSION}.zip", new StringBuilder().AppendLine("URL to the ZIP of managed Unity base libraries.").AppendLine("The base libraries are used by Il2CppUnhollower to generate unhollowed Unity assemblies").AppendLine("The URL template MUST use HTTP.")
			.AppendLine("The URL can include {VERSION} template which will be replaced with the game's Unity engine version")
			.ToString());

		private static readonly ConfigEntry<IL2CPPDumperType> ConfigIl2CppDumperType = ConfigFile.CoreConfig.Bind<IL2CPPDumperType>("IL2CPP", "Il2CppDumperType", IL2CPPDumperType.Cpp2IL, new StringBuilder().AppendLine("The IL2CPP metadata dumper tool to use when generating dummy assemblies for Il2CppAssemblyUnhollower.").AppendLine("Il2CppDumper - Default. The traditional choice that has been used by BepInEx.").AppendLine("Cpp2IL - Experimental, may provide better results than Il2CppDumper. Required for use with BepInEx.MelonLoader.Loader.")
			.ToString());

		private static readonly ConfigEntry<bool> ConfigDumpDummyAssemblies = ConfigFile.CoreConfig.Bind<bool>("IL2CPP", "DumpDummyAssemblies", false, "If enabled, BepInEx will save dummy assemblies generated by an il2cpp dumper into BepInEx/dummy.");

		private static readonly ConfigEntry<string> UnhollowedAssembliesPath = ConfigFile.CoreConfig.Bind<string>("IL2CPP", "UnhollowedAssembliesPath", "{BepInEx}", new StringBuilder().AppendLine("The path to the folder where unhollowed assemblies are stored.").AppendLine("Supports the following placeholders:").AppendLine("{BepInEx} - Path to the BepInEx folder.")
			.AppendLine("{ProcessName} - Name of the current process")
			.ToString());

		private static readonly ConfigEntry<string> ConfigUnhollowerDeobfuscationRegex = ConfigFile.CoreConfig.Bind<string>("IL2CPP", "UnhollowerDeobfuscationRegex", string.Empty, new StringBuilder().AppendLine("The RegEx string to pass to Il2CppAssemblyUnhollower for renaming obfuscated names.").AppendLine("All types and members matching this RegEx will get a name based on their signature,").AppendLine("resulting in names that persist after game updates.")
			.ToString());

		private static ManualLogSource Il2cppDumperLogger;

		private static string unhollowedBasePath;

		public static string GameAssemblyPath => Path.Combine(Paths.GameRootPath, "GameAssembly.dll");

		private static string HashPath => Path.Combine(Preloader.IL2CPPUnhollowedPath, "assembly-hash.txt");

		private static string UnhollowedBasePath
		{
			get
			{
				if (unhollowedBasePath != null)
				{
					return unhollowedBasePath;
				}
				unhollowedBasePath = (Utility.GetCommandLineArgValue("--unhollowed-path") ?? UnhollowedAssembliesPath.Value).Replace("{BepInEx}", Paths.BepInExRootPath).Replace("{ProcessName}", Paths.ProcessName);
				return unhollowedBasePath;
			}
		}

		private static string UnityBaseLibsDirectory => Path.Combine(UnhollowedBasePath, "unity-libs");

		internal static string IL2CPPUnhollowedPath => Path.Combine(UnhollowedBasePath, "unhollowed");

		private static string ComputeHash()
		{
			using (MD5 mD = MD5.Create())
			{
				HashFile(mD, GameAssemblyPath);
				if (Directory.Exists(UnityBaseLibsDirectory))
				{
					foreach (string item in Directory.EnumerateFiles(UnityBaseLibsDirectory, "*.dll", SearchOption.TopDirectoryOnly))
					{
						HashString(mD, Path.GetFileName(item));
						HashFile(mD, item);
					}
				}
				HashString(mD, typeof(UnhollowedAssemblyGenerator).Assembly.GetName().Version.ToString());
				HashString(mD, typeof(Cpp2IlApi).Assembly.GetName().Version.ToString());
				HashString(mD, typeof(Il2CppDumper).Assembly.GetName().Version.ToString());
				mD.TransformFinalBlock(new byte[0], 0, 0);
				return Utility.ByteArrayToString(mD.Hash);
			}
			static void HashFile(ICryptoTransform hash, string file)
			{
				using FileStream fileStream = File.OpenRead(file);
				byte[] array = new byte[81920];
				int inputCount;
				while ((inputCount = fileStream.Read(array)) > 0)
				{
					hash.TransformBlock(array, 0, inputCount, array, 0);
				}
			}
			static void HashString(ICryptoTransform hash, string str)
			{
				byte[] bytes = Encoding.UTF8.GetBytes(str);
				hash.TransformBlock(bytes, 0, bytes.Length, bytes, 0);
			}
		}

		public static bool CheckIfGenerationRequired()
		{
			if (!Directory.Exists(Preloader.IL2CPPUnhollowedPath))
			{
				return true;
			}
			if (!File.Exists(HashPath))
			{
				return NeedGenerationOrSkip();
			}
			if (ComputeHash() != File.ReadAllText(HashPath) && NeedGenerationOrSkip())
			{
				Preloader.Log.Log((LogLevel)16, (object)"Detected outdated proxy assemblies, will regenerate them now");
				return true;
			}
			return false;
			static bool NeedGenerationOrSkip()
			{
				//IL_0018: Unknown result type (might be due to invalid IL or missing references)
				//IL_0019: Unknown result type (might be due to invalid IL or missing references)
				//IL_001a: Unknown result type (might be due to invalid IL or missing references)
				//IL_001e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0021: Unknown result type (might be due to invalid IL or missing references)
				//IL_0027: Expected O, but got Unknown
				//IL_0053: Unknown result type (might be due to invalid IL or missing references)
				if (!ConfigUpdateUnhollowedAssemblies.Value)
				{
					string text = ComputeHash();
					ManualLogSource log = Preloader.Log;
					LogLevel val = (LogLevel)4;
					LogLevel val2 = val;
					bool flag = default(bool);
					BepInExLogInterpolatedStringHandler val3 = new BepInExLogInterpolatedStringHandler(115, 2, val, ref flag);
					if (flag)
					{
						val3.AppendLiteral("Unhollowed assemblies are possibly out of date. To disable this message, create file ");
						val3.AppendFormatted<string>(HashPath);
						val3.AppendLiteral(" with the following contents: ");
						val3.AppendFormatted<string>(text);
					}
					log.Log(val2, val3);
					return false;
				}
				return true;
			}
		}

		public static void GenerateAssemblies()
		{
			if (Il2cppDumperLogger == null)
			{
				Il2cppDumperLogger = Logger.CreateLogSource((ConfigIl2CppDumperType.Value == IL2CPPDumperType.Il2CppDumper) ? "Il2CppDumper" : "Cpp2IL");
			}
			AppDomain appDomain = AppDomainHelper.CreateDomain("GeneratorDomain", new AppDomainHelper.AppDomainSetup
			{
				ApplicationBase = Paths.BepInExAssemblyDirectory
			});
			AppDomainRunner obj = (AppDomainRunner)AppDomainHelper.CreateInstanceAndUnwrap(appDomain, typeof(AppDomainRunner).Assembly.FullName, typeof(AppDomainRunner).FullName);
			obj.Setup(Paths.ExecutablePath, Paths.BepInExRootPath, Paths.ManagedPath);
			bool num = obj.GenerateAssemblies(new AppDomainListener(), Preloader.UnityVersion.ToString(3), ConfigIl2CppDumperType.Value);
			AppDomain.Unload(appDomain);
			if (num)
			{
				File.WriteAllText(HashPath, ComputeHash());
			}
		}
	}
}
namespace BepInEx.IL2CPP.Utils
{
	internal static class Il2CppUtils
	{
		private static GameObject managerGo;

		public static Il2CppObjectBase AddComponent(Type t)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			if ((Object)(object)managerGo == (Object)null)
			{
				managerGo = new GameObject
				{
					hideFlags = (HideFlags)61
				};
			}
			if (!ClassInjector.IsTypeRegisteredInIl2Cpp(t))
			{
				ClassInjector.RegisterTypeInIl2Cpp(t);
			}
			return (Il2CppObjectBase)(object)managerGo.AddComponent(Il2CppType.From(t));
		}
	}
	public static class MonoBehaviourExtensions
	{
		public static Coroutine StartCoroutine(this MonoBehaviour self, IEnumerator coroutine)
		{
			return self.StartCoroutine(coroutine.WrapToIl2Cpp());
		}
	}
}
namespace BepInEx.IL2CPP.Utils.Collections
{
	public static class CollectionExtensions
	{
		public static IEnumerator WrapToIl2Cpp(this IEnumerator self)
		{
			return ((Il2CppObjectBase)new Il2CppManagedEnumerator(self)).Cast<IEnumerator>();
		}

		public static IEnumerator WrapToManaged(this IEnumerator self)
		{
			return new ManagedIl2CppEnumerator(self);
		}

		public static IEnumerable WrapToIl2Cpp(this IEnumerable self)
		{
			return ((Il2CppObjectBase)new Il2CppManagedEnumerable(self)).Cast<IEnumerable>();
		}

		public static IEnumerable WrapToManaged(this IEnumerable self)
		{
			return new ManagedIl2CppEnumerable(self);
		}
	}
	public class Il2CppManagedEnumerable : Object
	{
		private readonly IEnumerable enumerable;

		static Il2CppManagedEnumerable()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			RegisterTypeOptions val = new RegisterTypeOptions();
			val.set_Interfaces(Il2CppInterfaceCollection.op_Implicit(new Type[1] { typeof(IEnumerable) }));
			ClassInjector.RegisterTypeInIl2Cpp<Il2CppManagedEnumerable>(val);
		}

		public Il2CppManagedEnumerable(IntPtr ptr)
			: base(ptr)
		{
		}

		public Il2CppManagedEnumerable(IEnumerable enumerable)
			: base(ClassInjector.DerivedConstructorPointer<Il2CppManagedEnumerable>())
		{
			this.enumerable = enumerable ?? throw new ArgumentNullException("enumerable");
			ClassInjector.DerivedConstructorBody((Il2CppObjectBase)(object)this);
		}

		public IEnumerator GetEnumerator()
		{
			return ((Il2CppObjectBase)new Il2CppManagedEnumerator(enumerable.GetEnumerator())).Cast<IEnumerator>();
		}
	}
	public class Il2CppManagedEnumerator : Object
	{
		private static readonly Dictionary<Type, Func<object, Object>> boxers;

		private readonly IEnumerator enumerator;

		public Object Current
		{
			get
			{
				object current = this.enumerator.Current;
				IEnumerator val = (IEnumerator)((current is IEnumerator) ? current : null);
				if (val == null)
				{
					if (!(current is IEnumerator enumerator))
					{
						Object val2 = (Object)((current is Object) ? current : null);
						if (val2 == null)
						{
							if (current != null)
							{
								return ManagedToIl2CppObject(current);
							}
							return null;
						}
						return val2;
					}
					return (Object)(object)new Il2CppManagedEnumerator(enumerator);
				}
				return ((Il2CppObjectBase)val).Cast<Object>();
			}
		}

		static Il2CppManagedEnumerator()
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			boxers = new Dictionary<Type, Func<object, Object>>();
			RegisterTypeOptions val = new RegisterTypeOptions();
			val.set_Interfaces(Il2CppInterfaceCollection.op_Implicit(new Type[1] { typeof(IEnumerator) }));
			ClassInjector.RegisterTypeInIl2Cpp<Il2CppManagedEnumerator>(val);
		}

		public Il2CppManagedEnumerator(IntPtr ptr)
			: base(ptr)
		{
		}

		public Il2CppManagedEnumerator(IEnumerator enumerator)
			: base(ClassInjector.DerivedConstructorPointer<Il2CppManagedEnumerator>())
		{
			this.enumerator = enumerator ?? throw new ArgumentNullException("enumerator");
			ClassInjector.DerivedConstructorBody((Il2CppObjectBase)(object)this);
		}

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

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

		private static Func<object, Object> GetValueBoxer(Type t)
		{
			if (boxers.TryGetValue(t, out var value))
			{
				return value;
			}
			DynamicMethod dynamicMethod = new DynamicMethod("Il2CppUnbox_" + GeneralExtensions.FullDescription(t), typeof(Object), new Type[1] { typeof(object) });
			ILGenerator iLGenerator = dynamicMethod.GetILGenerator();
			LocalBuilder local = iLGenerator.DeclareLocal(t);
			FieldInfo field = typeof(Il2CppClassPointerStore<>).MakeGenericType(t).GetField("NativeClassPtr");
			iLGenerator.Emit(OpCodes.Ldsfld, field);
			iLGenerator.Emit(OpCodes.Ldarg_0);
			iLGenerator.Emit(OpCodes.Unbox_Any, t);
			iLGenerator.Emit(OpCodes.Stloc, local);
			iLGenerator.Emit(OpCodes.Ldloca, local);
			iLGenerator.Emit(OpCodes.Call, typeof(IL2CPP).GetMethod("il2cpp_value_box"));
			iLGenerator.Emit(OpCodes.Newobj, typeof(Object).GetConstructor(new Type[1] { typeof(IntPtr) }));
			iLGenerator.Emit(OpCodes.Ret);
			Func<object, Object> func = dynamicMethod.CreateDelegate(typeof(Func<object, Object>)) as Func<object, Object>;
			boxers[t] = func;
			return func;
		}

		private static Object ManagedToIl2CppObject(object obj)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected O, but got Unknown
			Type type = obj.GetType();
			if (obj is string text)
			{
				return new Object(IL2CPP.ManagedStringToIl2Cpp(text));
			}
			if (type.IsPrimitive)
			{
				return GetValueBoxer(type)(obj);
			}
			throw new NotSupportedException($"Type {type} cannot be converted directly to an Il2Cpp object");
		}
	}
	public class ManagedIl2CppEnumerable : IEnumerable
	{
		private readonly IEnumerable enumerable;

		public ManagedIl2CppEnumerable(IEnumerable enumerable)
		{
			this.enumerable = enumerable ?? throw new ArgumentNullException("enumerable");
		}

		public IEnumerator GetEnumerator()
		{
			return new ManagedIl2CppEnumerator(enumerable.GetEnumerator());
		}
	}
	public class ManagedIl2CppEnumerator : IEnumerator
	{
		private static readonly Func<IEnumerator, bool> moveNext;

		private static readonly Action<IEnumerator> reset;

		private readonly IEnumerator enumerator;

		public object Current => enumerator.Current;

		public ManagedIl2CppEnumerator(IEnumerator enumerator)
		{
			this.enumerator = enumerator ?? throw new ArgumentNullException("enumerator");
		}

		public bool MoveNext()
		{
			return moveNext?.Invoke(enumerator) ?? false;
		}

		public void Reset()
		{
			reset?.Invoke(enumerator);
		}

		static ManagedIl2CppEnumerator()
		{
			MethodInfo methodInfo = AccessTools.Method(typeof(IEnumerator), "MoveNext", (Type[])null, (Type[])null);
			moveNext = (((object)methodInfo != null) ? Extensions.CreateDelegate<Func<IEnumerator, bool>>((MethodBase)methodInfo) : null);
			MethodInfo methodInfo2 = AccessTools.Method(typeof(IEnumerator), "Reset", (Type[])null, (Type[])null);
			reset = (((object)methodInfo2 != null) ? Extensions.CreateDelegate<Action<IEnumerator>>((MethodBase)methodInfo2) : null);
		}
	}
}
namespace BepInEx.IL2CPP.UnityEngine
{
	public enum KeyCode
	{
		None = 0,
		Backspace = 8,
		Delete = 127,
		Tab = 9,
		Clear = 12,
		Return = 13,
		Pause = 19,
		Escape = 27,
		Space = 32,
		Keypad0 = 256,
		Keypad1 = 257,
		Keypad2 = 258,
		Keypad3 = 259,
		Keypad4 = 260,
		Keypad5 = 261,
		Keypad6 = 262,
		Keypad7 = 263,
		Keypad8 = 264,
		Keypad9 = 265,
		KeypadPeriod = 266,
		KeypadDivide = 267,
		KeypadMultiply = 268,
		KeypadMinus = 269,
		KeypadPlus = 270,
		KeypadEnter = 271,
		KeypadEquals = 272,
		UpArrow = 273,
		DownArrow = 274,
		RightArrow = 275,
		LeftArrow = 276,
		Insert = 277,
		Home = 278,
		End = 279,
		PageUp = 280,
		PageDown = 281,
		F1 = 282,
		F2 = 283,
		F3 = 284,
		F4 = 285,
		F5 = 286,
		F6 = 287,
		F7 = 288,
		F8 = 289,
		F9 = 290,
		F10 = 291,
		F11 = 292,
		F12 = 293,
		F13 = 294,
		F14 = 295,
		F15 = 296,
		Alpha0 = 48,
		Alpha1 = 49,
		Alpha2 = 50,
		Alpha3 = 51,
		Alpha4 = 52,
		Alpha5 = 53,
		Alpha6 = 54,
		Alpha7 = 55,
		Alpha8 = 56,
		Alpha9 = 57,
		Exclaim = 33,
		DoubleQuote = 34,
		Hash = 35,
		Dollar = 36,
		Percent = 37,
		Ampersand = 38,
		Quote = 39,
		LeftParen = 40,
		RightParen = 41,
		Asterisk = 42,
		Plus = 43,
		Comma = 44,
		Minus = 45,
		Period = 46,
		Slash = 47,
		Colon = 58,
		Semicolon = 59,
		Less = 60,
		Equals = 61,
		Greater = 62,
		Question = 63,
		At = 64,
		LeftBracket = 91,
		Backslash = 92,
		RightBracket = 93,
		Caret = 94,
		Underscore = 95,
		BackQuote = 96,
		A = 97,
		B = 98,
		C = 99,
		D = 100,
		E = 101,
		F = 102,
		G = 103,
		H = 104,
		I = 105,
		J = 106,
		K = 107,
		L = 108,
		M = 109,
		N = 110,
		O = 111,
		P = 112,
		Q = 113,
		R = 114,
		S = 115,
		T = 116,
		U = 117,
		V = 118,
		W = 119,
		X = 120,
		Y = 121,
		Z = 122,
		LeftCurlyBracket = 123,
		Pipe = 124,
		RightCurlyBracket = 125,
		Tilde = 126,
		Numlock = 300,
		CapsLock = 301,
		ScrollLock = 302,
		RightShift = 303,
		LeftShift = 304,
		RightControl = 305,
		LeftControl = 306,
		RightAlt = 307,
		LeftAlt = 308,
		LeftCommand = 310,
		LeftApple = 310,
		LeftWindows = 311,
		RightCommand = 309,
		RightApple = 309,
		RightWindows = 312,
		AltGr = 313,
		Help = 315,
		Print = 316,
		SysReq = 317,
		Break = 318,
		Menu = 319,
		Mouse0 = 323,
		Mouse1 = 324,
		Mouse2 = 325,
		Mouse3 = 326,
		Mouse4 = 327,
		Mouse5 = 328,
		Mouse6 = 329,
		JoystickButton0 = 330,
		JoystickButton1 = 331,
		JoystickButton2 = 332,
		JoystickButton3 = 333,
		JoystickButton4 = 334,
		JoystickButton5 = 335,
		JoystickButton6 = 336,
		JoystickButton7 = 337,
		JoystickButton8 = 338,
		JoystickButton9 = 339,
		JoystickButton10 = 340,
		JoystickButton11 = 341,
		JoystickButton12 = 342,
		JoystickButton13 = 343,
		JoystickButton14 = 344,
		JoystickButton15 = 345,
		JoystickButton16 = 346,
		JoystickButton17 = 347,
		JoystickButton18 = 348,
		JoystickButton19 = 349,
		Joystick1Button0 = 350,
		Joystick1Button1 = 351,
		Joystick1Button2 = 352,
		Joystick1Button3 = 353,
		Joystick1Button4 = 354,
		Joystick1Button5 = 355,
		Joystick1Button6 = 356,
		Joystick1Button7 = 357,
		Joystick1Button8 = 358,
		Joystick1Button9 = 359,
		Joystick1Button10 = 360,
		Joystick1Button11 = 361,
		Joystick1Button12 = 362,
		Joystick1Button13 = 363,
		Joystick1Button14 = 364,
		Joystick1Button15 = 365,
		Joystick1Button16 = 366,
		Joystick1Button17 = 367,
		Joystick1Button18 = 368,
		Joystick1Button19 = 369,
		Joystick2Button0 = 370,
		Joystick2Button1 = 371,
		Joystick2Button2 = 372,
		Joystick2Button3 = 373,
		Joystick2Button4 = 374,
		Joystick2Button5 = 375,
		Joystick2Button6 = 376,
		Joystick2Button7 = 377,
		Joystick2Button8 = 378,
		Joystick2Button9 = 379,
		Joystick2Button10 = 380,
		Joystick2Button11 = 381,
		Joystick2Button12 = 382,
		Joystick2Button13 = 383,
		Joystick2Button14 = 384,
		Joystick2Button15 = 385,
		Joystick2Button16 = 386,
		Joystick2Button17 = 387,
		Joystick2Button18 = 388,
		Joystick2Button19 = 389,
		Joystick3Button0 = 390,
		Joystick3Button1 = 391,
		Joystick3Button2 = 392,
		Joystick3Button3 = 393,
		Joystick3Button4 = 394,
		Joystick3Button5 = 395,
		Joystick3Button6 = 396,
		Joystick3Button7 = 397,
		Joystick3Button8 = 398,
		Joystick3Button9 = 399,
		Joystick3Button10 = 400,
		Joystick3Button11 = 401,
		Joystick3Button12 = 402,
		Joystick3Button13 = 403,
		Joystick3Button14 = 404,
		Joystick3Button15 = 405,
		Joystick3Button16 = 406,
		Joystick3Button17 = 407,
		Joystick3Button18 = 408,
		Joystick3Button19 = 409,
		Joystick4Button0 = 410,
		Joystick4Button1 = 411,
		Joystick4Button2 = 412,
		Joystick4Button3 = 413,
		Joystick4Button4 = 414,
		Joystick4Button5 = 415,
		Joystick4Button6 = 416,
		Joystick4Button7 = 417,
		Joystick4Button8 = 418,
		Joystick4Button9 = 419,
		Joystick4Button10 = 420,
		Joystick4Button11 = 421,
		Joystick4Button12 = 422,
		Joystick4Button13 = 423,
		Joystick4Button14 = 424,
		Joystick4Button15 = 425,
		Joystick4Button16 = 426,
		Joystick4Button17 = 427,
		Joystick4Button18 = 428,
		Joystick4Button19 = 429,
		Joystick5Button0 = 430,
		Joystick5Button1 = 431,
		Joystick5Button2 = 432,
		Joystick5Button3 = 433,
		Joystick5Button4 = 434,
		Joystick5Button5 = 435,
		Joystick5Button6 = 436,
		Joystick5Button7 = 437,
		Joystick5Button8 = 438,
		Joystick5Button9 = 439,
		Joystick5Button10 = 440,
		Joystick5Button11 = 441,
		Joystick5Button12 = 442,
		Joystick5Button13 = 443,
		Joystick5Button14 = 444,
		Joystick5Button15 = 445,
		Joystick5Button16 = 446,
		Joystick5Button17 = 447,
		Joystick5Button18 = 448,
		Joystick5Button19 = 449,
		Joystick6Button0 = 450,
		Joystick6Button1 = 451,
		Joystick6Button2 = 452,
		Joystick6Button3 = 453,
		Joystick6Button4 = 454,
		Joystick6Button5 = 455,
		Joystick6Button6 = 456,
		Joystick6Button7 = 457,
		Joystick6Button8 = 458,
		Joystick6Button9 = 459,
		Joystick6Button10 = 460,
		Joystick6Button11 = 461,
		Joystick6Button12 = 462,
		Joystick6Button13 = 463,
		Joystick6Button14 = 464,
		Joystick6Button15 = 465,
		Joystick6Button16 = 466,
		Joystick6Button17 = 467,
		Joystick6Button18 = 468,
		Joystick6Button19 = 469,
		Joystick7Button0 = 470,
		Joystick7Button1 = 471,
		Joystick7Button2 = 472,
		Joystick7Button3 = 473,
		Joystick7Button4 = 474,
		Joystick7Button5 = 475,
		Joystick7Button6 = 476,
		Joystick7Button7 = 477,
		Joystick7Button8 = 478,
		Joystick7Button9 = 479,
		Joystick7Button10 = 480,
		Joystick7Button11 = 481,
		Joystick7Button12 = 482,
		Joystick7Button13 = 483,
		Joystick7Button14 = 484,
		Joystick7Button15 = 485,
		Joystick7Button16 = 486,
		Joystick7Button17 = 487,
		Joystick7Button18 = 488,
		Joystick7Button19 = 489,
		Joystick8Button0 = 490,
		Joystick8Button1 = 491,
		Joystick8Button2 = 492,
		Joystick8Button3 = 493,
		Joystick8Button4 = 494,
		Joystick8Button5 = 495,
		Joystick8Button6 = 496,
		Joystick8Button7 = 497,
		Joystick8Button8 = 498,
		Joystick8Button9 = 499,
		Joystick8Button10 = 500,
		Joystick8Button11 = 501,
		Joystick8Button12 = 502,
		Joystick8Button13 = 503,
		Joystick8Button14 = 504,
		Joystick8Button15 = 505,
		Joystick8Button16 = 506,
		Joystick8Button17 = 507,
		Joystick8Button18 = 508,
		Joystick8Button19 = 509
	}
	public static class Input
	{
		private delegate bool GetKeyIntDelegate(KeyCode key);

		private static readonly GetKeyIntDelegate GetKeyInt_Value = IL2CPP.ResolveICall<GetKeyIntDelegate>("UnityEngine.Input::GetKeyInt(UnityEngine.KeyCode)");

		public static bool GetKeyInt(KeyCode key)
		{
			return GetKeyInt_Value(key);
		}
	}
}
namespace BepInEx.IL2CPP.Logging
{
	public class IL2CPPLogSource : ILogSource, IDisposable
	{
		[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
		private delegate void IL2CPPLogCallbackDelegate([In][MarshalAs(UnmanagedType.LPStr)] string message);

		public string SourceName { get; } = "IL2CPP";


		public event EventHandler<LogEventArgs> LogEvent;

		public IL2CPPLogSource()
		{
			IL2CPP.il2cpp_register_log_callback(Marshal.GetFunctionPointerForDelegate<IL2CPPLogCallbackDelegate>(IL2CPPLogCallback));
		}

		public void Dispose()
		{
		}

		private void IL2CPPLogCallback(string message)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			this.LogEvent?.Invoke(this, new LogEventArgs((object)message.Trim(), (LogLevel)8, (ILogSource)(object)this));
		}
	}
	public class IL2CPPUnityLogSource : ILogSource, IDisposable
	{
		private delegate IntPtr SetLogCallbackDefinedDelegate(bool defined);

		public string SourceName { get; } = "Unity";


		public event EventHandler<LogEventArgs> LogEvent;

		public IL2CPPUnityLogSource()
		{
			Application.s_LogCallbackHandler = LogCallback.op_Implicit((Action<string, string, LogType>)UnityLogCallback);
			IL2CPP.ResolveICall<SetLogCallbackDefinedDelegate>("UnityEngine.Application::SetLogCallbackDefined")(defined: true);
		}

		public void Dispose()
		{
		}

		public void UnityLogCallback(string logLine, string exception, LogType type)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Expected I4, but got Unknown
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: 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_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_0034: 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_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Expected O, but got Unknown
			this.LogEvent?.Invoke(this, new LogEventArgs((object)logLine, (LogLevel)((int)type switch
			{
				0 => 2, 
				1 => 32, 
				2 => 4, 
				3 => 8, 
				4 => 2, 
				_ => 8, 
			}), (ILogSource)(object)this));
		}
	}
}
namespace BepInEx.IL2CPP.Hook
{
	public class FastNativeDetour : IDetour, IDisposable
	{
		private static readonly ManualLogSource logger = Logger.CreateLogSource("FastNativeDetour");

		protected byte[] BackupBytes { get; set; }

		public IntPtr OriginalFunctionPtr { get; protected set; }

		public IntPtr DetourFunctionPtr { get; protected set; }

		public IntPtr TrampolinePtr { get; protected set; } = IntPtr.Zero;


		public int TrampolineSize { get; protected set; }

		protected int TrampolineJmpSize { get; set; }

		protected MethodInfo TrampolineMethod { get; set; }

		public bool IsValid { get; protected set; } = true;


		public bool IsApplied { get; protected set; }

		public FastNativeDetour(IntPtr originalFunctionPtr, IntPtr detourFunctionPtr)
		{
			OriginalFunctionPtr = originalFunctionPtr;
			DetourFunctionPtr = detourFunctionPtr;
			BackupBytes = new byte[20];
			Marshal.Copy(originalFunctionPtr, BackupBytes, 0, 20);
		}

		public void Apply()
		{
			Apply(null);
		}

		public void Undo()
		{
			if (IsApplied)
			{
				Marshal.Copy(BackupBytes, 0, OriginalFunctionPtr, BackupBytes.Length);
				PageAllocator.Instance.Free(TrampolinePtr);
				TrampolinePtr = IntPtr.Zero;
				TrampolineSize = 0;
				IsApplied = false;
			}
		}

		public void Free()
		{
			IsValid = false;
		}

		public MethodBase GenerateTrampoline(MethodBase signature = null)
		{
			if (TrampolineMethod == null)
			{
				GenerateTrampolineInner(out var _, out var _);
				if (TrampolinePtr == IntPtr.Zero)
				{
					throw new InvalidOperationException("Trampoline pointer is not available");
				}
				TrampolineMethod = DetourHelper.GenerateNativeProxy(TrampolinePtr, signature);
			}
			return TrampolineMethod;
		}

		public T GenerateTrampoline<T>() where T : Delegate
		{
			if (!typeof(Delegate).IsAssignableFrom(typeof(T)))
			{
				throw new InvalidOperationException($"Type {typeof(T)} not a delegate type.");
			}
			return Extensions.CreateDelegate(GenerateTrampoline(typeof(T).GetMethod("Invoke")), typeof(T)) as T;
		}

		public void Dispose()
		{
			if (IsValid)
			{
				Undo();
				Free();
			}
		}

		public void Apply(ManualLogSource debuggerLogSource)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Expected O, but got Unknown
			//IL_00ce: 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_00d2: 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)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Expected O, but got Unknown
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Expected O, but got Unknown
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			if (IsApplied)
			{
				return;
			}
			DetourHelper.Native.MakeWritable(OriginalFunctionPtr, 32u);
			bool flag = default(bool);
			if (debuggerLogSource != null)
			{
				BepInExDebugLogInterpolatedStringHandler val = new BepInExDebugLogInterpolatedStringHandler(18, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Detouring 0x");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(OriginalFunctionPtr.ToString("X"));
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" -> 0x");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(DetourFunctionPtr.ToString("X"));
				}
				debuggerLogSource.LogDebug(val);
				debuggerLogSource.Log((LogLevel)32, (object)"Original (32) asm");
				DetourGenerator.Disassemble(debuggerLogSource, OriginalFunctionPtr, 32);
			}
			Architecture architecture = ((IntPtr.Size == 8) ? Architecture.X64 : Architecture.X86);
			GenerateTrampolineInner(out var trampolineLength, out var jmpLength);
			DetourGenerator.ApplyDetour(OriginalFunctionPtr, DetourFunctionPtr, architecture, trampolineLength - jmpLength);
			if (debuggerLogSource != null)
			{
				LogLevel val2 = (LogLevel)32;
				LogLevel val3 = val2;
				BepInExLogInterpolatedStringHandler val4 = new BepInExLogInterpolatedStringHandler(25, 1, val2, ref flag);
				if (flag)
				{
					val4.AppendLiteral("Trampoline allocation: 0x");
					val4.AppendFormatted<string>(TrampolinePtr.ToString("X"));
				}
				debuggerLogSource.Log(val3, val4);
				debuggerLogSource.Log((LogLevel)32, (object)"Modified (32) asm");
				DetourGenerator.Disassemble(debuggerLogSource, OriginalFunctionPtr, 32);
				val3 = (LogLevel)32;
				val2 = val3;
				val4 = new BepInExLogInterpolatedStringHandler(17, 1, val3, ref flag);
				if (flag)
				{
					val4.AppendLiteral("Trampoline (");
					val4.AppendFormatted<int>(trampolineLength);
					val4.AppendLiteral(") asm");
				}
				debuggerLogSource.Log(val2, val4);
				DetourGenerator.Disassemble(debuggerLogSource, TrampolinePtr, trampolineLength);
			}
			DetourHelper.Native.MakeExecutable(OriginalFunctionPtr, 32u);
			IsApplied = true;
		}

		private void GenerateTrampolineInner(out int trampolineLength, out int jmpLength)
		{
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Expected O, but got Unknown
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			if (TrampolinePtr != IntPtr.Zero)
			{
				trampolineLength = TrampolineSize;
				jmpLength = TrampolineJmpSize;
				return;
			}
			byte[] array = new byte[32];
			Marshal.Copy(OriginalFunctionPtr, array, 0, 32);
			nint num = PageAllocator.Instance.Allocate(OriginalFunctionPtr);
			LogLevel val = (LogLevel)32;
			LogLevel val2 = val;
			bool flag = default(bool);
			BepInExLogInterpolatedStringHandler val3 = new BepInExLogInterpolatedStringHandler(57, 4, val, ref flag);
			if (flag)
			{
				val3.AppendLiteral("Original: ");
				val3.AppendFormatted<long>(OriginalFunctionPtr.ToInt64(), "X");
				val3.AppendLiteral(", Trampoline: ");
				val3.AppendFormatted((IntPtr)num, "X");
				val3.AppendLiteral(", diff: ");
				val3.AppendFormatted<long>(Math.Abs(OriginalFunctionPtr.ToInt64() - num), "X");
				val3.AppendLiteral("; is within +-1GB range: ");
				val3.AppendFormatted<bool>(PageAllocator.IsInRelJmpRange(OriginalFunctionPtr, num));
			}
			logger.Log(val2, val3);
			DetourHelper.Native.MakeWritable((IntPtr)num, 4096u);
			Architecture arch = ((IntPtr.Size == 8) ? Architecture.X64 : Architecture.X86);
			DetourGenerator.CreateTrampolineFromFunction(array, OriginalFunctionPtr, num, DetourGenerator.GetDetourLength(arch), arch, out trampolineLength, out jmpLength);
			DetourHelper.Native.MakeExecutable((IntPtr)num, 4096u);
			TrampolinePtr = num;
			TrampolineSize = trampolineLength;
			TrampolineJmpSize = jmpLength;
		}

		public static FastNativeDetour CreateAndApply<T>(IntPtr from, T to, out T original, CallingConvention? callingConvention = null) where T : Delegate
		{
			IntPtr detourFunctionPtr = (callingConvention.HasValue ? MonoExtensions.GetFunctionPointerForDelegate(to, callingConvention.Value) : Marshal.GetFunctionPointerForDelegate(to));
			FastNativeDetour fastNativeDetour = new FastNativeDetour(from, detourFunctionPtr);
			original = fastNativeDetour.GenerateTrampoline<T>();
			fastNativeDetour.Apply();
			return fastNativeDetour;
		}
	}
	public class IL2CPPDetourMethodPatcher : MethodPatcher
	{
		private static readonly MethodInfo IL2CPPToManagedStringMethodInfo = AccessTools.Method(typeof(IL2CPP), "Il2CppStringToManaged", (Type[])null, (Type[])null);

		private static readonly MethodInfo ManagedToIL2CPPStringMethodInfo = AccessTools.Method(typeof(IL2CPP), "ManagedStringToIl2Cpp", (Type[])null, (Type[])null);

		private static readonly MethodInfo ObjectBaseToPtrMethodInfo = AccessTools.Method(typeof(IL2CPP), "Il2CppObjectBaseToPtr", (Type[])null, (Type[])null);

		private static readonly MethodInfo ReportExceptionMethodInfo = AccessTools.Method(typeof(IL2CPPDetourMethodPatcher), "ReportException", (Type[])null, (Type[])null);

		private static readonly ManualLogSource DetourLogger = Logger.CreateLogSource("Detour");

		private static readonly Dictionary<Type, OpCode> StIndOpcodes = new Dictionary<Type, OpCode>
		{
			[typeof(byte)] = OpCodes.Stind_I1,
			[typeof(sbyte)] = OpCodes.Stind_I1,
			[typeof(bool)] = OpCodes.Stind_I1,
			[typeof(short)] = OpCodes.Stind_I2,
			[typeof(ushort)] = OpCodes.Stind_I2,
			[typeof(int)] = OpCodes.Stind_I4,
			[typeof(uint)] = OpCodes.Stind_I4,
			[typeof(long)] = OpCodes.Stind_I8,
			[typeof(ulong)] = OpCodes.Stind_I8,
			[typeof(float)] = OpCodes.Stind_R4,
			[typeof(double)] = OpCodes.Stind_R8
		};

		private static AssemblyBuilder fixedStructAssembly;

		private static ModuleBuilder fixedStructModuleBuilder;

		private static readonly Dictionary<int, Type> FixedStructCache = new Dictionary<int, Type>();

		private bool isValid;

		private INativeMethodInfoStruct modifiedNativeMethodInfo;

		private FastNativeDetour nativeDetour;

		private INativeMethodInfoStruct originalNativeMethodInfo;

		public IL2CPPDetourMethodPatcher(MethodBase original)
			: base(original)
		{
			Init();
		}

		private unsafe void Init()
		{
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Expected O, but got Unknown
			try
			{
				FieldInfo il2CppMethodInfoPointerFieldForGeneratedMethod = UnhollowerUtils.GetIl2CppMethodInfoPointerFieldForGeneratedMethod(((MethodPatcher)this).Original);
				if (il2CppMethodInfoPointerFieldForGeneratedMethod == null)
				{
					if (UnhollowerUtils.GetIl2CppFieldInfoPointerFieldForGeneratedFieldAccessor(((MethodPatcher)this).Original) != null)
					{
						throw new Exception("Method " + GeneralExtensions.FullDescription(((MethodPatcher)this).Original) + " is a field accessor, it can't be patched.");
					}
					return;
				}
				originalNativeMethodInfo = UnityVersionHandler.Wrap((Il2CppMethodInfo*)(void*)(IntPtr)il2CppMethodInfoPointerFieldForGeneratedMethod.GetValue(null));
				int trampolineLength;
				int jmpLength;
				IntPtr intPtr = DetourGenerator.CreateTrampolineFromFunction(originalNativeMethodInfo.MethodPointer, out trampolineLength, out jmpLength);
				modifiedNativeMethodInfo = UnityVersionHandler.NewMethod();
				Buffer.MemoryCopy(((INativeStruct)originalNativeMethodInfo).Pointer.ToPointer(), ((INativeStruct)modifiedNativeMethodInfo).Pointer.ToPointer(), UnityVersionHandler.MethodSize(), UnityVersionHandler.MethodSize());
				modifiedNativeMethodInfo.MethodPointer = intPtr;
				isValid = true;
			}
			catch (Exception ex)
			{
				bool flag = default(bool);
				BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(71, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Failed to init IL2CPP patch backend for ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(GeneralExtensions.FullDescription(((MethodPatcher)this).Original));
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(", using normal patch handlers: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
				}
				DetourLogger.LogWarning(val);
			}
		}

		public override DynamicMethodDefinition PrepareOriginal()
		{
			return null;
		}

		public override MethodBase DetourTo(MethodBase replacement)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Expected O, but got Unknown
			nativeDetour?.Dispose();
			DynamicMethodDefinition val = ((MethodPatcher)this).CopyOriginal();
			HarmonyManipulator.Manipulate(val.OriginalMethod, PatchManager.GetPatchInfo(val.OriginalMethod), new ILContext(val.Definition));
			MethodInfo methodInfo = val.Generate();
			MethodInfo methodInfo2 = GenerateNativeToManagedTrampoline(methodInfo).Generate();
			Type delegateType = DelegateTypeFactory.instance.CreateDelegateType(methodInfo2, (CallingConvention?)CallingConvention.Cdecl);
			IntPtr functionPointerForDelegate = Marshal.GetFunctionPointerForDelegate(methodInfo2.CreateDelegate(delegateType));
			nativeDetour = new FastNativeDetour(originalNativeMethodInfo.MethodPointer, functionPointerForDelegate);
			nativeDetour.Apply();
			return methodInfo;
		}

		public override DynamicMethodDefinition CopyOriginal()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Expected O, but got Unknown
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Expected O, but got Unknown
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			DynamicMethodDefinition val = new DynamicMethodDefinition(((MethodPatcher)this).Original);
			((MemberReference)val.Definition).Name = "UnhollowedWrapper_" + ((MemberReference)val.Definition).Name;
			ILCursor val2 = new ILCursor(new ILContext(val.Definition));
			FieldReference val3 = default(FieldReference);
			if (val2.TryGotoNext(new Func<Instruction, bool>[4]
			{
				(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0),
				(Instruction x) => ILPatternMatchingExt.MatchCall(x, typeof(IL2CPP), "Il2CppObjectBaseToPtr"),
				(Instruction x) => ILPatternMatchingExt.MatchLdsfld(x, ref val3),
				(Instruction x) => ILPatternMatchingExt.MatchCall(x, typeof(IL2CPP), "il2cpp_object_get_virtual_method")
			}))
			{
				val2.RemoveRange(4);
			}
			else
			{
				val2.Goto(0, (MoveType)0, false).GotoNext(new Func<Instruction, bool>[1]
				{
					(Instruction x) => ILPatternMatchingExt.MatchLdsfld(x, UnhollowerUtils.GetIl2CppMethodInfoPointerFieldForGeneratedMethod(((MethodPatcher)this).Original))
				}).Remove();
			}
			val2.Emit(OpCodes.Ldc_I8, ((INativeStruct)modifiedNativeMethodInfo).Pointer.ToInt64()).Emit(OpCodes.Conv_I);
			return val;
		}

		public static void TryResolve(object sender, PatcherResolverEventArgs args)
		{
			Type? declaringType = args.Original.DeclaringType;
			if ((object)declaringType != null && declaringType.IsSubclassOf(typeof(Il2CppObjectBase)))
			{
				IL2CPPDetourMethodPatcher iL2CPPDetourMethodPatcher = new IL2CPPDetourMethodPatcher(args.Original);
				if (iL2CPPDetourMethodPatcher.isValid)
				{
					args.MethodPatcher = (MethodPatcher)(object)iL2CPPDetourMethodPatcher;
				}
			}
		}

		private unsafe DynamicMethodDefinition GenerateNativeToManagedTrampoline(MethodInfo targetManagedMethodInfo)
		{
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Expected O, but got Unknown
			int num = 0;
			Type returnedType = AccessTools.GetReturnedType(((MethodPatcher)this).Original);
			bool flag = returnedType.IsSubclassOf(typeof(ValueType)) && Environment.Is64BitProcess;
			if (flag)
			{
				num++;
			}
			if (!((MethodPatcher)this).Original.IsStatic)
			{
				num++;
			}
			Type[] array = (from x in ((MethodPatcher)this).Original.GetParameters()
				select x.ParameterType).ToArray();
			Type[] array2 = new Type[array.Length + num + 1];
			if (flag)
			{
				array2[0] = typeof(IntPtr);
			}
			if (!((MethodPatcher)this).Original.IsStatic)
			{
				array2[num - 1] = typeof(IntPtr);
			}
			array2[^1] = typeof(Il2CppMethodInfo*);
			Array.Copy(array.Select(ConvertManagedTypeToIL2CPPType).ToArray(), 0, array2, num, array.Length);
			Type type = ConvertManagedTypeToIL2CPPType(returnedType);
			DynamicMethodDefinition val = new DynamicMethodDefinition("(il2cpp -> managed) " + ((MethodPatcher)this).Original.Name, type, array2);
			ILGenerator iLGenerator = val.GetILGenerator();
			iLGenerator.BeginExceptionBlock();
			LocalBuilder[] array3 = new LocalBuilder[array.Length];
			if (!((MethodPatcher)this).Original.IsStatic)
			{
				EmitConvertArgumentToManaged(iLGenerator, num - 1, ((MethodPatcher)this).Original.DeclaringType, out var _);
			}
			for (int i = 0; i < array.Length; i++)
			{
				EmitConvertArgumentToManaged(iLGenerator, i + num, array[i], out array3[i]);
			}
			iLGenerator.Emit(OpCodes.Call, targetManagedMethodInfo);
			LocalBuilder localBuilder = null;
			if (returnedType != typeof(void))
			{
				localBuilder = iLGenerator.DeclareLocal(returnedType);
				iLGenerator.Emit(OpCodes.Stloc, localBuilder);
			}
			for (int j = 0; j < array.Length; j++)
			{
				if (array3[j] != null)
				{
					iLGenerator.Emit(OpCodes.Ldarg_S, j + num);
					iLGenerator.Emit(OpCodes.Ldloc, array3[j]);
					Type elementType = array[j].GetElementType();
					EmitConvertManagedTypeToIL2CPP(iLGenerator, elementType);
					iLGenerator.Emit(StIndOpcodes.TryGetValue(elementType, out var value) ? value : OpCodes.Stind_I);
				}
			}
			iLGenerator.BeginCatchBlock(typeof(Exception));
			iLGenerator.Emit(OpCodes.Call, ReportExceptionMethodInfo);
			iLGenerator.EndExceptionBlock();
			if (localBuilder != null)
			{
				if (flag)
				{
					uint num2 = 0u;
					int arg = IL2CPP.il2cpp_class_value_size(Il2CppTypeToClassPointer(returnedType), ref num2);
					iLGenerator.Emit(OpCodes.Ldarg_0);
					iLGenerator.Emit(OpCodes.Ldloc, localBuilder);
					iLGenerator.Emit(OpCodes.Call, ObjectBaseToPtrMethodInfo);
					iLGenerator.Emit(OpCodes.Ldc_I4, arg);
					iLGenerator.Emit(OpCodes.Cpblk);
					iLGenerator.Emit(OpCodes.Ldarg_0);
				}
				else
				{
					iLGenerator.Emit(OpCodes.Ldloc, localBuilder);
					EmitConvertManagedTypeToIL2CPP(iLGenerator, returnedType);
				}
			}
			iLGenerator.Emit(OpCodes.Ret);
			return val;
		}

		private static void ReportException(Exception ex)
		{
			DetourLogger.Log((LogLevel)2, (object)ex.ToString());
		}

		private unsafe static Type ConvertManagedTypeToIL2CPPType(Type managedType)
		{
			if (managedType.IsByRef)
			{
				Type elementType = managedType.GetElementType();
				if (elementType == typeof(bool))
				{
					return typeof(byte).MakeByRefType();
				}
				if (elementType == typeof(string) || elementType.IsSubclassOf(typeof(Il2CppObjectBase)))
				{
					return typeof(IntPtr*);
				}
			}
			else
			{
				if (managedType.IsSubclassOf(typeof(ValueType)) && !Environment.Is64BitProcess)
				{
					uint num = 0u;
					return GetFixedSizeStructType(IL2CPP.il2cpp_class_value_size(Il2CppTypeToClassPointer(managedType), ref num));
				}
				if (managedType == typeof(string) || managedType.IsSubclassOf(typeof(Il2CppObjectBase)))
				{
					return typeof(IntPtr);
				}
				if (managedType == typeof(bool))
				{
					return typeof(byte);
				}
			}
			return managedType;
		}

		private static void EmitConvertManagedTypeToIL2CPP(ILGenerator il, Type returnType)
		{
			if (returnType == typeof(string))
			{
				il.Emit(OpCodes.Call, ManagedToIL2CPPStringMethodInfo);
			}
			else if (!returnType.IsValueType && returnType.IsSubclassOf(typeof(Il2CppObjectBase)))
			{
				il.Emit(OpCodes.Call, ObjectBaseToPtrMethodInfo);
			}
		}

		private static IntPtr Il2CppTypeToClassPointer(Type type)
		{
			if (type == typeof(void))
			{
				return Il2CppClassPointerStore<Void>.NativeClassPtr;
			}
			return (IntPtr)typeof(Il2CppClassPointerStore<>).MakeGenericType(type).GetField("NativeClassPtr").GetValue(null);
		}

		private static void EmitConvertArgumentToManaged(ILGenerator il, int argIndex, Type managedParamType, out LocalBuilder variable)
		{
			variable = null;
			if (managedParamType.IsSubclassOf(typeof(ValueType)))
			{
				il.Emit(OpCodes.Ldc_I8, Il2CppTypeToClassPointer(managedParamType).ToInt64());
				il.Emit(OpCodes.Conv_I);
				il.Emit(Environment.Is64BitProcess ? OpCodes.Ldarg : OpCodes.Ldarga_S, argIndex);
				il.Emit(OpCodes.Call, AccessTools.Method(typeof(IL2CPP), "il2cpp_value_box", (Type[])null, (Type[])null));
			}
			else
			{
				il.Emit(OpCodes.Ldarg_S, argIndex);
			}
			if (!managedParamType.IsValueType)
			{
				if (managedParamType.IsByRef)
				{
					Type elementType = managedParamType.GetElementType();
					variable = il.DeclareLocal(elementType);
					il.Emit(OpCodes.Ldind_I);
					HandleTypeConversion(elementType);
					il.Emit(OpCodes.Stloc, variable);
					il.Emit(OpCodes.Ldloca, variable);
				}
				else
				{
					HandleTypeConversion(managedParamType);
				}
			}
			void EmitCreateIl2CppObject(Type originalType)
			{
				Label label = il.DefineLabel();
				Label label2 = il.DefineLabel();
				il.Emit(OpCodes.Dup);
				il.Emit(OpCodes.Brtrue_S, label2);
				il.Emit(OpCodes.Pop);
				il.Emit(OpCodes.Ldnull);
				il.Emit(OpCodes.Br_S, label);
				il.MarkLabel(label2);
				il.Emit(OpCodes.Newobj, AccessTools.DeclaredConstructor(originalType, new Type[1] { typeof(IntPtr) }, false));
				il.MarkLabel(label);
			}
			void HandleTypeConversion(Type originalType)
			{
				if (originalType == typeof(string))
				{
					il.Emit(OpCodes.Call, IL2CPPToManagedStringMethodInfo);
				}
				else if (originalType.IsSubclassOf(typeof(Il2CppObjectBase)))
				{
					EmitCreateIl2CppObject(originalType);
				}
			}
		}

		private static Type GetFixedSizeStructType(int size)
		{
			if (FixedStructCache.TryGetValue(size, out var value))
			{
				return value;
			}
			if ((object)fixedStructAssembly == null)
			{
				fixedStructAssembly = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName("FixedSizeStructAssembly"), AssemblyBuilderAccess.RunAndCollect);
			}
			if ((object)fixedStructModuleBuilder == null)
			{
				fixedStructModuleBuilder = fixedStructAssembly.DefineDynamicModule("FixedSizeStructAssembly");
			}
			TypeBuilder typeBuilder = fixedStructModuleBuilder.DefineType($"IL2CPPDetour_FixedSizeStruct_{size}b", TypeAttributes.SequentialLayout, typeof(ValueType));
			typeBuilder.DefineField("buffer", typeof(IntPtr), FieldAttributes.Public).SetCustomAttribute(new CustomAttributeBuilder(AccessTools.Constructor(typeof(MarshalAsAttribute), new Type[1] { typeof(UnmanagedType) }, false), new object[1] { UnmanagedType.ByValArray }, new FieldInfo[2]
			{
				AccessTools.Field(typeof(MarshalAsAttribute), "SizeConst"),
				AccessTools.Field(typeof(MarshalAsAttribute), "ArraySubType")
			}, new object[2]
			{
				size,
				UnmanagedType.U1
			}));
			Type type = typeBuilder.CreateType();
			return FixedStructCache[size] = type;
		}
	}
	public class UnhollowerDetourHandler : IManagedDetour
	{
		public T Detour<T>(IntPtr from, T to) where T : Delegate
		{
			FastNativeDetour.CreateAndApply(from, to, out var original);
			return original;
		}
	}
}
namespace BepInEx.IL2CPP.Hook.Allocator
{
	internal class LinuxPageAllocator : UnixPageAllocator
	{
		protected override IEnumerable<(nint, nint)> MapMemoryAreas()
		{
			using StreamReader procMap = new StreamReader(File.OpenRead("/proc/self/maps"));
			string text;
			while ((text = procMap.ReadLine()) != null)
			{
				int num = text.IndexOf('-');
				int num2 = text.IndexOf(' ');
				long num3 = long.Parse(text.Substring(0, num), NumberStyles.HexNumber);
				int num4 = num + 1;
				long num5 = long.Parse(text.Substring(num4, num2 - num4), NumberStyles.HexNumber);
				yield return ((nint)num3, (nint)num5);
			}
		}
	}
	internal class MacOsPageAllocator : UnixPageAllocator
	{
		private static class LibSystem
		{
			public readonly struct vm_region_basic_info_64
			{
				public readonly int protection;

				public readonly int max_protection;

				public readonly uint inheritance;

				[MarshalAs(UnmanagedType.I4)]
				public readonly bool shared;

				[MarshalAs(UnmanagedType.I4)]
				public readonly bool reserved;

				public readonly ulong offset;

				public readonly int behavior;

				public readonly ushort user_wired_count;
			}

			public delegate int vm_region_64Delegate(nint target_task, ref nint address, ref nint size, int flavor, ref vm_region_basic_info_64 info, ref uint infoCnt, ref uint object_name);

			public const int VM_REGION_BASIC_INFO_64 = 9;

			public const int KERN_SUCCESS = 0;

			public static readonly nint TaskSelf;

			[DynDllImport("libSystem", new string[] { })]
			public static vm_region_64Delegate vm_region_64;

			static LibSystem()
			{
				DynDll.ResolveDynDllImports(typeof(LibSystem), new Dictionary<string, List<DynDllMapping>> { ["libSystem"] = new List<DynDllMapping> { DynDllMapping.op_Implicit("/usr/lib/libSystem.dylib") } });
				TaskSelf = DynDll.GetFunction(DynDll.OpenLibrary("/usr/lib/libSystem.dylib", false, (int?)null), "mach_task_self_");
			}
		}

		protected override IEnumerable<(nint, nint)> MapMemoryAreas()
		{
			LibSystem.vm_region_basic_info_64 info = default(LibSystem.vm_region_basic_info_64);
			uint infoCount = (uint)(Marshal.SizeOf<LibSystem.vm_region_basic_info_64>() / 4);
			uint objectName = 0u;
			nint address = 0;
			nint size = 0;
			while (LibSystem.vm_region_64(LibSystem.TaskSelf, ref address, ref size, 9, ref info, ref infoCount, ref objectName) == 0)
			{
				nint item = address;
				nint num = address + size;
				address = num;
				yield return (item, num);
			}
		}
	}
	internal class PageAllocatorException : Exception
	{
		public PageAllocatorException(string message)
			: base(message)
		{
		}
	}
	internal abstract class PageAllocator
	{
		private class PageChunk
		{
			public readonly bool[] Pages = new bool[16];

			public nint BaseAddress;

			public int UsedPages;

			public nint GetPage(int index)
			{
				return BaseAddress + index * 4096;
			}
		}

		public const int PAGE_SIZE = 4096;

		protected const int ALLOCATION_UNIT = 65536;

		protected const int PAGES_PER_UNIT = 16;

		private static PageAllocator instance;

		private readonly List<PageChunk> allocatedChunks = new List<PageChunk>();

		public static PageAllocator Instance => instance ?? (instance = Init());

		protected abstract nint AllocateChunk(nint hint);

		public virtual nint Allocate(nint hint)
		{
			foreach (PageChunk allocatedChunk in allocatedChunks)
			{
				if (allocatedChunk.UsedPages == 16)
				{
					continue;
				}
				for (int i = 0; i < allocatedChunk.Pages.Length; i++)
				{
					if (!allocatedChunk.Pages[i])
					{
						nint page = allocatedChunk.GetPage(i);
						if (IsInRelJmpRange(hint, page))
						{
							allocatedChunk.Pages[i] = true;
							allocatedChunk.UsedPages++;
							return page;
						}
					}
				}
			}
			PageChunk pageChunk = new PageChunk
			{
				BaseAddress = AllocateChunk(hint)
			};
			allocatedChunks.Add(pageChunk);
			pageChunk.Pages[0] = true;
			pageChunk.UsedPages++;
			return pageChunk.BaseAddress;
		}

		public void Free(nint page)
		{
			foreach (PageChunk allocatedChunk in allocatedChunks)
			{
				long num = (page - allocatedChunk.BaseAddress) / 4096;
				if (num >= 0 && num < 16)
				{
					if (allocatedChunk.Pages[num])
					{
						allocatedChunk.Pages[num] = false;
						allocatedChunk.UsedPages--;
					}
					break;
				}
			}
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static bool IsInRelJmpRange(nint src, nint dst)
		{
			nint num = dst - src;
			if (num <= int.MaxValue)
			{
				return num >= int.MinValue;
			}
			return false;
		}

		private static PageAllocator Init()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: 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)
			Platform current = PlatformHelper.Current;
			if (current.Is((Platform)37))
			{
				return new WindowsPageAllocator();
			}
			if (current.Is((Platform)137))
			{
				return new LinuxPageAllocator();
			}
			if (current.Is((Platform)73))
			{
				return new MacOsPageAllocator();
			}
			throw new NotSupportedException();
		}
	}
	internal static class PlatformExt
	{
		public static bool Is(this Platform pl, Platform val)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			return (Platform)(pl & val) == val;
		}
	}
	internal abstract class UnixPageAllocator : PageAllocator
	{
		private static class Unix
		{
			public delegate nint mmapDelegate(nint addr, nuint length, Protection prot, MapFlags flags, int fd, int offset);

			public delegate int munmapDelegate(nint addr, nuint length);

			[Flags]
			public enum MapFlags
			{
				MAP_PRIVATE = 2,
				MAP_ANONYMOUS = 0x20
			}

			[Flags]
			public enum Protection
			{
				PROT_READ = 1,
				PROT_WRITE = 2
			}

			public static readonly nint MAP_FAILED;

			[DynDllImport("mmap", new string[] { })]
			public static mmapDelegate mmap;

			[DynDllImport("munmap", new string[] { })]
			public static munmapDelegate munmap;

			static Unix()
			{
				MAP_FAILED = -1;
				DynDll.ResolveDynDllImports(typeof(Unix), new Dictionary<string, List<DynDllMapping>> { ["libc"] = new List<DynDllMapping>
				{
					DynDllMapping.op_Implicit("libc.so.6"),
					DynDllMapping.op_Implicit("libc"),
					DynDllMapping.op_Implicit("/usr/lib/libSystem.dylib")
				} });
			}
		}

		protected abstract IEnumerable<(nint, nint)> MapMemoryAreas();

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		private static bool CheckFreeRegionBefore(nint start, nint hint, ref (nint Start, nint End) region)
		{
			if (start < hint)
			{
				nint num = start - 4096;
				if (hint - num < int.MaxValue)
				{
					region.Start = num;
				}
			}
			return false;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		private static bool CheckFreeRegionAfter(nint end, nint hint, ref (nint Start, nint End) region)
		{
			if (hint < end)
			{
				if (end - hint < int.MaxValue)
				{
					region.End = end;
				}
				return true;
			}
			return false;
		}

		private (nint, nint) GetFreeArea(nint hint)
		{
			(IntPtr, IntPtr) region = ((IntPtr)0, (IntPtr)0);
			nint num = 0;
			foreach (var (num2, intPtr) in MapMemoryAreas())
			{
				if (num + 4096 <= num2 && (CheckFreeRegionBefore(num2, hint, ref region) || CheckFreeRegionAfter(num, hint, ref region)))
				{
					return region;
				}
				num = intPtr;
			}
			if (CheckFreeRegionAfter(num, hint, ref region))
			{
				return region;
			}
			throw new PageAllocatorException($"Could not find free region near {(long)hint:X8}");
		}

		protected override nint AllocateChunk(nint hint)
		{
			for (int i = 0; i < 3; i++)
			{
				(nint, nint) freeArea = GetFreeArea(hint);
				IntPtr item = freeArea.Item1;
				IntPtr item2 = freeArea.Item2;
				IntPtr[] array = new IntPtr[2] { item2, item };
				foreach (nint num in array)
				{
					if (num != 0)
					{
						nint num2 = Unix.mmap(num, 4096u, Unix.Protection.PROT_READ | Unix.Protection.PROT_WRITE, Unix.MapFlags.MAP_PRIVATE | Unix.MapFlags.MAP_ANONYMOUS, -1, 0);
						if (num2 == num)
						{
							return num2;
						}
						if (num2 == Unix.MAP_FAILED)
						{
							throw new Win32Exception(Marshal.GetLastWin32Error());
						}
						Unix.munmap(num2, 4096u);
					}
				}
			}
			throw new PageAllocatorException("Failed to allocate memory in unused regions");
		}
	}
	internal class WindowsPageAllocator : PageAllocator
	{
		private static class WinApi
		{
			[Flags]
			public enum AllocationType : uint
			{
				MEM_COMMIT = 0x1000u,
				MEM_RESERVE = 0x2000u
			}

			[Flags]
			public enum FreeType : uint
			{
				MEM_RELEASE = 0x8000u
			}

			public enum PageState : uint
			{
				MEM_FREE = 0x10000u
			}

			[Flags]
			public enum ProtectConstant : uint
			{
				PAGE_NOACCESS = 1u,
				PAGE_READWRITE = 4u
			}

			public struct MEMORY_BASIC_INFORMATION
			{
				public nint BaseAddress;

				public nint AllocationBase;

				public uint AllocationProtect;

				public nint RegionSize;

				public PageState State;

				public uint Protect;

				public uint Type;
			}

			private struct MEMORY_BASIC_INFORMATION64
			{
				public nint BaseAddress;

				public nint AllocationBase;

				public uint AllocationProtect;

				public uint __alignment1;

				public nint RegionSize;

				public PageState State;

				public uint Protect;

				public uint Type;

				public int __alignment2;
			}

			[DllImport("kerne

BepInExPack/BepInEx/core/BepInEx.Preloader.Core.dll

Decompiled a month ago
using System;
using System.Collections.Generic;
using System.ComponentModel;
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.Text;
using System.Text.RegularExpressions;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Shared;
using HarmonyLib;
using Mono.Cecil;
using MonoMod.Utils;
using SemanticVersioning;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: InternalsVisibleTo("BepInEx.Preloader.Unity")]
[assembly: InternalsVisibleTo("BepInEx.NetLauncher")]
[assembly: InternalsVisibleTo("BepInEx.NetCore")]
[assembly: InternalsVisibleTo("BepInEx.IL2CPP")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = "")]
[assembly: BuildInfo("BLEEDING EDGE Build #577 from ec79ad057b20c302c17b34e63906ee398352d852 at master")]
[assembly: AssemblyCompany("BepInEx")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyCopyright("Copyright © 2021 BepInEx Team")]
[assembly: AssemblyDescription("Core classes and utilities for BepInEx Preloader")]
[assembly: AssemblyFileVersion("6.0.0.577")]
[assembly: AssemblyInformationalVersion("6.0.0-be.577")]
[assembly: AssemblyProduct("BepInEx.Preloader.Core")]
[assembly: AssemblyTitle("BepInEx.Preloader.Core")]
[assembly: AssemblyVersion("6.0.0.577")]
namespace BepInEx.Shared
{
	[AttributeUsage(AttributeTargets.Assembly)]
	public class BuildInfoAttribute : Attribute
	{
		public string Info { get; }

		public BuildInfoAttribute(string info)
		{
			Info = info;
		}
	}
}
namespace BepInEx.Preloader.RuntimeFixes
{
	public static class ConsoleSetOutFix
	{
		private static LoggedTextWriter loggedTextWriter;

		internal static ManualLogSource ConsoleLogSource = Logger.CreateLogSource("Console");

		public static void Apply()
		{
			loggedTextWriter = new LoggedTextWriter
			{
				Parent = Console.Out
			};
			Console.SetOut(loggedTextWriter);
			Harmony.CreateAndPatchAll(typeof(ConsoleSetOutFix), (string)null);
		}

		[HarmonyPatch(typeof(Console), "SetOut")]
		[HarmonyPrefix]
		private static bool OnSetOut(TextWriter newOut)
		{
			loggedTextWriter.Parent = newOut;
			return false;
		}
	}
	internal class LoggedTextWriter : TextWriter
	{
		public override Encoding Encoding { get; } = Encoding.UTF8;


		public TextWriter Parent { get; set; }

		public override void Flush()
		{
			Parent.Flush();
		}

		public override void Write(string value)
		{
			ConsoleSetOutFix.ConsoleLogSource.Log((LogLevel)16, (object)value);
			Parent.Write(value);
		}

		public override void WriteLine(string value)
		{
			ConsoleSetOutFix.ConsoleLogSource.Log((LogLevel)16, (object)value);
			Parent.WriteLine(value);
		}
	}
	public static class HarmonyBackendFix
	{
		private enum MonoModBackend
		{
			[Description("Auto")]
			auto,
			[Description("DynamicMethod")]
			dynamicmethod,
			[Description("MethodBuilder")]
			methodbuilder,
			[Description("Cecil")]
			cecil
		}

		private static readonly ConfigEntry<MonoModBackend> ConfigHarmonyBackend = ConfigFile.CoreConfig.Bind<MonoModBackend>("Preloader", "HarmonyBackend", MonoModBackend.auto, "Specifies which MonoMod backend to use for Harmony patches. Auto uses the best available backend.\nThis setting should only be used for development purposes (e.g. debugging in dnSpy). Other code might override this setting.");

		public static void Initialize()
		{
			switch (ConfigHarmonyBackend.Value)
			{
			case MonoModBackend.dynamicmethod:
			case MonoModBackend.methodbuilder:
			case MonoModBackend.cecil:
				Environment.SetEnvironmentVariable("MONOMOD_DMD_TYPE", ConfigHarmonyBackend.Value.ToString());
				break;
			default:
				throw new ArgumentOutOfRangeException("ConfigHarmonyBackend", ConfigHarmonyBackend.Value, "Unknown backend");
			case MonoModBackend.auto:
				break;
			}
		}
	}
}
namespace BepInEx.Preloader.Core
{
	public class AssemblyBuildInfo
	{
		public enum FrameworkType
		{
			Unknown,
			NetFramework,
			NetStandard,
			NetCore
		}

		public Version NetFrameworkVersion { get; private set; }

		public bool IsAnyCpu { get; set; }

		public bool Is64Bit { get; set; }

		public FrameworkType AssemblyFrameworkType { get; set; }

		private void SetNet4Version(AssemblyDefinition assemblyDefinition)
		{
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: 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)
			NetFrameworkVersion = new Version(0, 0);
			AssemblyFrameworkType = FrameworkType.Unknown;
			CustomAttribute val = ((IEnumerable<CustomAttribute>)assemblyDefinition.CustomAttributes).FirstOrDefault((Func<CustomAttribute, bool>)((CustomAttribute x) => ((MemberReference)x.AttributeType).FullName == "System.Runtime.Versioning.TargetFrameworkAttribute"));
			if (val == null || val.ConstructorArguments.Count < 1)
			{
				return;
			}
			CustomAttributeArgument val2 = val.ConstructorArguments[0];
			if (((MemberReference)((CustomAttributeArgument)(ref val2)).Type).Name != "String")
			{
				return;
			}
			val2 = val.ConstructorArguments[0];
			string[] array = ((string)((CustomAttributeArgument)(ref val2)).Value).Split(',');
			foreach (string text in array)
			{
				if (text.StartsWith(".NET"))
				{
					AssemblyFrameworkType = text switch
					{
						".NETFramework" => FrameworkType.NetFramework, 
						".NETCoreApp" => FrameworkType.NetCore, 
						".NETStandard" => FrameworkType.NetStandard, 
						_ => FrameworkType.Unknown, 
					};
				}
				else if (text.StartsWith("Version=v"))
				{
					try
					{
						NetFrameworkVersion = new Version(text.Substring("Version=v".Length));
					}
					catch
					{
					}
				}
			}
		}

		public static AssemblyBuildInfo DetermineInfo(AssemblyDefinition assemblyDefinition)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Invalid comparison between Unknown and I4
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Invalid comparison between Unknown and I4
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Invalid comparison between Unknown and I4
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Invalid comparison between Unknown and I4
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Invalid comparison between Unknown and I4
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Invalid comparison between Unknown and I4
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			AssemblyBuildInfo assemblyBuildInfo = new AssemblyBuildInfo();
			TargetRuntime runtime = assemblyDefinition.MainModule.Runtime;
			if ((int)runtime == 0)
			{
				assemblyBuildInfo.NetFrameworkVersion = new Version(1, 0);
				assemblyBuildInfo.AssemblyFrameworkType = FrameworkType.NetFramework;
			}
			else if ((int)runtime == 1)
			{
				assemblyBuildInfo.NetFrameworkVersion = new Version(1, 1);
				assemblyBuildInfo.AssemblyFrameworkType = FrameworkType.NetFramework;
			}
			else if ((int)runtime == 2)
			{
				assemblyBuildInfo.NetFrameworkVersion = new Version(3, 5);
				assemblyBuildInfo.AssemblyFrameworkType = FrameworkType.NetFramework;
			}
			else
			{
				assemblyBuildInfo.SetNet4Version(assemblyDefinition);
			}
			TargetArchitecture architecture = assemblyDefinition.MainModule.Architecture;
			ModuleAttributes attributes = assemblyDefinition.MainModule.Attributes;
			if ((int)architecture == 34404)
			{
				assemblyBuildInfo.Is64Bit = true;
				assemblyBuildInfo.IsAnyCpu = false;
			}
			else if ((int)architecture == 332 && HasFlag(attributes, (ModuleAttributes)131074))
			{
				assemblyBuildInfo.Is64Bit = false;
				assemblyBuildInfo.IsAnyCpu = true;
			}
			else if ((int)architecture == 332 && HasFlag(attributes, (ModuleAttributes)2))
			{
				assemblyBuildInfo.Is64Bit = false;
				assemblyBuildInfo.IsAnyCpu = false;
			}
			else
			{
				if ((int)architecture != 332)
				{
					throw new Exception("Unable to determine assembly architecture");
				}
				assemblyBuildInfo.Is64Bit = true;
				assemblyBuildInfo.IsAnyCpu = true;
			}
			return assemblyBuildInfo;
		}

		private static bool HasFlag(ModuleAttributes value, ModuleAttributes flag)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			return (ModuleAttributes)(value & flag) == flag;
		}

		public override string ToString()
		{
			string arg = AssemblyFrameworkType switch
			{
				FrameworkType.NetFramework => "Framework", 
				FrameworkType.NetStandard => "Standard", 
				FrameworkType.NetCore => "Core", 
				FrameworkType.Unknown => "Unknown", 
				_ => throw new ArgumentOutOfRangeException(), 
			};
			if (IsAnyCpu)
			{
				return string.Format(".NET {0} {1}, AnyCPU ({2}-bit preferred)", arg, NetFrameworkVersion, Is64Bit ? "64" : "32");
			}
			return string.Format(".NET {0} {1}, {2}", arg, NetFrameworkVersion, Is64Bit ? "x64" : "x86");
		}
	}
	public static class EnvVars
	{
		public static string DOORSTOP_INVOKE_DLL_PATH { get; private set; }

		public static string DOORSTOP_MANAGED_FOLDER_DIR { get; private set; }

		public static string DOORSTOP_PROCESS_PATH { get; private set; }

		public static string[] DOORSTOP_DLL_SEARCH_DIRS { get; private set; }

		internal static void LoadVars()
		{
			DOORSTOP_INVOKE_DLL_PATH = Environment.GetEnvironmentVariable("DOORSTOP_INVOKE_DLL_PATH");
			DOORSTOP_MANAGED_FOLDER_DIR = Environment.GetEnvironmentVariable("DOORSTOP_MANAGED_FOLDER_DIR");
			DOORSTOP_PROCESS_PATH = Environment.GetEnvironmentVariable("DOORSTOP_PROCESS_PATH");
			DOORSTOP_DLL_SEARCH_DIRS = Environment.GetEnvironmentVariable("DOORSTOP_DLL_SEARCH_DIRS")?.Split(Path.PathSeparator) ?? new string[0];
		}
	}
	public static class PreloaderLogger
	{
		public static ManualLogSource Log { get; } = Logger.CreateLogSource("Preloader");

	}
	internal static class PlatformUtils
	{
		[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode, Pack = 1)]
		public struct WindowsOSVersionInfoExW
		{
			public uint dwOSVersionInfoSize;

			public uint dwMajorVersion;

			public uint dwMinorVersion;

			public uint dwBuildNumber;

			public uint dwPlatformId;

			[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
			public string szCSDVersion;

			public ushort wServicePackMajor;

			public ushort wServicePackMinor;

			public ushort wSuiteMask;

			public byte wProductType;

			public byte wReserved;

			public WindowsOSVersionInfoExW()
			{
				dwOSVersionInfoSize = (uint)Marshal.SizeOf(typeof(WindowsOSVersionInfoExW));
				dwMajorVersion = 0u;
				dwMinorVersion = 0u;
				dwBuildNumber = 0u;
				dwPlatformId = 0u;
				szCSDVersion = null;
				wServicePackMajor = 0;
				wServicePackMinor = 0;
				wSuiteMask = 0;
				wProductType = 0;
				wReserved = 0;
			}
		}

		[StructLayout(LayoutKind.Sequential, Pack = 1)]
		public struct utsname_osx
		{
			private const int osx_utslen = 256;

			[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
			public string sysname;

			[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
			public string nodename;

			[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
			public string release;

			[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
			public string version;

			[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
			public string machine;
		}

		[StructLayout(LayoutKind.Sequential, Pack = 1)]
		public struct utsname_linux
		{
			private const int linux_utslen = 65;

			[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 65)]
			public string sysname;

			[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 65)]
			public string nodename;

			[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 65)]
			public string release;

			[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 65)]
			public string version;

			[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 65)]
			public string machine;

			[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 65)]
			public string domainname;
		}

		public static readonly bool ProcessIs64Bit = IntPtr.Size >= 8;

		public static Version WindowsVersion { get; set; }

		public static string LinuxArchitecture { get; set; }

		public static string LinuxKernelVersion { get; set; }

		[DllImport("libc.so.6", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, EntryPoint = "uname")]
		private static extern IntPtr uname_linux(ref utsname_linux utsname);

		[DllImport("/usr/lib/libSystem.dylib", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, EntryPoint = "uname")]
		private static extern IntPtr uname_osx(ref utsname_osx utsname);

		[DllImport("ntdll.dll", SetLastError = true)]
		private static extern bool RtlGetVersion(ref WindowsOSVersionInfoExW versionInfo);

		private static bool Is(this Platform current, Platform expected)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			return (Platform)(current & expected) == expected;
		}

		public static void SetPlatform()
		{
			//IL_0002: 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_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: 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_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: 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_025d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0263: Unknown result type (might be due to invalid IL or missing references)
			//IL_0264: Unknown result type (might be due to invalid IL or missing references)
			//IL_0232: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: Unknown result type (might be due to invalid IL or missing references)
			//IL_0239: Unknown result type (might be due to invalid IL or missing references)
			Platform val = (Platform)17;
			PropertyInfo property = typeof(Environment).GetProperty("Platform", BindingFlags.Static | BindingFlags.NonPublic);
			string text = ((!(property != null)) ? Environment.OSVersion.Platform.ToString() : property.GetValue(null, new object[0]).ToString());
			text = text.ToLowerInvariant();
			if (text.Contains("win"))
			{
				val = (Platform)37;
			}
			else if (text.Contains("mac") || text.Contains("osx"))
			{
				val = (Platform)73;
			}
			else if (text.Contains("lin") || text.Contains("unix"))
			{
				val = (Platform)137;
			}
			if (val.Is((Platform)137) && Directory.Exists("/data") && File.Exists("/system/build.prop"))
			{
				val = (Platform)393;
			}
			else if (val.Is((Platform)8) && Directory.Exists("/System/Library/AccessibilityBundles"))
			{
				val = (Platform)585;
			}
			if (val.Is((Platform)37))
			{
				WindowsOSVersionInfoExW versionInfo = new WindowsOSVersionInfoExW();
				RtlGetVersion(ref versionInfo);
				WindowsVersion = new Version((int)versionInfo.dwMajorVersion, (int)versionInfo.dwMinorVersion, 0, (int)versionInfo.dwBuildNumber);
			}
			MethodInfo methodInfo = typeof(Environment).GetProperty("Is64BitOperatingSystem")?.GetGetMethod();
			val = (Platform)((!(methodInfo != null)) ? (val | ((IntPtr.Size >= 8) ? 2 : 0)) : (val | (((bool)methodInfo.Invoke(null, new object[0])) ? 2 : 0)));
			if ((val.Is((Platform)73) || val.Is((Platform)137)) && Type.GetType("Mono.Runtime") != null)
			{
				IntPtr intPtr;
				string machine;
				if (val.Is((Platform)73))
				{
					utsname_osx utsname = default(utsname_osx);
					intPtr = uname_osx(ref utsname);
					machine = utsname.machine;
				}
				else
				{
					utsname_linux utsname2 = default(utsname_linux);
					intPtr = uname_linux(ref utsname2);
					machine = utsname2.machine;
					LinuxArchitecture = utsname2.machine;
					LinuxKernelVersion = utsname2.version;
				}
				if (intPtr == IntPtr.Zero && (machine.StartsWith("aarch") || machine.StartsWith("arm")))
				{
					val = (Platform)(val | 0x10000);
				}
			}
			else
			{
				typeof(object).Module.GetPEKind(out var _, out var machine2);
				if (machine2 == ImageFileMachine.ARM)
				{
					val = (Platform)(val | 0x10000);
				}
			}
			PlatformHelper.Current = val;
		}
	}
}
namespace BepInEx.Preloader.Core.Patching
{
	public class AssemblyPatcher : IDisposable
	{
		private static readonly string CurrentAssemblyName = Assembly.GetExecutingAssembly().GetName().Name;

		private static readonly ConfigEntry<bool> ConfigDumpAssemblies = ConfigFile.CoreConfig.Bind<bool>("Preloader", "DumpAssemblies", false, "If enabled, BepInEx will save patched assemblies into BepInEx/DumpedAssemblies.\nThis can be used by developers to inspect and debug preloader patchers.");

		private static readonly ConfigEntry<bool> ConfigLoadDumpedAssemblies = ConfigFile.CoreConfig.Bind<bool>("Preloader", "LoadDumpedAssemblies", false, "If enabled, BepInEx will load patched assemblies from BepInEx/DumpedAssemblies instead of memory.\nThis can be used to be able to load patched assemblies into debuggers like dnSpy.\nIf set to true, will override DumpAssemblies.");

		private static readonly ConfigEntry<bool> ConfigBreakBeforeLoadAssemblies = ConfigFile.CoreConfig.Bind<bool>("Preloader", "BreakBeforeLoadAssemblies", false, "If enabled, BepInEx will call Debugger.Break() once before loading patched assemblies.\nThis can be used with debuggers like dnSpy to install breakpoints into patched assemblies before they are loaded.");

		public PatcherContext PatcherContext { get; } = new PatcherContext
		{
			DumpedAssembliesPath = Utility.CombinePaths(new string[3]
			{
				Paths.BepInExRootPath,
				"DumpedAssemblies",
				Paths.ProcessName
			})
		};


		private IEnumerable<BasePatcher> PatcherPluginsSafe => PatcherContext.PatcherPlugins.ToList();

		private ManualLogSource Logger { get; } = Logger.CreateLogSource("AssemblyPatcher");


		private static Regex allowedGuidRegex { get; } = new Regex("^[a-zA-Z0-9\\._\\-]+$");


		public void Dispose()
		{
			foreach (KeyValuePair<string, AssemblyDefinition> availableAssembly in PatcherContext.AvailableAssemblies)
			{
				availableAssembly.Value.Dispose();
			}
			PatcherContext.AvailableAssemblies.Clear();
			PatcherContext.PatcherPlugins.Clear();
		}

		private PatcherPluginMetadata ToPatcherPlugin(TypeDefinition type, string assemblyPath)
		{
			//IL_004f: 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_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Expected O, but got Unknown
			//IL_00b8: 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_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Expected O, but got Unknown
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Expected O, but got Unknown
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Expected O, but got Unknown
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			if (type.IsInterface || (type.IsAbstract && !type.IsSealed))
			{
				return null;
			}
			try
			{
				if (!Utility.IsSubtypeOf(type, typeof(BasePatcher)))
				{
					return null;
				}
			}
			catch (AssemblyResolutionException)
			{
				return null;
			}
			PatcherPluginInfoAttribute patcherPluginInfoAttribute = PatcherPluginInfoAttribute.FromCecilType(type);
			bool flag = default(bool);
			if (patcherPluginInfoAttribute == null)
			{
				ManualLogSource logger = Logger;
				LogLevel val2 = (LogLevel)4;
				LogLevel val3 = val2;
				BepInExLogInterpolatedStringHandler val4 = new BepInExLogInterpolatedStringHandler(59, 1, val2, ref flag);
				if (flag)
				{
					val4.AppendLiteral("Skipping over type [");
					val4.AppendFormatted<string>(((MemberReference)type).FullName);
					val4.AppendLiteral("] as no metadata attribute is specified");
				}
				logger.Log(val3, val4);
				return null;
			}
			if (string.IsNullOrEmpty(patcherPluginInfoAttribute.GUID) || !allowedGuidRegex.IsMatch(patcherPluginInfoAttribute.GUID))
			{
				ManualLogSource logger2 = Logger;
				LogLevel val3 = (LogLevel)4;
				LogLevel val2 = val3;
				BepInExLogInterpolatedStringHandler val4 = new BepInExLogInterpolatedStringHandler(60, 2, val3, ref flag);
				if (flag)
				{
					val4.AppendLiteral("Skipping type [");
					val4.AppendFormatted<string>(((MemberReference)type).FullName);
					val4.AppendLiteral("] because its GUID [");
					val4.AppendFormatted<string>(patcherPluginInfoAttribute.GUID);
					val4.AppendLiteral("] is of an illegal format");
				}
				logger2.Log(val2, val4);
				return null;
			}
			if (patcherPluginInfoAttribute.Version == (Version)null)
			{
				ManualLogSource logger3 = Logger;
				LogLevel val2 = (LogLevel)4;
				LogLevel val3 = val2;
				BepInExLogInterpolatedStringHandler val4 = new BepInExLogInterpolatedStringHandler(47, 1, val2, ref flag);
				if (flag)
				{
					val4.AppendLiteral("Skipping type [");
					val4.AppendFormatted<string>(((MemberReference)type).FullName);
					val4.AppendLiteral("] because its version is invalid");
				}
				logger3.Log(val3, val4);
				return null;
			}
			if (patcherPluginInfoAttribute.Name == null)
			{
				ManualLogSource logger4 = Logger;
				LogLevel val3 = (LogLevel)4;
				LogLevel val2 = val3;
				BepInExLogInterpolatedStringHandler val4 = new BepInExLogInterpolatedStringHandler(41, 1, val3, ref flag);
				if (flag)
				{
					val4.AppendLiteral("Skipping type [");
					val4.AppendFormatted<string>(((MemberReference)type).FullName);
					val4.AppendLiteral("] because its name is null");
				}
				logger4.Log(val2, val4);
				return null;
			}
			return new PatcherPluginMetadata
			{
				TypeName = ((MemberReference)type).FullName
			};
		}

		private bool HasPatcherPlugins(AssemblyDefinition ass)
		{
			if (((IEnumerable<AssemblyNameReference>)ass.MainModule.AssemblyReferences).All((AssemblyNameReference r) => r.Name != CurrentAssemblyName) && ((AssemblyNameReference)ass.Name).Name != CurrentAssemblyName)
			{
				return false;
			}
			if (ass.MainModule.GetTypeReferences().All((TypeReference r) => ((MemberReference)r).FullName != typeof(BasePatcher).FullName))
			{
				return false;
			}
			return true;
		}

		public void AddPatchersFromDirectory(string directory)
		{
			//IL_0295: Unknown result type (might be due to invalid IL or missing references)
			//IL_0297: Unknown result type (might be due to invalid IL or missing references)
			//IL_0299: Unknown result type (might be due to invalid IL or missing references)
			//IL_029e: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a9: Expected O, but got Unknown
			//IL_02f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_033c: Unknown result type (might be due to invalid IL or missing references)
			//IL_033e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0340: Unknown result type (might be due to invalid IL or missing references)
			//IL_0345: Unknown result type (might be due to invalid IL or missing references)
			//IL_0349: Unknown result type (might be due to invalid IL or missing references)
			//IL_0350: Expected O, but got Unknown
			//IL_03da: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Expected O, but got Unknown
			//IL_020c: Unknown result type (might be due to invalid IL or missing references)
			if (!Directory.Exists(directory))
			{
				return;
			}
			List<PatchDefinition> sortedPatchers = new List<PatchDefinition>();
			bool flag = default(bool);
			foreach (KeyValuePair<string, List<PatcherPluginMetadata>> item in TypeLoader.FindPluginTypes<PatcherPluginMetadata>(directory, (Func<TypeDefinition, string, PatcherPluginMetadata>)ToPatcherPlugin, (Func<AssemblyDefinition, bool>)HasPatcherPlugins, (string)null))
			{
				string key = item.Key;
				List<PatcherPluginMetadata> value = item.Value;
				if (value.Count == 0)
				{
					continue;
				}
				Assembly assembly = Assembly.LoadFrom(key);
				LogLevel val;
				LogLevel val2;
				BepInExLogInterpolatedStringHandler val3;
				foreach (PatcherPluginMetadata item2 in value)
				{
					try
					{
						Type? type = assembly.GetType(item2.TypeName);
						BasePatcher basePatcher = (BasePatcher)Activator.CreateInstance(type);
						basePatcher.Context = PatcherContext;
						PatcherContext.PatcherPlugins.Add(basePatcher);
						MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
						foreach (MethodInfo methodInfo in methods)
						{
							TargetAssemblyAttribute[] attributes = MetadataHelper.GetAttributes<TargetAssemblyAttribute>((MemberInfo)methodInfo);
							TargetTypeAttribute[] attributes2 = MetadataHelper.GetAttributes<TargetTypeAttribute>((MemberInfo)methodInfo);
							if (attributes.Length == 0 && attributes2.Length == 0)
							{
								continue;
							}
							ParameterInfo[] parameters = methodInfo.GetParameters();
							if (parameters.Length < 1 || parameters.Length > 2 || (!(parameters[0].ParameterType == typeof(AssemblyDefinition)) && (!(parameters[0].ParameterType == typeof(AssemblyDefinition).MakeByRefType()) || attributes2.Length != 0) && (!(parameters[0].ParameterType == typeof(TypeDefinition)) || attributes.Length != 0)) || (parameters.Length == 2 && parameters[1].ParameterType != typeof(string)) || (methodInfo.ReturnType != typeof(void) && methodInfo.ReturnType != typeof(bool)))
							{
								ManualLogSource logger = Logger;
								val = (LogLevel)4;
								val2 = val;
								val3 = new BepInExLogInterpolatedStringHandler(54, 1, val, ref flag);
								if (flag)
								{
									val3.AppendLiteral("Skipping method [");
									val3.AppendFormatted<string>(GeneralExtensions.FullDescription((MethodBase)methodInfo));
									val3.AppendLiteral("] as it is not a valid patcher method");
								}
								logger.Log(val2, val3);
							}
							else
							{
								TargetAssemblyAttribute[] array = attributes;
								foreach (TargetAssemblyAttribute targetAssembly in array)
								{
									AddDefinition(new PatchDefinition(targetAssembly, basePatcher, methodInfo));
								}
								TargetTypeAttribute[] array2 = attributes2;
								foreach (TargetTypeAttribute targetType in array2)
								{
									AddDefinition(new PatchDefinition(targetType, basePatcher, methodInfo));
								}
							}
						}
					}
					catch (Exception ex)
					{
						ManualLogSource logger2 = Logger;
						val2 = (LogLevel)2;
						val = val2;
						val3 = new BepInExLogInterpolatedStringHandler(38, 2, val2, ref flag);
						if (flag)
						{
							val3.AppendLiteral("Failed to load patchers from type [");
							val3.AppendFormatted<string>(item2.TypeName);
							val3.AppendLiteral("]: ");
							val3.AppendFormatted<string>((ex is ReflectionTypeLoadException ex2) ? TypeLoader.TypeLoadExceptionToString(ex2) : ex.ToString());
						}
						logger2.Log(val, val3);
					}
				}
				AssemblyName name = assembly.GetName();
				ManualLogSource logger3 = Logger;
				val = (LogLevel)(value.Any() ? 16 : 32);
				val2 = val;
				val3 = new BepInExLogInterpolatedStringHandler(29, 4, val, ref flag);
				if (flag)
				{
					val3.AppendLiteral("Loaded ");
					val3.AppendFormatted<int>(value.Count);
					val3.AppendLiteral(" patcher type");
					val3.AppendFormatted<string>((value.Count == 1) ? "" : "s");
					val3.AppendLiteral(" from [");
					val3.AppendFormatted<string>(name.Name);
					val3.AppendLiteral(" ");
					val3.AppendFormatted<Version>(name.Version);
					val3.AppendLiteral("]");
				}
				logger3.Log(val2, val3);
			}
			PatcherContext.PatchDefinitions.AddRange(sortedPatchers);
			void AddDefinition(PatchDefinition definition)
			{
				//IL_0008: Unknown result type (might be due to invalid IL or missing references)
				//IL_0009: Unknown result type (might be due to invalid IL or missing references)
				//IL_000a: Unknown result type (might be due to invalid IL or missing references)
				//IL_000e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0011: Unknown result type (might be due to invalid IL or missing references)
				//IL_0017: Expected O, but got Unknown
				//IL_003c: Unknown result type (might be due to invalid IL or missing references)
				ManualLogSource logger4 = Logger;
				LogLevel val4 = (LogLevel)32;
				LogLevel val5 = val4;
				bool flag2 = default(bool);
				BepInExLogInterpolatedStringHandler val6 = new BepInExLogInterpolatedStringHandler(19, 1, val4, ref flag2);
				if (flag2)
				{
					val6.AppendLiteral("Discovered patch [");
					val6.AppendFormatted<string>(definition.FullName);
					val6.AppendLiteral("]");
				}
				logger4.Log(val5, val6);
				sortedPatchers.Add(definition);
			}
		}

		public void LoadAssemblyDirectories(params string[] directories)
		{
			LoadAssemblyDirectories(directories, new string[1] { "dll" });
		}

		public void LoadAssemblyDirectories(IEnumerable<string> directories, IEnumerable<string> assemblyExtensions)
		{
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Expected O, but got Unknown
			bool flag = default(bool);
			foreach (string item in assemblyExtensions.SelectMany((string ext) => Utility.GetUniqueFilesInDirectories(directories, "*." + ext)))
			{
				if (!TryLoadAssembly(item, out var assembly))
				{
					continue;
				}
				if (((AssemblyNameReference)assembly.Name).Name == "System" || ((AssemblyNameReference)assembly.Name).Name == "mscorlib")
				{
					assembly.Dispose();
					continue;
				}
				PatcherContext.AvailableAssemblies.Add(Path.GetFileName(item), assembly);
				ManualLogSource logger = Logger;
				BepInExDebugLogInterpolatedStringHandler val = new BepInExDebugLogInterpolatedStringHandler(17, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Assembly loaded: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(Path.GetFileName(item));
				}
				logger.LogDebug(val);
			}
		}

		public static bool TryLoadAssembly(string path, out AssemblyDefinition assembly)
		{
			try
			{
				assembly = AssemblyDefinition.ReadAssembly(path, TypeLoader.ReaderParameters);
				return true;
			}
			catch (BadImageFormatException)
			{
				assembly = null;
				return false;
			}
		}

		public void PatchAndLoad()
		{
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Expected O, but got Unknown
			//IL_06d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_06d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_06da: Unknown result type (might be due to invalid IL or missing references)
			//IL_06df: Unknown result type (might be due to invalid IL or missing references)
			//IL_06e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_06ea: Expected O, but got Unknown
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_0722: 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_00ea: Unknown result type (might be due to invalid IL or missing references)
			//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_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Expected O, but got Unknown
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_04fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0502: Unknown result type (might be due to invalid IL or missing references)
			//IL_0509: Expected O, but got Unknown
			//IL_0535: Unknown result type (might be due to invalid IL or missing references)
			//IL_0546: Unknown result type (might be due to invalid IL or missing references)
			//IL_0548: Unknown result type (might be due to invalid IL or missing references)
			//IL_054a: Unknown result type (might be due to invalid IL or missing references)
			//IL_054f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0553: Unknown result type (might be due to invalid IL or missing references)
			//IL_055a: Expected O, but got Unknown
			//IL_057c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0642: Unknown result type (might be due to invalid IL or missing references)
			//IL_0644: Unknown result type (might be due to invalid IL or missing references)
			//IL_0646: Unknown result type (might be due to invalid IL or missing references)
			//IL_064b: Unknown result type (might be due to invalid IL or missing references)
			//IL_064f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0656: Expected O, but got Unknown
			//IL_0680: Unknown result type (might be due to invalid IL or missing references)
			Dictionary<string, AssemblyDefinition> dictionary = new Dictionary<string, AssemblyDefinition>(PatcherContext.AvailableAssemblies, StringComparer.InvariantCultureIgnoreCase);
			bool flag = default(bool);
			LogLevel val2;
			LogLevel val;
			BepInExLogInterpolatedStringHandler val3;
			foreach (BasePatcher item in PatcherPluginsSafe)
			{
				try
				{
					item.Initialize();
				}
				catch (Exception ex)
				{
					ManualLogSource logger = Logger;
					val = (LogLevel)2;
					val2 = val;
					val3 = new BepInExLogInterpolatedStringHandler(31, 2, val, ref flag);
					if (flag)
					{
						val3.AppendLiteral("Failed to run initializer of ");
						val3.AppendFormatted<string>(item.Info.GUID);
						val3.AppendLiteral(": ");
						val3.AppendFormatted<Exception>(ex);
					}
					logger.Log(val2, val3);
				}
			}
			HashSet<string> patchedAssemblies = new HashSet<string>(StringComparer.InvariantCultureIgnoreCase);
			Dictionary<string, string> dictionary2 = new Dictionary<string, string>();
			HashSet<string> invalidAssemblies = new HashSet<string>(StringComparer.InvariantCultureIgnoreCase);
			ManualLogSource logger2 = Logger;
			val2 = (LogLevel)8;
			val = val2;
			val3 = new BepInExLogInterpolatedStringHandler(20, 1, val2, ref flag);
			if (flag)
			{
				val3.AppendLiteral("Executing ");
				val3.AppendFormatted<int>(PatcherContext.PatchDefinitions.Count);
				val3.AppendLiteral(" patch(es)");
			}
			logger2.Log(val, val3);
			AssemblyName assemblyName = default(AssemblyName);
			foreach (PatchDefinition item2 in PatcherContext.PatchDefinitions.ToList())
			{
				PatchDefinition patchDefinition = item2;
				string text = patchDefinition.TargetAssembly?.TargetAssembly ?? patchDefinition.TargetType.TargetAssembly;
				bool isAssemblyPatch = patchDefinition.TargetAssembly != null;
				if (text == "_all")
				{
					foreach (KeyValuePair<string, AssemblyDefinition> item3 in PatcherContext.AvailableAssemblies.ToList())
					{
						if (!invalidAssemblies.Contains(item3.Key))
						{
							RunPatcher(item3.Value, item3.Key);
						}
					}
				}
				else
				{
					if (!PatcherContext.AvailableAssemblies.TryGetValue(text, out var value) || invalidAssemblies.Contains(text))
					{
						continue;
					}
					RunPatcher(value, text);
				}
				Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
				foreach (Assembly assembly2 in assemblies)
				{
					string key = (Utility.TryParseAssemblyName(assembly2.FullName, ref assemblyName) ? assemblyName.Name : assembly2.FullName);
					if (!dictionary2.ContainsKey(key))
					{
						dictionary2[key] = patchDefinition.MethodInfo.DeclaringType.ToString();
					}
				}
				bool RunPatcher(AssemblyDefinition assembly, string targetDll)
				{
					//IL_0193: Unknown result type (might be due to invalid IL or missing references)
					//IL_0195: Unknown result type (might be due to invalid IL or missing references)
					//IL_0197: Unknown result type (might be due to invalid IL or missing references)
					//IL_019c: Unknown result type (might be due to invalid IL or missing references)
					//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
					//IL_01a7: Expected O, but got Unknown
					//IL_01fc: 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_005e: Expected O, but got Unknown
					//IL_0143: Unknown result type (might be due to invalid IL or missing references)
					//IL_014a: Expected O, but got Unknown
					try
					{
						object[] array = new object[patchDefinition.MethodInfo.GetParameters().Length];
						if (!isAssemblyPatch)
						{
							TypeDefinition val4 = ((IEnumerable<TypeDefinition>)assembly.MainModule.Types).FirstOrDefault((Func<TypeDefinition, bool>)((TypeDefinition x) => ((MemberReference)x).FullName == patchDefinition.TargetType.TargetType));
							if (val4 == null)
							{
								ManualLogSource logger7 = Logger;
								bool flag2 = default(bool);
								BepInExWarningLogInterpolatedStringHandler val5 = new BepInExWarningLogInterpolatedStringHandler(52, 2, ref flag2);
								if (flag2)
								{
									((BepInExLogInterpolatedStringHandler)val5).AppendLiteral("Unable to find type [");
									((BepInExLogInterpolatedStringHandler)val5).AppendFormatted<string>(patchDefinition.TargetType.TargetType);
									((BepInExLogInterpolatedStringHandler)val5).AppendLiteral("] defined in ");
									((BepInExLogInterpolatedStringHandler)val5).AppendFormatted<string>(patchDefinition.MethodInfo.Name);
									((BepInExLogInterpolatedStringHandler)val5).AppendLiteral(". Skipping patcher");
								}
								logger7.LogWarning(val5);
								return false;
							}
							array[0] = val4;
						}
						else
						{
							array[0] = assembly;
						}
						if (array.Length > 1)
						{
							array[1] = targetDll;
						}
						object obj = patchDefinition.MethodInfo.Invoke(patchDefinition.Instance, array);
						if (patchDefinition.MethodInfo.ReturnType == typeof(void) || (patchDefinition.MethodInfo.ReturnType == typeof(bool) && (bool)obj))
						{
							if (isAssemblyPatch)
							{
								assembly = (AssemblyDefinition)array[0];
								PatcherContext.AvailableAssemblies[targetDll] = assembly;
							}
							patchedAssemblies.Add(targetDll);
						}
						return true;
					}
					catch (Exception ex3)
					{
						ManualLogSource logger8 = Logger;
						LogLevel val6 = (LogLevel)2;
						LogLevel val7 = val6;
						bool flag3 = default(bool);
						BepInExLogInterpolatedStringHandler val8 = new BepInExLogInterpolatedStringHandler(77, 3, val6, ref flag3);
						if (flag3)
						{
							val8.AppendLiteral("Failed to run [");
							val8.AppendFormatted<string>(patchDefinition.FullName);
							val8.AppendLiteral("] when patching [");
							val8.AppendFormatted<string>(((AssemblyNameReference)assembly.Name).Name);
							val8.AppendLiteral("]. This assembly will not be patched. Error: ");
							val8.AppendFormatted<Exception>(ex3);
						}
						logger8.Log(val7, val8);
						patchedAssemblies.Remove(targetDll);
						invalidAssemblies.Add(targetDll);
						return false;
					}
				}
			}
			HashSet<string> patchedAssemblyNames = new HashSet<string>(from kv in dictionary
				where patchedAssemblies.Contains(kv.Key)
				select ((AssemblyNameReference)kv.Value.Name).Name, StringComparer.InvariantCultureIgnoreCase);
			List<KeyValuePair<string, string>> list = dictionary2.Where((KeyValuePair<string, string> kv) => patchedAssemblyNames.Contains(kv.Key)).ToList();
			if (list.Count != 0)
			{
				Logger.Log((LogLevel)4, (object)new StringBuilder().AppendLine("The following assemblies have been loaded too early and will not be patched by preloader:").AppendLine(string.Join(Environment.NewLine, list.Select((KeyValuePair<string, string> kv) => "* [" + kv.Key + "] (first loaded by [" + kv.Value + "])").ToArray())).AppendLine("Expect unexpected behavior and issues with plugins and patchers not being loaded.")
					.ToString());
			}
			Dictionary<string, string> dictionary3 = new Dictionary<string, string>();
			if (ConfigDumpAssemblies.Value || ConfigLoadDumpedAssemblies.Value)
			{
				if (!Directory.Exists(PatcherContext.DumpedAssembliesPath))
				{
					Directory.CreateDirectory(PatcherContext.DumpedAssembliesPath);
				}
				FileStream fileStream = default(FileStream);
				foreach (KeyValuePair<string, AssemblyDefinition> item4 in dictionary)
				{
					string key2 = item4.Key;
					string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(key2);
					string extension = Path.GetExtension(key2);
					AssemblyDefinition value2 = item4.Value;
					if (!patchedAssemblies.Contains(key2))
					{
						continue;
					}
					int num = 0;
					string text3;
					while (true)
					{
						string text2 = ((num > 0) ? $"_{num}" : "");
						text3 = Path.Combine(PatcherContext.DumpedAssembliesPath, fileNameWithoutExtension + text2 + extension);
						if (Utility.TryOpenFileStream(text3, FileMode.Create, ref fileStream, FileAccess.ReadWrite, FileShare.Read))
						{
							break;
						}
						num++;
					}
					value2.Write((Stream)fileStream);
					fileStream.Dispose();
					dictionary3[key2] = text3;
				}
			}
			if (ConfigBreakBeforeLoadAssemblies.Value)
			{
				ManualLogSource logger3 = Logger;
				val = (LogLevel)16;
				val2 = val;
				val3 = new BepInExLogInterpolatedStringHandler(48, 1, val, ref flag);
				if (flag)
				{
					val3.AppendLiteral("BepInEx is about load the following assemblies:\n");
					val3.AppendFormatted<string>(string.Join("\n", patchedAssemblies.ToArray()));
				}
				logger3.Log(val2, val3);
				ManualLogSource logger4 = Logger;
				val2 = (LogLevel)16;
				val = val2;
				val3 = new BepInExLogInterpolatedStringHandler(32, 1, val2, ref flag);
				if (flag)
				{
					val3.AppendLiteral("The assemblies were dumped into ");
					val3.AppendFormatted<string>(PatcherContext.DumpedAssembliesPath);
				}
				logger4.Log(val, val3);
				Logger.Log((LogLevel)16, (object)"Load any assemblies into the debugger, set breakpoints and continue execution.");
				Debugger.Break();
			}
			foreach (KeyValuePair<string, AssemblyDefinition> item5 in dictionary)
			{
				string key3 = item5.Key;
				AssemblyDefinition value3 = item5.Value;
				if (patchedAssemblies.Contains(key3))
				{
					Assembly value5;
					if (ConfigLoadDumpedAssemblies.Value && dictionary3.TryGetValue(key3, out var value4))
					{
						value5 = Assembly.LoadFrom(value4);
					}
					else
					{
						using MemoryStream memoryStream = new MemoryStream();
						value3.Write((Stream)memoryStream);
						value5 = Assembly.Load(memoryStream.ToArray());
					}
					PatcherContext.LoadedAssemblies.Add(key3, value5);
					ManualLogSource logger5 = Logger;
					val = (LogLevel)32;
					val2 = val;
					val3 = new BepInExLogInterpolatedStringHandler(21, 1, val, ref flag);
					if (flag)
					{
						val3.AppendLiteral("Loaded '");
						val3.AppendFormatted<string>(value3.FullName);
						val3.AppendLiteral("' into memory");
					}
					logger5.Log(val2, val3);
				}
				value3.Dispose();
			}
			foreach (BasePatcher item6 in PatcherPluginsSafe)
			{
				try
				{
					item6.Finalizer();
				}
				catch (Exception ex2)
				{
					ManualLogSource logger6 = Logger;
					val2 = (LogLevel)2;
					val = val2;
					val3 = new BepInExLogInterpolatedStringHandler(29, 2, val2, ref flag);
					if (flag)
					{
						val3.AppendLiteral("Failed to run finalizer of ");
						val3.AppendFormatted<string>(item6.Info.GUID);
						val3.AppendLiteral(": ");
						val3.AppendFormatted<Exception>(ex2);
					}
					logger6.Log(val, val3);
				}
			}
		}
	}
	[AttributeUsage(AttributeTargets.Class)]
	public class PatcherPluginInfoAttribute : Attribute
	{
		public string GUID { get; protected set; }

		public string Name { get; protected set; }

		public Version Version { get; protected set; }

		public PatcherPluginInfoAttribute(string GUID, string Name, string Version)
		{
			this.GUID = GUID;
			this.Name = Name;
			this.Version = TryParseLongVersion(Version);
		}

		private static Version TryParseLongVersion(string version)
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Expected O, but got Unknown
			Version result = default(Version);
			if (Version.TryParse(version, ref result))
			{
				return result;
			}
			try
			{
				Version version2 = new Version(version);
				return new Version(version2.Major, version2.Minor, (version2.Build != -1) ? version2.Build : 0, (string)null, (string)null);
			}
			catch
			{
			}
			return null;
		}

		internal static PatcherPluginInfoAttribute FromCecilType(TypeDefinition td)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			CustomAttribute val = MetadataHelper.GetCustomAttributes<PatcherPluginInfoAttribute>(td, false).FirstOrDefault();
			if (val == null)
			{
				return null;
			}
			CustomAttributeArgument val2 = val.ConstructorArguments[0];
			string gUID = (string)((CustomAttributeArgument)(ref val2)).Value;
			val2 = val.ConstructorArguments[1];
			string name = (string)((CustomAttributeArgument)(ref val2)).Value;
			val2 = val.ConstructorArguments[2];
			return new PatcherPluginInfoAttribute(gUID, name, (string)((CustomAttributeArgument)(ref val2)).Value);
		}

		internal static PatcherPluginInfoAttribute FromType(Type type)
		{
			object[] customAttributes = type.GetCustomAttributes(typeof(PatcherPluginInfoAttribute), inherit: false);
			if (customAttributes.Length == 0)
			{
				return null;
			}
			return (PatcherPluginInfoAttribute)customAttributes[0];
		}
	}
	[AttributeUsage(AttributeTargets.Method)]
	public class TargetAssemblyAttribute : Attribute
	{
		public const string AllAssemblies = "_all";

		public string TargetAssembly { get; }

		public TargetAssemblyAttribute(string targetAssembly)
		{
			TargetAssembly = targetAssembly;
		}
	}
	[AttributeUsage(AttributeTargets.Method)]
	public class TargetTypeAttribute : Attribute
	{
		public string TargetAssembly { get; }

		public string TargetType { get; }

		public TargetTypeAttribute(string targetAssembly, string targetType)
		{
			TargetAssembly = targetAssembly;
			TargetType = targetType;
		}
	}
	public abstract class BasePatcher
	{
		public ManualLogSource Log { get; }

		public ConfigFile Config { get; }

		public PatcherPluginInfoAttribute Info { get; }

		public PatcherContext Context { get; set; }

		protected BasePatcher()
		{
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Expected O, but got Unknown
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Expected O, but got Unknown
			Info = PatcherPluginInfoAttribute.FromType(GetType());
			Log = Logger.CreateLogSource(Info.Name);
			Config = new ConfigFile(Utility.CombinePaths(new string[2]
			{
				Paths.ConfigPath,
				Info.GUID + ".cfg"
			}), false, new BepInPlugin(Info.GUID, Info.Name, ((object)Info.Version).ToString()));
		}

		public virtual void Initialize()
		{
		}

		public virtual void Finalizer()
		{
		}
	}
	public class PatchDefinition
	{
		public TargetAssemblyAttribute TargetAssembly { get; }

		public TargetTypeAttribute TargetType { get; }

		public BasePatcher Instance { get; }

		public MethodInfo MethodInfo { get; }

		public string FullName { get; }

		public PatchDefinition(TargetAssemblyAttribute targetAssembly, BasePatcher instance, MethodInfo methodInfo)
		{
			TargetAssembly = targetAssembly;
			Instance = instance;
			MethodInfo = methodInfo;
			FullName = MethodInfo.DeclaringType.FullName + "/" + MethodInfo.Name + " -> " + TargetAssembly.TargetAssembly;
		}

		public PatchDefinition(TargetTypeAttribute targetType, BasePatcher instance, MethodInfo methodInfo)
		{
			TargetType = targetType;
			Instance = instance;
			MethodInfo = methodInfo;
			FullName = MethodInfo.DeclaringType.FullName + "/" + MethodInfo.Name + " -> " + TargetType.TargetAssembly + "/" + TargetType.TargetType;
		}
	}
	public class PatcherContext
	{
		public Dictionary<string, AssemblyDefinition> AvailableAssemblies { get; } = new Dictionary<string, AssemblyDefinition>();


		public Dictionary<string, Assembly> LoadedAssemblies { get; } = new Dictionary<string, Assembly>();


		public List<BasePatcher> PatcherPlugins { get; } = new List<BasePatcher>();


		public List<PatchDefinition> PatchDefinitions { get; } = new List<PatchDefinition>();


		public string DumpedAssembliesPath { get; internal set; }
	}
	internal class PatcherPluginMetadata : ICacheable
	{
		public string TypeName { get; set; } = string.Empty;


		public void Save(BinaryWriter bw)
		{
			bw.Write(TypeName);
		}

		public void Load(BinaryReader br)
		{
			TypeName = br.ReadString();
		}
	}
}
namespace BepInEx.Preloader.Core.Logging
{
	public static class ChainloaderLogHelper
	{
		private static Dictionary<string, string> MacOSVersions { get; } = new Dictionary<string, string>
		{
			["16.0.0"] = "10.12",
			["16.5.0"] = "10.12.4",
			["16.6.0"] = "10.12.6",
			["17.5.0"] = "10.13.4",
			["17.6.0"] = "10.13.5",
			["17.7.0"] = "10.13.6",
			["18.2.0"] = "10.14.1",
			["19.2.0"] = "10.15.2",
			["19.3.0"] = "10.15.3",
			["19.5.0"] = "10.15.5.1",
			["20.1.0"] = "11.0",
			["20.2.0"] = "11.1",
			["20.3.0"] = "11.2",
			["20.4.0"] = "11.3",
			["20.5.0"] = "11.4",
			["21.0.1"] = "12.0",
			["21.1.0"] = "12.0.1",
			["21.2.0"] = "12.1"
		};


		public static void PrintLogInfo(ManualLogSource log)
		{
			//IL_0066: 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_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Expected O, but got Unknown
			//IL_009a: 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_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Expected O, but got Unknown
			string text = $"BepInEx {Paths.BepInExVersion} - {Paths.ProcessName}";
			log.Log((LogLevel)8, (object)text);
			if (ConsoleManager.ConsoleActive)
			{
				ConsoleManager.SetConsoleTitle(text);
			}
			object[] customAttributes = typeof(BuildInfoAttribute).Assembly.GetCustomAttributes(typeof(BuildInfoAttribute), inherit: false);
			if (customAttributes.Length != 0)
			{
				BuildInfoAttribute buildInfoAttribute = (BuildInfoAttribute)customAttributes[0];
				log.Log((LogLevel)8, (object)buildInfoAttribute.Info);
			}
			LogLevel val = (LogLevel)16;
			LogLevel val2 = val;
			bool flag = default(bool);
			BepInExLogInterpolatedStringHandler val3 = new BepInExLogInterpolatedStringHandler(17, 1, val, ref flag);
			if (flag)
			{
				val3.AppendLiteral("System platform: ");
				val3.AppendFormatted<string>(GetPlatformString());
			}
			Logger.Log(val2, val3);
			val = (LogLevel)16;
			LogLevel val4 = val;
			val3 = new BepInExLogInterpolatedStringHandler(17, 1, val, ref flag);
			if (flag)
			{
				val3.AppendLiteral("Process bitness: ");
				val3.AppendFormatted<string>(PlatformUtils.ProcessIs64Bit ? "64-bit (x64)" : "32-bit (x86)");
			}
			Logger.Log(val4, val3);
		}

		private static string GetPlatformString()
		{
			StringBuilder stringBuilder = new StringBuilder();
			Version version = Environment.OSVersion.Version;
			if (PlatformHelper.Is((Platform)37))
			{
				version = PlatformUtils.WindowsVersion;
				stringBuilder.Append("Windows ");
				if (version.Major >= 10 && version.Build >= 22000)
				{
					stringBuilder.Append("11");
				}
				else if (version.Major >= 10)
				{
					stringBuilder.Append("10");
				}
				else if (version.Major == 6 && version.Minor == 3)
				{
					stringBuilder.Append("8.1");
				}
				else if (version.Major == 6 && version.Minor == 2)
				{
					stringBuilder.Append("8");
				}
				else if (version.Major == 6 && version.Minor == 1)
				{
					stringBuilder.Append("7");
				}
				else if (version.Major == 6 && version.Minor == 0)
				{
					stringBuilder.Append("Vista");
				}
				else if (version.Major <= 5)
				{
					stringBuilder.Append("XP");
				}
			}
			else if (PlatformHelper.Is((Platform)73))
			{
				stringBuilder.Append("macOS ");
				string key = version.ToString(3);
				if (MacOSVersions.TryGetValue(key, out var value))
				{
					stringBuilder.Append(value);
				}
				else
				{
					stringBuilder.AppendFormat("Unknown (kernel {0})", version);
				}
			}
			else if (PlatformHelper.Is((Platform)137))
			{
				stringBuilder.Append("Linux");
				if (PlatformUtils.LinuxKernelVersion != null)
				{
					stringBuilder.AppendFormat(" (kernel {0})", PlatformUtils.LinuxKernelVersion);
				}
			}
			stringBuilder.Append(PlatformHelper.Is((Platform)2) ? " 64-bit" : " 32-bit");
			if (PlatformHelper.Is((Platform)393))
			{
				stringBuilder.Append(" Android");
			}
			if (PlatformHelper.Is((Platform)65536))
			{
				stringBuilder.Append(" ARM");
				if (PlatformHelper.Is((Platform)2))
				{
					stringBuilder.Append("64");
				}
			}
			return stringBuilder.ToString();
		}

		public static void RewritePreloaderLogs()
		{
			if (PreloaderConsoleListener.LogEvents == null || PreloaderConsoleListener.LogEvents.Count == 0)
			{
				return;
			}
			ILogListener val = ((IEnumerable<ILogListener>)Logger.Listeners).FirstOrDefault((Func<ILogListener, bool>)((ILogListener logger) => logger is ConsoleLogListener));
			if (val != null)
			{
				Logger.Listeners.Remove(val);
			}
			foreach (LogEventArgs logEvent in PreloaderConsoleListener.LogEvents)
			{
				Logger.InternalLogEvent((object)PreloaderLogger.Log, logEvent);
			}
			if (val != null)
			{
				Logger.Listeners.Add(val);
			}
		}
	}
	public class PreloaderConsoleListener : ILogListener, IDisposable
	{
		private static readonly ConfigEntry<LogLevel> ConfigConsoleDisplayedLevel = ConfigFile.CoreConfig.Bind<LogLevel>("Logging.Console", "LogLevels", (LogLevel)31, "Which log levels to show in the console output.");

		public static List<LogEventArgs> LogEvents { get; } = new List<LogEventArgs>();


		public LogLevel LogLevelFilter => ConfigConsoleDisplayedLevel.Value;

		public void LogEvent(object sender, LogEventArgs eventArgs)
		{
			LogEvents.Add(eventArgs);
		}

		public void Dispose()
		{
		}
	}
}

BepInExPack/BepInEx/core/Cpp2IL.Core.dll

Decompiled a month ago
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using Cpp2IL.Core.Analysis;
using Cpp2IL.Core.Analysis.Actions.ARM64;
using Cpp2IL.Core.Analysis.Actions.Base;
using Cpp2IL.Core.Analysis.Actions.WASM;
using Cpp2IL.Core.Analysis.Actions.x86;
using Cpp2IL.Core.Analysis.Actions.x86.Important;
using Cpp2IL.Core.Analysis.PostProcessActions;
using Cpp2IL.Core.Analysis.PostProcessActions.ILPostProcess;
using Cpp2IL.Core.Analysis.ResultModels;
using Cpp2IL.Core.Exceptions;
using Cpp2IL.Core.Utils;
using Gee.External.Capstone;
using Gee.External.Capstone.Arm;
using Gee.External.Capstone.Arm64;
using HarmonyLib;
using Iced.Intel;
using LibCpp2IL;
using LibCpp2IL.BinaryStructures;
using LibCpp2IL.Logging;
using LibCpp2IL.Metadata;
using LibCpp2IL.NintendoSwitch;
using LibCpp2IL.Reflection;
using LibCpp2IL.Wasm;
using Microsoft.CodeAnalysis;
using Mono.Cecil;
using Mono.Cecil.Cil;
using Mono.Cecil.Rocks;
using Mono.Collections.Generic;
using WasmDisassembler;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("Samboy063")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyCopyright("Copyright © Samboy063 2019-2022")]
[assembly: AssemblyDescription("Reverses Unity's IL2CPP Build Process")]
[assembly: AssemblyFileVersion("2022.0.5")]
[assembly: AssemblyInformationalVersion("2022.0.5")]
[assembly: AssemblyProduct("Cpp2IL.Core")]
[assembly: AssemblyTitle("Cpp2IL.Core")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/SamboyCoding/Cpp2IL.git")]
[assembly: AssemblyVersion("2022.0.5.0")]
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;
		}
	}
}
namespace System.Diagnostics.CodeAnalysis
{
	[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, Inherited = false)]
	[ExcludeFromCodeCoverage]
	[DebuggerNonUserCode]
	internal sealed class AllowNullAttribute : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, Inherited = false)]
	[ExcludeFromCodeCoverage]
	[DebuggerNonUserCode]
	internal sealed class DisallowNullAttribute : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Method, Inherited = false)]
	[ExcludeFromCodeCoverage]
	[DebuggerNonUserCode]
	internal sealed class DoesNotReturnAttribute : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
	[ExcludeFromCodeCoverage]
	[DebuggerNonUserCode]
	internal sealed class DoesNotReturnIfAttribute : Attribute
	{
		public bool ParameterValue { get; }

		public DoesNotReturnIfAttribute(bool parameterValue)
		{
			ParameterValue = parameterValue;
		}
	}
	[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.ReturnValue, Inherited = false)]
	[ExcludeFromCodeCoverage]
	[DebuggerNonUserCode]
	internal sealed class MaybeNullAttribute : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
	[ExcludeFromCodeCoverage]
	[DebuggerNonUserCode]
	internal sealed class MaybeNullWhenAttribute : Attribute
	{
		public bool ReturnValue { get; }

		public MaybeNullWhenAttribute(bool returnValue)
		{
			ReturnValue = returnValue;
		}
	}
	[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)]
	[ExcludeFromCodeCoverage]
	[DebuggerNonUserCode]
	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)]
	[ExcludeFromCodeCoverage]
	[DebuggerNonUserCode]
	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;
		}
	}
	[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.ReturnValue, Inherited = false)]
	[ExcludeFromCodeCoverage]
	[DebuggerNonUserCode]
	internal sealed class NotNullAttribute : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Property | AttributeTargets.Parameter | AttributeTargets.ReturnValue, AllowMultiple = true, Inherited = false)]
	[ExcludeFromCodeCoverage]
	[DebuggerNonUserCode]
	internal sealed class NotNullIfNotNullAttribute : Attribute
	{
		public string ParameterName { get; }

		public NotNullIfNotNullAttribute(string parameterName)
		{
			ParameterName = parameterName;
		}
	}
	[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
	[ExcludeFromCodeCoverage]
	[DebuggerNonUserCode]
	internal sealed class NotNullWhenAttribute : Attribute
	{
		public bool ReturnValue { get; }

		public NotNullWhenAttribute(bool returnValue)
		{
			ReturnValue = returnValue;
		}
	}
}
namespace Cpp2IL.Core
{
	public enum AnalysisLevel
	{
		PRINT_ALL,
		SKIP_ASM,
		SKIP_ASM_AND_SYNOPSIS,
		IL_ONLY,
		PSUEDOCODE_ONLY,
		NONE
	}
	public class Arm64KeyFunctionAddresses : BaseKeyFunctionAddresses
	{
		private readonly List<Arm64Instruction> _allInstructions;

		public Arm64KeyFunctionAddresses()
		{
			CapstoneArm64Disassembler val = CapstoneDisassembler.CreateArm64Disassembler((Arm64DisassembleMode)(((EndianAwareBinaryReader)LibCpp2IlMain.Binary).IsBigEndian ? int.MinValue : 0));
			((CapstoneDisassembler)val).EnableInstructionDetails = true;
			((CapstoneDisassembler<Arm64DisassembleMode, Arm64Instruction, Arm64InstructionDetail, Arm64InstructionGroup, Arm64InstructionGroupId, Arm64InstructionId, Arm64Register, Arm64RegisterId>)(object)val).DisassembleSyntax = (DisassembleSyntax)1;
			((CapstoneDisassembler)val).EnableSkipDataMode = true;
			byte[] array = LibCpp2IlMain.Binary.GetEntirePrimaryExecutableSection();
			ulong num = LibCpp2IlMain.Binary.GetVirtualAddressOfPrimaryExecutableSection();
			ulong num2 = num + (ulong)array.Length;
			Logger.InfoNewline("\tRunning entire .text section through Arm64 disassembler, this might take up to several minutes for large games, and may fail on large games if you have <16GB ram...");
			Logger.VerboseNewline($"\tPrimary executable section is {array.Length} bytes, starting at 0x{num:X} and extending to 0x{num2:X}");
			List<ulong> list = SharedState.AttributeGeneratorStarts.ToList();
			Extensions.SortByExtractedKey<ulong, ulong>(list, (Func<ulong, ulong>)((ulong a) => a));
			if (list.Count > 0)
			{
				if (!(LibCpp2IlMain.Binary is NsoFile))
				{
					Logger.VerboseNewline($"\tLast attribute generator function is at address 0x{list[list.Count - 1]:X}. Skipping everything before that.");
					int num3 = array.Length;
					int num4 = (int)(list[list.Count - 1] - num);
					array = array.Skip(num4).ToArray();
					num = list[list.Count - 1];
					Logger.VerboseNewline($"\tBy trimming out attribute generator functions, reduced decompilation work by {num4} of {num3} bytes (a {(float)(num4 * 100) / (float)num3:f1}% saving)");
					List<ulong> list2 = SharedState.MethodsByAddress.Keys.Where((ulong a) => a != 0).ToList();
					Extensions.SortByExtractedKey<ulong, ulong>(list2, (Func<ulong, ulong>)((ulong a) => a));
					if (list2[0] < num2 && LibCpp2IlMain.Binary.GetVirtualAddressOfExportedFunctionByName("il2cpp_object_new") != 0L)
					{
						ulong[] source = (from a in ((IEnumerable<string>)new string[9] { "il2cpp_object_new", "il2cpp_value_box", "il2cpp_runtime_class_init", "il2cpp_array_new_specific", "il2cpp_type_get_object", "il2cpp_resolve_icall", "il2cpp_string_new", "il2cpp_string_new_wrapper", "il2cpp_raise_exception" }).Select((Func<string, ulong>)LibCpp2IlMain.Binary.GetVirtualAddressOfExportedFunctionByName)
							where a != 0
							select a).ToArray();
						ulong num5 = source.Max();
						ulong num6 = source.Min();
						Logger.VerboseNewline($"\tDetected that the il2cpp-ified managed methods are in the .text section and api functions are available. Attempting to trim out managed methods for KFA scanning - the first managed method is at 0x{list2[0]:X} and the last at 0x{list2[list2.Count - 1]:X}, " + $"the first export function is at 0x{num6:X} and the last at 0x{num5:X}");
						ulong num7 = Math.Min(num6, list2[list2.Count - 1]);
						if (num7 > 16777216)
						{
							num7 -= 1048576;
						}
						Logger.VerboseNewline($"\tTrimming everything before 0x{num7:X}.");
						num3 = array.Length;
						num4 = (int)(num7 - num);
						array = array.Skip(num4).ToArray();
						num = num7;
						Logger.VerboseNewline($"\tBy trimming out most of the il2cpp-ified managed methods, reduced decompilation work by {num4} of {num3} bytes (a {(float)((long)num4 * 100L) / (float)num3:f1}% saving)");
					}
					else if (list2[0] < num2)
					{
						Logger.VerboseNewline($"\tDetected that the il2cpp-ified managed methods are in the .text section, but api functions are not available. Attempting to (conservatively) trim out managed methods for KFA scanning - the first managed method is at 0x{list2[0]:X} and the last at 0x{list2[list2.Count - 1]:X}");
						ulong num8 = list2[list2.Count - 1];
						if (num8 > 16777216)
						{
							num8 -= 1048576;
						}
						Logger.VerboseNewline($"\tTrimming everything before 0x{num8:X}.");
						num3 = array.Length;
						num4 = (int)(num8 - num);
						array = array.Skip(num4).ToArray();
						num = num8;
						Logger.VerboseNewline($"\tBy trimming out most of the il2cpp-ified managed methods, reduced decompilation work by {num4} of {num3} bytes (a {(float)((long)num4 * 100L) / (float)num3:f1}% saving)");
					}
				}
				else
				{
					Logger.VerboseNewline($"\tNSO: Last attribute generator function is at address 0x{list[list.Count - 1]:X}. Skipping everything after that.");
					int num9 = array.Length;
					int num10 = (int)(list[list.Count - 1] - num);
					array = array.SubArray(..num10);
					Logger.VerboseNewline($"\tBy trimming out everything after and including attribute generator functions, reduced decompilation work by {num9 - num10} of {num9} bytes (a {(float)((long)(num9 - num10) * 100L) / (float)num9:f1}% saving)");
				}
			}
			_allInstructions = ((CapstoneDisassembler<Arm64DisassembleMode, Arm64Instruction, Arm64InstructionDetail, Arm64InstructionGroup, Arm64InstructionGroupId, Arm64InstructionId, Arm64Register, Arm64RegisterId>)(object)val).Disassemble(array, (long)num).ToList();
		}

		protected override IEnumerable<ulong> FindAllThunkFunctions(ulong addr, uint maxBytesBack = 0u, params ulong[] addressesToIgnore)
		{
			List<Arm64Instruction> list = (from i in _allInstructions.Where(delegate(Arm64Instruction i)
				{
					string mnemonic2 = ((Instruction<Arm64Instruction, Arm64InstructionDetail, Arm64DisassembleMode, Arm64InstructionGroup, Arm64InstructionGroupId, Arm64InstructionId, Arm64Register, Arm64RegisterId>)(object)i).Mnemonic;
					return mnemonic2 == "b" || mnemonic2 == "bl";
				})
				where ((Instruction<Arm64Instruction, Arm64InstructionDetail, Arm64DisassembleMode, Arm64InstructionGroup, Arm64InstructionGroupId, Arm64InstructionId, Arm64Register, Arm64RegisterId>)(object)i).Details.Operands[0].IsImmediate() && ((Instruction<Arm64Instruction, Arm64InstructionDetail, Arm64DisassembleMode, Arm64InstructionGroup, Arm64InstructionGroupId, Arm64InstructionId, Arm64Register, Arm64RegisterId>)(object)i).Details.Operands[0].Immediate == (long)addr
				select i).ToList();
			foreach (Arm64Instruction item in list)
			{
				if (addressesToIgnore.Contains((ulong)((Instruction<Arm64Instruction, Arm64InstructionDetail, Arm64DisassembleMode, Arm64InstructionGroup, Arm64InstructionGroupId, Arm64InstructionId, Arm64Register, Arm64RegisterId>)(object)item).Address))
				{
					continue;
				}
				int num = 0;
				int num2 = _allInstructions.IndexOf(item);
				do
				{
					if (num2 - num > 0)
					{
						Arm64Instruction val = _allInstructions[num2 - num - 1];
						if (addressesToIgnore.Contains((ulong)((Instruction<Arm64Instruction, Arm64InstructionDetail, Arm64DisassembleMode, Arm64InstructionGroup, Arm64InstructionGroupId, Arm64InstructionId, Arm64Register, Arm64RegisterId>)(object)val).Address))
						{
							num++;
							continue;
						}
						if (((Instruction<Arm64Instruction, Arm64InstructionDetail, Arm64DisassembleMode, Arm64InstructionGroup, Arm64InstructionGroupId, Arm64InstructionId, Arm64Register, Arm64RegisterId>)(object)val).IsSkippedData && ((Instruction<Arm64Instruction, Arm64InstructionDetail, Arm64DisassembleMode, Arm64InstructionGroup, Arm64InstructionGroupId, Arm64InstructionId, Arm64Register, Arm64RegisterId>)(object)val).Bytes.All((byte b) => b == 0))
						{
							yield return (ulong)(((Instruction<Arm64Instruction, Arm64InstructionDetail, Arm64DisassembleMode, Arm64InstructionGroup, Arm64InstructionGroupId, Arm64InstructionId, Arm64Register, Arm64RegisterId>)(object)item).Address - num * 4);
							break;
						}
						string mnemonic = ((Instruction<Arm64Instruction, Arm64InstructionDetail, Arm64DisassembleMode, Arm64InstructionGroup, Arm64InstructionGroupId, Arm64InstructionId, Arm64Register, Arm64RegisterId>)(object)val).Mnemonic;
						if (mnemonic == "adrp" || mnemonic == "str")
						{
							break;
						}
						mnemonic = ((Instruction<Arm64Instruction, Arm64InstructionDetail, Arm64DisassembleMode, Arm64InstructionGroup, Arm64InstructionGroupId, Arm64InstructionId, Arm64Register, Arm64RegisterId>)(object)val).Mnemonic;
						if (mnemonic == "b" || mnemonic == "bl")
						{
							yield return (ulong)(((Instruction<Arm64Instruction, Arm64InstructionDetail, Arm64DisassembleMode, Arm64InstructionGroup, Arm64InstructionGroupId, Arm64InstructionId, Arm64Register, Arm64RegisterId>)(object)item).Address - num * 4);
							break;
						}
						if (((Instruction<Arm64Instruction, Arm64InstructionDetail, Arm64DisassembleMode, Arm64InstructionGroup, Arm64InstructionGroupId, Arm64InstructionId, Arm64Register, Arm64RegisterId>)(object)val).Mnemonic == "ret")
						{
							yield return (ulong)(((Instruction<Arm64Instruction, Arm64InstructionDetail, Arm64DisassembleMode, Arm64InstructionGroup, Arm64InstructionGroupId, Arm64InstructionId, Arm64Register, Arm64RegisterId>)(object)item).Address - num * 4);
							break;
						}
					}
					num++;
				}
				while (num * 4 < maxBytesBack);
			}
		}

		protected override ulong GetObjectIsInstFromSystemType()
		{
			Logger.Verbose("\tTrying to use System.Type::IsInstanceOfType to find il2cpp::vm::Object::IsInst...");
			Il2CppTypeDefinition type = LibCpp2IlReflection.GetType("Type", "System");
			Il2CppMethodDefinition val = ((type == null) ? null : type.Methods?.FirstOrDefault((Func<Il2CppMethodDefinition, bool>)((Il2CppMethodDefinition m) => m.Name == "IsInstanceOfType")));
			if (val == null)
			{
				Logger.VerboseNewline("Type or method not found, aborting.");
				return 0uL;
			}
			Logger.Verbose($"IsInstanceOfType found at 0x{val.MethodPointer:X}...");
			Arm64Instruction val2 = ((IEnumerable<Arm64Instruction>)Arm64Utils.GetArm64MethodBodyAtVirtualAddress(val.MethodPointer, managed: false)).LastOrDefault((Func<Arm64Instruction, bool>)((Arm64Instruction i) => ((Instruction<Arm64Instruction, Arm64InstructionDetail, Arm64DisassembleMode, Arm64InstructionGroup, Arm64InstructionGroupId, Arm64InstructionId, Arm64Register, Arm64RegisterId>)(object)i).Mnemonic == "bl"));
			if (val2 == null)
			{
				Logger.VerboseNewline("Method does not match expected signature. Aborting.");
				return 0uL;
			}
			Logger.VerboseNewline($"Success. IsInst found at 0x{((Instruction<Arm64Instruction, Arm64InstructionDetail, Arm64DisassembleMode, Arm64InstructionGroup, Arm64InstructionGroupId, Arm64InstructionId, Arm64Register, Arm64RegisterId>)(object)val2).Details.Operands[0].Immediate:X}");
			return (ulong)((Instruction<Arm64Instruction, Arm64InstructionDetail, Arm64DisassembleMode, Arm64InstructionGroup, Arm64InstructionGroupId, Arm64InstructionId, Arm64Register, Arm64RegisterId>)(object)val2).Details.Operands[0].Immediate;
		}

		protected override ulong FindFunctionThisIsAThunkOf(ulong thunkPtr, bool prioritiseCall = false)
		{
			int num = _allInstructions.FindIndex((Arm64Instruction i) => ((Instruction<Arm64Instruction, Arm64InstructionDetail, Arm64DisassembleMode, Arm64InstructionGroup, Arm64InstructionGroupId, Arm64InstructionId, Arm64Register, Arm64RegisterId>)(object)i).Address == (long)thunkPtr);
			if (num < 0)
			{
				return 0uL;
			}
			string mnemonic = ((Instruction<Arm64Instruction, Arm64InstructionDetail, Arm64DisassembleMode, Arm64InstructionGroup, Arm64InstructionGroupId, Arm64InstructionId, Arm64Register, Arm64RegisterId>)(object)_allInstructions[num]).Mnemonic;
			if (mnemonic == "b" || mnemonic == "bl")
			{
				return (ulong)((Instruction<Arm64Instruction, Arm64InstructionDetail, Arm64DisassembleMode, Arm64InstructionGroup, Arm64InstructionGroupId, Arm64InstructionId, Arm64Register, Arm64RegisterId>)(object)_allInstructions[num]).Details.Operands[0].Immediate;
			}
			for (int j = 0; j <= 12; j++)
			{
				num++;
				mnemonic = ((Instruction<Arm64Instruction, Arm64InstructionDetail, Arm64DisassembleMode, Arm64InstructionGroup, Arm64InstructionGroupId, Arm64InstructionId, Arm64Register, Arm64RegisterId>)(object)_allInstructions[num]).Mnemonic;
				if (mnemonic == "b" || mnemonic == "bl")
				{
					return (ulong)((Instruction<Arm64Instruction, Arm64InstructionDetail, Arm64DisassembleMode, Arm64InstructionGroup, Arm64InstructionGroupId, Arm64InstructionId, Arm64Register, Arm64RegisterId>)(object)_allInstructions[num]).Details.Operands[0].Immediate;
				}
			}
			return 0uL;
		}

		protected override int GetCallerCount(ulong toWhere)
		{
			return _allInstructions.Where(delegate(Arm64Instruction i)
			{
				string mnemonic = ((Instruction<Arm64Instruction, Arm64InstructionDetail, Arm64DisassembleMode, Arm64InstructionGroup, Arm64InstructionGroupId, Arm64InstructionId, Arm64Register, Arm64RegisterId>)(object)i).Mnemonic;
				return mnemonic == "b" || mnemonic == "bl";
			}).Count((Arm64Instruction i) => ((Instruction<Arm64Instruction, Arm64InstructionDetail, Arm64DisassembleMode, Arm64InstructionGroup, Arm64InstructionGroupId, Arm64InstructionId, Arm64Register, Arm64RegisterId>)(object)i).Details.Operands[0].IsImmediate() && ((Instruction<Arm64Instruction, Arm64InstructionDetail, Arm64DisassembleMode, Arm64InstructionGroup, Arm64InstructionGroupId, Arm64InstructionId, Arm64Register, Arm64RegisterId>)(object)i).Details.Operands[0].Immediate == (long)toWhere);
		}

		protected override void AttemptInstructionAnalysisToFillGaps()
		{
			if (il2cpp_object_new != 0L)
			{
				return;
			}
			Logger.Verbose("\tAttempting to use Array GetEnumerator to find il2cpp_codegen_object_new...");
			TypeDefinition array = TypeDefinitions.Array;
			if (array != null)
			{
				MethodDefinition val = ((IEnumerable<MethodDefinition>)array.Methods).FirstOrDefault((Func<MethodDefinition, bool>)((MethodDefinition m) => ((MemberReference)m).Name == "GetEnumerator"));
				if (val != null)
				{
					List<Arm64Instruction> arm64MethodBodyAtVirtualAddress = Arm64Utils.GetArm64MethodBodyAtVirtualAddress(val.AsUnmanaged().MethodPointer);
					long num = 0L;
					int num2 = 0;
					for (int i = 0; i < arm64MethodBodyAtVirtualAddress.Count - 4; i++)
					{
						if (!(((Instruction<Arm64Instruction, Arm64InstructionDetail, Arm64DisassembleMode, Arm64InstructionGroup, Arm64InstructionGroupId, Arm64InstructionId, Arm64Register, Arm64RegisterId>)(object)arm64MethodBodyAtVirtualAddress[i]).Mnemonic != "adrp") && !(((Instruction<Arm64Instruction, Arm64InstructionDetail, Arm64DisassembleMode, Arm64InstructionGroup, Arm64InstructionGroupId, Arm64InstructionId, Arm64Register, Arm64RegisterId>)(object)arm64MethodBodyAtVirtualAddress[i + 1]).Mnemonic != "ldr") && !(((Instruction<Arm64Instruction, Arm64InstructionDetail, Arm64DisassembleMode, Arm64InstructionGroup, Arm64InstructionGroupId, Arm64InstructionId, Arm64Register, Arm64RegisterId>)(object)arm64MethodBodyAtVirtualAddress[i + 2]).Mnemonic != "ldr") && !(((Instruction<Arm64Instruction, Arm64InstructionDetail, Arm64DisassembleMode, Arm64InstructionGroup, Arm64InstructionGroupId, Arm64InstructionId, Arm64Register, Arm64RegisterId>)(object)arm64MethodBodyAtVirtualAddress[i + 3]).Mnemonic != "bl") && num2++ < 2)
						{
							num = ((Instruction<Arm64Instruction, Arm64InstructionDetail, Arm64DisassembleMode, Arm64InstructionGroup, Arm64InstructionGroupId, Arm64InstructionId, Arm64Register, Arm64RegisterId>)(object)arm64MethodBodyAtVirtualAddress[i + 3]).Details.Operands[0].Immediate;
						}
					}
					if (num > 0)
					{
						Logger.Verbose($"Probably found at 0x{num:X}...");
						ulong num3 = FindFunctionThisIsAThunkOf((ulong)num);
						long addr = ((num3 == 0) ? num : ((long)num3));
						List<ulong> list = FindAllThunkFunctions((ulong)addr, 16u, (ulong)num).ToList();
						Extensions.SortByExtractedKey<ulong, int>(list, (Func<ulong, int>)GetCallerCount);
						list.Reverse();
						il2cpp_object_new = list.FirstOrDefault();
						Logger.VerboseNewline($"Leaving il2cpp_object_new at 0x{il2cpp_object_new:X}");
					}
					else
					{
						Logger.VerboseNewline("Couldn't find a matching instruction, can't be used.");
					}
				}
				else
				{
					Logger.VerboseNewline("Method stripped, can't be used.");
				}
			}
			else
			{
				Logger.VerboseNewline("Type stripped, can't be used.");
			}
		}
	}
	internal static class AssemblyPopulator
	{
		internal const string InjectedNamespaceName = "Cpp2IlInjected";

		private static readonly Dictionary<ModuleDefinition, (MethodDefinition, MethodDefinition, MethodDefinition)> _attributesByModule = new Dictionary<ModuleDefinition, (MethodDefinition, MethodDefinition, MethodDefinition)>();

		internal static void Reset()
		{
			_attributesByModule.Clear();
		}

		public static void ConfigureHierarchy()
		{
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Expected O, but got Unknown
			foreach (TypeDefinition allTypeDefinition in SharedState.AllTypeDefinitions)
			{
				Il2CppTypeDefinition obj = SharedState.ManagedToUnmanagedTypes[allTypeDefinition];
				PopulateGenericParamsForType(obj, allTypeDefinition);
				Il2CppType rawBaseType = obj.RawBaseType;
				if (rawBaseType != null)
				{
					allTypeDefinition.BaseType = MiscUtils.ImportTypeInto((MemberReference)(object)allTypeDefinition, rawBaseType);
				}
				Il2CppType[] rawInterfaces = obj.RawInterfaces;
				foreach (Il2CppType toImport in rawInterfaces)
				{
					allTypeDefinition.Interfaces.Add(new InterfaceImplementation(MiscUtils.ImportTypeInto((MemberReference)(object)allTypeDefinition, toImport)));
				}
			}
		}

		private static void CreateDefaultConstructor(TypeDefinition typeDefinition)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			//IL_005f: 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)
			ModuleDefinition module = ((MemberReference)typeDefinition).Module;
			MethodDefinition val = new MethodDefinition(".ctor", (MethodAttributes)6278, module.ImportReference((TypeReference)(object)TypeDefinitions.Void));
			ILProcessor iLProcessor = val.Body.GetILProcessor();
			MethodDefinition val2 = TypeDefinitionRocks.GetConstructors(TypeDefinitions.Attribute).FirstOrDefault();
			if (val2 != null)
			{
				iLProcessor.Emit(OpCodes.Ldarg_0);
				iLProcessor.Emit(OpCodes.Call, module.ImportReference((MethodReference)(object)val2));
			}
			iLProcessor.Emit(OpCodes.Ret);
			typeDefinition.Methods.Add(val);
		}

		private static void InjectAttribute(string name, TypeReference stringRef, TypeReference attributeRef, AssemblyDefinition assembly, params string[] fields)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Expected O, but got Unknown
			TypeDefinition val = new TypeDefinition("Cpp2IlInjected", name, (TypeAttributes)1048576, attributeRef);
			foreach (string text in fields)
			{
				val.Fields.Add(new FieldDefinition(text, (FieldAttributes)6, stringRef));
			}
			assembly.MainModule.Types.Add(val);
			CreateDefaultConstructor(val);
		}

		private static void InjectOurTypes(AssemblyDefinition imageDef, bool suppressAttributes)
		{
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Expected O, but got Unknown
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Expected O, but got Unknown
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Expected O, but got Unknown
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			TypeReference val = imageDef.MainModule.ImportReference((TypeReference)(object)TypeDefinitions.String);
			TypeReference attributeRef = imageDef.MainModule.ImportReference((TypeReference)(object)TypeDefinitions.Attribute);
			TypeReference val2 = imageDef.MainModule.ImportReference((TypeReference)(object)TypeDefinitions.Exception);
			if (!suppressAttributes)
			{
				InjectAttribute("AddressAttribute", val, attributeRef, imageDef, "RVA", "Offset", "VA", "Slot");
				InjectAttribute("FieldOffsetAttribute", val, attributeRef, imageDef, "Offset");
				InjectAttribute("AttributeAttribute", val, attributeRef, imageDef, "Name", "RVA", "Offset");
				InjectAttribute("MetadataOffsetAttribute", val, attributeRef, imageDef, "Offset");
				InjectAttribute("TokenAttribute", val, attributeRef, imageDef, "Token");
			}
			TypeDefinition val3 = new TypeDefinition("Cpp2IlInjected", "AnalysisFailedException", (TypeAttributes)1048576, val2);
			MethodDefinition val4 = new MethodDefinition(".ctor", (MethodAttributes)6278, imageDef.MainModule.ImportReference((TypeReference)(object)TypeDefinitions.Void));
			((MethodReference)val4).Parameters.Add(new ParameterDefinition("message", (ParameterAttributes)0, val));
			MethodDefinition val5 = ((IEnumerable<MethodDefinition>)val2.Resolve().Methods).FirstOrDefault((Func<MethodDefinition, bool>)((MethodDefinition m) => m.IsConstructor && ((MethodReference)m).Parameters.Count == 1 && ((MemberReference)((ParameterReference)((MethodReference)m).Parameters[0]).ParameterType).Name == "String"));
			if (val5 != null)
			{
				ILProcessor iLProcessor = val4.Body.GetILProcessor();
				iLProcessor.Emit(OpCodes.Ldarg_0);
				iLProcessor.Emit(OpCodes.Ldarg_1);
				iLProcessor.Emit(OpCodes.Call, imageDef.MainModule.ImportReference((MethodReference)(object)val5));
				iLProcessor.Emit(OpCodes.Ret);
			}
			val3.Methods.Add(val4);
			imageDef.MainModule.Types.Add(val3);
		}

		public static void PopulateStubTypesInAssembly(Il2CppImageDefinition imageDef, bool suppressAttributes)
		{
			InjectOurTypes(((MemberReference)SharedState.TypeDefsByIndex[imageDef.firstTypeIndex]).Module.Assembly, suppressAttributes);
			Il2CppTypeDefinition[] types = imageDef.Types;
			foreach (Il2CppTypeDefinition val in types)
			{
				TypeDefinition val2 = SharedState.UnmanagedToManagedTypes[val];
				try
				{
					CopyIl2CppDataToManagedType(val, val2, suppressAttributes);
				}
				catch (Exception innerException)
				{
					string[] obj = new string[8]
					{
						"Failed to process type ",
						((MemberReference)val2).FullName,
						" (module ",
						((ModuleReference)((MemberReference)val2).Module).Name,
						", declaring type ",
						null,
						null,
						null
					};
					TypeDefinition declaringType = val2.DeclaringType;
					obj[5] = ((declaringType != null) ? ((MemberReference)declaringType).FullName : null);
					obj[6] = ") in ";
					obj[7] = imageDef.Name;
					throw new Exception(string.Concat(obj), innerException);
				}
			}
		}

		public static void FixupExplicitOverridesInAssembly(Il2CppImageDefinition imageDef)
		{
			Il2CppTypeDefinition[] types = imageDef.Types;
			foreach (Il2CppTypeDefinition key in types)
			{
				FixupExplicitOverridesInType(SharedState.UnmanagedToManagedTypes[key]);
			}
		}

		private static void FixupExplicitOverridesInType(TypeDefinition ilTypeDefinition)
		{
			//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)
			TypeDefinition ilTypeDefinition2 = ilTypeDefinition;
			Enumerator<MethodDefinition> enumerator = ilTypeDefinition2.Methods.GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					MethodDefinition currentlyFixingUp = enumerator.Current;
					Il2CppMethodDefinition val = currentlyFixingUp.AsUnmanaged();
					if (!val.Name.Contains(".") || val.Name.StartsWith(".") || val.Name.StartsWith("<"))
					{
						continue;
					}
					string text = val.Name.Substring(0, val.Name.LastIndexOf(".", StringComparison.Ordinal));
					string name2 = val.Name;
					int num = val.Name.LastIndexOf(".", StringComparison.Ordinal) + 1;
					string baseMethodName = name2.Substring(num, name2.Length - num);
					var (baseType, array2) = MiscUtils.TryLookupTypeDefByName(text);
					if (baseType == null)
					{
						Logger.WarnNewline("\tFailed to resolve base type " + text + " for base method override " + val.Name);
						continue;
					}
					string[] targetParameters = ((IEnumerable<ParameterDefinition>)((MethodReference)currentlyFixingUp).Parameters).Select((ParameterDefinition p) => ((MemberReference)((ParameterReference)p).ParameterType).FullName).ToArray();
					MethodReference val3;
					if (array2.Length == 0)
					{
						try
						{
							val3 = (MethodReference)(object)((IEnumerable<MethodDefinition>)baseType.Methods).SingleOrDefault((Func<MethodDefinition, bool>)((MethodDefinition m) => ((MemberReference)m).Name == baseMethodName && ((MethodReference)m).Parameters.Count == ((MethodReference)currentlyFixingUp).Parameters.Count && ((MemberReference)((MethodReference)m).ReturnType).FullName == ((MemberReference)((MethodReference)currentlyFixingUp).ReturnType).FullName && ((IEnumerable<ParameterDefinition>)((MethodReference)m).Parameters).Select((ParameterDefinition p) => ((MemberReference)((ParameterReference)p).ParameterType).FullName).SequenceEqual(targetParameters)));
						}
						catch (InvalidOperationException)
						{
							Logger.WarnNewline("\tMore than one potential base method for base type \"" + ((MemberReference)baseType).FullName + "\", method name \"" + baseMethodName + "\", parameter types " + Extensions.ToStringEnumerable<string>((IEnumerable<string>)targetParameters) + ", while considering explicit override " + ((MemberReference)currentlyFixingUp).FullName);
							continue;
						}
					}
					else
					{
						MethodDefinition self;
						try
						{
							self = ((IEnumerable<MethodDefinition>)baseType.Methods).Single((MethodDefinition m) => ((MemberReference)m).Name == baseMethodName && ((MethodReference)m).Parameters.Count == ((MethodReference)currentlyFixingUp).Parameters.Count);
						}
						catch (InvalidOperationException)
						{
							Logger.WarnNewline($"\tMore than one potential base method for base type \"{((MemberReference)baseType).FullName}\", method name \"{baseMethodName}\", parameter count {((MethodReference)currentlyFixingUp).Parameters.Count}, while considering explicit override {((MemberReference)currentlyFixingUp).FullName}");
							continue;
						}
						List<TypeReference> list = array2.Select(ResolveGenericParameter).ToList();
						if (!list.All((TypeReference gp) => gp != null))
						{
							int num2 = list.FindIndex((TypeReference g) => g == null);
							Logger.WarnNewline("\tFailed to resolve generic parameter \"" + array2[num2] + "\" for base method override " + val.Name + ".");
							continue;
						}
						list = list.Select((TypeReference p) => (!(p is GenericParameter)) ? ((MemberReference)ilTypeDefinition2).Module.ImportReference(p, (IGenericParameterProvider)(object)currentlyFixingUp) : p).ToList();
						val3 = ((MethodReference)(object)self).MakeMethodOnGenericType(list.ToArray());
					}
					if (val3 != null)
					{
						currentlyFixingUp.Overrides.Add(((MemberReference)ilTypeDefinition2).Module.ImportReference(val3, (IGenericParameterProvider)(object)currentlyFixingUp));
						continue;
					}
					Logger.WarnNewline("\tFailed to resolve base method override in type " + ((MemberReference)ilTypeDefinition2).FullName + ": Type " + text + " / Name " + baseMethodName);
					TypeReference? ResolveGenericParameter(string name)
					{
						//IL_001d: Unknown result type (might be due to invalid IL or missing references)
						//IL_0038: Expected O, but got Unknown
						var (val5, array4) = MiscUtils.TryLookupTypeDefByName(name);
						if (val5 == null)
						{
							return GenericInstanceUtils.ResolveGenericParameterType(new GenericParameter(name, (IGenericParameterProvider)(object)baseType), (TypeReference?)(object)ilTypeDefinition2);
						}
						if (array4.Length != 0)
						{
							TypeReference[] array5 = array4.Select(ResolveGenericParameter).ToArray();
							if (array5.Any((TypeReference gp) => gp == null))
							{
								return null;
							}
							return ((MemberReference)ilTypeDefinition2).Module.ImportRecursive(TypeReferenceRocks.MakeGenericInstanceType((TypeReference)(object)val5, array5));
						}
						return (TypeReference?)(object)val5;
					}
				}
			}
			finally
			{
				((IDisposable)enumerator).Dispose();
			}
		}

		private static void CopyIl2CppDataToManagedType(Il2CppTypeDefinition cppTypeDefinition, TypeDefinition ilTypeDefinition, bool suppressAttributes)
		{
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Expected O, but got Unknown
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			MethodDefinition addressAttribute = null;
			MethodDefinition fieldOffsetAttribute = null;
			MethodDefinition val = null;
			if (!suppressAttributes)
			{
				(addressAttribute, fieldOffsetAttribute, val) = GetInjectedAttributes(ilTypeDefinition);
			}
			TypeReference val2 = ((MemberReference)ilTypeDefinition).Module.ImportReference((TypeReference)(object)TypeDefinitions.String);
			if (!suppressAttributes)
			{
				CustomAttribute val3 = new CustomAttribute(((MemberReference)ilTypeDefinition).Module.ImportReference((MethodReference)(object)val));
				val3.Fields.Add(new CustomAttributeNamedArgument("Token", new CustomAttributeArgument(val2, (object)$"0x{cppTypeDefinition.token:X}")));
				ilTypeDefinition.CustomAttributes.Add(val3);
			}
			ProcessFieldsInType(cppTypeDefinition, ilTypeDefinition, val2, fieldOffsetAttribute, val);
			ProcessMethodsInType(cppTypeDefinition, ilTypeDefinition, val, addressAttribute, val2);
			ProcessPropertiesInType(cppTypeDefinition, ilTypeDefinition, val, val2);
			ProcessEventsInType(cppTypeDefinition, ilTypeDefinition, val, val2);
		}

		private static void PopulateGenericParamsForType(Il2CppTypeDefinition cppTypeDefinition, TypeDefinition ilTypeDefinition)
		{
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Expected O, but got Unknown
			TypeDefinition ilTypeDefinition2 = ilTypeDefinition;
			if (cppTypeDefinition.GenericContainer == null)
			{
				return;
			}
			foreach (Il2CppGenericParameter genericParameter in cppTypeDefinition.GenericContainer.GenericParameters)
			{
				if (!SharedState.GenericParamsByIndex.TryGetValue(genericParameter.Index, out GenericParameter value))
				{
					value = Extensions.WithFlags(new GenericParameter(genericParameter.Name, (IGenericParameterProvider)(object)ilTypeDefinition2), genericParameter.flags);
					SharedState.GenericParamsByIndex[genericParameter.Index] = value;
					((TypeReference)ilTypeDefinition2).GenericParameters.Add(value);
					((IEnumerable<Il2CppType>)genericParameter.ConstraintTypes).Select((Func<Il2CppType, GenericParameterConstraint>)((Il2CppType c) => new GenericParameterConstraint(MiscUtils.ImportTypeInto((MemberReference)(object)ilTypeDefinition2, c)))).ToList().ForEach((Action<GenericParameterConstraint>)value.Constraints.Add);
				}
				else if (!((TypeReference)ilTypeDefinition2).GenericParameters.Contains(value))
				{
					((TypeReference)ilTypeDefinition2).GenericParameters.Add(value);
				}
			}
		}

		private static (MethodDefinition addressAttribute, MethodDefinition fieldOffsetAttribute, MethodDefinition tokenAttribute) GetInjectedAttributes(TypeDefinition ilTypeDefinition)
		{
			MethodDefinition item;
			MethodDefinition item2;
			MethodDefinition item3;
			if (_attributesByModule.ContainsKey(((MemberReference)ilTypeDefinition).Module))
			{
				(item, item2, item3) = _attributesByModule[((MemberReference)ilTypeDefinition).Module];
			}
			else
			{
				item = ((IEnumerable<TypeDefinition>)((MemberReference)ilTypeDefinition).Module.Types).First((TypeDefinition x) => ((MemberReference)x).Name == "AddressAttribute").Methods[0];
				item2 = ((IEnumerable<TypeDefinition>)((MemberReference)ilTypeDefinition).Module.Types).First((TypeDefinition x) => ((MemberReference)x).FullName == "Cpp2IlInjected.FieldOffsetAttribute").Methods[0];
				item3 = ((IEnumerable<TypeDefinition>)((MemberReference)ilTypeDefinition).Module.Types).First((TypeDefinition x) => ((MemberReference)x).Name == "TokenAttribute").Methods[0];
				_attributesByModule[((MemberReference)ilTypeDefinition).Module] = (item, item2, item3);
			}
			return (item, item2, item3);
		}

		private static void ProcessFieldsInType(Il2CppTypeDefinition cppTypeDefinition, TypeDefinition ilTypeDefinition, TypeReference stringType, MethodDefinition? fieldOffsetAttribute, MethodDefinition? tokenAttribute)
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Expected O, but got Unknown
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Expected O, but got Unknown
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Expected O, but got Unknown
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			List<FieldInType> list = new List<FieldInType>();
			int num = -1;
			Il2CppFieldDefinition[] fields = cppTypeDefinition.Fields;
			foreach (Il2CppFieldDefinition val in fields)
			{
				num++;
				TypeReference val2 = MiscUtils.ImportTypeInto((MemberReference)(object)ilTypeDefinition, val.RawFieldType);
				FieldDefinition val3 = new FieldDefinition(val.Name, (FieldAttributes)(ushort)val.RawFieldType.attrs, val2);
				ilTypeDefinition.Fields.Add(val3);
				SharedState.UnmanagedToManagedFields[val] = val3;
				SharedState.ManagedToUnmanagedFields[val3] = val;
				if (val3.HasDefault)
				{
					Il2CppFieldDefaultValue defaultValue = val.DefaultValue;
					val3.Constant = ((defaultValue != null) ? defaultValue.Value : null);
				}
				if ((val.RawFieldType.attrs & 0x100u) != 0)
				{
					val3.InitialValue = val.StaticArrayInitialValue;
				}
				int fieldOffsetFromIndex = LibCpp2IlMain.Binary.GetFieldOffsetFromIndex(cppTypeDefinition.TypeIndex, num, val.FieldIndex, ((TypeReference)ilTypeDefinition).IsValueType, val3.IsStatic);
				list.Add(GetFieldInType(val2, fieldOffsetFromIndex, val.Name, val3));
				if (!val3.IsStatic && fieldOffsetAttribute != null)
				{
					CustomAttribute val4 = new CustomAttribute(((MemberReference)ilTypeDefinition).Module.ImportReference((MethodReference)(object)fieldOffsetAttribute));
					val4.Fields.Add(new CustomAttributeNamedArgument("Offset", new CustomAttributeArgument(stringType, (object)$"0x{list.Last().Offset:X}")));
					val3.CustomAttributes.Add(val4);
				}
				if (tokenAttribute != null)
				{
					CustomAttribute val5 = new CustomAttribute(((MemberReference)ilTypeDefinition).Module.ImportReference((MethodReference)(object)tokenAttribute));
					val5.Fields.Add(new CustomAttributeNamedArgument("Token", new CustomAttributeArgument(stringType, (object)$"0x{val.token:X}")));
					val3.CustomAttributes.Add(val5);
				}
			}
			list.Sort();
			SharedState.FieldsByType[ilTypeDefinition] = list;
		}

		private static void ProcessMethodsInType(Il2CppTypeDefinition cppTypeDefinition, TypeDefinition ilTypeDefinition, MethodDefinition? tokenAttribute, MethodDefinition? addressAttribute, TypeReference stringType)
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Expected O, but got Unknown
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Expected O, but got Unknown
			//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_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Expected O, but got Unknown
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_028a: Unknown result type (might be due to invalid IL or missing references)
			//IL_028f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0204: Unknown result type (might be due to invalid IL or missing references)
			//IL_0209: Unknown result type (might be due to invalid IL or missing references)
			//IL_0255: Unknown result type (might be due to invalid IL or missing references)
			//IL_025a: Unknown result type (might be due to invalid IL or missing references)
			Il2CppMethodDefinition[] methods = cppTypeDefinition.Methods;
			long num = default(long);
			foreach (Il2CppMethodDefinition val in methods)
			{
				Il2CppType rawReturnType = val.RawReturnType;
				MethodDefinition methodDefinition = new MethodDefinition(val.Name, (MethodAttributes)val.flags, ((MemberReference)ilTypeDefinition).Module.ImportReference((TypeReference)(object)TypeDefinitions.Void));
				SharedState.UnmanagedToManagedMethods[val] = methodDefinition;
				SharedState.ManagedToUnmanagedMethods[methodDefinition] = val;
				ilTypeDefinition.Methods.Add(methodDefinition);
				((MethodReference)methodDefinition).ReturnType = MiscUtils.ImportTypeInto((MemberReference)(object)methodDefinition, rawReturnType);
				if (tokenAttribute != null)
				{
					CustomAttribute val2 = new CustomAttribute(((MemberReference)ilTypeDefinition).Module.ImportReference((MethodReference)(object)tokenAttribute));
					val2.Fields.Add(new CustomAttributeNamedArgument("Token", new CustomAttributeArgument(stringType, (object)$"0x{val.token:X}")));
					methodDefinition.CustomAttributes.Add(val2);
				}
				if (methodDefinition.HasBody)
				{
					TypeReference baseType = ilTypeDefinition.BaseType;
					if (((baseType != null) ? ((MemberReference)baseType).FullName : null) != "System.MulticastDelegate")
					{
						FillMethodBodyWithStub(methodDefinition);
					}
				}
				SharedState.MethodsByIndex.TryAdd(val.MethodIndex, methodDefinition);
				SharedState.MethodsByAddress.TryAdd(val.MethodPointer, methodDefinition);
				HandleMethodParameters(val, methodDefinition);
				ulong methodPointer = val.MethodPointer;
				if ((methodPointer != 0 || val.slot != ushort.MaxValue) && addressAttribute != null)
				{
					CustomAttribute val3 = new CustomAttribute(((MemberReference)ilTypeDefinition).Module.ImportReference((MethodReference)(object)addressAttribute));
					if (methodPointer != 0)
					{
						val3.Fields.Add(new CustomAttributeNamedArgument("RVA", new CustomAttributeArgument(stringType, (object)$"0x{LibCpp2IlMain.Binary.GetRVA(methodPointer):X}")));
						if (LibCpp2IlMain.Binary.TryMapVirtualAddressToRaw(methodPointer, ref num))
						{
							val3.Fields.Add(new CustomAttributeNamedArgument("Offset", new CustomAttributeArgument(stringType, (object)$"0x{num:X}")));
						}
						else
						{
							Logger.WarnNewline($"Couldn't get file offset for method pointer 0x{methodPointer:X} for method {val.HumanReadableSignature}");
						}
						val3.Fields.Add(new CustomAttributeNamedArgument("VA", new CustomAttributeArgument(stringType, (object)$"0x{methodPointer:X}")));
					}
					if (val.slot != ushort.MaxValue)
					{
						val3.Fields.Add(new CustomAttributeNamedArgument("Slot", new CustomAttributeArgument(stringType, (object)val.slot.ToString())));
					}
					methodDefinition.CustomAttributes.Add(val3);
				}
				Il2CppGenericContainer genericContainer = val.GenericContainer;
				if (genericContainer != null)
				{
					genericContainer.GenericParameters.ToList().ForEach(delegate(Il2CppGenericParameter p)
					{
						//IL_0046: Unknown result type (might be due to invalid IL or missing references)
						//IL_0056: Expected O, but got Unknown
						if (SharedState.GenericParamsByIndex.TryGetValue(p.Index, out GenericParameter value))
						{
							if (!((MethodReference)methodDefinition).GenericParameters.Contains(value))
							{
								((MethodReference)methodDefinition).GenericParameters.Add(value);
							}
						}
						else
						{
							value = Extensions.WithFlags(new GenericParameter(p.Name, (IGenericParameterProvider)(object)methodDefinition), p.flags);
							if (!((MethodReference)methodDefinition).GenericParameters.Contains(value))
							{
								((MethodReference)methodDefinition).GenericParameters.Add(value);
							}
							((IEnumerable<Il2CppType>)p.ConstraintTypes).Select((Func<Il2CppType, GenericParameterConstraint>)((Il2CppType c) => new GenericParameterConstraint(MiscUtils.ImportTypeInto((MemberReference)(object)methodDefinition, c)))).ToList().ForEach((Action<GenericParameterConstraint>)value.Constraints.Add);
						}
					});
				}
				if (val.slot < ushort.MaxValue)
				{
					SharedState.VirtualMethodsBySlot[val.slot] = methodDefinition;
				}
			}
		}

		private static void ProcessPropertiesInType(Il2CppTypeDefinition cppTypeDefinition, TypeDefinition ilTypeDefinition, MethodDefinition? tokenAttribute, TypeReference stringType)
		{
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Expected O, but got Unknown
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Expected O, but got Unknown
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			Il2CppPropertyDefinition[] properties = cppTypeDefinition.Properties;
			foreach (Il2CppPropertyDefinition val in properties)
			{
				MethodDefinition val2 = val.Getter?.AsManaged();
				MethodDefinition val3 = val.Setter?.AsManaged();
				object obj = ((val2 != null) ? ((MethodReference)val2).ReturnType : null);
				if (obj == null)
				{
					if (val3 == null)
					{
						obj = null;
					}
					else
					{
						ParameterDefinition obj2 = ((MethodReference)val3).Parameters[0];
						obj = ((obj2 != null) ? ((ParameterReference)obj2).ParameterType : null);
					}
				}
				TypeReference val4 = (TypeReference)obj;
				PropertyDefinition val5 = new PropertyDefinition(val.Name, (PropertyAttributes)(ushort)val.attrs, ((MemberReference)ilTypeDefinition).Module.ImportReference(val4))
				{
					GetMethod = val2,
					SetMethod = val3
				};
				if (tokenAttribute != null)
				{
					CustomAttribute val6 = new CustomAttribute(((MemberReference)ilTypeDefinition).Module.ImportReference((MethodReference)(object)tokenAttribute));
					val6.Fields.Add(new CustomAttributeNamedArgument("Token", new CustomAttributeArgument(stringType, (object)$"0x{val.token:X}")));
					val5.CustomAttributes.Add(val6);
				}
				ilTypeDefinition.Properties.Add(val5);
				SharedState.UnmanagedToManagedProperties[val] = val5;
				SharedState.ManagedToUnmanagedProperties[val5] = val;
			}
		}

		private static void ProcessEventsInType(Il2CppTypeDefinition cppTypeDefinition, TypeDefinition ilTypeDefinition, MethodDefinition? tokenAttribute, TypeReference stringType)
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Expected O, but got Unknown
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Expected O, but got Unknown
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			Il2CppEventDefinition[] events = cppTypeDefinition.Events;
			foreach (Il2CppEventDefinition val in events)
			{
				EventDefinition val2 = new EventDefinition(val.Name, (EventAttributes)(ushort)val.EventAttributes, MiscUtils.ImportTypeInto((MemberReference)(object)ilTypeDefinition, val.RawType))
				{
					AddMethod = val.Adder?.AsManaged(),
					RemoveMethod = val.Remover?.AsManaged(),
					InvokeMethod = val.Invoker?.AsManaged()
				};
				if (tokenAttribute != null)
				{
					CustomAttribute val3 = new CustomAttribute(((MemberReference)ilTypeDefinition).Module.ImportReference((MethodReference)(object)tokenAttribute));
					val3.Fields.Add(new CustomAttributeNamedArgument("Token", new CustomAttributeArgument(stringType, (object)$"0x{val.token:X}")));
					val2.CustomAttributes.Add(val3);
				}
				ilTypeDefinition.Events.Add(val2);
			}
		}

		private static FieldInType GetFieldInType(TypeReference fieldTypeRef, int fieldOffset, string fieldName, FieldDefinition fieldDefinition)
		{
			if (((MemberReference)fieldDefinition.DeclaringType).FullName == "System.String" && ((MemberReference)fieldTypeRef).FullName == "System.Char")
			{
				fieldTypeRef = (TypeReference)(object)TypeReferenceRocks.MakeArrayType(fieldTypeRef);
			}
			FieldInType result = default(FieldInType);
			result.Name = fieldName;
			result.FieldType = fieldTypeRef;
			result.Offset = (ulong)fieldOffset;
			result.Static = fieldDefinition.IsStatic;
			result.Constant = fieldDefinition.Constant;
			result.DeclaringType = fieldDefinition.DeclaringType;
			result.Definition = fieldDefinition;
			return result;
		}

		private static void FillMethodBodyWithStub(MethodDefinition methodDefinition)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: 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_004e: Expected O, but got Unknown
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			ILProcessor iLProcessor = methodDefinition.Body.GetILProcessor();
			if (((MemberReference)((MethodReference)methodDefinition).ReturnType).FullName == "System.Void")
			{
				iLProcessor.Append(iLProcessor.Create(OpCodes.Ret));
			}
			else if (((MethodReference)methodDefinition).ReturnType.IsValueType)
			{
				VariableDefinition val = new VariableDefinition(((MethodReference)methodDefinition).ReturnType);
				methodDefinition.Body.Variables.Add(val);
				iLProcessor.Append(iLProcessor.Create(OpCodes.Ldloca_S, val));
				iLProcessor.Append(iLProcessor.Create(OpCodes.Initobj, ((MethodReference)methodDefinition).ReturnType));
				iLProcessor.Append(iLProcessor.Create(OpCodes.Ldloc_0));
				iLProcessor.Append(iLProcessor.Create(OpCodes.Ret));
			}
			else
			{
				iLProcessor.Append(iLProcessor.Create(OpCodes.Ldnull));
				iLProcessor.Append(iLProcessor.Create(OpCodes.Ret));
			}
		}

		private static void HandleMethodParameters(Il2CppMethodDefinition il2CppMethodDef, MethodDefinition monoMethodDef)
		{
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Expected O, but got Unknown
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Expected O, but got Unknown
			Il2CppParameterReflectionData[] parameters = il2CppMethodDef.Parameters;
			foreach (Il2CppParameterReflectionData val in parameters)
			{
				TypeReference val2 = MiscUtils.ImportTypeInto((MemberReference)(object)monoMethodDef, val.RawType);
				if (val.RawType.byref == 1)
				{
					val2 = (TypeReference)new ByReferenceType(val2);
				}
				ParameterDefinition val3 = new ParameterDefinition(val.ParameterName, (ParameterAttributes)(ushort)val.ParameterAttributes, val2);
				if (val.DefaultValue != null)
				{
					val3.Constant = val.DefaultValue;
				}
				((MethodReference)monoMethodDef).Parameters.Add(val3);
			}
		}

		internal static string BuildWholeMetadataString(TypeDefinition typeDefinition)
		{
			StringBuilder ret = new StringBuilder();
			ret.Append((object?)GetBasicTypeMetadataString(typeDefinition));
			SharedState.FieldsByType[typeDefinition].ToList().ForEach(delegate(FieldInType f)
			{
				ret.Append((object?)GetFieldMetadataString(f));
			});
			((IEnumerable<MethodDefinition>)typeDefinition.Methods).ToList().ForEach(delegate(MethodDefinition m)
			{
				ret.Append((object?)GetMethodMetadataString(m.AsUnmanaged()));
			});
			return ret.ToString();
		}

		private static StringBuilder GetBasicTypeMetadataString(TypeDefinition ilTypeDefinition)
		{
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.Append("Type: " + ((MemberReference)ilTypeDefinition).FullName + ":").Append($"\n\tBase Class: \n\t\t{ilTypeDefinition.BaseType}\n").Append("\n\tInterfaces:\n");
			Enumerator<InterfaceImplementation> enumerator = ilTypeDefinition.Interfaces.GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					InterfaceImplementation current = enumerator.Current;
					stringBuilder.Append("\t\t" + ((MemberReference)current.InterfaceType).FullName + "\n");
				}
			}
			finally
			{
				((IDisposable)enumerator).Dispose();
			}
			if (ilTypeDefinition.NestedTypes.Count > 0)
			{
				stringBuilder.Append("\n\tNested Types:\n");
				Enumerator<TypeDefinition> enumerator2 = ilTypeDefinition.NestedTypes.GetEnumerator();
				try
				{
					while (enumerator2.MoveNext())
					{
						TypeDefinition current2 = enumerator2.Current;
						stringBuilder.Append("\t\t" + ((MemberReference)current2).FullName + "\n");
					}
				}
				finally
				{
					((IDisposable)enumerator2).Dispose();
				}
			}
			return stringBuilder;
		}

		private static StringBuilder GetFieldMetadataString(FieldInType field)
		{
			StringBuilder stringBuilder = new StringBuilder();
			StringBuilder stringBuilder2 = stringBuilder.Append("\n\t" + (field.Static ? "Static Field" : "Field") + ": " + field.Name + "\n");
			TypeReference? fieldType = field.FieldType;
			stringBuilder2.Append("\t\tType: " + ((fieldType != null) ? ((MemberReference)fieldType).FullName : null) + "\n").Append($"\t\tOffset in Defining Type: 0x{field.Offset:X}\n").Append($"\t\tHas Default: {field.Definition.HasDefault}\n");
			if (field.Constant is char c && char.IsSurrogate(c))
			{
				return stringBuilder;
			}
			if (field.Constant != null)
			{
				stringBuilder.Append($"\t\tDefault Value: {field.Constant}\n");
			}
			return stringBuilder;
		}

		private static StringBuilder GetMethodMetadataString(Il2CppMethodDefinition methodDef)
		{
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.Append("\n\tMethod: " + methodDef.Name + ":\n").Append($"\t\tAccessibility: {methodDef.Attributes & MethodAttributes.MemberAccessMask}\n").Append($"\t\tReturn Type: {methodDef.ReturnType}\n")
				.Append($"\t\tFile Offset 0x{methodDef.MethodOffsetInFile:X8}\n")
				.Append($"\t\tRam Offset 0x{methodDef.MethodPointer:x8}\n")
				.Append($"\t\tVirtual Method Slot: {methodDef.slot}\n");
			int num = -1;
			Il2CppParameterReflectionData[] parameters = methodDef.Parameters;
			foreach (Il2CppParameterReflectionData val in parameters)
			{
				num++;
				stringBuilder.Append($"\n\t\tParameter {num}:\n").Append("\t\t\tName: " + val.ParameterName + "\n").Append($"\t\t\tType: {val.Type}\n")
					.Append($"\t\t\tDefault Value: {val.DefaultValue}");
			}
			return stringBuilder;
		}
	}
	public static class AttributeRestorer
	{
		private struct FieldToParameterMapping
		{
			public FieldDefinition Field;

			public ParameterDefinition Parameter;

			public FieldToParameterMapping(FieldDefinition field, ParameterDefinition parameter)
			{
				Field = field;
				Parameter = parameter;
			}
		}

		private static readonly ConcurrentDictionary<long, MethodDefinition> _attributeCtorsByClassIndex;

		private static readonly ConcurrentDictionary<TypeDefinition, Dictionary<FieldDefinition, PropertyDefinition>> _simpleFieldToPropertyCache;

		internal static readonly TypeDefinition DummyTypeDefForAttributeCache;

		internal static readonly TypeDefinition DummyTypeDefForAttributeList;

		private static readonly ConcurrentDictionary<MethodDefinition, FieldToParameterMapping[]?> FieldToParameterMappings;

		private static List<Il2CppCustomAttributeTypeRange> _sortedTypeRangeList;

		private static Dictionary<ModuleDefinition, MethodDefinition> _attributeAttributeCtorsByModule;

		static AttributeRestorer()
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected O, but got Unknown
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Expected O, but got Unknown
			_attributeCtorsByClassIndex = new ConcurrentDictionary<long, MethodDefinition>();
			_simpleFieldToPropertyCache = new ConcurrentDictionary<TypeDefinition, Dictionary<FieldDefinition, PropertyDefinition>>();
			DummyTypeDefForAttributeCache = new TypeDefinition("dummy", "AttributeCache", (TypeAttributes)1048833);
			DummyTypeDefForAttributeList = new TypeDefinition("dummy", "AttributeList", (TypeAttributes)1048833);
			FieldToParameterMappings = new ConcurrentDictionary<MethodDefinition, FieldToParameterMapping[]>();
			_attributeAttributeCtorsByModule = new Dictionary<ModuleDefinition, MethodDefinition>();
			Initialize();
		}

		private static void Initialize()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected O, but got Unknown
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Expected O, but got Unknown
			DummyTypeDefForAttributeCache.BaseType = (TypeReference)(object)TypeDefinitions.ValueType;
			DummyTypeDefForAttributeCache.Fields.Add(new FieldDefinition("count", (FieldAttributes)6, (TypeReference)(object)TypeDefinitions.Int32));
			DummyTypeDefForAttributeCache.Fields.Add(new FieldDefinition("attributes", (FieldAttributes)6, (TypeReference)(object)DummyTypeDefForAttributeList));
			SharedState.FieldsByType[DummyTypeDefForAttributeCache] = new List<FieldInType>
			{
				new FieldInType
				{
					Definition = ((IEnumerable<FieldDefinition>)DummyTypeDefForAttributeCache.Fields).First(),
					Name = "count",
					Offset = 0uL,
					Static = false,
					DeclaringType = DummyTypeDefForAttributeCache,
					FieldType = (TypeReference?)(object)TypeDefinitions.Int32
				},
				new FieldInType
				{
					Definition = ((IEnumerable<FieldDefinition>)DummyTypeDefForAttributeCache.Fields).Last(),
					Name = "attributes",
					Offset = (ulong)(((ClassReadingBinaryReader)LibCpp2IlMain.Binary).is32Bit ? 4 : 8),
					Static = false,
					DeclaringType = DummyTypeDefForAttributeCache,
					FieldType = (TypeReference?)(object)DummyTypeDefForAttributeList
				}
			};
			SharedState.FieldsByType[DummyTypeDefForAttributeList] = new List<FieldInType>();
			_sortedTypeRangeList = LibCpp2IlMain.TheMetadata.attributeTypeRanges?.ToList() ?? new List<Il2CppCustomAttributeTypeRange>();
			Extensions.SortByExtractedKey<Il2CppCustomAttributeTypeRange, uint>(_sortedTypeRangeList, (Func<Il2CppCustomAttributeTypeRange, uint>)((Il2CppCustomAttributeTypeRange r) => r.token));
		}

		internal static void Reset()
		{
			lock (_attributeCtorsByClassIndex)
			{
				_attributeCtorsByClassIndex.Clear();
			}
			lock (FieldToParameterMappings)
			{
				FieldToParameterMappings.Clear();
			}
			_simpleFieldToPropertyCache.Clear();
			_sortedTypeRangeList.Clear();
			_attributeAttributeCtorsByModule.Clear();
			Initialize();
		}

		internal static void ApplyCustomAttributesToAllTypesInAssembly<T>(AssemblyDefinition assemblyDefinition, BaseKeyFunctionAddresses? keyFunctionAddresses)
		{
			Il2CppImageDefinition imageDef = SharedState.ManagedToUnmanagedAssemblies[assemblyDefinition];
			foreach (TypeDefinition item in ((IEnumerable<TypeDefinition>)assemblyDefinition.MainModule.Types).Where((TypeDefinition t) => ((TypeReference)t).Namespace != "Cpp2IlInjected"))
			{
				RestoreAttributesInType<T>(imageDef, item, keyFunctionAddresses);
			}
		}

		private static void RestoreAttributesInType<T>(Il2CppImageDefinition imageDef, TypeDefinition typeDefinition, BaseKeyFunctionAddresses? keyFunctionAddresses)
		{
			//IL_0277: Unknown result type (might be due to invalid IL or missing references)
			//IL_027c: Unknown result type (might be due to invalid IL or missing references)
			TypeDefinition typeDefinition2 = typeDefinition;
			Il2CppTypeDefinition val = SharedState.ManagedToUnmanagedTypes[typeDefinition2];
			GetCustomAttributesByAttributeIndex<T>(imageDef, val.customAttributeIndex, val.token, ((MemberReference)typeDefinition2).Module, keyFunctionAddresses, val.FullName).ForEach(delegate(CustomAttribute attribute)
			{
				typeDefinition2.CustomAttributes.Add(attribute);
			});
			Il2CppFieldDefinition[] fields = val.Fields;
			foreach (Il2CppFieldDefinition val2 in fields)
			{
				FieldDefinition fieldDefinition = SharedState.UnmanagedToManagedFields[val2];
				GetCustomAttributesByAttributeIndex<T>(imageDef, val2.customAttributeIndex, val2.token, ((MemberReference)typeDefinition2).Module, keyFunctionAddresses, ((MemberReference)fieldDefinition).FullName).ForEach(delegate(CustomAttribute attribute)
				{
					fieldDefinition.CustomAttributes.Add(attribute);
				});
			}
			Il2CppMethodDefinition[] methods = val.Methods;
			foreach (Il2CppMethodDefinition val3 in methods)
			{
				MethodDefinition methodDefinition = val3.AsManaged();
				GetCustomAttributesByAttributeIndex<T>(imageDef, val3.customAttributeIndex, val3.token, ((MemberReference)typeDefinition2).Module, keyFunctionAddresses, val3.DeclaringType.FullName + "::" + ((MemberReference)methodDefinition).FullName).ForEach(delegate(CustomAttribute attribute)
				{
					methodDefinition.CustomAttributes.Add(attribute);
				});
				Il2CppParameterDefinition[] internalParameterData = val3.InternalParameterData;
				for (int j = 0; j < val3.parameterCount; j++)
				{
					Il2CppParameterDefinition val4 = internalParameterData[j];
					ParameterDefinition paramDefinition = ((MethodReference)methodDefinition).Parameters[j];
					GetCustomAttributesByAttributeIndex<T>(imageDef, val4.customAttributeIndex, val4.token, ((MemberReference)typeDefinition2).Module, keyFunctionAddresses, "Parameter " + ((ParameterReference)paramDefinition).Name + " of " + ((MemberReference)methodDefinition).FullName).ForEach(delegate(CustomAttribute attribute)
					{
						paramDefinition.CustomAttributes.Add(attribute);
					});
				}
			}
			Il2CppPropertyDefinition[] properties = val.Properties;
			foreach (Il2CppPropertyDefinition val5 in properties)
			{
				PropertyDefinition propertyDefinition = SharedState.UnmanagedToManagedProperties[val5];
				GetCustomAttributesByAttributeIndex<T>(imageDef, val5.customAttributeIndex, val5.token, ((MemberReference)typeDefinition2).Module, keyFunctionAddresses, ((MemberReference)propertyDefinition).FullName).ForEach(delegate(CustomAttribute attribute)
				{
					propertyDefinition.CustomAttributes.Add(attribute);
				});
			}
			Enumerator<TypeDefinition> enumerator = typeDefinition2.NestedTypes.GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					TypeDefinition current = enumerator.Current;
					RestoreAttributesInType<T>(imageDef, current, keyFunctionAddresses);
				}
			}
			finally
			{
				((IDisposable)enumerator).Dispose();
			}
		}

		public static List<CustomAttribute> GetCustomAttributesByAttributeIndex<T>(Il2CppImageDefinition imageDef, int attributeIndex, uint token, ModuleDefinition module, BaseKeyFunctionAddresses? keyFunctionAddresses, string warningName)
		{
			//IL_044e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0453: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Invalid comparison between Unknown and I4
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Invalid comparison between Unknown and I4
			//IL_051f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0524: Unknown result type (might be due to invalid IL or missing references)
			List<CustomAttribute> list = new List<CustomAttribute>();
			Il2CppCustomAttributeTypeRange attributeTypeRange = LibCpp2IlMain.TheMetadata.GetCustomAttributeData(imageDef, attributeIndex, token);
			if (attributeTypeRange == null || attributeTypeRange.count == 0)
			{
				return list;
			}
			List<TypeDefinition> attributesFromRange = GetAttributesFromRange(attributeTypeRange);
			List<MethodReference> list2 = (from i in Enumerable.Range(0, attributeTypeRange.count)
				select ResolveConstructorForAttribute(attributeTypeRange, i)).ToList();
			bool num = list2.Any((MethodReference c) => c.HasParameters);
			ulong addressOfAttributeGeneratorFunction = GetAddressOfAttributeGeneratorFunction(imageDef, attributeTypeRange);
			if (!num)
			{
				return GenerateAttributesWithoutAnalysis(list2, module, addressOfAttributeGeneratorFunction, generateFallback: false);
			}
			if (keyFunctionAddresses != null)
			{
				InstructionSet instructionSet = LibCpp2IlMain.Binary.InstructionSet;
				if ((int)instructionSet != 2 && (int)instructionSet != 4)
				{
					long num2 = default(long);
					if (!LibCpp2IlMain.Binary.TryMapVirtualAddressToRaw(addressOfAttributeGeneratorFunction, ref num2))
					{
						return GenerateAttributesWithoutAnalysis(list2, module, 0uL, generateFallback: true);
					}
					List<BaseAction<T>> actionsPerformedByGenerator;
					try
					{
						actionsPerformedByGenerator = GetActionsPerformedByGenerator<T>(keyFunctionAddresses, addressOfAttributeGeneratorFunction, attributesFromRange);
					}
					catch (AnalysisExceptionRaisedException)
					{
						return GenerateAttributesWithoutAnalysis(list2, module, addressOfAttributeGeneratorFunction, generateFallback: true);
					}
					LocalDefinition[] array = new LocalDefinition[attributesFromRange.Count];
					foreach (AbstractAttributeLoadFromListAction<T> item in actionsPerformedByGenerator.Where((BaseAction<T> a) => a is AbstractAttributeLoadFromListAction<T>).Cast<AbstractAttributeLoadFromListAction<T>>())
					{
						if (item.LocalMade != null)
						{
							array[item.OffsetInList] = item.LocalMade;
						}
					}
					list.AddRange(GenerateAttributesWithoutAnalysis(list2, module, addressOfAttributeGeneratorFunction, generateFallback: false));
					for (int j = 0; j < attributesFromRange.Count; j++)
					{
						LocalDefinition local = array[j];
						TypeDefinition val = attributesFromRange[j];
						MethodDefinition val2 = TypeDefinitionRocks.GetConstructors(val).FirstOrDefault((Func<MethodDefinition, bool>)((MethodDefinition c) => !((MethodReference)c).HasParameters));
						if (local == null && val2 != null)
						{
							continue;
						}
						if (local == null)
						{
							CustomAttribute val3 = GenerateFallbackAttribute((MethodReference)(object)TypeDefinitionRocks.GetConstructors(val).First(), module, addressOfAttributeGeneratorFunction);
							if (val3 != null)
							{
								list.Add(val3);
							}
							continue;
						}
						List<string> allCtorNames = (from c in TypeDefinitionRocks.GetConstructors(val)
							select ((MemberReference)c).FullName).ToList();
						AbstractCallAction<T> abstractCallAction2 = (AbstractCallAction<T>)actionsPerformedByGenerator.FirstOrDefault(delegate(BaseAction<T> c)
						{
							if (c is AbstractCallAction<T> abstractCallAction4)
							{
								MethodReference managedMethodBeingCalled2 = abstractCallAction4.ManagedMethodBeingCalled;
								if (managedMethodBeingCalled2 != null && abstractCallAction4.InstanceBeingCalledOn == local)
								{
									return allCtorNames.Contains(((MemberReference)managedMethodBeingCalled2).FullName);
								}
							}
							return false;
						});
						(MethodDefinition, List<CustomAttributeArgument>)? tuple = null;
						if (abstractCallAction2?.ManagedMethodBeingCalled == null && val2 == null)
						{
							try
							{
								tuple = TryResolveAttributeConstructorParamsTheHardWay(keyFunctionAddresses, val, actionsPerformedByGenerator, local);
							}
							catch (Exception)
							{
							}
							if (!tuple.HasValue)
							{
								CustomAttribute val4 = GenerateFallbackAttribute((MethodReference)(object)TypeDefinitionRocks.GetConstructors(val).First(), module, addressOfAttributeGeneratorFunction);
								if (val4 != null)
								{
									list.Add(val4);
								}
								continue;
							}
						}
						CustomAttribute val5;
						try
						{
							if (abstractCallAction2?.ManagedMethodBeingCalled == null)
							{
								goto IL_033f;
							}
							List<IAnalysedOperand?>? arguments = abstractCallAction2.Arguments;
							if (arguments == null || arguments.Count <= 0)
							{
								goto IL_033f;
							}
							val5 = GenerateCustomAttributeWithConstructorParams(module.ImportReference(abstractCallAction2.ManagedMethodBeingCalled), abstractCallAction2.Arguments, module);
							goto end_IL_02f9;
							IL_033f:
							if (!tuple.HasValue)
							{
								continue;
							}
							val5 = GenerateCustomAttributeFromHardWayResult(tuple.Value.Item1, tuple.Value.Item2, module);
							end_IL_02f9:;
						}
						catch (Exception)
						{
							CustomAttribute val6 = GenerateFallbackAttribute((MethodReference)(object)TypeDefinitionRocks.GetConstructors(val).First(), module, addressOfAttributeGeneratorFunction);
							if (val6 != null)
							{
								list.Add(val6);
							}
							continue;
						}
						List<AbstractFieldWriteFromVariableAction<T>> list3 = actionsPerformedByGenerator.Where((BaseAction<T> c) => c is AbstractFieldWriteFromVariableAction<T> abstractFieldWriteFromVariableAction && (object)abstractFieldWriteFromVariableAction.FieldWritten != null && abstractFieldWriteFromVariableAction.InstanceBeingSetOn == local).Cast<AbstractFieldWriteFromVariableAction<T>>().ToList();
						List<AbstractCallAction<T>> list4 = actionsPerformedByGenerator.Where(delegate(BaseAction<T> c)
						{
							if (c is AbstractCallAction<T> abstractCallAction3)
							{
								MethodReference managedMethodBeingCalled = abstractCallAction3.ManagedMethodBeingCalled;
								if (managedMethodBeingCalled != null && ((MemberReference)managedMethodBeingCalled).Name != ".ctor")
								{
									return abstractCallAction3.InstanceBeingCalledOn == local;
								}
							}
							return false;
						}).Cast<AbstractCallAction<T>>().ToList();
						if (list3.Count > 0 && !tuple.HasValue)
						{
							Dictionary<FieldDefinition, PropertyDefinition> simplePropertyFieldMappings = GetSimplePropertyFieldMappings<T>(val, keyFunctionAddresses);
							foreach (AbstractFieldWriteFromVariableAction<T> item2 in list3)
							{
								FieldDefinition finalLoadInChain = item2.FieldWritten.GetLast().FinalLoadInChain;
								if (simplePropertyFieldMappings.TryGetValue(finalLoadInChain, out var value))
								{
									try
									{
										val5.Properties.Add(new CustomAttributeNamedArgument(((MemberReference)value).Name, CoerceAnalyzedOpToType(item2.SourceOperand, ((PropertyReference)value).PropertyType)));
									}
									catch (Exception)
									{
									}
								}
							}
						}
						if (list4.Count > 0 && !tuple.HasValue)
						{
							Collection<PropertyDefinition> properties = val.Properties;
							foreach (AbstractCallAction<T> abstractCallAction in list4)
							{
								PropertyDefinition val7 = ((IEnumerable<PropertyDefinition>)properties).FirstOrDefault((Func<PropertyDefinition, bool>)((PropertyDefinition p) => p.SetMethod == abstractCallAction.ManagedMethodBeingCalled));
								if (val7 == null)
								{
									continue;
								}
								List<IAnalysedOperand?>? arguments2 = abstractCallAction.Arguments;
								if (arguments2 == null || arguments2.Count >= 1)
								{
									try
									{
										val5.Properties.Add(new CustomAttributeNamedArgument(((MemberReference)val7).Name, CoerceAnalyzedOpToType(abstractCallAction.Arguments[0], ((PropertyReference)val7).PropertyType)));
									}
									catch (Exception)
									{
									}
								}
							}
						}
						list.Add(val5);
					}
					return list;
				}
			}
			return GenerateAttributesWithoutAnalysis(list2, module, addressOfAttributeGeneratorFunction, generateFallback: true);
		}

		private static List<CustomAttribute> GenerateAttributesWithoutAnalysis(List<MethodReference> attributeCtors, ModuleDefinition module, ulong generatorPtr, bool generateFallback)
		{
			ModuleDefinition module2 = module;
			return (from c in attributeCtors
				where !c.HasParameters || generateFallback
				select (CustomAttribute)((!c.HasParameters) ? ((object)new CustomAttribute(module2.ImportReference(c))) : ((object)GenerateFallbackAttribute(c, module2, generatorPtr))) into c
				where c != null
				select c).ToList();
		}

		private static CustomAttribute? GenerateFallbackAttribute(MethodReference constructor, ModuleDefinition module, ulong generatorPtr)
		{
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: 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_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: 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_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Expected O, but got Unknown
			if (!_attributeAttributeCtorsByModule.TryGetValue(module, out MethodDefinition value))
			{
				TypeDefinition val = ((IEnumerable<TypeDefinition>)module.Types).SingleOrDefault((Func<TypeDefinition, bool>)((TypeDefinition t) => ((TypeReference)t).Namespace == "Cpp2IlInjected" && ((MemberReference)t).Name == "AttributeAttribute"));
				if (val == null)
				{
					return null;
				}
				MethodDefinition val3 = (_attributeAttributeCtorsByModule[module] = TypeDefinitionRocks.GetConstructors(val).First());
				value = val3;
			}
			CustomAttribute val4 = new CustomAttribute((MethodReference)(object)value);
			CustomAttributeNamedArgument val5 = default(CustomAttributeNamedArgument);
			((CustomAttributeNamedArgument)(ref val5))..ctor("Name", new CustomAttributeArgument(module.ImportReference((TypeReference)(object)TypeDefinitions.String), (object)((MemberReference)((MemberReference)constructor).DeclaringType).Name));
			CustomAttributeNamedArgument val6 = default(CustomAttributeNamedArgument);
			((CustomAttributeNamedArgument)(ref val6))..ctor("RVA", new CustomAttributeArgument(module.ImportReference((TypeReference)(object)TypeDefinitions.String), (object)$"0x{LibCpp2IlMain.Binary.GetRVA(generatorPtr):X}"));
			long num = default(long);
			if (!LibCpp2IlMain.Binary.TryMapVirtualAddressToRaw(generatorPtr, ref num))
			{
				num = 0L;
			}
			CustomAttributeNamedArgument val7 = default(CustomAttributeNamedArgument);
			((CustomAttributeNamedArgument)(ref val7))..ctor("Offset", new CustomAttributeArgument(module.ImportReference((TypeReference)(object)TypeDefinitions.String), (object)$"0x{num:X}"));
			val4.Fields.Add(val5);
			val4.Fields.Add(val6);
			val4.Fields.Add(val7);
			return val4;
		}

		private static List<BaseAction<T>> GetActionsPerformedByGenerator<T>(BaseKeyFunctionAddresses keyFunctionAddresses, ulong attributeGeneratorAddress, List<TypeDefinition> attributesExpected)
		{
			//IL_0014: 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_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Invalid comparison between Unknown and I4
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Invalid comparison between Unknown and I4
			InstructionSet? val = LibCpp2IlMain.Binary?.InstructionSet;
			if (val.HasValue)
			{
				InstructionSet valueOrDefault = val.GetValueOrDefault();
				object obj;
				if ((int)valueOrDefault > 1)
				{
					if ((int)valueOrDefault != 3)
					{
						goto IL_005d;
					}
					obj = new AsmAnalyzerArmV8A(attributeGeneratorAddress, Arm64Utils.GetArm64MethodBodyAtVirtualAddress(attributeGeneratorAddress), keyFunctionAddresses);
				}
				else
				{
					obj = new AsmAnalyzerX86(attributeGeneratorAddress, X86Utils.GetMethodBodyAtVirtAddressNew(attributeGeneratorAddress, peek: false), keyFunctionAddresses);
				}
				AsmAnalyzerBase<T> obj2 = (AsmAnalyzerBase<T>)obj;
				obj2.AddParameter(DummyTypeDefForAttributeCache, "attributeCache");
				obj2.AttributesForRestoration = attributesExpected;
				obj2.AnalyzeMethod();
				return obj2.Analysis.Actions.ToList();
			}
			goto IL_005d;
			IL_005d:
			throw new UnsupportedInstructionSetException();
		}

		private static List<TypeDefinition> GetAttributesFromRange(Il2CppCustomAttributeTypeRange attributeTypeRange)
		{
			List<Il2CppType> source = (from attrIdx in Enumerable.Range(attributeTypeRange.start, attributeTypeRange.count)
				select LibCpp2IlMain.TheMetadata.attributeTypes[attrIdx] into typeIdx
				select LibCpp2IlMain.Binary.GetType(typeIdx)).ToList();
			if (source.Any((Il2CppType a) => (int)a.type != 18))
			{
				throw new Exception("Non-class attribute? How does that work?");
			}
			return (from attributeType in source
				select LibCpp2IlMain.TheMetadata.typeDefs[attributeType.data.classIndex] into typeDef
				select SharedState.UnmanagedToManagedTypes[typeDef]).ToList();
		}

		private static ulong GetAddressOfAttributeGeneratorFunction(Il2CppImageDefinition imageDef, Il2CppCustomAttributeTypeRange attributeTypeRange)
		{
			int num = _sortedTypeRangeList.BinarySearch(attributeTypeRange, (IComparer<Il2CppCustomAttributeTypeRange>?)new TokenComparer());
			if (num < 0)
			{
				Logger.WarnNewline("Found attribute type range that's not in the list we have?");
				return ulong.MaxValue;
			}
			if (LibCpp2IlMain.MetadataVersion < 27f)
			{
				try
				{
					return LibCpp2IlMain.Binary.GetCustomAttributeGenerator(num);
				}
				catch (IndexOutOfRangeException)
				{
					Logger.WarnNewline($"Found attribute type range for token 0x{attributeTypeRange.token:X} at index {num} which is beyond the known generator address list (length={LibCpp2IlMain.Binary.AllCustomAttributeGenerators.Length}).");
					return ulong.MaxValue;
				}
			}
			ulong customAttributeCacheGenerator = LibCpp2IlMain.Binary.GetCodegenModuleByName(imageDef.Name).customAttributeCacheGenerator;
			int num2 = num - imageDef.customAttributeStart;
			ulong num3 = customAttributeCacheGenerator + (ulong)((long)num2 * (long)(((ClassReadingBinaryReader)LibCpp2IlMain.Binary).is32Bit ? 4 : 8));
			return LibCpp2IlMain.Binary.ReadClassAtVirtualAddress<ulong>(num3);
		}

		private static MethodReference ResolveConstructorForAttribute(Il2CppCustomAttributeTypeRange attributeTypeRange, int attributeIdx)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Invalid comparison between Unknown and I4
			int num = LibCpp2IlMain.TheMetadata.attributeTypes[attributeTypeRange.start + attributeIdx];
			Il2CppType type = LibCpp2IlMain.Binary.GetType(num);
			if ((int)type.type != 18)
			{
				throw new Exception("Non-class attribute? How does that work?");
			}
			lock (_attributeCtorsByClassIndex)
			{
				if (!_attributeCtorsByClassIndex.TryGetValue(type.data.classIndex, out MethodDefinition value))
				{
					MethodDefinition val = LibCpp2IlMain.TheMetadata.typeDefs[type.data.classIndex].Methods.First((Il2CppMethodDefinition c) => c.Name == ".ctor").AsManaged();
					_attributeCtorsByClassIndex.TryAdd(type.data.classIndex, val);
					return (MethodReference)(object)val;
				}
				return (MethodReference)(object)value;
			}
		}

		private static CustomAttribute GenerateCustomAttributeWithConstructorParams(MethodReference constructor, List<IAnalysedOperand> constructorArgs, ModuleDefinition module)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Expected O, but got Unknown
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			CustomAttribute val = new CustomAttribute(module.ImportReference(constructor));
			if (constructorArgs.Count == 0)
			{
				return val;
			}
			if (constructor.Parameters.Count != constructorArgs.Count)
			{
				throw new Exception("Mismatch between constructor param count & actual args count? Probably because named args support not implemented");
			}
			int num = 0;
			foreach (IAnalysedOperand constructorArg in constructorArgs)
			{
				ParameterDefinition val2 = constructor.Parameters[num];
				val.ConstructorArguments.Add(CoerceAnalyzedOpToType(constructorArg, ((ParameterReference)val2).ParameterType));
				num++;
			}
			return val;
		}

		private static CustomAttributeArgument CoerceAnalyzedOpToType(IAnalysedOperand analysedOperand, TypeReference typeReference)
		{
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: 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)
			if (!(analysedOperand is ConstantDefinition constantDefinition))
			{
				if (analysedOperand is LocalDefinition localDefinition)
				{
					if (localDefinition.KnownInitialValue == null)
					{
						throw new Exception($"Can't use a local without a KnownInitialValue in an attribute ctor: {localDefinition}");
					}
					object obj = localDefinition.KnownInitialValue;
					object obj2 = obj;
					TypeDefinition obj3 = typeReference.Resolve();
					TypeReference val = (TypeReference)((obj3 != null && obj3.IsEnum) ? ((object)TypeDefinitionRocks.GetEnumUnderlyingType(typeReference.Resolve())) : ((object)typeReference));
					if (obj is AllocatedArray array)
					{
						obj = AllocateArray(array);
					}
					else if (((MemberReference)localDefinition.Type).FullName != ((MemberReference)val).FullName)
					{
						try
						{
							obj = AnalysisUtils.CoerceValue(obj, val);
						}
						catch (Exception innerException)
						{
							throw new Exception($"Failed to coerce local's known initial value \"{obj}\" to type {val}", innerException);
						}
					}
					if (((MemberReference)val).FullName == "System.Object")
					{
						obj = (object)new CustomAttributeArgument((TypeReference)(object)MiscUtils.TryLookupTypeDefKnownNotGeneric(obj2.GetType().FullName), obj2);
					}
					return new CustomAttributeArgument(typeReference, obj);
				}
				throw new Exception($"Operand {analysedOperand} is not valid for use in a attribute ctor");
			}
			object obj4 = constantDefinition.Value;
			TypeDefinition obj5 = typeReference.Resolve();
			TypeReference val2 = (TypeReference)((obj5 != null && obj5.IsEnum) ? ((object)TypeDefinitionRocks.GetEnumUnderlyingType(typeReference.Resolve())) : ((object)typeReference));
			if (constantDefinition.Type.FullName != ((MemberReference)val2).FullName)
			{
				obj4 = AnalysisUtils.CoerceValue(obj4, val2);
			}
			return new CustomAttributeArgument(typeReference, obj4);
		}

		private static object AllocateArray(AllocatedArray array)
		{
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			AllocatedArray array2 = array;
			TypeReference val = ((TypeSpecification)array2.ArrayType).ElementType;
			if (val == null)
			{
				throw new Exception("Array has no type");
			}
			TypeDefinition val2 = val.Resolve();
			if (val2 != null && val2.IsEnum)
			{
				val = TypeDefinitionRocks.GetEnumUnderlyingType(val2) ?? val;
			}
			Array array3 = Array.CreateInstance(Type.GetType(((MemberReference)val).FullName) ?? throw new Exception("Could not resolve array type " + ((MemberReference)((TypeSpecification)array2.ArrayType).ElementType).FullName), array2.Size);
			if (array2.KnownValuesAtOffsets.Count != array2.Size)
			{
				throw new Exception($"Failed to populate known array - only have {array2.KnownValuesAtOffsets.Count} known values for an array of length {array2.Size}.");
			}
			int num = default(int);
			object obj = default(object);
			foreach (KeyValuePair<int, object> knownValuesAtOffset in array2.KnownValuesAtOffsets)
			{
				Extensions.Deconstruct<int, object>(knownValuesAtOffset, ref num, ref obj);
				int num2 = num;
				object obj2 = obj;
				try
				{
					object value = ((obj2 == null) ? null : AnalysisUtils.CoerceValue(obj2, val));
					if (((MemberReference)val).FullName == "System.Object")
					{
						value = (object)new CustomAttributeArgument((TypeReference)(object)MiscUtils.TryLookupTypeDefKnownNotGeneric(obj2.GetType().FullName), obj2);
					}
					array3.SetValue(value, num2);
				}
				catch (Exception innerException)
				{
					throw new Exception($"Failed to coerce value \"{obj2}\" (type {obj2?.GetType().FullName}) at index {num2} to type {val} for array of length {array2.Size}", innerException);
				}
			}
			return array3.Cast<object>().Select((Func<object, CustomAttributeArgument>)((object o) => new CustomAttributeArgument(((TypeSpecification)array2.ArrayType).ElementType, o))).ToArray();
		}

		private static FieldToParameterMapping[]? TryAnalyzeAttributeConstructorToResolveFieldWrites(MethodDefinition constructor, BaseKeyFunctionAddresses keyFunctionAddresses)
		{
			lock (FieldToParameterMappings)
			{
				if (FieldToParameterMappings.TryGetValue(constructor, out FieldToParameterMapping[] value))
				{
					return value;
				}
				Logger.VerboseNewline("Attempting to run attribute constructor reconstruction for " + ((MemberReference)constructor).FullName, "AttributeRestore");
				_ = constructor.AsUnmanaged().MethodPointer;
				AsmAnalyzerX86 asmAnalyzerX = new AsmAnalyzerX86(constructor, keyFunctionAddresses);
				bool flag = false;
				List<RegToFieldAction> source = null;
				try
				{
					asmAnalyzerX.AnalyzeMethod();
					source = asmAnalyzerX.Analysis.Actions.Where((BaseAction<Instruction> f) => f is RegToFieldAction).Cast<RegToFieldAction>().ToList();
					if (!source.All((RegToFieldAction f) => f.SourceOperand is LocalDefinition localDefinition && localDefinition.ParameterDefinition != null))
					{
						flag = true;
					}
					if (source.Any((RegToFieldAction f) => f.FieldWritten?.FinalLoadInChain == null))
					{
						flag = true;
					}
				}
				catch (Exception arg)
				{
					Logger.WarnNewline($"Failed to run constructor restoration: {arg}.");
					flag = true;
				}
				if (flag)
				{
					FieldToParameterMappings.TryAdd(constructor, null);
					return null;
				}
				value = source.Select((RegToFieldAction f) => new FieldToParameterMapping(f.FieldWritten.FinalLoadInChain, ((LocalDefinition)f.SourceOperand).ParameterDefinition)).ToArray();
				FieldToParameterMappings.TryAdd(constructor, value);
				return value;
			}
		}

		private static (MethodDefinition potentialCtor, List<CustomAttributeArgument> parameterList)? TryResolveAttributeConstructorParamsTheHardWay<T>(BaseKeyFunctionAddresses keyFunctionAddresses, TypeDefinition attr, List<BaseAction<T>> actions, LocalDefinition? local)
		{
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0347: Unknown result type (might be due to invalid IL or missing references)
			//IL_0335: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0417: Unknown result type (might be due to invalid IL or missing references)
			BaseKeyFunctionAddresses keyFunctionAddresses2 = keyFunctionAddresses;
			LocalDefinition local2 = local;
			if (typeof(T) != typeof(Instruction))
			{
				return null;
			}
			List<(MethodDefinition, FieldToParameterMapping[])> list = (from f in TypeDefinitionRocks.GetConstructors(attr)
				where !f.IsStatic
				select f into c
				select (c, TryAnalyzeAttributeConstructorToResolveFieldWrites(c, keyFunctionAddresses2)) into pair
				where pair.Item2 != null
				select pair).ToList();
			List<AbstractFieldWriteAction<T>> source = actions.Where((BaseAction<T> a) => a is AbstractFieldWriteAction<T> abstractFieldWriteAction2 && abstractFieldWriteAction2.InstanceBeingSetOn == local2).Cast<AbstractFieldWriteAction<T>>().ToList();
			if (source.Any((AbstractFieldWriteAction<T> w) => w.FieldWritten?.FinalLoadInChain == null))
			{
				return null;
			}
			Extensions.SortByExtractedKey<(MethodDefinition, FieldToParameterMapping[]), int>(list, (Func<(MethodDefinition, FieldToParameterMapping[]), int>)(((MethodDefinition, FieldToParameterMapping[]) pair) => pair.Item2.Length));
			list.Reverse();
			foreach (var (val, array) in list)
			{
				if (array == null || !(from w in source.Take(array.Length)
					select w.FieldWritten.FinalLoadInChain).SequenceEqual<FieldDefinition>(array.Select((FieldToParameterMapping m) => m.Field)))
				{
					continue;
				}
				List<CustomAttributeArgument> list2 = new List<CustomAttributeArgument>();
				Enumerator<ParameterDefinition> enumerator2 = ((MethodReference)val).Parameters.GetEnumerator();
				try
				{
					while (enumerator2.MoveNext())
					{
						ParameterDefinition parameter = enumerator2.Current;
						FieldToParameterMapping mapping = array.FirstOrDefault((FieldToParameterMapping m) => m.Parameter == parameter);
						if (mapping.Parameter == null)
						{
							return null;
						}
						AbstractFieldWriteAction<T> abstractFieldWriteAction = source.FirstOrDefault((AbstractFieldWriteAction<T> w) => w.FieldWritten.FinalLoadInChain == mapping.Field);
						if (abstractFieldWriteAction == null)
						{
							return null;
						}
						TypeDefinition obj = ((ParameterReference)parameter).ParameterType.Resolve();
						TypeReference val2 = ((obj != null && obj.IsEnum) ? TypeDefinitionRocks.GetEnumUnderlyingType(((ParameterReference)parameter).ParameterType.Resolve()) : ((ParameterReference)parameter).ParameterType);
						if (!(abstractFieldWriteAction is ImmediateToFieldAction immediateToFieldAction))
						{
							if (!(abstractFieldWriteAction is Arm64ImmediateToFieldAction arm64ImmediateToFieldAction))
							{
								if (abstractFieldWriteAction is RegToFieldAction regToFieldAction)
								{
									if (regToFieldAction.SourceOperand != null)
									{
										list2.Add(CoerceAnalyzedOpToType(regToFieldAction.SourceOperand, ((ParameterReference)parameter).ParameterType));
										continue;
									}
								}
								else if (abstractFieldWriteAction is Arm64RegisterToFieldAction arm64RegisterToFieldAction && arm64RegisterToFieldAction.SourceOperand != null)
								{
									list2.Add(CoerceAnalyzedOpToType(arm64RegisterToFieldAction.SourceOperand, ((ParameterReference)parameter).ParameterType));
									continue;
								}
								return null;
							}
							object obj2 = arm64ImmediateToFieldAction.ImmValue;
							if (obj2.GetType().FullName != ((MemberReference)val2).FullName)
							{
								obj2 = AnalysisUtils.CoerceValue(obj2, val2);
							}
							if (((MemberReference)val2).FullName == "System.Object")
							{
								obj2 = (object)new CustomAttributeArgument((TypeReference)(object)MiscUtils.TryLookupTypeDefKnownNotGeneric(arm64ImmediateToFieldAction.ImmValue.GetType().FullName), (object)arm64ImmediateToFieldAction.ImmValue);
							}
							list2.Add(new CustomAttributeArgument(val2, obj2));
						}
						else
						{
							object obj3 = immediateToFieldAction.ConstantValue;
							if (obj3.GetType().FullName != ((MemberReference)val2).FullName)
							{
								obj3 = AnalysisUtils.CoerceValue(obj3, val2);
							}
							if (((MemberReference)val2).FullName == "System.Object")
							{
								obj3 = (object)new CustomAttributeArgument((TypeReference)(object)MiscUtils.TryLookupTypeDefKnownNotGeneric(immediateToFieldAction.ConstantValue.GetType().FullName), immediateToFieldAction.ConstantValue);
							}
							list2.Add(new CustomAttributeArgument(val2, obj3));
						}
					}
				}
				finally
				{
					((IDisposable)enumerator2).Dispose();
				}
				return (val, list2);
			}
			return null;
		}

		private static CustomAttribute GenerateCustomAttributeFromHardWayResult(MethodDefinition constructor, List<CustomAttributeArgument> constructorArgs, ModuleDefinition module)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Expected O, but got Unknown
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			CustomAttribute val = new CustomAttribute(module.ImportReference((MethodReference)(object)constructor));
			if (constructorArgs.Count == 0)
			{
				return val;
			}
			if (((MethodReference)constructor).Parameters.Count != constructorArgs.Count)
			{
				throw new Exception("Mismatch between constructor param count & actual args count? Probably because named args support not implemented");
			}
			foreach (CustomAttributeArgument constructorArg in constructorArgs)
			{
				val.ConstructorArguments.Add(constructorArg);
			}
			return val;
		}

		private static Dictionary<FieldDefinition, PropertyDefinition> GetSimplePropertyFieldMappings<T>(TypeDefinition type, BaseKeyFunctionAddresses keyFunctionAddresses)
		{
			if (_simpleFieldToPropertyCache.TryGetValue(type, out Dictionary<FieldDefinition, PropertyDefinition> value))
			{
				return value;
			}
			value = new Dictionary<FieldDefinition, PropertyDefinition>();
			foreach (PropertyDefinition item in ((IEnumerable<PropertyDefinition>)type.Properties).Where((PropertyDefinition p) => p.SetMethod != null))
			{
				AsmAnalyzerBase<T> asmAnalyzerBase = AnalyzeProperty<T>(item, keyFunctionAddresses);
				if (asmAnalyzerBase.Analysis.Actions.Count((BaseAction<T> a) => a.IsImportant()) <= 2 && asmAnalyzerBase.Analysis.Actions[0] is AbstractFieldWriteFromVariableAction<T> abstractFieldWriteFromVariableAction && !(abstractFieldWriteFromVariableAction.FieldWritten == null) && abstractFieldWriteFromVariableAction.InstanceBeingSetOn?.ParameterDefinition != null && abstractFieldWriteFromVariableAction.SourceOperand is LocalDefinition localDefinition && localDefinition.ParameterDefinition != null)
				{
					FieldUtils.FieldBeingAccessedData last = abstractFieldWriteFromVariableAction.FieldWritten.GetLast();
					value[last.FinalLoadInChain] = item;
				}
			}
			_simpleFieldToPropertyCache[type] = value;
			return value;
		}

		private static AsmAnalyzerBase<T> AnalyzeProperty<T>(PropertyDefinition propertyDefinition, BaseKeyFunctionAddresses keyFunctionAddresses)
		{
			//IL_0014: 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_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Invalid comparison between Unknown and I4
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Invalid comparison between Unknown and I4
			InstructionSet? val = LibCpp2IlMain.Binary?.InstructionSet;
			if (val.HasValue)
			{
				InstructionSet valueOrDefault = val.GetValueOrDefault();
				object obj;
				if ((int)valueOrDefault > 1)
				{
					if ((int)valueOrDefault != 3)
					{
						goto IL_0058;
					}
					obj = new AsmAnalyzerArmV8A(propertyDefinition.SetMethod, keyFunctionAddresses);
				}
				else
				{
					obj = new AsmAnalyzerX86(propertyDefinition.SetMethod, keyFunctionAddresses);
				}
				AsmAnalyzerBase<T> obj2 = (AsmAnalyzerBase<T>)obj;
				obj2.AnalyzeMethod();
				return obj2;
			}
			goto IL_0058;
			IL_0058:
			throw new UnsupportedInstructionSetException();
		}
	}
	public static class AttributeRestorerPost29
	{
		internal static void ApplyCustomAttributesToAllTypesInAssembly(AssemblyDefinition assemblyDefinition)
		{
			Il2CppImageDefinition imageDef = SharedState.ManagedToUnmanagedAssemblies[assemblyDefinition];
			foreach (TypeDefinition item in ((IEnumerable<TypeDefinition>)assemblyDefinition.MainModule.Types).Where((TypeDefinition t) => ((TypeReference)t).Namespace != "Cpp2IlInjected"))
			{
				RestoreAttributesInType(imageDef, item);
			}
		}

		private static void RestoreAttributesInType(Il2CppImageDefinition imageDef, TypeDefinition typeDefinition)
		{
			//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
			TypeDefinition typeDefinition2 = typeDefinition;
			Il2CppTypeDefinition val = SharedState.ManagedToUnmanagedTypes[typeDefinition2];
			GetCustomAttributesByAttributeIndex(imageDef, ((

BepInExPack/BepInEx/core/Gee.External.Capstone.dll

Decompiled a month 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 Gee.External.Capstone.Arm;
using Gee.External.Capstone.Arm64;
using Gee.External.Capstone.M68K;
using Gee.External.Capstone.Mips;
using Gee.External.Capstone.PowerPc;
using Gee.External.Capstone.X86;
using Gee.External.Capstone.XCore;
using Microsoft.Win32.SafeHandles;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("Ahmed Garhy (@9ee1)")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyCopyright("Copyright (c) Ahmed Garhy")]
[assembly: AssemblyDescription("Capstone.NET is a .NET Core and a .NET Framework binding for the Capstone disassembly framework. It is written in C#, supports Capstone 4, and has a friendly and simple type safe API that is ridiculously easy to learn and quick to pick up.")]
[assembly: AssemblyFileVersion("2.1.0.0")]
[assembly: AssemblyInformationalVersion("2.1.0")]
[assembly: AssemblyProduct("Gee.External.Capstone")]
[assembly: AssemblyTitle("Gee.External.Capstone")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/js6pak/Capstone.NET")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("2.1.0.0")]
[module: UnverifiableCode]
namespace Gee.External.Capstone
{
	public abstract class CapstoneDisassembler : IDisposable
	{
		public static bool IsArm64Supported => NativeCapstone.Query(NativeQueryOption.QueryArm64Architecture);

		public static bool IsArmSupported => NativeCapstone.Query(NativeQueryOption.QueryArmArchitecture);

		public static bool IsDietModeEnabled => NativeCapstone.Query(NativeQueryOption.QueryDietMode);

		internal static bool IsEvmSupported => NativeCapstone.Query(NativeQueryOption.QueryEvmArchitecture);

		internal static bool IsM680XSupported => NativeCapstone.Query(NativeQueryOption.QueryM680XArchitecture);

		public static bool IsM68KSupported => NativeCapstone.Query(NativeQueryOption.QueryM68KArchitecture);

		public static bool IsMipsSupported => NativeCapstone.Query(NativeQueryOption.QueryMipsArchitecture);

		public static bool IsPowerPcSupported => NativeCapstone.Query(NativeQueryOption.QueryPowerPcArchitecture);

		internal static bool IsSparcSupported => NativeCapstone.Query(NativeQueryOption.QuerySparcArchitecture);

		internal static bool IsSystemZSupported => NativeCapstone.Query(NativeQueryOption.QuerySystemZArchitecture);

		internal static bool IsTms320C64XSupported => NativeCapstone.Query(NativeQueryOption.QueryTms320C64XArchitecture);

		public static bool IsX86ReduceModeEnabled => NativeCapstone.Query(NativeQueryOption.QueryX86ReduceMode);

		public static bool IsX86Supported => NativeCapstone.Query(NativeQueryOption.QueryX86Architecture);

		public static bool IsXCoreSupported => NativeCapstone.Query(NativeQueryOption.QueryXCoreArchitecture);

		public static Version Version => NativeCapstone.GetVersion();

		public abstract DisassembleArchitecture DisassembleArchitecture { get; }

		public abstract bool EnableInstructionDetails { get; set; }

		public abstract bool EnableSkipDataMode { get; set; }

		internal abstract NativeDisassemblerHandle Handle { get; }

		internal abstract NativeDisassembleMode NativeDisassembleMode { get; }

		public abstract string SkipDataInstructionMnemonic { get; set; }

		public static CapstoneArm64Disassembler CreateArm64Disassembler(Arm64DisassembleMode disassembleMode)
		{
			return new CapstoneArm64Disassembler(disassembleMode);
		}

		public static CapstoneArmDisassembler CreateArmDisassembler(ArmDisassembleMode disassembleMode)
		{
			return new CapstoneArmDisassembler(disassembleMode);
		}

		public static CapstoneM68KDisassembler CreateM68KDisassembler(M68KDisassembleMode disassembleMode)
		{
			return new CapstoneM68KDisassembler(disassembleMode);
		}

		public static CapstoneMipsDisassembler CreateMipsDisassembler(MipsDisassembleMode disassembleMode)
		{
			return new CapstoneMipsDisassembler(disassembleMode);
		}

		public static CapstonePowerPcDisassembler CreatePowerPcDisassembler(PowerPcDisassembleMode disassembleMode)
		{
			return new CapstonePowerPcDisassembler(disassembleMode);
		}

		public static CapstoneX86Disassembler CreateX86Disassembler(X86DisassembleMode disassembleMode)
		{
			return new CapstoneX86Disassembler(disassembleMode);
		}

		public static CapstoneXCoreDisassembler CreateXCoreDisassembler(XCoreDisassembleMode disassembleMode)
		{
			return new CapstoneXCoreDisassembler(disassembleMode);
		}

		internal static void ThrowIfDietModeIsEnabled()
		{
			if (IsDietModeEnabled)
			{
				throw new NotSupportedException("An operation is not supported when Diet Mode is enabled.");
			}
		}

		internal static void ThrowIfValueIsNullReference<T>(string name, T value) where T : class
		{
			if (value == null)
			{
				throw new ArgumentNullException(name, "A value cannot be a null reference.");
			}
		}

		public abstract void Dispose();
	}
	public abstract class CapstoneDisassembler<TDisassembleMode, TInstruction, TInstructionDetail, TInstructionGroup, TInstructionGroupId, TInstructionId, TRegister, TRegisterId> : CapstoneDisassembler where TDisassembleMode : Enum where TInstruction : Instruction<TInstruction, TInstructionDetail, TDisassembleMode, TInstructionGroup, TInstructionGroupId, TInstructionId, TRegister, TRegisterId> where TInstructionDetail : InstructionDetail<TInstructionDetail, TDisassembleMode, TInstructionGroup, TInstructionGroupId, TInstruction, TInstructionId, TRegister, TRegisterId> where TInstructionGroup : InstructionGroup<TInstructionGroupId> where TInstructionGroupId : Enum where TInstructionId : Enum where TRegister : Register<TRegisterId> where TRegisterId : Enum
	{
		private readonly DisassembleArchitecture _disassembleArchitecture;

		private TDisassembleMode _disassembleMode;

		private DisassembleSyntax _disassembleSyntax;

		private bool _enableInstructionDetails;

		private bool _enableSkipDataMode;

		private readonly NativeDisassemblerHandle _handle;

		private NativeDisassembleMode _nativeDisassembleMode;

		private Func<byte[], long, long> _skipDataCallback;

		private string _skipDataInstructionMnemonic;

		public override DisassembleArchitecture DisassembleArchitecture => _disassembleArchitecture;

		public TDisassembleMode DisassembleMode
		{
			get
			{
				return _disassembleMode;
			}
			set
			{
				int num = Convert.ToInt32(value);
				NativeDisassembleMode nativeDisassembleMode = (NativeDisassembleMode)num;
				NativeCapstone.SetDisassembleModeOption(_handle, nativeDisassembleMode);
				_disassembleMode = value;
				_nativeDisassembleMode = nativeDisassembleMode;
			}
		}

		public DisassembleSyntax DisassembleSyntax
		{
			get
			{
				return _disassembleSyntax;
			}
			set
			{
				NativeCapstone.SetDisassemblerOption(_handle, NativeDisassemblerOptionType.SetSyntax, (NativeDisassemblerOptionValue)value);
				_disassembleSyntax = value;
			}
		}

		public override bool EnableInstructionDetails
		{
			get
			{
				return _enableInstructionDetails;
			}
			set
			{
				NativeDisassemblerOptionValue optionValue = (value ? NativeDisassemblerOptionValue.Enable : NativeDisassemblerOptionValue.Disable);
				NativeCapstone.SetDisassemblerOption(_handle, NativeDisassemblerOptionType.SetInstructionDetails, optionValue);
				_enableInstructionDetails = value;
			}
		}

		public override bool EnableSkipDataMode
		{
			get
			{
				return _enableSkipDataMode;
			}
			set
			{
				NativeDisassemblerOptionValue optionValue = (value ? NativeDisassemblerOptionValue.Enable : NativeDisassemblerOptionValue.Disable);
				NativeCapstone.SetDisassemblerOption(_handle, NativeDisassemblerOptionType.SetSkipData, optionValue);
				_enableSkipDataMode = value;
			}
		}

		internal override NativeDisassemblerHandle Handle => _handle;

		internal override NativeDisassembleMode NativeDisassembleMode => _nativeDisassembleMode;

		public Func<byte[], long, long> SkipDataCallback
		{
			get
			{
				return _skipDataCallback;
			}
			set
			{
				ThrowIfDisassemblerIsDisposed();
				_skipDataCallback = value;
			}
		}

		public override string SkipDataInstructionMnemonic
		{
			get
			{
				return _skipDataInstructionMnemonic;
			}
			set
			{
				ThrowIfDisassemblerIsDisposed();
				CapstoneDisassembler.ThrowIfValueIsNullReference("SkipDataInstructionMnemonic", value);
				_skipDataInstructionMnemonic = value;
			}
		}

		private protected CapstoneDisassembler(DisassembleArchitecture disassembleArchitecture, TDisassembleMode disassembleMode)
		{
			_disassembleArchitecture = disassembleArchitecture;
			_disassembleMode = disassembleMode;
			_disassembleSyntax = DisassembleSyntax.Intel;
			_skipDataInstructionMnemonic = ".byte";
			_nativeDisassembleMode = CreateNativeDisassembleMode(this);
			_handle = NativeCapstone.CreateDisassembler(_disassembleArchitecture, _nativeDisassembleMode);
			static NativeDisassembleMode CreateNativeDisassembleMode(CapstoneDisassembler<TDisassembleMode, TInstruction, TInstructionDetail, TInstructionGroup, TInstructionGroupId, TInstructionId, TRegister, TRegisterId> @this)
			{
				return (NativeDisassembleMode)Convert.ToInt32(@this._disassembleMode);
			}
		}

		private protected abstract TInstruction CreateInstruction(NativeInstructionHandle hInstruction);

		public TInstruction[] Disassemble(byte[] binaryCode)
		{
			return Disassemble(binaryCode, 4096L);
		}

		public TInstruction[] Disassemble(byte[] binaryCode, long startingAddress)
		{
			return Disassemble(binaryCode, startingAddress, 0);
		}

		public TInstruction[] Disassemble(byte[] binaryCode, long startingAddress, int count)
		{
			IEnumerable<TInstruction> source = Iterate(binaryCode, startingAddress);
			if (count != 0)
			{
				source = source.Skip(0).Take(count);
			}
			return source.ToArray();
		}

		public override void Dispose()
		{
			_handle.Dispose();
		}

		public string GetInstructionGroupName(TInstructionGroupId instructionGroupId)
		{
			ThrowIfDisassemblerIsDisposed();
			CapstoneDisassembler.ThrowIfDietModeIsEnabled();
			int instructionGroupId2 = Convert.ToInt32(instructionGroupId);
			string instructionGroupName = NativeCapstone.GetInstructionGroupName(_handle, instructionGroupId2);
			if (instructionGroupName == null)
			{
				throw new ArgumentException("An instruction group unique identifier is invalid.", "instructionGroupId");
			}
			return instructionGroupName;
		}

		public string GetRegisterName(TRegisterId registerId)
		{
			ThrowIfDisassemblerIsDisposed();
			CapstoneDisassembler.ThrowIfDietModeIsEnabled();
			int registerId2 = Convert.ToInt32(registerId);
			string registerName = NativeCapstone.GetRegisterName(_handle, registerId2);
			if (registerName == null)
			{
				throw new ArgumentException("A register unique identifier is invalid.", "registerId");
			}
			return registerName;
		}

		public IEnumerable<TInstruction> Iterate(byte[] binaryCode)
		{
			return Iterate(binaryCode, 4096L);
		}

		public IEnumerable<TInstruction> Iterate(byte[] binaryCode, long startingAddress)
		{
			CapstoneDisassembler.ThrowIfValueIsNullReference("binaryCode", binaryCode);
			int binaryCodeOffset = 0;
			NativeCapstone.SkipDataCallback callback = null;
			if (EnableSkipDataMode)
			{
				if (_skipDataCallback != null)
				{
					callback = OnNativeSkipDataCallback;
				}
				NativeSkipDataOptionValue optionValue2 = default(NativeSkipDataOptionValue);
				optionValue2.Callback = callback;
				optionValue2.InstructionMnemonic = _skipDataInstructionMnemonic;
				optionValue2.State = IntPtr.Zero;
				NativeCapstone.SetSkipDataOption(_handle, ref optionValue2);
			}
			try
			{
				using NativeInstructionHandle hInstruction = NativeCapstone.CreateInstruction(_handle);
				while (binaryCodeOffset < binaryCode.Length)
				{
					if (NativeCapstone.Iterate(_handle, binaryCode, ref binaryCodeOffset, ref startingAddress, hInstruction))
					{
						yield return CreateInstruction(hInstruction);
						continue;
					}
					yield break;
				}
			}
			finally
			{
				if (callback != null)
				{
					NativeSkipDataOptionValue optionValue = default(NativeSkipDataOptionValue);
					optionValue.Callback = null;
					optionValue.InstructionMnemonic = _skipDataInstructionMnemonic;
					optionValue.State = IntPtr.Zero;
					NativeCapstone.SetSkipDataOption(_handle, ref optionValue);
				}
			}
			IntPtr OnNativeSkipDataCallback(IntPtr cPBinaryCode, IntPtr cBinaryCodeSize, IntPtr cDataOffset, IntPtr pState)
			{
				long value = SkipDataCallback(binaryCode, binaryCodeOffset);
				return new IntPtr(value);
			}
		}

		public void ResetInstructionMnemonic(TInstructionId instructionId)
		{
			int instructionId2 = Convert.ToInt32(instructionId);
			NativeInstructionMnemonicOptionValue nativeInstructionMnemonicOptionValue = default(NativeInstructionMnemonicOptionValue);
			nativeInstructionMnemonicOptionValue.InstructionId = instructionId2;
			nativeInstructionMnemonicOptionValue.InstructionMnemonic = null;
			NativeInstructionMnemonicOptionValue optionValue = nativeInstructionMnemonicOptionValue;
			NativeCapstone.SetInstructionMnemonicOption(_handle, ref optionValue);
		}

		public void SetInstructionMnemonic(TInstructionId instructionId, string instructionMnemonic)
		{
			CapstoneDisassembler.ThrowIfValueIsNullReference("instructionMnemonic", instructionMnemonic);
			int instructionId2 = Convert.ToInt32(instructionId);
			NativeInstructionMnemonicOptionValue nativeInstructionMnemonicOptionValue = default(NativeInstructionMnemonicOptionValue);
			nativeInstructionMnemonicOptionValue.InstructionId = instructionId2;
			nativeInstructionMnemonicOptionValue.InstructionMnemonic = instructionMnemonic;
			NativeInstructionMnemonicOptionValue optionValue = nativeInstructionMnemonicOptionValue;
			NativeCapstone.SetInstructionMnemonicOption(_handle, ref optionValue);
		}

		private void ThrowIfDisassemblerIsDisposed()
		{
			if (_handle.IsClosed)
			{
				throw new ObjectDisposedException("CapstoneDisassembler", "A disassembler is disposed.");
			}
		}
	}
	public sealed class CapstoneException : Exception
	{
		internal CapstoneException(string detailMessage)
			: base(detailMessage)
		{
		}

		internal CapstoneException(string detailMessage, Exception innerException)
			: base(detailMessage, innerException)
		{
		}
	}
	public enum DisassembleArchitecture
	{
		Arm,
		Arm64,
		Mips,
		X86,
		PowerPc,
		Sparc,
		SystemZ,
		XCore,
		M68K,
		Tms320C64X,
		M680X,
		Evm
	}
	public enum DisassembleSyntax
	{
		Att = 2,
		Intel = 1,
		Masm = 4
	}
	public abstract class Instruction<TSelf, TDetail, TDisassembleMode, TGroup, TGroupId, TId, TRegister, TRegisterId> where TSelf : Instruction<TSelf, TDetail, TDisassembleMode, TGroup, TGroupId, TId, TRegister, TRegisterId> where TDetail : InstructionDetail<TDetail, TDisassembleMode, TGroup, TGroupId, TSelf, TId, TRegister, TRegisterId> where TDisassembleMode : Enum where TGroup : InstructionGroup<TGroupId> where TGroupId : Enum where TId : Enum where TRegister : Register<TRegisterId> where TRegisterId : Enum
	{
		private readonly TDetail _details;

		private readonly string _mnemonic;

		private readonly string _operand;

		public long Address { get; }

		public byte[] Bytes { get; }

		public TDetail Details
		{
			get
			{
				if (_details == null)
				{
					throw new InvalidOperationException("An operation is invalid.");
				}
				return _details;
			}
		}

		public DisassembleArchitecture DisassembleArchitecture { get; }

		public TDisassembleMode DisassembleMode { get; }

		public bool HasDetails => _details != null;

		public TId Id { get; }

		public bool IsDietModeEnabled => CapstoneDisassembler.IsDietModeEnabled;

		public bool IsSkippedData { get; }

		public string Mnemonic
		{
			get
			{
				CapstoneDisassembler.ThrowIfDietModeIsEnabled();
				return _mnemonic;
			}
		}

		public string Operand
		{
			get
			{
				CapstoneDisassembler.ThrowIfDietModeIsEnabled();
				return _operand;
			}
		}

		private protected Instruction(InstructionBuilder<TDetail, TDisassembleMode, TGroup, TGroupId, TSelf, TId, TRegister, TRegisterId> builder)
		{
			Address = builder.Address;
			Bytes = builder.Bytes;
			_details = builder.Details;
			DisassembleArchitecture = builder.DisassembleArchitecture;
			DisassembleMode = builder.DisassembleMode;
			Id = builder.Id;
			IsSkippedData = builder.IsSkippedData;
			_mnemonic = builder.Mnemonic;
			_operand = builder.Operand;
		}
	}
	internal abstract class InstructionBuilder<TDetail, TDisassembleMode, TGroup, TGroupId, TInstruction, TId, TRegister, TRegisterId> where TDetail : InstructionDetail<TDetail, TDisassembleMode, TGroup, TGroupId, TInstruction, TId, TRegister, TRegisterId> where TDisassembleMode : Enum where TGroup : InstructionGroup<TGroupId> where TGroupId : Enum where TInstruction : Instruction<TInstruction, TDetail, TDisassembleMode, TGroup, TGroupId, TId, TRegister, TRegisterId> where TId : Enum where TRegister : Register<TRegisterId> where TRegisterId : Enum
	{
		internal long Address { get; private set; }

		internal byte[] Bytes { get; private set; }

		internal TDetail Details { get; private set; }

		internal DisassembleArchitecture DisassembleArchitecture { get; private set; }

		internal TDisassembleMode DisassembleMode { get; private set; }

		internal TId Id { get; private set; }

		internal bool IsSkippedData { get; private set; }

		internal string Mnemonic { get; private set; }

		internal string Operand { get; private set; }

		internal InstructionBuilder()
		{
			Address = 0L;
			Bytes = new byte[0];
			Details = null;
			Id = default(TId);
			IsSkippedData = false;
			Mnemonic = null;
			Operand = null;
		}

		internal virtual void Build(CapstoneDisassembler disassembler, NativeInstructionHandle hInstruction)
		{
			NativeInstruction cNativeInstruction2 = NativeCapstone.GetInstruction(hInstruction);
			Address = cNativeInstruction2.Address;
			DisassembleArchitecture = disassembler.DisassembleArchitecture;
			DisassembleMode = CreateDisassembleMode(disassembler.NativeDisassembleMode);
			Id = CreateId(cNativeInstruction2.Id);
			IsSkippedData = disassembler.EnableSkipDataMode && cNativeInstruction2.Id <= 0;
			Mnemonic = ((!CapstoneDisassembler.IsDietModeEnabled) ? cNativeInstruction2.Mnemonic : null);
			Operand = ((!CapstoneDisassembler.IsDietModeEnabled) ? cNativeInstruction2.Operand : null);
			SetBytes(this, ref cNativeInstruction2);
			SetDetails(this, disassembler, hInstruction, ref cNativeInstruction2);
			static void SetBytes(InstructionBuilder<TDetail, TDisassembleMode, TGroup, TGroupId, TInstruction, TId, TRegister, TRegisterId> @this, ref NativeInstruction cNativeInstruction)
			{
				@this.Bytes = new byte[0];
				if (cNativeInstruction.Id >= 0)
				{
					@this.Bytes = new byte[cNativeInstruction.Size];
					for (int i = 0; i < @this.Bytes.Length; i++)
					{
						@this.Bytes[i] = cNativeInstruction.Bytes[i];
					}
				}
			}
			static void SetDetails(InstructionBuilder<TDetail, TDisassembleMode, TGroup, TGroupId, TInstruction, TId, TRegister, TRegisterId> @this, CapstoneDisassembler cDisassembler, NativeInstructionHandle cHInstruction, ref NativeInstruction cNativeInstruction)
			{
				bool flag = cNativeInstruction.Details != IntPtr.Zero;
				bool enableInstructionDetails = cDisassembler.EnableInstructionDetails;
				@this.Details = null;
				if (flag && enableInstructionDetails && cNativeInstruction.Id > 0)
				{
					@this.Details = @this.CreateDetails(cDisassembler, cHInstruction);
				}
			}
		}

		private protected abstract TDetail CreateDetails(CapstoneDisassembler disassembler, NativeInstructionHandle hInstruction);

		private protected abstract TDisassembleMode CreateDisassembleMode(NativeDisassembleMode nativeDisassembleMode);

		private protected abstract TId CreateId(int id);
	}
	public abstract class InstructionDetail<TSelf, TDisassembleMode, TGroup, TGroupId, TInstruction, TInstructionId, TRegister, TRegisterId> where TSelf : InstructionDetail<TSelf, TDisassembleMode, TGroup, TGroupId, TInstruction, TInstructionId, TRegister, TRegisterId> where TDisassembleMode : Enum where TGroup : InstructionGroup<TGroupId> where TGroupId : Enum where TInstruction : Instruction<TInstruction, TSelf, TDisassembleMode, TGroup, TGroupId, TInstructionId, TRegister, TRegisterId> where TInstructionId : Enum where TRegister : Register<TRegisterId> where TRegisterId : Enum
	{
		private readonly TRegister[] _allReadRegisters;

		private readonly TRegister[] _allWrittenRegisters;

		private readonly Lazy<TRegister[]> _explicitlyReadRegisters;

		private readonly Lazy<TRegister[]> _explicitlyWrittenRegisters;

		private readonly TGroup[] _groups;

		private readonly TRegister[] _implicitlyReadRegisters;

		private readonly TRegister[] _implicitlyWrittenRegisters;

		public TRegister[] AllReadRegisters
		{
			get
			{
				CapstoneDisassembler.ThrowIfDietModeIsEnabled();
				if (IsDisassembleArchitectureUnsupported())
				{
					throw new NotSupportedException("An operation is unsupported.");
				}
				return _allReadRegisters;
			}
		}

		public TRegister[] AllWrittenRegisters
		{
			get
			{
				CapstoneDisassembler.ThrowIfDietModeIsEnabled();
				if (IsDisassembleArchitectureUnsupported())
				{
					throw new NotSupportedException("An operation is unsupported.");
				}
				return _allWrittenRegisters;
			}
		}

		public DisassembleArchitecture DisassembleArchitecture { get; }

		public TDisassembleMode DisassembleMode { get; }

		public TRegister[] ExplicitlyReadRegisters
		{
			get
			{
				CapstoneDisassembler.ThrowIfDietModeIsEnabled();
				if (IsDisassembleArchitectureUnsupported())
				{
					throw new NotSupportedException("An operation is unsupported.");
				}
				return _explicitlyReadRegisters.Value;
			}
		}

		public TRegister[] ExplicitlyWrittenRegisters
		{
			get
			{
				CapstoneDisassembler.ThrowIfDietModeIsEnabled();
				if (IsDisassembleArchitectureUnsupported())
				{
					throw new NotSupportedException("An operation is unsupported.");
				}
				return _explicitlyWrittenRegisters.Value;
			}
		}

		public TGroup[] Groups
		{
			get
			{
				CapstoneDisassembler.ThrowIfDietModeIsEnabled();
				return _groups;
			}
		}

		public TRegister[] ImplicitlyReadRegisters
		{
			get
			{
				CapstoneDisassembler.ThrowIfDietModeIsEnabled();
				return _implicitlyReadRegisters;
			}
		}

		public TRegister[] ImplicitlyWrittenRegisters
		{
			get
			{
				CapstoneDisassembler.ThrowIfDietModeIsEnabled();
				return _implicitlyWrittenRegisters;
			}
		}

		public bool IsDietModeEnabled => CapstoneDisassembler.IsDietModeEnabled;

		private protected InstructionDetail(InstructionDetailBuilder<TSelf, TDisassembleMode, TGroup, TGroupId, TInstruction, TInstructionId, TRegister, TRegisterId> builder)
		{
			_allReadRegisters = builder.AllReadRegisters;
			_allWrittenRegisters = builder.AllWrittenRegisters;
			DisassembleArchitecture = builder.DisassembleArchitecture;
			DisassembleMode = builder.DisassembleMode;
			_explicitlyReadRegisters = new Lazy<TRegister[]>(OnExplicitlyReadRegistersLazyInitialization);
			_explicitlyWrittenRegisters = new Lazy<TRegister[]>(OnExplicitlyWrittenRegistersLazyInitialization);
			_groups = builder.Groups;
			_implicitlyReadRegisters = builder.ImplicitlyReadRegisters;
			_implicitlyWrittenRegisters = builder.ImplicitlyWrittenRegisters;
		}

		public bool BelongsToGroup(string instructionGroupName)
		{
			return Groups.Any((TGroup g) => g.Name == instructionGroupName);
		}

		public bool BelongsToGroup(TGroupId instructionGroupId)
		{
			return Groups.Any((TGroup g) => g.Id.Equals(instructionGroupId));
		}

		private bool IsDisassembleArchitectureUnsupported()
		{
			return DisassembleArchitecture == DisassembleArchitecture.M68K || DisassembleArchitecture == DisassembleArchitecture.Mips || DisassembleArchitecture == DisassembleArchitecture.PowerPc || DisassembleArchitecture == DisassembleArchitecture.XCore;
		}

		public bool IsRegisterExplicitlyRead(string registerName)
		{
			return ExplicitlyReadRegisters.Any((TRegister r) => r.Name == registerName);
		}

		public bool IsRegisterExplicitlyRead(TRegisterId registerId)
		{
			return ExplicitlyReadRegisters.Any((TRegister r) => r.Id.Equals(registerId));
		}

		public bool IsRegisterExplicitlyWritten(string registerName)
		{
			return ExplicitlyWrittenRegisters.Any((TRegister r) => r.Name == registerName);
		}

		public bool IsRegisterExplicitlyWritten(TRegisterId registerId)
		{
			return ExplicitlyWrittenRegisters.Any((TRegister r) => r.Id.Equals(registerId));
		}

		public bool IsRegisterImplicitlyRead(string registerName)
		{
			return ImplicitlyReadRegisters.Any((TRegister r) => r.Name == registerName);
		}

		public bool IsRegisterImplicitlyRead(TRegisterId registerId)
		{
			return ImplicitlyReadRegisters.Any((TRegister r) => r.Id.Equals(registerId));
		}

		public bool IsRegisterImplicitlyWritten(string registerName)
		{
			return ImplicitlyWrittenRegisters.Any((TRegister r) => r.Name == registerName);
		}

		public bool IsRegisterImplicitlyWritten(TRegisterId registerId)
		{
			return ImplicitlyWrittenRegisters.Any((TRegister r) => r.Id.Equals(registerId));
		}

		public bool IsRegisterRead(string registerName)
		{
			return IsDisassembleArchitectureUnsupported() ? ImplicitlyReadRegisters.Any((TRegister r) => r.Name == registerName) : AllReadRegisters.Any((TRegister r) => r.Name == registerName);
		}

		public bool IsRegisterRead(TRegisterId registerId)
		{
			return IsDisassembleArchitectureUnsupported() ? ImplicitlyReadRegisters.Any((TRegister r) => r.Id.Equals(registerId)) : AllReadRegisters.Any((TRegister r) => r.Id.Equals(registerId));
		}

		public bool IsRegisterWritten(string registerName)
		{
			return IsDisassembleArchitectureUnsupported() ? ImplicitlyWrittenRegisters.Any((TRegister r) => r.Name == registerName) : AllWrittenRegisters.Any((TRegister r) => r.Name == registerName);
		}

		public bool IsRegisterWritten(TRegisterId registerId)
		{
			return IsDisassembleArchitectureUnsupported() ? ImplicitlyWrittenRegisters.Any((TRegister r) => r.Id.Equals(registerId)) : AllWrittenRegisters.Any((TRegister r) => r.Id.Equals(registerId));
		}

		private TRegister[] OnExplicitlyReadRegistersLazyInitialization()
		{
			return _allReadRegisters.Except(_implicitlyReadRegisters).ToArray();
		}

		private TRegister[] OnExplicitlyWrittenRegistersLazyInitialization()
		{
			return _allWrittenRegisters.Except(_implicitlyWrittenRegisters).ToArray();
		}
	}
	internal abstract class InstructionDetailBuilder<TDetail, TDisassembleMode, TGroup, TGroupId, TInstruction, TInstructionId, TRegister, TRegisterId> where TDetail : InstructionDetail<TDetail, TDisassembleMode, TGroup, TGroupId, TInstruction, TInstructionId, TRegister, TRegisterId> where TDisassembleMode : Enum where TGroup : InstructionGroup<TGroupId> where TGroupId : Enum where TInstruction : Instruction<TInstruction, TDetail, TDisassembleMode, TGroup, TGroupId, TInstructionId, TRegister, TRegisterId> where TInstructionId : Enum where TRegister : Register<TRegisterId> where TRegisterId : Enum
	{
		internal TRegister[] AllReadRegisters { get; private set; }

		internal TRegister[] AllWrittenRegisters { get; private set; }

		internal DisassembleArchitecture DisassembleArchitecture { get; private set; }

		internal TDisassembleMode DisassembleMode { get; private set; }

		internal TGroup[] Groups { get; private set; }

		internal TRegister[] ImplicitlyReadRegisters { get; private set; }

		internal TRegister[] ImplicitlyWrittenRegisters { get; private set; }

		internal virtual void Build(CapstoneDisassembler disassembler, NativeInstructionHandle hInstruction)
		{
			NativeInstructionDetail cNativeInstructionDetail2 = NativeCapstone.GetInstructionDetail(hInstruction).GetValueOrDefault();
			DisassembleArchitecture = disassembler.DisassembleArchitecture;
			DisassembleMode = CreateDisassembleMode(disassembler.NativeDisassembleMode);
			SetAccessedRegisters(this, disassembler, hInstruction);
			SetGroups(this, disassembler, ref cNativeInstructionDetail2);
			SetImplicitlyReadRegisters(this, disassembler, ref cNativeInstructionDetail2);
			SetImplicitlyWrittenRegisters(this, disassembler, ref cNativeInstructionDetail2);
			static void SetAccessedRegisters(InstructionDetailBuilder<TDetail, TDisassembleMode, TGroup, TGroupId, TInstruction, TInstructionId, TRegister, TRegisterId> @this, CapstoneDisassembler cDisassembler, NativeInstructionHandle cHInstruction)
			{
				@this.AllReadRegisters = new TRegister[0];
				@this.AllWrittenRegisters = new TRegister[0];
				if (!CapstoneDisassembler.IsDietModeEnabled && cDisassembler.DisassembleArchitecture != DisassembleArchitecture.M68K && cDisassembler.DisassembleArchitecture != DisassembleArchitecture.Mips && cDisassembler.DisassembleArchitecture != DisassembleArchitecture.PowerPc && cDisassembler.DisassembleArchitecture != DisassembleArchitecture.XCore)
				{
					Tuple<short[], short[]> accessedRegisters = NativeCapstone.GetAccessedRegisters(cDisassembler.Handle, cHInstruction);
					@this.AllReadRegisters = new TRegister[accessedRegisters.Item1.Length];
					for (int l = 0; l < @this.AllReadRegisters.Length; l++)
					{
						short registerId3 = accessedRegisters.Item1[l];
						@this.AllReadRegisters[l] = @this.CreateRegister(cDisassembler, registerId3);
					}
					@this.AllWrittenRegisters = new TRegister[accessedRegisters.Item2.Length];
					for (int m = 0; m < @this.AllWrittenRegisters.Length; m++)
					{
						short registerId4 = accessedRegisters.Item2[m];
						@this.AllWrittenRegisters[m] = @this.CreateRegister(cDisassembler, registerId4);
					}
				}
			}
			static void SetGroups(InstructionDetailBuilder<TDetail, TDisassembleMode, TGroup, TGroupId, TInstruction, TInstructionId, TRegister, TRegisterId> @this, CapstoneDisassembler cDisassembler, ref NativeInstructionDetail cNativeInstructionDetail)
			{
				@this.Groups = new TGroup[cNativeInstructionDetail.GroupCount];
				if (!CapstoneDisassembler.IsDietModeEnabled)
				{
					for (int k = 0; k < @this.Groups.Length; k++)
					{
						byte instructionGroupId = cNativeInstructionDetail.Groups[k];
						@this.Groups[k] = @this.CreateInstructionGroup(cDisassembler, instructionGroupId);
					}
				}
			}
			static void SetImplicitlyReadRegisters(InstructionDetailBuilder<TDetail, TDisassembleMode, TGroup, TGroupId, TInstruction, TInstructionId, TRegister, TRegisterId> @this, CapstoneDisassembler cDisassembler, ref NativeInstructionDetail cNativeInstructionDetail)
			{
				@this.ImplicitlyReadRegisters = new TRegister[cNativeInstructionDetail.ImplicitlyReadRegisterCount];
				if (!CapstoneDisassembler.IsDietModeEnabled)
				{
					for (int j = 0; j < @this.ImplicitlyReadRegisters.Length; j++)
					{
						short registerId2 = cNativeInstructionDetail.ImplicitlyReadRegisters[j];
						@this.ImplicitlyReadRegisters[j] = @this.CreateRegister(cDisassembler, registerId2);
					}
				}
			}
			static void SetImplicitlyWrittenRegisters(InstructionDetailBuilder<TDetail, TDisassembleMode, TGroup, TGroupId, TInstruction, TInstructionId, TRegister, TRegisterId> @this, CapstoneDisassembler cDisassembler, ref NativeInstructionDetail cNativeInstructionDetail)
			{
				@this.ImplicitlyWrittenRegisters = new TRegister[cNativeInstructionDetail.ImplicitlyWrittenRegisterCount];
				if (!CapstoneDisassembler.IsDietModeEnabled)
				{
					for (int i = 0; i < @this.ImplicitlyWrittenRegisters.Length; i++)
					{
						short registerId = cNativeInstructionDetail.ImplicitlyWrittenRegisters[i];
						@this.ImplicitlyWrittenRegisters[i] = @this.CreateRegister(cDisassembler, registerId);
					}
				}
			}
		}

		private protected abstract TDisassembleMode CreateDisassembleMode(NativeDisassembleMode nativeDisassembleMode);

		private protected abstract TGroup CreateInstructionGroup(CapstoneDisassembler disassembler, byte instructionGroupId);

		private protected abstract TRegister CreateRegister(CapstoneDisassembler disassembler, short registerId);
	}
	public abstract class InstructionGroup<TId> where TId : Enum
	{
		private readonly string _name;

		public TId Id { get; }

		public bool IsDietModeEnabled => CapstoneDisassembler.IsDietModeEnabled;

		public string Name
		{
			get
			{
				CapstoneDisassembler.ThrowIfDietModeIsEnabled();
				return _name;
			}
		}

		private protected InstructionGroup(TId id, string name)
		{
			Id = id;
			_name = name;
		}

		public override bool Equals(object @object)
		{
			bool flag = @object != null;
			if (flag)
			{
				InstructionGroup<TId> instructionGroup = @object as InstructionGroup<TId>;
				flag = instructionGroup != null;
				if (flag)
				{
					flag = Id.Equals(instructionGroup.Id) && _name == instructionGroup._name;
				}
			}
			return flag;
		}

		public override int GetHashCode()
		{
			int num = 13;
			num = num * 7 + Id.GetHashCode();
			return (_name != null) ? (num * 7 + _name.GetHashCode()) : 0;
		}
	}
	internal static class MarshalExtension
	{
		internal static IntPtr AllocHGlobal<T>()
		{
			int cb = SizeOf<T>();
			return Marshal.AllocHGlobal(cb);
		}

		internal static IntPtr AllocHGlobal<T>(int size)
		{
			int cb = SizeOf<T>() * size;
			return Marshal.AllocHGlobal(cb);
		}

		internal static T FreePtrToStructure<T>(IntPtr p)
		{
			object obj = Marshal.PtrToStructure(p, typeof(T));
			Marshal.FreeHGlobal(p);
			return (T)obj;
		}

		internal static T PtrToStructure<T>(IntPtr p)
		{
			object obj = Marshal.PtrToStructure(p, typeof(T));
			return (T)obj;
		}

		internal static T[] PtrToStructure<T>(IntPtr p, int size)
		{
			T[] array = new T[size];
			IntPtr p2 = p;
			for (int i = 0; i < size; i++)
			{
				T val = PtrToStructure<T>(p2);
				array[i] = val;
				p2 += Marshal.SizeOf(typeof(T));
			}
			return array;
		}

		internal static int SizeOf<T>()
		{
			return Marshal.SizeOf(typeof(T));
		}
	}
	internal static class NativeCapstone
	{
		[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
		internal delegate IntPtr SkipDataCallback(IntPtr pBinaryCode, IntPtr binaryCodeSize, IntPtr dataOffset, IntPtr pState);

		private const int MagicInstructionArchitectureDetailsFieldOffset = 80;

		static NativeCapstone()
		{
		}

		internal static NativeDisassemblerHandle CreateDisassembler(DisassembleArchitecture disassembleArchitecture, NativeDisassembleMode disassembleMode)
		{
			IntPtr pDisassembler = IntPtr.Zero;
			switch (NativeCapstoneImport.CreateDisassembler(disassembleArchitecture, disassembleMode, ref pDisassembler))
			{
			case NativeCapstoneResultCode.UninitializedMemoryManagement:
				throw new CapstoneException("Memory Management is uninitialized.");
			case NativeCapstoneResultCode.UnsupportedDisassembleArchitecture:
			{
				string message2 = $"A disassemble architecture ({disassembleArchitecture}) is invalid.";
				throw new ArgumentException(message2, "disassembleArchitecture");
			}
			case NativeCapstoneResultCode.UnsupportedDisassembleMode:
			{
				string message = $"A disassemble mode ({disassembleMode}) is invalid.";
				throw new ArgumentException(message, "disassembleMode");
			}
			case NativeCapstoneResultCode.OutOfMemory:
				throw new OutOfMemoryException("Sufficient memory could not be allocated.");
			default:
				throw new CapstoneException("A disassembler could not be created.");
			case NativeCapstoneResultCode.Ok:
				return new NativeDisassemblerHandle(pDisassembler);
			}
		}

		internal static NativeInstructionHandle CreateInstruction(NativeDisassemblerHandle hDisassembler)
		{
			IntPtr pInstruction = NativeCapstoneImport.CreateInstruction(hDisassembler);
			return new NativeInstructionHandle(pInstruction);
		}

		internal static Tuple<short[], short[]> GetAccessedRegisters(NativeDisassemblerHandle hDisassembler, NativeInstructionHandle hInstruction)
		{
			short[] array = new short[64];
			byte readRegistersCount = 0;
			short[] array2 = new short[64];
			byte writtenRegistersCount = 0;
			switch (NativeCapstoneImport.GetAccessedRegisters(hDisassembler, hInstruction, array, ref readRegistersCount, array2, ref writtenRegistersCount))
			{
			case (NativeCapstoneResultCode)(-1):
			{
				string message = "A disassembler handle (hDisassembler) is invalid.";
				throw new ArgumentException(message, "hDisassembler");
			}
			case NativeCapstoneResultCode.UnsupportedDisassembleArchitecture:
				throw new NotSupportedException("A disassembler's hardware architecture is not supported.");
			case NativeCapstoneResultCode.UnSupportedDietModeOperation:
				throw new NotSupportedException("An operation is not supported when diet mode is enabled.");
			case NativeCapstoneResultCode.UnsupportedInstructionDetail:
				throw new InvalidOperationException("An operation is not supported when instruction details are disabled.");
			case NativeCapstoneResultCode.UnsupportedSkipDataModeOperation:
				throw new InvalidOperationException("An operation is not supported when skip-data mode is enabled.");
			default:
				throw new CapstoneException("An instruction's accessed registers could not be retrieved.");
			case NativeCapstoneResultCode.Ok:
			{
				short[] array3 = new short[readRegistersCount];
				short[] array4 = new short[writtenRegistersCount];
				Array.Copy(array, array3, array3.Length);
				Array.Copy(array2, array4, array4.Length);
				return Tuple.Create(array3, array4);
			}
			}
		}

		internal static NativeInstruction GetInstruction(NativeInstructionHandle hInstruction)
		{
			IntPtr p = hInstruction.DangerousAddRefAndGetHandle();
			try
			{
				return MarshalExtension.PtrToStructure<NativeInstruction>(p);
			}
			finally
			{
				hInstruction.DangerousRelease();
			}
		}

		internal static NativeInstructionDetail? GetInstructionDetail(NativeInstructionHandle hInstruction)
		{
			IntPtr intPtr = hInstruction.DangerousAddRefAndGetHandle();
			try
			{
				IntPtr intPtr2 = Marshal.OffsetOf(typeof(NativeInstruction), "Details");
				IntPtr ptr = (IntPtr)((long)intPtr + (long)intPtr2);
				IntPtr intPtr3 = Marshal.ReadIntPtr(ptr);
				NativeInstructionDetail? result = null;
				if (intPtr3 != IntPtr.Zero)
				{
					result = MarshalExtension.PtrToStructure<NativeInstructionDetail>(intPtr3);
				}
				return result;
			}
			finally
			{
				hInstruction.DangerousRelease();
			}
		}

		internal static TInstructionDetail? GetInstructionDetail<TInstructionDetail>(NativeInstructionHandle hInstruction) where TInstructionDetail : struct
		{
			IntPtr intPtr = hInstruction.DangerousAddRefAndGetHandle();
			try
			{
				IntPtr intPtr2 = Marshal.OffsetOf(typeof(NativeInstruction), "Details");
				IntPtr ptr = (IntPtr)((long)intPtr + (long)intPtr2);
				IntPtr intPtr3 = Marshal.ReadIntPtr(ptr);
				TInstructionDetail? result = null;
				if (intPtr3 != IntPtr.Zero)
				{
					IntPtr ptr2 = intPtr3 + 80;
					result = (TInstructionDetail)Marshal.PtrToStructure(ptr2, typeof(TInstructionDetail));
				}
				return result;
			}
			finally
			{
				hInstruction.DangerousRelease();
			}
		}

		internal static NativeInstructionDetail? GetInstructionDetail(ref NativeInstruction instruction)
		{
			NativeInstructionDetail? result = null;
			if (instruction.Details != IntPtr.Zero)
			{
				IntPtr details = instruction.Details;
				result = MarshalExtension.PtrToStructure<NativeInstructionDetail>(details);
			}
			return result;
		}

		internal static TInstructionDetails? GetInstructionDetail<TInstructionDetails>(ref NativeInstruction instruction) where TInstructionDetails : struct
		{
			TInstructionDetails? result = null;
			if (instruction.Details != IntPtr.Zero)
			{
				IntPtr p = instruction.Details + 80;
				result = MarshalExtension.PtrToStructure<TInstructionDetails>(p);
			}
			return result;
		}

		internal unsafe static string GetInstructionGroupName(NativeDisassemblerHandle hDisassembler, int instructionGroupId)
		{
			string result = null;
			IntPtr instructionGroupName = NativeCapstoneImport.GetInstructionGroupName(hDisassembler, instructionGroupId);
			if (instructionGroupName != IntPtr.Zero)
			{
				result = new string((sbyte*)(void*)instructionGroupName);
			}
			return result;
		}

		internal unsafe static string GetRegisterName(NativeDisassemblerHandle hDisassembler, int registerId)
		{
			string result = null;
			IntPtr registerName = NativeCapstoneImport.GetRegisterName(hDisassembler, registerId);
			if (registerName != IntPtr.Zero)
			{
				result = new string((sbyte*)(void*)registerName);
			}
			return result;
		}

		internal static Version GetVersion()
		{
			int majorVersion = 0;
			int minorVersion = 0;
			NativeCapstoneImport.GetVersion(ref majorVersion, ref minorVersion);
			return new Version(majorVersion, minorVersion);
		}

		internal static bool Iterate(NativeDisassemblerHandle hDisassembler, byte[] binaryCode, ref int binaryCodeOffset, ref long address, NativeInstructionHandle hInstruction)
		{
			GCHandle gCHandle = GCHandle.Alloc(binaryCode, GCHandleType.Pinned);
			try
			{
				IntPtr pCode = gCHandle.AddrOfPinnedObject() + binaryCodeOffset;
				IntPtr codeSize = (IntPtr)binaryCode.Length - binaryCodeOffset;
				IntPtr intPtr = pCode;
				bool flag = NativeCapstoneImport.Iterate(hDisassembler, ref pCode, ref codeSize, ref address, hInstruction);
				if (flag)
				{
					binaryCodeOffset += (int)((long)pCode - (long)intPtr);
				}
				return flag;
			}
			finally
			{
				if (gCHandle.IsAllocated)
				{
					gCHandle.Free();
				}
			}
		}

		[Conditional("NET40")]
		[Conditional("NET45")]
		internal static void LoadLibrary()
		{
			string path = (Environment.Is64BitProcess ? "x64" : "x86");
			string baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
			string libraryFilePath = Path.Combine(baseDirectory, path, "capstone.dll");
			NativeCapstoneImport.LoadLibrary(libraryFilePath);
		}

		internal static bool Query(NativeQueryOption queryOption)
		{
			return NativeCapstoneImport.Query(queryOption);
		}

		internal static void SetDisassembleModeOption(NativeDisassemblerHandle hDisassembler, NativeDisassembleMode disassembleMode)
		{
			switch (NativeCapstoneImport.SetDisassemblerOption(hDisassembler, NativeDisassemblerOptionType.SetDisassembleMode, (IntPtr)(int)disassembleMode))
			{
			case NativeCapstoneResultCode.InvalidOption:
			{
				string message = "An option (optionType) is invalid.";
				throw new ArgumentException(message, "optionType");
			}
			default:
			{
				string detailMessage = $"A disassembler option ({NativeDisassemblerOptionType.SetDisassembleMode}) could not be set.";
				throw new CapstoneException(detailMessage);
			}
			case NativeCapstoneResultCode.Ok:
				break;
			}
		}

		internal static void SetDisassemblerOption(NativeDisassemblerHandle hDisassembler, NativeDisassemblerOptionType optionType, NativeDisassemblerOptionValue optionValue)
		{
			if (optionType == NativeDisassemblerOptionType.SetSkipDataConfig)
			{
				string message = $"A disassembler option ({optionType}) is unsupported.";
				throw new NotSupportedException(message);
			}
			switch (NativeCapstoneImport.SetDisassemblerOption(hDisassembler, optionType, (IntPtr)(int)optionValue))
			{
			case NativeCapstoneResultCode.InvalidHandle2:
			{
				string message3 = "A disassembler handle (hDisassembler) is invalid.";
				throw new ArgumentException(message3, "hDisassembler");
			}
			case NativeCapstoneResultCode.InvalidOption:
			{
				string message2 = "An option (optionType) is invalid.";
				throw new ArgumentException(message2, "optionType");
			}
			default:
			{
				string detailMessage = $"A disassembler option ({optionType}) could not be set.";
				throw new CapstoneException(detailMessage);
			}
			case NativeCapstoneResultCode.Ok:
				break;
			}
		}

		internal static void SetInstructionMnemonicOption(NativeDisassemblerHandle hDisassembler, ref NativeInstructionMnemonicOptionValue optionValue)
		{
			IntPtr intPtr = IntPtr.Zero;
			try
			{
				intPtr = MarshalExtension.AllocHGlobal<NativeInstructionMnemonicOptionValue>();
				Marshal.StructureToPtr(optionValue, intPtr, fDeleteOld: false);
				switch (NativeCapstoneImport.SetDisassemblerOption(hDisassembler, NativeDisassemblerOptionType.SetMnemonic, intPtr))
				{
				case NativeCapstoneResultCode.InvalidHandle2:
				{
					string message = "A disassembler handle (hDisassembler) is invalid.";
					throw new ArgumentException(message, "hDisassembler");
				}
				default:
				{
					string detailMessage = $"A disassembler option ({NativeDisassemblerOptionType.SetMnemonic}) could not be set.";
					throw new CapstoneException(detailMessage);
				}
				case NativeCapstoneResultCode.Ok:
					break;
				}
			}
			finally
			{
				if (intPtr != IntPtr.Zero)
				{
					Marshal.FreeHGlobal(intPtr);
				}
			}
		}

		internal static void SetSkipDataOption(NativeDisassemblerHandle hDisassembler, ref NativeSkipDataOptionValue optionValue)
		{
			IntPtr intPtr = IntPtr.Zero;
			try
			{
				intPtr = MarshalExtension.AllocHGlobal<NativeSkipDataOptionValue>();
				Marshal.StructureToPtr(optionValue, intPtr, fDeleteOld: false);
				NativeCapstoneResultCode nativeCapstoneResultCode = NativeCapstoneImport.SetDisassemblerOption(hDisassembler, NativeDisassemblerOptionType.SetSkipDataConfig, intPtr);
			}
			finally
			{
				if (intPtr != IntPtr.Zero)
				{
					Marshal.FreeHGlobal(intPtr);
				}
			}
		}
	}
	internal static class NativeCapstoneImport
	{
		[DllImport("capstone", CallingConvention = CallingConvention.Cdecl, EntryPoint = "cs_close")]
		internal static extern NativeCapstoneResultCode CloseDisassembler(ref IntPtr pDissembler);

		[DllImport("capstone", CallingConvention = CallingConvention.Cdecl, EntryPoint = "cs_open")]
		internal static extern NativeCapstoneResultCode CreateDisassembler(DisassembleArchitecture disassembleArchitecture, NativeDisassembleMode disassembleMode, ref IntPtr pDisassembler);

		[DllImport("capstone", CallingConvention = CallingConvention.Cdecl, EntryPoint = "cs_malloc")]
		internal static extern IntPtr CreateInstruction(NativeDisassemblerHandle hDisassembler);

		[DllImport("capstone", CallingConvention = CallingConvention.Cdecl, EntryPoint = "cs_disasm")]
		internal static extern IntPtr Disassemble(NativeDisassemblerHandle hDisassembler, IntPtr pCode, IntPtr codeSize, long startingAddress, IntPtr count, ref IntPtr pInstructions);

		[DllImport("capstone", CallingConvention = CallingConvention.Cdecl, EntryPoint = "cs_free")]
		internal static extern void FreeInstructions(IntPtr pInstructions, IntPtr count);

		[DllImport("capstone", CallingConvention = CallingConvention.Cdecl, EntryPoint = "cs_regs_access")]
		internal static extern NativeCapstoneResultCode GetAccessedRegisters(NativeDisassemblerHandle hDisassembler, NativeInstructionHandle hInstruction, short[] readRegisters, ref byte readRegistersCount, short[] writtenRegisters, ref byte writtenRegistersCount);

		[DllImport("capstone", CallingConvention = CallingConvention.Cdecl, EntryPoint = "cs_group_name")]
		internal static extern IntPtr GetInstructionGroupName(NativeDisassemblerHandle hDisassembler, int instructionGroupId);

		[DllImport("capstone", CallingConvention = CallingConvention.Cdecl, EntryPoint = "cs_errno")]
		internal static extern NativeCapstoneResultCode GetLastErrorCode(NativeDisassemblerHandle hDisassembler);

		[DllImport("capstone", CallingConvention = CallingConvention.Cdecl, EntryPoint = "cs_reg_name")]
		internal static extern IntPtr GetRegisterName(NativeDisassemblerHandle hDisassembler, int registerId);

		[DllImport("capstone", CallingConvention = CallingConvention.Cdecl, EntryPoint = "cs_version")]
		internal static extern int GetVersion(ref int majorVersion, ref int minorVersion);

		[DllImport("capstone", CallingConvention = CallingConvention.Cdecl, EntryPoint = "cs_disasm_iter")]
		[return: MarshalAs(UnmanagedType.I1)]
		internal static extern bool Iterate(NativeDisassemblerHandle hDisassembler, ref IntPtr pCode, ref IntPtr codeSize, ref long address, NativeInstructionHandle hInstruction);

		[DllImport("kernel32.dll", CharSet = CharSet.Ansi, EntryPoint = "LoadLibraryA", SetLastError = true)]
		internal static extern IntPtr LoadLibrary(string libraryFilePath);

		[DllImport("capstone", CallingConvention = CallingConvention.Cdecl, EntryPoint = "cs_support")]
		[return: MarshalAs(UnmanagedType.I1)]
		internal static extern bool Query(NativeQueryOption queryOption);

		[DllImport("capstone", CallingConvention = CallingConvention.Cdecl, EntryPoint = "cs_option")]
		internal static extern NativeCapstoneResultCode SetDisassemblerOption(NativeDisassemblerHandle hDisassembler, NativeDisassemblerOptionType optionType, IntPtr optionValue);
	}
	internal enum NativeCapstoneResultCode
	{
		Ok,
		OutOfMemory,
		UnsupportedDisassembleArchitecture,
		InvalidHandle1,
		InvalidHandle2,
		UnsupportedDisassembleMode,
		InvalidOption,
		UnsupportedInstructionDetail,
		UninitializedMemoryManagement,
		UnsupportedVersion,
		UnSupportedDietModeOperation,
		UnsupportedSkipDataModeOperation,
		UnSupportedX86AttSyntax,
		UnSupportedX86IntelSyntax,
		UnSupportedX86MasmSyntax
	}
	[Flags]
	internal enum NativeDisassembleMode
	{
		LittleEndian = 0,
		Arm = 0,
		Bit16 = 2,
		Bit32 = 4,
		Bit64 = 8,
		ArmThumb = 0x10,
		ArmCortexM = 0x20,
		ArmV8 = 0x40,
		MipsMicro = 0x10,
		Mips3 = 0x20,
		Mips32R6 = 0x40,
		Mips2 = 0x80,
		SparcV9 = 0x10,
		PowerPcQuadProcessingExtensions = 0x10,
		M68K000 = 2,
		M68K010 = 4,
		M68K020 = 8,
		M68K030 = 0x10,
		M68K040 = 0x20,
		M68K060 = 0x40,
		BigEndian = int.MinValue,
		Mips32 = 4,
		Mips64 = 8,
		M680X6301 = 2,
		M680X6309 = 4,
		M680X6800 = 8,
		M680X6801 = 0x10,
		M680X6805 = 0x20,
		M680X6808 = 0x40,
		M680X6809 = 0x80,
		M680X6811 = 0x100,
		M680XCpu12 = 0x200,
		M680XHcS08 = 0x400
	}
	internal sealed class NativeDisassemblerHandle : SafeHandleZeroOrMinusOneIsInvalid
	{
		internal NativeDisassemblerHandle(IntPtr pDisassembler)
			: base(ownsHandle: true)
		{
			handle = pDisassembler;
		}

		protected override bool ReleaseHandle()
		{
			NativeCapstoneResultCode nativeCapstoneResultCode = NativeCapstoneImport.CloseDisassembler(ref handle);
			return nativeCapstoneResultCode == NativeCapstoneResultCode.Ok;
		}
	}
	internal enum NativeDisassemblerOptionType
	{
		None,
		SetSyntax,
		SetInstructionDetails,
		SetDisassembleMode,
		SetMemory,
		SetSkipData,
		SetSkipDataConfig,
		SetMnemonic,
		SetUnsigned
	}
	internal enum NativeDisassemblerOptionValue
	{
		Disable = 0,
		Enable = 3,
		UseDefaultSyntax = 0,
		UseIntelSyntax = 1,
		UseAttSyntax = 2,
		CS_OPT_SYNTAX_NOREGNAME = 3,
		UseMasmSyntax = 4
	}
	internal struct NativeInstruction
	{
		public int Id;

		public long Address;

		public short Size;

		[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
		public byte[] Bytes;

		[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
		public string Mnemonic;

		[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 160)]
		public string Operand;

		public IntPtr Details;
	}
	[StructLayout(LayoutKind.Sequential, Pack = 8)]
	internal struct NativeInstructionDetail
	{
		[MarshalAs(UnmanagedType.ByValArray, SizeConst = 12)]
		public short[] ImplicitlyReadRegisters;

		public byte ImplicitlyReadRegisterCount;

		[MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)]
		public short[] ImplicitlyWrittenRegisters;

		public byte ImplicitlyWrittenRegisterCount;

		[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
		public byte[] Groups;

		public byte GroupCount;
	}
	internal sealed class NativeInstructionHandle : SafeHandleZeroOrMinusOneIsInvalid
	{
		internal NativeInstructionHandle(IntPtr pInstruction)
			: base(ownsHandle: true)
		{
			handle = pInstruction;
		}

		protected override bool ReleaseHandle()
		{
			NativeCapstoneImport.FreeInstructions(handle, (IntPtr)1);
			handle = IntPtr.Zero;
			return true;
		}
	}
	internal struct NativeInstructionMnemonicOptionValue
	{
		public int InstructionId;

		[MarshalAs(UnmanagedType.LPStr)]
		public string InstructionMnemonic;
	}
	internal enum NativeQueryOption
	{
		QueryArmArchitecture = 0,
		QueryArm64Architecture = 1,
		QueryMipsArchitecture = 2,
		QueryX86Architecture = 3,
		QueryPowerPcArchitecture = 4,
		QuerySparcArchitecture = 5,
		QuerySystemZArchitecture = 6,
		QueryXCoreArchitecture = 7,
		QueryM68KArchitecture = 8,
		QueryTms320C64XArchitecture = 9,
		QueryM680XArchitecture = 10,
		QueryEvmArchitecture = 11,
		QueryAllArchitectures = 65535,
		QueryDietMode = 65536,
		QueryX86ReduceMode = 65537
	}
	internal struct NativeSkipDataOptionValue
	{
		[MarshalAs(UnmanagedType.LPStr)]
		public string InstructionMnemonic;

		[MarshalAs(UnmanagedType.FunctionPtr)]
		public NativeCapstone.SkipDataCallback Callback;

		public IntPtr State;
	}
	[Flags]
	public enum OperandAccessType : byte
	{
		Invalid = 0,
		Read = 1,
		Write = 2
	}
	public abstract class Register<TId> where TId : Enum
	{
		private readonly string _name;

		public TId Id { get; }

		public bool IsDietModeEnabled => CapstoneDisassembler.IsDietModeEnabled;

		public string Name
		{
			get
			{
				CapstoneDisassembler.ThrowIfDietModeIsEnabled();
				return _name;
			}
		}

		private protected Register(TId id, string name)
		{
			Id = id;
			_name = name;
		}

		public override bool Equals(object @object)
		{
			bool flag = @object != null;
			if (flag)
			{
				Register<TId> register = @object as Register<TId>;
				flag = register != null;
				if (flag)
				{
					flag = Id.Equals(register.Id) && _name == register._name;
				}
			}
			return flag;
		}

		public override int GetHashCode()
		{
			int num = 13;
			num = num * 7 + Id.GetHashCode();
			return (_name != null) ? (num * 7 + _name.GetHashCode()) : 0;
		}
	}
	internal static class SafeHandleExtension
	{
		internal static IntPtr DangerousAddRefAndGetHandle(this SafeHandle @this)
		{
			bool success = false;
			@this.DangerousAddRef(ref success);
			if (!success)
			{
				throw new InvalidOperationException("Unable to add a reference to a handle.");
			}
			return @this.DangerousGetHandle();
		}
	}
}
namespace Gee.External.Capstone.XCore
{
	public sealed class CapstoneXCoreDisassembler : CapstoneDisassembler<XCoreDisassembleMode, XCoreInstruction, XCoreInstructionDetail, XCoreInstructionGroup, XCoreInstructionGroupId, XCoreInstructionId, XCoreRegister, XCoreRegisterId>
	{
		public CapstoneXCoreDisassembler(XCoreDisassembleMode disassembleMode)
			: base(DisassembleArchitecture.XCore, disassembleMode)
		{
		}

		private protected override XCoreInstruction CreateInstruction(NativeInstructionHandle hInstruction)
		{
			return XCoreInstruction.Create(this, hInstruction);
		}
	}
	internal struct NativeXCoreInstructionDetail
	{
		public byte OperandCount;

		[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
		public NativeXCoreOperand[] Operands;
	}
	internal struct NativeXCoreMemoryOperandValue
	{
		public byte Base;

		public byte Index;

		public int Displacement;

		public int Direct;
	}
	internal struct NativeXCoreOperand
	{
		public XCoreOperandType Type;

		public NativeXCoreOperandValue Value;
	}
	[StructLayout(LayoutKind.Explicit)]
	internal struct NativeXCoreOperandValue
	{
		[FieldOffset(0)]
		public XCoreRegisterId Register;

		[FieldOffset(0)]
		public int Immediate;

		[FieldOffset(0)]
		public NativeXCoreMemoryOperandValue Memory;
	}
	public enum XCoreDisassembleMode
	{
		BigEndian = int.MinValue
	}
	public sealed class XCoreInstruction : Instruction<XCoreInstruction, XCoreInstructionDetail, XCoreDisassembleMode, XCoreInstructionGroup, XCoreInstructionGroupId, XCoreInstructionId, XCoreRegister, XCoreRegisterId>
	{
		internal static XCoreInstruction Create(CapstoneDisassembler disassembler, NativeInstructionHandle hInstruction)
		{
			XCoreInstructionBuilder xCoreInstructionBuilder = new XCoreInstructionBuilder();
			xCoreInstructionBuilder.Build(disassembler, hInstruction);
			return xCoreInstructionBuilder.Create();
		}

		internal XCoreInstruction(XCoreInstructionBuilder builder)
			: base((InstructionBuilder<XCoreInstructionDetail, XCoreDisassembleMode, XCoreInstructionGroup, XCoreInstructionGroupId, XCoreInstruction, XCoreInstructionId, XCoreRegister, XCoreRegisterId>)builder)
		{
		}
	}
	internal sealed class XCoreInstructionBuilder : InstructionBuilder<XCoreInstructionDetail, XCoreDisassembleMode, XCoreInstructionGroup, XCoreInstructionGroupId, XCoreInstruction, XCoreInstructionId, XCoreRegister, XCoreRegisterId>
	{
		internal XCoreInstruction Create()
		{
			return new XCoreInstruction(this);
		}

		private protected override XCoreInstructionDetail CreateDetails(CapstoneDisassembler disassembler, NativeInstructionHandle hInstruction)
		{
			return XCoreInstructionDetail.Create(disassembler, hInstruction);
		}

		private protected override XCoreDisassembleMode CreateDisassembleMode(NativeDisassembleMode nativeDisassembleMode)
		{
			return (XCoreDisassembleMode)nativeDisassembleMode;
		}

		private protected override XCoreInstructionId CreateId(int id)
		{
			return (XCoreInstructionId)id;
		}
	}
	public sealed class XCoreInstructionDetail : InstructionDetail<XCoreInstructionDetail, XCoreDisassembleMode, XCoreInstructionGroup, XCoreInstructionGroupId, XCoreInstruction, XCoreInstructionId, XCoreRegister, XCoreRegisterId>
	{
		public XCoreOperand[] Operands { get; }

		internal static XCoreInstructionDetail Create(CapstoneDisassembler disassembler, NativeInstructionHandle hInstruction)
		{
			XCoreInstructionDetailBuilder xCoreInstructionDetailBuilder = new XCoreInstructionDetailBuilder();
			xCoreInstructionDetailBuilder.Build(disassembler, hInstruction);
			return xCoreInstructionDetailBuilder.Create();
		}

		internal XCoreInstructionDetail(XCoreInstructionDetailBuilder builder)
			: base((InstructionDetailBuilder<XCoreInstructionDetail, XCoreDisassembleMode, XCoreInstructionGroup, XCoreInstructionGroupId, XCoreInstruction, XCoreInstructionId, XCoreRegister, XCoreRegisterId>)builder)
		{
			Operands = builder.Operands;
		}
	}
	internal sealed class XCoreInstructionDetailBuilder : InstructionDetailBuilder<XCoreInstructionDetail, XCoreDisassembleMode, XCoreInstructionGroup, XCoreInstructionGroupId, XCoreInstruction, XCoreInstructionId, XCoreRegister, XCoreRegisterId>
	{
		internal XCoreOperand[] Operands { get; private set; }

		internal override void Build(CapstoneDisassembler disassembler, NativeInstructionHandle hInstruction)
		{
			base.Build(disassembler, hInstruction);
			NativeXCoreInstructionDetail nativeInstructionDetail = NativeCapstone.GetInstructionDetail<NativeXCoreInstructionDetail>(hInstruction).GetValueOrDefault();
			Operands = XCoreOperand.Create(disassembler, ref nativeInstructionDetail);
		}

		internal XCoreInstructionDetail Create()
		{
			return new XCoreInstructionDetail(this);
		}

		private protected override XCoreDisassembleMode CreateDisassembleMode(NativeDisassembleMode nativeDisassembleMode)
		{
			return (XCoreDisassembleMode)nativeDisassembleMode;
		}

		private protected override XCoreInstructionGroup CreateInstructionGroup(CapstoneDisassembler disassembler, byte instructionGroupId)
		{
			return XCoreInstructionGroup.Create(disassembler, (XCoreInstructionGroupId)instructionGroupId);
		}

		private protected override XCoreRegister CreateRegister(CapstoneDisassembler disassembler, short registerId)
		{
			return XCoreRegister.TryCreate(disassembler, (XCoreRegisterId)registerId);
		}
	}
	public sealed class XCoreInstructionGroup : InstructionGroup<XCoreInstructionGroupId>
	{
		internal static XCoreInstructionGroup Create(CapstoneDisassembler disassembler, XCoreInstructionGroupId id)
		{
			string instructionGroupName = NativeCapstone.GetInstructionGroupName(disassembler.Handle, (int)id);
			return new XCoreInstructionGroup(id, instructionGroupName);
		}

		internal XCoreInstructionGroup(XCoreInstructionGroupId id, string name)
			: base(id, name)
		{
		}
	}
	public enum XCoreInstructionGroupId
	{
		Invalid,
		XCORE_GRP_JUMP
	}
	public enum XCoreInstructionId
	{
		Invalid,
		XCORE_INS_ADD,
		XCORE_INS_ANDNOT,
		XCORE_INS_AND,
		XCORE_INS_ASHR,
		XCORE_INS_BAU,
		XCORE_INS_BITREV,
		XCORE_INS_BLA,
		XCORE_INS_BLAT,
		XCORE_INS_BL,
		XCORE_INS_BF,
		XCORE_INS_BT,
		XCORE_INS_BU,
		XCORE_INS_BRU,
		XCORE_INS_BYTEREV,
		XCORE_INS_CHKCT,
		XCORE_INS_CLRE,
		XCORE_INS_CLRPT,
		XCORE_INS_CLRSR,
		XCORE_INS_CLZ,
		XCORE_INS_CRC8,
		XCORE_INS_CRC32,
		XCORE_INS_DCALL,
		XCORE_INS_DENTSP,
		XCORE_INS_DGETREG,
		XCORE_INS_DIVS,
		XCORE_INS_DIVU,
		XCORE_INS_DRESTSP,
		XCORE_INS_DRET,
		XCORE_INS_ECALLF,
		XCORE_INS_ECALLT,
		XCORE_INS_EDU,
		XCORE_INS_EEF,
		XCORE_INS_EET,
		XCORE_INS_EEU,
		XCORE_INS_ENDIN,
		XCORE_INS_ENTSP,
		XCORE_INS_EQ,
		XCORE_INS_EXTDP,
		XCORE_INS_EXTSP,
		XCORE_INS_FREER,
		XCORE_INS_FREET,
		XCORE_INS_GETD,
		XCORE_INS_GET,
		XCORE_INS_GETN,
		XCORE_INS_GETR,
		XCORE_INS_GETSR,
		XCORE_INS_GETST,
		XCORE_INS_GETTS,
		XCORE_INS_INCT,
		XCORE_INS_INIT,
		XCORE_INS_INPW,
		XCORE_INS_INSHR,
		XCORE_INS_INT,
		XCORE_INS_IN,
		XCORE_INS_KCALL,
		XCORE_INS_KENTSP,
		XCORE_INS_KRESTSP,
		XCORE_INS_KRET,
		XCORE_INS_LADD,
		XCORE_INS_LD16S,
		XCORE_INS_LD8U,
		XCORE_INS_LDA16,
		XCORE_INS_LDAP,
		XCORE_INS_LDAW,
		XCORE_INS_LDC,
		XCORE_INS_LDW,
		XCORE_INS_LDIVU,
		XCORE_INS_LMUL,
		XCORE_INS_LSS,
		XCORE_INS_LSUB,
		XCORE_INS_LSU,
		XCORE_INS_MACCS,
		XCORE_INS_MACCU,
		XCORE_INS_MJOIN,
		XCORE_INS_MKMSK,
		XCORE_INS_MSYNC,
		XCORE_INS_MUL,
		XCORE_INS_NEG,
		XCORE_INS_NOT,
		XCORE_INS_OR,
		XCORE_INS_OUTCT,
		XCORE_INS_OUTPW,
		XCORE_INS_OUTSHR,
		XCORE_INS_OUTT,
		XCORE_INS_OUT,
		XCORE_INS_PEEK,
		XCORE_INS_REMS,
		XCORE_INS_REMU,
		XCORE_INS_RETSP,
		XCORE_INS_SETCLK,
		XCORE_INS_SET,
		XCORE_INS_SETC,
		XCORE_INS_SETD,
		XCORE_INS_SETEV,
		XCORE_INS_SETN,
		XCORE_INS_SETPSC,
		XCORE_INS_SETPT,
		XCORE_INS_SETRDY,
		XCORE_INS_SETSR,
		XCORE_INS_SETTW,
		XCORE_INS_SETV,
		XCORE_INS_SEXT,
		XCORE_INS_SHL,
		XCORE_INS_SHR,
		XCORE_INS_SSYNC,
		XCORE_INS_ST16,
		XCORE_INS_ST8,
		XCORE_INS_STW,
		XCORE_INS_SUB,
		XCORE_INS_SYNCR,
		XCORE_INS_TESTCT,
		XCORE_INS_TESTLCL,
		XCORE_INS_TESTWCT,
		XCORE_INS_TSETMR,
		XCORE_INS_START,
		XCORE_INS_WAITEF,
		XCORE_INS_WAITET,
		XCORE_INS_WAITEU,
		XCORE_INS_XOR,
		XCORE_INS_ZEXT
	}
	public sealed class XCoreMemoryOperandValue
	{
		internal XCoreRegister Base { get; }

		internal int Direct { get; }

		internal int Displacement { get; }

		internal XCoreRegister Index { get; }

		internal XCoreMemoryOperandValue(CapstoneDisassembler disassembler, ref NativeXCoreMemoryOperandValue nativeMemoryOperandValue)
		{
			Base = XCoreRegister.TryCreate(disassembler, (XCoreRegisterId)nativeMemoryOperandValue.Base);
			Direct = nativeMemoryOperandValue.Direct;
			Displacement = nativeMemoryOperandValue.Displacement;
			Index = XCoreRegister.TryCreate(disassembler, (XCoreRegisterId)nativeMemoryOperandValue.Index);
		}
	}
	public sealed class XCoreOperand
	{
		private readonly int _immediate;

		private readonly XCoreMemoryOperandValue _memory;

		private readonly XCoreRegister _register;

		public long Immediate
		{
			get
			{
				if (Type != XCoreOperandType.Immediate)
				{
					string message = string.Format("A value ({0}) is invalid when the type is ({1}).", "Immediate", Type);
					throw new InvalidOperationException(message);
				}
				return _immediate;
			}
		}

		public XCoreMemoryOperandValue Memory
		{
			get
			{
				if (Type != XCoreOperandType.Memory)
				{
					string message = string.Format("A value ({0}) is invalid when the type is ({1}).", "Memory", Type);
					throw new InvalidOperationException(message);
				}
				return _memory;
			}
		}

		public XCoreRegister Register
		{
			get
			{
				if (Type != XCoreOperandType.Register)
				{
					string message = string.Format("A value ({0}) is invalid when the type is ({1}).", "Register", Type);
					throw new InvalidOperationException(message);
				}
				return _register;
			}
		}

		public XCoreOperandType Type { get; }

		internal static XCoreOperand[] Create(CapstoneDisassembler disassembler, ref NativeXCoreInstructionDetail nativeInstructionDetail)
		{
			XCoreOperand[] array = new XCoreOperand[nativeInstructionDetail.OperandCount];
			for (int i = 0; i < array.Length; i++)
			{
				array[i] = new XCoreOperand(disassembler, ref nativeInstructionDetail.Operands[i]);
			}
			return array;
		}

		internal XCoreOperand(CapstoneDisassembler disassembler, ref NativeXCoreOperand nativeOperand)
		{
			Type = nativeOperand.Type;
			switch (Type)
			{
			case XCoreOperandType.Immediate:
				_immediate = nativeOperand.Value.Immediate;
				break;
			case XCoreOperandType.Memory:
				_memory = new XCoreMemoryOperandValue(disassembler, ref nativeOperand.Value.Memory);
				break;
			case XCoreOperandType.Register:
				_register = XCoreRegister.TryCreate(disassembler, nativeOperand.Value.Register);
				break;
			}
		}
	}
	public enum XCoreOperandType
	{
		Invalid,
		Register,
		Immediate,
		Memory
	}
	public sealed class XCoreRegister : Register<XCoreRegisterId>
	{
		internal static XCoreRegister TryCreate(CapstoneDisassembler disassembler, XCoreRegisterId id)
		{
			XCoreRegister result = null;
			if (id != 0)
			{
				string registerName = NativeCapstone.GetRegisterName(disassembler.Handle, (int)id);
				result = new XCoreRegister(id, registerName);
			}
			return result;
		}

		internal XCoreRegister(XCoreRegisterId id, string name)
			: base(id, name)
		{
		}
	}
	public enum XCoreRegisterId
	{
		Invalid,
		XCORE_REG_CP,
		XCORE_REG_DP,
		XCORE_REG_LR,
		XCORE_REG_SP,
		XCORE_REG_R0,
		XCORE_REG_R1,
		XCORE_REG_R2,
		XCORE_REG_R3,
		XCORE_REG_R4,
		XCORE_REG_R5,
		XCORE_REG_R6,
		XCORE_REG_R7,
		XCORE_REG_R8,
		XCORE_REG_R9,
		XCORE_REG_R10,
		XCORE_REG_R11,
		XCORE_REG_PC,
		XCORE_REG_SCP,
		XCORE_REG_SSR,
		XCORE_REG_ET,
		XCORE_REG_ED,
		XCORE_REG_SED,
		XCORE_REG_KEP,
		XCORE_REG_KSP,
		XCORE_REG_ID
	}
}
namespace Gee.External.Capstone.X86
{
	public sealed class CapstoneX86Disassembler : CapstoneDisassembler<X86DisassembleMode, X86Instruction, X86InstructionDetail, X86InstructionGroup, X86InstructionGroupId, X86InstructionId, X86Register, X86RegisterId>
	{
		public bool IsReduceModeEnabled => CapstoneDisassembler.IsX86ReduceModeEnabled;

		public CapstoneX86Disassembler(X86DisassembleMode disassembleMode)
			: base(DisassembleArchitecture.X86, disassembleMode)
		{
		}

		private protected override X86Instruction CreateInstruction(NativeInstructionHandle hInstruction)
		{
			return X86Instruction.Create(this, hInstruction);
		}
	}
	internal struct NativeX86Encoding
	{
		public byte ModRmOffset;

		public byte DisplacementOffset;

		public byte DisplacementSize;

		public byte ImmediateOffset;

		public byte ImmediateSize;
	}
	[StructLayout(LayoutKind.Explicit)]
	internal struct NativeX86Flag
	{
		[FieldOffset(0)]
		public long EFlags;

		[FieldOffset(0)]
		public long FpuFlags;
	}
	internal struct NativeX86InstructionDetail
	{
		[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4, ArraySubType = UnmanagedType.I1)]
		public X86Prefix[] Prefix;

		[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
		public byte[] Opcode;

		public byte Rex;

		public byte AddressSize;

		public byte ModRm;

		public byte Sib;

		public long Displacement;

		public X86RegisterId SibIndex;

		public byte SibScale;

		public X86RegisterId SibBase;

		public X86XopConditionCode XopConditionCode;

		public X86SseConditionCode SseConditionCode;

		public X86AvxConditionCode AvxConditionCode;

		[MarshalAs(UnmanagedType.I1)]
		public bool AvxSuppressAllExceptions;

		public X86AvxRoundingMode AvxRoundingMode;

		public NativeX86Flag Flag;

		public byte OperandCount;

		[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
		public NativeX86Operand[] Operands;

		public NativeX86Encoding Encoding;
	}
	internal struct NativeX86MemoryOperandValue
	{
		public X86RegisterId Segment;

		public X86RegisterId Base;

		public X86RegisterId Index;

		public int Scale;

		public long Displacement;
	}
	internal struct NativeX86Operand
	{
		public X86OperandType Type;

		public NativeX86OperandValue Value;

		public byte Size;

		[MarshalAs(UnmanagedType.I1)]
		public OperandAccessType AccessType;

		public X86AvxBroadcast AvxBroadcast;

		[MarshalAs(UnmanagedType.I1)]
		public bool AvxZeroOpMask;
	}
	[StructLayout(LayoutKind.Explicit)]
	internal struct NativeX86OperandValue
	{
		[FieldOffset(0)]
		public X86RegisterId Register;

		[FieldOffset(0)]
		public long Immediate;

		[FieldOffset(0)]
		public NativeX86MemoryOperandValue Memory;
	}
	public enum X86AvxBroadcast
	{
		Invalid,
		X86_AVX_BCAST_2,
		X86_AVX_BCAST_4,
		X86_AVX_BCAST_8,
		X86_AVX_BCAST_16
	}
	public enum X86AvxConditionCode
	{
		Invalid,
		X86_AVX_CC_EQ,
		X86_AVX_CC_LT,
		X86_AVX_CC_LE,
		X86_AVX_CC_UNORD,
		X86_AVX_CC_NEQ,
		X86_AVX_CC_NLT,
		X86_AVX_CC_NLE,
		X86_AVX_CC_ORD,
		X86_AVX_CC_EQ_UQ,
		X86_AVX_CC_NGE,
		X86_AVX_CC_NGT,
		X86_AVX_CC_FALSE,
		X86_AVX_CC_NEQ_OQ,
		X86_AVX_CC_GE,
		X86_AVX_CC_GT,
		X86_AVX_CC_TRUE,
		X86_AVX_CC_EQ_OS,
		X86_AVX_CC_LT_OQ,
		X86_AVX_CC_LE_OQ,
		X86_AVX_CC_UNORD_S,
		X86_AVX_CC_NEQ_US,
		X86_AVX_CC_NLT_UQ,
		X86_AVX_CC_NLE_UQ,
		X86_AVX_CC_ORD_S,
		X86_AVX_CC_EQ_US,
		X86_AVX_CC_NGE_UQ,
		X86_AVX_CC_NGT_UQ,
		X86_AVX_CC_FALSE_OS,
		X86_AVX_CC_NEQ_OS,
		X86_AVX_CC_GE_OQ,
		X86_AVX_CC_GT_OQ,
		X86_AVX_CC_TRUE_US
	}
	public enum X86AvxRoundingMode
	{
		Invalid,
		X86_AVX_RM_RN,
		X86_AVX_RM_RD,
		X86_AVX_RM_RU,
		X86_AVX_RM_RZ
	}
	[Flags]
	public enum X86DisassembleMode
	{
		Bit16 = 2,
		Bit32 = 4,
		Bit64 = 8,
		LittleEndian = 0
	}
	public sealed class X86Encoding
	{
		public byte DisplacementOffset { get; }

		public byte DisplacementSize { get; }

		public byte ImmediateOffset { get; }

		public byte ImmediateSize { get; }

		public byte ModRmOffset { get; }

		internal X86Encoding(ref NativeX86Encoding nativeEncoding)
		{
			DisplacementOffset = nativeEncoding.DisplacementOffset;
			DisplacementSize = nativeEncoding.DisplacementSize;
			ImmediateOffset = nativeEncoding.ImmediateOffset;
			ImmediateSize = nativeEncoding.ImmediateSize;
			ModRmOffset = nativeEncoding.ModRmOffset;
		}
	}
	public sealed class X86Instruction : Instruction<X86Instruction, X86InstructionDetail, X86DisassembleMode, X86InstructionGroup, X86InstructionGroupId, X86InstructionId, X86Register, X86RegisterId>
	{
		internal static X86Instruction Create(CapstoneDisassembler disassembler, NativeInstructionHandle hInstruction)
		{
			X86InstructionBuilder x86InstructionBuilder = new X86InstructionBuilder();
			x86InstructionBuilder.Build(disassembler, hInstruction);
			return x86InstructionBuilder.Create();
		}

		internal X86Instruction(X86InstructionBuilder builder)
			: base((InstructionBuilder<X86InstructionDetail, X86DisassembleMode, X86InstructionGroup, X86InstructionGroupId, X86Instruction, X86InstructionId, X86Register, X86RegisterId>)builder)
		{
		}
	}
	internal sealed class X86InstructionBuilder : InstructionBuilder<X86InstructionDetail, X86DisassembleMode, X86InstructionGroup, X86InstructionGroupId, X86Instruction, X86InstructionId, X86Register, X86RegisterId>
	{
		internal X86Instruction Create()
		{
			return new X86Instruction(this);
		}

		private protected override X86InstructionDetail CreateDetails(CapstoneDisassembler disassembler, NativeInstructionHandle hInstruction)
		{
			return X86InstructionDetail.Create(disassembler, hInstruction);
		}

		private protected override X86DisassembleMode CreateDisassembleMode(NativeDisassembleMode nativeDisassembleMode)
		{
			return (X86DisassembleMode)nativeDisassembleMode;
		}

		private protected override X86InstructionId CreateId(int id)
		{
			return (X86InstructionId)id;
		}
	}
	public sealed class X86InstructionDetail : InstructionDetail<X86InstructionDetail, X86DisassembleMode, X86InstructionGroup, X86InstructionGroupId, X86Instruction, X86InstructionId, X86Register, X86RegisterId>
	{
		public byte AddressSize { get; }

		public X86AvxConditionCode AvxConditionCode { get; }

		public X86AvxRoundingMode AvxRoundingMode { get; }

		public bool AvxSuppressAllExceptions { get; }

		public long Displacement { get; }

		public long EFlags { get; }

		public X86Encoding Encoding { get; }

		public long FpuFlags { get; }

		public byte ModRm { get; }

		public byte[] Opcode { get; }

		public X86Operand[] Operands { get; }

		public X86Prefix[] Prefix { get; }

		public byte Rex { get; }

		public byte Sib { get; }

		public X86Register SibBase { get; }

		public X86Register SibIndex { get; }

		public byte SibScale { get; }

		public X86SseConditionCode SseConditionCode { get; }

		public X86XopConditionCode XopConditionCode { get; }

		internal static X86InstructionDetail Create(CapstoneDisassembler disassembler, NativeInstructionHandle hInstruction)
		{
			X86InstructionDetailBuilder x86InstructionDetailBuilder = new X86InstructionDetailBuilder();
			x86InstructionDetailBuilder.Build(disassembler, hInstruction);
			return x86InstructionDetailBuilder.Create();
		}

		internal X86InstructionDetail(X86InstructionDetailBuilder builder)
			: base((InstructionDetailBuilder<X86InstructionDetail, X86DisassembleMode, X86InstructionGroup, X86InstructionGroupId, X86Instruction, X86InstructionId, X86Register, X86RegisterId>)builder)
		{
			AddressSize = builder.AddressSize;
			AvxConditionCode = builder.AvxConditionCode;
			AvxRoundingMode = builder.AvxRoundingMode;
			AvxSuppressAllExceptions = builder.AvxSuppressAllExceptions;
			Displacement = builder.Displacement;
			EFlags = builder.EFlags;
			Encoding = builder.Encoding;
			FpuFlags = builder.FpuFlags;
			ModRm = builder.ModRm;
			Opcode = builder.Opcode;
			Operands = builder.Operands;
			Prefix = builder.Prefix;
			Rex = builder.Rex;
			Sib = builder.Sib;
			SibBase = builder.SibBase;
			SibIndex = builder.SibIndex;
			SibScale = builder.SibScale;
			SseConditionCode = builder.SseConditionCode;
			XopConditionCode = builder.XopConditionCode;
		}
	}
	internal sealed class X86InstructionDetailBuilder : InstructionDetailBuilder<X86InstructionDetail, X86DisassembleMode, X86InstructionGroup, X86InstructionGroupId, X86Instruction, X86InstructionId, X86Register, X86RegisterId>
	{
		internal byte AddressSize { get; private set; }

		internal X86AvxConditionCode AvxConditionCode { get; private set; }

		internal X86AvxRoundingMode AvxRoundingMode { get; private set; }

		internal bool AvxSuppressAllExceptions { get; private set; }

		internal long Displacement { get; private set; }

		internal long EFlags { get; private set; }

		internal X86Encoding Encoding { get; private set; }

		internal long FpuFlags { get; private set; }

		internal byte ModRm { get; private set; }

		internal byte[] Opcode { get; private set; }

		internal X86Operand[] Operands { get; private set; }

		internal X86Prefix[] Prefix { get; private set; }

		internal byte Rex { get; private set; }

		internal byte Sib { get; private set; }

		internal X86Register SibBase { get; private set; }

		internal X86Register SibIndex { get; private set; }

		internal byte SibScale { get; private set; }

		internal X86SseConditionCode SseConditionCode { get; private set; }

		internal X86XopConditionCode XopConditionCode { get; private set; }

		internal override void Build(CapstoneDisassembler disassembler, NativeInstructionHandle hInstruction)
		{
			base.Build(disassembler, hInstruction);
			NativeX86InstructionDetail nativeInstructionDetail = NativeCapstone.GetInstructionDetail<NativeX86InstructionDetail>(hInstruction).GetValueOrDefault();
			AddressSize = nativeInstructionDetail.AddressSize;
			AvxConditionCode = nativeInstructionDetail.AvxConditionCode;
			AvxRoundingMode = nativeInstructionDetail.AvxRoundingMode;
			AvxSuppressAllExceptions = nativeInstructionDetail.AvxSuppressAllExceptions;
			Displacement = nativeInstructionDetail.Displacement;
			EFlags = nativeInstructionDetail.Flag.EFlags;
			Encoding = new X86Encoding(ref nativeInstructionDetail.Encoding);
			FpuFlags = nativeInstructionDetail.Flag.FpuFlags;
			ModRm = nativeInstructionDetail.ModRm;
			Opcode = nativeInstructionDetail.Opcode;
			Operands = X86Operand.Create(disassembler, ref nativeInstructionDetail);
			Prefix = nativeInstructionDetail.Prefix;
			Rex = nativeInstructionDetail.Rex;
			Sib = nativeInstructionDetail.Sib;
			SibBase = X86Register.TryCreate(disassembler, nativeInstructionDetail.SibBase);
			SibIndex = X86Register.TryCreate(disassembler, nativeInstructionDetail.SibIndex);
			SibScale = nativeInstructionDetail.SibScale;
			SseConditionCode = nativeInstructionDetail.SseConditionCode;
			XopConditionCode = nativeInstructionDetail.XopConditionCode;
		}

		internal X86InstructionDetail Create()
		{
			return new X86InstructionDetail(this);
		}

		private protected override X86DisassembleMode CreateDisassembleMode(NativeDisassembleMode nativeDisassembleMode)
		{
			return (X86DisassembleMode)nativeDisassembleMode;
		}

		private protected override X86InstructionGroup CreateInstructionGroup(CapstoneDisassembler disassembler, byte instructionGroupId)
		{
			return X86InstructionGroup.Create(disassembler, (X86InstructionGroupId)instructionGroupId);
		}

		private protected override X86Register CreateRegister(CapstoneDisassembler disassembler, short registerId)
		{
			return X86Register.TryCreate(disassembler, (X86RegisterId)registerId);
		}
	}
	public sealed class X86InstructionGroup : InstructionGroup<X86InstructionGroupId>
	{
		internal static X86InstructionGroup Create(CapstoneDisassembler disassembler, X86InstructionGroupId id)
		{
			string instructionGroupName = NativeCapstone.GetInstructionGroupName(disassembler.Handle, (int)id);
			return new X86InstructionGroup(id, instructionGroupName);
		}

		internal X86InstructionGroup(X86InstructionGroupId id, string name)
			: base(id, name)
		{
		}
	}
	public enum X86InstructionGroupId : byte
	{
		Invalid = 0,
		X86_GRP_JUMP = 1,
		X86_GRP_CALL = 2,
		X86_GRP_RET = 3,
		X86_GRP_INT = 4,
		X86_GRP_IRET = 5,
		X86_GRP_PRIVILEGE = 6,
		X86_GRP_BRANCH_RELATIVE = 7,
		X86_GRP_VM = 128,
		X86_GRP_3DNOW = 129,
		X86_GRP_AES = 130,
		X86_GRP_ADX = 131,
		X86_GRP_AVX = 132,
		X86_GRP_AVX2 = 133,
		X86_GRP_AVX512 = 134,
		X86_GRP_BMI = 135,
		X86_GRP_BMI2 = 136,
		X86_GRP_CMOV = 137,
		X86_GRP_F16C = 138,
		X86_GRP_FMA = 139,
		X86_GRP_FMA4 = 140,
		X86_GRP_FSGSBASE = 141,
		X86_GRP_HLE = 142,
		X86_GRP_MMX = 143,
		X86_GRP_MODE32 = 144,
		X86_GRP_MODE64 = 145,
		X86_GRP_RTM = 146,
		X86_GRP_SHA = 147,
		X86_GRP_SSE1 = 148,
		X86_GRP_SSE2 = 149,
		X86_GRP_SSE3 = 150,
		X86_GRP_SSE41 = 151,
		X86_GRP_SSE42 = 152,
		X86_GRP_SSE4A = 153,
		X86_GRP_SSSE3 = 154,
		X86_GRP_PCLMUL = 155,
		X86_GRP_XOP = 156,
		X86_GRP_CDI = 157,
		X86_GRP_ERI = 158,
		X86_GRP_TBM = 159,
		X86_GRP_16BITMODE = 160,
		X86_GRP_NOT64BITMODE = 161,
		X86_GRP_SGX = 162,
		X86_GRP_DQI = 163,
		X86_GRP_BWI = 164,
		X86_GRP_PFI = 165,
		X86_GRP_VLX = 166,
		X86_GRP_SMAP = 167,
		X86_GRP_NOVLX = 168,
		X86_GRP_FPU = 169
	}
	public enum X86InstructionId
	{
		Invalid,
		X86_INS_AAA,
		X86_INS_AAD,
		X86_INS_AAM,
		X86_INS_AAS,
		X86_INS_FABS,
		X86_INS_ADC,
		X86_INS_ADCX,
		X86_INS_ADD,
		X86_INS_ADDPD,
		X86_INS_ADDPS,
		X86_INS_ADDSD,
		X86_INS_ADDSS,
		X86_INS_ADDSUBPD,
		X86_INS_ADDSUBPS,
		X86_INS_FADD,
		X86_INS_FIADD,
		X86_INS_FADDP,
		X86_INS_ADOX,
		X86_INS_AESDECLAST,
		X86_INS_AESDEC,
		X86_INS_AESENCLAST,
		X86_INS_AESENC,
		X86_INS_AESIMC,
		X86_INS_AESKEYGENASSIST,
		X86_INS_AND,
		X86_INS_ANDN,
		X86_INS_ANDNPD,
		X86_INS_ANDNPS,
		X86_INS_ANDPD,
		X86_INS_ANDPS,
		X86_INS_ARPL,
		X86_INS_BEXTR,
		X86_INS_BLCFILL,
		X86_INS_BLCI,
		X86_INS_BLCIC,
		X86_INS_BLCMSK,
		X86_INS_BLCS,
		X86_INS_BLENDPD,
		X86_INS_BLENDPS,
		X86_INS_BLENDVPD,
		X86_INS_BLENDVPS,
		X86_INS_BLSFILL,
		X86_INS_BLSI,
		X86_INS_BLSIC,
		X86_INS_BLSMSK,
		X86_INS_BLSR,
		X86_INS_BOUND,
		X86_INS_BSF,
		X86_INS_BSR,
		X86_INS_BSWAP,
		X86_INS_BT,
		X86_INS_BTC,
		X86_INS_BTR,
		X86_INS_BTS,
		X86_INS_BZHI,
		X86_INS_CALL,
		X86_INS_CBW,
		X86_INS_CDQ,
		X86_INS_CDQE,
		X86_INS_FCHS,
		X86_INS_CLAC,
		X86_INS_CLC,
		X86_INS_CLD,
		X86_INS_CLFLUSH,
		X86_INS_CLFLUSHOPT,
		X86_INS_CLGI,
		X86_INS_CLI,
		X86_INS_CLTS,
		X86_INS_CLWB,
		X86_INS_CMC,
		X86_INS_CMOVA,
		X86_INS_CMOVAE,
		X86_INS_CMOVB,
		X86_INS_CMOVBE,
		X86_INS_FCMOVBE,
		X86_INS_FCMOVB,
		X86_INS_CMOVE,
		X86_INS_FCMOVE,
		X86_INS_CMOVG,
		X86_INS_CMOVGE,
		X86_INS_CMOVL,
		X86_INS_CMOVLE,
		X86_INS_FCMOVNBE,
		X86_INS_FCMOVNB,
		X86_INS_CMOVNE,
		X86_INS_FCMOVNE,
		X86_INS_CMOVNO,
		X86_INS_CMOVNP,
		X86_INS_FCMOVNU,
		X86_INS_CMOVNS,
		X86_INS_CMOVO,
		X86_INS_CMOVP,
		X86_INS_FCMOVU,
		X86_INS_CMOVS,
		X86_INS_CMP,
		X86_INS_CMPSB,
		X86_INS_CMPSQ,
		X86_INS_CMPSW,
		X86_INS_CMPXCHG16B,
		X86_INS_CMPXCHG,
		X86_INS_CMPXCHG8B,
		X86_INS_COMISD,
		X86_INS_COMISS,
		X86_INS_FCOMP,
		X86_INS_FCOMIP,
		X86_INS_FCOMI,
		X86_INS_FCOM,
		X86_INS_FCOS,
		X86_INS_CPUID,
		X86_INS_CQO,
		X86_INS_CRC32,
		X86_INS_CVTDQ2PD,
		X86_INS_CVTDQ2PS,
		X86_INS_CVTPD2DQ,
		X86_INS_CVTPD2PS,
		X86_INS_CVTPS2DQ,
		X86_INS_CVTPS2PD,
		X86_INS_CVTSD2SI,
		X86_INS_CVTSD2SS,
		X86_INS_CVTSI2SD,
		X86_INS_CVTSI2SS,
		X86_INS_CVTSS2SD,
		X86_INS_CVTSS2SI,
		X86_INS_CVTTPD2DQ,
		X86_INS_CVTTPS2DQ,
		X86_INS_CVTTSD2SI,
		X86_INS_CVTTSS2SI,
		X86_INS_CWD,
		X86_INS_CWDE,
		X86_INS_DAA,
		X86_INS_DAS,
		X86_INS_DATA16,
		X86_INS_DEC,
		X86_INS_DIV,
		X86_INS_DIVPD,
		X86_INS_DIVPS,
		X86_INS_FDIVR,
		X86_INS_FIDIVR,
		X86_INS_FDIVRP,
		X86_INS_DIVSD,
		X86_INS_DIVSS,
		X86_INS_FDIV,
		X86_INS_FIDIV,
		X86_INS_FDIVP,
		X86_INS_DPPD,
		X86_INS_DPPS,
		X86_INS_RET,
		X86_INS_ENCLS,
		X86_INS_ENCLU,
		X86_INS_ENTER,
		X86_INS_EXTRACTPS,
		X86_INS_EXTRQ,
		X86_INS_F2XM1,
		X86_INS_LCALL,
		X86_INS_LJMP,
		X86_INS_FBLD,
		X86_INS_FBSTP,
		X86_INS_FCOMPP,
		X86_INS_FDECSTP,
		X86_INS_FEMMS,
		X86_INS_FFREE,
		X86_INS_FICOM,
		X86_INS_FICOMP,
		X86_INS_FINCSTP,
		X86_INS_FLDCW,
		X86_INS_FLDENV,
		X86_INS_FLDL2E,
		X86_INS_FLDL2T,
		X86_INS_FLDLG2,
		X86_INS_FLDLN2,
		X86_INS_FLDPI,
		X86_INS_FNCLEX,
		X86_INS_FNINIT,
		X86_INS_FNOP,
		X86_INS_FNSTCW,
		X86_INS_FNSTSW,
		X86_INS_FPATAN,
		X86_INS_FPREM,
		X86_INS_FPREM1,
		X86_INS_FPTAN,
		X86_INS_FFREEP,
		X86_INS_FRNDINT,
		X86_INS_FRSTOR,
		X86_INS_FNSAVE,
		X86_INS_FSCALE,
		X86_INS_FSETPM,
		X86_INS_FSINCOS,
		X86_INS_FNSTENV,
		X86_INS_FXAM,
		X86_INS_FXRSTOR,
		X86_INS_FXRSTOR64,
		X86_INS_FXSAVE,
		X86_INS_FXSAVE64,
		X86_INS_FXTRACT,
		X86_INS_FYL2X,
		X86_INS_FYL2XP1,
		X86_INS_MOVAPD,
		X86_INS_MOVAPS,
		X86_INS_ORPD,
		X86_INS_ORPS,
		X86_INS_VMOVAPD,
		X86_INS_VMOVAPS,
		X86_INS_XORPD,
		X86_INS_XORPS,
		X86_INS_GETSEC,
		X86_INS_HADDPD,
		X86_INS_HADDPS,
		X86_INS_HLT,
		X86_INS_HSUBPD,
		X86_INS_HSUBPS,
		X86_INS_IDIV,
		X86_INS_FILD,
		X86_INS_IMUL,
		X86_INS_IN,
		X86_INS_INC,
		X86_INS_INSB,
		X86_INS_INSERTPS,
		X86_INS_INSERTQ,
		X86_INS_INSD,
		X86_INS_INSW,
		X86_INS_INT,
		X86_INS_INT1,
		X86_INS_INT3,
		X86_INS_INTO,
		X86_INS_INVD,
		X86_INS_INVEPT,
		X86_INS_INVLPG,
		X86_INS_INVLPGA,
		X86_INS_INVPCID,
		X86_INS_INVVPID,
		X86_INS_IRET,
		X86_INS_IRETD,
		X86_INS_IRETQ,
		X86_INS_FISTTP,
		X86_INS_FIST,
		X86_INS_FISTP,
		X86_INS_UCOMISD,
		X86_INS_UCOMISS,
		X86_INS_VCOMISD,
		X86_INS_VCOMISS,
		X86_INS_VCVTSD2SS,
		X86_INS_VCVTSI2SD,
		X86_INS_VCVTSI2SS,
		X86_INS_VCVTSS2SD,
		X86_INS_VCVTTSD2SI,
		X86_INS_VCVTTSD2USI,
		X86_INS_VCVTTSS2SI,
		X86_INS_VCVTTSS2USI,
		X86_INS_VCVTUSI2SD,
		X86_INS_VCVTUSI2SS,
		X86_INS_VUCOMISD,
		X86_INS_VUCOMISS,
		X86_INS_JAE,
		X86_INS_JA,
		X86_INS_JBE,
		X86_INS_JB,
		X86_INS_JCXZ,
		X86_INS_JECXZ,
		X86_INS_JE,
		X86_INS_JGE,
		X86_INS_JG,
		X86_INS_JLE,
		X86_INS_JL,
		X86_INS_JMP,
		X86_INS_JNE,
		X86_INS_JNO,
		X86_INS_JNP,
		X86_INS_JNS,
		X86_INS_JO,
		X86_INS_JP,
		X86_INS_JRCXZ,
		X86_INS_JS,
		X86_INS_KANDB,
		X86_INS_KANDD,
		X86_INS_KANDNB,
		X86_INS_KANDND,
		X86_INS_KANDNQ,
		X86_INS_KANDNW,
		X86_INS_KANDQ,
		X86_INS_KANDW,
		X86_INS_KMOVB,
		X86_INS_KMOVD,
		X86_INS_KMOVQ,
		X86_INS_KMOVW,
		X86_INS_KNOTB,
		X86_INS_KNOTD,
		X86_INS_KNOTQ,
		X86_INS_KNOTW,
		X86_INS_KORB,
		X86_INS_KORD,
		X86_INS_KORQ,
		X86_INS_KORTESTB,
		X86_INS_KORTESTD,
		X86_INS_KORTESTQ,
		X86_INS_KORTESTW,
		X86_INS_KORW,
		X86_INS_KSHIFTLB,
		X86_INS_KSHIFTLD,
		X86_INS_KSHIFTLQ,
		X86_INS_KSHIFTLW,
		X86_INS_KSHIFTRB,
		X86_INS_KSHIFTRD,
		X86_INS_KSHIFTRQ,
		X86_INS_KSHIFTRW,
		X86_INS_KUNPCKBW,
		X86_INS_KXNORB,
		X86_INS_KXNORD,
		X86_INS_KXNORQ,
		X86_INS_KXNORW,
		X86_INS_KXORB,
		X86_INS_KXORD,
		X86_INS_KXORQ,
		X86_INS_KXORW,
		X86_INS_LAHF,
		X86_INS_LAR,
		X86_INS_LDDQU,
		X86_INS_LDMXCSR,
		X86_INS_LDS,
		X86_INS_FLDZ,
		X86_INS_FLD1,
		X86_INS_FLD,
		X86_INS_LEA,
		X86_INS_LEAVE,
		X86_INS_LES,
		X86_INS_LFENCE,
		X86_INS_LFS,
		X86_INS_LGDT,
		X86_INS_LGS,
		X86_INS_LIDT,
		X86_INS_LLDT,
		X86_INS_LMSW,
		X86_INS_OR,
		X86_INS_SUB,
		X86_INS_XOR,
		X86_INS_LODSB,
		X86_INS_LODSD,
		X86_INS_LODSQ,
		X86_INS_LODSW,
		X86_INS_LOOP,
		X86_INS_LOOPE,
		X86_INS_LOOPNE,
		X86_INS_RETF,
		X86_INS_RETFQ,
		X86_INS_LSL,
		X86_INS_LSS,
		X86_INS_LTR,
		X86_INS_XADD,
		X86_INS_LZCNT,
		X86_INS_MASKMOVDQU,
		X86_INS_MAXPD,
		X86_INS_MAXPS,
		X86_INS_MAXSD,
		X86_INS_MAXSS,
		X86_INS_MFENCE,
		X86_INS_MINPD,
		X86_INS_MINPS,
		X86_INS_MINSD,
		X86_INS_MINSS,
		X86_INS_CVTPD2PI,
		X86_INS_CVTPI2PD,
		X86_INS_CVTPI2PS,
		X86_INS_CVTPS2PI,
		X86_INS_CVTTPD2PI,
		X86_INS_CVTTPS2PI,
		X86_INS_EMMS,
		X86_INS_MASKMOVQ,
		X86_INS_MOVD,
		X86_INS_MOVDQ2Q,
		X86_INS_MOVNTQ,
		X86_INS_MOVQ2DQ,
		X86_INS_MOVQ,
		X86_INS_PABSB,
		X86_INS_PABSD,
		X86_INS_PABSW,
		X86_INS_PACKSSDW,
		X86_INS_PACKSSWB,
		X86_INS_PACKUSWB,
		X86_INS_PADDB,
		X86_INS_PADDD,
		X86_INS_PADDQ,
		X86_INS_PADDSB,
		X86_INS_PADDSW,
		X86_INS_PADDUSB,
		X86_INS_PADDUSW,
		X86_INS_PADDW,
		X86_INS_PALIGNR,
		X86_INS_PANDN,
		X86_INS_PAND,
		X86_INS_PAVGB,
		X86_INS_PAVGW,
		X86_INS_PCMPEQB,
		X86_INS_PCMPEQD,
		X86_INS_PCMPEQW,
		X86_INS_PCMPGTB,
		X86_INS_PCMPGTD,
		X86_INS_PCMPGTW,
		X86_INS_PEXTRW,
		X86_INS_PHADDSW,
		X86_INS_PHADDW,
		X86_INS_PHADDD,
		X86_INS_PHSUBD,
		X86_INS_PHSUBSW,
		X86_INS_PHSUBW,
		X86_INS_PINSRW,
		X86_INS_PMADDUBSW,
		X86_INS_PMADDWD,
		X86_INS_PMAXSW,
		X86_INS_PMAXUB,
		X86_INS_PMINSW,
		X86_INS_PMINUB,
		X86_INS_PMOVMSKB,
		X86_INS_PMULHRSW,
		X86_INS_PMULHUW,
		X86_INS_PMULHW,
		X86_INS_PMULLW,
		X86_INS_PMULUDQ,
		X86_INS_POR,
		X86_INS_PSADBW,
		X86_INS_PSHUFB,
		X86_INS_PSHUFW,
		X86_INS_PSIGNB,
		X86_INS_PSIGND,
		X86_INS_PSIGNW,
		X86_INS_PSLLD,
		X86_INS_PSLLQ,
		X86_INS_PSLLW,
		X86_INS_PSRAD,
		X86_INS_PSRAW,
		X86_INS_PSRLD,
		X86_INS_PSRLQ,
		X86_INS_PSRLW,
		X86_INS_PSUBB,
		X86_INS_PSUBD,
		X86_INS_PSUBQ,
		X86_INS_PSUBSB,
		X86_INS_PSUBSW,
		X86_INS_PSUBUSB,
		X86_INS_PSUBUSW,
		X86_INS_PSUBW,
		X86_INS_PUNPCKHBW,
		X86_INS_PUNPCKHDQ,
		X86_INS_PUNPCKHWD,
		X86_INS_PUNPCKLBW,
		X86_INS_PUNPCKLDQ,
		X86_INS_PUNPCKLWD,
		X86_INS_PXOR,
		X86_INS_MONITOR,
		X86_INS_MONTMUL,
		X86_INS_MOV,
		X86_INS_MOVABS,
		X86_INS_MOVBE,
		X86_INS_MOVDDUP,
		X86_INS_MOVDQA,
		X86_INS_MOVDQU,
		X86_INS_MOVHLPS,
		X86_INS_MOVHPD,
		X86_INS_MOVHPS,
		X86_INS_MOVLHPS,
		X86_INS_MOVLPD,
		X86_INS_MOVLPS,
		X86_INS_MOVMSKPD,
		X86_INS_MOVMSKPS,
		X86_INS_MOVNTDQA,
		X86_INS_MOVNTDQ,
		X86_INS_MOVNTI,
		X86_INS_MOVNTPD,
		X86_INS_MOVNTPS,
		X86_INS_MOVNTSD,
		X86_INS_MOVNTSS,
		X86_INS_MOVSB,
		X86_INS_MOVSD,
		X86_INS_MOVSHDUP,
		X86_INS_MOVSLDUP,
		X86_INS_MOVSQ,
		X86_INS_MOVSS,
		X86_INS_MOVSW,
		X86_INS_MOVSX,
		X86_INS_MOVSXD,
		X86_INS_MOVUPD,
		X86_INS_MOVUPS,
		X86_INS_MOVZX,
		X86_INS_MPSADBW,
		X86_INS_MUL,
		X86_INS_MULPD,
		X86_INS_MULPS,
		X86_INS_MULSD,
		X86_INS_MULSS,
		X86_INS_MULX,
		X86_INS_FMUL,
		X86_INS_FIMUL,
		X86_INS_FMULP,
		X86_INS_MWAIT,
		X86_INS_NEG,
		X86_INS_NOP,
		X86_INS_NOT,
		X86_INS_OUT,
		X86_INS_OUTSB,
		X86_INS_OUTSD,
		X86_INS_OUTSW,
		X86_INS_PACKUSDW,
		X86_INS_PAUSE,
		X86_INS_PAVGUSB,
		X86_INS_PBLENDVB,
		X86_INS_PBLENDW,
		X86_INS_PCLMULQDQ,
		X86_INS_PCMPEQQ,
		X86_INS_PCMPESTRI,
		X86_INS_PCMPESTRM,
		X86_INS_PCMPGTQ,
		X86_INS_PCMPISTRI,
		X86_INS_PCMPISTRM,
		X86_INS_PCOMMIT,
		X86_INS_PDEP,
		X86_INS_PEXT,
		X86_INS_PEXTRB,
		X86_INS_PEXTRD,
		X86_INS_PEXTRQ,
		X86_INS_PF2ID,
		X86_INS_PF2IW,
		X86_INS_PFACC,
		X86_INS_PFADD,
		X86_INS_PFCMPEQ,
		X86_INS_PFCMPGE,
		X86_INS_PFCMPGT,
		X86_INS_PFMAX,
		X86_INS_PFMIN,
		X86_INS_PFMUL,
		X86_INS_PFNACC,
		X86_INS_PFPNACC,
		X86_INS_PFRCPIT1,
		X86_INS_PFRCPIT2,
		X86_INS_PFRCP,
		X86_INS_PFRSQIT1,
		X86_INS_PFRSQRT,
		X86_INS_PFSUBR,
		X86_INS_PFSUB,
		X86_INS_PHMINPOSUW,
		X86_INS_PI2FD,
		X86_INS_PI2FW,
		X86_INS_PINSRB,
		X86_INS_PINSRD,
		X86_INS_PINSRQ,
		X86_INS_PMAXSB,
		X86_INS_PMAXSD,
		X86_INS_PMAXUD,
		X86_INS_PMAXUW,
		X86_INS_PMINSB,
		X86_INS_PMINSD,
		X86_INS_PMINUD,
		X86_INS_PMINUW,
		X86_INS_PMOVSXBD,
		X86_INS_PMOVSXBQ,
		X86_INS_PMOVSXBW,
		X86_INS_PMOVSXDQ,
		X86_INS_PMOVSXWD,
		X86_INS_PMOVSXWQ,
		X86_INS_PMOVZXBD,
		X86_INS_PMOVZXBQ,
		X86_INS_PMOVZXBW,
		X86_INS_PMOVZXDQ,
		X86_INS_PMOVZXWD,
		X86_INS_PMOVZXWQ,
		X86_INS_PMULDQ,
		X86_INS_PMULHRW,
		X86_INS_PMULLD,
		X86_INS_POP,
		X86_INS_POPAW,
		X86_INS_POPAL,
		X86_INS_POPCNT,
		X86_INS_POPF,
		X86_INS_POPFD,
		X86_INS_POPFQ,
		X86_INS_PREFETCH,
		X86_INS_PREFETCHNTA,
		X86_INS_PREFETCHT0,
		X86_INS_PREFETCHT1,
		X86_INS_PREFETCHT2,
		X86_INS_PREFETCHW,
		X86_INS_PSHUFD,
		X86_INS_PSHUFHW,
		X86_INS_PSHUFLW,
		X86_INS_PSLLDQ,
		X86_INS_PSRLDQ,
		X86_INS_PSWAPD,
		X86_INS_PTEST,
		X86_INS_PUNPCKHQDQ,
		X86_INS_PUNPCKLQDQ,
		X86_INS_PUSH,
		X86_INS_PUSHAW,
		X86_INS_PUSHAL,
		X86_INS_PUSHF,
		X86_INS_PUSHFD,
		X86_INS_PUSHFQ,
		X86_INS_RCL,
		X86_INS_RCPPS,
		X86_INS_RCPSS,
		X86_INS_RCR,
		X86_INS_RDFSBASE,
		X86_INS_RDGSBASE,
		X86_INS_RDMSR,
		X86_INS_RDPMC,
		X86_INS_RDRAND,
		X86_INS_RDSEED,
		X86_INS_RDTSC,
		X86_INS_RDTSCP,
		X86_INS_ROL,
		X86_INS_ROR,
		X86_INS_RORX,
		X86_INS_ROUNDPD,
		X86_INS_ROUNDPS,
		X86_INS_ROUNDSD,
		X86_INS_ROUNDSS,
		X86_INS_RSM,
		X86_INS_RSQRTPS,
		X86_INS_RSQRTSS,
		X86_INS_SAHF,
		X86_INS_SAL,
		X86_INS_SALC,
		X86_INS_SAR,
		X86_INS_SARX,
		X86_INS_SBB,
		X86_INS_SCASB,
		X86_INS_SCASD,
		X86_INS_SCASQ,
		X86_INS_SCASW,
		X86_INS_SETAE,
		X86_INS_SETA,
		X86_INS_SETBE,
		X86_INS_SETB,
		X86_INS_SETE,
		X86_INS_SETGE,
		X86_INS_SETG,
		X86_INS_SETLE,
		X86_INS_SETL,
		X86_INS_SETNE,
		X86_INS_SETNO,
		X86_INS_SETNP,
		X86_INS_SETNS,
		X86_INS_SETO,
		X86_INS_SETP,
		X86_INS_SETS,
		X86_INS_SFENCE,
		X86_INS_SGDT,
		X86_INS_SHA1MSG1,
		X86_INS_SHA1MSG2,
		X86_INS_SHA1NEXTE,
		X86_INS_SHA1RNDS4,
		X86_INS_SHA256MSG1,
		X86_INS_SHA256MSG2,
		X86_INS_SHA256RNDS2,
		X86_INS_SHL,
		X86_INS_SHLD,
		X86_INS_SHLX,
		X86_INS_SHR,
		X86_INS_SHRD,
		X86_INS_SHRX,
		X86_INS_SHUFPD,
		X86_INS_SHUFPS,
		X86_INS_SIDT,
		X86_INS_FSIN,
		X86_INS_SKINIT,
		X86_INS_SLDT,
		X86_INS_SMSW,
		X86_INS_SQRTPD,
		X86_INS_SQRTPS,
		X86_INS_SQRTSD,
		X86_INS_SQRTSS,
		X86_INS_FSQRT,
		X86_INS_STAC,
		X86_INS_STC,
		X86_INS_STD,
		X86_INS_STGI,
		X86_INS_STI,
		X86_INS_STMXCSR,
		X86_INS_STOSB,
		X86_INS_STOSD,
		X86_INS_STOSQ,
		X86_INS_STOSW,
		X86_INS_STR,
		X86_INS_FST,
		X86_INS_FSTP,
		X86_INS_FSTPNCE,
		X86_INS_FXCH,
		X86_INS_SUBPD,
		X86_INS_SUBPS,
		X86_INS_FSUBR,
		X86_INS_FISUBR,
		X86_INS_FSUBRP,
		X86_INS_SUBSD,
		X86_INS_SUBSS,
		X86_INS_FSUB,
		X86_INS_FISUB,
		X86_INS_FSUBP,
		X86_INS_SWAPGS,
		X86_INS_SYSCALL,
		X86_INS_SYSENTER,
		X86_INS_SYSEXIT,
		X86_INS_SYSRET,
		X86_INS_T1MSKC,
		X86_INS_TEST,
		X86_INS_UD2,
		X86_INS_FTST,
		X86_INS_TZCNT,
		X86_INS_TZMSK,
		X86_INS_FUCOMIP,
		X86_INS_FUCOMI,
		X86_INS_FUCOMPP,
		X86_INS_FUCOMP,
		X86_INS_FUCOM,
		X86_INS_UD2B,
		X86_INS_UNPCKHPD,
		X86_INS_UNPCKHPS,
		X86_INS_UNPCKLPD,
		X86_INS_UNPCKLPS,
		X86_INS_VADDPD,
		X86_INS_VADDPS,
		X86_INS_VADDSD,
		X86_INS_VADDSS,
		X86_INS_VADDSUBPD,
		X86_INS_VADDSUBPS,
		X86_INS_VAESDECLAST,
		X86_INS_VAESDEC,
		X86_INS_VAESENCLAST,
		X86_INS_VAESENC,
		X86_INS_VAESIMC,
		X86_INS_VAESKEYGENASSIST,
		X86_INS_VALIGND,
		X86_INS_VALIGNQ,
		X86_INS_VANDNPD,
		X86_INS_VANDNPS,
		X86_INS_VANDPD,
		X86_INS_VANDPS,
		X86_INS_VBLENDMPD,
		X86_INS_VBLENDMPS,
		X86_INS_VBLENDPD,
		X86_INS_VBLENDPS,
		X86_INS_VBLENDVPD,
		X86_INS_VBLENDVPS,
		X86_INS_VBROADCASTF128,
		X86_INS_VBROADCASTI32X4,
		X86_INS_VBROADCASTI64X4,
		X86_INS_VBROADCASTSD,
		X86_INS_VBROADCASTSS,
		X86_INS_VCOMPRESSPD,
		X86_INS_VCOMPRESSPS,
		X86_INS_VCVTDQ2PD,
		X86_INS_VCVTDQ2PS,
		X86_INS_VCVTPD2DQX,
		X86_INS_VCVTPD2DQ,
		X86_INS_VCVTPD2PSX,
		X86_INS_VCVTPD2PS,
		X86_INS_VCVTPD2UDQ,
		X86_INS_VCVTPH2PS,
		X86_INS_VCVTPS2DQ,
		X86_INS_VCVTPS2PD,
		X86_INS_VCVTPS2PH,
		X86_INS_VCVTPS2UDQ,
		X86_INS_VCVTSD2SI,
		X86_INS_VCVTSD2USI,
		X86_INS_VCVTSS2SI,
		X86_INS_VCVTSS2USI,
		X86_INS_VCVTTPD2DQX,
		X86_INS_VCVTTPD2DQ,
		X86_INS_VCVTTPD2UDQ,
		X86_INS_VCVTTPS2DQ,
		X86_INS_VCVTTPS2UDQ,
		X86_INS_VCVTUDQ2PD,
		X86_INS_VCVTUDQ2PS,
		X86_INS_VDIVPD,
		X86_INS_VDIVPS,
		X86_INS_VDIVSD,
		X86_INS_VDIVSS,
		X86_INS_VDPPD,
		X86_INS_VDPPS,
		X86_INS_VERR,
		X86_INS_VERW,
		X86_INS_VEXP2PD,
		X86_INS_VEXP2PS,
		X86_INS_VEXPANDPD,
		X86_INS_VEXPANDPS,
		X86_INS_VEXTRACTF128,
		X86_INS_VEXTRACTF32X4,
		X86_INS_VEXTRACTF64X4,
		X86_INS_VEXTRACTI128,
		X86_INS_VEXTRACTI32X4,
		X86_INS_VEXTRACTI64X4,
		X86_INS_VEXTRACTPS,
		X86_INS_VFMADD132PD,
		X86_INS_VFMADD132PS,
		X86_INS_VFMADDPD,
		X86_INS_VFMADD213PD,
		X86_INS_VFMADD231PD,
		X86_INS_VFMADDPS,
		X86_INS_VFMADD213PS,
		X86_INS_VFMADD231PS,
		X86_INS_VFMADDSD,
		X86_INS_VFMADD213SD,
		X86_INS_VFMADD132SD,
		X86_INS_VFMADD231SD,
		X86_INS_VFMADDSS,
		X86_INS_VFMADD213SS,
		X86_INS_VFMADD132SS,
		X86_INS_VFMADD231SS,
		X86_INS_VFMADDSUB132PD,
		X86_INS_VFMADDSUB132PS,
		X86_INS_VFMADDSUBPD,
		X86_INS_VFMADDSUB213PD,
		X86_INS_VFMADDSUB231PD,
		X86_INS_VFMADDSUBPS,
		X86_INS_VFMADDSUB213PS,
		X86_INS_VFMADDSUB231PS,
		X86_INS_VFMSUB132PD,
		X86_INS_VFMSUB132PS,
		X86_INS_VFMSUBADD132PD,
		X86_INS_VFMSUBADD132PS,
		X86_INS_VFMSUBADDPD,
		X86_INS_VFMSUBADD213PD,
		X86_INS_VFMSUBADD231PD,
		X86_INS_VFMSUBADDPS,
		X86_INS_VFMSUBADD213PS,
		X86_INS_VFMSUBADD231PS,
		X86_INS_VFMSUBPD,
		X86_INS_VFMSUB213PD,
		X86_INS_VFMSUB231PD,
		X86_INS_VFMSUBPS,
		X86_INS_VFMSUB213PS,
		X86_INS_VFMSUB231PS,
		X86_INS_VFMSUBSD,
		X86_INS_VFMSUB213SD,
		X86_INS_VFMSUB132SD,
		X86_INS_VFMSUB231SD,
		X86_INS_VFMSUBSS,
		X86_INS_VFMSUB213SS,
		X86_INS_VFMSUB132SS,
		X86_INS_VFMSUB231SS,
		X86_INS_VFNMADD132PD,
		X86_INS_VFNMADD132PS,
		X86_INS_VFNMADDPD,
		X86_INS_VFNMADD213PD,
		X86_INS_VFNMADD231PD,
		X86_INS_VFNMADDPS,
		X86_INS_VFNMADD213PS,
		X86_INS_VFNMADD231PS,
		X86_INS_VFNMADDSD,
		X86_INS_VFNMADD213SD,
		X86_INS_VFNMADD132SD,
		X86_INS_VFNMADD231SD,
		X86_INS_VFNMADDSS,
		X86_INS_VFNMADD213SS,
		X86_INS_VFNMADD132SS,
		X86_INS_VFNMADD231SS,
		X86_INS_VFNMSUB132PD,
		X86_INS_VFNMSUB132PS,
		X86_INS_VFNMSUBPD,
		X86_INS_VFNMSUB213PD,
		X86_INS_VFNMSUB231PD,
		X86_INS_VFNMSUBPS,
		X86_INS_VFNMSUB213PS,
		X86_INS_VFNMSUB231PS,
		X86_INS_VFNMSUBSD,
		X86_INS_VFNMSUB213SD,
		X86_INS_VFNMSUB132SD,
		X86_INS_VFNMSUB231SD,
		X86_INS_VFNMSUBSS,
		X86_INS_VFNMSUB213SS,
		X86_INS_VFNMSUB132SS,
		X86_INS_VFNMSUB231SS,
		X86_INS_VFRCZPD,
		X86_INS_VFRCZPS,
		X86_INS_VFRCZSD,
		X86_INS_VFRCZSS,
		X86_INS_VORPD,
		X86_INS_VORPS,
		X86_INS_VXORPD,
		X86_INS_VXORPS,
		X86_INS_VGATHERDPD,
		X86_INS_VGATHERDPS,
		X86_INS_VGATHERPF0DPD,
		X86_INS_VGATHERPF0DPS,
		X86_INS_VGATHERPF0QPD,
		X86_INS_VGATHERPF0QPS,
		X86_INS_VGATHERPF1DPD,
		X86_INS_VGATHERPF1DPS,
		X86_INS_VGATHERPF1QPD,
		X86_INS_VGATHERPF1QPS,
		X86_INS_VGATHERQPD,
		X86_INS_VGATHERQPS,
		X86_INS_VHADDPD,
		X86_INS_VHADDPS,
		X86_INS_VHSUBPD,
		X86_INS_VHSUBPS,
		X86_INS_VINSERTF128,
		X86_INS_VINSERTF32X4,
		X86_INS_VINSERTF32X8,
		X86_INS_VINSERTF64X2,
		X86_INS_VINSERTF64X4,
		X86_INS_VINSERTI128,
		X86_INS_VINSERTI32X4,
		X86_INS_VINSERTI32X8,
		X86_INS_VINSERTI64X2,
		X86_INS_VINSERTI64X4,
		X86_INS_VINSERTPS,
		X86_INS_VLDDQU,
		X86_INS_VLDMXCSR,
		X86_INS_VMASKMOVDQU,
		X86_INS_VMASKMOVPD,
		X86_INS_VMASKMOVPS,
		X86_INS_VMAXPD,
		X86_INS_VMAXPS,
		X86_INS_VMAXSD,
		X86_INS_VMAXSS,
		X86_INS_VMCALL,
		X86_INS_VMCLEAR,
		X86_INS_VMFUNC,
		X86_INS_VMINPD,
		X86_INS_VMINPS,
		X86_INS_VMINSD,
		X86_INS_VMINSS,
		X86_INS_VMLAUNCH,
		X86_INS_VMLOAD,
		X86_INS_VMMCALL,
		X86_INS_VMOVQ,
		X86_INS_VMOVDDUP,
		X86_INS_VMOVD,
		X86_INS_VMOVDQA32,
		X86_INS_VMOVDQA64,
		X86_INS_VMOVDQA,
		X86_INS_VMOVDQU16,
		X86_INS_VMOVDQU32,
		X86_INS_VMOVDQU64,
		X86_INS_VMOVDQU8,
		X86_INS_VMOVDQU,
		X86_INS_VMOVHLPS,
		X86_INS_VMOVHPD,
		X86_INS_VMOVHPS,
		X86_INS_VMOVLHPS,
		X86_INS_VMOVLPD,
		X86_INS_VMOVLPS,
		X86_INS_VMOVMSKPD,
		X86_INS_VMOVMSKPS,
		X86_INS_VMOVNTDQA,
		X86_INS_VMOVNTDQ,
		X86_INS_VMOVNTPD,
		X86_INS_VMOVNTPS,
		X86_INS_VMOVSD,
		X86_INS_VMOVSHDUP,
		X86_INS_VMOVSLDUP,
		X86_INS_VMOVSS,
		X86_INS_VMOVUPD,
		X86_INS_VMOVUPS,
		X86_INS_VMPSADBW,
		X86_INS_VMPTRLD,
		X86_INS_VMPTRST,
		X86_INS_VMREAD,
		X86_INS_VMRESUME,
		X86_INS_VMRUN,
		X86_INS_VMSAVE,
		X86_INS_VMULPD,
		X86_INS_VMULPS,
		X86_INS_VMULSD,
		X86_INS_VMULSS,
		X86_INS_VMWRITE,
		X86_INS_VMXOFF,
		X86_INS_VMXON,
		X86_INS_VPABSB,
		X86_INS_VPABSD,
		X86_INS_VPABSQ,
		X86_INS_VPABSW,
		X86_INS_VPACKSSDW,
		X86_INS_VPACKSSWB,
		X86_INS_VPACKUSDW,
		X86_INS_VPACKUSWB,
		X86_INS_VPADDB,
		X86_INS_VPADDD,
		X86_INS_VPADDQ,
		X86_INS_VPADDSB,
		X86_INS_VPADDSW,
		X86_INS_VPADDUSB,
		X86_INS_VPADDUSW,
		X86_INS_VPADDW,
		X86_INS_VPALIGNR,
		X86_INS_VPANDD,
		X86_INS_VPANDND,
		X86_INS_VPANDNQ,
		X86_INS_VPANDN,
		X86_INS_VPANDQ,
		X86_INS_VPAND,
		X86_INS_VPAVGB,
		X86_INS_VPAVGW,
		X86_INS_VPBLENDD,
		X86_INS_VPBLENDMB,
		X86_INS_VPBLENDMD,
		X86_INS_VPBLENDMQ,
		X86_INS_VPBLENDMW,
		X86_INS_VPBLENDVB,
		X86_INS_VPBLENDW,
		X86_INS_VPBROADCASTB,
		X86_INS_VPBROADCASTD,
		X86_INS_VPBROADCASTMB2Q,
		X86_INS_VPBROADCASTMW2D,
		X86_INS_VPBROADCASTQ,
		X86_INS_VPBROADCASTW,
		X86_INS_VPCLMULQDQ,
		X86_INS_VPCMOV,
		X86_INS_VPCMPB,
		X86_INS_VPCMPD,
		X86_INS_VPCMPEQB,
		X86_INS_VPCMPEQD,
		X86_INS_VPCMPEQQ,
		X86_INS_VPCMPEQW,
		X86_INS_VPCMPESTRI,
		X86_INS_VPCMPESTRM,
		X86_INS_VPCMPGTB,
		X86_INS_VPCMPGTD,
		X86_INS_VPCMPGTQ,
		X86_INS_VPCMPGTW,
		X86_INS_VPCMPISTRI,
		X86_INS_VPCMPISTRM,
		X86_INS_VPCMPQ,
		X86_INS_VPCMPUB,
		X86_INS_VPCMPUD,
		X86_INS_VPCMPUQ,
		X86_INS_VPCMPUW,
		X86_INS_VPCMPW,
		X86_INS_VPCOMB,
		X86_INS_VPCOMD,
		X86_INS_VPCOMPRESSD,
		X86_INS_VPCOMPRESSQ,
		X86_INS_VPCOMQ,
		X86_INS_VPCOMUB,
		X86_INS_VPCOMUD,
		X86_INS_VPCOMUQ,
		X86_INS_VPCOMUW,
		X86_INS_VPCOMW,
		X86_INS_VPCONFLICTD,
		X86_INS_VPCONFLICTQ,
		X86_INS_VPERM2F128,
		X86_INS_VPERM2I128,
		X86_INS_VPERMD,
		X86_INS_VPERMI2D,
		X86_INS_VPERMI2PD,
		X86_INS_VPERMI2PS,
		X86_INS_VPERMI2Q,
		X86_INS_VPERMIL2PD,
		X86_INS_VPERMIL2PS,
		X86_INS_VPERMILPD,
		X86_INS_VPERMILPS,
		X86_INS_VPERMPD,
		X86_INS_VPERMPS,
		X86_INS_VPERMQ,
		X86_INS_VPERMT2D,
		X86_INS_VPERMT2PD,
		X86_INS_VPERMT2PS,
		X86_INS_VPERMT2Q,
		X86_INS_VPEXPANDD,
		X86_INS_VPEXPANDQ,
		X86_INS_VPEXTRB,
		X86_INS_VPEXTRD,
		X86_INS_VPEXTRQ,
		X86_INS_VPEXTRW,
		X86_INS_VPGATHERDD,
		X86_INS_VPGATHERDQ,
		X86_INS_VPGATHERQD,
		X86_INS_VPGATHERQQ,
		X86_INS_VPHADDBD,
		X86_INS_VPHADDBQ,
		X86_INS_VPHADDBW,
		X86_INS_VPHADDDQ,
		X86_INS_VPHADDD,
		X86_INS_VPHADDSW,
		X86_INS_VPHADDUBD,
		X86_INS_VPHADDUBQ,
		X86_INS_VPHADDUBW,
		X86_INS_VPHADDUDQ,
		X86_INS_VPHADDUWD,
		X86_INS_VPHADDUWQ,
		X86_INS_VPHADDWD,
		X86_INS_VPHADDWQ,
		X86_INS_VPHADDW,
		X86_INS_VPHMINPOSUW,
		X86_INS_VPHSUBBW,
		X86_INS_VPHSUBDQ,
		X86_INS_VPHSUBD,
		X86_INS_VPHSUBSW,
		X86_INS_VPHSUBWD,
		X86_INS_VPHSUBW,
		X86_INS_VPINSRB,
		X86_INS_VPINSRD,
		X86_INS_VPINSRQ,
		X86_INS_VPINSRW,
		X86_INS_VPLZCNTD,
		X86_INS_VPLZCNTQ,
		X86_INS_VPMACSDD,
		X86_INS_VPMACSDQH,
		X86_INS_VPMACSDQL,
		X86_INS_VPMACSSDD,
		X86_INS_VPMACSSDQH,
		X86_INS_VPMACSSDQL,
		X86_INS_VPMACSSWD,
		X86_INS_VPMACSSWW,
		X86_INS_VPMACSWD,
		X86_INS_VPMACSWW,
		X86_INS_VPMADCSSWD,
		X86_INS_VPMADCSWD,
		X86_INS_VPMADDUBSW,
		X86_INS_VPMADDWD,
		X86_INS_VPMASKMOVD,
		X86_INS_VPMASKMOVQ,
		X86_INS_VPMAXSB,
		X86_INS_VPMAXSD,
		X86_INS_VPMAXSQ,
		X86_INS_VPMAXSW,
		X86_INS_VPMAXUB,
		X86_INS_VPMAXUD,
		X86_INS_VPMAXUQ,
		X86_INS_VPMAXUW,
		X86_INS_VPMINSB,
		X86_INS_VPMINSD,
		X86_INS_VPMINSQ,
		X86_INS_VPMINSW,
		X86_INS_VPMINUB,
		X86_INS_VPMINUD,
		X86_INS_VPMINUQ,
		X86_INS_VPMINUW,
		X86_INS_VPMOVDB,
		X86_INS_VPMOVDW,
		X86_INS_VPMOVM2B,
		X86_INS_VPMOVM2D,
		X86_INS_VPMOVM2Q,
		X86_INS_VPMOVM2W,
		X86_INS_VPMOVMSKB,
		X86_INS_VPMOVQB,
		X86_INS_VPMOVQD,
		X86_INS_VPMOVQW,
		X86_INS_VPMOVSDB,
		X86_INS_VPMOVSDW,
		X86_INS_VPMOVSQB,
		X86_INS_VPMOVSQD,
		X86_INS_VPMOVSQW,
		X86_INS_VPMOVSXBD,
		X86_INS_VPMOVSXBQ,
		X86_INS_VPMOVSXBW,
		X86_INS_VPMOVSXDQ,
		X86_INS_VPMOVSXWD,
		X86_INS_VPMOVSXWQ,
		X86_INS_VPMOVUSDB,
		X86_INS_VPMOVUSDW,
		X86_INS_VPMOVUSQB,
		X86_INS_VPMOVUSQD,
		X86_INS_VPMOVUSQW,
		X86_INS_VPMOVZXBD,
		X86_INS_VPMOVZXBQ,
		X86_INS_VPMOVZXBW,
		X86_INS_VPMOVZXDQ,
		X86_INS_VPMOVZXWD,
		X86_INS_VPMOVZXWQ,
		X86_INS_VPMULDQ,
		X86_INS_VPMULHRSW,
		X86_INS_VPMULHUW,
		X86_INS_VPMULHW,
		X86_INS_VPMULLD,
		X86_INS_VPMULLQ,
		X86_INS_VPMULLW,
		X86_INS_VPMULUDQ,
		X86_INS_VPORD,
		X86_INS_VPORQ,
		X86_INS_VPOR,
		X86_INS_VPPERM,
		X86_INS_VPROTB,
		X86_INS_VPROTD,
		X86_INS_VPROTQ,
		X86_INS_VPROTW,
		X86_INS_VPSADBW,
		X86_INS_VPSCATTERDD,
		X86_INS_VPSCATTERDQ,
		X86_INS_VPSCATTERQD,
		X86_INS_VPSCATTERQQ,
		X86_INS_VPSHAB,
		X86_INS_VPSHAD,
		X86_INS_VPSHAQ,
		X86_INS_VPSHAW,
		X86_INS_VPSHLB,
		X86_INS_VPSHLD,
		X86_INS_VPSHLQ,
		X86_INS_VPSHLW,
		X86_INS_VPSHUFB,
		X86_INS_VPSHUFD,
		X86_INS_VPSHUFHW,
		X86_INS_VPSHUFLW,
		X86_INS_VPSIGNB,
		X86_INS_VPSIGND,
		X86_INS_VPSIGNW,
		X86_INS_VPSLLDQ,
		X86_INS_VPSLLD,
		X86_INS_VPSLLQ,
		X86_INS_VPSLLVD,
		X86_INS_VPSLLVQ,
		X86_INS_VPSLLW,
		X86_INS_VPSRAD,
		X86_INS_VPSRAQ,
		X86_INS_VPSRAVD,
		X86_INS_VPSRAVQ,
		X86_INS_VPSRAW,
		X86_INS_VPSRLDQ,
		X86_INS_VPSRLD,
		X86_INS_VPSRLQ,
		X86_INS_VPSRLVD,
		X86_INS_VPSRLVQ,
		X86_INS_VPSRLW,
		X86_INS_VPSUBB,
		X86_INS_VPSUBD,
		X86_INS_VPSUBQ,
		X86_INS_VPSUBSB,
		X86_INS_VPSUBSW,
		X86_INS_VPSUBUSB,
		X86_INS_VPSUBUSW,
		X86_INS_VPSUBW,
		X86_INS_VPTESTMD,
	

BepInExPack/BepInEx/core/Iced.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Serialization;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using Iced.Intel.BlockEncoderInternal;
using Iced.Intel.DecoderInternal;
using Iced.Intel.EncoderInternal;
using Iced.Intel.FastFormatterInternal;
using Iced.Intel.FormatterInternal;
using Iced.Intel.GasFormatterInternal;
using Iced.Intel.InstructionInfoInternal;
using Iced.Intel.IntelFormatterInternal;
using Iced.Intel.Internal;
using Iced.Intel.MasmFormatterInternal;
using Iced.Intel.NasmFormatterInternal;
using Microsoft.CodeAnalysis;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("iced project and contributors <https://github.com/icedland>")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyCopyright("Copyright (C) 2018-present iced project and contributors")]
[assembly: AssemblyDescription("x86/x64 disassembler, assembler, instruction decoder")]
[assembly: AssemblyFileVersion("1.17.0.0")]
[assembly: AssemblyInformationalVersion("1.17.0+c7aa5116314e90d391a3350878f9fb99192aafb6")]
[assembly: AssemblyProduct("Iced")]
[assembly: AssemblyTitle("Iced")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/icedland/iced")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.17.0.0")]
[module: UnverifiableCode]
[module: System.Runtime.CompilerServices.NullablePublicOnly(false)]
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 NullablePublicOnlyAttribute : Attribute
	{
		public readonly bool IncludesInternals;

		public NullablePublicOnlyAttribute(bool P_0)
		{
			IncludesInternals = P_0;
		}
	}
}
namespace Iced.Intel
{
	public class Assembler
	{
		[Flags]
		private enum PrefixFlags
		{
			None = 0,
			Lock = 1,
			Repe = 2,
			Repne = 4,
			Notrack = 8,
			PreferVex = 0x10,
			PreferEvex = 0x20
		}

		private readonly InstructionList instructions;

		private ulong currentLabelId;

		private Label currentLabel;

		private Label currentAnonLabel;

		private Label nextAnonLabel;

		private bool definedAnonLabel;

		private PrefixFlags prefixFlags;

		public int Bitness { get; }

		public bool PreferVex { get; set; }

		public bool PreferShortBranch { get; set; }

		internal bool InstructionPreferVex
		{
			get
			{
				if ((prefixFlags & (PrefixFlags.PreferVex | PrefixFlags.PreferEvex)) != 0)
				{
					return (prefixFlags & PrefixFlags.PreferVex) != 0;
				}
				return PreferVex;
			}
		}

		public IReadOnlyList<Instruction> Instructions => instructions;

		public Label CurrentLabel => currentLabel;

		[DebuggerBrowsable(DebuggerBrowsableState.Never)]
		public Label B
		{
			get
			{
				if (currentAnonLabel.IsEmpty)
				{
					throw new InvalidOperationException("No anonymous label has been created yet");
				}
				return currentAnonLabel;
			}
		}

		[DebuggerBrowsable(DebuggerBrowsableState.Never)]
		public Label F
		{
			get
			{
				if (nextAnonLabel.IsEmpty)
				{
					nextAnonLabel = CreateLabel();
				}
				return nextAnonLabel;
			}
		}

		[DebuggerBrowsable(DebuggerBrowsableState.Never)]
		public Assembler @lock
		{
			get
			{
				prefixFlags |= PrefixFlags.Lock;
				return this;
			}
		}

		[DebuggerBrowsable(DebuggerBrowsableState.Never)]
		public Assembler xacquire
		{
			get
			{
				prefixFlags |= PrefixFlags.Repne;
				return this;
			}
		}

		[DebuggerBrowsable(DebuggerBrowsableState.Never)]
		public Assembler xrelease
		{
			get
			{
				prefixFlags |= PrefixFlags.Repe;
				return this;
			}
		}

		[DebuggerBrowsable(DebuggerBrowsableState.Never)]
		public Assembler rep
		{
			get
			{
				prefixFlags |= PrefixFlags.Repe;
				return this;
			}
		}

		[DebuggerBrowsable(DebuggerBrowsableState.Never)]
		public Assembler repe
		{
			get
			{
				prefixFlags |= PrefixFlags.Repe;
				return this;
			}
		}

		[DebuggerBrowsable(DebuggerBrowsableState.Never)]
		public Assembler repz => repe;

		[DebuggerBrowsable(DebuggerBrowsableState.Never)]
		public Assembler repne
		{
			get
			{
				prefixFlags |= PrefixFlags.Repne;
				return this;
			}
		}

		[DebuggerBrowsable(DebuggerBrowsableState.Never)]
		public Assembler repnz => repne;

		[DebuggerBrowsable(DebuggerBrowsableState.Never)]
		public Assembler bnd
		{
			get
			{
				prefixFlags |= PrefixFlags.Repne;
				return this;
			}
		}

		[DebuggerBrowsable(DebuggerBrowsableState.Never)]
		public Assembler notrack
		{
			get
			{
				prefixFlags |= PrefixFlags.Notrack;
				return this;
			}
		}

		[DebuggerBrowsable(DebuggerBrowsableState.Never)]
		public Assembler vex
		{
			get
			{
				prefixFlags |= PrefixFlags.PreferVex;
				return this;
			}
		}

		[DebuggerBrowsable(DebuggerBrowsableState.Never)]
		public Assembler evex
		{
			get
			{
				prefixFlags |= PrefixFlags.PreferEvex;
				return this;
			}
		}

		public Assembler(int bitness)
		{
			if (bitness != 16 && bitness != 32 && bitness != 64)
			{
				throw new ArgumentOutOfRangeException("bitness");
			}
			Bitness = bitness;
			instructions = new InstructionList();
			currentLabelId = 0uL;
			currentLabel = default(Label);
			currentAnonLabel = default(Label);
			nextAnonLabel = default(Label);
			definedAnonLabel = false;
			prefixFlags = PrefixFlags.None;
			PreferVex = true;
			PreferShortBranch = true;
		}

		public void Reset()
		{
			instructions.Clear();
			currentLabelId = 0uL;
			currentLabel = default(Label);
			currentAnonLabel = default(Label);
			nextAnonLabel = default(Label);
			definedAnonLabel = false;
			prefixFlags = PrefixFlags.None;
		}

		public Label CreateLabel(string? name = null)
		{
			currentLabelId++;
			return new Label(name, currentLabelId);
		}

		public void Label(ref Label label)
		{
			if (label.IsEmpty)
			{
				throw new ArgumentException("Invalid label. Must be created via CreateLabel", "label");
			}
			if (label.InstructionIndex >= 0)
			{
				throw new ArgumentException($"Cannot reuse label. The specified label is already associated with an instruction at index {label.InstructionIndex}.", "label");
			}
			if (!currentLabel.IsEmpty)
			{
				throw new ArgumentException("At most one label per instruction is allowed");
			}
			label.InstructionIndex = instructions.Count;
			currentLabel = label;
		}

		public void AnonymousLabel()
		{
			if (definedAnonLabel)
			{
				throw new InvalidOperationException("At most one anonymous label per instruction is allowed");
			}
			if (nextAnonLabel.IsEmpty)
			{
				currentAnonLabel = CreateLabel();
			}
			else
			{
				currentAnonLabel = nextAnonLabel;
			}
			nextAnonLabel = default(Label);
			definedAnonLabel = true;
		}

		public void AddInstruction(Instruction instruction)
		{
			AddInstruction(ref instruction);
		}

		public void AddInstruction(ref Instruction instruction)
		{
			if (!currentLabel.IsEmpty && definedAnonLabel)
			{
				throw new InvalidOperationException("You can't create both an anonymous label and a normal label");
			}
			if (!currentLabel.IsEmpty)
			{
				instruction.IP = currentLabel.Id;
			}
			else if (definedAnonLabel)
			{
				instruction.IP = currentAnonLabel.Id;
			}
			if (prefixFlags != 0)
			{
				if ((prefixFlags & PrefixFlags.Lock) != 0)
				{
					instruction.HasLockPrefix = true;
				}
				if ((prefixFlags & PrefixFlags.Repe) != 0)
				{
					instruction.HasRepePrefix = true;
				}
				else if ((prefixFlags & PrefixFlags.Repne) != 0)
				{
					instruction.HasRepnePrefix = true;
				}
				if ((prefixFlags & PrefixFlags.Notrack) != 0)
				{
					instruction.SegmentPrefix = Register.DS;
				}
			}
			instructions.Add(in instruction);
			currentLabel = default(Label);
			definedAnonLabel = false;
			prefixFlags = PrefixFlags.None;
		}

		private void AddInstruction(Instruction instruction, AssemblerOperandFlags flags)
		{
			if (flags != 0)
			{
				if ((flags & AssemblerOperandFlags.Broadcast) != 0)
				{
					instruction.IsBroadcast = true;
				}
				if ((flags & AssemblerOperandFlags.Zeroing) != 0)
				{
					instruction.ZeroingMasking = true;
				}
				if ((flags & AssemblerOperandFlags.K7) != 0)
				{
					instruction.OpMask = (Register)(173 + ((int)(flags & AssemblerOperandFlags.K7) >> 6));
				}
				if ((flags & AssemblerOperandFlags.SuppressAllExceptions) != 0)
				{
					instruction.SuppressAllExceptions = true;
				}
				if ((flags & AssemblerOperandFlags.RoundControlMask) != 0)
				{
					instruction.RoundingControl = (RoundingControl)((int)(flags & AssemblerOperandFlags.RoundControlMask) >> 3);
				}
			}
			AddInstruction(ref instruction);
		}

		public void db(byte[] array)
		{
			if (array == null)
			{
				ThrowHelper.ThrowArgumentNullException_array();
			}
			db(array, 0, array.Length);
		}

		public void db(byte[] array, int index, int length)
		{
			if (array == null)
			{
				ThrowHelper.ThrowArgumentNullException_array();
			}
			if (index < 0)
			{
				ThrowHelper.ThrowArgumentOutOfRangeException_index();
			}
			if (length < 0 || (uint)(index + length) > (uint)array.Length)
			{
				ThrowHelper.ThrowArgumentOutOfRangeException_length();
			}
			int result;
			int num = Math.DivRem(length, 16, out result);
			int num2 = index;
			for (int i = 0; i < num; i++)
			{
				AddInstruction(Instruction.CreateDeclareByte(array, num2, 16));
				num2 += 16;
			}
			if (result > 0)
			{
				AddInstruction(Instruction.CreateDeclareByte(array, num2, result));
			}
		}

		public void db(ReadOnlySpan<byte> data)
		{
			int result;
			int num = Math.DivRem(data.Length, 16, out result);
			int num2 = 0;
			for (int i = 0; i < num; i++)
			{
				AddInstruction(Instruction.CreateDeclareByte(data.Slice(num2, 16)));
				num2 += 16;
			}
			if (result > 0)
			{
				AddInstruction(Instruction.CreateDeclareByte(data.Slice(num2, result)));
			}
		}

		public void call(ushort selector, uint offset)
		{
			AddInstruction(Instruction.CreateBranch((Bitness >= 32) ? Code.Call_ptr1632 : Code.Call_ptr1616, selector, offset));
		}

		public void jmp(ushort selector, uint offset)
		{
			AddInstruction(Instruction.CreateBranch((Bitness >= 32) ? Code.Jmp_ptr1632 : Code.Jmp_ptr1616, selector, offset));
		}

		public void xlatb()
		{
			MemoryOperand memory = new MemoryOperand(Bitness switch
			{
				64 => Register.RBX, 
				32 => Register.EBX, 
				_ => Register.BX, 
			}, Register.AL);
			AddInstruction(Instruction.Create(Code.Xlat_m8, in memory));
		}

		public void nop(int sizeInBytes)
		{
			if (sizeInBytes < 0)
			{
				throw new ArgumentOutOfRangeException("sizeInBytes");
			}
			if (prefixFlags != 0)
			{
				throw new InvalidOperationException("No prefixes are allowed");
			}
			if (sizeInBytes != 0)
			{
				int result;
				int num = Math.DivRem(sizeInBytes, 9, out result);
				for (int i = 0; i < num; i++)
				{
					AppendNop(9);
				}
				if (result > 0)
				{
					AppendNop(result);
				}
			}
			void AppendNop(int amount)
			{
				switch (amount)
				{
				case 1:
					db(144);
					break;
				case 2:
					db(102, 144);
					break;
				case 3:
					db(15, 31, 0);
					break;
				case 4:
					db(15, 31, 64, 0);
					break;
				case 5:
					if (Bitness != 16)
					{
						db(15, 31, 68, 0, 0);
					}
					else
					{
						db(15, 31, 128, 0, 0);
					}
					break;
				case 6:
					if (Bitness != 16)
					{
						db(102, 15, 31, 68, 0, 0);
					}
					else
					{
						db(102, 15, 31, 128, 0, 0);
					}
					break;
				case 7:
					if (Bitness != 16)
					{
						db(15, 31, 128, 0, 0, 0, 0);
					}
					else
					{
						db(103, 102, 15, 31, 68, 0, 0);
					}
					break;
				case 8:
					if (Bitness != 16)
					{
						db(15, 31, 132, 0, 0, 0, 0, 0);
					}
					else
					{
						db(103, 15, 31, 128, 0, 0, 0, 0);
					}
					break;
				case 9:
					if (Bitness != 16)
					{
						db(102, 15, 31, 132, 0, 0, 0, 0, 0);
					}
					else
					{
						db(103, 15, 31, 132, 0, 0, 0, 0, 0);
					}
					break;
				}
			}
		}

		public AssemblerResult Assemble(CodeWriter writer, ulong rip, BlockEncoderOptions options = BlockEncoderOptions.None)
		{
			if (!TryAssemble(writer, rip, out string errorMessage, out AssemblerResult assemblerResult, options))
			{
				throw new InvalidOperationException(errorMessage);
			}
			return assemblerResult;
		}

		public bool TryAssemble(CodeWriter writer, ulong rip, [NotNullWhen(false)] out string? errorMessage, out AssemblerResult assemblerResult, BlockEncoderOptions options = BlockEncoderOptions.None)
		{
			if (writer == null)
			{
				ThrowHelper.ThrowArgumentNullException_writer();
			}
			assemblerResult = default(AssemblerResult);
			if (prefixFlags != 0)
			{
				errorMessage = $"Unused prefixes {prefixFlags}. You must emit an instruction after using an instruction prefix.";
				return false;
			}
			if (!currentLabel.IsEmpty)
			{
				errorMessage = $"Unused label {currentLabel}. You must emit an instruction after emitting a label.";
				return false;
			}
			if (definedAnonLabel)
			{
				errorMessage = "Unused anonymous label. You must emit an instruction after emitting a label.";
				return false;
			}
			if (!nextAnonLabel.IsEmpty)
			{
				errorMessage = "Found an @F anonymous label reference but there was no call to AnonymousLabel";
				return false;
			}
			InstructionBlock[] blocks = new InstructionBlock[1]
			{
				new InstructionBlock(writer, instructions, rip)
			};
			if (BlockEncoder.TryEncode(Bitness, blocks, out errorMessage, out BlockEncoderResult[] result, options))
			{
				assemblerResult = new AssemblerResult(result);
				return true;
			}
			assemblerResult = new AssemblerResult(Array2.Empty<BlockEncoderResult>());
			return false;
		}

		private InvalidOperationException NoOpCodeFoundFor(Mnemonic mnemonic, params object[] argNames)
		{
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.Append("Unable to calculate an OpCode for `" + mnemonic.ToString().ToLowerInvariant());
			for (int i = 0; i < argNames.Length; i++)
			{
				stringBuilder.Append((i == 0) ? " " : ", ");
				stringBuilder.Append(argNames[i]);
			}
			stringBuilder.Append($"`. Combination of arguments and/or current bitness {Bitness} is not compatible with any existing OpCode encoding.");
			return new InvalidOperationException(stringBuilder.ToString());
		}

		public void aaa()
		{
			AddInstruction(Instruction.Create(Code.Aaa));
		}

		public void aad(sbyte imm)
		{
			AddInstruction(Instruction.Create(Code.Aad_imm8, imm));
		}

		public void aad(byte imm)
		{
			AddInstruction(Instruction.Create(Code.Aad_imm8, (uint)imm));
		}

		public void aam(sbyte imm)
		{
			AddInstruction(Instruction.Create(Code.Aam_imm8, imm));
		}

		public void aam(byte imm)
		{
			AddInstruction(Instruction.Create(Code.Aam_imm8, (uint)imm));
		}

		public void aas()
		{
			AddInstruction(Instruction.Create(Code.Aas));
		}

		public void adc(AssemblerRegister8 dst, AssemblerRegister8 src)
		{
			AddInstruction(Instruction.Create(Code.Adc_rm8_r8, dst, src));
		}

		public void adc(AssemblerMemoryOperand dst, AssemblerRegister8 src)
		{
			MemoryOperand memory = dst.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Adc_rm8_r8, in memory, src));
		}

		public void adc(AssemblerRegister16 dst, AssemblerRegister16 src)
		{
			AddInstruction(Instruction.Create(Code.Adc_rm16_r16, dst, src));
		}

		public void adc(AssemblerMemoryOperand dst, AssemblerRegister16 src)
		{
			MemoryOperand memory = dst.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Adc_rm16_r16, in memory, src));
		}

		public void adc(AssemblerRegister32 dst, AssemblerRegister32 src)
		{
			AddInstruction(Instruction.Create(Code.Adc_rm32_r32, dst, src));
		}

		public void adc(AssemblerMemoryOperand dst, AssemblerRegister32 src)
		{
			MemoryOperand memory = dst.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Adc_rm32_r32, in memory, src));
		}

		public void adc(AssemblerRegister64 dst, AssemblerRegister64 src)
		{
			AddInstruction(Instruction.Create(Code.Adc_rm64_r64, dst, src));
		}

		public void adc(AssemblerMemoryOperand dst, AssemblerRegister64 src)
		{
			MemoryOperand memory = dst.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Adc_rm64_r64, in memory, src));
		}

		public void adc(AssemblerRegister8 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Adc_r8_rm8, register, in memory));
		}

		public void adc(AssemblerRegister16 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Adc_r16_rm16, register, in memory));
		}

		public void adc(AssemblerRegister32 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Adc_r32_rm32, register, in memory));
		}

		public void adc(AssemblerRegister64 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Adc_r64_rm64, register, in memory));
		}

		public void adc(AssemblerRegister8 dst, sbyte imm)
		{
			Code code = (((Register)dst == Register.AL) ? Code.Adc_AL_imm8 : Code.Adc_rm8_imm8);
			AddInstruction(Instruction.Create(code, dst, imm));
		}

		public void adc(AssemblerRegister16 dst, short imm)
		{
			Code code = (((Register)dst != Register.AX) ? ((imm >= -128 && imm <= 127) ? Code.Adc_rm16_imm8 : Code.Adc_rm16_imm16) : Code.Adc_AX_imm16);
			AddInstruction(Instruction.Create(code, dst, imm));
		}

		public void adc(AssemblerRegister32 dst, int imm)
		{
			Code code = (((Register)dst != Register.EAX) ? ((imm >= -128 && imm <= 127) ? Code.Adc_rm32_imm8 : Code.Adc_rm32_imm32) : Code.Adc_EAX_imm32);
			AddInstruction(Instruction.Create(code, dst, imm));
		}

		public void adc(AssemblerRegister64 dst, int imm)
		{
			Code code = (((Register)dst != Register.RAX) ? ((imm >= -128 && imm <= 127) ? Code.Adc_rm64_imm8 : Code.Adc_rm64_imm32) : Code.Adc_RAX_imm32);
			AddInstruction(Instruction.Create(code, dst, imm));
		}

		public void adc(AssemblerMemoryOperand dst, int imm)
		{
			Code code;
			if (dst.Size == MemoryOperandSize.Qword)
			{
				code = ((imm >= -128 && imm <= 127) ? Code.Adc_rm64_imm8 : Code.Adc_rm64_imm32);
			}
			else if (dst.Size == MemoryOperandSize.Dword)
			{
				code = ((imm >= -128 && imm <= 127) ? Code.Adc_rm32_imm8 : Code.Adc_rm32_imm32);
			}
			else if (dst.Size == MemoryOperandSize.Word)
			{
				code = ((imm >= -128 && imm <= 127) ? Code.Adc_rm16_imm8 : Code.Adc_rm16_imm16);
			}
			else
			{
				if (dst.Size != MemoryOperandSize.Byte)
				{
					throw NoOpCodeFoundFor(Mnemonic.Adc, dst, imm);
				}
				code = Code.Adc_rm8_imm8;
			}
			Code code2 = code;
			MemoryOperand memory = dst.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(code2, in memory, imm));
		}

		public void adc(AssemblerRegister8 dst, byte imm)
		{
			Code code = (((Register)dst == Register.AL) ? Code.Adc_AL_imm8 : Code.Adc_rm8_imm8);
			AddInstruction(Instruction.Create(code, (Register)dst, (uint)imm));
		}

		public void adc(AssemblerRegister16 dst, ushort imm)
		{
			Code code = (((Register)dst != Register.AX) ? ((imm <= 127 || (65408 <= imm && imm <= ushort.MaxValue)) ? Code.Adc_rm16_imm8 : Code.Adc_rm16_imm16) : Code.Adc_AX_imm16);
			AddInstruction(Instruction.Create(code, (Register)dst, (uint)imm));
		}

		public void adc(AssemblerRegister32 dst, uint imm)
		{
			Code code = (((Register)dst != Register.EAX) ? ((imm <= 127 || 4294967168u <= imm) ? Code.Adc_rm32_imm8 : Code.Adc_rm32_imm32) : Code.Adc_EAX_imm32);
			AddInstruction(Instruction.Create(code, dst, imm));
		}

		public void adc(AssemblerMemoryOperand dst, uint imm)
		{
			Code code;
			if (dst.Size == MemoryOperandSize.Dword)
			{
				code = ((imm <= 127 || 4294967168u <= imm) ? Code.Adc_rm32_imm8 : Code.Adc_rm32_imm32);
			}
			else if (dst.Size == MemoryOperandSize.Word)
			{
				code = ((imm <= 127 || (65408 <= imm && imm <= 65535)) ? Code.Adc_rm16_imm8 : Code.Adc_rm16_imm16);
			}
			else
			{
				if (dst.Size != MemoryOperandSize.Byte)
				{
					throw NoOpCodeFoundFor(Mnemonic.Adc, dst, imm);
				}
				code = Code.Adc_rm8_imm8;
			}
			Code code2 = code;
			MemoryOperand memory = dst.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(code2, in memory, imm));
		}

		public void adcx(AssemblerRegister32 dst, AssemblerRegister32 src)
		{
			AddInstruction(Instruction.Create(Code.Adcx_r32_rm32, dst, src));
		}

		public void adcx(AssemblerRegister64 dst, AssemblerRegister64 src)
		{
			AddInstruction(Instruction.Create(Code.Adcx_r64_rm64, dst, src));
		}

		public void adcx(AssemblerRegister32 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Adcx_r32_rm32, register, in memory));
		}

		public void adcx(AssemblerRegister64 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Adcx_r64_rm64, register, in memory));
		}

		public void add(AssemblerRegister8 dst, AssemblerRegister8 src)
		{
			AddInstruction(Instruction.Create(Code.Add_rm8_r8, dst, src));
		}

		public void add(AssemblerMemoryOperand dst, AssemblerRegister8 src)
		{
			MemoryOperand memory = dst.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Add_rm8_r8, in memory, src));
		}

		public void add(AssemblerRegister16 dst, AssemblerRegister16 src)
		{
			AddInstruction(Instruction.Create(Code.Add_rm16_r16, dst, src));
		}

		public void add(AssemblerMemoryOperand dst, AssemblerRegister16 src)
		{
			MemoryOperand memory = dst.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Add_rm16_r16, in memory, src));
		}

		public void add(AssemblerRegister32 dst, AssemblerRegister32 src)
		{
			AddInstruction(Instruction.Create(Code.Add_rm32_r32, dst, src));
		}

		public void add(AssemblerMemoryOperand dst, AssemblerRegister32 src)
		{
			MemoryOperand memory = dst.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Add_rm32_r32, in memory, src));
		}

		public void add(AssemblerRegister64 dst, AssemblerRegister64 src)
		{
			AddInstruction(Instruction.Create(Code.Add_rm64_r64, dst, src));
		}

		public void add(AssemblerMemoryOperand dst, AssemblerRegister64 src)
		{
			MemoryOperand memory = dst.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Add_rm64_r64, in memory, src));
		}

		public void add(AssemblerRegister8 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Add_r8_rm8, register, in memory));
		}

		public void add(AssemblerRegister16 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Add_r16_rm16, register, in memory));
		}

		public void add(AssemblerRegister32 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Add_r32_rm32, register, in memory));
		}

		public void add(AssemblerRegister64 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Add_r64_rm64, register, in memory));
		}

		public void add(AssemblerRegister8 dst, sbyte imm)
		{
			Code code = (((Register)dst == Register.AL) ? Code.Add_AL_imm8 : Code.Add_rm8_imm8);
			AddInstruction(Instruction.Create(code, dst, imm));
		}

		public void add(AssemblerRegister16 dst, short imm)
		{
			Code code = (((Register)dst != Register.AX) ? ((imm >= -128 && imm <= 127) ? Code.Add_rm16_imm8 : Code.Add_rm16_imm16) : Code.Add_AX_imm16);
			AddInstruction(Instruction.Create(code, dst, imm));
		}

		public void add(AssemblerRegister32 dst, int imm)
		{
			Code code = (((Register)dst != Register.EAX) ? ((imm >= -128 && imm <= 127) ? Code.Add_rm32_imm8 : Code.Add_rm32_imm32) : Code.Add_EAX_imm32);
			AddInstruction(Instruction.Create(code, dst, imm));
		}

		public void add(AssemblerRegister64 dst, int imm)
		{
			Code code = (((Register)dst != Register.RAX) ? ((imm >= -128 && imm <= 127) ? Code.Add_rm64_imm8 : Code.Add_rm64_imm32) : Code.Add_RAX_imm32);
			AddInstruction(Instruction.Create(code, dst, imm));
		}

		public void add(AssemblerMemoryOperand dst, int imm)
		{
			Code code;
			if (dst.Size == MemoryOperandSize.Qword)
			{
				code = ((imm >= -128 && imm <= 127) ? Code.Add_rm64_imm8 : Code.Add_rm64_imm32);
			}
			else if (dst.Size == MemoryOperandSize.Dword)
			{
				code = ((imm >= -128 && imm <= 127) ? Code.Add_rm32_imm8 : Code.Add_rm32_imm32);
			}
			else if (dst.Size == MemoryOperandSize.Word)
			{
				code = ((imm >= -128 && imm <= 127) ? Code.Add_rm16_imm8 : Code.Add_rm16_imm16);
			}
			else
			{
				if (dst.Size != MemoryOperandSize.Byte)
				{
					throw NoOpCodeFoundFor(Mnemonic.Add, dst, imm);
				}
				code = Code.Add_rm8_imm8;
			}
			Code code2 = code;
			MemoryOperand memory = dst.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(code2, in memory, imm));
		}

		public void add(AssemblerRegister8 dst, byte imm)
		{
			Code code = (((Register)dst == Register.AL) ? Code.Add_AL_imm8 : Code.Add_rm8_imm8);
			AddInstruction(Instruction.Create(code, (Register)dst, (uint)imm));
		}

		public void add(AssemblerRegister16 dst, ushort imm)
		{
			Code code = (((Register)dst != Register.AX) ? ((imm <= 127 || (65408 <= imm && imm <= ushort.MaxValue)) ? Code.Add_rm16_imm8 : Code.Add_rm16_imm16) : Code.Add_AX_imm16);
			AddInstruction(Instruction.Create(code, (Register)dst, (uint)imm));
		}

		public void add(AssemblerRegister32 dst, uint imm)
		{
			Code code = (((Register)dst != Register.EAX) ? ((imm <= 127 || 4294967168u <= imm) ? Code.Add_rm32_imm8 : Code.Add_rm32_imm32) : Code.Add_EAX_imm32);
			AddInstruction(Instruction.Create(code, dst, imm));
		}

		public void add(AssemblerMemoryOperand dst, uint imm)
		{
			Code code;
			if (dst.Size == MemoryOperandSize.Dword)
			{
				code = ((imm <= 127 || 4294967168u <= imm) ? Code.Add_rm32_imm8 : Code.Add_rm32_imm32);
			}
			else if (dst.Size == MemoryOperandSize.Word)
			{
				code = ((imm <= 127 || (65408 <= imm && imm <= 65535)) ? Code.Add_rm16_imm8 : Code.Add_rm16_imm16);
			}
			else
			{
				if (dst.Size != MemoryOperandSize.Byte)
				{
					throw NoOpCodeFoundFor(Mnemonic.Add, dst, imm);
				}
				code = Code.Add_rm8_imm8;
			}
			Code code2 = code;
			MemoryOperand memory = dst.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(code2, in memory, imm));
		}

		public void addpd(AssemblerRegisterXMM dst, AssemblerRegisterXMM src)
		{
			AddInstruction(Instruction.Create(Code.Addpd_xmm_xmmm128, dst, src));
		}

		public void addpd(AssemblerRegisterXMM dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Addpd_xmm_xmmm128, register, in memory));
		}

		public void addps(AssemblerRegisterXMM dst, AssemblerRegisterXMM src)
		{
			AddInstruction(Instruction.Create(Code.Addps_xmm_xmmm128, dst, src));
		}

		public void addps(AssemblerRegisterXMM dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Addps_xmm_xmmm128, register, in memory));
		}

		public void addsd(AssemblerRegisterXMM dst, AssemblerRegisterXMM src)
		{
			AddInstruction(Instruction.Create(Code.Addsd_xmm_xmmm64, dst, src));
		}

		public void addsd(AssemblerRegisterXMM dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Addsd_xmm_xmmm64, register, in memory));
		}

		public void addss(AssemblerRegisterXMM dst, AssemblerRegisterXMM src)
		{
			AddInstruction(Instruction.Create(Code.Addss_xmm_xmmm32, dst, src));
		}

		public void addss(AssemblerRegisterXMM dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Addss_xmm_xmmm32, register, in memory));
		}

		public void addsubpd(AssemblerRegisterXMM dst, AssemblerRegisterXMM src)
		{
			AddInstruction(Instruction.Create(Code.Addsubpd_xmm_xmmm128, dst, src));
		}

		public void addsubpd(AssemblerRegisterXMM dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Addsubpd_xmm_xmmm128, register, in memory));
		}

		public void addsubps(AssemblerRegisterXMM dst, AssemblerRegisterXMM src)
		{
			AddInstruction(Instruction.Create(Code.Addsubps_xmm_xmmm128, dst, src));
		}

		public void addsubps(AssemblerRegisterXMM dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Addsubps_xmm_xmmm128, register, in memory));
		}

		public void adox(AssemblerRegister32 dst, AssemblerRegister32 src)
		{
			AddInstruction(Instruction.Create(Code.Adox_r32_rm32, dst, src));
		}

		public void adox(AssemblerRegister64 dst, AssemblerRegister64 src)
		{
			AddInstruction(Instruction.Create(Code.Adox_r64_rm64, dst, src));
		}

		public void adox(AssemblerRegister32 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Adox_r32_rm32, register, in memory));
		}

		public void adox(AssemblerRegister64 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Adox_r64_rm64, register, in memory));
		}

		public void aesdec(AssemblerRegisterXMM dst, AssemblerRegisterXMM src)
		{
			AddInstruction(Instruction.Create(Code.Aesdec_xmm_xmmm128, dst, src));
		}

		public void aesdec(AssemblerRegisterXMM dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Aesdec_xmm_xmmm128, register, in memory));
		}

		public void aesdec128kl(AssemblerRegisterXMM dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Aesdec128kl_xmm_m384, register, in memory));
		}

		public void aesdec256kl(AssemblerRegisterXMM dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Aesdec256kl_xmm_m512, register, in memory));
		}

		public void aesdeclast(AssemblerRegisterXMM dst, AssemblerRegisterXMM src)
		{
			AddInstruction(Instruction.Create(Code.Aesdeclast_xmm_xmmm128, dst, src));
		}

		public void aesdeclast(AssemblerRegisterXMM dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Aesdeclast_xmm_xmmm128, register, in memory));
		}

		public void aesdecwide128kl(AssemblerMemoryOperand dst)
		{
			MemoryOperand memory = dst.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Aesdecwide128kl_m384, in memory));
		}

		public void aesdecwide256kl(AssemblerMemoryOperand dst)
		{
			MemoryOperand memory = dst.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Aesdecwide256kl_m512, in memory));
		}

		public void aesenc(AssemblerRegisterXMM dst, AssemblerRegisterXMM src)
		{
			AddInstruction(Instruction.Create(Code.Aesenc_xmm_xmmm128, dst, src));
		}

		public void aesenc(AssemblerRegisterXMM dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Aesenc_xmm_xmmm128, register, in memory));
		}

		public void aesenc128kl(AssemblerRegisterXMM dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Aesenc128kl_xmm_m384, register, in memory));
		}

		public void aesenc256kl(AssemblerRegisterXMM dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Aesenc256kl_xmm_m512, register, in memory));
		}

		public void aesenclast(AssemblerRegisterXMM dst, AssemblerRegisterXMM src)
		{
			AddInstruction(Instruction.Create(Code.Aesenclast_xmm_xmmm128, dst, src));
		}

		public void aesenclast(AssemblerRegisterXMM dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Aesenclast_xmm_xmmm128, register, in memory));
		}

		public void aesencwide128kl(AssemblerMemoryOperand dst)
		{
			MemoryOperand memory = dst.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Aesencwide128kl_m384, in memory));
		}

		public void aesencwide256kl(AssemblerMemoryOperand dst)
		{
			MemoryOperand memory = dst.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Aesencwide256kl_m512, in memory));
		}

		public void aesimc(AssemblerRegisterXMM dst, AssemblerRegisterXMM src)
		{
			AddInstruction(Instruction.Create(Code.Aesimc_xmm_xmmm128, dst, src));
		}

		public void aesimc(AssemblerRegisterXMM dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Aesimc_xmm_xmmm128, register, in memory));
		}

		public void aeskeygenassist(AssemblerRegisterXMM dst, AssemblerRegisterXMM src1, sbyte imm)
		{
			AddInstruction(Instruction.Create(Code.Aeskeygenassist_xmm_xmmm128_imm8, dst, src1, imm));
		}

		public void aeskeygenassist(AssemblerRegisterXMM dst, AssemblerMemoryOperand src1, sbyte imm)
		{
			Register register = dst;
			MemoryOperand memory = src1.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Aeskeygenassist_xmm_xmmm128_imm8, register, in memory, imm));
		}

		public void aeskeygenassist(AssemblerRegisterXMM dst, AssemblerRegisterXMM src1, byte imm)
		{
			AddInstruction(Instruction.Create(Code.Aeskeygenassist_xmm_xmmm128_imm8, (Register)dst, (Register)src1, (uint)imm));
		}

		public void aeskeygenassist(AssemblerRegisterXMM dst, AssemblerMemoryOperand src1, byte imm)
		{
			Register register = dst;
			MemoryOperand memory = src1.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Aeskeygenassist_xmm_xmmm128_imm8, register, in memory, (uint)imm));
		}

		public void altinst()
		{
			AddInstruction(Instruction.Create(Code.Altinst));
		}

		public void and(AssemblerRegister8 dst, AssemblerRegister8 src)
		{
			AddInstruction(Instruction.Create(Code.And_rm8_r8, dst, src));
		}

		public void and(AssemblerMemoryOperand dst, AssemblerRegister8 src)
		{
			MemoryOperand memory = dst.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.And_rm8_r8, in memory, src));
		}

		public void and(AssemblerRegister16 dst, AssemblerRegister16 src)
		{
			AddInstruction(Instruction.Create(Code.And_rm16_r16, dst, src));
		}

		public void and(AssemblerMemoryOperand dst, AssemblerRegister16 src)
		{
			MemoryOperand memory = dst.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.And_rm16_r16, in memory, src));
		}

		public void and(AssemblerRegister32 dst, AssemblerRegister32 src)
		{
			AddInstruction(Instruction.Create(Code.And_rm32_r32, dst, src));
		}

		public void and(AssemblerMemoryOperand dst, AssemblerRegister32 src)
		{
			MemoryOperand memory = dst.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.And_rm32_r32, in memory, src));
		}

		public void and(AssemblerRegister64 dst, AssemblerRegister64 src)
		{
			AddInstruction(Instruction.Create(Code.And_rm64_r64, dst, src));
		}

		public void and(AssemblerMemoryOperand dst, AssemblerRegister64 src)
		{
			MemoryOperand memory = dst.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.And_rm64_r64, in memory, src));
		}

		public void and(AssemblerRegister8 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.And_r8_rm8, register, in memory));
		}

		public void and(AssemblerRegister16 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.And_r16_rm16, register, in memory));
		}

		public void and(AssemblerRegister32 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.And_r32_rm32, register, in memory));
		}

		public void and(AssemblerRegister64 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.And_r64_rm64, register, in memory));
		}

		public void and(AssemblerRegister8 dst, sbyte imm)
		{
			Code code = (((Register)dst == Register.AL) ? Code.And_AL_imm8 : Code.And_rm8_imm8);
			AddInstruction(Instruction.Create(code, dst, imm));
		}

		public void and(AssemblerRegister16 dst, short imm)
		{
			Code code = (((Register)dst != Register.AX) ? ((imm >= -128 && imm <= 127) ? Code.And_rm16_imm8 : Code.And_rm16_imm16) : Code.And_AX_imm16);
			AddInstruction(Instruction.Create(code, dst, imm));
		}

		public void and(AssemblerRegister32 dst, int imm)
		{
			Code code = (((Register)dst != Register.EAX) ? ((imm >= -128 && imm <= 127) ? Code.And_rm32_imm8 : Code.And_rm32_imm32) : Code.And_EAX_imm32);
			AddInstruction(Instruction.Create(code, dst, imm));
		}

		public void and(AssemblerRegister64 dst, int imm)
		{
			Code code = (((Register)dst != Register.RAX) ? ((imm >= -128 && imm <= 127) ? Code.And_rm64_imm8 : Code.And_rm64_imm32) : Code.And_RAX_imm32);
			AddInstruction(Instruction.Create(code, dst, imm));
		}

		public void and(AssemblerMemoryOperand dst, int imm)
		{
			Code code;
			if (dst.Size == MemoryOperandSize.Qword)
			{
				code = ((imm >= -128 && imm <= 127) ? Code.And_rm64_imm8 : Code.And_rm64_imm32);
			}
			else if (dst.Size == MemoryOperandSize.Dword)
			{
				code = ((imm >= -128 && imm <= 127) ? Code.And_rm32_imm8 : Code.And_rm32_imm32);
			}
			else if (dst.Size == MemoryOperandSize.Word)
			{
				code = ((imm >= -128 && imm <= 127) ? Code.And_rm16_imm8 : Code.And_rm16_imm16);
			}
			else
			{
				if (dst.Size != MemoryOperandSize.Byte)
				{
					throw NoOpCodeFoundFor(Mnemonic.And, dst, imm);
				}
				code = Code.And_rm8_imm8;
			}
			Code code2 = code;
			MemoryOperand memory = dst.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(code2, in memory, imm));
		}

		public void and(AssemblerRegister8 dst, byte imm)
		{
			Code code = (((Register)dst == Register.AL) ? Code.And_AL_imm8 : Code.And_rm8_imm8);
			AddInstruction(Instruction.Create(code, (Register)dst, (uint)imm));
		}

		public void and(AssemblerRegister16 dst, ushort imm)
		{
			Code code = (((Register)dst != Register.AX) ? ((imm <= 127 || (65408 <= imm && imm <= ushort.MaxValue)) ? Code.And_rm16_imm8 : Code.And_rm16_imm16) : Code.And_AX_imm16);
			AddInstruction(Instruction.Create(code, (Register)dst, (uint)imm));
		}

		public void and(AssemblerRegister32 dst, uint imm)
		{
			Code code = (((Register)dst != Register.EAX) ? ((imm <= 127 || 4294967168u <= imm) ? Code.And_rm32_imm8 : Code.And_rm32_imm32) : Code.And_EAX_imm32);
			AddInstruction(Instruction.Create(code, dst, imm));
		}

		public void and(AssemblerMemoryOperand dst, uint imm)
		{
			Code code;
			if (dst.Size == MemoryOperandSize.Dword)
			{
				code = ((imm <= 127 || 4294967168u <= imm) ? Code.And_rm32_imm8 : Code.And_rm32_imm32);
			}
			else if (dst.Size == MemoryOperandSize.Word)
			{
				code = ((imm <= 127 || (65408 <= imm && imm <= 65535)) ? Code.And_rm16_imm8 : Code.And_rm16_imm16);
			}
			else
			{
				if (dst.Size != MemoryOperandSize.Byte)
				{
					throw NoOpCodeFoundFor(Mnemonic.And, dst, imm);
				}
				code = Code.And_rm8_imm8;
			}
			Code code2 = code;
			MemoryOperand memory = dst.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(code2, in memory, imm));
		}

		public void andn(AssemblerRegister32 dst, AssemblerRegister32 src1, AssemblerRegister32 src2)
		{
			AddInstruction(Instruction.Create(Code.VEX_Andn_r32_r32_rm32, dst, src1, src2));
		}

		public void andn(AssemblerRegister64 dst, AssemblerRegister64 src1, AssemblerRegister64 src2)
		{
			AddInstruction(Instruction.Create(Code.VEX_Andn_r64_r64_rm64, dst, src1, src2));
		}

		public void andn(AssemblerRegister32 dst, AssemblerRegister32 src1, AssemblerMemoryOperand src2)
		{
			Register register = dst;
			Register register2 = src1;
			MemoryOperand memory = src2.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.VEX_Andn_r32_r32_rm32, register, register2, in memory));
		}

		public void andn(AssemblerRegister64 dst, AssemblerRegister64 src1, AssemblerMemoryOperand src2)
		{
			Register register = dst;
			Register register2 = src1;
			MemoryOperand memory = src2.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.VEX_Andn_r64_r64_rm64, register, register2, in memory));
		}

		public void andnpd(AssemblerRegisterXMM dst, AssemblerRegisterXMM src)
		{
			AddInstruction(Instruction.Create(Code.Andnpd_xmm_xmmm128, dst, src));
		}

		public void andnpd(AssemblerRegisterXMM dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Andnpd_xmm_xmmm128, register, in memory));
		}

		public void andnps(AssemblerRegisterXMM dst, AssemblerRegisterXMM src)
		{
			AddInstruction(Instruction.Create(Code.Andnps_xmm_xmmm128, dst, src));
		}

		public void andnps(AssemblerRegisterXMM dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Andnps_xmm_xmmm128, register, in memory));
		}

		public void andpd(AssemblerRegisterXMM dst, AssemblerRegisterXMM src)
		{
			AddInstruction(Instruction.Create(Code.Andpd_xmm_xmmm128, dst, src));
		}

		public void andpd(AssemblerRegisterXMM dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Andpd_xmm_xmmm128, register, in memory));
		}

		public void andps(AssemblerRegisterXMM dst, AssemblerRegisterXMM src)
		{
			AddInstruction(Instruction.Create(Code.Andps_xmm_xmmm128, dst, src));
		}

		public void andps(AssemblerRegisterXMM dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Andps_xmm_xmmm128, register, in memory));
		}

		public void arpl(AssemblerRegister16 dst, AssemblerRegister16 src)
		{
			AddInstruction(Instruction.Create(Code.Arpl_rm16_r16, dst, src));
		}

		public void arpl(AssemblerMemoryOperand dst, AssemblerRegister16 src)
		{
			MemoryOperand memory = dst.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Arpl_rm16_r16, in memory, src));
		}

		public void arpl(AssemblerRegister32 dst, AssemblerRegister32 src)
		{
			AddInstruction(Instruction.Create(Code.Arpl_r32m16_r32, dst, src));
		}

		public void arpl(AssemblerMemoryOperand dst, AssemblerRegister32 src)
		{
			MemoryOperand memory = dst.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Arpl_r32m16_r32, in memory, src));
		}

		public void bb0_reset()
		{
			AddInstruction(Instruction.Create(Code.Bb0_reset));
		}

		public void bb1_reset()
		{
			AddInstruction(Instruction.Create(Code.Bb1_reset));
		}

		public void bextr(AssemblerRegister32 dst, AssemblerRegister32 src1, AssemblerRegister32 src2)
		{
			AddInstruction(Instruction.Create(Code.VEX_Bextr_r32_rm32_r32, dst, src1, src2));
		}

		public void bextr(AssemblerRegister32 dst, AssemblerMemoryOperand src1, AssemblerRegister32 src2)
		{
			Register register = dst;
			MemoryOperand memory = src1.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.VEX_Bextr_r32_rm32_r32, register, in memory, src2));
		}

		public void bextr(AssemblerRegister64 dst, AssemblerRegister64 src1, AssemblerRegister64 src2)
		{
			AddInstruction(Instruction.Create(Code.VEX_Bextr_r64_rm64_r64, dst, src1, src2));
		}

		public void bextr(AssemblerRegister64 dst, AssemblerMemoryOperand src1, AssemblerRegister64 src2)
		{
			Register register = dst;
			MemoryOperand memory = src1.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.VEX_Bextr_r64_rm64_r64, register, in memory, src2));
		}

		public void bextr(AssemblerRegister32 dst, AssemblerRegister32 src1, int imm)
		{
			AddInstruction(Instruction.Create(Code.XOP_Bextr_r32_rm32_imm32, dst, src1, imm));
		}

		public void bextr(AssemblerRegister64 dst, AssemblerRegister64 src1, int imm)
		{
			AddInstruction(Instruction.Create(Code.XOP_Bextr_r64_rm64_imm32, dst, src1, imm));
		}

		public void bextr(AssemblerRegister32 dst, AssemblerMemoryOperand src1, int imm)
		{
			Register register = dst;
			MemoryOperand memory = src1.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.XOP_Bextr_r32_rm32_imm32, register, in memory, imm));
		}

		public void bextr(AssemblerRegister64 dst, AssemblerMemoryOperand src1, int imm)
		{
			Register register = dst;
			MemoryOperand memory = src1.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.XOP_Bextr_r64_rm64_imm32, register, in memory, imm));
		}

		public void bextr(AssemblerRegister32 dst, AssemblerRegister32 src1, uint imm)
		{
			AddInstruction(Instruction.Create(Code.XOP_Bextr_r32_rm32_imm32, dst, src1, imm));
		}

		public void bextr(AssemblerRegister64 dst, AssemblerRegister64 src1, uint imm)
		{
			AddInstruction(Instruction.Create(Code.XOP_Bextr_r64_rm64_imm32, dst, src1, imm));
		}

		public void bextr(AssemblerRegister32 dst, AssemblerMemoryOperand src1, uint imm)
		{
			Register register = dst;
			MemoryOperand memory = src1.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.XOP_Bextr_r32_rm32_imm32, register, in memory, imm));
		}

		public void bextr(AssemblerRegister64 dst, AssemblerMemoryOperand src1, uint imm)
		{
			Register register = dst;
			MemoryOperand memory = src1.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.XOP_Bextr_r64_rm64_imm32, register, in memory, imm));
		}

		public void blcfill(AssemblerRegister32 dst, AssemblerRegister32 src)
		{
			AddInstruction(Instruction.Create(Code.XOP_Blcfill_r32_rm32, dst, src));
		}

		public void blcfill(AssemblerRegister64 dst, AssemblerRegister64 src)
		{
			AddInstruction(Instruction.Create(Code.XOP_Blcfill_r64_rm64, dst, src));
		}

		public void blcfill(AssemblerRegister32 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.XOP_Blcfill_r32_rm32, register, in memory));
		}

		public void blcfill(AssemblerRegister64 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.XOP_Blcfill_r64_rm64, register, in memory));
		}

		public void blci(AssemblerRegister32 dst, AssemblerRegister32 src)
		{
			AddInstruction(Instruction.Create(Code.XOP_Blci_r32_rm32, dst, src));
		}

		public void blci(AssemblerRegister64 dst, AssemblerRegister64 src)
		{
			AddInstruction(Instruction.Create(Code.XOP_Blci_r64_rm64, dst, src));
		}

		public void blci(AssemblerRegister32 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.XOP_Blci_r32_rm32, register, in memory));
		}

		public void blci(AssemblerRegister64 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.XOP_Blci_r64_rm64, register, in memory));
		}

		public void blcic(AssemblerRegister32 dst, AssemblerRegister32 src)
		{
			AddInstruction(Instruction.Create(Code.XOP_Blcic_r32_rm32, dst, src));
		}

		public void blcic(AssemblerRegister64 dst, AssemblerRegister64 src)
		{
			AddInstruction(Instruction.Create(Code.XOP_Blcic_r64_rm64, dst, src));
		}

		public void blcic(AssemblerRegister32 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.XOP_Blcic_r32_rm32, register, in memory));
		}

		public void blcic(AssemblerRegister64 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.XOP_Blcic_r64_rm64, register, in memory));
		}

		public void blcmsk(AssemblerRegister32 dst, AssemblerRegister32 src)
		{
			AddInstruction(Instruction.Create(Code.XOP_Blcmsk_r32_rm32, dst, src));
		}

		public void blcmsk(AssemblerRegister64 dst, AssemblerRegister64 src)
		{
			AddInstruction(Instruction.Create(Code.XOP_Blcmsk_r64_rm64, dst, src));
		}

		public void blcmsk(AssemblerRegister32 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.XOP_Blcmsk_r32_rm32, register, in memory));
		}

		public void blcmsk(AssemblerRegister64 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.XOP_Blcmsk_r64_rm64, register, in memory));
		}

		public void blcs(AssemblerRegister32 dst, AssemblerRegister32 src)
		{
			AddInstruction(Instruction.Create(Code.XOP_Blcs_r32_rm32, dst, src));
		}

		public void blcs(AssemblerRegister64 dst, AssemblerRegister64 src)
		{
			AddInstruction(Instruction.Create(Code.XOP_Blcs_r64_rm64, dst, src));
		}

		public void blcs(AssemblerRegister32 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.XOP_Blcs_r32_rm32, register, in memory));
		}

		public void blcs(AssemblerRegister64 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.XOP_Blcs_r64_rm64, register, in memory));
		}

		public void blendpd(AssemblerRegisterXMM dst, AssemblerRegisterXMM src1, sbyte imm)
		{
			AddInstruction(Instruction.Create(Code.Blendpd_xmm_xmmm128_imm8, dst, src1, imm));
		}

		public void blendpd(AssemblerRegisterXMM dst, AssemblerMemoryOperand src1, sbyte imm)
		{
			Register register = dst;
			MemoryOperand memory = src1.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Blendpd_xmm_xmmm128_imm8, register, in memory, imm));
		}

		public void blendpd(AssemblerRegisterXMM dst, AssemblerRegisterXMM src1, byte imm)
		{
			AddInstruction(Instruction.Create(Code.Blendpd_xmm_xmmm128_imm8, (Register)dst, (Register)src1, (uint)imm));
		}

		public void blendpd(AssemblerRegisterXMM dst, AssemblerMemoryOperand src1, byte imm)
		{
			Register register = dst;
			MemoryOperand memory = src1.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Blendpd_xmm_xmmm128_imm8, register, in memory, (uint)imm));
		}

		public void blendps(AssemblerRegisterXMM dst, AssemblerRegisterXMM src1, sbyte imm)
		{
			AddInstruction(Instruction.Create(Code.Blendps_xmm_xmmm128_imm8, dst, src1, imm));
		}

		public void blendps(AssemblerRegisterXMM dst, AssemblerMemoryOperand src1, sbyte imm)
		{
			Register register = dst;
			MemoryOperand memory = src1.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Blendps_xmm_xmmm128_imm8, register, in memory, imm));
		}

		public void blendps(AssemblerRegisterXMM dst, AssemblerRegisterXMM src1, byte imm)
		{
			AddInstruction(Instruction.Create(Code.Blendps_xmm_xmmm128_imm8, (Register)dst, (Register)src1, (uint)imm));
		}

		public void blendps(AssemblerRegisterXMM dst, AssemblerMemoryOperand src1, byte imm)
		{
			Register register = dst;
			MemoryOperand memory = src1.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Blendps_xmm_xmmm128_imm8, register, in memory, (uint)imm));
		}

		public void blendvpd(AssemblerRegisterXMM dst, AssemblerRegisterXMM src)
		{
			AddInstruction(Instruction.Create(Code.Blendvpd_xmm_xmmm128, dst, src));
		}

		public void blendvpd(AssemblerRegisterXMM dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Blendvpd_xmm_xmmm128, register, in memory));
		}

		public void blendvps(AssemblerRegisterXMM dst, AssemblerRegisterXMM src)
		{
			AddInstruction(Instruction.Create(Code.Blendvps_xmm_xmmm128, dst, src));
		}

		public void blendvps(AssemblerRegisterXMM dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Blendvps_xmm_xmmm128, register, in memory));
		}

		public void blsfill(AssemblerRegister32 dst, AssemblerRegister32 src)
		{
			AddInstruction(Instruction.Create(Code.XOP_Blsfill_r32_rm32, dst, src));
		}

		public void blsfill(AssemblerRegister64 dst, AssemblerRegister64 src)
		{
			AddInstruction(Instruction.Create(Code.XOP_Blsfill_r64_rm64, dst, src));
		}

		public void blsfill(AssemblerRegister32 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.XOP_Blsfill_r32_rm32, register, in memory));
		}

		public void blsfill(AssemblerRegister64 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.XOP_Blsfill_r64_rm64, register, in memory));
		}

		public void blsi(AssemblerRegister32 dst, AssemblerRegister32 src)
		{
			AddInstruction(Instruction.Create(Code.VEX_Blsi_r32_rm32, dst, src));
		}

		public void blsi(AssemblerRegister64 dst, AssemblerRegister64 src)
		{
			AddInstruction(Instruction.Create(Code.VEX_Blsi_r64_rm64, dst, src));
		}

		public void blsi(AssemblerRegister32 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.VEX_Blsi_r32_rm32, register, in memory));
		}

		public void blsi(AssemblerRegister64 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.VEX_Blsi_r64_rm64, register, in memory));
		}

		public void blsic(AssemblerRegister32 dst, AssemblerRegister32 src)
		{
			AddInstruction(Instruction.Create(Code.XOP_Blsic_r32_rm32, dst, src));
		}

		public void blsic(AssemblerRegister64 dst, AssemblerRegister64 src)
		{
			AddInstruction(Instruction.Create(Code.XOP_Blsic_r64_rm64, dst, src));
		}

		public void blsic(AssemblerRegister32 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.XOP_Blsic_r32_rm32, register, in memory));
		}

		public void blsic(AssemblerRegister64 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.XOP_Blsic_r64_rm64, register, in memory));
		}

		public void blsmsk(AssemblerRegister32 dst, AssemblerRegister32 src)
		{
			AddInstruction(Instruction.Create(Code.VEX_Blsmsk_r32_rm32, dst, src));
		}

		public void blsmsk(AssemblerRegister64 dst, AssemblerRegister64 src)
		{
			AddInstruction(Instruction.Create(Code.VEX_Blsmsk_r64_rm64, dst, src));
		}

		public void blsmsk(AssemblerRegister32 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.VEX_Blsmsk_r32_rm32, register, in memory));
		}

		public void blsmsk(AssemblerRegister64 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.VEX_Blsmsk_r64_rm64, register, in memory));
		}

		public void blsr(AssemblerRegister32 dst, AssemblerRegister32 src)
		{
			AddInstruction(Instruction.Create(Code.VEX_Blsr_r32_rm32, dst, src));
		}

		public void blsr(AssemblerRegister64 dst, AssemblerRegister64 src)
		{
			AddInstruction(Instruction.Create(Code.VEX_Blsr_r64_rm64, dst, src));
		}

		public void blsr(AssemblerRegister32 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.VEX_Blsr_r32_rm32, register, in memory));
		}

		public void blsr(AssemblerRegister64 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.VEX_Blsr_r64_rm64, register, in memory));
		}

		public void bndcl(AssemblerRegisterBND dst, AssemblerRegister32 src)
		{
			AddInstruction(Instruction.Create(Code.Bndcl_bnd_rm32, dst, src));
		}

		public void bndcl(AssemblerRegisterBND dst, AssemblerRegister64 src)
		{
			AddInstruction(Instruction.Create(Code.Bndcl_bnd_rm64, dst, src));
		}

		public void bndcl(AssemblerRegisterBND dst, AssemblerMemoryOperand src)
		{
			Code code;
			if (src.Size == MemoryOperandSize.Qword)
			{
				code = Code.Bndcl_bnd_rm64;
			}
			else
			{
				if (src.Size != MemoryOperandSize.Dword)
				{
					throw NoOpCodeFoundFor(Mnemonic.Bndcl, dst, src);
				}
				code = Code.Bndcl_bnd_rm32;
			}
			Code code2 = code;
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(code2, register, in memory));
		}

		public void bndcn(AssemblerRegisterBND dst, AssemblerRegister32 src)
		{
			AddInstruction(Instruction.Create(Code.Bndcn_bnd_rm32, dst, src));
		}

		public void bndcn(AssemblerRegisterBND dst, AssemblerRegister64 src)
		{
			AddInstruction(Instruction.Create(Code.Bndcn_bnd_rm64, dst, src));
		}

		public void bndcn(AssemblerRegisterBND dst, AssemblerMemoryOperand src)
		{
			Code code;
			if (src.Size == MemoryOperandSize.Qword)
			{
				code = Code.Bndcn_bnd_rm64;
			}
			else
			{
				if (src.Size != MemoryOperandSize.Dword)
				{
					throw NoOpCodeFoundFor(Mnemonic.Bndcn, dst, src);
				}
				code = Code.Bndcn_bnd_rm32;
			}
			Code code2 = code;
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(code2, register, in memory));
		}

		public void bndcu(AssemblerRegisterBND dst, AssemblerRegister32 src)
		{
			AddInstruction(Instruction.Create(Code.Bndcu_bnd_rm32, dst, src));
		}

		public void bndcu(AssemblerRegisterBND dst, AssemblerRegister64 src)
		{
			AddInstruction(Instruction.Create(Code.Bndcu_bnd_rm64, dst, src));
		}

		public void bndcu(AssemblerRegisterBND dst, AssemblerMemoryOperand src)
		{
			Code code;
			if (src.Size == MemoryOperandSize.Qword)
			{
				code = Code.Bndcu_bnd_rm64;
			}
			else
			{
				if (src.Size != MemoryOperandSize.Dword)
				{
					throw NoOpCodeFoundFor(Mnemonic.Bndcu, dst, src);
				}
				code = Code.Bndcu_bnd_rm32;
			}
			Code code2 = code;
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(code2, register, in memory));
		}

		public void bndldx(AssemblerRegisterBND dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Bndldx_bnd_mib, register, in memory));
		}

		public void bndmk(AssemblerRegisterBND dst, AssemblerMemoryOperand src)
		{
			Code code;
			if (src.Size == MemoryOperandSize.Qword)
			{
				code = Code.Bndmk_bnd_m64;
			}
			else
			{
				if (src.Size != MemoryOperandSize.Dword)
				{
					throw NoOpCodeFoundFor(Mnemonic.Bndmk, dst, src);
				}
				code = Code.Bndmk_bnd_m32;
			}
			Code code2 = code;
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(code2, register, in memory));
		}

		public void bndmov(AssemblerRegisterBND dst, AssemblerRegisterBND src)
		{
			Code code = ((Bitness == 64) ? Code.Bndmov_bnd_bndm128 : Code.Bndmov_bnd_bndm64);
			AddInstruction(Instruction.Create(code, dst, src));
		}

		public void bndmov(AssemblerMemoryOperand dst, AssemblerRegisterBND src)
		{
			Code code = ((Bitness == 64) ? Code.Bndmov_bndm128_bnd : Code.Bndmov_bndm64_bnd);
			MemoryOperand memory = dst.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(code, in memory, src));
		}

		public void bndmov(AssemblerRegisterBND dst, AssemblerMemoryOperand src)
		{
			Code code = ((Bitness == 64) ? Code.Bndmov_bnd_bndm128 : Code.Bndmov_bnd_bndm64);
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(code, register, in memory));
		}

		public void bndstx(AssemblerMemoryOperand dst, AssemblerRegisterBND src)
		{
			MemoryOperand memory = dst.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Bndstx_mib_bnd, in memory, src));
		}

		public void bound(AssemblerRegister16 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Bound_r16_m1616, register, in memory));
		}

		public void bound(AssemblerRegister32 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Bound_r32_m3232, register, in memory));
		}

		public void bsf(AssemblerRegister16 dst, AssemblerRegister16 src)
		{
			AddInstruction(Instruction.Create(Code.Bsf_r16_rm16, dst, src));
		}

		public void bsf(AssemblerRegister32 dst, AssemblerRegister32 src)
		{
			AddInstruction(Instruction.Create(Code.Bsf_r32_rm32, dst, src));
		}

		public void bsf(AssemblerRegister64 dst, AssemblerRegister64 src)
		{
			AddInstruction(Instruction.Create(Code.Bsf_r64_rm64, dst, src));
		}

		public void bsf(AssemblerRegister16 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Bsf_r16_rm16, register, in memory));
		}

		public void bsf(AssemblerRegister32 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Bsf_r32_rm32, register, in memory));
		}

		public void bsf(AssemblerRegister64 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Bsf_r64_rm64, register, in memory));
		}

		public void bsr(AssemblerRegister16 dst, AssemblerRegister16 src)
		{
			AddInstruction(Instruction.Create(Code.Bsr_r16_rm16, dst, src));
		}

		public void bsr(AssemblerRegister32 dst, AssemblerRegister32 src)
		{
			AddInstruction(Instruction.Create(Code.Bsr_r32_rm32, dst, src));
		}

		public void bsr(AssemblerRegister64 dst, AssemblerRegister64 src)
		{
			AddInstruction(Instruction.Create(Code.Bsr_r64_rm64, dst, src));
		}

		public void bsr(AssemblerRegister16 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Bsr_r16_rm16, register, in memory));
		}

		public void bsr(AssemblerRegister32 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Bsr_r32_rm32, register, in memory));
		}

		public void bsr(AssemblerRegister64 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Bsr_r64_rm64, register, in memory));
		}

		public void bswap(AssemblerRegister16 dst)
		{
			AddInstruction(Instruction.Create(Code.Bswap_r16, dst));
		}

		public void bswap(AssemblerRegister32 dst)
		{
			AddInstruction(Instruction.Create(Code.Bswap_r32, dst));
		}

		public void bswap(AssemblerRegister64 dst)
		{
			AddInstruction(Instruction.Create(Code.Bswap_r64, dst));
		}

		public void bt(AssemblerRegister16 dst, AssemblerRegister16 src)
		{
			AddInstruction(Instruction.Create(Code.Bt_rm16_r16, dst, src));
		}

		public void bt(AssemblerMemoryOperand dst, AssemblerRegister16 src)
		{
			MemoryOperand memory = dst.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Bt_rm16_r16, in memory, src));
		}

		public void bt(AssemblerRegister32 dst, AssemblerRegister32 src)
		{
			AddInstruction(Instruction.Create(Code.Bt_rm32_r32, dst, src));
		}

		public void bt(AssemblerMemoryOperand dst, AssemblerRegister32 src)
		{
			MemoryOperand memory = dst.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Bt_rm32_r32, in memory, src));
		}

		public void bt(AssemblerRegister64 dst, AssemblerRegister64 src)
		{
			AddInstruction(Instruction.Create(Code.Bt_rm64_r64, dst, src));
		}

		public void bt(AssemblerMemoryOperand dst, AssemblerRegister64 src)
		{
			MemoryOperand memory = dst.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Bt_rm64_r64, in memory, src));
		}

		public void bt(AssemblerRegister16 dst, sbyte imm)
		{
			AddInstruction(Instruction.Create(Code.Bt_rm16_imm8, dst, imm));
		}

		public void bt(AssemblerRegister32 dst, sbyte imm)
		{
			AddInstruction(Instruction.Create(Code.Bt_rm32_imm8, dst, imm));
		}

		public void bt(AssemblerRegister64 dst, sbyte imm)
		{
			AddInstruction(Instruction.Create(Code.Bt_rm64_imm8, dst, imm));
		}

		public void bt(AssemblerMemoryOperand dst, sbyte imm)
		{
			Code code;
			if (dst.Size == MemoryOperandSize.Qword)
			{
				code = Code.Bt_rm64_imm8;
			}
			else if (dst.Size == MemoryOperandSize.Dword)
			{
				code = Code.Bt_rm32_imm8;
			}
			else
			{
				if (dst.Size != MemoryOperandSize.Word)
				{
					throw NoOpCodeFoundFor(Mnemonic.Bt, dst, imm);
				}
				code = Code.Bt_rm16_imm8;
			}
			Code code2 = code;
			MemoryOperand memory = dst.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(code2, in memory, imm));
		}

		public void bt(AssemblerRegister16 dst, byte imm)
		{
			AddInstruction(Instruction.Create(Code.Bt_rm16_imm8, (Register)dst, (uint)imm));
		}

		public void bt(AssemblerRegister32 dst, byte imm)
		{
			AddInstruction(Instruction.Create(Code.Bt_rm32_imm8, (Register)dst, (uint)imm));
		}

		public void bt(AssemblerRegister64 dst, byte imm)
		{
			AddInstruction(Instruction.Create(Code.Bt_rm64_imm8, (Register)dst, (uint)imm));
		}

		public void bt(AssemblerMemoryOperand dst, byte imm)
		{
			Code code;
			if (dst.Size == MemoryOperandSize.Qword)
			{
				code = Code.Bt_rm64_imm8;
			}
			else if (dst.Size == MemoryOperandSize.Dword)
			{
				code = Code.Bt_rm32_imm8;
			}
			else
			{
				if (dst.Size != MemoryOperandSize.Word)
				{
					throw NoOpCodeFoundFor(Mnemonic.Bt, dst, imm);
				}
				code = Code.Bt_rm16_imm8;
			}
			Code code2 = code;
			MemoryOperand memory = dst.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(code2, in memory, (uint)imm));
		}

		public void btc(AssemblerRegister16 dst, AssemblerRegister16 src)
		{
			AddInstruction(Instruction.Create(Code.Btc_rm16_r16, dst, src));
		}

		public void btc(AssemblerMemoryOperand dst, AssemblerRegister16 src)
		{
			MemoryOperand memory = dst.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Btc_rm16_r16, in memory, src));
		}

		public void btc(AssemblerRegister32 dst, AssemblerRegister32 src)
		{
			AddInstruction(Instruction.Create(Code.Btc_rm32_r32, dst, src));
		}

		public void btc(AssemblerMemoryOperand dst, AssemblerRegister32 src)
		{
			MemoryOperand memory = dst.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Btc_rm32_r32, in memory, src));
		}

		public void btc(AssemblerRegister64 dst, AssemblerRegister64 src)
		{
			AddInstruction(Instruction.Create(Code.Btc_rm64_r64, dst, src));
		}

		public void btc(AssemblerMemoryOperand dst, AssemblerRegister64 src)
		{
			MemoryOperand memory = dst.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Btc_rm64_r64, in memory, src));
		}

		public void btc(AssemblerRegister16 dst, sbyte imm)
		{
			AddInstruction(Instruction.Create(Code.Btc_rm16_imm8, dst, imm));
		}

		public void btc(AssemblerRegister32 dst, sbyte imm)
		{
			AddInstruction(Instruction.Create(Code.Btc_rm32_imm8, dst, imm));
		}

		public void btc(AssemblerRegister64 dst, sbyte imm)
		{
			AddInstruction(Instruction.Create(Code.Btc_rm64_imm8, dst, imm));
		}

		public void btc(AssemblerMemoryOperand dst, sbyte imm)
		{
			Code code;
			if (dst.Size == MemoryOperandSize.Qword)
			{
				code = Code.Btc_rm64_imm8;
			}
			else if (dst.Size == MemoryOperandSize.Dword)
			{
				code = Code.Btc_rm32_imm8;
			}
			else
			{
				if (dst.Size != MemoryOperandSize.Word)
				{
					throw NoOpCodeFoundFor(Mnemonic.Btc, dst, imm);
				}
				code = Code.Btc_rm16_imm8;
			}
			Code code2 = code;
			MemoryOperand memory = dst.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(code2, in memory, imm));
		}

		public void btc(AssemblerRegister16 dst, byte imm)
		{
			AddInstruction(Instruction.Create(Code.Btc_rm16_imm8, (Register)dst, (uint)imm));
		}

		public void btc(AssemblerRegister32 dst, byte imm)
		{
			AddInstruction(Instruction.Create(Code.Btc_rm32_imm8, (Register)dst, (uint)imm));
		}

		public void btc(AssemblerRegister64 dst, byte imm)
		{
			AddInstruction(Instruction.Create(Code.Btc_rm64_imm8, (Register)dst, (uint)imm));
		}

		public void btc(AssemblerMemoryOperand dst, byte imm)
		{
			Code code;
			if (dst.Size == MemoryOperandSize.Qword)
			{
				code = Code.Btc_rm64_imm8;
			}
			else if (dst.Size == MemoryOperandSize.Dword)
			{
				code = Code.Btc_rm32_imm8;
			}
			else
			{
				if (dst.Size != MemoryOperandSize.Word)
				{
					throw NoOpCodeFoundFor(Mnemonic.Btc, dst, imm);
				}
				code = Code.Btc_rm16_imm8;
			}
			Code code2 = code;
			MemoryOperand memory = dst.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(code2, in memory, (uint)imm));
		}

		public void btr(AssemblerRegister16 dst, AssemblerRegister16 src)
		{
			AddInstruction(Instruction.Create(Code.Btr_rm16_r16, dst, src));
		}

		public void btr(AssemblerMemoryOperand dst, AssemblerRegister16 src)
		{
			MemoryOperand memory = dst.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Btr_rm16_r16, in memory, src));
		}

		public void btr(AssemblerRegister32 dst, AssemblerRegister32 src)
		{
			AddInstruction(Instruction.Create(Code.Btr_rm32_r32, dst, src));
		}

		public void btr(AssemblerMemoryOperand dst, AssemblerRegister32 src)
		{
			MemoryOperand memory = dst.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Btr_rm32_r32, in memory, src));
		}

		public void btr(AssemblerRegister64 dst, AssemblerRegister64 src)
		{
			AddInstruction(Instruction.Create(Code.Btr_rm64_r64, dst, src));
		}

		public void btr(AssemblerMemoryOperand dst, AssemblerRegister64 src)
		{
			MemoryOperand memory = dst.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Btr_rm64_r64, in memory, src));
		}

		public void btr(AssemblerRegister16 dst, sbyte imm)
		{
			AddInstruction(Instruction.Create(Code.Btr_rm16_imm8, dst, imm));
		}

		public void btr(AssemblerRegister32 dst, sbyte imm)
		{
			AddInstruction(Instruction.Create(Code.Btr_rm32_imm8, dst, imm));
		}

		public void btr(AssemblerRegister64 dst, sbyte imm)
		{
			AddInstruction(Instruction.Create(Code.Btr_rm64_imm8, dst, imm));
		}

		public void btr(AssemblerMemoryOperand dst, sbyte imm)
		{
			Code code;
			if (dst.Size == MemoryOperandSize.Qword)
			{
				code = Code.Btr_rm64_imm8;
			}
			else if (dst.Size == MemoryOperandSize.Dword)
			{
				code = Code.Btr_rm32_imm8;
			}
			else
			{
				if (dst.Size != MemoryOperandSize.Word)
				{
					throw NoOpCodeFoundFor(Mnemonic.Btr, dst, imm);
				}
				code = Code.Btr_rm16_imm8;
			}
			Code code2 = code;
			MemoryOperand memory = dst.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(code2, in memory, imm));
		}

		public void btr(AssemblerRegister16 dst, byte imm)
		{
			AddInstruction(Instruction.Create(Code.Btr_rm16_imm8, (Register)dst, (uint)imm));
		}

		public void btr(AssemblerRegister32 dst, byte imm)
		{
			AddInstruction(Instruction.Create(Code.Btr_rm32_imm8, (Register)dst, (uint)imm));
		}

		public void btr(AssemblerRegister64 dst, byte imm)
		{
			AddInstruction(Instruction.Create(Code.Btr_rm64_imm8, (Register)dst, (uint)imm));
		}

		public void btr(AssemblerMemoryOperand dst, byte imm)
		{
			Code code;
			if (dst.Size == MemoryOperandSize.Qword)
			{
				code = Code.Btr_rm64_imm8;
			}
			else if (dst.Size == MemoryOperandSize.Dword)
			{
				code = Code.Btr_rm32_imm8;
			}
			else
			{
				if (dst.Size != MemoryOperandSize.Word)
				{
					throw NoOpCodeFoundFor(Mnemonic.Btr, dst, imm);
				}
				code = Code.Btr_rm16_imm8;
			}
			Code code2 = code;
			MemoryOperand memory = dst.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(code2, in memory, (uint)imm));
		}

		public void bts(AssemblerRegister16 dst, AssemblerRegister16 src)
		{
			AddInstruction(Instruction.Create(Code.Bts_rm16_r16, dst, src));
		}

		public void bts(AssemblerMemoryOperand dst, AssemblerRegister16 src)
		{
			MemoryOperand memory = dst.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Bts_rm16_r16, in memory, src));
		}

		public void bts(AssemblerRegister32 dst, AssemblerRegister32 src)
		{
			AddInstruction(Instruction.Create(Code.Bts_rm32_r32, dst, src));
		}

		public void bts(AssemblerMemoryOperand dst, AssemblerRegister32 src)
		{
			MemoryOperand memory = dst.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Bts_rm32_r32, in memory, src));
		}

		public void bts(AssemblerRegister64 dst, AssemblerRegister64 src)
		{
			AddInstruction(Instruction.Create(Code.Bts_rm64_r64, dst, src));
		}

		public void bts(AssemblerMemoryOperand dst, AssemblerRegister64 src)
		{
			MemoryOperand memory = dst.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Bts_rm64_r64, in memory, src));
		}

		public void bts(AssemblerRegister16 dst, sbyte imm)
		{
			AddInstruction(Instruction.Create(Code.Bts_rm16_imm8, dst, imm));
		}

		public void bts(AssemblerRegister32 dst, sbyte imm)
		{
			AddInstruction(Instruction.Create(Code.Bts_rm32_imm8, dst, imm));
		}

		public void bts(AssemblerRegister64 dst, sbyte imm)
		{
			AddInstruction(Instruction.Create(Code.Bts_rm64_imm8, dst, imm));
		}

		public void bts(AssemblerMemoryOperand dst, sbyte imm)
		{
			Code code;
			if (dst.Size == MemoryOperandSize.Qword)
			{
				code = Code.Bts_rm64_imm8;
			}
			else if (dst.Size == MemoryOperandSize.Dword)
			{
				code = Code.Bts_rm32_imm8;
			}
			else
			{
				if (dst.Size != MemoryOperandSize.Word)
				{
					throw NoOpCodeFoundFor(Mnemonic.Bts, dst, imm);
				}
				code = Code.Bts_rm16_imm8;
			}
			Code code2 = code;
			MemoryOperand memory = dst.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(code2, in memory, imm));
		}

		public void bts(AssemblerRegister16 dst, byte imm)
		{
			AddInstruction(Instruction.Create(Code.Bts_rm16_imm8, (Register)dst, (uint)imm));
		}

		public void bts(AssemblerRegister32 dst, byte imm)
		{
			AddInstruction(Instruction.Create(Code.Bts_rm32_imm8, (Register)dst, (uint)imm));
		}

		public void bts(AssemblerRegister64 dst, byte imm)
		{
			AddInstruction(Instruction.Create(Code.Bts_rm64_imm8, (Register)dst, (uint)imm));
		}

		public void bts(AssemblerMemoryOperand dst, byte imm)
		{
			Code code;
			if (dst.Size == MemoryOperandSize.Qword)
			{
				code = Code.Bts_rm64_imm8;
			}
			else if (dst.Size == MemoryOperandSize.Dword)
			{
				code = Code.Bts_rm32_imm8;
			}
			else
			{
				if (dst.Size != MemoryOperandSize.Word)
				{
					throw NoOpCodeFoundFor(Mnemonic.Bts, dst, imm);
				}
				code = Code.Bts_rm16_imm8;
			}
			Code code2 = code;
			MemoryOperand memory = dst.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(code2, in memory, (uint)imm));
		}

		public void bzhi(AssemblerRegister32 dst, AssemblerRegister32 src1, AssemblerRegister32 src2)
		{
			AddInstruction(Instruction.Create(Code.VEX_Bzhi_r32_rm32_r32, dst, src1, src2));
		}

		public void bzhi(AssemblerRegister32 dst, AssemblerMemoryOperand src1, AssemblerRegister32 src2)
		{
			Register register = dst;
			MemoryOperand memory = src1.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.VEX_Bzhi_r32_rm32_r32, register, in memory, src2));
		}

		public void bzhi(AssemblerRegister64 dst, AssemblerRegister64 src1, AssemblerRegister64 src2)
		{
			AddInstruction(Instruction.Create(Code.VEX_Bzhi_r64_rm64_r64, dst, src1, src2));
		}

		public void bzhi(AssemblerRegister64 dst, AssemblerMemoryOperand src1, AssemblerRegister64 src2)
		{
			Register register = dst;
			MemoryOperand memory = src1.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.VEX_Bzhi_r64_rm64_r64, register, in memory, src2));
		}

		public void call(AssemblerRegister16 dst)
		{
			AddInstruction(Instruction.Create(Code.Call_rm16, dst));
		}

		public void call(AssemblerRegister32 dst)
		{
			AddInstruction(Instruction.Create(Code.Call_rm32, dst));
		}

		public void call(AssemblerRegister64 dst)
		{
			AddInstruction(Instruction.Create(Code.Call_rm64, dst));
		}

		public void call(AssemblerMemoryOperand dst)
		{
			Code code;
			if (dst.Size == MemoryOperandSize.Tbyte)
			{
				code = Code.Call_m1664;
			}
			else if (dst.Size == MemoryOperandSize.Qword)
			{
				code = Code.Call_rm64;
			}
			else if (dst.Size == MemoryOperandSize.Fword)
			{
				code = Code.Call_m1632;
			}
			else if (dst.Size == MemoryOperandSize.Dword)
			{
				code = ((Bitness >= 32) ? Code.Call_rm32 : Code.Call_m1616);
			}
			else
			{
				if (dst.Size != MemoryOperandSize.Word)
				{
					throw NoOpCodeFoundFor(Mnemonic.Call, dst);
				}
				code = Code.Call_rm16;
			}
			Code code2 = code;
			MemoryOperand memory = dst.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(code2, in memory));
		}

		public void call(Label dst)
		{
			Code code = ((Bitness != 64) ? ((Bitness >= 32) ? Code.Call_rel32_32 : Code.Call_rel16) : Code.Call_rel32_64);
			AddInstruction(Instruction.CreateBranch(code, dst.Id));
		}

		public void call(ulong dst)
		{
			Code code = ((Bitness != 64) ? ((Bitness >= 32) ? Code.Call_rel32_32 : Code.Call_rel16) : Code.Call_rel32_64);
			AddInstruction(Instruction.CreateBranch(code, dst));
		}

		public void cbw()
		{
			AddInstruction(Instruction.Create(Code.Cbw));
		}

		public void ccs_encrypt()
		{
			Code code = ((Bitness != 64) ? ((Bitness >= 32) ? Code.Ccs_encrypt_32 : Code.Ccs_encrypt_16) : Code.Ccs_encrypt_64);
			AddInstruction(Instruction.Create(code));
		}

		public void ccs_hash()
		{
			Code code = ((Bitness != 64) ? ((Bitness >= 32) ? Code.Ccs_hash_32 : Code.Ccs_hash_16) : Code.Ccs_hash_64);
			AddInstruction(Instruction.Create(code));
		}

		public void cdq()
		{
			AddInstruction(Instruction.Create(Code.Cdq));
		}

		public void cdqe()
		{
			AddInstruction(Instruction.Create(Code.Cdqe));
		}

		public void cl1invmb()
		{
			AddInstruction(Instruction.Create(Code.Cl1invmb));
		}

		public void clac()
		{
			AddInstruction(Instruction.Create(Code.Clac));
		}

		public void clc()
		{
			AddInstruction(Instruction.Create(Code.Clc));
		}

		public void cld()
		{
			AddInstruction(Instruction.Create(Code.Cld));
		}

		public void cldemote(AssemblerMemoryOperand dst)
		{
			MemoryOperand memory = dst.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Cldemote_m8, in memory));
		}

		public void clflush(AssemblerMemoryOperand dst)
		{
			MemoryOperand memory = dst.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Clflush_m8, in memory));
		}

		public void clflushopt(AssemblerMemoryOperand dst)
		{
			MemoryOperand memory = dst.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Clflushopt_m8, in memory));
		}

		public void clgi()
		{
			AddInstruction(Instruction.Create(Code.Clgi));
		}

		public void cli()
		{
			AddInstruction(Instruction.Create(Code.Cli));
		}

		public void clrssbsy(AssemblerMemoryOperand dst)
		{
			MemoryOperand memory = dst.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Clrssbsy_m64, in memory));
		}

		public void clts()
		{
			AddInstruction(Instruction.Create(Code.Clts));
		}

		public void clui()
		{
			AddInstruction(Instruction.Create(Code.Clui));
		}

		public void clwb(AssemblerMemoryOperand dst)
		{
			MemoryOperand memory = dst.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Clwb_m8, in memory));
		}

		public void clzero()
		{
			Code code = ((Bitness != 64) ? ((Bitness >= 32) ? Code.Clzerod : Code.Clzerow) : Code.Clzeroq);
			AddInstruction(Instruction.Create(code));
		}

		public void cmc()
		{
			AddInstruction(Instruction.Create(Code.Cmc));
		}

		public void cmova(AssemblerRegister16 dst, AssemblerRegister16 src)
		{
			AddInstruction(Instruction.Create(Code.Cmova_r16_rm16, dst, src));
		}

		public void cmova(AssemblerRegister32 dst, AssemblerRegister32 src)
		{
			AddInstruction(Instruction.Create(Code.Cmova_r32_rm32, dst, src));
		}

		public void cmova(AssemblerRegister64 dst, AssemblerRegister64 src)
		{
			AddInstruction(Instruction.Create(Code.Cmova_r64_rm64, dst, src));
		}

		public void cmova(AssemblerRegister16 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Cmova_r16_rm16, register, in memory));
		}

		public void cmova(AssemblerRegister32 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Cmova_r32_rm32, register, in memory));
		}

		public void cmova(AssemblerRegister64 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Cmova_r64_rm64, register, in memory));
		}

		public void cmovae(AssemblerRegister16 dst, AssemblerRegister16 src)
		{
			AddInstruction(Instruction.Create(Code.Cmovae_r16_rm16, dst, src));
		}

		public void cmovae(AssemblerRegister32 dst, AssemblerRegister32 src)
		{
			AddInstruction(Instruction.Create(Code.Cmovae_r32_rm32, dst, src));
		}

		public void cmovae(AssemblerRegister64 dst, AssemblerRegister64 src)
		{
			AddInstruction(Instruction.Create(Code.Cmovae_r64_rm64, dst, src));
		}

		public void cmovae(AssemblerRegister16 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Cmovae_r16_rm16, register, in memory));
		}

		public void cmovae(AssemblerRegister32 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Cmovae_r32_rm32, register, in memory));
		}

		public void cmovae(AssemblerRegister64 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Cmovae_r64_rm64, register, in memory));
		}

		public void cmovb(AssemblerRegister16 dst, AssemblerRegister16 src)
		{
			AddInstruction(Instruction.Create(Code.Cmovb_r16_rm16, dst, src));
		}

		public void cmovb(AssemblerRegister32 dst, AssemblerRegister32 src)
		{
			AddInstruction(Instruction.Create(Code.Cmovb_r32_rm32, dst, src));
		}

		public void cmovb(AssemblerRegister64 dst, AssemblerRegister64 src)
		{
			AddInstruction(Instruction.Create(Code.Cmovb_r64_rm64, dst, src));
		}

		public void cmovb(AssemblerRegister16 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Cmovb_r16_rm16, register, in memory));
		}

		public void cmovb(AssemblerRegister32 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Cmovb_r32_rm32, register, in memory));
		}

		public void cmovb(AssemblerRegister64 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Cmovb_r64_rm64, register, in memory));
		}

		public void cmovbe(AssemblerRegister16 dst, AssemblerRegister16 src)
		{
			AddInstruction(Instruction.Create(Code.Cmovbe_r16_rm16, dst, src));
		}

		public void cmovbe(AssemblerRegister32 dst, AssemblerRegister32 src)
		{
			AddInstruction(Instruction.Create(Code.Cmovbe_r32_rm32, dst, src));
		}

		public void cmovbe(AssemblerRegister64 dst, AssemblerRegister64 src)
		{
			AddInstruction(Instruction.Create(Code.Cmovbe_r64_rm64, dst, src));
		}

		public void cmovbe(AssemblerRegister16 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Cmovbe_r16_rm16, register, in memory));
		}

		public void cmovbe(AssemblerRegister32 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Cmovbe_r32_rm32, register, in memory));
		}

		public void cmovbe(AssemblerRegister64 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Cmovbe_r64_rm64, register, in memory));
		}

		public void cmovc(AssemblerRegister16 dst, AssemblerRegister16 src)
		{
			AddInstruction(Instruction.Create(Code.Cmovb_r16_rm16, dst, src));
		}

		public void cmovc(AssemblerRegister32 dst, AssemblerRegister32 src)
		{
			AddInstruction(Instruction.Create(Code.Cmovb_r32_rm32, dst, src));
		}

		public void cmovc(AssemblerRegister64 dst, AssemblerRegister64 src)
		{
			AddInstruction(Instruction.Create(Code.Cmovb_r64_rm64, dst, src));
		}

		public void cmovc(AssemblerRegister16 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Cmovb_r16_rm16, register, in memory));
		}

		public void cmovc(AssemblerRegister32 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Cmovb_r32_rm32, register, in memory));
		}

		public void cmovc(AssemblerRegister64 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Cmovb_r64_rm64, register, in memory));
		}

		public void cmove(AssemblerRegister16 dst, AssemblerRegister16 src)
		{
			AddInstruction(Instruction.Create(Code.Cmove_r16_rm16, dst, src));
		}

		public void cmove(AssemblerRegister32 dst, AssemblerRegister32 src)
		{
			AddInstruction(Instruction.Create(Code.Cmove_r32_rm32, dst, src));
		}

		public void cmove(AssemblerRegister64 dst, AssemblerRegister64 src)
		{
			AddInstruction(Instruction.Create(Code.Cmove_r64_rm64, dst, src));
		}

		public void cmove(AssemblerRegister16 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Cmove_r16_rm16, register, in memory));
		}

		public void cmove(AssemblerRegister32 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Cmove_r32_rm32, register, in memory));
		}

		public void cmove(AssemblerRegister64 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Cmove_r64_rm64, register, in memory));
		}

		public void cmovg(AssemblerRegister16 dst, AssemblerRegister16 src)
		{
			AddInstruction(Instruction.Create(Code.Cmovg_r16_rm16, dst, src));
		}

		public void cmovg(AssemblerRegister32 dst, AssemblerRegister32 src)
		{
			AddInstruction(Instruction.Create(Code.Cmovg_r32_rm32, dst, src));
		}

		public void cmovg(AssemblerRegister64 dst, AssemblerRegister64 src)
		{
			AddInstruction(Instruction.Create(Code.Cmovg_r64_rm64, dst, src));
		}

		public void cmovg(AssemblerRegister16 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Cmovg_r16_rm16, register, in memory));
		}

		public void cmovg(AssemblerRegister32 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Cmovg_r32_rm32, register, in memory));
		}

		public void cmovg(AssemblerRegister64 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Cmovg_r64_rm64, register, in memory));
		}

		public void cmovge(AssemblerRegister16 dst, AssemblerRegister16 src)
		{
			AddInstruction(Instruction.Create(Code.Cmovge_r16_rm16, dst, src));
		}

		public void cmovge(AssemblerRegister32 dst, AssemblerRegister32 src)
		{
			AddInstruction(Instruction.Create(Code.Cmovge_r32_rm32, dst, src));
		}

		public void cmovge(AssemblerRegister64 dst, AssemblerRegister64 src)
		{
			AddInstruction(Instruction.Create(Code.Cmovge_r64_rm64, dst, src));
		}

		public void cmovge(AssemblerRegister16 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Cmovge_r16_rm16, register, in memory));
		}

		public void cmovge(AssemblerRegister32 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Cmovge_r32_rm32, register, in memory));
		}

		public void cmovge(AssemblerRegister64 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Cmovge_r64_rm64, register, in memory));
		}

		public void cmovl(AssemblerRegister16 dst, AssemblerRegister16 src)
		{
			AddInstruction(Instruction.Create(Code.Cmovl_r16_rm16, dst, src));
		}

		public void cmovl(AssemblerRegister32 dst, AssemblerRegister32 src)
		{
			AddInstruction(Instruction.Create(Code.Cmovl_r32_rm32, dst, src));
		}

		public void cmovl(AssemblerRegister64 dst, AssemblerRegister64 src)
		{
			AddInstruction(Instruction.Create(Code.Cmovl_r64_rm64, dst, src));
		}

		public void cmovl(AssemblerRegister16 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Cmovl_r16_rm16, register, in memory));
		}

		public void cmovl(AssemblerRegister32 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Cmovl_r32_rm32, register, in memory));
		}

		public void cmovl(AssemblerRegister64 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Cmovl_r64_rm64, register, in memory));
		}

		public void cmovle(AssemblerRegister16 dst, AssemblerRegister16 src)
		{
			AddInstruction(Instruction.Create(Code.Cmovle_r16_rm16, dst, src));
		}

		public void cmovle(AssemblerRegister32 dst, AssemblerRegister32 src)
		{
			AddInstruction(Instruction.Create(Code.Cmovle_r32_rm32, dst, src));
		}

		public void cmovle(AssemblerRegister64 dst, AssemblerRegister64 src)
		{
			AddInstruction(Instruction.Create(Code.Cmovle_r64_rm64, dst, src));
		}

		public void cmovle(AssemblerRegister16 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Cmovle_r16_rm16, register, in memory));
		}

		public void cmovle(AssemblerRegister32 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Cmovle_r32_rm32, register, in memory));
		}

		public void cmovle(AssemblerRegister64 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Cmovle_r64_rm64, register, in memory));
		}

		public void cmovna(AssemblerRegister16 dst, AssemblerRegister16 src)
		{
			AddInstruction(Instruction.Create(Code.Cmovbe_r16_rm16, dst, src));
		}

		public void cmovna(AssemblerRegister32 dst, AssemblerRegister32 src)
		{
			AddInstruction(Instruction.Create(Code.Cmovbe_r32_rm32, dst, src));
		}

		public void cmovna(AssemblerRegister64 dst, AssemblerRegister64 src)
		{
			AddInstruction(Instruction.Create(Code.Cmovbe_r64_rm64, dst, src));
		}

		public void cmovna(AssemblerRegister16 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Cmovbe_r16_rm16, register, in memory));
		}

		public void cmovna(AssemblerRegister32 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Cmovbe_r32_rm32, register, in memory));
		}

		public void cmovna(AssemblerRegister64 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Cmovbe_r64_rm64, register, in memory));
		}

		public void cmovnae(AssemblerRegister16 dst, AssemblerRegister16 src)
		{
			AddInstruction(Instruction.Create(Code.Cmovb_r16_rm16, dst, src));
		}

		public void cmovnae(AssemblerRegister32 dst, AssemblerRegister32 src)
		{
			AddInstruction(Instruction.Create(Code.Cmovb_r32_rm32, dst, src));
		}

		public void cmovnae(AssemblerRegister64 dst, AssemblerRegister64 src)
		{
			AddInstruction(Instruction.Create(Code.Cmovb_r64_rm64, dst, src));
		}

		public void cmovnae(AssemblerRegister16 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Cmovb_r16_rm16, register, in memory));
		}

		public void cmovnae(AssemblerRegister32 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Cmovb_r32_rm32, register, in memory));
		}

		public void cmovnae(AssemblerRegister64 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Cmovb_r64_rm64, register, in memory));
		}

		public void cmovnb(AssemblerRegister16 dst, AssemblerRegister16 src)
		{
			AddInstruction(Instruction.Create(Code.Cmovae_r16_rm16, dst, src));
		}

		public void cmovnb(AssemblerRegister32 dst, AssemblerRegister32 src)
		{
			AddInstruction(Instruction.Create(Code.Cmovae_r32_rm32, dst, src));
		}

		public void cmovnb(AssemblerRegister64 dst, AssemblerRegister64 src)
		{
			AddInstruction(Instruction.Create(Code.Cmovae_r64_rm64, dst, src));
		}

		public void cmovnb(AssemblerRegister16 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Cmovae_r16_rm16, register, in memory));
		}

		public void cmovnb(AssemblerRegister32 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Cmovae_r32_rm32, register, in memory));
		}

		public void cmovnb(AssemblerRegister64 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Cmovae_r64_rm64, register, in memory));
		}

		public void cmovnbe(AssemblerRegister16 dst, AssemblerRegister16 src)
		{
			AddInstruction(Instruction.Create(Code.Cmova_r16_rm16, dst, src));
		}

		public void cmovnbe(AssemblerRegister32 dst, AssemblerRegister32 src)
		{
			AddInstruction(Instruction.Create(Code.Cmova_r32_rm32, dst, src));
		}

		public void cmovnbe(AssemblerRegister64 dst, AssemblerRegister64 src)
		{
			AddInstruction(Instruction.Create(Code.Cmova_r64_rm64, dst, src));
		}

		public void cmovnbe(AssemblerRegister16 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Cmova_r16_rm16, register, in memory));
		}

		public void cmovnbe(AssemblerRegister32 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Cmova_r32_rm32, register, in memory));
		}

		public void cmovnbe(AssemblerRegister64 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Cmova_r64_rm64, register, in memory));
		}

		public void cmovnc(AssemblerRegister16 dst, AssemblerRegister16 src)
		{
			AddInstruction(Instruction.Create(Code.Cmovae_r16_rm16, dst, src));
		}

		public void cmovnc(AssemblerRegister32 dst, AssemblerRegister32 src)
		{
			AddInstruction(Instruction.Create(Code.Cmovae_r32_rm32, dst, src));
		}

		public void cmovnc(AssemblerRegister64 dst, AssemblerRegister64 src)
		{
			AddInstruction(Instruction.Create(Code.Cmovae_r64_rm64, dst, src));
		}

		public void cmovnc(AssemblerRegister16 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Cmovae_r16_rm16, register, in memory));
		}

		public void cmovnc(AssemblerRegister32 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Cmovae_r32_rm32, register, in memory));
		}

		public void cmovnc(AssemblerRegister64 dst, AssemblerMemoryOperand src)
		{
			Register register = dst;
			MemoryOperand memory = src.ToMemoryOperand(Bitness);
			AddInstruction(Instruction.Create(Code.Cmovae_r64_rm64, register, in memory));
		}

		public void cmovne(AssemblerRegister16 dst, AssemblerRegister16 src)
		{
			AddInstruction(Instruction.Create(Code.Cmovne_r16_rm16, dst, src));
		}

		public void cmovne(AssemblerRegister32 dst, AssemblerRegister32 src)
		{
			AddInstruction(Instruction.Create(Code.Cmovne_r32_rm32, dst, src));
		}

		public void cmovne(AssemblerRegister64 dst, AssemblerRegister64 src)
		{
			AddInstruction(Instruction.Create(Code.Cmovne_r64_rm64, dst, src));
		}

		public void cmovne(Assembl

BepInExPack/BepInEx/core/Il2Cpp.TlsAdapter.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Net;
using System.Net.Security;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Authentication;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using System.Security.Permissions;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using HarmonyLib;
using Il2Cpp.TlsAdapter;
using Il2Cpp.TlsAdapter.MonoLegacyTls;
using Mono.Net.Security;
using Mono.Security.Cryptography;
using Mono.Security.Interface;
using Mono.Security.Protocol.Tls;
using Mono.Security.Protocol.Tls.Handshake;
using Mono.Security.Protocol.Tls.Handshake.Client;
using Mono.Security.Protocol.Tls.Handshake.Server;
using Mono.Security.X509;
using Mono.Security.X509.Extensions;
using Mono.Unity;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("BepInEx")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("\n            Implements common Mono TLS providers for modding Unity games which use Il2Cpp runtime.\n            This allows to use HTTPS the same way you'd do it in a normal Unity game using Mono runtime.\n        ")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1")]
[assembly: AssemblyProduct("Il2Cpp.TlsAdapter")]
[assembly: AssemblyTitle("Il2Cpp.TlsAdapter")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/BepInEx/Il2Cpp.TlsAdapter")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.0")]
[module: UnverifiableCode]
namespace Mono.Unity
{
	internal static class CertHelper
	{
		public unsafe static void AddCertificatesToNativeChain(UnityTls.unitytls_x509list* nativeCertificateChain, X509CertificateCollection certificates, UnityTls.unitytls_errorstate* errorState)
		{
			foreach (X509Certificate certificate in certificates)
			{
				AddCertificateToNativeChain(nativeCertificateChain, certificate, errorState);
			}
		}

		public unsafe static void AddCertificateToNativeChain(UnityTls.unitytls_x509list* nativeCertificateChain, X509Certificate certificate, UnityTls.unitytls_errorstate* errorState)
		{
			byte[] rawCertData = certificate.GetRawCertData();
			fixed (byte* buffer = rawCertData)
			{
				UnityTls.NativeInterface.unitytls_x509list_append_der(nativeCertificateChain, buffer, (IntPtr)rawCertData.Length, errorState);
			}
			X509CertificateImpl impl = certificate.Impl;
			X509Certificate2Impl val = (X509Certificate2Impl)(object)((impl is X509Certificate2Impl) ? impl : null);
			if (!(certificate is X509Certificate2 x509Certificate) || x509Certificate.Impl == null)
			{
				return;
			}
			X509CertificateImplCollection intermediateCertificates = val.IntermediateCertificates;
			if (intermediateCertificates != null && intermediateCertificates.Count > 0)
			{
				for (int i = 0; i < intermediateCertificates.Count; i++)
				{
					AddCertificateToNativeChain(nativeCertificateChain, new X509Certificate(intermediateCertificates[i]), errorState);
				}
			}
		}
	}
	internal static class Debug
	{
		public static void CheckAndThrow(UnityTls.unitytls_errorstate errorState, string context, AlertDescription defaultAlert = 80)
		{
			//IL_0020: 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)
			if (errorState.code == UnityTls.unitytls_error_code.UNITYTLS_SUCCESS)
			{
				return;
			}
			string text = $"{context} - error code: {errorState.code}";
			throw new TlsException(defaultAlert, text);
		}

		public static void CheckAndThrow(UnityTls.unitytls_errorstate errorState, UnityTls.unitytls_x509verify_result verifyResult, string context, AlertDescription defaultAlert = 80)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: 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)
			if (verifyResult == UnityTls.unitytls_x509verify_result.UNITYTLS_X509VERIFY_SUCCESS)
			{
				CheckAndThrow(errorState, context, defaultAlert);
				return;
			}
			AlertDescription val = UnityTlsConversions.VerifyResultToAlertDescription(verifyResult, defaultAlert);
			string text = $"{context} - error code: {errorState.code}, verify result: {verifyResult}";
			throw new TlsException(val, text);
		}
	}
	internal static class UnityTls
	{
		public enum unitytls_error_code : uint
		{
			UNITYTLS_SUCCESS = 0u,
			UNITYTLS_INVALID_ARGUMENT = 1u,
			UNITYTLS_INVALID_FORMAT = 2u,
			UNITYTLS_INVALID_PASSWORD = 3u,
			UNITYTLS_INVALID_STATE = 4u,
			UNITYTLS_BUFFER_OVERFLOW = 5u,
			UNITYTLS_OUT_OF_MEMORY = 6u,
			UNITYTLS_INTERNAL_ERROR = 7u,
			UNITYTLS_NOT_SUPPORTED = 8u,
			UNITYTLS_ENTROPY_SOURCE_FAILED = 9u,
			UNITYTLS_STREAM_CLOSED = 10u,
			UNITYTLS_USER_CUSTOM_ERROR_START = 1048576u,
			UNITYTLS_USER_WOULD_BLOCK = 1048577u,
			UNITYTLS_USER_READ_FAILED = 1048578u,
			UNITYTLS_USER_WRITE_FAILED = 1048579u,
			UNITYTLS_USER_UNKNOWN_ERROR = 1048580u,
			UNITYTLS_USER_CUSTOM_ERROR_END = 2097152u
		}

		public struct unitytls_errorstate
		{
			private uint magic;

			public unitytls_error_code code;

			private ulong reserved;
		}

		[StructLayout(LayoutKind.Sequential, Size = 1)]
		public struct unitytls_key
		{
		}

		public struct unitytls_key_ref
		{
			public ulong handle;
		}

		[StructLayout(LayoutKind.Sequential, Size = 1)]
		public struct unitytls_x509
		{
		}

		public struct unitytls_x509_ref
		{
			public ulong handle;
		}

		[StructLayout(LayoutKind.Sequential, Size = 1)]
		public struct unitytls_x509list
		{
		}

		public struct unitytls_x509list_ref
		{
			public ulong handle;
		}

		[Flags]
		public enum unitytls_x509verify_result : uint
		{
			UNITYTLS_X509VERIFY_SUCCESS = 0u,
			UNITYTLS_X509VERIFY_NOT_DONE = 0x80000000u,
			UNITYTLS_X509VERIFY_FATAL_ERROR = uint.MaxValue,
			UNITYTLS_X509VERIFY_FLAG_EXPIRED = 1u,
			UNITYTLS_X509VERIFY_FLAG_REVOKED = 2u,
			UNITYTLS_X509VERIFY_FLAG_CN_MISMATCH = 4u,
			UNITYTLS_X509VERIFY_FLAG_NOT_TRUSTED = 8u,
			UNITYTLS_X509VERIFY_FLAG_USER_ERROR1 = 0x10000u,
			UNITYTLS_X509VERIFY_FLAG_USER_ERROR2 = 0x20000u,
			UNITYTLS_X509VERIFY_FLAG_USER_ERROR3 = 0x40000u,
			UNITYTLS_X509VERIFY_FLAG_USER_ERROR4 = 0x80000u,
			UNITYTLS_X509VERIFY_FLAG_USER_ERROR5 = 0x100000u,
			UNITYTLS_X509VERIFY_FLAG_USER_ERROR6 = 0x200000u,
			UNITYTLS_X509VERIFY_FLAG_USER_ERROR7 = 0x400000u,
			UNITYTLS_X509VERIFY_FLAG_USER_ERROR8 = 0x800000u,
			UNITYTLS_X509VERIFY_FLAG_UNKNOWN_ERROR = 0x8000000u
		}

		[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
		public unsafe delegate unitytls_x509verify_result unitytls_x509verify_callback(void* userData, unitytls_x509_ref cert, unitytls_x509verify_result result, unitytls_errorstate* errorState);

		[StructLayout(LayoutKind.Sequential, Size = 1)]
		public struct unitytls_tlsctx
		{
		}

		public struct unitytls_tlsctx_ref
		{
			public ulong handle;
		}

		[StructLayout(LayoutKind.Sequential, Size = 1)]
		public struct unitytls_x509name
		{
		}

		public enum unitytls_ciphersuite : uint
		{
			UNITYTLS_CIPHERSUITE_INVALID = 16777215u
		}

		public enum unitytls_protocol : uint
		{
			UNITYTLS_PROTOCOL_TLS_1_0,
			UNITYTLS_PROTOCOL_TLS_1_1,
			UNITYTLS_PROTOCOL_TLS_1_2,
			UNITYTLS_PROTOCOL_INVALID
		}

		public struct unitytls_tlsctx_protocolrange
		{
			public unitytls_protocol min;

			public unitytls_protocol max;
		}

		[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
		public unsafe delegate IntPtr unitytls_tlsctx_write_callback(void* userData, byte* data, IntPtr bufferLen, unitytls_errorstate* errorState);

		[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
		public unsafe delegate IntPtr unitytls_tlsctx_read_callback(void* userData, byte* buffer, IntPtr bufferLen, unitytls_errorstate* errorState);

		[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
		public unsafe delegate void unitytls_tlsctx_trace_callback(void* userData, unitytls_tlsctx* ctx, byte* traceMessage, IntPtr traceMessageLen);

		[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
		public unsafe delegate void unitytls_tlsctx_certificate_callback(void* userData, unitytls_tlsctx* ctx, byte* cn, IntPtr cnLen, unitytls_x509name* caList, IntPtr caListLen, unitytls_x509list_ref* chain, unitytls_key_ref* key, unitytls_errorstate* errorState);

		[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
		public unsafe delegate unitytls_x509verify_result unitytls_tlsctx_x509verify_callback(void* userData, unitytls_x509list_ref chain, unitytls_errorstate* errorState);

		public struct unitytls_tlsctx_callbacks
		{
			public unitytls_tlsctx_read_callback read;

			public unitytls_tlsctx_write_callback write;

			public unsafe void* data;
		}

		[StructLayout(LayoutKind.Sequential)]
		public class unitytls_interface_struct
		{
			[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
			public delegate unitytls_errorstate unitytls_errorstate_create_t();

			[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
			public unsafe delegate void unitytls_errorstate_raise_error_t(unitytls_errorstate* errorState, unitytls_error_code errorCode);

			[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
			public unsafe delegate unitytls_key_ref unitytls_key_get_ref_t(unitytls_key* key, unitytls_errorstate* errorState);

			[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
			public unsafe delegate unitytls_key* unitytls_key_parse_der_t(byte* buffer, IntPtr bufferLen, byte* password, IntPtr passwordLen, unitytls_errorstate* errorState);

			[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
			public unsafe delegate unitytls_key* unitytls_key_parse_pem_t(byte* buffer, IntPtr bufferLen, byte* password, IntPtr passwordLen, unitytls_errorstate* errorState);

			[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
			public unsafe delegate void unitytls_key_free_t(unitytls_key* key);

			[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
			public unsafe delegate IntPtr unitytls_x509_export_der_t(unitytls_x509_ref cert, byte* buffer, IntPtr bufferLen, unitytls_errorstate* errorState);

			[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
			public unsafe delegate unitytls_x509list_ref unitytls_x509list_get_ref_t(unitytls_x509list* list, unitytls_errorstate* errorState);

			[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
			public unsafe delegate unitytls_x509_ref unitytls_x509list_get_x509_t(unitytls_x509list_ref list, IntPtr index, unitytls_errorstate* errorState);

			[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
			public unsafe delegate unitytls_x509list* unitytls_x509list_create_t(unitytls_errorstate* errorState);

			[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
			public unsafe delegate void unitytls_x509list_append_t(unitytls_x509list* list, unitytls_x509_ref cert, unitytls_errorstate* errorState);

			[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
			public unsafe delegate void unitytls_x509list_append_der_t(unitytls_x509list* list, byte* buffer, IntPtr bufferLen, unitytls_errorstate* errorState);

			[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
			public unsafe delegate void unitytls_x509list_append_pem_t(unitytls_x509list* list, byte* buffer, IntPtr bufferLen, unitytls_errorstate* errorState);

			[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
			public unsafe delegate void unitytls_x509list_free_t(unitytls_x509list* list);

			[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
			public unsafe delegate unitytls_x509verify_result unitytls_x509verify_default_ca_t(unitytls_x509list_ref chain, byte* cn, IntPtr cnLen, unitytls_x509verify_callback cb, void* userData, unitytls_errorstate* errorState);

			[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
			public unsafe delegate unitytls_x509verify_result unitytls_x509verify_explicit_ca_t(unitytls_x509list_ref chain, unitytls_x509list_ref trustCA, byte* cn, IntPtr cnLen, unitytls_x509verify_callback cb, void* userData, unitytls_errorstate* errorState);

			[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
			public unsafe delegate unitytls_tlsctx* unitytls_tlsctx_create_server_t(unitytls_tlsctx_protocolrange supportedProtocols, unitytls_tlsctx_callbacks callbacks, ulong certChain, ulong leafCertificateKey, unitytls_errorstate* errorState);

			[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
			public unsafe delegate unitytls_tlsctx* unitytls_tlsctx_create_client_t(unitytls_tlsctx_protocolrange supportedProtocols, unitytls_tlsctx_callbacks callbacks, byte* cn, IntPtr cnLen, unitytls_errorstate* errorState);

			[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
			public unsafe delegate void unitytls_tlsctx_server_require_client_authentication_t(unitytls_tlsctx* ctx, unitytls_x509list_ref clientAuthCAList, unitytls_errorstate* errorState);

			[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
			public unsafe delegate void unitytls_tlsctx_set_certificate_callback_t(unitytls_tlsctx* ctx, unitytls_tlsctx_certificate_callback cb, void* userData, unitytls_errorstate* errorState);

			[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
			public unsafe delegate void unitytls_tlsctx_set_trace_callback_t(unitytls_tlsctx* ctx, unitytls_tlsctx_trace_callback cb, void* userData, unitytls_errorstate* errorState);

			[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
			public unsafe delegate void unitytls_tlsctx_set_x509verify_callback_t(unitytls_tlsctx* ctx, unitytls_tlsctx_x509verify_callback cb, void* userData, unitytls_errorstate* errorState);

			[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
			public unsafe delegate void unitytls_tlsctx_set_supported_ciphersuites_t(unitytls_tlsctx* ctx, unitytls_ciphersuite* supportedCiphersuites, IntPtr supportedCiphersuitesLen, unitytls_errorstate* errorState);

			[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
			public unsafe delegate unitytls_ciphersuite unitytls_tlsctx_get_ciphersuite_t(unitytls_tlsctx* ctx, unitytls_errorstate* errorState);

			[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
			public unsafe delegate unitytls_protocol unitytls_tlsctx_get_protocol_t(unitytls_tlsctx* ctx, unitytls_errorstate* errorState);

			[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
			public unsafe delegate unitytls_x509verify_result unitytls_tlsctx_process_handshake_t(unitytls_tlsctx* ctx, unitytls_errorstate* errorState);

			[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
			public unsafe delegate IntPtr unitytls_tlsctx_read_t(unitytls_tlsctx* ctx, byte* buffer, IntPtr bufferLen, unitytls_errorstate* errorState);

			[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
			public unsafe delegate IntPtr unitytls_tlsctx_write_t(unitytls_tlsctx* ctx, byte* data, IntPtr bufferLen, unitytls_errorstate* errorState);

			[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
			public unsafe delegate void unitytls_tlsctx_notify_close_t(unitytls_tlsctx* ctx, unitytls_errorstate* errorState);

			[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
			public unsafe delegate void unitytls_tlsctx_free_t(unitytls_tlsctx* ctx);

			[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
			public unsafe delegate void unitytls_random_generate_bytes_t(byte* buffer, IntPtr bufferLen, unitytls_errorstate* errorState);

			public readonly ulong UNITYTLS_INVALID_HANDLE;

			public readonly unitytls_tlsctx_protocolrange UNITYTLS_TLSCTX_PROTOCOLRANGE_DEFAULT;

			public unitytls_errorstate_create_t unitytls_errorstate_create;

			public unitytls_errorstate_raise_error_t unitytls_errorstate_raise_error;

			public unitytls_key_get_ref_t unitytls_key_get_ref;

			public unitytls_key_parse_der_t unitytls_key_parse_der;

			public unitytls_key_parse_pem_t unitytls_key_parse_pem;

			public unitytls_key_free_t unitytls_key_free;

			public unitytls_x509_export_der_t unitytls_x509_export_der;

			public unitytls_x509list_get_ref_t unitytls_x509list_get_ref;

			public unitytls_x509list_get_x509_t unitytls_x509list_get_x509;

			public unitytls_x509list_create_t unitytls_x509list_create;

			public unitytls_x509list_append_t unitytls_x509list_append;

			public unitytls_x509list_append_der_t unitytls_x509list_append_der;

			public unitytls_x509list_append_der_t unitytls_x509list_append_pem;

			public unitytls_x509list_free_t unitytls_x509list_free;

			public unitytls_x509verify_default_ca_t unitytls_x509verify_default_ca;

			public unitytls_x509verify_explicit_ca_t unitytls_x509verify_explicit_ca;

			public unitytls_tlsctx_create_server_t unitytls_tlsctx_create_server;

			public unitytls_tlsctx_create_client_t unitytls_tlsctx_create_client;

			public unitytls_tlsctx_server_require_client_authentication_t unitytls_tlsctx_server_require_client_authentication;

			public unitytls_tlsctx_set_certificate_callback_t unitytls_tlsctx_set_certificate_callback;

			public unitytls_tlsctx_set_trace_callback_t unitytls_tlsctx_set_trace_callback;

			public unitytls_tlsctx_set_x509verify_callback_t unitytls_tlsctx_set_x509verify_callback;

			public unitytls_tlsctx_set_supported_ciphersuites_t unitytls_tlsctx_set_supported_ciphersuites;

			public unitytls_tlsctx_get_ciphersuite_t unitytls_tlsctx_get_ciphersuite;

			public unitytls_tlsctx_get_protocol_t unitytls_tlsctx_get_protocol;

			public unitytls_tlsctx_process_handshake_t unitytls_tlsctx_process_handshake;

			public unitytls_tlsctx_read_t unitytls_tlsctx_read;

			public unitytls_tlsctx_write_t unitytls_tlsctx_write;

			public unitytls_tlsctx_notify_close_t unitytls_tlsctx_notify_close;

			public unitytls_tlsctx_free_t unitytls_tlsctx_free;

			public unitytls_random_generate_bytes_t unitytls_random_generate_bytes;
		}

		private static unitytls_interface_struct marshalledInterface;

		public static bool IsSupported => NativeInterface != null;

		public static unitytls_interface_struct NativeInterface
		{
			get
			{
				if (marshalledInterface == null)
				{
					IntPtr unityTlsInterface = Il2CppTlsAdapter.Options.UnityTlsInterface;
					if (unityTlsInterface == IntPtr.Zero)
					{
						return null;
					}
					marshalledInterface = Marshal.PtrToStructure<unitytls_interface_struct>(unityTlsInterface);
				}
				return marshalledInterface;
			}
		}

		[MethodImpl(MethodImplOptions.InternalCall)]
		private static extern IntPtr GetUnityTlsInterface();
	}
	internal class UnityTlsContext : MobileTlsContext
	{
		private const bool ActivateTracing = false;

		private readonly UnityTls.unitytls_tlsctx_certificate_callback certificateCallback;

		private readonly UnityTls.unitytls_tlsctx_read_callback readCallback;

		private readonly UnityTls.unitytls_tlsctx_trace_callback traceCallback;

		private readonly UnityTls.unitytls_tlsctx_x509verify_callback verifyCallback;

		private readonly UnityTls.unitytls_tlsctx_write_callback writeCallback;

		private bool closedGraceful;

		private MonoTlsConnectionInfo connectioninfo;

		private GCHandle handle;

		private bool hasContext;

		private bool isAuthenticated;

		private Exception lastException;

		private X509Certificate localClientCertificate;

		private byte[] readBuffer;

		private X509Certificate2 remoteCertificate;

		private unsafe UnityTls.unitytls_x509list* requestedClientCertChain = null;

		private unsafe UnityTls.unitytls_key* requestedClientKey = null;

		private unsafe UnityTls.unitytls_tlsctx* tlsContext = null;

		private byte[] writeBuffer;

		public override bool HasContext => hasContext;

		public override bool IsAuthenticated => isAuthenticated;

		public override MonoTlsConnectionInfo ConnectionInfo => connectioninfo;

		public override bool IsRemoteCertificateAvailable => remoteCertificate != null;

		public override X509Certificate LocalClientCertificate => localClientCertificate;

		public override X509Certificate2 RemoteCertificate => remoteCertificate;

		public override TlsProtocols NegotiatedProtocol => ((MobileTlsContext)this).ConnectionInfo.ProtocolVersion;

		public override bool CanRenegotiate => false;

		public unsafe UnityTlsContext(MobileAuthenticatedStream parent, MonoSslAuthenticationOptions opts)
			: base(parent, opts)
		{
			handle = GCHandle.Alloc(this);
			UnityTls.unitytls_errorstate errorState = UnityTls.NativeInterface.unitytls_errorstate_create();
			UnityTls.unitytls_tlsctx_protocolrange supportedProtocols = new UnityTls.unitytls_tlsctx_protocolrange
			{
				min = UnityTlsConversions.GetMinProtocol(((MobileTlsContext)this).EnabledProtocols),
				max = UnityTlsConversions.GetMaxProtocol(((MobileTlsContext)this).EnabledProtocols)
			};
			readCallback = ReadCallback;
			writeCallback = WriteCallback;
			UnityTls.unitytls_tlsctx_callbacks callbacks = new UnityTls.unitytls_tlsctx_callbacks
			{
				write = writeCallback,
				read = readCallback,
				data = (void*)(IntPtr)handle
			};
			if (opts.ServerMode)
			{
				ExtractNativeKeyAndChainFromManagedCertificate(opts.ServerCertificate, &errorState, out var nativeCertChain, out var nativeKey);
				try
				{
					UnityTls.unitytls_x509list_ref unitytls_x509list_ref = UnityTls.NativeInterface.unitytls_x509list_get_ref(nativeCertChain, &errorState);
					UnityTls.unitytls_key_ref unitytls_key_ref = UnityTls.NativeInterface.unitytls_key_get_ref(nativeKey, &errorState);
					Debug.CheckAndThrow(errorState, "Failed to parse server key/certificate", (AlertDescription)80);
					tlsContext = UnityTls.NativeInterface.unitytls_tlsctx_create_server(supportedProtocols, callbacks, unitytls_x509list_ref.handle, unitytls_key_ref.handle, &errorState);
					if (opts.ClientCertificateRequired)
					{
						UnityTls.unitytls_x509list* list = null;
						try
						{
							list = UnityTls.NativeInterface.unitytls_x509list_create(&errorState);
							UnityTls.unitytls_x509list_ref clientAuthCAList = UnityTls.NativeInterface.unitytls_x509list_get_ref(list, &errorState);
							UnityTls.NativeInterface.unitytls_tlsctx_server_require_client_authentication(tlsContext, clientAuthCAList, &errorState);
						}
						finally
						{
							UnityTls.NativeInterface.unitytls_x509list_free(list);
						}
					}
				}
				finally
				{
					UnityTls.NativeInterface.unitytls_x509list_free(nativeCertChain);
					UnityTls.NativeInterface.unitytls_key_free(nativeKey);
				}
			}
			else
			{
				byte[] bytes = Encoding.UTF8.GetBytes(opts.TargetHost);
				fixed (byte* cn = bytes)
				{
					tlsContext = UnityTls.NativeInterface.unitytls_tlsctx_create_client(supportedProtocols, callbacks, cn, (IntPtr)bytes.Length, &errorState);
				}
				certificateCallback = CertificateCallback;
				UnityTls.NativeInterface.unitytls_tlsctx_set_certificate_callback(tlsContext, certificateCallback, (void*)(IntPtr)handle, &errorState);
			}
			verifyCallback = VerifyCallback;
			UnityTls.NativeInterface.unitytls_tlsctx_set_x509verify_callback(tlsContext, verifyCallback, (void*)(IntPtr)handle, &errorState);
			Debug.CheckAndThrow(errorState, "Failed to create UnityTls context", (AlertDescription)80);
			hasContext = true;
		}

		private unsafe static void ExtractNativeKeyAndChainFromManagedCertificate(X509Certificate cert, UnityTls.unitytls_errorstate* errorState, out UnityTls.unitytls_x509list* nativeCertChain, out UnityTls.unitytls_key* nativeKey)
		{
			if (cert == null)
			{
				throw new ArgumentNullException("cert");
			}
			if (!(cert is X509Certificate2 x509Certificate) || x509Certificate.PrivateKey == null)
			{
				throw new ArgumentException("Certificate does not have a private key", "cert");
			}
			nativeCertChain = null;
			nativeKey = null;
			try
			{
				nativeCertChain = UnityTls.NativeInterface.unitytls_x509list_create(errorState);
				CertHelper.AddCertificateToNativeChain(nativeCertChain, x509Certificate, errorState);
				byte[] array = PrivateKeyInfo.Encode(x509Certificate.PrivateKey);
				fixed (byte* buffer = array)
				{
					nativeKey = UnityTls.NativeInterface.unitytls_key_parse_der(buffer, (IntPtr)array.Length, null, (IntPtr)0, errorState);
				}
			}
			catch
			{
				UnityTls.NativeInterface.unitytls_x509list_free(nativeCertChain);
				UnityTls.NativeInterface.unitytls_key_free(nativeKey);
				throw;
			}
		}

		public override void Flush()
		{
		}

		public unsafe override (int ret, bool wantMore) Read(byte[] buffer, int offset, int count)
		{
			int num = 0;
			lastException = null;
			UnityTls.unitytls_errorstate errorState = UnityTls.NativeInterface.unitytls_errorstate_create();
			fixed (byte* ptr = buffer)
			{
				num = (int)UnityTls.NativeInterface.unitytls_tlsctx_read(tlsContext, ptr + offset, (IntPtr)count, &errorState);
			}
			if (lastException != null)
			{
				throw lastException;
			}
			switch (errorState.code)
			{
			case UnityTls.unitytls_error_code.UNITYTLS_SUCCESS:
				return (num, num < count);
			case UnityTls.unitytls_error_code.UNITYTLS_USER_WOULD_BLOCK:
				return (num, true);
			case UnityTls.unitytls_error_code.UNITYTLS_STREAM_CLOSED:
				return (0, false);
			default:
				if (!closedGraceful)
				{
					Debug.CheckAndThrow(errorState, "Failed to read data to TLS context", (AlertDescription)80);
				}
				return (0, false);
			}
		}

		public unsafe override (int ret, bool wantMore) Write(byte[] buffer, int offset, int count)
		{
			int num = 0;
			lastException = null;
			UnityTls.unitytls_errorstate errorState = UnityTls.NativeInterface.unitytls_errorstate_create();
			fixed (byte* ptr = buffer)
			{
				num = (int)UnityTls.NativeInterface.unitytls_tlsctx_write(tlsContext, ptr + offset, (IntPtr)count, &errorState);
			}
			if (lastException != null)
			{
				throw lastException;
			}
			switch (errorState.code)
			{
			case UnityTls.unitytls_error_code.UNITYTLS_SUCCESS:
				return (num, num < count);
			case UnityTls.unitytls_error_code.UNITYTLS_USER_WOULD_BLOCK:
				return (num, true);
			case UnityTls.unitytls_error_code.UNITYTLS_STREAM_CLOSED:
				return (0, false);
			default:
				Debug.CheckAndThrow(errorState, "Failed to write data to TLS context", (AlertDescription)80);
				return (0, false);
			}
		}

		public unsafe override void Shutdown()
		{
			if (((MobileTlsContext)this).Settings != null && ((MobileTlsContext)this).Settings.SendCloseNotify)
			{
				UnityTls.unitytls_errorstate unitytls_errorstate = UnityTls.NativeInterface.unitytls_errorstate_create();
				UnityTls.NativeInterface.unitytls_tlsctx_notify_close(tlsContext, &unitytls_errorstate);
			}
			UnityTls.NativeInterface.unitytls_x509list_free(requestedClientCertChain);
			UnityTls.NativeInterface.unitytls_key_free(requestedClientKey);
			UnityTls.NativeInterface.unitytls_tlsctx_free(tlsContext);
			tlsContext = null;
			hasContext = false;
		}

		public override bool PendingRenegotiation()
		{
			return false;
		}

		public override void Renegotiate()
		{
		}

		public override void Dispose(bool disposing)
		{
			try
			{
				if (disposing)
				{
					((MobileTlsContext)this).Shutdown();
					localClientCertificate = null;
					remoteCertificate = null;
					if (localClientCertificate != null)
					{
						localClientCertificate.Dispose();
						localClientCertificate = null;
					}
					if (remoteCertificate != null)
					{
						remoteCertificate.Dispose();
						remoteCertificate = null;
					}
					connectioninfo = null;
					isAuthenticated = false;
					hasContext = false;
				}
				handle.Free();
			}
			finally
			{
				((MobileTlsContext)this).Dispose(disposing);
			}
		}

		public unsafe override void StartHandshake()
		{
			if (((MobileTlsContext)this).Settings != null && ((MobileTlsContext)this).Settings.EnabledCiphers != null)
			{
				UnityTls.unitytls_ciphersuite[] array = new UnityTls.unitytls_ciphersuite[((MobileTlsContext)this).Settings.EnabledCiphers.Length];
				for (int i = 0; i < array.Length; i++)
				{
					array[i] = (UnityTls.unitytls_ciphersuite)((MobileTlsContext)this).Settings.EnabledCiphers[i];
				}
				UnityTls.unitytls_errorstate errorState = UnityTls.NativeInterface.unitytls_errorstate_create();
				fixed (UnityTls.unitytls_ciphersuite* supportedCiphersuites = array)
				{
					UnityTls.NativeInterface.unitytls_tlsctx_set_supported_ciphersuites(tlsContext, supportedCiphersuites, (IntPtr)array.Length, &errorState);
				}
				Debug.CheckAndThrow(errorState, "Failed to set list of supported ciphers", (AlertDescription)40);
			}
		}

		public unsafe override bool ProcessHandshake()
		{
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			lastException = null;
			UnityTls.unitytls_errorstate errorState = UnityTls.NativeInterface.unitytls_errorstate_create();
			UnityTls.unitytls_x509verify_result unitytls_x509verify_result = UnityTls.NativeInterface.unitytls_tlsctx_process_handshake(tlsContext, &errorState);
			if (errorState.code == UnityTls.unitytls_error_code.UNITYTLS_USER_WOULD_BLOCK)
			{
				return false;
			}
			if (lastException != null)
			{
				throw lastException;
			}
			if (((MobileTlsContext)this).IsServer && unitytls_x509verify_result == UnityTls.unitytls_x509verify_result.UNITYTLS_X509VERIFY_NOT_DONE)
			{
				Debug.CheckAndThrow(errorState, "Handshake failed", (AlertDescription)40);
				if (!((MobileTlsContext)this).ValidateCertificate((X509Certificate2)null, (X509Chain)null))
				{
					throw new TlsException((AlertDescription)40, "Verification failure during handshake");
				}
			}
			else
			{
				Debug.CheckAndThrow(errorState, unitytls_x509verify_result, "Handshake failed", (AlertDescription)40);
			}
			return true;
		}

		public unsafe override void FinishHandshake()
		{
			//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_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Expected O, but got Unknown
			UnityTls.unitytls_errorstate unitytls_errorstate = UnityTls.NativeInterface.unitytls_errorstate_create();
			UnityTls.unitytls_ciphersuite unitytls_ciphersuite = UnityTls.NativeInterface.unitytls_tlsctx_get_ciphersuite(tlsContext, &unitytls_errorstate);
			UnityTls.unitytls_protocol protocol = UnityTls.NativeInterface.unitytls_tlsctx_get_protocol(tlsContext, &unitytls_errorstate);
			connectioninfo = new MonoTlsConnectionInfo
			{
				CipherSuiteCode = (CipherSuiteCode)(ushort)unitytls_ciphersuite,
				ProtocolVersion = UnityTlsConversions.ConvertProtocolVersion(protocol),
				PeerDomainName = ((MobileTlsContext)this).ServerName
			};
			isAuthenticated = true;
		}

		private unsafe static IntPtr WriteCallback(void* userData, byte* data, IntPtr bufferLen, UnityTls.unitytls_errorstate* errorState)
		{
			return ((UnityTlsContext)((GCHandle)(IntPtr)userData).Target).WriteCallback(data, bufferLen, errorState);
		}

		private unsafe IntPtr WriteCallback(byte* data, IntPtr bufferLen, UnityTls.unitytls_errorstate* errorState)
		{
			try
			{
				if (writeBuffer == null || writeBuffer.Length < (int)bufferLen)
				{
					writeBuffer = new byte[(int)bufferLen];
				}
				Marshal.Copy((IntPtr)data, writeBuffer, 0, (int)bufferLen);
				if (!((MobileTlsContext)this).Parent.InternalWrite(writeBuffer, 0, (int)bufferLen))
				{
					UnityTls.NativeInterface.unitytls_errorstate_raise_error(errorState, UnityTls.unitytls_error_code.UNITYTLS_USER_WRITE_FAILED);
					return (IntPtr)0;
				}
				return bufferLen;
			}
			catch (Exception ex)
			{
				UnityTls.NativeInterface.unitytls_errorstate_raise_error(errorState, UnityTls.unitytls_error_code.UNITYTLS_USER_UNKNOWN_ERROR);
				if (lastException == null)
				{
					lastException = ex;
				}
				return (IntPtr)0;
			}
		}

		private unsafe static IntPtr ReadCallback(void* userData, byte* buffer, IntPtr bufferLen, UnityTls.unitytls_errorstate* errorState)
		{
			return ((UnityTlsContext)((GCHandle)(IntPtr)userData).Target).ReadCallback(buffer, bufferLen, errorState);
		}

		private unsafe IntPtr ReadCallback(byte* buffer, IntPtr bufferLen, UnityTls.unitytls_errorstate* errorState)
		{
			try
			{
				if (readBuffer == null || readBuffer.Length < (int)bufferLen)
				{
					readBuffer = new byte[(int)bufferLen];
				}
				bool flag = default(bool);
				int num = ((MobileTlsContext)this).Parent.InternalRead(readBuffer, 0, (int)bufferLen, ref flag);
				if (num < 0)
				{
					UnityTls.NativeInterface.unitytls_errorstate_raise_error(errorState, UnityTls.unitytls_error_code.UNITYTLS_USER_READ_FAILED);
				}
				else if (num > 0)
				{
					Marshal.Copy(readBuffer, 0, (IntPtr)buffer, (int)bufferLen);
				}
				else if (flag)
				{
					UnityTls.NativeInterface.unitytls_errorstate_raise_error(errorState, UnityTls.unitytls_error_code.UNITYTLS_USER_WOULD_BLOCK);
				}
				else
				{
					closedGraceful = true;
					UnityTls.NativeInterface.unitytls_errorstate_raise_error(errorState, UnityTls.unitytls_error_code.UNITYTLS_USER_READ_FAILED);
				}
				return (IntPtr)num;
			}
			catch (Exception ex)
			{
				UnityTls.NativeInterface.unitytls_errorstate_raise_error(errorState, UnityTls.unitytls_error_code.UNITYTLS_USER_UNKNOWN_ERROR);
				if (lastException == null)
				{
					lastException = ex;
				}
				return (IntPtr)0;
			}
		}

		private unsafe static UnityTls.unitytls_x509verify_result VerifyCallback(void* userData, UnityTls.unitytls_x509list_ref chain, UnityTls.unitytls_errorstate* errorState)
		{
			return ((UnityTlsContext)((GCHandle)(IntPtr)userData).Target).VerifyCallback(chain, errorState);
		}

		private unsafe UnityTls.unitytls_x509verify_result VerifyCallback(UnityTls.unitytls_x509list_ref chain, UnityTls.unitytls_errorstate* errorState)
		{
			try
			{
				X509ChainImplUnityTls x509ChainImplUnityTls = new X509ChainImplUnityTls(chain);
				try
				{
					using X509Chain x509Chain = new X509Chain((X509ChainImpl)(object)x509ChainImplUnityTls);
					remoteCertificate = x509Chain.ChainElements[0].Certificate;
					if (((MobileTlsContext)this).ValidateCertificate(remoteCertificate, x509Chain))
					{
						return UnityTls.unitytls_x509verify_result.UNITYTLS_X509VERIFY_SUCCESS;
					}
					return UnityTls.unitytls_x509verify_result.UNITYTLS_X509VERIFY_FLAG_NOT_TRUSTED;
				}
				finally
				{
					((IDisposable)x509ChainImplUnityTls)?.Dispose();
				}
			}
			catch (Exception ex)
			{
				if (lastException == null)
				{
					lastException = ex;
				}
				return UnityTls.unitytls_x509verify_result.UNITYTLS_X509VERIFY_FATAL_ERROR;
			}
		}

		private unsafe static void CertificateCallback(void* userData, UnityTls.unitytls_tlsctx* ctx, byte* cn, IntPtr cnLen, UnityTls.unitytls_x509name* caList, IntPtr caListLen, UnityTls.unitytls_x509list_ref* chain, UnityTls.unitytls_key_ref* key, UnityTls.unitytls_errorstate* errorState)
		{
			((UnityTlsContext)((GCHandle)(IntPtr)userData).Target).CertificateCallback(ctx, cn, cnLen, caList, caListLen, chain, key, errorState);
		}

		private unsafe void CertificateCallback(UnityTls.unitytls_tlsctx* ctx, byte* cn, IntPtr cnLen, UnityTls.unitytls_x509name* caList, IntPtr caListLen, UnityTls.unitytls_x509list_ref* chain, UnityTls.unitytls_key_ref* key, UnityTls.unitytls_errorstate* errorState)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (remoteCertificate == null)
				{
					throw new TlsException((AlertDescription)80, "Cannot request client certificate before receiving one from the server.");
				}
				localClientCertificate = ((MobileTlsContext)this).SelectClientCertificate((string[])null);
				if (localClientCertificate == null)
				{
					*chain = new UnityTls.unitytls_x509list_ref
					{
						handle = UnityTls.NativeInterface.UNITYTLS_INVALID_HANDLE
					};
					*key = new UnityTls.unitytls_key_ref
					{
						handle = UnityTls.NativeInterface.UNITYTLS_INVALID_HANDLE
					};
				}
				else
				{
					UnityTls.NativeInterface.unitytls_x509list_free(requestedClientCertChain);
					UnityTls.NativeInterface.unitytls_key_free(requestedClientKey);
					ExtractNativeKeyAndChainFromManagedCertificate(localClientCertificate, errorState, out requestedClientCertChain, out requestedClientKey);
					*chain = UnityTls.NativeInterface.unitytls_x509list_get_ref(requestedClientCertChain, errorState);
					*key = UnityTls.NativeInterface.unitytls_key_get_ref(requestedClientKey, errorState);
				}
				Debug.CheckAndThrow(*errorState, "Failed to retrieve certificates on request.", (AlertDescription)40);
			}
			catch (Exception ex)
			{
				UnityTls.NativeInterface.unitytls_errorstate_raise_error(errorState, UnityTls.unitytls_error_code.UNITYTLS_USER_UNKNOWN_ERROR);
				if (lastException == null)
				{
					lastException = ex;
				}
			}
		}

		private unsafe static void TraceCallback(void* userData, UnityTls.unitytls_tlsctx* ctx, byte* traceMessage, IntPtr traceMessageLen)
		{
			Console.Write(Encoding.UTF8.GetString(traceMessage, (int)traceMessageLen));
		}
	}
	internal static class UnityTlsConversions
	{
		public static UnityTls.unitytls_protocol GetMinProtocol(SslProtocols protocols)
		{
			if (protocols.HasFlag(SslProtocols.Tls))
			{
				return UnityTls.unitytls_protocol.UNITYTLS_PROTOCOL_TLS_1_0;
			}
			if (protocols.HasFlag(SslProtocols.Tls11))
			{
				return UnityTls.unitytls_protocol.UNITYTLS_PROTOCOL_TLS_1_1;
			}
			if (protocols.HasFlag(SslProtocols.Tls12))
			{
				return UnityTls.unitytls_protocol.UNITYTLS_PROTOCOL_TLS_1_2;
			}
			return UnityTls.unitytls_protocol.UNITYTLS_PROTOCOL_TLS_1_0;
		}

		public static UnityTls.unitytls_protocol GetMaxProtocol(SslProtocols protocols)
		{
			if (protocols.HasFlag(SslProtocols.Tls12))
			{
				return UnityTls.unitytls_protocol.UNITYTLS_PROTOCOL_TLS_1_2;
			}
			if (protocols.HasFlag(SslProtocols.Tls11))
			{
				return UnityTls.unitytls_protocol.UNITYTLS_PROTOCOL_TLS_1_1;
			}
			if (protocols.HasFlag(SslProtocols.Tls))
			{
				return UnityTls.unitytls_protocol.UNITYTLS_PROTOCOL_TLS_1_0;
			}
			return UnityTls.unitytls_protocol.UNITYTLS_PROTOCOL_TLS_1_2;
		}

		public static TlsProtocols ConvertProtocolVersion(UnityTls.unitytls_protocol protocol)
		{
			return (TlsProtocols)(protocol switch
			{
				UnityTls.unitytls_protocol.UNITYTLS_PROTOCOL_TLS_1_0 => 192, 
				UnityTls.unitytls_protocol.UNITYTLS_PROTOCOL_TLS_1_1 => 768, 
				UnityTls.unitytls_protocol.UNITYTLS_PROTOCOL_TLS_1_2 => 3072, 
				UnityTls.unitytls_protocol.UNITYTLS_PROTOCOL_INVALID => 0, 
				_ => 0, 
			});
		}

		public static AlertDescription VerifyResultToAlertDescription(UnityTls.unitytls_x509verify_result verifyResult, AlertDescription defaultAlert = 80)
		{
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			if (verifyResult == UnityTls.unitytls_x509verify_result.UNITYTLS_X509VERIFY_FATAL_ERROR)
			{
				return (AlertDescription)46;
			}
			if (verifyResult.HasFlag(UnityTls.unitytls_x509verify_result.UNITYTLS_X509VERIFY_FLAG_EXPIRED))
			{
				return (AlertDescription)45;
			}
			if (verifyResult.HasFlag(UnityTls.unitytls_x509verify_result.UNITYTLS_X509VERIFY_FLAG_REVOKED))
			{
				return (AlertDescription)44;
			}
			if (verifyResult.HasFlag(UnityTls.unitytls_x509verify_result.UNITYTLS_X509VERIFY_FLAG_CN_MISMATCH))
			{
				return (AlertDescription)48;
			}
			if (verifyResult.HasFlag(UnityTls.unitytls_x509verify_result.UNITYTLS_X509VERIFY_FLAG_NOT_TRUSTED))
			{
				return (AlertDescription)46;
			}
			if (verifyResult.HasFlag(UnityTls.unitytls_x509verify_result.UNITYTLS_X509VERIFY_FLAG_USER_ERROR1))
			{
				return (AlertDescription)90;
			}
			if (verifyResult.HasFlag(UnityTls.unitytls_x509verify_result.UNITYTLS_X509VERIFY_FLAG_USER_ERROR2))
			{
				return (AlertDescription)90;
			}
			if (verifyResult.HasFlag(UnityTls.unitytls_x509verify_result.UNITYTLS_X509VERIFY_FLAG_USER_ERROR2))
			{
				return (AlertDescription)90;
			}
			if (verifyResult.HasFlag(UnityTls.unitytls_x509verify_result.UNITYTLS_X509VERIFY_FLAG_USER_ERROR3))
			{
				return (AlertDescription)90;
			}
			if (verifyResult.HasFlag(UnityTls.unitytls_x509verify_result.UNITYTLS_X509VERIFY_FLAG_USER_ERROR4))
			{
				return (AlertDescription)90;
			}
			if (verifyResult.HasFlag(UnityTls.unitytls_x509verify_result.UNITYTLS_X509VERIFY_FLAG_USER_ERROR5))
			{
				return (AlertDescription)90;
			}
			if (verifyResult.HasFlag(UnityTls.unitytls_x509verify_result.UNITYTLS_X509VERIFY_FLAG_USER_ERROR6))
			{
				return (AlertDescription)90;
			}
			if (verifyResult.HasFlag(UnityTls.unitytls_x509verify_result.UNITYTLS_X509VERIFY_FLAG_USER_ERROR7))
			{
				return (AlertDescription)90;
			}
			if (verifyResult.HasFlag(UnityTls.unitytls_x509verify_result.UNITYTLS_X509VERIFY_FLAG_USER_ERROR8))
			{
				return (AlertDescription)90;
			}
			return defaultAlert;
		}

		public static SslPolicyErrors VerifyResultToPolicyErrror(UnityTls.unitytls_x509verify_result verifyResult)
		{
			switch (verifyResult)
			{
			case UnityTls.unitytls_x509verify_result.UNITYTLS_X509VERIFY_SUCCESS:
				return SslPolicyErrors.None;
			case UnityTls.unitytls_x509verify_result.UNITYTLS_X509VERIFY_FATAL_ERROR:
				return SslPolicyErrors.RemoteCertificateChainErrors;
			default:
			{
				SslPolicyErrors sslPolicyErrors = SslPolicyErrors.None;
				if (verifyResult.HasFlag(UnityTls.unitytls_x509verify_result.UNITYTLS_X509VERIFY_FLAG_CN_MISMATCH))
				{
					sslPolicyErrors |= SslPolicyErrors.RemoteCertificateNameMismatch;
				}
				if (verifyResult != UnityTls.unitytls_x509verify_result.UNITYTLS_X509VERIFY_FLAG_CN_MISMATCH)
				{
					sslPolicyErrors |= SslPolicyErrors.RemoteCertificateChainErrors;
				}
				return sslPolicyErrors;
			}
			}
		}

		public static X509ChainStatusFlags VerifyResultToChainStatus(UnityTls.unitytls_x509verify_result verifyResult)
		{
			switch (verifyResult)
			{
			case UnityTls.unitytls_x509verify_result.UNITYTLS_X509VERIFY_SUCCESS:
				return X509ChainStatusFlags.NoError;
			case UnityTls.unitytls_x509verify_result.UNITYTLS_X509VERIFY_FATAL_ERROR:
				return X509ChainStatusFlags.UntrustedRoot;
			default:
			{
				X509ChainStatusFlags x509ChainStatusFlags = X509ChainStatusFlags.NoError;
				if (verifyResult.HasFlag(UnityTls.unitytls_x509verify_result.UNITYTLS_X509VERIFY_FLAG_EXPIRED))
				{
					x509ChainStatusFlags |= X509ChainStatusFlags.NotTimeValid;
				}
				if (verifyResult.HasFlag(UnityTls.unitytls_x509verify_result.UNITYTLS_X509VERIFY_FLAG_REVOKED))
				{
					x509ChainStatusFlags |= X509ChainStatusFlags.Revoked;
				}
				if (verifyResult.HasFlag(UnityTls.unitytls_x509verify_result.UNITYTLS_X509VERIFY_FLAG_CN_MISMATCH))
				{
					x509ChainStatusFlags |= X509ChainStatusFlags.UntrustedRoot;
				}
				if (verifyResult.HasFlag(UnityTls.unitytls_x509verify_result.UNITYTLS_X509VERIFY_FLAG_NOT_TRUSTED))
				{
					x509ChainStatusFlags |= X509ChainStatusFlags.UntrustedRoot;
				}
				return x509ChainStatusFlags;
			}
			}
		}
	}
	internal class UnityTlsProvider : MobileTlsProvider
	{
		public static readonly Guid Guid = new Guid("9b378a65-b817-4b78-853a-b9bc32de5d0b");

		public static readonly string ProviderName = "unitytls";

		public override string Name => ProviderName;

		public override Guid ID => Guid;

		public override bool SupportsSslStream => true;

		public override bool SupportsMonoExtensions => true;

		public override bool SupportsConnectionInfo => true;

		public override SslProtocols SupportedProtocols => SslProtocols.Tls | SslProtocols.Tls11 | SslProtocols.Tls12;

		public override bool SupportsCleanShutdown => true;

		public override MobileAuthenticatedStream CreateSslStream(SslStream sslStream, Stream innerStream, bool leaveInnerStreamOpen, MonoTlsSettings settings)
		{
			return (MobileAuthenticatedStream)(object)new UnityTlsStream(innerStream, leaveInnerStreamOpen, sslStream, settings, (MobileTlsProvider)(object)this);
		}

		public unsafe override bool ValidateCertificate(ChainValidationHelper validator, string targetHost, bool serverMode, X509CertificateCollection certificates, bool wantsChain, ref X509Chain chain, ref SslPolicyErrors errors, ref int status11)
		{
			UnityTls.unitytls_errorstate unitytls_errorstate = UnityTls.NativeInterface.unitytls_errorstate_create();
			X509ChainImplUnityTls x509ChainImplUnityTls = chain.Impl as X509ChainImplUnityTls;
			if (x509ChainImplUnityTls == null)
			{
				if (certificates == null || certificates.Count == 0)
				{
					errors |= SslPolicyErrors.RemoteCertificateNotAvailable;
					return false;
				}
				if (wantsChain)
				{
					chain = SystemCertificateValidator.CreateX509Chain(certificates);
				}
			}
			else if (UnityTls.NativeInterface.unitytls_x509list_get_x509(x509ChainImplUnityTls.NativeCertificateChain, (IntPtr)0, &unitytls_errorstate).handle == UnityTls.NativeInterface.UNITYTLS_INVALID_HANDLE)
			{
				errors |= SslPolicyErrors.RemoteCertificateNotAvailable;
				return false;
			}
			if (!string.IsNullOrEmpty(targetHost))
			{
				int num = targetHost.IndexOf(':');
				if (num > 0)
				{
					targetHost = targetHost.Substring(0, num);
				}
			}
			UnityTls.unitytls_x509verify_result unitytls_x509verify_result = UnityTls.unitytls_x509verify_result.UNITYTLS_X509VERIFY_NOT_DONE;
			UnityTls.unitytls_x509list* ptr = null;
			try
			{
				UnityTls.unitytls_x509list_ref chain2;
				if (x509ChainImplUnityTls == null)
				{
					ptr = UnityTls.NativeInterface.unitytls_x509list_create(&unitytls_errorstate);
					CertHelper.AddCertificatesToNativeChain(ptr, certificates, &unitytls_errorstate);
					chain2 = UnityTls.NativeInterface.unitytls_x509list_get_ref(ptr, &unitytls_errorstate);
				}
				else
				{
					chain2 = x509ChainImplUnityTls.NativeCertificateChain;
				}
				byte[] bytes = Encoding.UTF8.GetBytes(targetHost);
				if (validator.Settings.TrustAnchors != null)
				{
					UnityTls.unitytls_x509list* ptr2 = null;
					try
					{
						ptr2 = UnityTls.NativeInterface.unitytls_x509list_create(&unitytls_errorstate);
						CertHelper.AddCertificatesToNativeChain(ptr2, validator.Settings.TrustAnchors, &unitytls_errorstate);
						UnityTls.unitytls_x509list_ref trustCA = UnityTls.NativeInterface.unitytls_x509list_get_ref(ptr2, &unitytls_errorstate);
						fixed (byte* cn = bytes)
						{
							unitytls_x509verify_result = UnityTls.NativeInterface.unitytls_x509verify_explicit_ca(chain2, trustCA, cn, (IntPtr)bytes.Length, null, null, &unitytls_errorstate);
						}
					}
					finally
					{
						UnityTls.NativeInterface.unitytls_x509list_free(ptr2);
					}
				}
				else
				{
					fixed (byte* cn2 = bytes)
					{
						unitytls_x509verify_result = UnityTls.NativeInterface.unitytls_x509verify_default_ca(chain2, cn2, (IntPtr)bytes.Length, null, null, &unitytls_errorstate);
					}
				}
			}
			finally
			{
				UnityTls.NativeInterface.unitytls_x509list_free(ptr);
			}
			errors = UnityTlsConversions.VerifyResultToPolicyErrror(unitytls_x509verify_result);
			if (x509ChainImplUnityTls != null)
			{
				((X509ChainImpl)x509ChainImplUnityTls).AddStatus(UnityTlsConversions.VerifyResultToChainStatus(unitytls_x509verify_result));
			}
			if (unitytls_x509verify_result == UnityTls.unitytls_x509verify_result.UNITYTLS_X509VERIFY_SUCCESS)
			{
				return unitytls_errorstate.code == UnityTls.unitytls_error_code.UNITYTLS_SUCCESS;
			}
			return false;
		}
	}
	internal class UnityTlsStream : MobileAuthenticatedStream
	{
		public UnityTlsStream(Stream innerStream, bool leaveInnerStreamOpen, SslStream owner, MonoTlsSettings settings, MobileTlsProvider provider)
			: base(innerStream, leaveInnerStreamOpen, owner, settings, provider)
		{
		}

		public override MobileTlsContext CreateContext(MonoSslAuthenticationOptions options)
		{
			return (MobileTlsContext)(object)new UnityTlsContext((MobileAuthenticatedStream)(object)this, options);
		}
	}
	internal class X509ChainImplUnityTls : X509ChainImpl
	{
		private List<X509ChainStatus> chainStatusList;

		private X509ChainElementCollection elements;

		private UnityTls.unitytls_x509list_ref nativeCertificateChain;

		public override bool IsValid => nativeCertificateChain.handle != UnityTls.NativeInterface.UNITYTLS_INVALID_HANDLE;

		public override IntPtr Handle => new IntPtr((long)nativeCertificateChain.handle);

		internal UnityTls.unitytls_x509list_ref NativeCertificateChain => nativeCertificateChain;

		public unsafe override X509ChainElementCollection ChainElements
		{
			get
			{
				((X509ChainImpl)this).ThrowIfContextInvalid();
				if (elements != null)
				{
					return elements;
				}
				elements = new X509ChainElementCollection();
				UnityTls.unitytls_errorstate unitytls_errorstate = UnityTls.NativeInterface.unitytls_errorstate_create();
				UnityTls.unitytls_x509_ref cert = UnityTls.NativeInterface.unitytls_x509list_get_x509(nativeCertificateChain, (IntPtr)0, &unitytls_errorstate);
				int num = 0;
				while (cert.handle != UnityTls.NativeInterface.UNITYTLS_INVALID_HANDLE)
				{
					IntPtr intPtr = UnityTls.NativeInterface.unitytls_x509_export_der(cert, null, (IntPtr)0, &unitytls_errorstate);
					byte[] array = new byte[(int)intPtr];
					fixed (byte* buffer = array)
					{
						UnityTls.NativeInterface.unitytls_x509_export_der(cert, buffer, intPtr, &unitytls_errorstate);
					}
					elements.Add(new X509Certificate2(array));
					cert = UnityTls.NativeInterface.unitytls_x509list_get_x509(nativeCertificateChain, (IntPtr)num, &unitytls_errorstate);
					num++;
				}
				return elements;
			}
		}

		public override X509ChainPolicy ChainPolicy { get; set; } = new X509ChainPolicy();


		public override X509ChainStatus[] ChainStatus => chainStatusList?.ToArray() ?? new X509ChainStatus[0];

		internal X509ChainImplUnityTls(UnityTls.unitytls_x509list_ref nativeCertificateChain)
		{
			elements = null;
			this.nativeCertificateChain = nativeCertificateChain;
		}

		public override void AddStatus(X509ChainStatusFlags errorCode)
		{
			if (chainStatusList == null)
			{
				chainStatusList = new List<X509ChainStatus>();
			}
			chainStatusList.Add(new X509ChainStatus(errorCode));
		}

		public override bool Build(X509Certificate2 certificate)
		{
			return false;
		}

		public override void Reset()
		{
			if (elements != null)
			{
				nativeCertificateChain.handle = UnityTls.NativeInterface.UNITYTLS_INVALID_HANDLE;
				elements.Clear();
				elements = null;
			}
		}

		public override void Dispose(bool disposing)
		{
			((X509ChainImpl)this).Reset();
			((X509ChainImpl)this).Dispose(disposing);
		}
	}
}
namespace Mono.Security.Protocol.Tls
{
	[Serializable]
	internal enum AlertLevel : byte
	{
		Warning = 1,
		Fatal
	}
	[Serializable]
	internal enum AlertDescription : byte
	{
		CloseNotify = 0,
		UnexpectedMessage = 10,
		BadRecordMAC = 20,
		DecryptionFailed = 21,
		RecordOverflow = 22,
		DecompressionFailiure = 30,
		HandshakeFailiure = 40,
		NoCertificate = 41,
		BadCertificate = 42,
		UnsupportedCertificate = 43,
		CertificateRevoked = 44,
		CertificateExpired = 45,
		CertificateUnknown = 46,
		IlegalParameter = 47,
		UnknownCA = 48,
		AccessDenied = 49,
		DecodeError = 50,
		DecryptError = 51,
		ExportRestriction = 60,
		ProtocolVersion = 70,
		InsuficientSecurity = 71,
		InternalError = 80,
		UserCancelled = 90,
		NoRenegotiation = 100
	}
	internal class Alert
	{
		public AlertLevel Level { get; }

		public AlertDescription Description { get; }

		public string Message => GetAlertMessage(Description);

		public bool IsWarning
		{
			get
			{
				if (Level != AlertLevel.Warning)
				{
					return false;
				}
				return true;
			}
		}

		public bool IsCloseNotify
		{
			get
			{
				if (IsWarning && Description == AlertDescription.CloseNotify)
				{
					return true;
				}
				return false;
			}
		}

		private static AlertLevel inferAlertLevel(AlertDescription description)
		{
			switch (description)
			{
			case AlertDescription.CloseNotify:
			case AlertDescription.UserCancelled:
			case AlertDescription.NoRenegotiation:
				return AlertLevel.Warning;
			default:
				return AlertLevel.Fatal;
			}
		}

		public static string GetAlertMessage(AlertDescription description)
		{
			return "The authentication or decryption has failed.";
		}

		public Alert(AlertDescription description)
		{
			Description = description;
			Level = inferAlertLevel(description);
		}

		public Alert(AlertLevel level, AlertDescription description)
		{
			Level = level;
			Description = description;
		}
	}
	[Serializable]
	public enum CipherAlgorithmType
	{
		Des,
		None,
		Rc2,
		Rc4,
		Rijndael,
		SkipJack,
		TripleDes
	}
	internal abstract class CipherSuite
	{
		public static byte[] EmptyArray = new byte[0];

		private readonly byte blockSize;

		private SymmetricAlgorithm encryptionAlgorithm;

		private SymmetricAlgorithm decryptionAlgorithm;

		protected ICryptoTransform EncryptionCipher { get; private set; }

		protected ICryptoTransform DecryptionCipher { get; private set; }

		protected KeyedHashAlgorithm ClientHMAC { get; private set; }

		protected KeyedHashAlgorithm ServerHMAC { get; private set; }

		public CipherAlgorithmType CipherAlgorithmType { get; }

		public string HashAlgorithmName => HashAlgorithmType switch
		{
			HashAlgorithmType.Md5 => "MD5", 
			HashAlgorithmType.Sha1 => "SHA1", 
			_ => "None", 
		};

		public HashAlgorithmType HashAlgorithmType { get; }

		public int HashSize => HashAlgorithmType switch
		{
			HashAlgorithmType.Md5 => 16, 
			HashAlgorithmType.Sha1 => 20, 
			_ => 0, 
		};

		public ExchangeAlgorithmType ExchangeAlgorithmType { get; }

		public CipherMode CipherMode { get; }

		public short Code { get; }

		public string Name { get; }

		public bool IsExportable { get; }

		public byte KeyMaterialSize { get; }

		public int KeyBlockSize { get; }

		public byte ExpandedKeyMaterialSize { get; }

		public short EffectiveKeyBits { get; }

		public byte IvSize { get; }

		public Context Context { get; set; }

		public CipherSuite(short code, string name, CipherAlgorithmType cipherAlgorithmType, HashAlgorithmType hashAlgorithmType, ExchangeAlgorithmType exchangeAlgorithmType, bool exportable, bool blockMode, byte keyMaterialSize, byte expandedKeyMaterialSize, short effectiveKeyBits, byte ivSize, byte blockSize)
		{
			Code = code;
			Name = name;
			CipherAlgorithmType = cipherAlgorithmType;
			HashAlgorithmType = hashAlgorithmType;
			ExchangeAlgorithmType = exchangeAlgorithmType;
			IsExportable = exportable;
			if (blockMode)
			{
				CipherMode = CipherMode.CBC;
			}
			KeyMaterialSize = keyMaterialSize;
			ExpandedKeyMaterialSize = expandedKeyMaterialSize;
			EffectiveKeyBits = effectiveKeyBits;
			IvSize = ivSize;
			this.blockSize = blockSize;
			KeyBlockSize = KeyMaterialSize + HashSize + IvSize << 1;
		}

		internal HashAlgorithm CreateHashAlgorithm()
		{
			return HashAlgorithmType switch
			{
				HashAlgorithmType.Md5 => MD5.Create(), 
				HashAlgorithmType.Sha1 => SHA1.Create(), 
				_ => null, 
			};
		}

		internal void Write(byte[] array, int offset, short value)
		{
			if (offset > array.Length - 2)
			{
				throw new ArgumentException("offset");
			}
			array[offset] = (byte)(value >> 8);
			array[offset + 1] = (byte)value;
		}

		internal void Write(byte[] array, int offset, ulong value)
		{
			if (offset > array.Length - 8)
			{
				throw new ArgumentException("offset");
			}
			array[offset] = (byte)(value >> 56);
			array[offset + 1] = (byte)(value >> 48);
			array[offset + 2] = (byte)(value >> 40);
			array[offset + 3] = (byte)(value >> 32);
			array[offset + 4] = (byte)(value >> 24);
			array[offset + 5] = (byte)(value >> 16);
			array[offset + 6] = (byte)(value >> 8);
			array[offset + 7] = (byte)value;
		}

		public void InitializeCipher()
		{
			createEncryptionCipher();
			createDecryptionCipher();
		}

		public byte[] EncryptRecord(byte[] fragment, byte[] mac)
		{
			int num = fragment.Length + mac.Length;
			int num2 = 0;
			if (CipherMode == CipherMode.CBC)
			{
				num++;
				num2 = blockSize - num % blockSize;
				if (num2 == blockSize)
				{
					num2 = 0;
				}
				num += num2;
			}
			byte[] array = new byte[num];
			Buffer.BlockCopy(fragment, 0, array, 0, fragment.Length);
			Buffer.BlockCopy(mac, 0, array, fragment.Length, mac.Length);
			if (num2 > 0)
			{
				int num3 = fragment.Length + mac.Length;
				for (int i = num3; i < num3 + num2 + 1; i++)
				{
					array[i] = (byte)num2;
				}
			}
			EncryptionCipher.TransformBlock(array, 0, array.Length, array, 0);
			return array;
		}

		public void DecryptRecord(byte[] fragment, out byte[] dcrFragment, out byte[] dcrMAC)
		{
			int num = 0;
			int num2 = 0;
			DecryptionCipher.TransformBlock(fragment, 0, fragment.Length, fragment, 0);
			if (CipherMode == CipherMode.CBC)
			{
				num2 = fragment[^1];
				num = fragment.Length - (num2 + 1) - HashSize;
			}
			else
			{
				num = fragment.Length - HashSize;
			}
			dcrFragment = new byte[num];
			dcrMAC = new byte[HashSize];
			Buffer.BlockCopy(fragment, 0, dcrFragment, 0, dcrFragment.Length);
			Buffer.BlockCopy(fragment, dcrFragment.Length, dcrMAC, 0, dcrMAC.Length);
		}

		public abstract byte[] ComputeClientRecordMAC(ContentType contentType, byte[] fragment);

		public abstract byte[] ComputeServerRecordMAC(ContentType contentType, byte[] fragment);

		public abstract void ComputeMasterSecret(byte[] preMasterSecret);

		public abstract void ComputeKeys();

		public byte[] CreatePremasterSecret()
		{
			ClientContext clientContext = (ClientContext)Context;
			byte[] secureRandomBytes = Context.GetSecureRandomBytes(48);
			secureRandomBytes[0] = (byte)(clientContext.ClientHelloProtocol >> 8);
			secureRandomBytes[1] = (byte)clientContext.ClientHelloProtocol;
			return secureRandomBytes;
		}

		public byte[] PRF(byte[] secret, string label, byte[] data, int length)
		{
			int num = secret.Length >> 1;
			if ((secret.Length & 1) == 1)
			{
				num++;
			}
			TlsStream tlsStream = new TlsStream();
			tlsStream.Write(Encoding.ASCII.GetBytes(label));
			tlsStream.Write(data);
			byte[] seed = tlsStream.ToArray();
			tlsStream.Reset();
			byte[] array = new byte[num];
			Buffer.BlockCopy(secret, 0, array, 0, num);
			byte[] array2 = new byte[num];
			Buffer.BlockCopy(secret, secret.Length - num, array2, 0, num);
			byte[] array3 = Expand(MD5.Create(), array, seed, length);
			byte[] array4 = Expand(SHA1.Create(), array2, seed, length);
			byte[] array5 = new byte[length];
			for (int i = 0; i < array5.Length; i++)
			{
				array5[i] = (byte)(array3[i] ^ array4[i]);
			}
			return array5;
		}

		public byte[] Expand(HashAlgorithm hash, byte[] secret, byte[] seed, int length)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			int num = hash.HashSize / 8;
			int num2 = length / num;
			if (length % num > 0)
			{
				num2++;
			}
			HMAC val = new HMAC(hash, secret);
			TlsStream tlsStream = new TlsStream();
			byte[][] array = new byte[num2 + 1][];
			array[0] = seed;
			for (int i = 1; i <= num2; i++)
			{
				TlsStream tlsStream2 = new TlsStream();
				((HashAlgorithm)(object)val).TransformFinalBlock(array[i - 1], 0, array[i - 1].Length);
				array[i] = ((HashAlgorithm)(object)val).Hash;
				tlsStream2.Write(array[i]);
				tlsStream2.Write(seed);
				((HashAlgorithm)(object)val).TransformFinalBlock(tlsStream2.ToArray(), 0, (int)tlsStream2.Length);
				tlsStream.Write(((HashAlgorithm)(object)val).Hash);
				tlsStream2.Reset();
			}
			byte[] array2 = new byte[length];
			Buffer.BlockCopy(tlsStream.ToArray(), 0, array2, 0, array2.Length);
			tlsStream.Reset();
			return array2;
		}

		private void createEncryptionCipher()
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Expected O, but got Unknown
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Expected O, but got Unknown
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Expected O, but got Unknown
			switch (CipherAlgorithmType)
			{
			case CipherAlgorithmType.Des:
				encryptionAlgorithm = DES.Create();
				break;
			case CipherAlgorithmType.Rc2:
				encryptionAlgorithm = RC2.Create();
				break;
			case CipherAlgorithmType.Rc4:
				encryptionAlgorithm = (SymmetricAlgorithm)new ARC4Managed();
				break;
			case CipherAlgorithmType.TripleDes:
				encryptionAlgorithm = TripleDES.Create();
				break;
			case CipherAlgorithmType.Rijndael:
				encryptionAlgorithm = Aes.Create();
				break;
			}
			if (CipherMode == CipherMode.CBC)
			{
				encryptionAlgorithm.Mode = CipherMode;
				encryptionAlgorithm.Padding = PaddingMode.None;
				encryptionAlgorithm.KeySize = ExpandedKeyMaterialSize * 8;
				encryptionAlgorithm.BlockSize = blockSize * 8;
			}
			if (Context is ClientContext)
			{
				encryptionAlgorithm.Key = Context.ClientWriteKey;
				encryptionAlgorithm.IV = Context.ClientWriteIV;
			}
			else
			{
				encryptionAlgorithm.Key = Context.ServerWriteKey;
				encryptionAlgorithm.IV = Context.ServerWriteIV;
			}
			EncryptionCipher = encryptionAlgorithm.CreateEncryptor();
			if (Context is ClientContext)
			{
				ClientHMAC = (KeyedHashAlgorithm)new HMAC(CreateHashAlgorithm(), Context.Negotiating.ClientWriteMAC);
			}
			else
			{
				ServerHMAC = (KeyedHashAlgorithm)new HMAC(CreateHashAlgorithm(), Context.Negotiating.ServerWriteMAC);
			}
		}

		private void createDecryptionCipher()
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Expected O, but got Unknown
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Expected O, but got Unknown
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Expected O, but got Unknown
			switch (CipherAlgorithmType)
			{
			case CipherAlgorithmType.Des:
				decryptionAlgorithm = DES.Create();
				break;
			case CipherAlgorithmType.Rc2:
				decryptionAlgorithm = RC2.Create();
				break;
			case CipherAlgorithmType.Rc4:
				decryptionAlgorithm = (SymmetricAlgorithm)new ARC4Managed();
				break;
			case CipherAlgorithmType.TripleDes:
				decryptionAlgorithm = TripleDES.Create();
				break;
			case CipherAlgorithmType.Rijndael:
				decryptionAlgorithm = Aes.Create();
				break;
			}
			if (CipherMode == CipherMode.CBC)
			{
				decryptionAlgorithm.Mode = CipherMode;
				decryptionAlgorithm.Padding = PaddingMode.None;
				decryptionAlgorithm.KeySize = ExpandedKeyMaterialSize * 8;
				decryptionAlgorithm.BlockSize = blockSize * 8;
			}
			if (Context is ClientContext)
			{
				decryptionAlgorithm.Key = Context.ServerWriteKey;
				decryptionAlgorithm.IV = Context.ServerWriteIV;
			}
			else
			{
				decryptionAlgorithm.Key = Context.ClientWriteKey;
				decryptionAlgorithm.IV = Context.ClientWriteIV;
			}
			DecryptionCipher = decryptionAlgorithm.CreateDecryptor();
			if (Context is ClientContext)
			{
				ServerHMAC = (KeyedHashAlgorithm)new HMAC(CreateHashAlgorithm(), Context.Negotiating.ServerWriteMAC);
			}
			else
			{
				ClientHMAC = (KeyedHashAlgorithm)new HMAC(CreateHashAlgorithm(), Context.Negotiating.ClientWriteMAC);
			}
		}
	}
	internal sealed class CipherSuiteCollection : List<CipherSuite>
	{
		private readonly SecurityProtocolType protocol;

		public CipherSuite this[string name]
		{
			get
			{
				int num = IndexOf(name);
				if (num != -1)
				{
					return ((IList<CipherSuite>)this)[num];
				}
				return null;
			}
		}

		public CipherSuite this[short code]
		{
			get
			{
				int num = IndexOf(code);
				if (num != -1)
				{
					return ((IList<CipherSuite>)this)[num];
				}
				return null;
			}
		}

		public CipherSuiteCollection(SecurityProtocolType protocol)
		{
			switch (protocol)
			{
			case SecurityProtocolType.Default:
			case SecurityProtocolType.Ssl3:
			case SecurityProtocolType.Tls:
				this.protocol = protocol;
				break;
			default:
				throw new NotSupportedException("Unsupported security protocol type.");
			}
		}

		public int IndexOf(string name)
		{
			int num = 0;
			using (Enumerator enumerator = GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					CipherSuite current = enumerator.Current;
					if (string.CompareOrdinal(name, current.Name) == 0)
					{
						return num;
					}
					num++;
				}
			}
			return -1;
		}

		public int IndexOf(short code)
		{
			int num = 0;
			using (Enumerator enumerator = GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					if (enumerator.Current.Code == code)
					{
						return num;
					}
					num++;
				}
			}
			return -1;
		}

		public void Add(short code, string name, CipherAlgorithmType cipherType, HashAlgorithmType hashType, ExchangeAlgorithmType exchangeType, bool exportable, bool blockMode, byte keyMaterialSize, byte expandedKeyMaterialSize, short effectiveKeyBytes, byte ivSize, byte blockSize)
		{
			switch (protocol)
			{
			case SecurityProtocolType.Default:
			case SecurityProtocolType.Tls:
				Add(new TlsCipherSuite(code, name, cipherType, hashType, exchangeType, exportable, blockMode, keyMaterialSize, expandedKeyMaterialSize, effectiveKeyBytes, ivSize, blockSize));
				break;
			case SecurityProtocolType.Ssl3:
				Add(new SslCipherSuite(code, name, cipherType, hashType, exchangeType, exportable, blockMode, keyMaterialSize, expandedKeyMaterialSize, effectiveKeyBytes, ivSize, blockSize));
				break;
			}
		}

		public IList<string> GetNames()
		{
			List<string> list = new List<string>(base.Count);
			using Enumerator enumerator = GetEnumerator();
			while (enumerator.MoveNext())
			{
				CipherSuite current = enumerator.Current;
				list.Add(current.Name);
			}
			return list;
		}
	}
	internal static class CipherSuiteFactory
	{
		public static CipherSuiteCollection GetSupportedCiphers(bool server, SecurityProtocolType protocol)
		{
			switch (protocol)
			{
			case SecurityProtocolType.Default:
			case SecurityProtocolType.Tls:
				return GetTls1SupportedCiphers();
			case SecurityProtocolType.Ssl3:
				return GetSsl3SupportedCiphers();
			default:
				throw new NotSupportedException("Unsupported security protocol type");
			}
		}

		private static CipherSuiteCollection GetTls1SupportedCiphers()
		{
			return new CipherSuiteCollection(SecurityProtocolType.Tls)
			{
				{
					53,
					"TLS_RSA_WITH_AES_256_CBC_SHA",
					CipherAlgorithmType.Rijndael,
					HashAlgorithmType.Sha1,
					ExchangeAlgorithmType.RsaKeyX,
					false,
					true,
					32,
					32,
					256,
					16,
					16
				},
				{
					47,
					"TLS_RSA_WITH_AES_128_CBC_SHA",
					CipherAlgorithmType.Rijndael,
					HashAlgorithmType.Sha1,
					ExchangeAlgorithmType.RsaKeyX,
					false,
					true,
					16,
					16,
					128,
					16,
					16
				},
				{
					10,
					"TLS_RSA_WITH_3DES_EDE_CBC_SHA",
					CipherAlgorithmType.TripleDes,
					HashAlgorithmType.Sha1,
					ExchangeAlgorithmType.RsaKeyX,
					false,
					true,
					24,
					24,
					168,
					8,
					8
				},
				{
					5,
					"TLS_RSA_WITH_RC4_128_SHA",
					CipherAlgorithmType.Rc4,
					HashAlgorithmType.Sha1,
					ExchangeAlgorithmType.RsaKeyX,
					false,
					false,
					16,
					16,
					128,
					0,
					0
				},
				{
					4,
					"TLS_RSA_WITH_RC4_128_MD5",
					CipherAlgorithmType.Rc4,
					HashAlgorithmType.Md5,
					ExchangeAlgorithmType.RsaKeyX,
					false,
					false,
					16,
					16,
					128,
					0,
					0
				},
				{
					9,
					"TLS_RSA_WITH_DES_CBC_SHA",
					CipherAlgorithmType.Des,
					HashAlgorithmType.Sha1,
					ExchangeAlgorithmType.RsaKeyX,
					false,
					true,
					8,
					8,
					56,
					8,
					8
				}
			};
		}

		private static CipherSuiteCollection GetSsl3SupportedCiphers()
		{
			return new CipherSuiteCollection(SecurityProtocolType.Ssl3)
			{
				{
					53,
					"SSL_RSA_WITH_AES_256_CBC_SHA",
					CipherAlgorithmType.Rijndael,
					HashAlgorithmType.Sha1,
					ExchangeAlgorithmType.RsaKeyX,
					false,
					true,
					32,
					32,
					256,
					16,
					16
				},
				{
					47,
					"SSL_RSA_WITH_AES_128_CBC_SHA",
					CipherAlgorithmType.Rijndael,
					HashAlgorithmType.Sha1,
					ExchangeAlgorithmType.RsaKeyX,
					false,
					true,
					16,
					16,
					128,
					16,
					16
				},
				{
					10,
					"SSL_RSA_WITH_3DES_EDE_CBC_SHA",
					CipherAlgorithmType.TripleDes,
					HashAlgorithmType.Sha1,
					ExchangeAlgorithmType.RsaKeyX,
					false,
					true,
					24,
					24,
					168,
					8,
					8
				},
				{
					5,
					"SSL_RSA_WITH_RC4_128_SHA",
					CipherAlgorithmType.Rc4,
					HashAlgorithmType.Sha1,
					ExchangeAlgorithmType.RsaKeyX,
					false,
					false,
					16,
					16,
					128,
					0,
					0
				},
				{
					4,
					"SSL_RSA_WITH_RC4_128_MD5",
					CipherAlgorithmType.Rc4,
					HashAlgorithmType.Md5,
					ExchangeAlgorithmType.RsaKeyX,
					false,
					false,
					16,
					16,
					128,
					0,
					0
				},
				{
					9,
					"SSL_RSA_WITH_DES_CBC_SHA",
					CipherAlgorithmType.Des,
					HashAlgorithmType.Sha1,
					ExchangeAlgorithmType.RsaKeyX,
					false,
					true,
					8,
					8,
					56,
					8,
					8
				}
			};
		}
	}
	internal class ClientContext : Context
	{
		public SslClientStream SslStream { get; }

		public short ClientHelloProtocol { get; set; }

		public ClientContext(SslClientStream stream, SecurityProtocolType securityProtocolType, string targetHost, X509CertificateCollection clientCertificates)
			: base(securityProtocolType)
		{
			SslStream = stream;
			base.ClientSettings.Certificates = clientCertificates;
			base.ClientSettings.TargetHost = targetHost;
		}

		public override void Clear()
		{
			ClientHelloProtocol = 0;
			base.Clear();
		}
	}
	internal class ClientRecordProtocol : RecordProtocol
	{
		public ClientRecordProtocol(Stream innerStream, ClientContext context)
			: base(innerStream, context)
		{
		}

		public override HandshakeMessage GetMessage(HandshakeType type)
		{
			return createClientHandshakeMessage(type);
		}

		protected override void ProcessHandshakeMessage(TlsStream handMsg)
		{
			HandshakeType handshakeType = (HandshakeType)handMsg.ReadByte();
			HandshakeMessage handshakeMessage = null;
			int num = handMsg.ReadInt24();
			byte[] array = null;
			if (num > 0)
			{
				array = new byte[num];
				handMsg.Read(array, 0, num);
			}
			handshakeMessage = createServerHandshakeMessage(handshakeType, array);
			handshakeMessage?.Process();
			base.Context.LastHandshakeMsg = handshakeType;
			if (handshakeMessage != null)
			{
				handshakeMessage.Update();
				base.Context.HandshakeMessages.WriteByte((byte)handshakeType);
				base.Context.HandshakeMessages.WriteInt24(num);
				if (num > 0)
				{
					base.Context.HandshakeMessages.Write(array, 0, array.Length);
				}
			}
		}

		private HandshakeMessage createClientHandshakeMessage(HandshakeType type)
		{
			return type switch
			{
				HandshakeType.ClientHello => new Mono.Security.Protocol.Tls.Handshake.Client.TlsClientHello(context), 
				HandshakeType.Certificate => new Mono.Security.Protocol.Tls.Handshake.Client.TlsClientCertificate(context), 
				HandshakeType.ClientKeyExchange => new Mono.Security.Protocol.Tls.Handshake.Client.TlsClientKeyExchange(context), 
				HandshakeType.CertificateVerify => new Mono.Security.Protocol.Tls.Handshake.Client.TlsClientCertificateVerify(context), 
				HandshakeType.Finished => new Mono.Security.Protocol.Tls.Handshake.Client.TlsClientFinished(context), 
				_ => throw new InvalidOperationException("Unknown client handshake message type: " + type), 
			};
		}

		private HandshakeMessage createServerHandshakeMessage(HandshakeType type, byte[] buffer)
		{
			ClientContext clientContext = (ClientContext)context;
			HandshakeType lastHandshakeMsg = clientContext.LastHandshakeMsg;
			switch (type)
			{
			case HandshakeType.HelloRequest:
				if (clientContext.HandshakeState != HandshakeState.Started)
				{
					clientContext.HandshakeState = HandshakeState.None;
				}
				else
				{
					SendAlert(AlertLevel.Warning, AlertDescription.NoRenegotiation);
				}
				return null;
			case HandshakeType.ServerHello:
				if (lastHandshakeMsg == HandshakeType.HelloRequest)
				{
					return new Mono.Security.Protocol.Tls.Handshake.Client.TlsServerHello(context, buffer);
				}
				break;
			case HandshakeType.Certificate:
				if (lastHandshakeMsg == HandshakeType.ServerHello)
				{
					return new Mono.Security.Protocol.Tls.Handshake.Client.TlsServerCertificate(context, buffer);
				}
				break;
			case HandshakeType.CertificateRequest:
				if (lastHandshakeMsg == HandshakeType.ServerKeyExchange || lastHandshakeMsg == HandshakeType.Certificate)
				{
					return new Mono.Security.Protocol.Tls.Handshake.Client.TlsServerCertificateRequest(context, buffer);
				}
				break;
			case HandshakeType.ServerHelloDone:
				if (lastHandshakeMsg == HandshakeType.CertificateRequest || lastHandshakeMsg == HandshakeType.Certificate || lastHandshakeMsg == HandshakeType.ServerHello)
				{
					return new Mono.Security.Protocol.Tls.Handshake.Client.TlsServerHelloDone(context, buffer);
				}
				break;
			case HandshakeType.Finished:
				if ((clientContext.AbbreviatedHandshake ? (lastHandshakeMsg == HandshakeType.ServerHello) : (lastHandshakeMsg == HandshakeType.ServerHelloDone)) && clientContext.ChangeCipherSpecDone)
				{
					clientContext.ChangeCipherSpecDone = false;
					return new Mono.Security.Protocol.Tls.Handshake.Client.TlsServerFinished(context, buffer);
				}
				break;
			default:
				throw new TlsException(AlertDescription.UnexpectedMessage, string.Format(CultureInfo.CurrentUICulture, "Unknown server handshake message received ({0})", type.ToString()));
			}
			throw new TlsException(AlertDescription.HandshakeFailiure, $"Protocol error, unexpected protocol transition from {lastHandshakeMsg} to {type}");
		}
	}
	internal class ClientSessionInfo : IDisposable
	{
		private const int DefaultValidityInterval = 180;

		private static readonly int ValidityInterval;

		private bool disposed;

		private byte[] masterSecret;

		private DateTime validuntil;

		public string HostName { get; private set; }

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

		public bool Valid
		{
			get
			{
				if (masterSecret != null)
				{
					return validuntil > DateTime.UtcNow;
				}
				return false;
			}
		}

		static ClientSessionInfo()
		{
			string environmentVariable = Environment.GetEnvironmentVariable("MONO_TLS_SESSION_CACHE_TIMEOUT");
			if (environmentVariable == null)
			{
				ValidityInterval = 180;
				return;
			}
			try
			{
				ValidityInterval = int.Parse(environmentVariable);
			}
			catch
			{
				ValidityInterval = 180;
			}
		}

		public ClientSessionInfo(string hostname, byte[] id)
		{
			HostName = hostname;
			Id = id;
			KeepAlive();
		}

		public void Dispose()
		{
			Dispose(disposing: true);
			GC.SuppressFinalize(this);
		}

		~ClientSessionInfo()
		{
			Dispose(disposing: false);
		}

		public void GetContext(Context context)
		{
			CheckDisposed();
			if (context.MasterSecret != null)
			{
				masterSecret = (byte[])context.MasterSecret.Clone();
			}
		}

		public void SetContext(Context context)
		{
			CheckDisposed();
			if (masterSecret != null)
			{
				context.MasterSecret = (byte[])masterSecret.Clone();
			}
		}

		public void KeepAlive()
		{
			CheckDisposed();
			validuntil = DateTime.UtcNow.AddSeconds(ValidityInterval);
		}

		private void Dispose(bool disposing)
		{
			if (!disposed)
			{
				validuntil = DateTime.MinValue;
				HostName = null;
				Id = null;
				if (masterSecret != null)
				{
					Array.Clear(masterSecret, 0, masterSecret.Length);
					masterSecret = null;
				}
			}
			disposed = true;
		}

		private void CheckDisposed()
		{
			if (disposed)
			{
				throw new ObjectDisposedException(Locale.GetText("Cache session information were disposed."));
			}
		}
	}
	internal class ClientSessionCache
	{
		private static readonly Hashtable cache;

		private static readonly object locker;

		static ClientSessionCache()
		{
			cache = new Hashtable();
			locker = new object();
		}

		public static void Add(string host, byte[] id)
		{
			lock (locker)
			{
				string key = BitConverter.ToString(id);
				ClientSessionInfo clientSessionInfo = (ClientSessionInfo)cache[key];
				if (clientSessionInfo == null)
				{
					cache.Add(key, new ClientSessionInfo(host, id));
					return;
				}
				if (clientSessionInfo.HostName == host)
				{
					clientSessionInfo.KeepAlive();
					return;
				}
				clientSessionInfo.Dispose();
				cache.Remove(key);
				cache.Add(key, new ClientSessionInfo(host, id));
			}
		}

		public static byte[] FromHost(string host)
		{
			lock (locker)
			{
				foreach (ClientSessionInfo value in cache.Values)
				{
					if (value.HostName == host && value.Valid)
					{
						value.KeepAlive();
						return value.Id;
					}
				}
				return null;
			}
		}

		private static ClientSessionInfo FromContext(Context context, bool checkValidity)
		{
			if (context == null)
			{
				return null;
			}
			byte[] sessionId = context.SessionId;
			if (sessionId == null || sessionId.Length == 0)
			{
				return null;
			}
			string key = BitConverter.ToString(sessionId);
			ClientSessionInfo clientSessionInfo = (ClientSessionInfo)cache[key];
			if (clientSessionInfo == null)
			{
				return null;
			}
			if (context.ClientSettings.TargetHost != clientSessionInfo.HostName)
			{
				return null;
			}
			if (checkValidity && !clientSessionInfo.Valid)
			{
				clientSessionInfo.Dispose();
				cache.Remove(key);
				return null;
			}
			return clientSessionInfo;
		}

		public static bool SetContextInCache(Context context)
		{
			lock (locker)
			{
				ClientSessionInfo clientSessionInfo = FromContext(context, checkValidity: false);
				if (clientSessionInfo == null)
				{
					return false;
				}
				clientSessionInfo.GetContext(context);
				clientSessionInfo.KeepAlive();
				return true;
			}
		}

		public static bool SetContextFromCache(Context context)
		{
			lock (locker)
			{
				ClientSessionInfo clientSessionInfo = FromContext(context, checkValidity: true);
				if (clientSessionInfo == null)
				{
					return false;
				}
				clientSessionInfo.SetContext(context);
				clientSessionInfo.KeepAlive();
				return true;
			}
		}
	}
	[Serializable]
	internal enum ContentType : byte
	{
		ChangeCipherSpec = 20,
		Alert,
		Handshake,
		ApplicationData
	}
	internal abstract class Context
	{
		internal const short MAX_FRAGMENT_SIZE = 16384;

		internal const short TLS1_PROTOCOL_CODE = 769;

		internal const short SSL3_PROTOCOL_CODE = 768;

		internal const long UNIX_BASE_TICKS = 621355968000000000L;

		private SecurityParameters current;

		private SecurityParameters negotiating;

		private readonly RandomNumberGenerator random;

		public bool AbbreviatedHandshake { get; set; }

		public bool ProtocolNegotiated { get; set; }

		public bool ChangeCipherSpecDone { get; set; }

		public SecurityProtocolType SecurityProtocol
		{
			get
			{
				if ((SecurityProtocolFlags & SecurityProtocolType.Tls) == SecurityProtocolType.Tls || (SecurityProtocolFlags & SecurityProtocolType.Default) == SecurityProtocolType.Default)
				{
					return SecurityProtocolType.Tls;
				}
				if ((SecurityProtocolFlags & SecurityProtocolType.Ssl3) == SecurityProtocolType.Ssl3)
				{
					return SecurityProtocolType.Ssl3;
				}
				throw new NotSupportedException("Unsupported security protocol type");
			}
			set
			{
				SecurityProtocolFlags = value;
			}
		}

		public SecurityProtocolType SecurityProtocolFlags { get; private set; }

		public short Protocol
		{
			get
			{
				switch (SecurityProtocol)
				{
				case SecurityProtocolType.Default:
				case SecurityProtocolType.Tls:
					return 769;
				case SecurityProtocolType.Ssl3:
					return 768;
				default:
					throw new NotSupportedException("Unsupported security protocol type");
				}
			}
		}

		public byte[] SessionId { get; set; }

		public SecurityCompressionType CompressionMethod { get; set; }

		public TlsServerSettings ServerSettings { get; private set; }

		public TlsClientSettings ClientSettings { get; private set; }

		public HandshakeType LastHandshakeMsg { get; set; }

		public HandshakeState HandshakeState { get; set; }

		public bool ReceivedConnectionEnd { get; set; }

		public bool SentConnectionEnd { get; set; }

		public CipherSuiteCollection SupportedCiphers { get; set; }

		public TlsStream HandshakeMessages { get; private set; }

		public ulong WriteSequenceNumber { get; set; }

		public ulong ReadSequenceNumber { get; set; }

		public byte[] ClientRandom { get; set; }

		public byte[] ServerRandom { get; set; }

		public byte[] RandomCS { get; set; }

		public byte[] RandomSC { get; set; }

		public byte[] MasterSecret { get; set; }

		public byte[] ClientWriteKey { get; set; }

		public byte[] ServerWriteKey { get; set; }

		public byte[] ClientWriteIV { get; set; }

		public byte[] ServerWriteIV { get; set; }

		public RecordProtocol RecordProtocol { get; set; }

		public SecurityParameters Current
		{
			get
			{
				if (current == null)
				{
					current = new SecurityParameters();
				}
				if (current.Cipher != null)
				{
					current.Cipher.Context = this;
				}
				return current;
			}
		}

		public SecurityParameters Negotiating
		{
			get
			{
				if (negotiating == null)
				{
					negotiating = new SecurityParameters();
				}
				if (negotiating.Cipher != null)
				{
					negotiating.Cipher.Context = this;
				}
				return negotiating;
			}
		}

		public SecurityParameters Read { get; private set; }

		public SecurityParameters Write { get; private set; }

		public Context(SecurityProtocolType securityProtocolType)
		{
			SecurityProtocol = securityProtocolType;
			CompressionMethod = SecurityCompressionType.None;
			ServerSettings = new TlsServerSettings();
			ClientSettings = new TlsClientSettings();
			HandshakeMessages = new TlsStream();
			SessionId = null;
			HandshakeState = HandshakeState.None;
			random = RandomNumberGenerator.Create();
		}

		public int GetUnixTime()
		{
			return (int)((DateTime.UtcNow.Ticks - 621355968000000000L) / 10000000);
		}

		public byte[] GetSecureRandomBytes(int count)
		{
			byte[] array = new byte[count];
			random.GetNonZeroBytes(array);
			return array;
		}

		public virtual void Clear()
		{
			CompressionMethod = SecurityCompressionType.None;
			ServerSettings = new TlsServerSettings();
			ClientSettings = new TlsClientSettings();
			HandshakeMessages = new TlsStream();
			SessionId = null;
			HandshakeState = HandshakeState.None;
			ClearKeyInfo();
		}

		public virtual void ClearKeyInfo()
		{
			if (MasterSecret != null)
			{
				Array.Clear(MasterSecret, 0, MasterSecret.Length);
				MasterSecret = null;
			}
			if (ClientRandom != null)
			{
				Array.Clear(ClientRandom, 0, ClientRandom.Length);
				ClientRandom = null;
			}
			if (ServerRandom != null)
			{
				Array.Clear(ServerRandom, 0, ServerRandom.Length);
				ServerRandom = null;
			}
			if (RandomCS != null)
			{
				Array.Clear(RandomCS, 0, RandomCS.Length);
				RandomCS = null;
			}
			if (RandomSC != null)
			{
				Array.Clear(RandomSC, 0, RandomSC.Length);
				RandomSC = null;
			}
			if (ClientWriteKey != null)
			{
				Array.Clear(ClientWriteKey, 0, ClientWriteKey.Length);
				ClientWriteKey = null;
			}
			if (ClientWriteIV != null)
			{
				Array.Clear(ClientWriteIV, 0, ClientWriteIV.Length);
				ClientWriteIV = null;
			}
			if (ServerWriteKey != null)
			{
				Array.Clear(ServerWriteKey, 0, ServerWriteKey.Length);
				ServerWriteKey = null;
			}
			if (ServerWriteIV != null)
			{
				Array.Clear(ServerWriteIV, 0, ServerWriteIV.Length);
				ServerWriteIV = null;
			}
			HandshakeMessages.Reset();
			_ = SecurityProtocolFlags;
			_ = 48;
		}

		public SecurityProtocolType DecodeProtocolCode(short code, bool allowFallback = false)
		{
			switch (code)
			{
			case 769:
				return SecurityProtocolType.Tls;
			case 768:
				return SecurityProtocolType.Ssl3;
			default:
				if (allowFallback && code > 769)
				{
					return SecurityProtocolType.Tls;
				}
				throw new NotSupportedException("Unsupported security protocol type");
			}
		}

		public void ChangeProtocol(short protocol)
		{
			SecurityProtocolType securityProtocolType = DecodeProtocolCode(protocol);
			if ((securityProtocolType & SecurityProtocolFlags) == securityProtocolType || (SecurityProtocolFlags & SecurityProtocolType.Default) == SecurityProtocolType.Default)
			{
				SecurityProtocol = securityProtocolType;
				SupportedCiphers = CipherSuiteFactory.GetSupportedCiphers(this is ServerContext, securityProtocolType);
				return;
			}
			throw new TlsException(AlertDescription.ProtocolVersion, "Incorrect protocol version received from server");
		}

		public void StartSwitchingSecurityParameters(bool client)
		{
			if (client)
			{
				Write = negotiating;
				Read = current;
			}
			else
			{
				Read = negotiating;
				Write = current;
			}
			current = negotiating;
		}

		public void EndSwitchingSecurityParameters(bool client)
		{
			SecurityParameters securityParameters;
			if (client)
			{
				securityParameters = Read;
				Read = current;
			}
			else
			{
				securityParameters = Write;
				Write = current;
			}
			securityParameters?.Clear();
			negotiating = securityParameters;
		}
	}
	internal class DebugHelper
	{
		private static bool isInitialized;

		[Conditional("DEBUG")]
		public static void Initialize()
		{
			if (!isInitialized)
			{
				System.Diagnostics.Debug.Listeners.Add(new TextWriterTraceListener(Console.Out));
				System.Diagnostics.Debug.AutoFlush = true;
				isInitialized = true;
			}
		}

		[Conditional("DEBUG")]
		public static void WriteLine(string format, params object[] args)
		{
		}

		[Conditional("DEBUG")]
		public static void WriteLine(string message)
		{
		}

		[Conditional("DEBUG")]
		public static void WriteLine(string message, byte[] buffer)
		{
		}

		[Conditional("DEBUG")]
		public static void WriteBuffer(byte[] buffer)
		{
		}

		[Conditional("DEBUG")]
		public static void WriteBuffer(byte[] buffer, int index, int length)
		{
			for (int i = index; i < length; i += 16)
			{
				int num = ((length - i >= 16) ? 16 : (length - i));
				string text = "";
				for (int j = 0; j < num; j++)
				{
					text = text + buffer[i + j].ToString("x2") + " ";
				}
			}
		}
	}
	[Serializable]
	public enum ExchangeAlgorithmType
	{
		DiffieHellman,
		Fortezza,
		None,
		RsaKeyX,
		RsaSign
	}
	[Serializable]
	internal enum HandshakeState
	{
		None,
		Started,
		Finished
	}
	[Serializable]
	public enum HashAlgorithmType
	{
		Md5,
		None,
		Sha1
	}
	[Obsolete("This class is obsolete and will be removed shortly.")]
	internal class HttpsClientStream : SslClientStream
	{
		private readonly HttpWebRequest _request;

		private int _status;

		public bool TrustFailure
		{
			get
			{
				int status = _status;
				if ((uint)(status - -2146762487) <= 1u)
				{
					return true;
				}
				return false;
			}
		}

		public HttpsClientStream(Stream stream, X509CertificateCollection clientCertificates, HttpWebRequest request, byte[] buffer)
			: base(stream, request.Address.Host, ownsStream: false, (SecurityProtocolType)ServicePointManager.SecurityProtocol, clientCertificates)
		{
			_request = request;
			_status = 0;
			if (buffer != null)
			{
				base.InputBuffer.Write(buffer, 0, buffer.Length);
			}
			base.CheckCertRevocationStatus = ServicePointManager.CheckCertificateRevocationList;
			base.ClientCertSelection += (X509CertificateCollection clientCerts, X509Certificate serverCertificate, string targetHost, X509CertificateCollection serverRequestedCertificates) => (clientCerts != null && clientCerts.Count != 0) ? clientCerts[0] : null;
			base.PrivateKeySelection += (X509Certificate certificate, string targetHost) => (certificate is X509Certificate2 x509Certificate) ? x509Certificate.PrivateKey : null;
		}

		internal override bool RaiseServerCertificateValidation(X509Certificate certificate, int[] certificateErrors)
		{
			bool flag = certificateErrors.Length != 0;
			_status = (flag ? certificateErrors[0] : 0);
			if (ServicePointManager.CertificatePolicy != null)
			{
				ServicePoint servicePoint = _request.ServicePoint;
				if (!ServicePointManager.CertificatePolicy.CheckValidationResult(servicePoint, certificate, (WebRequest)_request, _status))
				{
					return false;
				}
				flag = true;
			}
			if (HaveRemoteValidation2Callback)
			{
				return flag;
			}
			RemoteCertificateValidationCallback serverCertificateValidationCallback = ServicePointManager.ServerCertificateValidationCallback;
			if (serverCertificateValidationCallback != null)
			{
				SslPolicyErrors sslPolicyErrors = SslPolicyErrors.None;
				for (int i = 0; i < certificateErrors.Length; i++)
				{
					sslPolicyErrors = certificateErrors[i] switch
					{
						-2146762490 => sslPolicyErrors | SslPolicyErrors.RemoteCertificateNotAvailable, 
						-2146762481 => sslPolicyErrors | SslPolicyErrors.RemoteCertificateNameMismatch, 
						_ => sslPolicyErrors | SslPolicyErrors.RemoteCertificateChainErrors, 
					};
				}
				X509Certificate2 certificate2 = new X509Certificate2(certificate.GetRawCertData());
				X509Chain x509Chain = new X509Chain();
				if (!x509Chain.Build(certificate2))
				{
					sslPolicyErrors |= SslPolicyErrors.RemoteCertificateChainErrors;
				}
				return serverCertificateValidationCallback(_request, certificate2, x509Chain, sslPolicyErrors);
			}
			return flag;
		}
	}
	internal class MD5SHA1 : HashAlgorithm
	{
		private readonly HashAlgorithm md5;

		private readonly HashAlgorithm sha;

		private bool hashing;

		public MD5SHA1()
		{
			md5 = MD5.Create();
			sha = SHA1.Create();
			HashSizeValue = md5.HashSize + sha.HashSize;
		}

		public override void Initialize()
		{
			md5.Initialize();
			sha.Initialize();
			hashing = false;
		}

		public override byte[] HashFinal()
		{
			if (!hashing)
			{
				hashing = true;
			}
			md5.TransformFinalBlock(new byte[0], 0, 0);
			sha.TransformFinalBlock(new byte[0], 0, 0);
			byte[] array = new byte[36];
			Buffer.BlockCopy(md5.Hash, 0, array, 0, 16);
			Buffer.BlockCopy(sha.Hash, 0, array, 16, 20);
			return array;
		}

		public override void HashCore(byte[] array, int ibStart, int cbSize)
		{
			if (!hashing)
			{
				hashing = true;
			}
			md5.TransformBlock(array, ibStart, cbSize, array, ibStart);
			sha.TransformBlock(array, ibStart, cbSize, array, ibStart);
		}

		public byte[] CreateSignature(RSA rsa)
		{
			if (rsa == null)
			{
				throw new CryptographicUnexpectedOperationException("missing key");
			}
			RSASslSignatureFormatter rSASslSignatureFormatter = new RSASslSignatureFormatter(rsa);
			rSASslSignatureFormatter.SetHashAlgorithm("MD5SHA1");
			return rSASslSignatureFormatter.CreateSignature(Hash);
		}

		public bool VerifySignature(RSA rsa, byte[] rgbSignature)
		{
			if (rsa == null)
			{
				throw new CryptographicUnexpectedOperationException("missing key");
			}
			if (rgbSignature == null)
			{
				throw new ArgumentNullException("rgbSignature");
			}
			RSASslSignatureDeformatter rSASslSignatureDeformatter = new RSASslSignatureDeformatter(rsa);
			rSASslSignatureDeformatter.SetHashAlgorithm("MD5SHA1");
			return rSASslSignatureDeformatter.VerifySignature(Hash, rgbSignature);
		}
	}
	internal abstract class RecordProtocol
	{
		private class ReceiveRecordAsyncResult : IAsyncResult
		{
			private readonly AsyncCallback _userCallback;

			private readonly object locker = new object();

			private bool completed;

			private ManualResetEvent handle;

			public Stream Record { get; }

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

			public byte[] InitialBuffer { get; }

			public Exception AsyncException { get; private set; }

			public bool CompletedWithError
			{
				get
				{
					if (!IsCompleted)
					{
						return false;
					}
					return AsyncException != null;
				}
			}

			public object AsyncState { get; }

			public WaitHandle AsyncWaitHandle
			{
				get
				{
					lock (locker)
					{
						if (handle == null)
						{
							handle = new ManualResetEvent(completed);
						}
					}
					return handle;
				}
			}

			public bool CompletedSynchronously => false;

			public bool IsCompleted
			{
				get
				{
					lock (locker)
					{
						return completed;
					}
				}
			}

			public ReceiveRecordAsyncResult(AsyncCallback userCallback, object userState, byte[] initialBuffer, Stream record)
			{
				_userCallback = userCallback;
				AsyncState = userState;
				InitialBuffer = initialBuffer;
				Record = record;
			}

			private void SetComplete(Exception ex, byte[] resultingBuffer)
			{
				lock (locker)
				{
					if (!completed)
					{
						completed = true;
						AsyncException = ex;
						ResultingBuffer = resultingBuffer;
						if (handle != null)
						{
							handle.Set();
						}
						if (_userCallback != null)
						{
							_userCallback.BeginInvoke(this, null, null);
						}
					}
				}
			}

			public void SetComplete(Exception ex)
			{
				SetComplete(ex, null);
			}

			public void SetComplete(byte[] resultingBuffer)
			{
				SetComplete(null, resultingBuffer);
			}

			public void SetComplete()
			{
				SetComplete(null, null);
			}
		}

		private class SendRecordAsyncResult : IAsyncResult
		{
			private readonly AsyncCallback _userCallback;

			private readonly object locker = new object();

			private bool completed;

			private ManualResetEvent handle;

			public HandshakeMessage Message { get; }

			public Exception AsyncException { get; private set; }

			public bool CompletedWithError
			{
				get
				{
					if (!IsCompleted)
					{
						return false;
					}
					return AsyncException != null;
				}
			}

			public object AsyncState { get; }

			public WaitHandle AsyncWaitHandle
			{
				get
				{
					lock (locker)
					{
						if (handle == null)
						{
							handle = new ManualResetEvent(completed);
						}
					}
					return handle;
				}
			}

			public bool CompletedSynchronously => false;

			public bool IsCompleted
			{
				get
				{
					lock (locker)
					{
						return completed;
					}
				}
			}

			public SendRecordAsyncResult(AsyncCallback userCallback, object userState, HandshakeMessage message)
			{
				_userCallback = userCallback;
				AsyncState = userState;
				Message = message;
			}

			public void SetComplete(Exception ex)
			{
				lock (locker)
				{
					if (!completed)
					{
						completed = true;
						if (handle != null)
						{
							handle.Set();
						}
						if (_userCallback != null)
						{
							_userCallback.BeginInvoke(this, null, null);
						}
						AsyncException = ex;
					}
				}
			}

			public void SetComplete()
			{
				SetComplete(null);
			}
		}

		private static readonly ManualResetEvent record_processing = new ManualResetEvent(initialState: true);

		protected Stream innerStream;

		protected Context context;

		public Context Context
		{
			get
			{
				return context;
			}
			set
			{
				context = value;
			}
		}

		public RecordProtocol(Stream innerStream, Context context)
		{
			this.innerStream = innerStream;
			this.context = context;
			this.context.RecordProtocol = this;
		}

		public virtual void SendRecord(HandshakeType type)
		{
			IAsyncResult asyncResult = BeginSendRecord(type, null, null);
			EndSendRecord(asyncResult);
		}

		protected abstract void ProcessHandshakeMessage(TlsStream handMsg);

		protected virtual void ProcessChangeCipherSpec()
		{
			Context context = Context;
			context.ReadSequenceNumber = 0uL;
			if (context is ClientContext)
			{
				context.EndSwitchingSecurityParameters(client: true);
			}
			else
			{
				context.StartSwitchingSecurityParameters(client: false);
			}
			context.ChangeCipherSpecDone = true;
		}

		public virtual HandshakeMessage GetMessage(HandshakeType type)
		{
			throw new NotSupportedException();
		}

		public IAsyncResult BeginReceiveRecord(Stream record, AsyncCallback callback, object state)
		{
			if (context.ReceivedConnectionEnd)
			{
				throw new TlsException(AlertDescription.InternalError, "The session is finished and it's no longer valid.");
			}
			record_processing.Reset();
			byte[] initialBuffer = new byte[1];
			ReceiveRecordAsyncResult receiveRecordAsyncResult = new ReceiveRecordAsyncResult(callback, state, initialBuffer, record);
			record.BeginRead(receiveRecordAsyncResult.InitialBuffer, 0, receiveRecordAsyncResult.InitialBuffer.Length, InternalReceiveRecordCallback, receiveRecordAsyncResult);
			return receiveRecordAsyncResult;
		}

		private void InternalReceiveRecordCallback(IAsyncResult asyncResult)
		{
			ReceiveRecordAsyncResult receiveRecordAsyncResult = asyncResult.AsyncState as ReceiveRecordAsyncResult;
			Stream record = receiveRecordAsyncResult.Record;
			try
			{
				if (receiveRecordAsyncResult.Record.EndRead(asyncResult) == 0)
				{
					receiveRecordAsyncResult.SetComplete((byte[])null);
					return;
				}
				int num = receiveRecordAsyncResult.InitialBuffer[0];
				ContentType contentType = (ContentType)num;
				byte[] array = ReadRecordBuffer(num, record);
				if (array == null)
				{
					receiveRecordAsyncResult.SetComplete((byte[])null);
					return;
				}
				if ((contentType != ContentType.Alert || array.Length != 2) && Context.Read != null && Context.Read.Cipher != null)
				{
					array = decryptRecordFragment(contentType, array);
				}
				switch (contentType)
				{
				case ContentType.Alert:
					ProcessAlert((AlertLevel)array[0], (AlertDescription)array[1]);
					if (record.CanSeek)
					{
						record.SetLength(0L);
					}
					array = null;
					break;
				case ContentType.ChangeCipherSpec:
					ProcessChangeCipherSpec();
					break;
				case ContentType.Handshake:
				{
					TlsStream tlsStream = new TlsStream(array);
					while (!tlsStream.EOF)
					{
						ProcessHandshakeMessage(tlsStream);
					}
					break;
				}
				case (ContentType)128:
					context.HandshakeMessages.Write(array);
					break;
				default:
					throw new TlsException(AlertDescription.UnexpectedMessage, "Unknown record received from server.");
				case ContentType.ApplicationData:
					break;
				}
				receiveRecordAsyncResult.SetComplete(array);
			}
			catch (Exception complete)
			{
				receiveRecordAsyncResult.SetComplete(complete);
			}
		}

		public byte[] EndReceiveRecord(IAsyncResult asyncResult)
		{
			if (!(asyncResult is ReceiveRecordAsyncResult receiveRecordAsyncResult))
			{
				throw new ArgumentException("Either the provided async result is null or was not created by this RecordProtocol.");
			}
			if (!receiveRecordAsyncResult.IsCompleted)
			{
				receiveRecordAsyncResult.AsyncWaitHandle.WaitOne();
			}
			if (receiveRecordAsyncResult.CompletedWithError)
			{
				throw receiveRecordAsyncResult.AsyncException;
			}
			byte[] resultingBuffer = receiveRecordAsyncResult.ResultingBuffer;
			record_processing.Set();
			return resultingBuffer;
		}

		public byte[] ReceiveRecord(Stream record)
		{
			if (context.ReceivedConnectionEnd)
			{
				throw new TlsException(AlertDescription.InternalError, "The session is finished and it's no longer valid.");
			}
			record_processing.Reset();
			byte[] array = new byte[1];
			if (record.Read(array, 0, array.Length) == 0)
			{
				return null;
			}
			int num = array[0];
			ContentType contentType = (ContentType)num;
			byte[] array2 = ReadRecordBuffer(num, record);
			if (array2 == null)
			{
				return null;
			}
			if ((contentType != ContentType.Alert || array2.Length != 2) && Context.Read != null && Context.Read.Cipher != null)
			{
				array2 = decryptRecordFragment(contentType, array2);
			}
			switch (contentType)
			{
			case ContentType.Alert:
				ProcessAlert((AlertLevel)array2[0], (AlertDescription)array2[1]);
				if (record.CanSeek)
				{
					record.SetLength(0L);
				}
				array2 = null;
				break;
			case ContentType.ChangeCipherSpec:
				ProcessChangeCipherSpec();
				break;
			case ContentType.Handshake:
			{
				TlsStream tlsStream = new TlsStream(array2);
				while (!tlsStream.EOF)
				{
					ProcessHandshakeMessage(tlsStream);
				}
				break;
			}
			case (ContentType)128:
				context.HandshakeMessages.Write(array2);
				break;
			default:
				throw new TlsException(AlertDescription.UnexpectedMessage, "Unknown record received from server.");
			case ContentType.ApplicationData:
				break;
			}
			record_processing.Set();
			return array2;
		}

		private byte[] ReadRecordBuffer(int contentType, Stream record)
		{
			if (!Enum.IsDefined(typeof(ContentType), (ContentType)contentType))
			{
				throw new TlsException(AlertDescription.DecodeError);
			}
			byte[] array = new byte[4];
			if (record.Read(array, 0, 4) != 4)
			{
				throw new TlsException("buffer underrun");
			}
			short num = (short)((array[0] << 8) | array[1]);
			short num2 = (short)((array[2] << 8) | array[3]);
			if (record.CanSeek && num2 + 5 > record.Length)
			{
				return null;
			}
			int i = 0;
			byte[] array2 = new byte[num2];
			int num3;
			for (; i != num2; i += num3)
			{
				num3 = record.Read(array2, i, array2.Length - i);
				if (num3 == 0)
				{
					throw new TlsException(AlertDescription.CloseNotify, "Received 0 bytes from stream. It must be closed.");
				}
			}
			if (num != context.Protocol && context.ProtocolNegotiated)
			{
				throw new TlsException(AlertDescription.ProtocolVersion, "Invalid protocol version on message received");
			}
			return array2;
		}

		private void ProcessAlert(AlertLevel alertLevel, AlertDescription alertDesc)
		{
			if (alertLevel != AlertLevel.Warning && alertLevel == AlertLevel.Fatal)
			{
				throw new TlsException(alertLevel, alertDesc);
			}
			if (alertDesc == AlertDescription.CloseNotify)
			{
				context.ReceivedConnectionEnd = true;
			}
		}

		internal void SendAlert(ref Exception ex)
		{
			Alert alert = ((ex is TlsException ex2) ? ex2.Alert : new Alert(AlertDescription.InternalError));
			try
			{
				SendAlert(alert);
			}
			catch (Exception innerException)
			{
			

BepInExPack/BepInEx/core/Il2CppDumper.dll

Decompiled a month 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.Text;
using System.Text.RegularExpressions;
using Mono.Cecil;
using Mono.Cecil.Cil;
using Mono.Collections.Generic;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("Perfare")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyCopyright("Copyright © Perfare 2016-2021")]
[assembly: AssemblyFileVersion("6.6.4.0")]
[assembly: AssemblyInformationalVersion("6.6.4")]
[assembly: AssemblyProduct("Il2CppDumper")]
[assembly: AssemblyTitle("Il2CppDumper")]
[assembly: AssemblyVersion("6.6.4.0")]
namespace Il2CppDumper;

[AttributeUsage(AttributeTargets.Field)]
internal class ArrayLengthAttribute : Attribute
{
	public int Length { get; set; }
}
[AttributeUsage(AttributeTargets.Field, AllowMultiple = true)]
internal class VersionAttribute : Attribute
{
	public double Min { get; set; }

	public double Max { get; set; } = 99.0;

}
public class Config
{
	public bool DumpMethod = true;

	public bool DumpField = true;

	public bool DumpProperty;

	public bool DumpAttribute;

	public bool DumpFieldOffset = true;

	public bool DumpMethodOffset = true;

	public bool DumpTypeDefIndex = true;

	public bool GenerateDummyDll = true;

	public bool GenerateStruct = true;

	public bool DummyDllAddToken = true;

	public bool RequireAnyKey = true;

	public bool ForceIl2CppVersion;

	public double ForceVersion = 24.3;
}
public sealed class Elf : ElfBase
{
	private Elf32_Ehdr elfHeader;

	private Elf32_Phdr[] programSegment;

	private Elf32_Dyn[] dynamicSection;

	private Elf32_Sym[] symbolTable;

	private Elf32_Shdr[] sectionTable;

	private Elf32_Phdr pt_dynamic;

	private static readonly string ARMFeatureBytes = "? 0x10 ? 0xE7 ? 0x00 ? 0xE0 ? 0x20 ? 0xE0";

	private static readonly string X86FeatureBytes = "? 0x10 ? 0xE7 ? 0x00 ? 0xE0 ? 0x20 ? 0xE0";

	public Elf(Stream stream, Action<string> reportProgressAction)
		: base(stream, reportProgressAction)
	{
		Is32Bit = true;
		elfHeader = ReadClass<Elf32_Ehdr>();
		programSegment = ReadClassArray<Elf32_Phdr>(elfHeader.e_phoff, elfHeader.e_phnum);
		if (!CheckSection())
		{
			GetDumpAddress();
		}
		if (IsDumped)
		{
			FixedProgramSegment();
		}
		pt_dynamic = programSegment.First((Elf32_Phdr x) => x.p_type == 2);
		dynamicSection = ReadClassArray<Elf32_Dyn>(pt_dynamic.p_offset, pt_dynamic.p_filesz / 8);
		if (IsDumped)
		{
			FixedDynamicSection();
		}
		ReadSymbol();
		if (!IsDumped)
		{
			RelocationProcessing();
			if (CheckProtection())
			{
				reportProgressAction("ERROR: This file may be protected.");
			}
		}
	}

	public bool CheckSection()
	{
		try
		{
			List<string> list = new List<string>();
			sectionTable = ReadClassArray<Elf32_Shdr>(elfHeader.e_shoff, elfHeader.e_shnum);
			uint sh_offset = sectionTable[elfHeader.e_shstrndx].sh_offset;
			Elf32_Shdr[] array = sectionTable;
			foreach (Elf32_Shdr elf32_Shdr in array)
			{
				list.Add(ReadStringToNull(sh_offset + elf32_Shdr.sh_name));
			}
			if (!list.Contains(".text"))
			{
				return false;
			}
			return true;
		}
		catch
		{
			return false;
		}
	}

	public override ulong MapVATR(ulong addr)
	{
		Elf32_Phdr elf32_Phdr = programSegment.First((Elf32_Phdr x) => addr >= x.p_vaddr && addr <= x.p_vaddr + x.p_memsz);
		return addr - elf32_Phdr.p_vaddr + elf32_Phdr.p_offset;
	}

	public override ulong MapRTVA(ulong addr)
	{
		Elf32_Phdr elf32_Phdr = programSegment.FirstOrDefault((Elf32_Phdr x) => addr >= x.p_offset && addr <= x.p_offset + x.p_filesz);
		if (elf32_Phdr == null)
		{
			return 0uL;
		}
		return addr - elf32_Phdr.p_offset + elf32_Phdr.p_vaddr;
	}

	public override bool Search()
	{
		uint d_un = dynamicSection.First((Elf32_Dyn x) => x.d_tag == 3).d_un;
		Elf32_Phdr[] array = programSegment.Where((Elf32_Phdr x) => x.p_type == 1 && (x.p_flags & 1) == 1).ToArray();
		List<int> list = new List<int>();
		string stringPattern = ((elfHeader.e_machine == 40) ? ARMFeatureBytes : X86FeatureBytes);
		Elf32_Phdr[] array2 = array;
		foreach (Elf32_Phdr elf32_Phdr in array2)
		{
			base.Position = elf32_Phdr.p_offset;
			byte[] array3 = ReadBytes((int)elf32_Phdr.p_filesz);
			foreach (int item in array3.Search(stringPattern))
			{
				if (array3[item + 2].HexToBin()[3] == '1')
				{
					list.Add(item);
				}
			}
		}
		if (list.Count == 1)
		{
			uint num = 0u;
			uint num2 = 0u;
			uint num3 = (uint)list[0];
			if (Version < 24.0)
			{
				if (elfHeader.e_machine == 40)
				{
					base.Position = num3 + 20;
					num = ReadUInt32() + d_un;
					base.Position = num3 + 24;
					uint num4 = ReadUInt32() + d_un;
					base.Position = MapVATR(num4);
					num2 = ReadUInt32();
				}
			}
			else if (Version >= 24.0 && elfHeader.e_machine == 40)
			{
				base.Position = num3 + 20;
				num = ReadUInt32() + num3 + 12 + (uint)(int)DumpAddr;
				base.Position = num3 + 16;
				uint num5 = ReadUInt32() + num3 + 8;
				base.Position = MapVATR(num5 + DumpAddr);
				num2 = ReadUInt32();
			}
			reportProgressAction($"CodeRegistration : {num:x}");
			reportProgressAction($"MetadataRegistration : {num2:x}");
			Init(num, num2);
			return true;
		}
		return false;
	}

	public override bool PlusSearch(int methodCount, int typeDefinitionsCount, int imageCount)
	{
		List<Elf32_Phdr> list = new List<Elf32_Phdr>();
		List<Elf32_Phdr> list2 = new List<Elf32_Phdr>();
		Elf32_Phdr[] array = programSegment;
		foreach (Elf32_Phdr elf32_Phdr in array)
		{
			if ((long)elf32_Phdr.p_memsz != 0L)
			{
				switch (elf32_Phdr.p_flags)
				{
				case 1u:
				case 3u:
				case 5u:
				case 7u:
					list2.Add(elf32_Phdr);
					break;
				case 2u:
				case 4u:
				case 6u:
					list.Add(elf32_Phdr);
					break;
				}
			}
		}
		Elf32_Phdr[] sections = list.ToArray();
		Elf32_Phdr[] sections2 = list2.ToArray();
		PlusSearch plusSearch = new PlusSearch(this, methodCount, typeDefinitionsCount, maxMetadataUsages, imageCount);
		plusSearch.SetSection(SearchSectionType.Exec, sections2);
		plusSearch.SetSection(SearchSectionType.Data, sections);
		plusSearch.SetSection(SearchSectionType.Bss, sections);
		ulong codeRegistration = plusSearch.FindCodeRegistration();
		ulong metadataRegistration = plusSearch.FindMetadataRegistration();
		return AutoPlusInit(codeRegistration, metadataRegistration);
	}

	public override bool SymbolSearch()
	{
		uint num = 0u;
		uint num2 = 0u;
		ulong num3 = MapVATR(dynamicSection.First((Elf32_Dyn x) => x.d_tag == 5).d_un);
		Elf32_Sym[] array = symbolTable;
		foreach (Elf32_Sym elf32_Sym in array)
		{
			string text = ReadStringToNull(num3 + elf32_Sym.st_name);
			if (!(text == "g_CodeRegistration"))
			{
				if (text == "g_MetadataRegistration")
				{
					num2 = elf32_Sym.st_value;
				}
			}
			else
			{
				num = elf32_Sym.st_value;
			}
		}
		if (num != 0 && num2 != 0)
		{
			reportProgressAction("Detected Symbol !");
			reportProgressAction($"CodeRegistration : {num:x}");
			reportProgressAction($"MetadataRegistration : {num2:x}");
			Init(num, num2);
			return true;
		}
		reportProgressAction("ERROR: No symbol is detected");
		return false;
	}

	private void ReadSymbol()
	{
		try
		{
			ulong num = MapVATR(dynamicSection.First((Elf32_Dyn x) => x.d_tag == 6).d_un);
			ulong num2 = MapVATR(dynamicSection.First((Elf32_Dyn x) => x.d_tag == 5).d_un) - num;
			symbolTable = ReadClassArray<Elf32_Sym>(num, (long)num2 / 16L);
		}
		catch
		{
		}
	}

	private void RelocationProcessing()
	{
		reportProgressAction("Applying relocations...");
		try
		{
			ulong addr = MapVATR(dynamicSection.First((Elf32_Dyn x) => x.d_tag == 17).d_un);
			uint d_un = dynamicSection.First((Elf32_Dyn x) => x.d_tag == 18).d_un;
			Elf32_Rel[] array = ReadClassArray<Elf32_Rel>(addr, d_un / 8);
			bool flag = elfHeader.e_machine == 3;
			Elf32_Rel[] array2 = array;
			foreach (Elf32_Rel elf32_Rel in array2)
			{
				uint num = elf32_Rel.r_info & 0xFF;
				uint num2 = elf32_Rel.r_info >> 8;
				uint num3 = num;
				if (num3 != 1)
				{
					if (num3 != 2 || flag)
					{
						continue;
					}
				}
				else if (!flag)
				{
					continue;
				}
				Elf32_Sym elf32_Sym = symbolTable[num2];
				base.Position = MapVATR(elf32_Rel.r_offset);
				Write(elf32_Sym.st_value);
			}
		}
		catch
		{
		}
	}

	private bool CheckProtection()
	{
		if (dynamicSection.Any((Elf32_Dyn x) => x.d_tag == 12))
		{
			reportProgressAction("WARNING: find .init_proc");
			return true;
		}
		ulong num = MapVATR(dynamicSection.First((Elf32_Dyn x) => x.d_tag == 5).d_un);
		Elf32_Sym[] array = symbolTable;
		foreach (Elf32_Sym elf32_Sym in array)
		{
			if (ReadStringToNull(num + elf32_Sym.st_name) == "JNI_OnLoad")
			{
				reportProgressAction("WARNING: find JNI_OnLoad");
				return true;
			}
		}
		if (sectionTable != null && sectionTable.Any((Elf32_Shdr x) => x.sh_type == 2147483648u))
		{
			reportProgressAction("WARNING: find SHT_LOUSER section");
			return true;
		}
		return false;
	}

	public override ulong GetRVA(ulong pointer)
	{
		if (IsDumped)
		{
			return pointer - DumpAddr;
		}
		return pointer;
	}

	private void FixedProgramSegment()
	{
		for (uint num = 0u; num < programSegment.Length; num++)
		{
			base.Position = elfHeader.e_phoff + num * 32 + 4;
			Elf32_Phdr elf32_Phdr = programSegment[num];
			elf32_Phdr.p_offset = elf32_Phdr.p_vaddr;
			Write(elf32_Phdr.p_offset);
			elf32_Phdr.p_vaddr += (uint)(int)DumpAddr;
			Write(elf32_Phdr.p_vaddr);
			base.Position += 4uL;
			elf32_Phdr.p_filesz = elf32_Phdr.p_memsz;
			Write(elf32_Phdr.p_filesz);
		}
	}

	private void FixedDynamicSection()
	{
		for (uint num = 0u; num < dynamicSection.Length; num++)
		{
			base.Position = pt_dynamic.p_offset + num * 8 + 4;
			Elf32_Dyn elf32_Dyn = dynamicSection[num];
			switch (elf32_Dyn.d_tag)
			{
			case 3:
			case 4:
			case 5:
			case 6:
			case 7:
			case 12:
			case 13:
			case 17:
			case 23:
			case 25:
			case 26:
				elf32_Dyn.d_un += (uint)(int)DumpAddr;
				Write(elf32_Dyn.d_un);
				break;
			}
		}
	}
}
public sealed class Elf64 : ElfBase
{
	private Elf64_Ehdr elfHeader;

	private Elf64_Phdr[] programSegment;

	private Elf64_Dyn[] dynamicSection;

	private Elf64_Sym[] symbolTable;

	private Elf64_Shdr[] sectionTable;

	private Elf64_Phdr pt_dynamic;

	public Elf64(Stream stream, Action<string> reportProgressAction)
		: base(stream, reportProgressAction)
	{
		elfHeader = ReadClass<Elf64_Ehdr>();
		programSegment = ReadClassArray<Elf64_Phdr>(elfHeader.e_phoff, elfHeader.e_phnum);
		if (!CheckSection())
		{
			GetDumpAddress();
		}
		if (IsDumped)
		{
			FixedProgramSegment();
		}
		pt_dynamic = programSegment.First((Elf64_Phdr x) => x.p_type == 2);
		dynamicSection = ReadClassArray<Elf64_Dyn>(pt_dynamic.p_offset, (long)pt_dynamic.p_filesz / 16L);
		if (IsDumped)
		{
			FixedDynamicSection();
		}
		ReadSymbol();
		if (!IsDumped)
		{
			RelocationProcessing();
			if (CheckProtection())
			{
				reportProgressAction("ERROR: This file may be protected.");
			}
		}
	}

	public bool CheckSection()
	{
		try
		{
			List<string> list = new List<string>();
			sectionTable = ReadClassArray<Elf64_Shdr>(elfHeader.e_shoff, elfHeader.e_shnum);
			ulong sh_offset = sectionTable[elfHeader.e_shstrndx].sh_offset;
			Elf64_Shdr[] array = sectionTable;
			foreach (Elf64_Shdr elf64_Shdr in array)
			{
				list.Add(ReadStringToNull(sh_offset + elf64_Shdr.sh_name));
			}
			if (!list.Contains(".text"))
			{
				return false;
			}
			return true;
		}
		catch
		{
			return false;
		}
	}

	public override ulong MapVATR(ulong addr)
	{
		Elf64_Phdr elf64_Phdr = programSegment.First((Elf64_Phdr x) => addr >= x.p_vaddr && addr <= x.p_vaddr + x.p_memsz);
		return addr - elf64_Phdr.p_vaddr + elf64_Phdr.p_offset;
	}

	public override ulong MapRTVA(ulong addr)
	{
		Elf64_Phdr elf64_Phdr = programSegment.FirstOrDefault((Elf64_Phdr x) => addr >= x.p_offset && addr <= x.p_offset + x.p_filesz);
		if (elf64_Phdr == null)
		{
			return 0uL;
		}
		return addr - elf64_Phdr.p_offset + elf64_Phdr.p_vaddr;
	}

	public override bool Search()
	{
		return false;
	}

	public override bool PlusSearch(int methodCount, int typeDefinitionsCount, int imageCount)
	{
		List<Elf64_Phdr> list = new List<Elf64_Phdr>();
		List<Elf64_Phdr> list2 = new List<Elf64_Phdr>();
		Elf64_Phdr[] array = programSegment;
		foreach (Elf64_Phdr elf64_Phdr in array)
		{
			if (elf64_Phdr.p_memsz != 0L)
			{
				switch (elf64_Phdr.p_flags)
				{
				case 1u:
				case 3u:
				case 5u:
				case 7u:
					list2.Add(elf64_Phdr);
					break;
				case 2u:
				case 4u:
				case 6u:
					list.Add(elf64_Phdr);
					break;
				}
			}
		}
		Elf64_Phdr[] sections = list.ToArray();
		Elf64_Phdr[] sections2 = list2.ToArray();
		PlusSearch plusSearch = new PlusSearch(this, methodCount, typeDefinitionsCount, maxMetadataUsages, imageCount);
		plusSearch.SetSection(SearchSectionType.Exec, sections2);
		plusSearch.SetSection(SearchSectionType.Data, sections);
		plusSearch.SetSection(SearchSectionType.Bss, sections);
		ulong codeRegistration = plusSearch.FindCodeRegistration();
		ulong metadataRegistration = plusSearch.FindMetadataRegistration();
		return AutoPlusInit(codeRegistration, metadataRegistration);
	}

	public override bool SymbolSearch()
	{
		ulong num = 0uL;
		ulong num2 = 0uL;
		ulong num3 = MapVATR(dynamicSection.First((Elf64_Dyn x) => x.d_tag == 5).d_un);
		Elf64_Sym[] array = symbolTable;
		foreach (Elf64_Sym elf64_Sym in array)
		{
			string text = ReadStringToNull(num3 + elf64_Sym.st_name);
			if (!(text == "g_CodeRegistration"))
			{
				if (text == "g_MetadataRegistration")
				{
					num2 = elf64_Sym.st_value;
				}
			}
			else
			{
				num = elf64_Sym.st_value;
			}
		}
		if (num != 0 && num2 != 0)
		{
			reportProgressAction("Detected Symbol !");
			reportProgressAction($"CodeRegistration : {num:x}");
			reportProgressAction($"MetadataRegistration : {num2:x}");
			Init(num, num2);
			return true;
		}
		reportProgressAction("ERROR: No symbol is detected");
		return false;
	}

	private void ReadSymbol()
	{
		try
		{
			ulong num = MapVATR(dynamicSection.First((Elf64_Dyn x) => x.d_tag == 6).d_un);
			ulong num2 = MapVATR(dynamicSection.First((Elf64_Dyn x) => x.d_tag == 5).d_un) - num;
			symbolTable = ReadClassArray<Elf64_Sym>(num, (long)num2 / 24L);
		}
		catch
		{
		}
	}

	private void RelocationProcessing()
	{
		reportProgressAction("Applying relocations...");
		try
		{
			ulong addr = MapVATR(dynamicSection.First((Elf64_Dyn x) => x.d_tag == 7).d_un);
			ulong d_un = dynamicSection.First((Elf64_Dyn x) => x.d_tag == 8).d_un;
			Elf64_Rela[] array = ReadClassArray<Elf64_Rela>(addr, (long)d_un / 24L);
			foreach (Elf64_Rela elf64_Rela in array)
			{
				ulong num = elf64_Rela.r_info & 0xFFFFFFFFu;
				ulong num2 = elf64_Rela.r_info >> 32;
				switch (num)
				{
				case 257uL:
				{
					Elf64_Sym elf64_Sym = symbolTable[num2];
					base.Position = MapVATR(elf64_Rela.r_offset);
					Write(elf64_Sym.st_value + (ulong)elf64_Rela.r_addend);
					break;
				}
				case 1027uL:
					base.Position = MapVATR(elf64_Rela.r_offset);
					Write(elf64_Rela.r_addend);
					break;
				}
			}
		}
		catch
		{
		}
	}

	private bool CheckProtection()
	{
		if (dynamicSection.Any((Elf64_Dyn x) => x.d_tag == 12))
		{
			reportProgressAction("WARNING: find .init_proc");
			return true;
		}
		ulong num = MapVATR(dynamicSection.First((Elf64_Dyn x) => x.d_tag == 5).d_un);
		Elf64_Sym[] array = symbolTable;
		foreach (Elf64_Sym elf64_Sym in array)
		{
			if (ReadStringToNull(num + elf64_Sym.st_name) == "JNI_OnLoad")
			{
				reportProgressAction("WARNING: find JNI_OnLoad");
				return true;
			}
		}
		if (sectionTable != null && sectionTable.Any((Elf64_Shdr x) => x.sh_type == 2147483648u))
		{
			reportProgressAction("WARNING: find SHT_LOUSER section");
			return true;
		}
		return false;
	}

	public override ulong GetRVA(ulong pointer)
	{
		if (IsDumped)
		{
			return pointer - DumpAddr;
		}
		return pointer;
	}

	private void FixedProgramSegment()
	{
		for (uint num = 0u; num < programSegment.Length; num++)
		{
			base.Position = elfHeader.e_phoff + num * 56 + 8;
			Elf64_Phdr elf64_Phdr = programSegment[num];
			elf64_Phdr.p_offset = elf64_Phdr.p_vaddr;
			Write(elf64_Phdr.p_offset);
			elf64_Phdr.p_vaddr += DumpAddr;
			Write(elf64_Phdr.p_vaddr);
			base.Position += 8uL;
			elf64_Phdr.p_filesz = elf64_Phdr.p_memsz;
			Write(elf64_Phdr.p_filesz);
		}
	}

	private void FixedDynamicSection()
	{
		for (uint num = 0u; num < dynamicSection.Length; num++)
		{
			base.Position = pt_dynamic.p_offset + num * 16 + 8;
			Elf64_Dyn elf64_Dyn = dynamicSection[num];
			long d_tag = elf64_Dyn.d_tag;
			long num2 = d_tag - 3;
			if ((ulong)num2 <= 14uL)
			{
				switch (num2)
				{
				case 0L:
				case 1L:
				case 2L:
				case 3L:
				case 4L:
				case 9L:
				case 10L:
				case 14L:
					goto IL_008f;
				case 5L:
				case 6L:
				case 7L:
				case 8L:
				case 11L:
				case 12L:
				case 13L:
					continue;
				}
			}
			if (d_tag != 23 && (ulong)(d_tag - 25) > 1uL)
			{
				continue;
			}
			goto IL_008f;
			IL_008f:
			elf64_Dyn.d_un += DumpAddr;
			Write(elf64_Dyn.d_un);
		}
	}
}
public abstract class ElfBase : Il2Cpp
{
	public bool IsDumped;

	public ulong DumpAddr;

	protected ElfBase(Stream stream, Action<string> reportProgressAction)
		: base(stream, reportProgressAction)
	{
	}

	public void GetDumpAddress()
	{
		reportProgressAction("Detected this may be a dump file.");
		reportProgressAction("Forcing continuation...");
	}
}
public class Elf32_Ehdr
{
	public uint ei_mag;

	public byte ei_class;

	public byte ei_data;

	public byte ei_version;

	public byte ei_osabi;

	public byte ei_abiversion;

	[ArrayLength(Length = 7)]
	public byte[] ei_pad;

	public ushort e_type;

	public ushort e_machine;

	public uint e_version;

	public uint e_entry;

	public uint e_phoff;

	public uint e_shoff;

	public uint e_flags;

	public ushort e_ehsize;

	public ushort e_phentsize;

	public ushort e_phnum;

	public ushort e_shentsize;

	public ushort e_shnum;

	public ushort e_shstrndx;
}
public class Elf32_Phdr
{
	public uint p_type;

	public uint p_offset;

	public uint p_vaddr;

	public uint p_paddr;

	public uint p_filesz;

	public uint p_memsz;

	public uint p_flags;

	public uint p_align;
}
public class Elf32_Shdr
{
	public uint sh_name;

	public uint sh_type;

	public uint sh_flags;

	public uint sh_addr;

	public uint sh_offset;

	public uint sh_size;

	public uint sh_link;

	public uint sh_info;

	public uint sh_addralign;

	public uint sh_entsize;
}
public class Elf32_Sym
{
	public uint st_name;

	public uint st_value;

	public uint st_size;

	public byte st_info;

	public byte st_other;

	public ushort st_shndx;
}
public class Elf32_Dyn
{
	public int d_tag;

	public uint d_un;
}
public class Elf32_Rel
{
	public uint r_offset;

	public uint r_info;
}
public class Elf64_Ehdr
{
	public uint ei_mag;

	public byte ei_class;

	public byte ei_data;

	public byte ei_version;

	public byte ei_osabi;

	public byte ei_abiversion;

	[ArrayLength(Length = 7)]
	public byte[] ei_pad;

	public ushort e_type;

	public ushort e_machine;

	public uint e_version;

	public ulong e_entry;

	public ulong e_phoff;

	public ulong e_shoff;

	public uint e_flags;

	public ushort e_ehsize;

	public ushort e_phentsize;

	public ushort e_phnum;

	public ushort e_shentsize;

	public ushort e_shnum;

	public ushort e_shstrndx;
}
public class Elf64_Phdr
{
	public uint p_type;

	public uint p_flags;

	public ulong p_offset;

	public ulong p_vaddr;

	public ulong p_paddr;

	public ulong p_filesz;

	public ulong p_memsz;

	public ulong p_align;
}
public class Elf64_Shdr
{
	public uint sh_name;

	public uint sh_type;

	public ulong sh_flags;

	public ulong sh_addr;

	public ulong sh_offset;

	public ulong sh_size;

	public uint sh_link;

	public uint sh_info;

	public ulong sh_addralign;

	public ulong sh_entsize;
}
public class Elf64_Sym
{
	public uint st_name;

	public byte st_info;

	public byte st_other;

	public ushort st_shndx;

	public ulong st_value;

	public ulong st_size;
}
public class Elf64_Dyn
{
	public long d_tag;

	public ulong d_un;
}
public class Elf64_Rela
{
	public ulong r_offset;

	public ulong r_info;

	public long r_addend;
}
public static class ElfConstants
{
	public const int EM_386 = 3;

	public const int EM_ARM = 40;

	public const int PT_LOAD = 1;

	public const int PT_DYNAMIC = 2;

	public const int PF_X = 1;

	public const int DT_PLTGOT = 3;

	public const int DT_HASH = 4;

	public const int DT_STRTAB = 5;

	public const int DT_SYMTAB = 6;

	public const int DT_RELA = 7;

	public const int DT_RELASZ = 8;

	public const int DT_INIT = 12;

	public const int DT_FINI = 13;

	public const int DT_REL = 17;

	public const int DT_RELSZ = 18;

	public const int DT_JMPREL = 23;

	public const int DT_INIT_ARRAY = 25;

	public const int DT_FINI_ARRAY = 26;

	public const uint SHT_LOUSER = 2147483648u;

	public const int R_ARM_ABS32 = 2;

	public const int R_386_32 = 1;

	public const int R_AARCH64_ABS64 = 257;

	public const int R_AARCH64_RELATIVE = 1027;
}
public sealed class Macho : Il2Cpp
{
	private List<MachoSection> sections = new List<MachoSection>();

	private static readonly byte[] FeatureBytes1 = new byte[2] { 0, 34 };

	private static readonly byte[] FeatureBytes2 = new byte[4] { 120, 68, 121, 68 };

	private ulong vmaddr;

	public Macho(Stream stream, Action<string> reportProgressAction)
		: base(stream, reportProgressAction)
	{
		Is32Bit = true;
		base.Position += 16uL;
		uint num = ReadUInt32();
		base.Position += 8uL;
		for (int i = 0; i < num; i++)
		{
			ulong position = base.Position;
			uint num2 = ReadUInt32();
			uint num3 = ReadUInt32();
			switch (num2)
			{
			case 1u:
			{
				if (Encoding.UTF8.GetString(ReadBytes(16)).TrimEnd(new char[1]) == "__TEXT")
				{
					vmaddr = ReadUInt32();
				}
				else
				{
					base.Position += 4uL;
				}
				base.Position += 20uL;
				uint num4 = ReadUInt32();
				base.Position += 4uL;
				for (int j = 0; j < num4; j++)
				{
					MachoSection machoSection = new MachoSection();
					sections.Add(machoSection);
					machoSection.sectname = Encoding.UTF8.GetString(ReadBytes(16)).TrimEnd(new char[1]);
					base.Position += 16uL;
					machoSection.addr = ReadUInt32();
					machoSection.size = ReadUInt32();
					machoSection.offset = ReadUInt32();
					base.Position += 12uL;
					machoSection.flags = ReadUInt32();
					base.Position += 8uL;
				}
				break;
			}
			case 33u:
				base.Position += 8uL;
				if (ReadUInt32() != 0)
				{
					reportProgressAction("ERROR: This Mach-O executable is encrypted and cannot be processed.");
				}
				break;
			}
			base.Position = position + num3;
		}
	}

	public override void Init(ulong codeRegistration, ulong metadataRegistration)
	{
		base.Init(codeRegistration, metadataRegistration);
		methodPointers = methodPointers.Select((ulong x) => x - 1).ToArray();
		customAttributeGenerators = customAttributeGenerators.Select((ulong x) => x - 1).ToArray();
	}

	public override ulong MapVATR(ulong addr)
	{
		MachoSection machoSection = sections.First((MachoSection x) => addr >= x.addr && addr <= x.addr + x.size);
		return addr - machoSection.addr + machoSection.offset;
	}

	public override ulong MapRTVA(ulong addr)
	{
		MachoSection machoSection = sections.FirstOrDefault((MachoSection x) => addr >= x.offset && addr <= x.offset + x.size);
		if (machoSection == null)
		{
			return 0uL;
		}
		return addr - machoSection.offset + machoSection.addr;
	}

	public override bool Search()
	{
		uint[] array;
		if (Version < 21.0)
		{
			MachoSection machoSection = sections.First((MachoSection x) => x.sectname == "__mod_init_func");
			array = ReadClassArray<uint>(machoSection.offset, machoSection.size / 4);
			foreach (uint num in array)
			{
				if (num == 0)
				{
					continue;
				}
				uint num2 = num - 1;
				base.Position = MapVATR(num2);
				base.Position += 4uL;
				byte[] second = ReadBytes(2);
				if (FeatureBytes1.SequenceEqual(second))
				{
					base.Position += 12uL;
					second = ReadBytes(4);
					if (FeatureBytes2.SequenceEqual(second))
					{
						base.Position = MapVATR(num2) + 10;
						uint num3 = ArmUtils.DecodeMov(ReadBytes(8)) + num2 + 24 - 1;
						ulong num5 = (base.Position = MapVATR(num3));
						uint num6 = ArmUtils.DecodeMov(ReadBytes(8)) + num3 + 16;
						base.Position = MapVATR(num6);
						uint num7 = ReadUInt32();
						base.Position = num5 + 8;
						second = ReadBytes(4);
						base.Position = num5 + 14;
						second = second.Concat(ReadBytes(4)).ToArray();
						uint num8 = ArmUtils.DecodeMov(second) + num3 + 22;
						reportProgressAction($"CodeRegistration : {num8:x}");
						reportProgressAction($"MetadataRegistration : {num7:x}");
						Init(num8, num7);
						return true;
					}
				}
			}
			return false;
		}
		MachoSection machoSection2 = sections.First((MachoSection x) => x.sectname == "__mod_init_func");
		array = ReadClassArray<uint>(machoSection2.offset, machoSection2.size / 4);
		foreach (uint num9 in array)
		{
			if (num9 == 0)
			{
				continue;
			}
			uint num10 = num9 - 1;
			base.Position = MapVATR(num10);
			base.Position += 4uL;
			byte[] second2 = ReadBytes(2);
			if (FeatureBytes1.SequenceEqual(second2))
			{
				base.Position += 12uL;
				second2 = ReadBytes(4);
				if (FeatureBytes2.SequenceEqual(second2))
				{
					base.Position = MapVATR(num10) + 10;
					uint num11 = ArmUtils.DecodeMov(ReadBytes(8)) + num10 + 24 - 1;
					ulong num13 = (base.Position = MapVATR(num11));
					uint num14 = ArmUtils.DecodeMov(ReadBytes(8)) + num11 + 16;
					base.Position = MapVATR(num14);
					uint num15 = ReadUInt32();
					base.Position = num13 + 8;
					second2 = ReadBytes(4);
					base.Position = num13 + 14;
					second2 = second2.Concat(ReadBytes(4)).ToArray();
					uint num16 = ArmUtils.DecodeMov(second2) + num11 + 26;
					reportProgressAction($"CodeRegistration : {num16:x}");
					reportProgressAction($"MetadataRegistration : {num15:x}");
					Init(num16, num15);
					return true;
				}
			}
		}
		return false;
	}

	public override bool PlusSearch(int methodCount, int typeDefinitionsCount, int imageCount)
	{
		MachoSection[] array = sections.Where((MachoSection x) => x.sectname == "__const").ToArray();
		MachoSection[] array2 = sections.Where((MachoSection x) => x.flags == 2147484672u).ToArray();
		MachoSection[] array3 = sections.Where((MachoSection x) => x.flags == 1).ToArray();
		PlusSearch plusSearch = new PlusSearch(this, methodCount, typeDefinitionsCount, maxMetadataUsages, imageCount);
		plusSearch.SetSection(SearchSectionType.Exec, array2);
		plusSearch.SetSection(SearchSectionType.Data, array);
		plusSearch.SetSection(SearchSectionType.Bss, array3);
		ulong codeRegistration = plusSearch.FindCodeRegistration();
		ulong metadataRegistration = plusSearch.FindMetadataRegistration();
		return AutoPlusInit(codeRegistration, metadataRegistration);
	}

	public override bool SymbolSearch()
	{
		return false;
	}

	public override ulong GetRVA(ulong pointer)
	{
		return pointer - vmaddr;
	}
}
public sealed class Macho64 : Il2Cpp
{
	private List<MachoSection64Bit> sections = new List<MachoSection64Bit>();

	private static readonly byte[] FeatureBytes1 = new byte[4] { 2, 0, 128, 210 };

	private static readonly byte[] FeatureBytes2 = new byte[4] { 3, 0, 128, 82 };

	private ulong vmaddr;

	public Macho64(Stream stream, Action<string> reportProgressAction)
		: base(stream, reportProgressAction)
	{
		base.Position += 16uL;
		uint num = ReadUInt32();
		base.Position += 12uL;
		for (int i = 0; i < num; i++)
		{
			ulong position = base.Position;
			uint num2 = ReadUInt32();
			uint num3 = ReadUInt32();
			switch (num2)
			{
			case 25u:
			{
				if (Encoding.UTF8.GetString(ReadBytes(16)).TrimEnd(new char[1]) == "__TEXT")
				{
					vmaddr = ReadUInt64();
				}
				else
				{
					base.Position += 8uL;
				}
				base.Position += 32uL;
				uint num4 = ReadUInt32();
				base.Position += 4uL;
				for (int j = 0; j < num4; j++)
				{
					MachoSection64Bit machoSection64Bit = new MachoSection64Bit();
					sections.Add(machoSection64Bit);
					machoSection64Bit.sectname = Encoding.UTF8.GetString(ReadBytes(16)).TrimEnd(new char[1]);
					base.Position += 16uL;
					machoSection64Bit.addr = ReadUInt64();
					machoSection64Bit.size = ReadUInt64();
					machoSection64Bit.offset = ReadUInt32();
					base.Position += 12uL;
					machoSection64Bit.flags = ReadUInt32();
					base.Position += 12uL;
				}
				break;
			}
			case 44u:
				base.Position += 8uL;
				if (ReadUInt32() != 0)
				{
					reportProgressAction("ERROR: This Mach-O executable is encrypted and cannot be processed.");
				}
				break;
			}
			base.Position = position + num3;
		}
	}

	public override ulong MapVATR(ulong addr)
	{
		MachoSection64Bit machoSection64Bit = sections.First((MachoSection64Bit x) => addr >= x.addr && addr <= x.addr + x.size);
		if (machoSection64Bit.sectname == "__bss")
		{
			throw new Exception();
		}
		return addr - machoSection64Bit.addr + machoSection64Bit.offset;
	}

	public override ulong MapRTVA(ulong addr)
	{
		MachoSection64Bit machoSection64Bit = sections.FirstOrDefault((MachoSection64Bit x) => addr >= x.offset && addr <= x.offset + x.size);
		if (machoSection64Bit == null)
		{
			return 0uL;
		}
		if (machoSection64Bit.sectname == "__bss")
		{
			throw new Exception();
		}
		return addr - machoSection64Bit.offset + machoSection64Bit.addr;
	}

	public override bool Search()
	{
		ulong num = 0uL;
		ulong num2 = 0uL;
		if (Version < 23.0)
		{
			MachoSection64Bit machoSection64Bit = sections.First((MachoSection64Bit x) => x.sectname == "__mod_init_func");
			ulong[] array = ReadClassArray<ulong>(machoSection64Bit.offset, (long)machoSection64Bit.size / 8L);
			foreach (ulong num3 in array)
			{
				if (num3 == 0)
				{
					continue;
				}
				bool flag = false;
				ulong num4 = 0uL;
				base.Position = MapVATR(num3);
				byte[] second = ReadBytes(4);
				if (FeatureBytes1.SequenceEqual(second))
				{
					second = ReadBytes(4);
					if (FeatureBytes2.SequenceEqual(second))
					{
						base.Position += 8uL;
						byte[] inst = ReadBytes(4);
						if (ArmUtils.IsAdr(inst))
						{
							num4 = ArmUtils.DecodeAdr(num3 + 16, inst);
							flag = true;
						}
					}
				}
				else
				{
					base.Position += 12uL;
					second = ReadBytes(4);
					if (FeatureBytes2.SequenceEqual(second))
					{
						second = ReadBytes(4);
						if (FeatureBytes1.SequenceEqual(second))
						{
							base.Position -= 16uL;
							byte[] inst2 = ReadBytes(4);
							if (ArmUtils.IsAdr(inst2))
							{
								num4 = ArmUtils.DecodeAdr(num3 + 8, inst2);
								flag = true;
							}
						}
					}
				}
				if (flag)
				{
					ulong num6 = (base.Position = MapVATR(num4));
					num = ArmUtils.DecodeAdrp(num4, ReadBytes(4));
					num += ArmUtils.DecodeAdd(ReadBytes(4));
					base.Position = num6 + 8;
					num2 = ArmUtils.DecodeAdrp(num4 + 8, ReadBytes(4));
					num2 += ArmUtils.DecodeAdd(ReadBytes(4));
				}
			}
		}
		if (Version == 23.0)
		{
			MachoSection64Bit machoSection64Bit2 = sections.First((MachoSection64Bit x) => x.sectname == "__mod_init_func");
			ulong[] array = ReadClassArray<ulong>(machoSection64Bit2.offset, (long)machoSection64Bit2.size / 8L);
			foreach (ulong num7 in array)
			{
				if (num7 == 0)
				{
					continue;
				}
				base.Position = MapVATR(num7) + 16;
				byte[] second2 = ReadBytes(4);
				if (FeatureBytes1.SequenceEqual(second2))
				{
					second2 = ReadBytes(4);
					if (FeatureBytes2.SequenceEqual(second2))
					{
						base.Position -= 16uL;
						ulong num8 = ArmUtils.DecodeAdr(num7 + 8, ReadBytes(4));
						ulong num10 = (base.Position = MapVATR(num8));
						num = ArmUtils.DecodeAdrp(num8, ReadBytes(4));
						num += ArmUtils.DecodeAdd(ReadBytes(4));
						base.Position = num10 + 8;
						num2 = ArmUtils.DecodeAdrp(num8 + 8, ReadBytes(4));
						num2 += ArmUtils.DecodeAdd(ReadBytes(4));
					}
				}
			}
		}
		if (Version >= 24.0)
		{
			MachoSection64Bit machoSection64Bit3 = sections.First((MachoSection64Bit x) => x.sectname == "__mod_init_func");
			ulong[] array = ReadClassArray<ulong>(machoSection64Bit3.offset, (long)machoSection64Bit3.size / 8L);
			foreach (ulong num11 in array)
			{
				if (num11 == 0)
				{
					continue;
				}
				base.Position = MapVATR(num11) + 16;
				byte[] second3 = ReadBytes(4);
				if (FeatureBytes2.SequenceEqual(second3))
				{
					second3 = ReadBytes(4);
					if (FeatureBytes1.SequenceEqual(second3))
					{
						base.Position -= 16uL;
						ulong num12 = ArmUtils.DecodeAdr(num11 + 8, ReadBytes(4));
						ulong num14 = (base.Position = MapVATR(num12));
						num = ArmUtils.DecodeAdrp(num12, ReadBytes(4));
						num += ArmUtils.DecodeAdd(ReadBytes(4));
						base.Position = num14 + 8;
						num2 = ArmUtils.DecodeAdrp(num12 + 8, ReadBytes(4));
						num2 += ArmUtils.DecodeAdd(ReadBytes(4));
					}
				}
			}
		}
		if (num != 0L && num2 != 0L)
		{
			reportProgressAction($"CodeRegistration : {num:x}");
			reportProgressAction($"MetadataRegistration : {num2:x}");
			Init(num, num2);
			return true;
		}
		return false;
	}

	public override bool PlusSearch(int methodCount, int typeDefinitionsCount, int imageCount)
	{
		MachoSection64Bit[] array = sections.Where((MachoSection64Bit x) => x.sectname == "__const" || x.sectname == "__cstring" || x.sectname == "__data").ToArray();
		MachoSection64Bit[] array2 = sections.Where((MachoSection64Bit x) => x.flags == 2147484672u).ToArray();
		MachoSection64Bit[] array3 = sections.Where((MachoSection64Bit x) => x.flags == 1).ToArray();
		PlusSearch plusSearch = new PlusSearch(this, methodCount, typeDefinitionsCount, maxMetadataUsages, imageCount);
		plusSearch.SetSection(SearchSectionType.Exec, array2);
		plusSearch.SetSection(SearchSectionType.Data, array);
		plusSearch.SetSection(SearchSectionType.Bss, array3);
		ulong codeRegistration = plusSearch.FindCodeRegistration();
		ulong metadataRegistration = plusSearch.FindMetadataRegistration();
		return AutoPlusInit(codeRegistration, metadataRegistration);
	}

	public override bool SymbolSearch()
	{
		return false;
	}

	public override ulong GetRVA(ulong pointer)
	{
		return pointer - vmaddr;
	}
}
public class MachoSection
{
	public string sectname;

	public uint addr;

	public uint size;

	public uint offset;

	public uint flags;
}
public class MachoSection64Bit
{
	public string sectname;

	public ulong addr;

	public ulong size;

	public ulong offset;

	public uint flags;
}
public class Fat
{
	public uint offset;

	public uint size;

	public uint magic;
}
public sealed class MachoFat : BinaryStream
{
	public Fat[] fats;

	public MachoFat(Stream stream)
		: base(stream)
	{
		base.Position += 4uL;
		int num = BitConverter.ToInt32(ReadBytes(4).Reverse().ToArray(), 0);
		fats = new Fat[num];
		for (int i = 0; i < num; i++)
		{
			base.Position += 8uL;
			fats[i] = new Fat();
			fats[i].offset = BitConverter.ToUInt32(ReadBytes(4).Reverse().ToArray(), 0);
			fats[i].size = BitConverter.ToUInt32(ReadBytes(4).Reverse().ToArray(), 0);
			base.Position += 4uL;
		}
		for (int j = 0; j < num; j++)
		{
			base.Position = fats[j].offset;
			fats[j].magic = ReadUInt32();
		}
	}

	public byte[] GetMacho(int index)
	{
		base.Position = fats[index].offset;
		return ReadBytes((int)fats[index].size);
	}
}
public sealed class NSO : Il2Cpp
{
	private NSOHeader header;

	private bool isTextCompressed;

	private bool isRoDataCompressed;

	private bool isDataCompressed;

	private List<NSOSegmentHeader> segments = new List<NSOSegmentHeader>();

	private bool isCompressed
	{
		get
		{
			if (!isTextCompressed && !isRoDataCompressed)
			{
				return isDataCompressed;
			}
			return true;
		}
	}

	public NSO(Stream stream, Action<string> reportProgressAction)
		: base(stream, reportProgressAction)
	{
		header = new NSOHeader();
		header.Magic = ReadUInt32();
		header.Version = ReadUInt32();
		header.Reserved = ReadUInt32();
		header.Flags = ReadUInt32();
		isTextCompressed = (header.Flags & 1) != 0;
		isRoDataCompressed = (header.Flags & 2) != 0;
		isDataCompressed = (header.Flags & 4) != 0;
		header.TextSegment = new NSOSegmentHeader
		{
			FileOffset = ReadUInt32(),
			MemoryOffset = ReadUInt32(),
			DecompressedSize = ReadUInt32()
		};
		segments.Add(header.TextSegment);
		header.ModuleOffset = ReadUInt32();
		header.RoDataSegment = new NSOSegmentHeader
		{
			FileOffset = ReadUInt32(),
			MemoryOffset = ReadUInt32(),
			DecompressedSize = ReadUInt32()
		};
		segments.Add(header.RoDataSegment);
		header.ModuleFileSize = ReadUInt32();
		header.DataSegment = new NSOSegmentHeader
		{
			FileOffset = ReadUInt32(),
			MemoryOffset = ReadUInt32(),
			DecompressedSize = ReadUInt32()
		};
		segments.Add(header.DataSegment);
		header.BssSize = ReadUInt32();
		header.DigestBuildID = ReadBytes(32);
		header.TextCompressedSize = ReadUInt32();
		header.RoDataCompressedSize = ReadUInt32();
		header.DataCompressedSize = ReadUInt32();
		header.Padding = ReadBytes(28);
		header.APIInfo = new NSORelativeExtent
		{
			RegionRoDataOffset = ReadUInt32(),
			RegionSize = ReadUInt32()
		};
		header.DynStr = new NSORelativeExtent
		{
			RegionRoDataOffset = ReadUInt32(),
			RegionSize = ReadUInt32()
		};
		header.DynSym = new NSORelativeExtent
		{
			RegionRoDataOffset = ReadUInt32(),
			RegionSize = ReadUInt32()
		};
		header.TextHash = ReadBytes(32);
		header.RoDataHash = ReadBytes(32);
		header.DataHash = ReadBytes(32);
		if (!isCompressed)
		{
			base.Position = header.TextSegment.FileOffset + 4;
			uint num = ReadUInt32();
			base.Position = header.TextSegment.FileOffset + num + 8;
			uint num2 = ReadUInt32();
			uint num3 = ReadUInt32();
			header.BssSegment = new NSOSegmentHeader
			{
				FileOffset = num2,
				MemoryOffset = num2,
				DecompressedSize = num3 - num2
			};
		}
	}

	public override ulong MapVATR(ulong addr)
	{
		NSOSegmentHeader nSOSegmentHeader = segments.First((NSOSegmentHeader x) => addr >= x.MemoryOffset && addr <= x.MemoryOffset + x.DecompressedSize);
		return addr - nSOSegmentHeader.MemoryOffset + nSOSegmentHeader.FileOffset;
	}

	public override ulong MapRTVA(ulong addr)
	{
		NSOSegmentHeader nSOSegmentHeader = segments.FirstOrDefault((NSOSegmentHeader x) => addr >= x.FileOffset && addr <= x.FileOffset + x.DecompressedSize);
		if (nSOSegmentHeader == null)
		{
			return 0uL;
		}
		return addr - nSOSegmentHeader.FileOffset + nSOSegmentHeader.MemoryOffset;
	}

	public override bool Search()
	{
		return false;
	}

	public override bool PlusSearch(int methodCount, int typeDefinitionsCount, int imageCount)
	{
		PlusSearch plusSearch = new PlusSearch(this, methodCount, typeDefinitionsCount, maxMetadataUsages, imageCount);
		plusSearch.SetSection(SearchSectionType.Exec, header.TextSegment);
		plusSearch.SetSection(SearchSectionType.Data, header.DataSegment, header.RoDataSegment);
		plusSearch.SetSection(SearchSectionType.Bss, header.BssSegment);
		ulong codeRegistration = plusSearch.FindCodeRegistration();
		ulong metadataRegistration = plusSearch.FindMetadataRegistration();
		return AutoPlusInit(codeRegistration, metadataRegistration);
	}

	public override bool SymbolSearch()
	{
		return false;
	}

	public NSO UnCompress()
	{
		if (isTextCompressed || isRoDataCompressed || isDataCompressed)
		{
			MemoryStream memoryStream = new MemoryStream();
			BinaryWriter binaryWriter = new BinaryWriter(memoryStream);
			binaryWriter.Write(header.Magic);
			binaryWriter.Write(header.Version);
			binaryWriter.Write(header.Reserved);
			binaryWriter.Write(0);
			binaryWriter.Write(header.TextSegment.FileOffset);
			binaryWriter.Write(header.TextSegment.MemoryOffset);
			binaryWriter.Write(header.TextSegment.DecompressedSize);
			binaryWriter.Write(header.ModuleOffset);
			uint num = header.TextSegment.FileOffset + header.TextSegment.DecompressedSize;
			binaryWriter.Write(num);
			binaryWriter.Write(header.RoDataSegment.MemoryOffset);
			binaryWriter.Write(header.RoDataSegment.DecompressedSize);
			binaryWriter.Write(header.ModuleFileSize);
			binaryWriter.Write(num + header.RoDataSegment.DecompressedSize);
			binaryWriter.Write(header.DataSegment.MemoryOffset);
			binaryWriter.Write(header.DataSegment.DecompressedSize);
			binaryWriter.Write(header.BssSize);
			binaryWriter.Write(header.DigestBuildID);
			binaryWriter.Write(header.TextCompressedSize);
			binaryWriter.Write(header.RoDataCompressedSize);
			binaryWriter.Write(header.DataCompressedSize);
			binaryWriter.Write(header.Padding);
			binaryWriter.Write(header.APIInfo.RegionRoDataOffset);
			binaryWriter.Write(header.APIInfo.RegionSize);
			binaryWriter.Write(header.DynStr.RegionRoDataOffset);
			binaryWriter.Write(header.DynStr.RegionSize);
			binaryWriter.Write(header.DynSym.RegionRoDataOffset);
			binaryWriter.Write(header.DynSym.RegionSize);
			binaryWriter.Write(header.TextHash);
			binaryWriter.Write(header.RoDataHash);
			binaryWriter.Write(header.DataHash);
			binaryWriter.BaseStream.Position = header.TextSegment.FileOffset;
			base.Position = header.TextSegment.FileOffset;
			byte[] buffer = ReadBytes((int)header.TextCompressedSize);
			if (isTextCompressed)
			{
				byte[] array = new byte[header.TextSegment.DecompressedSize];
				using (Lz4DecoderStream lz4DecoderStream = new Lz4DecoderStream(new MemoryStream(buffer)))
				{
					lz4DecoderStream.Read(array, 0, array.Length);
				}
				binaryWriter.Write(array);
			}
			else
			{
				binaryWriter.Write(buffer);
			}
			byte[] buffer2 = ReadBytes((int)header.RoDataCompressedSize);
			if (isRoDataCompressed)
			{
				byte[] array2 = new byte[header.RoDataSegment.DecompressedSize];
				using (Lz4DecoderStream lz4DecoderStream2 = new Lz4DecoderStream(new MemoryStream(buffer2)))
				{
					lz4DecoderStream2.Read(array2, 0, array2.Length);
				}
				binaryWriter.Write(array2);
			}
			else
			{
				binaryWriter.Write(buffer2);
			}
			byte[] buffer3 = ReadBytes((int)header.DataCompressedSize);
			if (isDataCompressed)
			{
				byte[] array3 = new byte[header.DataSegment.DecompressedSize];
				using (Lz4DecoderStream lz4DecoderStream3 = new Lz4DecoderStream(new MemoryStream(buffer3)))
				{
					lz4DecoderStream3.Read(array3, 0, array3.Length);
				}
				binaryWriter.Write(array3);
			}
			else
			{
				binaryWriter.Write(buffer3);
			}
			binaryWriter.Flush();
			memoryStream.Position = 0L;
			return new NSO(memoryStream, reportProgressAction);
		}
		return this;
	}
}
public class NSOHeader
{
	public uint Magic;

	public uint Version;

	public uint Reserved;

	public uint Flags;

	public NSOSegmentHeader TextSegment;

	public uint ModuleOffset;

	public NSOSegmentHeader RoDataSegment;

	public uint ModuleFileSize;

	public NSOSegmentHeader DataSegment;

	public uint BssSize;

	public byte[] DigestBuildID;

	public uint TextCompressedSize;

	public uint RoDataCompressedSize;

	public uint DataCompressedSize;

	public byte[] Padding;

	public NSORelativeExtent APIInfo;

	public NSORelativeExtent DynStr;

	public NSORelativeExtent DynSym;

	public byte[] TextHash;

	public byte[] RoDataHash;

	public byte[] DataHash;

	public NSOSegmentHeader BssSegment;
}
public class NSOSegmentHeader
{
	public uint FileOffset;

	public uint MemoryOffset;

	public uint DecompressedSize;
}
public class NSORelativeExtent
{
	public uint RegionRoDataOffset;

	public uint RegionSize;
}
public sealed class PE : Il2Cpp
{
	private SectionHeader[] sections;

	private ulong imageBase;

	public PE(Stream stream, Action<string> reportProgressAction)
		: base(stream, reportProgressAction)
	{
		DosHeader dosHeader = ReadClass<DosHeader>();
		if (dosHeader.Magic != 23117)
		{
			throw new InvalidDataException("ERROR: Invalid PE file");
		}
		base.Position = dosHeader.Lfanew;
		if (ReadUInt32() != 17744)
		{
			throw new InvalidDataException("ERROR: Invalid PE file");
		}
		FileHeader fileHeader = ReadClass<FileHeader>();
		ulong position = base.Position;
		ushort num = ReadUInt16();
		base.Position -= 2uL;
		switch (num)
		{
		case 267:
		{
			Is32Bit = true;
			OptionalHeader optionalHeader2 = ReadClass<OptionalHeader>();
			imageBase = optionalHeader2.ImageBase;
			break;
		}
		case 523:
		{
			OptionalHeader64 optionalHeader = ReadClass<OptionalHeader64>();
			imageBase = optionalHeader.ImageBase;
			break;
		}
		default:
			throw new NotSupportedException($"Invalid Optional header magic {num}");
		}
		base.Position = position + fileHeader.SizeOfOptionalHeader;
		sections = ReadClassArray<SectionHeader>(fileHeader.NumberOfSections);
	}

	public void LoadFromMemory(ulong addr)
	{
		imageBase = addr;
		SectionHeader[] array = sections;
		foreach (SectionHeader obj in array)
		{
			obj.PointerToRawData = obj.VirtualAddress;
			obj.SizeOfRawData = obj.VirtualSize;
		}
	}

	public override ulong MapVATR(ulong absAddr)
	{
		ulong addr = absAddr - imageBase;
		SectionHeader sectionHeader = sections.FirstOrDefault((SectionHeader x) => addr >= x.VirtualAddress && addr <= x.VirtualAddress + x.VirtualSize);
		if (sectionHeader == null)
		{
			return 0uL;
		}
		return addr - sectionHeader.VirtualAddress + sectionHeader.PointerToRawData;
	}

	public override ulong MapRTVA(ulong addr)
	{
		SectionHeader sectionHeader = sections.FirstOrDefault((SectionHeader x) => addr >= x.PointerToRawData && addr <= x.PointerToRawData + x.SizeOfRawData);
		if (sectionHeader == null)
		{
			return 0uL;
		}
		return addr - sectionHeader.PointerToRawData + sectionHeader.VirtualAddress + imageBase;
	}

	public override bool Search()
	{
		return false;
	}

	public override bool PlusSearch(int methodCount, int typeDefinitionsCount, int imageCount)
	{
		List<SectionHeader> list = new List<SectionHeader>();
		List<SectionHeader> list2 = new List<SectionHeader>();
		SectionHeader[] array = sections;
		foreach (SectionHeader sectionHeader in array)
		{
			switch (sectionHeader.Characteristics)
			{
			case 1610612768u:
				list.Add(sectionHeader);
				break;
			case 3221225536u:
			case 1073741888u:
				list2.Add(sectionHeader);
				break;
			}
		}
		PlusSearch plusSearch = new PlusSearch(this, methodCount, typeDefinitionsCount, maxMetadataUsages, imageCount);
		SectionHeader[] array2 = list2.ToArray();
		plusSearch.SetSection(sections: list.ToArray(), type: SearchSectionType.Exec, imageBase: imageBase);
		plusSearch.SetSection(SearchSectionType.Data, imageBase, array2);
		plusSearch.SetSection(SearchSectionType.Bss, imageBase, array2);
		ulong codeRegistration = plusSearch.FindCodeRegistration();
		ulong metadataRegistration = plusSearch.FindMetadataRegistration();
		return AutoPlusInit(codeRegistration, metadataRegistration);
	}

	public override bool SymbolSearch()
	{
		return false;
	}

	public override ulong GetRVA(ulong pointer)
	{
		return pointer - imageBase;
	}
}
public class DosHeader
{
	public ushort Magic;

	public ushort Cblp;

	public ushort Cp;

	public ushort Crlc;

	public ushort Cparhdr;

	public ushort Minalloc;

	public ushort Maxalloc;

	public ushort Ss;

	public ushort Sp;

	public ushort Csum;

	public ushort Ip;

	public ushort Cs;

	public ushort Lfarlc;

	public ushort Ovno;

	[ArrayLength(Length = 4)]
	public ushort[] Res;

	public ushort Oemid;

	public ushort Oeminfo;

	[ArrayLength(Length = 10)]
	public ushort[] Res2;

	public uint Lfanew;
}
public class FileHeader
{
	public ushort Machine;

	public ushort NumberOfSections;

	public uint TimeDateStamp;

	public uint PointerToSymbolTable;

	public uint NumberOfSymbols;

	public ushort SizeOfOptionalHeader;

	public ushort Characteristics;
}
public class OptionalHeader
{
	public ushort Magic;

	public byte MajorLinkerVersion;

	public byte MinorLinkerVersion;

	public uint SizeOfCode;

	public uint SizeOfInitializedData;

	public uint SizeOfUninitializedData;

	public uint AddressOfEntryPoint;

	public uint BaseOfCode;

	public uint BaseOfData;

	public uint ImageBase;

	public uint SectionAlignment;

	public uint FileAlignment;

	public ushort MajorOperatingSystemVersion;

	public ushort MinorOperatingSystemVersion;

	public ushort MajorImageVersion;

	public ushort MinorImageVersion;

	public ushort MajorSubsystemVersion;

	public ushort MinorSubsystemVersion;

	public uint Win32VersionValue;

	public uint SizeOfImage;

	public uint SizeOfHeaders;

	public uint CheckSum;

	public ushort Subsystem;

	public ushort DllCharacteristics;

	public uint SizeOfStackReserve;

	public uint SizeOfStackCommit;

	public uint SizeOfHeapReserve;

	public uint SizeOfHeapCommit;

	public uint LoaderFlags;

	public uint NumberOfRvaAndSizes;
}
public class OptionalHeader64
{
	public ushort Magic;

	public byte MajorLinkerVersion;

	public byte MinorLinkerVersion;

	public uint SizeOfCode;

	public uint SizeOfInitializedData;

	public uint SizeOfUninitializedData;

	public uint AddressOfEntryPoint;

	public uint BaseOfCode;

	public ulong ImageBase;

	public uint SectionAlignment;

	public uint FileAlignment;

	public ushort MajorOperatingSystemVersion;

	public ushort MinorOperatingSystemVersion;

	public ushort MajorImageVersion;

	public ushort MinorImageVersion;

	public ushort MajorSubsystemVersion;

	public ushort MinorSubsystemVersion;

	public uint Win32VersionValue;

	public uint SizeOfImage;

	public uint SizeOfHeaders;

	public uint CheckSum;

	public ushort Subsystem;

	public ushort DllCharacteristics;

	public ulong SizeOfStackReserve;

	public ulong SizeOfStackCommit;

	public ulong SizeOfHeapReserve;

	public ulong SizeOfHeapCommit;

	public uint LoaderFlags;

	public uint NumberOfRvaAndSizes;
}
public class SectionHeader
{
	[ArrayLength(Length = 8)]
	public byte[] Name;

	public uint VirtualSize;

	public uint VirtualAddress;

	public uint SizeOfRawData;

	public uint PointerToRawData;

	public uint PointerToRelocations;

	public uint PointerToLinenumbers;

	public ushort NumberOfRelocations;

	public ushort NumberOfLinenumbers;

	public uint Characteristics;
}
[Flags]
public enum SectionCharacteristics : uint
{
	IMAGE_SCN_MEM_EXECUTE = 0x20000000u,
	IMAGE_SCN_MEM_READ = 0x40000000u,
	IMAGE_SCN_MEM_WRITE = 0x80000000u
}
public sealed class WebAssembly : BinaryStream
{
	private DataSection[] dataSections;

	private Action<string> reportProgressAction;

	public WebAssembly(Stream stream, Action<string> reportProgressAction)
		: base(stream)
	{
		this.reportProgressAction = reportProgressAction;
		Is32Bit = true;
		ReadUInt32();
		ReadInt32();
		while (base.Position < base.Length)
		{
			uint num = ReadULeb128();
			uint num2 = ReadULeb128();
			if (num == 11)
			{
				uint num3 = ReadULeb128();
				dataSections = new DataSection[num3];
				for (int i = 0; i < num3; i++)
				{
					DataSection dataSection = new DataSection();
					dataSections[i] = dataSection;
					dataSection.Index = ReadULeb128();
					if (ReadByte() != 65)
					{
						throw new InvalidOperationException();
					}
					dataSection.Offset = ReadULeb128();
					if (ReadByte() != 11)
					{
						throw new InvalidOperationException();
					}
					dataSection.Data = ReadBytes((int)ReadULeb128());
				}
				break;
			}
			base.Position += num2;
		}
	}

	public WebAssemblyMemory CreateMemory()
	{
		DataSection dataSection = dataSections[dataSections.Length - 1];
		MemoryStream memoryStream = new MemoryStream((int)dataSection.Offset + dataSection.Data.Length);
		DataSection[] array = dataSections;
		foreach (DataSection dataSection2 in array)
		{
			memoryStream.Position = dataSection2.Offset;
			memoryStream.Write(dataSection2.Data, 0, dataSection2.Data.Length);
		}
		return new WebAssemblyMemory(memoryStream, Is32Bit, reportProgressAction);
	}
}
public class DataSection
{
	public uint Index;

	public uint Offset;

	public byte[] Data;
}
public sealed class WebAssemblyMemory : Il2Cpp
{
	public WebAssemblyMemory(Stream stream, bool is32Bit, Action<string> reportProgressAction)
		: base(stream, reportProgressAction)
	{
		Is32Bit = is32Bit;
	}

	public override ulong MapVATR(ulong addr)
	{
		return addr;
	}

	public override ulong MapRTVA(ulong addr)
	{
		return addr;
	}

	public override bool PlusSearch(int methodCount, int typeDefinitionsCount, int imageCount)
	{
		SearchSection searchSection = new SearchSection
		{
			offset = 0uL,
			offsetEnd = (ulong)methodCount,
			address = 0uL,
			addressEnd = (ulong)methodCount
		};
		SearchSection searchSection2 = new SearchSection
		{
			offset = 1024uL,
			offsetEnd = base.Length,
			address = 1024uL,
			addressEnd = base.Length
		};
		SearchSection searchSection3 = new SearchSection
		{
			offset = base.Length,
			offsetEnd = 9223372036854775807uL,
			address = base.Length,
			addressEnd = 9223372036854775807uL
		};
		PlusSearch plusSearch = new PlusSearch(this, methodCount, typeDefinitionsCount, maxMetadataUsages, imageCount);
		plusSearch.SetSection(SearchSectionType.Exec, searchSection);
		plusSearch.SetSection(SearchSectionType.Data, searchSection2);
		plusSearch.SetSection(SearchSectionType.Bss, searchSection3);
		ulong codeRegistration = plusSearch.FindCodeRegistration();
		ulong metadataRegistration = plusSearch.FindMetadataRegistration();
		return AutoPlusInit(codeRegistration, metadataRegistration);
	}

	public override bool Search()
	{
		return false;
	}

	public override bool SymbolSearch()
	{
		return false;
	}
}
internal static class BoyerMooreHorspool
{
	public static IEnumerable<int> Search(this byte[] source, byte[] pattern)
	{
		if (source == null)
		{
			throw new ArgumentNullException("source");
		}
		if (pattern == null)
		{
			throw new ArgumentNullException("pattern");
		}
		int valueLength = source.Length;
		int patternLength = pattern.Length;
		if (valueLength == 0 || patternLength == 0 || patternLength > valueLength)
		{
			yield break;
		}
		int[] badCharacters = new int[256];
		for (int i = 0; i < 256; i++)
		{
			badCharacters[i] = patternLength;
		}
		int lastPatternByte = patternLength - 1;
		for (int j = 0; j < lastPatternByte; j++)
		{
			badCharacters[pattern[j]] = lastPatternByte - j;
		}
		for (int index = 0; index <= valueLength - patternLength; index += badCharacters[source[index + lastPatternByte]])
		{
			int num = lastPatternByte;
			while (source[index + num] == pattern[num])
			{
				if (num == 0)
				{
					yield return index;
					break;
				}
				num--;
			}
		}
	}

	public static IEnumerable<int> Search(this byte[] source, string stringPattern)
	{
		if (source == null)
		{
			throw new ArgumentNullException("source");
		}
		if (stringPattern == null)
		{
			throw new ArgumentNullException("stringPattern");
		}
		string[] pattern = stringPattern.Split(new char[1] { ' ' });
		int valueLength = source.Length;
		int patternLength = pattern.Length;
		if (valueLength == 0 || patternLength == 0 || patternLength > valueLength)
		{
			yield break;
		}
		int[] badCharacters = new int[256];
		for (int i = 0; i < 256; i++)
		{
			badCharacters[i] = patternLength;
		}
		int lastPatternByte = patternLength - 1;
		for (int j = 0; j < lastPatternByte; j++)
		{
			if (pattern[j] != "?")
			{
				int num = Convert.ToInt32(pattern[j], 16);
				badCharacters[num] = lastPatternByte - j;
			}
		}
		for (int index = 0; index <= valueLength - patternLength; index += badCharacters[source[index + lastPatternByte]])
		{
			int num2 = lastPatternByte;
			while (CheckEqual(source, pattern, index, num2))
			{
				if (num2 == 0)
				{
					yield return index;
					break;
				}
				num2--;
			}
		}
	}

	private static bool CheckEqual(byte[] source, string[] pattern, int index, int i)
	{
		if (pattern[i] != "?")
		{
			int num = Convert.ToInt32(pattern[i], 16);
			return source[index + i] == num;
		}
		return true;
	}
}
internal static class HexExtensions
{
	public static string HexToBin(this byte b)
	{
		return Convert.ToString(b, 2).PadLeft(8, '0');
	}

	public static string HexToBin(this byte[] bytes)
	{
		StringBuilder stringBuilder = new StringBuilder(bytes.Length * 8);
		foreach (byte b in bytes)
		{
			stringBuilder.Insert(0, b.HexToBin());
		}
		return stringBuilder.ToString();
	}
}
public static class StringExtensions
{
	public static string ToEscapedString(this string s)
	{
		StringBuilder stringBuilder = new StringBuilder(s.Length);
		foreach (char c in s)
		{
			switch (c)
			{
			case '\'':
				stringBuilder.Append("\\'");
				break;
			case '"':
				stringBuilder.Append("\\\"");
				break;
			case '\\':
				stringBuilder.Append("\\\\");
				break;
			case '\0':
				stringBuilder.Append("\\0");
				break;
			case '\a':
				stringBuilder.Append("\\a");
				break;
			case '\b':
				stringBuilder.Append("\\b");
				break;
			case '\f':
				stringBuilder.Append("\\f");
				break;
			case '\n':
				stringBuilder.Append("\\n");
				break;
			case '\r':
				stringBuilder.Append("\\r");
				break;
			case '\t':
				stringBuilder.Append("\\t");
				break;
			case '\v':
				stringBuilder.Append("\\v");
				break;
			case '\u0085':
				stringBuilder.Append("\\u0085");
				break;
			case '\u2028':
				stringBuilder.Append("\\u2028");
				break;
			case '\u2029':
				stringBuilder.Append("\\u2029");
				break;
			default:
				stringBuilder.Append(c);
				break;
			}
		}
		return stringBuilder.ToString();
	}
}
public static class Il2CppDumper
{
	public static bool PerformDump(string gameAssemblyPath, string metadataDatPath, string outputDirectoryPath, Config config, Action<string> reportProgressAction)
	{
		Init(gameAssemblyPath, metadataDatPath, config, reportProgressAction, out var metadata, out var il2Cpp);
		reportProgressAction("Dumping...");
		Il2CppExecutor il2CppExecutor = new Il2CppExecutor(metadata, il2Cpp);
		Il2CppDecompiler il2CppDecompiler = new Il2CppDecompiler(il2CppExecutor);
		reportProgressAction("Done!");
		if (config.GenerateStruct)
		{
			il2CppDecompiler.Decompile(config, outputDirectoryPath, reportProgressAction);
			reportProgressAction("Generate struct...");
			new StructGenerator(il2CppExecutor).WriteScript(outputDirectoryPath);
			reportProgressAction("Done!");
		}
		if (config.GenerateDummyDll)
		{
			reportProgressAction("Generate dummy dll...");
			DummyAssemblyExporter.Export(il2CppExecutor, outputDirectoryPath, config.DummyDllAddToken);
			reportProgressAction("Done!");
		}
		return true;
	}

	public static void Init(string il2cppPath, string metadataPath, Config config, Action<string> reportProgressAction, out Metadata metadata, out Il2Cpp il2Cpp)
	{
		reportProgressAction("Initializing metadata...");
		byte[] buffer = File.ReadAllBytes(metadataPath);
		metadata = new Metadata(new MemoryStream(buffer));
		reportProgressAction($"Metadata Version: {metadata.Version}");
		reportProgressAction("Initializing il2cpp file...");
		byte[] array = File.ReadAllBytes(il2cppPath);
		uint num = BitConverter.ToUInt32(array, 0);
		MemoryStream stream = new MemoryStream(array);
		switch (num)
		{
		default:
			throw new NotSupportedException("ERROR: il2cpp file not supported.");
		case 1836278016u:
		{
			WebAssembly webAssembly = new WebAssembly(stream, reportProgressAction);
			il2Cpp = webAssembly.CreateMemory();
			break;
		}
		case 810505038u:
		{
			NSO nSO = new NSO(stream, reportProgressAction);
			il2Cpp = nSO.UnCompress();
			break;
		}
		case 9460301u:
			il2Cpp = new PE(stream, reportProgressAction);
			break;
		case 1179403647u:
			if (array[4] == 2)
			{
				il2Cpp = new Elf64(stream, reportProgressAction);
			}
			else
			{
				il2Cpp = new Elf(stream, reportProgressAction);
			}
			break;
		case 3199925962u:
		case 3405691582u:
			throw new InvalidOperationException("FAT Mach-O format is currently not supported.");
		case 4277009103u:
			il2Cpp = new Macho64(stream, reportProgressAction);
			break;
		case 4277009102u:
			il2Cpp = new Macho(stream, reportProgressAction);
			break;
		}
		double version = (config.ForceIl2CppVersion ? config.ForceVersion : metadata.Version);
		il2Cpp.SetProperties(version, metadata.maxMetadataUsages);
		reportProgressAction($"Il2Cpp Version: {il2Cpp.Version}");
		if (il2Cpp.Version >= 27.0 && il2Cpp is ElfBase elfBase && elfBase.IsDumped)
		{
			reportProgressAction("Input global-metadata.dat dump address:");
			metadata.Address = Convert.ToUInt64(Console.ReadLine(), 16);
		}
		reportProgressAction("Searching...");
		try
		{
			bool flag = il2Cpp.PlusSearch(metadata.methodDefs.Count((Il2CppMethodDefinition x) => x.methodIndex >= 0), metadata.typeDefs.Length, metadata.imageDefs.Length);
			if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && !flag && il2Cpp is PE)
			{
				reportProgressAction("Use custom PE loader");
				il2Cpp = PELoader.Load(il2cppPath, reportProgressAction);
				il2Cpp.SetProperties(version, metadata.maxMetadataUsages);
				flag = il2Cpp.PlusSearch(metadata.methodDefs.Count((Il2CppMethodDefinition x) => x.methodIndex >= 0), metadata.typeDefs.Length, metadata.imageDefs.Length);
			}
			if (!flag)
			{
				flag = il2Cpp.Search();
			}
			if (!flag)
			{
				flag = il2Cpp.SymbolSearch();
			}
			if (!flag)
			{
				reportProgressAction("ERROR: Unable to automatically determine CodeRegistration and MetadataRegistration properties");
			}
		}
		catch (Exception arg)
		{
			reportProgressAction($"ERROR: An error occurred while processing: {arg}");
		}
	}
}
public abstract class Il2Cpp : BinaryStream
{
	private Il2CppMetadataRegistration pMetadataRegistration;

	private Il2CppCodeRegistration pCodeRegistration;

	public ulong[] methodPointers;

	public ulong[] genericMethodPointers;

	public ulong[] invokerPointers;

	public ulong[] customAttributeGenerators;

	public ulong[] reversePInvokeWrappers;

	public ulong[] unresolvedVirtualCallPointers;

	private ulong[] fieldOffsets;

	public Il2CppType[] types;

	private Dictionary<ulong, Il2CppType> typeDic = new Dictionary<ulong, Il2CppType>();

	public ulong[] metadataUsages;

	private Il2CppGenericMethodFunctionsDefinitions[] genericMethodTable;

	public ulong[] genericInstPointers;

	public Il2CppGenericInst[] genericInsts;

	public Il2CppMethodSpec[] methodSpecs;

	public Dictionary<int, List<Il2CppMethodSpec>> methodDefinitionMethodSpecs = new Dictionary<int, List<Il2CppMethodSpec>>();

	public Dictionary<Il2CppMethodSpec, ulong> methodSpecGenericMethodPointers = new Dictionary<Il2CppMethodSpec, ulong>();

	private bool fieldOffsetsArePointers;

	protected long maxMetadataUsages;

	public Dictionary<string, Il2CppCodeGenModule> codeGenModules;

	public Dictionary<string, ulong[]> codeGenModuleMethodPointers;

	public Dictionary<string, Dictionary<uint, Il2CppRGCTXDefinition[]>> rgctxsDictionary;

	protected Action<string> reportProgressAction;

	public abstract ulong MapVATR(ulong addr);

	public abstract ulong MapRTVA(ulong addr);

	public abstract bool Search();

	public abstract bool PlusSearch(int methodCount, int typeDefinitionsCount, int imageCount);

	public abstract bool SymbolSearch();

	protected Il2Cpp(Stream stream, Action<string> reportProgressAction)
		: base(stream)
	{
		this.reportProgressAction = reportProgressAction;
	}

	public void SetProperties(double version, long maxMetadataUsages)
	{
		Version = version;
		this.maxMetadataUsages = maxMetadataUsages;
	}

	protected bool AutoPlusInit(ulong codeRegistration, ulong metadataRegistration)
	{
		if (codeRegistration != 0L && metadataRegistration != 0L)
		{
			if (Version == 24.2)
			{
				pCodeRegistration = MapVATR<Il2CppCodeRegistration>(codeRegistration);
				if (pCodeRegistration.reversePInvokeWrapperCount > 196608)
				{
					Version = 24.4;
					codeRegistration -= base.PointerSize * 3;
					reportProgressAction($"Change il2cpp version to: {Version}");
				}
				else
				{
					pMetadataRegistration = MapVATR<Il2CppMetadataRegistration>(metadataRegistration);
					genericMethodTable = MapVATR<Il2CppGenericMethodFunctionsDefinitions>(pMetadataRegistration.genericMethodTable, pMetadataRegistration.genericMethodTableCount);
					int num = genericMethodTable.Max((Il2CppGenericMethodFunctionsDefinitions x) => x.indices.methodIndex) + 1;
					if (pCodeRegistration.reversePInvokeWrapperCount == num)
					{
						Version = 24.3;
						codeRegistration -= (uint)(Is32Bit ? 8 : 16);
						reportProgressAction($"Change il2cpp version to: {Version}");
					}
				}
			}
			reportProgressAction($"CodeRegistration : {codeRegistration:x}");
			reportProgressAction($"MetadataRegistration : {metadataRegistration:x}");
			Init(codeRegistration, metadataRegistration);
			return true;
		}
		reportProgressAction($"CodeRegistration : {codeRegistration:x}");
		reportProgressAction($"MetadataRegistration : {metadataRegistration:x}");
		return false;
	}

	public virtual void Init(ulong codeRegistration, ulong metadataRegistration)
	{
		pCodeRegistration = MapVATR<Il2CppCodeRegistration>(codeRegistration);
		if (Version == 27.0 && pCodeRegistration.reversePInvokeWrapperCount > 196608)
		{
			Version = 27.1;
			codeRegistration -= base.PointerSize;
			reportProgressAction($"Change il2cpp version to: {Version}");
			reportProgressAction($"CodeRegistration : {codeRegistration:x}");
			pCodeRegistration = MapVATR<Il2CppCodeRegistration>(codeRegistration);
		}
		if (Version == 24.2)
		{
			if (pCodeRegistration.reversePInvokeWrapperCount > 196608)
			{
				Version = 24.4;
				codeRegistration -= base.PointerSize * 3;
				reportProgressAction($"Change il2cpp version to: {Version}");
				reportProgressAction($"CodeRegistration : {codeRegistration:x}");
				pCodeRegistration = MapVATR<Il2CppCodeRegistration>(codeRegistration);
			}
			else if (pCodeRegistration.codeGenModules == 0L)
			{
				Version = 24.3;
				reportProgressAction($"Change il2cpp version to: {Version}");
				pCodeRegistration = MapVATR<Il2CppCodeRegistration>(codeRegistration);
			}
		}
		pMetadataRegistration = MapVATR<Il2CppMetadataRegistration>(metadataRegistration);
		genericMethodPointers = MapVATR<ulong>(pCodeRegistration.genericMethodPointers, pCodeRegistration.genericMethodPointersCount);
		invokerPointers = MapVATR<ulong>(pCodeRegistration.invokerPointers, pCodeRegistration.invokerPointersCount);
		if (Version < 27.0)
		{
			customAttributeGenerators = MapVATR<ulong>(pCodeRegistration.customAttributeGenerators, pCodeRegistration.customAttributeCount);
		}
		if (Version > 16.0 && Version < 27.0)
		{
			metadataUsages = MapVATR<ulong>(pMetadataRegistration.metadataUsages, maxMetadataUsages);
		}
		if (Version >= 22.0)
		{
			if (pCodeRegistration.reversePInvokeWrapperCount != 0L)
			{
				reversePInvokeWrappers = MapVATR<ulong>(pCodeRegistration.reversePInvokeWrappers, pCodeRegistration.reversePInvokeWrapperCount);
			}
			if (pCodeRegistration.unresolvedVirtualCallCount != 0L)
			{
				unresolvedVirtualCallPointers = MapVATR<ulong>(pCodeRegistration.unresolvedVirtualCallPointers, pCodeRegistration.unresolvedVirtualCallCount);
			}
		}
		genericInstPointers = MapVATR<ulong>(pMetadataRegistration.genericInsts, pMetadataRegistration.genericInstsCount);
		genericInsts = Array.ConvertAll(genericInstPointers, MapVATR<Il2CppGenericInst>);
		fieldOffsetsArePointers = Version > 21.0;
		if (Version == 21.0)
		{
			uint[] array = MapVATR<uint>(pMetadataRegistration.fieldOffsets, 6L);
			fieldOffsetsArePointers = array[0] == 0 && array[1] == 0 && array[2] == 0 && array[3] == 0 && array[4] == 0 && array[5] != 0;
		}
		if (fieldOffsetsArePointers)
		{
			fieldOffsets = MapVATR<ulong>(pMetadataRegistration.fieldOffsets, pMetadataRegistration.fieldOffsetsCount);
		}
		else
		{
			fieldOffsets = Array.ConvertAll(MapVATR<uint>(pMetadataRegistration.fieldOffsets, pMetadataRegistration.fieldOffsetsCount), (Converter<uint, ulong>)((uint x) => x));
		}
		ulong[] array2 = MapVATR<ulong>(pMetadataRegistration.types, pMetadataRegistration.typesCount);
		types = new Il2CppType[pMetadataRegistration.typesCount];
		for (int i = 0; i < pMetadataRegistration.typesCount; i++)
		{
			types[i] = MapVATR<Il2CppType>(array2[i]);
			types[i].Init();
			typeDic.Add(array2[i], types[i]);
		}
		if (Version >= 24.2)
		{
			ulong[] array3 = MapVATR<ulong>(pCodeRegistration.codeGenModules, pCodeRegistration.codeGenModulesCount);
			codeGenModules = new Dictionary<string, Il2CppCodeGenModule>(array3.Length, StringComparer.Ordinal);
			codeGenModuleMethodPointers = new Dictionary<string, ulong[]>(array3.Length, StringComparer.Ordinal);
			rgctxsDictionary = new Dictionary<string, Dictionary<uint, Il2CppRGCTXDefinition[]>>(array3.Length, StringComparer.Ordinal);
			ulong[] array4 = array3;
			foreach (ulong addr in array4)
			{
				Il2CppCodeGenModule il2CppCodeGenModule = MapVATR<Il2CppCodeGenModule>(addr);
				string key = ReadStringToNull(MapVATR(il2CppCodeGenModule.moduleName));
				codeGenModules.Add(key, il2CppCodeGenModule);
				ulong[] value;
				try
				{
					value = MapVATR<ulong>(il2CppCodeGenModule.methodPointers, il2CppCodeGenModule.methodPointerCount);
				}
				catch
				{
					value = new ulong[il2CppCodeGenModule.methodPointerCount];
				}
				codeGenModuleMethodPointers.Add(key, value);
				Dictionary<uint, Il2CppRGCTXDefinition[]> dictionary = new Dictionary<uint, Il2CppRGCTXDefinition[]>();
				rgctxsDictionary.Add(key, dictionary);
				if (il2CppCodeGenModule.rgctxsCount > 0)
				{
					Il2CppRGCTXDefinition[] sourceArray = MapVATR<Il2CppRGCTXDefinition>(il2CppCodeGenModule.rgctxs, il2CppCodeGenModule.rgctxsCount);
					Il2CppTokenRangePair[] array5 = MapVATR<Il2CppTokenRangePair>(il2CppCodeGenModule.rgctxRanges, il2CppCodeGenModule.rgctxRangesCount);
					foreach (Il2CppTokenRangePair il2CppTokenRangePair in array5)
					{
						Il2CppRGCTXDefinition[] array6 = new Il2CppRGCTXDefinition[il2CppTokenRangePair.range.length];
						Array.Copy(sourceArray, il2CppTokenRangePair.range.start, array6, 0, il2CppTokenRangePair.range.length);
						dictionary.Add(il2CppTokenRangePair.token, array6);
					}
				}
			}
		}
		else
		{
			methodPointers = MapVATR<ulong>(pCodeRegistration.methodPointers, pCodeRegistration.methodPointersCount);
		}
		genericMethodTable = MapVATR<Il2CppGenericMethodFunctionsDefinitions>(pMetadataRegistration.genericMethodTable, pMetadataRegistration.genericMethodTableCount);
		methodSpecs = MapVATR<Il2CppMethodSpec>(pMetadataRegistration.methodSpecs, pMetadataRegistration.methodSpecsCount);
		Il2CppGenericMethodFunctionsDefinitions[] array7 = genericMethodTable;
		foreach (Il2CppGenericMethodFunctionsDefinitions il2CppGenericMethodFunctionsDefinitions in array7)
		{
			Il2CppMethodSpec il2CppMethodSpec = methodSpecs[il2CppGenericMethodFunctionsDefinitions.genericMethodIndex];
			int methodDefinitionIndex = il2CppMethodSpec.methodDefinitionIndex;
			if (!methodDefinitionMethodSpecs.TryGetValue(methodDefinitionIndex, out var value2))
			{
				value2 = new List<Il2CppMethodSpec>();
				methodDefinitionMethodSpecs.Add(methodDefinitionIndex, value2);
			}
			value2.Add(il2CppMethodSpec);
			methodSpecGenericMethodPointers.Add(il2CppMethodSpec, genericMethodPointers[il2CppGenericMethodFunctionsDefinitions.indices.methodIndex]);
		}
	}

	public T MapVATR<T>(ulong addr) where T : new()
	{
		return ReadClass<T>(MapVATR(addr));
	}

	public T[] MapVATR<T>(ulong addr, long count) where T : new()
	{
		return ReadClassArray<T>(MapVATR(addr), count);
	}

	public int GetFieldOffsetFromIndex(int typeIndex, int fieldIndexInType, int fieldIndex, bool isValueType, bool isStatic)
	{
		try
		{
			int num = -1;
			if (fieldOffsetsArePointers)
			{
				ulong num2 = fieldOffsets[typeIndex];
				if (num2 != 0)
				{
					base.Position = MapVATR(num2) + (ulong)(4L * (long)fieldIndexInType);
					num = ReadInt32();
				}
			}
			else
			{
				num = (int)fieldOffsets[fieldIndex];
			}
			if (num > 0 && isValueType && !isStatic)
			{
				num = ((!Is32Bit) ? (num - 16) : (num - 8));
			}
			return num;
		}
		catch
		{
			return -1;
		}
	}

	public Il2CppType GetIl2CppType(ulong pointer)
	{
		return typeDic[pointer];
	}

	public ulong GetMethodPointer(string imageName, Il2CppMethodDefinition methodDef)
	{
		if (Version >= 24.2)
		{
			uint token = methodDef.token;
			ulong[] array = codeGenModuleMethodPointers[imageName];
			uint num = token & 0xFFFFFFu;
			return array[num - 1];
		}
		int methodIndex = methodDef.methodIndex;
		if (methodIndex >= 0)
		{
			return methodPointers[methodIndex];
		}
		return 0uL;
	}

	public virtual ulong GetRVA(ulong pointer)
	{
		return pointer;
	}
}
public class Il2CppCodeRegistration
{
	[Version(Max = 24.1)]
	public long methodPointersCount;

	[Version(Max = 24.1)]
	public ulong methodPointers;

	[Version(Max = 21.0)]
	public ulong delegateWrappersFromNativeToManagedCount;

	[Version(Max = 21.0)]
	public ulong delegateWrappersFromNativeToManaged;

	[Version(Min = 22.0)]
	public long reversePInvokeWrapperCount;

	[Version(Min = 22.0)]
	public ulong reversePInvokeWrappers;

	[Version(Max = 22.0)]
	public ulong delegateWrappersFromManagedToNativeCount;

	[Version(Max = 22.0)]
	public ulong delegateWrappersFromManagedToNative;

	[Version(Max = 22.0)]
	public ulong marshalingFunctionsCount;

	[Version(Max = 22.0)]
	public ulong marshalingFunctions;

	[Version(Min = 21.0, Max = 22.0)]
	public ulong ccwMarshalingFunctionsCount;

	[Version(Min = 21.0, Max = 22.0)]
	public ulong ccwMarshalingFunctions;

	public long genericMethodPointersCount;

	public ulong genericMethodPointers;

	[Version(Min = 24.4, Max = 24.4)]
	[Version(Min = 27.1)]
	public ulong genericAdjustorThunks;

	public long invokerPointersCount;

	public ulong invokerPointers;

	[Version(Max = 24.4)]
	public long customAttributeCount;

	[Version(Max = 24.4)]
	public ulong customAttributeGenerators;

	[Version(Min = 21.0, Max = 22.0)]
	public long guidCount;

	[Version(Min = 21.0, Max = 22.0)]
	public ulong guids;

	[Version(Min = 22.0)]
	public long unresolvedVirtualCallCount;

	[Version(Min = 22.0)]
	public ulong unresolvedVirtualCallPointers;

	[Version(Min = 23.0)]
	public ulong interopDataCount;

	[Version(Min = 23.0)]
	public ulong interopData;

	[Version(Min = 24.3)]
	public ulong windowsRuntimeFactoryCount;

	[Version(Min = 24.3)]
	public ulong windowsRuntimeFactoryTable;

	[Version(Min = 24.2)]
	public long codeGenModulesCount;

	[Version(Min = 24.2)]
	public ulong codeGenModules;
}
public class Il2CppMetadataRegistration
{
	public long genericClassesCount;

	public ulong genericClasses;

	public long genericInstsCount;

	public ulong genericInsts;

	public long genericMethodTableCount;

	public ulong genericMethodTable;

	public long typesCount;

	public ulong types;

	public long methodSpecsCount;

	public ulong methodSpecs;

	[Version(Max = 16.0)]
	public long methodReferencesCount;

	[Version(Max = 16.0)]
	public ulong methodReferences;

	public long fieldOffsetsCount;

	public ulong fieldOffsets;

	public long typeDefinitionsSizesCount;

	public ulong typeDefinitionsSizes;

	[Version(Min = 19.0)]
	public ulong metadataUsagesCount;

	[Version(Min = 19.0)]
	public ulong metadataUsages;
}
public enum Il2CppTypeEnum
{
	IL2CPP_TYPE_END = 0,
	IL2CPP_TYPE_VOID = 1,
	IL2CPP_TYPE_BOOLEAN = 2,
	IL2CPP_TYPE_CHAR = 3,
	IL2CPP_TYPE_I1 = 4,
	IL2CPP_TYPE_U1 = 5,
	IL2CPP_TYPE_I2 = 6,
	IL2CPP_TYPE_U2 = 7,
	IL2CPP_TYPE_I4 = 8,
	IL2CPP_TYPE_U4 = 9,
	IL2CPP_TYPE_I8 = 10,
	IL2CPP_TYPE_U8 = 11,
	IL2CPP_TYPE_R4 = 12,
	IL2CPP_TYPE_R8 = 13,
	IL2CPP_TYPE_STRING = 14,
	IL2CPP_TYPE_PTR = 15,
	IL2CPP_TYPE_BYREF = 16,
	IL2CPP_TYPE_VALUETYPE = 17,
	IL2CPP_TYPE_CLASS = 18,
	IL2CPP_TYPE_VAR = 19,
	IL2CPP_TYPE_ARRAY = 20,
	IL2CPP_TYPE_GENERICINST = 21,
	IL2CPP_TYPE_TYPEDBYREF = 22,
	IL2CPP_TYPE_I = 24,
	IL2CPP_TYPE_U = 25,
	IL2CPP_TYPE_FNPTR = 27,
	IL2CPP_TYPE_OBJECT = 28,
	IL2CPP_TYPE_SZARRAY = 29,
	IL2CPP_TYPE_MVAR = 30,
	IL2CPP_TYPE_CMOD_REQD = 31,
	IL2CPP_TYPE_CMOD_OPT = 32,
	IL2CPP_TYPE_INTERNAL = 33,
	IL2CPP_TYPE_MODIFIER = 64,
	IL2CPP_TYPE_SENTINEL = 65,
	IL2CPP_TYPE_PINNED = 69,
	IL2CPP_TYPE_ENUM = 85
}
public class Il2CppType
{
	public class Union
	{
		public ulong dummy;

		public long klassIndex => (long)dummy;

		public ulong typeHandle => dummy;

		public ulong type => dummy;

		public ulong array => dummy;

		public long genericParameterIndex => (long)dummy;

		public ulong genericParameterHandle => dummy;

		public ulong generic_class => dummy;
	}

	public ulong datapoint;

	public uint bits;

	public Union data { get; set; }

	public uint attrs { get; set; }

	public Il2CppTypeEnum type { get; set; }

	public uint num_mods { get; set; }

	public uint byref { get; set; }

	public uint pinned { get; set; }

	public void Init()
	{
		attrs = bits & 0xFFFFu;
		type = (Il2CppTypeEnum)((int)(bits >> 16) & 0xFF);
		num_mods = (bits >> 24) & 0x3Fu;
		byref = (bits >> 30) & 1u;
		pinned = bits >> 31;
		data = new Union
		{
			dummy = datapoint
		};
	}
}
public class Il2CppGenericClass
{
	[Version(Max = 24.4)]
	public long typeDefinitionIndex;

	[Version(Min = 27.0)]
	public ulong type;

	public Il2CppGenericContext context;

	public ulong cached_class;
}
public class Il2CppGenericContext
{
	public ulong class_inst;

	public ulong method_inst;
}
public class Il2CppGenericInst
{
	public long type_argc;

	public ulong type_argv;
}
public class Il2CppArrayType
{
	public ulong etype;

	public byte rank;

	public byte numsizes;

	public byte numlobounds;

	public ulong sizes;

	public ulong lobounds;
}
public class Il2CppGenericMethodFunctionsDefinitions
{
	public int genericMethodIndex;

	public Il2CppGenericMethodIndices indices;
}
public class Il2CppGenericMethodIndices
{
	public int methodIndex;

	public int invokerIndex;

	[Version(Min = 24.4, Max = 24.4)]
	[Version(Min = 27.1)]
	public int adjustorThunk;
}
public class Il2CppMethodSpec
{
	public int methodDefinitionIndex;

	public int classIndexIndex;

	public int methodIndexIndex;
}
public class Il2CppCodeGenModule
{
	public ulong moduleName;

	public long methodPointerCount;

	public ulong methodPointers;

	[Version(Min = 24.4, Max = 24.4)]
	[Version(Min = 27.1)]
	public long adjustorThunkCount;

	[Version(Min = 24.4, Max = 24.4)]
	[Version(Min = 27.1)]
	public ulong adjustorThunks;

	public ulong invokerIndices;

	public ulong reversePInvokeWrapperCount;

	public ulong reversePInvokeWrapperIndices;

	public long rgctxRangesCount;

	public ulong rgctxRanges;

	public long rgctxsCount;

	public ulong rgctxs;

	public ulong debuggerMetadata;

	[Version(Min = 27.0)]
	public ulong customAttributeCacheGenerator;

	[Version(Min = 27.0)]
	public ulong moduleInitializer;

	[Version(Min = 27.0)]
	public ulong staticConstructorTypeIndices;

	[Version(Min = 27.0)]
	public ulong metadataRegistration;

	[Version(Min = 27.0)]
	public ulong codeRegistaration;
}
public class Il2CppRange
{
	public int start;

	public int length;
}
public class Il2CppTokenRangePair
{
	public uint token;

	public Il2CppRange range;
}
public sealed class Metadata : BinaryStream
{
	public Il2CppGlobalMetadataHeader header;

	public Il2CppImageDefinition[] imageDefs;

	public Il2CppTypeDefinition[] typeDefs;

	public Il2CppMethodDefinition[] methodDefs;

	public Il2CppParameterDefinition[] parameterDefs;

	public Il2CppFieldDefinition[] fieldDefs;

	private Dictionary<int, Il2CppFieldDefaultValue> fieldDefaultValuesDic;

	private Dictionary<int, Il2CppParameterDefaultValue> parameterDefaultValuesDic;

	public Il2CppPropertyDefinition[] propertyDefs;

	public Il2CppCustomAttributeTypeRange[] attributeTypeRanges;

	private Dictionary<Il2CppImageDefinition, Dictionary<uint, int>> attributeTypeRangesDic;

	public Il2CppStringLiteral[] stringLiterals;

	private Il2CppMetadataUsageList[] metadataUsageLists;

	private Il2CppMetadataUsagePair[] metadataUsagePairs;

	public int[] attributeTypes;

	public int[] interfaceIndices;

	public Dictionary<Il2CppMetadataUsage, SortedDictionary<uint, uint>> metadataUsageDic;

	public long maxMetadataUsages;

	public int[] nestedTypeIndices;

	public Il2CppEventDefinition[] eventDefs;

	public Il2CppGenericContainer[] genericContainers;

	public Il2CppFieldRef[] fieldRefs;

	public Il2CppGenericParameter[] genericParameters;

	public int[] constraintIndices;

	public uint[] vtableMethods;

	public Il2CppRGCTXDefinition[] rgctxEntries;

	private Dictionary<uint, string> stringCache = new Dictionary<uint, string>();

	public ulong Address;

	public Metadata(Stream stream)
		: base(stream)
	{
		if (ReadUInt32() != 4205910959u)
		{
			throw new InvalidDataException("ERROR: Metadata file supplied is not valid metadata file.");
		}
		int num = ReadInt32();
		if (num < 16 || num > 27)
		{
			throw new NotSupportedException($"ERROR: Metadata file supplied is not a supported version[{num}].");
		}
		Version = num;
		header = ReadClass<Il2CppGlobalMetadataHeader>(0uL);
		if (num == 24)
		{
			if (header.stringLiteralOffset == 264)
			{
				Version = 24.2;
				header = ReadClass<Il2CppGlobalMetadataHeader>(0uL);
			}
			else
			{
				imageDefs = ReadMetadataClassArray<Il2CppImageDefinition>(header.imagesOffset, header.imagesCount);
				if (imageDefs.Any((Il2CppImageDefinition x) => x.token != 1))
				{
					Version = 24.1;
				}
			}
		}
		imageDefs = ReadMetadataClassArray<Il2CppImageDefinition>(header.imagesOffset, header.imagesCount);
		typeDefs = ReadMetadataClassArray<Il2CppTypeDefinition>(header.typeDefinitionsOffset, header.typeDefinitionsCount);
		methodDefs = ReadMetadataClassArray<Il2CppMethodDefinition>(header.methodsOffset, header.methodsCount);
		parameterDefs = ReadMetadataClassArray<Il2CppParameterDefinition>(header.parametersOffset, header.parametersCount);
		fieldDefs = ReadMetadataClassArray<Il2CppFieldDefinition>(header.fieldsOffset, header.fieldsCount);
		Il2CppFieldDefaultValue[] source = ReadMetadataClassArray<Il2CppFieldDefaultValue>(header.fieldDefaultValuesOffset, header.fieldDefaultValuesCount);
		Il2CppParameterDefaultValue[] source2 = ReadMetadataClassArray<Il2CppParameterDefaultValue>(header.parameterDefaultValuesOffset, header.parameterDefaultValuesCount);
		fieldDefaultValuesDic = source.ToDictionary((Il2CppFieldDefaultValue x) => x.fieldIndex);
		parameterDefaultValuesDic = source2.ToDictionary((Il2CppParameterDefaultValue x) => x.parameterIndex);
		propertyDefs = ReadMetadataClassArray<Il2CppPropertyDefinition>(header.propertiesOffset, header.propertiesCount);
		interfaceIndices = ReadClassArray<int>(header.interfacesOffset, header.interfacesCount / 4);
		nestedTypeIndices = ReadClassArray<int>(header.nestedTypesOffset, header.nestedTypesCount / 4);
		eventDefs = ReadMetadataClassArray<Il2CppEventDefinition>(header.eventsOffset, header.eventsCount);
		genericContainers = ReadMetadataClassArray<Il2CppGenericContainer>(header.genericContainersOffset, header.genericContainersCount);
		genericParameters = ReadMetadataClassArray<Il2CppGenericParameter>(header.genericParametersOffset, header.genericParametersCount);
		constraintIndices = ReadClassArray<int>(header.genericParameterConstraintsOffset, header.genericParameterConstraintsCount / 4);
		vtableMethods = ReadClassArray<uint>(header.vtableMethodsOffset, header.vtableMethodsCount / 4);
		stringLiterals = ReadMetadataClassArray<Il2CppStringLiteral>(header.stringLiteralOffset, header.stringLiteralCount);
		if (Version > 16.0)
		{
			fieldRefs = ReadMetadataClassArray<Il2CppFieldRef>(header.fieldRefsOffset, header.fieldRefsCount);
			if (Version < 27.0)
			{
				metadataUsageLists = ReadMetadataClassArray<Il2CppMetadataUsageList>(header.metadataUsageListsOffset, header.metadataUsageListsCount);
				metadataUsagePairs = ReadMetadataClassArray<Il2CppMetadataUsagePair>(header.metadataUsagePairsOffset, header.metadataUsagePairsCount);
				ProcessingMetadataUsage();
			}
		}
		if (Version > 20.0)
		{
			attributeTypeRanges = ReadMetadataClassArray<Il2CppCustomAttributeTypeRange>(header.attributesInfoOffset, header.attributesInfoCount);
			attributeTypes = ReadClassArray<int>(header.attributeTypesOffset, header.attributeTypesCount / 4);
		}
		if (Version > 24.0)
		{
			attributeTypeRangesDic = new Dictionary<Il2CppImageDefinition, Dictionary<uint, int>>();
			Il2CppImageDefinition[] array = imageDefs;
			foreach (Il2CppImageDefinition il2CppImageDefinition in array)
			{
				Dictionary<uint, int> dictionary = new Dictionary<uint, int>();
				attributeTypeRangesDic[il2CppImageDefinition] = dictionary;
				long num2 = il2CppImageDefinition.customAttributeStart + il2CppImageDefinition.customAttributeCount;
				for (int j = il2CppImageDefinition.customAttributeStart; j < num2; j++)
				{
					dictionary.Add(attributeTypeRanges[j].token, j);
				}
			}
		}
		if (Version <= 24.1)
		{
			rgctxEntries = ReadMetadataClassArray<Il2CppRGCTXDefinition>(header.rgctxEntriesOffset, header.rgctxEntriesCount);
		}
	}

	private T[] ReadMetadataClassArray<T>(uint addr, int count) where T : new()
	{
		return ReadClassArray<T>(addr, count / SizeOf(typeof(T)));
	}

	public bool GetFieldDefaultValueFromIndex(int index, out Il2CppFieldDefaultValue value)
	{
		return fieldDefaultValuesDic.TryGetValue(index, out value);
	}

	public bool GetParameterDefaultValueFromIndex(int index, out Il2CppParameterDefaultValue value)
	{
		return parameterDefaultValuesDic.TryGetValue(index, out value);
	}

	public uint GetDefaultValueFromIndex(int index)
	{
		return (uint)(header.fieldAndParameterDefaultValueDataOffset + index);
	}

	public string GetStringFromIndex(uint index)
	{
		if (!stringCache.TryGetValue(index, out var value))
		{
			value = ReadStringToNull(header.stringOffset + index);
			stringCache.Add(index, value);
		}
		return value;
	}

	public int GetCustomAttributeIndex(Il2CppImageDefinition imageDef, int customAttributeIndex, uint token)
	{
		if (Version > 24.0)
		{
			if (attributeTypeRangesDic[imageDef].TryGetValue(token, out var value))
			{
				return value;
			}
			return -1;
		}
		return customAttributeIndex;
	}

	public string GetStringLiteralFromIndex(uint index)
	{
		Il2CppStringLiteral il2CppStringLiteral = stringLiterals[index];
		base.Position = (uint)(header.stringLiteralDataOffset + il2CppStringLiteral.dataIndex);
		return Encoding.UTF8.GetString(ReadBytes((int)il2CppStringLiteral.length));
	}

	private void ProcessingMetadataUsage()
	{
		metadataUsageDic = new Dictionary<Il2CppMetadataUsage, SortedDictionary<uint, uint>>();
		for (uint num = 1u; num <= 6; num++)
		{
			metadataUsageDic[(Il2CppMetadataUsage)num] = new SortedDictionary<uint, uint>();
		}
		Il2CppMetadataUsageList[] array = metadataUsageLists;
		foreach (Il2CppMetadataUsageList il2CppMetadataUsageList in array)
		{
			for (int j = 0; j < il2CppMetadataUsageList.count; j++)
			{
				long num2 = il2CppMetadataUsageList.start + j;
				Il2CppMetadataUsagePair il2CppMetadataUsagePair = metadataUsagePairs[num2];
				uint encodedIndexType = GetEncodedIndexType(il2CppMetadataUsagePair.encodedSourceIndex);
				uint decodedMethodIndex = GetDecodedMethodIndex(il2CppMetadataUsagePair.encodedSourceIndex);
				metadataUsageDic[(Il2CppMetadataUsage)encodedIndexType][il2CppMetadataUsagePair.destinationIndex] = decodedMethodIndex;
			}
		}
		maxMetadataUsages = metadataUsageDic.Max((KeyValuePair<Il2CppMetadataUsage, SortedDictionary<uint, uint>> x) => x.Value.Max((KeyValuePair<uint, uint> y) => y.Key)) + 1;
	}

	public uint GetEncodedIndexType(uint index)
	{
		return (index & 0xE0000000u) >> 29;
	}

	public uint GetDecodedMethodIndex(uint index)
	{
		if (Version >= 27.0)
		{
			return (index & 0x1FFFFFFE) >> 1;
		}
		return index & 0x1FFFFFFFu;
	}

	public int SizeOf(Type type)
	{
		int num = 0;
		FieldInfo[] fields = type.GetFields();
		foreach (FieldInfo fieldInfo in fields)
		{
			VersionAttribute versionAttribute = (VersionAttribute)Attribute.GetCustomAttribute(fieldInfo, typeof(VersionAttribute));
			if (versionAttribute == null || (!(Version < versionAttribute.Min) && !(Version > versionAttribute.Max)))
			{
				Type fieldType = fieldInfo.FieldType;
				if (fieldType.IsPrimitive)
				{
					num += GetPrimitiveTypeSize(fieldType.Name);
				}
				else if (fieldType.IsEnum)
				{
					Type fieldType2 = fieldType.GetField("value__").FieldType;
					num += GetPrimitiveTypeSize(fieldType2.Name);
				}
				else
				{
					num += SizeOf(fieldType);
				}
			}
		}
		return num;
		static int GetPrimitiveTypeSize(string name)
		{
			switch (name)
			{
			case "Int32":
			case "UInt32":
				return 4;
			case "Int16":
			case "UInt16":
				return 2;
			default:
				return 0;
			}
		}
	}

	public string ReadString(int numChars)
	{
		ulong position = base.Position;
		string text = Encoding.UTF8.GetString(ReadBytes(numChars * 4)).Substring(0, numChars);
		base.Position = position;
		ReadBytes(Encoding.UTF8.GetByteCount(text));
		return text;
	}
}
public class Il2CppGlobalMetadataHeader
{
	public uint sanity;

	public int version;

	public uint stringLiteralOffset;

	public int stringLiteralCount;

	public uint stringLiteralDataOffset;

	public int stringLiteralDataCount;

	public uint stringOffset;

	public int stringCount;

	public uint eventsOffset;

	public int eventsCount;

	public uint propertiesOffset;

	public int propertiesCount;

	public uint methodsOffset;

	public int methodsCount;

	public uint parameterDefaultValuesOffset;

	public int parameterDefaultValuesCount;

	public uint fieldDefaultValuesOffset;

	public int fieldDefaultValuesCount;

	public uint fieldAndParameterDefaultValueDataOffset;

	public int fieldAndParameterDefaultValueDataCount;

	public int fieldMarshaledSizesOffset;

	public int fieldMarshaledSizesCount;

	public uint parametersOffset;

	public int parametersCount;

	public uint fieldsOffset;

	public int fieldsCount;

	public uint genericParametersOffset;

	public int genericParametersCount;

	public uint genericParameterConstraintsOffset;

	public int genericParameterConstraintsCount;

	public uint genericContainersOffset;

	public int genericContainersCount;

	public uint nestedTypesOffset;

	public int nestedTypesCount;

	public uint interfacesOffset;

	public int interfacesCount;

	public uint vtableMethodsOffset;

	public int vtableMethodsCount;

	public int interfaceOffsetsOffset;

	public int interfaceOffsetsCount;

	public uint typeDefinitionsOffset;

	public int typeDefinitionsCount;

	[Version(Max = 24.1)]
	public uint rgctxEntriesOffset;

	[Version(Max = 24.1)]
	public int rgctxEntriesCount;

	public uint imagesOffset;

	public int imagesCount;

	public int assembliesOffset;

	public int assembliesCount;

	[Version(Min = 19.0, Max = 24.4)]
	public uint metadataUsageListsOffset;

	[Version(Min = 19.0, Max = 24.4)]
	public int metadataUsageListsCount;

	[Version(Min = 19.0, Max = 24.4)]
	public uint metadataUsagePairsOffset;

	[Version(Min = 19.0, Max = 24.4)]
	public int metadataUsagePairsCount;

	[Version(Min = 19.0)]
	public uint fieldRefsOffset;

	[Version(Min = 19.0)]
	public int fieldRefsCount;

	[Version(Min = 20.0)]
	public int referencedAssembliesOffset;

	[Version(Min = 20.0)]
	public int referencedAssembliesCount;

	[Version(Min = 21.0)]
	public uint attributesInfoOffset;

	[Version(Min = 21.0)]
	public int attributesInfoCount;

	[Version(Min = 21.0)]
	public uint attributeTypesOffset;

	[Version(Min = 21.0)]
	public int attributeTypesCount;

	[Version(Min = 22.0)]
	public int unresolvedVirtualCallParameterTypesOffset;

	[Version(Min = 22.0)]
	public int unresolvedVirtualCallParameterTypesCount;

	[Version(Min = 22.0)]
	public int unresolvedVirtualCallParameterRangesOffset;

	[Version(Min = 22.0)]
	public int unresolvedVirtualCallParameterRangesCount;

	[Version(Min = 23.0)]
	public int windowsRuntimeTypeNamesOffset;

	[Version(Min = 23.0)]
	public int windowsRuntimeTypeNamesSize;

	[Version(Min = 27.0)]
	public int windowsRuntimeStringsOffset;

	[Version(Min = 27.0)]
	public int windowsRuntimeStringsSize;

	[Version(Min = 24.0)]
	public int exportedTypeDefinitionsOffset;

	[Version(Min = 24.0)]
	public int exportedTypeDefinitionsCount;
}
public class Il2CppImageDefinition
{
	public uint nameIndex;

	public int assemblyIndex;

	public int typeStart;

	public uint typeCount;

	[Version(Min = 24.0)]
	public int exportedTypeStart;

	[Version(Min = 24.0)]
	public uint exportedTypeCount;

	public int entryPointIndex;

	[Version(Min = 19.0)]
	public uint token;

	[Version(Min = 24.1)]
	public int customAttributeStart;

	[Version(Min = 24.1)]
	public uint customAttributeCount;
}
public class Il2CppTypeDefinition
{
	public uint nameIndex;

	public uint namespaceIndex;

	[Version(Max = 24.0)]
	public int customAttributeIndex;

	public int byvalTypeIndex;

	[Version(Max = 24.4)]
	public int byrefTypeIndex;

	public int declaringTypeIndex;

	public int parentIndex;

	public int elementTypeIndex;

	[Version(Max = 24.1)]
	public int rgctxStartIndex;

	[Version(Max = 24.1)]
	public int rgctxCount;

	public int genericContainerIndex;

	[Version(Max = 22.0)]
	public int delegateWrapperFromManagedToNativeIndex;

	[Version(Max = 22.0)]
	public int marshalingFunctionsIndex;

	[Version(Min = 21.0, Max = 22.0)]
	public int ccwFunctionIndex;

	[Version(Min = 21.0, Max = 22.0)]
	public int guidIndex;

	public uint flags;

	public int fieldStart;

	public int methodStart;

	public int eventStart;

	public int propertyStart;

	public int nestedTypesStart;

	public int interfacesStart;

	public int vtableStart;

	public int interfaceOffsetsStart;

	public ushort method_count;

	public ushort property_count;

	public ushort field_count;

	public ushort event_count;

	public ushort nested_type_count;

	public ushort vtable_count;

	public ushort interfaces_count;

	public ushort interface_offsets_count;

	public uint bitfield;

	[Version(Min = 19.0)]
	public uint token;

	public bool IsValueType => (bitfield & 1) == 1;

	public bool IsEnum => ((bitfield >> 1) & 1) == 1;
}
public class Il2CppMethodDefinition
{
	public uint nameIndex;

	public int declaringType;

	public int returnType;

	public int parameterStart;

	[Version(Max = 24.0)]
	public int customAttributeIndex;

	public int genericContainerIndex;

	[Version(Max = 24.1)]
	public int methodIndex;

	[Version(Max = 24.1)]
	public int invokerIndex;

	[Version(Max = 24.1)]
	public int delegateWrapperIndex;

	[Version(Max = 24.1)]
	public int rgctxStartIndex;

	[Version(Max = 24.1)]
	public int rgctxCount;

	public uint token;

	public ushort flags;

	public ushort iflags;

	public ushort slot;

	public ushort parameterCount;
}
public class Il2CppParameterDefinition
{
	public uint nameIndex;

	public uint token;

	[Version(Max = 24.0)]
	public int customAttributeIndex;

	public int typeIndex;
}
public class Il2CppFieldDefinition
{
	public uint nameIndex;

	public int typeIndex;

	[Version(Max = 24.0)]
	public int customAttributeIndex;

	[Version(Min = 19.0)]
	public uint token;
}
public class Il2CppFieldDefaultValue
{
	public int fieldIndex;

	public int typeIndex;

	public int dataIndex;
}
public class Il2CppPropertyDefinition
{
	public uint nameIndex;

	public int get;

	public int set;

	public uint attrs;

	[Version(Max = 24.0)]
	public int customAttributeIndex;

	[Version(Min = 19.0)]
	public uint token;
}
public class Il2CppCustomAttributeTypeRange
{
	[Version(Min = 24.1)]
	public uint token;

	public int start;

	public int count;
}
public class Il2CppMetadataUsageList
{
	public uint start;

	public uint count;
}
public class Il2CppMetadataUsagePair
{
	public uint destinationIndex;

	public uint encodedSourceIndex;
}
public class Il2CppStringLiteral
{
	public uint length;

	public int dataIndex;
}
public class Il2CppParameterDefaultValue
{
	public int parameterIndex;

	public int typeIndex;

	public int dataIndex;
}
public class Il2CppEventDefinition
{
	public uint nameIndex;

	public int typeIndex;

	public int add;

	public int remove;

	public int raise;

	[Version(Max = 24.0)]
	public int customAttributeIndex;

	[Version(Min = 19.0)]
	public uint token;
}
public class Il2CppGenericContainer
{
	public int ownerIndex;

	public int type_argc;

	public int is_method;

	public int genericParameterStart;
}
public class Il2CppFieldRef
{
	public int typeIndex;

	public int fieldIndex;
}
public class Il2CppGenericParameter
{
	public int ownerIndex;

	public uint nameIndex;

	public short constraintsStart;

	public short constraintsCount;

	public ushort num;

	public ushort flags;
}
public enum Il2CppRGCTXDataType
{
	IL2CPP_RGCTX_DATA_INVALID,
	IL2CPP_RGCTX_DATA_TYPE,
	IL2CPP_RGCTX_DATA_CLASS,
	IL2CPP_RGCTX_DATA_METHOD,
	IL2CPP_RGCTX_DATA_ARRAY
}
public class Il2CppRGCTXDefinitionData
{
	public int rgctxDataDummy;

	public int methodIndex => rgctxDataDummy;

	public int typeIndex => rgctxDataDummy;
}
public class Il2CppRGCTXDefinition
{
	public Il2CppRGCTXDataType type;

	public Il2CppRGCTXDefinitionData data;
}
public enum Il2CppMetadataUsage
{
	kIl2CppMetadataUsageInvalid,
	kIl2CppMetadataUsageTypeInfo,
	kIl2CppMetadataUsageIl2CppType,
	kIl2CppMetadataUsageMethodDef,
	kIl2CppMetadataUsageFieldInfo,
	kIl2CppMetadataUsageStringLiteral,
	kIl2CppMetadataUsageMethodRef
}
public class BinaryStream : IDisposable
{
	public double Version;

	public bool Is32Bit;

	private Stream stream;

	private BinaryReader reader;

	private BinaryWriter writer;

	private MethodInfo readClass;

	private MethodInfo readClassArray;

	private Dictionary<Type, MethodInfo> genericMethodCache = new Dictionary<Type, MethodInfo>();

	private Dictionary<FieldInfo, VersionAttribute[]> attributeCache = new Dictionary<FieldInfo, VersionAttribute[]>();

	public ulong Position
	{
		get
		{
			return (ulong)stream.Position;
		}
		set
		{
			stream.Position = (long)value;
		}
	}

	public ulong Length => (ulong)stream.Length;

	public ulong PointerSize
	{
		get
		{
			if (!Is32Bit)
			{
				return 8uL;
			}
			return 4uL;
		}
	}

	public BinaryStream(Stream input)
	{
		stream = input;
		reader = new BinaryReader(stream, Encoding.UTF8, leaveOpen: true);
		writer = new BinaryWriter(stream, Encoding.UTF8, leaveOpen: true);
		readClass = GetType().GetMethod("ReadClass", Type.EmptyTypes);
		readClassArray = GetType().GetMethod("ReadClassArray", new Type[1] { typeof(long) });
	}

	public bool ReadBoolean()
	{
		return reader.ReadBoolean();
	}

	public byte ReadByte()
	{
		return reader.ReadByte();
	}

	public byte[] ReadBytes(int count)
	{
		return reader.ReadBytes(count);
	}

	public sbyte ReadSByte()
	{
		return reader.ReadSByte();
	}

	public short ReadInt16()
	{
		return reader.ReadInt16();
	}

	public ushort ReadUInt16()
	{
		return reader.ReadUInt16();
	}

	public int ReadInt32()
	{
		return reader.ReadInt32();
	}

	public uint ReadUInt32()
	{
		return reader.ReadUInt32();
	}

	public long ReadInt64()
	{
		return reader.ReadInt64();
	}

	public ulong ReadUInt64()
	{
		return reader.ReadUInt64();
	}

	public float ReadSingle()
	{
		return reader.ReadSingle();
	}

	public double ReadDouble()
	{
		return reader.ReadDouble();
	}

	public uint ReadULeb128()
	{
		uint num = reader.ReadByte();
		if (num >= 128)
		{
			int num2 = 0;
			num &= 0x7Fu;
			byte b;
			do
			{
				b = reader.ReadByte();
				num2 += 7;
				num |= (uint)((b & 0x7F) << num2);
			}
			while (b >= 128);
		}
		return num;
	}

	public void Write(bool value)
	{
		writer.Write(value);
	}

	public void Write(byte value)
	{
		writer.Write(value);
	}

	public void Write(sbyte value)
	{
		writer.Write(value);
	}

	public void Write(short value)
	{
		writer.Write(value);
	}

	public void Write(ushort value)
	{
		writer.Write(value);
	}

	public void Write(int value)
	{
		writer.Write(value);
	}

	public void Write(uint value)
	{
		writer.Write(value);
	}

	public void Write(long value)
	{
		writer.Write(value);
	}

	public void Write(ulong value)
	{
		writer.Write(value);
	}

	public void Write(float value)
	{
		writer.Write(value);
	}

	public void Write(double value)
	{
		writer.Write(value);
	}

	private object ReadPrimitive(Type type)
	{
		switch (type.Name)
		{
		case "Int32":
			return ReadInt32();
		case "UInt32":
			return ReadUInt32();
		case "Int16":
			return ReadInt16();
		case "UInt16":
			return ReadUInt16();
		case "Byte":
			return ReadByte();
		case "Int64":
			if (Is32Bit)
			{
				return (long)ReadInt32();
			}
			return ReadInt64();
		case "UInt64":
			if (Is32Bit)
			{
				return (ulong)ReadUInt32();
			}
			return ReadUInt64();
		default:
			throw new NotSupportedException();
		}
	}

	public T ReadClass<T>(ulong addr) where T : new()
	{
		Position = addr;
		return ReadClass<T>();
	}

	public T ReadClass<T>() where T : new()
	{
		Type typeFromHandle = typeof(T);
		if (typeFromHandle.IsPrimitive)
		{
			return (T)ReadPrimitive(typeFromHandle);
		}
		T val = new T();
		FieldInfo[] fields = val.GetType().GetFields();
		foreach (FieldInfo fieldInfo in fields)
		{
			if (!attributeCache.TryGetValue(fieldInfo, out var value) && Attribute.IsDefined(fieldInfo, typeof(VersionAttribute)))
			{
				value = fieldInfo.GetCustomAttributes<VersionAttribute>().ToArray();
				attributeCache.Add(fieldInfo, value);
			}
			if (value != null && value.Length != 0)
			{
				bool flag = false;
				VersionAttribute[] array = value;
				foreach (VersionAttribute versionAttribute in array)
				{
					if (Version >= versionAttribute.Min && Version <= versionAttribute.Max)
					{
						flag = true;
						break;
					}
				}
				if (!flag)
				{
					continue;
				}
			}
			Type fieldType = fieldInfo.FieldType;
			if (fieldType.IsPrimitive)
			{
				fieldInfo.SetValue(val, ReadPrimitive(fieldType));
			}
			else if (fieldType.IsEnum)
			{
				Type fieldType2 = fieldType.GetField("value__").FieldType;
				fieldInfo.SetValue(val, ReadPrimitive(fieldType2));
			}
			else if (fieldType.IsArray)
			{
				ArrayLengthAttribute customAttribute = fieldInfo.GetCustomAttribute<ArrayLengthAttribute>();
				if (!genericMethodCache.TryGetValue(fieldType, out var value2))
				{
					value2 = readClassArray.MakeGenericMethod(fieldType.GetElementType());
					genericMethodCache.Add(fieldType, value2);
				}
				fieldInfo.SetValue(val, value2.Invoke(this, new object[1] { customAttribute.Length }));
			}
			else
			{
				if (!genericMethodCache.TryGetValue(fieldType, out var value3))
				{
					value3 = readClass.MakeGenericMethod(fieldType);
					genericMethodCache.Add(fieldType, value3);
				}
				fieldInfo.SetValue(val, value3.Invoke(this, null));
			}
		}
		return val;
	}

	public T[] ReadClassArray<T>(long count) where T : new()
	{
		T[] array = new T[count];
		for (int i = 0; i < count; i++)
		{
			array[i] = ReadClass<T>();
		}
		return array;
	}

	public T[] ReadClass

BepInExPack/BepInEx/core/IndexRange.dll

Decompiled a month ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("Bradley Grainger")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyCopyright("Copyright 2019 Bradley Grainger")]
[assembly: AssemblyDescription("Implementations of System.Index and System.Range for netstandard2.0 and .NET Framework.")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+ea0d705a76aae25bcc5a24cbe2c654bcc77b1f76")]
[assembly: AssemblyProduct("IndexRange")]
[assembly: AssemblyTitle("IndexRange")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: TypeForwardedTo(typeof(Index))]
[assembly: TypeForwardedTo(typeof(Range))]

BepInExPack/BepInEx/core/LibAssemblyUnhollower.dll

Decompiled a month ago
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.IO.Compression;
using System.IO.MemoryMappedFiles;
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 System.Text.RegularExpressions;
using System.Threading.Tasks;
using AssemblyUnhollower.Contexts;
using AssemblyUnhollower.Extensions;
using AssemblyUnhollower.MetadataAccess;
using AssemblyUnhollower.Passes;
using AssemblyUnhollower.Utils;
using Iced.Intel;
using Microsoft.CodeAnalysis;
using Mono.Cecil;
using Mono.Cecil.Cil;
using Mono.Collections.Generic;
using UnhollowerBaseLib;
using UnhollowerBaseLib.Attributes;
using UnhollowerBaseLib.Maps;
using UnhollowerRuntimeLib;
using UnhollowerRuntimeLib.XrefScans;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("knah et al.")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.4.33.3")]
[assembly: AssemblyInformationalVersion("0.4.33.3")]
[assembly: AssemblyProduct("LibAssemblyUnhollower")]
[assembly: AssemblyTitle("LibAssemblyUnhollower")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.4.33.3")]
[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 IsUnmanagedAttribute : 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;
		}
	}
}
namespace UnhollowerRuntimeLib.XrefScans
{
	internal static class XrefScanMetadataGenerationUtil
	{
		internal static long MetadataInitForMethodRva;

		internal static IntPtr MetadataInitForMethodFileOffset;

		private static readonly (string Assembly, string Type, string Method)[] MetadataInitCandidates = new(string, string, string)[3]
		{
			("UnityEngine.CoreModule", "UnityEngine.Object", ".cctor"),
			("mscorlib", "System.Exception", "get_Message"),
			("mscorlib", "System.IntPtr", "Equals")
		};

		private static void FindMetadataInitForMethod(RewriteGlobalContext context, long gameAssemblyBase)
		{
			(string, string, string)[] metadataInitCandidates = MetadataInitCandidates;
			for (int i = 0; i < metadataInitCandidates.Length; i++)
			{
				(string Assembly, string Type, string Method) metadataInitCandidate = metadataInitCandidates[i];
				AssemblyRewriteContext? assemblyRewriteContext = context.Assemblies.FirstOrDefault((AssemblyRewriteContext it) => ((AssemblyNameReference)it.OriginalAssembly.Name).Name == metadataInitCandidate.Assembly);
				object obj;
				if (assemblyRewriteContext == null)
				{
					obj = null;
				}
				else
				{
					TypeRewriteContext? typeRewriteContext = assemblyRewriteContext.TryGetTypeByName(metadataInitCandidate.Type);
					obj = ((typeRewriteContext != null) ? ((IEnumerable<MethodDefinition>)typeRewriteContext.OriginalType.Methods).FirstOrDefault((Func<MethodDefinition, bool>)((MethodDefinition it) => ((MemberReference)it).Name == metadataInitCandidate.Method)) : null);
				}
				MethodDefinition val = (MethodDefinition)obj;
				if (val != null)
				{
					MetadataInitForMethodFileOffset = (IntPtr)(long)XrefScannerLowLevel.JumpTargets((IntPtr)(gameAssemblyBase + ((ICustomAttributeProvider)(object)val).ExtractOffset())).First();
					MetadataInitForMethodRva = (long)MetadataInitForMethodFileOffset - gameAssemblyBase - ((ICustomAttributeProvider)(object)val).ExtractOffset() + ((ICustomAttributeProvider)(object)val).ExtractRva();
					return;
				}
			}
			throw new ApplicationException("Unable to find a method with metadata init reference");
		}

		internal static (long FlagRva, long TokenRva) FindMetadataInitForMethod(MethodRewriteContext method, long gameAssemblyBase)
		{
			if (MetadataInitForMethodRva == 0L)
			{
				FindMetadataInitForMethod(method.DeclaringType.AssemblyContext.GlobalContext, gameAssemblyBase);
			}
			IntPtr intPtr = (IntPtr)(gameAssemblyBase + method.FileOffset);
			IntPtr intPtr2 = XrefScannerLowLevel.JumpTargets(intPtr).FirstOrDefault();
			if (intPtr2 != MetadataInitForMethodFileOffset || intPtr2 == IntPtr.Zero)
			{
				return (0L, 0L);
			}
			IntPtr intPtr3 = XrefScanUtilFinder.FindLastRcxReadAddressBeforeCallTo(intPtr, MetadataInitForMethodFileOffset);
			IntPtr intPtr4 = XrefScanUtilFinder.FindByteWriteTargetRightAfterCallTo(intPtr, MetadataInitForMethodFileOffset);
			if (intPtr3 == IntPtr.Zero || intPtr4 == IntPtr.Zero)
			{
				return (0L, 0L);
			}
			return ((long)intPtr4 - gameAssemblyBase - method.FileOffset + method.Rva, (long)intPtr3 - gameAssemblyBase - method.FileOffset + method.Rva);
		}
	}
}
namespace AssemblyUnhollower
{
	public class AssemblyKnownImports
	{
		private static readonly Dictionary<ModuleDefinition, AssemblyKnownImports> AssemblyMap = new Dictionary<ModuleDefinition, AssemblyKnownImports>();

		public readonly ModuleDefinition Module;

		private readonly RewriteGlobalContext myContext;

		private readonly Lazy<TypeReference> myVoidReference;

		private readonly Lazy<TypeReference> myIntPtrReference;

		private readonly Lazy<TypeReference> myStringReference;

		private readonly Lazy<TypeReference> myIntReference;

		private readonly Lazy<TypeReference> myLongReference;

		private readonly Lazy<TypeDefinition> myTypeReference;

		private readonly Lazy<TypeReference> myEnumReference;

		private readonly Lazy<TypeReference> myDelegateReference;

		private readonly Lazy<TypeReference> myMulticastDelegateReference;

		private readonly Lazy<TypeReference> myValueTypeReference;

		private readonly Lazy<TypeReference> myObjectReference;

		private readonly Lazy<TypeReference> myIl2CppClassPointerStoreReference;

		private readonly Lazy<TypeReference> myIl2CppObjectBaseReference;

		private readonly Lazy<TypeReference> myIl2CppReferenceArray;

		private readonly Lazy<TypeReference> myIl2CppStructArray;

		private readonly Lazy<TypeReference> myIl2CppStringArray;

		private readonly Lazy<MethodBase> myIl2CppReferenceArrayCtor;

		private readonly Lazy<MethodBase> myIl2CppStructArrayCtor;

		private readonly Lazy<MethodReference> myIl2CppStringArrayCtor;

		private readonly Lazy<TypeReference> myIl2CppArrayBase;

		private readonly Lazy<TypeReference> myIl2CppArrayBaseSetlfSubst;

		private readonly Lazy<TypeReference> myDefaultMemberAttribute;

		private readonly Lazy<MethodReference> myIl2CppObjectToPointer;

		private readonly Lazy<MethodReference> myIl2CppObjectToPointerNotNull;

		private readonly Lazy<MethodReference> myStringToNative;

		private readonly Lazy<MethodReference> myStringFromNative;

		private readonly Lazy<MethodReference> myIl2CppObjectCast;

		private readonly Lazy<MethodReference> myIl2CppObjectTryCast;

		private readonly Lazy<MethodReference> myIl2CppResolveICall;

		private readonly Lazy<MethodReference> myWriteFieldWBarrier;

		private readonly Lazy<MethodReference> myFieldGetOffset;

		private readonly Lazy<MethodReference> myFieldStaticGet;

		private readonly Lazy<MethodReference> myFieldStaticSet;

		private readonly Lazy<MethodReference> myRuntimeInvoke;

		private readonly Lazy<MethodReference> myRuntimeClassInit;

		private readonly Lazy<MethodReference> myObjectUnbox;

		private readonly Lazy<MethodReference> myObjectBox;

		private readonly Lazy<MethodReference> myValueSizeGet;

		private readonly Lazy<MethodReference> myObjectGetClass;

		private readonly Lazy<MethodReference> myClassIsValueType;

		private readonly Lazy<MethodReference> myRaiseExceptionIfNecessary;

		private readonly Lazy<MethodReference> myGetVirtualMethod;

		private readonly Lazy<MethodReference> myGetFieldPtr;

		private readonly Lazy<MethodReference> myGetIl2CppNestedClass;

		private readonly Lazy<MethodReference> myGetIl2CppGlobalClass;

		private readonly Lazy<MethodReference> myGetIl2CppMethod;

		private readonly Lazy<MethodReference> myGetIl2CppMethodFromToken;

		private readonly Lazy<MethodReference> myGetIl2CppTypeFromClass;

		private readonly Lazy<MethodReference> myGetIl2CppTypeToClass;

		private readonly Lazy<MethodReference> myIl2CppNewObject;

		private readonly Lazy<MethodReference> myIl2CppMethodInfoToReflection;

		private readonly Lazy<MethodReference> myIl2CppMethodInfoFromReflection;

		private readonly Lazy<MethodReference> myIl2CppPointerToGeneric;

		private readonly Lazy<MethodReference> myIl2CppRenderTypeNameGeneric;

		private readonly Lazy<MethodReference> myDelegateCombine;

		private readonly Lazy<MethodReference> myDelegateRemove;

		private readonly Lazy<MethodReference> myLdTokUnstrippedImpl;

		private readonly Lazy<MethodReference> myFlagsAttributeCtor;

		private readonly Lazy<MethodReference> myObsoleteAttributeCtor;

		private readonly Lazy<MethodReference> myNotSupportedExceptionCtor;

		private readonly Lazy<MethodReference> myObfuscatedNameAttributeCtor;

		private readonly Lazy<MethodReference> myCallerCountAttributeCtor;

		private readonly Lazy<MethodReference> myCachedScanResultsAttributeCtor;

		private readonly Lazy<MethodReference> myExtensionAttributeCtor;

		private readonly Lazy<MethodReference> myParamArrayAttributeCtor;

		public TypeReference Void => myVoidReference.Value;

		public TypeReference IntPtr => myIntPtrReference.Value;

		public TypeReference String => myStringReference.Value;

		public TypeReference Int => myIntReference.Value;

		public TypeReference Long => myLongReference.Value;

		public TypeDefinition Type => myTypeReference.Value;

		public TypeReference Enum => myEnumReference.Value;

		public TypeReference Delegate => myDelegateReference.Value;

		public TypeReference MulticastDelegate => myMulticastDelegateReference.Value;

		public TypeReference ValueType => myValueTypeReference.Value;

		public TypeReference Object => myObjectReference.Value;

		public TypeReference Il2CppClassPointerStore => myIl2CppClassPointerStoreReference.Value;

		public TypeReference Il2CppObjectBase => myIl2CppObjectBaseReference.Value;

		public TypeReference Il2CppReferenceArray => myIl2CppReferenceArray.Value;

		public TypeReference Il2CppStructArray => myIl2CppStructArray.Value;

		public TypeReference Il2CppStringArray => myIl2CppStringArray.Value;

		public MethodBase Il2CppReferenceArrayCtor => myIl2CppReferenceArrayCtor.Value;

		public MethodBase Il2CppStructArrayCtor => myIl2CppStructArrayCtor.Value;

		public MethodReference Il2CppStringArrayCtor => myIl2CppStringArrayCtor.Value;

		public TypeReference Il2CppArrayBase => myIl2CppArrayBase.Value;

		public TypeReference Il2CppArrayBaseSelfSubst => myIl2CppArrayBaseSetlfSubst.Value;

		public TypeReference DefaultMemberAttribute => myDefaultMemberAttribute.Value;

		public MethodReference Il2CppObjectBaseToPointer => myIl2CppObjectToPointer.Value;

		public MethodReference Il2CppObjectBaseToPointerNotNull => myIl2CppObjectToPointerNotNull.Value;

		public MethodReference StringToNative => myStringToNative.Value;

		public MethodReference StringFromNative => myStringFromNative.Value;

		public MethodReference Il2CppObjectCast => myIl2CppObjectCast.Value;

		public MethodReference Il2CppObjectTryCast => myIl2CppObjectTryCast.Value;

		public MethodReference Il2CppResolveICall => myIl2CppResolveICall.Value;

		public MethodReference WriteFieldWBarrier => myWriteFieldWBarrier.Value;

		public MethodReference FieldGetOffset => myFieldGetOffset.Value;

		public MethodReference FieldStaticGet => myFieldStaticGet.Value;

		public MethodReference FieldStaticSet => myFieldStaticSet.Value;

		public MethodReference RuntimeInvoke => myRuntimeInvoke.Value;

		public MethodReference RuntimeClassInit => myRuntimeClassInit.Value;

		public MethodReference ObjectUnbox => myObjectUnbox.Value;

		public MethodReference ObjectBox => myObjectBox.Value;

		public MethodReference ValueSizeGet => myValueSizeGet.Value;

		public MethodReference ClassIsValueType => myClassIsValueType.Value;

		public MethodReference ObjectGetClass => myObjectGetClass.Value;

		public MethodReference RaiseExceptionIfNecessary => myRaiseExceptionIfNecessary.Value;

		public MethodReference GetVirtualMethod => myGetVirtualMethod.Value;

		public MethodReference GetFieldPointer => myGetFieldPtr.Value;

		public MethodReference GetIl2CppNestedClass => myGetIl2CppNestedClass.Value;

		public MethodReference GetIl2CppGlobalClass => myGetIl2CppGlobalClass.Value;

		public MethodReference GetIl2CppMethod => myGetIl2CppMethod.Value;

		public MethodReference GetIl2CppMethodFromToken => myGetIl2CppMethodFromToken.Value;

		public MethodReference GetIl2CppTypeFromClass => myGetIl2CppTypeFromClass.Value;

		public MethodReference GetIl2CppTypeToClass => myGetIl2CppTypeToClass.Value;

		public MethodReference Il2CppNewObject => myIl2CppNewObject.Value;

		public MethodReference Il2CppMethodInfoToReflection => myIl2CppMethodInfoToReflection.Value;

		public MethodReference Il2CppMethodInfoFromReflection => myIl2CppMethodInfoFromReflection.Value;

		public MethodReference Il2CppPointerToGeneric => myIl2CppPointerToGeneric.Value;

		public MethodReference Il2CppRenderTypeNameGeneric => myIl2CppRenderTypeNameGeneric.Value;

		public MethodReference DelegateCombine => myDelegateCombine.Value;

		public MethodReference DelegateRemove => myDelegateRemove.Value;

		public MethodReference LdTokUnstrippedImpl => myLdTokUnstrippedImpl.Value;

		public MethodReference FlagsAttributeCtor => myFlagsAttributeCtor.Value;

		public MethodReference ObsoleteAttributeCtor => myObsoleteAttributeCtor.Value;

		public MethodReference NotSupportedExceptionCtor => myNotSupportedExceptionCtor.Value;

		public MethodReference ObfuscatedNameAttributeCtor => myObfuscatedNameAttributeCtor.Value;

		public MethodReference CallerCountAttributeCtor => myCallerCountAttributeCtor.Value;

		public MethodReference CachedScanResultsAttributeCtor => myCachedScanResultsAttributeCtor.Value;

		public MethodReference ExtensionAttributeCtor => myExtensionAttributeCtor.Value;

		public MethodReference ParamArrayAttributeCtor => myParamArrayAttributeCtor.Value;

		public static AssemblyKnownImports For(ModuleDefinition module, RewriteGlobalContext context)
		{
			RewriteGlobalContext context2 = context;
			return AssemblyMap.GetOrCreate(module, (ModuleDefinition mod) => new AssemblyKnownImports(mod, context2));
		}

		public AssemblyKnownImports(ModuleDefinition module, RewriteGlobalContext context)
		{
			Module = module;
			myContext = context;
			myVoidReference = new Lazy<TypeReference>((Func<TypeReference>)(() => Module.ImportReference(TargetTypeSystemHandler.Void)));
			myIntPtrReference = new Lazy<TypeReference>((Func<TypeReference>)(() => Module.ImportReference(TargetTypeSystemHandler.IntPtr)));
			myStringReference = new Lazy<TypeReference>((Func<TypeReference>)(() => Module.ImportReference((TypeReference)(object)TargetTypeSystemHandler.String)));
			myIntReference = new Lazy<TypeReference>((Func<TypeReference>)(() => Module.ImportReference((TypeReference)(object)TargetTypeSystemHandler.Int)));
			myLongReference = new Lazy<TypeReference>((Func<TypeReference>)(() => Module.ImportReference((TypeReference)(object)TargetTypeSystemHandler.Long)));
			myTypeReference = new Lazy<TypeDefinition>((Func<TypeDefinition>)(() => TargetTypeSystemHandler.Type));
			myEnumReference = new Lazy<TypeReference>((Func<TypeReference>)(() => Module.ImportReference(TargetTypeSystemHandler.Enum)));
			myDelegateReference = new Lazy<TypeReference>((Func<TypeReference>)(() => Module.ImportReference(TargetTypeSystemHandler.Delegate)));
			myMulticastDelegateReference = new Lazy<TypeReference>((Func<TypeReference>)(() => Module.ImportReference(TargetTypeSystemHandler.MulticastDelegate)));
			myValueTypeReference = new Lazy<TypeReference>((Func<TypeReference>)(() => Module.ImportReference(TargetTypeSystemHandler.ValueType)));
			myObjectReference = new Lazy<TypeReference>((Func<TypeReference>)(() => Module.ImportReference(TargetTypeSystemHandler.Object)));
			myIl2CppClassPointerStoreReference = new Lazy<TypeReference>((Func<TypeReference>)(() => Module.ImportReference(typeof(Il2CppClassPointerStore<>))));
			myIl2CppReferenceArray = new Lazy<TypeReference>((Func<TypeReference>)(() => Module.ImportReference(typeof(Il2CppReferenceArray<>))));
			myIl2CppStructArray = new Lazy<TypeReference>((Func<TypeReference>)(() => Module.ImportReference(typeof(Il2CppStructArray<>))));
			myIl2CppStringArray = new Lazy<TypeReference>((Func<TypeReference>)(() => Module.ImportReference(typeof(Il2CppStringArray))));
			myIl2CppReferenceArrayCtor = new Lazy<MethodBase>(delegate
			{
				return FindArrayConstructor(typeof(Il2CppReferenceArray<>));
				static ConstructorInfo FindArrayConstructor(Type type)
				{
					return type.GetConstructors().Single(delegate(ConstructorInfo constructorInfo)
					{
						ParameterInfo[] parameters = constructorInfo.GetParameters();
						return parameters.Length == 1 && parameters.Single().ParameterType.IsArray;
					});
				}
			});
			myIl2CppStructArrayCtor = new Lazy<MethodBase>(() => AssemblyKnownImports.<.ctor>g__FindArrayConstructor|199_15(typeof(Il2CppStructArray<>)));
			myIl2CppStringArrayCtor = new Lazy<MethodReference>((Func<MethodReference>)(() => Module.ImportReference((MethodBase)AssemblyKnownImports.<.ctor>g__FindArrayConstructor|199_15(typeof(Il2CppStringArray)))));
			myIl2CppArrayBase = new Lazy<TypeReference>((Func<TypeReference>)(() => Module.ImportReference(typeof(Il2CppArrayBase<>))));
			myIl2CppArrayBaseSetlfSubst = new Lazy<TypeReference>((Func<TypeReference>)delegate
			{
				//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_0032: Expected O, but got Unknown
				ModuleDefinition module2 = Module;
				GenericInstanceType val8 = new GenericInstanceType(Il2CppArrayBase);
				val8.GenericArguments.Add((TypeReference)(object)Il2CppArrayBase.GenericParameters[0]);
				return module2.ImportReference((TypeReference)val8);
			});
			myIl2CppObjectBaseReference = new Lazy<TypeReference>((Func<TypeReference>)(() => Module.ImportReference(typeof(Il2CppObjectBase))));
			myDefaultMemberAttribute = new Lazy<TypeReference>((Func<TypeReference>)(() => Module.ImportReference(TargetTypeSystemHandler.DefaultMemberAttribute)));
			myIl2CppObjectToPointer = new Lazy<MethodReference>((Func<MethodReference>)(() => Module.ImportReference((MethodBase)typeof(IL2CPP).GetMethod("Il2CppObjectBaseToPtr"))));
			myIl2CppObjectToPointerNotNull = new Lazy<MethodReference>((Func<MethodReference>)(() => Module.ImportReference((MethodBase)typeof(IL2CPP).GetMethod("Il2CppObjectBaseToPtrNotNull"))));
			myStringFromNative = new Lazy<MethodReference>((Func<MethodReference>)(() => Module.ImportReference((MethodBase)typeof(IL2CPP).GetMethod("Il2CppStringToManaged"))));
			myStringToNative = new Lazy<MethodReference>((Func<MethodReference>)(() => Module.ImportReference((MethodBase)typeof(IL2CPP).GetMethod("ManagedStringToIl2Cpp"))));
			myIl2CppObjectCast = new Lazy<MethodReference>((Func<MethodReference>)(() => Module.ImportReference((MethodBase)typeof(Il2CppObjectBase).GetMethod("Cast"))));
			myIl2CppObjectTryCast = new Lazy<MethodReference>((Func<MethodReference>)(() => Module.ImportReference((MethodBase)typeof(Il2CppObjectBase).GetMethod("TryCast"))));
			myIl2CppResolveICall = new Lazy<MethodReference>((Func<MethodReference>)(() => Module.ImportReference((MethodBase)typeof(IL2CPP).GetMethod("ResolveICall"))));
			myWriteFieldWBarrier = new Lazy<MethodReference>((Func<MethodReference>)(() => Module.ImportReference((MethodBase)(myContext.HasGcWbarrierFieldWrite ? typeof(IL2CPP).GetMethod("il2cpp_gc_wbarrier_set_field") : typeof(IL2CPP).GetMethod("FieldWriteWbarrierStub")))));
			myFieldGetOffset = new Lazy<MethodReference>((Func<MethodReference>)(() => Module.ImportReference((MethodBase)typeof(IL2CPP).GetMethod("il2cpp_field_get_offset"))));
			myFieldStaticGet = new Lazy<MethodReference>((Func<MethodReference>)(() => Module.ImportReference((MethodBase)typeof(IL2CPP).GetMethod("il2cpp_field_static_get_value"))));
			myFieldStaticSet = new Lazy<MethodReference>((Func<MethodReference>)(() => Module.ImportReference((MethodBase)typeof(IL2CPP).GetMethod("il2cpp_field_static_set_value"))));
			myRuntimeInvoke = new Lazy<MethodReference>((Func<MethodReference>)(() => Module.ImportReference((MethodBase)typeof(IL2CPP).GetMethod("il2cpp_runtime_invoke"))));
			myRuntimeClassInit = new Lazy<MethodReference>((Func<MethodReference>)(() => Module.ImportReference((MethodBase)typeof(IL2CPP).GetMethod("il2cpp_runtime_class_init"))));
			myObjectUnbox = new Lazy<MethodReference>((Func<MethodReference>)(() => Module.ImportReference((MethodBase)typeof(IL2CPP).GetMethod("il2cpp_object_unbox"))));
			myObjectBox = new Lazy<MethodReference>((Func<MethodReference>)(() => Module.ImportReference((MethodBase)typeof(IL2CPP).GetMethod("il2cpp_value_box"))));
			myValueSizeGet = new Lazy<MethodReference>((Func<MethodReference>)(() => Module.ImportReference((MethodBase)typeof(IL2CPP).GetMethod("il2cpp_class_value_size"))));
			myObjectGetClass = new Lazy<MethodReference>((Func<MethodReference>)(() => Module.ImportReference((MethodBase)typeof(IL2CPP).GetMethod("il2cpp_object_get_class"))));
			myClassIsValueType = new Lazy<MethodReference>((Func<MethodReference>)(() => Module.ImportReference((MethodBase)typeof(IL2CPP).GetMethod("il2cpp_class_is_valuetype"))));
			myRaiseExceptionIfNecessary = new Lazy<MethodReference>((Func<MethodReference>)(() => Module.ImportReference((MethodBase)typeof(Il2CppException).GetMethod("RaiseExceptionIfNecessary"))));
			myGetVirtualMethod = new Lazy<MethodReference>((Func<MethodReference>)(() => Module.ImportReference((MethodBase)typeof(IL2CPP).GetMethod("il2cpp_object_get_virtual_method"))));
			myGetFieldPtr = new Lazy<MethodReference>((Func<MethodReference>)(() => Module.ImportReference((MethodBase)typeof(IL2CPP).GetMethod("GetIl2CppField"))));
			myGetIl2CppNestedClass = new Lazy<MethodReference>((Func<MethodReference>)(() => Module.ImportReference((MethodBase)typeof(IL2CPP).GetMethod("GetIl2CppNestedType"))));
			myGetIl2CppGlobalClass = new Lazy<MethodReference>((Func<MethodReference>)(() => Module.ImportReference((MethodBase)typeof(IL2CPP).GetMethod("GetIl2CppClass"))));
			myGetIl2CppMethod = new Lazy<MethodReference>((Func<MethodReference>)(() => Module.ImportReference((MethodBase)typeof(IL2CPP).GetMethod("GetIl2CppMethod"))));
			myGetIl2CppMethodFromToken = new Lazy<MethodReference>((Func<MethodReference>)(() => Module.ImportReference((MethodBase)typeof(IL2CPP).GetMethod("GetIl2CppMethodByToken"))));
			myGetIl2CppTypeFromClass = new Lazy<MethodReference>((Func<MethodReference>)(() => Module.ImportReference((MethodBase)typeof(IL2CPP).GetMethod("il2cpp_class_get_type"))));
			myGetIl2CppTypeToClass = new Lazy<MethodReference>((Func<MethodReference>)(() => Module.ImportReference((MethodBase)typeof(IL2CPP).GetMethod("il2cpp_class_from_type"))));
			myIl2CppNewObject = new Lazy<MethodReference>((Func<MethodReference>)(() => Module.ImportReference((MethodBase)typeof(IL2CPP).GetMethod("il2cpp_object_new"))));
			myIl2CppMethodInfoFromReflection = new Lazy<MethodReference>((Func<MethodReference>)(() => Module.ImportReference((MethodBase)typeof(IL2CPP).GetMethod("il2cpp_method_get_from_reflection"))));
			myIl2CppMethodInfoToReflection = new Lazy<MethodReference>((Func<MethodReference>)(() => Module.ImportReference((MethodBase)typeof(IL2CPP).GetMethod("il2cpp_method_get_object"))));
			myIl2CppPointerToGeneric = new Lazy<MethodReference>((Func<MethodReference>)(() => Module.ImportReference((MethodBase)typeof(IL2CPP).GetMethod("PointerToValueGeneric"))));
			myIl2CppRenderTypeNameGeneric = new Lazy<MethodReference>((Func<MethodReference>)(() => Module.ImportReference((MethodBase)typeof(IL2CPP).GetMethod("RenderTypeName", new Type[1] { typeof(bool) }))));
			myDelegateCombine = new Lazy<MethodReference>((Func<MethodReference>)(() => Module.ImportReference((MethodReference)(object)((IEnumerable<MethodDefinition>)myContext.GetAssemblyByName("mscorlib").NewAssembly.MainModule.GetType("Il2CppSystem.Delegate").Methods).Single((MethodDefinition m) => ((MemberReference)m).Name == "Combine" && ((MethodReference)m).Parameters.Count == 2))));
			myDelegateRemove = new Lazy<MethodReference>((Func<MethodReference>)(() => Module.ImportReference((MethodReference)(object)((IEnumerable<MethodDefinition>)myContext.GetAssemblyByName("mscorlib").NewAssembly.MainModule.GetType("Il2CppSystem.Delegate").Methods).Single((MethodDefinition m) => ((MemberReference)m).Name == "Remove"))));
			myLdTokUnstrippedImpl = new Lazy<MethodReference>((Func<MethodReference>)delegate
			{
				//IL_004d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0052: Unknown result type (might be due to invalid IL or missing references)
				//IL_005a: 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
				TypeReference val5 = Module.ImportReference(typeof(RuntimeReflectionHelper));
				TypeReference val6 = Module.ImportReference((TypeReference)(object)myContext.GetAssemblyByName("mscorlib").NewAssembly.MainModule.GetType("Il2CppSystem.RuntimeTypeHandle"));
				MethodReference val7 = new MethodReference("GetRuntimeTypeHandle", val6, val5)
				{
					HasThis = false
				};
				val7.GenericParameters.Add(new GenericParameter("T", (IGenericParameterProvider)(object)val7));
				return Module.ImportReference(val7);
			});
			myFlagsAttributeCtor = new Lazy<MethodReference>((Func<MethodReference>)(() => new MethodReference(".ctor", Void, Module.ImportReference(TargetTypeSystemHandler.FlagsAttribute))
			{
				HasThis = true
			}));
			myObsoleteAttributeCtor = new Lazy<MethodReference>((Func<MethodReference>)delegate
			{
				//IL_001b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0020: Unknown result type (might be due to invalid IL or missing references)
				//IL_0027: 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_003d: Expected O, but got Unknown
				//IL_003e: Expected O, but got Unknown
				MethodReference val4 = new MethodReference(".ctor", Void, Module.ImportReference(TargetTypeSystemHandler.ObsoleteAttribute))
				{
					HasThis = true
				};
				val4.Parameters.Add(new ParameterDefinition(String));
				return val4;
			});
			myNotSupportedExceptionCtor = new Lazy<MethodReference>((Func<MethodReference>)delegate
			{
				//IL_001b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0020: Unknown result type (might be due to invalid IL or missing references)
				//IL_0027: 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_003d: Expected O, but got Unknown
				//IL_003e: Expected O, but got Unknown
				MethodReference val3 = new MethodReference(".ctor", Void, Module.ImportReference(TargetTypeSystemHandler.NotSupportedException))
				{
					HasThis = true
				};
				val3.Parameters.Add(new ParameterDefinition(String));
				return val3;
			});
			myObfuscatedNameAttributeCtor = new Lazy<MethodReference>((Func<MethodReference>)delegate
			{
				//IL_0020: 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_002c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0038: Unknown result type (might be due to invalid IL or missing references)
				//IL_0042: Expected O, but got Unknown
				//IL_0043: Expected O, but got Unknown
				MethodReference val2 = new MethodReference(".ctor", Void, Module.ImportReference(typeof(ObfuscatedNameAttribute)))
				{
					HasThis = true
				};
				val2.Parameters.Add(new ParameterDefinition(String));
				return val2;
			});
			myCallerCountAttributeCtor = new Lazy<MethodReference>((Func<MethodReference>)delegate
			{
				//IL_0020: 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_002c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0038: Unknown result type (might be due to invalid IL or missing references)
				//IL_0042: Expected O, but got Unknown
				//IL_0043: Expected O, but got Unknown
				MethodReference val = new MethodReference(".ctor", Void, Module.ImportReference(typeof(CallerCountAttribute)))
				{
					HasThis = true
				};
				val.Parameters.Add(new ParameterDefinition(Int));
				return val;
			});
			myCachedScanResultsAttributeCtor = new Lazy<MethodReference>((Func<MethodReference>)(() => new MethodReference(".ctor", Void, Module.ImportReference(typeof(CachedScanResultsAttribute)))
			{
				HasThis = true
			}));
			myExtensionAttributeCtor = new Lazy<MethodReference>((Func<MethodReference>)(() => new MethodReference(".ctor", Void, Module.ImportReference(typeof(ExtensionAttribute)))
			{
				HasThis = true
			}));
			myParamArrayAttributeCtor = new Lazy<MethodReference>((Func<MethodReference>)(() => new MethodReference(".ctor", Void, Module.ImportReference(typeof(ParamArrayAttribute)))
			{
				HasThis = true
			}));
		}
	}
	public static class DeobfuscationMapGenerator
	{
		public static void AnalyzeDeobfuscationParams(UnhollowerOptions options)
		{
			IIl2CppMetadataAccess gameAssemblies;
			using (new TimingCookie("Reading assemblies"))
			{
				gameAssemblies = new CecilMetadataAccess(options.Source);
			}
			RewriteGlobalContext rewriteGlobalContext;
			using (new TimingCookie("Creating assembly contexts"))
			{
				rewriteGlobalContext = new RewriteGlobalContext(options, gameAssemblies, NullMetadataAccess.Instance, NullMetadataAccess.Instance);
			}
			for (int i = 1; i <= 3; i++)
			{
				for (int j = 3; j <= 15; j++)
				{
					options.TypeDeobfuscationCharsPerUniquifier = i;
					options.TypeDeobfuscationMaxUniquifiers = j;
					rewriteGlobalContext.RenamedTypes.Clear();
					rewriteGlobalContext.RenameGroups.Clear();
					Pass05CreateRenameGroups.DoPass(rewriteGlobalContext);
					int num = rewriteGlobalContext.RenameGroups.Values.Count((List<TypeDefinition> it) => it.Count == 1);
					int num2 = rewriteGlobalContext.RenameGroups.Values.Count((List<TypeDefinition> it) => it.Count > 1);
					Console.WriteLine($"Chars=\t{i}\tMaxU=\t{j}\tUniq=\t{num}\tNonUniq=\t{num2}");
				}
			}
		}

		public static void GenerateDeobfuscationMap(UnhollowerOptions options)
		{
			if (options.Source == null || !options.Source.Any())
			{
				Console.WriteLine("No input specified; use -h for help");
				return;
			}
			if (string.IsNullOrEmpty(options.OutputDir))
			{
				Console.WriteLine("No target dir specified; use -h for help");
				return;
			}
			if (string.IsNullOrEmpty(options.DeobfuscationNewAssembliesPath))
			{
				Console.WriteLine("No obfuscated assembly path specified; use -h for help");
				return;
			}
			if (!Directory.Exists(options.OutputDir))
			{
				Directory.CreateDirectory(options.OutputDir);
			}
			IIl2CppMetadataAccess gameAssemblies;
			using (new TimingCookie("Reading assemblies"))
			{
				gameAssemblies = new CecilMetadataAccess(Directory.EnumerateFiles(options.DeobfuscationNewAssembliesPath, "*.dll"));
			}
			IIl2CppMetadataAccess systemAssemblies;
			using (new TimingCookie("Reading system assemblies"))
			{
				systemAssemblies = (string.IsNullOrEmpty(options.SystemLibrariesPath) ? new CecilMetadataAccess(new string[1] { options.MscorlibPath }) : new CecilMetadataAccess(from it in Directory.EnumerateFiles(options.SystemLibrariesPath, "*.dll")
					where Path.GetFileName(it).StartsWith("System.") || Path.GetFileName(it) == "mscorlib.dll" || Path.GetFileName(it) == "netstandard.dll"
					select it));
			}
			RewriteGlobalContext rewriteGlobalContext;
			using (new TimingCookie("Creating rewrite assemblies"))
			{
				rewriteGlobalContext = new RewriteGlobalContext(options, gameAssemblies, systemAssemblies, NullMetadataAccess.Instance);
			}
			using (new TimingCookie("Computing renames"))
			{
				Pass05CreateRenameGroups.DoPass(rewriteGlobalContext);
			}
			using (new TimingCookie("Creating typedefs"))
			{
				Pass10CreateTypedefs.DoPass(rewriteGlobalContext);
			}
			using (new TimingCookie("Computing struct blittability"))
			{
				Pass11ComputeTypeSpecifics.DoPass(rewriteGlobalContext);
			}
			using (new TimingCookie("Filling typedefs"))
			{
				Pass12FillTypedefs.DoPass(rewriteGlobalContext);
			}
			using (new TimingCookie("Filling generic constraints"))
			{
				Pass13FillGenericConstraints.DoPass(rewriteGlobalContext);
			}
			using (new TimingCookie("Creating members"))
			{
				Pass15GenerateMemberContexts.DoPass(rewriteGlobalContext);
			}
			IIl2CppMetadataAccess gameAssemblies2;
			using (new TimingCookie("Reading clean assemblies"))
			{
				gameAssemblies2 = new CecilMetadataAccess(options.Source);
			}
			RewriteGlobalContext rewriteGlobalContext2;
			using (new TimingCookie("Creating clean rewrite assemblies"))
			{
				rewriteGlobalContext2 = new RewriteGlobalContext(options, gameAssemblies2, systemAssemblies, NullMetadataAccess.Instance);
			}
			using (new TimingCookie("Computing clean assembly renames"))
			{
				Pass05CreateRenameGroups.DoPass(rewriteGlobalContext2);
			}
			using (new TimingCookie("Creating clean assembly typedefs"))
			{
				Pass10CreateTypedefs.DoPass(rewriteGlobalContext2);
			}
			Dictionary<TypeDefinition, (string OldName, int Penalty, bool ForceNs)> usedNames = new Dictionary<TypeDefinition, (string, int, bool)>();
			StreamWriter writer;
			using (FileStream stream = new FileStream(options.OutputDir + Path.DirectorySeparatorChar + "RenameMap.csv.gz", FileMode.Create, FileAccess.Write))
			{
				using GZipStream stream2 = new GZipStream(stream, CompressionLevel.Optimal, leaveOpen: true);
				writer = new StreamWriter(stream2, Encoding.UTF8, 65536, leaveOpen: true);
				try
				{
					foreach (AssemblyRewriteContext assembly in rewriteGlobalContext.Assemblies)
					{
						if (options.DeobfuscationGenerationAssemblies.Count > 0 && !options.DeobfuscationGenerationAssemblies.Contains(((AssemblyNameReference)assembly.NewAssembly.Name).Name))
						{
							continue;
						}
						AssemblyRewriteContext cleanAssembly = rewriteGlobalContext2.GetAssemblyByName(((AssemblyNameReference)assembly.OriginalAssembly.Name).Name);
						foreach (TypeRewriteContext type in assembly.Types)
						{
							if (type.NewType.DeclaringType == null)
							{
								DoType(type, null);
							}
						}
						void DoType(TypeRewriteContext typeContext, TypeRewriteContext? enclosingType)
						{
							//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
							//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
							if (typeContext.OriginalNameWasObfuscated)
							{
								(TypeRewriteContext, int) tuple = FindBestMatchType(typeContext, cleanAssembly, enclosingType);
								if (tuple.Item1 != null && (!usedNames.TryGetValue(tuple.Item1.NewType, out (string, int, bool) value) || value.Item2 < tuple.Item2))
								{
									usedNames[tuple.Item1.NewType] = (((TypeReference)(object)typeContext.NewType).GetNamespacePrefix() + "." + ((MemberReference)typeContext.NewType).Name, tuple.Item2, ((TypeReference)typeContext.OriginalType).Namespace != ((TypeReference)tuple.Item1.OriginalType).Namespace);
									if (typeContext.OriginalType.IsEnum)
									{
										DoEnum(typeContext, tuple.Item1);
									}
									Enumerator<TypeDefinition> enumerator5 = typeContext.OriginalType.NestedTypes.GetEnumerator();
									try
									{
										while (enumerator5.MoveNext())
										{
											TypeDefinition current5 = enumerator5.Current;
											DoType(typeContext.AssemblyContext.GetContextForOriginalType(current5), tuple.Item1);
										}
									}
									finally
									{
										((IDisposable)enumerator5).Dispose();
									}
								}
							}
						}
					}
					foreach (KeyValuePair<TypeDefinition, (string, int, bool)> item in usedNames)
					{
						writer.WriteLine(item.Value.Item1 + ";" + (item.Value.Item3 ? (((TypeReference)item.Key).Namespace + ".") : "") + ((MemberReference)item.Key).Name + ";" + item.Value.Item2);
					}
					LogSupport.Info("Done!");
					rewriteGlobalContext.Dispose();
				}
				finally
				{
					if (writer != null)
					{
						((IDisposable)writer).Dispose();
					}
				}
			}
			void DoEnum(TypeRewriteContext obfuscatedType, TypeRewriteContext cleanType)
			{
				//IL_000b: 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)
				Enumerator<FieldDefinition> enumerator4 = obfuscatedType.OriginalType.Fields.GetEnumerator();
				try
				{
					while (enumerator4.MoveNext())
					{
						FieldDefinition current4 = enumerator4.Current;
						if (((MemberReference)current4).Name.IsObfuscated(obfuscatedType.AssemblyContext.GlobalContext.Options))
						{
							FieldDefinition val = cleanType.OriginalType.Fields[obfuscatedType.OriginalType.Fields.IndexOf(current4)];
							writer.WriteLine(((TypeReference)(object)obfuscatedType.NewType).GetNamespacePrefix() + "." + ((MemberReference)obfuscatedType.NewType).Name + "::" + Pass22GenerateEnums.GetUnmangledName(current4) + ";" + ((MemberReference)val).Name + ";0");
						}
					}
				}
				finally
				{
					((IDisposable)enumerator4).Dispose();
				}
			}
		}

		private static (TypeRewriteContext?, int) FindBestMatchType(TypeRewriteContext obfType, AssemblyRewriteContext cleanAssembly, TypeRewriteContext? enclosingCleanType)
		{
			//IL_02b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_0380: Unknown result type (might be due to invalid IL or missing references)
			//IL_0385: Unknown result type (might be due to invalid IL or missing references)
			AssemblyRewriteContext cleanAssembly2 = cleanAssembly;
			int num = 0;
			TypeReference baseType = obfType.OriginalType.BaseType;
			while (baseType != null)
			{
				TypeRewriteContext typeRewriteContext = obfType.AssemblyContext.GlobalContext.TryGetNewTypeForOriginal(baseType.Resolve());
				if (typeRewriteContext == null || !typeRewriteContext.OriginalNameWasObfuscated)
				{
					break;
				}
				num++;
				baseType = typeRewriteContext.OriginalType.BaseType;
			}
			int num2 = int.MinValue;
			TypeRewriteContext item = null;
			foreach (TypeRewriteContext item2 in ((enclosingCleanType != null) ? ((IEnumerable<TypeDefinition>)enclosingCleanType.OriginalType.NestedTypes).Select((TypeDefinition it) => cleanAssembly2.GlobalContext.GetNewTypeForOriginal(it)) : null) ?? cleanAssembly2.Types.Where((TypeRewriteContext it) => it.NewType.DeclaringType == null))
			{
				if (obfType.OriginalType.HasMethods != item2.OriginalType.HasMethods || obfType.OriginalType.HasFields != item2.OriginalType.HasFields || (obfType.OriginalType.IsEnum && obfType.OriginalType.Fields.Count != item2.OriginalType.Fields.Count))
				{
					continue;
				}
				int num3 = 0;
				TypeReference val = item2.OriginalType.BaseType;
				int num4 = 0;
				while (val != null && (!(((val != null) ? ((MemberReference)val).Name : null) == ((baseType != null) ? ((MemberReference)baseType).Name : null)) || !(((val != null) ? val.Namespace : null) == ((baseType != null) ? baseType.Namespace : null))))
				{
					val = ((val != null) ? val.Resolve().BaseType : null);
					num4++;
				}
				if (val == null && baseType != null)
				{
					continue;
				}
				int num5 = Math.Abs(num4 - num);
				if (num5 > 1)
				{
					continue;
				}
				num3 -= num5 * 50;
				num3 -= Math.Abs(item2.OriginalType.Fields.Count - obfType.OriginalType.Fields.Count) * 5;
				num3 -= Math.Abs(obfType.OriginalType.NestedTypes.Count - item2.OriginalType.NestedTypes.Count) * 10;
				num3 -= Math.Abs(obfType.OriginalType.Properties.Count - item2.OriginalType.Properties.Count) * 5;
				num3 -= Math.Abs(obfType.OriginalType.Interfaces.Count - item2.OriginalType.Interfaces.Count) * 35;
				UnhollowerOptions options = obfType.AssemblyContext.GlobalContext.Options;
				Enumerator<FieldDefinition> enumerator2 = obfType.OriginalType.Fields.GetEnumerator();
				try
				{
					while (enumerator2.MoveNext())
					{
						FieldDefinition obfuscatedField = enumerator2.Current;
						if (((MemberReference)obfuscatedField).Name.IsObfuscated(options))
						{
							int num6 = ((IEnumerable<FieldDefinition>)item2.OriginalType.Fields).Max((FieldDefinition it) => TypeMatchWeight(((FieldReference)obfuscatedField).FieldType, ((FieldReference)it).FieldType, options));
							num3 += num6 * ((num6 < 0) ? 10 : 2);
						}
						else if (((IEnumerable<FieldDefinition>)item2.OriginalType.Fields).Any((FieldDefinition it) => ((MemberReference)it).Name == ((MemberReference)obfuscatedField).Name))
						{
							num3 += 10;
						}
					}
				}
				finally
				{
					((IDisposable)enumerator2).Dispose();
				}
				Enumerator<MethodDefinition> enumerator3 = obfType.OriginalType.Methods.GetEnumerator();
				try
				{
					while (enumerator3.MoveNext())
					{
						MethodDefinition obfuscatedMethod = enumerator3.Current;
						if (((MemberReference)obfuscatedMethod).Name.Contains(".ctor"))
						{
							continue;
						}
						if (((MemberReference)obfuscatedMethod).Name.IsObfuscated(options))
						{
							int num7 = ((IEnumerable<MethodDefinition>)item2.OriginalType.Methods).Max((MethodDefinition it) => MethodSignatureMatchWeight(obfuscatedMethod, it, options));
							num3 += num7 * ((num7 >= 0) ? 1 : 10);
						}
						else if (((IEnumerable<MethodDefinition>)item2.OriginalType.Methods).Any((MethodDefinition it) => ((MemberReference)it).Name == ((MemberReference)obfuscatedMethod).Name))
						{
							num3 += ((MemberReference)obfuscatedMethod).Name.Length / 10 * 5 + 1;
						}
					}
				}
				finally
				{
					((IDisposable)enumerator3).Dispose();
				}
				if (num3 == num2)
				{
					item = null;
				}
				else if (num3 > num2)
				{
					num2 = num3;
					item = item2;
				}
			}
			return (item, num2);
		}

		private static int TypeMatchWeight(TypeReference a, TypeReference b, UnhollowerOptions options)
		{
			if (((object)a).GetType() != ((object)b).GetType())
			{
				return -1;
			}
			int runningSum = 0;
			ArrayType val = (ArrayType)(object)((a is ArrayType) ? a : null);
			if (val == null)
			{
				ByReferenceType val2 = (ByReferenceType)(object)((a is ByReferenceType) ? a : null);
				if (val2 == null)
				{
					GenericInstanceType val3 = (GenericInstanceType)(object)((a is GenericInstanceType) ? a : null);
					if (val3 == null)
					{
						if (a is GenericParameter)
						{
							if (!(b is GenericParameter))
							{
								return -1;
							}
							return 5;
						}
						if (a.IsNested)
						{
							if (!b.IsNested)
							{
								return -1;
							}
							if (((MemberReference)a).Name.IsObfuscated(options))
							{
								return 0;
							}
							if (TypeMatchWeight(((MemberReference)a).DeclaringType, ((MemberReference)b).DeclaringType, options) == -1 || ((MemberReference)a).Name != ((MemberReference)b).Name)
							{
								return -1;
							}
							return 1;
						}
						if (((MemberReference)a).Name.IsObfuscated(options))
						{
							return 0;
						}
						if (!(((MemberReference)a).Name == ((MemberReference)b).Name) || !(a.Namespace == b.Namespace))
						{
							return -1;
						}
						return 1;
					}
					GenericInstanceType val4 = (GenericInstanceType)(object)((b is GenericInstanceType) ? b : null);
					if (val4 == null)
					{
						return -1;
					}
					if (val3.GenericArguments.Count != val4.GenericArguments.Count)
					{
						return -1;
					}
					Accumulate(TypeMatchWeight(((TypeSpecification)val3).ElementType, ((TypeSpecification)val4).ElementType, options));
					for (int j = 0; j < val3.GenericArguments.Count; j++)
					{
						Accumulate(TypeMatchWeight(val3.GenericArguments[j], val4.GenericArguments[j], options));
					}
					return runningSum * 5;
				}
				ByReferenceType val5 = (ByReferenceType)(object)((b is ByReferenceType) ? b : null);
				if (val5 == null)
				{
					return -1;
				}
				return TypeMatchWeight(((TypeSpecification)val2).ElementType, ((TypeSpecification)val5).ElementType, options) * 5;
			}
			ArrayType val6 = (ArrayType)(object)((b is ArrayType) ? b : null);
			if (val6 == null)
			{
				return -1;
			}
			return TypeMatchWeight(((TypeSpecification)val).ElementType, ((TypeSpecification)val6).ElementType, options) * 5;
			void Accumulate(int i)
			{
				if (i < 0 || runningSum < 0)
				{
					runningSum = -1;
				}
				else
				{
					runningSum += i;
				}
			}
		}

		private static int MethodSignatureMatchWeight(MethodDefinition a, MethodDefinition b, UnhollowerOptions options)
		{
			//IL_0027: 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_002f: 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)
			if (((MethodReference)a).Parameters.Count != ((MethodReference)b).Parameters.Count || a.IsStatic != b.IsStatic || (a.Attributes & 7) != (b.Attributes & 7))
			{
				return -1;
			}
			int runningSum = TypeMatchWeight(((MethodReference)a).ReturnType, ((MethodReference)b).ReturnType, options);
			if (runningSum == -1)
			{
				return -1;
			}
			for (int j = 0; j < ((MethodReference)a).Parameters.Count; j++)
			{
				Accumulate(TypeMatchWeight(((ParameterReference)((MethodReference)a).Parameters[j]).ParameterType, ((ParameterReference)((MethodReference)b).Parameters[j]).ParameterType, options));
			}
			return runningSum * (((MethodReference)a).Parameters.Count + 1);
			void Accumulate(int i)
			{
				if (i < 0 || runningSum < 0)
				{
					runningSum = -1;
				}
				else
				{
					runningSum += i;
				}
			}
		}
	}
	public static class FieldAccessorGenerator
	{
		public static void MakeGetter(FieldDefinition field, FieldRewriteContext fieldContext, PropertyDefinition property, AssemblyKnownImports imports)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Expected O, but got Unknown
			//IL_020c: Unknown result type (might be due to invalid IL or missing references)
			//IL_021d: Unknown result type (might be due to invalid IL or missing references)
			//IL_022e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0239: Unknown result type (might be due to invalid IL or missing references)
			//IL_025c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0276: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Expected O, but got Unknown
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Expected O, but got Unknown
			//IL_00e3: 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_00ff: Expected O, but got Unknown
			//IL_0100: 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)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			MethodDefinition val = new MethodDefinition("get_" + ((MemberReference)property).Name, (MethodAttributes)(Field2MethodAttrs(field.Attributes) | 0x800 | 0x80), ((PropertyReference)property).PropertyType);
			ILProcessor iLProcessor = val.Body.GetILProcessor();
			property.DeclaringType.Methods.Add(val);
			if (field.IsStatic)
			{
				VariableDefinition val2 = new VariableDefinition((TypeReference)(((PropertyReference)property).PropertyType.IsValueType ? ((object)((PropertyReference)property).PropertyType) : ((object)imports.IntPtr)));
				val.Body.Variables.Add(val2);
				bool flag = false;
				if (((FieldReference)field).FieldType.IsValueType && !((PropertyReference)property).PropertyType.IsValueType)
				{
					GenericInstanceType val3 = new GenericInstanceType(imports.Il2CppClassPointerStore);
					val3.GenericArguments.Add(((PropertyReference)property).PropertyType);
					TypeReference val4 = ((MemberReference)property.DeclaringType).Module.ImportReference((TypeReference)(object)val3);
					iLProcessor.Emit(OpCodes.Ldsfld, new FieldReference("NativeClassPtr", imports.IntPtr, val4));
					iLProcessor.Emit(OpCodes.Ldc_I4, 0);
					iLProcessor.Emit(OpCodes.Conv_U);
					iLProcessor.Emit(OpCodes.Call, imports.ValueSizeGet);
					iLProcessor.Emit(OpCodes.Conv_U);
					iLProcessor.Emit(OpCodes.Localloc);
					iLProcessor.Emit(OpCodes.Stloc, val2);
					flag = true;
				}
				iLProcessor.Emit(OpCodes.Ldsfld, fieldContext.PointerField);
				if (flag)
				{
					iLProcessor.Emit(OpCodes.Ldloc, val2);
				}
				else
				{
					iLProcessor.Emit(OpCodes.Ldloca_S, val2);
				}
				iLProcessor.Emit(OpCodes.Conv_U);
				iLProcessor.Emit(OpCodes.Call, imports.FieldStaticGet);
				if (((PropertyReference)property).PropertyType.IsValueType)
				{
					iLProcessor.Emit(OpCodes.Ldloc, val2);
					iLProcessor.Emit(OpCodes.Ret);
					property.GetMethod = val;
					return;
				}
			}
			else
			{
				VariableDefinition val5 = new VariableDefinition(imports.IntPtr);
				val.Body.Variables.Add(val5);
				iLProcessor.EmitObjectToPointer((TypeReference)(object)fieldContext.DeclaringType.OriginalType, (TypeReference)(object)fieldContext.DeclaringType.NewType, fieldContext.DeclaringType, 0, valueTypeArgument0IsAPointer: false, allowNullable: false, unboxNonBlittableType: false, out VariableDefinition _);
				iLProcessor.Emit(OpCodes.Ldsfld, fieldContext.PointerField);
				iLProcessor.Emit(OpCodes.Call, imports.FieldGetOffset);
				iLProcessor.Emit(OpCodes.Add);
				iLProcessor.Emit(OpCodes.Stloc_0);
			}
			iLProcessor.EmitPointerToObject(((FieldReference)fieldContext.OriginalField).FieldType, ((PropertyReference)property).PropertyType, fieldContext.DeclaringType, iLProcessor.Create(OpCodes.Ldloc_0), !field.IsStatic, unboxValueType: false);
			iLProcessor.Emit(OpCodes.Ret);
			property.GetMethod = val;
		}

		public static void MakeSetter(FieldDefinition field, FieldRewriteContext fieldContext, PropertyDefinition property, AssemblyKnownImports imports)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Expected O, but got Unknown
			//IL_00d9: 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)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			MethodDefinition val = new MethodDefinition("set_" + ((MemberReference)property).Name, (MethodAttributes)(Field2MethodAttrs(field.Attributes) | 0x800 | 0x80), imports.Void);
			((MethodReference)val).Parameters.Add(new ParameterDefinition(((PropertyReference)property).PropertyType));
			property.DeclaringType.Methods.Add(val);
			ILProcessor iLProcessor = val.Body.GetILProcessor();
			VariableDefinition refVariable;
			if (field.IsStatic)
			{
				iLProcessor.Emit(OpCodes.Ldsfld, fieldContext.PointerField);
				iLProcessor.EmitObjectToPointer(((FieldReference)field).FieldType, ((PropertyReference)property).PropertyType, fieldContext.DeclaringType, 0, valueTypeArgument0IsAPointer: false, allowNullable: true, unboxNonBlittableType: true, out refVariable);
				iLProcessor.Emit(OpCodes.Call, imports.FieldStaticSet);
			}
			else
			{
				iLProcessor.EmitObjectToPointer((TypeReference)(object)fieldContext.DeclaringType.OriginalType, (TypeReference)(object)fieldContext.DeclaringType.NewType, fieldContext.DeclaringType, 0, valueTypeArgument0IsAPointer: false, allowNullable: false, unboxNonBlittableType: false, out refVariable);
				iLProcessor.Emit(OpCodes.Dup);
				iLProcessor.Emit(OpCodes.Ldsfld, fieldContext.PointerField);
				iLProcessor.Emit(OpCodes.Call, imports.FieldGetOffset);
				iLProcessor.Emit(OpCodes.Add);
				iLProcessor.EmitObjectStore(((FieldReference)field).FieldType, ((PropertyReference)property).PropertyType, fieldContext.DeclaringType, 1);
			}
			iLProcessor.Emit(OpCodes.Ret);
			property.SetMethod = val;
		}

		private static MethodAttributes Field2MethodAttrs(FieldAttributes fieldAttributes)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			if ((fieldAttributes & 0x10) == 0)
			{
				return (MethodAttributes)6;
			}
			return (MethodAttributes)22;
		}
	}
	public static class TargetTypeSystemHandler
	{
		public static TypeReference Void { get; private set; }

		public static TypeReference IntPtr { get; private set; }

		public static TypeDefinition String { get; private set; }

		public static TypeDefinition Int { get; private set; }

		public static TypeDefinition Long { get; private set; }

		public static TypeDefinition Type { get; private set; }

		public static TypeReference Object { get; private set; }

		public static TypeReference Enum { get; private set; }

		public static TypeReference ValueType { get; private set; }

		public static TypeReference Delegate { get; private set; }

		public static TypeReference MulticastDelegate { get; private set; }

		public static TypeReference DefaultMemberAttribute { get; private set; }

		public static TypeReference NotSupportedException { get; private set; }

		public static TypeReference FlagsAttribute { get; private set; }

		public static TypeReference ObsoleteAttribute { get; private set; }

		public static void Init(IMetadataAccess systemLibraries)
		{
			AssemblyDefinition? obj = systemLibraries.GetAssemblyBySimpleName("mscorlib") ?? systemLibraries.GetAssemblyBySimpleName("netstandard") ?? throw new ArgumentException("System libraries metadata access doesn't contain mscorlib or netstandard");
			Void = obj.MainModule.TypeSystem.Void;
			IntPtr = obj.MainModule.TypeSystem.IntPtr;
			String = obj.MainModule.GetType("System.String");
			Int = obj.MainModule.GetType("System.Int32");
			Long = obj.MainModule.GetType("System.Int64");
			Type = obj.MainModule.GetType("System.Type");
			Object = obj.MainModule.TypeSystem.Object;
			Enum = (TypeReference)(object)obj.MainModule.GetType("System.Enum");
			ValueType = (TypeReference)(object)obj.MainModule.GetType("System.ValueType");
			Delegate = (TypeReference)(object)obj.MainModule.GetType("System.Delegate");
			MulticastDelegate = (TypeReference)(object)obj.MainModule.GetType("System.MulticastDelegate");
			DefaultMemberAttribute = (TypeReference)(object)obj.MainModule.GetType("System.Reflection.DefaultMemberAttribute");
			NotSupportedException = (TypeReference)(object)obj.MainModule.GetType("System.NotSupportedException");
			FlagsAttribute = (TypeReference)(object)obj.MainModule.GetType("System.FlagsAttribute");
			ObsoleteAttribute = (TypeReference)(object)obj.MainModule.GetType("System.ObsoleteAttribute");
		}
	}
	internal readonly struct TimingCookie : IDisposable
	{
		private readonly Stopwatch myStopwatch;

		public TimingCookie(string message)
		{
			LogSupport.Info(message + "... ");
			myStopwatch = Stopwatch.StartNew();
		}

		public void Dispose()
		{
			LogSupport.Info($"Done in {myStopwatch.Elapsed}");
		}
	}
	public static class UnhollowedAssemblyGenerator
	{
		public static void GenerateUnhollowedAssemblies(UnhollowerOptions options)
		{
			if (options.Source == null || !options.Source.Any())
			{
				Console.WriteLine("No input specified; use -h for help");
				return;
			}
			if (string.IsNullOrEmpty(options.OutputDir))
			{
				Console.WriteLine("No target dir specified; use -h for help");
				return;
			}
			if (string.IsNullOrEmpty(options.MscorlibPath) && string.IsNullOrEmpty(options.SystemLibrariesPath))
			{
				Console.WriteLine("No mscorlib or system libraries specified; use -h for help");
				return;
			}
			if (!Directory.Exists(options.OutputDir))
			{
				Directory.CreateDirectory(options.OutputDir);
			}
			IIl2CppMetadataAccess gameAssemblies;
			using (new TimingCookie("Reading assemblies"))
			{
				gameAssemblies = new CecilMetadataAccess(options.Source);
			}
			IMetadataAccess systemAssemblies;
			using (new TimingCookie("Reading system assemblies"))
			{
				systemAssemblies = (string.IsNullOrEmpty(options.SystemLibrariesPath) ? new CecilMetadataAccess(new string[1] { options.MscorlibPath }) : new CecilMetadataAccess(from it in Directory.EnumerateFiles(options.SystemLibrariesPath, "*.dll")
					where Path.GetFileName(it).StartsWith("System.") || Path.GetFileName(it) == "mscorlib.dll" || Path.GetFileName(it) == "netstandard.dll"
					select it));
			}
			IMetadataAccess unityAssemblies;
			if (!string.IsNullOrEmpty(options.UnityBaseLibsDir))
			{
				using (new TimingCookie("Reading unity assemblies"))
				{
					unityAssemblies = new CecilMetadataAccess(Directory.EnumerateFiles(options.UnityBaseLibsDir, "*.dll"));
				}
			}
			else
			{
				unityAssemblies = NullMetadataAccess.Instance;
			}
			RewriteGlobalContext rewriteGlobalContext;
			using (new TimingCookie("Creating rewrite assemblies"))
			{
				rewriteGlobalContext = new RewriteGlobalContext(options, gameAssemblies, systemAssemblies, unityAssemblies);
			}
			using (new TimingCookie("Computing renames"))
			{
				Pass05CreateRenameGroups.DoPass(rewriteGlobalContext);
			}
			using (new TimingCookie("Creating typedefs"))
			{
				Pass10CreateTypedefs.DoPass(rewriteGlobalContext);
			}
			using (new TimingCookie("Computing struct blittability"))
			{
				Pass11ComputeTypeSpecifics.DoPass(rewriteGlobalContext);
			}
			using (new TimingCookie("Filling typedefs"))
			{
				Pass12FillTypedefs.DoPass(rewriteGlobalContext);
			}
			using (new TimingCookie("Filling generic constraints"))
			{
				Pass13FillGenericConstraints.DoPass(rewriteGlobalContext);
			}
			using (new TimingCookie("Creating members"))
			{
				Pass15GenerateMemberContexts.DoPass(rewriteGlobalContext);
			}
			using (new TimingCookie("Scanning method cross-references"))
			{
				Pass16ScanMethodRefs.DoPass(rewriteGlobalContext, options);
			}
			using (new TimingCookie("Finalizing method declarations"))
			{
				Pass18FinalizeMethodContexts.DoPass(rewriteGlobalContext);
			}
			LogSupport.Info($"{Pass18FinalizeMethodContexts.TotalPotentiallyDeadMethods} total potentially dead methods");
			using (new TimingCookie("Filling method parameters"))
			{
				Pass19CopyMethodParameters.DoPass(rewriteGlobalContext);
			}
			using (new TimingCookie("Creating static constructors"))
			{
				Pass20GenerateStaticConstructors.DoPass(rewriteGlobalContext);
			}
			using (new TimingCookie("Creating value type fields"))
			{
				Pass21GenerateValueTypeFields.DoPass(rewriteGlobalContext);
			}
			using (new TimingCookie("Creating enums"))
			{
				Pass22GenerateEnums.DoPass(rewriteGlobalContext);
			}
			using (new TimingCookie("Creating IntPtr constructors"))
			{
				Pass23GeneratePointerConstructors.DoPass(rewriteGlobalContext);
			}
			using (new TimingCookie("Creating type getters"))
			{
				Pass24GenerateTypeStaticGetters.DoPass(rewriteGlobalContext);
			}
			using (new TimingCookie("Creating non-blittable struct constructors"))
			{
				Pass25GenerateNonBlittableValueTypeDefaultCtors.DoPass(rewriteGlobalContext);
			}
			using (new TimingCookie("Creating generic method static constructors"))
			{
				Pass30GenerateGenericMethodStoreConstructors.DoPass(rewriteGlobalContext);
			}
			using (new TimingCookie("Creating field accessors"))
			{
				Pass40GenerateFieldAccessors.DoPass(rewriteGlobalContext);
			}
			using (new TimingCookie("Filling methods"))
			{
				Pass50GenerateMethods.DoPass(rewriteGlobalContext);
			}
			using (new TimingCookie("Generating implicit conversions"))
			{
				Pass60AddImplicitConversions.DoPass(rewriteGlobalContext);
			}
			using (new TimingCookie("Creating properties"))
			{
				Pass70GenerateProperties.DoPass(rewriteGlobalContext);
			}
			if (options.UnityBaseLibsDir != null)
			{
				using (new TimingCookie("Unstripping types"))
				{
					Pass79UnstripTypes.DoPass(rewriteGlobalContext);
				}
				using (new TimingCookie("Unstripping fields"))
				{
					Pass80UnstripFields.DoPass(rewriteGlobalContext);
				}
				using (new TimingCookie("Unstripping methods"))
				{
					Pass80UnstripMethods.DoPass(rewriteGlobalContext);
				}
				using (new TimingCookie("Unstripping method bodies"))
				{
					Pass81FillUnstrippedMethodBodies.DoPass(rewriteGlobalContext);
				}
			}
			else
			{
				LogSupport.Warning("Not performing unstripping as unity libs are not specified");
			}
			using (new TimingCookie("Generating forwarded types"))
			{
				Pass89GenerateForwarders.DoPass(rewriteGlobalContext);
			}
			using (new TimingCookie("Writing xref cache"))
			{
				Pass89GenerateMethodXrefCache.DoPass(rewriteGlobalContext, options);
			}
			using (new TimingCookie("Writing assemblies"))
			{
				Pass90WriteToDisk.DoPass(rewriteGlobalContext, options);
			}
			using (new TimingCookie("Writing method pointer map"))
			{
				Pass91GenerateMethodPointerMap.DoPass(rewriteGlobalContext, options);
			}
			if (!options.NoCopyUnhollowerLibs)
			{
				File.Copy(typeof(IL2CPP).Assembly.Location, Path.Combine(options.OutputDir, typeof(IL2CPP).Assembly.GetName().Name + ".dll"), overwrite: true);
				File.Copy(typeof(RuntimeLibMarker).Assembly.Location, Path.Combine(options.OutputDir, typeof(RuntimeLibMarker).Assembly.GetName().Name + ".dll"), overwrite: true);
				File.Copy(typeof(Decoder).Assembly.Location, Path.Combine(options.OutputDir, typeof(Decoder).Assembly.GetName().Name + ".dll"), overwrite: true);
			}
			LogSupport.Info("Done!");
			rewriteGlobalContext.Dispose();
		}
	}
	public class UnhollowerOptions
	{
		public List<AssemblyDefinition>? Source { get; set; }

		public string OutputDir { get; set; }

		public string MscorlibPath { get; set; }

		public string SystemLibrariesPath { get; set; }

		public string? UnityBaseLibsDir { get; set; }

		public List<string> AdditionalAssembliesBlacklist { get; } = new List<string>();


		public int TypeDeobfuscationCharsPerUniquifier { get; set; } = 2;


		public int TypeDeobfuscationMaxUniquifiers { get; set; } = 10;


		public string GameAssemblyPath { get; set; }

		public bool Verbose { get; set; }

		public bool NoXrefCache { get; set; }

		public bool NoCopyUnhollowerLibs { get; set; }

		public Regex? ObfuscatedNamesRegex { get; set; }

		public Dictionary<string, string> RenameMap { get; } = new Dictionary<string, string>();


		public bool PassthroughNames { get; set; }

		public HashSet<string> NamespacesAndAssembliesToPrefix { get; } = new HashSet<string> { "System", "mscorlib", "Microsoft", "Mono", "I18N" };


		public List<string> DeobfuscationGenerationAssemblies { get; } = new List<string>();


		public string DeobfuscationNewAssembliesPath { get; set; }

		public void ReadRenameMap(string fileName)
		{
			using FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read);
			ReadRenameMap(fileStream, fileName.EndsWith(".gz"));
		}

		public void ReadRenameMap(Stream fileStream, bool isGzip)
		{
			if (isGzip)
			{
				using (GZipStream fileStream2 = new GZipStream(fileStream, CompressionMode.Decompress, leaveOpen: true))
				{
					ReadRenameMap(fileStream2, isGzip: false);
					return;
				}
			}
			using StreamReader streamReader = new StreamReader(fileStream, Encoding.UTF8, detectEncodingFromByteOrderMarks: false, 65536, leaveOpen: true);
			while (!streamReader.EndOfStream)
			{
				string text = streamReader.ReadLine();
				if (!string.IsNullOrEmpty(text) && !text.StartsWith("#"))
				{
					string[] array = text.Split(';');
					if (array.Length >= 2)
					{
						RenameMap[array[0]] = array[1];
					}
				}
			}
		}
	}
	public static class UtilGenerator
	{
		private static readonly OpCode[] I4Constants = (OpCode[])(object)new OpCode[10]
		{
			OpCodes.Ldc_I4_M1,
			OpCodes.Ldc_I4_0,
			OpCodes.Ldc_I4_1,
			OpCodes.Ldc_I4_2,
			OpCodes.Ldc_I4_3,
			OpCodes.Ldc_I4_4,
			OpCodes.Ldc_I4_5,
			OpCodes.Ldc_I4_6,
			OpCodes.Ldc_I4_7,
			OpCodes.Ldc_I4_8
		};

		public static void EmitLdcI4(this ILProcessor body, int constant)
		{
			//IL_0037: 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_0029: Unknown result type (might be due to invalid IL or missing references)
			if (constant >= -1 && constant <= 8)
			{
				body.Emit(I4Constants[constant + 1]);
			}
			else if (constant >= 0 && constant <= 255)
			{
				body.Emit(OpCodes.Ldc_I4_S, (sbyte)constant);
			}
			else
			{
				body.Emit(OpCodes.Ldc_I4, constant);
			}
		}

		public static void EmitObjectStore(this ILProcessor body, TypeReference originalType, TypeReference newType, TypeRewriteContext enclosingType, int argumentIndex)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: 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_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Expected O, but got Unknown
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Expected O, but got Unknown
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: 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_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			if (originalType is GenericParameter)
			{
				EmitObjectStoreGeneric(body, originalType, newType, enclosingType, argumentIndex);
				return;
			}
			AssemblyKnownImports imports = enclosingType.AssemblyContext.Imports;
			if (((MemberReference)originalType).FullName == "System.String")
			{
				body.Emit(OpCodes.Ldarg, argumentIndex);
				body.Emit(OpCodes.Call, imports.StringToNative);
				body.Emit(OpCodes.Call, imports.WriteFieldWBarrier);
			}
			else if (originalType.IsValueType)
			{
				if (enclosingType.AssemblyContext.GlobalContext.JudgeSpecificsByOriginalType(originalType) == TypeRewriteContext.TypeSpecifics.BlittableStruct)
				{
					body.Emit(OpCodes.Ldarg, argumentIndex);
					body.Emit(OpCodes.Stobj, newType);
					body.Emit(OpCodes.Pop);
					return;
				}
				body.Emit(OpCodes.Ldarg, argumentIndex);
				body.Emit(OpCodes.Call, imports.Il2CppObjectBaseToPointer);
				body.Emit(OpCodes.Call, imports.ObjectUnbox);
				GenericInstanceType val = new GenericInstanceType(imports.Il2CppClassPointerStore);
				val.GenericArguments.Add(newType);
				GenericInstanceType val2 = val;
				FieldReference val3 = new FieldReference("NativeClassPtr", imports.IntPtr, (TypeReference)(object)val2);
				body.Emit(OpCodes.Ldsfld, ((MemberReference)enclosingType.NewType).Module.ImportReference(val3));
				body.Emit(OpCodes.Ldc_I4_0);
				body.Emit(OpCodes.Conv_U);
				body.Emit(OpCodes.Call, imports.ValueSizeGet);
				body.Emit(OpCodes.Cpblk);
				body.Emit(OpCodes.Pop);
			}
			else
			{
				body.Emit(OpCodes.Ldarg, argumentIndex);
				body.Emit(OpCodes.Call, imports.Il2CppObjectBaseToPointer);
				body.Emit(OpCodes.Call, imports.WriteFieldWBarrier);
			}
		}

		private static void EmitObjectStoreGeneric(ILProcessor body, TypeReference originalType, TypeReference newType, TypeRewriteContext enclosingType, int argumentIndex)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: 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_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: 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_013f: 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_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_01df: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: Unknown result type (might be due to invalid IL or missing references)
			//IL_0224: Unknown result type (might be due to invalid IL or missing references)
			//IL_0231: Unknown result type (might be due to invalid IL or missing references)
			//IL_0241: Unknown result type (might be due to invalid IL or missing references)
			//IL_0248: Expected O, but got Unknown
			//IL_025b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0268: Unknown result type (might be due to invalid IL or missing references)
			//IL_0279: Unknown result type (might be due to invalid IL or missing references)
			//IL_0286: Unknown result type (might be due to invalid IL or missing references)
			//IL_0297: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_02be: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_030c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0319: Unknown result type (might be due to invalid IL or missing references)
			//IL_0325: Unknown result type (might be due to invalid IL or missing references)
			//IL_0336: Unknown result type (might be due to invalid IL or missing references)
			//IL_0347: Unknown result type (might be due to invalid IL or missing references)
			//IL_0358: Unknown result type (might be due to invalid IL or missing references)
			//IL_036b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0376: Unknown result type (might be due to invalid IL or missing references)
			//IL_0383: Unknown result type (might be due to invalid IL or missing references)
			//IL_038f: Unknown result type (might be due to invalid IL or missing references)
			AssemblyKnownImports imports = enclosingType.AssemblyContext.Imports;
			body.Emit(OpCodes.Ldtoken, newType);
			body.Emit(OpCodes.Call, ((MemberReference)enclosingType.NewType).Module.ImportReference((MethodReference)(object)((IEnumerable<MethodDefinition>)imports.Type.Methods).Single((MethodDefinition it) => ((MemberReference)it).Name == "GetTypeFromHandle")));
			body.Emit(OpCodes.Dup);
			body.Emit(OpCodes.Callvirt, ((MemberReference)enclosingType.NewType).Module.ImportReference((MethodReference)(object)((IEnumerable<MethodDefinition>)imports.Type.Methods).Single((MethodDefinition it) => ((MemberReference)it).Name == typeof(Type).GetProperty("IsValueType").GetMethod.Name)));
			Instruction val = body.Create(OpCodes.Nop);
			Instruction val2 = body.Create(OpCodes.Nop);
			Instruction val3 = body.Create(OpCodes.Nop);
			Instruction val4 = body.Create(OpCodes.Nop);
			body.Emit(OpCodes.Brtrue, val3);
			body.Emit(OpCodes.Callvirt, ((MemberReference)enclosingType.NewType).Module.ImportReference((MethodReference)(object)((IEnumerable<MethodDefinition>)imports.Type.Methods).Single((MethodDefinition it) => ((MemberReference)it).Name == typeof(Type).GetProperty("FullName").GetMethod.Name)));
			body.Emit(OpCodes.Ldstr, "System.String");
			body.Emit(OpCodes.Call, ((MemberReference)enclosingType.NewType).Module.ImportReference((MethodReference)(object)((IEnumerable<MethodDefinition>)TargetTypeSystemHandler.String.Methods).Single((MethodDefinition it) => ((MemberReference)it).Name == "Equals" && it.IsStatic && ((MethodReference)it).Parameters.Count == 2)));
			body.Emit(OpCodes.Brtrue_S, val2);
			body.Emit(OpCodes.Ldarg, argumentIndex);
			body.Emit(OpCodes.Box, newType);
			body.Emit(OpCodes.Isinst, imports.Il2CppObjectBase);
			body.Emit(OpCodes.Call, imports.Il2CppObjectBaseToPointer);
			body.Emit(OpCodes.Dup);
			body.Emit(OpCodes.Brfalse_S, val4);
			body.Emit(OpCodes.Dup);
			body.Emit(OpCodes.Call, imports.ObjectGetClass);
			body.Emit(OpCodes.Call, imports.ClassIsValueType);
			body.Emit(OpCodes.Brfalse_S, val4);
			body.Emit(OpCodes.Dup);
			VariableDefinition val5 = new VariableDefinition(imports.IntPtr);
			body.Body.Variables.Add(val5);
			body.Emit(OpCodes.Stloc, val5);
			body.Emit(OpCodes.Call, imports.ObjectUnbox);
			body.Emit(OpCodes.Ldloc, val5);
			body.Emit(OpCodes.Call, imports.ObjectGetClass);
			body.Emit(OpCodes.Ldc_I4_0);
			body.Emit(OpCodes.Conv_U);
			body.Emit(OpCodes.Call, imports.ValueSizeGet);
			body.Emit(OpCodes.Cpblk);
			body.Emit(OpCodes.Pop);
			body.Emit(OpCodes.Br_S, val);
			body.Append(val4);
			body.Emit(OpCodes.Call, imports.WriteFieldWBarrier);
			body.Emit(OpCodes.Br_S, val);
			body.Append(val2);
			body.Emit(OpCodes.Ldarg, argumentIndex);
			body.Emit(OpCodes.Box, newType);
			body.Emit(OpCodes.Isinst, imports.String);
			body.Emit(OpCodes.Call, imports.StringToNative);
			body.Emit(OpCodes.Call, imports.WriteFieldWBarrier);
			body.Emit(OpCodes.Br_S, val);
			body.Append(val3);
			body.Emit(OpCodes.Pop);
			body.Emit(OpCodes.Ldarg, argumentIndex);
			body.Emit(OpCodes.Stobj, newType);
			body.Emit(OpCodes.Pop);
			body.Append(val);
		}

		public static void EmitObjectToPointer(this ILProcessor body, TypeReference originalType, TypeReference newType, TypeRewriteContext enclosingType, int argumentIndex, bool valueTypeArgument0IsAPointer, bool allowNullable, bool unboxNonBlittableType, out VariableDefinition refVariable)
		{
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Expected O, but got Unknown
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: 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_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			refVariable = null;
			if (originalType is GenericParameter)
			{
				EmitObjectToPointerGeneric(body, originalType, newType, enclosingType, argumentIndex, valueTypeArgument0IsAPointer, allowNullable, unboxNonBlittableType);
				return;
			}
			AssemblyKnownImports imports = enclosingType.AssemblyContext.Imports;
			if (originalType is ByReferenceType)
			{
				if (newType.GetElementType().IsValueType)
				{
					body.Emit(OpCodes.Ldarg, argumentIndex);
					body.Emit(OpCodes.Conv_I);
					return;
				}
				if (originalType.GetElementType().IsValueType)
				{
					body.Emit(OpCodes.Ldarg, argumentIndex);
					body.Emit(OpCodes.Ldind_Ref);
					body.Emit(OpCodes.Call, imports.Il2CppObjectBaseToPointerNotNull);
					return;
				}
				VariableDefinition val = (refVariable = new VariableDefinition(imports.IntPtr));
				body.Body.Variables.Add(val);
				body.Emit(OpCodes.Ldarg, argumentIndex);
				body.Emit(OpCodes.Ldind_Ref);
				if (((MemberReference)originalType.GetElementType()).FullName == "System.String")
				{
					body.Emit(OpCodes.Call, imports.StringToNative);
				}
				else
				{
					body.Emit(OpCodes.Call, imports.Il2CppObjectBaseToPointer);
				}
				body.Emit(OpCodes.Stloc, val);
				body.Emit(OpCodes.Ldloca, val);
				body.Emit(OpCodes.Conv_I);
			}
			else if (originalType.IsValueType)
			{
				if (newType.IsValueType)
				{
					if (argumentIndex == 0 && valueTypeArgument0IsAPointer)
					{
						body.Emit(OpCodes.Ldarg_0);
					}
					else
					{
						body.Emit(OpCodes.Ldarga, argumentIndex);
					}
					return;
				}
				body.Emit(OpCodes.Ldarg, argumentIndex);
				body.Emit(OpCodes.Call, imports.Il2CppObjectBaseToPointerNotNull);
				if (unboxNonBlittableType)
				{
					body.Emit(OpCodes.Call, imports.ObjectUnbox);
				}
			}
			else if (((MemberReference)originalType).FullName == "System.String")
			{
				body.Emit(OpCodes.Ldarg, argumentIndex);
				body.Emit(OpCodes.Call, imports.StringToNative);
			}
			else
			{
				body.Emit(OpCodes.Ldarg, argumentIndex);
				body.Emit(OpCodes.Call, allowNullable ? imports.Il2CppObjectBaseToPointer : imports.Il2CppObjectBaseToPointerNotNull);
			}
		}

		private static void EmitObjectToPointerGeneric(ILProcessor body, TypeReference originalType, TypeReference newType, TypeRewriteContext enclosingType, int argumentIndex, bool valueTypeArgument0IsAPointer, bool allowNullable, bool unboxNonBlittableType)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: 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_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			AssemblyKnownImports imports = enclosingType.AssemblyContext.Imports;
			body.Emit(OpCodes.Ldtoken, newType);
			body.Emit(OpCodes.Call, ((MemberReference)enclosingType.NewType).Module.ImportReference((MethodReference)(object)((IEnumerable<MethodDefinition>)imports.Type.Methods).Single((MethodDefinition it) => ((MemberReference)it).Name == "GetTypeFromHandle")));
			body.Emit(OpCodes.Callvirt, ((MemberReference)enclosingType.NewType).Module.ImportReference((MethodReference)(object)((IEnumerable<MethodDefinition>)imports.Type.Methods).Single((MethodDefinition it) => ((MemberReference)it).Name == typeof(Type).GetProperty("IsValueType").GetMethod.Name)));
			Instruction val = body.Create(OpCodes.Nop);
			Instruction val2 = body.Create(OpCodes.Nop);
			Instruction val3 = body.Create(OpCodes.Nop);
			body.Emit(OpCodes.Brtrue, val2);
			body.Emit(OpCodes.Ldarg, argumentIndex);
			body.Emit(OpCodes.Box, newType);
			body.Emit(OpCodes.Dup);
			body.Emit(OpCodes.Isinst, imports.String);
			body.Emit(OpCodes.Brtrue_S, val3);
			body.Emit(OpCodes.Isinst, imports.Il2CppObjectBase);
			body.Emit(OpCodes.Call, allowNullable ? imports.Il2CppObjectBaseToPointer : imports.Il2CppObjectBaseToPointerNotNull);
			if (unboxNonBlittableType)
			{
				body.Emit(OpCodes.Dup);
				body.Emit(OpCodes.Brfalse_S, val);
				body.Emit(OpCodes.Dup);
				body.Emit(OpCodes.Call, imports.ObjectGetClass);
				body.Emit(OpCodes.Call, imports.ClassIsValueType);
				body.Emit(OpCodes.Brfalse_S, val);
				body.Emit(OpCodes.Call, imports.ObjectUnbox);
			}
			body.Emit(OpCodes.Br, val);
			body.Append(val3);
			body.Emit(OpCodes.Isinst, imports.String);
			body.Emit(OpCodes.Call, imports.StringToNative);
			body.Emit(OpCodes.Br_S, val);
			body.Append(val2);
			body.Emit(OpCodes.Ldarga, argumentIndex);
			body.Append(val);
		}

		public static void EmitPointerToObject(this ILProcessor body, TypeReference originalReturnType, TypeReference convertedReturnType, TypeRewriteContext enclosingType, Instruction loadPointer, bool extraDerefForNonValueTypes, bool unboxValueType)
		{
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Expected O, but got Unknown
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ee: Expected O, but got Unknown
			//IL_01f1: 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_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Expected O, but got Unknown
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Expected O, but got Unknown
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: 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_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0215: Unknown result type (might be due to invalid IL or missing references)
			//IL_0220: Unknown result type (might be due to invalid IL or missing references)
			//IL_022d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: Unknown result type (might be due to invalid IL or missing references)
			//IL_0243: Unknown result type (might be due to invalid IL or missing references)
			//IL_020a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: 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_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Expected O, but got Unknown
			//IL_01a7: Expected O, but got Unknown
			//IL_01a8: 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)
			//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_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Expected O, but got Unknown
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Expected O, but got Unknown
			if (originalReturnType is GenericParameter)
			{
				EmitPointerToObjectGeneric(body, originalReturnType, convertedReturnType, enclosingType, loadPointer, extraDerefForNonValueTypes, unboxValueType);
				return;
			}
			AssemblyKnownImports imports = enclosingType.AssemblyContext.Imports;
			if (((MemberReference)originalReturnType).FullName == "System.Void")
			{
				return;
			}
			if (originalReturnType.IsValueType)
			{
				if (convertedReturnType.IsValueType)
				{
					body.Append(loadPointer);
					if (unboxValueType)
					{
						body.Emit(OpCodes.Call, imports.ObjectUnbox);
					}
					body.Emit(OpCodes.Ldobj, convertedReturnType);
					return;
				}
				if (!unboxValueType)
				{
					GenericInstanceType val = new GenericInstanceType(imports.Il2CppClassPointerStore);
					val.GenericArguments.Add(convertedReturnType);
					GenericInstanceType val2 = val;
					FieldReference val3 = new FieldReference("NativeClassPtr", imports.IntPtr, (TypeReference)(object)val2);
					body.Emit(OpCodes.Ldsfld, ((MemberReference)enclosingType.NewType).Module.ImportReference(val3));
					body.Append(loadPointer);
					body.Emit(OpCodes.Call, imports.ObjectBox);
				}
				else
				{
					body.Append(loadPointer);
				}
				OpCode newobj = OpCodes.Newobj;
				MethodReference val4 = new MethodReference(".ctor", imports.Void, convertedReturnType);
				val4.Parameters.Add(new ParameterDefinition(imports.IntPtr));
				val4.HasThis = true;
				body.Emit(newobj, val4);
			}
			else if (((MemberReference)originalReturnType).FullName == "System.String")
			{
				body.Append(loadPointer);
				if (extraDerefForNonValueTypes)
				{
					body.Emit(OpCodes.Ldind_I);
				}
				body.Emit(OpCodes.Call, imports.StringFromNative);
			}
			else if (originalReturnType.IsArray && originalReturnType.GetElementType().IsGenericParameter)
			{
				body.Append(loadPointer);
				TypeReference il2CppArrayBaseSelfSubst = imports.Il2CppArrayBaseSelfSubst;
				MethodReference val5 = new MethodReference("WrapNativeGenericArrayPointer", il2CppArrayBaseSelfSubst, convertedReturnType)
				{
					HasThis = false
				};
				val5.Parameters.Add(new ParameterDefinition(imports.IntPtr));
				MethodReference val6 = val5;
				body.Emit(OpCodes.Call, val6);
			}
			else
			{
				OpCode newobj2 = OpCodes.Newobj;
				MethodReference val7 = new MethodReference(".ctor", imports.Void, convertedReturnType);
				val7.Parameters.Add(new ParameterDefinition(imports.IntPtr));
				val7.HasThis = true;
				Instruction val8 = body.Create(newobj2, val7);
				Instruction val9 = body.Create(OpCodes.Nop);
				body.Append(loadPointer);
				if (extraDerefForNonValueTypes)
				{
					body.Emit(OpCodes.Ldind_I);
				}
				body.Emit(OpCodes.Dup);
				body.Emit(OpCodes.Brtrue_S, val8);
				body.Emit(OpCodes.Pop);
				body.Emit(OpCodes.Ldnull);
				body.Emit(OpCodes.Br, val9);
				body.Append(val8);
				body.Append(val9);
			}
		}

		private static void EmitPointerToObjectGeneric(ILProcessor body, TypeReference originalReturnType, TypeReference newReturnType, TypeRewriteContext enclosingType, Instruction loadPointer, bool extraDerefForNonValueTypes, bool unboxValueType)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: 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_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Expected O, but got Unknown
			AssemblyKnownImports imports = enclosingType.AssemblyContext.Imports;
			body.Append(loadPointer);
			body.Emit(extraDerefForNonValueTypes ? OpCodes.Ldc_I4_1 : OpCodes.Ldc_I4_0);
			body.Emit(unboxValueType ? OpCodes.Ldc_I4_1 : OpCodes.Ldc_I4_0);
			OpCode call = OpCodes.Call;
			ModuleDefinition module = imports.Module;
			GenericInstanceMethod val = new GenericInstanceMethod(imports.Il2CppPointerToGeneric);
			val.GenericArguments.Add(newReturnType);
			body.Emit(call, module.ImportReference((MethodReference)val));
		}

		public static void GenerateBoxMethod(TypeDefinition targetType, FieldReference classHandle, TypeReference il2CppObjectTypeDef)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: 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_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Expected O, but got Unknown
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Expected O, but got Unknown
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			MethodDefinition val = new MethodDefinition("BoxIl2CppObject", (MethodAttributes)134, ((MemberReference)targetType).Module.ImportReference(il2CppObjectTypeDef));
			targetType.Methods.Add(val);
			ILProcessor iLProcessor = val.Body.GetILProcessor();
			iLProcessor.Emit(OpCodes.Ldsfld, classHandle);
			iLProcessor.Emit(OpCodes.Ldarg_0);
			iLProcessor.Emit(OpCodes.Call, ((MemberReference)targetType).Module.ImportReference((MethodBase)typeof(IL2CPP).GetMethod("il2cpp_value_box")));
			OpCode newobj = OpCodes.Newobj;
			MethodReference val2 = new MethodReference(".ctor", ((MemberReference)targetType).Module.ImportReference(TargetTypeSystemHandler.Void), il2CppObjectTypeDef);
			val2.Parameters.Add(new ParameterDefinition(((MemberReference)targetType).Module.ImportReference(TargetTypeSystemHandler.IntPtr)));
			val2.HasThis = true;
			iLProcessor.Emit(newobj, val2);
			iLProcessor.Emit(OpCodes.Ret);
		}

		public static void EmitUpdateRef(this ILProcessor body, ParameterDefinition newMethodParameter, int argIndex, VariableDefinition paramVariable, AssemblyKnownImports imports)
		{
			//IL_0001: 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_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: 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_007b: 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_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Expected O, but got Unknown
			//IL_00bf: Expected O, but got Unknown
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			body.Emit(OpCodes.Ldarg, argIndex);
			body.Emit(OpCodes.Ldloc, paramVariable);
			if (((MemberReference)((ParameterReference)newMethodParameter).ParameterType.GetElementType()).FullName == "System.String")
			{
				body.Emit(OpCodes.Call, imports.StringFromNative);
			}
			else
			{
				body.Emit(OpCodes.Dup);
				Instruction val = body.Create(OpCodes.Pop);
				Instruction val2 = body.Create(OpCodes.Nop);
				body.Emit(OpCodes.Brfalse_S, val);
				OpCode newobj = OpCodes.Newobj;
				MethodReference val3 = new MethodReference(".ctor", imports.Void, ((ParameterReference)newMethodParameter).ParameterType.GetElementType())
				{
					HasThis = true
				};
				val3.Parameters.Add(new ParameterDefinition(imports.IntPtr));
				body.Emit(newobj, val3);
				body.Emit(OpCodes.Br_S, val2);
				body.Append(val);
				body.Emit(OpCodes.Ldnull);
				body.Append(val2);
			}
			body.Emit(OpCodes.Stind_Ref);
		}
	}
}
namespace AssemblyUnhollower.Utils
{
	public class UniquificationContext
	{
		private class Item2Comparer : IComparer<(string, float)>
		{
			public int Compare((string, float) x, (string, float) y)
			{
				return x.Item2.CompareTo(y.Item2);
			}
		}

		private readonly UnhollowerOptions myUnhollowerOptions;

		private readonly Dictionary<string, int> myUniquifiersCount = new Dictionary<string, int>();

		private readonly SortedSet<(string, float)> myPrefixes = new SortedSet<(string, float)>(new Item2Comparer());

		public UniquificationContext(UnhollowerOptions unhollowerOptions)
		{
			myUnhollowerOptions = unhollowerOptions;
		}

		public bool CheckFull()
		{
			return myUniquifiersCount.Count >= myUnhollowerOptions.TypeDeobfuscationMaxUniquifiers;
		}

		public void Push(string str, bool noSubstring = false)
		{
			if (!str.IsInvalidInSource())
			{
				string text = (noSubstring ? str : SubstringBounded(str, 0, myUnhollowerOptions.TypeDeobfuscationCharsPerUniquifier));
				int num2 = (myUniquifiersCount[text] = myUniquifiersCount.GetOrCreate(text, (string _) => 0) + 1);
				int num3 = num2;
				myPrefixes.Add((text, (float)(myUniquifiersCount.Count + num3 * 2) + (float)myPrefixes.Count / 100f));
			}
		}

		public void Push(List<string> strings, bool noSubstring = false)
		{
			foreach (string @string in strings)
			{
				Push(@string, noSubstring);
			}
		}

		public string GetTop()
		{
			return string.Join("", from it in myPrefixes.Take(myUnhollowerOptions.TypeDeobfuscationMaxUniquifiers)
				select it.Item1);
		}

		private static string SubstringBounded(string str, int startIndex, int length)
		{
			l

BepInExPack/BepInEx/core/LibCpp2IL.dll

Decompiled a month ago
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Text;
using System.Threading;
using LibCpp2IL.BinaryStructures;
using LibCpp2IL.Elf;
using LibCpp2IL.Logging;
using LibCpp2IL.MachO;
using LibCpp2IL.Metadata;
using LibCpp2IL.NintendoSwitch;
using LibCpp2IL.PE;
using LibCpp2IL.Reflection;
using LibCpp2IL.Wasm;
using Microsoft.CodeAnalysis;
using WasmDisassembler;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyDescription("Library for reversing Unity's il2cpp build process")]
[assembly: AssemblyCopyright("Copyright © Samboy063 2019-2022")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyFileVersion("2022.0.5")]
[assembly: ComVisible(false)]
[assembly: Guid("7C9601B4-B53B-48CD-866F-DB908B3BF54D")]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = "")]
[assembly: AssemblyVersion("2022.0.5.0")]
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;
		}
	}
}
namespace LibCpp2IL
{
	public static class ArmUtils
	{
		public const uint PC_REG = 15u;

		public static (uint register, ushort immediateValue) GetOperandsForLiteralLdr(uint inst)
		{
			if (inst.Bits(16, 16) != 58783)
			{
				return (0u, 0);
			}
			return (inst.Bits(12, 4), (ushort)inst.Bits(0, 12));
		}

		public static (uint firstReg, uint secondReg, uint thirdReg) GetOperandsForRegisterLdr(uint inst)
		{
			if (inst.Bits(20, 12) != 3705)
			{
				return (0u, 0u, 0u);
			}
			uint item = inst.Bits(16, 4);
			uint item2 = inst.Bits(12, 4);
			uint item3 = inst.Bits(0, 4);
			return (item2, item, item3);
		}

		public static (uint firstReg, uint secondReg, uint thirdReg) GetOperandsForRegisterAdd(uint inst)
		{
			if (inst.Bits(21, 11) != 1796)
			{
				return (0u, 0u, 0u);
			}
			uint item = inst.Bits(12, 4);
			uint item2 = inst.Bits(16, 4);
			uint item3 = inst.Bits(0, 4);
			return (item, item2, item3);
		}
	}
	public static class BinaryReaderHelpers
	{
		public static byte[] Reverse(this byte[] b)
		{
			Array.Reverse((Array)b);
			return b;
		}

		public static ushort ReadUInt16WithReversedBits(this BinaryReader binRdr)
		{
			return BitConverter.ToUInt16(binRdr.ReadBytesRequired(2).Reverse(), 0);
		}

		public static short ReadInt16WithReversedBits(this BinaryReader binRdr)
		{
			return BitConverter.ToInt16(binRdr.ReadBytesRequired(2).Reverse(), 0);
		}

		public static uint ReadUInt32WithReversedBits(this BinaryReader binRdr)
		{
			return BitConverter.ToUInt32(binRdr.ReadBytesRequired(4).Reverse(), 0);
		}

		public static int ReadInt32WithReversedBits(this BinaryReader binRdr)
		{
			return BitConverter.ToInt32(binRdr.ReadBytesRequired(4).Reverse(), 0);
		}

		public static ulong ReadUInt64WithReversedBits(this BinaryReader binRdr)
		{
			return BitConverter.ToUInt64(binRdr.ReadBytesRequired(8).Reverse(), 0);
		}

		public static long ReadInt64WithReversedBits(this BinaryReader binRdr)
		{
			return BitConverter.ToInt64(binRdr.ReadBytesRequired(8).Reverse(), 0);
		}

		public static float ReadSingleWithReversedBits(this BinaryReader binRdr)
		{
			return BitConverter.ToSingle(binRdr.ReadBytesRequired(4).Reverse(), 0);
		}

		public static double ReadDoubleWithReversedBits(this BinaryReader binRdr)
		{
			return BitConverter.ToDouble(binRdr.ReadBytesRequired(8).Reverse(), 0);
		}

		private static byte[] ReadBytesRequired(this BinaryReader binRdr, int byteCount)
		{
			byte[] array = binRdr.ReadBytes(byteCount);
			if (array.Length != byteCount)
			{
				throw new EndOfStreamException($"{byteCount} bytes required from stream, but only {array.Length} returned.");
			}
			return array;
		}
	}
	public class BinarySearcher
	{
		private class Section
		{
			public ulong RawStartAddress;

			public ulong RawEndAddress;

			public ulong VirtualStartAddress;
		}

		private static readonly byte[] FeatureBytes2019 = new byte[13]
		{
			109, 115, 99, 111, 114, 108, 105, 98, 46, 100,
			108, 108, 0
		};

		private readonly Il2CppBinary _binary;

		private readonly byte[] binaryBytes;

		private readonly int methodCount;

		private readonly int typeDefinitionsCount;

		public BinarySearcher(Il2CppBinary binary, int methodCount, int typeDefinitionsCount)
		{
			_binary = binary;
			binaryBytes = binary.GetRawBinaryContent();
			this.methodCount = methodCount;
			this.typeDefinitionsCount = typeDefinitionsCount;
		}

		private int FindBytes(byte[] blob, byte[] signature, int requiredAlignment = 1, int startOffset = 0)
		{
			int num = Array.IndexOf(blob, signature[0], startOffset);
			byte[] array = new byte[signature.Length];
			while (num >= 0 && num <= blob.Length - signature.Length)
			{
				Buffer.BlockCopy(blob, num, array, 0, signature.Length);
				if (num % requiredAlignment == 0 && array.SequenceEqual(signature))
				{
					return num;
				}
				num = Array.IndexOf(blob, signature[0], num + 1);
			}
			return -1;
		}

		private IEnumerable<uint> FindAllBytes(byte[] signature, int alignment = 0)
		{
			LibLogger.VerboseNewline("\t\t\tLooking for bytes: " + string.Join(" ", signature.Select((byte b) => b.ToString("x2"))));
			int offset = 0;
			int ptrSize = (_binary.is32Bit ? 4 : 8);
			while (offset != -1)
			{
				offset = FindBytes(binaryBytes, signature, (alignment != 0) ? alignment : ptrSize, offset);
				if (offset != -1)
				{
					yield return (uint)offset;
					offset += ptrSize;
				}
			}
		}

		private IEnumerable<uint> FindAllStrings(string str)
		{
			return FindAllBytes(Encoding.ASCII.GetBytes(str), 1);
		}

		private IEnumerable<uint> FindAllDWords(uint word)
		{
			return FindAllBytes(BitConverter.GetBytes(word), 1);
		}

		private IEnumerable<uint> FindAllQWords(ulong word)
		{
			return FindAllBytes(BitConverter.GetBytes(word), 1);
		}

		private IEnumerable<uint> FindAllWords(ulong word)
		{
			if (!_binary.is32Bit)
			{
				return FindAllQWords(word);
			}
			return FindAllDWords((uint)word);
		}

		private IEnumerable<ulong> MapOffsetsToVirt(IEnumerable<uint> offsets)
		{
			foreach (uint offset2 in offsets)
			{
				uint offset = offset2;
				if (_binary.TryMapRawAddressToVirtual(in offset, out var va))
				{
					yield return va;
				}
			}
		}

		private IEnumerable<ulong> FindAllMappedWords(ulong word)
		{
			IEnumerable<uint> offsets = FindAllWords(word);
			return MapOffsetsToVirt(offsets);
		}

		private IEnumerable<ulong> FindAllMappedWords(IEnumerable<ulong> va)
		{
			return va.SelectMany(FindAllMappedWords);
		}

		private IEnumerable<ulong> FindAllMappedWords(IEnumerable<uint> va)
		{
			return va.SelectMany((uint a) => FindAllMappedWords(a));
		}

		public ulong FindCodeRegistrationPre2019()
		{
			List<ulong> list = MapOffsetsToVirt(FindAllBytes(BitConverter.GetBytes(methodCount), 1)).ToList();
			LibLogger.VerboseNewline(string.Format("\t\t\tFound {0} instances of the method count {1}, as bytes {2}", list.Count, methodCount, string.Join(", ", from x in BitConverter.GetBytes((ulong)methodCount)
				select $"0x{x:X}")));
			if (list.Count == 0)
			{
				return 0uL;
			}
			foreach (ulong item in list)
			{
				if (_binary.ReadClassAtVirtualAddress<Il2CppCodeRegistration>(item).customAttributeCount == (ulong)LibCpp2IlMain.TheMetadata.attributeTypeRanges.Length)
				{
					return item;
				}
			}
			return 0uL;
		}

		internal ulong FindCodeRegistrationPost2019()
		{
			List<ulong> list = (from idx in FindAllStrings("mscorlib.dll\0")
				select _binary.MapRawAddressToVirtual(idx)).ToList();
			LibLogger.VerboseNewline(string.Format("\t\t\tFound {0} occurrences of mscorlib.dll: [{1}]", list.Count, string.Join(", ", list.Select((ulong p) => p.ToString("X")))));
			List<ulong> list2 = FindAllMappedWords(list).ToList();
			LibLogger.VerboseNewline(string.Format("\t\t\tFound {0} potential codegen modules for mscorlib: [{1}]", list2.Count, string.Join(", ", list2.Select((ulong p) => p.ToString("X")))));
			List<ulong> list3 = FindAllMappedWords(list2).ToList();
			LibLogger.VerboseNewline(string.Format("\t\t\tFound {0} address for potential codegen modules in potential codegen module lists: [{1}]", list3.Count, string.Join(", ", list3.Select((ulong p) => p.ToString("X")))));
			uint ptrSize = (_binary.is32Bit ? 4u : 8u);
			List<ulong> list4 = null;
			if (!(LibCpp2IlMain.MetadataVersion >= 27f))
			{
				list4 = FindAllMappedWords(list3).ToList();
			}
			else
			{
				ulong num = 200uL;
				IEnumerable<ulong> source = list3.AsEnumerable();
				int num2 = LibCpp2IlMain.TheMetadata.imageDefinitions.Length;
				ulong initialBacktrack = (ulong)num2 - 5uL;
				source = source.Select((ulong va) => va - ptrSize * initialBacktrack);
				for (ulong num3 = initialBacktrack; num3 < num; num3++)
				{
					if ((list4?.Count() ?? 0) == 1)
					{
						break;
					}
					list4 = FindAllMappedWords(source).ToList();
					if (list4.Count == 1 && _binary.ReadClassAtVirtualAddress<uint>(list4.First() - ptrSize) > num)
					{
						list4 = new List<ulong>();
					}
					source = source.Select((ulong va) => va - ptrSize);
				}
				if (list4 == null || !list4.Any())
				{
					throw new Exception("Failed to find pCodegenModules");
				}
				if (list4.Count() > 1)
				{
					throw new Exception("Found more than 1 pointer as pCodegenModules");
				}
			}
			LibLogger.VerboseNewline(string.Format("\t\t\tFound {0} potential pCodegenModules addresses: [{1}]", list4.Count, string.Join(", ", list4.Select((ulong p) => p.ToString("X")))));
			ulong num4 = (ulong)(LibCpp2ILUtils.VersionAwareSizeOf(typeof(Il2CppCodeRegistration)) - ptrSize);
			LibLogger.VerboseNewline($"\t\t\tpCodegenModules is the second-to-last field of the codereg struct. Therefore on this version and architecture, we need to subtract {num4} bytes from its address to get pCodeReg");
			Dictionary<string, FieldInfo> fieldsByName = typeof(Il2CppCodeRegistration).GetFields().ToDictionary((FieldInfo f) => f.Name);
			foreach (ulong item in list4)
			{
				ulong num5 = item - num4;
				if (list4.Count == 1)
				{
					LibLogger.Verbose($"\t\t\tOnly found one codegen module pointer, so assuming it's correct and returning pCodeReg = 0x{num5:X}");
					return num5;
				}
				LibLogger.Verbose($"\t\t\tConsidering potential code registration at 0x{num5:X}...");
				if (ValidateCodeRegistration(LibCpp2IlMain.Binary.ReadClassAtVirtualAddress<Il2CppCodeRegistration>(num5), fieldsByName))
				{
					LibLogger.VerboseNewline("Looks good!");
					return num5;
				}
			}
			return 0uL;
		}

		public static bool ValidateCodeRegistration(Il2CppCodeRegistration codeReg, Dictionary<string, FieldInfo> fieldsByName)
		{
			bool result = true;
			foreach (KeyValuePair<string, FieldInfo> item in fieldsByName)
			{
				ulong num = (ulong)item.Value.GetValue(codeReg);
				if (num == 0L)
				{
					continue;
				}
				long result2;
				if (item.Key.EndsWith("count", StringComparison.OrdinalIgnoreCase))
				{
					if (num > 458752)
					{
						LibLogger.VerboseNewline($"Rejected due to unreasonable count field 0x{num:X} for field {item.Key}");
						result = false;
						break;
					}
				}
				else if (!LibCpp2IlMain.Binary.TryMapVirtualAddressToRaw(num, out result2))
				{
					LibLogger.VerboseNewline($"Rejected due to invalid pointer 0x{num:X} for field {item.Key}");
					result = false;
					break;
				}
			}
			return result;
		}

		public ulong FindMetadataRegistrationPre24_5()
		{
			ulong num = (ulong)LibCpp2ILUtils.VersionAwareSizeOf(typeof(Il2CppMetadataRegistration));
			ulong num2 = (ulong)(_binary.is32Bit ? 4 : 8);
			ulong bytesToSubtract = num - num2 * 4;
			List<ulong> list = MapOffsetsToVirt(FindAllBytes(BitConverter.GetBytes(LibCpp2IlMain.TheMetadata.typeDefs.Length), 1)).ToList();
			LibLogger.VerboseNewline($"\t\t\tFound {list.Count} instances of the number of type defs, {LibCpp2IlMain.TheMetadata.typeDefs.Length}");
			list = list.Select((ulong p) => p - bytesToSubtract).ToList();
			foreach (ulong item in list)
			{
				Il2CppMetadataRegistration il2CppMetadataRegistration = _binary.ReadClassAtVirtualAddress<Il2CppMetadataRegistration>(item);
				if (il2CppMetadataRegistration.metadataUsagesCount == (ulong)LibCpp2IlMain.TheMetadata.metadataUsageLists.Length)
				{
					LibLogger.VerboseNewline($"\t\t\tFound and selected probably valid metadata registration at 0x{item:X}.");
					return item;
				}
				LibLogger.VerboseNewline($"\t\t\tSkipping 0x{item:X} as the metadata reg, metadata usage count was 0x{il2CppMetadataRegistration.metadataUsagesCount:X}, expecting 0x{LibCpp2IlMain.TheMetadata.metadataUsageLists.Length:X}");
			}
			return 0uL;
		}

		public ulong FindMetadataRegistrationPost24_5()
		{
			ulong ptrSize = (ulong)(_binary.is32Bit ? 4 : 8);
			uint sizeOfMr = (uint)LibCpp2ILUtils.VersionAwareSizeOf(typeof(Il2CppMetadataRegistration));
			LibLogger.VerboseNewline($"\t\t\tLooking for the number of type definitions, 0x{typeDefinitionsCount:X}");
			List<ulong> list = FindAllMappedWords((ulong)typeDefinitionsCount).ToList();
			LibLogger.VerboseNewline(string.Format("\t\t\tFound {0} instances of the number of type definitions: [{1}]", list.Count, string.Join(", ", list.Select((ulong p) => p.ToString("X")))));
			List<ulong> list2 = list.Select((ulong a) => a - sizeOfMr + ptrSize * 4).ToList();
			LibLogger.VerboseNewline(string.Format("\t\t\tFound {0} potential metadata registrations: [{1}]", list2.Count, string.Join(", ", list2.Select((ulong p) => p.ToString("X")))));
			ulong num = sizeOfMr / ptrSize;
			foreach (ulong item in list2)
			{
				ulong[] array = _binary.ReadClassArrayAtVirtualAddress<ulong>(item, (int)num);
				bool flag = true;
				for (int i = 0; i < array.Length && flag; i++)
				{
					if (i % 2 == 0)
					{
						flag = array[i] < 655360;
						if (!flag && array[i] < 1048575)
						{
							LibLogger.VerboseNewline($"\t\t\tRejected Metadata registration at 0x{item:X}, because it has a count field 0x{array[i]:X} which is above sanity limit of 0xA0000. If metadata registration detection fails, need to bump up the limit.");
						}
					}
					else if (array[i] == 0L)
					{
						flag = i >= 14;
					}
					else
					{
						flag = _binary.TryMapVirtualAddressToRaw(array[i], out var _);
						if (!flag)
						{
							LibLogger.VerboseNewline($"\t\t\tRejecting metadata registration 0x{item:X} because the pointer at index {i}, which is 0x{array[i]:X}, can't be mapped to the binary.");
						}
					}
					if (!flag)
					{
						break;
					}
				}
				if (!flag)
				{
					continue;
				}
				Il2CppMetadataRegistration il2CppMetadataRegistration = _binary.ReadClassAtVirtualAddress<Il2CppMetadataRegistration>(item);
				if (LibCpp2IlMain.MetadataVersion >= 27f && (il2CppMetadataRegistration.metadataUsagesCount != 0L || il2CppMetadataRegistration.metadataUsages != 0L))
				{
					LibLogger.VerboseNewline($"\t\t\tRejecting metadata registration 0x{item:X} because it has {il2CppMetadataRegistration.metadataUsagesCount} metadata usages at a pointer of 0x{il2CppMetadataRegistration.metadataUsages:X}. We're on v27, these should be 0.");
					continue;
				}
				if (il2CppMetadataRegistration.typeDefinitionsSizesCount != LibCpp2IlMain.TheMetadata.typeDefs.Length)
				{
					LibLogger.VerboseNewline($"\t\t\tRejecting metadata registration 0x{item:X} because it has {il2CppMetadataRegistration.typeDefinitionsSizesCount} type def sizes, while we have {LibCpp2IlMain.TheMetadata.typeDefs.Length} type defs");
					continue;
				}
				if (il2CppMetadataRegistration.numTypes < LibCpp2IlMain.TheMetadata.typeDefs.Length)
				{
					LibLogger.VerboseNewline($"\t\t\tRejecting metadata registration 0x{item:X} because it has {il2CppMetadataRegistration.numTypes} types, while we have {LibCpp2IlMain.TheMetadata.typeDefs.Length} type defs");
					continue;
				}
				LibLogger.VerboseNewline($"\t\t\tAccepting metadata reg as VA 0x{item:X}");
				return item;
			}
			return 0uL;
		}
	}
	public class ClassReadingBinaryReader : EndianAwareBinaryReader
	{
		private static readonly Dictionary<Type, FieldInfo[]> CachedFields = new Dictionary<Type, FieldInfo[]>();

		private SpinLock PositionShiftLock;

		public bool is32Bit;

		private MemoryStream _memoryStream;

		private Dictionary<FieldInfo, bool> _cachedNoSerialize = new Dictionary<FieldInfo, bool>();

		public long Position
		{
			get
			{
				return BaseStream.Position;
			}
			protected set
			{
				BaseStream.Position = value;
			}
		}

		public ClassReadingBinaryReader(MemoryStream input)
			: base(input)
		{
			_memoryStream = input;
		}

		internal virtual object? ReadPrimitive(Type type, bool overrideArchCheck = false)
		{
			if (type == typeof(bool))
			{
				return ReadBoolean();
			}
			if (type == typeof(char))
			{
				return ReadChar();
			}
			if (type == typeof(int))
			{
				return ReadInt32();
			}
			if (type == typeof(uint))
			{
				return ReadUInt32();
			}
			if (type == typeof(short))
			{
				return ReadInt16();
			}
			if (type == typeof(ushort))
			{
				return ReadUInt16();
			}
			if (type == typeof(sbyte))
			{
				return ReadSByte();
			}
			if (type == typeof(byte))
			{
				return ReadByte();
			}
			if (type == typeof(long))
			{
				return (is32Bit && !overrideArchCheck) ? ReadInt32() : ReadInt64();
			}
			if (type == typeof(ulong))
			{
				return (is32Bit && !overrideArchCheck) ? ReadUInt32() : ReadUInt64();
			}
			if (type == typeof(float))
			{
				return ReadSingle();
			}
			if (type == typeof(double))
			{
				return ReadDouble();
			}
			return null;
		}

		public T ReadClassAtRawAddr<T>(long offset, bool overrideArchCheck = false) where T : new()
		{
			bool lockTaken = false;
			PositionShiftLock.Enter(ref lockTaken);
			if (!lockTaken)
			{
				throw new Exception("Failed to obtain lock");
			}
			try
			{
				if (offset >= 0)
				{
					Position = offset;
				}
				return InternalReadClass<T>(overrideArchCheck);
			}
			finally
			{
				PositionShiftLock.Exit();
			}
		}

		public uint ReadUnityCompressedUIntAtRawAddr(long offset, out int bytesRead)
		{
			bool lockTaken = false;
			PositionShiftLock.Enter(ref lockTaken);
			if (!lockTaken)
			{
				throw new Exception("Failed to obtain lock");
			}
			try
			{
				if (offset >= 0)
				{
					Position = offset;
				}
				byte b = ReadByte();
				bytesRead = 1;
				if (b < 128)
				{
					return b;
				}
				switch (b)
				{
				case 240:
					bytesRead = 5;
					return ReadUInt32();
				case byte.MaxValue:
					return uint.MaxValue;
				case 254:
					return 4294967294u;
				default:
					if ((b & 0xC0) == 192)
					{
						bytesRead = 4;
						return (uint)(((b & -193) << 24) | (ReadByte() << 16) | (ReadByte() << 8) | ReadByte());
					}
					if ((b & 0x80) == 128)
					{
						bytesRead = 2;
						return (uint)(((b & -129) << 8) | ReadByte());
					}
					throw new Exception($"How did we even get here? Invalid compressed int first byte {b}");
				}
			}
			finally
			{
				PositionShiftLock.Exit();
			}
		}

		public int ReadUnityCompressedIntAtRawAddr(long position, out int bytesRead)
		{
			uint num = ReadUnityCompressedUIntAtRawAddr(position, out bytesRead);
			if (num == uint.MaxValue)
			{
				return int.MinValue;
			}
			bool num2 = (num & 1) == 1;
			num >>= 1;
			if (num2)
			{
				return (int)(0 - (num + 1));
			}
			return (int)num;
		}

		private T InternalReadClass<T>(bool overrideArchCheck = false) where T : new()
		{
			return (T)InternalReadClass(typeof(T), overrideArchCheck);
		}

		private object InternalReadClass(Type type, bool overrideArchCheck = false)
		{
			object obj = Activator.CreateInstance(type);
			if (type.IsPrimitive)
			{
				return ReadAndConvertPrimitive(overrideArchCheck, type);
			}
			if (type.IsEnum)
			{
				return ReadPrimitive(type.GetEnumUnderlyingType());
			}
			ReadClassFieldwise(overrideArchCheck, obj);
			return obj;
		}

		private object ReadAndConvertPrimitive(bool overrideArchCheck, Type type)
		{
			object obj = ReadPrimitive(type, overrideArchCheck);
			if (obj is uint && type == typeof(ulong))
			{
				obj = Convert.ToUInt64(obj);
			}
			if (obj is int && type == typeof(long))
			{
				obj = Convert.ToInt64(obj);
			}
			return obj;
		}

		private void ReadClassFieldwise<T>(bool overrideArchCheck, T t) where T : new()
		{
			if (t == null)
			{
				throw new ArgumentNullException("t");
			}
			FieldInfo[] fieldsCached = GetFieldsCached(t.GetType());
			foreach (FieldInfo fieldInfo in fieldsCached)
			{
				if (!_cachedNoSerialize.ContainsKey(fieldInfo))
				{
					_cachedNoSerialize[fieldInfo] = Attribute.GetCustomAttribute(fieldInfo, typeof(NonSerializedAttribute)) != null;
				}
				if (!_cachedNoSerialize[fieldInfo] && LibCpp2ILUtils.ShouldReadFieldOnThisVersion(fieldInfo))
				{
					if (fieldInfo.FieldType.IsPrimitive)
					{
						fieldInfo.SetValue(t, ReadPrimitive(fieldInfo.FieldType));
					}
					else
					{
						fieldInfo.SetValue(t, InternalReadClass(fieldInfo.FieldType, overrideArchCheck));
					}
				}
			}
		}

		public T[] ReadClassArrayAtRawAddr<T>(ulong offset, ulong count) where T : new()
		{
			return ReadClassArrayAtRawAddr<T>((long)offset, (long)count);
		}

		public T[] ReadClassArrayAtRawAddr<T>(long offset, long count) where T : new()
		{
			T[] array = new T[count];
			bool lockTaken = false;
			PositionShiftLock.Enter(ref lockTaken);
			if (!lockTaken)
			{
				throw new Exception("Failed to obtain lock");
			}
			try
			{
				if (offset != -1)
				{
					Position = offset;
				}
				for (int i = 0; i < count; i++)
				{
					array[i] = InternalReadClass<T>();
				}
				return array;
			}
			finally
			{
				PositionShiftLock.Exit();
			}
		}

		public string ReadStringToNull(ulong offset)
		{
			return ReadStringToNull((long)offset);
		}

		public virtual string ReadStringToNull(long offset)
		{
			List<byte> list = new List<byte>();
			bool lockTaken = false;
			PositionShiftLock.Enter(ref lockTaken);
			if (!lockTaken)
			{
				throw new Exception("Failed to obtain lock");
			}
			try
			{
				Position = offset;
				byte item;
				while ((item = (byte)_memoryStream.ReadByte()) != 0)
				{
					list.Add(item);
				}
				return Encoding.UTF8.GetString(list.ToArray());
			}
			finally
			{
				PositionShiftLock.Exit();
			}
		}

		public byte[] ReadByteArrayAtRawAddress(long offset, int count)
		{
			bool lockTaken = false;
			PositionShiftLock.Enter(ref lockTaken);
			if (!lockTaken)
			{
				throw new Exception("Failed to obtain lock");
			}
			try
			{
				Position = offset;
				byte[] array = new byte[count];
				Read(array, 0, count);
				return array;
			}
			finally
			{
				PositionShiftLock.Exit();
			}
		}

		protected void WriteWord(int position, ulong word)
		{
			WriteWord(position, (long)word);
		}

		protected void WriteWord(int position, long word)
		{
			bool lockTaken = false;
			PositionShiftLock.Enter(ref lockTaken);
			if (!lockTaken)
			{
				throw new Exception("Failed to obtain lock");
			}
			try
			{
				byte[] array = ((!is32Bit) ? BitConverter.GetBytes(word) : BitConverter.GetBytes((int)word));
				if (shouldReverseArrays)
				{
					array = array.Reverse();
				}
				if (position > _memoryStream.Length)
				{
					throw new Exception($"WriteWord: Position {position} beyond length {_memoryStream.Length}");
				}
				int num = (is32Bit ? 4 : 8);
				if (position + num > _memoryStream.Length)
				{
					throw new Exception($"WriteWord: Writing {num} bytes at {position} would go beyond length {_memoryStream.Length}");
				}
				if (array.Length != num)
				{
					throw new Exception($"WriteWord: Expected {num} bytes from BitConverter, got {position}");
				}
				try
				{
					_memoryStream.Seek(position, SeekOrigin.Begin);
					_memoryStream.Write(array, 0, num);
				}
				catch
				{
					LibLogger.ErrorNewline("WriteWord: Unexpected exception!");
					throw;
				}
			}
			finally
			{
				PositionShiftLock.Exit();
			}
		}

		private static FieldInfo[] GetFieldsCached(Type t)
		{
			if (CachedFields.TryGetValue(t, out FieldInfo[] value))
			{
				return value;
			}
			return CachedFields[t] = t.GetFields();
		}

		public ulong ReadNUint()
		{
			if (!is32Bit)
			{
				return ReadUInt64();
			}
			return ReadUInt32();
		}
	}
	public class EndianAwareBinaryReader : BinaryReader
	{
		protected bool shouldReverseArrays = !BitConverter.IsLittleEndian;

		public bool IsBigEndian;

		public EndianAwareBinaryReader(Stream input)
			: base(input)
		{
		}

		public EndianAwareBinaryReader(Stream input, Encoding encoding)
			: base(input, encoding)
		{
		}

		public EndianAwareBinaryReader(Stream input, Encoding encoding, bool leaveOpen)
			: base(input, encoding, leaveOpen)
		{
		}

		protected void SetBigEndian()
		{
			shouldReverseArrays = BitConverter.IsLittleEndian;
			IsBigEndian = true;
		}

		public sealed override short ReadInt16()
		{
			if (!shouldReverseArrays)
			{
				return base.ReadInt16();
			}
			return this.ReadInt16WithReversedBits();
		}

		public sealed override int ReadInt32()
		{
			if (!shouldReverseArrays)
			{
				return base.ReadInt32();
			}
			return this.ReadInt32WithReversedBits();
		}

		public sealed override long ReadInt64()
		{
			if (!shouldReverseArrays)
			{
				return base.ReadInt64();
			}
			return this.ReadInt64WithReversedBits();
		}

		public sealed override ushort ReadUInt16()
		{
			if (!shouldReverseArrays)
			{
				return base.ReadUInt16();
			}
			return this.ReadUInt16WithReversedBits();
		}

		public sealed override uint ReadUInt32()
		{
			if (!shouldReverseArrays)
			{
				return base.ReadUInt32();
			}
			return this.ReadUInt32WithReversedBits();
		}

		public sealed override ulong ReadUInt64()
		{
			if (!shouldReverseArrays)
			{
				return base.ReadUInt64();
			}
			return this.ReadUInt64WithReversedBits();
		}

		public sealed override float ReadSingle()
		{
			if (!shouldReverseArrays)
			{
				return base.ReadSingle();
			}
			return this.ReadSingleWithReversedBits();
		}

		public sealed override double ReadDouble()
		{
			if (!shouldReverseArrays)
			{
				return base.ReadDouble();
			}
			return this.ReadDoubleWithReversedBits();
		}
	}
	public static class Extensions
	{
		public static T[] SubArray<T>(this T[] data, int index, int length)
		{
			T[] array = new T[length];
			Array.Copy(data, index, array, 0, length);
			return array;
		}

		public static T RemoveAndReturn<T>(this List<T> data, int index)
		{
			T result = data[index];
			data.RemoveAt(index);
			return result;
		}

		public static string Repeat(this string source, int count)
		{
			StringBuilder stringBuilder = new StringBuilder();
			for (int i = 0; i < count; i++)
			{
				stringBuilder.Append(source);
			}
			return stringBuilder.ToString();
		}

		public static string ToStringEnumerable<T>(this IEnumerable<T> enumerable)
		{
			StringBuilder stringBuilder = new StringBuilder("[");
			stringBuilder.Append(string.Join(", ", enumerable));
			stringBuilder.Append("]");
			return stringBuilder.ToString();
		}

		public static TValue? GetValueOrDefault<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key, TValue? defaultValue)
		{
			if (dictionary == null)
			{
				throw new ArgumentNullException("dictionary");
			}
			if (dictionary.TryGetValue(key, out TValue value))
			{
				return value;
			}
			return defaultValue;
		}

		public static TValue? GetValueOrDefault<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key)
		{
			return dictionary.GetValueOrDefault(key, default(TValue));
		}

		public static void Deconstruct<TKey, TValue>(this KeyValuePair<TKey, TValue> pair, out TKey one, out TValue two)
		{
			one = pair.Key;
			two = pair.Value;
		}

		public static uint Bits(this uint x, int low, int count)
		{
			return (x >> low) & (uint)((1 << count) - 1);
		}

		public static bool TryAdd<TKey, TValue>(this Dictionary<TKey, TValue> dictionary, TKey key, TValue value)
		{
			if (dictionary.ContainsKey(key))
			{
				return false;
			}
			dictionary.Add(key, value);
			return true;
		}

		public static void SortByExtractedKey<T, K>(this List<T> list, Func<T, K> keyObtainer) where K : IComparable<K>
		{
			Func<T, K> keyObtainer2 = keyObtainer;
			list.Sort(delegate(T a, T b)
			{
				K val = keyObtainer2(a);
				K other = keyObtainer2(b);
				return val.CompareTo(other);
			});
		}

		public static int ParseDigit(this char c)
		{
			return c - 48;
		}
	}
	public interface IIl2CppTokenProvider
	{
		uint Token { get; }
	}
	public abstract class Il2CppBinary : ClassReadingBinaryReader
	{
		public InstructionSet InstructionSet;

		protected readonly long maxMetadataUsages;

		private Il2CppMetadataRegistration metadataRegistration;

		private Il2CppCodeRegistration codeRegistration;

		protected ulong[] methodPointers;

		private ulong[] genericMethodPointers;

		private ulong[] invokerPointers;

		private ulong[]? customAttributeGenerators;

		protected long[] fieldOffsets;

		protected ulong[] metadataUsages;

		protected ulong[][] codeGenModuleMethodPointers;

		protected Il2CppType[] types;

		private Il2CppGenericMethodFunctionsDefinitions[] genericMethodTables;

		protected Il2CppGenericInst[] genericInsts;

		protected Il2CppMethodSpec[] methodSpecs;

		protected Il2CppCodeGenModule[] codeGenModules;

		protected Il2CppTokenRangePair[][] codegenModuleRgctxRanges;

		protected Il2CppRGCTXDefinition[][] codegenModuleRgctxs;

		protected Dictionary<int, ulong> genericMethodDictionary;

		protected readonly Dictionary<ulong, Il2CppType> typesDict = new Dictionary<ulong, Il2CppType>();

		public readonly Dictionary<Il2CppMethodDefinition, List<Il2CppGenericMethodRef>> ConcreteGenericMethods = new Dictionary<Il2CppMethodDefinition, List<Il2CppGenericMethodRef>>();

		public readonly Dictionary<ulong, List<Il2CppGenericMethodRef>> ConcreteGenericImplementationsByAddress = new Dictionary<ulong, List<Il2CppGenericMethodRef>>();

		public ulong[] TypeDefinitionSizePointers;

		public abstract long RawLength { get; }

		public int NumTypes => types.Length;

		public ulong[] AllCustomAttributeGenerators
		{
			get
			{
				if (!(LibCpp2IlMain.MetadataVersion >= 29f))
				{
					if (!(LibCpp2IlMain.MetadataVersion >= 27f))
					{
						return customAttributeGenerators;
					}
					return AllCustomAttributeGeneratorsV27;
				}
				return Array.Empty<ulong>();
			}
		}

		private ulong[] AllCustomAttributeGeneratorsV27 => (from p in LibCpp2IlMain.TheMetadata.imageDefinitions.Select((Il2CppImageDefinition i) => (i, GetCodegenModuleByName(i.Name), (ulong)(is32Bit ? 4 : 8))).SelectMany<(Il2CppImageDefinition, Il2CppCodeGenModule, ulong), ulong>(((Il2CppImageDefinition image, Il2CppCodeGenModule cgm, ulong ptrSize) tuple) => from o in LibCpp2ILUtils.Range(0, (int)tuple.image.customAttributeCount)
				select tuple.cgm.customAttributeCacheGenerator + (ulong)((long)o * (long)tuple.ptrSize))
			select ReadClassAtVirtualAddress<ulong>(p)).ToArray();

		protected Il2CppBinary(MemoryStream input, long maxMetadataUsages)
			: base(input)
		{
			this.maxMetadataUsages = maxMetadataUsages;
		}

		public void Init(ulong pCodeRegistration, ulong pMetadataRegistration)
		{
			codeRegistration = ReadClassAtVirtualAddress<Il2CppCodeRegistration>(pCodeRegistration);
			metadataRegistration = ReadClassAtVirtualAddress<Il2CppMetadataRegistration>(pMetadataRegistration);
			LibLogger.Verbose("\tReading generic instances...");
			DateTime now = DateTime.Now;
			genericInsts = Array.ConvertAll(ReadClassArrayAtVirtualAddress<ulong>(metadataRegistration.genericInsts, metadataRegistration.genericInstsCount), ReadClassAtVirtualAddress<Il2CppGenericInst>);
			LibLogger.VerboseNewline($"OK ({(DateTime.Now - now).TotalMilliseconds} ms)");
			LibLogger.Verbose("\tReading generic method pointers...");
			now = DateTime.Now;
			genericMethodPointers = ReadClassArrayAtVirtualAddress<ulong>(codeRegistration.genericMethodPointers, (long)codeRegistration.genericMethodPointersCount);
			LibLogger.VerboseNewline($"OK ({(DateTime.Now - now).TotalMilliseconds} ms)");
			LibLogger.Verbose("\tReading invoker pointers...");
			now = DateTime.Now;
			invokerPointers = ReadClassArrayAtVirtualAddress<ulong>(codeRegistration.invokerPointers, (long)codeRegistration.invokerPointersCount);
			LibLogger.VerboseNewline($"OK ({(DateTime.Now - now).TotalMilliseconds} ms)");
			if (LibCpp2IlMain.MetadataVersion < 27f)
			{
				LibLogger.Verbose("\tReading custom attribute generators...");
				now = DateTime.Now;
				customAttributeGenerators = ReadClassArrayAtVirtualAddress<ulong>(codeRegistration.customAttributeGeneratorListAddress, (long)codeRegistration.customAttributeCount);
				LibLogger.VerboseNewline($"OK ({(DateTime.Now - now).TotalMilliseconds} ms)");
			}
			LibLogger.Verbose("\tReading field offsets...");
			now = DateTime.Now;
			fieldOffsets = ReadClassArrayAtVirtualAddress<long>(metadataRegistration.fieldOffsetListAddress, metadataRegistration.fieldOffsetsCount);
			LibLogger.VerboseNewline($"OK ({(DateTime.Now - now).TotalMilliseconds} ms)");
			LibLogger.Verbose("\tReading types...");
			now = DateTime.Now;
			ulong[] array = ReadClassArrayAtVirtualAddress<ulong>(metadataRegistration.typeAddressListAddress, metadataRegistration.numTypes);
			types = new Il2CppType[metadataRegistration.numTypes];
			for (int i = 0; i < metadataRegistration.numTypes; i++)
			{
				types[i] = ReadClassAtVirtualAddress<Il2CppType>(array[i]);
				types[i].Init();
				typesDict[array[i]] = types[i];
			}
			LibLogger.VerboseNewline($"OK ({(DateTime.Now - now).TotalMilliseconds} ms)");
			LibLogger.Verbose("\tReading type definition sizes...");
			now = DateTime.Now;
			TypeDefinitionSizePointers = ReadClassArrayAtVirtualAddress<ulong>(metadataRegistration.typeDefinitionsSizes, metadataRegistration.typeDefinitionsSizesCount);
			LibLogger.VerboseNewline($"OK ({(DateTime.Now - now).TotalMilliseconds} ms)");
			if (metadataRegistration.metadataUsages != 0L)
			{
				LibLogger.Verbose("\tReading metadata usages...");
				now = DateTime.Now;
				metadataUsages = ReadClassArrayAtVirtualAddress<ulong>(metadataRegistration.metadataUsages, (long)Math.Max((decimal)metadataRegistration.metadataUsagesCount, (decimal)maxMetadataUsages));
				LibLogger.VerboseNewline($"OK ({(DateTime.Now - now).TotalMilliseconds} ms)");
			}
			if (LibCpp2IlMain.MetadataVersion >= 24.2f)
			{
				LibLogger.VerboseNewline("\tReading code gen modules...");
				now = DateTime.Now;
				ulong[] array2 = ReadClassArrayAtVirtualAddress<ulong>(codeRegistration.addrCodeGenModulePtrs, (long)codeRegistration.codeGenModulesCount);
				codeGenModules = new Il2CppCodeGenModule[array2.Length];
				codeGenModuleMethodPointers = new ulong[array2.Length][];
				codegenModuleRgctxRanges = new Il2CppTokenRangePair[array2.Length][];
				codegenModuleRgctxs = new Il2CppRGCTXDefinition[array2.Length][];
				for (int j = 0; j < array2.Length; j++)
				{
					Il2CppCodeGenModule il2CppCodeGenModule = ReadClassAtVirtualAddress<Il2CppCodeGenModule>(array2[j]);
					codeGenModules[j] = il2CppCodeGenModule;
					string text = ReadStringToNull(MapVirtualAddressToRaw(il2CppCodeGenModule.moduleName));
					LibLogger.VerboseNewline($"\t\t-Read module data for {text}, contains {il2CppCodeGenModule.methodPointerCount} method pointers starting at 0x{il2CppCodeGenModule.methodPointers:X}");
					if (il2CppCodeGenModule.methodPointerCount > 0)
					{
						try
						{
							ulong[] array3 = ReadClassArrayAtVirtualAddress<ulong>(il2CppCodeGenModule.methodPointers, il2CppCodeGenModule.methodPointerCount);
							codeGenModuleMethodPointers[j] = array3;
							LibLogger.VerboseNewline($"\t\t\t-Read {il2CppCodeGenModule.methodPointerCount} method pointers.");
						}
						catch (Exception ex)
						{
							LibLogger.VerboseNewline("\t\t\tWARNING: Unable to get function pointers for " + text + ": " + ex.Message);
							codeGenModuleMethodPointers[j] = new ulong[il2CppCodeGenModule.methodPointerCount];
						}
					}
					if (il2CppCodeGenModule.rgctxRangesCount > 0)
					{
						try
						{
							Il2CppTokenRangePair[] array4 = ReadClassArrayAtVirtualAddress<Il2CppTokenRangePair>(il2CppCodeGenModule.pRgctxRanges, il2CppCodeGenModule.rgctxRangesCount);
							codegenModuleRgctxRanges[j] = array4;
							LibLogger.VerboseNewline($"\t\t\t-Read {il2CppCodeGenModule.rgctxRangesCount} RGCTX ranges.");
						}
						catch (Exception ex2)
						{
							LibLogger.VerboseNewline("\t\t\tWARNING: Unable to get RGCTX ranges for " + text + ": " + ex2.Message);
							codegenModuleRgctxRanges[j] = new Il2CppTokenRangePair[il2CppCodeGenModule.rgctxRangesCount];
						}
					}
					if (il2CppCodeGenModule.rgctxsCount > 0)
					{
						try
						{
							Il2CppRGCTXDefinition[] array5 = ReadClassArrayAtVirtualAddress<Il2CppRGCTXDefinition>(il2CppCodeGenModule.rgctxs, il2CppCodeGenModule.rgctxsCount);
							codegenModuleRgctxs[j] = array5;
							LibLogger.VerboseNewline($"\t\t\t-Read {il2CppCodeGenModule.rgctxsCount} RGCTXs.");
						}
						catch (Exception ex3)
						{
							LibLogger.VerboseNewline("\t\t\tWARNING: Unable to get RGCTXs for " + text + ": " + ex3.Message);
							codegenModuleRgctxs[j] = new Il2CppRGCTXDefinition[il2CppCodeGenModule.rgctxsCount];
						}
					}
				}
				LibLogger.VerboseNewline($"\tOK ({(DateTime.Now - now).TotalMilliseconds} ms)");
			}
			else
			{
				LibLogger.Verbose("\tReading method pointers...");
				now = DateTime.Now;
				methodPointers = ReadClassArrayAtVirtualAddress<ulong>(codeRegistration.methodPointers, (long)codeRegistration.methodPointersCount);
				LibLogger.VerboseNewline($"Read {methodPointers.Length} OK ({(DateTime.Now - now).TotalMilliseconds} ms)");
			}
			LibLogger.Verbose("\tReading generic method tables...");
			now = DateTime.Now;
			genericMethodTables = ReadClassArrayAtVirtualAddress<Il2CppGenericMethodFunctionsDefinitions>(metadataRegistration.genericMethodTable, metadataRegistration.genericMethodTableCount);
			LibLogger.VerboseNewline($"OK ({(DateTime.Now - now).TotalMilliseconds} ms)");
			LibLogger.Verbose("\tReading method specifications...");
			now = DateTime.Now;
			methodSpecs = ReadClassArrayAtVirtualAddress<Il2CppMethodSpec>(metadataRegistration.methodSpecs, metadataRegistration.methodSpecsCount);
			LibLogger.VerboseNewline($"OK ({(DateTime.Now - now).TotalMilliseconds} ms)");
			LibLogger.Verbose("\tReading generic methods...");
			now = DateTime.Now;
			genericMethodDictionary = new Dictionary<int, ulong>();
			Il2CppGenericMethodFunctionsDefinitions[] array6 = genericMethodTables;
			foreach (Il2CppGenericMethodFunctionsDefinitions obj in array6)
			{
				int genericMethodIndex = obj.genericMethodIndex;
				int methodIndex = obj.indices.methodIndex;
				Il2CppGenericMethodRef genericMethodRef;
				int genericMethodFromIndex = GetGenericMethodFromIndex(genericMethodIndex, methodIndex, out genericMethodRef);
				if (!genericMethodDictionary.ContainsKey(genericMethodFromIndex) && methodIndex < genericMethodPointers.Length)
				{
					Extensions.TryAdd(genericMethodDictionary, genericMethodFromIndex, genericMethodPointers[methodIndex]);
				}
			}
			LibLogger.VerboseNewline($"OK ({(DateTime.Now - now).TotalMilliseconds} ms)");
		}

		private int GetGenericMethodFromIndex(int genericMethodIndex, int genericMethodPointerIndex, out Il2CppGenericMethodRef? genericMethodRef)
		{
			Il2CppMethodSpec methodSpec = GetMethodSpec(genericMethodIndex);
			int methodDefinitionIndex = methodSpec.methodDefinitionIndex;
			genericMethodRef = new Il2CppGenericMethodRef(methodSpec);
			if (genericMethodPointerIndex >= 0 && genericMethodPointerIndex < genericMethodPointers.Length)
			{
				genericMethodRef.GenericVariantPtr = genericMethodPointers[genericMethodPointerIndex];
			}
			if (!ConcreteGenericMethods.ContainsKey(genericMethodRef.BaseMethod))
			{
				ConcreteGenericMethods[genericMethodRef.BaseMethod] = new List<Il2CppGenericMethodRef>();
			}
			ConcreteGenericMethods[genericMethodRef.BaseMethod].Add(genericMethodRef);
			if (genericMethodRef.GenericVariantPtr != 0)
			{
				if (!ConcreteGenericImplementationsByAddress.ContainsKey(genericMethodRef.GenericVariantPtr))
				{
					ConcreteGenericImplementationsByAddress[genericMethodRef.GenericVariantPtr] = new List<Il2CppGenericMethodRef>();
				}
				ConcreteGenericImplementationsByAddress[genericMethodRef.GenericVariantPtr].Add(genericMethodRef);
			}
			return methodDefinitionIndex;
		}

		public abstract byte GetByteAtRawAddress(ulong addr);

		public abstract long MapVirtualAddressToRaw(ulong uiAddr);

		public abstract ulong MapRawAddressToVirtual(uint offset);

		public abstract ulong GetRVA(ulong pointer);

		public bool TryMapRawAddressToVirtual(in uint offset, out ulong va)
		{
			try
			{
				va = MapRawAddressToVirtual(offset);
				return true;
			}
			catch (Exception)
			{
				va = 0uL;
				return false;
			}
		}

		public bool TryMapVirtualAddressToRaw(ulong virtAddr, out long result)
		{
			try
			{
				result = MapVirtualAddressToRaw(virtAddr);
				return true;
			}
			catch (Exception)
			{
				result = 0L;
				return false;
			}
		}

		public T[] ReadClassArrayAtVirtualAddress<T>(ulong addr, long count) where T : new()
		{
			return ReadClassArrayAtRawAddr<T>(MapVirtualAddressToRaw(addr), count);
		}

		public T ReadClassAtVirtualAddress<T>(ulong addr) where T : new()
		{
			return ReadClassAtRawAddr<T>(MapVirtualAddressToRaw(addr));
		}

		public Il2CppGenericInst GetGenericInst(int index)
		{
			return genericInsts[index];
		}

		public Il2CppMethodSpec GetMethodSpec(int index)
		{
			if (index < methodSpecs.Length)
			{
				if (index >= 0)
				{
					return methodSpecs[index];
				}
				throw new ArgumentException($"GetMethodSpec: index {index} < 0");
			}
			throw new ArgumentException($"GetMethodSpec: index {index} >= length {methodSpecs.Length}");
		}

		public Il2CppType GetType(int index)
		{
			return types[index];
		}

		public ulong GetRawMetadataUsage(uint index)
		{
			return metadataUsages[index];
		}

		public ulong[] GetCodegenModuleMethodPointers(int codegenModuleIndex)
		{
			return codeGenModuleMethodPointers[codegenModuleIndex];
		}

		public Il2CppCodeGenModule? GetCodegenModuleByName(string name)
		{
			string name2 = name;
			return codeGenModules.FirstOrDefault((Il2CppCodeGenModule m) => m.Name == name2);
		}

		public int GetCodegenModuleIndex(Il2CppCodeGenModule module)
		{
			return Array.IndexOf(codeGenModules, module);
		}

		public int GetCodegenModuleIndexByName(string name)
		{
			Il2CppCodeGenModule codegenModuleByName = GetCodegenModuleByName(name);
			if (codegenModuleByName == null)
			{
				return -1;
			}
			return GetCodegenModuleIndex(codegenModuleByName);
		}

		public Il2CppTokenRangePair[] GetRGCTXRangePairsForModule(Il2CppCodeGenModule module)
		{
			return codegenModuleRgctxRanges[GetCodegenModuleIndex(module)];
		}

		public Il2CppRGCTXDefinition[] GetRGCTXDataForPair(Il2CppCodeGenModule module, Il2CppTokenRangePair rangePair)
		{
			return codegenModuleRgctxs[GetCodegenModuleIndex(module)].Skip(rangePair.start).Take(rangePair.length).ToArray();
		}

		public Il2CppType GetIl2CppTypeFromPointer(ulong pointer)
		{
			return typesDict[pointer];
		}

		public ulong[] GetPointers(ulong pointer, long count)
		{
			if (is32Bit)
			{
				return Array.ConvertAll(ReadClassArrayAtVirtualAddress<uint>(pointer, count), (Converter<uint, ulong>)((uint x) => x));
			}
			return ReadClassArrayAtVirtualAddress<ulong>(pointer, count);
		}

		public int GetFieldOffsetFromIndex(int typeIndex, int fieldIndexInType, int fieldIndex, bool isValueType, bool isStatic)
		{
			try
			{
				int num = -1;
				if (LibCpp2IlMain.MetadataVersion > 21f)
				{
					ulong num2 = (ulong)fieldOffsets[typeIndex];
					if (num2 != 0)
					{
						num = ReadClassAtRawAddr<int>(MapVirtualAddressToRaw(num2) + 4L * (long)fieldIndexInType);
					}
				}
				else
				{
					num = (int)fieldOffsets[fieldIndex];
				}
				if (num > 0 && isValueType && !isStatic)
				{
					num = ((!is32Bit) ? (num - 16) : (num - 8));
				}
				return num;
			}
			catch
			{
				return -1;
			}
		}

		public ulong GetMethodPointer(int methodIndex, int methodDefinitionIndex, int imageIndex, uint methodToken)
		{
			if (LibCpp2IlMain.MetadataVersion >= 24.2f)
			{
				if (genericMethodDictionary.TryGetValue(methodDefinitionIndex, out var value))
				{
					return value;
				}
				ulong[] obj = codeGenModuleMethodPointers[imageIndex];
				uint num = methodToken & 0xFFFFFFu;
				return obj[num - 1];
			}
			if (methodIndex >= 0)
			{
				return methodPointers[methodIndex];
			}
			genericMethodDictionary.TryGetValue(methodDefinitionIndex, out var value2);
			return value2;
		}

		public ulong GetCustomAttributeGenerator(int index)
		{
			return customAttributeGenerators[index];
		}

		public abstract byte[] GetRawBinaryContent();

		public abstract ulong GetVirtualAddressOfExportedFunctionByName(string toFind);

		public abstract byte[] GetEntirePrimaryExecutableSection();

		public abstract ulong GetVirtualAddressOfPrimaryExecutableSection();

		public (ulong pCodeRegistration, ulong pMetadataRegistration) PlusSearch(int methodCount, int typeDefinitionsCount)
		{
			ulong result = 0uL;
			LibLogger.VerboseNewline("\tAttempting to locate code and metadata registration functions...");
			BinarySearcher binarySearcher = new BinarySearcher(this, methodCount, typeDefinitionsCount);
			LibLogger.VerboseNewline("\t\t-Searching for MetadataReg...");
			ulong result2 = ((LibCpp2IlMain.MetadataVersion < 24.5f) ? binarySearcher.FindMetadataRegistrationPre24_5() : binarySearcher.FindMetadataRegistrationPost24_5());
			LibLogger.VerboseNewline("\t\t-Searching for CodeReg...");
			if (result == 0L)
			{
				if (LibCpp2IlMain.MetadataVersion >= 24.2f)
				{
					LibLogger.VerboseNewline("\t\t\tUsing mscorlib full-disassembly approach to get codereg, this may take a while...");
					result = binarySearcher.FindCodeRegistrationPost2019();
				}
				else
				{
					result = binarySearcher.FindCodeRegistrationPre2019();
				}
			}
			if (result == 0L && LibCpp2IlMain.Settings.AllowManualMetadataAndCodeRegInput)
			{
				LibLogger.Info("Couldn't identify a CodeRegistration address. If you know it, enter it now, otherwise enter nothing or zero to fail: ");
				ulong.TryParse(Console.ReadLine(), NumberStyles.HexNumber, null, out result);
			}
			if (result2 == 0L && LibCpp2IlMain.Settings.AllowManualMetadataAndCodeRegInput)
			{
				LibLogger.Info("Couldn't identify a MetadataRegistration address. If you know it, enter it now, otherwise enter nothing or zero to fail: ");
				ulong.TryParse(Console.ReadLine(), NumberStyles.HexNumber, null, out result2);
			}
			return (result, result2);
		}
	}
	public class Il2CppGenericMethodRef
	{
		public readonly Il2CppTypeDefinition DeclaringType;

		public readonly Il2CppTypeReflectionData[] TypeGenericParams;

		public readonly Il2CppMethodDefinition BaseMethod;

		public readonly Il2CppTypeReflectionData[] MethodGenericParams;

		public ulong GenericVariantPtr;

		public Il2CppGenericMethodRef(Il2CppMethodSpec methodSpec)
		{
			Il2CppTypeReflectionData[] typeGenericParams = new Il2CppTypeReflectionData[0];
			if (methodSpec.classIndexIndex != -1)
			{
				typeGenericParams = LibCpp2ILUtils.GetGenericTypeParams(methodSpec.GenericClassInst);
			}
			Il2CppTypeReflectionData[] methodGenericParams = new Il2CppTypeReflectionData[0];
			if (methodSpec.methodIndexIndex != -1)
			{
				methodGenericParams = LibCpp2ILUtils.GetGenericTypeParams(methodSpec.GenericMethodInst);
			}
			BaseMethod = methodSpec.MethodDefinition;
			DeclaringType = methodSpec.MethodDefinition.DeclaringType;
			TypeGenericParams = typeGenericParams;
			MethodGenericParams = methodGenericParams;
		}

		public override string ToString()
		{
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.Append(BaseMethod?.ReturnType).Append(" ");
			stringBuilder.Append(DeclaringType.FullName);
			if (TypeGenericParams.Length != 0)
			{
				stringBuilder.Append("<").Append(string.Join(", ", TypeGenericParams.AsEnumerable())).Append(">");
			}
			stringBuilder.Append(".").Append(BaseMethod?.Name);
			if (MethodGenericParams.Length != 0)
			{
				stringBuilder.Append("<").Append(string.Join(", ", MethodGenericParams.AsEnumerable())).Append(">");
			}
			return stringBuilder.ToString();
		}
	}
	public enum InstructionSet
	{
		X86_32,
		X86_64,
		ARM32,
		ARM64,
		WASM
	}
	public static class LEB128
	{
		private const long SIGN_EXTEND_MASK = -1L;

		private const int INT64_BITSIZE = 64;

		public static void WriteLEB128Signed(this Stream stream, long value)
		{
			stream.WriteLEB128Signed(value, out var _);
		}

		public static void WriteLEB128Signed(this Stream stream, long value, out int bytes)
		{
			bytes = 0;
			bool flag = true;
			while (flag)
			{
				byte b = (byte)(value & 0x7F);
				value >>= 7;
				bool flag2 = (b & 0x40) != 0;
				flag = (value != 0L || flag2) && !(value == -1 && flag2);
				if (flag)
				{
					b = (byte)(b | 0x80u);
				}
				stream.WriteByte(b);
				bytes++;
			}
		}

		public static void WriteLEB128Unsigned(this Stream stream, ulong value)
		{
			stream.WriteLEB128Unsigned(value, out var _);
		}

		public static void WriteLEB128Unsigned(this Stream stream, ulong value, out int bytes)
		{
			bytes = 0;
			bool flag = true;
			while (flag)
			{
				byte b = (byte)(value & 0x7F);
				value >>= 7;
				flag = value != 0;
				if (flag)
				{
					b = (byte)(b | 0x80u);
				}
				stream.WriteByte(b);
				bytes++;
			}
		}

		public static long ReadLEB128Signed(this Stream stream)
		{
			int bytes;
			return stream.ReadLEB128Signed(out bytes);
		}

		public static long ReadLEB128Signed(this Stream stream, out int bytes)
		{
			bytes = 0;
			long num = 0L;
			int num2 = 0;
			bool flag = true;
			bool flag2 = false;
			while (flag)
			{
				int num3 = stream.ReadByte();
				if (num3 < 0)
				{
					throw new InvalidOperationException("Unexpected end of stream");
				}
				byte num4 = (byte)num3;
				bytes++;
				flag = (num4 & 0x80) != 0;
				flag2 = (num4 & 0x40) != 0;
				long num5 = (long)num4 & 0x7FL;
				num |= num5 << num2;
				num2 += 7;
			}
			if (num2 < 64 && flag2)
			{
				num |= -1L << num2;
			}
			return num;
		}

		public static ulong ReadLEB128Unsigned(this Stream stream)
		{
			int bytes;
			return stream.ReadLEB128Unsigned(out bytes);
		}

		public static ulong ReadLEB128Unsigned(this Stream stream, out int bytes)
		{
			bytes = 0;
			ulong num = 0uL;
			int num2 = 0;
			bool flag = true;
			while (flag)
			{
				int num3 = stream.ReadByte();
				if (num3 < 0)
				{
					throw new InvalidOperationException("Unexpected end of stream");
				}
				byte num4 = (byte)num3;
				bytes++;
				flag = (num4 & 0x80) != 0;
				ulong num5 = (ulong)num4 & 0x7FuL;
				num |= num5 << num2;
				num2 += 7;
			}
			return num;
		}
	}
	public static class LibCpp2IlGlobalMapper
	{
		internal static List<MetadataUsage> TypeRefs = new List<MetadataUsage>();

		internal static List<MetadataUsage> MethodRefs = new List<MetadataUsage>();

		internal static List<MetadataUsage> FieldRefs = new List<MetadataUsage>();

		internal static List<MetadataUsage> Literals = new List<MetadataUsage>();

		internal static Dictionary<ulong, MetadataUsage> TypeRefsByAddress = new Dictionary<ulong, MetadataUsage>();

		internal static Dictionary<ulong, MetadataUsage> MethodRefsByAddress = new Dictionary<ulong, MetadataUsage>();

		internal static Dictionary<ulong, MetadataUsage> FieldRefsByAddress = new Dictionary<ulong, MetadataUsage>();

		internal static Dictionary<ulong, MetadataUsage> LiteralsByAddress = new Dictionary<ulong, MetadataUsage>();

		internal static void Reset()
		{
			TypeRefs.Clear();
			MethodRefs.Clear();
			FieldRefs.Clear();
			Literals.Clear();
			TypeRefsByAddress.Clear();
			MethodRefsByAddress.Clear();
			FieldRefsByAddress.Clear();
			LiteralsByAddress.Clear();
		}

		internal static void MapGlobalIdentifiers(Il2CppMetadata metadata, Il2CppBinary cppAssembly)
		{
			if (LibCpp2IlMain.MetadataVersion < 27f)
			{
				MapGlobalIdentifiersPre27(metadata, cppAssembly);
			}
			else
			{
				MapGlobalIdentifiersPost27(metadata, cppAssembly);
			}
		}

		private static void MapGlobalIdentifiersPost27(Il2CppMetadata metadata, Il2CppBinary cppAssembly)
		{
		}

		private static void MapGlobalIdentifiersPre27(Il2CppMetadata metadata, Il2CppBinary cppAssembly)
		{
			Il2CppBinary cppAssembly2 = cppAssembly;
			TypeRefs = metadata.metadataUsageDic[1u].Select((KeyValuePair<uint, uint> kvp) => new MetadataUsage(MetadataUsageType.Type, cppAssembly2.GetRawMetadataUsage(kvp.Key), kvp.Value)).ToList();
			TypeRefs.AddRange(metadata.metadataUsageDic[2u].Select((KeyValuePair<uint, uint> kvp) => new MetadataUsage(MetadataUsageType.Type, cppAssembly2.GetRawMetadataUsage(kvp.Key), kvp.Value)));
			MethodRefs = metadata.metadataUsageDic[3u].Select((KeyValuePair<uint, uint> kvp) => new MetadataUsage(MetadataUsageType.MethodDef, cppAssembly2.GetRawMetadataUsage(kvp.Key), kvp.Value)).ToList();
			FieldRefs = metadata.metadataUsageDic[4u].Select((KeyValuePair<uint, uint> kvp) => new MetadataUsage(MetadataUsageType.FieldInfo, cppAssembly2.GetRawMetadataUsage(kvp.Key), kvp.Value)).ToList();
			Literals = metadata.metadataUsageDic[5u].Select((KeyValuePair<uint, uint> kvp) => new MetadataUsage(MetadataUsageType.StringLiteral, cppAssembly2.GetRawMetadataUsage(kvp.Key), kvp.Value)).ToList();
			foreach (var (index, value) in metadata.metadataUsageDic[6u])
			{
				MethodRefs.Add(new MetadataUsage(MetadataUsageType.MethodRef, cppAssembly2.GetRawMetadataUsage(index), value));
			}
			foreach (MetadataUsage typeRef in TypeRefs)
			{
				TypeRefsByAddress[typeRef.Offset] = typeRef;
			}
			foreach (MetadataUsage methodRef in MethodRefs)
			{
				MethodRefsByAddress[methodRef.Offset] = methodRef;
			}
			foreach (MetadataUsage fieldRef in FieldRefs)
			{
				FieldRefsByAddress[fieldRef.Offset] = fieldRef;
			}
			foreach (MetadataUsage literal in Literals)
			{
				LiteralsByAddress[literal.Offset] = literal;
			}
		}

		public static MetadataUsage? CheckForPost27GlobalAt(ulong address)
		{
			if (!LibCpp2IlMain.Binary.TryMapVirtualAddressToRaw(address, out var result) || result >= LibCpp2IlMain.Binary.RawLength)
			{
				return null;
			}
			MetadataUsage metadataUsage = MetadataUsage.DecodeMetadataUsage(LibCpp2IlMain.Binary.ReadClassAtVirtualAddress<ulong>(address), address);
			if (metadataUsage == null || !metadataUsage.IsValid)
			{
				return null;
			}
			return metadataUsage;
		}
	}
	public static class LibCpp2IlMain
	{
		public class LibCpp2IlSettings
		{
			public bool AllowManualMetadataAndCodeRegInput;

			public bool DisableMethodPointerMapping;

			public bool DisableGlobalResolving;
		}

		public static readonly LibCpp2IlSettings Settings = new LibCpp2IlSettings();

		public static float MetadataVersion = 24f;

		public static Il2CppBinary? Binary;

		public static Il2CppMetadata? TheMetadata;

		private static readonly Dictionary<ulong, List<Il2CppMethodDefinition>> MethodsByPtr = new Dictionary<ulong, List<Il2CppMethodDefinition>>();

		public static void Reset()
		{
			LibCpp2IlGlobalMapper.Reset();
			LibCpp2ILUtils.Reset();
			MethodsByPtr.Clear();
			MetadataVersion = 0f;
			Binary?.Dispose();
			TheMetadata?.Dispose();
			Binary = null;
			TheMetadata = null;
		}

		public static List<Il2CppMethodDefinition>? GetManagedMethodImplementationsAtAddress(ulong addr)
		{
			MethodsByPtr.TryGetValue(addr, out List<Il2CppMethodDefinition> value);
			return value;
		}

		public static MetadataUsage? GetAnyGlobalByAddress(ulong address)
		{
			if (MetadataVersion >= 27f)
			{
				return LibCpp2IlGlobalMapper.CheckForPost27GlobalAt(address);
			}
			MetadataUsage metadataUsage = GetLiteralGlobalByAddress(address);
			if (metadataUsage == null)
			{
				metadataUsage = GetMethodGlobalByAddress(address);
			}
			if (metadataUsage == null)
			{
				metadataUsage = GetRawFieldGlobalByAddress(address);
			}
			if (metadataUsage == null)
			{
				metadataUsage = GetRawTypeGlobalByAddress(address);
			}
			return metadataUsage;
		}

		public static MetadataUsage? GetLiteralGlobalByAddress(ulong address)
		{
			if (MetadataVersion < 27f)
			{
				return LibCpp2IlGlobalMapper.LiteralsByAddress.GetValueOrDefault(address);
			}
			return GetAnyGlobalByAddress(address);
		}

		public static string? GetLiteralByAddress(ulong address)
		{
			return GetLiteralGlobalByAddress(address)?.AsLiteral();
		}

		public static MetadataUsage? GetRawTypeGlobalByAddress(ulong address)
		{
			if (MetadataVersion < 27f)
			{
				return LibCpp2IlGlobalMapper.TypeRefsByAddress.GetValueOrDefault(address);
			}
			return GetAnyGlobalByAddress(address);
		}

		public static Il2CppTypeReflectionData? GetTypeGlobalByAddress(ulong address)
		{
			if (TheMetadata == null)
			{
				return null;
			}
			return GetRawTypeGlobalByAddress(address)?.AsType();
		}

		public static MetadataUsage? GetRawFieldGlobalByAddress(ulong address)
		{
			if (MetadataVersion < 27f)
			{
				return LibCpp2IlGlobalMapper.FieldRefsByAddress.GetValueOrDefault(address);
			}
			return GetAnyGlobalByAddress(address);
		}

		public static Il2CppFieldDefinition? GetFieldGlobalByAddress(ulong address)
		{
			if (TheMetadata == null)
			{
				return null;
			}
			return GetRawFieldGlobalByAddress(address)?.AsField();
		}

		public static MetadataUsage? GetMethodGlobalByAddress(ulong address)
		{
			if (TheMetadata == null)
			{
				return null;
			}
			if (MetadataVersion < 27f)
			{
				return LibCpp2IlGlobalMapper.MethodRefsByAddress.GetValueOrDefault(address);
			}
			return GetAnyGlobalByAddress(address);
		}

		public static Il2CppMethodDefinition? GetMethodDefinitionByGlobalAddress(ulong address)
		{
			MetadataUsage methodGlobalByAddress = GetMethodGlobalByAddress(address);
			if (methodGlobalByAddress != null && methodGlobalByAddress.Type == MetadataUsageType.MethodRef)
			{
				return methodGlobalByAddress.AsGenericMethodRef().BaseMethod;
			}
			return methodGlobalByAddress?.AsMethod();
		}

		public static bool Initialize(byte[] binaryBytes, byte[] metadataBytes, int[] unityVersion)
		{
			LibCpp2IlReflection.ResetCaches();
			DateTime now = DateTime.Now;
			LibLogger.InfoNewline("Initializing Metadata...");
			TheMetadata = Il2CppMetadata.ReadFrom(metadataBytes, unityVersion);
			LibLogger.InfoNewline($"Initialized Metadata in {(DateTime.Now - now).TotalMilliseconds:F0}ms");
			if (TheMetadata == null)
			{
				return false;
			}
			LibLogger.InfoNewline("Searching Binary for Required Data...");
			now = DateTime.Now;
			ulong num;
			ulong num2;
			if (BitConverter.ToInt16(binaryBytes, 0) == 23117)
			{
				(num, num2) = (Binary = new LibCpp2IL.PE.PE(new MemoryStream(binaryBytes, 0, binaryBytes.Length, writable: false, publiclyVisible: true), TheMetadata.maxMetadataUsages)).PlusSearch(TheMetadata.methodDefs.Count((Il2CppMethodDefinition x) => x.methodIndex >= 0), TheMetadata.typeDefs.Length);
			}
			else if (BitConverter.ToInt32(binaryBytes, 0) == 1179403647)
			{
				(num, num2) = ((ElfFile)(Binary = new ElfFile(new MemoryStream(binaryBytes, 0, binaryBytes.Length, writable: true, publiclyVisible: true), TheMetadata.maxMetadataUsages))).FindCodeAndMetadataReg();
			}
			else if (BitConverter.ToInt32(binaryBytes, 0) == 810505038)
			{
				(num, num2) = (Binary = new NsoFile(new MemoryStream(binaryBytes, 0, binaryBytes.Length, writable: true, publiclyVisible: true), TheMetadata.maxMetadataUsages).Decompress()).PlusSearch(TheMetadata.methodDefs.Count((Il2CppMethodDefinition x) => x.methodIndex >= 0), TheMetadata.typeDefs.Length);
			}
			else if (BitConverter.ToInt32(binaryBytes, 0) == 1836278016)
			{
				(num, num2) = (Binary = new WasmFile(new MemoryStream(binaryBytes, 0, binaryBytes.Length, writable: false, publiclyVisible: true), TheMetadata.maxMetadataUsages)).PlusSearch(TheMetadata.methodDefs.Count((Il2CppMethodDefinition x) => x.methodIndex >= 0), TheMetadata.typeDefs.Length);
			}
			else
			{
				uint num3 = BitConverter.ToUInt32(binaryBytes, 0);
				if (num3 != 4277009102u && num3 != 4277009103u)
				{
					throw new Exception("Unknown binary type");
				}
				(num, num2) = (Binary = new MachOFile(new MemoryStream(binaryBytes, 0, binaryBytes.Length, writable: false, publiclyVisible: true), TheMetadata.maxMetadataUsages)).PlusSearch(TheMetadata.methodDefs.Count((Il2CppMethodDefinition x) => x.methodIndex >= 0), TheMetadata.typeDefs.Length);
			}
			if (num == 0L || num2 == 0L)
			{
				throw new Exception("Failed to find Binary code or metadata registration");
			}
			LibLogger.InfoNewline($"Got Binary codereg: 0x{num:X}, metareg: 0x{num2:X} in {(DateTime.Now - now).TotalMilliseconds:F0}ms.");
			LibLogger.InfoNewline("Initializing Binary...");
			now = DateTime.Now;
			Binary.Init(num, num2);
			LibLogger.InfoNewline($"Initialized Binary in {(DateTime.Now - now).TotalMilliseconds:F0}ms");
			if (!Settings.DisableGlobalResolving && MetadataVersion < 27f)
			{
				now = DateTime.Now;
				LibLogger.Info("Mapping Globals...");
				LibCpp2IlGlobalMapper.MapGlobalIdentifiers(TheMetadata, Binary);
				LibLogger.InfoNewline($"OK ({(DateTime.Now - now).TotalMilliseconds:F0}ms)");
			}
			if (!Settings.DisableMethodPointerMapping)
			{
				now = DateTime.Now;
				LibLogger.Info("Mapping pointers to Il2CppMethodDefinitions...");
				int num4 = 0;
				foreach (var (item, key) in TheMetadata.methodDefs.Select((Il2CppMethodDefinition method) => (method, method.MethodPointer)))
				{
					if (!MethodsByPtr.ContainsKey(key))
					{
						MethodsByPtr[key] = new List<Il2CppMethodDefinition>();
					}
					MethodsByPtr[key].Add(item);
					num4++;
				}
				LibLogger.InfoNewline($"Processed {num4} OK ({(DateTime.Now - now).TotalMilliseconds:F0}ms)");
			}
			return true;
		}

		public static bool LoadFromFile(string pePath, string metadataPath, int[] unityVersion)
		{
			byte[] metadataBytes = File.ReadAllBytes(metadataPath);
			return Initialize(File.ReadAllBytes(pePath), metadataBytes, unityVersion);
		}
	}
	public static class LibCpp2ILUtils
	{
		private static readonly Dictionary<int, string> TypeString = new Dictionary<int, string>
		{
			{ 1, "void" },
			{ 2, "bool" },
			{ 3, "char" },
			{ 4, "sbyte" },
			{ 5, "byte" },
			{ 6, "short" },
			{ 7, "ushort" },
			{ 8, "int" },
			{ 9, "uint" },
			{ 10, "long" },
			{ 11, "ulong" },
			{ 12, "float" },
			{ 13, "double" },
			{ 14, "string" },
			{ 22, "TypedReference" },
			{ 24, "IntPtr" },
			{ 25, "UIntPtr" },
			{ 28, "object" }
		};

		private static readonly Dictionary<string, ulong> PrimitiveSizes = new Dictionary<string, ulong>
		{
			{ "Byte", 1uL },
			{ "SByte", 1uL },
			{ "Boolean", 1uL },
			{ "Int16", 2uL },
			{ "UInt16", 2uL },
			{ "Char", 2uL },
			{ "Int32", 4uL },
			{ "UInt32", 4uL },
			{ "Single", 4uL },
			{ "Int64", 8uL },
			{ "UInt64", 8uL },
			{ "Double", 8uL },
			{ "IntPtr", 8uL },
			{ "UIntPtr", 8uL }
		};

		private static Dictionary<FieldInfo, VersionAttribute[]> _cachedVersionAttributes = new Dictionary<FieldInfo, VersionAttribute[]>();

		internal static void Reset()
		{
			_cachedVersionAttributes.Clear();
		}

		internal static string GetTypeName(Il2CppMetadata metadata, Il2CppBinary cppAssembly, Il2CppTypeDefinition typeDef, bool fullName = false)
		{
			string text = string.Empty;
			if (fullName)
			{
				text = typeDef.Namespace;
				if (text != string.Empty)
				{
					text += ".";
				}
			}
			if (typeDef.declaringTypeIndex != -1)
			{
				text = text + GetTypeName(metadata, cppAssembly, cppAssembly.GetType(typeDef.declaringTypeIndex)) + ".";
			}
			text += metadata.GetStringFromIndex(typeDef.nameIndex);
			List<string> list = new List<string>();
			if (typeDef.genericContainerIndex < 0)
			{
				return text;
			}
			Il2CppGenericContainer il2CppGenericContainer = metadata.genericContainers[typeDef.genericContainerIndex];
			for (int i = 0; i < il2CppGenericContainer.type_argc; i++)
			{
				int num = il2CppGenericContainer.genericParameterStart + i;
				Il2CppGenericParameter il2CppGenericParameter = metadata.genericParameters[num];
				list.Add(metadata.GetStringFromIndex(il2CppGenericParameter.nameIndex));
			}
			text = text.Replace($"`{il2CppGenericContainer.type_argc}", "");
			return text + "<" + string.Join(", ", list) + ">";
		}

		internal static Il2CppTypeReflectionData[]? GetGenericTypeParams(Il2CppGenericInst genericInst)
		{
			if (LibCpp2IlMain.Binary == null || LibCpp2IlMain.TheMetadata == null)
			{
				return null;
			}
			List<Il2CppTypeReflectionData> list = new List<Il2CppTypeReflectionData>();
			ulong[] array = LibCpp2IlMain.Binary.ReadClassArrayAtVirtualAddress<ulong>(genericInst.pointerStart, (long)genericInst.pointerCount);
			for (uint num = 0u; num < genericInst.pointerCount; num++)
			{
				Il2CppType il2CppTypeFromPointer = LibCpp2IlMain.Binary.GetIl2CppTypeFromPointer(array[num]);
				list.Add(GetTypeReflectionData(il2CppTypeFromPointer));
			}
			return list.ToArray();
		}

		internal static string GetGenericTypeParamNames(Il2CppMetadata metadata, Il2CppBinary cppAssembly, Il2CppGenericInst genericInst)
		{
			List<string> list = new List<string>();
			ulong[] array = cppAssembly.ReadClassArrayAtVirtualAddress<ulong>(genericInst.pointerStart, (long)genericInst.pointerCount);
			for (uint num = 0u; num < genericInst.pointerCount; num++)
			{
				Il2CppType il2CppTypeFromPointer = cppAssembly.GetIl2CppTypeFromPointer(array[num]);
				list.Add(GetTypeName(metadata, cppAssembly, il2CppTypeFromPointer));
			}
			return "<" + string.Join(", ", list) + ">";
		}

		public static string GetTypeName(Il2CppMetadata metadata, Il2CppBinary cppAssembly, Il2CppType type, bool fullName = false)
		{
			switch (type.type)
			{
			case Il2CppTypeEnum.IL2CPP_TYPE_VALUETYPE:
			case Il2CppTypeEnum.IL2CPP_TYPE_CLASS:
			{
				Il2CppTypeDefinition typeDef = metadata.typeDefs[type.data.classIndex];
				string stringFromIndex = string.Empty;
				return stringFromIndex + GetTypeName(metadata, cppAssembly, typeDef, fullName);
			}
			case Il2CppTypeEnum.IL2CPP_TYPE_GENERICINST:
			{
				Il2CppGenericClass il2CppGenericClass = cppAssembly.ReadClassAtVirtualAddress<Il2CppGenericClass>(type.data.generic_class);
				Il2CppTypeDefinition il2CppTypeDefinition = metadata.typeDefs[il2CppGenericClass.typeDefinitionIndex];
				string stringFromIndex = metadata.GetStringFromIndex(il2CppTypeDefinition.nameIndex);
				Il2CppGenericInst il2CppGenericInst = cppAssembly.ReadClassAtVirtualAddress<Il2CppGenericInst>(il2CppGenericClass.context.class_inst);
				stringFromIndex = stringFromIndex.Replace($"`{il2CppGenericInst.pointerCount}", "");
				return stringFromIndex + GetGenericTypeParamNames(metadata, cppAssembly, il2CppGenericInst);
			}
			case Il2CppTypeEnum.IL2CPP_TYPE_VAR:
			case Il2CppTypeEnum.IL2CPP_TYPE_MVAR:
			{
				Il2CppGenericParameter il2CppGenericParameter = metadata.genericParameters[type.data.genericParameterIndex];
				return metadata.GetStringFromIndex(il2CppGenericParameter.nameIndex);
			}
			case Il2CppTypeEnum.IL2CPP_TYPE_ARRAY:
			{
				Il2CppArrayType il2CppArrayType = cppAssembly.ReadClassAtVirtualAddress<Il2CppArrayType>(type.data.array);
				Il2CppType il2CppTypeFromPointer3 = cppAssembly.GetIl2CppTypeFromPointer(il2CppArrayType.etype);
				return GetTypeName(metadata, cppAssembly, il2CppTypeFromPointer3) + "[" + new string(',', il2CppArrayType.rank - 1) + "]";
			}
			case Il2CppTypeEnum.IL2CPP_TYPE_SZARRAY:
			{
				Il2CppType il2CppTypeFromPointer2 = cppAssembly.GetIl2CppTypeFromPointer(type.data.type);
				return GetTypeName(metadata, cppAssembly, il2CppTypeFromPointer2) + "[]";
			}
			case Il2CppTypeEnum.IL2CPP_TYPE_PTR:
			{
				Il2CppType il2CppTypeFromPointer = cppAssembly.GetIl2CppTypeFromPointer(type.data.type);
				return GetTypeName(metadata, cppAssembly, il2CppTypeFromPointer) + "*";
			}
			default:
				return TypeString[(int)type.type];
			}
		}

		internal static object? GetDefaultValue(int dataIndex, int typeIndex)
		{
			Il2CppMetadata theMetadata = LibCpp2IlMain.TheMetadata;
			Il2CppBinary binary = LibCpp2IlMain.Binary;
			if (dataIndex == -1)
			{
				return null;
			}
			int defaultValueFromIndex = theMetadata.GetDefaultValueFromIndex(dataIndex);
			if (defaultValueFromIndex <= 0)
			{
				return null;
			}
			int bytesRead2;
			switch (binary.GetType(typeIndex).type)
			{
			case Il2CppTypeEnum.IL2CPP_TYPE_BOOLEAN:
				return theMetadata.ReadClassAtRawAddr<bool>(defaultValueFromIndex);
			case Il2CppTypeEnum.IL2CPP_TYPE_U1:
				return theMetadata.ReadClassAtRawAddr<byte>(defaultValueFromIndex);
			case Il2CppTypeEnum.IL2CPP_TYPE_I1:
				return theMetadata.ReadClassAtRawAddr<sbyte>(defaultValueFromIndex);
			case Il2CppTypeEnum.IL2CPP_TYPE_CHAR:
				return BitConverter.ToChar(theMetadata.ReadByteArrayAtRawAddress(defaultValueFromIndex, 2), 0);
			case Il2CppTypeEnum.IL2CPP_TYPE_U2:
				return theMetadata.ReadClassAtRawAddr<ushort>(defaultValueFromIndex);
			case Il2CppTypeEnum.IL2CPP_TYPE_I2:
				return theMetadata.ReadClassAtRawAddr<short>(defaultValueFromIndex);
			case Il2CppTypeEnum.IL2CPP_TYPE_U4:
				if (LibCpp2IlMain.MetadataVersion < 29f)
				{
					return theMetadata.ReadClassAtRawAddr<uint>(defaultValueFromIndex);
				}
				return theMetadata.ReadUnityCompressedUIntAtRawAddr(defaultValueFromIndex, out bytesRead2);
			case Il2CppTypeEnum.IL2CPP_TYPE_I4:
				if (LibCpp2IlMain.MetadataVersion < 29f)
				{
					return theMetadata.ReadClassAtRawAddr<int>(defaultValueFromIndex);
				}
				return theMetadata.ReadUnityCompressedIntAtRawAddr(defaultValueFromIndex, out bytesRead2);
			case Il2CppTypeEnum.IL2CPP_TYPE_U8:
				return theMetadata.ReadClassAtRawAddr<ulong>(defaultValueFromIndex, overrideArchCheck: true);
			case Il2CppTypeEnum.IL2CPP_TYPE_I8:
				return theMetadata.ReadClassAtRawAddr<long>(defaultValueFromIndex, overrideArchCheck: true);
			case Il2CppTypeEnum.IL2CPP_TYPE_R4:
				return theMetadata.ReadClassAtRawAddr<float>(defaultValueFromIndex);
			case Il2CppTypeEnum.IL2CPP_TYPE_R8:
				return theMetadata.ReadClassAtRawAddr<double>(defaultValueFromIndex);
			case Il2CppTypeEnum.IL2CPP_TYPE_STRING:
			{
				int bytesRead = 4;
				int num = ((!(LibCpp2IlMain.MetadataVersion < 29f)) ? theMetadata.ReadUnityCompressedIntAtRawAddr(defaultValueFromIndex, out bytesRead) : theMetadata.ReadClassAtRawAddr<int>(defaultValueFromIndex));
				if (num > 65536)
				{
					LibLogger.WarnNewline("[GetDefaultValue] String length is really large: " + num);
				}
				return Encoding.UTF8.GetString(theMetadata.ReadByteArrayAtRawAddress(defaultValueFromIndex + bytesRead, num));
			}
			default:
				return null;
			}
		}

		public static Il2CppTypeReflectionData WrapType(Il2CppTypeDefinition what)
		{
			return new Il2CppTypeReflectionData
			{
				baseType = what,
				genericParams = new Il2CppTypeReflectionData[0],
				isGenericType = false,
				isType = true
			};
		}

		public static Il2CppTypeReflectionData GetTypeReflectionData(Il2CppType forWhat)
		{
			if (LibCpp2IlMain.Binary == null || LibCpp2IlMain.TheMetadata == null)
			{
				throw new Exception("Can't get type reflection data when not initialized. How did you even get the type?");
			}
			switch (forWhat.type)
			{
			case Il2CppTypeEnum.IL2CPP_TYPE_OBJECT:
				return WrapType(LibCpp2IlReflection.GetType("Object", "System"));
			case Il2CppTypeEnum.IL2CPP_TYPE_VOID:
				return WrapType(LibCpp2IlReflection.GetType("Void", "System"));
			case Il2CppTypeEnum.IL2CPP_TYPE_BOOLEAN:
				return WrapType(LibCpp2IlReflection.GetType("Boolean", "System"));
			case Il2CppTypeEnum.IL2CPP_TYPE_CHAR:
				return WrapType(LibCpp2IlReflection.GetType("Char", "System"));
			case Il2CppTypeEnum.IL2CPP_TYPE_I1:
				return WrapType(LibCpp2IlReflection.GetType("SByte", "System"));
			case Il2CppTypeEnum.IL2CPP_TYPE_U1:
				return WrapType(LibCpp2IlReflection.GetType("Byte", "System"));
			case Il2CppTypeEnum.IL2CPP_TYPE_I2:
				return WrapType(LibCpp2IlReflection.GetType("Int16", "System"));
			case Il2CppTypeEnum.IL2CPP_TYPE_U2:
				return WrapType(LibCpp2IlReflection.GetType("UInt16", "System"));
			case Il2CppTypeEnum.IL2CPP_TYPE_I4:
				return WrapType(LibCpp2IlReflection.GetType("Int32", "System"));
			case Il2CppTypeEnum.IL2CPP_TYPE_U4:
				return WrapType(LibCpp2IlReflection.GetType("UInt32", "System"));
			case Il2CppTypeEnum.IL2CPP_TYPE_I:
				return WrapType(LibCpp2IlReflection.GetType("IntPtr", "System"));
			case Il2CppTypeEnum.IL2CPP_TYPE_U:
				return WrapType(LibCpp2IlReflection.GetType("UIntPtr", "System"));
			case Il2CppTypeEnum.IL2CPP_TYPE_I8:
				return WrapType(LibCpp2IlReflection.GetType("Int64", "System"));
			case Il2CppTypeEnum.IL2CPP_TYPE_U8:
				return WrapType(LibCpp2IlReflection.GetType("UInt64", "System"));
			case Il2CppTypeEnum.IL2CPP_TYPE_R4:
				return WrapType(LibCpp2IlReflection.GetType("Single", "System"));
			case Il2CppTypeEnum.IL2CPP_TYPE_R8:
				return WrapType(LibCpp2IlReflection.GetType("Double", "System"));
			case Il2CppTypeEnum.IL2CPP_TYPE_STRING:
				return WrapType(LibCpp2IlReflection.GetType("String", "System"));
			case Il2CppTypeEnum.IL2CPP_TYPE_TYPEDBYREF:
				return WrapType(LibCpp2IlReflection.GetType("TypedReference", "System"));
			case Il2CppTypeEnum.IL2CPP_TYPE_VALUETYPE:
			case Il2CppTypeEnum.IL2CPP_TYPE_CLASS:
				return new Il2CppTypeReflectionData
				{
					baseType = LibCpp2IlMain.TheMetadata.typeDefs[forWhat.data.classIndex],
					genericParams = new Il2CppTypeReflectionData[0],
					isType = true,
					isGenericType = false
				};
			case Il2CppTypeEnum.IL2CPP_TYPE_GENERICINST:
			{
				Il2CppGenericClass il2CppGenericClass = LibCpp2IlMain.Binary.ReadClassAtVirtualAddress<Il2CppGenericClass>(forWhat.data.generic_class);
				Il2CppTypeDefinition baseType;
				if (LibCpp2IlMain.MetadataVersion < 27f)
				{
					baseType = LibCpp2IlMain.TheMetadata.typeDefs[il2CppGenericClass.typeDefinitionIndex];
				}
				else
				{
					Il2CppType il2CppType = LibCpp2IlMain.Binary.ReadClassAtVirtualAddress<Il2CppType>((ulong)il2CppGenericClass.typeDefinitionIndex);
					il2CppType.Init();
					baseType = LibCpp2IlMain.TheMetadata.typeDefs[il2CppType.data.classIndex];
				}
				Il2CppGenericInst il2CppGenericInst = LibCpp2IlMain.Binary.ReadClassAtVirtualAddress<Il2CppGenericInst>(il2CppGenericClass.context.class_inst);
				List<Il2CppTypeReflectionData> list = (from pointer in LibCpp2IlMain.Binary.GetPointers(il2CppGenericInst.pointerStart, (long)il2CppGenericInst.pointerCount)
					select LibCpp2IlMain.Binary.GetIl2CppTypeFromPointer(pointer) into type
					select GetTypeReflectionData(type)).ToList();
				return new Il2CppTypeReflectionData
				{
					baseType = baseType,
					genericParams = list.ToArray(),
					isType = true,
					isGenericType = true
				};
			}
			case Il2CppTypeEnum.IL2CPP_TYPE_VAR:
			case Il2CppTypeEnum.IL2CPP_TYPE_MVAR:
			{
				Il2CppGenericParameter il2CppGenericParameter = LibCpp2IlMain.TheMetadata.genericParameters[forWhat.data.genericParameterIndex];
				string stringFromIndex = LibCpp2IlMain.TheMetadata.GetStringFromIndex(il2CppGenericParameter.nameIndex);
				return new Il2CppTypeReflectionData
				{
					baseType = null,
					genericParams = new Il2CppTypeReflectionData[0],
					isType = false,
					isGenericType = false,
					variableGenericParamName = stringFromIndex
				};
			}
			case Il2CppTypeEnum.IL2CPP_TYPE_SZARRAY:
			{
				Il2CppType il2CppTypeFromPointer2 = LibCpp2IlMain.Binary.GetIl2CppTypeFromPointer(forWhat.data.type);
				return new Il2CppTypeReflectionData
				{
					baseType = null,
					arrayType = GetTypeReflectionData(il2CppTypeFromPointer2),
					arrayRank = 1,
					isArray = true,
					isType = false,
					isGenericType = false,
					genericParams = new Il2CppTypeReflectionData[0]
				};
			}
			case Il2CppTypeEnum.IL2CPP_TYPE_ARRAY:
			{
				Il2CppArrayType il2CppArrayType = LibCpp2IlMain.Binary.ReadClassAtVirtualAddress<Il2CppArrayType>(forWhat.data.array);
				Il2CppType il2CppTypeFromPointer = LibCpp2IlMain.Binary.GetIl2CppTypeFromPointer(il2CppArrayType.etype);
				return new Il2CppTypeReflectionData
				{
					baseType = null,
					arrayType = GetTypeReflectionData(il2CppTypeFromPointer),
					isArray = true,
					isType = false,
					arrayRank = il2CppArrayType.rank,
					isGenericType = false,
					genericParams = new Il2CppTypeReflectionData[0]
				};
			}
			case Il2CppTypeEnum.IL2CPP_TYPE_PTR:
			{
				Il2CppTypeReflectionData typeReflectionData = GetTypeReflectionData(LibCpp2IlMain.Binary.GetIl2CppTypeFromPointer(forWhat.data.type));
				typeReflectionData.isPointer = true;
				return typeReflectionData;
			}
			default:
				throw new ArgumentException($"Unknown type {forWhat.type}");
			}
		}

		public static int VersionAwareSizeOf(Type type, bool dontCheckVersionAttributes = false, bool downsize = true)
		{
			if (type.IsEnum)
			{
				type = type.GetEnumUnderlyingType();
			}
			if (type.IsPrimitive)
			{
				return (int)PrimitiveSizes[type.Name];
			}
			bool flag = downsize && LibCpp2IlMain.Binary.is32Bit;
			int num = 0;
			FieldInfo[] fields = type.GetFields();
			foreach (FieldInfo fieldInfo in fields)
			{
				if (!dontCheckVersionAttributes && !ShouldReadFieldOnThisVersion(fieldInfo))
				{
					continue;
				}
				switch (fieldInfo.FieldType.Name)
				{
				case "Int64":
				case "UInt64":
					num += (flag ? 4 : 8);
					continue;
				case "Int32":
				case "UInt32":
					num += 4;
					continue;
				case "Int16":
				case "UInt16":
					num += 2;
					continue;
				case "Byte":
				case "SByte":
					num++;
					continue;
				}
				if (fieldInfo.FieldType == type)
				{
					throw new Exception($"Infinite recursion is not allowed. Field {fieldInfo} of type {type} has the same type as its parent.");
				}
				num += VersionAwareSizeOf(fieldInfo.FieldType, dontCheckVersionAttributes, downsize);
			}
			return num;
		}

		internal static IEnumerable<int> Range(int start, int count)
		{
			for (int i = start; i < start + count; i++)
			{
				yield return i;
			}
		}

		internal static bool ShouldReadFieldOnThisVersion(FieldInfo i)
		{
			if (!_cachedVersionAttributes.TryGetValue(i, out VersionAttribute[] value))
			{
				value = Attribute.GetCustomAttributes(i, typeof(VersionAttribute)).Cast<VersionAttribute>().ToArray();
				_cachedVersionAttributes[i] = value;
			}
			if (value.Length != 0)
			{
				return value.Any((VersionAttribute attr) => LibCpp2IlMain.MetadataVersion >= attr.Min && LibCpp2IlMain.MetadataVersion <= attr.Max);
			}
			return true;
		}

		internal static void PopulateDeclaringAssemblyCache()
		{
			Il2CppImageDefinition[] imageDefinitions = LibCpp2IlMain.TheMetadata.imageDefinitions;
			foreach (Il2CppImageDefinition il2CppImageDefinition in imageDefinitions)
			{
				Il2CppTypeDefinition[] types = il2CppImageDefinition.Types;
				for (int j = 0; j < types.Length; j++)
				{
					types[j].DeclaringAssembly = il2CppImageDefinition;
				}
			}
		}
	}
	public class Lz4DecodeStream : Stream
	{
		private enum DecodePhase
		{
			ReadToken,
			ReadExLiteralLength,
			CopyLiteral,
			ReadMatch,
			ReadExMatchLength,
			CopyMatch,
			Finish
		}

		private const int InputBufferCapacity = 4096;

		private const int DecodeBufferCapacity = 65536;

		private const int DecodeBufferMask = 65535;

		private readonly byte[] m_inputBuffer = new byte[4096];

		private readonly byte[] m_decodeBuffer = new byte[65536];

		private readonly Stream m_baseStream;

		private readonly bool m_leaveOpen;

		private long m_position;

		private long m_inputLeft;

		private int m_inputBufferPosition = 4096;

		private int m_decodeBufferPosition;

		private DecodePhase m_phase;

		private int m_literalLength;

		private int m_matchLength;

		private int m_matchDestination;

		private int m_decodeBufferStart;

		public bool IsDataLeft
		{
			get
			{
				if (m_phase != DecodePhase.CopyLiteral)
				{
					return m_matchLength != 0;
				}
				return m_literalLength != 0;
			}
		}

		public override bool CanSeek => false;

		public override bool CanRead => true;

		public override bool CanWrite => false;

		public override long Length { get; }

		public override long Position
		{
			get
			{
				return m_position;
			}
			set
			{
				throw new NotSupportedException();
			}
		}

		public Lz4DecodeStream(byte[] buffer, int offset, int length)
			: this(new MemoryStream(buffer, offset, length), length, leaveOpen: false)
		{
		}

		public Lz4DecodeStream(Stream baseStream, bool leaveOpen = true)
			: this(baseStream, baseStream.Length, leaveOpen)
		{
		}

		public Lz4DecodeStream(Stream baseStream, long compressedSize, bool leaveOpen = true)
		{
			if (compressedSize <= 0)
			{
				throw new ArgumentException($"Compressed size {compressedSize} must be greater then 0");
			}
			m_baseStream = baseStream ?? throw new ArgumentNullException("baseStream");
			Length = compressedSize;
			m_inputLeft = compressedSize;
			m_phase = DecodePhase.ReadToken;
			m_leaveOpen = leaveOpen;
		}

		~Lz4DecodeStream()
		{
			Dispose(disposing: false);
		}

		public override void Flush()
		{
		}

		public override long Seek(long offset, SeekOrigin origin)
		{
			throw new NotSupportedException();
		}

		public override int Read(byte[] buffer, int offset, int count)
		{
			using MemoryStream stream = new MemoryStream(buffer, offset, count);
			return (int)Read(stream, count);
		}

		public long Read(Stream stream, long count)
		{
			if (stream == null)
			{
				throw new ArgumentNullException("stream");
			}
			if (count <= 0)
			{
				throw new ArgumentException("count");
			}
			long num = count;
			switch (m_phase)
			{
			case DecodePhase.ReadToken:
			{
				int num2 = ReadInputByte();
				m_literalLength = num2 >> 4;
				m_matchLength = (num2 & 0xF) + 4;
				if (m_literalLength != 0)
				{
					if (m_literalLength == 15)
					{
						goto case DecodePhase.ReadExLiteralLength;
					}
					goto case DecodePhase.CopyLiteral;
				}
				goto case DecodePhase.ReadMatch;
			}
			case DecodePhase.ReadExLiteralLength:
			{
				int num4;
				do
				{
					num4 = ReadInputByte();
					m_literalLength += num4;
				}
				while (num4 == 255);
				goto case DecodePhase.CopyLiteral;
			}
			case DecodePhase.CopyLiteral:
				if (m_literalLength >= num)
				{
					Write(stream, (int)num);
					m_literalLength -= (int)num;
					num = 0L;
					m_phase = DecodePhase.CopyLiteral;
					goto case DecodePhase.Finish;
				}
				Write(stream, m_literalLength);
				num -= m_literalLength;
				goto case DecodePhase.ReadMatch;
			case DecodePhase.ReadMatch:
				m_matchDestination = ReadInputInt16();
				if (m_matchLength == 19)
				{
					goto case DecodePhase.ReadExMatchLength;
				}
				goto case DecodePhase.CopyMatch;
			case DecodePhase.ReadExMatchLength:
			{
				int num3;
				do
				{
					num3 = ReadInputByte();
					m_matchLength += num3;
				}
				while (num3 == 255);
				goto case DecodePhase.CopyMatch;
			}
			case DecodePhase.CopyMatch:
			{
				int num5 = (int)((m_matchLength < num) ? m_matchLength : num);
				while (num5 > 0)
				{
					int num6 = (m_decodeBufferPosition - m_matchDestination) & 0xFFFF;
					int num7 = 65536 - num6;
					int num8 = 65536 - m_decodeBufferPosition;
					int num9 = ((num7 < num8) ? num7 : num8);
					int num10 = ((num5 < num9) ? num5 : num9);
					int num11 = m_decodeBufferPosition - num6;
					if (num11 > 0 && num11 < num10)
					{
						for (int i = 0; i < num10; i++)
						{
							m_decodeBuffer[m_decodeBufferPosition++] = m_decodeBuffer[num6++];
						}
					}
					else
					{
						Buffer.BlockCopy(m_decodeBuffer, num6, m_decodeBuffer, m_decodeBufferPosition, num10);
						m_decodeBufferPosition += num10;
					}
					num5 -= num10;
					m_matchLength -= num10;
					num -= num10;
					if (m_decodeBufferPosition == 65536)
					{
						FillOutputStream(stream);
					}
				}
				if (num != 0L)
				{
					goto case DecodePhase.ReadToken;
				}
				m_phase = DecodePhase.CopyMatch;
				goto case DecodePhase.Finish;
			}
			case DecodePhase.Finish:
				FillOutputStream(stream);
				return count - num;
			default:
				throw new Exception($"Unknonw decode phase {m_phase}");
			}
		}

		public void ReadBuffer(byte[] buffer, int offset, int count)
		{
			using MemoryStream stream = new MemoryStream(buffer, offset, count);
			ReadBuffer(stream, count);
		}

		public void ReadBuffer(Stream stream, long count)
		{
			int num = (int)Read(stream, count);
			if (num != count)
			{
				throw new Exception($"Unexpected end of input stream. Read {num} but expected {count}");
			}
			if (IsDataLeft)
			{
				throw new Exception("Some data left");
			}
		}

		public override void Write(byte[] buffer, int offset, int count)
		{
			throw new NotSupportedException();
		}

		public override void SetLength(long value)
		{
			throw new NotSupportedException();
		}

		protected override void Dispose(bool disposing)
		{
			if (!m_leaveOpen)
			{
				m_baseStream.Dispose();
			}
			base.Dispose(disposing);
		}

		private int ReadInputByte()
		{
			if (m_inputBufferPosition == 4096)
			{
				FillInputBuffer();
			}
			return m_inputBuffer[m_inputBufferPosition++];
		}

		private int ReadInputInt16()
		{
			switch (4096 - m_inputBufferPosition)
			{
			case 0:
				FillInputBuffer();
				break;
			case 1:
				m_inputBuffer[0] = m_inputBuffer[m_inputBufferPosition];
				FillInputBuffer(1);
				break;
			}
			return m_inputBuffer[m_inputBufferPosition++] | (m_inputBuffer[m_inputBufferPosition++] << 8);
		}

		private void Write(Stream stream, int count)
		{
			while (count > 0)
			{
				if (m_inputBufferPosition == 4096)
				{
					FillInputBuffer();
				}
				int num = 4096 - m_inputBufferPosition;
				int num2 = 65536 - m_decodeBufferPosition;
				int num3 = ((num < num2) ? num : num2);
				int num4 = ((count < num3) ? count : num3);
				Buffer.BlockCopy(m_inputBuffer, m_inputBufferPosition, m_decodeBuffer, m_decodeBufferPosition, num4);
				count -= num4;
				m_inputBufferPosition += num4;
				m_decodeBufferPosition += num4;
				if (m_decodeBufferPosition == 65536)
				{
					FillOutputStream(stream);
				}
			}
		}

		private void FillInputBuffer(int offset = 0)
		{
			int num = 4096 - offset;
			int num2 = (int)((num < m_inputLeft) ? num : m_inputLeft);
			m_inputBufferPosition = 0;
			while (num2 > 0)
			{
				int num3 = m_baseStream.Read(m_inputBuffer, offset, num2);
				if (num3 == 0)
				{
					throw new Exception("No data left");
				}
				m_position += num3;
				offset += num3;
				num2 -= num3;
				m_inputLeft -= num3;
			}
		}

		private void FillOutputStream(Stream stream)
		{
			int num = m_decodeBufferPosition - m_decodeBufferStart;
			int num2 = 65536 - m_decodeBufferStart;
			int num3 = ((num2 < num) ? num2 : num);
			stream.Write(m_decodeBuffer, m_decodeBufferStart, num3);
			stream.Write(m_decodeBuffer, 0, num - num3);
			m_decodeBufferPosition &= 65535;
			m_decodeBufferStart = m_decodeBufferPosition;
		}
	}
	public class MetadataUsage
	{
		public readonly MetadataUsageType Type;

		public readonly ulong Offset;

		private readonly uint _value;

		private string? _cachedName;

		private Il2CppType? _cachedType;

		private Il2CppTypeReflectionData? _cachedTypeReflectionData;

		private Il2CppMethodDefinition? _cachedMethod;

		private Il2CppFieldDefinition? _cachedField;

		private string? _cachedLiteral;

		private Il2CppGenericMethodRef? _cachedGenericMethod;

		public uint RawValue => _value;

		public object Value
		{
			get
			{
				switch (Type)
				{
				case MetadataUsageType.TypeInfo:
				case MetadataUsageType.Type:
					return AsType();
				case MetadataUsageType.MethodDef:
					return AsMethod();
				case MetadataUsageType.FieldInfo:
					return AsField();
				case MetadataUsageType.StringLiteral:
					return AsLiteral();
				case MetadataUsageType.MethodRef:
					return AsGenericMethodRef();
				default:
					throw new ArgumentOutOfRangeException();
				}
			}
		}

		public bool IsValid
		{
			get
			{
				try
				{
					_ = Value;
					return true;
				}
				catch (Exception)
				{
					return false;
				}
			}
		}

		public MetadataUsage(MetadataUsageType type, ulong offset, uint value)
		{
			Type = type;
			_value = value;
			Offset = offset;
		}

		public Il2CppTypeReflectionData AsType()
		{
			if (_cachedTypeReflectionData == null)
			{
				MetadataUsageType type = Type;
				if (type - 1 > MetadataUsageType.TypeInfo)
				{
					throw new Exception($"Cannot cast metadata usage of kind {Type} to a Type");
				}
				try
				{
					_cachedType = LibCpp2IlMain.Binary.GetType((int)_value);
					_cachedTypeReflectionData = LibCpp2ILUtils.GetTypeReflectionData(_cachedType);
					_cachedName = LibCpp2ILUtils.GetTypeReflectionData(_cachedType)?.ToString();
				}
				catch (Exception innerException)
				{
					throw new Exception($"Failed to convert this metadata usage to a type, but it is of type {Type}, with a value of {_value} (0x{_value:X}). There are {LibCpp2IlMain.Binary.NumTypes} types", innerException);
				}
			}
			return _cachedTypeReflectionData;
		}

		public Il2CppMethodDefinition AsMethod()
		{
			if (_cachedMethod == null)
			{
				if (Type != MetadataUsageType.MethodDef)
				{
					throw new Exception($"Cannot cast metadata usage of kind {Type} to a Method Def");
				}
				_cachedMethod = LibCpp2IlMain.TheMetadata.methodDefs[_value];
				_cachedName = _cachedMethod.GlobalKey;
			}
			return _cachedMethod;
		}

		public Il2CppFieldDefinition AsField()
		{
			if (_cachedField == null)
			{
				if (Type != MetadataUsageType.FieldInfo)
				{
					throw new Exception($"Cannot cast metadata usage of kind {Type} to a Field");
				}
				Il2CppFieldRef il2CppFieldRef = LibCpp2IlMain.TheMetadata.fieldRefs[_value];
				_cachedField = il2CppFieldRef.FieldDefinition;
				_cachedName = il2CppFieldRef.DeclaringTypeDefinition.FullName + "." + _cachedField.Name;
			}
			return _cachedField;
		}

		public string AsLiteral()
		{
			if (_cachedLiteral == null)
			{
				if (Type != MetadataUsageType.StringLiteral)
				{
					throw new Exception($"Cannot cast metadata usage of kind {Type} to a String Literal");
				}
				_cachedName = (_cachedLiteral = LibCpp2IlMain.TheMetadata.GetStringLiteralFromIndex(_value));
			}
			return _cachedLiteral;
		}

		public Il2CppGenericMethodRef AsGenericMethodRef()
		{
			if (_cachedGenericMethod == null)
			{
				if (Type != MetadataUsageType.MethodRef)
				{
					throw new Exception($"Cannot cast metadata usage of kind {Type} to a Generic Method Ref");
				}
				Il2CppMethodSpec methodSpec = LibCpp2IlMain.Binary.GetMethodSpec((int)_value);
				_cachedGenericMethod = new Il2CppGenericMethodRef(methodSpec);
				_cachedName = _cachedGenericMethod.ToString();
			}
			return _cachedGenericMethod;
		}

		public override string ToString()
		{
			return $"Metadata Usage {{type={Type}, Value={Value}}}";
		}

		public static MetadataUsage? DecodeMetadataUsage(ulong encoded, ulong address)
		{
			MetadataUsageType metadataUsageType = (MetadataUsageType)((encoded & 0xE0000000u) >> 29);
			if (metadataUsageType <= MetadataUsageType.MethodRef && metadataUsageType >= MetadataUsageType.TypeInfo)
			{
				uint num = (uint)(encoded & 0x1FFFFFFF);
				if (LibCpp2IlMain.MetadataVersion >= 27f)
				{
					num >>= 1;
				}
				if ((metadataUsageType == MetadataUsageType.Type || metadataUsageType == MetadataUsageType.TypeInfo) && num > LibCpp2IlMain.Binary.NumTypes)
				{
					return null;
				}
				if (metadataUsageType == MetadataUsageType.MethodDef && num > LibCpp2IlMain.TheMetadata.methodDefs.Length)
				{
					return null;
				}
				return new MetadataUsage(metadataUsageType, address, num);
			}
			return null;
		}
	}
	public enum MetadataUsageType : uint
	{
		TypeInfo = 1u,
		Type,
		MethodDef,
		FieldInfo,
		StringLiteral,
		MethodRef
	}
	internal static class MiniArm64Decompiler
	{
		private static (uint reg, ulong page)? GetAdrp(uint inst, ulong pc)
		{
			if ((inst.Bits(24, 8) & 0x8F) != 128)
			{
				return null;
			}
			uint num = inst.Bits(29, 2);
			uint num2 = (inst.Bits(5, 19) << 14) + (num << 12);
			ulong num3 = pc & 0xFFFFFFFFFFFFF000uL;
			return (inst.Bits(0, 5), num3 + num2);
		}

		private static (uint reg, ulong addr)? GetAdr(uint inst, ulong pc)
		{
			if (inst.Bits(24, 5) != 16 || inst.Bits(31, 1) != 0)
			{
				return null;
			}
			ulong num = (inst.Bits(5, 19) << 2) + inst.Bits(29, 2);
			num = (((num & 0x100000) == 0L) ? num : (num | 0xFFFFFFFFFFE00000uL));
			return (inst.Bits(0, 5), pc + num);
		}

		private static (uint reg_n, uint reg_d, uint imm)? GetAdd64(uint inst)
		{
			if (inst.Bits(22, 10) != 580)
			{
				return null;
			}
			uint item = inst.Bits(10, 12);
			uint item2 = inst.Bits(5, 5);
			uint item3 = inst.Bits(0, 5);
			return (item2, item3, item);
		}

		private static (uint reg_t, uint reg_n, uint simm)? GetLdr64ImmOffset(uint inst)
		{
			if (inst.Bits(22, 10) != 997)
			{
				return null;
			}
			uint item = inst.Bits(10, 12);
			uint item2 = inst.Bits(0, 5);
			uint item3 = inst.Bits(5, 5);
			return (item2, item3, item);
		}

		public static bool IsB(uint inst)
		{
			return inst.Bits(26, 6) == 5;
		}

		public static Dictionary<uint, ulong> GetAddressesLoadedIntoRegisters(List<uint> funcBody, ulong baseAddress, ElfFile image)
		{
			Dictionary<uint, ulong> dictionary = new Dictionary<uint, ulong>();
			ulong num = baseAddress;
			foreach (uint item5 in funcBody)
			{
				(uint, ulong)? adrp = GetAdrp(item5, num);
				if (adrp.HasValue)
				{
					(uint, ulong) valueOrDefault = adrp.GetValueOrDefault();
					uint item = valueOrDefault.Item1;
					ulong item2 = valueOrDefault.Item2;
					dictionary[item] = item2;
				}
				(uint, ulong)? adr = GetAdr(item5, num);
				if (adr.HasValue)
				{
					(uint, ulong) valueOrDefault2 = adr.GetValueOrDefault();
					uint item3 = valueOrDefault2.Item1;
					ulong item4 = valueOrDefault2.Item2;
					dictionary[item3] = item4;
				}
				(uint, uint, uint)? add = GetAdd64(item5);
				if (add.HasValue)
				{
					var (num2, num3, num4) = add.GetValueOrDefault();
					if (num2 == num3 && dictionary.ContainsKey(num3))
					{
						dictionary[num3] += num4;
					}
				}
				(uint, uint, uint)? ldr64ImmOffset = GetLdr64ImmOffset(item5);
				if (ldr64ImmOffset.HasValue)
				{
					var (num5, num6, num7) = ldr64ImmOffset.GetValueOrDefault();
					if (num5 == num6 && dictionary.ContainsKey(num6))
					{
						dictionary[num6] += num7 * 8;
						dictionary[num6] = image.ReadClassAtVirtualAddress<ulong>(dictionary[num6]);
					}
				}
				num += 4;
			}
			return dictionary;
		}

		public static List<uint> ReadFunctionAtRawAddress(ElfFile file, uint loc, uint maxLength)
		{
			List<uint> list = new List<uint>();
			uint num;
			do
			{
				num = file.ReadClassAtVirtualAddress<uint>(loc);
				list.Add(num);
				loc += 4;
			}
			while (!IsB(num) && list.Count < maxLength);
			return list;
		}
	}
	public struct Il2CppFieldReflectionData
	{
		public Il2CppFieldDefinition field;

		public FieldAttributes attributes;

		public object? defaultValue;
	}
	public static class LibCpp2IlReflection
	{
		private static readonly Dictionary<(string, string?), Il2CppTypeDefinition> _cachedTypes = new Dictionary<(string, string), Il2CppTypeDefinition>();

		private static readonly Dictionary<string, Il2CppTypeDefinition> _cachedTypesByFullName = new Dictionary<string, Il2CppTypeDefinition>();

		private static readonly Dictionary<Il2CppTypeDefinition, int> _typeIndices = new Dictionary<Il2CppTypeDefinition, int>();

		private static readonly Dictionary<Il2CppMethodDefinition, int> _methodIndices = new Dictionary<Il2CppMethodDefinition, int>();

		private static readonly Dictionary<Il2CppFieldDefinition, int> _fieldIndices = new Dictionary<Il2CppFieldDefinition, int>();

		private static readonly Dictionary<Il2CppPropertyDefinition, int> _propertyIndices = new Dictionary<Il2CppPropertyDefinition, int>();

		internal static void ResetCaches()
		{
			_cachedTypes.Clear();
			_cachedTypesByFullName.Clear();
			_typeIndices.Clear();
			_methodIndices.Clear();
			_fieldIndices.Clear();
			_propertyIndices.Clear();
		}

		public static Il2CppTypeDefinition? GetType(string name, string? @namespace = null)
		{
			string name2 = name;
			string namespace2 = @namespace;
			if (LibCpp2IlMain.TheMetadata == null)
			{
				return null;
			}
			(string, string) key = (name2, namespace2);
			if (!_cachedTypes.ContainsKey(key))
			{
				Il2CppTypeDefinition value = LibCpp2IlMain.TheMetadata.typeDefs.FirstOrDefault((Il2CppTypeDefinition td) => td.Name == name2 && (namespace2 == null || namespace2 == td.Namespace));
				_cachedTypes[key] = value;
			}
			return _cachedTypes[key];
		}

		public static Il2CppTypeDefinition? GetTypeByFullName(string fullName)
		{
			string fullName2 = fullName;
			if (LibCpp2IlMain.TheMetadata == null)
			{
				return null;
			}
			if (!_cachedTypesByFullName.ContainsKey(fullName2))
			{
				Il2CppTypeDefinition value = LibCpp2IlMain.TheMetadata.typeDefs.FirstOrDefault((Il2CppTypeDefinition td) => td.FullName == fullName2);
				_cachedTypesByFullName[fullName2] = value;
			}
			return _cachedTypesByFullName[fullName2];
		}

		public static Il2CppTypeDefinition? GetTypeDefinitionByTypeIndex(int index)
		{
			if (LibCpp2IlMain.TheMetadata == null || LibCpp2IlMain.Binary == null)
			{
				return null;
			}
			if (index >= LibCpp2IlMain.Binary.NumTypes || index < 0)
			{
				return null;
			}
			Il2CppType type = LibCpp2IlMain.Binary.GetType(index);
			return LibCpp2IlMain.TheMetadata.typeDefs[type.data.classIndex];
		}

		public static int GetTypeIndexFromType(Il2CppTypeDefinition typeDefinition)
		{
			if (LibCpp2IlMain.TheMetadata == null)
			{
				return -1;
			}
			lock (_typeIndices)
			{
				if (!_typeIndices.ContainsKey(typeDefinition))
				{
					for (int i = 0; i < LibCpp2IlMain.TheMetadata.typeDefs.Length; i++)
					{
						if (LibCpp2IlMain.TheMetadata.typeDefs[i] == typeDefinition)
						{
							_typeIndices[typeDefinition] = i;
						}
					}
				}
				return _typeIndices.GetValueOrDefault(typeDefinition, -1);
			}
		}

		public static int GetMethodIndexFromMethod(Il2CppMethodDefinition methodDefinition)
		{
			if (LibCpp2IlMain.TheMetadata == null)
			{
				return -1;
			}
			if (_methodIndices.Count == 0)
			{
				lock (_methodIndices)
				{
					if (_methodIndices.Count == 0)
					{
						for (int i = 0; i < LibCpp2IlMain.TheMetadata.methodDefs.Length; i++)
						{
							Il2CppMethodDefinition key = LibCpp2IlMain.TheMetadata.methodDefs[i];
							_methodIndices[key] = i;
						}
					}
				}
			}
			return _methodIndices.GetValueOrDefault(methodDefinition, -1);
		}

		public static int GetFieldIndexFromField(Il2CppFieldDefinition fieldDefinition)
		{
			if (LibCpp2IlMain.TheMetadata == null)
			{
				return -1;
			}
			if (_fieldIndices.Count == 0)
			{
				lock (_fieldIndices)
				{
					if (_fieldIndices.Count == 0)
					{
						for (int i = 0; i < LibCpp2IlMain.TheMetadata.fieldDefs.Length; i++)
						{
							Il2CppFieldDefinition key = LibCpp2IlMain.TheMetadata.fieldDefs[i];
							_fieldIndices[key] = i;
						}
					}
				}
			}
			return _fieldIndices[fieldDefinition];
		}

		public static int GetPropertyIndexFromProperty(Il2CppPropertyDefinition propertyDefinition)
		{
			if (LibCpp2IlMain.TheMetadata == null)
			{
				return -1;
			}
			if (_propertyIndices.Count == 0)
			{
				lock (_propertyIndices)
				{
					if (_propertyIndices.Count == 0)
					{
						for (int i = 0; i < LibCpp2IlMain.TheMetadata.propertyDefs.Length; i++)
						{
							Il2CppPropertyDefinition key = LibCpp2IlMain.TheMetadata.propertyDefs[i];
							_propertyIndices[key] = i;
						}
					}
				}
			}
			return _propertyIndices[propertyDefinition];
		}
	}
	public readonly struct UnityVersion : IEquatable<UnityVersion>, IComparable, IComparable<UnityVersion>
	{
		private readonly ulong m_data;

		public static UnityVersion MinVersion => new UnityVersion(0uL);

		public static UnityVersion MaxVersion => new UnityVersion(ulong.MaxValue);

		public static UnityVersion DefaultVersion => new UnityVersion(2017, 3, 0, UnityVersionType.Final, 3);

		public int Major => (int)((m_data >> 48) & 0xFFFF);

		public int Minor => (int)((m_data >> 40) & 0xFF);

		public int Build => (int)((m_data >> 32) & 0xFF);

		public UnityVersionType Type => (UnityVersionType)((m_data >> 24) & 0xFF);

		public int TypeNumber => (int)((m_data >> 16) & 0xFF);

		public UnityVersion(int major)
		{
			m_data = (ulong)((long)(major & 0xFFFF) << 48);
		}

		public UnityVersion(int major, int minor)
		{
			m_data = (ulong)(((long)(major & 0xFFFF) << 48) | ((long)(minor & 0xFF) << 40));
		}

		public UnityVersion(int major, int minor, int build)
		{
			m_data = (ulong)(((long)(major & 0xFFFF) << 48) | ((long)(minor & 0xFF) << 40) | ((long)(build & 0xFF) << 32));
		}

		public UnityVersion(int major, int minor, int build, UnityVersionType type)
		{
			m_data = (ulong)(((long)(major & 0xFFFF) << 48) |

BepInExPack/BepInEx/core/Mono.Cecil.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.IO.Compression;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Runtime.Versioning;
using System.Security.Cryptography;
using System.Text;
using System.Threading;
using Mono.Cecil;
using Mono.Cecil.Cil;
using Mono.Cecil.Metadata;
using Mono.Cecil.PE;
using Mono.Collections.Generic;
using Mono.Security.Cryptography;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyProduct("Mono.Cecil")]
[assembly: AssemblyCopyright("Copyright © 2008 - 2018 Jb Evain")]
[assembly: ComVisible(false)]
[assembly: AssemblyFileVersion("0.11.4.0")]
[assembly: AssemblyInformationalVersion("0.11.4.0")]
[assembly: AssemblyTitle("Mono.Cecil")]
[assembly: Guid("fd225bb4-fa53-44b2-a6db-85f5e48dcb54")]
[assembly: InternalsVisibleTo("Mono.Cecil.Tests, PublicKey=00240000048000009400000006020000002400005253413100040000010001002b5c9f7f04346c324a3176f8d3ee823bbf2d60efdbc35f86fd9e65ea3e6cd11bcdcba3a353e55133c8ac5c4caaba581b2c6dfff2cc2d0edc43959ddb86b973300a479a82419ef489c3225f1fe429a708507bd515835160e10bc743d20ca33ab9570cfd68d479fcf0bc797a763bec5d1000f0159ef619e709d915975e87beebaf")]
[assembly: InternalsVisibleTo("Mono.Cecil.Pdb, PublicKey=00240000048000009400000006020000002400005253413100040000010001002b5c9f7f04346c324a3176f8d3ee823bbf2d60efdbc35f86fd9e65ea3e6cd11bcdcba3a353e55133c8ac5c4caaba581b2c6dfff2cc2d0edc43959ddb86b973300a479a82419ef489c3225f1fe429a708507bd515835160e10bc743d20ca33ab9570cfd68d479fcf0bc797a763bec5d1000f0159ef619e709d915975e87beebaf")]
[assembly: InternalsVisibleTo("Mono.Cecil.Mdb, PublicKey=00240000048000009400000006020000002400005253413100040000010001002b5c9f7f04346c324a3176f8d3ee823bbf2d60efdbc35f86fd9e65ea3e6cd11bcdcba3a353e55133c8ac5c4caaba581b2c6dfff2cc2d0edc43959ddb86b973300a479a82419ef489c3225f1fe429a708507bd515835160e10bc743d20ca33ab9570cfd68d479fcf0bc797a763bec5d1000f0159ef619e709d915975e87beebaf")]
[assembly: InternalsVisibleTo("Mono.Cecil.Rocks, PublicKey=00240000048000009400000006020000002400005253413100040000010001002b5c9f7f04346c324a3176f8d3ee823bbf2d60efdbc35f86fd9e65ea3e6cd11bcdcba3a353e55133c8ac5c4caaba581b2c6dfff2cc2d0edc43959ddb86b973300a479a82419ef489c3225f1fe429a708507bd515835160e10bc743d20ca33ab9570cfd68d479fcf0bc797a763bec5d1000f0159ef619e709d915975e87beebaf")]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = "")]
[assembly: AssemblyVersion("0.11.4.0")]
internal static class Consts
{
	public const string AssemblyName = "Mono.Cecil";

	public const string PublicKey = "00240000048000009400000006020000002400005253413100040000010001002b5c9f7f04346c324a3176f8d3ee823bbf2d60efdbc35f86fd9e65ea3e6cd11bcdcba3a353e55133c8ac5c4caaba581b2c6dfff2cc2d0edc43959ddb86b973300a479a82419ef489c3225f1fe429a708507bd515835160e10bc743d20ca33ab9570cfd68d479fcf0bc797a763bec5d1000f0159ef619e709d915975e87beebaf";
}
namespace Mono
{
	internal static class Disposable
	{
		public static Disposable<T> Owned<T>(T value) where T : class, IDisposable
		{
			return new Disposable<T>(value, owned: true);
		}

		public static Disposable<T> NotOwned<T>(T value) where T : class, IDisposable
		{
			return new Disposable<T>(value, owned: false);
		}
	}
	internal struct Disposable<T> : IDisposable where T : class, IDisposable
	{
		internal readonly T value;

		private readonly bool owned;

		public Disposable(T value, bool owned)
		{
			this.value = value;
			this.owned = owned;
		}

		public void Dispose()
		{
			if (value != null && owned)
			{
				value.Dispose();
			}
		}
	}
	internal static class Empty<T>
	{
		public static readonly T[] Array = new T[0];
	}
	internal class ArgumentNullOrEmptyException : ArgumentException
	{
		public ArgumentNullOrEmptyException(string paramName)
			: base("Argument null or empty", paramName)
		{
		}
	}
	internal class MergeSort<T>
	{
		private readonly T[] elements;

		private readonly T[] buffer;

		private readonly IComparer<T> comparer;

		private MergeSort(T[] elements, IComparer<T> comparer)
		{
			this.elements = elements;
			buffer = new T[elements.Length];
			Array.Copy(this.elements, buffer, elements.Length);
			this.comparer = comparer;
		}

		public static void Sort(T[] source, IComparer<T> comparer)
		{
			Sort(source, 0, source.Length, comparer);
		}

		public static void Sort(T[] source, int start, int length, IComparer<T> comparer)
		{
			new MergeSort<T>(source, comparer).Sort(start, length);
		}

		private void Sort(int start, int length)
		{
			TopDownSplitMerge(buffer, elements, start, length);
		}

		private void TopDownSplitMerge(T[] a, T[] b, int start, int end)
		{
			if (end - start >= 2)
			{
				int num = (end + start) / 2;
				TopDownSplitMerge(b, a, start, num);
				TopDownSplitMerge(b, a, num, end);
				TopDownMerge(a, b, start, num, end);
			}
		}

		private void TopDownMerge(T[] a, T[] b, int start, int middle, int end)
		{
			int num = start;
			int num2 = middle;
			for (int i = start; i < end; i++)
			{
				if (num < middle && (num2 >= end || comparer.Compare(a[num], a[num2]) <= 0))
				{
					b[i] = a[num++];
				}
				else
				{
					b[i] = a[num2++];
				}
			}
		}
	}
}
namespace Mono.Security.Cryptography
{
	internal static class CryptoConvert
	{
		private static int ToInt32LE(byte[] bytes, int offset)
		{
			return (bytes[offset + 3] << 24) | (bytes[offset + 2] << 16) | (bytes[offset + 1] << 8) | bytes[offset];
		}

		private static uint ToUInt32LE(byte[] bytes, int offset)
		{
			return (uint)((bytes[offset + 3] << 24) | (bytes[offset + 2] << 16) | (bytes[offset + 1] << 8) | bytes[offset]);
		}

		private static byte[] GetBytesLE(int val)
		{
			return new byte[4]
			{
				(byte)((uint)val & 0xFFu),
				(byte)((uint)(val >> 8) & 0xFFu),
				(byte)((uint)(val >> 16) & 0xFFu),
				(byte)((uint)(val >> 24) & 0xFFu)
			};
		}

		private static byte[] Trim(byte[] array)
		{
			for (int i = 0; i < array.Length; i++)
			{
				if (array[i] != 0)
				{
					byte[] array2 = new byte[array.Length - i];
					Buffer.BlockCopy(array, i, array2, 0, array2.Length);
					return array2;
				}
			}
			return null;
		}

		private static RSA FromCapiPrivateKeyBlob(byte[] blob, int offset)
		{
			RSAParameters parameters = default(RSAParameters);
			try
			{
				if (blob[offset] != 7 || blob[offset + 1] != 2 || blob[offset + 2] != 0 || blob[offset + 3] != 0 || ToUInt32LE(blob, offset + 8) != 843141970)
				{
					throw new CryptographicException("Invalid blob header");
				}
				int num = ToInt32LE(blob, offset + 12);
				byte[] array = new byte[4];
				Buffer.BlockCopy(blob, offset + 16, array, 0, 4);
				Array.Reverse((Array)array);
				parameters.Exponent = Trim(array);
				int num2 = offset + 20;
				int num3 = num >> 3;
				parameters.Modulus = new byte[num3];
				Buffer.BlockCopy(blob, num2, parameters.Modulus, 0, num3);
				Array.Reverse((Array)parameters.Modulus);
				num2 += num3;
				int num4 = num3 >> 1;
				parameters.P = new byte[num4];
				Buffer.BlockCopy(blob, num2, parameters.P, 0, num4);
				Array.Reverse((Array)parameters.P);
				num2 += num4;
				parameters.Q = new byte[num4];
				Buffer.BlockCopy(blob, num2, parameters.Q, 0, num4);
				Array.Reverse((Array)parameters.Q);
				num2 += num4;
				parameters.DP = new byte[num4];
				Buffer.BlockCopy(blob, num2, parameters.DP, 0, num4);
				Array.Reverse((Array)parameters.DP);
				num2 += num4;
				parameters.DQ = new byte[num4];
				Buffer.BlockCopy(blob, num2, parameters.DQ, 0, num4);
				Array.Reverse((Array)parameters.DQ);
				num2 += num4;
				parameters.InverseQ = new byte[num4];
				Buffer.BlockCopy(blob, num2, parameters.InverseQ, 0, num4);
				Array.Reverse((Array)parameters.InverseQ);
				num2 += num4;
				parameters.D = new byte[num3];
				if (num2 + num3 + offset <= blob.Length)
				{
					Buffer.BlockCopy(blob, num2, parameters.D, 0, num3);
					Array.Reverse((Array)parameters.D);
				}
			}
			catch (Exception inner)
			{
				throw new CryptographicException("Invalid blob.", inner);
			}
			RSA rSA = null;
			try
			{
				rSA = RSA.Create();
				rSA.ImportParameters(parameters);
			}
			catch (CryptographicException)
			{
				bool flag = false;
				try
				{
					rSA = new RSACryptoServiceProvider(new CspParameters
					{
						Flags = CspProviderFlags.UseMachineKeyStore
					});
					rSA.ImportParameters(parameters);
				}
				catch
				{
					flag = true;
				}
				if (flag)
				{
					throw;
				}
			}
			return rSA;
		}

		private static RSA FromCapiPublicKeyBlob(byte[] blob, int offset)
		{
			try
			{
				if (blob[offset] != 6 || blob[offset + 1] != 2 || blob[offset + 2] != 0 || blob[offset + 3] != 0 || ToUInt32LE(blob, offset + 8) != 826364754)
				{
					throw new CryptographicException("Invalid blob header");
				}
				int num = ToInt32LE(blob, offset + 12);
				RSAParameters parameters = new RSAParameters
				{
					Exponent = new byte[3]
				};
				parameters.Exponent[0] = blob[offset + 18];
				parameters.Exponent[1] = blob[offset + 17];
				parameters.Exponent[2] = blob[offset + 16];
				int srcOffset = offset + 20;
				int num2 = num >> 3;
				parameters.Modulus = new byte[num2];
				Buffer.BlockCopy(blob, srcOffset, parameters.Modulus, 0, num2);
				Array.Reverse((Array)parameters.Modulus);
				RSA rSA = null;
				try
				{
					rSA = RSA.Create();
					rSA.ImportParameters(parameters);
				}
				catch (CryptographicException)
				{
					rSA = new RSACryptoServiceProvider(new CspParameters
					{
						Flags = CspProviderFlags.UseMachineKeyStore
					});
					rSA.ImportParameters(parameters);
				}
				return rSA;
			}
			catch (Exception inner)
			{
				throw new CryptographicException("Invalid blob.", inner);
			}
		}

		public static RSA FromCapiKeyBlob(byte[] blob)
		{
			return FromCapiKeyBlob(blob, 0);
		}

		public static RSA FromCapiKeyBlob(byte[] blob, int offset)
		{
			if (blob == null)
			{
				throw new ArgumentNullException("blob");
			}
			if (offset >= blob.Length)
			{
				throw new ArgumentException("blob is too small.");
			}
			switch (blob[offset])
			{
			case 0:
				if (blob[offset + 12] == 6)
				{
					return FromCapiPublicKeyBlob(blob, offset + 12);
				}
				break;
			case 6:
				return FromCapiPublicKeyBlob(blob, offset);
			case 7:
				return FromCapiPrivateKeyBlob(blob, offset);
			}
			throw new CryptographicException("Unknown blob format.");
		}

		public static byte[] ToCapiPublicKeyBlob(RSA rsa)
		{
			RSAParameters rSAParameters = rsa.ExportParameters(includePrivateParameters: false);
			int num = rSAParameters.Modulus.Length;
			byte[] array = new byte[20 + num];
			array[0] = 6;
			array[1] = 2;
			array[5] = 36;
			array[8] = 82;
			array[9] = 83;
			array[10] = 65;
			array[11] = 49;
			byte[] bytesLE = GetBytesLE(num << 3);
			array[12] = bytesLE[0];
			array[13] = bytesLE[1];
			array[14] = bytesLE[2];
			array[15] = bytesLE[3];
			int num2 = 16;
			int num3 = rSAParameters.Exponent.Length;
			while (num3 > 0)
			{
				array[num2++] = rSAParameters.Exponent[--num3];
			}
			num2 = 20;
			byte[]? modulus = rSAParameters.Modulus;
			int num4 = modulus.Length;
			Array.Reverse((Array)modulus, 0, num4);
			Buffer.BlockCopy(modulus, 0, array, num2, num4);
			num2 += num4;
			return array;
		}
	}
}
namespace Mono.Collections.Generic
{
	public class Collection<T> : IList<T>, ICollection<T>, IEnumerable<T>, IEnumerable, IList, ICollection
	{
		public struct Enumerator : IEnumerator<T>, IEnumerator, IDisposable
		{
			private Collection<T> collection;

			private T current;

			private int next;

			private readonly int version;

			public T Current => current;

			object IEnumerator.Current
			{
				get
				{
					CheckState();
					if (next <= 0)
					{
						throw new InvalidOperationException();
					}
					return current;
				}
			}

			internal Enumerator(Collection<T> collection)
			{
				this = default(Enumerator);
				this.collection = collection;
				version = collection.version;
			}

			public bool MoveNext()
			{
				CheckState();
				if (next < 0)
				{
					return false;
				}
				if (next < collection.size)
				{
					current = collection.items[next++];
					return true;
				}
				next = -1;
				return false;
			}

			public void Reset()
			{
				CheckState();
				next = 0;
			}

			private void CheckState()
			{
				if (collection == null)
				{
					throw new ObjectDisposedException(GetType().FullName);
				}
				if (version != collection.version)
				{
					throw new InvalidOperationException();
				}
			}

			public void Dispose()
			{
				collection = null;
			}
		}

		internal T[] items;

		internal int size;

		private int version;

		public int Count => size;

		public T this[int index]
		{
			get
			{
				if (index >= size)
				{
					throw new ArgumentOutOfRangeException();
				}
				return items[index];
			}
			set
			{
				CheckIndex(index);
				if (index == size)
				{
					throw new ArgumentOutOfRangeException();
				}
				OnSet(value, index);
				items[index] = value;
			}
		}

		public int Capacity
		{
			get
			{
				return items.Length;
			}
			set
			{
				if (value < 0 || value < size)
				{
					throw new ArgumentOutOfRangeException();
				}
				Resize(value);
			}
		}

		bool ICollection<T>.IsReadOnly => false;

		bool IList.IsFixedSize => false;

		bool IList.IsReadOnly => false;

		object IList.this[int index]
		{
			get
			{
				return this[index];
			}
			set
			{
				CheckIndex(index);
				try
				{
					this[index] = (T)value;
					return;
				}
				catch (InvalidCastException)
				{
				}
				catch (NullReferenceException)
				{
				}
				throw new ArgumentException();
			}
		}

		int ICollection.Count => Count;

		bool ICollection.IsSynchronized => false;

		object ICollection.SyncRoot => this;

		public Collection()
		{
			items = Empty<T>.Array;
		}

		public Collection(int capacity)
		{
			if (capacity < 0)
			{
				throw new ArgumentOutOfRangeException();
			}
			items = ((capacity == 0) ? Empty<T>.Array : new T[capacity]);
		}

		public Collection(ICollection<T> items)
		{
			if (items == null)
			{
				throw new ArgumentNullException("items");
			}
			this.items = new T[items.Count];
			items.CopyTo(this.items, 0);
			size = this.items.Length;
		}

		public void Add(T item)
		{
			if (size == items.Length)
			{
				Grow(1);
			}
			OnAdd(item, size);
			items[size++] = item;
			version++;
		}

		public bool Contains(T item)
		{
			return IndexOf(item) != -1;
		}

		public int IndexOf(T item)
		{
			return Array.IndexOf(items, item, 0, size);
		}

		public void Insert(int index, T item)
		{
			CheckIndex(index);
			if (size == items.Length)
			{
				Grow(1);
			}
			OnInsert(item, index);
			Shift(index, 1);
			items[index] = item;
			version++;
		}

		public void RemoveAt(int index)
		{
			if (index < 0 || index >= size)
			{
				throw new ArgumentOutOfRangeException();
			}
			T item = items[index];
			OnRemove(item, index);
			Shift(index, -1);
			version++;
		}

		public bool Remove(T item)
		{
			int num = IndexOf(item);
			if (num == -1)
			{
				return false;
			}
			OnRemove(item, num);
			Shift(num, -1);
			version++;
			return true;
		}

		public void Clear()
		{
			OnClear();
			Array.Clear(items, 0, size);
			size = 0;
			version++;
		}

		public void CopyTo(T[] array, int arrayIndex)
		{
			Array.Copy(items, 0, array, arrayIndex, size);
		}

		public T[] ToArray()
		{
			T[] array = new T[size];
			Array.Copy(items, 0, array, 0, size);
			return array;
		}

		private void CheckIndex(int index)
		{
			if (index < 0 || index > size)
			{
				throw new ArgumentOutOfRangeException();
			}
		}

		private void Shift(int start, int delta)
		{
			if (delta < 0)
			{
				start -= delta;
			}
			if (start < size)
			{
				Array.Copy(items, start, items, start + delta, size - start);
			}
			size += delta;
			if (delta < 0)
			{
				Array.Clear(items, size, -delta);
			}
		}

		protected virtual void OnAdd(T item, int index)
		{
		}

		protected virtual void OnInsert(T item, int index)
		{
		}

		protected virtual void OnSet(T item, int index)
		{
		}

		protected virtual void OnRemove(T item, int index)
		{
		}

		protected virtual void OnClear()
		{
		}

		internal virtual void Grow(int desired)
		{
			int num = size + desired;
			if (num > items.Length)
			{
				num = Math.Max(Math.Max(items.Length * 2, 4), num);
				Resize(num);
			}
		}

		protected void Resize(int new_size)
		{
			if (new_size != size)
			{
				if (new_size < size)
				{
					throw new ArgumentOutOfRangeException();
				}
				items = items.Resize(new_size);
			}
		}

		int IList.Add(object value)
		{
			try
			{
				Add((T)value);
				return size - 1;
			}
			catch (InvalidCastException)
			{
			}
			catch (NullReferenceException)
			{
			}
			throw new ArgumentException();
		}

		void IList.Clear()
		{
			Clear();
		}

		bool IList.Contains(object value)
		{
			return ((IList)this).IndexOf(value) > -1;
		}

		int IList.IndexOf(object value)
		{
			try
			{
				return IndexOf((T)value);
			}
			catch (InvalidCastException)
			{
			}
			catch (NullReferenceException)
			{
			}
			return -1;
		}

		void IList.Insert(int index, object value)
		{
			CheckIndex(index);
			try
			{
				Insert(index, (T)value);
				return;
			}
			catch (InvalidCastException)
			{
			}
			catch (NullReferenceException)
			{
			}
			throw new ArgumentException();
		}

		void IList.Remove(object value)
		{
			try
			{
				Remove((T)value);
			}
			catch (InvalidCastException)
			{
			}
			catch (NullReferenceException)
			{
			}
		}

		void IList.RemoveAt(int index)
		{
			RemoveAt(index);
		}

		void ICollection.CopyTo(Array array, int index)
		{
			Array.Copy(items, 0, array, index, size);
		}

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

		IEnumerator IEnumerable.GetEnumerator()
		{
			return new Enumerator(this);
		}

		IEnumerator<T> IEnumerable<T>.GetEnumerator()
		{
			return new Enumerator(this);
		}
	}
	public sealed class ReadOnlyCollection<T> : Collection<T>, ICollection<T>, IEnumerable<T>, IEnumerable, IList, ICollection
	{
		private static ReadOnlyCollection<T> empty;

		public static ReadOnlyCollection<T> Empty
		{
			get
			{
				if (empty != null)
				{
					return empty;
				}
				Interlocked.CompareExchange(ref empty, new ReadOnlyCollection<T>(), null);
				return empty;
			}
		}

		bool ICollection<T>.IsReadOnly => true;

		bool IList.IsFixedSize => true;

		bool IList.IsReadOnly => true;

		private ReadOnlyCollection()
		{
		}

		public ReadOnlyCollection(T[] array)
		{
			if (array == null)
			{
				throw new ArgumentNullException();
			}
			Initialize(array, array.Length);
		}

		public ReadOnlyCollection(Collection<T> collection)
		{
			if (collection == null)
			{
				throw new ArgumentNullException();
			}
			Initialize(collection.items, collection.size);
		}

		private void Initialize(T[] items, int size)
		{
			base.items = new T[size];
			Array.Copy(items, 0, base.items, 0, size);
			base.size = size;
		}

		internal override void Grow(int desired)
		{
			throw new InvalidOperationException();
		}

		protected override void OnAdd(T item, int index)
		{
			throw new InvalidOperationException();
		}

		protected override void OnClear()
		{
			throw new InvalidOperationException();
		}

		protected override void OnInsert(T item, int index)
		{
			throw new InvalidOperationException();
		}

		protected override void OnRemove(T item, int index)
		{
			throw new InvalidOperationException();
		}

		protected override void OnSet(T item, int index)
		{
			throw new InvalidOperationException();
		}
	}
}
namespace Mono.Cecil
{
	internal static class Mixin
	{
		public enum Argument
		{
			name,
			fileName,
			fullName,
			stream,
			type,
			method,
			field,
			parameters,
			module,
			modifierType,
			eventType,
			fieldType,
			declaringType,
			returnType,
			propertyType,
			interfaceType,
			constraintType
		}

		public static Version ZeroVersion = new Version(0, 0, 0, 0);

		public const int NotResolvedMarker = -2;

		public const int NoDataMarker = -1;

		internal static object NoValue = new object();

		internal static object NotResolved = new object();

		public const string mscorlib = "mscorlib";

		public const string system_runtime = "System.Runtime";

		public const string system_private_corelib = "System.Private.CoreLib";

		public const string netstandard = "netstandard";

		public const int TableCount = 58;

		public const int CodedIndexCount = 14;

		public static bool IsNullOrEmpty<T>(this T[] self)
		{
			if (self != null)
			{
				return self.Length == 0;
			}
			return true;
		}

		public static bool IsNullOrEmpty<T>(this Collection<T> self)
		{
			if (self != null)
			{
				return self.size == 0;
			}
			return true;
		}

		public static T[] Resize<T>(this T[] self, int length)
		{
			Array.Resize(ref self, length);
			return self;
		}

		public static T[] Add<T>(this T[] self, T item)
		{
			if (self == null)
			{
				self = new T[1] { item };
				return self;
			}
			self = self.Resize(self.Length + 1);
			self[^1] = item;
			return self;
		}

		public static Version CheckVersion(Version version)
		{
			if (version == null)
			{
				return ZeroVersion;
			}
			if (version.Build == -1)
			{
				return new Version(version.Major, version.Minor, 0, 0);
			}
			if (version.Revision == -1)
			{
				return new Version(version.Major, version.Minor, version.Build, 0);
			}
			return version;
		}

		public static bool TryGetUniqueDocument(this MethodDebugInformation info, out Document document)
		{
			document = info.SequencePoints[0].Document;
			for (int i = 1; i < info.SequencePoints.Count; i++)
			{
				if (info.SequencePoints[i].Document != document)
				{
					return false;
				}
			}
			return true;
		}

		public static void ResolveConstant(this IConstantProvider self, ref object constant, ModuleDefinition module)
		{
			if (module == null)
			{
				constant = NoValue;
				return;
			}
			lock (module.SyncRoot)
			{
				if (constant != NotResolved)
				{
					return;
				}
				if (module.HasImage())
				{
					constant = module.Read(self, (IConstantProvider provider, MetadataReader reader) => reader.ReadConstant(provider));
				}
				else
				{
					constant = NoValue;
				}
			}
		}

		public static bool GetHasCustomAttributes(this ICustomAttributeProvider self, ModuleDefinition module)
		{
			if (module.HasImage())
			{
				return module.Read(self, (ICustomAttributeProvider provider, MetadataReader reader) => reader.HasCustomAttributes(provider));
			}
			return false;
		}

		public static Collection<CustomAttribute> GetCustomAttributes(this ICustomAttributeProvider self, ref Collection<CustomAttribute> variable, ModuleDefinition module)
		{
			if (module.HasImage())
			{
				return module.Read(ref variable, self, (ICustomAttributeProvider provider, MetadataReader reader) => reader.ReadCustomAttributes(provider));
			}
			Interlocked.CompareExchange(ref variable, new Collection<CustomAttribute>(), null);
			return variable;
		}

		public static bool ContainsGenericParameter(this IGenericInstance self)
		{
			Collection<TypeReference> genericArguments = self.GenericArguments;
			for (int i = 0; i < genericArguments.Count; i++)
			{
				if (genericArguments[i].ContainsGenericParameter)
				{
					return true;
				}
			}
			return false;
		}

		public static void GenericInstanceFullName(this IGenericInstance self, StringBuilder builder)
		{
			builder.Append("<");
			Collection<TypeReference> genericArguments = self.GenericArguments;
			for (int i = 0; i < genericArguments.Count; i++)
			{
				if (i > 0)
				{
					builder.Append(",");
				}
				builder.Append(genericArguments[i].FullName);
			}
			builder.Append(">");
		}

		public static bool GetHasGenericParameters(this IGenericParameterProvider self, ModuleDefinition module)
		{
			if (module.HasImage())
			{
				return module.Read(self, (IGenericParameterProvider provider, MetadataReader reader) => reader.HasGenericParameters(provider));
			}
			return false;
		}

		public static Collection<GenericParameter> GetGenericParameters(this IGenericParameterProvider self, ref Collection<GenericParameter> collection, ModuleDefinition module)
		{
			if (module.HasImage())
			{
				return module.Read(ref collection, self, (IGenericParameterProvider provider, MetadataReader reader) => reader.ReadGenericParameters(provider));
			}
			Interlocked.CompareExchange(ref collection, new GenericParameterCollection(self), null);
			return collection;
		}

		public static bool GetHasMarshalInfo(this IMarshalInfoProvider self, ModuleDefinition module)
		{
			if (module.HasImage())
			{
				return module.Read(self, (IMarshalInfoProvider provider, MetadataReader reader) => reader.HasMarshalInfo(provider));
			}
			return false;
		}

		public static MarshalInfo GetMarshalInfo(this IMarshalInfoProvider self, ref MarshalInfo variable, ModuleDefinition module)
		{
			if (!module.HasImage())
			{
				return null;
			}
			return module.Read(ref variable, self, (IMarshalInfoProvider provider, MetadataReader reader) => reader.ReadMarshalInfo(provider));
		}

		public static bool GetAttributes(this uint self, uint attributes)
		{
			return (self & attributes) != 0;
		}

		public static uint SetAttributes(this uint self, uint attributes, bool value)
		{
			if (value)
			{
				return self | attributes;
			}
			return self & ~attributes;
		}

		public static bool GetMaskedAttributes(this uint self, uint mask, uint attributes)
		{
			return (self & mask) == attributes;
		}

		public static uint SetMaskedAttributes(this uint self, uint mask, uint attributes, bool value)
		{
			if (value)
			{
				self &= ~mask;
				return self | attributes;
			}
			return self & ~(mask & attributes);
		}

		public static bool GetAttributes(this ushort self, ushort attributes)
		{
			return (self & attributes) != 0;
		}

		public static ushort SetAttributes(this ushort self, ushort attributes, bool value)
		{
			if (value)
			{
				return (ushort)(self | attributes);
			}
			return (ushort)(self & ~attributes);
		}

		public static bool GetMaskedAttributes(this ushort self, ushort mask, uint attributes)
		{
			return (self & mask) == attributes;
		}

		public static ushort SetMaskedAttributes(this ushort self, ushort mask, uint attributes, bool value)
		{
			if (value)
			{
				self = (ushort)(self & ~mask);
				return (ushort)(self | attributes);
			}
			return (ushort)(self & ~(mask & attributes));
		}

		public static bool HasImplicitThis(this IMethodSignature self)
		{
			if (self.HasThis)
			{
				return !self.ExplicitThis;
			}
			return false;
		}

		public static void MethodSignatureFullName(this IMethodSignature self, StringBuilder builder)
		{
			builder.Append("(");
			if (self.HasParameters)
			{
				Collection<ParameterDefinition> parameters = self.Parameters;
				for (int i = 0; i < parameters.Count; i++)
				{
					ParameterDefinition parameterDefinition = parameters[i];
					if (i > 0)
					{
						builder.Append(",");
					}
					if (parameterDefinition.ParameterType.IsSentinel)
					{
						builder.Append("...,");
					}
					builder.Append(parameterDefinition.ParameterType.FullName);
				}
			}
			builder.Append(")");
		}

		public static void CheckModule(ModuleDefinition module)
		{
			if (module == null)
			{
				throw new ArgumentNullException(Argument.module.ToString());
			}
		}

		public static bool TryGetAssemblyNameReference(this ModuleDefinition module, AssemblyNameReference name_reference, out AssemblyNameReference assembly_reference)
		{
			Collection<AssemblyNameReference> assemblyReferences = module.AssemblyReferences;
			for (int i = 0; i < assemblyReferences.Count; i++)
			{
				AssemblyNameReference assemblyNameReference = assemblyReferences[i];
				if (Equals(name_reference, assemblyNameReference))
				{
					assembly_reference = assemblyNameReference;
					return true;
				}
			}
			assembly_reference = null;
			return false;
		}

		private static bool Equals(byte[] a, byte[] b)
		{
			if (a == b)
			{
				return true;
			}
			if (a == null)
			{
				return false;
			}
			if (a.Length != b.Length)
			{
				return false;
			}
			for (int i = 0; i < a.Length; i++)
			{
				if (a[i] != b[i])
				{
					return false;
				}
			}
			return true;
		}

		private static bool Equals<T>(T a, T b) where T : class, IEquatable<T>
		{
			if (a == b)
			{
				return true;
			}
			return a?.Equals(b) ?? false;
		}

		private static bool Equals(AssemblyNameReference a, AssemblyNameReference b)
		{
			if (a == b)
			{
				return true;
			}
			if (a.Name != b.Name)
			{
				return false;
			}
			if (!Equals(a.Version, b.Version))
			{
				return false;
			}
			if (a.Culture != b.Culture)
			{
				return false;
			}
			if (!Equals(a.PublicKeyToken, b.PublicKeyToken))
			{
				return false;
			}
			return true;
		}

		public static ParameterDefinition GetParameter(this Mono.Cecil.Cil.MethodBody self, int index)
		{
			MethodDefinition method = self.method;
			if (method.HasThis)
			{
				if (index == 0)
				{
					return self.ThisParameter;
				}
				index--;
			}
			Collection<ParameterDefinition> parameters = method.Parameters;
			if (index < 0 || index >= parameters.size)
			{
				return null;
			}
			return parameters[index];
		}

		public static VariableDefinition GetVariable(this Mono.Cecil.Cil.MethodBody self, int index)
		{
			Collection<VariableDefinition> variables = self.Variables;
			if (index < 0 || index >= variables.size)
			{
				return null;
			}
			return variables[index];
		}

		public static bool GetSemantics(this MethodDefinition self, MethodSemanticsAttributes semantics)
		{
			return (self.SemanticsAttributes & semantics) != 0;
		}

		public static void SetSemantics(this MethodDefinition self, MethodSemanticsAttributes semantics, bool value)
		{
			if (value)
			{
				self.SemanticsAttributes |= semantics;
			}
			else
			{
				self.SemanticsAttributes &= (MethodSemanticsAttributes)(ushort)(~(int)semantics);
			}
		}

		public static bool IsVarArg(this IMethodSignature self)
		{
			return self.CallingConvention == MethodCallingConvention.VarArg;
		}

		public static int GetSentinelPosition(this IMethodSignature self)
		{
			if (!self.HasParameters)
			{
				return -1;
			}
			Collection<ParameterDefinition> parameters = self.Parameters;
			for (int i = 0; i < parameters.Count; i++)
			{
				if (parameters[i].ParameterType.IsSentinel)
				{
					return i;
				}
			}
			return -1;
		}

		public static void CheckName(object name)
		{
			if (name == null)
			{
				throw new ArgumentNullException(Argument.name.ToString());
			}
		}

		public static void CheckName(string name)
		{
			if (string.IsNullOrEmpty(name))
			{
				throw new ArgumentNullOrEmptyException(Argument.name.ToString());
			}
		}

		public static void CheckFileName(string fileName)
		{
			if (string.IsNullOrEmpty(fileName))
			{
				throw new ArgumentNullOrEmptyException(Argument.fileName.ToString());
			}
		}

		public static void CheckFullName(string fullName)
		{
			if (string.IsNullOrEmpty(fullName))
			{
				throw new ArgumentNullOrEmptyException(Argument.fullName.ToString());
			}
		}

		public static void CheckStream(object stream)
		{
			if (stream == null)
			{
				throw new ArgumentNullException(Argument.stream.ToString());
			}
		}

		public static void CheckWriteSeek(Stream stream)
		{
			if (!stream.CanWrite || !stream.CanSeek)
			{
				throw new ArgumentException("Stream must be writable and seekable.");
			}
		}

		public static void CheckReadSeek(Stream stream)
		{
			if (!stream.CanRead || !stream.CanSeek)
			{
				throw new ArgumentException("Stream must be readable and seekable.");
			}
		}

		public static void CheckType(object type)
		{
			if (type == null)
			{
				throw new ArgumentNullException(Argument.type.ToString());
			}
		}

		public static void CheckType(object type, Argument argument)
		{
			if (type == null)
			{
				throw new ArgumentNullException(argument.ToString());
			}
		}

		public static void CheckField(object field)
		{
			if (field == null)
			{
				throw new ArgumentNullException(Argument.field.ToString());
			}
		}

		public static void CheckMethod(object method)
		{
			if (method == null)
			{
				throw new ArgumentNullException(Argument.method.ToString());
			}
		}

		public static void CheckParameters(object parameters)
		{
			if (parameters == null)
			{
				throw new ArgumentNullException(Argument.parameters.ToString());
			}
		}

		public static uint GetTimestamp()
		{
			return (uint)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds;
		}

		public static bool HasImage(this ModuleDefinition self)
		{
			return self?.HasImage ?? false;
		}

		public static string GetFileName(this Stream self)
		{
			if (!(self is FileStream fileStream))
			{
				return string.Empty;
			}
			return Path.GetFullPath(fileStream.Name);
		}

		public static TargetRuntime ParseRuntime(this string self)
		{
			if (string.IsNullOrEmpty(self))
			{
				return TargetRuntime.Net_4_0;
			}
			switch (self[1])
			{
			case '1':
				if (self[3] != '0')
				{
					return TargetRuntime.Net_1_1;
				}
				return TargetRuntime.Net_1_0;
			case '2':
				return TargetRuntime.Net_2_0;
			default:
				return TargetRuntime.Net_4_0;
			}
		}

		public static string RuntimeVersionString(this TargetRuntime runtime)
		{
			return runtime switch
			{
				TargetRuntime.Net_1_0 => "v1.0.3705", 
				TargetRuntime.Net_1_1 => "v1.1.4322", 
				TargetRuntime.Net_2_0 => "v2.0.50727", 
				_ => "v4.0.30319", 
			};
		}

		public static bool IsWindowsMetadata(this ModuleDefinition module)
		{
			return module.MetadataKind != MetadataKind.Ecma335;
		}

		public static byte[] ReadAll(this Stream self)
		{
			MemoryStream memoryStream = new MemoryStream((int)self.Length);
			byte[] array = new byte[1024];
			int count;
			while ((count = self.Read(array, 0, array.Length)) != 0)
			{
				memoryStream.Write(array, 0, count);
			}
			return memoryStream.ToArray();
		}

		public static void Read(object o)
		{
		}

		public static bool GetHasSecurityDeclarations(this ISecurityDeclarationProvider self, ModuleDefinition module)
		{
			if (module.HasImage())
			{
				return module.Read(self, (ISecurityDeclarationProvider provider, MetadataReader reader) => reader.HasSecurityDeclarations(provider));
			}
			return false;
		}

		public static Collection<SecurityDeclaration> GetSecurityDeclarations(this ISecurityDeclarationProvider self, ref Collection<SecurityDeclaration> variable, ModuleDefinition module)
		{
			if (module.HasImage)
			{
				return module.Read(ref variable, self, (ISecurityDeclarationProvider provider, MetadataReader reader) => reader.ReadSecurityDeclarations(provider));
			}
			Interlocked.CompareExchange(ref variable, new Collection<SecurityDeclaration>(), null);
			return variable;
		}

		public static TypeReference GetEnumUnderlyingType(this TypeDefinition self)
		{
			Collection<FieldDefinition> fields = self.Fields;
			for (int i = 0; i < fields.Count; i++)
			{
				FieldDefinition fieldDefinition = fields[i];
				if (!fieldDefinition.IsStatic)
				{
					return fieldDefinition.FieldType;
				}
			}
			throw new ArgumentException();
		}

		public static TypeDefinition GetNestedType(this TypeDefinition self, string fullname)
		{
			if (!self.HasNestedTypes)
			{
				return null;
			}
			Collection<TypeDefinition> nestedTypes = self.NestedTypes;
			for (int i = 0; i < nestedTypes.Count; i++)
			{
				TypeDefinition typeDefinition = nestedTypes[i];
				if (typeDefinition.TypeFullName() == fullname)
				{
					return typeDefinition;
				}
			}
			return null;
		}

		public static bool IsPrimitive(this ElementType self)
		{
			if (self - 2 <= ElementType.U8 || self - 24 <= ElementType.Void)
			{
				return true;
			}
			return false;
		}

		public static string TypeFullName(this TypeReference self)
		{
			if (!string.IsNullOrEmpty(self.Namespace))
			{
				return self.Namespace + "." + self.Name;
			}
			return self.Name;
		}

		public static bool IsTypeOf(this TypeReference self, string @namespace, string name)
		{
			if (self.Name == name)
			{
				return self.Namespace == @namespace;
			}
			return false;
		}

		public static bool IsTypeSpecification(this TypeReference type)
		{
			switch (type.etype)
			{
			case ElementType.Ptr:
			case ElementType.ByRef:
			case ElementType.Var:
			case ElementType.Array:
			case ElementType.GenericInst:
			case ElementType.FnPtr:
			case ElementType.SzArray:
			case ElementType.MVar:
			case ElementType.CModReqD:
			case ElementType.CModOpt:
			case ElementType.Sentinel:
			case ElementType.Pinned:
				return true;
			default:
				return false;
			}
		}

		public static TypeDefinition CheckedResolve(this TypeReference self)
		{
			return self.Resolve() ?? throw new ResolutionException(self);
		}

		public static bool TryGetCoreLibraryReference(this ModuleDefinition module, out AssemblyNameReference reference)
		{
			Collection<AssemblyNameReference> assemblyReferences = module.AssemblyReferences;
			for (int i = 0; i < assemblyReferences.Count; i++)
			{
				reference = assemblyReferences[i];
				if (IsCoreLibrary(reference))
				{
					return true;
				}
			}
			reference = null;
			return false;
		}

		public static bool IsCoreLibrary(this ModuleDefinition module)
		{
			if (module.Assembly == null)
			{
				return false;
			}
			if (!IsCoreLibrary(module.Assembly.Name))
			{
				return false;
			}
			if (module.HasImage && module.Read(module, (ModuleDefinition m, MetadataReader reader) => reader.image.GetTableLength(Table.AssemblyRef) > 0))
			{
				return false;
			}
			return true;
		}

		public static void KnownValueType(this TypeReference type)
		{
			if (!type.IsDefinition)
			{
				type.IsValueType = true;
			}
		}

		private static bool IsCoreLibrary(AssemblyNameReference reference)
		{
			string name = reference.Name;
			switch (name)
			{
			default:
				return name == "netstandard";
			case "mscorlib":
			case "System.Runtime":
			case "System.Private.CoreLib":
				return true;
			}
		}

		public static ImageDebugHeaderEntry GetCodeViewEntry(this ImageDebugHeader header)
		{
			return header.GetEntry(ImageDebugType.CodeView);
		}

		public static ImageDebugHeaderEntry GetDeterministicEntry(this ImageDebugHeader header)
		{
			return header.GetEntry(ImageDebugType.Deterministic);
		}

		public static ImageDebugHeader AddDeterministicEntry(this ImageDebugHeader header)
		{
			ImageDebugDirectory directory = default(ImageDebugDirectory);
			directory.Type = ImageDebugType.Deterministic;
			ImageDebugHeaderEntry imageDebugHeaderEntry = new ImageDebugHeaderEntry(directory, Empty<byte>.Array);
			if (header == null)
			{
				return new ImageDebugHeader(imageDebugHeaderEntry);
			}
			ImageDebugHeaderEntry[] array = new ImageDebugHeaderEntry[header.Entries.Length + 1];
			Array.Copy(header.Entries, array, header.Entries.Length);
			array[^1] = imageDebugHeaderEntry;
			return new ImageDebugHeader(array);
		}

		public static ImageDebugHeaderEntry GetEmbeddedPortablePdbEntry(this ImageDebugHeader header)
		{
			return header.GetEntry(ImageDebugType.EmbeddedPortablePdb);
		}

		private static ImageDebugHeaderEntry GetEntry(this ImageDebugHeader header, ImageDebugType type)
		{
			if (!header.HasEntries)
			{
				return null;
			}
			for (int i = 0; i < header.Entries.Length; i++)
			{
				ImageDebugHeaderEntry imageDebugHeaderEntry = header.Entries[i];
				if (imageDebugHeaderEntry.Directory.Type == type)
				{
					return imageDebugHeaderEntry;
				}
			}
			return null;
		}

		public static string GetPdbFileName(string assemblyFileName)
		{
			return Path.ChangeExtension(assemblyFileName, ".pdb");
		}

		public static string GetMdbFileName(string assemblyFileName)
		{
			return assemblyFileName + ".mdb";
		}

		public static bool IsPortablePdb(string fileName)
		{
			using FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
			return IsPortablePdb(stream);
		}

		public static bool IsPortablePdb(Stream stream)
		{
			if (stream.Length < 4)
			{
				return false;
			}
			long position = stream.Position;
			try
			{
				return new BinaryReader(stream).ReadUInt32() == 1112167234;
			}
			finally
			{
				stream.Position = position;
			}
		}

		public static uint ReadCompressedUInt32(this byte[] data, ref int position)
		{
			uint result;
			if ((data[position] & 0x80) == 0)
			{
				result = data[position];
				position++;
			}
			else if ((data[position] & 0x40) == 0)
			{
				result = (uint)((data[position] & -129) << 8);
				result |= data[position + 1];
				position += 2;
			}
			else
			{
				result = (uint)((data[position] & -193) << 24);
				result |= (uint)(data[position + 1] << 16);
				result |= (uint)(data[position + 2] << 8);
				result |= data[position + 3];
				position += 4;
			}
			return result;
		}

		public static MetadataToken GetMetadataToken(this CodedIndex self, uint data)
		{
			uint rid;
			TokenType type;
			switch (self)
			{
			case CodedIndex.TypeDefOrRef:
				rid = data >> 2;
				switch (data & 3)
				{
				case 0u:
					break;
				case 1u:
					goto IL_006d;
				case 2u:
					goto IL_0078;
				default:
					goto end_IL_0001;
				}
				type = TokenType.TypeDef;
				goto IL_05b3;
			case CodedIndex.HasConstant:
				rid = data >> 2;
				switch (data & 3)
				{
				case 0u:
					break;
				case 1u:
					goto IL_00ad;
				case 2u:
					goto IL_00b8;
				default:
					goto end_IL_0001;
				}
				type = TokenType.Field;
				goto IL_05b3;
			case CodedIndex.HasCustomAttribute:
				rid = data >> 5;
				switch (data & 0x1F)
				{
				case 0u:
					break;
				case 1u:
					goto IL_013a;
				case 2u:
					goto IL_0145;
				case 3u:
					goto IL_0150;
				case 4u:
					goto IL_015b;
				case 5u:
					goto IL_0166;
				case 6u:
					goto IL_0171;
				case 7u:
					goto IL_017c;
				case 8u:
					goto IL_0183;
				case 9u:
					goto IL_018e;
				case 10u:
					goto IL_0199;
				case 11u:
					goto IL_01a4;
				case 12u:
					goto IL_01af;
				case 13u:
					goto IL_01ba;
				case 14u:
					goto IL_01c5;
				case 15u:
					goto IL_01d0;
				case 16u:
					goto IL_01db;
				case 17u:
					goto IL_01e6;
				case 18u:
					goto IL_01f1;
				case 19u:
					goto IL_01fc;
				case 20u:
					goto IL_0207;
				case 21u:
					goto IL_0212;
				default:
					goto end_IL_0001;
				}
				type = TokenType.Method;
				goto IL_05b3;
			case CodedIndex.HasFieldMarshal:
			{
				rid = data >> 1;
				uint num = data & 1u;
				if (num != 0)
				{
					if (num != 1)
					{
						break;
					}
					type = TokenType.Param;
				}
				else
				{
					type = TokenType.Field;
				}
				goto IL_05b3;
			}
			case CodedIndex.HasDeclSecurity:
				rid = data >> 2;
				switch (data & 3)
				{
				case 0u:
					break;
				case 1u:
					goto IL_0271;
				case 2u:
					goto IL_027c;
				default:
					goto end_IL_0001;
				}
				type = TokenType.TypeDef;
				goto IL_05b3;
			case CodedIndex.MemberRefParent:
				rid = data >> 3;
				switch (data & 7)
				{
				case 0u:
					break;
				case 1u:
					goto IL_02b9;
				case 2u:
					goto IL_02c4;
				case 3u:
					goto IL_02cf;
				case 4u:
					goto IL_02da;
				default:
					goto end_IL_0001;
				}
				type = TokenType.TypeDef;
				goto IL_05b3;
			case CodedIndex.HasSemantics:
			{
				rid = data >> 1;
				uint num = data & 1u;
				if (num != 0)
				{
					if (num != 1)
					{
						break;
					}
					type = TokenType.Property;
				}
				else
				{
					type = TokenType.Event;
				}
				goto IL_05b3;
			}
			case CodedIndex.MethodDefOrRef:
			{
				rid = data >> 1;
				uint num = data & 1u;
				if (num != 0)
				{
					if (num != 1)
					{
						break;
					}
					type = TokenType.MemberRef;
				}
				else
				{
					type = TokenType.Method;
				}
				goto IL_05b3;
			}
			case CodedIndex.MemberForwarded:
			{
				rid = data >> 1;
				uint num = data & 1u;
				if (num != 0)
				{
					if (num != 1)
					{
						break;
					}
					type = TokenType.Method;
				}
				else
				{
					type = TokenType.Field;
				}
				goto IL_05b3;
			}
			case CodedIndex.Implementation:
				rid = data >> 2;
				switch (data & 3)
				{
				case 0u:
					break;
				case 1u:
					goto IL_038d;
				case 2u:
					goto IL_0398;
				default:
					goto end_IL_0001;
				}
				type = TokenType.File;
				goto IL_05b3;
			case CodedIndex.CustomAttributeType:
			{
				rid = data >> 3;
				uint num = data & 7u;
				if (num != 2)
				{
					if (num != 3)
					{
						break;
					}
					type = TokenType.MemberRef;
				}
				else
				{
					type = TokenType.Method;
				}
				goto IL_05b3;
			}
			case CodedIndex.ResolutionScope:
				rid = data >> 2;
				switch (data & 3)
				{
				case 0u:
					break;
				case 1u:
					goto IL_03f8;
				case 2u:
					goto IL_0403;
				case 3u:
					goto IL_040e;
				default:
					goto end_IL_0001;
				}
				type = TokenType.Module;
				goto IL_05b3;
			case CodedIndex.TypeOrMethodDef:
			{
				rid = data >> 1;
				uint num = data & 1u;
				if (num != 0)
				{
					if (num != 1)
					{
						break;
					}
					type = TokenType.Method;
				}
				else
				{
					type = TokenType.TypeDef;
				}
				goto IL_05b3;
			}
			case CodedIndex.HasCustomDebugInformation:
				{
					rid = data >> 5;
					switch (data & 0x1F)
					{
					case 0u:
						break;
					case 1u:
						goto IL_04ce;
					case 2u:
						goto IL_04d9;
					case 3u:
						goto IL_04e4;
					case 4u:
						goto IL_04ef;
					case 5u:
						goto IL_04fa;
					case 6u:
						goto IL_0505;
					case 7u:
						goto IL_0510;
					case 8u:
						goto IL_0517;
					case 9u:
						goto IL_0522;
					case 10u:
						goto IL_052d;
					case 11u:
						goto IL_0535;
					case 12u:
						goto IL_053d;
					case 13u:
						goto IL_0545;
					case 14u:
						goto IL_054d;
					case 15u:
						goto IL_0555;
					case 16u:
						goto IL_055d;
					case 17u:
						goto IL_0565;
					case 18u:
						goto IL_056d;
					case 19u:
						goto IL_0575;
					case 20u:
						goto IL_057d;
					case 21u:
						goto IL_0585;
					case 22u:
						goto IL_058d;
					case 23u:
						goto IL_0595;
					case 24u:
						goto IL_059d;
					case 25u:
						goto IL_05a5;
					case 26u:
						goto IL_05ad;
					default:
						goto end_IL_0001;
					}
					type = TokenType.Method;
					goto IL_05b3;
				}
				IL_05ad:
				type = TokenType.ImportScope;
				goto IL_05b3;
				IL_05a5:
				type = TokenType.LocalConstant;
				goto IL_05b3;
				IL_059d:
				type = TokenType.LocalVariable;
				goto IL_05b3;
				IL_0595:
				type = TokenType.LocalScope;
				goto IL_05b3;
				IL_058d:
				type = TokenType.Document;
				goto IL_05b3;
				IL_0585:
				type = TokenType.MethodSpec;
				goto IL_05b3;
				IL_057d:
				type = TokenType.GenericParamConstraint;
				goto IL_05b3;
				IL_0575:
				type = TokenType.GenericParam;
				goto IL_05b3;
				IL_056d:
				type = TokenType.ManifestResource;
				goto IL_05b3;
				IL_0565:
				type = TokenType.ExportedType;
				goto IL_05b3;
				IL_055d:
				type = TokenType.File;
				goto IL_05b3;
				IL_0555:
				type = TokenType.AssemblyRef;
				goto IL_05b3;
				IL_054d:
				type = TokenType.Assembly;
				goto IL_05b3;
				IL_0545:
				type = TokenType.TypeSpec;
				goto IL_05b3;
				IL_053d:
				type = TokenType.ModuleRef;
				goto IL_05b3;
				IL_0535:
				type = TokenType.Signature;
				goto IL_05b3;
				IL_052d:
				type = TokenType.Event;
				goto IL_05b3;
				IL_0522:
				type = TokenType.Property;
				goto IL_05b3;
				IL_0517:
				type = TokenType.Permission;
				goto IL_05b3;
				IL_0510:
				type = TokenType.Module;
				goto IL_05b3;
				IL_0505:
				type = TokenType.MemberRef;
				goto IL_05b3;
				IL_04fa:
				type = TokenType.InterfaceImpl;
				goto IL_05b3;
				IL_04ef:
				type = TokenType.Param;
				goto IL_05b3;
				IL_04e4:
				type = TokenType.TypeDef;
				goto IL_05b3;
				IL_04d9:
				type = TokenType.TypeRef;
				goto IL_05b3;
				IL_04ce:
				type = TokenType.Field;
				goto IL_05b3;
				IL_01db:
				type = TokenType.File;
				goto IL_05b3;
				IL_01d0:
				type = TokenType.AssemblyRef;
				goto IL_05b3;
				IL_01ba:
				type = TokenType.TypeSpec;
				goto IL_05b3;
				IL_01c5:
				type = TokenType.Assembly;
				goto IL_05b3;
				IL_040e:
				type = TokenType.TypeRef;
				goto IL_05b3;
				IL_0403:
				type = TokenType.AssemblyRef;
				goto IL_05b3;
				IL_03f8:
				type = TokenType.ModuleRef;
				goto IL_05b3;
				IL_01af:
				type = TokenType.ModuleRef;
				goto IL_05b3;
				IL_01a4:
				type = TokenType.Signature;
				goto IL_05b3;
				IL_018e:
				type = TokenType.Property;
				goto IL_05b3;
				IL_0199:
				type = TokenType.Event;
				goto IL_05b3;
				IL_0398:
				type = TokenType.ExportedType;
				goto IL_05b3;
				IL_038d:
				type = TokenType.AssemblyRef;
				goto IL_05b3;
				IL_0183:
				type = TokenType.Permission;
				goto IL_05b3;
				IL_017c:
				type = TokenType.Module;
				goto IL_05b3;
				IL_0166:
				type = TokenType.InterfaceImpl;
				goto IL_05b3;
				IL_0171:
				type = TokenType.MemberRef;
				goto IL_05b3;
				IL_015b:
				type = TokenType.Param;
				goto IL_05b3;
				IL_0145:
				type = TokenType.TypeRef;
				goto IL_05b3;
				IL_0150:
				type = TokenType.TypeDef;
				goto IL_05b3;
				IL_013a:
				type = TokenType.Field;
				goto IL_05b3;
				IL_006d:
				type = TokenType.TypeRef;
				goto IL_05b3;
				IL_02da:
				type = TokenType.TypeSpec;
				goto IL_05b3;
				IL_02cf:
				type = TokenType.Method;
				goto IL_05b3;
				IL_02c4:
				type = TokenType.ModuleRef;
				goto IL_05b3;
				IL_02b9:
				type = TokenType.TypeRef;
				goto IL_05b3;
				IL_00b8:
				type = TokenType.Property;
				goto IL_05b3;
				IL_027c:
				type = TokenType.Assembly;
				goto IL_05b3;
				IL_0271:
				type = TokenType.Method;
				goto IL_05b3;
				IL_00ad:
				type = TokenType.Param;
				goto IL_05b3;
				IL_05b3:
				return new MetadataToken(type, rid);
				IL_0078:
				type = TokenType.TypeSpec;
				goto IL_05b3;
				IL_0212:
				type = TokenType.MethodSpec;
				goto IL_05b3;
				IL_0207:
				type = TokenType.GenericParamConstraint;
				goto IL_05b3;
				IL_01fc:
				type = TokenType.GenericParam;
				goto IL_05b3;
				IL_01f1:
				type = TokenType.ManifestResource;
				goto IL_05b3;
				IL_01e6:
				type = TokenType.ExportedType;
				goto IL_05b3;
				end_IL_0001:
				break;
			}
			return MetadataToken.Zero;
		}

		public static uint CompressMetadataToken(this CodedIndex self, MetadataToken token)
		{
			uint result = 0u;
			if (token.RID == 0)
			{
				return result;
			}
			switch (self)
			{
			case CodedIndex.TypeDefOrRef:
				result = token.RID << 2;
				switch (token.TokenType)
				{
				case TokenType.TypeDef:
					return result | 0u;
				case TokenType.TypeRef:
					return result | 1u;
				case TokenType.TypeSpec:
					return result | 2u;
				}
				break;
			case CodedIndex.HasConstant:
				result = token.RID << 2;
				switch (token.TokenType)
				{
				case TokenType.Field:
					return result | 0u;
				case TokenType.Param:
					return result | 1u;
				case TokenType.Property:
					return result | 2u;
				}
				break;
			case CodedIndex.HasCustomAttribute:
				result = token.RID << 5;
				switch (token.TokenType)
				{
				case TokenType.Method:
					return result | 0u;
				case TokenType.Field:
					return result | 1u;
				case TokenType.TypeRef:
					return result | 2u;
				case TokenType.TypeDef:
					return result | 3u;
				case TokenType.Param:
					return result | 4u;
				case TokenType.InterfaceImpl:
					return result | 5u;
				case TokenType.MemberRef:
					return result | 6u;
				case TokenType.Module:
					return result | 7u;
				case TokenType.Permission:
					return result | 8u;
				case TokenType.Property:
					return result | 9u;
				case TokenType.Event:
					return result | 0xAu;
				case TokenType.Signature:
					return result | 0xBu;
				case TokenType.ModuleRef:
					return result | 0xCu;
				case TokenType.TypeSpec:
					return result | 0xDu;
				case TokenType.Assembly:
					return result | 0xEu;
				case TokenType.AssemblyRef:
					return result | 0xFu;
				case TokenType.File:
					return result | 0x10u;
				case TokenType.ExportedType:
					return result | 0x11u;
				case TokenType.ManifestResource:
					return result | 0x12u;
				case TokenType.GenericParam:
					return result | 0x13u;
				case TokenType.GenericParamConstraint:
					return result | 0x14u;
				case TokenType.MethodSpec:
					return result | 0x15u;
				}
				break;
			case CodedIndex.HasFieldMarshal:
				result = token.RID << 1;
				switch (token.TokenType)
				{
				case TokenType.Field:
					return result | 0u;
				case TokenType.Param:
					return result | 1u;
				}
				break;
			case CodedIndex.HasDeclSecurity:
				result = token.RID << 2;
				switch (token.TokenType)
				{
				case TokenType.TypeDef:
					return result | 0u;
				case TokenType.Method:
					return result | 1u;
				case TokenType.Assembly:
					return result | 2u;
				}
				break;
			case CodedIndex.MemberRefParent:
				result = token.RID << 3;
				switch (token.TokenType)
				{
				case TokenType.TypeDef:
					return result | 0u;
				case TokenType.TypeRef:
					return result | 1u;
				case TokenType.ModuleRef:
					return result | 2u;
				case TokenType.Method:
					return result | 3u;
				case TokenType.TypeSpec:
					return result | 4u;
				}
				break;
			case CodedIndex.HasSemantics:
				result = token.RID << 1;
				switch (token.TokenType)
				{
				case TokenType.Event:
					return result | 0u;
				case TokenType.Property:
					return result | 1u;
				}
				break;
			case CodedIndex.MethodDefOrRef:
				result = token.RID << 1;
				switch (token.TokenType)
				{
				case TokenType.Method:
					return result | 0u;
				case TokenType.MemberRef:
					return result | 1u;
				}
				break;
			case CodedIndex.MemberForwarded:
				result = token.RID << 1;
				switch (token.TokenType)
				{
				case TokenType.Field:
					return result | 0u;
				case TokenType.Method:
					return result | 1u;
				}
				break;
			case CodedIndex.Implementation:
				result = token.RID << 2;
				switch (token.TokenType)
				{
				case TokenType.File:
					return result | 0u;
				case TokenType.AssemblyRef:
					return result | 1u;
				case TokenType.ExportedType:
					return result | 2u;
				}
				break;
			case CodedIndex.CustomAttributeType:
				result = token.RID << 3;
				switch (token.TokenType)
				{
				case TokenType.Method:
					return result | 2u;
				case TokenType.MemberRef:
					return result | 3u;
				}
				break;
			case CodedIndex.ResolutionScope:
				result = token.RID << 2;
				switch (token.TokenType)
				{
				case TokenType.Module:
					return result | 0u;
				case TokenType.ModuleRef:
					return result | 1u;
				case TokenType.AssemblyRef:
					return result | 2u;
				case TokenType.TypeRef:
					return result | 3u;
				}
				break;
			case CodedIndex.TypeOrMethodDef:
				result = token.RID << 1;
				switch (token.TokenType)
				{
				case TokenType.TypeDef:
					return result | 0u;
				case TokenType.Method:
					return result | 1u;
				}
				break;
			case CodedIndex.HasCustomDebugInformation:
				result = token.RID << 5;
				switch (token.TokenType)
				{
				case TokenType.Method:
					return result | 0u;
				case TokenType.Field:
					return result | 1u;
				case TokenType.TypeRef:
					return result | 2u;
				case TokenType.TypeDef:
					return result | 3u;
				case TokenType.Param:
					return result | 4u;
				case TokenType.InterfaceImpl:
					return result | 5u;
				case TokenType.MemberRef:
					return result | 6u;
				case TokenType.Module:
					return result | 7u;
				case TokenType.Permission:
					return result | 8u;
				case TokenType.Property:
					return result | 9u;
				case TokenType.Event:
					return result | 0xAu;
				case TokenType.Signature:
					return result | 0xBu;
				case TokenType.ModuleRef:
					return result | 0xCu;
				case TokenType.TypeSpec:
					return result | 0xDu;
				case TokenType.Assembly:
					return result | 0xEu;
				case TokenType.AssemblyRef:
					return result | 0xFu;
				case TokenType.File:
					return result | 0x10u;
				case TokenType.ExportedType:
					return result | 0x11u;
				case TokenType.ManifestResource:
					return result | 0x12u;
				case TokenType.GenericParam:
					return result | 0x13u;
				case TokenType.GenericParamConstraint:
					return result | 0x14u;
				case TokenType.MethodSpec:
					return result | 0x15u;
				case TokenType.Document:
					return result | 0x16u;
				case TokenType.LocalScope:
					return result | 0x17u;
				case TokenType.LocalVariable:
					return result | 0x18u;
				case TokenType.LocalConstant:
					return result | 0x19u;
				case TokenType.ImportScope:
					return result | 0x1Au;
				}
				break;
			}
			throw new ArgumentException();
		}

		public static int GetSize(this CodedIndex self, Func<Table, int> counter)
		{
			int num;
			Table[] array;
			switch (self)
			{
			case CodedIndex.TypeDefOrRef:
				num = 2;
				array = new Table[3]
				{
					Table.TypeDef,
					Table.TypeRef,
					Table.TypeSpec
				};
				break;
			case CodedIndex.HasConstant:
				num = 2;
				array = new Table[3]
				{
					Table.Field,
					Table.Param,
					Table.Property
				};
				break;
			case CodedIndex.HasCustomAttribute:
				num = 5;
				array = new Table[22]
				{
					Table.Method,
					Table.Field,
					Table.TypeRef,
					Table.TypeDef,
					Table.Param,
					Table.InterfaceImpl,
					Table.MemberRef,
					Table.Module,
					Table.DeclSecurity,
					Table.Property,
					Table.Event,
					Table.StandAloneSig,
					Table.ModuleRef,
					Table.TypeSpec,
					Table.Assembly,
					Table.AssemblyRef,
					Table.File,
					Table.ExportedType,
					Table.ManifestResource,
					Table.GenericParam,
					Table.GenericParamConstraint,
					Table.MethodSpec
				};
				break;
			case CodedIndex.HasFieldMarshal:
				num = 1;
				array = new Table[2]
				{
					Table.Field,
					Table.Param
				};
				break;
			case CodedIndex.HasDeclSecurity:
				num = 2;
				array = new Table[3]
				{
					Table.TypeDef,
					Table.Method,
					Table.Assembly
				};
				break;
			case CodedIndex.MemberRefParent:
				num = 3;
				array = new Table[5]
				{
					Table.TypeDef,
					Table.TypeRef,
					Table.ModuleRef,
					Table.Method,
					Table.TypeSpec
				};
				break;
			case CodedIndex.HasSemantics:
				num = 1;
				array = new Table[2]
				{
					Table.Event,
					Table.Property
				};
				break;
			case CodedIndex.MethodDefOrRef:
				num = 1;
				array = new Table[2]
				{
					Table.Method,
					Table.MemberRef
				};
				break;
			case CodedIndex.MemberForwarded:
				num = 1;
				array = new Table[2]
				{
					Table.Field,
					Table.Method
				};
				break;
			case CodedIndex.Implementation:
				num = 2;
				array = new Table[3]
				{
					Table.File,
					Table.AssemblyRef,
					Table.ExportedType
				};
				break;
			case CodedIndex.CustomAttributeType:
				num = 3;
				array = new Table[2]
				{
					Table.Method,
					Table.MemberRef
				};
				break;
			case CodedIndex.ResolutionScope:
				num = 2;
				array = new Table[4]
				{
					Table.Module,
					Table.ModuleRef,
					Table.AssemblyRef,
					Table.TypeRef
				};
				break;
			case CodedIndex.TypeOrMethodDef:
				num = 1;
				array = new Table[2]
				{
					Table.TypeDef,
					Table.Method
				};
				break;
			case CodedIndex.HasCustomDebugInformation:
				num = 5;
				array = new Table[27]
				{
					Table.Method,
					Table.Field,
					Table.TypeRef,
					Table.TypeDef,
					Table.Param,
					Table.InterfaceImpl,
					Table.MemberRef,
					Table.Module,
					Table.DeclSecurity,
					Table.Property,
					Table.Event,
					Table.StandAloneSig,
					Table.ModuleRef,
					Table.TypeSpec,
					Table.Assembly,
					Table.AssemblyRef,
					Table.File,
					Table.ExportedType,
					Table.ManifestResource,
					Table.GenericParam,
					Table.GenericParamConstraint,
					Table.MethodSpec,
					Table.Document,
					Table.LocalScope,
					Table.LocalVariable,
					Table.LocalConstant,
					Table.ImportScope
				};
				break;
			default:
				throw new ArgumentException();
			}
			int num2 = 0;
			for (int i = 0; i < array.Length; i++)
			{
				num2 = Math.Max(counter(array[i]), num2);
			}
			if (num2 >= 1 << 16 - num)
			{
				return 4;
			}
			return 2;
		}

		public static RSA CreateRSA(this WriterParameters writer_parameters)
		{
			if (writer_parameters.StrongNameKeyBlob != null)
			{
				return CryptoConvert.FromCapiKeyBlob(writer_parameters.StrongNameKeyBlob);
			}
			string key_container;
			byte[] key;
			if (writer_parameters.StrongNameKeyContainer != null)
			{
				key_container = writer_parameters.StrongNameKeyContainer;
			}
			else if (!TryGetKeyContainer(writer_parameters.StrongNameKeyPair, out key, out key_container))
			{
				return CryptoConvert.FromCapiKeyBlob(key);
			}
			return new RSACryptoServiceProvider(new CspParameters
			{
				Flags = CspProviderFlags.UseMachineKeyStore,
				KeyContainerName = key_container,
				KeyNumber = 2
			});
		}

		private static bool TryGetKeyContainer(ISerializable key_pair, out byte[] key, out string key_container)
		{
			SerializationInfo serializationInfo = new SerializationInfo(typeof(StrongNameKeyPair), new FormatterConverter());
			key_pair.GetObjectData(serializationInfo, default(StreamingContext));
			key = (byte[])serializationInfo.GetValue("_keyPairArray", typeof(byte[]));
			key_container = serializationInfo.GetString("_keyPairContainer");
			return key_container != null;
		}
	}
	public struct ArrayDimension
	{
		private int? lower_bound;

		private int? upper_bound;

		public int? LowerBound
		{
			get
			{
				return lower_bound;
			}
			set
			{
				lower_bound = value;
			}
		}

		public int? UpperBound
		{
			get
			{
				return upper_bound;
			}
			set
			{
				upper_bound = value;
			}
		}

		public bool IsSized
		{
			get
			{
				if (!lower_bound.HasValue)
				{
					return upper_bound.HasValue;
				}
				return true;
			}
		}

		public ArrayDimension(int? lowerBound, int? upperBound)
		{
			lower_bound = lowerBound;
			upper_bound = upperBound;
		}

		public override string ToString()
		{
			if (IsSized)
			{
				int? num = lower_bound;
				string? text = num.ToString();
				num = upper_bound;
				return text + "..." + num;
			}
			return string.Empty;
		}
	}
	public sealed class ArrayType : TypeSpecification
	{
		private Collection<ArrayDimension> dimensions;

		public Collection<ArrayDimension> Dimensions
		{
			get
			{
				if (dimensions != null)
				{
					return dimensions;
				}
				Collection<ArrayDimension> collection = new Collection<ArrayDimension>();
				collection.Add(default(ArrayDimension));
				Interlocked.CompareExchange(ref dimensions, collection, null);
				return dimensions;
			}
		}

		public int Rank
		{
			get
			{
				if (dimensions != null)
				{
					return dimensions.Count;
				}
				return 1;
			}
		}

		public bool IsVector
		{
			get
			{
				if (dimensions == null)
				{
					return true;
				}
				if (dimensions.Count > 1)
				{
					return false;
				}
				return !dimensions[0].IsSized;
			}
		}

		public override bool IsValueType
		{
			get
			{
				return false;
			}
			set
			{
				throw new InvalidOperationException();
			}
		}

		public override string Name => base.Name + Suffix;

		public override string FullName => base.FullName + Suffix;

		private string Suffix
		{
			get
			{
				if (IsVector)
				{
					return "[]";
				}
				StringBuilder stringBuilder = new StringBuilder();
				stringBuilder.Append("[");
				for (int i = 0; i < dimensions.Count; i++)
				{
					if (i > 0)
					{
						stringBuilder.Append(",");
					}
					stringBuilder.Append(dimensions[i].ToString());
				}
				stringBuilder.Append("]");
				return stringBuilder.ToString();
			}
		}

		public override bool IsArray => true;

		public ArrayType(TypeReference type)
			: base(type)
		{
			Mixin.CheckType(type);
			etype = Mono.Cecil.Metadata.ElementType.Array;
		}

		public ArrayType(TypeReference type, int rank)
			: this(type)
		{
			Mixin.CheckType(type);
			if (rank != 1)
			{
				dimensions = new Collection<ArrayDimension>(rank);
				for (int i = 0; i < rank; i++)
				{
					dimensions.Add(default(ArrayDimension));
				}
				etype = Mono.Cecil.Metadata.ElementType.Array;
			}
		}
	}
	public sealed class AssemblyDefinition : ICustomAttributeProvider, IMetadataTokenProvider, ISecurityDeclarationProvider, IDisposable
	{
		private AssemblyNameDefinition name;

		internal ModuleDefinition main_module;

		private Collection<ModuleDefinition> modules;

		private Collection<CustomAttribute> custom_attributes;

		private Collection<SecurityDeclaration> security_declarations;

		public AssemblyNameDefinition Name
		{
			get
			{
				return name;
			}
			set
			{
				name = value;
			}
		}

		public string FullName
		{
			get
			{
				if (name == null)
				{
					return string.Empty;
				}
				return name.FullName;
			}
		}

		public MetadataToken MetadataToken
		{
			get
			{
				return new MetadataToken(TokenType.Assembly, 1);
			}
			set
			{
			}
		}

		public Collection<ModuleDefinition> Modules
		{
			get
			{
				if (modules != null)
				{
					return modules;
				}
				if (main_module.HasImage)
				{
					return main_module.Read(ref modules, this, (AssemblyDefinition _, MetadataReader reader) => reader.ReadModules());
				}
				Interlocked.CompareExchange(ref modules, new Collection<ModuleDefinition>(1) { main_module }, null);
				return modules;
			}
		}

		public ModuleDefinition MainModule => main_module;

		public MethodDefinition EntryPoint
		{
			get
			{
				return main_module.EntryPoint;
			}
			set
			{
				main_module.EntryPoint = value;
			}
		}

		public bool HasCustomAttributes
		{
			get
			{
				if (custom_attributes != null)
				{
					return custom_attributes.Count > 0;
				}
				return this.GetHasCustomAttributes(main_module);
			}
		}

		public Collection<CustomAttribute> CustomAttributes => custom_attributes ?? this.GetCustomAttributes(ref custom_attributes, main_module);

		public bool HasSecurityDeclarations
		{
			get
			{
				if (security_declarations != null)
				{
					return security_declarations.Count > 0;
				}
				return this.GetHasSecurityDeclarations(main_module);
			}
		}

		public Collection<SecurityDeclaration> SecurityDeclarations => security_declarations ?? this.GetSecurityDeclarations(ref security_declarations, main_module);

		internal AssemblyDefinition()
		{
		}

		public void Dispose()
		{
			if (modules == null)
			{
				main_module.Dispose();
				return;
			}
			Collection<ModuleDefinition> collection = Modules;
			for (int i = 0; i < collection.Count; i++)
			{
				collection[i].Dispose();
			}
		}

		public static AssemblyDefinition CreateAssembly(AssemblyNameDefinition assemblyName, string moduleName, ModuleKind kind)
		{
			return CreateAssembly(assemblyName, moduleName, new ModuleParameters
			{
				Kind = kind
			});
		}

		public static AssemblyDefinition CreateAssembly(AssemblyNameDefinition assemblyName, string moduleName, ModuleParameters parameters)
		{
			if (assemblyName == null)
			{
				throw new ArgumentNullException("assemblyName");
			}
			if (moduleName == null)
			{
				throw new ArgumentNullException("moduleName");
			}
			Mixin.CheckParameters(parameters);
			if (parameters.Kind == ModuleKind.NetModule)
			{
				throw new ArgumentException("kind");
			}
			AssemblyDefinition assembly = ModuleDefinition.CreateModule(moduleName, parameters).Assembly;
			assembly.Name = assemblyName;
			return assembly;
		}

		public static AssemblyDefinition ReadAssembly(string fileName)
		{
			return ReadAssembly(ModuleDefinition.ReadModule(fileName));
		}

		public static AssemblyDefinition ReadAssembly(string fileName, ReaderParameters parameters)
		{
			return ReadAssembly(ModuleDefinition.ReadModule(fileName, parameters));
		}

		public static AssemblyDefinition ReadAssembly(Stream stream)
		{
			return ReadAssembly(ModuleDefinition.ReadModule(stream));
		}

		public static AssemblyDefinition ReadAssembly(Stream stream, ReaderParameters parameters)
		{
			return ReadAssembly(ModuleDefinition.ReadModule(stream, parameters));
		}

		private static AssemblyDefinition ReadAssembly(ModuleDefinition module)
		{
			return module.Assembly ?? throw new ArgumentException();
		}

		public void Write(string fileName)
		{
			Write(fileName, new WriterParameters());
		}

		public void Write(string fileName, WriterParameters parameters)
		{
			main_module.Write(fileName, parameters);
		}

		public void Write()
		{
			main_module.Write();
		}

		public void Write(WriterParameters parameters)
		{
			main_module.Write(parameters);
		}

		public void Write(Stream stream)
		{
			Write(stream, new WriterParameters());
		}

		public void Write(Stream stream, WriterParameters parameters)
		{
			main_module.Write(stream, parameters);
		}

		public override string ToString()
		{
			return FullName;
		}
	}
	[Flags]
	public enum AssemblyAttributes : uint
	{
		PublicKey = 1u,
		SideBySideCompatible = 0u,
		Retargetable = 0x100u,
		WindowsRuntime = 0x200u,
		DisableJITCompileOptimizer = 0x4000u,
		EnableJITCompileTracking = 0x8000u
	}
	public enum AssemblyHashAlgorithm : uint
	{
		None = 0u,
		MD5 = 32771u,
		SHA1 = 32772u,
		SHA256 = 32780u,
		SHA384 = 32781u,
		SHA512 = 32782u,
		Reserved = 32771u
	}
	public sealed class AssemblyLinkedResource : Resource
	{
		private AssemblyNameReference reference;

		public AssemblyNameReference Assembly
		{
			get
			{
				return reference;
			}
			set
			{
				reference = value;
			}
		}

		public override ResourceType ResourceType => ResourceType.AssemblyLinked;

		public AssemblyLinkedResource(string name, ManifestResourceAttributes flags)
			: base(name, flags)
		{
		}

		public AssemblyLinkedResource(string name, ManifestResourceAttributes flags, AssemblyNameReference reference)
			: base(name, flags)
		{
			this.reference = reference;
		}
	}
	public sealed class AssemblyNameDefinition : AssemblyNameReference
	{
		public override byte[] Hash => Empty<byte>.Array;

		internal AssemblyNameDefinition()
		{
			token = new MetadataToken(TokenType.Assembly, 1);
		}

		public AssemblyNameDefinition(string name, Version version)
			: base(name, version)
		{
			token = new MetadataToken(TokenType.Assembly, 1);
		}
	}
	public class AssemblyNameReference : IMetadataScope, IMetadataTokenProvider
	{
		private string name;

		private string culture;

		private Version version;

		private uint attributes;

		private byte[] public_key;

		private byte[] public_key_token;

		private AssemblyHashAlgorithm hash_algorithm;

		private byte[] hash;

		internal MetadataToken token;

		private string full_name;

		public string Name
		{
			get
			{
				return name;
			}
			set
			{
				name = value;
				full_name = null;
			}
		}

		public string Culture
		{
			get
			{
				return culture;
			}
			set
			{
				culture = value;
				full_name = null;
			}
		}

		public Version Version
		{
			get
			{
				return version;
			}
			set
			{
				version = Mixin.CheckVersion(value);
				full_name = null;
			}
		}

		public AssemblyAttributes Attributes
		{
			get
			{
				return (AssemblyAttributes)attributes;
			}
			set
			{
				attributes = (uint)value;
			}
		}

		public bool HasPublicKey
		{
			get
			{
				return attributes.GetAttributes(1u);
			}
			set
			{
				attributes = attributes.SetAttributes(1u, value);
			}
		}

		public bool IsSideBySideCompatible
		{
			get
			{
				return attributes.GetAttributes(0u);
			}
			set
			{
				attributes = attributes.SetAttributes(0u, value);
			}
		}

		public bool IsRetargetable
		{
			get
			{
				return attributes.GetAttributes(256u);
			}
			set
			{
				attributes = attributes.SetAttributes(256u, value);
			}
		}

		public bool IsWindowsRuntime
		{
			get
			{
				return attributes.GetAttributes(512u);
			}
			set
			{
				attributes = attributes.SetAttributes(512u, value);
			}
		}

		public byte[] PublicKey
		{
			get
			{
				return public_key ?? Empty<byte>.Array;
			}
			set
			{
				public_key = value;
				HasPublicKey = !public_key.IsNullOrEmpty();
				public_key_token = null;
				full_name = null;
			}
		}

		public byte[] PublicKeyToken
		{
			get
			{
				if (public_key_token == null && !public_key.IsNullOrEmpty())
				{
					byte[] array = HashPublicKey();
					byte[] array2 = new byte[8];
					Array.Copy(array, array.Length - 8, array2, 0, 8);
					Array.Reverse((Array)array2, 0, 8);
					Interlocked.CompareExchange(ref public_key_token, array2, null);
				}
				return public_key_token ?? Empty<byte>.Array;
			}
			set
			{
				public_key_token = value;
				full_name = null;
			}
		}

		public virtual MetadataScopeType MetadataScopeType => MetadataScopeType.AssemblyNameReference;

		public string FullName
		{
			get
			{
				if (full_name != null)
				{
					return full_name;
				}
				StringBuilder stringBuilder = new StringBuilder();
				stringBuilder.Append(name);
				stringBuilder.Append(", ");
				stringBuilder.Append("Version=");
				stringBuilder.Append(version.ToString(4));
				stringBuilder.Append(", ");
				stringBuilder.Append("Culture=");
				stringBuilder.Append(string.IsNullOrEmpty(culture) ? "neutral" : culture);
				stringBuilder.Append(", ");
				stringBuilder.Append("PublicKeyToken=");
				byte[] publicKeyToken = PublicKeyToken;
				if (!publicKeyToken.IsNullOrEmpty() && publicKeyToken.Length != 0)
				{
					for (int i = 0; i < publicKeyToken.Length; i++)
					{
						stringBuilder.Append(publicKeyToken[i].ToString("x2"));
					}
				}
				else
				{
					stringBuilder.Append("null");
				}
				if (IsRetargetable)
				{
					stringBuilder.Append(", ");
					stringBuilder.Append("Retargetable=Yes");
				}
				Interlocked.CompareExchange(ref full_name, stringBuilder.ToString(), null);
				return full_name;
			}
		}

		public AssemblyHashAlgorithm HashAlgorithm
		{
			get
			{
				return hash_algorithm;
			}
			set
			{
				hash_algorithm = value;
			}
		}

		public virtual byte[] Hash
		{
			get
			{
				return hash;
			}
			set
			{
				hash = value;
			}
		}

		public MetadataToken MetadataToken
		{
			get
			{
				return token;
			}
			set
			{
				token = value;
			}
		}

		private byte[] HashPublicKey()
		{
			HashAlgorithm hashAlgorithm = ((hash_algorithm != AssemblyHashAlgorithm.MD5) ? ((HashAlgorithm)SHA1.Create()) : ((HashAlgorithm)MD5.Create()));
			using (hashAlgorithm)
			{
				return hashAlgorithm.ComputeHash(public_key);
			}
		}

		public static AssemblyNameReference Parse(string fullName)
		{
			if (fullName == null)
			{
				throw new ArgumentNullException("fullName");
			}
			if (fullName.Length == 0)
			{
				throw new ArgumentException("Name can not be empty");
			}
			AssemblyNameReference assemblyNameReference = new AssemblyNameReference();
			string[] array = fullName.Split(new char[1] { ',' });
			for (int i = 0; i < array.Length; i++)
			{
				string text = array[i].Trim();
				if (i == 0)
				{
					assemblyNameReference.Name = text;
					continue;
				}
				string[] array2 = text.Split(new char[1] { '=' });
				if (array2.Length != 2)
				{
					throw new ArgumentException("Malformed name");
				}
				switch (array2[0].ToLowerInvariant())
				{
				case "version":
					assemblyNameReference.Version = new Version(array2[1]);
					break;
				case "culture":
					assemblyNameReference.Culture = ((array2[1] == "neutral") ? "" : array2[1]);
					break;
				case "publickeytoken":
				{
					string text2 = array2[1];
					if (!(text2 == "null"))
					{
						assemblyNameReference.PublicKeyToken = new byte[text2.Length / 2];
						for (int j = 0; j < assemblyNameReference.PublicKeyToken.Length; j++)
						{
							assemblyNameReference.PublicKeyToken[j] = byte.Parse(text2.Substring(j * 2, 2), NumberStyles.HexNumber);
						}
					}
					break;
				}
				}
			}
			return assemblyNameReference;
		}

		internal AssemblyNameReference()
		{
			version = Mixin.ZeroVersion;
			token = new MetadataToken(TokenType.AssemblyRef);
		}

		public AssemblyNameReference(string name, Version version)
		{
			Mixin.CheckName(name);
			this.name = name;
			this.version = Mixin.CheckVersion(version);
			hash_algorithm = AssemblyHashAlgorithm.None;
			token = new MetadataToken(TokenType.AssemblyRef);
		}

		public override string ToString()
		{
			return FullName;
		}
	}
	internal abstract class ModuleReader
	{
		protected readonly ModuleDefinition module;

		protected ModuleReader(Image image, ReadingMode mode)
		{
			module = new ModuleDefinition(image);
			module.ReadingMode = mode;
		}

		protected abstract void ReadModule();

		public abstract void ReadSymbols(ModuleDefinition module);

		protected void ReadModuleManifest(MetadataReader reader)
		{
			reader.Populate(module);
			ReadAssembly(reader);
		}

		private void ReadAssembly(MetadataReader reader)
		{
			AssemblyNameDefinition assemblyNameDefinition = reader.ReadAssemblyNameDefinition();
			if (assemblyNameDefinition == null)
			{
				module.kind = ModuleKind.NetModule;
				return;
			}
			AssemblyDefinition assemblyDefinition = new AssemblyDefinition();
			assemblyDefinition.Name = assemblyNameDefinition;
			module.assembly = assemblyDefinition;
			assemblyDefinition.main_module = module;
		}

		public static ModuleDefinition CreateModule(Image image, ReaderParameters parameters)
		{
			ModuleReader moduleReader = CreateModuleReader(image, parameters.ReadingMode);
			ModuleDefinition moduleDefinition = moduleReader.module;
			if (parameters.assembly_resolver != null)
			{
				moduleDefinition.assembly_resolver = Disposable.NotOwned(parameters.assembly_resolver);
			}
			if (parameters.metadata_resolver != null)
			{
				moduleDefinition.metadata_resolver = parameters.metadata_resolver;
			}
			if (parameters.metadata_importer_provider != null)
			{
				moduleDefinition.metadata_importer = parameters.metadata_importer_provider.GetMetadataImporter(moduleDefinition);
			}
			if (parameters.reflection_importer_provider != null)
			{
				moduleDefinition.reflection_importer = parameters.reflection_importer_provider.GetReflectionImporter(moduleDefinition);
			}
			GetMetadataKind(moduleDefinition, parameters);
			moduleReader.ReadModule();
			ReadSymbols(moduleDefinition, parameters);
			moduleReader.ReadSymbols(moduleDefinition);
			if (parameters.ReadingMode == ReadingMode.Immediate)
			{
				moduleDefinition.MetadataSystem.Clear();
			}
			return moduleDefinition;
		}

		private static void ReadSymbols(ModuleDefinition module, ReaderParameters parameters)
		{
			ISymbolReaderProvider symbolReaderProvider = parameters.SymbolReaderProvider;
			if (symbolReaderProvider == null && parameters.ReadSymbols)
			{
				symbolReaderProvider = new DefaultSymbolReaderProvider();
			}
			if (symbolReaderProvider != null)
			{
				module.SymbolReaderProvider = symbolReaderProvider;
				ISymbolReader symbolReader = ((parameters.SymbolStream != null) ? symbolReaderProvider.GetSymbolReader(module, parameters.SymbolStream) : symbolReaderProvider.GetSymbolReader(module, module.FileName));
				if (symbolReader != null)
				{
					try
					{
						module.ReadSymbols(symbolReader, parameters.ThrowIfSymbolsAreNotMatching);
					}
					catch (Exception)
					{
						symbolReader.Dispose();
						throw;
					}
				}
			}
			if (module.Image.HasDebugTables())
			{
				module.ReadSymbols(new PortablePdbReader(module.Image, module));
			}
		}

		private static void GetMetadataKind(ModuleDefinition module, ReaderParameters parameters)
		{
			if (!parameters.ApplyWindowsRuntimeProjections)
			{
				module.MetadataKind = MetadataKind.Ecma335;
				return;
			}
			string runtimeVersion = module.RuntimeVersion;
			if (!runtimeVersion.Contains("WindowsRuntime"))
			{
				module.MetadataKind = MetadataKind.Ecma335;
			}
			else if (runtimeVersion.Contains("CLR"))
			{
				module.MetadataKind = MetadataKind.ManagedWindowsMetadata;
			}
			else
			{
				module.MetadataKind = MetadataKind.WindowsMetadata;
			}
		}

		private static ModuleReader CreateModuleReader(Image image, ReadingMode mode)
		{
			return mode switch
			{
				ReadingMode.Immediate => new ImmediateModuleReader(image), 
				ReadingMode.Deferred => new DeferredModuleReader(image), 
				_ => throw new ArgumentException(), 
			};
		}
	}
	internal sealed class ImmediateModuleReader : ModuleReader
	{
		private bool resolve_attributes;

		public ImmediateModuleReader(Image image)
			: base(image, ReadingMode.Immediate)
		{
		}

		protected override void ReadModule()
		{
			module.Read(module, delegate(ModuleDefinition module, MetadataReader reader)
			{
				ReadModuleManifest(reader);
				ReadModule(module, resolve_attributes: true);
			});
		}

		public void ReadModule(ModuleDefinition module, bool resolve_attributes)
		{
			this.resolve_attributes = resolve_attributes;
			if (module.HasAssemblyReferences)
			{
				Mixin.Read(module.AssemblyReferences);
			}
			if (module.HasResources)
			{
				Mixin.Read(module.Resources);
			}
			if (module.HasModuleReferences)
			{
				Mixin.Read(module.ModuleReferences);
			}
			if (module.HasTypes)
			{
				ReadTypes(module.Types);
			}
			if (module.HasExportedTypes)
			{
				Mixin.Read(module.ExportedTypes);
			}
			ReadCustomAttributes(module);
			AssemblyDefinition assembly = module.Assembly;
			if (module.kind != ModuleKind.NetModule && assembly != null)
			{
				ReadCustomAttributes(assembly);
				ReadSecurityDeclarations(assembly);
			}
		}

		private void ReadTypes(Collection<TypeDefinition> types)
		{
			for (int i = 0; i < types.Count; i++)
			{
				ReadType(types[i]);
			}
		}

		private void ReadType(TypeDefinition type)
		{
			ReadGenericParameters(type);
			if (type.HasInterfaces)
			{
				ReadInterfaces(type);
			}
			if (type.HasNestedTypes)
			{
				ReadTypes(type.NestedTypes);
			}
			if (type.HasLayoutInfo)
			{
				Mixin.Read(type.ClassSize);
			}
			if (type.HasFields)
			{
				ReadFields(type);
			}
			if (type.HasMethods)
			{
				ReadMethods(type);
			}
			if (type.HasProperties)
			{
				ReadProperties(type);
			}
			if (type.HasEvents)
			{
				ReadEvents(type);
			}
			ReadSecurityDeclarations(type);
			ReadCustomAttributes(type);
		}

		private void ReadInterfaces(TypeDefinition type)
		{
			Collection<InterfaceImplementation> interfaces = type.Interfaces;
			for (int i = 0; i < interfaces.Count; i++)
			{
				ReadCustomAttributes(interfaces[i]);
			}
		}

		private void ReadGenericParameters(IGenericParameterProvider provider)
		{
			if (!provider.HasGenericParameters)
			{
				return;
			}
			Collection<GenericParameter> genericParameters = provider.GenericParameters;
			for (int i = 0; i < genericParameters.Count; i++)
			{
				GenericParameter genericParameter = genericParameters[i];
				if (genericParameter.HasConstraints)
				{
					ReadGenericParameterConstraints(genericParameter);
				}
				ReadCustomAttributes(genericParameter);
			}
		}

		private void ReadGenericParameterConstraints(GenericParameter parameter)
		{
			Collection<GenericParameterConstraint> constraints = parameter.Constraints;
			for (int i = 0; i < constraints.Count; i++)
			{
				ReadCustomAttributes(constraints[i]);
			}
		}

		private void ReadSecurityDeclarations(ISecurityDeclarationProvider provider)
		{
			if (!provider.HasSecurityDeclarations)
			{
				return;
			}
			Collection<SecurityDeclaration> securityDeclarations = provider.SecurityDeclarations;
			if (resolve_attributes)
			{
				for (int i = 0; i < securityDeclarations.Count; i++)
				{
					Mixin.Read(securityDeclarations[i].SecurityAttributes);
				}
			}
		}

		private void ReadCustomAttributes(ICustomAttributeProvider provider)
		{
			if (!provider.HasCustomAttributes)
			{
				return;
			}
			Collection<CustomAttribute> customAttributes = provider.CustomAttributes;
			if (resolve_attributes)
			{
				for (int i = 0; i < customAttributes.Count; i++)
				{
					Mixin.Read(customAttributes[i].ConstructorArguments);
				}
			}
		}

		private void ReadFields(TypeDefinition type)
		{
			Collection<FieldDefinition> fields = type.Fields;
			for (int i = 0; i < fields.Count; i++)
			{
				FieldDefinition fieldDefinition = fields[i];
				if (fieldDefinition.HasConstant)
				{
					Mixin.Read(fieldDefinition.Constant);
				}
				if (fieldDefinition.HasLayoutInfo)
				{
					Mixin.Read(fieldDefinition.Offset);
				}
				if (fieldDefinition.RVA > 0)
				{
					Mixin.Read(fieldDefinition.InitialValue);
				}
				if (fieldDefinition.HasMarshalInfo)
				{
					Mixin.Read(fieldDefinition.MarshalInfo);
				}
				ReadCustomAttributes(fieldDefinition);
			}
		}

		private void ReadMethods(TypeDefinition type)
		{
			Collection<MethodDefinition> methods = type.Methods;
			for (int i = 0; i < methods.Count; i++)
			{
				MethodDefinition methodDefinition = methods[i];
				ReadGenericParameters(methodDefinition);
				if (methodDefinition.HasParameters)
				{
					ReadParameters(methodDefinition);
				}
				if (methodDefinition.HasOverrides)
				{
					Mixin.Read(methodDefinition.Overrides);
				}
				if (methodDefinition.IsPInvokeImpl)
				{
					Mixin.Read(methodDefinition.PInvokeInfo);
				}
				ReadSecurityDeclarations(methodDefinition);
				ReadCustomAttributes(methodDefinition);
				MethodReturnType methodReturnType = methodDefinition.MethodReturnType;
				if (methodReturnType.HasConstant)
				{
					Mixin.Read(methodReturnType.Constant);
				}
				if (methodReturnType.HasMarshalInfo)
				{
					Mixin.Read(methodReturnType.MarshalInfo);
				}
				ReadCustomAttributes(methodReturnType);
			}
		}

		private void ReadParameters(MethodDefinition method)
		{
			Collection<ParameterDefinition> parameters = method.Parameters;
			for (int i = 0; i < parameters.Count; i++)
			{
				ParameterDefinition parameterDefinition = parameters[i];
				if (parameterDefinition.HasConstant)
				{
					Mixin.Read(parameterDefinition.Constant);
				}
				if (parameterDefinition.HasMarshalInfo)
				{
					Mixin.Read(parameterDefinition.MarshalInfo);
				}
				ReadCustomAttributes(parameterDefinition);
			}
		}

		private void ReadProperties(TypeDefinition type)
		{
			Collection<PropertyDefinition> properties = type.Properties;
			for (int i = 0; i < properties.Count; i++)
			{
				PropertyDefinition propertyDefinition = properties[i];
				Mixin.Read(propertyDefinition.GetMethod);
				if (propertyDefinition.HasConstant)
				{
					Mixin.Read(propertyDefinition.Constant);
				}
				ReadCustomAttributes(propertyDefinition);
			}
		}

		private void ReadEvents(TypeDefinition type)
		{
			Collection<EventDefinition> events = type.Events;
			for (int i = 0; i < events.Count; i++)
			{
				EventDefinition eventDefinition = events[i];
				Mixin.Read(eventDefinition.AddMethod);
				ReadCustomAttributes(eventDefinition);
			}
		}

		public override void ReadSymbols(ModuleDefinition module)
		{
			if (module.symbol_reader != null)
			{
				ReadTypesSymbols(module.Types, module.symbol_reader);
			}
		}

		private void ReadTypesSymbols(Collection<TypeDefinition> types, ISymbolReader symbol_reader)
		{
			for (int i = 0; i < types.Count; i++)
			{
				TypeDefinition typeDefinition = types[i];
				if (typeDefinition.HasNestedTypes)
				{
					ReadTypesSymbols(typeDefinition.NestedTypes, symbol_reader);
				}
				if (typeDefinition.HasMethods)
				{
					ReadMethodsSymbols(typeDefinition, symbol_reader);
				}
			}
		}

		private void ReadMethodsSymbols(TypeDefinition type, ISymbolReader symbol_reader)
		{
			Collection<MethodDefinition> methods = type.Methods;
			for (int i = 0; i < methods.Count; i++)
			{
				MethodDefinition methodDefinition = methods[i];
				if (methodDefinition.HasBody && methodDefinition.token.RID != 0 && methodDefinition.debug_info == null)
				{
					methodDefinition.debug_info = symbol_reader.Read(methodDefinition);
				}
			}
		}
	}
	internal sealed class DeferredModuleReader : ModuleReader
	{
		public DeferredModuleReader(Image image)
			: base(image, ReadingMode.Deferred)
		{
		}

		protected override void ReadModule()
		{
			module.Read(module, delegate(ModuleDefinition _, MetadataReader reader)
			{
				ReadModuleManifest(reader);
			});
		}

		public override void ReadSymbols(ModuleDefinition module)
		{
		}
	}
	internal sealed class MetadataReader : ByteBuffer
	{
		internal readonly Image image;

		internal readonly ModuleDefinition module;

		internal readonly MetadataSystem metadata;

		internal CodeReader code;

		internal IGenericContext context;

		private readonly MetadataReader metadata_reader;

		public MetadataReader(ModuleDefinition module)
			: base(module.Image.TableHeap.data)
		{
			image = module.Image;
			this.module = module;
			metadata = module.MetadataSystem;
			code = new CodeReader(this);
		}

		public MetadataReader(Image image, ModuleDefinition module, MetadataReader metadata_reader)
			: base(image.TableHeap.data)
		{
			this.image = image;
			this.module = module;
			metadata = module.MetadataSystem;
			this.metadata_reader = metadata_reader;
		}

		private int GetCodedIndexSize(CodedIndex index)
		{
			return image.GetCodedIndexSize(index);
		}

		private uint ReadByIndexSize(int size)
		{
			if (size == 4)
			{
				return ReadUInt32();
			}
			return ReadUInt16();
		}

		private byte[] ReadBlob()
		{
			BlobHeap blobHeap = image.BlobHeap;
			if (blobHeap == null)
			{
				position += 2;
				return Empty<byte>.Array;
			}
			return blobHeap.Read(ReadBlobIndex());
		}

		private byte[] ReadBlob(uint signature)
		{
			BlobHeap blobHeap = image.BlobHeap;
			if (blobHeap == null)
			{
				return Empty<byte>.Array;
			}
			return blobHeap.Read(signature);
		}

		private uint ReadBlobIndex()
		{
			return ReadByIndexSize(image.BlobHeap?.IndexSize ?? 2);
		}

		private void GetBlobView(uint signature, out byte[] blob, out int index, out int count)
		{
			BlobHeap blobHeap = image.BlobHeap;
			if (blobHeap == null)
			{
				blob = null;
				index = (count = 0);
			}
			else
			{
				blobHeap.GetView(signature, out blob, out index, out count);
			}
		}

		private string ReadString()
		{
			return image.StringHeap.Read(ReadByIndexSize(image.StringHeap.IndexSize));
		}

		private uint ReadStringIndex()
		{
			return ReadByIndexSize(image.StringHeap.IndexSize);
		}

		private Guid ReadGuid()
		{
			return image.GuidHeap.Read(ReadByIndexSize(image.GuidHeap.IndexSize));
		}

		private uint ReadTableIndex(Table table)
		{
			return ReadByIndexSize(image.GetTableIndexSize(table));
		}

		private MetadataToken ReadMetadataToken(CodedIndex index)
		{
			return index.GetMetadataToken(ReadByIndexSize(GetCodedIndexSize(index)));
		}

		private int MoveTo(Table table)
		{
			TableInformation tableInformation = image.TableHeap[table];
			if (tableInformation.Length != 0)
			{
				position = (int)tableInformation.Offset;
			}
			return (int)tableInformation.Length;
		}

		private bool MoveTo(Table table, uint row)
		{
			TableInformation tableInformation = image.TableHeap[table];
			uint num = tableInformation.Length;
			if (num == 0 || row > num)
			{
				return false;
			}
			position = (int)(tableInformation.Offset + tableInformation.RowSize * (row - 1));
			return true;
		}

		public AssemblyNameDefinition ReadAssemblyNameDefinition()
		{
			if (MoveTo(Table.Assembly) == 0)
			{
				return null;
			}
			AssemblyNameDefinition assemblyNameDefinition = new AssemblyNameDefinition();
			assemblyNameDefinition.HashAlgorithm = (AssemblyHashAlgorithm)ReadUInt32();
			PopulateVersionAndFlags(assemblyNameDefinition);
			assemblyNameDefinition.PublicKey = ReadBlob();
			PopulateNameAndCulture(assemblyNameDefinition);
			return assemblyNameDefinition;
		}

		public ModuleDefinition Populate(ModuleDefinition module)
		{
			if (MoveTo(Table.Module) == 0)
			{
				return module;
			}
			Advance(2);
			module.Name = ReadString();
			module.Mvid = ReadGuid();
			return module;
		}

		private void InitializeAssemblyReferences()
		{
			if (metadata.AssemblyReferences != null)
			{
				return;
			}
			int num = MoveTo(Table.AssemblyRef);
			AssemblyNameReference[] array = (metadata.AssemblyReferences = new AssemblyNameReference[num]);
			for (uint num2 = 0u; num2 < num; num2++)
			{
				AssemblyNameReference assemblyNameReference = new AssemblyNameReference();
				assemblyNameReference.token = new MetadataToken(TokenType.AssemblyRef, num2 + 1);
				PopulateVersionAndFlags(assemblyNameReference);
				byte[] array2 = ReadBlob();
				if (assemblyNameReference.HasPublicKey)
				{
					assemblyNameReference.PublicKey = array2;
				}
				else
				{
					assemblyNameReference.PublicKeyToken = array2;
				}
				PopulateNameAndCulture(assemblyNameReference);
				assemblyNameReference.Hash = ReadBlob();
				array[num2] = assemblyNameReference;
			}
		}

		public Collection<AssemblyNameReference> ReadAssemblyReferences()
		{
			InitializeAssemblyReferences();
			Collection<AssemblyNameReference> collection = new Collection<AssemblyNameReference>(metadata.AssemblyReferences);
			if (module.IsWindowsMetadata())
			{
				module.Projections.AddVirtualReferences(collection);
			}
			return collection;
		}

		public MethodDefinition ReadEntryPoint()
		{
			if (module.Image.EntryPointToken == 0)
			{
				return null;
			}
			return GetMethodDefinition(new MetadataToken(module.Image.EntryPointToken).RID);
		}

		public Collection<ModuleDefinition> ReadModules()
		{
			Collection<ModuleDefinition> collection = new Collection<ModuleDefinition>(1);
			collection.Add(module);
			int num = MoveTo(Table.File);
			for (uint num2 = 1u; num2 <= num; num2++)
			{
				uint num3 = ReadUInt32();
				string name = ReadString();
				ReadBlobIndex();
				if (num3 == 0)
				{
					ReaderParameters parameters = new ReaderParameters
					{
						ReadingMode = module.ReadingMode,
						SymbolReaderProvider = module.SymbolReaderProvider,
						AssemblyResolver = module.AssemblyResolver
					};
					ModuleDefinition moduleDefinition = ModuleDefinition.ReadModule(GetModuleFileName(name), parameters);
					moduleDefinition.assembly = module.assembly;
					collection.Add(moduleDefinition);
				}
			}
			return collection;
		}

		private string GetModuleFileName(string name)
		{
			if (module.FileName == null)
			{
				throw new NotSupportedException();
			}
			return Path.Combine(Path.GetDirectoryName(module.FileName), name);
		}

		private void InitializeModuleReferences()
		{
			if (metadata.ModuleReferences == null)
			{
				int num = MoveTo(Table.ModuleRef);
				ModuleReference[] array = (metadata.ModuleReferences = new ModuleReference[num]);
				for (uint num2 = 0u; num2 < num; num2++)
				{
					ModuleReference moduleReference = new ModuleReference(ReadString());
					moduleReference.token = new MetadataToken(TokenType.ModuleRef, num2 + 1);
					array[num2] = moduleReference;
				}
			}
		}

		public Collection<ModuleReference> ReadModuleReferences()
		{
			InitializeModuleReferences();
			return new Collection<ModuleReference>(metadata.ModuleReferences);
		}

		public bool HasFileResource()
		{
			int num = MoveTo(Table.File);
			if (num == 0)
			{
				return false;
			}
			for (uint num2 = 1u; num2 <= num; num2++)
			{
				if (ReadFileRecord(num2).Col1 == FileAttributes.ContainsNoMetaData)
				{
					return true;
				}
			}
			return false;
		}

		public Collection<Resource> ReadResources()
		{
			int num = MoveTo(Table.ManifestResource);
			Collection<Resource> collection = new Collection<Resource>(num);
			for (int i = 1; i <= num; i++)
			{
				uint offset = ReadUInt32();
				ManifestResourceAttributes manifestResourceAttributes = (ManifestResourceAttributes)ReadUInt32();
				string name = ReadString();
				MetadataToken scope = ReadMetadataToken(CodedIndex.Implementation);
				Resource item;
				if (scope.RID == 0)
				{
					item = new EmbeddedResource(name, manifestResourceAttributes, offset, this);
				}
				else if (scope.TokenType == TokenType.AssemblyRef)
				{
					item = new AssemblyLinkedResource(name, manifestResourceAttributes)
					{
						Assembly = (AssemblyNameReference)GetTypeReferenceScope(scope)
					};
				}
				else
				{
					if (scope.TokenType != TokenType.File)
					{
						continue;
					}
					Row<FileAttributes, string, uint> row = ReadFileRecord(scope.RID);
					item = new LinkedResource(name, manifestResourceAttributes)
					{
						File = row.Col2,
						hash = ReadBlob(row.Col3)
					};
				}
				collection.Add(item);
			}
			return collection;
		}

		private Row<FileAttributes, string, uint> ReadFileRecord(uint rid)
		{
			int num = position;
			if (!MoveTo(Table.File, rid))
			{
				throw new ArgumentException();
			}
			Row<FileAttributes, string, uint> result = new Row<FileAttributes, string, uint>((FileAttributes)ReadUInt32(), ReadString(), ReadBlobIndex());
			position = num;
			return result;
		}

		public byte[] GetManagedResource(uint offset)
		{
			return image.GetReaderAt(image.Resources.VirtualAddress, offset, delegate(uint o, BinaryStreamReader reader)
			{
				reader.Advance((int)o);
				return reader.ReadBytes(reader.ReadInt32());
			}) ?? Empty<byte>.Array;
		}

		private void PopulateVersionAndFlags(AssemblyNameReference name)
		{
			name.Version = new Version(ReadUInt16(), ReadUInt16(), ReadUInt16(), ReadUInt16());
			name.Attributes = (AssemblyAttributes)ReadUInt32();
		}

		private void PopulateNameAndCulture(AssemblyNameReference name)
		{
			name.Name = ReadString();
			name.Culture = ReadString();
		}

		public TypeDefinitionCollection ReadTypes()
		{
			InitializeTypeDefinitions();
			TypeDefinition[] types = metadata.Types;
			int capacity = types.Length - metadata.NestedTypes.Count;
			TypeDefinitionCollection typeDefinitionCollection = new TypeDefinitionCollection(module, capacity);
			foreach (TypeDefinition typeDefinition in types)
			{
				if (!IsNested(typeDefinition.Attributes))
				{
					typeDefinitionCollection.Add(typeDefinition);
				}
			}
			if (image.HasTable(Table.MethodPtr) || image.HasTable(Table.FieldPtr))
			{
				CompleteTypes();
			}
			return typeDefinitionCollection;
		}

		private void CompleteTypes()
		{
			TypeDefinition[] types = metadata.Types;
			foreach (TypeDefinition obj in types)
			{
				Mixin.Read(obj.Fields);
				Mixin.Read(obj.Methods);
			}
		}

		private void InitializeTypeDefinitions()
		{
			if (metadata.Types != null)
			{
				return;
			}
			InitializeNestedTypes();
			InitializeFields();
			InitializeMethods();
			int num = MoveTo(Table.TypeDef);
			TypeDefinition[] array = (metadata.Types = new TypeDefinition[num]);
			for (uint num2 = 0u; num2 < num; num2++)
			{
				if (array[num2] == null)
				{
					array[num2] = ReadType(num2 + 1);
				}
			}
			if (module.IsWindowsMetadata())
			{
				for (uint num3 = 0u; num3 < num; num3++)
				{
					WindowsRuntimeProjections.Project(array[num3]);
				}
			}
		}

		private static bool IsNested(TypeAttributes attributes)
		{
			TypeAttributes typeAttributes = attributes & TypeAttributes.VisibilityMask;
			if (typeAttributes - 2 <= TypeAttributes.NestedAssembly)
			{
				return true;
			}
			return false;
		}

		public bool HasNestedTypes(TypeDefinition type)
		{
			InitializeNestedTypes();
			if (!metadata.TryGetNestedTypeMapping(type, out var mapping))
			{
				return false;
			}
			return mapping.Count > 0;
		}

		public Collection<TypeDefinition> ReadNestedTypes(TypeDefinition type)
		{
			InitializeNestedTypes();
			if (!metadata.TryGetNestedTypeMapping(type, out var mapping))
			{
				return new MemberDefinitionCollection<TypeDefinition>(type);
			}
			MemberDefinitionCollection<TypeDefinition> memberDefinitionCollection = new MemberDefinitionCollection<TypeDefinition>(type, mapping.Count);
			for (int i = 0; i < mapping.Count; i++)
			{
				TypeDefinition typeDefinition = GetTypeDefinition(mapping[i]);
				if (typeDefinition != null)
				{
					memberDefinitionCollection.Add(typeDefinition);
				}
			}
			metadata.RemoveNestedTypeMapping(type);
			return memberDefinitionCollection;
		}

		private void InitializeNestedTypes()
		{
			if (metadata.NestedTypes != null)
			{
				return;
			}
			int num = MoveTo(Table.NestedClass);
			metadata.NestedTypes = new Dictionary<uint, Collection<uint>>(num);
			metadata.ReverseNestedTypes = new Dictionary<uint, uint>(num);
			if (num != 0)
			{
				for (int i = 1; i <= num; i++)
				{
					uint nested = ReadTableIndex(Table.TypeDef);
					uint declaring = ReadTableIndex(Table.TypeDef);
					AddNestedMapping(declaring, nested);
				}
			}
		}

		private void AddNestedMapping(uint declaring, uint nested)
		{
			metadata.SetNestedTypeMapping(declaring, AddMapping(metadata.NestedTypes, declaring, nested));
			metadata.SetReverseNestedTypeMapping(nested, declaring);
		}

		private static Collection<TValue> AddMapping<TKey, TValue>(Dictionary<TKey, Collection<TValue>> cache, TKey key, TValue value)
		{
			if (!cache.TryGetValue(key, out var value2))
			{
				value2 = new Collection<TValue>();
			}
			value2.Add(value);
			return value2;
		}

		private TypeDefinition ReadType(uint rid)
		{
			if (!MoveTo(Table.TypeDef, rid))
			{
				return null;
			}
			TypeAttributes attributes = (TypeAttributes)ReadUInt32();
			string name = ReadString();
			TypeDefinition typeDefinition = new TypeDefinition(ReadString(), name, attributes);
			typeDefinition.token = new MetadataToken(TokenType.TypeDef, rid);
			typeDefinition.scope = module;
			typeDefinition.module = module;
			metadata.AddTypeDefinition(typeDefinition);
			context = typeDefinition;
			typeDefinition.BaseType = GetTypeDefOrRef(ReadMetadataToken(CodedIndex.TypeDefOrRef));
			typeDefinition.fields_range = ReadListRange(rid, Table.TypeDef, Table.Field);
			typeDefinition.methods_range = ReadListRange(rid, Table.TypeDef, Table.Method);
			if (IsNested(attributes))
			{
				typeDefinition.DeclaringType = GetNestedTypeDeclaringType(typeDefinition);
			}
			return typeDefinition;
		}

		private TypeDefinition GetNestedTypeDeclaringType(TypeDefinition type)
		{
			if (!metadata.TryGetReverseNestedTypeMapping(type, out var declaring))
			{
				return null;
			}
			metadata.RemoveReverseNestedTypeMapping(type);
			return GetTypeDefinition(declaring);
		}

		private Range ReadListRange(uint current_index, Table current, Table target)
		{
			Range result = default(Range);
			uint num = ReadTableIndex(target);
	

BepInExPack/BepInEx/core/Mono.Cecil.Mdb.dll

Decompiled a month ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security.Cryptography;
using Mono.Cecil.Cil;
using Mono.Collections.Generic;
using Mono.CompilerServices.SymbolWriter;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyProduct("Mono.Cecil")]
[assembly: AssemblyCopyright("Copyright © 2008 - 2018 Jb Evain")]
[assembly: ComVisible(false)]
[assembly: AssemblyFileVersion("0.11.4.0")]
[assembly: AssemblyInformationalVersion("0.11.4.0")]
[assembly: AssemblyTitle("Mono.Cecil.Mdb")]
[assembly: CLSCompliant(false)]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = "")]
[assembly: AssemblyVersion("0.11.4.0")]
namespace Mono.CompilerServices.SymbolWriter
{
	public class MonoSymbolFileException : Exception
	{
		public MonoSymbolFileException()
		{
		}

		public MonoSymbolFileException(string message, params object[] args)
			: base(string.Format(message, args))
		{
		}

		public MonoSymbolFileException(string message, Exception innerException)
			: base(message, innerException)
		{
		}
	}
	internal sealed class MyBinaryWriter : BinaryWriter
	{
		public MyBinaryWriter(Stream stream)
			: base(stream)
		{
		}

		public void WriteLeb128(int value)
		{
			Write7BitEncodedInt(value);
		}
	}
	internal class MyBinaryReader : BinaryReader
	{
		public MyBinaryReader(Stream stream)
			: base(stream)
		{
		}

		public int ReadLeb128()
		{
			return Read7BitEncodedInt();
		}

		public string ReadString(int offset)
		{
			long position = BaseStream.Position;
			BaseStream.Position = offset;
			string result = ReadString();
			BaseStream.Position = position;
			return result;
		}
	}
	public interface ISourceFile
	{
		SourceFileEntry Entry { get; }
	}
	public interface ICompileUnit
	{
		CompileUnitEntry Entry { get; }
	}
	public interface IMethodDef
	{
		string Name { get; }

		int Token { get; }
	}
	public class MonoSymbolFile : IDisposable
	{
		private List<MethodEntry> methods = new List<MethodEntry>();

		private List<SourceFileEntry> sources = new List<SourceFileEntry>();

		private List<CompileUnitEntry> comp_units = new List<CompileUnitEntry>();

		private Dictionary<int, AnonymousScopeEntry> anonymous_scopes;

		private OffsetTable ot;

		private int last_type_index;

		private int last_method_index;

		private int last_namespace_index;

		public readonly int MajorVersion = 50;

		public readonly int MinorVersion;

		public int NumLineNumbers;

		private MyBinaryReader reader;

		private Dictionary<int, SourceFileEntry> source_file_hash;

		private Dictionary<int, CompileUnitEntry> compile_unit_hash;

		private List<MethodEntry> method_list;

		private Dictionary<int, MethodEntry> method_token_hash;

		private Dictionary<string, int> source_name_hash;

		private Guid guid;

		internal int LineNumberCount;

		internal int LocalCount;

		internal int StringSize;

		internal int LineNumberSize;

		internal int ExtendedLineNumberSize;

		public int CompileUnitCount => ot.CompileUnitCount;

		public int SourceCount => ot.SourceCount;

		public int MethodCount => ot.MethodCount;

		public int TypeCount => ot.TypeCount;

		public int AnonymousScopeCount => ot.AnonymousScopeCount;

		public int NamespaceCount => last_namespace_index;

		public Guid Guid => guid;

		public OffsetTable OffsetTable => ot;

		public SourceFileEntry[] Sources
		{
			get
			{
				if (reader == null)
				{
					throw new InvalidOperationException();
				}
				SourceFileEntry[] array = new SourceFileEntry[SourceCount];
				for (int i = 0; i < SourceCount; i++)
				{
					array[i] = GetSourceFile(i + 1);
				}
				return array;
			}
		}

		public CompileUnitEntry[] CompileUnits
		{
			get
			{
				if (reader == null)
				{
					throw new InvalidOperationException();
				}
				CompileUnitEntry[] array = new CompileUnitEntry[CompileUnitCount];
				for (int i = 0; i < CompileUnitCount; i++)
				{
					array[i] = GetCompileUnit(i + 1);
				}
				return array;
			}
		}

		public MethodEntry[] Methods
		{
			get
			{
				if (reader == null)
				{
					throw new InvalidOperationException();
				}
				lock (this)
				{
					read_methods();
					MethodEntry[] array = new MethodEntry[MethodCount];
					method_list.CopyTo(array, 0);
					return array;
				}
			}
		}

		internal MyBinaryReader BinaryReader
		{
			get
			{
				if (reader == null)
				{
					throw new InvalidOperationException();
				}
				return reader;
			}
		}

		public MonoSymbolFile()
		{
			ot = new OffsetTable();
		}

		public int AddSource(SourceFileEntry source)
		{
			sources.Add(source);
			return sources.Count;
		}

		public int AddCompileUnit(CompileUnitEntry entry)
		{
			comp_units.Add(entry);
			return comp_units.Count;
		}

		public void AddMethod(MethodEntry entry)
		{
			methods.Add(entry);
		}

		public MethodEntry DefineMethod(CompileUnitEntry comp_unit, int token, ScopeVariable[] scope_vars, LocalVariableEntry[] locals, LineNumberEntry[] lines, CodeBlockEntry[] code_blocks, string real_name, MethodEntry.Flags flags, int namespace_id)
		{
			if (reader != null)
			{
				throw new InvalidOperationException();
			}
			MethodEntry methodEntry = new MethodEntry(this, comp_unit, token, scope_vars, locals, lines, code_blocks, real_name, flags, namespace_id);
			AddMethod(methodEntry);
			return methodEntry;
		}

		internal void DefineAnonymousScope(int id)
		{
			if (reader != null)
			{
				throw new InvalidOperationException();
			}
			if (anonymous_scopes == null)
			{
				anonymous_scopes = new Dictionary<int, AnonymousScopeEntry>();
			}
			anonymous_scopes.Add(id, new AnonymousScopeEntry(id));
		}

		internal void DefineCapturedVariable(int scope_id, string name, string captured_name, CapturedVariable.CapturedKind kind)
		{
			if (reader != null)
			{
				throw new InvalidOperationException();
			}
			anonymous_scopes[scope_id].AddCapturedVariable(name, captured_name, kind);
		}

		internal void DefineCapturedScope(int scope_id, int id, string captured_name)
		{
			if (reader != null)
			{
				throw new InvalidOperationException();
			}
			anonymous_scopes[scope_id].AddCapturedScope(id, captured_name);
		}

		internal int GetNextTypeIndex()
		{
			return ++last_type_index;
		}

		internal int GetNextMethodIndex()
		{
			return ++last_method_index;
		}

		internal int GetNextNamespaceIndex()
		{
			return ++last_namespace_index;
		}

		private void Write(MyBinaryWriter bw, Guid guid)
		{
			bw.Write(5037318119232611860L);
			bw.Write(MajorVersion);
			bw.Write(MinorVersion);
			bw.Write(guid.ToByteArray());
			long position = bw.BaseStream.Position;
			ot.Write(bw, MajorVersion, MinorVersion);
			methods.Sort();
			for (int i = 0; i < methods.Count; i++)
			{
				methods[i].Index = i + 1;
			}
			ot.DataSectionOffset = (int)bw.BaseStream.Position;
			foreach (SourceFileEntry source in sources)
			{
				source.WriteData(bw);
			}
			foreach (CompileUnitEntry comp_unit in comp_units)
			{
				comp_unit.WriteData(bw);
			}
			foreach (MethodEntry method in methods)
			{
				method.WriteData(this, bw);
			}
			ot.DataSectionSize = (int)bw.BaseStream.Position - ot.DataSectionOffset;
			ot.MethodTableOffset = (int)bw.BaseStream.Position;
			for (int j = 0; j < methods.Count; j++)
			{
				methods[j].Write(bw);
			}
			ot.MethodTableSize = (int)bw.BaseStream.Position - ot.MethodTableOffset;
			ot.SourceTableOffset = (int)bw.BaseStream.Position;
			for (int k = 0; k < sources.Count; k++)
			{
				sources[k].Write(bw);
			}
			ot.SourceTableSize = (int)bw.BaseStream.Position - ot.SourceTableOffset;
			ot.CompileUnitTableOffset = (int)bw.BaseStream.Position;
			for (int l = 0; l < comp_units.Count; l++)
			{
				comp_units[l].Write(bw);
			}
			ot.CompileUnitTableSize = (int)bw.BaseStream.Position - ot.CompileUnitTableOffset;
			ot.AnonymousScopeCount = ((anonymous_scopes != null) ? anonymous_scopes.Count : 0);
			ot.AnonymousScopeTableOffset = (int)bw.BaseStream.Position;
			if (anonymous_scopes != null)
			{
				foreach (AnonymousScopeEntry value in anonymous_scopes.Values)
				{
					value.Write(bw);
				}
			}
			ot.AnonymousScopeTableSize = (int)bw.BaseStream.Position - ot.AnonymousScopeTableOffset;
			ot.TypeCount = last_type_index;
			ot.MethodCount = methods.Count;
			ot.SourceCount = sources.Count;
			ot.CompileUnitCount = comp_units.Count;
			ot.TotalFileSize = (int)bw.BaseStream.Position;
			bw.Seek((int)position, SeekOrigin.Begin);
			ot.Write(bw, MajorVersion, MinorVersion);
			bw.Seek(0, SeekOrigin.End);
		}

		public void CreateSymbolFile(Guid guid, FileStream fs)
		{
			if (reader != null)
			{
				throw new InvalidOperationException();
			}
			Write(new MyBinaryWriter(fs), guid);
		}

		private MonoSymbolFile(Stream stream)
		{
			reader = new MyBinaryReader(stream);
			try
			{
				long num = reader.ReadInt64();
				int num2 = reader.ReadInt32();
				int num3 = reader.ReadInt32();
				if (num != 5037318119232611860L)
				{
					throw new MonoSymbolFileException("Symbol file is not a valid");
				}
				if (num2 != 50)
				{
					throw new MonoSymbolFileException("Symbol file has version {0} but expected {1}", num2, 50);
				}
				if (num3 != 0)
				{
					throw new MonoSymbolFileException("Symbol file has version {0}.{1} but expected {2}.{3}", num2, num3, 50, 0);
				}
				MajorVersion = num2;
				MinorVersion = num3;
				guid = new Guid(reader.ReadBytes(16));
				ot = new OffsetTable(reader, num2, num3);
			}
			catch (Exception innerException)
			{
				throw new MonoSymbolFileException("Cannot read symbol file", innerException);
			}
			source_file_hash = new Dictionary<int, SourceFileEntry>();
			compile_unit_hash = new Dictionary<int, CompileUnitEntry>();
		}

		public static MonoSymbolFile ReadSymbolFile(string mdbFilename)
		{
			return ReadSymbolFile(new FileStream(mdbFilename, FileMode.Open, FileAccess.Read));
		}

		public static MonoSymbolFile ReadSymbolFile(string mdbFilename, Guid assemblyGuid)
		{
			MonoSymbolFile monoSymbolFile = ReadSymbolFile(mdbFilename);
			if (assemblyGuid != monoSymbolFile.guid)
			{
				throw new MonoSymbolFileException("Symbol file `{0}' does not match assembly", mdbFilename);
			}
			return monoSymbolFile;
		}

		public static MonoSymbolFile ReadSymbolFile(Stream stream)
		{
			return new MonoSymbolFile(stream);
		}

		public SourceFileEntry GetSourceFile(int index)
		{
			if (index < 1 || index > ot.SourceCount)
			{
				throw new ArgumentException();
			}
			if (reader == null)
			{
				throw new InvalidOperationException();
			}
			lock (this)
			{
				if (source_file_hash.TryGetValue(index, out var value))
				{
					return value;
				}
				long position = reader.BaseStream.Position;
				reader.BaseStream.Position = ot.SourceTableOffset + SourceFileEntry.Size * (index - 1);
				value = new SourceFileEntry(this, reader);
				source_file_hash.Add(index, value);
				reader.BaseStream.Position = position;
				return value;
			}
		}

		public CompileUnitEntry GetCompileUnit(int index)
		{
			if (index < 1 || index > ot.CompileUnitCount)
			{
				throw new ArgumentException();
			}
			if (reader == null)
			{
				throw new InvalidOperationException();
			}
			lock (this)
			{
				if (compile_unit_hash.TryGetValue(index, out var value))
				{
					return value;
				}
				long position = reader.BaseStream.Position;
				reader.BaseStream.Position = ot.CompileUnitTableOffset + CompileUnitEntry.Size * (index - 1);
				value = new CompileUnitEntry(this, reader);
				compile_unit_hash.Add(index, value);
				reader.BaseStream.Position = position;
				return value;
			}
		}

		private void read_methods()
		{
			lock (this)
			{
				if (method_token_hash == null)
				{
					method_token_hash = new Dictionary<int, MethodEntry>();
					method_list = new List<MethodEntry>();
					long position = reader.BaseStream.Position;
					reader.BaseStream.Position = ot.MethodTableOffset;
					for (int i = 0; i < MethodCount; i++)
					{
						MethodEntry methodEntry = new MethodEntry(this, reader, i + 1);
						method_token_hash.Add(methodEntry.Token, methodEntry);
						method_list.Add(methodEntry);
					}
					reader.BaseStream.Position = position;
				}
			}
		}

		public MethodEntry GetMethodByToken(int token)
		{
			if (reader == null)
			{
				throw new InvalidOperationException();
			}
			lock (this)
			{
				read_methods();
				method_token_hash.TryGetValue(token, out var value);
				return value;
			}
		}

		public MethodEntry GetMethod(int index)
		{
			if (index < 1 || index > ot.MethodCount)
			{
				throw new ArgumentException();
			}
			if (reader == null)
			{
				throw new InvalidOperationException();
			}
			lock (this)
			{
				read_methods();
				return method_list[index - 1];
			}
		}

		public int FindSource(string file_name)
		{
			if (reader == null)
			{
				throw new InvalidOperationException();
			}
			lock (this)
			{
				if (source_name_hash == null)
				{
					source_name_hash = new Dictionary<string, int>();
					for (int i = 0; i < ot.SourceCount; i++)
					{
						SourceFileEntry sourceFile = GetSourceFile(i + 1);
						source_name_hash.Add(sourceFile.FileName, i);
					}
				}
				if (!source_name_hash.TryGetValue(file_name, out var value))
				{
					return -1;
				}
				return value;
			}
		}

		public AnonymousScopeEntry GetAnonymousScope(int id)
		{
			if (reader == null)
			{
				throw new InvalidOperationException();
			}
			lock (this)
			{
				if (anonymous_scopes != null)
				{
					anonymous_scopes.TryGetValue(id, out var value);
					return value;
				}
				anonymous_scopes = new Dictionary<int, AnonymousScopeEntry>();
				reader.BaseStream.Position = ot.AnonymousScopeTableOffset;
				for (int i = 0; i < ot.AnonymousScopeCount; i++)
				{
					AnonymousScopeEntry value = new AnonymousScopeEntry(reader);
					anonymous_scopes.Add(value.ID, value);
				}
				return anonymous_scopes[id];
			}
		}

		public void Dispose()
		{
			Dispose(disposing: true);
		}

		protected virtual void Dispose(bool disposing)
		{
			if (disposing && reader != null)
			{
				reader.Dispose();
				reader = null;
			}
		}
	}
	public class OffsetTable
	{
		[Flags]
		public enum Flags
		{
			IsAspxSource = 1,
			WindowsFileNames = 2
		}

		public const int MajorVersion = 50;

		public const int MinorVersion = 0;

		public const long Magic = 5037318119232611860L;

		public int TotalFileSize;

		public int DataSectionOffset;

		public int DataSectionSize;

		public int CompileUnitCount;

		public int CompileUnitTableOffset;

		public int CompileUnitTableSize;

		public int SourceCount;

		public int SourceTableOffset;

		public int SourceTableSize;

		public int MethodCount;

		public int MethodTableOffset;

		public int MethodTableSize;

		public int TypeCount;

		public int AnonymousScopeCount;

		public int AnonymousScopeTableOffset;

		public int AnonymousScopeTableSize;

		public Flags FileFlags;

		public int LineNumberTable_LineBase = -1;

		public int LineNumberTable_LineRange = 8;

		public int LineNumberTable_OpcodeBase = 9;

		internal OffsetTable()
		{
		}

		internal OffsetTable(BinaryReader reader, int major_version, int minor_version)
		{
			TotalFileSize = reader.ReadInt32();
			DataSectionOffset = reader.ReadInt32();
			DataSectionSize = reader.ReadInt32();
			CompileUnitCount = reader.ReadInt32();
			CompileUnitTableOffset = reader.ReadInt32();
			CompileUnitTableSize = reader.ReadInt32();
			SourceCount = reader.ReadInt32();
			SourceTableOffset = reader.ReadInt32();
			SourceTableSize = reader.ReadInt32();
			MethodCount = reader.ReadInt32();
			MethodTableOffset = reader.ReadInt32();
			MethodTableSize = reader.ReadInt32();
			TypeCount = reader.ReadInt32();
			AnonymousScopeCount = reader.ReadInt32();
			AnonymousScopeTableOffset = reader.ReadInt32();
			AnonymousScopeTableSize = reader.ReadInt32();
			LineNumberTable_LineBase = reader.ReadInt32();
			LineNumberTable_LineRange = reader.ReadInt32();
			LineNumberTable_OpcodeBase = reader.ReadInt32();
			FileFlags = (Flags)reader.ReadInt32();
		}

		internal void Write(BinaryWriter bw, int major_version, int minor_version)
		{
			bw.Write(TotalFileSize);
			bw.Write(DataSectionOffset);
			bw.Write(DataSectionSize);
			bw.Write(CompileUnitCount);
			bw.Write(CompileUnitTableOffset);
			bw.Write(CompileUnitTableSize);
			bw.Write(SourceCount);
			bw.Write(SourceTableOffset);
			bw.Write(SourceTableSize);
			bw.Write(MethodCount);
			bw.Write(MethodTableOffset);
			bw.Write(MethodTableSize);
			bw.Write(TypeCount);
			bw.Write(AnonymousScopeCount);
			bw.Write(AnonymousScopeTableOffset);
			bw.Write(AnonymousScopeTableSize);
			bw.Write(LineNumberTable_LineBase);
			bw.Write(LineNumberTable_LineRange);
			bw.Write(LineNumberTable_OpcodeBase);
			bw.Write((int)FileFlags);
		}

		public override string ToString()
		{
			return $"OffsetTable [{TotalFileSize} - {DataSectionOffset}:{DataSectionSize} - {SourceCount}:{SourceTableOffset}:{SourceTableSize} - {MethodCount}:{MethodTableOffset}:{MethodTableSize} - {TypeCount}]";
		}
	}
	public class LineNumberEntry
	{
		public sealed class LocationComparer : IComparer<LineNumberEntry>
		{
			public static readonly LocationComparer Default = new LocationComparer();

			public int Compare(LineNumberEntry l1, LineNumberEntry l2)
			{
				if (l1.Row != l2.Row)
				{
					int row = l1.Row;
					return row.CompareTo(l2.Row);
				}
				return l1.Column.CompareTo(l2.Column);
			}
		}

		public readonly int Row;

		public int Column;

		public int EndRow;

		public int EndColumn;

		public readonly int File;

		public readonly int Offset;

		public readonly bool IsHidden;

		public static readonly LineNumberEntry Null = new LineNumberEntry(0, 0, 0, 0);

		public LineNumberEntry(int file, int row, int column, int offset)
			: this(file, row, column, offset, is_hidden: false)
		{
		}

		public LineNumberEntry(int file, int row, int offset)
			: this(file, row, -1, offset, is_hidden: false)
		{
		}

		public LineNumberEntry(int file, int row, int column, int offset, bool is_hidden)
			: this(file, row, column, -1, -1, offset, is_hidden)
		{
		}

		public LineNumberEntry(int file, int row, int column, int end_row, int end_column, int offset, bool is_hidden)
		{
			File = file;
			Row = row;
			Column = column;
			EndRow = end_row;
			EndColumn = end_column;
			Offset = offset;
			IsHidden = is_hidden;
		}

		public override string ToString()
		{
			return $"[Line {File}:{Row},{Column}-{EndRow},{EndColumn}:{Offset}]";
		}
	}
	public class CodeBlockEntry
	{
		public enum Type
		{
			Lexical = 1,
			CompilerGenerated,
			IteratorBody,
			IteratorDispatcher
		}

		public int Index;

		public int Parent;

		public Type BlockType;

		public int StartOffset;

		public int EndOffset;

		public CodeBlockEntry(int index, int parent, Type type, int start_offset)
		{
			Index = index;
			Parent = parent;
			BlockType = type;
			StartOffset = start_offset;
		}

		internal CodeBlockEntry(int index, MyBinaryReader reader)
		{
			Index = index;
			int num = reader.ReadLeb128();
			BlockType = (Type)(num & 0x3F);
			Parent = reader.ReadLeb128();
			StartOffset = reader.ReadLeb128();
			EndOffset = reader.ReadLeb128();
			if (((uint)num & 0x40u) != 0)
			{
				int num2 = reader.ReadInt16();
				reader.BaseStream.Position += num2;
			}
		}

		public void Close(int end_offset)
		{
			EndOffset = end_offset;
		}

		internal void Write(MyBinaryWriter bw)
		{
			bw.WriteLeb128((int)BlockType);
			bw.WriteLeb128(Parent);
			bw.WriteLeb128(StartOffset);
			bw.WriteLeb128(EndOffset);
		}

		public override string ToString()
		{
			return $"[CodeBlock {Index}:{Parent}:{BlockType}:{StartOffset}:{EndOffset}]";
		}
	}
	public struct LocalVariableEntry
	{
		public readonly int Index;

		public readonly string Name;

		public readonly int BlockIndex;

		public LocalVariableEntry(int index, string name, int block)
		{
			Index = index;
			Name = name;
			BlockIndex = block;
		}

		internal LocalVariableEntry(MonoSymbolFile file, MyBinaryReader reader)
		{
			Index = reader.ReadLeb128();
			Name = reader.ReadString();
			BlockIndex = reader.ReadLeb128();
		}

		internal void Write(MonoSymbolFile file, MyBinaryWriter bw)
		{
			bw.WriteLeb128(Index);
			bw.Write(Name);
			bw.WriteLeb128(BlockIndex);
		}

		public override string ToString()
		{
			return $"[LocalVariable {Name}:{Index}:{BlockIndex - 1}]";
		}
	}
	public struct CapturedVariable
	{
		public enum CapturedKind : byte
		{
			Local,
			Parameter,
			This
		}

		public readonly string Name;

		public readonly string CapturedName;

		public readonly CapturedKind Kind;

		public CapturedVariable(string name, string captured_name, CapturedKind kind)
		{
			Name = name;
			CapturedName = captured_name;
			Kind = kind;
		}

		internal CapturedVariable(MyBinaryReader reader)
		{
			Name = reader.ReadString();
			CapturedName = reader.ReadString();
			Kind = (CapturedKind)reader.ReadByte();
		}

		internal void Write(MyBinaryWriter bw)
		{
			bw.Write(Name);
			bw.Write(CapturedName);
			bw.Write((byte)Kind);
		}

		public override string ToString()
		{
			return $"[CapturedVariable {Name}:{CapturedName}:{Kind}]";
		}
	}
	public struct CapturedScope
	{
		public readonly int Scope;

		public readonly string CapturedName;

		public CapturedScope(int scope, string captured_name)
		{
			Scope = scope;
			CapturedName = captured_name;
		}

		internal CapturedScope(MyBinaryReader reader)
		{
			Scope = reader.ReadLeb128();
			CapturedName = reader.ReadString();
		}

		internal void Write(MyBinaryWriter bw)
		{
			bw.WriteLeb128(Scope);
			bw.Write(CapturedName);
		}

		public override string ToString()
		{
			return $"[CapturedScope {Scope}:{CapturedName}]";
		}
	}
	public struct ScopeVariable
	{
		public readonly int Scope;

		public readonly int Index;

		public ScopeVariable(int scope, int index)
		{
			Scope = scope;
			Index = index;
		}

		internal ScopeVariable(MyBinaryReader reader)
		{
			Scope = reader.ReadLeb128();
			Index = reader.ReadLeb128();
		}

		internal void Write(MyBinaryWriter bw)
		{
			bw.WriteLeb128(Scope);
			bw.WriteLeb128(Index);
		}

		public override string ToString()
		{
			return $"[ScopeVariable {Scope}:{Index}]";
		}
	}
	public class AnonymousScopeEntry
	{
		public readonly int ID;

		private List<CapturedVariable> captured_vars = new List<CapturedVariable>();

		private List<CapturedScope> captured_scopes = new List<CapturedScope>();

		public CapturedVariable[] CapturedVariables
		{
			get
			{
				CapturedVariable[] array = new CapturedVariable[captured_vars.Count];
				captured_vars.CopyTo(array, 0);
				return array;
			}
		}

		public CapturedScope[] CapturedScopes
		{
			get
			{
				CapturedScope[] array = new CapturedScope[captured_scopes.Count];
				captured_scopes.CopyTo(array, 0);
				return array;
			}
		}

		public AnonymousScopeEntry(int id)
		{
			ID = id;
		}

		internal AnonymousScopeEntry(MyBinaryReader reader)
		{
			ID = reader.ReadLeb128();
			int num = reader.ReadLeb128();
			for (int i = 0; i < num; i++)
			{
				captured_vars.Add(new CapturedVariable(reader));
			}
			int num2 = reader.ReadLeb128();
			for (int j = 0; j < num2; j++)
			{
				captured_scopes.Add(new CapturedScope(reader));
			}
		}

		internal void AddCapturedVariable(string name, string captured_name, CapturedVariable.CapturedKind kind)
		{
			captured_vars.Add(new CapturedVariable(name, captured_name, kind));
		}

		internal void AddCapturedScope(int scope, string captured_name)
		{
			captured_scopes.Add(new CapturedScope(scope, captured_name));
		}

		internal void Write(MyBinaryWriter bw)
		{
			bw.WriteLeb128(ID);
			bw.WriteLeb128(captured_vars.Count);
			foreach (CapturedVariable captured_var in captured_vars)
			{
				captured_var.Write(bw);
			}
			bw.WriteLeb128(captured_scopes.Count);
			foreach (CapturedScope captured_scope in captured_scopes)
			{
				captured_scope.Write(bw);
			}
		}

		public override string ToString()
		{
			return $"[AnonymousScope {ID}]";
		}
	}
	public class CompileUnitEntry : ICompileUnit
	{
		public readonly int Index;

		private int DataOffset;

		private MonoSymbolFile file;

		private SourceFileEntry source;

		private List<SourceFileEntry> include_files;

		private List<NamespaceEntry> namespaces;

		private bool creating;

		public static int Size => 8;

		CompileUnitEntry ICompileUnit.Entry => this;

		public SourceFileEntry SourceFile
		{
			get
			{
				if (creating)
				{
					return source;
				}
				ReadData();
				return source;
			}
		}

		public NamespaceEntry[] Namespaces
		{
			get
			{
				ReadData();
				NamespaceEntry[] array = new NamespaceEntry[namespaces.Count];
				namespaces.CopyTo(array, 0);
				return array;
			}
		}

		public SourceFileEntry[] IncludeFiles
		{
			get
			{
				ReadData();
				if (include_files == null)
				{
					return new SourceFileEntry[0];
				}
				SourceFileEntry[] array = new SourceFileEntry[include_files.Count];
				include_files.CopyTo(array, 0);
				return array;
			}
		}

		public CompileUnitEntry(MonoSymbolFile file, SourceFileEntry source)
		{
			this.file = file;
			this.source = source;
			Index = file.AddCompileUnit(this);
			creating = true;
			namespaces = new List<NamespaceEntry>();
		}

		public void AddFile(SourceFileEntry file)
		{
			if (!creating)
			{
				throw new InvalidOperationException();
			}
			if (include_files == null)
			{
				include_files = new List<SourceFileEntry>();
			}
			include_files.Add(file);
		}

		public int DefineNamespace(string name, string[] using_clauses, int parent)
		{
			if (!creating)
			{
				throw new InvalidOperationException();
			}
			int nextNamespaceIndex = file.GetNextNamespaceIndex();
			NamespaceEntry item = new NamespaceEntry(name, nextNamespaceIndex, using_clauses, parent);
			namespaces.Add(item);
			return nextNamespaceIndex;
		}

		internal void WriteData(MyBinaryWriter bw)
		{
			DataOffset = (int)bw.BaseStream.Position;
			bw.WriteLeb128(source.Index);
			int value = ((include_files != null) ? include_files.Count : 0);
			bw.WriteLeb128(value);
			if (include_files != null)
			{
				foreach (SourceFileEntry include_file in include_files)
				{
					bw.WriteLeb128(include_file.Index);
				}
			}
			bw.WriteLeb128(namespaces.Count);
			foreach (NamespaceEntry @namespace in namespaces)
			{
				@namespace.Write(file, bw);
			}
		}

		internal void Write(BinaryWriter bw)
		{
			bw.Write(Index);
			bw.Write(DataOffset);
		}

		internal CompileUnitEntry(MonoSymbolFile file, MyBinaryReader reader)
		{
			this.file = file;
			Index = reader.ReadInt32();
			DataOffset = reader.ReadInt32();
		}

		public void ReadAll()
		{
			ReadData();
		}

		private void ReadData()
		{
			if (creating)
			{
				throw new InvalidOperationException();
			}
			lock (file)
			{
				if (namespaces != null)
				{
					return;
				}
				MyBinaryReader binaryReader = file.BinaryReader;
				int num = (int)binaryReader.BaseStream.Position;
				binaryReader.BaseStream.Position = DataOffset;
				int index = binaryReader.ReadLeb128();
				source = file.GetSourceFile(index);
				int num2 = binaryReader.ReadLeb128();
				if (num2 > 0)
				{
					include_files = new List<SourceFileEntry>();
					for (int i = 0; i < num2; i++)
					{
						include_files.Add(file.GetSourceFile(binaryReader.ReadLeb128()));
					}
				}
				int num3 = binaryReader.ReadLeb128();
				namespaces = new List<NamespaceEntry>();
				for (int j = 0; j < num3; j++)
				{
					namespaces.Add(new NamespaceEntry(file, binaryReader));
				}
				binaryReader.BaseStream.Position = num;
			}
		}
	}
	public class SourceFileEntry
	{
		public readonly int Index;

		private int DataOffset;

		private MonoSymbolFile file;

		private string file_name;

		private byte[] guid;

		private byte[] hash;

		private bool creating;

		private bool auto_generated;

		private readonly string sourceFile;

		public static int Size => 8;

		public byte[] Checksum => hash;

		public string FileName
		{
			get
			{
				return file_name;
			}
			set
			{
				file_name = value;
			}
		}

		public bool AutoGenerated => auto_generated;

		public SourceFileEntry(MonoSymbolFile file, string file_name)
		{
			this.file = file;
			this.file_name = file_name;
			Index = file.AddSource(this);
			creating = true;
		}

		public SourceFileEntry(MonoSymbolFile file, string sourceFile, byte[] guid, byte[] checksum)
			: this(file, sourceFile, sourceFile, guid, checksum)
		{
		}

		public SourceFileEntry(MonoSymbolFile file, string fileName, string sourceFile, byte[] guid, byte[] checksum)
			: this(file, fileName)
		{
			this.guid = guid;
			hash = checksum;
			this.sourceFile = sourceFile;
		}

		internal void WriteData(MyBinaryWriter bw)
		{
			DataOffset = (int)bw.BaseStream.Position;
			bw.Write(file_name);
			if (guid == null)
			{
				guid = new byte[16];
			}
			if (hash == null)
			{
				try
				{
					using FileStream inputStream = new FileStream(sourceFile, FileMode.Open, FileAccess.Read);
					MD5 mD = MD5.Create();
					hash = mD.ComputeHash(inputStream);
				}
				catch
				{
					hash = new byte[16];
				}
			}
			bw.Write(guid);
			bw.Write(hash);
			bw.Write((byte)(auto_generated ? 1u : 0u));
		}

		internal void Write(BinaryWriter bw)
		{
			bw.Write(Index);
			bw.Write(DataOffset);
		}

		internal SourceFileEntry(MonoSymbolFile file, MyBinaryReader reader)
		{
			this.file = file;
			Index = reader.ReadInt32();
			DataOffset = reader.ReadInt32();
			int num = (int)reader.BaseStream.Position;
			reader.BaseStream.Position = DataOffset;
			sourceFile = (file_name = reader.ReadString());
			guid = reader.ReadBytes(16);
			hash = reader.ReadBytes(16);
			auto_generated = reader.ReadByte() == 1;
			reader.BaseStream.Position = num;
		}

		public void SetAutoGenerated()
		{
			if (!creating)
			{
				throw new InvalidOperationException();
			}
			auto_generated = true;
			file.OffsetTable.FileFlags |= OffsetTable.Flags.IsAspxSource;
		}

		public bool CheckChecksum()
		{
			try
			{
				using FileStream inputStream = new FileStream(sourceFile, FileMode.Open);
				byte[] array = MD5.Create().ComputeHash(inputStream);
				for (int i = 0; i < 16; i++)
				{
					if (array[i] != hash[i])
					{
						return false;
					}
				}
				return true;
			}
			catch
			{
				return false;
			}
		}

		public override string ToString()
		{
			return $"SourceFileEntry ({Index}:{DataOffset})";
		}
	}
	public class LineNumberTable
	{
		protected LineNumberEntry[] _line_numbers;

		public readonly int LineBase;

		public readonly int LineRange;

		public readonly byte OpcodeBase;

		public readonly int MaxAddressIncrement;

		public const int Default_LineBase = -1;

		public const int Default_LineRange = 8;

		public const byte Default_OpcodeBase = 9;

		public const byte DW_LNS_copy = 1;

		public const byte DW_LNS_advance_pc = 2;

		public const byte DW_LNS_advance_line = 3;

		public const byte DW_LNS_set_file = 4;

		public const byte DW_LNS_const_add_pc = 8;

		public const byte DW_LNE_end_sequence = 1;

		public const byte DW_LNE_MONO_negate_is_hidden = 64;

		internal const byte DW_LNE_MONO__extensions_start = 64;

		internal const byte DW_LNE_MONO__extensions_end = 127;

		public LineNumberEntry[] LineNumbers => _line_numbers;

		protected LineNumberTable(MonoSymbolFile file)
		{
			LineBase = file.OffsetTable.LineNumberTable_LineBase;
			LineRange = file.OffsetTable.LineNumberTable_LineRange;
			OpcodeBase = (byte)file.OffsetTable.LineNumberTable_OpcodeBase;
			MaxAddressIncrement = (255 - OpcodeBase) / LineRange;
		}

		internal LineNumberTable(MonoSymbolFile file, LineNumberEntry[] lines)
			: this(file)
		{
			_line_numbers = lines;
		}

		internal void Write(MonoSymbolFile file, MyBinaryWriter bw, bool hasColumnsInfo, bool hasEndInfo)
		{
			int num = (int)bw.BaseStream.Position;
			bool flag = false;
			int num2 = 1;
			int num3 = 0;
			int num4 = 1;
			for (int i = 0; i < LineNumbers.Length; i++)
			{
				int num5 = LineNumbers[i].Row - num2;
				int num6 = LineNumbers[i].Offset - num3;
				if (LineNumbers[i].File != num4)
				{
					bw.Write((byte)4);
					bw.WriteLeb128(LineNumbers[i].File);
					num4 = LineNumbers[i].File;
				}
				if (LineNumbers[i].IsHidden != flag)
				{
					bw.Write((byte)0);
					bw.Write((byte)1);
					bw.Write((byte)64);
					flag = LineNumbers[i].IsHidden;
				}
				if (num6 >= MaxAddressIncrement)
				{
					if (num6 < 2 * MaxAddressIncrement)
					{
						bw.Write((byte)8);
						num6 -= MaxAddressIncrement;
					}
					else
					{
						bw.Write((byte)2);
						bw.WriteLeb128(num6);
						num6 = 0;
					}
				}
				if (num5 < LineBase || num5 >= LineBase + LineRange)
				{
					bw.Write((byte)3);
					bw.WriteLeb128(num5);
					if (num6 != 0)
					{
						bw.Write((byte)2);
						bw.WriteLeb128(num6);
					}
					bw.Write((byte)1);
				}
				else
				{
					byte value = (byte)(num5 - LineBase + LineRange * num6 + OpcodeBase);
					bw.Write(value);
				}
				num2 = LineNumbers[i].Row;
				num3 = LineNumbers[i].Offset;
			}
			bw.Write((byte)0);
			bw.Write((byte)1);
			bw.Write((byte)1);
			if (hasColumnsInfo)
			{
				for (int j = 0; j < LineNumbers.Length; j++)
				{
					LineNumberEntry lineNumberEntry = LineNumbers[j];
					if (lineNumberEntry.Row >= 0)
					{
						bw.WriteLeb128(lineNumberEntry.Column);
					}
				}
			}
			if (hasEndInfo)
			{
				for (int k = 0; k < LineNumbers.Length; k++)
				{
					LineNumberEntry lineNumberEntry2 = LineNumbers[k];
					if (lineNumberEntry2.EndRow == -1 || lineNumberEntry2.EndColumn == -1 || lineNumberEntry2.Row > lineNumberEntry2.EndRow)
					{
						bw.WriteLeb128(16777215);
						continue;
					}
					bw.WriteLeb128(lineNumberEntry2.EndRow - lineNumberEntry2.Row);
					bw.WriteLeb128(lineNumberEntry2.EndColumn);
				}
			}
			file.ExtendedLineNumberSize += (int)bw.BaseStream.Position - num;
		}

		internal static LineNumberTable Read(MonoSymbolFile file, MyBinaryReader br, bool readColumnsInfo, bool readEndInfo)
		{
			LineNumberTable lineNumberTable = new LineNumberTable(file);
			lineNumberTable.DoRead(file, br, readColumnsInfo, readEndInfo);
			return lineNumberTable;
		}

		private void DoRead(MonoSymbolFile file, MyBinaryReader br, bool includesColumns, bool includesEnds)
		{
			List<LineNumberEntry> list = new List<LineNumberEntry>();
			bool flag = false;
			bool flag2 = false;
			int num = 1;
			int num2 = 0;
			int file2 = 1;
			while (true)
			{
				byte b = br.ReadByte();
				if (b == 0)
				{
					byte b2 = br.ReadByte();
					long position = br.BaseStream.Position + b2;
					b = br.ReadByte();
					switch (b)
					{
					case 1:
					{
						if (flag2)
						{
							list.Add(new LineNumberEntry(file2, num, -1, num2, flag));
						}
						_line_numbers = list.ToArray();
						if (includesColumns)
						{
							for (int i = 0; i < _line_numbers.Length; i++)
							{
								LineNumberEntry lineNumberEntry = _line_numbers[i];
								if (lineNumberEntry.Row >= 0)
								{
									lineNumberEntry.Column = br.ReadLeb128();
								}
							}
						}
						if (!includesEnds)
						{
							return;
						}
						for (int j = 0; j < _line_numbers.Length; j++)
						{
							LineNumberEntry lineNumberEntry2 = _line_numbers[j];
							int num3 = br.ReadLeb128();
							if (num3 == 16777215)
							{
								lineNumberEntry2.EndRow = -1;
								lineNumberEntry2.EndColumn = -1;
							}
							else
							{
								lineNumberEntry2.EndRow = lineNumberEntry2.Row + num3;
								lineNumberEntry2.EndColumn = br.ReadLeb128();
							}
						}
						return;
					}
					case 64:
						flag = !flag;
						flag2 = true;
						break;
					default:
						throw new MonoSymbolFileException("Unknown extended opcode {0:x}", b);
					case 65:
					case 66:
					case 67:
					case 68:
					case 69:
					case 70:
					case 71:
					case 72:
					case 73:
					case 74:
					case 75:
					case 76:
					case 77:
					case 78:
					case 79:
					case 80:
					case 81:
					case 82:
					case 83:
					case 84:
					case 85:
					case 86:
					case 87:
					case 88:
					case 89:
					case 90:
					case 91:
					case 92:
					case 93:
					case 94:
					case 95:
					case 96:
					case 97:
					case 98:
					case 99:
					case 100:
					case 101:
					case 102:
					case 103:
					case 104:
					case 105:
					case 106:
					case 107:
					case 108:
					case 109:
					case 110:
					case 111:
					case 112:
					case 113:
					case 114:
					case 115:
					case 116:
					case 117:
					case 118:
					case 119:
					case 120:
					case 121:
					case 122:
					case 123:
					case 124:
					case 125:
					case 126:
					case 127:
						break;
					}
					br.BaseStream.Position = position;
				}
				else if (b < OpcodeBase)
				{
					switch (b)
					{
					case 1:
						list.Add(new LineNumberEntry(file2, num, -1, num2, flag));
						flag2 = false;
						break;
					case 2:
						num2 += br.ReadLeb128();
						flag2 = true;
						break;
					case 3:
						num += br.ReadLeb128();
						flag2 = true;
						break;
					case 4:
						file2 = br.ReadLeb128();
						flag2 = true;
						break;
					case 8:
						num2 += MaxAddressIncrement;
						flag2 = true;
						break;
					default:
						throw new MonoSymbolFileException("Unknown standard opcode {0:x} in LNT", b);
					}
				}
				else
				{
					b -= OpcodeBase;
					num2 += b / LineRange;
					num += LineBase + b % LineRange;
					list.Add(new LineNumberEntry(file2, num, -1, num2, flag));
					flag2 = false;
				}
			}
		}

		public bool GetMethodBounds(out LineNumberEntry start, out LineNumberEntry end)
		{
			if (_line_numbers.Length > 1)
			{
				start = _line_numbers[0];
				end = _line_numbers[_line_numbers.Length - 1];
				return true;
			}
			start = LineNumberEntry.Null;
			end = LineNumberEntry.Null;
			return false;
		}
	}
	public class MethodEntry : IComparable
	{
		[Flags]
		public enum Flags
		{
			LocalNamesAmbiguous = 1,
			ColumnsInfoIncluded = 2,
			EndInfoIncluded = 4
		}

		public readonly int CompileUnitIndex;

		public readonly int Token;

		public readonly int NamespaceID;

		private int DataOffset;

		private int LocalVariableTableOffset;

		private int LineNumberTableOffset;

		private int CodeBlockTableOffset;

		private int ScopeVariableTableOffset;

		private int RealNameOffset;

		private Flags flags;

		private int index;

		public readonly CompileUnitEntry CompileUnit;

		private LocalVariableEntry[] locals;

		private CodeBlockEntry[] code_blocks;

		private ScopeVariable[] scope_vars;

		private LineNumberTable lnt;

		private string real_name;

		public readonly MonoSymbolFile SymbolFile;

		public const int Size = 12;

		public Flags MethodFlags => flags;

		public int Index
		{
			get
			{
				return index;
			}
			set
			{
				index = value;
			}
		}

		internal MethodEntry(MonoSymbolFile file, MyBinaryReader reader, int index)
		{
			SymbolFile = file;
			this.index = index;
			Token = reader.ReadInt32();
			DataOffset = reader.ReadInt32();
			LineNumberTableOffset = reader.ReadInt32();
			long position = reader.BaseStream.Position;
			reader.BaseStream.Position = DataOffset;
			CompileUnitIndex = reader.ReadLeb128();
			LocalVariableTableOffset = reader.ReadLeb128();
			NamespaceID = reader.ReadLeb128();
			CodeBlockTableOffset = reader.ReadLeb128();
			ScopeVariableTableOffset = reader.ReadLeb128();
			RealNameOffset = reader.ReadLeb128();
			flags = (Flags)reader.ReadLeb128();
			reader.BaseStream.Position = position;
			CompileUnit = file.GetCompileUnit(CompileUnitIndex);
		}

		internal MethodEntry(MonoSymbolFile file, CompileUnitEntry comp_unit, int token, ScopeVariable[] scope_vars, LocalVariableEntry[] locals, LineNumberEntry[] lines, CodeBlockEntry[] code_blocks, string real_name, Flags flags, int namespace_id)
		{
			SymbolFile = file;
			this.real_name = real_name;
			this.locals = locals;
			this.code_blocks = code_blocks;
			this.scope_vars = scope_vars;
			this.flags = flags;
			index = -1;
			Token = token;
			CompileUnitIndex = comp_unit.Index;
			CompileUnit = comp_unit;
			NamespaceID = namespace_id;
			CheckLineNumberTable(lines);
			lnt = new LineNumberTable(file, lines);
			file.NumLineNumbers += lines.Length;
			int num = ((locals != null) ? locals.Length : 0);
			if (num <= 32)
			{
				for (int i = 0; i < num; i++)
				{
					string name = locals[i].Name;
					for (int j = i + 1; j < num; j++)
					{
						if (locals[j].Name == name)
						{
							flags |= Flags.LocalNamesAmbiguous;
							return;
						}
					}
				}
				return;
			}
			Dictionary<string, LocalVariableEntry> dictionary = new Dictionary<string, LocalVariableEntry>();
			for (int k = 0; k < locals.Length; k++)
			{
				LocalVariableEntry value = locals[k];
				if (dictionary.ContainsKey(value.Name))
				{
					flags |= Flags.LocalNamesAmbiguous;
					break;
				}
				dictionary.Add(value.Name, value);
			}
		}

		private static void CheckLineNumberTable(LineNumberEntry[] line_numbers)
		{
			int num = -1;
			int num2 = -1;
			if (line_numbers == null)
			{
				return;
			}
			foreach (LineNumberEntry lineNumberEntry in line_numbers)
			{
				if (lineNumberEntry.Equals(LineNumberEntry.Null))
				{
					throw new MonoSymbolFileException();
				}
				if (lineNumberEntry.Offset < num)
				{
					throw new MonoSymbolFileException();
				}
				if (lineNumberEntry.Offset > num)
				{
					num2 = lineNumberEntry.Row;
					num = lineNumberEntry.Offset;
				}
				else if (lineNumberEntry.Row > num2)
				{
					num2 = lineNumberEntry.Row;
				}
			}
		}

		internal void Write(MyBinaryWriter bw)
		{
			if (index <= 0 || DataOffset == 0)
			{
				throw new InvalidOperationException();
			}
			bw.Write(Token);
			bw.Write(DataOffset);
			bw.Write(LineNumberTableOffset);
		}

		internal void WriteData(MonoSymbolFile file, MyBinaryWriter bw)
		{
			if (index <= 0)
			{
				throw new InvalidOperationException();
			}
			LocalVariableTableOffset = (int)bw.BaseStream.Position;
			int num = ((locals != null) ? locals.Length : 0);
			bw.WriteLeb128(num);
			for (int i = 0; i < num; i++)
			{
				locals[i].Write(file, bw);
			}
			file.LocalCount += num;
			CodeBlockTableOffset = (int)bw.BaseStream.Position;
			int num2 = ((code_blocks != null) ? code_blocks.Length : 0);
			bw.WriteLeb128(num2);
			for (int j = 0; j < num2; j++)
			{
				code_blocks[j].Write(bw);
			}
			ScopeVariableTableOffset = (int)bw.BaseStream.Position;
			int num3 = ((scope_vars != null) ? scope_vars.Length : 0);
			bw.WriteLeb128(num3);
			for (int k = 0; k < num3; k++)
			{
				scope_vars[k].Write(bw);
			}
			if (real_name != null)
			{
				RealNameOffset = (int)bw.BaseStream.Position;
				bw.Write(real_name);
			}
			LineNumberEntry[] lineNumbers = lnt.LineNumbers;
			foreach (LineNumberEntry lineNumberEntry in lineNumbers)
			{
				if (lineNumberEntry.EndRow != -1 || lineNumberEntry.EndColumn != -1)
				{
					flags |= Flags.EndInfoIncluded;
				}
			}
			LineNumberTableOffset = (int)bw.BaseStream.Position;
			lnt.Write(file, bw, (flags & Flags.ColumnsInfoIncluded) != 0, (flags & Flags.EndInfoIncluded) != 0);
			DataOffset = (int)bw.BaseStream.Position;
			bw.WriteLeb128(CompileUnitIndex);
			bw.WriteLeb128(LocalVariableTableOffset);
			bw.WriteLeb128(NamespaceID);
			bw.WriteLeb128(CodeBlockTableOffset);
			bw.WriteLeb128(ScopeVariableTableOffset);
			bw.WriteLeb128(RealNameOffset);
			bw.WriteLeb128((int)flags);
		}

		public void ReadAll()
		{
			GetLineNumberTable();
			GetLocals();
			GetCodeBlocks();
			GetScopeVariables();
			GetRealName();
		}

		public LineNumberTable GetLineNumberTable()
		{
			lock (SymbolFile)
			{
				if (lnt != null)
				{
					return lnt;
				}
				if (LineNumberTableOffset == 0)
				{
					return null;
				}
				MyBinaryReader binaryReader = SymbolFile.BinaryReader;
				long position = binaryReader.BaseStream.Position;
				binaryReader.BaseStream.Position = LineNumberTableOffset;
				lnt = LineNumberTable.Read(SymbolFile, binaryReader, (flags & Flags.ColumnsInfoIncluded) != 0, (flags & Flags.EndInfoIncluded) != 0);
				binaryReader.BaseStream.Position = position;
				return lnt;
			}
		}

		public LocalVariableEntry[] GetLocals()
		{
			lock (SymbolFile)
			{
				if (locals != null)
				{
					return locals;
				}
				if (LocalVariableTableOffset == 0)
				{
					return null;
				}
				MyBinaryReader binaryReader = SymbolFile.BinaryReader;
				long position = binaryReader.BaseStream.Position;
				binaryReader.BaseStream.Position = LocalVariableTableOffset;
				int num = binaryReader.ReadLeb128();
				locals = new LocalVariableEntry[num];
				for (int i = 0; i < num; i++)
				{
					locals[i] = new LocalVariableEntry(SymbolFile, binaryReader);
				}
				binaryReader.BaseStream.Position = position;
				return locals;
			}
		}

		public CodeBlockEntry[] GetCodeBlocks()
		{
			lock (SymbolFile)
			{
				if (code_blocks != null)
				{
					return code_blocks;
				}
				if (CodeBlockTableOffset == 0)
				{
					return null;
				}
				MyBinaryReader binaryReader = SymbolFile.BinaryReader;
				long position = binaryReader.BaseStream.Position;
				binaryReader.BaseStream.Position = CodeBlockTableOffset;
				int num = binaryReader.ReadLeb128();
				code_blocks = new CodeBlockEntry[num];
				for (int i = 0; i < num; i++)
				{
					code_blocks[i] = new CodeBlockEntry(i, binaryReader);
				}
				binaryReader.BaseStream.Position = position;
				return code_blocks;
			}
		}

		public ScopeVariable[] GetScopeVariables()
		{
			lock (SymbolFile)
			{
				if (scope_vars != null)
				{
					return scope_vars;
				}
				if (ScopeVariableTableOffset == 0)
				{
					return null;
				}
				MyBinaryReader binaryReader = SymbolFile.BinaryReader;
				long position = binaryReader.BaseStream.Position;
				binaryReader.BaseStream.Position = ScopeVariableTableOffset;
				int num = binaryReader.ReadLeb128();
				scope_vars = new ScopeVariable[num];
				for (int i = 0; i < num; i++)
				{
					scope_vars[i] = new ScopeVariable(binaryReader);
				}
				binaryReader.BaseStream.Position = position;
				return scope_vars;
			}
		}

		public string GetRealName()
		{
			lock (SymbolFile)
			{
				if (real_name != null)
				{
					return real_name;
				}
				if (RealNameOffset == 0)
				{
					return null;
				}
				real_name = SymbolFile.BinaryReader.ReadString(RealNameOffset);
				return real_name;
			}
		}

		public int CompareTo(object obj)
		{
			MethodEntry methodEntry = (MethodEntry)obj;
			if (methodEntry.Token < Token)
			{
				return 1;
			}
			if (methodEntry.Token > Token)
			{
				return -1;
			}
			return 0;
		}

		public override string ToString()
		{
			return $"[Method {index}:{Token:x}:{CompileUnitIndex}:{CompileUnit}]";
		}
	}
	public struct NamespaceEntry
	{
		public readonly string Name;

		public readonly int Index;

		public readonly int Parent;

		public readonly string[] UsingClauses;

		public NamespaceEntry(string name, int index, string[] using_clauses, int parent)
		{
			Name = name;
			Index = index;
			Parent = parent;
			UsingClauses = ((using_clauses != null) ? using_clauses : new string[0]);
		}

		internal NamespaceEntry(MonoSymbolFile file, MyBinaryReader reader)
		{
			Name = reader.ReadString();
			Index = reader.ReadLeb128();
			Parent = reader.ReadLeb128();
			int num = reader.ReadLeb128();
			UsingClauses = new string[num];
			for (int i = 0; i < num; i++)
			{
				UsingClauses[i] = reader.ReadString();
			}
		}

		internal void Write(MonoSymbolFile file, MyBinaryWriter bw)
		{
			bw.Write(Name);
			bw.WriteLeb128(Index);
			bw.WriteLeb128(Parent);
			bw.WriteLeb128(UsingClauses.Length);
			string[] usingClauses = UsingClauses;
			foreach (string value in usingClauses)
			{
				bw.Write(value);
			}
		}

		public override string ToString()
		{
			return $"[Namespace {Name}:{Index}:{Parent}]";
		}
	}
	public class MonoSymbolWriter
	{
		private List<SourceMethodBuilder> methods;

		private List<SourceFileEntry> sources;

		private List<CompileUnitEntry> comp_units;

		protected readonly MonoSymbolFile file;

		private string filename;

		private SourceMethodBuilder current_method;

		private Stack<SourceMethodBuilder> current_method_stack = new Stack<SourceMethodBuilder>();

		public MonoSymbolFile SymbolFile => file;

		public MonoSymbolWriter(string filename)
		{
			methods = new List<SourceMethodBuilder>();
			sources = new List<SourceFileEntry>();
			comp_units = new List<CompileUnitEntry>();
			file = new MonoSymbolFile();
			this.filename = filename + ".mdb";
		}

		public void CloseNamespace()
		{
		}

		public void DefineLocalVariable(int index, string name)
		{
			if (current_method != null)
			{
				current_method.AddLocal(index, name);
			}
		}

		public void DefineCapturedLocal(int scope_id, string name, string captured_name)
		{
			file.DefineCapturedVariable(scope_id, name, captured_name, CapturedVariable.CapturedKind.Local);
		}

		public void DefineCapturedParameter(int scope_id, string name, string captured_name)
		{
			file.DefineCapturedVariable(scope_id, name, captured_name, CapturedVariable.CapturedKind.Parameter);
		}

		public void DefineCapturedThis(int scope_id, string captured_name)
		{
			file.DefineCapturedVariable(scope_id, "this", captured_name, CapturedVariable.CapturedKind.This);
		}

		public void DefineCapturedScope(int scope_id, int id, string captured_name)
		{
			file.DefineCapturedScope(scope_id, id, captured_name);
		}

		public void DefineScopeVariable(int scope, int index)
		{
			if (current_method != null)
			{
				current_method.AddScopeVariable(scope, index);
			}
		}

		public void MarkSequencePoint(int offset, SourceFileEntry file, int line, int column, bool is_hidden)
		{
			if (current_method != null)
			{
				current_method.MarkSequencePoint(offset, file, line, column, is_hidden);
			}
		}

		public SourceMethodBuilder OpenMethod(ICompileUnit file, int ns_id, IMethodDef method)
		{
			SourceMethodBuilder result = new SourceMethodBuilder(file, ns_id, method);
			current_method_stack.Push(current_method);
			current_method = result;
			methods.Add(current_method);
			return result;
		}

		public void CloseMethod()
		{
			current_method = current_method_stack.Pop();
		}

		public SourceFileEntry DefineDocument(string url)
		{
			SourceFileEntry sourceFileEntry = new SourceFileEntry(file, url);
			sources.Add(sourceFileEntry);
			return sourceFileEntry;
		}

		public SourceFileEntry DefineDocument(string url, byte[] guid, byte[] checksum)
		{
			SourceFileEntry sourceFileEntry = new SourceFileEntry(file, url, guid, checksum);
			sources.Add(sourceFileEntry);
			return sourceFileEntry;
		}

		public CompileUnitEntry DefineCompilationUnit(SourceFileEntry source)
		{
			CompileUnitEntry compileUnitEntry = new CompileUnitEntry(file, source);
			comp_units.Add(compileUnitEntry);
			return compileUnitEntry;
		}

		public int DefineNamespace(string name, CompileUnitEntry unit, string[] using_clauses, int parent)
		{
			if (unit == null || using_clauses == null)
			{
				throw new NullReferenceException();
			}
			return unit.DefineNamespace(name, using_clauses, parent);
		}

		public int OpenScope(int start_offset)
		{
			if (current_method == null)
			{
				return 0;
			}
			current_method.StartBlock(CodeBlockEntry.Type.Lexical, start_offset);
			return 0;
		}

		public void CloseScope(int end_offset)
		{
			if (current_method != null)
			{
				current_method.EndBlock(end_offset);
			}
		}

		public void OpenCompilerGeneratedBlock(int start_offset)
		{
			if (current_method != null)
			{
				current_method.StartBlock(CodeBlockEntry.Type.CompilerGenerated, start_offset);
			}
		}

		public void CloseCompilerGeneratedBlock(int end_offset)
		{
			if (current_method != null)
			{
				current_method.EndBlock(end_offset);
			}
		}

		public void StartIteratorBody(int start_offset)
		{
			current_method.StartBlock(CodeBlockEntry.Type.IteratorBody, start_offset);
		}

		public void EndIteratorBody(int end_offset)
		{
			current_method.EndBlock(end_offset);
		}

		public void StartIteratorDispatcher(int start_offset)
		{
			current_method.StartBlock(CodeBlockEntry.Type.IteratorDispatcher, start_offset);
		}

		public void EndIteratorDispatcher(int end_offset)
		{
			current_method.EndBlock(end_offset);
		}

		public void DefineAnonymousScope(int id)
		{
			file.DefineAnonymousScope(id);
		}

		public void WriteSymbolFile(Guid guid)
		{
			foreach (SourceMethodBuilder method in methods)
			{
				method.DefineMethod(file);
			}
			try
			{
				File.Delete(filename);
			}
			catch
			{
			}
			using FileStream fs = new FileStream(filename, FileMode.Create, FileAccess.Write);
			file.CreateSymbolFile(guid, fs);
		}
	}
	public class SourceMethodBuilder
	{
		private List<LocalVariableEntry> _locals;

		private List<CodeBlockEntry> _blocks;

		private List<ScopeVariable> _scope_vars;

		private Stack<CodeBlockEntry> _block_stack;

		private readonly List<LineNumberEntry> method_lines;

		private readonly ICompileUnit _comp_unit;

		private readonly int ns_id;

		private readonly IMethodDef method;

		public CodeBlockEntry[] Blocks
		{
			get
			{
				if (_blocks == null)
				{
					return new CodeBlockEntry[0];
				}
				CodeBlockEntry[] array = new CodeBlockEntry[_blocks.Count];
				_blocks.CopyTo(array, 0);
				return array;
			}
		}

		public CodeBlockEntry CurrentBlock
		{
			get
			{
				if (_block_stack != null && _block_stack.Count > 0)
				{
					return _block_stack.Peek();
				}
				return null;
			}
		}

		public LocalVariableEntry[] Locals
		{
			get
			{
				if (_locals == null)
				{
					return new LocalVariableEntry[0];
				}
				return _locals.ToArray();
			}
		}

		public ICompileUnit SourceFile => _comp_unit;

		public ScopeVariable[] ScopeVariables
		{
			get
			{
				if (_scope_vars == null)
				{
					return new ScopeVariable[0];
				}
				return _scope_vars.ToArray();
			}
		}

		public SourceMethodBuilder(ICompileUnit comp_unit)
		{
			_comp_unit = comp_unit;
			method_lines = new List<LineNumberEntry>();
		}

		public SourceMethodBuilder(ICompileUnit comp_unit, int ns_id, IMethodDef method)
			: this(comp_unit)
		{
			this.ns_id = ns_id;
			this.method = method;
		}

		public void MarkSequencePoint(int offset, SourceFileEntry file, int line, int column, bool is_hidden)
		{
			MarkSequencePoint(offset, file, line, column, -1, -1, is_hidden);
		}

		public void MarkSequencePoint(int offset, SourceFileEntry file, int line, int column, int end_line, int end_column, bool is_hidden)
		{
			LineNumberEntry lineNumberEntry = new LineNumberEntry(file?.Index ?? 0, line, column, end_line, end_column, offset, is_hidden);
			if (method_lines.Count > 0)
			{
				LineNumberEntry lineNumberEntry2 = method_lines[method_lines.Count - 1];
				if (lineNumberEntry2.Offset == offset)
				{
					if (LineNumberEntry.LocationComparer.Default.Compare(lineNumberEntry, lineNumberEntry2) > 0)
					{
						method_lines[method_lines.Count - 1] = lineNumberEntry;
					}
					return;
				}
			}
			method_lines.Add(lineNumberEntry);
		}

		public void StartBlock(CodeBlockEntry.Type type, int start_offset)
		{
			StartBlock(type, start_offset, (_blocks == null) ? 1 : (_blocks.Count + 1));
		}

		public void StartBlock(CodeBlockEntry.Type type, int start_offset, int scopeIndex)
		{
			if (_block_stack == null)
			{
				_block_stack = new Stack<CodeBlockEntry>();
			}
			if (_blocks == null)
			{
				_blocks = new List<CodeBlockEntry>();
			}
			int parent = ((CurrentBlock != null) ? CurrentBlock.Index : (-1));
			CodeBlockEntry item = new CodeBlockEntry(scopeIndex, parent, type, start_offset);
			_block_stack.Push(item);
			_blocks.Add(item);
		}

		public void EndBlock(int end_offset)
		{
			_block_stack.Pop().Close(end_offset);
		}

		public void AddLocal(int index, string name)
		{
			if (_locals == null)
			{
				_locals = new List<LocalVariableEntry>();
			}
			int block = ((CurrentBlock != null) ? CurrentBlock.Index : 0);
			_locals.Add(new LocalVariableEntry(index, name, block));
		}

		public void AddScopeVariable(int scope, int index)
		{
			if (_scope_vars == null)
			{
				_scope_vars = new List<ScopeVariable>();
			}
			_scope_vars.Add(new ScopeVariable(scope, index));
		}

		public void DefineMethod(MonoSymbolFile file)
		{
			DefineMethod(file, method.Token);
		}

		public void DefineMethod(MonoSymbolFile file, int token)
		{
			CodeBlockEntry[] array = Blocks;
			if (array.Length != 0)
			{
				List<CodeBlockEntry> list = new List<CodeBlockEntry>(array.Length);
				int num = 0;
				for (int i = 0; i < array.Length; i++)
				{
					num = Math.Max(num, array[i].Index);
				}
				for (int j = 0; j < num; j++)
				{
					int num2 = j + 1;
					if (j < array.Length && array[j].Index == num2)
					{
						list.Add(array[j]);
						continue;
					}
					bool flag = false;
					for (int k = 0; k < array.Length; k++)
					{
						if (array[k].Index == num2)
						{
							list.Add(array[k]);
							flag = true;
							break;
						}
					}
					if (!flag)
					{
						list.Add(new CodeBlockEntry(num2, -1, CodeBlockEntry.Type.CompilerGenerated, 0));
					}
				}
				array = list.ToArray();
			}
			MethodEntry entry = new MethodEntry(file, _comp_unit.Entry, token, ScopeVariables, Locals, method_lines.ToArray(), array, null, MethodEntry.Flags.ColumnsInfoIncluded, ns_id);
			file.AddMethod(entry);
		}
	}
}
namespace Mono.Cecil.Mdb
{
	public sealed class MdbReaderProvider : ISymbolReaderProvider
	{
		public ISymbolReader GetSymbolReader(ModuleDefinition module, string fileName)
		{
			Mixin.CheckModule(module);
			Mixin.CheckFileName(fileName);
			return (ISymbolReader)(object)new MdbReader(module, MonoSymbolFile.ReadSymbolFile(Mixin.GetMdbFileName(fileName)));
		}

		public ISymbolReader GetSymbolReader(ModuleDefinition module, Stream symbolStream)
		{
			Mixin.CheckModule(module);
			Mixin.CheckStream((object)symbolStream);
			return (ISymbolReader)(object)new MdbReader(module, MonoSymbolFile.ReadSymbolFile(symbolStream));
		}
	}
	public sealed class MdbReader : ISymbolReader, IDisposable
	{
		private readonly ModuleDefinition module;

		private readonly MonoSymbolFile symbol_file;

		private readonly Dictionary<string, Document> documents;

		public MdbReader(ModuleDefinition module, MonoSymbolFile symFile)
		{
			this.module = module;
			symbol_file = symFile;
			documents = new Dictionary<string, Document>();
		}

		public ISymbolWriterProvider GetWriterProvider()
		{
			return (ISymbolWriterProvider)(object)new MdbWriterProvider();
		}

		public bool ProcessDebugHeader(ImageDebugHeader header)
		{
			return symbol_file.Guid == module.Mvid;
		}

		public MethodDebugInformation Read(MethodDefinition method)
		{
			//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_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Expected O, but got Unknown
			MetadataToken metadataToken = ((MemberReference)method).MetadataToken;
			MethodEntry methodByToken = symbol_file.GetMethodByToken(((MetadataToken)(ref metadataToken)).ToInt32());
			if (methodByToken == null)
			{
				return null;
			}
			MethodDebugInformation val = new MethodDebugInformation(method);
			val.code_size = ReadCodeSize(method);
			ScopeDebugInformation[] scopes = ReadScopes(methodByToken, val);
			ReadLineNumbers(methodByToken, val);
			ReadLocalVariables(methodByToken, scopes);
			return val;
		}

		private static int ReadCodeSize(MethodDefinition method)
		{
			return ((MemberReference)method).Module.Read<MethodDefinition, int>(method, (Func<MethodDefinition, MetadataReader, int>)((MethodDefinition m, MetadataReader reader) => reader.ReadCodeSize(m)));
		}

		private static void ReadLocalVariables(MethodEntry entry, ScopeDebugInformation[] scopes)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Expected O, but got Unknown
			LocalVariableEntry[] locals = entry.GetLocals();
			for (int i = 0; i < locals.Length; i++)
			{
				LocalVariableEntry localVariableEntry = locals[i];
				VariableDebugInformation val = new VariableDebugInformation(localVariableEntry.Index, localVariableEntry.Name);
				int blockIndex = localVariableEntry.BlockIndex;
				if (blockIndex >= 0 && blockIndex < scopes.Length)
				{
					ScopeDebugInformation val2 = scopes[blockIndex];
					if (val2 != null)
					{
						val2.Variables.Add(val);
					}
				}
			}
		}

		private void ReadLineNumbers(MethodEntry entry, MethodDebugInformation info)
		{
			LineNumberTable lineNumberTable = entry.GetLineNumberTable();
			info.sequence_points = new Collection<SequencePoint>(lineNumberTable.LineNumbers.Length);
			for (int i = 0; i < lineNumberTable.LineNumbers.Length; i++)
			{
				LineNumberEntry lineNumberEntry = lineNumberTable.LineNumbers[i];
				if (i <= 0 || lineNumberTable.LineNumbers[i - 1].Offset != lineNumberEntry.Offset)
				{
					info.sequence_points.Add(LineToSequencePoint(lineNumberEntry));
				}
			}
		}

		private Document GetDocument(SourceFileEntry file)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			string fileName = file.FileName;
			if (documents.TryGetValue(fileName, out var value))
			{
				return value;
			}
			value = new Document(fileName)
			{
				Hash = file.Checksum
			};
			documents.Add(fileName, value);
			return value;
		}

		private static ScopeDebugInformation[] ReadScopes(MethodEntry entry, MethodDebugInformation info)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: 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_002c: 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_0038: Expected O, but got Unknown
			//IL_0039: Expected O, but got Unknown
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Expected O, but got Unknown
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			CodeBlockEntry[] codeBlocks = entry.GetCodeBlocks();
			ScopeDebugInformation[] array = (ScopeDebugInformation[])(object)new ScopeDebugInformation[codeBlocks.Length + 1];
			ScopeDebugInformation val = new ScopeDebugInformation
			{
				Start = new InstructionOffset(0),
				End = new InstructionOffset(info.code_size)
			};
			ScopeDebugInformation scope = val;
			array[0] = val;
			info.scope = scope;
			CodeBlockEntry[] array2 = codeBlocks;
			foreach (CodeBlockEntry codeBlockEntry in array2)
			{
				if (codeBlockEntry.BlockType == CodeBlockEntry.Type.Lexical || codeBlockEntry.BlockType == CodeBlockEntry.Type.CompilerGenerated)
				{
					ScopeDebugInformation val2 = new ScopeDebugInformation();
					val2.Start = new InstructionOffset(codeBlockEntry.StartOffset);
					val2.End = new InstructionOffset(codeBlockEntry.EndOffset);
					array[codeBlockEntry.Index + 1] = val2;
					if (!AddScope(info.scope.Scopes, val2))
					{
						info.scope.Scopes.Add(val2);
					}
				}
			}
			return array;
		}

		private static bool AddScope(Collection<ScopeDebugInformation> scopes, ScopeDebugInformation scope)
		{
			//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_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			Enumerator<ScopeDebugInformation> enumerator = scopes.GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					ScopeDebugInformation current = enumerator.Current;
					if (current.HasScopes && AddScope(current.Scopes, scope))
					{
						return true;
					}
					InstructionOffset val = scope.Start;
					int offset = ((InstructionOffset)(ref val)).Offset;
					val = current.Start;
					if (offset >= ((InstructionOffset)(ref val)).Offset)
					{
						val = scope.End;
						int offset2 = ((InstructionOffset)(ref val)).Offset;
						val = current.End;
						if (offset2 <= ((InstructionOffset)(ref val)).Offset)
						{
							current.Scopes.Add(scope);
							return true;
						}
					}
				}
			}
			finally
			{
				((IDisposable)enumerator).Dispose();
			}
			return false;
		}

		private SequencePoint LineToSequencePoint(LineNumberEntry line)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: 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_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Expected O, but got Unknown
			SourceFileEntry sourceFile = symbol_file.GetSourceFile(line.File);
			return new SequencePoint(line.Offset, GetDocument(sourceFile))
			{
				StartLine = line.Row,
				EndLine = line.EndRow,
				StartColumn = line.Column,
				EndColumn = line.EndColumn
			};
		}

		public void Dispose()
		{
			symbol_file.Dispose();
		}
	}
	internal static class MethodEntryExtensions
	{
		public static bool HasColumnInfo(this MethodEntry entry)
		{
			return (entry.MethodFlags & MethodEntry.Flags.ColumnsInfoIncluded) != 0;
		}

		public static bool HasEndInfo(this MethodEntry entry)
		{
			return (entry.MethodFlags & MethodEntry.Flags.EndInfoIncluded) != 0;
		}
	}
	public sealed class MdbWriterProvider : ISymbolWriterProvider
	{
		public ISymbolWriter GetSymbolWriter(ModuleDefinition module, string fileName)
		{
			Mixin.CheckModule(module);
			Mixin.CheckFileName(fileName);
			return (ISymbolWriter)(object)new MdbWriter(module, fileName);
		}

		public ISymbolWriter GetSymbolWriter(ModuleDefinition module, Stream symbolStream)
		{
			throw new NotImplementedException();
		}
	}
	public sealed class MdbWriter : ISymbolWriter, IDisposable
	{
		private class SourceFile : ISourceFile
		{
			private readonly CompileUnitEntry compilation_unit;

			private readonly SourceFileEntry entry;

			public SourceFileEntry Entry => entry;

			public CompileUnitEntry CompilationUnit => compilation_unit;

			public SourceFile(CompileUnitEntry comp_unit, SourceFileEntry entry)
			{
				compilation_unit = comp_unit;
				this.entry = entry;
			}
		}

		private class SourceMethod : IMethodDef
		{
			private readonly MethodDefinition method;

			public string Name => ((MemberReference)method).Name;

			public int Token
			{
				get
				{
					//IL_0006: Unknown result type (might be due to invalid IL or missing references)
					//IL_000b: Unknown result type (might be due to invalid IL or missing references)
					MetadataToken metadataToken = ((MemberReference)method).MetadataToken;
					return ((MetadataToken)(ref metadataToken)).ToInt32();
				}
			}

			public SourceMethod(MethodDefinition method)
			{
				this.method = method;
			}
		}

		private readonly ModuleDefinition module;

		private readonly MonoSymbolWriter writer;

		private readonly Dictionary<string, SourceFile> source_files;

		public MdbWriter(ModuleDefinition module, string assembly)
		{
			this.module = module;
			writer = new MonoSymbolWriter(assembly);
			source_files = new Dictionary<string, SourceFile>();
		}

		public ISymbolReaderProvider GetReaderProvider()
		{
			return (ISymbolReaderProvider)(object)new MdbReaderProvider();
		}

		private SourceFile GetSourceFile(Document document)
		{
			string url = document.Url;
			if (source_files.TryGetValue(url, out var value))
			{
				return value;
			}
			SourceFileEntry sourceFileEntry = writer.DefineDocument(url, null, (document.Hash != null && document.Hash.Length == 16) ? document.Hash : null);
			value = new SourceFile(writer.DefineCompilationUnit(sourceFileEntry), sourceFileEntry);
			source_files.Add(url, value);
			return value;
		}

		private void Populate(Collection<SequencePoint> sequencePoints, int[] offsets, int[] startRows, int[] endRows, int[] startCols, int[] endCols, out SourceFile file)
		{
			SourceFile sourceFile = null;
			for (int i = 0; i < sequencePoints.Count; i++)
			{
				SequencePoint val = sequencePoints[i];
				offsets[i] = val.Offset;
				if (sourceFile == null)
				{
					sourceFile = GetSourceFile(val.Document);
				}
				startRows[i] = val.StartLine;
				endRows[i] = val.EndLine;
				startCols[i] = val.StartColumn;
				endCols[i] = val.EndColumn;
			}
			file = sourceFile;
		}

		public void Write(MethodDebugInformation info)
		{
			SourceMethod method = new SourceMethod(info.method);
			Collection<SequencePoint> sequencePoints = info.SequencePoints;
			int count = sequencePoints.Count;
			if (count != 0)
			{
				int[] array = new int[count];
				int[] array2 = new int[count];
				int[] array3 = new int[count];
				int[] array4 = new int[count];
				int[] array5 = new int[count];
				Populate(sequencePoints, array, array2, array3, array4, array5, out var file);
				SourceMethodBuilder sourceMethodBuilder = writer.OpenMethod(file.CompilationUnit, 0, method);
				for (int i = 0; i < count; i++)
				{
					sourceMethodBuilder.MarkSequencePoint(array[i], file.CompilationUnit.SourceFile, array2[i], array4[i], array3[i], array5[i], is_hidden: false);
				}
				if (info.scope != null)
				{
					WriteRootScope(info.scope, info);
				}
				writer.CloseMethod();
			}
		}

		private void WriteRootScope(ScopeDebugInformation scope, MethodDebugInformation info)
		{
			WriteScopeVariables(scope);
			if (scope.HasScopes)
			{
				WriteScopes(scope.Scopes, info);
			}
		}

		private void WriteScope(ScopeDebugInformation scope, MethodDebugInformation info)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			MonoSymbolWriter monoSymbolWriter = writer;
			InstructionOffset val = scope.Start;
			monoSymbolWriter.OpenScope(((InstructionOffset)(ref val)).Offset);
			WriteScopeVariables(scope);
			if (scope.HasScopes)
			{
				WriteScopes(scope.Scopes, info);
			}
			MonoSymbolWriter monoSymbolWriter2 = writer;
			val = scope.End;
			int end_offset;
			if (!((InstructionOffset)(ref val)).IsEndOfMethod)
			{
				val = scope.End;
				end_offset = ((InstructionOffset)(ref val)).Offset;
			}
			else
			{
				end_offset = info.code_size;
			}
			monoSymbolWriter2.CloseScope(end_offset);
		}

		private void WriteScopes(Collection<ScopeDebugInformation> scopes, MethodDebugInformation info)
		{
			for (int i = 0; i < scopes.Count; i++)
			{
				WriteScope(scopes[i], info);
			}
		}

		private void WriteScopeVariables(ScopeDebugInformation scope)
		{
			//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)
			if (!scope.HasVariables)
			{
				return;
			}
			Enumerator<VariableDebugInformation> enumerator = scope.variables.GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					VariableDebugInformation current = enumerator.Current;
					if (!string.IsNullOrEmpty(current.Name))
					{
						writer.DefineLocalVariable(current.Index, current.Name);
					}
				}
			}
			finally
			{
				((IDisposable)enumerator).Dispose();
			}
		}

		public ImageDebugHeader GetDebugHeader()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			return new ImageDebugHeader();
		}

		public void Dispose()
		{
			writer.WriteSymbolFile(module.Mvid);
		}
	}
}

BepInExPack/BepInEx/core/Mono.Cecil.Pdb.dll

Decompiled a month ago
using System;
using System.Collections;
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.InteropServices.ComTypes;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using Microsoft.Cci.Pdb;
using Mono.Cecil.Cil;
using Mono.Cecil.PE;
using Mono.Collections.Generic;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyProduct("Mono.Cecil")]
[assembly: AssemblyCopyright("Copyright © 2008 - 2018 Jb Evain")]
[assembly: ComVisible(false)]
[assembly: AssemblyFileVersion("0.11.4.0")]
[assembly: AssemblyInformationalVersion("0.11.4.0")]
[assembly: AssemblyTitle("Mono.Cecil.Pdb")]
[assembly: CLSCompliant(false)]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = "")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.11.4.0")]
[module: UnverifiableCode]
namespace Mono.Cecil.Pdb
{
	[ComImport]
	[Guid("B01FAFEB-C450-3A4D-BEEC-B4CEEC01E006")]
	[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
	internal interface ISymUnmanagedDocumentWriter
	{
		void SetSource(uint sourceSize, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)] byte[] source);

		void SetCheckSum(Guid algorithmId, uint checkSumSize, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] byte[] checkSum);
	}
	[ComImport]
	[Guid("0B97726E-9E6D-4f05-9A26-424022093CAA")]
	[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
	internal interface ISymUnmanagedWriter2
	{
		void DefineDocument([In][MarshalAs(UnmanagedType.LPWStr)] string url, [In] ref Guid langauge, [In] ref Guid languageVendor, [In] ref Guid documentType, [MarshalAs(UnmanagedType.Interface)] out ISymUnmanagedDocumentWriter pRetVal);

		void SetUserEntryPoint([In] int methodToken);

		void OpenMethod([In] int methodToken);

		void CloseMethod();

		void OpenScope([In] int startOffset, out int pRetVal);

		void CloseScope([In] int endOffset);

		void SetScopeRange_Placeholder();

		void DefineLocalVariable_Placeholder();

		void DefineParameter_Placeholder();

		void DefineField_Placeholder();

		void DefineGlobalVariable_Placeholder();

		void Close();

		void SetSymAttribute(uint parent, string name, uint data, IntPtr signature);

		void OpenNamespace([In][MarshalAs(UnmanagedType.LPWStr)] string name);

		void CloseNamespace();

		void UsingNamespace([In][MarshalAs(UnmanagedType.LPWStr)] string fullName);

		void SetMethodSourceRange_Placeholder();

		void Initialize([In][MarshalAs(UnmanagedType.IUnknown)] object emitter, [In][MarshalAs(UnmanagedType.LPWStr)] string filename, [In] IStream pIStream, [In] bool fFullBuild);

		void GetDebugInfo(out ImageDebugDirectory pIDD, [In] int cData, out int pcData, [In][Out][MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] byte[] data);

		void DefineSequencePoints([In][MarshalAs(UnmanagedType.Interface)] ISymUnmanagedDocumentWriter document, [In] int spCount, [In][MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] int[] offsets, [In][MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] int[] lines, [In][MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] int[] columns, [In][MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] int[] endLines, [In][MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] int[] endColumns);

		void RemapToken_Placeholder();

		void Initialize2_Placeholder();

		void DefineConstant_Placeholder();

		void Abort_Placeholder();

		void DefineLocalVariable2([In][MarshalAs(UnmanagedType.LPWStr)] string name, [In] int attributes, [In] int sigToken, [In] int addrKind, [In] int addr1, [In] int addr2, [In] int addr3, [In] int startOffset, [In] int endOffset);

		void DefineGlobalVariable2_Placeholder();

		void DefineConstant2([In][MarshalAs(UnmanagedType.LPWStr)] string name, [In][MarshalAs(UnmanagedType.Struct)] object variant, [In] int sigToken);
	}
	[ComImport]
	[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
	[Guid("BA3FEE4C-ECB9-4e41-83B7-183FA41CD859")]
	internal interface IMetaDataEmit
	{
		void SetModuleProps(string szName);

		void Save(string szFile, uint dwSaveFlags);

		void SaveToStream(IntPtr pIStream, uint dwSaveFlags);

		uint GetSaveSize(uint fSave);

		uint DefineTypeDef(IntPtr szTypeDef, uint dwTypeDefFlags, uint tkExtends, IntPtr rtkImplements);

		uint DefineNestedType(IntPtr szTypeDef, uint dwTypeDefFlags, uint tkExtends, IntPtr rtkImplements, uint tdEncloser);

		void SetHandler([In][MarshalAs(UnmanagedType.IUnknown)] object pUnk);

		uint DefineMethod(uint td, IntPtr zName, uint dwMethodFlags, IntPtr pvSigBlob, uint cbSigBlob, uint ulCodeRVA, uint dwImplFlags);

		void DefineMethodImpl(uint td, uint tkBody, uint tkDecl);

		uint DefineTypeRefByName(uint tkResolutionScope, IntPtr szName);

		uint DefineImportType(IntPtr pAssemImport, IntPtr pbHashValue, uint cbHashValue, IMetaDataImport pImport, uint tdImport, IntPtr pAssemEmit);

		uint DefineMemberRef(uint tkImport, string szName, IntPtr pvSigBlob, uint cbSigBlob);

		uint DefineImportMember(IntPtr pAssemImport, IntPtr pbHashValue, uint cbHashValue, IMetaDataImport pImport, uint mbMember, IntPtr pAssemEmit, uint tkParent);

		uint DefineEvent(uint td, string szEvent, uint dwEventFlags, uint tkEventType, uint mdAddOn, uint mdRemoveOn, uint mdFire, IntPtr rmdOtherMethods);

		void SetClassLayout(uint td, uint dwPackSize, IntPtr rFieldOffsets, uint ulClassSize);

		void DeleteClassLayout(uint td);

		void SetFieldMarshal(uint tk, IntPtr pvNativeType, uint cbNativeType);

		void DeleteFieldMarshal(uint tk);

		uint DefinePermissionSet(uint tk, uint dwAction, IntPtr pvPermission, uint cbPermission);

		void SetRVA(uint md, uint ulRVA);

		uint GetTokenFromSig(IntPtr pvSig, uint cbSig);

		uint DefineModuleRef(string szName);

		void SetParent(uint mr, uint tk);

		uint GetTokenFromTypeSpec(IntPtr pvSig, uint cbSig);

		void SaveToMemory(IntPtr pbData, uint cbData);

		uint DefineUserString(string szString, uint cchString);

		void DeleteToken(uint tkObj);

		void SetMethodProps(uint md, uint dwMethodFlags, uint ulCodeRVA, uint dwImplFlags);

		void SetTypeDefProps(uint td, uint dwTypeDefFlags, uint tkExtends, IntPtr rtkImplements);

		void SetEventProps(uint ev, uint dwEventFlags, uint tkEventType, uint mdAddOn, uint mdRemoveOn, uint mdFire, IntPtr rmdOtherMethods);

		uint SetPermissionSetProps(uint tk, uint dwAction, IntPtr pvPermission, uint cbPermission);

		void DefinePinvokeMap(uint tk, uint dwMappingFlags, string szImportName, uint mrImportDLL);

		void SetPinvokeMap(uint tk, uint dwMappingFlags, string szImportName, uint mrImportDLL);

		void DeletePinvokeMap(uint tk);

		uint DefineCustomAttribute(uint tkObj, uint tkType, IntPtr pCustomAttribute, uint cbCustomAttribute);

		void SetCustomAttributeValue(uint pcv, IntPtr pCustomAttribute, uint cbCustomAttribute);

		uint DefineField(uint td, string szName, uint dwFieldFlags, IntPtr pvSigBlob, uint cbSigBlob, uint dwCPlusTypeFlag, IntPtr pValue, uint cchValue);

		uint DefineProperty(uint td, string szProperty, uint dwPropFlags, IntPtr pvSig, uint cbSig, uint dwCPlusTypeFlag, IntPtr pValue, uint cchValue, uint mdSetter, uint mdGetter, IntPtr rmdOtherMethods);

		uint DefineParam(uint md, uint ulParamSeq, string szName, uint dwParamFlags, uint dwCPlusTypeFlag, IntPtr pValue, uint cchValue);

		void SetFieldProps(uint fd, uint dwFieldFlags, uint dwCPlusTypeFlag, IntPtr pValue, uint cchValue);

		void SetPropertyProps(uint pr, uint dwPropFlags, uint dwCPlusTypeFlag, IntPtr pValue, uint cchValue, uint mdSetter, uint mdGetter, IntPtr rmdOtherMethods);

		void SetParamProps(uint pd, string szName, uint dwParamFlags, uint dwCPlusTypeFlag, IntPtr pValue, uint cchValue);

		uint DefineSecurityAttributeSet(uint tkObj, IntPtr rSecAttrs, uint cSecAttrs);

		void ApplyEditAndContinue([MarshalAs(UnmanagedType.IUnknown)] object pImport);

		uint TranslateSigWithScope(IntPtr pAssemImport, IntPtr pbHashValue, uint cbHashValue, IMetaDataImport import, IntPtr pbSigBlob, uint cbSigBlob, IntPtr pAssemEmit, IMetaDataEmit emit, IntPtr pvTranslatedSig, uint cbTranslatedSigMax);

		void SetMethodImplFlags(uint md, uint dwImplFlags);

		void SetFieldRVA(uint fd, uint ulRVA);

		void Merge(IMetaDataImport pImport, IntPtr pHostMapToken, [MarshalAs(UnmanagedType.IUnknown)] object pHandler);

		void MergeEnd();
	}
	[ComImport]
	[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
	[Guid("7DAC8207-D3AE-4c75-9B67-92801A497D44")]
	internal interface IMetaDataImport
	{
		[PreserveSig]
		void CloseEnum(uint hEnum);

		uint CountEnum(uint hEnum);

		void ResetEnum(uint hEnum, uint ulPos);

		uint EnumTypeDefs(ref uint phEnum, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)] uint[] rTypeDefs, uint cMax);

		uint EnumInterfaceImpls(ref uint phEnum, uint td, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 3)] uint[] rImpls, uint cMax);

		uint EnumTypeRefs(ref uint phEnum, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)] uint[] rTypeRefs, uint cMax);

		uint FindTypeDefByName(string szTypeDef, uint tkEnclosingClass);

		Guid GetScopeProps(StringBuilder szName, uint cchName, out uint pchName);

		uint GetModuleFromScope();

		[PreserveSig]
		unsafe uint GetTypeDefProps(uint td, char* szTypeDef, uint cchTypeDef, uint* pchTypeDef, uint* pdwTypeDefFlags, uint* ptkExtends);

		uint GetInterfaceImplProps(uint iiImpl, out uint pClass);

		uint GetTypeRefProps(uint tr, out uint ptkResolutionScope, StringBuilder szName, uint cchName);

		uint ResolveTypeRef(uint tr, [In] ref Guid riid, [MarshalAs(UnmanagedType.Interface)] out object ppIScope);

		uint EnumMembers(ref uint phEnum, uint cl, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 3)] uint[] rMembers, uint cMax);

		uint EnumMembersWithName(ref uint phEnum, uint cl, string szName, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 4)] uint[] rMembers, uint cMax);

		uint EnumMethods(ref uint phEnum, uint cl, IntPtr rMethods, uint cMax);

		uint EnumMethodsWithName(ref uint phEnum, uint cl, string szName, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 4)] uint[] rMethods, uint cMax);

		uint EnumFields(ref uint phEnum, uint cl, IntPtr rFields, uint cMax);

		uint EnumFieldsWithName(ref uint phEnum, uint cl, string szName, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 4)] uint[] rFields, uint cMax);

		uint EnumParams(ref uint phEnum, uint mb, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 3)] uint[] rParams, uint cMax);

		uint EnumMemberRefs(ref uint phEnum, uint tkParent, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 3)] uint[] rMemberRefs, uint cMax);

		uint EnumMethodImpls(ref uint phEnum, uint td, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 4)] uint[] rMethodBody, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 4)] uint[] rMethodDecl, uint cMax);

		uint EnumPermissionSets(ref uint phEnum, uint tk, uint dwActions, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 4)] uint[] rPermission, uint cMax);

		uint FindMember(uint td, string szName, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 3)] byte[] pvSigBlob, uint cbSigBlob);

		uint FindMethod(uint td, string szName, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 3)] byte[] pvSigBlob, uint cbSigBlob);

		uint FindField(uint td, string szName, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 3)] byte[] pvSigBlob, uint cbSigBlob);

		uint FindMemberRef(uint td, string szName, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 3)] byte[] pvSigBlob, uint cbSigBlob);

		[PreserveSig]
		unsafe uint GetMethodProps(uint mb, uint* pClass, char* szMethod, uint cchMethod, uint* pchMethod, uint* pdwAttr, IntPtr ppvSigBlob, IntPtr pcbSigBlob, uint* pulCodeRVA, uint* pdwImplFlags);

		uint GetMemberRefProps(uint mr, ref uint ptk, StringBuilder szMember, uint cchMember, out uint pchMember, out IntPtr ppvSigBlob);

		uint EnumProperties(ref uint phEnum, uint td, IntPtr rProperties, uint cMax);

		uint EnumEvents(ref uint phEnum, uint td, IntPtr rEvents, uint cMax);

		uint GetEventProps(uint ev, out uint pClass, StringBuilder szEvent, uint cchEvent, out uint pchEvent, out uint pdwEventFlags, out uint ptkEventType, out uint pmdAddOn, out uint pmdRemoveOn, out uint pmdFire, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 11)] uint[] rmdOtherMethod, uint cMax);

		uint EnumMethodSemantics(ref uint phEnum, uint mb, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 3)] uint[] rEventProp, uint cMax);

		uint GetMethodSemantics(uint mb, uint tkEventProp);

		uint GetClassLayout(uint td, out uint pdwPackSize, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 3)] IntPtr rFieldOffset, uint cMax, out uint pcFieldOffset);

		uint GetFieldMarshal(uint tk, out IntPtr ppvNativeType);

		uint GetRVA(uint tk, out uint pulCodeRVA);

		uint GetPermissionSetProps(uint pm, out uint pdwAction, out IntPtr ppvPermission);

		uint GetSigFromToken(uint mdSig, out IntPtr ppvSig);

		uint GetModuleRefProps(uint mur, StringBuilder szName, uint cchName);

		uint EnumModuleRefs(ref uint phEnum, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)] uint[] rModuleRefs, uint cmax);

		uint GetTypeSpecFromToken(uint typespec, out IntPtr ppvSig);

		uint GetNameFromToken(uint tk);

		uint EnumUnresolvedMethods(ref uint phEnum, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)] uint[] rMethods, uint cMax);

		uint GetUserString(uint stk, StringBuilder szString, uint cchString);

		uint GetPinvokeMap(uint tk, out uint pdwMappingFlags, StringBuilder szImportName, uint cchImportName, out uint pchImportName);

		uint EnumSignatures(ref uint phEnum, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)] uint[] rSignatures, uint cmax);

		uint EnumTypeSpecs(ref uint phEnum, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)] uint[] rTypeSpecs, uint cmax);

		uint EnumUserStrings(ref uint phEnum, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)] uint[] rStrings, uint cmax);

		[PreserveSig]
		int GetParamForMethodIndex(uint md, uint ulParamSeq, out uint pParam);

		uint EnumCustomAttributes(ref uint phEnum, uint tk, uint tkType, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 4)] uint[] rCustomAttributes, uint cMax);

		uint GetCustomAttributeProps(uint cv, out uint ptkObj, out uint ptkType, out IntPtr ppBlob);

		uint FindTypeRef(uint tkResolutionScope, string szName);

		uint GetMemberProps(uint mb, out uint pClass, StringBuilder szMember, uint cchMember, out uint pchMember, out uint pdwAttr, out IntPtr ppvSigBlob, out uint pcbSigBlob, out uint pulCodeRVA, out uint pdwImplFlags, out uint pdwCPlusTypeFlag, out IntPtr ppValue);

		uint GetFieldProps(uint mb, out uint pClass, StringBuilder szField, uint cchField, out uint pchField, out uint pdwAttr, out IntPtr ppvSigBlob, out uint pcbSigBlob, out uint pdwCPlusTypeFlag, out IntPtr ppValue);

		uint GetPropertyProps(uint prop, out uint pClass, StringBuilder szProperty, uint cchProperty, out uint pchProperty, out uint pdwPropFlags, out IntPtr ppvSig, out uint pbSig, out uint pdwCPlusTypeFlag, out IntPtr ppDefaultValue, out uint pcchDefaultValue, out uint pmdSetter, out uint pmdGetter, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 14)] uint[] rmdOtherMethod, uint cMax);

		uint GetParamProps(uint tk, out uint pmd, out uint pulSequence, StringBuilder szName, uint cchName, out uint pchName, out uint pdwAttr, out uint pdwCPlusTypeFlag, out IntPtr ppValue);

		uint GetCustomAttributeByName(uint tkObj, string szName, out IntPtr ppData);

		[PreserveSig]
		[return: MarshalAs(UnmanagedType.Bool)]
		bool IsValidToken(uint tk);

		[PreserveSig]
		unsafe uint GetNestedClassProps(uint tdNestedClass, uint* ptdEnclosingClass);

		uint GetNativeCallConvFromSig(IntPtr pvSig, uint cbSig);

		int IsGlobal(uint pd);
	}
	internal class ModuleMetadata : IMetaDataEmit, IMetaDataImport
	{
		private readonly ModuleDefinition module;

		private Dictionary<uint, TypeDefinition> types;

		private Dictionary<uint, MethodDefinition> methods;

		private const uint S_OK = 0u;

		private const uint E_FAIL = 2147500037u;

		public ModuleMetadata(ModuleDefinition module)
		{
			this.module = module;
		}

		private bool TryGetType(uint token, out TypeDefinition type)
		{
			if (types == null)
			{
				InitializeMetadata(module);
			}
			return types.TryGetValue(token, out type);
		}

		private bool TryGetMethod(uint token, out MethodDefinition method)
		{
			if (methods == null)
			{
				InitializeMetadata(module);
			}
			return methods.TryGetValue(token, out method);
		}

		private void InitializeMetadata(ModuleDefinition module)
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			types = new Dictionary<uint, TypeDefinition>();
			methods = new Dictionary<uint, MethodDefinition>();
			foreach (TypeDefinition type in module.GetTypes())
			{
				Dictionary<uint, TypeDefinition> dictionary = types;
				MetadataToken metadataToken = ((MemberReference)type).MetadataToken;
				dictionary.Add(((MetadataToken)(ref metadataToken)).ToUInt32(), type);
				InitializeMethods(type);
			}
		}

		private void InitializeMethods(TypeDefinition type)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			Enumerator<MethodDefinition> enumerator = type.Methods.GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					MethodDefinition current = enumerator.Current;
					Dictionary<uint, MethodDefinition> dictionary = methods;
					MetadataToken metadataToken = ((MemberReference)current).MetadataToken;
					dictionary.Add(((MetadataToken)(ref metadataToken)).ToUInt32(), current);
				}
			}
			finally
			{
				((IDisposable)enumerator).Dispose();
			}
		}

		public void SetModuleProps(string szName)
		{
			throw new NotImplementedException();
		}

		public void Save(string szFile, uint dwSaveFlags)
		{
			throw new NotImplementedException();
		}

		public void SaveToStream(IntPtr pIStream, uint dwSaveFlags)
		{
			throw new NotImplementedException();
		}

		public uint GetSaveSize(uint fSave)
		{
			throw new NotImplementedException();
		}

		public uint DefineTypeDef(IntPtr szTypeDef, uint dwTypeDefFlags, uint tkExtends, IntPtr rtkImplements)
		{
			throw new NotImplementedException();
		}

		public uint DefineNestedType(IntPtr szTypeDef, uint dwTypeDefFlags, uint tkExtends, IntPtr rtkImplements, uint tdEncloser)
		{
			throw new NotImplementedException();
		}

		public void SetHandler(object pUnk)
		{
			throw new NotImplementedException();
		}

		public uint DefineMethod(uint td, IntPtr zName, uint dwMethodFlags, IntPtr pvSigBlob, uint cbSigBlob, uint ulCodeRVA, uint dwImplFlags)
		{
			throw new NotImplementedException();
		}

		public void DefineMethodImpl(uint td, uint tkBody, uint tkDecl)
		{
			throw new NotImplementedException();
		}

		public uint DefineTypeRefByName(uint tkResolutionScope, IntPtr szName)
		{
			throw new NotImplementedException();
		}

		public uint DefineImportType(IntPtr pAssemImport, IntPtr pbHashValue, uint cbHashValue, IMetaDataImport pImport, uint tdImport, IntPtr pAssemEmit)
		{
			throw new NotImplementedException();
		}

		public uint DefineMemberRef(uint tkImport, string szName, IntPtr pvSigBlob, uint cbSigBlob)
		{
			throw new NotImplementedException();
		}

		public uint DefineImportMember(IntPtr pAssemImport, IntPtr pbHashValue, uint cbHashValue, IMetaDataImport pImport, uint mbMember, IntPtr pAssemEmit, uint tkParent)
		{
			throw new NotImplementedException();
		}

		public uint DefineEvent(uint td, string szEvent, uint dwEventFlags, uint tkEventType, uint mdAddOn, uint mdRemoveOn, uint mdFire, IntPtr rmdOtherMethods)
		{
			throw new NotImplementedException();
		}

		public void SetClassLayout(uint td, uint dwPackSize, IntPtr rFieldOffsets, uint ulClassSize)
		{
			throw new NotImplementedException();
		}

		public void DeleteClassLayout(uint td)
		{
			throw new NotImplementedException();
		}

		public void SetFieldMarshal(uint tk, IntPtr pvNativeType, uint cbNativeType)
		{
			throw new NotImplementedException();
		}

		public void DeleteFieldMarshal(uint tk)
		{
			throw new NotImplementedException();
		}

		public uint DefinePermissionSet(uint tk, uint dwAction, IntPtr pvPermission, uint cbPermission)
		{
			throw new NotImplementedException();
		}

		public void SetRVA(uint md, uint ulRVA)
		{
			throw new NotImplementedException();
		}

		public uint GetTokenFromSig(IntPtr pvSig, uint cbSig)
		{
			throw new NotImplementedException();
		}

		public uint DefineModuleRef(string szName)
		{
			throw new NotImplementedException();
		}

		public void SetParent(uint mr, uint tk)
		{
			throw new NotImplementedException();
		}

		public uint GetTokenFromTypeSpec(IntPtr pvSig, uint cbSig)
		{
			throw new NotImplementedException();
		}

		public void SaveToMemory(IntPtr pbData, uint cbData)
		{
			throw new NotImplementedException();
		}

		public uint DefineUserString(string szString, uint cchString)
		{
			throw new NotImplementedException();
		}

		public void DeleteToken(uint tkObj)
		{
			throw new NotImplementedException();
		}

		public void SetMethodProps(uint md, uint dwMethodFlags, uint ulCodeRVA, uint dwImplFlags)
		{
			throw new NotImplementedException();
		}

		public void SetTypeDefProps(uint td, uint dwTypeDefFlags, uint tkExtends, IntPtr rtkImplements)
		{
			throw new NotImplementedException();
		}

		public void SetEventProps(uint ev, uint dwEventFlags, uint tkEventType, uint mdAddOn, uint mdRemoveOn, uint mdFire, IntPtr rmdOtherMethods)
		{
			throw new NotImplementedException();
		}

		public uint SetPermissionSetProps(uint tk, uint dwAction, IntPtr pvPermission, uint cbPermission)
		{
			throw new NotImplementedException();
		}

		public void DefinePinvokeMap(uint tk, uint dwMappingFlags, string szImportName, uint mrImportDLL)
		{
			throw new NotImplementedException();
		}

		public void SetPinvokeMap(uint tk, uint dwMappingFlags, string szImportName, uint mrImportDLL)
		{
			throw new NotImplementedException();
		}

		public void DeletePinvokeMap(uint tk)
		{
			throw new NotImplementedException();
		}

		public uint DefineCustomAttribute(uint tkObj, uint tkType, IntPtr pCustomAttribute, uint cbCustomAttribute)
		{
			throw new NotImplementedException();
		}

		public void SetCustomAttributeValue(uint pcv, IntPtr pCustomAttribute, uint cbCustomAttribute)
		{
			throw new NotImplementedException();
		}

		public uint DefineField(uint td, string szName, uint dwFieldFlags, IntPtr pvSigBlob, uint cbSigBlob, uint dwCPlusTypeFlag, IntPtr pValue, uint cchValue)
		{
			throw new NotImplementedException();
		}

		public uint DefineProperty(uint td, string szProperty, uint dwPropFlags, IntPtr pvSig, uint cbSig, uint dwCPlusTypeFlag, IntPtr pValue, uint cchValue, uint mdSetter, uint mdGetter, IntPtr rmdOtherMethods)
		{
			throw new NotImplementedException();
		}

		public uint DefineParam(uint md, uint ulParamSeq, string szName, uint dwParamFlags, uint dwCPlusTypeFlag, IntPtr pValue, uint cchValue)
		{
			throw new NotImplementedException();
		}

		public void SetFieldProps(uint fd, uint dwFieldFlags, uint dwCPlusTypeFlag, IntPtr pValue, uint cchValue)
		{
			throw new NotImplementedException();
		}

		public void SetPropertyProps(uint pr, uint dwPropFlags, uint dwCPlusTypeFlag, IntPtr pValue, uint cchValue, uint mdSetter, uint mdGetter, IntPtr rmdOtherMethods)
		{
			throw new NotImplementedException();
		}

		public void SetParamProps(uint pd, string szName, uint dwParamFlags, uint dwCPlusTypeFlag, IntPtr pValue, uint cchValue)
		{
			throw new NotImplementedException();
		}

		public uint DefineSecurityAttributeSet(uint tkObj, IntPtr rSecAttrs, uint cSecAttrs)
		{
			throw new NotImplementedException();
		}

		public void ApplyEditAndContinue(object pImport)
		{
			throw new NotImplementedException();
		}

		public uint TranslateSigWithScope(IntPtr pAssemImport, IntPtr pbHashValue, uint cbHashValue, IMetaDataImport import, IntPtr pbSigBlob, uint cbSigBlob, IntPtr pAssemEmit, IMetaDataEmit emit, IntPtr pvTranslatedSig, uint cbTranslatedSigMax)
		{
			throw new NotImplementedException();
		}

		public void SetMethodImplFlags(uint md, uint dwImplFlags)
		{
			throw new NotImplementedException();
		}

		public void SetFieldRVA(uint fd, uint ulRVA)
		{
			throw new NotImplementedException();
		}

		public void Merge(IMetaDataImport pImport, IntPtr pHostMapToken, object pHandler)
		{
			throw new NotImplementedException();
		}

		public void MergeEnd()
		{
			throw new NotImplementedException();
		}

		public void CloseEnum(uint hEnum)
		{
			throw new NotImplementedException();
		}

		public uint CountEnum(uint hEnum)
		{
			throw new NotImplementedException();
		}

		public void ResetEnum(uint hEnum, uint ulPos)
		{
			throw new NotImplementedException();
		}

		public uint EnumTypeDefs(ref uint phEnum, uint[] rTypeDefs, uint cMax)
		{
			throw new NotImplementedException();
		}

		public uint EnumInterfaceImpls(ref uint phEnum, uint td, uint[] rImpls, uint cMax)
		{
			throw new NotImplementedException();
		}

		public uint EnumTypeRefs(ref uint phEnum, uint[] rTypeRefs, uint cMax)
		{
			throw new NotImplementedException();
		}

		public uint FindTypeDefByName(string szTypeDef, uint tkEnclosingClass)
		{
			throw new NotImplementedException();
		}

		public Guid GetScopeProps(StringBuilder szName, uint cchName, out uint pchName)
		{
			throw new NotImplementedException();
		}

		public uint GetModuleFromScope()
		{
			throw new NotImplementedException();
		}

		public unsafe uint GetTypeDefProps(uint td, char* szTypeDef, uint cchTypeDef, uint* pchTypeDef, uint* pdwTypeDefFlags, uint* ptkExtends)
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Expected I4, but got Unknown
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			if (!TryGetType(td, out var type))
			{
				return 2147500037u;
			}
			WriteNameBuffer(((TypeReference)type).IsNested ? ((MemberReference)type).Name : ((MemberReference)type).FullName, szTypeDef, cchTypeDef, pchTypeDef);
			if (pdwTypeDefFlags != null)
			{
				*pdwTypeDefFlags = (uint)(int)type.Attributes;
			}
			if (ptkExtends != null)
			{
				int num;
				if (type.BaseType == null)
				{
					num = 0;
				}
				else
				{
					MetadataToken metadataToken = ((MemberReference)type.BaseType).MetadataToken;
					num = (int)((MetadataToken)(ref metadataToken)).ToUInt32();
				}
				*ptkExtends = (uint)num;
			}
			return 0u;
		}

		public uint GetInterfaceImplProps(uint iiImpl, out uint pClass)
		{
			throw new NotImplementedException();
		}

		public uint GetTypeRefProps(uint tr, out uint ptkResolutionScope, StringBuilder szName, uint cchName)
		{
			throw new NotImplementedException();
		}

		public uint ResolveTypeRef(uint tr, ref Guid riid, out object ppIScope)
		{
			throw new NotImplementedException();
		}

		public uint EnumMembers(ref uint phEnum, uint cl, uint[] rMembers, uint cMax)
		{
			throw new NotImplementedException();
		}

		public uint EnumMembersWithName(ref uint phEnum, uint cl, string szName, uint[] rMembers, uint cMax)
		{
			throw new NotImplementedException();
		}

		public uint EnumMethods(ref uint phEnum, uint cl, IntPtr rMethods, uint cMax)
		{
			throw new NotImplementedException();
		}

		public uint EnumMethodsWithName(ref uint phEnum, uint cl, string szName, uint[] rMethods, uint cMax)
		{
			throw new NotImplementedException();
		}

		public uint EnumFields(ref uint phEnum, uint cl, IntPtr rFields, uint cMax)
		{
			throw new NotImplementedException();
		}

		public uint EnumFieldsWithName(ref uint phEnum, uint cl, string szName, uint[] rFields, uint cMax)
		{
			throw new NotImplementedException();
		}

		public uint EnumParams(ref uint phEnum, uint mb, uint[] rParams, uint cMax)
		{
			throw new NotImplementedException();
		}

		public uint EnumMemberRefs(ref uint phEnum, uint tkParent, uint[] rMemberRefs, uint cMax)
		{
			throw new NotImplementedException();
		}

		public uint EnumMethodImpls(ref uint phEnum, uint td, uint[] rMethodBody, uint[] rMethodDecl, uint cMax)
		{
			throw new NotImplementedException();
		}

		public uint EnumPermissionSets(ref uint phEnum, uint tk, uint dwActions, uint[] rPermission, uint cMax)
		{
			throw new NotImplementedException();
		}

		public uint FindMember(uint td, string szName, byte[] pvSigBlob, uint cbSigBlob)
		{
			throw new NotImplementedException();
		}

		public uint FindMethod(uint td, string szName, byte[] pvSigBlob, uint cbSigBlob)
		{
			throw new NotImplementedException();
		}

		public uint FindField(uint td, string szName, byte[] pvSigBlob, uint cbSigBlob)
		{
			throw new NotImplementedException();
		}

		public uint FindMemberRef(uint td, string szName, byte[] pvSigBlob, uint cbSigBlob)
		{
			throw new NotImplementedException();
		}

		public unsafe uint GetMethodProps(uint mb, uint* pClass, char* szMethod, uint cchMethod, uint* pchMethod, uint* pdwAttr, IntPtr ppvSigBlob, IntPtr pcbSigBlob, uint* pulCodeRVA, uint* pdwImplFlags)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Expected I4, but got Unknown
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Expected I4, but got Unknown
			if (!TryGetMethod(mb, out var method))
			{
				return 2147500037u;
			}
			if (pClass != null)
			{
				MetadataToken metadataToken = ((MemberReference)method.DeclaringType).MetadataToken;
				*pClass = ((MetadataToken)(ref metadataToken)).ToUInt32();
			}
			WriteNameBuffer(((MemberReference)method).Name, szMethod, cchMethod, pchMethod);
			if (pdwAttr != null)
			{
				*pdwAttr = (uint)(int)method.Attributes;
			}
			if (pulCodeRVA != null)
			{
				*pulCodeRVA = (uint)method.RVA;
			}
			if (pdwImplFlags != null)
			{
				*pdwImplFlags = (uint)(int)method.ImplAttributes;
			}
			return 0u;
		}

		private unsafe static void WriteNameBuffer(string name, char* buffer, uint bufferLength, uint* actualLength)
		{
			long num = Math.Min(name.Length, bufferLength - 1);
			if (actualLength != null)
			{
				*actualLength = (uint)num;
			}
			if (buffer != null && bufferLength != 0)
			{
				for (int i = 0; i < num; i++)
				{
					buffer[i] = name[i];
				}
				buffer[num + 1] = '\0';
			}
		}

		public uint GetMemberRefProps(uint mr, ref uint ptk, StringBuilder szMember, uint cchMember, out uint pchMember, out IntPtr ppvSigBlob)
		{
			throw new NotImplementedException();
		}

		public uint EnumProperties(ref uint phEnum, uint td, IntPtr rProperties, uint cMax)
		{
			throw new NotImplementedException();
		}

		public uint EnumEvents(ref uint phEnum, uint td, IntPtr rEvents, uint cMax)
		{
			throw new NotImplementedException();
		}

		public uint GetEventProps(uint ev, out uint pClass, StringBuilder szEvent, uint cchEvent, out uint pchEvent, out uint pdwEventFlags, out uint ptkEventType, out uint pmdAddOn, out uint pmdRemoveOn, out uint pmdFire, uint[] rmdOtherMethod, uint cMax)
		{
			throw new NotImplementedException();
		}

		public uint EnumMethodSemantics(ref uint phEnum, uint mb, uint[] rEventProp, uint cMax)
		{
			throw new NotImplementedException();
		}

		public uint GetMethodSemantics(uint mb, uint tkEventProp)
		{
			throw new NotImplementedException();
		}

		public uint GetClassLayout(uint td, out uint pdwPackSize, IntPtr rFieldOffset, uint cMax, out uint pcFieldOffset)
		{
			throw new NotImplementedException();
		}

		public uint GetFieldMarshal(uint tk, out IntPtr ppvNativeType)
		{
			throw new NotImplementedException();
		}

		public uint GetRVA(uint tk, out uint pulCodeRVA)
		{
			throw new NotImplementedException();
		}

		public uint GetPermissionSetProps(uint pm, out uint pdwAction, out IntPtr ppvPermission)
		{
			throw new NotImplementedException();
		}

		public uint GetSigFromToken(uint mdSig, out IntPtr ppvSig)
		{
			throw new NotImplementedException();
		}

		public uint GetModuleRefProps(uint mur, StringBuilder szName, uint cchName)
		{
			throw new NotImplementedException();
		}

		public uint EnumModuleRefs(ref uint phEnum, uint[] rModuleRefs, uint cmax)
		{
			throw new NotImplementedException();
		}

		public uint GetTypeSpecFromToken(uint typespec, out IntPtr ppvSig)
		{
			throw new NotImplementedException();
		}

		public uint GetNameFromToken(uint tk)
		{
			throw new NotImplementedException();
		}

		public uint EnumUnresolvedMethods(ref uint phEnum, uint[] rMethods, uint cMax)
		{
			throw new NotImplementedException();
		}

		public uint GetUserString(uint stk, StringBuilder szString, uint cchString)
		{
			throw new NotImplementedException();
		}

		public uint GetPinvokeMap(uint tk, out uint pdwMappingFlags, StringBuilder szImportName, uint cchImportName, out uint pchImportName)
		{
			throw new NotImplementedException();
		}

		public uint EnumSignatures(ref uint phEnum, uint[] rSignatures, uint cmax)
		{
			throw new NotImplementedException();
		}

		public uint EnumTypeSpecs(ref uint phEnum, uint[] rTypeSpecs, uint cmax)
		{
			throw new NotImplementedException();
		}

		public uint EnumUserStrings(ref uint phEnum, uint[] rStrings, uint cmax)
		{
			throw new NotImplementedException();
		}

		public int GetParamForMethodIndex(uint md, uint ulParamSeq, out uint pParam)
		{
			throw new NotImplementedException();
		}

		public uint EnumCustomAttributes(ref uint phEnum, uint tk, uint tkType, uint[] rCustomAttributes, uint cMax)
		{
			throw new NotImplementedException();
		}

		public uint GetCustomAttributeProps(uint cv, out uint ptkObj, out uint ptkType, out IntPtr ppBlob)
		{
			throw new NotImplementedException();
		}

		public uint FindTypeRef(uint tkResolutionScope, string szName)
		{
			throw new NotImplementedException();
		}

		public uint GetMemberProps(uint mb, out uint pClass, StringBuilder szMember, uint cchMember, out uint pchMember, out uint pdwAttr, out IntPtr ppvSigBlob, out uint pcbSigBlob, out uint pulCodeRVA, out uint pdwImplFlags, out uint pdwCPlusTypeFlag, out IntPtr ppValue)
		{
			throw new NotImplementedException();
		}

		public uint GetFieldProps(uint mb, out uint pClass, StringBuilder szField, uint cchField, out uint pchField, out uint pdwAttr, out IntPtr ppvSigBlob, out uint pcbSigBlob, out uint pdwCPlusTypeFlag, out IntPtr ppValue)
		{
			throw new NotImplementedException();
		}

		public uint GetPropertyProps(uint prop, out uint pClass, StringBuilder szProperty, uint cchProperty, out uint pchProperty, out uint pdwPropFlags, out IntPtr ppvSig, out uint pbSig, out uint pdwCPlusTypeFlag, out IntPtr ppDefaultValue, out uint pcchDefaultValue, out uint pmdSetter, out uint pmdGetter, uint[] rmdOtherMethod, uint cMax)
		{
			throw new NotImplementedException();
		}

		public uint GetParamProps(uint tk, out uint pmd, out uint pulSequence, StringBuilder szName, uint cchName, out uint pchName, out uint pdwAttr, out uint pdwCPlusTypeFlag, out IntPtr ppValue)
		{
			throw new NotImplementedException();
		}

		public uint GetCustomAttributeByName(uint tkObj, string szName, out IntPtr ppData)
		{
			throw new NotImplementedException();
		}

		public bool IsValidToken(uint tk)
		{
			throw new NotImplementedException();
		}

		public unsafe uint GetNestedClassProps(uint tdNestedClass, uint* ptdEnclosingClass)
		{
			//IL_0028: 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)
			if (!TryGetType(tdNestedClass, out var type))
			{
				return 2147500037u;
			}
			if (ptdEnclosingClass != null)
			{
				int num;
				if (!((TypeReference)type).IsNested)
				{
					num = 0;
				}
				else
				{
					MetadataToken metadataToken = ((MemberReference)type.DeclaringType).MetadataToken;
					num = (int)((MetadataToken)(ref metadataToken)).ToUInt32();
				}
				*ptdEnclosingClass = (uint)num;
			}
			return 0u;
		}

		public uint GetNativeCallConvFromSig(IntPtr pvSig, uint cbSig)
		{
			throw new NotImplementedException();
		}

		public int IsGlobal(uint pd)
		{
			throw new NotImplementedException();
		}
	}
	public class NativePdbReader : ISymbolReader, IDisposable
	{
		private readonly Disposable<Stream> pdb_file;

		private readonly Dictionary<string, Document> documents = new Dictionary<string, Document>();

		private readonly Dictionary<uint, PdbFunction> functions = new Dictionary<uint, PdbFunction>();

		private readonly Dictionary<PdbScope, ImportDebugInformation> imports = new Dictionary<PdbScope, ImportDebugInformation>();

		internal NativePdbReader(Disposable<Stream> file)
		{
			//IL_0028: 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)
			pdb_file = file;
		}

		public ISymbolWriterProvider GetWriterProvider()
		{
			return (ISymbolWriterProvider)(object)new NativePdbWriterProvider();
		}

		public bool ProcessDebugHeader(ImageDebugHeader header)
		{
			//IL_000b: 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)
			if (!header.HasEntries)
			{
				return false;
			}
			Disposable<Stream> val = pdb_file;
			try
			{
				PdbInfo pdbInfo = PdbFile.LoadFunctions(pdb_file.value);
				ImageDebugHeaderEntry[] entries = header.Entries;
				foreach (ImageDebugHeaderEntry entry in entries)
				{
					if (IsMatchingEntry(pdbInfo, entry))
					{
						PdbFunction[] array = pdbInfo.Functions;
						foreach (PdbFunction pdbFunction in array)
						{
							functions.Add(pdbFunction.token, pdbFunction);
						}
						return true;
					}
				}
			}
			finally
			{
				((IDisposable)val).Dispose();
			}
			return false;
		}

		private static bool IsMatchingEntry(PdbInfo info, ImageDebugHeaderEntry entry)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Invalid comparison between Unknown and I4
			if ((int)entry.Directory.Type != 2)
			{
				return false;
			}
			byte[] data = entry.Data;
			if (data.Length < 24)
			{
				return false;
			}
			if (ReadInt32(data, 0) != 1396986706)
			{
				return false;
			}
			byte[] array = new byte[16];
			Buffer.BlockCopy(data, 4, array, 0, 16);
			return info.Guid == new Guid(array);
		}

		private static int ReadInt32(byte[] bytes, int start)
		{
			return bytes[start] | (bytes[start + 1] << 8) | (bytes[start + 2] << 16) | (bytes[start + 3] << 24);
		}

		public MethodDebugInformation Read(MethodDefinition method)
		{
			//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_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Expected O, but got Unknown
			//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_0043: 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_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Expected O, but got Unknown
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Expected O, but got Unknown
			//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: Unknown result type (might be due to invalid IL or missing references)
			//IL_0224: Unknown result type (might be due to invalid IL or missing references)
			//IL_022e: Expected O, but got Unknown
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Expected O, but got Unknown
			MetadataToken metadataToken = ((MemberReference)method).MetadataToken;
			if (!functions.TryGetValue(((MetadataToken)(ref metadataToken)).ToUInt32(), out var value))
			{
				return null;
			}
			MethodDebugInformation val = new MethodDebugInformation(method);
			ReadSequencePoints(value, val);
			val.scope = (ScopeDebugInformation)((!Mixin.IsNullOrEmpty<PdbScope>(value.scopes)) ? ((object)ReadScopeAndLocals(value.scopes[0], val)) : ((object)new ScopeDebugInformation
			{
				Start = new InstructionOffset(0),
				End = new InstructionOffset((int)value.length)
			}));
			uint tokenOfMethodWhoseUsingInfoAppliesToThisMethod = value.tokenOfMethodWhoseUsingInfoAppliesToThisMethod;
			MetadataToken metadataToken2 = ((MemberReference)method).MetadataToken;
			if (tokenOfMethodWhoseUsingInfoAppliesToThisMethod != ((MetadataToken)(ref metadataToken2)).ToUInt32() && value.tokenOfMethodWhoseUsingInfoAppliesToThisMethod != 0)
			{
				val.scope.import = GetImport(value.tokenOfMethodWhoseUsingInfoAppliesToThisMethod, ((MemberReference)method).Module);
			}
			if (value.scopes.Length > 1)
			{
				for (int i = 1; i < value.scopes.Length; i++)
				{
					ScopeDebugInformation val2 = ReadScopeAndLocals(value.scopes[i], val);
					if (!AddScope(val.scope.Scopes, val2))
					{
						val.scope.Scopes.Add(val2);
					}
				}
			}
			if (value.iteratorScopes != null)
			{
				StateMachineScopeDebugInformation val3 = new StateMachineScopeDebugInformation();
				foreach (ILocalScope iteratorScope in value.iteratorScopes)
				{
					val3.Scopes.Add(new StateMachineScope((int)iteratorScope.Offset, (int)(iteratorScope.Offset + iteratorScope.Length + 1)));
				}
				((DebugInformation)val).CustomDebugInformations.Add((CustomDebugInformation)(object)val3);
			}
			if (value.synchronizationInformation != null)
			{
				AsyncMethodBodyDebugInformation val4 = new AsyncMethodBodyDebugInformation((int)value.synchronizationInformation.GeneratedCatchHandlerOffset);
				PdbSynchronizationPoint[] synchronizationPoints = value.synchronizationInformation.synchronizationPoints;
				foreach (PdbSynchronizationPoint pdbSynchronizationPoint in synchronizationPoints)
				{
					val4.Yields.Add(new InstructionOffset((int)pdbSynchronizationPoint.SynchronizeOffset));
					val4.Resumes.Add(new InstructionOffset((int)pdbSynchronizationPoint.ContinuationOffset));
					val4.ResumeMethods.Add(method);
				}
				((DebugInformation)val).CustomDebugInformations.Add((CustomDebugInformation)(object)val4);
				val.StateMachineKickOffMethod = (MethodDefinition)((MemberReference)method).Module.LookupToken((int)value.synchronizationInformation.kickoffMethodToken);
			}
			return val;
		}

		private Collection<ScopeDebugInformation> ReadScopeAndLocals(PdbScope[] scopes, MethodDebugInformation info)
		{
			Collection<ScopeDebugInformation> val = new Collection<ScopeDebugInformation>(scopes.Length);
			foreach (PdbScope pdbScope in scopes)
			{
				if (pdbScope != null)
				{
					val.Add(ReadScopeAndLocals(pdbScope, info));
				}
			}
			return val;
		}

		private ScopeDebugInformation ReadScopeAndLocals(PdbScope scope, MethodDebugInformation info)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			//IL_000d: 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_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Expected O, but got Unknown
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Expected O, but got Unknown
			ScopeDebugInformation val = new ScopeDebugInformation();
			val.Start = new InstructionOffset((int)scope.offset);
			val.End = new InstructionOffset((int)(scope.offset + scope.length));
			if (!Mixin.IsNullOrEmpty<PdbSlot>(scope.slots))
			{
				val.variables = new Collection<VariableDebugInformation>(scope.slots.Length);
				PdbSlot[] slots = scope.slots;
				foreach (PdbSlot pdbSlot in slots)
				{
					if ((pdbSlot.flags & 1) == 0)
					{
						VariableDebugInformation val2 = new VariableDebugInformation((int)pdbSlot.slot, pdbSlot.name);
						if ((pdbSlot.flags & 4u) != 0)
						{
							val2.IsDebuggerHidden = true;
						}
						val.variables.Add(val2);
					}
				}
			}
			if (!Mixin.IsNullOrEmpty<PdbConstant>(scope.constants))
			{
				val.constants = new Collection<ConstantDebugInformation>(scope.constants.Length);
				PdbConstant[] constants = scope.constants;
				foreach (PdbConstant pdbConstant in constants)
				{
					TypeReference val3 = ((MemberReference)info.Method).Module.Read<PdbConstant, TypeReference>(pdbConstant, (Func<PdbConstant, MetadataReader, TypeReference>)((PdbConstant c, MetadataReader r) => r.ReadConstantSignature(new MetadataToken(c.token))));
					object obj = pdbConstant.value;
					if (val3 != null && !val3.IsValueType && obj is int && (int)obj == 0)
					{
						obj = null;
					}
					val.constants.Add(new ConstantDebugInformation(pdbConstant.name, val3, obj));
				}
			}
			if (!Mixin.IsNullOrEmpty<string>(scope.usedNamespaces))
			{
				if (imports.TryGetValue(scope, out var value))
				{
					val.import = value;
				}
				else
				{
					value = GetImport(scope, ((MemberReference)info.Method).Module);
					imports.Add(scope, value);
					val.import = value;
				}
			}
			val.scopes = ReadScopeAndLocals(scope.scopes, info);
			return val;
		}

		private static bool AddScope(Collection<ScopeDebugInformation> scopes, ScopeDebugInformation scope)
		{
			//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_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			Enumerator<ScopeDebugInformation> enumerator = scopes.GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					ScopeDebugInformation current = enumerator.Current;
					if (current.HasScopes && AddScope(current.Scopes, scope))
					{
						return true;
					}
					InstructionOffset val = scope.Start;
					int offset = ((InstructionOffset)(ref val)).Offset;
					val = current.Start;
					if (offset >= ((InstructionOffset)(ref val)).Offset)
					{
						val = scope.End;
						int offset2 = ((InstructionOffset)(ref val)).Offset;
						val = current.End;
						if (offset2 <= ((InstructionOffset)(ref val)).Offset)
						{
							current.Scopes.Add(scope);
							return true;
						}
					}
				}
			}
			finally
			{
				((IDisposable)enumerator).Dispose();
			}
			return false;
		}

		private ImportDebugInformation GetImport(uint token, ModuleDefinition module)
		{
			if (!functions.TryGetValue(token, out var value))
			{
				return null;
			}
			if (value.scopes.Length != 1)
			{
				return null;
			}
			PdbScope pdbScope = value.scopes[0];
			if (imports.TryGetValue(pdbScope, out var value2))
			{
				return value2;
			}
			value2 = GetImport(pdbScope, module);
			imports.Add(pdbScope, value2);
			return value2;
		}

		private static ImportDebugInformation GetImport(PdbScope scope, ModuleDefinition module)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Expected O, but got Unknown
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Expected O, but got Unknown
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Expected O, but got Unknown
			//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_00b0: Expected O, but got Unknown
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Expected O, but got Unknown
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Expected O, but got Unknown
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Expected O, but got Unknown
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Expected O, but got Unknown
			if (Mixin.IsNullOrEmpty<string>(scope.usedNamespaces))
			{
				return null;
			}
			ImportDebugInformation val = new ImportDebugInformation();
			string[] usedNamespaces = scope.usedNamespaces;
			foreach (string text in usedNamespaces)
			{
				if (string.IsNullOrEmpty(text))
				{
					continue;
				}
				ImportTarget val2 = null;
				string text2 = text.Substring(1);
				switch (text[0])
				{
				case 'U':
					val2 = new ImportTarget((ImportTargetKind)1)
					{
						@namespace = text2
					};
					break;
				case 'T':
				{
					TypeReference val4 = TypeParser.ParseType(module, text2, false);
					if (val4 != null)
					{
						val2 = new ImportTarget((ImportTargetKind)3)
						{
							type = val4
						};
					}
					break;
				}
				case 'A':
				{
					int num = text.IndexOf(' ');
					if (num < 0)
					{
						val2 = new ImportTarget((ImportTargetKind)1)
						{
							@namespace = text
						};
						break;
					}
					string alias = text.Substring(1, num - 1);
					string text3 = text.Substring(num + 2);
					switch (text[num + 1])
					{
					case 'U':
						val2 = new ImportTarget((ImportTargetKind)7)
						{
							alias = alias,
							@namespace = text3
						};
						break;
					case 'T':
					{
						TypeReference val3 = TypeParser.ParseType(module, text3, false);
						if (val3 != null)
						{
							val2 = new ImportTarget((ImportTargetKind)9)
							{
								alias = alias,
								type = val3
							};
						}
						break;
					}
					}
					break;
				}
				case '*':
					val2 = new ImportTarget((ImportTargetKind)1)
					{
						@namespace = text2
					};
					break;
				case '@':
					if (!text2.StartsWith("P:"))
					{
						continue;
					}
					val2 = new ImportTarget((ImportTargetKind)1)
					{
						@namespace = text2.Substring(2)
					};
					break;
				}
				if (val2 != null)
				{
					val.Targets.Add(val2);
				}
			}
			return val;
		}

		private void ReadSequencePoints(PdbFunction function, MethodDebugInformation info)
		{
			if (function.lines != null)
			{
				info.sequence_points = new Collection<SequencePoint>();
				PdbLines[] lines = function.lines;
				foreach (PdbLines lines2 in lines)
				{
					ReadLines(lines2, info);
				}
			}
		}

		private void ReadLines(PdbLines lines, MethodDebugInformation info)
		{
			Document document = GetDocument(lines.file);
			PdbLine[] lines2 = lines.lines;
			for (int i = 0; i < lines2.Length; i++)
			{
				ReadLine(lines2[i], document, info);
			}
		}

		private static void ReadLine(PdbLine line, Document document, MethodDebugInformation info)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Expected O, but got Unknown
			SequencePoint val = new SequencePoint((int)line.offset, document);
			val.StartLine = (int)line.lineBegin;
			val.StartColumn = line.colBegin;
			val.EndLine = (int)line.lineEnd;
			val.EndColumn = line.colEnd;
			info.sequence_points.Add(val);
		}

		private Document GetDocument(PdbSource source)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: 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_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Expected O, but got Unknown
			string name = source.name;
			if (documents.TryGetValue(name, out var value))
			{
				return value;
			}
			value = new Document(name)
			{
				LanguageGuid = source.language,
				LanguageVendorGuid = source.vendor,
				TypeGuid = source.doctype,
				HashAlgorithmGuid = source.checksumAlgorithm,
				Hash = source.checksum
			};
			documents.Add(name, value);
			return value;
		}

		public void Dispose()
		{
			//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)
			pdb_file.Dispose();
		}
	}
	public class NativePdbWriter : ISymbolWriter, IDisposable
	{
		private readonly ModuleDefinition module;

		private readonly MetadataBuilder metadata;

		private readonly SymWriter writer;

		private readonly Dictionary<string, SymDocumentWriter> documents;

		private readonly Dictionary<ImportDebugInformation, MetadataToken> import_info_to_parent;

		internal NativePdbWriter(ModuleDefinition module, SymWriter writer)
		{
			this.module = module;
			metadata = module.metadata_builder;
			this.writer = writer;
			documents = new Dictionary<string, SymDocumentWriter>();
			import_info_to_parent = new Dictionary<ImportDebugInformation, MetadataToken>();
		}

		public ISymbolReaderProvider GetReaderProvider()
		{
			return (ISymbolReaderProvider)(object)new NativePdbReaderProvider();
		}

		public ImageDebugHeader GetDebugHeader()
		{
			//IL_0020: 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_002c: Expected O, but got Unknown
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected O, but got Unknown
			ImageDebugDirectory idd;
			byte[] debugInfo = writer.GetDebugInfo(out idd);
			idd.TimeDateStamp = (int)module.timestamp;
			return new ImageDebugHeader(new ImageDebugHeaderEntry(idd, debugInfo));
		}

		public void Write(MethodDebugInformation info)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: 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)
			MetadataToken metadataToken = ((MemberReference)info.method).MetadataToken;
			int methodToken = ((MetadataToken)(ref metadataToken)).ToInt32();
			if (info.HasSequencePoints || info.scope != null || ((DebugInformation)info).HasCustomDebugInformations || info.StateMachineKickOffMethod != null)
			{
				writer.OpenMethod(methodToken);
				if (!Mixin.IsNullOrEmpty<SequencePoint>(info.sequence_points))
				{
					DefineSequencePoints(info.sequence_points);
				}
				MetadataToken import_parent = default(MetadataToken);
				if (info.scope != null)
				{
					DefineScope(info.scope, info, out import_parent);
				}
				DefineCustomMetadata(info, import_parent);
				writer.CloseMethod();
			}
		}

		private void DefineCustomMetadata(MethodDebugInformation info, MetadataToken import_parent)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			CustomMetadataWriter customMetadataWriter = new CustomMetadataWriter(writer);
			if (((MetadataToken)(ref import_parent)).RID != 0)
			{
				customMetadataWriter.WriteForwardInfo(import_parent);
			}
			else if (info.scope != null && info.scope.Import != null && info.scope.Import.HasTargets)
			{
				customMetadataWriter.WriteUsingInfo(info.scope.Import);
			}
			if (info.Method.HasCustomAttributes)
			{
				Enumerator<CustomAttribute> enumerator = info.Method.CustomAttributes.GetEnumerator();
				try
				{
					while (enumerator.MoveNext())
					{
						CustomAttribute current = enumerator.Current;
						TypeReference attributeType = current.AttributeType;
						if (Mixin.IsTypeOf(attributeType, "System.Runtime.CompilerServices", "IteratorStateMachineAttribute") || Mixin.IsTypeOf(attributeType, "System.Runtime.CompilerServices", "AsyncStateMachineAttribute"))
						{
							CustomAttributeArgument val = current.ConstructorArguments[0];
							object value = ((CustomAttributeArgument)(ref val)).Value;
							TypeReference val2 = (TypeReference)((value is TypeReference) ? value : null);
							if (val2 != null)
							{
								customMetadataWriter.WriteForwardIterator(val2);
							}
						}
					}
				}
				finally
				{
					((IDisposable)enumerator).Dispose();
				}
			}
			if (((DebugInformation)info).HasCustomDebugInformations)
			{
				CustomDebugInformation? obj = ((IEnumerable<CustomDebugInformation>)((DebugInformation)info).CustomDebugInformations).FirstOrDefault((Func<CustomDebugInformation, bool>)((CustomDebugInformation cdi) => (int)cdi.Kind == 1));
				StateMachineScopeDebugInformation val3 = (StateMachineScopeDebugInformation)(object)((obj is StateMachineScopeDebugInformation) ? obj : null);
				if (val3 != null)
				{
					customMetadataWriter.WriteIteratorScopes(val3, info);
				}
			}
			customMetadataWriter.WriteCustomMetadata();
			DefineAsyncCustomMetadata(info);
		}

		private void DefineAsyncCustomMetadata(MethodDebugInformation info)
		{
			//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_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Expected O, but got Unknown
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: 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)
			if (!((DebugInformation)info).HasCustomDebugInformations)
			{
				return;
			}
			Enumerator<CustomDebugInformation> enumerator = ((DebugInformation)info).CustomDebugInformations.GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					CustomDebugInformation current = enumerator.Current;
					AsyncMethodBodyDebugInformation val = (AsyncMethodBodyDebugInformation)(object)((current is AsyncMethodBodyDebugInformation) ? current : null);
					if (val == null)
					{
						continue;
					}
					using MemoryStream memoryStream = new MemoryStream();
					BinaryStreamWriter val2 = new BinaryStreamWriter((Stream)memoryStream);
					int num;
					MetadataToken metadataToken;
					if (info.StateMachineKickOffMethod == null)
					{
						num = 0;
					}
					else
					{
						metadataToken = ((MemberReference)info.StateMachineKickOffMethod).MetadataToken;
						num = (int)((MetadataToken)(ref metadataToken)).ToUInt32();
					}
					val2.WriteUInt32((uint)num);
					InstructionOffset val3 = val.CatchHandler;
					val2.WriteUInt32((uint)((InstructionOffset)(ref val3)).Offset);
					val2.WriteUInt32((uint)val.Resumes.Count);
					for (int i = 0; i < val.Resumes.Count; i++)
					{
						val3 = val.Yields[i];
						val2.WriteUInt32((uint)((InstructionOffset)(ref val3)).Offset);
						metadataToken = ((MemberReference)val.resume_methods[i]).MetadataToken;
						val2.WriteUInt32(((MetadataToken)(ref metadataToken)).ToUInt32());
						val3 = val.Resumes[i];
						val2.WriteUInt32((uint)((InstructionOffset)(ref val3)).Offset);
					}
					writer.DefineCustomMetadata("asyncMethodInfo", memoryStream.ToArray());
				}
			}
			finally
			{
				((IDisposable)enumerator).Dispose();
			}
		}

		private void DefineScope(ScopeDebugInformation scope, MethodDebugInformation info, out MetadataToken import_parent)
		{
			//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_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Invalid comparison between Unknown and I4
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Invalid comparison between Unknown and I4
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Invalid comparison between Unknown and I4
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Invalid comparison between Unknown and I4
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Invalid comparison between Unknown and I4
			InstructionOffset val = scope.Start;
			int offset = ((InstructionOffset)(ref val)).Offset;
			val = scope.End;
			int num;
			if (!((InstructionOffset)(ref val)).IsEndOfMethod)
			{
				val = scope.End;
				num = ((InstructionOffset)(ref val)).Offset;
			}
			else
			{
				num = info.code_size;
			}
			int num2 = num;
			import_parent = new MetadataToken(0u);
			writer.OpenScope(offset);
			if (scope.Import != null && scope.Import.HasTargets && !import_info_to_parent.TryGetValue(info.scope.Import, out import_parent))
			{
				Enumerator<ImportTarget> enumerator = scope.Import.Targets.GetEnumerator();
				try
				{
					while (enumerator.MoveNext())
					{
						ImportTarget current = enumerator.Current;
						ImportTargetKind kind = current.Kind;
						if ((int)kind <= 3)
						{
							if ((int)kind != 1)
							{
								if ((int)kind == 3)
								{
									writer.UsingNamespace("T" + TypeParser.ToParseable(current.type, true));
								}
							}
							else
							{
								writer.UsingNamespace("U" + current.@namespace);
							}
						}
						else if ((int)kind != 7)
						{
							if ((int)kind == 9)
							{
								writer.UsingNamespace("A" + current.Alias + " T" + TypeParser.ToParseable(current.type, true));
							}
						}
						else
						{
							writer.UsingNamespace("A" + current.Alias + " U" + current.@namespace);
						}
					}
				}
				finally
				{
					((IDisposable)enumerator).Dispose();
				}
				import_info_to_parent.Add(info.scope.Import, ((MemberReference)info.method).MetadataToken);
			}
			int local_var_token = ((MetadataToken)(ref info.local_var_token)).ToInt32();
			if (!Mixin.IsNullOrEmpty<VariableDebugInformation>(scope.variables))
			{
				for (int i = 0; i < scope.variables.Count; i++)
				{
					VariableDebugInformation variable = scope.variables[i];
					DefineLocalVariable(variable, local_var_token, offset, num2);
				}
			}
			if (!Mixin.IsNullOrEmpty<ConstantDebugInformation>(scope.constants))
			{
				for (int j = 0; j < scope.constants.Count; j++)
				{
					ConstantDebugInformation constant = scope.constants[j];
					DefineConstant(constant);
				}
			}
			if (!Mixin.IsNullOrEmpty<ScopeDebugInformation>(scope.scopes))
			{
				for (int k = 0; k < scope.scopes.Count; k++)
				{
					DefineScope(scope.scopes[k], info, out var _);
				}
			}
			writer.CloseScope(num2);
		}

		private void DefineSequencePoints(Collection<SequencePoint> sequence_points)
		{
			for (int i = 0; i < sequence_points.Count; i++)
			{
				SequencePoint val = sequence_points[i];
				writer.DefineSequencePoints(GetDocument(val.Document), new int[1] { val.Offset }, new int[1] { val.StartLine }, new int[1] { val.StartColumn }, new int[1] { val.EndLine }, new int[1] { val.EndColumn });
			}
		}

		private void DefineLocalVariable(VariableDebugInformation variable, int local_var_token, int start_offset, int end_offset)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			writer.DefineLocalVariable2(variable.Name, variable.Attributes, local_var_token, variable.Index, 0, 0, start_offset, end_offset);
		}

		private void DefineConstant(ConstantDebugInformation constant)
		{
			uint num = metadata.AddStandAloneSignature(metadata.GetConstantTypeBlobIndex(constant.ConstantType));
			MetadataToken val = default(MetadataToken);
			((MetadataToken)(ref val))..ctor((TokenType)285212672, num);
			writer.DefineConstant2(constant.Name, constant.Value, ((MetadataToken)(ref val)).ToInt32());
		}

		private SymDocumentWriter GetDocument(Document document)
		{
			if (document == null)
			{
				return null;
			}
			if (documents.TryGetValue(document.Url, out var value))
			{
				return value;
			}
			value = writer.DefineDocument(document.Url, document.LanguageGuid, document.LanguageVendorGuid, document.TypeGuid);
			if (!Mixin.IsNullOrEmpty<byte>(document.Hash))
			{
				value.SetCheckSum(document.HashAlgorithmGuid, document.Hash);
			}
			documents[document.Url] = value;
			return value;
		}

		public void Dispose()
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			MethodDefinition entryPoint = module.EntryPoint;
			if (entryPoint != null)
			{
				SymWriter symWriter = writer;
				MetadataToken metadataToken = ((MemberReference)entryPoint).MetadataToken;
				symWriter.SetUserEntryPoint(((MetadataToken)(ref metadataToken)).ToInt32());
			}
			writer.Close();
		}
	}
	internal enum CustomMetadataType : byte
	{
		UsingInfo = 0,
		ForwardInfo = 1,
		IteratorScopes = 3,
		ForwardIterator = 4
	}
	internal class CustomMetadataWriter : IDisposable
	{
		private readonly SymWriter sym_writer;

		private readonly MemoryStream stream;

		private readonly BinaryStreamWriter writer;

		private int count;

		private const byte version = 4;

		public CustomMetadataWriter(SymWriter sym_writer)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Expected O, but got Unknown
			this.sym_writer = sym_writer;
			stream = new MemoryStream();
			writer = new BinaryStreamWriter((Stream)stream);
			writer.WriteByte((byte)4);
			writer.WriteByte((byte)0);
			writer.Align(4);
		}

		public void WriteUsingInfo(ImportDebugInformation import_info)
		{
			Write(CustomMetadataType.UsingInfo, delegate
			{
				writer.WriteUInt16((ushort)1);
				writer.WriteUInt16((ushort)import_info.Targets.Count);
			});
		}

		public void WriteForwardInfo(MetadataToken import_parent)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			Write(CustomMetadataType.ForwardInfo, delegate
			{
				writer.WriteUInt32(((MetadataToken)(ref import_parent)).ToUInt32());
			});
		}

		public void WriteIteratorScopes(StateMachineScopeDebugInformation state_machine, MethodDebugInformation debug_info)
		{
			Write(CustomMetadataType.IteratorScopes, delegate
			{
				//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_0034: Unknown result type (might be due to invalid IL or missing references)
				//IL_0039: Unknown result type (might be due to invalid IL or missing references)
				//IL_0044: Unknown result type (might be due to invalid IL or missing references)
				//IL_0049: Unknown result type (might be due to invalid IL or missing references)
				//IL_0055: 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)
				Collection<StateMachineScope> scopes = state_machine.Scopes;
				writer.WriteInt32(scopes.Count);
				Enumerator<StateMachineScope> enumerator = scopes.GetEnumerator();
				try
				{
					while (enumerator.MoveNext())
					{
						StateMachineScope current = enumerator.Current;
						InstructionOffset val = current.Start;
						int offset = ((InstructionOffset)(ref val)).Offset;
						val = current.End;
						int num;
						if (!((InstructionOffset)(ref val)).IsEndOfMethod)
						{
							val = current.End;
							num = ((InstructionOffset)(ref val)).Offset;
						}
						else
						{
							num = debug_info.code_size;
						}
						int num2 = num;
						writer.WriteInt32(offset);
						writer.WriteInt32(num2 - 1);
					}
				}
				finally
				{
					((IDisposable)enumerator).Dispose();
				}
			});
		}

		public void WriteForwardIterator(TypeReference type)
		{
			Write(CustomMetadataType.ForwardIterator, delegate
			{
				writer.WriteBytes(Encoding.Unicode.GetBytes(((MemberReference)type).Name));
			});
		}

		private void Write(CustomMetadataType type, Action write)
		{
			count++;
			writer.WriteByte((byte)4);
			writer.WriteByte((byte)type);
			writer.Align(4);
			int position = writer.Position;
			writer.WriteUInt32(0u);
			write();
			writer.Align(4);
			int position2 = writer.Position;
			int num = position2 - position + 4;
			writer.Position = position;
			writer.WriteInt32(num);
			writer.Position = position2;
		}

		public void WriteCustomMetadata()
		{
			if (count != 0)
			{
				((BinaryWriter)(object)writer).BaseStream.Position = 1L;
				writer.WriteByte((byte)count);
				((BinaryWriter)(object)writer).Flush();
				sym_writer.DefineCustomMetadata("MD2", stream.ToArray());
			}
		}

		public void Dispose()
		{
			stream.Dispose();
		}
	}
	public sealed class NativePdbReaderProvider : ISymbolReaderProvider
	{
		public ISymbolReader GetSymbolReader(ModuleDefinition module, string fileName)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			Mixin.CheckModule(module);
			Mixin.CheckFileName(fileName);
			return (ISymbolReader)(object)new NativePdbReader(Disposable.Owned<Stream>((Stream)File.OpenRead(Mixin.GetPdbFileName(fileName))));
		}

		public ISymbolReader GetSymbolReader(ModuleDefinition module, Stream symbolStream)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			Mixin.CheckModule(module);
			Mixin.CheckStream((object)symbolStream);
			return (ISymbolReader)(object)new NativePdbReader(Disposable.NotOwned<Stream>(symbolStream));
		}
	}
	public sealed class PdbReaderProvider : ISymbolReaderProvider
	{
		public ISymbolReader GetSymbolReader(ModuleDefinition module, string fileName)
		{
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			Mixin.CheckModule(module);
			if (module.HasDebugHeader && Mixin.GetEmbeddedPortablePdbEntry(module.GetDebugHeader()) != null)
			{
				return new EmbeddedPortablePdbReaderProvider().GetSymbolReader(module, fileName);
			}
			Mixin.CheckFileName(fileName);
			if (!Mixin.IsPortablePdb(Mixin.GetPdbFileName(fileName)))
			{
				return new NativePdbReaderProvider().GetSymbolReader(module, fileName);
			}
			return new PortablePdbReaderProvider().GetSymbolReader(module, fileName);
		}

		public ISymbolReader GetSymbolReader(ModuleDefinition module, Stream symbolStream)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			Mixin.CheckModule(module);
			Mixin.CheckStream((object)symbolStream);
			Mixin.CheckReadSeek(symbolStream);
			if (!Mixin.IsPortablePdb(symbolStream))
			{
				return new NativePdbReaderProvider().GetSymbolReader(module, symbolStream);
			}
			return new PortablePdbReaderProvider().GetSymbolReader(module, symbolStream);
		}
	}
	public sealed class NativePdbWriterProvider : ISymbolWriterProvider
	{
		public ISymbolWriter GetSymbolWriter(ModuleDefinition module, string fileName)
		{
			Mixin.CheckModule(module);
			Mixin.CheckFileName(fileName);
			return (ISymbolWriter)(object)new NativePdbWriter(module, CreateWriter(module, Mixin.GetPdbFileName(fileName)));
		}

		private static SymWriter CreateWriter(ModuleDefinition module, string pdb)
		{
			SymWriter symWriter = new SymWriter();
			if (File.Exists(pdb))
			{
				File.Delete(pdb);
			}
			symWriter.Initialize(new ModuleMetadata(module), pdb, fFullBuild: true);
			return symWriter;
		}

		public ISymbolWriter GetSymbolWriter(ModuleDefinition module, Stream symbolStream)
		{
			throw new NotImplementedException();
		}
	}
	public sealed class PdbWriterProvider : ISymbolWriterProvider
	{
		public ISymbolWriter GetSymbolWriter(ModuleDefinition module, string fileName)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			Mixin.CheckModule(module);
			Mixin.CheckFileName(fileName);
			if (HasPortablePdbSymbols(module))
			{
				return new PortablePdbWriterProvider().GetSymbolWriter(module, fileName);
			}
			return new NativePdbWriterProvider().GetSymbolWriter(module, fileName);
		}

		private static bool HasPortablePdbSymbols(ModuleDefinition module)
		{
			if (module.symbol_reader != null)
			{
				return module.symbol_reader is PortablePdbReader;
			}
			return false;
		}

		public ISymbolWriter GetSymbolWriter(ModuleDefinition module, Stream symbolStream)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			Mixin.CheckModule(module);
			Mixin.CheckStream((object)symbolStream);
			Mixin.CheckReadSeek(symbolStream);
			if (HasPortablePdbSymbols(module))
			{
				return new PortablePdbWriterProvider().GetSymbolWriter(module, symbolStream);
			}
			return new NativePdbWriterProvider().GetSymbolWriter(module, symbolStream);
		}
	}
	internal class SymDocumentWriter
	{
		private readonly ISymUnmanagedDocumentWriter writer;

		public ISymUnmanagedDocumentWriter Writer => writer;

		public SymDocumentWriter(ISymUnmanagedDocumentWriter writer)
		{
			this.writer = writer;
		}

		public void SetSource(byte[] source)
		{
			writer.SetSource((uint)source.Length, source);
		}

		public void SetCheckSum(Guid hashAlgo, byte[] checkSum)
		{
			writer.SetCheckSum(hashAlgo, (uint)checkSum.Length, checkSum);
		}
	}
	internal class SymWriter
	{
		private static Guid s_symUnmangedWriterIID = new Guid("0b97726e-9e6d-4f05-9a26-424022093caa");

		private static Guid s_CorSymWriter_SxS_ClassID = new Guid("108296c1-281e-11d3-bd22-0000f80849bd");

		private readonly ISymUnmanagedWriter2 writer;

		private readonly Collection<ISymUnmanagedDocumentWriter> documents;

		[DllImport("ole32.dll")]
		private static extern int CoCreateInstance([In] ref Guid rclsid, [In][MarshalAs(UnmanagedType.IUnknown)] object pUnkOuter, [In] uint dwClsContext, [In] ref Guid riid, [MarshalAs(UnmanagedType.Interface)] out object ppv);

		public SymWriter()
		{
			CoCreateInstance(ref s_CorSymWriter_SxS_ClassID, null, 1u, ref s_symUnmangedWriterIID, out var ppv);
			writer = (ISymUnmanagedWriter2)ppv;
			documents = new Collection<ISymUnmanagedDocumentWriter>();
		}

		public byte[] GetDebugInfo(out ImageDebugDirectory idd)
		{
			writer.GetDebugInfo(out idd, 0, out var pcData, null);
			byte[] array = new byte[pcData];
			writer.GetDebugInfo(out idd, pcData, out pcData, array);
			return array;
		}

		public void DefineLocalVariable2(string name, VariableAttributes attributes, int sigToken, int addr1, int addr2, int addr3, int startOffset, int endOffset)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Expected I4, but got Unknown
			writer.DefineLocalVariable2(name, (int)attributes, sigToken, 1, addr1, addr2, addr3, startOffset, endOffset);
		}

		public void DefineConstant2(string name, object value, int sigToken)
		{
			if (value == null)
			{
				writer.DefineConstant2(name, 0, sigToken);
			}
			else
			{
				writer.DefineConstant2(name, value, sigToken);
			}
		}

		public void Close()
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			writer.Close();
			Marshal.ReleaseComObject(writer);
			Enumerator<ISymUnmanagedDocumentWriter> enumerator = documents.GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					Marshal.ReleaseComObject(enumerator.Current);
				}
			}
			finally
			{
				((IDisposable)enumerator).Dispose();
			}
		}

		public void CloseMethod()
		{
			writer.CloseMethod();
		}

		public void CloseNamespace()
		{
			writer.CloseNamespace();
		}

		public void CloseScope(int endOffset)
		{
			writer.CloseScope(endOffset);
		}

		public SymDocumentWriter DefineDocument(string url, Guid language, Guid languageVendor, Guid documentType)
		{
			writer.DefineDocument(url, ref language, ref languageVendor, ref documentType, out var pRetVal);
			documents.Add(pRetVal);
			return new SymDocumentWriter(pRetVal);
		}

		public void DefineSequencePoints(SymDocumentWriter document, int[] offsets, int[] lines, int[] columns, int[] endLines, int[] endColumns)
		{
			writer.DefineSequencePoints(document.Writer, offsets.Length, offsets, lines, columns, endLines, endColumns);
		}

		public void Initialize(object emitter, string filename, bool fFullBuild)
		{
			writer.Initialize(emitter, filename, null, fFullBuild);
		}

		public void SetUserEntryPoint(int methodToken)
		{
			writer.SetUserEntryPoint(methodToken);
		}

		public void OpenMethod(int methodToken)
		{
			writer.OpenMethod(methodToken);
		}

		public void OpenNamespace(string name)
		{
			writer.OpenNamespace(name);
		}

		public int OpenScope(int startOffset)
		{
			writer.OpenScope(startOffset, out var pRetVal);
			return pRetVal;
		}

		public void UsingNamespace(string fullName)
		{
			writer.UsingNamespace(fullName);
		}

		public void DefineCustomMetadata(string name, byte[] metadata)
		{
			GCHandle gCHandle = GCHandle.Alloc(metadata, GCHandleType.Pinned);
			writer.SetSymAttribute(0u, name, (uint)metadata.Length, gCHandle.AddrOfPinnedObject());
			gCHandle.Free();
		}
	}
}
namespace Microsoft.Cci.Pdb
{
	internal class BitAccess
	{
		private byte[] buffer;

		private int offset;

		internal byte[] Buffer => buffer;

		internal int Position
		{
			get
			{
				return offset;
			}
			set
			{
				offset = value;
			}
		}

		internal BitAccess(int capacity)
		{
			buffer = new byte[capacity];
		}

		internal BitAccess(byte[] buffer)
		{
			this.buffer = buffer;
			offset = 0;
		}

		internal void FillBuffer(Stream stream, int capacity)
		{
			MinCapacity(capacity);
			stream.Read(buffer, 0, capacity);
			offset = 0;
		}

		internal void Append(Stream stream, int count)
		{
			int num = offset + count;
			if (buffer.Length < num)
			{
				byte[] destinationArray = new byte[num];
				Array.Copy(buffer, destinationArray, buffer.Length);
				buffer = destinationArray;
			}
			stream.Read(buffer, offset, count);
			offset += count;
		}

		internal void MinCapacity(int capacity)
		{
			if (buffer.Length < capacity)
			{
				buffer = new byte[capacity];
			}
			offset = 0;
		}

		internal void Align(int alignment)
		{
			while (offset % alignment != 0)
			{
				offset++;
			}
		}

		internal void ReadInt16(out short value)
		{
			value = (short)((buffer[offset] & 0xFF) | (buffer[offset + 1] << 8));
			offset += 2;
		}

		internal void ReadInt8(out sbyte value)
		{
			value = (sbyte)buffer[offset];
			offset++;
		}

		internal void ReadInt32(out int value)
		{
			value = (buffer[offset] & 0xFF) | (buffer[offset + 1] << 8) | (buffer[offset + 2] << 16) | (buffer[offset + 3] << 24);
			offset += 4;
		}

		internal void ReadInt64(out long value)
		{
			value = ((long)buffer[offset] & 0xFFL) | (long)((ulong)buffer[offset + 1] << 8) | (long)((ulong)buffer[offset + 2] << 16) | (long)((ulong)buffer[offset + 3] << 24) | (long)((ulong)buffer[offset + 4] << 32) | (long)((ulong)buffer[offset + 5] << 40) | (long)((ulong)buffer[offset + 6] << 48) | (long)((ulong)buffer[offset + 7] << 56);
			offset += 8;
		}

		internal void ReadUInt16(out ushort value)
		{
			value = (ushort)((buffer[offset] & 0xFFu) | (uint)(buffer[offset + 1] << 8));
			offset += 2;
		}

		internal void ReadUInt8(out byte value)
		{
			value = (byte)(buffer[offset] & 0xFFu);
			offset++;
		}

		internal void ReadUInt32(out uint value)
		{
			value = (buffer[offset] & 0xFFu) | (uint)(buffer[offset + 1] << 8) | (uint)(buffer[offset + 2] << 16) | (uint)(buffer[offset + 3] << 24);
			offset += 4;
		}

		internal void ReadUInt64(out ulong value)
		{
			value = ((ulong)buffer[offset] & 0xFFuL) | ((ulong)buffer[offset + 1] << 8) | ((ulong)buffer[offset + 2] << 16) | ((ulong)buffer[offset + 3] << 24) | ((ulong)buffer[offset + 4] << 32) | ((ulong)buffer[offset + 5] << 40) | ((ulong)buffer[offset + 6] << 48) | ((ulong)buffer[offset + 7] << 56);
			offset += 8;
		}

		internal void ReadInt32(int[] values)
		{
			for (int i = 0; i < values.Length; i++)
			{
				ReadInt32(out values[i]);
			}
		}

		internal void ReadUInt32(uint[] values)
		{
			for (int i = 0; i < values.Length; i++)
			{
				ReadUInt32(out values[i]);
			}
		}

		internal void ReadBytes(byte[] bytes)
		{
			for (int i = 0; i < bytes.Length; i++)
			{
				bytes[i] = buffer[offset++];
			}
		}

		internal float ReadFloat()
		{
			float result = BitConverter.ToSingle(buffer, offset);
			offset += 4;
			return result;
		}

		internal double ReadDouble()
		{
			double result = BitConverter.ToDouble(buffer, offset);
			offset += 8;
			return result;
		}

		internal decimal ReadDecimal()
		{
			int[] array = new int[4];
			ReadInt32(array);
			return new decimal(array[2], array[3], array[1], array[0] < 0, (byte)((array[0] & 0xFF0000) >> 16));
		}

		internal void ReadBString(out string value)
		{
			ReadUInt16(out var value2);
			value = Encoding.UTF8.GetString(buffer, offset, value2);
			offset += value2;
		}

		internal string ReadBString(int len)
		{
			string @string = Encoding.UTF8.GetString(buffer, offset, len);
			offset += len;
			return @string;
		}

		internal void ReadCString(out string value)
		{
			int i;
			for (i = 0; offset + i < buffer.Length && buffer[offset + i] != 0; i++)
			{
			}
			value = Encoding.UTF8.GetString(buffer, offset, i);
			offset += i + 1;
		}

		internal void SkipCString(out string value)
		{
			int i;
			for (i = 0; offset + i < buffer.Length && buffer[offset + i] != 0; i++)
			{
			}
			offset += i + 1;
			value = null;
		}

		internal void ReadGuid(out Guid guid)
		{
			ReadUInt32(out var value);
			ReadUInt16(out var value2);
			ReadUInt16(out var value3);
			ReadUInt8(out var value4);
			ReadUInt8(out var value5);
			ReadUInt8(out var value6);
			ReadUInt8(out var value7);
			ReadUInt8(out var value8);
			ReadUInt8(out var value9);
			ReadUInt8(out var value10);
			ReadUInt8(out var value11);
			guid = new Guid(value, value2, value3, value4, value5, value6, value7, value8, value9, value10, value11);
		}

		internal string ReadString()
		{
			int i;
			for (i = 0; offset + i < buffer.Length && buffer[offset + i] != 0; i += 2)
			{
			}
			string @string = Encoding.Unicode.GetString(buffer, offset, i);
			offset += i + 2;
			return @string;
		}
	}
	internal struct BitSet
	{
		private int size;

		private uint[] words;

		internal bool IsEmpty => size == 0;

		internal BitSet(BitAccess bits)
		{
			bits.ReadInt32(out size);
			words = new uint[size];
			bits.ReadUInt32(words);
		}

		internal bool IsSet(int index)
		{
			int num = index / 32;
			if (num >= size)
			{
				return false;
			}
			return (words[num] & GetBit(index)) != 0;
		}

		private static uint GetBit(int index)
		{
			return (uint)(1 << index % 32);
		}
	}
	internal struct FLOAT10
	{
		internal byte Data_0;

		internal byte Data_1;

		internal byte Data_2;

		internal byte Data_3;

		internal byte Data_4;

		internal byte Data_5;

		internal byte Data_6;

		internal byte Data_7;

		internal byte Data_8;

		internal byte Data_9;
	}
	internal enum CV_SIGNATURE
	{
		C6 = 0,
		C7 = 1,
		C11 = 2,
		C13 = 4,
		RESERVERD = 5
	}
	internal enum CV_prmode
	{
		CV_TM_DIRECT = 0,
		CV_TM_NPTR32 = 4,
		CV_TM_NPTR64 = 6,
		CV_TM_NPTR128 = 7
	}
	internal enum CV_type
	{
		CV_SPECIAL = 0,
		CV_SIGNED = 1,
		CV_UNSIGNED = 2,
		CV_BOOLEAN = 3,
		CV_REAL = 4,
		CV_COMPLEX = 5,
		CV_SPECIAL2 = 6,
		CV_INT = 7,
		CV_CVRESERVED = 15
	}
	internal enum CV_special
	{
		CV_SP_NOTYPE,
		CV_SP_ABS,
		CV_SP_SEGMENT,
		CV_SP_VOID,
		CV_SP_CURRENCY,
		CV_SP_NBASICSTR,
		CV_SP_FBASICSTR,
		CV_SP_NOTTRANS,
		CV_SP_HRESULT
	}
	internal enum CV_special2
	{
		CV_S2_BIT,
		CV_S2_PASCHAR
	}
	internal enum CV_integral
	{
		CV_IN_1BYTE,
		CV_IN_2BYTE,
		CV_IN_4BYTE,
		CV_IN_8BYTE,
		CV_IN_16BYTE
	}
	internal enum CV_real
	{
		CV_RC_REAL32,
		CV_RC_REAL64,
		CV_RC_REAL80,
		CV_RC_REAL128
	}
	internal enum CV_int
	{
		CV_RI_CHAR = 0,
		CV_RI_INT1 = 0,
		CV_RI_WCHAR = 1,
		CV_RI_UINT1 = 1,
		CV_RI_INT2 = 2,
		CV_RI_UINT2 = 3,
		CV_RI_INT4 = 4,
		CV_RI_UINT4 = 5,
		CV_RI_INT8 = 6,
		CV_RI_UINT8 = 7,
		CV_RI_INT16 = 8,
		CV_RI_UINT16 = 9
	}
	[StructLayout(LayoutKind.Sequential, Size = 1)]
	internal struct CV_PRIMITIVE_TYPE
	{
		private const uint CV_MMASK = 1792u;

		private const uint CV_TMASK = 240u;

		private const uint CV_SMASK = 15u;

		private const int CV_MSHIFT = 8;

		private const int CV_TSHIFT = 4;

		private const int CV_SSHIFT = 0;

		private const uint CV_FIRST_NONPRIM = 4096u;
	}
	internal enum TYPE_ENUM
	{
		T_NOTYPE = 0,
		T_ABS = 1,
		T_SEGMENT = 2,
		T_VOID = 3,
		T_HRESULT = 8,
		T_32PHRESULT = 1032,
		T_64PHRESULT = 1544,
		T_PVOID = 259,
		T_PFVOID = 515,
		T_PHVOID = 771,
		T_32PVOID = 1027,
		T_64PVOID = 1539,
		T_CURRENCY = 4,
		T_NOTTRANS = 7,
		T_BIT = 96,
		T_PASCHAR = 97,
		T_CHAR = 16,
		T_32PCHAR = 1040,
		T_64PCHAR = 1552,
		T_UCHAR = 32,
		T_32PUCHAR = 1056,
		T_64PUCHAR = 1568,
		T_RCHAR = 112,
		T_32PRCHAR = 1136,
		T_64PRCHAR = 1648,
		T_WCHAR = 113,
		T_32PWCHAR = 1137,
		T_64PWCHAR = 1649,
		T_INT1 = 104,
		T_32PINT1 = 1128,
		T_64PINT1 = 1640,
		T_UINT1 = 105,
		T_32PUINT1 = 1129,
		T_64PUINT1 = 1641,
		T_SHORT = 17,
		T_32PSHORT = 1041,
		T_64PSHORT = 1553,
		T_USHORT = 33,
		T_32PUSHORT = 1057,
		T_64PUSHORT = 1569,
		T_INT2 = 114,
		T_32PINT2 = 1138,
		T_64PINT2 = 1650,
		T_UINT2 = 115,
		T_32PUINT2 = 1139,
		T_64PUINT2 = 1651,
		T_LONG = 18,
		T_ULONG = 34,
		T_32PLONG = 1042,
		T_32PULONG = 1058,
		T_64PLONG = 1554,
		T_64PULONG = 1570,
		T_INT4 = 116,
		T_32PINT4 = 1140,
		T_64PINT4 = 1652,
		T_UINT4 = 117,
		T_32PUINT4 = 1141,
		T_64PUINT4 = 1653,
		T_QUAD = 19,
		T_32PQUAD = 1043,
		T_64PQUAD = 1555,
		T_UQUAD = 35,
		T_32PUQUAD = 1059,
		T_64PUQUAD = 1571,
		T_INT8 = 118,
		T_32PINT8 = 1142,
		T_64PINT8 = 1654,
		T_UINT8 = 119,
		T_32PUINT8 = 1143,
		T_64PUINT8 = 1655,
		T_OCT = 20,
		T_32POCT = 1044,
		T_64POCT = 1556,
		T_UOCT = 36,
		T_32PUOCT = 1060,
		T_64PUOCT = 1572,
		T_INT16 = 120,
		T_32PINT16 = 1144,
		T_64PINT16 = 1656,
		T_UINT16 = 121,
		T_32PUINT16 = 1145,
		T_64PUINT16 = 1657,
		T_REAL32 = 64,
		T_32PREAL32 = 1088,
		T_64PREAL32 = 1600,
		T_REAL64 = 65,
		T_32PREAL64 = 1089,
		T_64PREAL64 = 1601,
		T_REAL80 = 66,
		T_32PREAL80 = 1090,
		T_64PREAL80 = 1602,
		T_REAL128 = 67,
		T_32PREAL128 = 1091,
		T_64PREAL128 = 1603,
		T_CPLX32 = 80,
		T_32PCPLX32 = 1104,
		T_64PCPLX32 = 1616,
		T_CPLX64 = 81,
		T_32PCPLX64 = 1105,
		T_64PCPLX64 = 1617,
		T_CPLX80 = 82,
		T_32PCPLX80 = 1106,
		T_64PCPLX80 = 1618,
		T_CPLX128 = 83,
		T_32PCPLX128 = 1107,
		T_64PCPLX128 = 1619,
		T_BOOL08 = 48,
		T_32PBOOL08 = 1072,
		T_64PBOOL08 = 1584,
		T_BOOL16 = 49,
		T_32PBOOL16 = 1073,
		T_64PBOOL16 = 1585,
		T_BOOL32 = 50,
		T_32PBOOL32 = 1074,
		T_64PBOOL32 = 1586,
		T_BOOL64 = 51,
		T_32PBOOL64 = 1075,
		T_64PBOOL64 = 1587
	}
	internal enum LEAF
	{
		LF_VTSHAPE = 10,
		LF_COBOL1 = 12,
		LF_LABEL = 14,
		LF_NULL = 15,
		LF_NOTTRAN = 16,
		LF_ENDPRECOMP = 20,
		LF_TYPESERVER_ST = 22,
		LF_LIST = 515,
		LF_REFSYM = 524,
		LF_ENUMERATE_ST = 1027,
		LF_TI16_MAX = 4096,
		LF_MODIFIER = 4097,
		LF_POINTER = 4098,
		LF_ARRAY_ST = 4099,
		LF_CLASS_ST = 4100,
		LF_STRUCTURE_ST = 4101,
		LF_UNION_ST = 4102,
		LF_ENUM_ST = 4103,
		LF_PROCEDURE = 4104,
		LF_MFUNCTION = 4105,
		LF_COBOL0 = 4106,
		LF_BARRAY = 4107,
		LF_DIMARRAY_ST = 4108,
		LF_VFTPATH = 4109,
		LF_PRECOMP_ST = 4110,
		LF_OEM = 4111,
		LF_ALIAS_ST = 4112,
		LF_OEM2 = 4113,
		LF_SKIP = 4608,
		LF_ARGLIST = 4609,
		LF_DEFARG_ST = 4610,
		LF_FIELDLIST = 4611,
		LF_DERIVED = 4612,
		LF_BITFIELD = 4613,
		LF_METHODLIST = 4614,
		LF_DIMCONU = 4615,
		LF_DIMCONLU = 4616,
		LF_DIMVARU = 4617,
		LF_DIMVARLU = 4618,
		LF_BCLASS = 5120,
		LF_VBCLASS = 5121,
		LF_IVBCLASS = 5122,
		LF_FRIENDFCN_ST = 5123,
		LF_INDEX = 5124,
		LF_MEMBER_ST = 5125,
		LF_STMEMBER_ST = 5126,
		LF_METHOD_ST = 5127,
		LF_NESTTYPE_ST = 5128,
		LF_VFUNCTAB = 5129,
		LF_FRIENDCLS = 5130,
		LF_ONEMETHOD_ST = 5131,
		LF_VFUNCOFF = 5132,
		LF_NESTTYPEEX_ST = 5133,
		LF_MEMBERMODIFY_ST = 5134,
		LF_MANAGED_ST = 5135,
		LF_ST_MAX = 5376,
		LF_TYPESERVER = 5377,
		LF_ENUMERATE = 5378,
		LF_ARRAY = 5379,
		LF_CLASS = 5380,
		LF_STRUCTURE = 5381,
		LF_UNION = 5382,
		LF_ENUM = 5383,
		LF_DIMARRAY = 5384,
		LF_PRECOMP = 5385,
		LF_ALIAS = 5386,
		LF_DEFARG = 5387,
		LF_FRIENDFCN = 5388,
		LF_MEMBER = 5389,
		LF_STMEMBER = 5390,
		LF_METHOD = 5391,
		LF_NESTTYPE = 5392,
		LF_ONEMETHOD = 5393,
		LF_NESTTYPEEX = 5394,
		LF_MEMBERMODIFY = 5395,
		LF_MANAGED = 5396,
		LF_TYPESERVER2 = 5397,
		LF_NUMERIC = 32768,
		LF_CHAR = 32768,
		LF_SHORT = 32769,
		LF_USHORT = 32770,
		LF_LONG = 32771,
		LF_ULONG = 32772,
		LF_REAL32 = 32773,
		LF_REAL64 = 32774,
		LF_REAL80 = 32775,
		LF_REAL128 = 32776,
		LF_QUADWORD = 32777,
		LF_UQUADWORD = 32778,
		LF_COMPLEX32 = 32780,
		LF_COMPLEX64 = 32781,
		LF_COMPLEX80 = 32782,
		LF_COMPLEX128 = 32783,
		LF_VARSTRING = 32784,
		LF_OCTWORD = 32791,
		LF_UOCTWORD = 32792,
		LF_DECIMAL = 32793,
		LF_DATE = 32794,
		LF_UTF8STRING = 32795,
		LF_PAD0 = 240,
		LF_PAD1 = 241,
		LF_PAD2 = 242,
		LF_PAD3 = 243,
		LF_PAD4 = 244,
		LF_PAD5 = 245,
		LF_PAD6 = 246,
		LF_PAD7 = 247,
		LF_PAD8 = 248,
		LF_PAD9 = 249,
		LF_PAD10 = 250,
		LF_PAD11 = 251,
		LF_PAD12 = 252,
		LF_PAD13 = 253,
		LF_PAD14 = 254,
		LF_PAD15 = 255
	}
	internal enum CV_ptrtype
	{
		CV_PTR_BASE_SEG = 3,
		CV_PTR_BASE_VAL = 4,
		CV_PTR_BASE_SEGVAL = 5,
		CV_PTR_BASE_ADDR = 6,
		CV_PTR_BASE_SEGADDR = 7,
		CV_PTR_BASE_TYPE = 8,
		CV_PTR_BASE_SELF = 9,
		CV_PTR_NEAR32 = 10,
		CV_PTR_64 = 12,
		CV_PTR_UNUSEDPTR = 13
	}
	internal enum CV_ptrmode
	{
		CV_PTR_MODE_PTR,
		CV_PTR_MODE_REF,
		CV_PTR_MODE_PMEM,
		CV_PTR_MODE_PMFUNC,
		CV_PTR_MODE_RESERVED
	}
	internal enum CV_pmtype
	{
		CV_PMTYPE_Undef,
		CV_PMTYPE_D_Single,
		CV_PMTYPE_D_Multiple,
		CV_PMTYPE_D_Virtual,
		CV_PMTYPE_D_General,
		CV_PMTYPE_F_Single,
		CV_PMTYPE_F_Multiple,
		CV_PMTYPE_F_Virtual,
		CV_PMTYPE_F_General
	}
	internal enum CV_methodprop
	{
		CV_MTvanilla,
		CV_MTvirtual,
		CV_MTstatic,
		CV_MTfriend,
		CV_MTintro,
		CV_MTpurevirt,
		CV_MTpureintro
	}
	internal enum CV_VTS_desc
	{
		CV_VTS_near,
		CV_VTS_far,
		CV_VTS_thin,
		CV_VTS_outer,
		CV_VTS_meta,
		CV_VTS_near32,
		CV_VTS_far32,
		CV_VTS_unused
	}
	internal enum CV_LABEL_TYPE
	{
		CV_LABEL_NEAR = 0,
		CV_LABEL_FAR = 4
	}
	[Flags]
	internal enum CV_modifier : ushort
	{
		MOD_const = 1,
		MOD_volatile = 2,
		MOD_unaligned = 4
	}
	[Flags]
	internal enum CV_prop : ushort
	{
		packed = 1,
		ctor = 2,
		ovlops = 4,
		isnested = 8,
		cnested = 0x10,
		opassign = 0x20,
		opcast = 0x40,
		fwdref = 0x80,
		scoped = 0x100
	}
	[Flags]
	internal enum CV_fldattr
	{
		access = 3,
		mprop = 0x1C,
		pseudo = 0x20,
		noinherit = 0x40,
		noconstruct = 0x80,
		compgenx = 0x100
	}
	internal struct TYPTYPE
	{
		internal ushort len;

		internal ushort leaf;
	}
	internal struct CV_PDMR32_NVVFCN
	{
		internal int mdisp;
	}
	internal struct CV_PDMR32_VBASE
	{
		internal int mdisp;

		internal int pdisp;

		internal int vdisp;
	}
	internal struct CV_PMFR32_NVSA
	{
		internal uint off;
	}
	internal struct CV_PMFR32_NVMA
	{
		internal uint off;

		internal int disp;
	}
	internal struct CV_PMFR32_VBASE
	{
		internal uint off;

		internal int mdisp;

		internal int pdisp;

		internal int vdisp;
	}
	internal struct LeafModifier
	{
		internal uint type;

		internal CV_modifier attr;
	}
	[Flags]
	internal enum LeafPointerAttr : uint
	{
		ptrtype = 0x1Fu,
		ptrmode = 0xE0u,
		isflat32 = 0x100u,
		isvolatile = 0x200u,
		isconst = 0x400u,
		isunaligned = 0x800u,
		isrestrict = 0x1000u
	}
	[StructLayout(LayoutKind.Sequential, Size = 1)]
	internal struct LeafPointer
	{
		internal struct LeafPointerBody
		{
			internal uint utype;

			internal LeafPointerAttr attr;
		}
	}
	internal struct LeafArray
	{
		internal uint elemtype;

		internal uint idxtype;

		internal byte[] data;

		internal string name;
	}
	internal struct LeafClass
	{
		internal ushort count;

		internal ushort property;

		internal uint field;

		internal uint derived;

		internal uint vshape;

		internal byte[] data;

		internal string name;
	}
	internal struct LeafUnion
	{
		internal ushort count;

		internal ushort property;

		internal uint field;

		internal byte[] data;

		internal string name;
	}
	internal struct LeafAlias
	{
		internal uint utype;

		internal string name;
	}
	internal struct LeafManaged
	{
		internal string name;
	}
	internal struct LeafEnum
	{
		internal ushort count;

		internal ushort property;

		internal uint utype;

		internal uint field;

		internal string name;
	}
	internal struct LeafProc
	{
		internal uint rvtype;

		internal byte calltype;

		internal byte reserved;

		internal ushort parmcount;

		internal uint arglist;
	}
	internal struct LeafMFunc
	{
		internal uint rvtype;

		internal uint classtype;

		internal uint thistype;

		internal byte calltype;

		internal byte reserved;

		internal ushort parmcount;

		internal uint arglist;

		internal int thisadjust;
	}
	internal struct LeafVTShape
	{
		internal ushort count;

		internal byte[] desc;
	}
	internal struct LeafCobol0
	{
		internal uint type;

		internal byte[] data;
	}
	internal struct LeafCobol1
	{
		internal byte[] data;
	}
	internal struct LeafBArray
	{
		internal uint utype;
	}
	internal struct LeafLabel
	{
		internal ushort mode;
	}
	internal struct LeafDimArray
	{
		internal uint utype;

		internal uint diminfo;

		internal string name;
	}
	internal struct LeafVFTPath
	{
		internal uint count;

		internal uint[] bases;
	}
	internal struct LeafPreComp
	{
		internal uint start;

		internal uint count;

		internal uint signature;

		internal string name;
	}
	internal struct LeafEndPreComp
	{
		internal uint signature;
	}
	internal struct LeafOEM
	{
		internal ushort cvOEM;

		internal ushort recOEM;

		internal uint count;

		internal uint[] index;
	}
	internal enum OEM_ID
	{
		OEM_MS_FORTRAN90 = 61584,
		OEM_ODI = 16,
		OEM_THOMSON_SOFTWARE = 21587,
		OEM_ODI_REC_BASELIST = 0
	}
	internal struct LeafOEM2
	{
		internal Guid idOem;

		internal uint count;

		internal uint[] index;
	}
	internal struct LeafTypeServer
	{
		internal uint signature;

		internal uint age;

		internal string name;
	}
	internal struct LeafTypeServer2
	{
		internal Guid sig70;

		internal uint age;

		internal string name;
	}
	internal struct LeafSkip
	{
		internal uint type;

		internal byte[] data;
	}
	internal struct LeafArgList
	{
		internal uint count;

		internal uint[] arg;
	}
	internal struct LeafDerived
	{
		internal uint count;

		internal uint[] drvdcls;
	}
	internal struct LeafDefArg
	{
		internal uint type;

		internal byte[] expr;
	}
	internal struct LeafList
	{
		internal byte[] data;
	}
	internal struct LeafFieldList
	{
		internal char[] data;
	}
	internal struct mlMethod
	{
		internal ushort attr;

		internal ushort pad0;

		internal uint index;

		internal uint[] vbaseoff;
	}
	internal struct LeafMethodList
	{
		internal byte[] mList;
	}
	internal struct LeafBitfield
	{
		internal uint type;

		internal byte length;

		internal byte position;
	}
	internal struct LeafDimCon
	{
		internal uint typ;

		internal ushort rank;

		internal byte[] dim;
	}
	internal struct LeafDimVar
	{
		internal uint rank;

		internal uint typ;

		internal uint[] dim;
	}
	internal struct LeafRefSym
	{
		internal byte[] Sym;
	}
	internal struct LeafChar
	{
		internal sbyte val;
	}
	internal struct LeafShort
	{
		internal short val;
	}
	internal struct LeafUShort
	{
		internal ushort val;
	}
	internal struct LeafLong
	{
		internal int val;
	}
	internal struct LeafULong
	{
		internal uint val;
	}
	internal struct LeafQuad
	{
		internal long val;
	}
	internal struct LeafUQuad
	{
		internal ulong val;
	}
	internal struct LeafOct
	{
		internal ulong val0;

		internal ulong val1;
	}
	internal struct LeafUOct
	{
		internal ulong val0;

		internal ulong val1;
	}
	internal struct LeafReal32
	{
		internal float val;
	}
	internal struct LeafReal64
	{
		internal double val;
	}
	internal struct LeafReal80
	{
		internal FLOAT10 val;
	}
	internal struct LeafReal128
	{
		internal ulong val0;

		internal ulong val1;
	}
	internal struct LeafCmplx32
	{
		internal float val_real;

		internal float val_imag;
	}
	internal struct LeafCmplx64
	{
		internal double val_real;

		internal double val_imag;
	}
	internal struct LeafCmplx80
	{
		internal FLOAT10 val_real;

		internal FLOAT10 val_imag;
	}
	internal struct LeafCmplx128
	{
		internal ulong val0_real;

		internal ulong val1_real;

		internal ulong val0_imag;

		internal ulong val1_imag;
	}
	internal struct LeafVarString
	{
		internal ushort len;

		internal byte[] value;
	}
	internal struct LeafIndex
	{
		internal ushort pad0;

		internal uint index;
	}
	internal struct LeafBClass
	{
		internal ushort attr;

		internal uint index;

		internal byte[] offset;
	}
	internal struct LeafVBClass
	{
		internal ushort attr;

		internal uint index;

		internal uint vbptr;

		internal byte[] vbpoff;
	}
	internal struct LeafFriendCls
	{
		internal ushort pad0;

		internal uint index;
	}
	internal struct LeafFriendFcn
	{
		internal ushort pad0;

		internal uint index;

		internal string name;
	}
	internal struct LeafMember
	{
		internal ushort attr;

		internal uint index;

		internal byte[] offset;

		internal string name;
	}
	internal struct LeafSTMember
	{
		internal ushort attr;

		internal uint index;

		internal string name;
	}
	internal struct LeafVFuncTab
	{
		internal ushort pad0;

		internal uint type;
	}
	internal struct LeafVFuncOff
	{
		internal ushort pad0;

		internal uint type;

		internal int offset;
	}
	internal struct LeafMethod
	{
		internal ushort count;

		internal uint mList;

		internal string name;
	}
	internal struct LeafOneMethod
	{
		internal ushort attr;

		internal uint index;

		internal uint[] vbaseoff;

		internal string name;
	}
	internal struct LeafEnumerate
	{
		internal ushort attr;

		internal byte[] value;

		internal string name;
	}
	internal struct LeafNestType
	{
		internal ushort pad0;

		internal uint index;

	

BepInExPack/BepInEx/core/Mono.Cecil.Rocks.dll

Decompiled a month 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.Text;
using Mono.Cecil.Cil;
using Mono.Cecil.PE;
using Mono.Collections.Generic;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyProduct("Mono.Cecil")]
[assembly: AssemblyCopyright("Copyright © 2008 - 2018 Jb Evain")]
[assembly: ComVisible(false)]
[assembly: AssemblyFileVersion("0.11.4.0")]
[assembly: AssemblyInformationalVersion("0.11.4.0")]
[assembly: AssemblyTitle("Mono.Cecil.Rocks")]
[assembly: CLSCompliant(false)]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = "")]
[assembly: AssemblyVersion("0.11.4.0")]
namespace Mono.Cecil.Rocks;

public class DocCommentId
{
	private StringBuilder id;

	private DocCommentId()
	{
		id = new StringBuilder();
	}

	private void WriteField(FieldDefinition field)
	{
		WriteDefinition('F', (IMemberDefinition)(object)field);
	}

	private void WriteEvent(EventDefinition @event)
	{
		WriteDefinition('E', (IMemberDefinition)(object)@event);
	}

	private void WriteType(TypeDefinition type)
	{
		id.Append('T').Append(':');
		WriteTypeFullName((TypeReference)(object)type);
	}

	private void WriteMethod(MethodDefinition method)
	{
		WriteDefinition('M', (IMemberDefinition)(object)method);
		if (((MethodReference)method).HasGenericParameters)
		{
			id.Append('`').Append('`');
			id.Append(((MethodReference)method).GenericParameters.Count);
		}
		if (((MethodReference)method).HasParameters)
		{
			WriteParameters((IList<ParameterDefinition>)((MethodReference)method).Parameters);
		}
		if (IsConversionOperator(method))
		{
			WriteReturnType(method);
		}
	}

	private static bool IsConversionOperator(MethodDefinition self)
	{
		if (self == null)
		{
			throw new ArgumentNullException("self");
		}
		if (self.IsSpecialName)
		{
			if (!(((MemberReference)self).Name == "op_Explicit"))
			{
				return ((MemberReference)self).Name == "op_Implicit";
			}
			return true;
		}
		return false;
	}

	private void WriteReturnType(MethodDefinition method)
	{
		id.Append('~');
		WriteTypeSignature(((MethodReference)method).ReturnType);
	}

	private void WriteProperty(PropertyDefinition property)
	{
		WriteDefinition('P', (IMemberDefinition)(object)property);
		if (property.HasParameters)
		{
			WriteParameters((IList<ParameterDefinition>)((PropertyReference)property).Parameters);
		}
	}

	private void WriteParameters(IList<ParameterDefinition> parameters)
	{
		id.Append('(');
		WriteList(parameters, delegate(ParameterDefinition p)
		{
			WriteTypeSignature(((ParameterReference)p).ParameterType);
		});
		id.Append(')');
	}

	private void WriteTypeSignature(TypeReference type)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Expected I4, but got Unknown
		//IL_010c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Expected O, but got Unknown
		//IL_008e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0098: Expected O, but got Unknown
		//IL_002c: 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_004d: Expected I4, but got Unknown
		//IL_0081: Unknown result type (might be due to invalid IL or missing references)
		//IL_008b: Expected O, but got Unknown
		//IL_00db: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0109: Expected O, but got Unknown
		//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fa: Expected O, but got Unknown
		MetadataType metadataType = type.MetadataType;
		switch (metadataType - 15)
		{
		default:
			switch (metadataType - 27)
			{
			case 0:
				WriteFunctionPointerTypeSignature((FunctionPointerType)type);
				return;
			case 3:
				id.Append('`').Append('`');
				id.Append(((GenericParameter)type).Position);
				return;
			case 5:
				WriteModiferTypeSignature((IModifierType)(OptionalModifierType)type, '!');
				return;
			case 4:
				WriteModiferTypeSignature((IModifierType)(RequiredModifierType)type, '|');
				return;
			}
			break;
		case 5:
			WriteArrayTypeSignature((ArrayType)type);
			return;
		case 1:
			WriteTypeSignature(((TypeSpecification)(ByReferenceType)type).ElementType);
			id.Append('@');
			return;
		case 6:
			WriteGenericInstanceTypeSignature((GenericInstanceType)type);
			return;
		case 4:
			id.Append('`');
			id.Append(((GenericParameter)type).Position);
			return;
		case 0:
			WriteTypeSignature(((TypeSpecification)(PointerType)type).ElementType);
			id.Append('*');
			return;
		case 2:
		case 3:
			break;
		}
		WriteTypeFullName(type);
	}

	private void WriteGenericInstanceTypeSignature(GenericInstanceType type)
	{
		if (Mixin.IsTypeSpecification(((TypeSpecification)type).ElementType))
		{
			throw new NotSupportedException();
		}
		WriteTypeFullName(((TypeSpecification)type).ElementType, stripGenericArity: true);
		id.Append('{');
		WriteList((IList<TypeReference>)type.GenericArguments, WriteTypeSignature);
		id.Append('}');
	}

	private void WriteList<T>(IList<T> list, Action<T> action)
	{
		for (int i = 0; i < list.Count; i++)
		{
			if (i > 0)
			{
				id.Append(',');
			}
			action(list[i]);
		}
	}

	private void WriteModiferTypeSignature(IModifierType type, char id)
	{
		WriteTypeSignature(type.ElementType);
		this.id.Append(id);
		WriteTypeSignature(type.ModifierType);
	}

	private void WriteFunctionPointerTypeSignature(FunctionPointerType type)
	{
		id.Append("=FUNC:");
		WriteTypeSignature(type.ReturnType);
		if (type.HasParameters)
		{
			WriteParameters((IList<ParameterDefinition>)type.Parameters);
		}
	}

	private void WriteArrayTypeSignature(ArrayType type)
	{
		WriteTypeSignature(((TypeSpecification)type).ElementType);
		if (type.IsVector)
		{
			id.Append("[]");
			return;
		}
		id.Append("[");
		WriteList((IList<ArrayDimension>)type.Dimensions, delegate(ArrayDimension dimension)
		{
			if (((ArrayDimension)(ref dimension)).LowerBound.HasValue)
			{
				id.Append(((ArrayDimension)(ref dimension)).LowerBound.Value);
			}
			id.Append(':');
			if (((ArrayDimension)(ref dimension)).UpperBound.HasValue)
			{
				id.Append(((ArrayDimension)(ref dimension)).UpperBound.Value - (((ArrayDimension)(ref dimension)).LowerBound.GetValueOrDefault() + 1));
			}
		});
		id.Append("]");
	}

	private void WriteDefinition(char id, IMemberDefinition member)
	{
		this.id.Append(id).Append(':');
		WriteTypeFullName((TypeReference)(object)member.DeclaringType);
		this.id.Append('.');
		WriteItemName(member.Name);
	}

	private void WriteTypeFullName(TypeReference type, bool stripGenericArity = false)
	{
		if (((MemberReference)type).DeclaringType != null)
		{
			WriteTypeFullName(((MemberReference)type).DeclaringType);
			id.Append('.');
		}
		if (!string.IsNullOrEmpty(type.Namespace))
		{
			id.Append(type.Namespace);
			id.Append('.');
		}
		string text = ((MemberReference)type).Name;
		if (stripGenericArity)
		{
			int num = text.LastIndexOf('`');
			if (num > 0)
			{
				text = text.Substring(0, num);
			}
		}
		id.Append(text);
	}

	private void WriteItemName(string name)
	{
		id.Append(name.Replace('.', '#').Replace('<', '{').Replace('>', '}'));
	}

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

	public static string GetDocCommentId(IMemberDefinition member)
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Invalid comparison between Unknown and I4
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Invalid comparison between Unknown and I4
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Invalid comparison between Unknown and I4
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Expected O, but got Unknown
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: Invalid comparison between Unknown and I4
		//IL_0075: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: Expected O, but got Unknown
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Invalid comparison between Unknown and I4
		//IL_0083: Unknown result type (might be due to invalid IL or missing references)
		//IL_008d: Expected O, but got Unknown
		//IL_004d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: Invalid comparison between Unknown and I4
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Expected O, but got Unknown
		//IL_0091: Unknown result type (might be due to invalid IL or missing references)
		//IL_009b: Expected O, but got Unknown
		if (member == null)
		{
			throw new ArgumentNullException("member");
		}
		DocCommentId docCommentId = new DocCommentId();
		MetadataToken metadataToken = ((IMetadataTokenProvider)member).MetadataToken;
		TokenType tokenType = ((MetadataToken)(ref metadataToken)).TokenType;
		if ((int)tokenType <= 67108864)
		{
			if ((int)tokenType != 33554432)
			{
				if ((int)tokenType != 67108864)
				{
					goto IL_009d;
				}
				docCommentId.WriteField((FieldDefinition)member);
			}
			else
			{
				docCommentId.WriteType((TypeDefinition)member);
			}
		}
		else if ((int)tokenType != 100663296)
		{
			if ((int)tokenType != 335544320)
			{
				if ((int)tokenType != 385875968)
				{
					goto IL_009d;
				}
				docCommentId.WriteProperty((PropertyDefinition)member);
			}
			else
			{
				docCommentId.WriteEvent((EventDefinition)member);
			}
		}
		else
		{
			docCommentId.WriteMethod((MethodDefinition)member);
		}
		return docCommentId.ToString();
		IL_009d:
		throw new NotSupportedException(member.FullName);
	}
}
internal static class Functional
{
	public static Func<A, R> Y<A, R>(Func<Func<A, R>, Func<A, R>> f)
	{
		Func<A, R> g = null;
		g = f((A a) => g(a));
		return g;
	}

	public static IEnumerable<TSource> Prepend<TSource>(this IEnumerable<TSource> source, TSource element)
	{
		if (source == null)
		{
			throw new ArgumentNullException("source");
		}
		return PrependIterator(source, element);
	}

	private static IEnumerable<TSource> PrependIterator<TSource>(IEnumerable<TSource> source, TSource element)
	{
		yield return element;
		foreach (TSource item in source)
		{
			yield return item;
		}
	}
}
public interface IILVisitor
{
	void OnInlineNone(OpCode opcode);

	void OnInlineSByte(OpCode opcode, sbyte value);

	void OnInlineByte(OpCode opcode, byte value);

	void OnInlineInt32(OpCode opcode, int value);

	void OnInlineInt64(OpCode opcode, long value);

	void OnInlineSingle(OpCode opcode, float value);

	void OnInlineDouble(OpCode opcode, double value);

	void OnInlineString(OpCode opcode, string value);

	void OnInlineBranch(OpCode opcode, int offset);

	void OnInlineSwitch(OpCode opcode, int[] offsets);

	void OnInlineVariable(OpCode opcode, VariableDefinition variable);

	void OnInlineArgument(OpCode opcode, ParameterDefinition parameter);

	void OnInlineSignature(OpCode opcode, CallSite callSite);

	void OnInlineType(OpCode opcode, TypeReference type);

	void OnInlineField(OpCode opcode, FieldReference field);

	void OnInlineMethod(OpCode opcode, MethodReference method);
}
public static class ILParser
{
	private class ParseContext
	{
		public CodeReader Code { get; set; }

		public int Position { get; set; }

		public MetadataReader Metadata { get; set; }

		public Collection<VariableDefinition> Variables { get; set; }

		public IILVisitor Visitor { get; set; }
	}

	public static void Parse(MethodDefinition method, IILVisitor visitor)
	{
		if (method == null)
		{
			throw new ArgumentNullException("method");
		}
		if (visitor == null)
		{
			throw new ArgumentNullException("visitor");
		}
		if (!method.HasBody || !((MemberReference)method).HasImage)
		{
			throw new ArgumentException();
		}
		((MemberReference)method).Module.Read<MethodDefinition, bool>(method, (Func<MethodDefinition, MetadataReader, bool>)delegate(MethodDefinition m, MetadataReader _)
		{
			ParseMethod(m, visitor);
			return true;
		});
	}

	private static void ParseMethod(MethodDefinition method, IILVisitor visitor)
	{
		ParseContext parseContext = CreateContext(method, visitor);
		CodeReader code = parseContext.Code;
		byte b = ((BinaryReader)(object)code).ReadByte();
		switch (b & 3)
		{
		case 2:
			ParseCode(b >> 2, parseContext);
			break;
		case 3:
			((BinaryStreamReader)code).Advance(-1);
			ParseFatMethod(parseContext);
			break;
		default:
			throw new NotSupportedException();
		}
		code.MoveBackTo(parseContext.Position);
	}

	private static ParseContext CreateContext(MethodDefinition method, IILVisitor visitor)
	{
		CodeReader val = ((MemberReference)method).Module.Read<MethodDefinition, CodeReader>(method, (Func<MethodDefinition, MetadataReader, CodeReader>)((MethodDefinition _, MetadataReader reader) => reader.code));
		int position = val.MoveTo(method);
		return new ParseContext
		{
			Code = val,
			Position = position,
			Metadata = val.reader,
			Visitor = visitor
		};
	}

	private static void ParseFatMethod(ParseContext context)
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: 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_002a: Unknown result type (might be due to invalid IL or missing references)
		CodeReader code = context.Code;
		((BinaryStreamReader)code).Advance(4);
		int code_size = ((BinaryReader)(object)code).ReadInt32();
		MetadataToken val = code.ReadToken();
		if (val != MetadataToken.Zero)
		{
			context.Variables = (Collection<VariableDefinition>)(object)code.ReadVariables(val);
		}
		ParseCode(code_size, context);
	}

	private static void ParseCode(int code_size, ParseContext context)
	{
		//IL_004d: 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_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b4: Expected I4, but got Unknown
		//IL_0116: Unknown result type (might be due to invalid IL or missing references)
		//IL_0240: Unknown result type (might be due to invalid IL or missing references)
		//IL_024e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0253: Unknown result type (might be due to invalid IL or missing references)
		//IL_0257: Unknown result type (might be due to invalid IL or missing references)
		//IL_025c: Unknown result type (might be due to invalid IL or missing references)
		//IL_025e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0265: Invalid comparison between Unknown and I4
		//IL_015d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0170: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_0196: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0226: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_0103: Unknown result type (might be due to invalid IL or missing references)
		//IL_0128: Unknown result type (might be due to invalid IL or missing references)
		//IL_012a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0183: 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_01db: Unknown result type (might be due to invalid IL or missing references)
		//IL_0287: Unknown result type (might be due to invalid IL or missing references)
		//IL_028e: Invalid comparison between Unknown and I4
		//IL_0267: Unknown result type (might be due to invalid IL or missing references)
		//IL_026e: Invalid comparison between Unknown and I4
		//IL_014a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0137: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ab: Invalid comparison between Unknown and I4
		//IL_0290: Unknown result type (might be due to invalid IL or missing references)
		//IL_0297: Invalid comparison between Unknown and I4
		//IL_02b9: 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_02c7: Expected O, but got Unknown
		//IL_0270: Unknown result type (might be due to invalid IL or missing references)
		//IL_0277: Invalid comparison between Unknown and I4
		//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b4: Invalid comparison between Unknown and I4
		//IL_02ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d8: Expected O, but got Unknown
		//IL_0299: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a0: Invalid comparison between Unknown and I4
		//IL_0279: Unknown result type (might be due to invalid IL or missing references)
		//IL_0280: Invalid comparison between Unknown and I4
		//IL_02db: Unknown result type (might be due to invalid IL or missing references)
		//IL_02df: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e9: Expected O, but got Unknown
		//IL_02f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0312: Unknown result type (might be due to invalid IL or missing references)
		CodeReader code = context.Code;
		MetadataReader metadata = context.Metadata;
		IILVisitor visitor = context.Visitor;
		int num = ((BinaryStreamReader)code).Position + code_size;
		while (((BinaryStreamReader)code).Position < num)
		{
			byte b = ((BinaryReader)(object)code).ReadByte();
			OpCode val = ((b != 254) ? OpCodes.OneByteOpCode[b] : OpCodes.TwoBytesOpCode[((BinaryReader)(object)code).ReadByte()]);
			OperandType operandType = ((OpCode)(ref val)).OperandType;
			IMetadataTokenProvider val2;
			switch ((int)operandType)
			{
			case 5:
				visitor.OnInlineNone(val);
				break;
			case 10:
			{
				int num2 = ((BinaryReader)(object)code).ReadInt32();
				int[] array = new int[num2];
				for (int i = 0; i < num2; i++)
				{
					array[i] = ((BinaryReader)(object)code).ReadInt32();
				}
				visitor.OnInlineSwitch(val, array);
				break;
			}
			case 15:
				visitor.OnInlineBranch(val, ((BinaryReader)(object)code).ReadSByte());
				break;
			case 0:
				visitor.OnInlineBranch(val, ((BinaryReader)(object)code).ReadInt32());
				break;
			case 16:
				if (val == OpCodes.Ldc_I4_S)
				{
					visitor.OnInlineSByte(val, ((BinaryReader)(object)code).ReadSByte());
				}
				else
				{
					visitor.OnInlineByte(val, ((BinaryReader)(object)code).ReadByte());
				}
				break;
			case 2:
				visitor.OnInlineInt32(val, ((BinaryReader)(object)code).ReadInt32());
				break;
			case 3:
				visitor.OnInlineInt64(val, ((BinaryReader)(object)code).ReadInt64());
				break;
			case 17:
				visitor.OnInlineSingle(val, ((BinaryReader)(object)code).ReadSingle());
				break;
			case 7:
				visitor.OnInlineDouble(val, ((BinaryReader)(object)code).ReadDouble());
				break;
			case 8:
				visitor.OnInlineSignature(val, code.GetCallSite(code.ReadToken()));
				break;
			case 9:
				visitor.OnInlineString(val, code.GetString(code.ReadToken()));
				break;
			case 19:
				visitor.OnInlineArgument(val, code.GetParameter((int)((BinaryReader)(object)code).ReadByte()));
				break;
			case 14:
				visitor.OnInlineArgument(val, code.GetParameter((int)((BinaryReader)(object)code).ReadInt16()));
				break;
			case 18:
				visitor.OnInlineVariable(val, GetVariable(context, ((BinaryReader)(object)code).ReadByte()));
				break;
			case 13:
				visitor.OnInlineVariable(val, GetVariable(context, ((BinaryReader)(object)code).ReadInt16()));
				break;
			case 1:
			case 4:
			case 11:
			case 12:
				{
					val2 = metadata.LookupToken(code.ReadToken());
					MetadataToken metadataToken = val2.MetadataToken;
					TokenType tokenType = ((MetadataToken)(ref metadataToken)).TokenType;
					if ((int)tokenType <= 67108864)
					{
						if ((int)tokenType != 16777216 && (int)tokenType != 33554432)
						{
							if ((int)tokenType == 67108864)
							{
								visitor.OnInlineField(val, (FieldReference)val2);
							}
							break;
						}
						goto IL_02b8;
					}
					if ((int)tokenType <= 167772160)
					{
						if ((int)tokenType != 100663296)
						{
							if ((int)tokenType != 167772160)
							{
								break;
							}
							FieldReference val3 = (FieldReference)(object)((val2 is FieldReference) ? val2 : null);
							if (val3 != null)
							{
								visitor.OnInlineField(val, val3);
								break;
							}
							MethodReference val4 = (MethodReference)(object)((val2 is MethodReference) ? val2 : null);
							if (val4 != null)
							{
								visitor.OnInlineMethod(val, val4);
								break;
							}
							throw new InvalidOperationException();
						}
					}
					else
					{
						if ((int)tokenType == 452984832)
						{
							goto IL_02b8;
						}
						if ((int)tokenType != 721420288)
						{
							break;
						}
					}
					visitor.OnInlineMethod(val, (MethodReference)val2);
					break;
				}
				IL_02b8:
				visitor.OnInlineType(val, (TypeReference)val2);
				break;
			}
		}
	}

	private static VariableDefinition GetVariable(ParseContext context, int index)
	{
		return context.Variables[index];
	}
}
public static class MethodBodyRocks
{
	public static void SimplifyMacros(this MethodBody self)
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: 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_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Invalid comparison between Unknown and I4
		//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_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: 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_0126: Expected I4, but got Unknown
		//IL_0137: Unknown result type (might be due to invalid IL or missing references)
		//IL_014e: 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_017c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0193: Unknown result type (might be due to invalid IL or missing references)
		//IL_01af: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0203: Unknown result type (might be due to invalid IL or missing references)
		//IL_021f: Unknown result type (might be due to invalid IL or missing references)
		//IL_023b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0257: Unknown result type (might be due to invalid IL or missing references)
		//IL_0273: Unknown result type (might be due to invalid IL or missing references)
		//IL_0283: Unknown result type (might be due to invalid IL or missing references)
		//IL_0293: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0315: Unknown result type (might be due to invalid IL or missing references)
		//IL_032b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0341: Unknown result type (might be due to invalid IL or missing references)
		//IL_0357: Unknown result type (might be due to invalid IL or missing references)
		//IL_036d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0383: Unknown result type (might be due to invalid IL or missing references)
		//IL_0399: Unknown result type (might be due to invalid IL or missing references)
		//IL_03af: Unknown result type (might be due to invalid IL or missing references)
		//IL_03cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_03df: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_040f: Unknown result type (might be due to invalid IL or missing references)
		//IL_041c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0429: Unknown result type (might be due to invalid IL or missing references)
		//IL_0436: Unknown result type (might be due to invalid IL or missing references)
		//IL_0443: Unknown result type (might be due to invalid IL or missing references)
		//IL_0450: Unknown result type (might be due to invalid IL or missing references)
		//IL_045d: Unknown result type (might be due to invalid IL or missing references)
		//IL_046a: 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)
		//IL_0126: Unknown result type (might be due to invalid IL or missing references)
		//IL_012c: Invalid comparison between Unknown and I4
		//IL_0484: Unknown result type (might be due to invalid IL or missing references)
		if (self == null)
		{
			throw new ArgumentNullException("self");
		}
		Enumerator<Instruction> enumerator = self.Instructions.GetEnumerator();
		try
		{
			while (enumerator.MoveNext())
			{
				Instruction current = enumerator.Current;
				OpCode opCode = current.OpCode;
				if ((int)((OpCode)(ref opCode)).OpCodeType != 1)
				{
					continue;
				}
				opCode = current.OpCode;
				Code code = ((OpCode)(ref opCode)).Code;
				switch (code - 2)
				{
				case 0:
					ExpandMacro(current, OpCodes.Ldarg, Mixin.GetParameter(self, 0));
					continue;
				case 1:
					ExpandMacro(current, OpCodes.Ldarg, Mixin.GetParameter(self, 1));
					continue;
				case 2:
					ExpandMacro(current, OpCodes.Ldarg, Mixin.GetParameter(self, 2));
					continue;
				case 3:
					ExpandMacro(current, OpCodes.Ldarg, Mixin.GetParameter(self, 3));
					continue;
				case 4:
					ExpandMacro(current, OpCodes.Ldloc, self.Variables[0]);
					continue;
				case 5:
					ExpandMacro(current, OpCodes.Ldloc, self.Variables[1]);
					continue;
				case 6:
					ExpandMacro(current, OpCodes.Ldloc, self.Variables[2]);
					continue;
				case 7:
					ExpandMacro(current, OpCodes.Ldloc, self.Variables[3]);
					continue;
				case 8:
					ExpandMacro(current, OpCodes.Stloc, self.Variables[0]);
					continue;
				case 9:
					ExpandMacro(current, OpCodes.Stloc, self.Variables[1]);
					continue;
				case 10:
					ExpandMacro(current, OpCodes.Stloc, self.Variables[2]);
					continue;
				case 11:
					ExpandMacro(current, OpCodes.Stloc, self.Variables[3]);
					continue;
				case 12:
					current.OpCode = OpCodes.Ldarg;
					continue;
				case 13:
					current.OpCode = OpCodes.Ldarga;
					continue;
				case 14:
					current.OpCode = OpCodes.Starg;
					continue;
				case 15:
					current.OpCode = OpCodes.Ldloc;
					continue;
				case 16:
					current.OpCode = OpCodes.Ldloca;
					continue;
				case 17:
					current.OpCode = OpCodes.Stloc;
					continue;
				case 19:
					ExpandMacro(current, OpCodes.Ldc_I4, -1);
					continue;
				case 20:
					ExpandMacro(current, OpCodes.Ldc_I4, 0);
					continue;
				case 21:
					ExpandMacro(current, OpCodes.Ldc_I4, 1);
					continue;
				case 22:
					ExpandMacro(current, OpCodes.Ldc_I4, 2);
					continue;
				case 23:
					ExpandMacro(current, OpCodes.Ldc_I4, 3);
					continue;
				case 24:
					ExpandMacro(current, OpCodes.Ldc_I4, 4);
					continue;
				case 25:
					ExpandMacro(current, OpCodes.Ldc_I4, 5);
					continue;
				case 26:
					ExpandMacro(current, OpCodes.Ldc_I4, 6);
					continue;
				case 27:
					ExpandMacro(current, OpCodes.Ldc_I4, 7);
					continue;
				case 28:
					ExpandMacro(current, OpCodes.Ldc_I4, 8);
					continue;
				case 29:
					ExpandMacro(current, OpCodes.Ldc_I4, (int)(sbyte)current.Operand);
					continue;
				case 40:
					current.OpCode = OpCodes.Br;
					continue;
				case 41:
					current.OpCode = OpCodes.Brfalse;
					continue;
				case 42:
					current.OpCode = OpCodes.Brtrue;
					continue;
				case 43:
					current.OpCode = OpCodes.Beq;
					continue;
				case 44:
					current.OpCode = OpCodes.Bge;
					continue;
				case 45:
					current.OpCode = OpCodes.Bgt;
					continue;
				case 46:
					current.OpCode = OpCodes.Ble;
					continue;
				case 47:
					current.OpCode = OpCodes.Blt;
					continue;
				case 48:
					current.OpCode = OpCodes.Bne_Un;
					continue;
				case 49:
					current.OpCode = OpCodes.Bge_Un;
					continue;
				case 50:
					current.OpCode = OpCodes.Bgt_Un;
					continue;
				case 51:
					current.OpCode = OpCodes.Ble_Un;
					continue;
				case 52:
					current.OpCode = OpCodes.Blt_Un;
					continue;
				case 18:
				case 30:
				case 31:
				case 32:
				case 33:
				case 34:
				case 35:
				case 36:
				case 37:
				case 38:
				case 39:
					continue;
				}
				if ((int)code == 188)
				{
					current.OpCode = OpCodes.Leave;
				}
			}
		}
		finally
		{
			((IDisposable)enumerator).Dispose();
		}
	}

	private static void ExpandMacro(Instruction instruction, OpCode opcode, object operand)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		instruction.OpCode = opcode;
		instruction.Operand = operand;
	}

	private static void MakeMacro(Instruction instruction, OpCode opcode)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		instruction.OpCode = opcode;
		instruction.Operand = null;
	}

	public static void Optimize(this MethodBody self)
	{
		if (self == null)
		{
			throw new ArgumentNullException("self");
		}
		self.OptimizeLongs();
		self.OptimizeMacros();
	}

	private static void OptimizeLongs(this MethodBody self)
	{
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Invalid comparison between Unknown and I4
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		for (int i = 0; i < self.Instructions.Count; i++)
		{
			Instruction val = self.Instructions[i];
			OpCode opCode = val.OpCode;
			if ((int)((OpCode)(ref opCode)).Code == 33)
			{
				long num = (long)val.Operand;
				if (num < int.MaxValue && num > int.MinValue)
				{
					ExpandMacro(val, OpCodes.Ldc_I4, (int)num);
					self.Instructions.Insert(++i, Instruction.Create(OpCodes.Conv_I8));
				}
			}
		}
	}

	public static void OptimizeMacros(this MethodBody self)
	{
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Invalid comparison between Unknown and I4
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Expected I4, but got Unknown
		//IL_02fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_030a: Unknown result type (might be due to invalid IL or missing references)
		//IL_031a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0327: Unknown result type (might be due to invalid IL or missing references)
		//IL_0334: Unknown result type (might be due to invalid IL or missing references)
		//IL_0341: Unknown result type (might be due to invalid IL or missing references)
		//IL_034e: Unknown result type (might be due to invalid IL or missing references)
		//IL_035b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0368: Unknown result type (might be due to invalid IL or missing references)
		//IL_0375: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_0238: Unknown result type (might be due to invalid IL or missing references)
		//IL_0124: Unknown result type (might be due to invalid IL or missing references)
		//IL_028c: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_0148: Unknown result type (might be due to invalid IL or missing references)
		//IL_0158: Unknown result type (might be due to invalid IL or missing references)
		//IL_0168: Unknown result type (might be due to invalid IL or missing references)
		//IL_0178: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_0202: Unknown result type (might be due to invalid IL or missing references)
		//IL_0391: Unknown result type (might be due to invalid IL or missing references)
		//IL_00be: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_00de: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_0271: Unknown result type (might be due to invalid IL or missing references)
		//IL_0193: Unknown result type (might be due to invalid IL or missing references)
		//IL_021d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0109: Unknown result type (might be due to invalid IL or missing references)
		if (self == null)
		{
			throw new ArgumentNullException("self");
		}
		MethodDefinition method = self.Method;
		Enumerator<Instruction> enumerator = self.Instructions.GetEnumerator();
		try
		{
			while (enumerator.MoveNext())
			{
				Instruction current = enumerator.Current;
				OpCode opCode = current.OpCode;
				Code code = ((OpCode)(ref opCode)).Code;
				if ((int)code != 32)
				{
					switch (code - 199)
					{
					case 0:
					{
						int index = ((ParameterReference)(ParameterDefinition)current.Operand).Index;
						if (index == -1 && current.Operand == self.ThisParameter)
						{
							index = 0;
						}
						else if (((MethodReference)method).HasThis)
						{
							index++;
						}
						switch (index)
						{
						case 0:
							MakeMacro(current, OpCodes.Ldarg_0);
							break;
						case 1:
							MakeMacro(current, OpCodes.Ldarg_1);
							break;
						case 2:
							MakeMacro(current, OpCodes.Ldarg_2);
							break;
						case 3:
							MakeMacro(current, OpCodes.Ldarg_3);
							break;
						default:
							if (index < 256)
							{
								ExpandMacro(current, OpCodes.Ldarg_S, current.Operand);
							}
							break;
						}
						break;
					}
					case 3:
					{
						int index = ((VariableReference)(VariableDefinition)current.Operand).Index;
						switch (index)
						{
						case 0:
							MakeMacro(current, OpCodes.Ldloc_0);
							break;
						case 1:
							MakeMacro(current, OpCodes.Ldloc_1);
							break;
						case 2:
							MakeMacro(current, OpCodes.Ldloc_2);
							break;
						case 3:
							MakeMacro(current, OpCodes.Ldloc_3);
							break;
						default:
							if (index < 256)
							{
								ExpandMacro(current, OpCodes.Ldloc_S, current.Operand);
							}
							break;
						}
						break;
					}
					case 5:
					{
						int index = ((VariableReference)(VariableDefinition)current.Operand).Index;
						switch (index)
						{
						case 0:
							MakeMacro(current, OpCodes.Stloc_0);
							break;
						case 1:
							MakeMacro(current, OpCodes.Stloc_1);
							break;
						case 2:
							MakeMacro(current, OpCodes.Stloc_2);
							break;
						case 3:
							MakeMacro(current, OpCodes.Stloc_3);
							break;
						default:
							if (index < 256)
							{
								ExpandMacro(current, OpCodes.Stloc_S, current.Operand);
							}
							break;
						}
						break;
					}
					case 1:
					{
						int index = ((ParameterReference)(ParameterDefinition)current.Operand).Index;
						if (index == -1 && current.Operand == self.ThisParameter)
						{
							index = 0;
						}
						else if (((MethodReference)method).HasThis)
						{
							index++;
						}
						if (index < 256)
						{
							ExpandMacro(current, OpCodes.Ldarga_S, current.Operand);
						}
						break;
					}
					case 4:
						if (((VariableReference)(VariableDefinition)current.Operand).Index < 256)
						{
							ExpandMacro(current, OpCodes.Ldloca_S, current.Operand);
						}
						break;
					}
					continue;
				}
				int num = (int)current.Operand;
				switch (num)
				{
				case -1:
					MakeMacro(current, OpCodes.Ldc_I4_M1);
					continue;
				case 0:
					MakeMacro(current, OpCodes.Ldc_I4_0);
					continue;
				case 1:
					MakeMacro(current, OpCodes.Ldc_I4_1);
					continue;
				case 2:
					MakeMacro(current, OpCodes.Ldc_I4_2);
					continue;
				case 3:
					MakeMacro(current, OpCodes.Ldc_I4_3);
					continue;
				case 4:
					MakeMacro(current, OpCodes.Ldc_I4_4);
					continue;
				case 5:
					MakeMacro(current, OpCodes.Ldc_I4_5);
					continue;
				case 6:
					MakeMacro(current, OpCodes.Ldc_I4_6);
					continue;
				case 7:
					MakeMacro(current, OpCodes.Ldc_I4_7);
					continue;
				case 8:
					MakeMacro(current, OpCodes.Ldc_I4_8);
					continue;
				}
				if (num >= -128 && num < 128)
				{
					ExpandMacro(current, OpCodes.Ldc_I4_S, (sbyte)num);
				}
			}
		}
		finally
		{
			((IDisposable)enumerator).Dispose();
		}
		OptimizeBranches(self);
	}

	private static void OptimizeBranches(MethodBody body)
	{
		//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_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		ComputeOffsets(body);
		Enumerator<Instruction> enumerator = body.Instructions.GetEnumerator();
		try
		{
			while (enumerator.MoveNext())
			{
				Instruction current = enumerator.Current;
				OpCode opCode = current.OpCode;
				if ((int)((OpCode)(ref opCode)).OperandType == 0 && OptimizeBranch(current))
				{
					ComputeOffsets(body);
				}
			}
		}
		finally
		{
			((IDisposable)enumerator).Dispose();
		}
	}

	private static bool OptimizeBranch(Instruction instruction)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: 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_0081: Expected I4, but got Unknown
		//IL_0092: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d2: 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_00ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0106: Unknown result type (might be due to invalid IL or missing references)
		//IL_0113: Unknown result type (might be due to invalid IL or missing references)
		//IL_0120: Unknown result type (might be due to invalid IL or missing references)
		//IL_012d: Unknown result type (might be due to invalid IL or missing references)
		//IL_013a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0081: Unknown result type (might be due to invalid IL or missing references)
		//IL_0087: Invalid comparison between Unknown and I4
		//IL_0147: Unknown result type (might be due to invalid IL or missing references)
		int offset = ((Instruction)instruction.Operand).Offset;
		int offset2 = instruction.Offset;
		OpCode opCode = instruction.OpCode;
		int num = offset - (offset2 + ((OpCode)(ref opCode)).Size + 4);
		if (num < -128 || num > 127)
		{
			return false;
		}
		opCode = instruction.OpCode;
		Code code = ((OpCode)(ref opCode)).Code;
		switch (code - 55)
		{
		default:
			if ((int)code == 187)
			{
				instruction.OpCode = OpCodes.Leave_S;
			}
			break;
		case 0:
			instruction.OpCode = OpCodes.Br_S;
			break;
		case 1:
			instruction.OpCode = OpCodes.Brfalse_S;
			break;
		case 2:
			instruction.OpCode = OpCodes.Brtrue_S;
			break;
		case 3:
			instruction.OpCode = OpCodes.Beq_S;
			break;
		case 4:
			instruction.OpCode = OpCodes.Bge_S;
			break;
		case 5:
			instruction.OpCode = OpCodes.Bgt_S;
			break;
		case 6:
			instruction.OpCode = OpCodes.Ble_S;
			break;
		case 7:
			instruction.OpCode = OpCodes.Blt_S;
			break;
		case 8:
			instruction.OpCode = OpCodes.Bne_Un_S;
			break;
		case 9:
			instruction.OpCode = OpCodes.Bge_Un_S;
			break;
		case 10:
			instruction.OpCode = OpCodes.Bgt_Un_S;
			break;
		case 11:
			instruction.OpCode = OpCodes.Ble_Un_S;
			break;
		case 12:
			instruction.OpCode = OpCodes.Blt_Un_S;
			break;
		}
		return true;
	}

	private static void ComputeOffsets(MethodBody body)
	{
		//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)
		int num = 0;
		Enumerator<Instruction> enumerator = body.Instructions.GetEnumerator();
		try
		{
			while (enumerator.MoveNext())
			{
				Instruction current = enumerator.Current;
				current.Offset = num;
				num += current.GetSize();
			}
		}
		finally
		{
			((IDisposable)enumerator).Dispose();
		}
	}
}
public static class MethodDefinitionRocks
{
	public static MethodDefinition GetBaseMethod(this MethodDefinition self)
	{
		if (self == null)
		{
			throw new ArgumentNullException("self");
		}
		if (!self.IsVirtual)
		{
			return self;
		}
		if (self.IsNewSlot)
		{
			return self;
		}
		for (TypeDefinition val = ResolveBaseType(self.DeclaringType); val != null; val = ResolveBaseType(val))
		{
			MethodDefinition matchingMethod = GetMatchingMethod(val, self);
			if (matchingMethod != null)
			{
				return matchingMethod;
			}
		}
		return self;
	}

	public static MethodDefinition GetOriginalBaseMethod(this MethodDefinition self)
	{
		if (self == null)
		{
			throw new ArgumentNullException("self");
		}
		while (true)
		{
			MethodDefinition baseMethod = self.GetBaseMethod();
			if (baseMethod == self)
			{
				break;
			}
			self = baseMethod;
		}
		return self;
	}

	private static TypeDefinition ResolveBaseType(TypeDefinition type)
	{
		if (type == null)
		{
			return null;
		}
		TypeReference baseType = type.BaseType;
		if (baseType == null)
		{
			return null;
		}
		return baseType.Resolve();
	}

	private static MethodDefinition GetMatchingMethod(TypeDefinition type, MethodDefinition method)
	{
		return MetadataResolver.GetMethod(type.Methods, (MethodReference)(object)method);
	}
}
public static class ModuleDefinitionRocks
{
	public static IEnumerable<TypeDefinition> GetAllTypes(this ModuleDefinition self)
	{
		if (self == null)
		{
			throw new ArgumentNullException("self");
		}
		return ((IEnumerable<TypeDefinition>)self.Types).SelectMany(Functional.Y((Func<TypeDefinition, IEnumerable<TypeDefinition>> f) => (TypeDefinition type) => ((IEnumerable<TypeDefinition>)type.NestedTypes).SelectMany(f).Prepend(type)));
	}
}
public static class ParameterReferenceRocks
{
	public static int GetSequence(this ParameterReference self)
	{
		return self.Index + 1;
	}
}
public static class TypeDefinitionRocks
{
	public static IEnumerable<MethodDefinition> GetConstructors(this TypeDefinition self)
	{
		if (self == null)
		{
			throw new ArgumentNullException("self");
		}
		if (!self.HasMethods)
		{
			return Empty<MethodDefinition>.Array;
		}
		return ((IEnumerable<MethodDefinition>)self.Methods).Where((MethodDefinition method) => method.IsConstructor);
	}

	public static MethodDefinition GetStaticConstructor(this TypeDefinition self)
	{
		if (self == null)
		{
			throw new ArgumentNullException("self");
		}
		if (!self.HasMethods)
		{
			return null;
		}
		return self.GetConstructors().FirstOrDefault((Func<MethodDefinition, bool>)((MethodDefinition ctor) => ctor.IsStatic));
	}

	public static IEnumerable<MethodDefinition> GetMethods(this TypeDefinition self)
	{
		if (self == null)
		{
			throw new ArgumentNullException("self");
		}
		if (!self.HasMethods)
		{
			return Empty<MethodDefinition>.Array;
		}
		return ((IEnumerable<MethodDefinition>)self.Methods).Where((MethodDefinition method) => !method.IsConstructor);
	}

	public static TypeReference GetEnumUnderlyingType(this TypeDefinition self)
	{
		if (self == null)
		{
			throw new ArgumentNullException("self");
		}
		if (!self.IsEnum)
		{
			throw new ArgumentException();
		}
		return Mixin.GetEnumUnderlyingType(self);
	}
}
public static class TypeReferenceRocks
{
	public static ArrayType MakeArrayType(this TypeReference self)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Expected O, but got Unknown
		return new ArrayType(self);
	}

	public static ArrayType MakeArrayType(this TypeReference self, int rank)
	{
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Expected O, but got Unknown
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		if (rank == 0)
		{
			throw new ArgumentOutOfRangeException("rank");
		}
		ArrayType val = new ArrayType(self);
		for (int i = 1; i < rank; i++)
		{
			val.Dimensions.Add(default(ArrayDimension));
		}
		return val;
	}

	public static PointerType MakePointerType(this TypeReference self)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Expected O, but got Unknown
		return new PointerType(self);
	}

	public static ByReferenceType MakeByReferenceType(this TypeReference self)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Expected O, but got Unknown
		return new ByReferenceType(self);
	}

	public static OptionalModifierType MakeOptionalModifierType(this TypeReference self, TypeReference modifierType)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Expected O, but got Unknown
		return new OptionalModifierType(modifierType, self);
	}

	public static RequiredModifierType MakeRequiredModifierType(this TypeReference self, TypeReference modifierType)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Expected O, but got Unknown
		return new RequiredModifierType(modifierType, self);
	}

	public static GenericInstanceType MakeGenericInstanceType(this TypeReference self, params TypeReference[] arguments)
	{
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Expected O, but got Unknown
		if (self == null)
		{
			throw new ArgumentNullException("self");
		}
		if (arguments == null)
		{
			throw new ArgumentNullException("arguments");
		}
		if (arguments.Length == 0)
		{
			throw new ArgumentException();
		}
		if (self.GenericParameters.Count != arguments.Length)
		{
			throw new ArgumentException();
		}
		GenericInstanceType val = new GenericInstanceType(self, arguments.Length);
		foreach (TypeReference val2 in arguments)
		{
			val.GenericArguments.Add(val2);
		}
		return val;
	}

	public static PinnedType MakePinnedType(this TypeReference self)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Expected O, but got Unknown
		return new PinnedType(self);
	}

	public static SentinelType MakeSentinelType(this TypeReference self)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Expected O, but got Unknown
		return new SentinelType(self);
	}
}

BepInExPack/BepInEx/core/MonoMod.RuntimeDetour.dll

Decompiled a month ago
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Dynamic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Net;
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 Microsoft.CodeAnalysis;
using Mono.Cecil;
using Mono.Cecil.Cil;
using Mono.Collections.Generic;
using MonoMod.Cil;
using MonoMod.RuntimeDetour.HookGen;
using MonoMod.RuntimeDetour.Platforms;
using MonoMod.Utils;
using MonoMod.Utils.Cil;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("0x0ade")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyCopyright("Copyright 2022 0x0ade")]
[assembly: AssemblyDescription("Flexible and easily extensible runtime detouring library. Wrap, replace and manipulate (Mono.Cecil) methods at runtime.")]
[assembly: AssemblyFileVersion("22.5.1.1")]
[assembly: AssemblyInformationalVersion("22.05.01.01")]
[assembly: AssemblyProduct("MonoMod.RuntimeDetour")]
[assembly: AssemblyTitle("MonoMod.RuntimeDetour")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("22.5.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
	{
	}
}
internal static class MultiTargetShims
{
	private static readonly object[] _NoArgs = new object[0];

	public static string Replace(this string self, string oldValue, string newValue, StringComparison comparison)
	{
		return self.Replace(oldValue, newValue);
	}

	public static bool Contains(this string self, string value, StringComparison comparison)
	{
		return self.Contains(value);
	}

	public static int GetHashCode(this string self, StringComparison comparison)
	{
		return self.GetHashCode();
	}

	public static int IndexOf(this string self, char value, StringComparison comparison)
	{
		return self.IndexOf(value);
	}

	public static int IndexOf(this string self, string value, StringComparison comparison)
	{
		return self.IndexOf(value);
	}

	public static Module[] GetModules(this Assembly asm)
	{
		return asm.Modules.ToArray();
	}

	public static Module GetModule(this Assembly asm, string name)
	{
		return asm.Modules.FirstOrDefault((Module module) => module.Name == name);
	}

	public static byte[] GetBuffer(this MemoryStream ms)
	{
		long position = ms.Position;
		byte[] array = new byte[ms.Length];
		ms.Read(array, 0, array.Length);
		ms.Position = position;
		return array;
	}

	public static TypeReference GetConstraintType(this GenericParameterConstraint constraint)
	{
		return constraint.ConstraintType;
	}
}
namespace MonoMod
{
	internal static class MMDbgLog
	{
		public static readonly string Tag;

		public static TextWriter Writer;

		public static bool Debugging;

		static MMDbgLog()
		{
			Tag = typeof(MMDbgLog).Assembly.GetName().Name;
			if (!(Environment.GetEnvironmentVariable("MONOMOD_DBGLOG") == "1"))
			{
				string? environmentVariable = Environment.GetEnvironmentVariable("MONOMOD_DBGLOG");
				bool? obj;
				if (environmentVariable == null)
				{
					obj = null;
				}
				else
				{
					string text = environmentVariable.ToLower(CultureInfo.InvariantCulture);
					obj = ((text != null) ? new bool?(MultiTargetShims.Contains(text, Tag.ToLower(CultureInfo.InvariantCulture), StringComparison.Ordinal)) : null);
				}
				bool? flag = obj;
				if (!flag.GetValueOrDefault())
				{
					return;
				}
			}
			Start();
		}

		public static void WaitForDebugger()
		{
			if (!Debugging)
			{
				Debugging = true;
				Debugger.Launch();
				Thread.Sleep(6000);
				Debugger.Break();
			}
		}

		public static void Start()
		{
			if (Writer != null)
			{
				return;
			}
			string text = Environment.GetEnvironmentVariable("MONOMOD_DBGLOG_PATH");
			if (text == "-")
			{
				Writer = Console.Out;
				return;
			}
			if (string.IsNullOrEmpty(text))
			{
				text = "mmdbglog.txt";
			}
			text = Path.GetFullPath(Path.GetFileNameWithoutExtension(text) + "-" + Tag + Path.GetExtension(text));
			try
			{
				if (File.Exists(text))
				{
					File.Delete(text);
				}
			}
			catch
			{
			}
			try
			{
				string directoryName = Path.GetDirectoryName(text);
				if (!Directory.Exists(directoryName))
				{
					Directory.CreateDirectory(directoryName);
				}
				Writer = new StreamWriter(new FileStream(text, FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite | FileShare.Delete), Encoding.UTF8);
			}
			catch
			{
			}
		}

		public static void Log(string str)
		{
			TextWriter writer = Writer;
			if (writer != null)
			{
				writer.WriteLine(str);
				writer.Flush();
			}
		}

		public static T Log<T>(string str, T value)
		{
			TextWriter writer = Writer;
			if (writer == null)
			{
				return value;
			}
			writer.WriteLine(string.Format(CultureInfo.InvariantCulture, str, value));
			writer.Flush();
			return value;
		}
	}
}
namespace MonoMod.RuntimeDetour
{
	public struct DetourConfig
	{
		public bool ManualApply;

		public int Priority;

		public string ID;

		public IEnumerable<string> Before;

		public IEnumerable<string> After;
	}
	public class Detour : ISortableDetour, IDetour, IDisposable
	{
		private static ConcurrentDictionary<MethodBase, List<Detour>> _DetourMap = new ConcurrentDictionary<MethodBase, List<Detour>>((IEqualityComparer<MethodBase>?)new GenericMethodInstantiationComparer());

		private static Dictionary<MethodBase, MethodInfo> _BackupMethods = new Dictionary<MethodBase, MethodInfo>();

		private static uint _GlobalIndexNext = 0u;

		public static Func<Detour, MethodBase, MethodBase, bool> OnDetour;

		public static Func<Detour, bool> OnUndo;

		public static Func<Detour, MethodBase, MethodBase> OnGenerateTrampoline;

		private readonly uint _GlobalIndex;

		private int _Priority;

		private string _ID;

		private List<string> _Before = new List<string>();

		private ReadOnlyCollection<string> _BeforeRO;

		private List<string> _After = new List<string>();

		private ReadOnlyCollection<string> _AfterRO;

		public readonly MethodBase Method;

		public readonly MethodBase Target;

		public readonly MethodBase TargetReal;

		private NativeDetour _TopDetour;

		private MethodInfo _ChainedTrampoline;

		private static int compileMethodSubscribed = 0;

		private List<Detour> _DetourChain
		{
			get
			{
				if (!_DetourMap.TryGetValue(Method, out var value))
				{
					return null;
				}
				return value;
			}
		}

		public bool IsValid => Index != -1;

		public bool IsApplied { get; private set; }

		private bool IsTop => _TopDetour != null;

		public int Index => _DetourChain?.IndexOf(this) ?? (-1);

		public int MaxIndex => _DetourChain?.Count ?? (-1);

		public uint GlobalIndex => _GlobalIndex;

		public int Priority
		{
			get
			{
				return _Priority;
			}
			set
			{
				if (_Priority != value)
				{
					_Priority = value;
					_RefreshChain(Method);
				}
			}
		}

		public string ID
		{
			get
			{
				return _ID;
			}
			set
			{
				if (string.IsNullOrEmpty(value))
				{
					value = Extensions.GetID(Target, (string)null, (string)null, true, false, true);
				}
				if (!(_ID == value))
				{
					_ID = value;
					_RefreshChain(Method);
				}
			}
		}

		public IEnumerable<string> Before
		{
			get
			{
				return _BeforeRO ?? (_BeforeRO = _Before.AsReadOnly());
			}
			set
			{
				lock (_Before)
				{
					_Before.Clear();
					if (value != null)
					{
						foreach (string item in value)
						{
							_Before.Add(item);
						}
					}
					_RefreshChain(Method);
				}
			}
		}

		public IEnumerable<string> After
		{
			get
			{
				return _AfterRO ?? (_AfterRO = _After.AsReadOnly());
			}
			set
			{
				lock (_After)
				{
					_After.Clear();
					if (value != null)
					{
						foreach (string item in value)
						{
							_After.Add(item);
						}
					}
					_RefreshChain(Method);
				}
			}
		}

		public Detour(MethodBase from, MethodBase to, ref DetourConfig config)
		{
			//IL_0264: Unknown result type (might be due to invalid IL or missing references)
			//IL_026b: Expected O, but got Unknown
			from = from.GetIdentifiable();
			if (from.Equals(to))
			{
				throw new ArgumentException("Cannot detour a method to itself!");
			}
			MMDbgLog.Log("detour from " + Extensions.GetID(from, (string)null, (string)null, true, false, false) + " to " + Extensions.GetID(to, (string)null, (string)null, true, false, false));
			Method = from;
			Target = to.Pin();
			TargetReal = DetourHelper.Runtime.GetDetourTarget(from, to);
			_GlobalIndex = _GlobalIndexNext++;
			_Priority = config.Priority;
			_ID = config.ID;
			if (config.Before != null)
			{
				foreach (string item in config.Before)
				{
					_Before.Add(item);
				}
			}
			if (config.After != null)
			{
				foreach (string item2 in config.After)
				{
					_After.Add(item2);
				}
			}
			lock (_BackupMethods)
			{
				if ((!_BackupMethods.TryGetValue(Method, out var value) || value == null) && (value = Method.CreateILCopy()) != null)
				{
					_BackupMethods[Method] = value.Pin();
				}
			}
			ParameterInfo[] parameters = Method.GetParameters();
			Type[] array;
			if (!Method.IsStatic)
			{
				array = new Type[parameters.Length + 1];
				array[0] = Extensions.GetThisParamType(Method);
				for (int i = 0; i < parameters.Length; i++)
				{
					array[i + 1] = parameters[i].ParameterType;
				}
			}
			else
			{
				array = new Type[parameters.Length];
				for (int j = 0; j < parameters.Length; j++)
				{
					array[j] = parameters[j].ParameterType;
				}
			}
			DynamicMethodDefinition val = new DynamicMethodDefinition($"Chain<{Extensions.GetID(Method, (string)null, (string)null, true, false, true)}>?{GetHashCode()}", (Method as MethodInfo)?.ReturnType ?? typeof(void), array);
			try
			{
				_ChainedTrampoline = val.StubCriticalDetour().Generate().Pin();
			}
			finally
			{
				((IDisposable)val)?.Dispose();
			}
			List<Detour> orAdd = _DetourMap.GetOrAdd(Method, (MethodBase m) => new List<Detour>());
			lock (orAdd)
			{
				orAdd.Add(this);
			}
			if (!config.ManualApply)
			{
				Apply();
			}
		}

		public Detour(MethodBase from, MethodBase to, DetourConfig config)
			: this(from, to, ref config)
		{
		}

		public Detour(MethodBase from, MethodBase to)
			: this(from, to, DetourContext.Current?.DetourConfig ?? default(DetourConfig))
		{
		}

		public Detour(MethodBase method, IntPtr to, ref DetourConfig config)
			: this(method, DetourHelper.GenerateNativeProxy(to, method), ref config)
		{
		}

		public Detour(MethodBase method, IntPtr to, DetourConfig config)
			: this(method, DetourHelper.GenerateNativeProxy(to, method), ref config)
		{
		}

		public Detour(MethodBase method, IntPtr to)
			: this(method, DetourHelper.GenerateNativeProxy(to, method))
		{
		}

		public Detour(Delegate from, IntPtr to, ref DetourConfig config)
			: this(from.Method, to, ref config)
		{
		}

		public Detour(Delegate from, IntPtr to, DetourConfig config)
			: this(from.Method, to, ref config)
		{
		}

		public Detour(Delegate from, IntPtr to)
			: this(from.Method, to)
		{
		}

		public Detour(Delegate from, Delegate to, ref DetourConfig config)
			: this(from.Method, to.Method, ref config)
		{
		}

		public Detour(Delegate from, Delegate to, DetourConfig config)
			: this(from.Method, to.Method, ref config)
		{
		}

		public Detour(Delegate from, Delegate to)
			: this(from.Method, to.Method)
		{
		}

		public Detour(Expression from, IntPtr to, ref DetourConfig config)
			: this(((MethodCallExpression)from).Method, to, ref config)
		{
		}

		public Detour(Expression from, IntPtr to, DetourConfig config)
			: this(((MethodCallExpression)from).Method, to, ref config)
		{
		}

		public Detour(Expression from, IntPtr to)
			: this(((MethodCallExpression)from).Method, to)
		{
		}

		public Detour(Expression from, Expression to, ref DetourConfig config)
			: this(((MethodCallExpression)from).Method, ((MethodCallExpression)to).Method, ref config)
		{
		}

		public Detour(Expression from, Expression to, DetourConfig config)
			: this(((MethodCallExpression)from).Method, ((MethodCallExpression)to).Method, ref config)
		{
		}

		public Detour(Expression from, Expression to)
			: this(((MethodCallExpression)from).Method, ((MethodCallExpression)to).Method)
		{
		}

		public Detour(Expression<Action> from, IntPtr to, ref DetourConfig config)
			: this(from.Body, to, ref config)
		{
		}

		public Detour(Expression<Action> from, IntPtr to, DetourConfig config)
			: this(from.Body, to, ref config)
		{
		}

		public Detour(Expression<Action> from, IntPtr to)
			: this(from.Body, to)
		{
		}

		public Detour(Expression<Action> from, Expression<Action> to, ref DetourConfig config)
			: this(from.Body, to.Body, ref config)
		{
		}

		public Detour(Expression<Action> from, Expression<Action> to, DetourConfig config)
			: this(from.Body, to.Body, ref config)
		{
		}

		public Detour(Expression<Action> from, Expression<Action> to)
			: this(from.Body, to.Body)
		{
		}

		public void Apply()
		{
			if (!IsValid)
			{
				throw new ObjectDisposedException("Detour");
			}
			if (!IsApplied)
			{
				Func<Detour, MethodBase, MethodBase, bool> onDetour = OnDetour;
				if (onDetour == null || Extensions.InvokeWhileTrue((MulticastDelegate)onDetour, new object[3] { this, Method, Target }))
				{
					IsApplied = true;
					_RefreshChain(Method);
				}
			}
		}

		public void Undo()
		{
			if (!IsValid)
			{
				throw new ObjectDisposedException("Detour");
			}
			if (IsApplied)
			{
				Func<Detour, bool> onUndo = OnUndo;
				if (onUndo == null || Extensions.InvokeWhileTrue((MulticastDelegate)onUndo, new object[1] { this }))
				{
					IsApplied = false;
					_RefreshChain(Method);
				}
			}
		}

		public void Free()
		{
			if (!IsValid)
			{
				return;
			}
			Undo();
			List<Detour> detourChain = _DetourChain;
			lock (detourChain)
			{
				detourChain.Remove(this);
				if (detourChain.Count == 0)
				{
					lock (_BackupMethods)
					{
						if (_BackupMethods.TryGetValue(Method, out var value))
						{
							value.Unpin();
							_BackupMethods.Remove(Method);
						}
					}
					_DetourMap.TryRemove(Method, out var _);
				}
			}
			_ChainedTrampoline.Unpin();
			Target.Unpin();
		}

		public void Dispose()
		{
			if (IsValid)
			{
				Undo();
				Free();
			}
		}

		public MethodBase GenerateTrampoline(MethodBase signature = null)
		{
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Expected O, but got Unknown
			//IL_00ca: 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)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			Func<Detour, MethodBase, MethodBase> onGenerateTrampoline = OnGenerateTrampoline;
			MethodBase methodBase = ((onGenerateTrampoline != null) ? Extensions.InvokeWhileNull<MethodBase>((MulticastDelegate)onGenerateTrampoline, new object[2] { this, signature }) : null);
			if (methodBase != null)
			{
				return methodBase;
			}
			if (signature == null)
			{
				signature = Target;
			}
			Type type = (signature as MethodInfo)?.ReturnType ?? typeof(void);
			ParameterInfo[] parameters = signature.GetParameters();
			Type[] array = new Type[parameters.Length];
			for (int i = 0; i < parameters.Length; i++)
			{
				array[i] = parameters[i].ParameterType;
			}
			DynamicMethodDefinition val = new DynamicMethodDefinition($"Trampoline<{Extensions.GetID(Method, (string)null, (string)null, true, false, true)}>?{GetHashCode()}", type, array);
			try
			{
				ILProcessor iLProcessor = val.GetILProcessor();
				for (int j = 0; j < 32; j++)
				{
					iLProcessor.Emit(OpCodes.Nop);
				}
				for (int k = 0; k < array.Length; k++)
				{
					iLProcessor.Emit(OpCodes.Ldarg, k);
				}
				Extensions.Emit(iLProcessor, OpCodes.Call, (MethodBase)_ChainedTrampoline);
				iLProcessor.Emit(OpCodes.Ret);
				return val.Generate();
			}
			finally
			{
				((IDisposable)val)?.Dispose();
			}
		}

		public T GenerateTrampoline<T>() where T : Delegate
		{
			if (!typeof(Delegate).IsAssignableFrom(typeof(T)))
			{
				throw new InvalidOperationException($"Type {typeof(T)} not a delegate type.");
			}
			return Extensions.CreateDelegate(GenerateTrampoline(typeof(T).GetMethod("Invoke")), typeof(T)) as T;
		}

		private void _TopUndo()
		{
			if (_TopDetour != null)
			{
				_TopDetour.Undo();
				_TopDetour.Free();
				_TopDetour = null;
				Method.Unpin();
				TargetReal.Unpin();
			}
		}

		private void _TopApply()
		{
			if (_TopDetour == null)
			{
				_TopDetour = new NativeDetour(Method.Pin().GetNativeStart(), TargetReal.Pin().GetNativeStart());
			}
		}

		private static void _OnCompileMethod(MethodBase method, IntPtr codeStart, ulong codeLen)
		{
			if (method == null)
			{
				return;
			}
			MMDbgLog.Log("compiling: " + Extensions.GetID(method, (string)null, (string)null, true, false, false));
			if (_DetourMap.TryGetValue(method, out var value))
			{
				value.FindLast((Detour d) => d.IsTop)?._TopDetour?.ChangeSource(codeStart);
			}
		}

		private static void _RefreshChain(MethodBase method)
		{
			if (Interlocked.CompareExchange(ref compileMethodSubscribed, 1, 0) == 0)
			{
				DetourHelper.Runtime.OnMethodCompiled += _OnCompileMethod;
			}
			MMDbgLog.Log("detours applying for " + Extensions.GetID(method, (string)null, (string)null, true, false, false));
			List<Detour> list = _DetourMap[method];
			lock (list)
			{
				DetourSorter<Detour>.Sort(list);
				Detour detour = list.FindLast((Detour d) => d.IsTop);
				Detour detour2 = list.FindLast((Detour d) => d.IsApplied);
				if (detour != detour2)
				{
					detour?._TopUndo();
				}
				if (list.Count == 0)
				{
					return;
				}
				MethodBase method2 = _BackupMethods[method];
				foreach (Detour item in list)
				{
					if (item.IsApplied)
					{
						_ = item._ChainedTrampoline;
						using (NativeDetour nativeDetour = new NativeDetour(item._ChainedTrampoline.GetNativeStart(), method2.GetNativeStart()))
						{
							nativeDetour.Free();
						}
						method2 = item.Target;
					}
				}
				if (detour != detour2)
				{
					detour2?._TopApply();
				}
			}
		}
	}
	public class Detour<T> : Detour where T : Delegate
	{
		public Detour(T from, IntPtr to, ref DetourConfig config)
			: base(from, to, ref config)
		{
		}

		public Detour(T from, IntPtr to, DetourConfig config)
			: base(from, to, ref config)
		{
		}

		public Detour(T from, IntPtr to)
			: base(from, to)
		{
		}

		public Detour(T from, T to, ref DetourConfig config)
			: base(from, to, ref config)
		{
		}

		public Detour(T from, T to, DetourConfig config)
			: base(from, to, ref config)
		{
		}

		public Detour(T from, T to)
			: base(from, to)
		{
		}
	}
	public sealed class DetourContext : IDisposable
	{
		[ThreadStatic]
		private static List<DetourContext> _Contexts;

		[ThreadStatic]
		private static DetourContext Last;

		private MethodBase Creator;

		public int Priority;

		private readonly string _FallbackID;

		private string _ID;

		public List<string> Before = new List<string>();

		public List<string> After = new List<string>();

		private bool IsDisposed;

		private static List<DetourContext> Contexts => _Contexts ?? (_Contexts = new List<DetourContext>());

		internal static DetourContext Current
		{
			get
			{
				DetourContext last = Last;
				if (last != null && last.IsValid)
				{
					return Last;
				}
				List<DetourContext> contexts = Contexts;
				int num = contexts.Count - 1;
				while (num > -1)
				{
					DetourContext detourContext = contexts[num];
					if (!detourContext.IsValid)
					{
						contexts.RemoveAt(num);
						num--;
						continue;
					}
					return Last = detourContext;
				}
				return null;
			}
		}

		public string ID
		{
			get
			{
				return _ID ?? _FallbackID;
			}
			set
			{
				_ID = (string.IsNullOrEmpty(value) ? null : value);
			}
		}

		public DetourConfig DetourConfig
		{
			get
			{
				DetourConfig result = default(DetourConfig);
				result.Priority = Priority;
				result.ID = ID;
				result.Before = Before;
				result.After = After;
				return result;
			}
		}

		public HookConfig HookConfig
		{
			get
			{
				HookConfig result = default(HookConfig);
				result.Priority = Priority;
				result.ID = ID;
				result.Before = Before;
				result.After = After;
				return result;
			}
		}

		public ILHookConfig ILHookConfig
		{
			get
			{
				ILHookConfig result = default(ILHookConfig);
				result.Priority = Priority;
				result.ID = ID;
				result.Before = Before;
				result.After = After;
				return result;
			}
		}

		internal bool IsValid
		{
			get
			{
				if (IsDisposed)
				{
					return false;
				}
				if (Creator == null)
				{
					return true;
				}
				StackTrace stackTrace = new StackTrace();
				int frameCount = stackTrace.FrameCount;
				for (int i = 0; i < frameCount; i++)
				{
					if (stackTrace.GetFrame(i).GetMethod() == Creator)
					{
						return true;
					}
				}
				return false;
			}
		}

		public DetourContext(int priority, string id)
		{
			StackTrace stackTrace = new StackTrace();
			int frameCount = stackTrace.FrameCount;
			for (int i = 0; i < frameCount; i++)
			{
				MethodBase method = stackTrace.GetFrame(i).GetMethod();
				if (!(method?.DeclaringType == typeof(DetourContext)))
				{
					Creator = method;
					break;
				}
			}
			object obj = Creator?.DeclaringType?.Assembly?.GetName().Name;
			if (obj == null)
			{
				MethodBase creator = Creator;
				obj = (((object)creator != null) ? Extensions.GetID(creator, (string)null, (string)null, true, false, true) : null);
			}
			_FallbackID = (string)obj;
			Last = this;
			Contexts.Add(this);
			Priority = priority;
			ID = id;
		}

		public DetourContext(string id)
			: this(0, id)
		{
		}

		public DetourContext(int priority)
			: this(priority, null)
		{
		}

		public DetourContext()
			: this(0, null)
		{
		}

		public void Dispose()
		{
			if (IsDisposed)
			{
				IsDisposed = true;
				Last = null;
				Contexts.Remove(this);
			}
		}
	}
	public sealed class DetourModManager : IDisposable
	{
		private readonly Dictionary<IDetour, Assembly> DetourOwners = new Dictionary<IDetour, Assembly>();

		private readonly Dictionary<Assembly, List<IDetour>> OwnedDetourLists = new Dictionary<Assembly, List<IDetour>>();

		public HashSet<Assembly> Ignored = new HashSet<Assembly>();

		private bool Disposed;

		private static readonly string[] HookTypeNames = new string[4] { "MonoMod.RuntimeDetour.NativeDetour", "MonoMod.RuntimeDetour.Detour", "MonoMod.RuntimeDetour.Hook", "MonoMod.RuntimeDetour.ILHook" };

		public event Action<Assembly, MethodBase, Manipulator> OnILHook;

		public event Action<Assembly, MethodBase, MethodBase, object> OnHook;

		public event Action<Assembly, MethodBase, MethodBase> OnDetour;

		public event Action<Assembly, MethodBase, IntPtr, IntPtr> OnNativeDetour;

		public DetourModManager()
		{
			Ignored.Add(typeof(DetourModManager).Assembly);
			ILHook.OnDetour = (Func<ILHook, MethodBase, Manipulator, bool>)Delegate.Combine(ILHook.OnDetour, new Func<ILHook, MethodBase, Manipulator, bool>(RegisterILHook));
			ILHook.OnUndo = (Func<ILHook, bool>)Delegate.Combine(ILHook.OnUndo, new Func<ILHook, bool>(UnregisterDetour));
			Hook.OnDetour = (Func<Hook, MethodBase, MethodBase, object, bool>)Delegate.Combine(Hook.OnDetour, new Func<Hook, MethodBase, MethodBase, object, bool>(RegisterHook));
			Hook.OnUndo = (Func<Hook, bool>)Delegate.Combine(Hook.OnUndo, new Func<Hook, bool>(UnregisterDetour));
			Detour.OnDetour = (Func<Detour, MethodBase, MethodBase, bool>)Delegate.Combine(Detour.OnDetour, new Func<Detour, MethodBase, MethodBase, bool>(RegisterDetour));
			Detour.OnUndo = (Func<Detour, bool>)Delegate.Combine(Detour.OnUndo, new Func<Detour, bool>(UnregisterDetour));
			NativeDetour.OnDetour = (Func<NativeDetour, MethodBase, IntPtr, IntPtr, bool>)Delegate.Combine(NativeDetour.OnDetour, new Func<NativeDetour, MethodBase, IntPtr, IntPtr, bool>(RegisterNativeDetour));
			NativeDetour.OnUndo = (Func<NativeDetour, bool>)Delegate.Combine(NativeDetour.OnUndo, new Func<NativeDetour, bool>(UnregisterDetour));
		}

		public void Dispose()
		{
			if (!Disposed)
			{
				Disposed = true;
				OwnedDetourLists.Clear();
				ILHook.OnDetour = (Func<ILHook, MethodBase, Manipulator, bool>)Delegate.Remove(ILHook.OnDetour, new Func<ILHook, MethodBase, Manipulator, bool>(RegisterILHook));
				ILHook.OnUndo = (Func<ILHook, bool>)Delegate.Remove(ILHook.OnUndo, new Func<ILHook, bool>(UnregisterDetour));
				Hook.OnDetour = (Func<Hook, MethodBase, MethodBase, object, bool>)Delegate.Remove(Hook.OnDetour, new Func<Hook, MethodBase, MethodBase, object, bool>(RegisterHook));
				Hook.OnUndo = (Func<Hook, bool>)Delegate.Remove(Hook.OnUndo, new Func<Hook, bool>(UnregisterDetour));
				Detour.OnDetour = (Func<Detour, MethodBase, MethodBase, bool>)Delegate.Remove(Detour.OnDetour, new Func<Detour, MethodBase, MethodBase, bool>(RegisterDetour));
				Detour.OnUndo = (Func<Detour, bool>)Delegate.Remove(Detour.OnUndo, new Func<Detour, bool>(UnregisterDetour));
				NativeDetour.OnDetour = (Func<NativeDetour, MethodBase, IntPtr, IntPtr, bool>)Delegate.Remove(NativeDetour.OnDetour, new Func<NativeDetour, MethodBase, IntPtr, IntPtr, bool>(RegisterNativeDetour));
				NativeDetour.OnUndo = (Func<NativeDetour, bool>)Delegate.Remove(NativeDetour.OnUndo, new Func<NativeDetour, bool>(UnregisterDetour));
			}
		}

		public void Unload(Assembly asm)
		{
			if (asm == null || Ignored.Contains(asm))
			{
				return;
			}
			HookEndpointManager.RemoveAllOwnedBy(asm);
			if (OwnedDetourLists.TryGetValue(asm, out var value))
			{
				IDetour[] array = value.ToArray();
				for (int i = 0; i < array.Length; i++)
				{
					array[i].Dispose();
				}
				if (value.Count > 0)
				{
					throw new Exception("Some detours failed to unregister in " + asm.FullName);
				}
				OwnedDetourLists.Remove(asm);
			}
		}

		internal Assembly GetHookOwner(StackTrace stack = null)
		{
			if (stack == null)
			{
				stack = new StackTrace();
			}
			Assembly assembly = null;
			int frameCount = stack.FrameCount;
			string text = null;
			for (int i = 0; i < frameCount; i++)
			{
				MethodBase method = stack.GetFrame(i).GetMethod();
				if (method?.DeclaringType == null)
				{
					continue;
				}
				string fullName = method.DeclaringType.FullName;
				if (text == null)
				{
					if (HookTypeNames.Contains(fullName))
					{
						text = method.DeclaringType.FullName;
					}
				}
				else if (!(fullName == text))
				{
					assembly = method?.DeclaringType.Assembly;
					break;
				}
			}
			if (Ignored.Contains(assembly))
			{
				return null;
			}
			return assembly;
		}

		internal void TrackDetour(Assembly owner, IDetour detour)
		{
			if (!OwnedDetourLists.TryGetValue(owner, out var value))
			{
				value = (OwnedDetourLists[owner] = new List<IDetour>());
			}
			value.Add(detour);
			DetourOwners[detour] = owner;
		}

		internal bool RegisterILHook(ILHook _detour, MethodBase from, Manipulator manipulator)
		{
			Assembly hookOwner = GetHookOwner();
			if (hookOwner == null)
			{
				return true;
			}
			this.OnILHook?.Invoke(hookOwner, from, manipulator);
			TrackDetour(hookOwner, _detour);
			return true;
		}

		internal bool RegisterHook(Hook _detour, MethodBase from, MethodBase to, object target)
		{
			Assembly hookOwner = GetHookOwner();
			if (hookOwner == null)
			{
				return true;
			}
			this.OnHook?.Invoke(hookOwner, from, to, target);
			TrackDetour(hookOwner, _detour);
			return true;
		}

		internal bool RegisterDetour(Detour _detour, MethodBase from, MethodBase to)
		{
			Assembly hookOwner = GetHookOwner();
			if (hookOwner == null)
			{
				return true;
			}
			this.OnDetour?.Invoke(hookOwner, from, to);
			TrackDetour(hookOwner, _detour);
			return true;
		}

		internal bool RegisterNativeDetour(NativeDetour _detour, MethodBase method, IntPtr from, IntPtr to)
		{
			Assembly hookOwner = GetHookOwner();
			if (hookOwner == null)
			{
				return true;
			}
			this.OnNativeDetour?.Invoke(hookOwner, method, from, to);
			TrackDetour(hookOwner, _detour);
			return true;
		}

		internal bool UnregisterDetour(IDetour _detour)
		{
			if (DetourOwners.TryGetValue(_detour, out var value))
			{
				DetourOwners.Remove(_detour);
				OwnedDetourLists[value].Remove(_detour);
			}
			return true;
		}
	}
	public sealed class DynamicHookGen : DynamicObject
	{
		private enum ActionType
		{
			Add,
			Remove
		}

		public enum HookType
		{
			OnOrIL,
			On,
			IL
		}

		private DynamicHookGen Parent;

		private string Name;

		private Type Type;

		private HookType NodeHookType;

		public static dynamic On = new DynamicHookGen(HookType.On);

		public static dynamic IL = new DynamicHookGen(HookType.IL);

		public static dynamic OnOrIL = new DynamicHookGen(HookType.OnOrIL);

		private int OwnLendID;

		private int NextLendID;

		private List<Tuple<ActionType, Delegate>> Actions = new List<Tuple<ActionType, Delegate>>();

		private string Path
		{
			get
			{
				if (Parent?.Name == null)
				{
					return Name;
				}
				List<string> list = new List<string>();
				DynamicHookGen dynamicHookGen = this;
				while (dynamicHookGen != null && dynamicHookGen.Name != null)
				{
					list.Add(dynamicHookGen.Name);
					dynamicHookGen = dynamicHookGen.Parent;
				}
				list.Reverse();
				return string.Join(".", list);
			}
		}

		private DynamicHookGen(HookType hookType)
		{
			NodeHookType = hookType;
		}

		private DynamicHookGen(DynamicHookGen parent, string name)
		{
			Parent = parent;
			Name = name;
			NodeHookType = parent.NodeHookType;
			OwnLendID = parent.NextLendID++;
		}

		private DynamicHookGen(DynamicHookGen source)
		{
			Parent = source.Parent;
			Name = source.Name;
			NodeHookType = source.NodeHookType;
			OwnLendID = source.OwnLendID;
			Actions.AddRange(source.Actions);
		}

		public DynamicHookGen(Type type)
			: this(type, HookType.OnOrIL)
		{
		}

		public DynamicHookGen(Type type, HookType hookType)
		{
			Name = type.FullName;
			Type = type;
			NodeHookType = hookType;
		}

		private void Apply()
		{
			string path = Parent.Path;
			Type type = Parent.Type ?? ReflectionHelper.GetType(path);
			if (type == null)
			{
				throw new ArgumentException("Couldn't find type " + path);
			}
			MethodBase methodBase = null;
			methodBase = ((!(Name == "ctor")) ? ((MethodBase)type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic).FirstOrDefault((MethodInfo m) => m.Name == Name)) : ((MethodBase)type.GetConstructors(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).FirstOrDefault()));
			if (methodBase == null)
			{
				throw new ArgumentException("Couldn't find method " + path + "::" + Name);
			}
			foreach (Tuple<ActionType, Delegate> action in Actions)
			{
				Delegate item = action.Item2;
				HookType hookType = NodeHookType;
				if (hookType == HookType.OnOrIL)
				{
					MethodInfo? method = item.GetType().GetMethod("Invoke");
					ParameterInfo[] parameters = method.GetParameters();
					hookType = ((!(method.ReturnType == typeof(void)) || parameters.Length != 1 || !Extensions.IsCompatible(parameters[0].ParameterType, typeof(ILContext)) || parameters[0].IsOut) ? HookType.On : HookType.IL);
				}
				switch (action.Item1)
				{
				case ActionType.Add:
					if (hookType == HookType.IL)
					{
						HookEndpointManager.Modify(methodBase, item);
					}
					else
					{
						HookEndpointManager.Add(methodBase, item);
					}
					break;
				case ActionType.Remove:
					if (hookType == HookType.IL)
					{
						HookEndpointManager.Unmodify(methodBase, item);
					}
					else
					{
						HookEndpointManager.Remove(methodBase, item);
					}
					break;
				}
			}
			Actions.Clear();
		}

		public override bool TryInvoke(InvokeBinder binder, object[] args, out object result)
		{
			if (args.Length != 1 || !(args[0] is Type type))
			{
				throw new ArgumentException("Expected type.");
			}
			result = new DynamicHookGen(type, NodeHookType);
			return true;
		}

		public override bool TryGetMember(GetMemberBinder binder, out object result)
		{
			result = new DynamicHookGen(this, binder.Name);
			return true;
		}

		public override bool TrySetMember(SetMemberBinder binder, object value)
		{
			DynamicHookGen obj = (value as DynamicHookGen) ?? throw new ArgumentException("Incompatible dynamic hooks type. Did you use += / -= properly?");
			if (obj.Parent != this)
			{
				throw new ArgumentException("Dynamic hooks target parent not matching.");
			}
			if (obj.Name != binder.Name)
			{
				throw new ArgumentException("Dynamic hooks target name not matching.");
			}
			if (obj.OwnLendID != NextLendID++ - 1)
			{
				throw new ArgumentException("Dynamic hooks object expired.");
			}
			obj.Apply();
			return true;
		}

		public static DynamicHookGen operator +(DynamicHookGen ctx, Delegate target)
		{
			ctx = new DynamicHookGen(ctx);
			ctx.Actions.Add(new Tuple<ActionType, Delegate>(ActionType.Add, target));
			return ctx;
		}

		public static DynamicHookGen operator -(DynamicHookGen ctx, Delegate target)
		{
			ctx = new DynamicHookGen(ctx);
			ctx.Actions.Add(new Tuple<ActionType, Delegate>(ActionType.Remove, target));
			return ctx;
		}
	}
	public static class HarmonyDetourBridge
	{
		public enum Type
		{
			Auto,
			Basic,
			AsOriginal,
			Override
		}

		private class DetourToRDAttribute : Attribute
		{
			public string Type { get; }

			public int SkipParams { get; }

			public string Name { get; }

			public DetourToRDAttribute(string type, int skipParams = 0, string name = null)
			{
				Type = type;
				SkipParams = skipParams;
				Name = name;
			}
		}

		private class DetourToHAttribute : Attribute
		{
			public string Type { get; }

			public int SkipParams { get; }

			public string Name { get; }

			public DetourToHAttribute(string type, int skipParams = 0, string name = null)
			{
				Type = type;
				SkipParams = skipParams;
				Name = name;
			}
		}

		private class TranspileAttribute : Attribute
		{
			public string Type { get; }

			public string Name { get; }

			public TranspileAttribute(string type, string name = null)
			{
				Type = type;
				Name = name;
			}
		}

		private class CriticalAttribute : Attribute
		{
		}

		private static Type CurrentType;

		private static Assembly _HarmonyASM;

		private static readonly HashSet<IDisposable> _Detours;

		private static readonly Dictionary<System.Type, MethodInfo> _Emitters;

		[ThreadStatic]
		private static DynamicMethodDefinition _LastWrapperDMD;

		private static Assembly _SharedStateASM;

		private static DetourConfig _DetourConfig;

		public static bool Initialized { get; private set; }

		static HarmonyDetourBridge()
		{
			_Detours = new HashSet<IDisposable>();
			_Emitters = new Dictionary<System.Type, MethodInfo>();
			System.Type typeFromHandle = typeof(OpCode);
			System.Type proxyType = ILGeneratorShim.GetProxyType<CecilILGenerator>();
			MethodInfo[] methods = proxyType.GetMethods();
			foreach (MethodInfo methodInfo in methods)
			{
				if (methodInfo.Name != "Emit")
				{
					continue;
				}
				ParameterInfo[] parameters = methodInfo.GetParameters();
				if (parameters.Length == 2 && !(parameters[0].ParameterType != typeFromHandle))
				{
					System.Type parameterType = parameters[1].ParameterType;
					if (!_Emitters.ContainsKey(parameterType) || !(methodInfo.DeclaringType != proxyType))
					{
						_Emitters[parameterType] = methodInfo;
					}
				}
			}
		}

		public static bool Init(bool forceLoad = true, Type type = Type.Auto)
		{
			//IL_0236: Unknown result type (might be due to invalid IL or missing references)
			//IL_023d: Expected O, but got Unknown
			//IL_0247: Unknown result type (might be due to invalid IL or missing references)
			//IL_024c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0259: Expected O, but got Unknown
			if (_HarmonyASM == null)
			{
				_HarmonyASM = _FindHarmony();
			}
			if (_HarmonyASM == null && forceLoad)
			{
				_HarmonyASM = Assembly.Load(new AssemblyName
				{
					Name = "0Harmony"
				});
			}
			if (_HarmonyASM == null)
			{
				return false;
			}
			if (Initialized)
			{
				return true;
			}
			Initialized = true;
			if (type == Type.Auto)
			{
				type = Type.AsOriginal;
			}
			DetourConfig detourConfig = default(DetourConfig);
			detourConfig.Priority = type switch
			{
				Type.Override => 536870911, 
				Type.AsOriginal => -536870912, 
				_ => 0, 
			};
			_DetourConfig = detourConfig;
			CurrentType = type;
			try
			{
				MethodInfo[] methods = typeof(HarmonyDetourBridge).GetMethods(BindingFlags.Static | BindingFlags.NonPublic);
				foreach (MethodInfo methodInfo in methods)
				{
					bool flag = methodInfo.GetCustomAttributes(typeof(CriticalAttribute), inherit: false).Any();
					object[] customAttributes = methodInfo.GetCustomAttributes(typeof(DetourToRDAttribute), inherit: false);
					for (int j = 0; j < customAttributes.Length; j++)
					{
						DetourToRDAttribute detourToRDAttribute = (DetourToRDAttribute)customAttributes[j];
						foreach (MethodInfo item in GetHarmonyMethod(methodInfo, detourToRDAttribute.Type, detourToRDAttribute.SkipParams, detourToRDAttribute.Name))
						{
							flag = false;
							_Detours.Add(new Hook(item, methodInfo));
						}
					}
					customAttributes = methodInfo.GetCustomAttributes(typeof(DetourToHAttribute), inherit: false);
					for (int j = 0; j < customAttributes.Length; j++)
					{
						DetourToHAttribute detourToHAttribute = (DetourToHAttribute)customAttributes[j];
						foreach (MethodInfo item2 in GetHarmonyMethod(methodInfo, detourToHAttribute.Type, detourToHAttribute.SkipParams, detourToHAttribute.Name))
						{
							flag = false;
							_Detours.Add(new Detour(methodInfo, item2));
						}
					}
					customAttributes = methodInfo.GetCustomAttributes(typeof(TranspileAttribute), inherit: false);
					for (int j = 0; j < customAttributes.Length; j++)
					{
						TranspileAttribute transpileAttribute = (TranspileAttribute)customAttributes[j];
						foreach (MethodInfo item3 in GetHarmonyMethod(methodInfo, transpileAttribute.Type, -1, transpileAttribute.Name))
						{
							DynamicMethodDefinition val = new DynamicMethodDefinition((MethodBase)item3);
							try
							{
								flag = false;
								ILContext val2 = new ILContext(val.Definition)
								{
									ReferenceBag = (IILReferenceBag)(object)RuntimeILReferenceBag.Instance
								};
								_Detours.Add((IDisposable)val2);
								val2.Invoke(Extensions.CreateDelegate<Manipulator>((MethodBase)methodInfo));
								if (val2.IsReadOnly)
								{
									val2.Dispose();
									_Detours.Remove((IDisposable)val2);
								}
								else
								{
									_Detours.Add(new Detour(item3, val.Generate()));
								}
							}
							finally
							{
								((IDisposable)val)?.Dispose();
							}
						}
					}
					if (flag)
					{
						throw new Exception("Cannot apply HarmonyDetourBridge rule " + methodInfo.Name);
					}
				}
			}
			catch
			{
				_EarlyReset();
				throw;
			}
			return true;
		}

		private static bool _EarlyReset()
		{
			foreach (IDisposable detour in _Detours)
			{
				detour.Dispose();
			}
			_Detours.Clear();
			return false;
		}

		public static void Reset()
		{
			if (Initialized)
			{
				Initialized = false;
				_EarlyReset();
			}
		}

		private static System.Type GetHarmonyType(string typeName)
		{
			return _HarmonyASM.GetType(typeName) ?? _HarmonyASM.GetType("HarmonyLib." + typeName) ?? _HarmonyASM.GetType("Harmony." + typeName) ?? _HarmonyASM.GetType("Harmony.ILCopying." + typeName);
		}

		private static IEnumerable<MethodInfo> GetHarmonyMethod(MethodInfo ctx, string typeName, int skipParams, string name)
		{
			System.Type harmonyType = GetHarmonyType(typeName);
			if (harmonyType == null)
			{
				return null;
			}
			if (string.IsNullOrEmpty(name))
			{
				name = ctx.Name;
			}
			if (skipParams < 0)
			{
				return from method in harmonyType.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)
					where method.Name == name
					select method;
			}
			return new MethodInfo[1] { harmonyType.GetMethod(name, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, (from p in ctx.GetParameters().Skip(skipParams)
				select p.ParameterType).ToArray(), null) };
		}

		private static DynamicMethodDefinition CreateDMD(MethodBase original, string suffix)
		{
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Expected O, but got Unknown
			if (original == null)
			{
				throw new ArgumentNullException("original");
			}
			ParameterInfo[] parameters = original.GetParameters();
			System.Type[] array;
			if (!original.IsStatic)
			{
				array = new System.Type[parameters.Length + 1];
				array[0] = Extensions.GetThisParamType(original);
				for (int i = 0; i < parameters.Length; i++)
				{
					array[i + 1] = parameters[i].ParameterType;
				}
			}
			else
			{
				array = new System.Type[parameters.Length];
				for (int j = 0; j < parameters.Length; j++)
				{
					array[j] = parameters[j].ParameterType;
				}
			}
			return new DynamicMethodDefinition(MultiTargetShims.Replace(original.Name + suffix, "<>", "", StringComparison.Ordinal), (original as MethodInfo)?.ReturnType ?? typeof(void), array);
		}

		[DetourToRD("Memory", 0, null)]
		private static long GetMethodStart(MethodBase method, out Exception exception)
		{
			exception = null;
			try
			{
				_Detours.Add((IDisposable)new LazyDisposable<MethodBase>(method, (Action<MethodBase>)delegate(MethodBase m)
				{
					m.Unpin();
				}));
				return (long)method.Pin().GetNativeStart();
			}
			catch (Exception ex)
			{
				exception = ex;
				return 0L;
			}
		}

		[DetourToRD("Memory", 0, null)]
		[Critical]
		private static string WriteJump(long memory, long destination)
		{
			_Detours.Add(new NativeDetour((IntPtr)memory, (IntPtr)destination));
			return null;
		}

		[DetourToRD("Memory", 0, null)]
		[Critical]
		private static string DetourMethod(MethodBase original, MethodBase replacement)
		{
			if (replacement == null)
			{
				replacement = _LastWrapperDMD.Generate();
				_LastWrapperDMD.Dispose();
				_LastWrapperDMD = null;
			}
			_Detours.Add(new Detour(original, replacement, ref _DetourConfig));
			return null;
		}

		[DetourToRD("MethodBodyReader", 1, null)]
		private static MethodInfo EmitMethodForType(object self, System.Type type)
		{
			foreach (KeyValuePair<System.Type, MethodInfo> emitter in _Emitters)
			{
				if (emitter.Key == type)
				{
					return emitter.Value;
				}
			}
			foreach (KeyValuePair<System.Type, MethodInfo> emitter2 in _Emitters)
			{
				if (emitter2.Key.IsAssignableFrom(type))
				{
					return emitter2.Value;
				}
			}
			return null;
		}

		[DetourToRD("PatchProcessor", 2, null)]
		[Critical]
		private static List<DynamicMethod> Patch(Func<object, List<DynamicMethod>> orig, object self)
		{
			orig(self);
			return new List<DynamicMethod>();
		}

		[Transpile("PatchFunctions", null)]
		[Critical]
		private static void UpdateWrapper(ILContext il)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			ILCursor val = new ILCursor(il);
			val.GotoNext(new Func<Instruction, bool>[1]
			{
				(Instruction i) => ILPatternMatchingExt.MatchThrow(i)
			});
			val.Next.OpCode = OpCodes.Pop;
		}

		[Transpile("MethodPatcher", null)]
		[Critical]
		private static void CreatePatchedMethod(ILContext il)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Expected O, but got Unknown
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			ILCursor val = new ILCursor(il);
			System.Type t_DynamicTools = GetHarmonyType("DynamicTools");
			if (!val.TryGotoNext(new Func<Instruction, bool>[1]
			{
				(Instruction i) => ILPatternMatchingExt.MatchCall(i, t_DynamicTools, "CreateDynamicMethod")
			}))
			{
				il.MakeReadOnly();
				return;
			}
			val.Next.OpCode = OpCodes.Call;
			val.Next.Operand = il.Import((MethodBase)typeof(HarmonyDetourBridge).GetMethod("CreateDMD", BindingFlags.Static | BindingFlags.NonPublic));
			int varDMDi = -1;
			val.GotoNext(new Func<Instruction, bool>[1]
			{
				(Instruction i) => ILPatternMatchingExt.MatchStloc(i, ref varDMDi)
			});
			((VariableReference)il.Body.Variables[varDMDi]).VariableType = il.Import(typeof(DynamicMethodDefinition));
			val.GotoNext(new Func<Instruction, bool>[1]
			{
				(Instruction i) => ILPatternMatchingExt.MatchCallvirt<DynamicMethod>(i, "GetILGenerator")
			});
			val.Next.OpCode = OpCodes.Call;
			val.Next.Operand = il.Import((MethodBase)typeof(DynamicMethodDefinition).GetMethod("GetILGenerator", BindingFlags.Instance | BindingFlags.Public));
			val.GotoNext(new Func<Instruction, bool>[1]
			{
				(Instruction i) => ILPatternMatchingExt.MatchCall(i, t_DynamicTools, "PrepareDynamicMethod")
			});
			val.Next.OpCode = OpCodes.Pop;
			val.Next.Operand = null;
			val.GotoNext(new Func<Instruction, bool>[1]
			{
				(Instruction i) => ILPatternMatchingExt.MatchLdloc(i, varDMDi)
			});
			int index = val.Index;
			val.Index = index + 1;
			val.EmitDelegate<Func<DynamicMethodDefinition, DynamicMethod>>((Func<DynamicMethodDefinition, DynamicMethod>)delegate(DynamicMethodDefinition dmd)
			{
				_LastWrapperDMD = dmd;
				return null;
			});
		}

		[DetourToRD("HarmonySharedState", 1, null)]
		private static Assembly SharedStateAssembly(Func<Assembly> orig)
		{
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Expected O, but got Unknown
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Expected O, but got Unknown
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Expected O, but got Unknown
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Expected O, but got Unknown
			Assembly assembly = orig();
			if (assembly != null)
			{
				return assembly;
			}
			if (_SharedStateASM != null)
			{
				return _SharedStateASM;
			}
			string text = (string)GetHarmonyType("HarmonySharedState").GetField("name", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null);
			ModuleDefinition val = ModuleDefinition.CreateModule("MonoMod.RuntimeDetour." + text, new ModuleParameters
			{
				Kind = (ModuleKind)0,
				ReflectionImporterProvider = MMReflectionImporter.Provider
			});
			try
			{
				TypeDefinition val2 = new TypeDefinition("", text, (TypeAttributes)385)
				{
					BaseType = val.TypeSystem.Object
				};
				val.Types.Add(val2);
				val2.Fields.Add(new FieldDefinition("state", (FieldAttributes)22, val.ImportReference(typeof(Dictionary<MethodBase, byte[]>))));
				val2.Fields.Add(new FieldDefinition("version", (FieldAttributes)22, val.ImportReference(typeof(int))));
				return _SharedStateASM = ReflectionHelper.Load(val);
			}
			finally
			{
				((IDisposable)val)?.Dispose();
			}
		}

		private static Assembly _FindHarmony()
		{
			Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
			foreach (Assembly assembly in assemblies)
			{
				if (assembly.GetName().Name == "0Harmony" || assembly.GetName().Name == "Harmony" || assembly.GetType("Harmony.HarmonyInstance") != null || assembly.GetType("HarmonyLib.Harmony") != null)
				{
					return assembly;
				}
			}
			object obj = System.Type.GetType("Harmony.HarmonyInstance", throwOnError: false, ignoreCase: false)?.Assembly;
			if (obj == null)
			{
				System.Type? type = System.Type.GetType("HarmonyLib.Harmony", throwOnError: false, ignoreCase: false);
				if ((object)type == null)
				{
					return null;
				}
				obj = type.Assembly;
			}
			return (Assembly)obj;
		}
	}
	public struct HookConfig
	{
		public bool ManualApply;

		public int Priority;

		public string ID;

		public IEnumerable<string> Before;

		public IEnumerable<string> After;
	}
	public class Hook : IDetour, IDisposable
	{
		public static Func<Hook, MethodBase, MethodBase, object, bool> OnDetour;

		public static Func<Hook, bool> OnUndo;

		public static Func<Hook, MethodBase, MethodBase> OnGenerateTrampoline;

		public readonly MethodBase Method;

		public readonly MethodBase Target;

		public readonly MethodBase TargetReal;

		public readonly object DelegateTarget;

		private Detour _Detour;

		private readonly Type _OrigDelegateType;

		private readonly MethodInfo _OrigDelegateInvoke;

		private int? _RefTarget;

		private int? _RefTrampoline;

		private int? _RefTrampolineTmp;

		public bool IsValid => _Detour.IsValid;

		public bool IsApplied => _Detour.IsApplied;

		public Detour Detour => _Detour;

		public Hook(MethodBase from, MethodInfo to, object target, ref HookConfig config)
		{
			//IL_025c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0261: Unknown result type (might be due to invalid IL or missing references)
			//IL_0264: Expected O, but got Unknown
			//IL_0266: Expected O, but got Unknown
			//IL_02a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0386: Unknown result type (might be due to invalid IL or missing references)
			//IL_038b: Unknown result type (might be due to invalid IL or missing references)
			//IL_038e: Expected O, but got Unknown
			//IL_0390: Expected O, but got Unknown
			//IL_03ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_040d: Unknown result type (might be due to invalid IL or missing references)
			from = from.GetIdentifiable();
			Method = from;
			Target = to;
			DelegateTarget = target;
			Type type = (from as MethodInfo)?.ReturnType ?? typeof(void);
			if (to.ReturnType != type && !Extensions.IsCompatible(to.ReturnType, type))
			{
				throw new InvalidOperationException($"Return type of hook for {from} doesn't match, must be {((from as MethodInfo)?.ReturnType ?? typeof(void)).FullName}");
			}
			if (target == null && !to.IsStatic)
			{
				throw new InvalidOperationException($"Hook for method {from} must be static, or you must pass a target instance.");
			}
			ParameterInfo[] parameters = Target.GetParameters();
			ParameterInfo[] parameters2 = Method.GetParameters();
			Type[] array;
			if (!Method.IsStatic)
			{
				array = new Type[parameters2.Length + 1];
				array[0] = Extensions.GetThisParamType(Method);
				for (int i = 0; i < parameters2.Length; i++)
				{
					array[i + 1] = parameters2[i].ParameterType;
				}
			}
			else
			{
				array = new Type[parameters2.Length];
				for (int j = 0; j < parameters2.Length; j++)
				{
					array[j] = parameters2[j].ParameterType;
				}
			}
			Type type2 = null;
			if (parameters.Length == array.Length + 1 && typeof(Delegate).IsAssignableFrom(parameters[0].ParameterType))
			{
				type2 = (_OrigDelegateType = parameters[0].ParameterType);
			}
			else if (parameters.Length != array.Length)
			{
				throw new InvalidOperationException($"Parameter count of hook for {from} doesn't match, must be {array.Length}");
			}
			for (int k = 0; k < array.Length; k++)
			{
				Type type3 = array[k];
				Type parameterType = parameters[k + ((!(type2 == null)) ? 1 : 0)].ParameterType;
				if (!Extensions.IsCompatible(type3, parameterType))
				{
					throw new InvalidOperationException($"Parameter #{k} of hook for {from} doesn't match, must be {type3.FullName} or related");
				}
			}
			MethodInfo methodInfo = (_OrigDelegateInvoke = type2?.GetMethod("Invoke"));
			DynamicMethodDefinition val = new DynamicMethodDefinition($"Hook<{Extensions.GetID(Method, (string)null, (string)null, true, false, true)}>?{GetHashCode()}", (Method as MethodInfo)?.ReturnType ?? typeof(void), array);
			DynamicMethodDefinition val2 = val;
			DynamicMethodDefinition val3 = val;
			try
			{
				ILProcessor iLProcessor = val2.GetILProcessor();
				if (target != null)
				{
					_RefTarget = DynamicMethodHelper.EmitReference<object>(iLProcessor, target);
				}
				if (type2 != null)
				{
					_RefTrampoline = DynamicMethodHelper.EmitReference<Delegate>(iLProcessor, (Delegate)null);
				}
				for (int l = 0; l < array.Length; l++)
				{
					iLProcessor.Emit(OpCodes.Ldarg, l);
				}
				Extensions.Emit(iLProcessor, OpCodes.Call, Target);
				iLProcessor.Emit(OpCodes.Ret);
				TargetReal = val2.Generate().Pin();
			}
			finally
			{
				((IDisposable)val3)?.Dispose();
			}
			if (type2 != null)
			{
				ParameterInfo[] parameters3 = methodInfo.GetParameters();
				Type[] array2 = new Type[parameters3.Length];
				for (int m = 0; m < parameters3.Length; m++)
				{
					array2[m] = parameters3[m].ParameterType;
				}
				DynamicMethodDefinition val4 = new DynamicMethodDefinition($"Chain:TMP<{Extensions.GetID(Method, (string)null, (string)null, true, false, true)}>?{GetHashCode()}", methodInfo?.ReturnType ?? typeof(void), array2);
				val2 = val4;
				val3 = val4;
				try
				{
					ILProcessor iLProcessor = val2.GetILProcessor();
					_RefTrampolineTmp = DynamicMethodHelper.EmitReference<Delegate>(iLProcessor, (Delegate)null);
					iLProcessor.Emit(OpCodes.Brfalse, iLProcessor.Body.Instructions[0]);
					DynamicMethodHelper.EmitGetReference<Delegate>(iLProcessor, _RefTrampolineTmp.Value);
					for (int n = 0; n < array.Length; n++)
					{
						iLProcessor.Emit(OpCodes.Ldarg, n);
					}
					Extensions.Emit(iLProcessor, OpCodes.Callvirt, (MethodBase)methodInfo);
					iLProcessor.Emit(OpCodes.Ret);
					DynamicMethodHelper.SetReference(_RefTrampoline.Value, (object)val2.Generate().CreateDelegate(type2));
				}
				finally
				{
					((IDisposable)val3)?.Dispose();
				}
			}
			_Detour = new Detour(Method, TargetReal, new DetourConfig
			{
				ManualApply = true,
				Priority = config.Priority,
				ID = config.ID,
				Before = config.Before,
				After = config.After
			});
			_UpdateOrig(null);
			if (!config.ManualApply)
			{
				Apply();
			}
		}

		public Hook(MethodBase from, MethodInfo to, object target, HookConfig config)
			: this(from, to, target, ref config)
		{
		}

		public Hook(MethodBase from, MethodInfo to, object target)
			: this(from, to, target, DetourContext.Current?.HookConfig ?? default(HookConfig))
		{
		}

		public Hook(MethodBase from, MethodInfo to, ref HookConfig config)
			: this(from, to, null, ref config)
		{
		}

		public Hook(MethodBase from, MethodInfo to, HookConfig config)
			: this(from, to, null, ref config)
		{
		}

		public Hook(MethodBase from, MethodInfo to)
			: this(from, to, null)
		{
		}

		public Hook(MethodBase method, IntPtr to, ref HookConfig config)
			: this(method, DetourHelper.GenerateNativeProxy(to, method), null, ref config)
		{
		}

		public Hook(MethodBase method, IntPtr to, HookConfig config)
			: this(method, DetourHelper.GenerateNativeProxy(to, method), null, ref config)
		{
		}

		public Hook(MethodBase method, IntPtr to)
			: this(method, DetourHelper.GenerateNativeProxy(to, method), null)
		{
		}

		public Hook(MethodBase method, Delegate to, ref HookConfig config)
			: this(method, to.Method, to.Target, ref config)
		{
		}

		public Hook(MethodBase method, Delegate to, HookConfig config)
			: this(method, to.Method, to.Target, ref config)
		{
		}

		public Hook(MethodBase method, Delegate to)
			: this(method, to.Method, to.Target)
		{
		}

		public Hook(Delegate from, IntPtr to, ref HookConfig config)
			: this(from.Method, to, ref config)
		{
		}

		public Hook(Delegate from, IntPtr to, HookConfig config)
			: this(from.Method, to, ref config)
		{
		}

		public Hook(Delegate from, IntPtr to)
			: this(from.Method, to)
		{
		}

		public Hook(Delegate from, Delegate to, ref HookConfig config)
			: this(from.Method, to, ref config)
		{
		}

		public Hook(Delegate from, Delegate to, HookConfig config)
			: this(from.Method, to, ref config)
		{
		}

		public Hook(Delegate from, Delegate to)
			: this(from.Method, to)
		{
		}

		public Hook(Expression from, IntPtr to, ref HookConfig config)
			: this(((MethodCallExpression)from).Method, to, ref config)
		{
		}

		public Hook(Expression from, IntPtr to, HookConfig config)
			: this(((MethodCallExpression)from).Method, to, ref config)
		{
		}

		public Hook(Expression from, IntPtr to)
			: this(((MethodCallExpression)from).Method, to)
		{
		}

		public Hook(Expression from, Delegate to, ref HookConfig config)
			: this(((MethodCallExpression)from).Method, to, ref config)
		{
		}

		public Hook(Expression from, Delegate to, HookConfig config)
			: this(((MethodCallExpression)from).Method, to, ref config)
		{
		}

		public Hook(Expression from, Delegate to)
			: this(((MethodCallExpression)from).Method, to)
		{
		}

		public Hook(Expression<Action> from, IntPtr to, ref HookConfig config)
			: this(from.Body, to, ref config)
		{
		}

		public Hook(Expression<Action> from, IntPtr to, HookConfig config)
			: this(from.Body, to, ref config)
		{
		}

		public Hook(Expression<Action> from, IntPtr to)
			: this(from.Body, to)
		{
		}

		public Hook(Expression<Action> from, Delegate to, ref HookConfig config)
			: this(from.Body, to, ref config)
		{
		}

		public Hook(Expression<Action> from, Delegate to, HookConfig config)
			: this(from.Body, to, ref config)
		{
		}

		public Hook(Expression<Action> from, Delegate to)
			: this(from.Body, to)
		{
		}

		public void Apply()
		{
			if (!IsValid)
			{
				throw new ObjectDisposedException("Hook");
			}
			if (!IsApplied)
			{
				Func<Hook, MethodBase, MethodBase, object, bool> onDetour = OnDetour;
				if (onDetour != null && !Extensions.InvokeWhileTrue((MulticastDelegate)onDetour, new object[4] { this, Method, Target, DelegateTarget }))
				{
					return;
				}
			}
			_Detour.Apply();
		}

		public void Undo()
		{
			if (!IsValid)
			{
				throw new ObjectDisposedException("Hook");
			}
			if (IsApplied)
			{
				Func<Hook, bool> onUndo = OnUndo;
				if (onUndo != null && !Extensions.InvokeWhileTrue((MulticastDelegate)onUndo, new object[1] { this }))
				{
					return;
				}
			}
			_Detour.Undo();
			if (!IsValid)
			{
				_Free();
			}
		}

		public void Free()
		{
			if (IsValid)
			{
				_Detour.Free();
				_Free();
			}
		}

		public void Dispose()
		{
			if (IsValid)
			{
				Undo();
				Free();
			}
		}

		private void _Free()
		{
			if (_RefTarget.HasValue)
			{
				DynamicMethodHelper.FreeReference(_RefTarget.Value);
			}
			if (_RefTrampoline.HasValue)
			{
				DynamicMethodHelper.FreeReference(_RefTrampoline.Value);
			}
			if (_RefTrampolineTmp.HasValue)
			{
				DynamicMethodHelper.FreeReference(_RefTrampolineTmp.Value);
			}
			TargetReal.Unpin();
		}

		public MethodBase GenerateTrampoline(MethodBase signature = null)
		{
			Func<Hook, MethodBase, MethodBase> onGenerateTrampoline = OnGenerateTrampoline;
			MethodBase methodBase = ((onGenerateTrampoline != null) ? Extensions.InvokeWhileNull<MethodBase>((MulticastDelegate)onGenerateTrampoline, new object[2] { this, signature }) : null);
			if (methodBase != null)
			{
				return methodBase;
			}
			return _Detour.GenerateTrampoline(signature);
		}

		public T GenerateTrampoline<T>() where T : Delegate
		{
			if (!typeof(Delegate).IsAssignableFrom(typeof(T)))
			{
				throw new InvalidOperationException($"Type {typeof(T)} not a delegate type.");
			}
			return Extensions.CreateDelegate(GenerateTrampoline(typeof(T).GetMethod("Invoke")), typeof(T)) as T;
		}

		internal void _UpdateOrig(MethodBase invoke)
		{
			if (!(_OrigDelegateType == null))
			{
				Delegate @delegate = Extensions.CreateDelegate(invoke ?? GenerateTrampoline(_OrigDelegateInvoke), _OrigDelegateType);
				DynamicMethodHelper.SetReference(_RefTrampoline.Value, (object)@delegate);
				DynamicMethodHelper.SetReference(_RefTrampolineTmp.Value, (object)@delegate);
			}
		}
	}
	public class Hook<T> : Hook
	{
		public Hook(Expression<Action> from, T to, ref HookConfig config)
			: base(from.Body, to as Delegate, ref config)
		{
		}

		public Hook(Expression<Action> from, T to, HookConfig config)
			: base(from.Body, to as Delegate, ref config)
		{
		}

		public Hook(Expression<Action> from, T to)
			: base(from.Body, to as Delegate)
		{
		}

		public Hook(Expression<Func<T>> from, IntPtr to, ref HookConfig config)
			: base(from.Body, to, ref config)
		{
		}

		public Hook(Expression<Func<T>> from, IntPtr to, HookConfig config)
			: base(from.Body, to, ref config)
		{
		}

		public Hook(Expression<Func<T>> from, IntPtr to)
			: base(from.Body, to)
		{
		}

		public Hook(Expression<Func<T>> from, Delegate to, ref HookConfig config)
			: base(from.Body, to, ref config)
		{
		}

		public Hook(Expression<Func<T>> from, Delegate to, HookConfig config)
			: base(from.Body, to, ref config)
		{
		}

		public Hook(Expression<Func<T>> from, Delegate to)
			: base(from.Body, to)
		{
		}

		public Hook(T from, IntPtr to, ref HookConfig config)
			: base(from as Delegate, to, ref config)
		{
		}

		public Hook(T from, IntPtr to, HookConfig config)
			: base(from as Delegate, to, ref config)
		{
		}

		public Hook(T from, IntPtr to)
			: base(from as Delegate, to)
		{
		}

		public Hook(T from, T to, ref HookConfig config)
			: base(from as Delegate, to as Delegate, ref config)
		{
		}

		public Hook(T from, T to, HookConfig config)
			: base(from as Delegate, to as Delegate, ref config)
		{
		}

		public Hook(T from, T to)
			: base(from as Delegate, to as Delegate)
		{
		}
	}
	public class Hook<TFrom, TTo> : Hook
	{
		public Hook(Expression<Func<TFrom>> from, TTo to, ref HookConfig config)
			: base(from.Body, to as Delegate)
		{
		}

		public Hook(Expression<Func<TFrom>> from, TTo to, HookConfig config)
			: base(from.Body, to as Delegate)
		{
		}

		public Hook(Expression<Func<TFrom>> from, TTo to)
			: base(from.Body, to as Delegate)
		{
		}

		public Hook(TFrom from, TTo to, ref HookConfig config)
			: base(from as Delegate, to as Delegate)
		{
		}

		public Hook(TFrom from, TTo to, HookConfig config)
			: base(from as Delegate, to as Delegate)
		{
		}

		public Hook(TFrom from, TTo to)
			: base(from as Delegate, to as Delegate)
		{
		}
	}
	public interface IDetour : IDisposable
	{
		bool IsValid { get; }

		bool IsApplied { get; }

		void Apply();

		void Undo();

		void Free();

		MethodBase GenerateTrampoline(MethodBase signature = null);

		T GenerateTrampoline<T>() where T : Delegate;
	}
	public interface ISortableDetour : IDetour, IDisposable
	{
		uint GlobalIndex { get; }

		int Priority { get; set; }

		string ID { get; set; }

		IEnumerable<string> Before { get; set; }

		IEnumerable<string> After { get; set; }
	}
	public struct ILHookConfig
	{
		public bool ManualApply;

		public int Priority;

		public string ID;

		public IEnumerable<string> Before;

		public IEnumerable<string> After;
	}
	public class ILHook : ISortableDetour, IDetour, IDisposable
	{
		private class Context
		{
			public List<ILHook> Chain = new List<ILHook>();

			public HashSet<ILContext> Active = new HashSet<ILContext>();

			public MethodBase Method;

			public Detour Detour;

			public Context(MethodBase method)
			{
				Method = method;
			}

			public void Add(ILHook hook)
			{
				List<ILHook> chain = Chain;
				lock (chain)
				{
					chain.Add(hook);
				}
			}

			public void Remove(ILHook hook)
			{
				List<ILHook> chain = Chain;
				lock (chain)
				{
					chain.Remove(hook);
					if (chain.Count == 0)
					{
						Refresh();
						lock (_Map)
						{
							_Map.Remove(Method);
							return;
						}
					}
				}
			}

			public void Refresh()
			{
				//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c9: Expected O, but got Unknown
				List<ILHook> chain = Chain;
				lock (chain)
				{
					foreach (ILContext item in Active)
					{
						item.Dispose();
					}
					Active.Clear();
					Detour?.Dispose();
					Detour = null;
					if (chain.Count == 0)
					{
						return;
					}
					bool flag = false;
					foreach (ILHook item2 in chain)
					{
						if (item2.IsApplied)
						{
							flag = true;
							break;
						}
					}
					if (!flag)
					{
						return;
					}
					DetourSorter<ILHook>.Sort(chain);
					DynamicMethodDefinition val = new DynamicMethodDefinition(Method);
					MethodBase to;
					try
					{
						MethodDefinition definition = val.Definition;
						foreach (ILHook item3 in chain)
						{
							if (item3.IsApplied)
							{
								InvokeManipulator(definition, item3.Manipulator);
							}
						}
						to = val.Generate();
					}
					finally
					{
						((IDisposable)val)?.Dispose();
					}
					Detour = new Detour(Method, to, ref ILDetourConfig);
				}
			}

			private void InvokeManipulator(MethodDefinition def, Manipulator cb)
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_0007: Expected O, but got Unknown
				ILContext val = new ILContext(def);
				val.ReferenceBag = (IILReferenceBag)(object)RuntimeILReferenceBag.Instance;
				val.Invoke(cb);
				if (val.IsReadOnly)
				{
					val.Dispose();
					return;
				}
				val.MakeReadOnly();
				Active.Add(val);
			}
		}

		public static Func<ILHook, MethodBase, Manipulator, bool> OnDetour;

		public static Func<ILHook, bool> OnUndo;

		private static DetourConfig ILDetourConfig = new DetourConfig
		{
			Priority = -268435456,
			Before = new string[1] { "*" }
		};

		private static Dictionary<MethodBase, Context> _Map = new Dictionary<MethodBase, Context>();

		private static uint _GlobalIndexNext = 0u;

		private readonly uint _GlobalIndex;

		private int _Priority;

		private string _ID;

		private List<string> _Before = new List<string>();

		private ReadOnlyCollection<string> _BeforeRO;

		private List<string> _After = new List<string>();

		private ReadOnlyCollection<string> _AfterRO;

		public readonly MethodBase Method;

		public readonly Manipulator Manipulator;

		private Context _Ctx
		{
			get
			{
				if (!_Map.TryGetValue(Method, out var value))
				{
					return null;
				}
				return value;
			}
		}

		public bool IsValid => Index != -1;

		public bool IsApplied { get; private set; }

		public int Index => _Ctx?.Chain.IndexOf(this) ?? (-1);

		public int MaxIndex => _Ctx?.Chain.Count ?? (-1);

		public uint GlobalIndex => _GlobalIndex;

		public int Priority
		{
			get
			{
				return _Priority;
			}
			set
			{
				if (_Priority != value)
				{
					_Priority = value;
					_Ctx.Refresh();
				}
			}
		}

		public string ID
		{
			get
			{
				return _ID;
			}
			set
			{
				if (string.IsNullOrEmpty(value))
				{
					MethodInfo method = ((Delegate)(object)Manipulator).Method;
					value = (((object)method != null) ? Extensions.GetID((MethodBase)method, (string)null, (string)null, true, false, true) : null) ?? GetHashCode().ToString(CultureInfo.InvariantCulture);
				}
				if (!(_ID == value))
				{
					_ID = value;
					_Ctx.Refresh();
				}
			}
		}

		public IEnumerable<string> Before
		{
			get
			{
				return _BeforeRO ?? (_BeforeRO = _Before.AsReadOnly());
			}
			set
			{
				lock (_Before)
				{
					_Before.Clear();
					if (value != null)
					{
						foreach (string item in value)
						{
							_Before.Add(item);
						}
					}
					_Ctx.Refresh();
				}
			}
		}

		public IEnumerable<string> After
		{
			get
			{
				return _AfterRO ?? (_AfterRO = _After.AsReadOnly());
			}
			set
			{
				lock (_After)
				{
					_After.Clear();
					if (value != null)
					{
						foreach (string item in value)
						{
							_After.Add(item);
						}
					}
					_Ctx.Refresh();
				}
			}
		}

		public ILHook(MethodBase from, Manipulator manipulator, ref ILHookConfig config)
		{
			from = from.GetIdentifiable();
			Method = from.Pin();
			Manipulator = manipulator;
			_GlobalIndex = _GlobalIndexNext++;
			_Priority = config.Priority;
			_ID = config.ID;
			if (config.Before != null)
			{
				foreach (string item in config.Before)
				{
					_Before.Add(item);
				}
			}
			if (config.After != null)
			{
				foreach (string item2 in config.After)
				{
					_After.Add(item2);
				}
			}
			Context value;
			lock (_Map)
			{
				if (!_Map.TryGetValue(Method, out value))
				{
					value = (_Map[Method] = new Context(Method));
				}
			}
			lock (value)
			{
				value.Add(this);
			}
			if (!config.ManualApply)
			{
				Apply();
			}
		}

		public ILHook(MethodBase from, Manipulator manipulator, ILHookConfig config)
			: this(from, manipulator, ref config)
		{
		}

		public ILHook(MethodBase from, Manipulator manipulator)
			: this(from, manipulator, DetourContext.Current?.ILHookConfig ?? default(ILHookConfig))
		{
		}

		public void Apply()
		{
			if (!IsValid)
			{
				throw new ObjectDisposedException("ILHook");
			}
			if (!IsApplied)
			{
				Func<ILHook, MethodBase, Manipulator, bool> onDetour = OnDetour;
				if (onDetour == null || Extensions.InvokeWhileTrue((MulticastDelegate)onDetour, new object[3] { this, Method, Manipulator }))
				{
					IsApplied = true;
					_Ctx.Refresh();
				}
			}
		}

		public void Undo()
		{
			if (!IsValid)
			{
				throw new ObjectDisposedException("ILHook");
			}
			if (IsApplied)
			{
				Func<ILHook, bool> onUndo = OnUndo;
				if (onUndo == null || Extensions.InvokeWhileTrue((MulticastDelegate)onUndo, new object[1] { this }))
				{
					IsApplied = false;
					_Ctx.Refresh();
				}
			}
		}

		public void Free()
		{
			if (IsValid)
			{
				Undo();
				_Ctx.Remove(this);
				Method.Unpin();
			}
		}

		public void Dispose()
		{
			if (IsValid)
			{
				Undo();
				Free();
			}
		}

		public MethodBase GenerateTrampoline(MethodBase signature = null)
		{
			throw new NotSupportedException();
		}

		public T GenerateTrampoline<T>() where T : Delegate
		{
			throw new NotSupportedException();
		}
	}
	public struct NativeDetourConfig
	{
		public bool ManualApply;

		public bool SkipILCopy;
	}
	public class NativeDetour : IDetour, IDisposable
	{
		public static Func<NativeDetour, MethodBase, IntPtr, IntPtr, bool> OnDetour;

		public static Func<NativeDetour, bool> OnUndo;

		public static Func<NativeDetour, MethodBase, MethodBase> OnGenerateTrampoline;

		private NativeDetourData _Data;

		public readonly MethodBase Method;

		private readonly MethodInfo _BackupMethod;

		private readonly IntPtr _BackupNative;

		private HashSet<MethodBase> _Pinned = new HashSet<MethodBase>();

		public bool IsValid { get; private set; }

		public bool IsApplied { get; private set; }

		public NativeDetourData Data => _Data;

		public NativeDetour(MethodBase method, IntPtr from, IntPtr to, ref NativeDetourConfig config)
		{
			if (from == to)
			{
				throw new InvalidOperationException($"Cannot detour from a location to itself! (from: {from:X16} to: {to:X16} method: {method})");
			}
			method = method?.GetIdentifiable();
			Method = method;
			Func<NativeDetour, MethodBase, IntPtr, IntPtr, bool> onDetour = OnDetour;
			if (onDetour == null || Extensions.InvokeWhileTrue((MulticastDelegate)onDetour, new object[4] { this, method, from, to }))
			{
				IsValid = true;
				_Data = DetourHelper.Native.Create(from, to);
				if (!config.SkipILCopy)
				{
					method?.TryCreateILCopy(out _BackupMethod);
				}
				_BackupNative = DetourHelper.Native.MemAlloc(_Data.Size);
				if (!config.ManualApply)
				{
					Apply();
				}
			}
		}

		public NativeDetour(MethodBase method, IntPtr from, IntPtr to, NativeDetourConfig config)
			: this(method, from, to, ref config)
		{
		}

		public NativeDetour(MethodBase method, IntPtr from, IntPtr to)
			: this(method, from, to, default(NativeDetourConfig))
		{
		}

		public NativeDetour(IntPtr from, IntPtr to, ref NativeDetourConfig config)
			: this(null, from, to, ref config)
		{
		}

		public NativeDetour(IntPtr from, IntPtr to, NativeDetourConfig config)
			: this(null, from, to, ref config)
		{
		}

		public NativeDetour(IntPtr from, IntPtr to)
			: this(null, from, to)
		{
		}

		public NativeDetour(MethodBase from, IntPtr to, ref NativeDetourConfig config)
			: this(from, from.Pin().GetNativeStart(), to, ref config)
		{
			_Pinned.Add(from);
		}

		public NativeDetour(MethodBase from, IntPtr to, NativeDetourConfig config)
			: this(from, from.Pin().GetNativeStart(), to, ref config)
		{
			_Pinned.Add(from);
		}

		public NativeDetour(MethodBase from, IntPtr to)
			: this(from, from.Pin().GetNativeStart(), to)
		{
			_Pinned.Add(from);
		}

		public NativeDetour(IntPtr from, MethodBase to, ref NativeDetourConfig config)
			: this(from, to.Pin().GetNativeStart(), ref config)
		{
			_Pinned.Add(to);
		}

		public NativeDetour(IntPtr from, MethodBase to, NativeDetourConfig config)
			: this(from, to.Pin().GetNativeStart(), ref config)
		{
			_Pinned.Add(to);
		}

		public NativeDetour(IntPtr from, MethodBase to)
			: this(from, to.Pin().GetNativeStart())
		{
			_Pinned.Add(to);
		}

		public NativeDetour(MethodBase from, MethodBase to, ref NativeDetourConfig config)
			: this(from.Pin().GetNativeStart(), DetourHelper.Runtime.GetDetourTarget(from, to), ref config)
		{
			_Pinned.Add(from);
		}

		public NativeDetour(MethodBase from, MethodBase to, NativeDetourConfig config)
			: this(from.Pin().GetNativeStart(), DetourHelper.Runtime.GetDetourTarget(from, to), ref config)
		{
			_Pinned.Add(from);
		}

		public NativeDetour(MethodBase from, MethodBase to)
			: this(from.Pin().GetNativeStart(), DetourHelper.Runtime.GetDetourTarget(from, to))
		{
			_Pinned.Add(from);
		}

		public NativeDetour(Delegate from, IntPtr to, ref NativeDetourConfig config)
			: this(from.Method, to, ref config)
		{
		}

		public NativeDetour(Delegate from, IntPtr to, NativeDetourConfig config)
			: this(from.Method, to, ref config)
		{
		}

		public NativeDetour(Delegate from, IntPtr to)
			: this(from.Method, to)
		{
		}

		public NativeDetour(IntPtr from, Delegate to, ref NativeDetourConfig config)
			: this(from, to.Method, ref config)
		{
		}

		public NativeDetour(IntPtr from, Delegate to, NativeDetourConfig config)
			: this(from, to.Method, ref config)
		{
		}

		public NativeDetour(IntPtr from, Delegate to)
			: this(from, to.Method)
		{
		}

		public NativeDetour(Delegate from, Delegate to, ref NativeDetourConfig config)
			: this(from.Method, to.Method, ref config)
		{
		}

		public NativeDetour(Delegate from, Delegate to, NativeDetourConfig config)
			: this(from.Method, to.Method, ref config)
		{
		}

		public NativeDetour(Delegate from, Delegate to)
			: this(from.Method, to.Method)
		{
		}

		public void Apply()
		{
			if (!IsValid)
			{
				throw new ObjectDisposedException("NativeDetour");
			}
			if (!IsApplied)
			{
				IsApplied = true;
				DetourHelper.Native.Copy(_Data.Method, _BackupNative, _Data.Type);
				DetourHelper.Native.MakeWritable(_Data);
				DetourHelper.Native.Apply(_Data);
				DetourHelper.Native.MakeExecutable(_Data);
				DetourHelper.Native.FlushICache(_Data);
			}
		}

		public void Undo()
		{
			if (!IsValid)
			{
				throw new ObjectDisposedException("NativeDetour");
			}
			Func<NativeDetour, bool> onUndo = OnUndo;
			if ((onUndo == null || Extensions.InvokeWhileTrue((MulticastDelegate)onUndo, new object[1] { this })) && IsApplied)
			{
				IsApplied = false;
				DetourHelper.Native.MakeWritable(_Data);
				DetourHelper.Native.Copy(_BackupNative, _Data.Method, _Data.Type);
				DetourHelper.Native.MakeExecutable(_Data);
				DetourHelper.Native.FlushICache(_Data);
			}
		}

		public void ChangeSource(IntPtr newSource)
		{
			if (!IsValid)
			{
				throw new ObjectDisposedException("NativeDetour");
			}
			NativeDetourData data = _Data;
			_Data = DetourHelper.Native.Create(newSource, _Data.Target);
			IsApplied = false;
			Apply();
			DetourHelper.Native.Free(data);
		}

		public void ChangeTarget(IntPtr newTarget)
		{
			if (!IsValid)
			{
				throw new ObjectDisposedException("NativeDetour");
			}
			NativeDetourData data = _Data;
			_Data = DetourHelper.Native.Create(_Data.Method, newTarget);
			IsApplied = false;
			Apply();
			DetourHelper.Native.Free(data);
		}

		public void Free()
		{
			if (!IsValid)
			{
				return;
			}
			IsValid = false;
			DetourHelper.Native.MemFree(_BackupNative);
			DetourHelper.Native.Free(_Data);
			if (IsApplied)
			{
				return;
			}
			foreach (MethodBase item in _Pinned)
			{
				item.Unpin();
			}
			_Pinned.Clear();
		}

		public void Dispose()
		{
			if (IsValid)
			{
				Undo();
				Free();
			}
		}

		public MethodBase GenerateTrampoline(MethodBase signature = null)
		{
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Expected O, but got Unknown
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Expected O, but got Unknown
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Expected O, but got Unknown
			//IL_01b5: Expected O, but got Unknown
			//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_020f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0255: Unknown result type (might be due to invalid IL or missing references)
			//IL_0247: Unknown result type (might be due to invalid IL or missing references)
			//IL_0306: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d2: Unknown result type (might be due to invalid IL or missing references)
			Func<NativeDetour, MethodBase, MethodBase> onGenerateTrampoline = OnGenerateTrampoline;
			MethodBase methodBase = ((onGenerateTrampoline != null) ? Extensions.InvokeWhileNull<MethodBase>((MulticastDelegate)onGenerateTrampoline, new object[2] { this, signature }) : null);
			if (methodBase != null)
			{
				return methodBase;
			}
			if (!IsValid)
			{
				throw new ObjectDisposedException("NativeDetour");
			}
			if (_BackupMethod != null)
			{
				return _BackupMethod;
			}
			if (signature == null)
			{
				throw new ArgumentNullException("A signature must be given if the NativeDetour doesn't hold a reference to a managed method.");
			}
			MethodBase methodBase2 = Method;
			if (methodBase2 == null)
			{
				methodBase2 = DetourHelper.GenerateNativeProxy(_Data.Method, signature);
			}
			Type type = (signature as MethodInfo)?.ReturnType ?? typeof(void);
			ParameterInfo[] parameters = signature.GetParameters();
			Type[] array = new Type[parameters.Length];
			for (int i = 0; i < parameters.Length; i++)
			{
				array[i] = parameters[i].ParameterType;
			}
			MethodBase method = Method;
			DynamicMethodDefinition val = new DynamicMethodDefinition(string.Format("Trampoline:Native<{0}>?{1}", (((object)method != null) ? Extensions.GetID(method, (string)null, (string)null, true, false, true) : null) ?? ((long)_Data.Method).ToString("X16", CultureInfo.InvariantCulture), GetHashCode()), type, array);
			try
			{
				ILProcessor iLProcessor = val.GetILProcessor();
				ExceptionHandler val2 = new ExceptionHandler((ExceptionHandlerType)2);
				iLProcessor.Body.ExceptionHandlers.Add(val2);
				iLProcessor.EmitDetourCopy(_BackupNative, _Data.Method, _Data.Type);
				VariableDefinition val3 = null;
				if (type != typeof(void))
				{
					Collection<VariableDefinition> variables = iLProcessor.Body.Variables;
					VariableDefinition val4 = new VariableDefinition(Extensions.Import(iLProcessor, type));
					val3 = val4;
					variables.Add(val4);
				}
				int count = iLProcessor.Body.Instructions.Count;
				for (int j = 0; j < array.Length; j++)
				{
					iLProcessor.Emit(OpCodes.Ldarg, j);
				}
				if (methodBase2 is MethodInfo)
				{
					Extensions.Emit(iLProcessor, OpCodes.Call, (MethodBase)(MethodInfo)methodBase2);
				}
				else
				{
					if (!(methodBase2 is ConstructorInfo))
					{
						throw new NotSupportedException("Method type " + methodBase2.GetType().FullName + " not supported.");
					}
					Extensions.Emit(iLProcessor, OpCodes.Call, (MethodBase)(ConstructorInfo)methodBase2);
				}
				if (val3 != null)
				{
					iLProcessor.Emit(OpCodes.Stloc, val3);
				}
				Extensions.Emit(iLProcessor, OpCodes.Leave, (object)null);
				Instruction obj = iLProcessor.Body.Instructions[iLProcessor.Body.Instructions.Count - 1];
				int count2 = iLProcessor.Body.Instructions.Count;
				_ = iLProcessor.Body.Instructions.Count;
				iLProcessor.EmitDetourApply(_Data);
				int count3 = iLProcessor.Body.Instructions.Count;
				Instruction val5 = null;
				if (val3 != null)
				{
					iLProcessor.Emit(OpCodes.Ldloc, val3);
					val5 = iLProcessor.Body.Instructions[iLProcessor.Body.Instructions.Count - 1];
				}
				iLProcessor.Emit(OpCodes.Ret);
				val5 = val5 ?? iLProcessor.Body.Instructions[iLProcessor.Body.Instructions.Count - 1];
				obj.Operand = val5;
				val2.TryStart = iLProcessor.Body.Instructions[count];
				val2.TryEnd = iLProcessor.Body.Instructions[count2];
				val2.HandlerStart = iLProcessor.Body.Instructions[count2];
				val2.HandlerEnd = iLProcessor.Body.Instructions[count3];
				return val.Generate();
			}
			finally
			{
				((IDisposable)val)?.Dispose();
			}
		}

		public T GenerateTrampoline<T>() where T : Delegate
		{
			if (!typeof(Delegate).IsAssignableFrom(typeof(T)))
			{
				throw new InvalidOperationException($"Type {typeof(T)} not a delegate type.");
			}
			return Extensions.CreateDelegate(GenerateTrampoline(typeof(T).GetMethod("Invoke")), typeof(T)) as T;
		}
	}
	internal static class DetourSorter<T> where T : ISortableDetour
	{
		private sealed class Group
		{
			public readonly string StepName;

			public List<T> Items = new List<T>();

			public List<Group> Children = new List<Group>();

			public List<Group> NonMatching = new List<Group>();

			public Group(string stepName)
			{
				StepName = stepName;
			}

			public Group(string stepName, List<T> items)
				: this(stepName)
			{
				Items.AddRange(items);
			}

			public void Step(Step step)
			{
				if (Children.Count != 0)
				{
					foreach (Group child in Children)
					{
						child.Step(step);
					}
					return;
				}
				if (Items.Count <= 1)
				{
					return;
				}
				if ((Items.Count == 2 && !((!step.IsFlat) ?? false)) || step.IsFlat.GetValueOrDefault())
				{
					Items.Sort(step);
					return;
				}
				string name = step.GetType().Name;
				Group group = new Group(name, new List<T> { Items[0] });
				Children.Add(group);
				for (int i = 1; i < Items.Count; i++)
				{
					T val = Items[i];
					if (step.Any(group.Items, val))
					{
						Group group2 = group;
						group = null;
						if (Children.Count > 1)
						{
							foreach (Group child2 in Children)
							{
								if (child2 != group2 && !step.Any(child2.Items, val) && !step.Any(child2.NonMatching, val))
								{
									group = child2;
									break;
								}
							}
						}
						if (group == null)
						{
							group = new Group(name);
							Children.Add(group);
							group.NonMatching.Add(group2);
							group2.NonMatching.Add(group);
						}
					}
					group.Items.Add(val);
				}
				if (Children.Count == 1)
				{
					Children.Clear();
				}
				else
				{
					Children.Sort(step.ForGroup);
				}
			}

			public void Flatten()
			{
				if (Children.Count != 0)
				{
					Items.Clear();
					Flatten(Items);
				}
			}

			public void Flatten(List<T> total)
			{
				if (Children.Count == 0)
				{
					total.AddRange(Items);
					return;
				}
				foreach (Group child in Children)
				{
					child.Flatten(total);
				}
			}
		}

		private abstract class Step : IComparer<T>
		{
			public abstract GroupComparer ForGroup { get; }

			public virtual bool? IsFlat => null;

			public abstract int Compare(T x, T y);

			public bool Any(List<T> xlist, T y)
			{
				foreach (T item in xlist)
				{
					if (Compare(item, y) != 0)
					{
						return true;
					}
				}
				return false;
			}

			public bool Any(List<Group> groups, T y)
			{
				foreach (Group group in groups)
				{
					if (Any(group.Items, y))
					{
						return true;
					}
				}
				return false;
			}
		}

		private sealed class GroupComparer : IComparer<Group>
		{
			public Step Step;

			public GroupComparer(Step step)
			{
				Step = step;
			}

			public int Compare(Group xg, Group yg)
			{
				foreach (T item in xg.Items)
				{
					foreach (T item2 in yg.Items)
					{
						int result;
						if ((result = Step.Compare(item, item2)) != 0)
						{
							return result;
						}
					}
				}
				return 0;
			}
		}

		private sealed class BeforeAfterAll : Step
		{
			public static readonly BeforeAfterAll _ = new BeforeAfterAll();

			public static readonly GroupComparer Group = new GroupComparer(_);

			public override GroupComparer ForGroup => Group;

			public override bool? IsFlat => false;

			public override int Compare(T a, T b)
			{
				if (a.Before.Contains("*") && !b.Before.Contains("*"))
				{
					return -1;
				}
				if (!a.Before.Contains("*") && b.Before.Contains("*"))
				{
					return 1;
				}
				if (a.After.Contains("*") && !b.After.Contains("*"))
				{
					return 1;
				}
				if (!a.After.Contains("*") && b.After.Contains("*"))
				{
					return -1;
				}
				return 0;
			}
		}

		private sealed class BeforeAfter : Step
		{
			public static readonly BeforeAfter _ = new BeforeAfter();

			public static readonly GroupComparer Group = new GroupComparer(_);

			public override GroupComparer ForGroup => Group;

			public override int Compare(T a, T b)
			{
				if (a.Before.Contains(b.ID))
				{
					return -1;
				}
				if (a.After.Contains(b.ID))
				{
					return 1;
				}
				if (b.Before.Contains(a.ID))
				{
					return 1;
				}
				if (b.After.Contains(a.ID))
				{
					return -1;
				}
				return 0;
			}
		}

		private sealed class Priority : Step
		{
			public static readonly Priority _ = new Priority();

			public static readonly GroupComparer Group = new GroupComparer(_);

			public override GroupComparer ForGroup => Group;

			public override int Compare(T a, T b)
			{
				int num = a.Priority - b.Priority;
				if (num != 0)
				{
					return num;
				}
				return 0;
			}
		}

		private sealed class GlobalIndex : Step
		{
			public static readonly GlobalIndex _ = new GlobalIndex();

			public static readonly GroupComparer Group = new GroupComparer(_);

			public override GroupComparer ForGroup => Group;

			public override int Compare(T a, T b)
			{
				return a.GlobalIndex.CompareTo(b.GlobalIndex);
			}
		}

		public static void Sort(List<T> detours)
		{
			lock (detours)
			{
				if (detours.Count > 1)
				{
					detours.Sort(GlobalIndex._);
					Group group = new Group("Init", detours);
					group.Step(BeforeAfterAll._);
					group.Step(BeforeAfter._);
					group.Step(Priority._);
					group.Step(GlobalIndex._);
					detours.Clear();
					group.Flatten(detours);
				}
			}
		}
	}
	public static class DetourHelper
	{
		private static readonly object _RuntimeLock = new object();

		private static bool _RuntimeInit = false;

		private static IDetourRuntimePlatform _Runtime;

		private static readonly object _NativeLock = new object();

		private static bool _NativeInit = false;

		private static IDetourNativePlatform _Native;

		private static readonly FieldInfo _f_Native = typeof(DetourHelper).GetField("_Native", BindingFlags.Static | BindingFlags.NonPublic);

		private static readonly MethodInfo _m_ToNativeDetourData = typeof(DetourHelper).GetMethod("ToNativeDetourData", BindingFlags.Static | BindingFlags.NonPublic);

		private static readonly MethodInfo _m_Copy = typeof(IDetourNativePlatform).GetMethod("Copy");

		private static readonly MethodInfo _m_Apply = typeof(IDetourNativePlatform).GetMethod("Apply");

		private static readonly ConstructorInfo _ctor_Exception = typeof(Exception).GetConstructor(new Type[1] { typeof(string) });

		public static IDetourRuntimePlatform Runtime
		{
			get
			{
				if (_Runtime != null)
				{
					return _Runtime;
				}
				lock (_RuntimeLock)
				{
					if (_Runtime != null)
					{
						return _Runtime;
					}
					if (_RuntimeInit)
					{
						return null;
					}
					_RuntimeInit = true;
					if (ReflectionHelper.IsMono)
					{
						_Runtime = new DetourRuntimeMonoPlatform();
					}
					else if (ReflectionHelper.IsCore)
					{
						_Runtime = DetourRuntimeNETCorePlatform.Create();
					}
					else
					{
						_Runtime = new DetourRuntimeNETPlatform();
					}
					return _Runtime;
				}
			}
			set
			{
				_Runtime = value;
			}
		}

		public static IDetourNativePlatform Native
		{
			get
			{
				if (_Native != null)
				{
					return _Native;
				}
				lock (_NativeLock)
				{
					if (_Native != null)
					{
						return _Native;
					}
					if (_NativeInit)
					{
						return null;
					}
					_NativeInit = true;
					IDetourNativePlatform detourNativePlatform = ((!PlatformHelper.Is((Platform)65536)) ? ((IDetourNativePlatform)new DetourNativeX86Platform()) : ((IDetourNativePlatform)new DetourNativeARMPlatform()));
					if (PlatformHelper.Is((Platform)37))
					{
						return _Native = new DetourNativeWindowsPlatform(detourNativePlatform);
					}
					if (ReflectionHelper.IsMono)
					{
						try
						{
							return _Native = new DetourNativeMonoPlatform(detourNativePlatform, "libmonosgen-2.0." + PlatformHelper.LibrarySuffix);
						}
						catch
						{
						}
					}
					string environmentVariable = Environment.GetEnvironmentVariable("MONOMOD_RUNTIMEDETOUR_MONOPOSIXHELPER");
					if ((ReflectionHelper.IsMono && environmentVariable != "0") || environmentVariable == "1")
					{
						try
						{
							return _Native = new DetourNativeMonoPosixPlatform(detourNativePlatform);
						}
						catch
						{
						}
					}
					try
					{
						return _Native = new DetourNativeLibcPlatform(detourNativePlatform);
					}
					catch
					{
					}
					return detourNativePlatform;
				}
			}
			set
			{
				_Native = value;
			}
		}

		public static void MakeWritable(this IDetourNativePlatform plat, NativeDetourData detour)
		{
			plat.MakeWritable(detour.Method, detour.Size);
		}

		public static void MakeExecutable(this IDetourNativePlatform plat, NativeDetourData detour)
		{
			plat.MakeExecutable(detour.Method, detour.Size);
		}

		public static void FlushICache(this IDetourNativePlatform plat, NativeDetourData detour)
		{
			plat.FlushICache(detour.Method, detour.Size);
		}

		public unsafe static void Write(this IntPtr to, ref int offs, byte value)
		{
			*(byte*)((long)to + offs) = value;
			offs++;
		}

		public unsafe static void Write(this IntPtr to, ref int offs, ushort value)
		{
			*(ushort*)((long)to + offs) = value;
			offs += 2;
		}

		public unsafe static void Write(this IntPtr to, ref int offs, uint value)
		{
			*(uint*)((long)to + offs) = value;
			offs += 4;
		}

		public unsafe static void Write(this IntPtr to, ref int offs, ulong value)
		{
			*(ulong*)((long)to + offs) = value;
			offs += 8;
		}

		public static MethodBase GetIdentifiable(this MethodBase method)
		{
			return Runtime.GetIdentifiable(method);
		}

		public static IntPtr GetNativeStart(this MethodBase method)
		{
			return Runtime.GetNativeStart(method);
		}

		public static IntPtr GetNativeStart(this Delegate method)
		{
			return method.Method.GetNativeStart();
		}

		public static IntPtr GetNativeStart(this Expression method)
		{
			return ((MethodCallExpression)method).Method.GetNativeStart();
		}

		public static MethodInfo CreateILCopy(this MethodBase method)
		{
			return Runtime.CreateCopy(method);
		}

		public static bool TryCreateILCopy(this MethodBase method, out MethodInfo dm)
		{
			return Runtime.TryCreateCopy(method, out dm);
		}

		public static T Pin<T>(this T method) where T : MethodBase
		{
			Runtime.Pin(method);
			return method;
		}

		public static T Unpin<T>(this T method) where T : MethodBase
		{
			Runtime.Unpin(method);
			return method;
		}

		public static MethodInfo GenerateNativeProxy(IntPtr target, MethodBase signature)
		{
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Expected O, but got Unknown
			Type type = (signature as MethodInfo)?.ReturnType ?? typeof(void);
			ParameterInfo[] parameters = signature.GetParameters();
			Type[] array = new Type[parameters.Length];
			for (int i = 0; i < parameters.Length; i++)
			{
				array[i] = parameters[i].ParameterType;
			}
			DynamicMethodDefinition val = new DynamicMethodDefinition("Native<" + ((long)target).ToString("X16", CultureInfo.InvariantCulture) + ">", type, array);
			MethodInfo methodInfo;
			try
			{
				methodInfo = val.StubCriticalDetour().Generate().Pin();
			}
			finally
			{
				((IDisposable)val)?.Dispose();
			}
			NativeDetourData detour = Native.Create(methodInfo.GetNativeStart(), target);
			Native.MakeWritable(detour);
			Native.Apply(detour);
			Native.MakeExecutable(detour);
			Native.FlushICache(detour);
			Native.Free(detour);
			return methodInfo;
		}

		private static NativeDetourData ToNativeDetourData(IntPtr method, IntPtr target, uint size, byte type, IntPtr extra)
		{
			NativeDetourData result = default(NativeDetourData);
			result.Method = method;
			result.Target = target;
			result.Size = size;
			result.Type = type;
			result.Extra = extra;
			return result;
		}

		public static DynamicMethodDefinition StubCriticalDetour(this DynamicMethodDefinition dm)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: 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)
			ILProcessor iLProcessor = dm.GetILProcessor();
			ModuleDefinition module = ((MemberReference)iLProcessor.Body.Method).Module;
			for (int i = 0; i < 32; i++)
			{
				iLProcessor.Emit(OpCodes.Nop);
			}
			iLProcessor.Emit(OpCodes.Ldstr, ((MemberReference)dm.Definition).Name + " should've been detoured!");
			iLProcessor.Emit(OpCodes.Newobj, module.ImportReference((MethodBase)_ctor_Exception));
			iLProcessor.Emit(OpCodes.Throw);
			return dm;
		}

		public static void EmitDetourCopy(this ILProcessor il, IntPtr src, IntPtr dst, byte type)
		{
			//IL_0012: 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_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			ModuleDefinition module = ((MemberReference)il.Body.Method).Module;
			il.Emit(OpCodes.Ldsfld, module.ImportReference(_f_Native));
			il.Emit(OpCodes.Ldc_I8, (long)src);
			il.Emit(OpCodes.Conv_I);
			il.Emit(OpCodes.Ldc_I8, (long)dst);
			il.Emit(OpCodes.Conv_I);
			il.Emit(OpCodes.Ldc_I4, (int)type);
			il.Emit(OpCodes.Conv_U1);
			il.Emit(OpCodes.Callvirt, module.ImportReference((MethodBase)_m_Copy));
		}

		public static void EmitDetourApply(this ILProcessor il, NativeDetourData data)
		{
			//IL_0012: 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_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: 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_007b: 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_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: 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)
			ModuleDefinition module = ((MemberReference)il.Body.Method).Module;
			il.Emit(OpCodes.Ldsfld, module.ImportReference(_f_Native));
			il.Emit(OpCodes.Ldc_I8, (long)data.Method);
			il.Emit(OpCodes.Conv_I);
			il.Emit(OpCodes.Ldc_I8, (long)data.Target);
			il.Emit(OpCodes.Conv_I);
			il.Emit(OpCodes.Ldc_I4, (int)data.Size);
			il.Emit(OpCodes.Ldc_I4, (int)data.Type);
			il.Emit(OpCodes.Conv_U1);
			il.Emit(OpCodes.Ldc_I8, (long)data.Extra);
			il.Emit(OpCodes.Conv_I);
			il.Emit(OpCodes.Call, module.ImportReference((MethodBase)_m_ToNativeDetourData));
			il.Emit(OpCodes.Callvirt, module.ImportReference((MethodBase)_m_Apply));
		}
	}
	public interface IDetourNativePlatform
	{
		NativeDetourData Create(IntPtr from, IntPtr to, byte? type = null);

		void Free(NativeDetourData detour);

		void Apply(NativeDetourData detour);

		void Copy(IntPtr src, IntPtr dst, byte type);

		void MakeWritable(IntPtr src, uint size);

		void MakeExecutable(IntPtr src, uint size);

		void MakeReadWriteExecutable(IntPtr src, uint size);

		void FlushICache(IntPtr src, uint size);

		IntPtr MemAlloc(uint size);

		void MemFree(IntPtr ptr);
	}
	public interface IDetourRuntimePlatform
	{
		bool OnMethodCompiledWillBeCalled { get; }

		event OnMethodCompiledEvent OnMethodCompiled;

		MethodBase GetIdentifiable(MethodBase method);

		IntPtr GetNativeStart(MethodBase method);

		MethodInfo CreateCopy(MethodBase method);

		bool TryCreateCopy(MethodBase method, out MethodInfo dm);

		void Pin(MethodBase method);

		void Unpin(MethodBase method);

		MethodBase GetDetourTarget(MethodBase from, MethodBase to);

		uint TryMemAllocScratchCloseTo(IntPtr target, out IntPtr ptr, int size);
	}
	public delegate void OnMethodCompiledEvent(MethodBase method, IntPtr codeStart, ulong codeSize);
	public struct NativeDetourData
	{
		public IntPtr Method;

		public IntPtr Target;

		public byte Type;

		public uint Size;

		public IntPtr Extra;
	}
}
namespace MonoMod.RuntimeDetour.Platforms
{
	public class DetourNativeARMPlatform : IDetourNativePlatform
	{
		public enum DetourType : byte
		{
			Thumb,
			ThumbBX,
			AArch32,
			AArch32BX,
			AArch64
		}

		[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
		private delegate int d_flushicache(IntPtr code, ulong size);

		private static readonly uint[] DetourSizes = new uint[5] { 8u, 12u, 8u, 12u, 16u };

		public bool ShouldFlushICache = true;

		private readonly byte[] _FlushCache32 = new byte[44]
		{
			128, 64, 45, 233, 0, 48, 160, 225, 1, 192,
			128, 224, 20, 224, 159, 229, 3, 0, 160, 225,
			12, 16, 160, 225, 14, 112, 160, 225, 0, 32,
			160, 227, 0, 0, 0, 239, 128, 128, 189, 232,
			2, 0, 15, 0
		};

		private readonly byte[] _FlushCache64 = new byte[76]
		{
			1, 0, 1, 139, 0, 244, 126, 146, 63, 0,
			0, 235, 201, 0, 0, 84, 226, 3, 0, 170,
			34, 126, 11, 213, 66, 16, 0, 145, 63, 0,
			2, 235, 168, 255, 255, 84, 159, 59, 3, 213,
			63, 0, 0, 235, 169, 0, 0, 84, 32, 117,
			11, 213, 0, 16, 0, 145, 63, 0, 0, 235,
			168, 255, 255, 84, 159, 59, 3, 213, 223, 63,
			3, 213, 192, 3, 95, 214
		};

		private static DetourType GetDetourType(IntPtr from, IntPtr to)
		{
			if (IntPtr.Size >= 8)
			{
				return DetourType.AArch64;
			}
			bool num = ((long)from & 1) == 1;
			bool flag = ((long)to & 1) == 1;
			if (num)
			{
				if (flag)
				{
					return DetourType.Thumb;
				}
				return DetourType.ThumbBX;
			}
			if (flag)
			{
				return DetourType.AArch32BX;
			}
			return DetourType.AArch32;
		}

		public NativeDetourData Create(IntPtr from, IntPtr to, byte? type)
		{
			NativeDetourData nativeDetourData = default(NativeDetourData);
			nativeDetourData.Method = (IntPtr)((long)from & -2);
			nativeDetourData.Target = (IntPtr)((long)to & -2);
			NativeDetourData result = nativeDetourData;
			uint[] detourSizes = DetourSizes;
			int num = ((int?)type) ?? ((int)GetDetourType(from, to));
			byte b = (byte)num;
			result.Type = (byte)num;
			result.Size = detourSizes[b];
			return result;
		}

		public void Free(NativeDetourData detour)
		{
		}

		public void Apply(NativeDetourData detour)
		{
			int offs = 0;
			switch ((DetourType)detour.Type)
			{
			case Det

BepInExPack/BepInEx/core/MonoMod.Utils.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Dynamic;
using System.Globalization;
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 Mono.Cecil;
using Mono.Cecil.Cil;
using Mono.Collections.Generic;
using MonoMod.Utils;
using MonoMod.Utils.Cil;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = "")]
[assembly: InternalsVisibleTo("MonoMod.Utils.Cil.ILGeneratorProxy")]
[assembly: AssemblyCompany("0x0ade")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyCopyright("Copyright 2022 0x0ade")]
[assembly: AssemblyDescription("Utilities and smaller MonoMod \"components\" (f.e. ModInterop, DynDll, DynData). Can be used for your own mods. Required by all other MonoMod components.")]
[assembly: AssemblyFileVersion("22.5.1.1")]
[assembly: AssemblyInformationalVersion("22.05.01.01")]
[assembly: AssemblyProduct("MonoMod.Utils")]
[assembly: AssemblyTitle("MonoMod.Utils")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("22.5.1.1")]
[module: UnverifiableCode]
internal static class MultiTargetShims
{
	private static readonly object[] _NoArgs = new object[0];

	public static string Replace(this string self, string oldValue, string newValue, StringComparison comparison)
	{
		return self.Replace(oldValue, newValue);
	}

	public static bool Contains(this string self, string value, StringComparison comparison)
	{
		return self.Contains(value);
	}

	public static int GetHashCode(this string self, StringComparison comparison)
	{
		return self.GetHashCode();
	}

	public static int IndexOf(this string self, char value, StringComparison comparison)
	{
		return self.IndexOf(value);
	}

	public static int IndexOf(this string self, string value, StringComparison comparison)
	{
		return self.IndexOf(value);
	}

	public static Module[] GetModules(this Assembly asm)
	{
		return asm.Modules.ToArray();
	}

	public static Module GetModule(this Assembly asm, string name)
	{
		return asm.Modules.FirstOrDefault((Module module) => module.Name == name);
	}

	public static byte[] GetBuffer(this MemoryStream ms)
	{
		long position = ms.Position;
		byte[] array = new byte[ms.Length];
		ms.Read(array, 0, array.Length);
		ms.Position = position;
		return array;
	}

	public static TypeReference GetConstraintType(this GenericParameterConstraint constraint)
	{
		return constraint.ConstraintType;
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	public class IgnoresAccessChecksToAttribute : Attribute
	{
		public string AssemblyName { get; }

		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
			AssemblyName = assemblyName;
		}
	}
}
namespace MonoMod
{
	internal static class MMDbgLog
	{
		public static readonly string Tag;

		public static TextWriter Writer;

		public static bool Debugging;

		static MMDbgLog()
		{
			Tag = typeof(MMDbgLog).Assembly.GetName().Name;
			if (!(Environment.GetEnvironmentVariable("MONOMOD_DBGLOG") == "1"))
			{
				string? environmentVariable = Environment.GetEnvironmentVariable("MONOMOD_DBGLOG");
				bool? obj;
				if (environmentVariable == null)
				{
					obj = null;
				}
				else
				{
					string text = environmentVariable.ToLower(CultureInfo.InvariantCulture);
					obj = ((text != null) ? new bool?(MultiTargetShims.Contains(text, Tag.ToLower(CultureInfo.InvariantCulture), StringComparison.Ordinal)) : null);
				}
				bool? flag = obj;
				if (!flag.GetValueOrDefault())
				{
					return;
				}
			}
			Start();
		}

		public static void WaitForDebugger()
		{
			if (!Debugging)
			{
				Debugging = true;
				Debugger.Launch();
				Thread.Sleep(6000);
				Debugger.Break();
			}
		}

		public static void Start()
		{
			if (Writer != null)
			{
				return;
			}
			string text = Environment.GetEnvironmentVariable("MONOMOD_DBGLOG_PATH");
			if (text == "-")
			{
				Writer = Console.Out;
				return;
			}
			if (string.IsNullOrEmpty(text))
			{
				text = "mmdbglog.txt";
			}
			text = Path.GetFullPath(Path.GetFileNameWithoutExtension(text) + "-" + Tag + Path.GetExtension(text));
			try
			{
				if (File.Exists(text))
				{
					File.Delete(text);
				}
			}
			catch
			{
			}
			try
			{
				string directoryName = Path.GetDirectoryName(text);
				if (!Directory.Exists(directoryName))
				{
					Directory.CreateDirectory(directoryName);
				}
				Writer = new StreamWriter(new FileStream(text, FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite | FileShare.Delete), Encoding.UTF8);
			}
			catch
			{
			}
		}

		public static void Log(string str)
		{
			TextWriter writer = Writer;
			if (writer != null)
			{
				writer.WriteLine(str);
				writer.Flush();
			}
		}

		public static T Log<T>(string str, T value)
		{
			TextWriter writer = Writer;
			if (writer == null)
			{
				return value;
			}
			writer.WriteLine(string.Format(CultureInfo.InvariantCulture, str, value));
			writer.Flush();
			return value;
		}
	}
}
namespace MonoMod.ModInterop
{
	[AttributeUsage(AttributeTargets.Class)]
	public sealed class ModExportNameAttribute : Attribute
	{
		public string Name;

		public ModExportNameAttribute(string name)
		{
			Name = name;
		}
	}
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Field)]
	public sealed class ModImportNameAttribute : Attribute
	{
		public string Name;

		public ModImportNameAttribute(string name)
		{
			Name = name;
		}
	}
	public static class ModInteropManager
	{
		private static HashSet<Type> Registered = new HashSet<Type>();

		private static Dictionary<string, List<MethodInfo>> Methods = new Dictionary<string, List<MethodInfo>>();

		private static List<FieldInfo> Fields = new List<FieldInfo>();

		public static void ModInterop(this Type type)
		{
			if (Registered.Contains(type))
			{
				return;
			}
			Registered.Add(type);
			string name = type.Assembly.GetName().Name;
			object[] customAttributes = type.GetCustomAttributes(typeof(ModExportNameAttribute), inherit: false);
			for (int i = 0; i < customAttributes.Length; i++)
			{
				name = ((ModExportNameAttribute)customAttributes[i]).Name;
			}
			FieldInfo[] fields = type.GetFields(BindingFlags.Static | BindingFlags.Public);
			foreach (FieldInfo fieldInfo in fields)
			{
				if (typeof(Delegate).IsAssignableFrom(fieldInfo.FieldType))
				{
					Fields.Add(fieldInfo);
				}
			}
			MethodInfo[] methods = type.GetMethods(BindingFlags.Static | BindingFlags.Public);
			foreach (MethodInfo method in methods)
			{
				method.RegisterModExport();
				method.RegisterModExport(name);
			}
			foreach (FieldInfo field in Fields)
			{
				if (!Methods.TryGetValue(field.GetModImportName(), out var value))
				{
					field.SetValue(null, null);
					continue;
				}
				bool flag = false;
				foreach (MethodInfo item in value)
				{
					try
					{
						field.SetValue(null, Delegate.CreateDelegate(field.FieldType, null, item));
						flag = true;
					}
					catch
					{
						continue;
					}
					break;
				}
				if (!flag)
				{
					field.SetValue(null, null);
				}
			}
		}

		public static void RegisterModExport(this MethodInfo method, string prefix = null)
		{
			if (!method.IsPublic || !method.IsStatic)
			{
				throw new MemberAccessException("Utility must be public static");
			}
			string text = method.Name;
			if (!string.IsNullOrEmpty(prefix))
			{
				text = prefix + "." + text;
			}
			if (!Methods.TryGetValue(text, out var value))
			{
				value = (Methods[text] = new List<MethodInfo>());
			}
			if (!value.Contains(method))
			{
				value.Add(method);
			}
		}

		private static string GetModImportName(this FieldInfo field)
		{
			object[] customAttributes = field.GetCustomAttributes(typeof(ModImportNameAttribute), inherit: false);
			int num = 0;
			if (num < customAttributes.Length)
			{
				return ((ModImportNameAttribute)customAttributes[num]).Name;
			}
			customAttributes = field.DeclaringType.GetCustomAttributes(typeof(ModImportNameAttribute), inherit: false);
			num = 0;
			if (num < customAttributes.Length)
			{
				return ((ModImportNameAttribute)customAttributes[num]).Name + "." + field.Name;
			}
			return field.Name;
		}
	}
}
namespace MonoMod.Utils
{
	public sealed class DynamicData : DynamicObject, IEnumerable<KeyValuePair<string, object>>, IEnumerable
	{
		private class _Cache_
		{
			public readonly Dictionary<string, Func<object, object>> Getters = new Dictionary<string, Func<object, object>>();

			public readonly Dictionary<string, Action<object, object>> Setters = new Dictionary<string, Action<object, object>>();

			public readonly Dictionary<string, Func<object, object[], object>> Methods = new Dictionary<string, Func<object, object[], object>>();

			public _Cache_(Type targetType)
			{
				bool flag = true;
				while (targetType != null && targetType != targetType.BaseType)
				{
					FieldInfo[] fields = targetType.GetFields(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
					foreach (FieldInfo field in fields)
					{
						string name = field.Name;
						if (!Getters.ContainsKey(name) && !Setters.ContainsKey(name))
						{
							Getters[name] = (object obj) => field.GetValue(obj);
							Setters[name] = delegate(object obj, object value)
							{
								field.SetValue(obj, value);
							};
						}
					}
					PropertyInfo[] properties = targetType.GetProperties(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
					foreach (PropertyInfo propertyInfo in properties)
					{
						string name2 = propertyInfo.Name;
						MethodInfo get = propertyInfo.GetGetMethod(nonPublic: true);
						if (get != null && !Getters.ContainsKey(name2))
						{
							Getters[name2] = (object obj) => get.Invoke(obj, _NoArgs);
						}
						MethodInfo set = propertyInfo.GetSetMethod(nonPublic: true);
						if (set != null && !Setters.ContainsKey(name2))
						{
							Setters[name2] = delegate(object obj, object value)
							{
								set.Invoke(obj, new object[1] { value });
							};
						}
					}
					Dictionary<string, MethodInfo> dictionary = new Dictionary<string, MethodInfo>();
					MethodInfo[] methods = targetType.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
					foreach (MethodInfo methodInfo in methods)
					{
						string name3 = methodInfo.Name;
						if (flag || !Methods.ContainsKey(name3))
						{
							if (dictionary.ContainsKey(name3))
							{
								dictionary[name3] = null;
							}
							else
							{
								dictionary[name3] = methodInfo;
							}
						}
					}
					foreach (KeyValuePair<string, MethodInfo> item in dictionary)
					{
						if (!(item.Value == null) && !item.Value.IsGenericMethod)
						{
							FastReflectionDelegate cb = item.Value.GetFastDelegate();
							Methods[item.Key] = (object target, object[] args) => cb(target, args);
						}
					}
					flag = false;
					targetType = targetType.BaseType;
				}
			}
		}

		private class _Data_
		{
			public readonly Dictionary<string, Func<object, object>> Getters = new Dictionary<string, Func<object, object>>();

			public readonly Dictionary<string, Action<object, object>> Setters = new Dictionary<string, Action<object, object>>();

			public readonly Dictionary<string, Func<object, object[], object>> Methods = new Dictionary<string, Func<object, object[], object>>();

			public readonly Dictionary<string, object> Data = new Dictionary<string, object>();

			public _Data_(Type type)
			{
				_ = type == null;
			}
		}

		private static readonly object[] _NoArgs = new object[0];

		private static readonly Dictionary<Type, _Cache_> _CacheMap = new Dictionary<Type, _Cache_>();

		private static readonly Dictionary<Type, _Data_> _DataStaticMap = new Dictionary<Type, _Data_>();

		private static readonly ConditionalWeakTable<object, _Data_> _DataMap = new ConditionalWeakTable<object, _Data_>();

		private static readonly ConditionalWeakTable<object, DynamicData> _DynamicDataMap = new ConditionalWeakTable<object, DynamicData>();

		private readonly WeakReference Weak;

		private object KeepAlive;

		private readonly _Cache_ _Cache;

		private readonly _Data_ _Data;

		public Dictionary<string, Func<object, object>> Getters => _Data.Getters;

		public Dictionary<string, Action<object, object>> Setters => _Data.Setters;

		public Dictionary<string, Func<object, object[], object>> Methods => _Data.Methods;

		public Dictionary<string, object> Data => _Data.Data;

		public bool IsAlive
		{
			get
			{
				if (Weak != null)
				{
					return Weak.SafeGetIsAlive();
				}
				return true;
			}
		}

		public object Target => Weak?.SafeGetTarget();

		public Type TargetType { get; private set; }

		public static event Action<DynamicData, Type, object> OnInitialize;

		public DynamicData(Type type)
			: this(type, null, keepAlive: false)
		{
		}

		public DynamicData(object obj)
			: this(obj.GetType(), obj, keepAlive: true)
		{
		}

		public DynamicData(Type type, object obj)
			: this(type, obj, keepAlive: true)
		{
		}

		public DynamicData(Type type, object obj, bool keepAlive)
		{
			TargetType = type;
			lock (_CacheMap)
			{
				if (!_CacheMap.TryGetValue(type, out _Cache))
				{
					_Cache = new _Cache_(type);
					_CacheMap.Add(type, _Cache);
				}
			}
			if (obj != null)
			{
				lock (_DataMap)
				{
					if (!_DataMap.TryGetValue(obj, out _Data))
					{
						_Data = new _Data_(type);
						_DataMap.Add(obj, _Data);
					}
				}
				Weak = new WeakReference(obj);
				if (keepAlive)
				{
					KeepAlive = obj;
				}
			}
			else
			{
				lock (_DataStaticMap)
				{
					if (!_DataStaticMap.TryGetValue(type, out _Data))
					{
						_Data = new _Data_(type);
						_DataStaticMap.Add(type, _Data);
					}
				}
			}
			DynamicData.OnInitialize?.Invoke(this, type, obj);
		}

		public static DynamicData For(object obj)
		{
			lock (_DynamicDataMap)
			{
				if (!_DynamicDataMap.TryGetValue(obj, out var value))
				{
					value = new DynamicData(obj);
					_DynamicDataMap.Add(obj, value);
				}
				return value;
			}
		}

		public static Func<object, T> New<T>(params object[] args)
		{
			T target = (T)Activator.CreateInstance(typeof(T), BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, args, null);
			return (object other) => Set(target, other);
		}

		public static Func<object, object> New(Type type, params object[] args)
		{
			object target = Activator.CreateInstance(type, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, args, null);
			return (object other) => Set(target, other);
		}

		public static Func<object, dynamic> NewWrap<T>(params object[] args)
		{
			T target = (T)Activator.CreateInstance(typeof(T), BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, args, null);
			return (object other) => Wrap(target, other);
		}

		public static Func<object, dynamic> NewWrap(Type type, params object[] args)
		{
			object target = Activator.CreateInstance(type, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, args, null);
			return (object other) => Wrap(target, other);
		}

		public static dynamic Wrap(object target, object other = null)
		{
			DynamicData dynamicData = new DynamicData(target);
			dynamicData.CopyFrom(other);
			return dynamicData;
		}

		public static T Set<T>(T target, object other = null)
		{
			return (T)Set((object)target, other);
		}

		public static object Set(object target, object other = null)
		{
			DynamicData dynamicData = new DynamicData(target);
			dynamicData.CopyFrom(other);
			return dynamicData.Target;
		}

		public void RegisterProperty(string name, Func<object, object> getter, Action<object, object> setter)
		{
			Getters[name] = getter;
			Setters[name] = setter;
		}

		public void UnregisterProperty(string name)
		{
			Getters.Remove(name);
			Setters.Remove(name);
		}

		public void RegisterMethod(string name, Func<object, object[], object> cb)
		{
			Methods[name] = cb;
		}

		public void UnregisterMethod(string name)
		{
			Methods.Remove(name);
		}

		public void CopyFrom(object other)
		{
			if (other != null)
			{
				PropertyInfo[] properties = other.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public);
				foreach (PropertyInfo propertyInfo in properties)
				{
					Set(propertyInfo.Name, propertyInfo.GetValue(other, null));
				}
			}
		}

		public object Get(string name)
		{
			TryGet(name, out var value);
			return value;
		}

		public bool TryGet(string name, out object value)
		{
			object target = Target;
			if (_Data.Getters.TryGetValue(name, out var value2))
			{
				value = value2(target);
				return true;
			}
			if (_Cache.Getters.TryGetValue(name, out value2))
			{
				value = value2(target);
				return true;
			}
			if (_Data.Data.TryGetValue(name, out value))
			{
				return true;
			}
			return false;
		}

		public T Get<T>(string name)
		{
			return (T)Get(name);
		}

		public bool TryGet<T>(string name, out T value)
		{
			object value2;
			bool result = TryGet(name, out value2);
			value = (T)value2;
			return result;
		}

		public void Set(string name, object value)
		{
			object target = Target;
			if (_Data.Setters.TryGetValue(name, out var value2))
			{
				value2(target, value);
			}
			else if (_Cache.Setters.TryGetValue(name, out value2))
			{
				value2(target, value);
			}
			else
			{
				Data[name] = value;
			}
		}

		public void Add(KeyValuePair<string, object> kvp)
		{
			Set(kvp.Key, kvp.Value);
		}

		public void Add(string key, object value)
		{
			Set(key, value);
		}

		public object Invoke(string name, params object[] args)
		{
			TryInvoke(name, args, out var result);
			return result;
		}

		public bool TryInvoke(string name, object[] args, out object result)
		{
			if (_Data.Methods.TryGetValue(name, out var value))
			{
				result = value(Target, args);
				return true;
			}
			if (_Cache.Methods.TryGetValue(name, out value))
			{
				result = value(Target, args);
				return true;
			}
			result = null;
			return false;
		}

		public T Invoke<T>(string name, params object[] args)
		{
			return (T)Invoke(name, args);
		}

		public bool TryInvoke<T>(string name, object[] args, out T result)
		{
			object result2;
			bool result3 = TryInvoke(name, args, out result2);
			result = (T)result2;
			return result3;
		}

		private void Dispose(bool disposing)
		{
			KeepAlive = null;
		}

		~DynamicData()
		{
			Dispose(disposing: false);
		}

		public void Dispose()
		{
			Dispose(disposing: true);
			GC.SuppressFinalize(this);
		}

		public override IEnumerable<string> GetDynamicMemberNames()
		{
			return _Data.Data.Keys.Union(_Data.Getters.Keys).Union(_Data.Setters.Keys).Union(_Data.Methods.Keys)
				.Union(_Cache.Getters.Keys)
				.Union(_Cache.Setters.Keys)
				.Union(_Cache.Methods.Keys);
		}

		public override bool TryConvert(ConvertBinder binder, out object result)
		{
			if (TargetType.IsCompatible(binder.Type) || TargetType.IsCompatible(binder.ReturnType) || binder.Type == typeof(object) || binder.ReturnType == typeof(object))
			{
				result = Target;
				return true;
			}
			if (typeof(DynamicData).IsCompatible(binder.Type) || typeof(DynamicData).IsCompatible(binder.ReturnType))
			{
				result = this;
				return true;
			}
			result = null;
			return false;
		}

		public override bool TryGetMember(GetMemberBinder binder, out object result)
		{
			if (Methods.ContainsKey(binder.Name))
			{
				result = null;
				return false;
			}
			result = Get(binder.Name);
			return true;
		}

		public override bool TrySetMember(SetMemberBinder binder, object value)
		{
			Set(binder.Name, value);
			return true;
		}

		public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result)
		{
			return TryInvoke(binder.Name, args, out result);
		}

		public IEnumerator<KeyValuePair<string, object>> GetEnumerator()
		{
			foreach (string item in _Data.Data.Keys.Union(_Data.Getters.Keys).Union(_Data.Setters.Keys).Union(_Cache.Getters.Keys)
				.Union(_Cache.Setters.Keys))
			{
				yield return new KeyValuePair<string, object>(item, Get(item));
			}
		}

		IEnumerator IEnumerable.GetEnumerator()
		{
			return GetEnumerator();
		}
	}
	public sealed class DynData<TTarget> : IDisposable where TTarget : class
	{
		private class _Data_ : IDisposable
		{
			public readonly Dictionary<string, Func<TTarget, object>> Getters = new Dictionary<string, Func<TTarget, object>>();

			public readonly Dictionary<string, Action<TTarget, object>> Setters = new Dictionary<string, Action<TTarget, object>>();

			public readonly Dictionary<string, object> Data = new Dictionary<string, object>();

			public readonly HashSet<string> Disposable = new HashSet<string>();

			~_Data_()
			{
				Dispose();
			}

			public void Dispose()
			{
				lock (Data)
				{
					if (Data.Count == 0)
					{
						return;
					}
					foreach (string item in Disposable)
					{
						if (Data.TryGetValue(item, out var value) && value is IDisposable disposable)
						{
							disposable.Dispose();
						}
					}
					Disposable.Clear();
					Data.Clear();
				}
			}
		}

		private static int CreationsInProgress;

		private static readonly object[] _NoArgs;

		private static readonly _Data_ _DataStatic;

		private static readonly ConditionalWeakTable<object, _Data_> _DataMap;

		private static readonly Dictionary<string, Func<TTarget, object>> _SpecialGetters;

		private static readonly Dictionary<string, Action<TTarget, object>> _SpecialSetters;

		private readonly WeakReference Weak;

		private TTarget KeepAlive;

		private readonly _Data_ _Data;

		public Dictionary<string, Func<TTarget, object>> Getters => _Data.Getters;

		public Dictionary<string, Action<TTarget, object>> Setters => _Data.Setters;

		public Dictionary<string, object> Data => _Data.Data;

		public bool IsAlive
		{
			get
			{
				if (Weak != null)
				{
					return Weak.SafeGetIsAlive();
				}
				return true;
			}
		}

		public TTarget Target => Weak?.SafeGetTarget() as TTarget;

		public object this[string name]
		{
			get
			{
				if (_SpecialGetters.TryGetValue(name, out var value) || Getters.TryGetValue(name, out value))
				{
					return value(Weak?.SafeGetTarget() as TTarget);
				}
				if (Data.TryGetValue(name, out var value2))
				{
					return value2;
				}
				return null;
			}
			set
			{
				if (_SpecialSetters.TryGetValue(name, out var value2) || Setters.TryGetValue(name, out value2))
				{
					value2(Weak?.SafeGetTarget() as TTarget, value);
					return;
				}
				object obj;
				if (_Data.Disposable.Contains(name) && (obj = this[name]) != null && obj is IDisposable disposable)
				{
					disposable.Dispose();
				}
				Data[name] = value;
			}
		}

		public static event Action<DynData<TTarget>, TTarget> OnInitialize;

		static DynData()
		{
			CreationsInProgress = 0;
			_NoArgs = new object[0];
			_DataStatic = new _Data_();
			_DataMap = new ConditionalWeakTable<object, _Data_>();
			_SpecialGetters = new Dictionary<string, Func<TTarget, object>>();
			_SpecialSetters = new Dictionary<string, Action<TTarget, object>>();
			FieldInfo[] fields = typeof(TTarget).GetFields(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
			foreach (FieldInfo field in fields)
			{
				string name = field.Name;
				_SpecialGetters[name] = (TTarget obj) => field.GetValue(obj);
				_SpecialSetters[name] = delegate(TTarget obj, object value)
				{
					field.SetValue(obj, value);
				};
			}
			PropertyInfo[] properties = typeof(TTarget).GetProperties(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
			foreach (PropertyInfo propertyInfo in properties)
			{
				string name2 = propertyInfo.Name;
				MethodInfo get = propertyInfo.GetGetMethod(nonPublic: true);
				if (get != null)
				{
					_SpecialGetters[name2] = (TTarget obj) => get.Invoke(obj, _NoArgs);
				}
				MethodInfo set = propertyInfo.GetSetMethod(nonPublic: true);
				if (set != null)
				{
					_SpecialSetters[name2] = delegate(TTarget obj, object value)
					{
						set.Invoke(obj, new object[1] { value });
					};
				}
			}
		}

		public DynData()
			: this((TTarget)null, keepAlive: false)
		{
		}

		public DynData(TTarget obj)
			: this(obj, keepAlive: true)
		{
		}

		public DynData(TTarget obj, bool keepAlive)
		{
			if (obj != null)
			{
				WeakReference weak = new WeakReference(obj);
				CreationsInProgress++;
				lock (_DataMap)
				{
					if (!_DataMap.TryGetValue(obj, out _Data))
					{
						_Data = new _Data_();
						_DataMap.Add(obj, _Data);
					}
				}
				CreationsInProgress--;
				Weak = weak;
				if (keepAlive)
				{
					KeepAlive = obj;
				}
			}
			else
			{
				_Data = _DataStatic;
			}
			DynData<TTarget>.OnInitialize?.Invoke(this, obj);
		}

		public T Get<T>(string name)
		{
			return (T)this[name];
		}

		public void Set<T>(string name, T value)
		{
			this[name] = value;
		}

		public void RegisterProperty(string name, Func<TTarget, object> getter, Action<TTarget, object> setter)
		{
			Getters[name] = getter;
			Setters[name] = setter;
		}

		public void UnregisterProperty(string name)
		{
			Getters.Remove(name);
			Setters.Remove(name);
		}

		private void Dispose(bool disposing)
		{
			KeepAlive = null;
		}

		~DynData()
		{
			Dispose(disposing: false);
		}

		public void Dispose()
		{
			Dispose(disposing: true);
			GC.SuppressFinalize(this);
		}
	}
	public static class Extensions
	{
		private static readonly Type t_StateMachineAttribute = typeof(object).Assembly.GetType("System.Runtime.CompilerServices.StateMachineAttribute");

		private static readonly PropertyInfo p_StateMachineType = t_StateMachineAttribute?.GetProperty("StateMachineType");

		private static readonly Type t_Code = typeof(Code);

		private static readonly Type t_OpCodes = typeof(OpCodes);

		private static readonly Dictionary<int, OpCode> _ToLongOp = new Dictionary<int, OpCode>();

		private static readonly Dictionary<int, OpCode> _ToShortOp = new Dictionary<int, OpCode>();

		private static readonly object[] _NoArgs = new object[0];

		private static readonly Dictionary<Type, FieldInfo> fmap_mono_assembly = new Dictionary<Type, FieldInfo>();

		private static readonly bool _MonoAssemblyNameHasArch = new AssemblyName("Dummy, ProcessorArchitecture=MSIL").ProcessorArchitecture == ProcessorArchitecture.MSIL;

		private static readonly Type _RTDynamicMethod = typeof(DynamicMethod).GetNestedType("RTDynamicMethod", BindingFlags.Public | BindingFlags.NonPublic);

		private static readonly Type t_ParamArrayAttribute = typeof(ParamArrayAttribute);

		private static readonly FieldInfo f_GenericParameter_position = typeof(GenericParameter).GetField("position", BindingFlags.Instance | BindingFlags.NonPublic);

		private static readonly FieldInfo f_GenericParameter_type = typeof(GenericParameter).GetField("type", BindingFlags.Instance | BindingFlags.NonPublic);

		private static readonly Dictionary<Type, int> _GetManagedSizeCache = new Dictionary<Type, int> { 
		{
			typeof(void),
			0
		} };

		private static MethodInfo _GetManagedSizeHelper;

		private static readonly Dictionary<MethodBase, Func<IntPtr>> _GetLdftnPointerCache = new Dictionary<MethodBase, Func<IntPtr>>();

		public static string ToHexadecimalString(this byte[] data)
		{
			return MultiTargetShims.Replace(BitConverter.ToString(data), "-", string.Empty, StringComparison.Ordinal);
		}

		public static T InvokePassing<T>(this MulticastDelegate md, T val, params object[] args)
		{
			if ((object)md == null)
			{
				return val;
			}
			object[] array = new object[args.Length + 1];
			array[0] = val;
			Array.Copy(args, 0, array, 1, args.Length);
			Delegate[] invocationList = md.GetInvocationList();
			for (int i = 0; i < invocationList.Length; i++)
			{
				array[0] = invocationList[i].DynamicInvoke(array);
			}
			return (T)array[0];
		}

		public static bool InvokeWhileTrue(this MulticastDelegate md, params object[] args)
		{
			if ((object)md == null)
			{
				return true;
			}
			Delegate[] invocationList = md.GetInvocationList();
			for (int i = 0; i < invocationList.Length; i++)
			{
				if (!(bool)invocationList[i].DynamicInvoke(args))
				{
					return false;
				}
			}
			return true;
		}

		public static bool InvokeWhileFalse(this MulticastDelegate md, params object[] args)
		{
			if ((object)md == null)
			{
				return false;
			}
			Delegate[] invocationList = md.GetInvocationList();
			for (int i = 0; i < invocationList.Length; i++)
			{
				if ((bool)invocationList[i].DynamicInvoke(args))
				{
					return true;
				}
			}
			return false;
		}

		public static T InvokeWhileNull<T>(this MulticastDelegate md, params object[] args) where T : class
		{
			if ((object)md == null)
			{
				return null;
			}
			Delegate[] invocationList = md.GetInvocationList();
			for (int i = 0; i < invocationList.Length; i++)
			{
				T val = (T)invocationList[i].DynamicInvoke(args);
				if (val != null)
				{
					return val;
				}
			}
			return null;
		}

		public static string SpacedPascalCase(this string input)
		{
			StringBuilder stringBuilder = new StringBuilder();
			for (int i = 0; i < input.Length; i++)
			{
				char c = input[i];
				if (i > 0 && char.IsUpper(c))
				{
					stringBuilder.Append(' ');
				}
				stringBuilder.Append(c);
			}
			return stringBuilder.ToString();
		}

		public static string ReadNullTerminatedString(this BinaryReader stream)
		{
			string text = "";
			char c;
			while ((c = stream.ReadChar()) != 0)
			{
				text += c;
			}
			return text;
		}

		public static void WriteNullTerminatedString(this BinaryWriter stream, string text)
		{
			if (text != null)
			{
				foreach (char ch in text)
				{
					stream.Write(ch);
				}
			}
			stream.Write('\0');
		}

		public static T CastDelegate<T>(this Delegate source) where T : class
		{
			return source.CastDelegate(typeof(T)) as T;
		}

		public static Delegate CastDelegate(this Delegate source, Type type)
		{
			if ((object)source == null)
			{
				return null;
			}
			Delegate[] invocationList = source.GetInvocationList();
			if (invocationList.Length == 1)
			{
				return invocationList[0].Method.CreateDelegate(type, invocationList[0].Target);
			}
			Delegate[] array = new Delegate[invocationList.Length];
			for (int i = 0; i < invocationList.Length; i++)
			{
				array[i] = invocationList[i].CastDelegate(type);
			}
			return Delegate.Combine(array);
		}

		public static bool TryCastDelegate<T>(this Delegate source, out T result) where T : class
		{
			if (source is T val)
			{
				result = val;
				return true;
			}
			Delegate result2;
			bool result3 = source.TryCastDelegate(typeof(T), out result2);
			result = result2 as T;
			return result3;
		}

		public static bool TryCastDelegate(this Delegate source, Type type, out Delegate result)
		{
			result = null;
			if ((object)source == null)
			{
				return false;
			}
			try
			{
				Delegate[] invocationList = source.GetInvocationList();
				if (invocationList.Length == 1)
				{
					result = invocationList[0].Method.CreateDelegate(type, invocationList[0].Target);
					return true;
				}
				Delegate[] array = new Delegate[invocationList.Length];
				for (int i = 0; i < invocationList.Length; i++)
				{
					array[i] = invocationList[i].CastDelegate(type);
				}
				result = Delegate.Combine(array);
				return true;
			}
			catch
			{
				return false;
			}
		}

		public static void LogDetailed(this Exception e, string tag = null)
		{
			if (tag == null)
			{
				Console.WriteLine("--------------------------------");
				Console.WriteLine("Detailed exception log:");
			}
			for (Exception ex = e; ex != null; ex = ex.InnerException)
			{
				Console.WriteLine("--------------------------------");
				Console.WriteLine(ex.GetType().FullName + ": " + ex.Message + "\n" + ex.StackTrace);
				if (ex is ReflectionTypeLoadException ex2)
				{
					for (int i = 0; i < ex2.Types.Length; i++)
					{
						Console.WriteLine("ReflectionTypeLoadException.Types[" + i + "]: " + ex2.Types[i]);
					}
					for (int j = 0; j < ex2.LoaderExceptions.Length; j++)
					{
						ex2.LoaderExceptions[j].LogDetailed(tag + ((tag == null) ? "" : ", ") + "rtle:" + j);
					}
				}
				if (ex is TypeLoadException)
				{
					Console.WriteLine("TypeLoadException.TypeName: " + ((TypeLoadException)ex).TypeName);
				}
				if (ex is BadImageFormatException)
				{
					Console.WriteLine("BadImageFormatException.FileName: " + ((BadImageFormatException)ex).FileName);
				}
			}
		}

		public static MethodInfo GetStateMachineTarget(this MethodInfo method)
		{
			if (p_StateMachineType == null)
			{
				return null;
			}
			object[] customAttributes = method.GetCustomAttributes(inherit: false);
			for (int i = 0; i < customAttributes.Length; i++)
			{
				Attribute attribute = (Attribute)customAttributes[i];
				if (t_StateMachineAttribute.IsCompatible(attribute.GetType()))
				{
					return (p_StateMachineType.GetValue(attribute, null) as Type)?.GetMethod("MoveNext", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				}
			}
			return null;
		}

		public static MethodBase GetActualGenericMethodDefinition(this MethodInfo method)
		{
			return (method.IsGenericMethod ? method.GetGenericMethodDefinition() : method).GetUnfilledMethodOnGenericType();
		}

		public static MethodBase GetUnfilledMethodOnGenericType(this MethodBase method)
		{
			if (method.DeclaringType != null && method.DeclaringType.IsGenericType)
			{
				Type genericTypeDefinition = method.DeclaringType.GetGenericTypeDefinition();
				method = MethodBase.GetMethodFromHandle(method.MethodHandle, genericTypeDefinition.TypeHandle);
			}
			return method;
		}

		public static bool Is(this MemberReference member, string fullName)
		{
			if (member == null)
			{
				return false;
			}
			return MultiTargetShims.Replace(member.FullName, "+", "/", StringComparison.Ordinal) == MultiTargetShims.Replace(fullName, "+", "/", StringComparison.Ordinal);
		}

		public static bool Is(this MemberReference member, string typeFullName, string name)
		{
			if (member == null)
			{
				return false;
			}
			if (MultiTargetShims.Replace(((MemberReference)member.DeclaringType).FullName, "+", "/", StringComparison.Ordinal) == MultiTargetShims.Replace(typeFullName, "+", "/", StringComparison.Ordinal))
			{
				return member.Name == name;
			}
			return false;
		}

		public static bool Is(this MemberReference member, Type type, string name)
		{
			if (member == null)
			{
				return false;
			}
			if (MultiTargetShims.Replace(((MemberReference)member.DeclaringType).FullName, "+", "/", StringComparison.Ordinal) == MultiTargetShims.Replace(type.FullName, "+", "/", StringComparison.Ordinal))
			{
				return member.Name == name;
			}
			return false;
		}

		public static bool Is(this MethodReference method, string fullName)
		{
			if (method == null)
			{
				return false;
			}
			if (MultiTargetShims.Contains(fullName, " ", StringComparison.Ordinal))
			{
				if (MultiTargetShims.Replace(method.GetID(null, null, withType: true, simple: true), "+", "/", StringComparison.Ordinal) == MultiTargetShims.Replace(fullName, "+", "/", StringComparison.Ordinal))
				{
					return true;
				}
				if (MultiTargetShims.Replace(method.GetID(), "+", "/", StringComparison.Ordinal) == MultiTargetShims.Replace(fullName, "+", "/", StringComparison.Ordinal))
				{
					return true;
				}
			}
			return MultiTargetShims.Replace(((MemberReference)method).FullName, "+", "/", StringComparison.Ordinal) == MultiTargetShims.Replace(fullName, "+", "/", StringComparison.Ordinal);
		}

		public static bool Is(this MethodReference method, string typeFullName, string name)
		{
			if (method == null)
			{
				return false;
			}
			if (MultiTargetShims.Contains(name, " ", StringComparison.Ordinal) && MultiTargetShims.Replace(((MemberReference)((MemberReference)method).DeclaringType).FullName, "+", "/", StringComparison.Ordinal) == MultiTargetShims.Replace(typeFullName, "+", "/", StringComparison.Ordinal) && MultiTargetShims.Replace(method.GetID(null, null, withType: false), "+", "/", StringComparison.Ordinal) == MultiTargetShims.Replace(name, "+", "/", StringComparison.Ordinal))
			{
				return true;
			}
			if (MultiTargetShims.Replace(((MemberReference)((MemberReference)method).DeclaringType).FullName, "+", "/", StringComparison.Ordinal) == MultiTargetShims.Replace(typeFullName, "+", "/", StringComparison.Ordinal))
			{
				return ((MemberReference)method).Name == name;
			}
			return false;
		}

		public static bool Is(this MethodReference method, Type type, string name)
		{
			if (method == null)
			{
				return false;
			}
			if (MultiTargetShims.Contains(name, " ", StringComparison.Ordinal) && MultiTargetShims.Replace(((MemberReference)((MemberReference)method).DeclaringType).FullName, "+", "/", StringComparison.Ordinal) == MultiTargetShims.Replace(type.FullName, "+", "/", StringComparison.Ordinal) && MultiTargetShims.Replace(method.GetID(null, null, withType: false), "+", "/", StringComparison.Ordinal) == MultiTargetShims.Replace(name, "+", "/", StringComparison.Ordinal))
			{
				return true;
			}
			if (MultiTargetShims.Replace(((MemberReference)((MemberReference)method).DeclaringType).FullName, "+", "/", StringComparison.Ordinal) == MultiTargetShims.Replace(type.FullName, "+", "/", StringComparison.Ordinal))
			{
				return ((MemberReference)method).Name == name;
			}
			return false;
		}

		public static void ReplaceOperands(this ILProcessor il, object from, object to)
		{
			//IL_000b: 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)
			Enumerator<Instruction> enumerator = il.Body.Instructions.GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					Instruction current = enumerator.Current;
					if (current.Operand?.Equals(from) ?? (from == null))
					{
						current.Operand = to;
					}
				}
			}
			finally
			{
				((IDisposable)enumerator).Dispose();
			}
		}

		public static FieldReference Import(this ILProcessor il, FieldInfo field)
		{
			return ((MemberReference)il.Body.Method).Module.ImportReference(field);
		}

		public static MethodReference Import(this ILProcessor il, MethodBase method)
		{
			return ((MemberReference)il.Body.Method).Module.ImportReference(method);
		}

		public static TypeReference Import(this ILProcessor il, Type type)
		{
			return ((MemberReference)il.Body.Method).Module.ImportReference(type);
		}

		public static MemberReference Import(this ILProcessor il, MemberInfo member)
		{
			if (member == null)
			{
				throw new ArgumentNullException("member");
			}
			if (!(member is FieldInfo field))
			{
				if (!(member is MethodBase method))
				{
					if (member is Type type)
					{
						return (MemberReference)(object)il.Import(type);
					}
					throw new NotSupportedException("Unsupported member type " + member.GetType().FullName);
				}
				return (MemberReference)(object)il.Import(method);
			}
			return (MemberReference)(object)il.Import(field);
		}

		public static Instruction Create(this ILProcessor il, OpCode opcode, FieldInfo field)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			return il.Create(opcode, il.Import(field));
		}

		public static Instruction Create(this ILProcessor il, OpCode opcode, MethodBase method)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			if (method is DynamicMethod)
			{
				return il.Create(opcode, (object)method);
			}
			return il.Create(opcode, il.Import(method));
		}

		public static Instruction Create(this ILProcessor il, OpCode opcode, Type type)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			return il.Create(opcode, il.Import(type));
		}

		public static Instruction Create(this ILProcessor il, OpCode opcode, object operand)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			Instruction obj = il.Create(OpCodes.Nop);
			obj.OpCode = opcode;
			obj.Operand = operand;
			return obj;
		}

		public static Instruction Create(this ILProcessor il, OpCode opcode, MemberInfo member)
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			if (member == null)
			{
				throw new ArgumentNullException("member");
			}
			if (!(member is FieldInfo field))
			{
				if (!(member is MethodBase method))
				{
					if (member is Type type)
					{
						return il.Create(opcode, type);
					}
					throw new NotSupportedException("Unsupported member type " + member.GetType().FullName);
				}
				return il.Create(opcode, method);
			}
			return il.Create(opcode, field);
		}

		public static void Emit(this ILProcessor il, OpCode opcode, FieldInfo field)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			il.Emit(opcode, il.Import(field));
		}

		public static void Emit(this ILProcessor il, OpCode opcode, MethodBase method)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			if (method is DynamicMethod)
			{
				il.Emit(opcode, (object)method);
			}
			else
			{
				il.Emit(opcode, il.Import(method));
			}
		}

		public static void Emit(this ILProcessor il, OpCode opcode, Type type)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			il.Emit(opcode, il.Import(type));
		}

		public static void Emit(this ILProcessor il, OpCode opcode, MemberInfo member)
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			if (member == null)
			{
				throw new ArgumentNullException("member");
			}
			if (!(member is FieldInfo field))
			{
				if (!(member is MethodBase method))
				{
					if (!(member is Type type))
					{
						throw new NotSupportedException("Unsupported member type " + member.GetType().FullName);
					}
					il.Emit(opcode, type);
				}
				else
				{
					il.Emit(opcode, method);
				}
			}
			else
			{
				il.Emit(opcode, field);
			}
		}

		public static void Emit(this ILProcessor il, OpCode opcode, object operand)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			il.Append(il.Create(opcode, operand));
		}

		public static TypeDefinition SafeResolve(this TypeReference r)
		{
			try
			{
				return r.Resolve();
			}
			catch
			{
				return null;
			}
		}

		public static FieldDefinition SafeResolve(this FieldReference r)
		{
			try
			{
				return r.Resolve();
			}
			catch
			{
				return null;
			}
		}

		public static MethodDefinition SafeResolve(this MethodReference r)
		{
			try
			{
				return r.Resolve();
			}
			catch
			{
				return null;
			}
		}

		public static PropertyDefinition SafeResolve(this PropertyReference r)
		{
			try
			{
				return r.Resolve();
			}
			catch
			{
				return null;
			}
		}

		public static CustomAttribute GetCustomAttribute(this ICustomAttributeProvider cap, string attribute)
		{
			//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)
			if (cap == null || !cap.HasCustomAttributes)
			{
				return null;
			}
			Enumerator<CustomAttribute> enumerator = cap.CustomAttributes.GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					CustomAttribute current = enumerator.Current;
					if (((MemberReference)current.AttributeType).FullName == attribute)
					{
						return current;
					}
				}
			}
			finally
			{
				((IDisposable)enumerator).Dispose();
			}
			return null;
		}

		public static bool HasCustomAttribute(this ICustomAttributeProvider cap, string attribute)
		{
			return cap.GetCustomAttribute(attribute) != null;
		}

		public static int GetInt(this Instruction instr)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: 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_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: 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_0061: 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_0070: 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_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			OpCode opCode = instr.OpCode;
			if (opCode == OpCodes.Ldc_I4_M1)
			{
				return -1;
			}
			if (opCode == OpCodes.Ldc_I4_0)
			{
				return 0;
			}
			if (opCode == OpCodes.Ldc_I4_1)
			{
				return 1;
			}
			if (opCode == OpCodes.Ldc_I4_2)
			{
				return 2;
			}
			if (opCode == OpCodes.Ldc_I4_3)
			{
				return 3;
			}
			if (opCode == OpCodes.Ldc_I4_4)
			{
				return 4;
			}
			if (opCode == OpCodes.Ldc_I4_5)
			{
				return 5;
			}
			if (opCode == OpCodes.Ldc_I4_6)
			{
				return 6;
			}
			if (opCode == OpCodes.Ldc_I4_7)
			{
				return 7;
			}
			if (opCode == OpCodes.Ldc_I4_8)
			{
				return 8;
			}
			if (opCode == OpCodes.Ldc_I4_S)
			{
				return (sbyte)instr.Operand;
			}
			return (int)instr.Operand;
		}

		public static int? GetIntOrNull(this Instruction instr)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: 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_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: 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_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			OpCode opCode = instr.OpCode;
			if (opCode == OpCodes.Ldc_I4_M1)
			{
				return -1;
			}
			if (opCode == OpCodes.Ldc_I4_0)
			{
				return 0;
			}
			if (opCode == OpCodes.Ldc_I4_1)
			{
				return 1;
			}
			if (opCode == OpCodes.Ldc_I4_2)
			{
				return 2;
			}
			if (opCode == OpCodes.Ldc_I4_3)
			{
				return 3;
			}
			if (opCode == OpCodes.Ldc_I4_4)
			{
				return 4;
			}
			if (opCode == OpCodes.Ldc_I4_5)
			{
				return 5;
			}
			if (opCode == OpCodes.Ldc_I4_6)
			{
				return 6;
			}
			if (opCode == OpCodes.Ldc_I4_7)
			{
				return 7;
			}
			if (opCode == OpCodes.Ldc_I4_8)
			{
				return 8;
			}
			if (opCode == OpCodes.Ldc_I4_S)
			{
				return (sbyte)instr.Operand;
			}
			if (opCode == OpCodes.Ldc_I4)
			{
				return (int)instr.Operand;
			}
			return null;
		}

		public static bool IsBaseMethodCall(this MethodBody body, MethodReference called)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			MethodDefinition method = body.Method;
			if (called == null)
			{
				return false;
			}
			TypeReference val = ((MemberReference)called).DeclaringType;
			while (val is TypeSpecification)
			{
				val = ((TypeSpecification)val).ElementType;
			}
			string patchFullName = ((MemberReference)(object)val).GetPatchFullName();
			bool flag = false;
			try
			{
				TypeDefinition val2 = method.DeclaringType;
				while ((val2 = val2.BaseType?.SafeResolve()) != null)
				{
					if (((MemberReference)(object)val2).GetPatchFullName() == patchFullName)
					{
						flag = true;
						break;
					}
				}
			}
			catch
			{
				flag = ((MemberReference)(object)method.DeclaringType).GetPatchFullName() == patchFullName;
			}
			if (!flag)
			{
				return false;
			}
			return true;
		}

		public static bool IsCallvirt(this MethodReference method)
		{
			if (!method.HasThis)
			{
				return false;
			}
			if (((MemberReference)method).DeclaringType.IsValueType)
			{
				return false;
			}
			return true;
		}

		public static bool IsStruct(this TypeReference type)
		{
			if (!type.IsValueType)
			{
				return false;
			}
			if (type.IsPrimitive)
			{
				return false;
			}
			return true;
		}

		public static OpCode ToLongOp(this OpCode op)
		{
			//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_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Expected I4, but got Unknown
			//IL_0058: 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_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Expected I4, but got Unknown
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			string name = Enum.GetName(t_Code, ((OpCode)(ref op)).Code);
			if (!name.EndsWith("_S", StringComparison.Ordinal))
			{
				return op;
			}
			lock (_ToLongOp)
			{
				if (_ToLongOp.TryGetValue((int)((OpCode)(ref op)).Code, out var value))
				{
					return value;
				}
				return _ToLongOp[(int)((OpCode)(ref op)).Code] = (OpCode)(((??)(OpCode?)t_OpCodes.GetField(name.Substring(0, name.Length - 2))?.GetValue(null)) ?? op);
			}
		}

		public static OpCode ToShortOp(this OpCode op)
		{
			//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_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Expected I4, but got Unknown
			//IL_0058: 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_004d: 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_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00a1: Expected I4, but got Unknown
			//IL_00a1: 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)
			string name = Enum.GetName(t_Code, ((OpCode)(ref op)).Code);
			if (name.EndsWith("_S", StringComparison.Ordinal))
			{
				return op;
			}
			lock (_ToShortOp)
			{
				if (_ToShortOp.TryGetValue((int)((OpCode)(ref op)).Code, out var value))
				{
					return value;
				}
				return _ToShortOp[(int)((OpCode)(ref op)).Code] = (OpCode)(((??)(OpCode?)t_OpCodes.GetField(name + "_S")?.GetValue(null)) ?? op);
			}
		}

		public static void RecalculateILOffsets(this MethodDefinition method)
		{
			if (method.HasBody)
			{
				int num = 0;
				for (int i = 0; i < method.Body.Instructions.Count; i++)
				{
					Instruction val = method.Body.Instructions[i];
					val.Offset = num;
					num += val.GetSize();
				}
			}
		}

		public static void FixShortLongOps(this MethodDefinition method)
		{
			//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_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			if (!method.HasBody)
			{
				return;
			}
			for (int i = 0; i < method.Body.Instructions.Count; i++)
			{
				Instruction val = method.Body.Instructions[i];
				if (val.Operand is Instruction)
				{
					val.OpCode = val.OpCode.ToLongOp();
				}
			}
			method.RecalculateILOffsets();
			bool flag;
			do
			{
				flag = false;
				for (int j = 0; j < method.Body.Instructions.Count; j++)
				{
					Instruction val2 = method.Body.Instructions[j];
					object operand = val2.Operand;
					Instruction val3 = (Instruction)((operand is Instruction) ? operand : null);
					if (val3 != null)
					{
						int num = val3.Offset - (val2.Offset + val2.GetSize());
						if (num == (sbyte)num)
						{
							OpCode opCode = val2.OpCode;
							val2.OpCode = val2.OpCode.ToShortOp();
							flag = opCode != val2.OpCode;
						}
					}
				}
			}
			while (flag);
		}

		public static bool Is(this MemberInfo minfo, MemberReference mref)
		{
			return mref.Is(minfo);
		}

		public static bool Is(this MemberReference mref, MemberInfo minfo)
		{
			if (mref == null)
			{
				return false;
			}
			TypeReference val = mref.DeclaringType;
			if (((val != null) ? ((MemberReference)val).FullName : null) == "<Module>")
			{
				val = null;
			}
			GenericParameter val2 = (GenericParameter)(object)((mref is GenericParameter) ? mref : null);
			if (val2 != null)
			{
				if (!(minfo is Type type))
				{
					return false;
				}
				if (!type.IsGenericParameter)
				{
					IGenericParameterProvider owner = val2.Owner;
					IGenericInstance val3 = (IGenericInstance)(object)((owner is IGenericInstance) ? owner : null);
					if (val3 != null)
					{
						return ((MemberReference)(object)val3.GenericArguments[val2.Position]).Is(type);
					}
					return false;
				}
				return val2.Position == type.GenericParameterPosition;
			}
			if (minfo.DeclaringType != null)
			{
				if (val == null)
				{
					return false;
				}
				Type type2 = minfo.DeclaringType;
				if (minfo is Type && type2.IsGenericType && !type2.IsGenericTypeDefinition)
				{
					type2 = type2.GetGenericTypeDefinition();
				}
				if (!((MemberReference)(object)val).Is(type2))
				{
					return false;
				}
			}
			else if (val != null)
			{
				return false;
			}
			if (!(mref is TypeSpecification) && mref.Name != minfo.Name)
			{
				return false;
			}
			TypeReference val4 = (TypeReference)(object)((mref is TypeReference) ? mref : null);
			if (val4 != null)
			{
				if (!(minfo is Type type3))
				{
					return false;
				}
				if (type3.IsGenericParameter)
				{
					return false;
				}
				GenericInstanceType val5 = (GenericInstanceType)(object)((mref is GenericInstanceType) ? mref : null);
				if (val5 != null)
				{
					if (!type3.IsGenericType)
					{
						return false;
					}
					Collection<TypeReference> genericArguments = val5.GenericArguments;
					Type[] genericArguments2 = type3.GetGenericArguments();
					if (genericArguments.Count != genericArguments2.Length)
					{
						return false;
					}
					for (int i = 0; i < genericArguments.Count; i++)
					{
						if (!((MemberReference)(object)genericArguments[i]).Is(genericArguments2[i]))
						{
							return false;
						}
					}
					return ((MemberReference)(object)((TypeSpecification)val5).ElementType).Is(type3.GetGenericTypeDefinition());
				}
				if (val4.HasGenericParameters)
				{
					if (!type3.IsGenericType)
					{
						return false;
					}
					Collection<GenericParameter> genericParameters = val4.GenericParameters;
					Type[] genericArguments3 = type3.GetGenericArguments();
					if (genericParameters.Count != genericArguments3.Length)
					{
						return false;
					}
					for (int j = 0; j < genericParameters.Count; j++)
					{
						if (!((MemberReference)(object)genericParameters[j]).Is(genericArguments3[j]))
						{
							return false;
						}
					}
				}
				else if (type3.IsGenericType)
				{
					return false;
				}
				ArrayType val6 = (ArrayType)(object)((mref is ArrayType) ? mref : null);
				if (val6 != null)
				{
					if (!type3.IsArray)
					{
						return false;
					}
					if (val6.Dimensions.Count == type3.GetArrayRank())
					{
						return ((MemberReference)(object)((TypeSpecification)val6).ElementType).Is(type3.GetElementType());
					}
					return false;
				}
				ByReferenceType val7 = (ByReferenceType)(object)((mref is ByReferenceType) ? mref : null);
				if (val7 != null)
				{
					if (!type3.IsByRef)
					{
						return false;
					}
					return ((MemberReference)(object)((TypeSpecification)val7).ElementType).Is(type3.GetElementType());
				}
				PointerType val8 = (PointerType)(object)((mref is PointerType) ? mref : null);
				if (val8 != null)
				{
					if (!type3.IsPointer)
					{
						return false;
					}
					return ((MemberReference)(object)((TypeSpecification)val8).ElementType).Is(type3.GetElementType());
				}
				TypeSpecification val9 = (TypeSpecification)(object)((mref is TypeSpecification) ? mref : null);
				if (val9 != null)
				{
					return ((MemberReference)(object)val9.ElementType).Is(type3.HasElementType ? type3.GetElementType() : type3);
				}
				if (val != null)
				{
					return mref.Name == type3.Name;
				}
				return mref.FullName == MultiTargetShims.Replace(type3.FullName, "+", "/", StringComparison.Ordinal);
			}
			if (minfo is Type)
			{
				return false;
			}
			MethodReference methodRef = (MethodReference)(object)((mref is MethodReference) ? mref : null);
			if (methodRef != null)
			{
				if (!(minfo is MethodBase methodBase))
				{
					return false;
				}
				Collection<ParameterDefinition> parameters = methodRef.Parameters;
				ParameterInfo[] parameters2 = methodBase.GetParameters();
				if (parameters.Count != parameters2.Length)
				{
					return false;
				}
				GenericInstanceMethod val10 = (GenericInstanceMethod)(object)((mref is GenericInstanceMethod) ? mref : null);
				if (val10 != null)
				{
					if (!methodBase.IsGenericMethod)
					{
						return false;
					}
					Collection<TypeReference> genericArguments4 = val10.GenericArguments;
					Type[] genericArguments5 = methodBase.GetGenericArguments();
					if (genericArguments4.Count != genericArguments5.Length)
					{
						return false;
					}
					for (int k = 0; k < genericArguments4.Count; k++)
					{
						if (!((MemberReference)(object)genericArguments4[k]).Is(genericArguments5[k]))
						{
							return false;
						}
					}
					return ((MemberReference)(object)((MethodSpecification)val10).ElementMethod).Is((methodBase as MethodInfo)?.GetGenericMethodDefinition() ?? methodBase);
				}
				if (methodRef.HasGenericParameters)
				{
					if (!methodBase.IsGenericMethod)
					{
						return false;
					}
					Collection<GenericParameter> genericParameters2 = methodRef.GenericParameters;
					Type[] genericArguments6 = methodBase.GetGenericArguments();
					if (genericParameters2.Count != genericArguments6.Length)
					{
						return false;
					}
					for (int l = 0; l < genericParameters2.Count; l++)
					{
						if (!((MemberReference)(object)genericParameters2[l]).Is(genericArguments6[l]))
						{
							return false;
						}
					}
				}
				else if (methodBase.IsGenericMethod)
				{
					return false;
				}
				Relinker relinker = null;
				relinker = delegate(IMetadataTokenProvider paramMemberRef, IGenericParameterProvider ctx)
				{
					TypeReference val15 = (TypeReference)(object)((paramMemberRef is TypeReference) ? paramMemberRef : null);
					return (IMetadataTokenProvider)((val15 == null) ? ((object)paramMemberRef) : ((object)ResolveParameter(val15)));
				};
				if (!((MemberReference)(object)methodRef.ReturnType.Relink(relinker, null)).Is((methodBase as MethodInfo)?.ReturnType ?? typeof(void)) && !((MemberReference)(object)methodRef.ReturnType).Is((methodBase as MethodInfo)?.ReturnType ?? typeof(void)))
				{
					return false;
				}
				for (int m = 0; m < parameters.Count; m++)
				{
					if (!((MemberReference)(object)((ParameterReference)parameters[m]).ParameterType.Relink(relinker, null)).Is(parameters2[m].ParameterType) && !((MemberReference)(object)((ParameterReference)parameters[m]).ParameterType).Is(parameters2[m].ParameterType))
					{
						return false;
					}
				}
				return true;
			}
			if (minfo is MethodInfo)
			{
				return false;
			}
			if (mref is FieldReference != minfo is FieldInfo)
			{
				return false;
			}
			if (mref is PropertyReference != minfo is PropertyInfo)
			{
				return false;
			}
			if (mref is EventReference != minfo is EventInfo)
			{
				return false;
			}
			return true;
			TypeReference ResolveParameter(TypeReference paramTypeRef)
			{
				GenericParameter val11 = (GenericParameter)(object)((paramTypeRef is GenericParameter) ? paramTypeRef : null);
				if (val11 != null)
				{
					if (val11.Owner is MethodReference)
					{
						MethodReference obj = methodRef;
						GenericInstanceMethod val12 = (GenericInstanceMethod)(object)((obj is GenericInstanceMethod) ? obj : null);
						if (val12 != null)
						{
							return val12.GenericArguments[val11.Position];
						}
					}
					IGenericParameterProvider owner2 = val11.Owner;
					TypeReference val13 = (TypeReference)(object)((owner2 is TypeReference) ? owner2 : null);
					if (val13 != null)
					{
						TypeReference declaringType = ((MemberReference)methodRef).DeclaringType;
						GenericInstanceType val14 = (GenericInstanceType)(object)((declaringType is GenericInstanceType) ? declaringType : null);
						if (val14 != null && ((MemberReference)val13).FullName == ((MemberReference)((TypeSpecification)val14).ElementType).FullName)
						{
							return val14.GenericArguments[val11.Position];
						}
					}
					return paramTypeRef;
				}
				if (paramTypeRef == ((MemberReference)methodRef).DeclaringType.GetElementType())
				{
					return ((MemberReference)methodRef).DeclaringType;
				}
				return paramTypeRef;
			}
		}

		public static IMetadataTokenProvider ImportReference(this ModuleDefinition mod, IMetadataTokenProvider mtp)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Expected O, but got Unknown
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Expected O, but got Unknown
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Expected O, but got Unknown
			if (mtp is TypeReference)
			{
				return (IMetadataTokenProvider)(object)mod.ImportReference((TypeReference)mtp);
			}
			if (mtp is FieldReference)
			{
				return (IMetadataTokenProvider)(object)mod.ImportReference((FieldReference)mtp);
			}
			if (mtp is MethodReference)
			{
				return (IMetadataTokenProvider)(object)mod.ImportReference((MethodReference)mtp);
			}
			return mtp;
		}

		public static void AddRange<T>(this Collection<T> list, IEnumerable<T> other)
		{
			foreach (T item in other)
			{
				list.Add(item);
			}
		}

		public static void AddRange(this IDictionary dict, IDictionary other)
		{
			foreach (DictionaryEntry item in other)
			{
				dict.Add(item.Key, item.Value);
			}
		}

		public static void AddRange<K, V>(this IDictionary<K, V> dict, IDictionary<K, V> other)
		{
			foreach (KeyValuePair<K, V> item in other)
			{
				dict.Add(item.Key, item.Value);
			}
		}

		public static void AddRange<K, V>(this Dictionary<K, V> dict, Dictionary<K, V> other)
		{
			foreach (KeyValuePair<K, V> item in other)
			{
				dict.Add(item.Key, item.Value);
			}
		}

		public static void InsertRange<T>(this Collection<T> list, int index, IEnumerable<T> other)
		{
			foreach (T item in other)
			{
				list.Insert(index++, item);
			}
		}

		public static bool IsCompatible(this Type type, Type other)
		{
			if (!type._IsCompatible(other))
			{
				return other._IsCompatible(type);
			}
			return true;
		}

		private static bool _IsCompatible(this Type type, Type other)
		{
			if (type == other)
			{
				return true;
			}
			if (type.IsAssignableFrom(other))
			{
				return true;
			}
			if (other.IsEnum && type.IsCompatible(Enum.GetUnderlyingType(other)))
			{
				return true;
			}
			if ((other.IsPointer || other.IsByRef) && type == typeof(IntPtr))
			{
				return true;
			}
			return false;
		}

		public static T GetDeclaredMember<T>(this T member) where T : MemberInfo
		{
			if (member.DeclaringType == member.ReflectedType)
			{
				return member;
			}
			int metadataToken = member.MetadataToken;
			MemberInfo[] members = member.DeclaringType.GetMembers((BindingFlags)(-1));
			foreach (MemberInfo memberInfo in members)
			{
				if (memberInfo.MetadataToken == metadataToken)
				{
					return (T)memberInfo;
				}
			}
			return member;
		}

		public unsafe static void SetMonoCorlibInternal(this Assembly asm, bool value)
		{
			if (!ReflectionHelper.IsMono)
			{
				return;
			}
			Type type = asm?.GetType();
			if (type == null)
			{
				return;
			}
			FieldInfo value2;
			lock (fmap_mono_assembly)
			{
				if (!fmap_mono_assembly.TryGetValue(type, out value2))
				{
					value2 = type.GetField("_mono_assembly", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) ?? type.GetField("dynamic_assembly", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					fmap_mono_assembly[type] = value2;
				}
			}
			if (value2 == null)
			{
				return;
			}
			AssemblyName assemblyName = new AssemblyName(asm.FullName);
			lock (ReflectionHelper.AssemblyCache)
			{
				WeakReference value3 = new WeakReference(asm);
				ReflectionHelper.AssemblyCache[asm.GetRuntimeHashedFullName()] = value3;
				ReflectionHelper.AssemblyCache[assemblyName.FullName] = value3;
				ReflectionHelper.AssemblyCache[assemblyName.Name] = value3;
			}
			long num = 0L;
			object value4 = value2.GetValue(asm);
			if (!(value4 is IntPtr intPtr))
			{
				if (value4 is UIntPtr uIntPtr)
				{
					num = (long)(ulong)uIntPtr;
				}
			}
			else
			{
				num = (long)intPtr;
			}
			int num2 = IntPtr.Size + IntPtr.Size + IntPtr.Size + IntPtr.Size + IntPtr.Size + IntPtr.Size + 20 + 4 + 4 + 4 + (_MonoAssemblyNameHasArch ? ((!ReflectionHelper.IsCore) ? ((IntPtr.Size == 4) ? 12 : 16) : ((IntPtr.Size == 4) ? 20 : 24)) : (ReflectionHelper.IsCore ? 16 : 8)) + IntPtr.Size + IntPtr.Size + 1 + 1 + 1;
			byte* ptr = (byte*)(num + num2);
			*ptr = (byte)(value ? 1 : 0);
		}

		public static bool IsDynamicMethod(this MethodBase method)
		{
			if (_RTDynamicMethod != null)
			{
				if (!(method is DynamicMethod))
				{
					return method.GetType() == _RTDynamicMethod;
				}
				return true;
			}
			if (method is DynamicMethod)
			{
				return true;
			}
			if (method.MetadataToken != 0 || !method.IsStatic || !method.IsPublic || (method.Attributes & MethodAttributes.PrivateScope) != 0)
			{
				return false;
			}
			MethodInfo[] methods = method.DeclaringType.GetMethods(BindingFlags.Static | BindingFlags.Public);
			foreach (MethodInfo methodInfo in methods)
			{
				if (method == methodInfo)
				{
					return false;
				}
			}
			return true;
		}

		public static object SafeGetTarget(this WeakReference weak)
		{
			try
			{
				return weak.Target;
			}
			catch (InvalidOperationException)
			{
				return null;
			}
		}

		public static bool SafeGetIsAlive(this WeakReference weak)
		{
			try
			{
				return weak.IsAlive;
			}
			catch (InvalidOperationException)
			{
				return false;
			}
		}

		public static T CreateDelegate<T>(this MethodBase method) where T : Delegate
		{
			return (T)method.CreateDelegate(typeof(T), null);
		}

		public static T CreateDelegate<T>(this MethodBase method, object target) where T : Delegate
		{
			return (T)method.CreateDelegate(typeof(T), target);
		}

		public static Delegate CreateDelegate(this MethodBase method, Type delegateType)
		{
			return method.CreateDelegate(delegateType, null);
		}

		public static Delegate CreateDelegate(this MethodBase method, Type delegateType, object target)
		{
			if (!typeof(Delegate).IsAssignableFrom(delegateType))
			{
				throw new ArgumentException("Type argument must be a delegate type!");
			}
			if (method is DynamicMethod dynamicMethod)
			{
				return dynamicMethod.CreateDelegate(delegateType, target);
			}
			if (method is MethodInfo methodInfo)
			{
				return methodInfo.CreateDelegate(delegateType, target);
			}
			RuntimeMethodHandle methodHandle = method.MethodHandle;
			RuntimeHelpers.PrepareMethod(methodHandle);
			IntPtr functionPointer = methodHandle.GetFunctionPointer();
			return (Delegate)Activator.CreateInstance(delegateType, target, functionPointer);
		}

		public static MethodDefinition FindMethod(this TypeDefinition type, string id, bool simple = true)
		{
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_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)
			Enumerator<MethodDefinition> enumerator;
			if (simple && !MultiTargetShims.Contains(id, " ", StringComparison.Ordinal))
			{
				enumerator = type.Methods.GetEnumerator();
				try
				{
					while (enumerator.MoveNext())
					{
						MethodDefinition current = enumerator.Current;
						if (((MethodReference)(object)current).GetID(null, null, withType: true, simple: true) == id)
						{
							return current;
						}
					}
				}
				finally
				{
					((IDisposable)enumerator).Dispose();
				}
				enumerator = type.Methods.GetEnumerator();
				try
				{
					while (enumerator.MoveNext())
					{
						MethodDefinition current2 = enumerator.Current;
						if (((MethodReference)(object)current2).GetID(null, null, withType: false, simple: true) == id)
						{
							return current2;
						}
					}
				}
				finally
				{
					((IDisposable)enumerator).Dispose();
				}
			}
			enumerator = type.Methods.GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					MethodDefinition current3 = enumerator.Current;
					if (((MethodReference)(object)current3).GetID() == id)
					{
						return current3;
					}
				}
			}
			finally
			{
				((IDisposable)enumerator).Dispose();
			}
			enumerator = type.Methods.GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					MethodDefinition current4 = enumerator.Current;
					if (((MethodReference)(object)current4).GetID(null, null, withType: false) == id)
					{
						return current4;
					}
				}
			}
			finally
			{
				((IDisposable)enumerator).Dispose();
			}
			return null;
		}

		public static MethodDefinition FindMethodDeep(this TypeDefinition type, string id, bool simple = true)
		{
			MethodDefinition obj = type.FindMethod(id, simple);
			if (obj == null)
			{
				TypeReference baseType = type.BaseType;
				if (baseType == null)
				{
					return null;
				}
				TypeDefinition obj2 = baseType.Resolve();
				if (obj2 == null)
				{
					return null;
				}
				obj = obj2.FindMethodDeep(id, simple);
			}
			return obj;
		}

		public static MethodInfo FindMethod(this Type type, string id, bool simple = true)
		{
			MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
			MethodInfo[] array;
			if (simple && !MultiTargetShims.Contains(id, " ", StringComparison.Ordinal))
			{
				array = methods;
				foreach (MethodInfo methodInfo in array)
				{
					if (methodInfo.GetID(null, null, withType: true, proxyMethod: false, simple: true) == id)
					{
						return methodInfo;
					}
				}
				array = methods;
				foreach (MethodInfo methodInfo2 in array)
				{
					if (methodInfo2.GetID(null, null, withType: false, proxyMethod: false, simple: true) == id)
					{
						return methodInfo2;
					}
				}
			}
			array = methods;
			foreach (MethodInfo methodInfo3 in array)
			{
				if (methodInfo3.GetID(null, null, withType: true, proxyMethod: false, simple: false) == id)
				{
					return methodInfo3;
				}
			}
			array = methods;
			foreach (MethodInfo methodInfo4 in array)
			{
				if (methodInfo4.GetID(null, null, withType: false, proxyMethod: false, simple: false) == id)
				{
					return methodInfo4;
				}
			}
			return null;
		}

		public static MethodInfo FindMethodDeep(this Type type, string id, bool simple = true)
		{
			MethodInfo methodInfo = type.FindMethod(id, simple);
			if ((object)methodInfo == null)
			{
				Type? baseType = type.BaseType;
				if ((object)baseType == null)
				{
					return null;
				}
				methodInfo = baseType.FindMethodDeep(id, simple);
			}
			return methodInfo;
		}

		public static PropertyDefinition FindProperty(this TypeDefinition type, string name)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			Enumerator<PropertyDefinition> enumerator = type.Properties.GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					PropertyDefinition current = enumerator.Current;
					if (((MemberReference)current).Name == name)
					{
						return current;
					}
				}
			}
			finally
			{
				((IDisposable)enumerator).Dispose();
			}
			return null;
		}

		public static PropertyDefinition FindPropertyDeep(this TypeDefinition type, string name)
		{
			PropertyDefinition obj = type.FindProperty(name);
			if (obj == null)
			{
				TypeReference baseType = type.BaseType;
				if (baseType == null)
				{
					return null;
				}
				TypeDefinition obj2 = baseType.Resolve();
				if (obj2 == null)
				{
					return null;
				}
				obj = obj2.FindPropertyDeep(name);
			}
			return obj;
		}

		public static FieldDefinition FindField(this TypeDefinition type, string name)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			Enumerator<FieldDefinition> enumerator = type.Fields.GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					FieldDefinition current = enumerator.Current;
					if (((MemberReference)current).Name == name)
					{
						return current;
					}
				}
			}
			finally
			{
				((IDisposable)enumerator).Dispose();
			}
			return null;
		}

		public static FieldDefinition FindFieldDeep(this TypeDefinition type, string name)
		{
			FieldDefinition obj = type.FindField(name);
			if (obj == null)
			{
				TypeReference baseType = type.BaseType;
				if (baseType == null)
				{
					return null;
				}
				TypeDefinition obj2 = baseType.Resolve();
				if (obj2 == null)
				{
					return null;
				}
				obj = obj2.FindFieldDeep(name);
			}
			return obj;
		}

		public static EventDefinition FindEvent(this TypeDefinition type, string name)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			Enumerator<EventDefinition> enumerator = type.Events.GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					EventDefinition current = enumerator.Current;
					if (((MemberReference)current).Name == name)
					{
						return current;
					}
				}
			}
			finally
			{
				((IDisposable)enumerator).Dispose();
			}
			return null;
		}

		public static EventDefinition FindEventDeep(this TypeDefinition type, string name)
		{
			EventDefinition obj = type.FindEvent(name);
			if (obj == null)
			{
				TypeReference baseType = type.BaseType;
				if (baseType == null)
				{
					return null;
				}
				TypeDefinition obj2 = baseType.Resolve();
				if (obj2 == null)
				{
					return null;
				}
				obj = obj2.FindEventDeep(name);
			}
			return obj;
		}

		public static string GetID(this MethodReference method, string name = null, string type = null, bool withType = true, bool simple = false)
		{
			StringBuilder stringBuilder = new StringBuilder();
			if (simple)
			{
				if (withType && (type != null || ((MemberReference)method).DeclaringType != null))
				{
					stringBuilder.Append(type ?? ((MemberReference)(object)((MemberReference)method).DeclaringType).GetPatchFullName()).Append("::");
				}
				stringBuilder.Append(name ?? ((MemberReference)method).Name);
				return stringBuilder.ToString();
			}
			stringBuilder.Append(((MemberReference)(object)method.ReturnType).GetPatchFullName()).Append(" ");
			if (withType && (type != null || ((MemberReference)method).DeclaringType != null))
			{
				stringBuilder.Append(type ?? ((MemberReference)(object)((MemberReference)method).DeclaringType).GetPatchFullName()).Append("::");
			}
			stringBuilder.Append(name ?? ((MemberReference)method).Name);
			GenericInstanceMethod val = (GenericInstanceMethod)(object)((method is GenericInstanceMethod) ? method : null);
			if (val != null && val.GenericArguments.Count != 0)
			{
				stringBuilder.Append("<");
				Collection<TypeReference> genericArguments = val.GenericArguments;
				for (int i = 0; i < genericArguments.Count; i++)
				{
					if (i > 0)
					{
						stringBuilder.Append(",");
					}
					stringBuilder.Append(((MemberReference)(object)genericArguments[i]).GetPatchFullName());
				}
				stringBuilder.Append(">");
			}
			else if (method.GenericParameters.Count != 0)
			{
				stringBuilder.Append("<");
				Collection<GenericParameter> genericParameters = method.GenericParameters;
				for (int j = 0; j < genericParameters.Count; j++)
				{
					if (j > 0)
					{
						stringBuilder.Append(",");
					}
					stringBuilder.Append(((MemberReference)genericParameters[j]).Name);
				}
				stringBuilder.Append(">");
			}
			stringBuilder.Append("(");
			if (method.HasParameters)
			{
				Collection<ParameterDefinition> parameters = method.Parameters;
				for (int k = 0; k < parameters.Count; k++)
				{
					ParameterDefinition val2 = parameters[k];
					if (k > 0)
					{
						stringBuilder.Append(",");
					}
					if (((ParameterReference)val2).ParameterType.IsSentinel)
					{
						stringBuilder.Append("...,");
					}
					stringBuilder.Append(((MemberReference)(object)((ParameterReference)val2).ParameterType).GetPatchFullName());
				}
			}
			stringBuilder.Append(")");
			return stringBuilder.ToString();
		}

		public static string GetID(this CallSite method)
		{
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.Append(((MemberReference)(object)method.ReturnType).GetPatchFullName()).Append(" ");
			stringBuilder.Append("(");
			if (method.HasParameters)
			{
				Collection<ParameterDefinition> parameters = method.Parameters;
				for (int i = 0; i < parameters.Count; i++)
				{
					ParameterDefinition val = parameters[i];
					if (i > 0)
					{
						stringBuilder.Append(",");
					}
					if (((ParameterReference)val).ParameterType.IsSentinel)
					{
						stringBuilder.Append("...,");
					}
					stringBuilder.Append(((MemberReference)(object)((ParameterReference)val).ParameterType).GetPatchFullName());
				}
			}
			stringBuilder.Append(")");
			return stringBuilder.ToString();
		}

		public static string GetID(this MethodBase method, string name = null, string type = null, bool withType = true, bool proxyMethod = false, bool simple = false)
		{
			while (method is MethodInfo && method.IsGenericMethod && !method.IsGenericMethodDefinition)
			{
				method = ((MethodInfo)method).GetGenericMethodDefinition();
			}
			StringBuilder stringBuilder = new StringBuilder();
			if (simple)
			{
				if (withType && (type != null || method.DeclaringType != null))
				{
					stringBuilder.Append(type ?? method.DeclaringType.FullName).Append("::");
				}
				stringBuilder.Append(name ?? method.Name);
				return stringBuilder.ToString();
			}
			stringBuilder.Append((method as MethodInfo)?.ReturnType?.FullName ?? "System.Void").Append(" ");
			if (withType && (type != null || method.DeclaringType != null))
			{
				stringBuilder.Append(type ?? MultiTargetShims.Replace(method.DeclaringType.FullName, "+", "/", StringComparison.Ordinal)).Append("::");
			}
			stringBuilder.Append(name ?? method.Name);
			if (method.ContainsGenericParameters)
			{
				stringBuilder.Append("<");
				Type[] genericArguments = method.GetGenericArguments();
				for (int i = 0; i < genericArguments.Length; i++)
				{
					if (i > 0)
					{
						stringBuilder.Append(",");
					}
					stringBuilder.Append(genericArguments[i].Name);
				}
				stringBuilder.Append(">");
			}
			stringBuilder.Append("(");
			ParameterInfo[] parameters = method.GetParameters();
			for (int j = (proxyMethod ? 1 : 0); j < parameters.Length; j++)
			{
				ParameterInfo parameterInfo = parameters[j];
				if (j > (proxyMethod ? 1 : 0))
				{
					stringBuilder.Append(",");
				}
				bool flag;
				try
				{
					flag = CustomAttributeExtensions.IsDefined(parameterInfo, t_ParamArrayAttribute, inherit: false);
				}
				catch (NotSupportedException)
				{
					flag = false;
				}
				if (flag)
				{
					stringBuilder.Append("...,");
				}
				stringBuilder.Append(parameterInfo.ParameterType.FullName);
			}
			stringBuilder.Append(")");
			return stringBuilder.ToString();
		}

		public static string GetPatchName(this MemberReference mr)
		{
			MemberReference obj = ((mr is ICustomAttributeProvider) ? mr : null);
			return ((obj != null) ? ((ICustomAttributeProvider)(object)obj).GetPatchName() : null) ?? mr.Name;
		}

		public static string GetPatchFullName(this MemberReference mr)
		{
			MemberReference obj = ((mr is ICustomAttributeProvider) ? mr : null);
			return ((obj != null) ? ((ICustomAttributeProvider)(object)obj).GetPatchFullName(mr) : null) ?? mr.FullName;
		}

		private static string GetPatchName(this ICustomAttributeProvider cap)
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			CustomAttribute customAttribute = cap.GetCustomAttribute("MonoMod.MonoModPatch");
			string text;
			if (customAttribute != null)
			{
				CustomAttributeArgument val = customAttribute.ConstructorArguments[0];
				text = (string)((CustomAttributeArgument)(ref val)).Value;
				int num = text.LastIndexOf('.');
				if (num != -1 && num != text.Length - 1)
				{
					text = text.Substring(num + 1);
				}
				return text;
			}
			text = ((MemberReference)cap).Name;
			if (!text.StartsWith("patch_", StringComparison.Ordinal))
			{
				return text;
			}
			return text.Substring(6);
		}

		private static string GetPatchFullName(this ICustomAttributeProvider cap, MemberReference mr)
		{
			//IL_003a: 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_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Expected O, but got Unknown
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: Expected O, but got Unknown
			//IL_0247: Unknown result type (might be due to invalid IL or missing references)
			//IL_027d: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ae: Expected O, but got Unknown
			//IL_0323: Unknown result type (might be due to invalid IL or missing references)
			//IL_032a: Expected O, but got Unknown
			//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
			TypeReference val = (TypeReference)(object)((cap is TypeReference) ? cap : null);
			if (val != null)
			{
				CustomAttribute customAttribute = cap.GetCustomAttribute("MonoMod.MonoModPatch");
				string text;
				if (customAttribute != null)
				{
					CustomAttributeArgument val2 = customAttribute.ConstructorArguments[0];
					text = (string)((CustomAttributeArgument)(ref val2)).Value;
				}
				else
				{
					text = ((MemberReference)cap).Name;
					text = (text.StartsWith("patch_", StringComparison.Ordinal) ? text.Substring(6) : text);
				}
				if (text.StartsWith("global::", StringComparison.Ordinal))
				{
					text = text.Substring(8);
				}
				else if (!MultiTargetShims.Contains(text, ".", StringComparison.Ordinal) && !MultiTargetShims.Contains(text, "/", StringComparison.Ordinal))
				{
					if (!string.IsNullOrEmpty(val.Namespace))
					{
						text = val.Namespace + "." + text;
					}
					else if (val.IsNested)
					{
						text = ((MemberReference)(object)((MemberReference)val).DeclaringType).GetPatchFullName() + "/" + text;
					}
				}
				if (mr is TypeSpecification)
				{
					List<TypeSpecification> list = new List<TypeSpecification>();
					TypeSpecification val3 = (TypeSpecification)mr;
					TypeReference elementType;
					do
					{
						list.Add(val3);
						elementType = val3.ElementType;
					}
					while ((val3 = (TypeSpecification)(object)((elementType is TypeSpecification) ? elementType : null)) != null);
					StringBuilder stringBuilder = new StringBuilder(text.Length + list.Count * 4);
					stringBuilder.Append(text);
					for (int num = list.Count - 1; num > -1; num--)
					{
						val3 = list[num];
						if (((TypeReference)val3).IsByReference)
						{
							stringBuilder.Append("&");
						}
						else if (((TypeReference)val3).IsPointer)
						{
							stringBuilder.Append("*");
						}
						else if (!((TypeReference)val3).IsPinned && !((TypeReference)val3).IsSentinel)
						{
							if (((TypeReference)val3).IsArray)
							{
								ArrayType val4 = (ArrayType)val3;
								if (val4.IsVector)
								{
									stringBuilder.Append("[]");
								}
								else
								{
									stringBuilder.Append("[");
									for (int i = 0; i < val4.Dimensions.Count; i++)
									{
										if (i > 0)
										{
											stringBuilder.Append(",");
										}
										ArrayDimension val5 = val4.Dimensions[i];
										stringBuilder.Append(((object)(ArrayDimension)(ref val5)).ToString());
									}
									stringBuilder.Append("]");
								}
							}
							else if (((TypeReference)val3).IsRequiredModifier)
							{
								stringBuilder.Append("modreq(").Append(((RequiredModifierType)val3).ModifierType).Append(")");
							}
							else if (((TypeReference)val3).IsOptionalModifier)
							{
								stringBuilder.Append("modopt(").Append(((OptionalModifierType)val3).ModifierType).Append(")");
							}
							else if (((TypeReference)val3).IsGenericInstance)
							{
								GenericInstanceType val6 = (GenericInstanceType)val3;
								stringBuilder.Append("<");
								for (int j = 0; j < val6.GenericArguments.Count; j++)
								{
									if (j > 0)
									{
										stringBuilder.Append(",");
									}
									stringBuilder.Append(((MemberReference)(object)val6.GenericArguments[j]).GetPatchFullName());
								}
								stringBuilder.Append(">");
							}
							else
							{
								if (!((TypeReference)val3).IsFunctionPointer)
								{
									throw new NotSupportedException($"MonoMod can't handle TypeSpecification: {((MemberReference)val).FullName} ({((object)val).GetType()})");
								}
								FunctionPointerType val7 = (FunctionPointerType)val3;
								stringBuilder.Append(" ").Append(((MemberReference)(object)val7.ReturnType).GetPatchFullName()).Append(" *(");
								if (val7.HasParameters)
								{
									for (int k = 0; k < val7.Parameters.Count; k++)
									{
										ParameterDefinition val8 = val7.Parameters[k];
										if (k > 0)
										{
											stringBuilder.Append(",");
										}
										if (((ParameterReference)val8).ParameterType.IsSentinel)
										{
											stringBuilder.Append("...,");
										}
										stringBuilder.Append(((MemberReference)((ParameterReference)val8).ParameterType).FullName);
									}
								}
								stringBuilder.Append(")");
							}
						}
					}
					text = stringBuilder.ToString();
				}
				return text;
			}
			FieldReference val9 = (FieldReference)(object)((cap is FieldReference) ? cap : null);
			if (val9 != null)
			{
				return ((MemberReference)(object)val9.FieldType).GetPatchFullName() + " " + ((MemberReference)(object)((MemberReference)val9).DeclaringType).GetPatchFullName() + "::" + cap.GetPatchName();
			}
			if (cap is MethodReference)
			{
				throw new InvalidOperationException("GetPatchFullName not supported on MethodReferences - use GetID instead");
			}
			throw new InvalidOperationException($"GetPatchFullName not supported on type {((object)cap).GetType()}");
		}

		public static MethodDefinition Clone(this MethodDefinition o, MethodDefinition c = null)
		{
			//IL_002f: 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_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			//IL_0078: 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_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			if (o == null)
			{
				return null;
			}
			if (c == null)
			{
				c = new MethodDefinition(((MemberReference)o).Name, o.Attributes, ((MethodReference)o).ReturnType);
			}
			((MemberReference)c).Name = ((MemberReference)o).Name;
			c.Attributes = o.Attributes;
			((MethodReference)c).ReturnType = ((MethodReference)o).ReturnType;
			c.DeclaringType = o.DeclaringType;
			((MemberReference)c).MetadataToken = ((MemberReference)c).MetadataToken;
			c.Body = o.Body?.Clone(c);
			c.Attributes = o.Attributes;
			c.ImplAttributes = o.ImplAttributes;
			c.PInvokeInfo = o.PInvokeInfo;
			c.IsPreserveSig = o.IsPreserveSig;
			c.IsPInvokeImpl = o.IsPInvokeImpl;
			Enumerator<GenericParameter> enumerator = ((MethodReference)o).GenericParameters.GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					GenericParameter current = enumerator.Current;
					((MethodReference)c).GenericParameters.Add(current.Clone());
				}
			}
			finally
			{
				((IDisposable)enumerator).Dispose();
			}
			Enumerator<ParameterDefinition> enumerator2 = ((MethodReference)o).Parameters.GetEnumerator();
			try
			{
				while (enumerator2.MoveNext())
				{
					ParameterDefinition current2 = enumerator2.Current;
					((MethodReference)c).Parameters.Add(current2.Clone());
				}
			}
			finally
			{
				((IDisposable)enumerator2).Dispose();
			}
			Enumerator<CustomAttribute> enumerator3 = o.CustomAttributes.GetEnumerator();
			try
			{
				while (enumerator3.MoveNext())
				{
					CustomAttribute current3 = enumerator3.Current;
					c.CustomAttributes.Add(current3.Clone());
				}
			}
			finally
			{
				((IDisposable)enumerator3).Dispose();
			}
			Enumerator<MethodReference> enumerator4 = o.Overrides.GetEnumerator();
			try
			{
				while (enumerator4.MoveNext())
				{
					MethodReference current4 = enumerator4.Current;
					c.Overrides.Add(current4);
				}
			}
			finally
			{
				((IDisposable)enumerator4).Dispose();
			}
			if (c.Body != null)
			{
				Enumerator<Instruction> enumerator5 = c.Body.Instructions.GetEnumerator();
				try
				{
					while (enumerator5.MoveNext())
					{
						Instruction current5 = enumerator5.Current;
						object operand = current5.Operand;
						GenericParameter val = (GenericParameter)((operand is GenericParameter) ? operand : null);
						int num;
						if (val != null && (num = ((MethodReference)o).GenericParameters.IndexOf(val)) != -1)
						{
							current5.Operand = ((MethodReference)c).GenericParameters[num];
							continue;
						}
						object operand2 = current5.Operand;
						ParameterDefinition val2 = (ParameterDefinition)((operand2 is ParameterDefinition) ? operand2 : null);
						if (val2 != null && (num = ((MethodReference)o).Parameters.IndexOf(val2)) != -1)
						{
							current5.Operand = ((MethodReference)c).Parameters[num];
						}
					}
				}
				finally
				{
					((IDisposable)enumerator5).Dispose();
				}
			}
			return c;
		}

		public static MethodBody Clone(this MethodBody bo, MethodDefinition m)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			//IL_005b: 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_00b4: Unknown result type (might be due to invalid IL or missing references)
			if (bo == null)
			{
				return null;
			}
			MethodBody bc = new MethodBody(m);
			bc.MaxStackSize = bo.MaxStackSize;
			bc.InitLocals = bo.InitLocals;
			bc.LocalVarToken = bo.LocalVarToken;
			bc.Instructions.AddRange(((IEnumerable<Instruction>)bo.Instructions).Select(delegate(Instruction o)
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				//IL_000c: Unknown result type (might be due to invalid IL or missing references)
				Instruction obj = Instruction.Create(OpCodes.Nop);
				obj.OpCode = o.OpCode;
				obj.Operand = o.Operand;
				obj.Offset = o.Offset;
				return obj;
			}));
			Enumerator<Instruction> enumerator = bc.Instructions.GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					Instruction current = enumerator.Current;
					object operand = current.Operand;
					Instruction val = (Instruction)((operand is Instruction) ? operand : null);
					if (val != null)
					{
						current.Operand = bc.Instructions[bo.Instructions.IndexOf(val)];
					}
					else if (current.Operand is Instruction[] source)
					{
						current.Operand = source.Select((Instruction i) => bc.Instructions[bo.Instructions.IndexOf(i)]).ToArray();
					}
				}
			}
			finally
			{
				((IDisposable)enumerator).Dispose();
			}
			bc.ExceptionHandlers.AddRange(((IEnumerable<ExceptionHandler>)bo.ExceptionHandlers).Select((Func<ExceptionHandler, ExceptionHandler>)((ExceptionHandler o) => new ExceptionHandler(o.HandlerType)
			{
				TryStart = ((o.TryStart == null) ? null : bc.Instructions[bo.Instructions.IndexOf(o.TryStart)]),
				TryEnd = ((o.TryEnd == null) ? null : bc.Instructions[bo.Instructions.IndexOf(o.TryEnd)]),
				FilterStart = ((o.FilterStart == null) ? null : bc.Instructions[bo.Instructions.IndexOf(o.FilterStart)]),
				HandlerStart = ((o.HandlerStart == null) ? null : bc.Instructions[bo.Instructions.IndexOf(o.HandlerStart)]),
				HandlerEnd = ((o.HandlerEnd == null) ? null : bc.Instructions[bo.Instructions.IndexOf(o.HandlerEnd)]),
				CatchType = o.CatchType
			})));
			bc.Variables.AddRange(((IEnumerable<VariableDefinition>)bo.Variables).Select((Func<VariableDefinition, VariableDefinition>)((VariableDefinition o) => new VariableDefinition(((VariableReference)o).VariableType))));
			m.CustomDebugInformations.AddRange((IEnumerable<CustomDebugInformation>)bo.Method.CustomDebugInformations);
			m.DebugInformation.SequencePoints.AddRange(((IEnumerable<SequencePoint>)bo.Method.DebugInformation.SequencePoints).Select((Func<SequencePoint, SequencePoint>)((SequencePoint o) => new SequencePoint(((IEnumerable<Instruction>)bc.Instructions).FirstOrDefault((Func<Instruction, bool>)((Instruction i) => i.Offset == o.Offset)), o.Document)
			{
				StartLine = o.StartLine,
				StartColumn = o.StartColumn,
				EndLine = o.EndLine,
				EndColumn = o.EndColumn
			})));
			return bc;
		}

		public static GenericParameter Update(this GenericParameter param, int position, GenericParameterType type)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			f_GenericParameter_position.SetValue(param, position);
			f_GenericParameter_type.SetValue(param, type);
			return param;
		}

		public static GenericParameter ResolveGenericParameter(this IGenericParameterProvider provider, GenericParameter orig)
		{
			//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_0009: 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_0027: Expected O, but got Unknown
			if (provider is GenericParameter && ((MemberReference)(GenericParameter)provider).Name

BepInExPack/BepInEx/core/SemanticVersioning.dll

Decompiled a month ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Text.RegularExpressions;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SemanticVersioning")]
[assembly: AssemblyTrademark("")]
[assembly: InternalsVisibleTo("SemanticVersioning.Tests, PublicKey=002400000480000094000000060200000024000052534131000400000100010019351d4288017757df1b69b4d0da9a775e6eec498ec93d209d6db4d62e9962476c8da01545cc47335cdc39ba803f4db368ce5f2fdd6cd395196f3328f9039dccdeb3c0f9aece7b8751cd3bc2cb2297d4f463a376eff61b7295b96af9b9faf3eef6005dc967a7a97431cc42cff72e60f05797f3e16186f8fbaf26074e96a2b5e1")]
[assembly: ComVisible(false)]
[assembly: Guid("a3ff1b6d-68bb-4a0a-a487-858aaa8e3573")]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = "")]
[assembly: AssemblyCopyright("Copyright 2016 Adam Reeve")]
[assembly: AssemblyDescription("This library implements the Semantic Versioning 2.0.0 specification and the version range specification used by npm.")]
[assembly: AssemblyFileVersion("2.0.2.0")]
[assembly: AssemblyInformationalVersion("2.0.2")]
[assembly: AssemblyTitle("SemanticVersioning")]
[assembly: AssemblyVersion("2.0.2.0")]
namespace SemanticVersioning;

internal class Comparator : IEquatable<Comparator>
{
	public enum Operator
	{
		Equal,
		LessThan,
		LessThanOrEqual,
		GreaterThan,
		GreaterThanOrEqual,
		GreaterThanOrEqualIncludingPrereleases,
		LessThanExcludingPrereleases
	}

	public readonly Operator ComparatorType;

	public readonly Version Version;

	private const string pattern = "\n            \\s*\n            ([=<>]*)                # Comparator type (can be empty)\n            \\s*\n            ([0-9a-zA-Z\\-\\+\\.\\*]+)  # Version (potentially partial version)\n            \\s*\n            ";

	public Comparator(string input)
	{
		Match match = new Regex(string.Format("^{0}$", "\n            \\s*\n            ([=<>]*)                # Comparator type (can be empty)\n            \\s*\n            ([0-9a-zA-Z\\-\\+\\.\\*]+)  # Version (potentially partial version)\n            \\s*\n            "), RegexOptions.IgnorePatternWhitespace).Match(input);
		if (!match.Success)
		{
			throw new ArgumentException($"Invalid comparator string: {input}");
		}
		ComparatorType = ParseComparatorType(match.Groups[1].Value);
		PartialVersion partialVersion = new PartialVersion(match.Groups[2].Value);
		if (!partialVersion.IsFull())
		{
			switch (ComparatorType)
			{
			case Operator.LessThanOrEqual:
				ComparatorType = Operator.LessThan;
				if (!partialVersion.Major.HasValue)
				{
					ComparatorType = Operator.GreaterThanOrEqual;
					Version = new Version(0, 0, 0);
				}
				else if (!partialVersion.Minor.HasValue)
				{
					Version = new Version(partialVersion.Major.Value + 1, 0, 0);
				}
				else
				{
					Version = new Version(partialVersion.Major.Value, partialVersion.Minor.Value + 1, 0);
				}
				break;
			case Operator.GreaterThan:
				ComparatorType = Operator.GreaterThanOrEqualIncludingPrereleases;
				if (!partialVersion.Major.HasValue)
				{
					ComparatorType = Operator.LessThan;
					Version = new Version(0, 0, 0);
				}
				else if (!partialVersion.Minor.HasValue)
				{
					Version = new Version(partialVersion.Major.Value + 1, 0, 0);
				}
				else
				{
					Version = new Version(partialVersion.Major.Value, partialVersion.Minor.Value + 1, 0);
				}
				break;
			case Operator.LessThan:
				ComparatorType = Operator.LessThanExcludingPrereleases;
				Version = partialVersion.ToZeroVersion();
				break;
			case Operator.GreaterThanOrEqual:
				ComparatorType = Operator.GreaterThanOrEqualIncludingPrereleases;
				Version = partialVersion.ToZeroVersion();
				break;
			default:
				Version = partialVersion.ToZeroVersion();
				break;
			}
		}
		else
		{
			Version = partialVersion.ToZeroVersion();
		}
	}

	public Comparator(Operator comparatorType, Version comparatorVersion)
	{
		if (comparatorVersion == null)
		{
			throw new NullReferenceException("Null comparator version");
		}
		ComparatorType = comparatorType;
		Version = comparatorVersion;
	}

	public static Tuple<int, Comparator> TryParse(string input)
	{
		Match match = new Regex(string.Format("^{0}", "\n            \\s*\n            ([=<>]*)                # Comparator type (can be empty)\n            \\s*\n            ([0-9a-zA-Z\\-\\+\\.\\*]+)  # Version (potentially partial version)\n            \\s*\n            "), RegexOptions.IgnorePatternWhitespace).Match(input);
		if (!match.Success)
		{
			return null;
		}
		return Tuple.Create(match.Length, new Comparator(match.Value));
	}

	private static Operator ParseComparatorType(string input)
	{
		if (input != null)
		{
			if (input == null || input.Length != 0)
			{
				switch (input)
				{
				case "=":
					break;
				case "<":
					return Operator.LessThan;
				case "<=":
					return Operator.LessThanOrEqual;
				case ">":
					return Operator.GreaterThan;
				case ">=":
					return Operator.GreaterThanOrEqual;
				default:
					goto IL_005b;
				}
			}
			return Operator.Equal;
		}
		goto IL_005b;
		IL_005b:
		throw new ArgumentException($"Invalid comparator type: {input}");
	}

	public bool IsSatisfied(Version version)
	{
		switch (ComparatorType)
		{
		case Operator.Equal:
			return version == Version;
		case Operator.LessThan:
			return version < Version;
		case Operator.LessThanOrEqual:
			return version <= Version;
		case Operator.GreaterThan:
			return version > Version;
		case Operator.GreaterThanOrEqual:
			return version >= Version;
		case Operator.GreaterThanOrEqualIncludingPrereleases:
			if (!(version >= Version))
			{
				if (version.IsPreRelease)
				{
					return version.BaseVersion() == Version;
				}
				return false;
			}
			return true;
		case Operator.LessThanExcludingPrereleases:
			if (version < Version)
			{
				if (version.IsPreRelease)
				{
					return !(version.BaseVersion() == Version);
				}
				return true;
			}
			return false;
		default:
			throw new InvalidOperationException("Comparator type not recognised.");
		}
	}

	public bool Intersects(Comparator other)
	{
		Func<Comparator, bool> func = (Comparator c) => c.ComparatorType == Operator.GreaterThan || c.ComparatorType == Operator.GreaterThanOrEqual || c.ComparatorType == Operator.GreaterThanOrEqualIncludingPrereleases;
		Func<Comparator, bool> func2 = (Comparator c) => c.ComparatorType == Operator.LessThan || c.ComparatorType == Operator.LessThanOrEqual || c.ComparatorType == Operator.LessThanExcludingPrereleases;
		Func<Comparator, bool> func3 = (Comparator c) => c.ComparatorType == Operator.GreaterThanOrEqual || c.ComparatorType == Operator.GreaterThanOrEqualIncludingPrereleases || c.ComparatorType == Operator.Equal || c.ComparatorType == Operator.LessThanOrEqual;
		if (Version > other.Version && (func2(this) || func(other)))
		{
			return true;
		}
		if (Version < other.Version && (func(this) || func2(other)))
		{
			return true;
		}
		if (Version == other.Version && ((func3(this) && func3(other)) || (func2(this) && func2(other)) || (func(this) && func(other))))
		{
			return true;
		}
		return false;
	}

	public override string ToString()
	{
		string text = null;
		switch (ComparatorType)
		{
		case Operator.Equal:
			text = "=";
			break;
		case Operator.LessThan:
		case Operator.LessThanExcludingPrereleases:
			text = "<";
			break;
		case Operator.LessThanOrEqual:
			text = "<=";
			break;
		case Operator.GreaterThan:
			text = ">";
			break;
		case Operator.GreaterThanOrEqual:
		case Operator.GreaterThanOrEqualIncludingPrereleases:
			text = ">=";
			break;
		default:
			throw new InvalidOperationException("Comparator type not recognised.");
		}
		return $"{text}{Version}";
	}

	public bool Equals(Comparator other)
	{
		if (other == null)
		{
			return false;
		}
		if (ComparatorType == other.ComparatorType)
		{
			return Version == other.Version;
		}
		return false;
	}

	public override bool Equals(object other)
	{
		return Equals(other as Comparator);
	}

	public override int GetHashCode()
	{
		return new { ComparatorType, Version }.GetHashCode();
	}
}
internal class ComparatorSet : IEquatable<ComparatorSet>
{
	private readonly List<Comparator> _comparators;

	public ComparatorSet(string spec)
	{
		_comparators = new List<Comparator>();
		spec = spec.Trim();
		if (spec == "")
		{
			spec = "*";
		}
		int num = 0;
		int length = spec.Length;
		while (num < length)
		{
			int num2 = num;
			Func<string, Tuple<int, Comparator[]>>[] array = new Func<string, Tuple<int, Comparator[]>>[4]
			{
				Desugarer.HyphenRange,
				Desugarer.TildeRange,
				Desugarer.CaretRange,
				Desugarer.StarRange
			};
			for (int i = 0; i < array.Length; i++)
			{
				Tuple<int, Comparator[]> tuple = array[i](spec.Substring(num));
				if (tuple != null)
				{
					num += tuple.Item1;
					_comparators.AddRange(tuple.Item2);
				}
			}
			Tuple<int, Comparator> tuple2 = Comparator.TryParse(spec.Substring(num));
			if (tuple2 != null)
			{
				num += tuple2.Item1;
				_comparators.Add(tuple2.Item2);
			}
			if (num == num2)
			{
				throw new ArgumentException($"Invalid range specification: \"{spec}\"");
			}
		}
	}

	private ComparatorSet(IEnumerable<Comparator> comparators)
	{
		_comparators = comparators.ToList();
	}

	public bool IsSatisfied(Version version, bool includePrerelease = false)
	{
		bool flag = _comparators.All((Comparator c) => c.IsSatisfied(version));
		if (version.PreRelease != null && !includePrerelease)
		{
			if (flag)
			{
				return _comparators.Any((Comparator c) => c.Version.PreRelease != null && c.Version.BaseVersion() == version.BaseVersion());
			}
			return false;
		}
		return flag;
	}

	public ComparatorSet Intersect(ComparatorSet other)
	{
		Func<Comparator, bool> predicate = (Comparator c) => c.ComparatorType == Comparator.Operator.GreaterThan || c.ComparatorType == Comparator.Operator.GreaterThanOrEqual || c.ComparatorType == Comparator.Operator.GreaterThanOrEqualIncludingPrereleases;
		Func<Comparator, bool> predicate2 = (Comparator c) => c.ComparatorType == Comparator.Operator.LessThan || c.ComparatorType == Comparator.Operator.LessThanOrEqual || c.ComparatorType == Comparator.Operator.LessThanExcludingPrereleases;
		Func<Comparator.Operator, int> operatorOrdering = (Comparator.Operator op) => op switch
		{
			Comparator.Operator.LessThanExcludingPrereleases => 0, 
			Comparator.Operator.LessThan => 1, 
			Comparator.Operator.LessThanOrEqual => 2, 
			Comparator.Operator.GreaterThan => 0, 
			Comparator.Operator.GreaterThanOrEqual => 1, 
			Comparator.Operator.GreaterThanOrEqualIncludingPrereleases => 2, 
			_ => throw new ArgumentOutOfRangeException("op", op, "Unexpected comparator operator"), 
		};
		Comparator comparator = (from c in _comparators.Concat(other._comparators).Where(predicate)
			orderby c.Version descending, operatorOrdering(c.ComparatorType)
			select c).FirstOrDefault();
		Comparator comparator2 = (from c in _comparators.Concat(other._comparators).Where(predicate2)
			orderby c.Version, operatorOrdering(c.ComparatorType)
			select c).FirstOrDefault();
		if (comparator != null && comparator2 != null && !comparator.Intersects(comparator2))
		{
			return null;
		}
		List<Version> equalityVersions = (from c in _comparators.Concat(other._comparators)
			where c.ComparatorType == Comparator.Operator.Equal
			select c.Version).ToList();
		if (equalityVersions.Count > 1 && equalityVersions.Any((Version v) => v != equalityVersions[0]))
		{
			return null;
		}
		if (equalityVersions.Count > 0)
		{
			if (comparator != null && !comparator.IsSatisfied(equalityVersions[0]))
			{
				return null;
			}
			if (comparator2 != null && !comparator2.IsSatisfied(equalityVersions[0]))
			{
				return null;
			}
			return new ComparatorSet(new List<Comparator>
			{
				new Comparator(Comparator.Operator.Equal, equalityVersions[0])
			});
		}
		List<Comparator> list = new List<Comparator>();
		if (comparator != null)
		{
			list.Add(comparator);
		}
		if (comparator2 != null)
		{
			list.Add(comparator2);
		}
		if (list.Count <= 0)
		{
			return null;
		}
		return new ComparatorSet(list);
	}

	public bool Equals(ComparatorSet other)
	{
		if (other == null)
		{
			return false;
		}
		return new HashSet<Comparator>(_comparators).SetEquals(other._comparators);
	}

	public override bool Equals(object other)
	{
		return Equals(other as ComparatorSet);
	}

	public override string ToString()
	{
		return string.Join(" ", _comparators.Select((Comparator c) => c.ToString()).ToArray());
	}

	public override int GetHashCode()
	{
		return _comparators.Aggregate(0, (int accum, Comparator next) => accum ^ next.GetHashCode());
	}
}
internal static class Desugarer
{
	private const string versionChars = "[0-9a-zA-Z\\-\\+\\.\\*]";

	public static Tuple<int, Comparator[]> TildeRange(string spec)
	{
		Match match = new Regex(string.Format("^\\s*~\\s*({0}+)\\s*", "[0-9a-zA-Z\\-\\+\\.\\*]")).Match(spec);
		if (!match.Success)
		{
			return null;
		}
		Version version = null;
		Version version2 = null;
		PartialVersion partialVersion = new PartialVersion(match.Groups[1].Value);
		if (partialVersion.Minor.HasValue)
		{
			version = partialVersion.ToZeroVersion();
			version2 = new Version(partialVersion.Major.Value, partialVersion.Minor.Value + 1, 0);
		}
		else
		{
			version = partialVersion.ToZeroVersion();
			version2 = new Version(partialVersion.Major.Value + 1, 0, 0);
		}
		return Tuple.Create(match.Length, MinMaxComparators(version, version2));
	}

	public static Tuple<int, Comparator[]> CaretRange(string spec)
	{
		Match match = new Regex(string.Format("^\\s*\\^\\s*({0}+)\\s*", "[0-9a-zA-Z\\-\\+\\.\\*]")).Match(spec);
		if (!match.Success)
		{
			return null;
		}
		Version version = null;
		Version version2 = null;
		PartialVersion partialVersion = new PartialVersion(match.Groups[1].Value);
		if (partialVersion.Major.Value > 0)
		{
			version = partialVersion.ToZeroVersion();
			version2 = new Version(partialVersion.Major.Value + 1, 0, 0);
		}
		else if (!partialVersion.Minor.HasValue)
		{
			version = partialVersion.ToZeroVersion();
			version2 = new Version(partialVersion.Major.Value + 1, 0, 0);
		}
		else if (!partialVersion.Patch.HasValue)
		{
			version = partialVersion.ToZeroVersion();
			version2 = new Version(0, partialVersion.Minor.Value + 1, 0);
		}
		else if (partialVersion.Minor > 0)
		{
			version = partialVersion.ToZeroVersion();
			version2 = new Version(0, partialVersion.Minor.Value + 1, 0);
		}
		else
		{
			version = partialVersion.ToZeroVersion();
			version2 = new Version(0, 0, partialVersion.Patch.Value + 1);
		}
		return Tuple.Create(match.Length, MinMaxComparators(version, version2, Comparator.Operator.GreaterThanOrEqualIncludingPrereleases));
	}

	public static Tuple<int, Comparator[]> HyphenRange(string spec)
	{
		Match match = new Regex(string.Format("^\\s*({0}+)\\s+\\-\\s+({0}+)\\s*", "[0-9a-zA-Z\\-\\+\\.\\*]")).Match(spec);
		if (!match.Success)
		{
			return null;
		}
		PartialVersion partialVersion = null;
		PartialVersion partialVersion2 = null;
		try
		{
			partialVersion = new PartialVersion(match.Groups[1].Value);
			partialVersion2 = new PartialVersion(match.Groups[2].Value);
		}
		catch (ArgumentException)
		{
			return null;
		}
		Version minVersion = partialVersion.ToZeroVersion();
		Comparator.Operator maxOperator = (partialVersion2.IsFull() ? Comparator.Operator.LessThanOrEqual : Comparator.Operator.LessThanExcludingPrereleases);
		Version maxVersion = null;
		if (partialVersion2.Major.HasValue)
		{
			maxVersion = ((!partialVersion2.Minor.HasValue) ? new Version(partialVersion2.Major.Value + 1, 0, 0) : (partialVersion2.Patch.HasValue ? partialVersion2.ToZeroVersion() : new Version(partialVersion2.Major.Value, partialVersion2.Minor.Value + 1, 0)));
		}
		return Tuple.Create(match.Length, MinMaxComparators(minVersion, maxVersion, Comparator.Operator.GreaterThanOrEqualIncludingPrereleases, maxOperator));
	}

	public static Tuple<int, Comparator[]> StarRange(string spec)
	{
		Match match = new Regex(string.Format("^\\s*=?\\s*({0}+)\\s*", "[0-9a-zA-Z\\-\\+\\.\\*]")).Match(spec);
		if (!match.Success)
		{
			return null;
		}
		PartialVersion partialVersion = null;
		try
		{
			partialVersion = new PartialVersion(match.Groups[1].Value);
		}
		catch (ArgumentException)
		{
			return null;
		}
		if (partialVersion.IsFull())
		{
			return null;
		}
		Version version = null;
		Version maxVersion = null;
		if (!partialVersion.Major.HasValue)
		{
			version = partialVersion.ToZeroVersion();
		}
		else if (!partialVersion.Minor.HasValue)
		{
			version = partialVersion.ToZeroVersion();
			maxVersion = new Version(partialVersion.Major.Value + 1, 0, 0);
		}
		else
		{
			version = partialVersion.ToZeroVersion();
			maxVersion = new Version(partialVersion.Major.Value, partialVersion.Minor.Value + 1, 0);
		}
		return Tuple.Create(match.Length, MinMaxComparators(version, maxVersion));
	}

	private static Comparator[] MinMaxComparators(Version minVersion, Version maxVersion, Comparator.Operator minOperator = Comparator.Operator.GreaterThanOrEqual, Comparator.Operator maxOperator = Comparator.Operator.LessThanExcludingPrereleases)
	{
		Comparator comparator = new Comparator(minOperator, minVersion);
		if (!(maxVersion == null))
		{
			Comparator comparator2 = new Comparator(maxOperator, maxVersion);
			return new Comparator[2] { comparator, comparator2 };
		}
		return new Comparator[1] { comparator };
	}
}
internal class PartialVersion
{
	private static Regex regex = new Regex("^\n                [v=\\s]*\n                (\\d+|[Xx\\*])                      # major version\n                (\n                    \\.\n                    (\\d+|[Xx\\*])                  # minor version\n                    (\n                        \\.\n                        (\\d+|[Xx\\*])              # patch version\n                        (\\-?([0-9A-Za-z\\-\\.]+))?  # pre-release version\n                        (\\+([0-9A-Za-z\\-\\.]+))?   # build version (ignored)\n                    )?\n                )?\n                $", RegexOptions.IgnorePatternWhitespace);

	public int? Major { get; set; }

	public int? Minor { get; set; }

	public int? Patch { get; set; }

	public string PreRelease { get; set; }

	public PartialVersion(string input)
	{
		string[] source = new string[3] { "X", "x", "*" };
		if (input.Trim() == "")
		{
			return;
		}
		Match match = regex.Match(input);
		if (!match.Success)
		{
			throw new ArgumentException($"Invalid version string: \"{input}\"");
		}
		if (source.Contains(match.Groups[1].Value))
		{
			Major = null;
		}
		else
		{
			Major = int.Parse(match.Groups[1].Value);
		}
		if (match.Groups[2].Success)
		{
			if (source.Contains(match.Groups[3].Value))
			{
				Minor = null;
			}
			else
			{
				Minor = int.Parse(match.Groups[3].Value);
			}
		}
		if (match.Groups[4].Success)
		{
			if (source.Contains(match.Groups[5].Value))
			{
				Patch = null;
			}
			else
			{
				Patch = int.Parse(match.Groups[5].Value);
			}
		}
		if (match.Groups[6].Success)
		{
			PreRelease = match.Groups[7].Value;
		}
	}

	public Version ToZeroVersion()
	{
		return new Version(Major.GetValueOrDefault(), Minor.GetValueOrDefault(), Patch.GetValueOrDefault(), PreRelease);
	}

	public bool IsFull()
	{
		if (Major.HasValue && Minor.HasValue)
		{
			return Patch.HasValue;
		}
		return false;
	}
}
internal static class PreReleaseVersion
{
	private class Identifier
	{
		public bool IsNumeric { get; set; }

		public int IntValue { get; set; }

		public string Value { get; set; }

		public Identifier(string input)
		{
			Value = input;
			SetNumeric();
		}

		public string Clean()
		{
			if (!IsNumeric)
			{
				return Value;
			}
			return IntValue.ToString();
		}

		private void SetNumeric()
		{
			int result;
			bool flag = int.TryParse(Value, out result);
			IsNumeric = flag && result >= 0;
			IntValue = result;
		}
	}

	public static int Compare(string a, string b)
	{
		if (a == null && b == null)
		{
			return 0;
		}
		if (a == null)
		{
			return 1;
		}
		if (b == null)
		{
			return -1;
		}
		foreach (int item in IdentifierComparisons(Identifiers(a), Identifiers(b)))
		{
			if (item != 0)
			{
				return item;
			}
		}
		return 0;
	}

	public static string Clean(string input)
	{
		IEnumerable<string> source = from i in Identifiers(input)
			select i.Clean();
		return string.Join(".", source.ToArray());
	}

	private static IEnumerable<Identifier> Identifiers(string input)
	{
		string[] array = input.Split(new char[1] { '.' });
		foreach (string input2 in array)
		{
			yield return new Identifier(input2);
		}
	}

	private static IEnumerable<int> IdentifierComparisons(IEnumerable<Identifier> aIdentifiers, IEnumerable<Identifier> bIdentifiers)
	{
		foreach (Tuple<Identifier, Identifier> item3 in ZipIdentifiers(aIdentifiers, bIdentifiers))
		{
			Identifier item = item3.Item1;
			Identifier item2 = item3.Item2;
			if (item == item2)
			{
				yield return 0;
			}
			else if (item == null)
			{
				yield return -1;
			}
			else if (item2 == null)
			{
				yield return 1;
			}
			else if (item.IsNumeric && item2.IsNumeric)
			{
				yield return item.IntValue.CompareTo(item2.IntValue);
			}
			else if (!item.IsNumeric && !item2.IsNumeric)
			{
				yield return string.CompareOrdinal(item.Value, item2.Value);
			}
			else if (item.IsNumeric && !item2.IsNumeric)
			{
				yield return -1;
			}
			else
			{
				yield return 1;
			}
		}
	}

	private static IEnumerable<Tuple<Identifier, Identifier>> ZipIdentifiers(IEnumerable<Identifier> first, IEnumerable<Identifier> second)
	{
		using IEnumerator<Identifier> ie1 = first.GetEnumerator();
		using IEnumerator<Identifier> ie2 = second.GetEnumerator();
		while (ie1.MoveNext())
		{
			if (ie2.MoveNext())
			{
				yield return Tuple.Create(ie1.Current, ie2.Current);
			}
			else
			{
				yield return Tuple.Create<Identifier, Identifier>(ie1.Current, null);
			}
		}
		while (ie2.MoveNext())
		{
			yield return Tuple.Create<Identifier, Identifier>(null, ie2.Current);
		}
	}
}
public class Range : IEquatable<Range>
{
	private readonly ComparatorSet[] _comparatorSets;

	private readonly string _rangeSpec;

	public Range(string rangeSpec, bool loose = false)
	{
		_rangeSpec = rangeSpec;
		string[] source = rangeSpec.Split(new string[1] { "||" }, StringSplitOptions.None);
		_comparatorSets = source.Select((string s) => new ComparatorSet(s)).ToArray();
	}

	private Range(IEnumerable<ComparatorSet> comparatorSets)
	{
		_comparatorSets = comparatorSets.ToArray();
		_rangeSpec = string.Join(" || ", _comparatorSets.Select((ComparatorSet cs) => cs.ToString()).ToArray());
	}

	public bool IsSatisfied(Version version, bool includePrerelease = false)
	{
		return _comparatorSets.Any((ComparatorSet s) => s.IsSatisfied(version, includePrerelease));
	}

	public bool IsSatisfied(string versionString, bool loose = false, bool includePrerelease = false)
	{
		try
		{
			Version version = new Version(versionString, loose);
			return IsSatisfied(version, includePrerelease);
		}
		catch (ArgumentException)
		{
			return false;
		}
	}

	public IEnumerable<Version> Satisfying(IEnumerable<Version> versions, bool includePrerelease = false)
	{
		return versions.Where((Version v) => IsSatisfied(v, includePrerelease));
	}

	public IEnumerable<string> Satisfying(IEnumerable<string> versions, bool loose = false, bool includePrerelease = false)
	{
		return versions.Where((string v) => IsSatisfied(v, loose, includePrerelease));
	}

	public Version MaxSatisfying(IEnumerable<Version> versions, bool includePrerelease = false)
	{
		return Satisfying(versions, includePrerelease).Max();
	}

	public string MaxSatisfying(IEnumerable<string> versionStrings, bool loose = false, bool includePrerelease = false)
	{
		IEnumerable<Version> versions = ValidVersions(versionStrings, loose);
		Version version = MaxSatisfying(versions, includePrerelease);
		if (!(version == null))
		{
			return version.ToString();
		}
		return null;
	}

	public Range Intersect(Range other)
	{
		List<ComparatorSet> list = (from cs in _comparatorSets.SelectMany((ComparatorSet thisCs) => other._comparatorSets.Select(thisCs.Intersect))
			where cs != null
			select cs).ToList();
		if (list.Count == 0)
		{
			return new Range("<0.0.0");
		}
		return new Range(list);
	}

	public override string ToString()
	{
		return _rangeSpec;
	}

	public bool Equals(Range other)
	{
		if ((object)other == null)
		{
			return false;
		}
		return new HashSet<ComparatorSet>(_comparatorSets).SetEquals(other._comparatorSets);
	}

	public override bool Equals(object other)
	{
		return Equals(other as Range);
	}

	public static bool operator ==(Range a, Range b)
	{
		return a?.Equals(b) ?? ((object)b == null);
	}

	public static bool operator !=(Range a, Range b)
	{
		return !(a == b);
	}

	public override int GetHashCode()
	{
		return _comparatorSets.Aggregate(0, (int accum, ComparatorSet next) => accum ^ next.GetHashCode());
	}

	public static bool IsSatisfied(string rangeSpec, string versionString, bool loose = false, bool includePrerelease = false)
	{
		return new Range(rangeSpec).IsSatisfied(versionString, loose, includePrerelease);
	}

	public static IEnumerable<string> Satisfying(string rangeSpec, IEnumerable<string> versions, bool loose = false, bool includePrerelease = false)
	{
		return new Range(rangeSpec).Satisfying(versions, loose, includePrerelease);
	}

	public static string MaxSatisfying(string rangeSpec, IEnumerable<string> versionStrings, bool loose = false, bool includePrerelease = false)
	{
		return new Range(rangeSpec).MaxSatisfying(versionStrings, loose: false, includePrerelease);
	}

	public static Range Parse(string rangeSpec, bool loose = false)
	{
		return new Range(rangeSpec, loose);
	}

	public static bool TryParse(string rangeSpec, out Range result)
	{
		return TryParse(rangeSpec, loose: false, out result);
	}

	public static bool TryParse(string rangeSpec, bool loose, out Range result)
	{
		try
		{
			result = Parse(rangeSpec, loose);
			return true;
		}
		catch
		{
			result = null;
			return false;
		}
	}

	private IEnumerable<Version> ValidVersions(IEnumerable<string> versionStrings, bool loose)
	{
		foreach (string versionString in versionStrings)
		{
			Version version = null;
			try
			{
				version = new Version(versionString, loose);
			}
			catch (ArgumentException)
			{
			}
			if (version != null)
			{
				yield return version;
			}
		}
	}
}
public class Version : IComparable<Version>, IComparable, IEquatable<Version>
{
	private readonly string _inputString;

	private readonly int _major;

	private readonly int _minor;

	private readonly int _patch;

	private readonly string _preRelease;

	private readonly string _build;

	private static Regex strictRegex = new Regex("^\n            \\s*v?\n            ([0-9]|[1-9][0-9]+)       # major version\n            \\.\n            ([0-9]|[1-9][0-9]+)       # minor version\n            \\.\n            ([0-9]|[1-9][0-9]+)       # patch version\n            (\\-([0-9A-Za-z\\-\\.]+))?   # pre-release version\n            (\\+([0-9A-Za-z\\-\\.]+))?   # build metadata\n            \\s*\n            $", RegexOptions.IgnorePatternWhitespace);

	private static Regex looseRegex = new Regex("^\n            [v=\\s]*\n            (\\d+)                     # major version\n            \\.\n            (\\d+)                     # minor version\n            \\.\n            (\\d+)                     # patch version\n            (\\-?([0-9A-Za-z\\-\\.]+))?  # pre-release version\n            (\\+([0-9A-Za-z\\-\\.]+))?   # build metadata\n            \\s*\n            $", RegexOptions.IgnorePatternWhitespace);

	public int Major => _major;

	public int Minor => _minor;

	public int Patch => _patch;

	public string PreRelease => _preRelease;

	public string Build => _build;

	public bool IsPreRelease => !string.IsNullOrEmpty(_preRelease);

	public Version(string input, bool loose = false)
	{
		_inputString = input;
		Match match = (loose ? looseRegex : strictRegex).Match(input);
		if (!match.Success)
		{
			throw new ArgumentException($"Invalid version string: {input}");
		}
		_major = int.Parse(match.Groups[1].Value);
		_minor = int.Parse(match.Groups[2].Value);
		_patch = int.Parse(match.Groups[3].Value);
		if (match.Groups[4].Success)
		{
			string value = match.Groups[5].Value;
			string text = PreReleaseVersion.Clean(value);
			if (!loose && value != text)
			{
				throw new ArgumentException($"Invalid pre-release version: {value}");
			}
			_preRelease = text;
		}
		if (match.Groups[6].Success)
		{
			_build = match.Groups[7].Value;
		}
	}

	public Version(int major, int minor, int patch, string preRelease = null, string build = null)
	{
		_major = major;
		_minor = minor;
		_patch = patch;
		_preRelease = preRelease;
		_build = build;
	}

	public Version BaseVersion()
	{
		return new Version(Major, Minor, Patch);
	}

	public override string ToString()
	{
		return _inputString ?? Clean();
	}

	public string Clean()
	{
		string text = ((PreRelease == null) ? "" : $"-{PreReleaseVersion.Clean(PreRelease)}");
		string text2 = ((Build == null) ? "" : $"+{Build}");
		return $"{Major}.{Minor}.{Patch}{text}{text2}";
	}

	public override int GetHashCode()
	{
		int num = 17;
		num = num * 23 + Major.GetHashCode();
		num = num * 23 + Minor.GetHashCode();
		num = num * 23 + Patch.GetHashCode();
		if (PreRelease != null)
		{
			num = num * 23 + PreRelease.GetHashCode();
		}
		return num;
	}

	public bool Equals(Version other)
	{
		if ((object)other == null)
		{
			return false;
		}
		return CompareTo(other) == 0;
	}

	public int CompareTo(object obj)
	{
		if (obj != null)
		{
			if (obj is Version other)
			{
				return CompareTo(other);
			}
			throw new ArgumentException("Object is not a Version");
		}
		return 1;
	}

	public int CompareTo(Version other)
	{
		if ((object)other == null)
		{
			return 1;
		}
		foreach (int item in PartComparisons(other))
		{
			if (item != 0)
			{
				return item;
			}
		}
		return PreReleaseVersion.Compare(PreRelease, other.PreRelease);
	}

	private IEnumerable<int> PartComparisons(Version other)
	{
		yield return Major.CompareTo(other.Major);
		yield return Minor.CompareTo(other.Minor);
		yield return Patch.CompareTo(other.Patch);
	}

	public override bool Equals(object other)
	{
		return Equals(other as Version);
	}

	public static Version Parse(string input, bool loose = false)
	{
		return new Version(input, loose);
	}

	public static bool TryParse(string input, out Version result)
	{
		return TryParse(input, loose: false, out result);
	}

	public static bool TryParse(string input, bool loose, out Version result)
	{
		try
		{
			result = Parse(input, loose);
			return true;
		}
		catch
		{
			result = null;
			return false;
		}
	}

	public static bool operator ==(Version a, Version b)
	{
		return a?.Equals(b) ?? ((object)b == null);
	}

	public static bool operator !=(Version a, Version b)
	{
		return !(a == b);
	}

	public static bool operator >(Version a, Version b)
	{
		if ((object)a == null)
		{
			return false;
		}
		return a.CompareTo(b) > 0;
	}

	public static bool operator >=(Version a, Version b)
	{
		if ((object)a == null)
		{
			if ((object)b != null)
			{
				return false;
			}
			return true;
		}
		return a.CompareTo(b) >= 0;
	}

	public static bool operator <(Version a, Version b)
	{
		if ((object)a == null)
		{
			if ((object)b != null)
			{
				return true;
			}
			return false;
		}
		return a.CompareTo(b) < 0;
	}

	public static bool operator <=(Version a, Version b)
	{
		if ((object)a == null)
		{
			return true;
		}
		return a.CompareTo(b) <= 0;
	}
}

BepInExPack/BepInEx/core/UnhollowerBaseLib.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.IO.MemoryMappedFiles;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using Iced.Intel;
using Il2CppSystem;
using Il2CppSystem.Reflection;
using Il2CppSystem.Runtime.CompilerServices;
using Microsoft.CodeAnalysis;
using UnhollowerBaseLib;
using UnhollowerBaseLib.Attributes;
using UnhollowerBaseLib.Maps;
using UnhollowerBaseLib.Runtime;
using UnhollowerBaseLib.Runtime.VersionSpecific.Assembly;
using UnhollowerBaseLib.Runtime.VersionSpecific.AssemblyName;
using UnhollowerBaseLib.Runtime.VersionSpecific.Class;
using UnhollowerBaseLib.Runtime.VersionSpecific.EventInfo;
using UnhollowerBaseLib.Runtime.VersionSpecific.Exception;
using UnhollowerBaseLib.Runtime.VersionSpecific.FieldInfo;
using UnhollowerBaseLib.Runtime.VersionSpecific.Image;
using UnhollowerBaseLib.Runtime.VersionSpecific.MethodInfo;
using UnhollowerBaseLib.Runtime.VersionSpecific.ParameterInfo;
using UnhollowerBaseLib.Runtime.VersionSpecific.PropertyInfo;
using UnhollowerBaseLib.Runtime.VersionSpecific.Type;
using UnhollowerRuntimeLib;
using UnhollowerRuntimeLib.Injection;
using UnhollowerRuntimeLib.XrefScans;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: InternalsVisibleTo("LibAssemblyUnhollower")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("knah et al.")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.4.33.3")]
[assembly: AssemblyInformationalVersion("0.4.33.3")]
[assembly: AssemblyProduct("UnhollowerBaseLib")]
[assembly: AssemblyTitle("UnhollowerBaseLib")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.4.33.3")]
[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 IsUnmanagedAttribute : 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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NativeIntegerAttribute : Attribute
	{
		public readonly bool[] TransformFlags;

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

		public NativeIntegerAttribute(bool[] P_0)
		{
			TransformFlags = P_0;
		}
	}
	[ExcludeFromCodeCoverage]
	[DebuggerNonUserCode]
	internal static class IsExternalInit
	{
	}
}
namespace UnhollowerRuntimeLib
{
	[Obsolete("UnhollowerRuntimeLib.ClassInjectionAssemblyTargetAttribute is obsolete. Use UnhollowerBaseLib.Attributes.ClassInjectionAssemblyTargetAttribute instead.")]
	[AttributeUsage(AttributeTargets.Class)]
	public class ClassInjectionAssemblyTargetAttribute : UnhollowerBaseLib.Attributes.ClassInjectionAssemblyTargetAttribute
	{
		public ClassInjectionAssemblyTargetAttribute(string assembly)
			: base(assembly)
		{
		}

		public ClassInjectionAssemblyTargetAttribute(string[] assemblies)
			: base(assemblies)
		{
		}
	}
	public static class DelegateSupport
	{
		internal class MethodSignature : IEquatable<MethodSignature>
		{
			public readonly bool HasThis;

			public readonly bool ConstructedFromNative;

			private readonly IntPtr myReturnType;

			private readonly IntPtr[] myParameterTypes;

			public MethodSignature(MethodInfo methodInfo, bool hasThis)
			{
				//IL_0028: Unknown result type (might be due to invalid IL or missing references)
				HasThis = hasThis;
				myReturnType = (methodInfo.ReturnType.IsValueType ? methodInfo.ReturnType._impl.value : IntPtr.Zero);
				myParameterTypes = (from it in ((MethodBase)methodInfo).GetParameters()
					select (!it.ParameterType.IsValueType) ? IntPtr.Zero : it.ParameterType._impl.value).ToArray();
				ConstructedFromNative = true;
			}

			public MethodSignature(MethodInfo methodInfo, bool hasThis)
			{
				HasThis = hasThis;
				myReturnType = (methodInfo.ReturnType.IsValueType ? methodInfo.ReturnType.TypeHandle.Value : IntPtr.Zero);
				myParameterTypes = (from it in methodInfo.GetParameters()
					select (!it.ParameterType.IsValueType) ? IntPtr.Zero : it.ParameterType.TypeHandle.Value).ToArray();
				ConstructedFromNative = false;
			}

			public bool Equals(MethodSignature other)
			{
				if ((object)other == null)
				{
					return false;
				}
				if ((object)this == other)
				{
					return true;
				}
				if (!myReturnType.Equals((object?)(nint)other.myReturnType))
				{
					return false;
				}
				if (HasThis != other.HasThis)
				{
					return false;
				}
				if (myParameterTypes.Length != other.myParameterTypes.Length)
				{
					return false;
				}
				for (int i = 0; i < myParameterTypes.Length; i++)
				{
					if (myParameterTypes[i] != other.myParameterTypes[i])
					{
						return false;
					}
				}
				return true;
			}

			public override bool Equals(object obj)
			{
				if (obj == null)
				{
					return false;
				}
				if (this == obj)
				{
					return true;
				}
				if (obj.GetType() != GetType())
				{
					return false;
				}
				return Equals((MethodSignature)obj);
			}

			public override int GetHashCode()
			{
				int num = myReturnType.GetHashCode() ^ HasThis.GetHashCode();
				IntPtr[] array = myParameterTypes;
				foreach (IntPtr intPtr in array)
				{
					num = num * 397 + intPtr.GetHashCode();
				}
				return num;
			}

			public static bool operator ==(MethodSignature left, MethodSignature right)
			{
				return object.Equals(left, right);
			}

			public static bool operator !=(MethodSignature left, MethodSignature right)
			{
				return !object.Equals(left, right);
			}
		}

		private class Il2CppToMonoDelegateReference : Object
		{
			public Delegate ReferencedDelegate;

			public IntPtr MethodInfo;

			public Il2CppToMonoDelegateReference(IntPtr obj0)
				: base(obj0)
			{
			}

			public Il2CppToMonoDelegateReference(Delegate referencedDelegate, IntPtr methodInfo)
				: base(ClassInjector.DerivedConstructorPointer<Il2CppToMonoDelegateReference>())
			{
				ClassInjector.DerivedConstructorBody((Il2CppObjectBase)(object)this);
				ReferencedDelegate = referencedDelegate;
				MethodInfo = methodInfo;
			}

			~Il2CppToMonoDelegateReference()
			{
				try
				{
					Marshal.FreeHGlobal(MethodInfo);
					MethodInfo = IntPtr.Zero;
					ReferencedDelegate = null;
				}
				finally
				{
					((Il2CppObjectBase)this).Finalize();
				}
			}
		}

		private static readonly ConcurrentDictionary<MethodSignature, Type> ourDelegateTypes = new ConcurrentDictionary<MethodSignature, Type>();

		private static readonly AssemblyBuilder AssemblyBuilder = System.Reflection.Emit.AssemblyBuilder.DefineDynamicAssembly(new AssemblyName("Il2CppTrampolineDelegates"), AssemblyBuilderAccess.Run);

		private static readonly ModuleBuilder ModuleBuilder = AssemblyBuilder.DefineDynamicModule("Il2CppTrampolineDelegates");

		private static readonly ConcurrentDictionary<MethodInfo, Delegate> NativeToManagedTrampolines = new ConcurrentDictionary<MethodInfo, Delegate>();

		internal static Type GetOrCreateDelegateType(MethodSignature signature, MethodInfo managedMethod)
		{
			return ourDelegateTypes.GetOrAdd(signature, (MethodSignature signature, MethodInfo managedMethodInner) => CreateDelegateType(managedMethodInner, signature.HasThis, signature.ConstructedFromNative), managedMethod);
		}

		private unsafe static Type CreateDelegateType(MethodInfo managedMethodInner, bool addIntPtrForThis, bool addNamingDisambig)
		{
			TypeBuilder typeBuilder = ModuleBuilder.DefineType("Il2CppToManagedDelegate_" + ExtractSignature(managedMethodInner) + (addIntPtrForThis ? "HasThis" : "") + (addNamingDisambig ? "FromNative" : ""), TypeAttributes.Public | TypeAttributes.Sealed, typeof(MulticastDelegate));
			typeBuilder.SetCustomAttribute(new CustomAttributeBuilder(typeof(UnmanagedFunctionPointerAttribute).GetConstructor(new Type[1] { typeof(CallingConvention) }), new object[1] { CallingConvention.Cdecl }));
			typeBuilder.DefineConstructor(MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName, CallingConventions.HasThis, new Type[2]
			{
				typeof(object),
				typeof(IntPtr)
			}).SetImplementationFlags(MethodImplAttributes.CodeTypeMask);
			int num = (addIntPtrForThis ? 1 : 0);
			ParameterInfo[] parameters = managedMethodInner.GetParameters();
			Type[] array = new Type[parameters.Length + 1 + num];
			if (addIntPtrForThis)
			{
				array[0] = typeof(IntPtr);
			}
			array[^1] = typeof(Il2CppMethodInfo*);
			for (int i = 0; i < parameters.Length; i++)
			{
				array[i + num] = (parameters[i].ParameterType.IsValueType ? parameters[i].ParameterType : typeof(IntPtr));
			}
			typeBuilder.DefineMethod("Invoke", MethodAttributes.Public | MethodAttributes.Virtual | MethodAttributes.HideBySig | MethodAttributes.VtableLayoutMask, CallingConventions.HasThis, managedMethodInner.ReturnType.IsValueType ? managedMethodInner.ReturnType : typeof(IntPtr), array).SetImplementationFlags(MethodImplAttributes.CodeTypeMask);
			typeBuilder.DefineMethod("BeginInvoke", MethodAttributes.Public | MethodAttributes.Virtual | MethodAttributes.HideBySig | MethodAttributes.VtableLayoutMask, CallingConventions.HasThis, typeof(IAsyncResult), array.Concat(new Type[2]
			{
				typeof(AsyncCallback),
				typeof(object)
			}).ToArray()).SetImplementationFlags(MethodImplAttributes.CodeTypeMask);
			typeBuilder.DefineMethod("EndInvoke", MethodAttributes.Public | MethodAttributes.Virtual | MethodAttributes.HideBySig | MethodAttributes.VtableLayoutMask, CallingConventions.HasThis, managedMethodInner.ReturnType.IsValueType ? managedMethodInner.ReturnType : typeof(IntPtr), new Type[1] { typeof(IAsyncResult) }).SetImplementationFlags(MethodImplAttributes.CodeTypeMask);
			return typeBuilder.CreateType();
		}

		private static string ExtractSignature(MethodInfo methodInfo)
		{
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.Append(methodInfo.ReturnType.FullName);
			ParameterInfo[] parameters = methodInfo.GetParameters();
			foreach (ParameterInfo parameterInfo in parameters)
			{
				stringBuilder.Append('_');
				stringBuilder.Append(parameterInfo.ParameterType.FullName);
			}
			return stringBuilder.ToString();
		}

		private static Delegate GetOrCreateNativeToManagedTrampoline(MethodSignature signature, MethodInfo nativeMethod, MethodInfo managedMethod)
		{
			return NativeToManagedTrampolines.GetOrAdd(managedMethod, (MethodInfo _, (MethodInfo nativeMethod, MethodInfo managedMethod, MethodSignature signature) tuple) => GenerateNativeToManagedTrampoline(tuple.nativeMethod, tuple.managedMethod, tuple.signature), (nativeMethod, managedMethod, signature));
		}

		private unsafe static Delegate GenerateNativeToManagedTrampoline(MethodInfo nativeMethod, MethodInfo managedMethod, MethodSignature signature)
		{
			Type type = (nativeMethod.ReturnType.IsValueType ? managedMethod.ReturnType : typeof(IntPtr));
			ParameterInfo[] parameters = managedMethod.GetParameters();
			Il2CppReferenceArray<ParameterInfo> parameters2 = ((MethodBase)nativeMethod).GetParameters();
			Type[] array = new Type[parameters.Length + 1 + 1];
			array[0] = typeof(IntPtr);
			array[parameters.Length + 1] = typeof(Il2CppMethodInfo*);
			for (int i = 0; i < parameters.Length; i++)
			{
				array[i + 1] = (parameters2[i].ParameterType.IsValueType ? parameters[i].ParameterType : typeof(IntPtr));
			}
			DynamicMethod dynamicMethod = new DynamicMethod("(il2cpp delegate trampoline) " + ExtractSignature(managedMethod), MethodAttributes.Static, CallingConventions.Standard, type, array, typeof(DelegateSupport), skipVisibility: true);
			ILGenerator iLGenerator = dynamicMethod.GetILGenerator();
			iLGenerator.BeginExceptionBlock();
			iLGenerator.Emit(OpCodes.Ldarg_0);
			iLGenerator.Emit(OpCodes.Call, typeof(ClassInjectorBase).GetMethod("GetMonoObjectFromIl2CppPointer"));
			iLGenerator.Emit(OpCodes.Castclass, typeof(Il2CppToMonoDelegateReference));
			iLGenerator.Emit(OpCodes.Ldfld, typeof(Il2CppToMonoDelegateReference).GetField("ReferencedDelegate"));
			for (int j = 0; j < parameters.Length; j++)
			{
				Type parameterType = parameters[j].ParameterType;
				iLGenerator.Emit(OpCodes.Ldarg, j + 1);
				if (parameterType == typeof(string))
				{
					iLGenerator.Emit(OpCodes.Call, typeof(IL2CPP).GetMethod("Il2CppStringToManaged"));
				}
				else if (!parameterType.IsValueType)
				{
					Label label = iLGenerator.DefineLabel();
					Label label2 = iLGenerator.DefineLabel();
					iLGenerator.Emit(OpCodes.Brfalse, label);
					iLGenerator.Emit(OpCodes.Ldarg, j + 1);
					iLGenerator.Emit(OpCodes.Newobj, parameterType.GetConstructor(new Type[1] { typeof(IntPtr) }));
					iLGenerator.Emit(OpCodes.Br, label2);
					iLGenerator.MarkLabel(label);
					iLGenerator.Emit(OpCodes.Ldnull);
					iLGenerator.MarkLabel(label2);
				}
			}
			iLGenerator.Emit(OpCodes.Call, managedMethod);
			if (type == typeof(string))
			{
				iLGenerator.Emit(OpCodes.Call, typeof(IL2CPP).GetMethod("ManagedStringToIl2Cpp"));
			}
			else if (!type.IsValueType)
			{
				Label label3 = iLGenerator.DefineLabel();
				Label label4 = iLGenerator.DefineLabel();
				iLGenerator.Emit(OpCodes.Dup);
				iLGenerator.Emit(OpCodes.Brfalse, label3);
				iLGenerator.Emit(OpCodes.Call, typeof(Il2CppObjectBase).GetProperty("Pointer").GetMethod);
				iLGenerator.Emit(OpCodes.Br, label4);
				iLGenerator.MarkLabel(label3);
				iLGenerator.Emit(OpCodes.Pop);
				iLGenerator.Emit(OpCodes.Ldc_I4_0);
				iLGenerator.Emit(OpCodes.Conv_I);
				iLGenerator.MarkLabel(label4);
			}
			LocalBuilder localBuilder = null;
			if (type != typeof(void))
			{
				localBuilder = iLGenerator.DeclareLocal(type);
				iLGenerator.Emit(OpCodes.Stloc, localBuilder);
			}
			LocalBuilder local = iLGenerator.DeclareLocal(typeof(Exception));
			iLGenerator.BeginCatchBlock(typeof(Exception));
			iLGenerator.Emit(OpCodes.Stloc, local);
			iLGenerator.Emit(OpCodes.Ldstr, "Exception in IL2CPP-to-Managed trampoline, not passing it to il2cpp: ");
			iLGenerator.Emit(OpCodes.Ldloc, local);
			iLGenerator.Emit(OpCodes.Callvirt, typeof(object).GetMethod("ToString"));
			iLGenerator.Emit(OpCodes.Call, typeof(string).GetMethod("Concat", new Type[2]
			{
				typeof(string),
				typeof(string)
			}));
			iLGenerator.Emit(OpCodes.Call, typeof(LogSupport).GetMethod("Error"));
			iLGenerator.EndExceptionBlock();
			if (localBuilder != null)
			{
				iLGenerator.Emit(OpCodes.Ldloc, localBuilder);
			}
			iLGenerator.Emit(OpCodes.Ret);
			return dynamicMethod.CreateDelegate(GetOrCreateDelegateType(signature, managedMethod));
		}

		public static TIl2Cpp ConvertDelegate<TIl2Cpp>(Delegate @delegate) where TIl2Cpp : Il2CppObjectBase
		{
			//IL_0316: Unknown result type (might be due to invalid IL or missing references)
			//IL_031d: Expected O, but got Unknown
			//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
			if ((object)@delegate == null)
			{
				return null;
			}
			if (!typeof(Delegate).IsAssignableFrom(typeof(TIl2Cpp)))
			{
				throw new ArgumentException($"{typeof(TIl2Cpp)} is not a delegate");
			}
			MethodInfo method = @delegate.GetType().GetMethod("Invoke");
			ParameterInfo[] parameters = method.GetParameters();
			ParameterInfo[] array = parameters;
			for (int i = 0; i < array.Length; i++)
			{
				Type parameterType = array[i].ParameterType;
				if (parameterType.IsGenericParameter)
				{
					throw new ArgumentException($"Delegate has unsubstituted generic parameter ({parameterType}) which is not supported");
				}
				if (parameterType.BaseType == typeof(ValueType))
				{
					throw new ArgumentException($"Delegate has parameter of type {parameterType} (non-blittable struct) which is not supported");
				}
			}
			IntPtr nativeClassPtr = Il2CppClassPointerStore<TIl2Cpp>.NativeClassPtr;
			if (nativeClassPtr == IntPtr.Zero)
			{
				throw new ArgumentException($"Type {typeof(TIl2Cpp)} has uninitialized class pointer");
			}
			if (Il2CppClassPointerStore<Il2CppToMonoDelegateReference>.NativeClassPtr == IntPtr.Zero)
			{
				ClassInjector.RegisterTypeInIl2Cpp<Il2CppToMonoDelegateReference>();
			}
			MethodInfo method2 = Type.internal_from_handle(IL2CPP.il2cpp_class_get_type(nativeClassPtr)).GetMethod("Invoke");
			Il2CppReferenceArray<ParameterInfo> parameters2 = ((MethodBase)method2).GetParameters();
			if (parameters2.Count != parameters.Length)
			{
				throw new ArgumentException($"Managed delegate has {parameters.Length} parameters, native has {parameters2.Count}, these should match");
			}
			for (int j = 0; j < parameters2.Count; j++)
			{
				Type parameterType2 = parameters2[j].ParameterType;
				Type parameterType3 = parameters[j].ParameterType;
				if (parameterType2.IsPrimitive || parameterType3.IsPrimitive)
				{
					if (parameterType2.FullName != parameterType3.FullName)
					{
						throw new ArgumentException($"Parameter type mismatch at parameter {j}: {parameterType2.FullName} != {parameterType3.FullName}");
					}
					continue;
				}
				IntPtr intPtr = (IntPtr)typeof(Il2CppClassPointerStore<>).MakeGenericType(parameterType3).GetField("NativeClassPtr").GetValue(null);
				IntPtr intPtr2 = IL2CPP.il2cpp_class_from_type(parameterType2._impl.value);
				if (intPtr != intPtr2)
				{
					throw new ArgumentException($"Parameter type at {j} has mismatched native type pointers; types: {parameterType2.FullName} != {parameterType3.FullName}");
				}
				if (parameterType2.IsByRef || parameterType3.IsByRef)
				{
					throw new ArgumentException($"Parameter at {j} is passed by reference, this is not supported");
				}
			}
			Delegate orCreateNativeToManagedTrampoline = GetOrCreateNativeToManagedTrampoline(new MethodSignature(method2, hasThis: true), method2, method);
			INativeMethodInfoStruct nativeMethodInfoStruct = UnityVersionHandler.NewMethod();
			nativeMethodInfoStruct.MethodPointer = Marshal.GetFunctionPointerForDelegate(orCreateNativeToManagedTrampoline);
			nativeMethodInfoStruct.ParametersCount = (byte)parameters.Length;
			nativeMethodInfoStruct.Slot = ushort.MaxValue;
			nativeMethodInfoStruct.IsMarshalledFromNative = true;
			Il2CppToMonoDelegateReference il2CppToMonoDelegateReference = new Il2CppToMonoDelegateReference(@delegate, nativeMethodInfoStruct.Pointer);
			Delegate val = (Delegate)((!UnityVersionHandler.MustUseDelegateConstructor) ? ((object)new Delegate(IL2CPP.il2cpp_object_new(nativeClassPtr))) : ((object)((Il2CppObjectBase)(TIl2Cpp)Activator.CreateInstance(typeof(TIl2Cpp), ((Il2CppObjectBase)(object)il2CppToMonoDelegateReference).Cast<Object>(), nativeMethodInfoStruct.Pointer)).Cast<Delegate>()));
			val.method_ptr = nativeMethodInfoStruct.MethodPointer;
			val.method_info = method2;
			val.method = nativeMethodInfoStruct.Pointer;
			val.m_target = (Object)(object)il2CppToMonoDelegateReference;
			if (UnityVersionHandler.MustUseDelegateConstructor)
			{
				val.invoke_impl = val.method_ptr;
				val.method_code = ((Il2CppObjectBase)(object)val.m_target).Pointer;
			}
			return ((Il2CppObjectBase)(object)val).Cast<TIl2Cpp>();
		}
	}
	public class Il2CppReferenceField<TRefObj> where TRefObj : Il2CppObjectBase
	{
		private static bool? isInjectedType;

		private readonly Il2CppObjectBase _obj;

		private readonly IntPtr _fieldPtr;

		internal Il2CppReferenceField(Il2CppObjectBase obj, string fieldName)
		{
			_obj = obj;
			_fieldPtr = IL2CPP.GetIl2CppField(obj.ObjectClass, fieldName);
		}

		public unsafe TRefObj Get()
		{
			IntPtr pointerToData = *GetPointerToData();
			if (pointerToData == IntPtr.Zero)
			{
				return null;
			}
			if (!isInjectedType.HasValue)
			{
				isInjectedType = RuntimeSpecificsStore.IsInjected(Il2CppClassPointerStore<TRefObj>.NativeClassPtr);
			}
			if (isInjectedType.Value && ClassInjectorBase.GetMonoObjectFromIl2CppPointer(pointerToData) is TRefObj result)
			{
				return result;
			}
			return (TRefObj)Activator.CreateInstance(typeof(TRefObj), pointerToData);
		}

		public unsafe void Set(TRefObj value)
		{
			*GetPointerToData() = value.Pointer;
		}

		public static implicit operator TRefObj(Il2CppReferenceField<TRefObj> _this)
		{
			return _this.Get();
		}

		public static implicit operator Il2CppReferenceField<TRefObj>(TRefObj _)
		{
			throw null;
		}

		private unsafe IntPtr* GetPointerToData()
		{
			return (IntPtr*)(void*)(IL2CPP.Il2CppObjectBaseToPtrNotNull(_obj) + (int)IL2CPP.il2cpp_field_get_offset(_fieldPtr));
		}
	}
	public static class Il2CppType
	{
		public static Type TypeFromPointer(IntPtr classPointer, string typeName = "<unknown type>")
		{
			return TypeFromPointerInternal(classPointer, typeName, throwOnFailure: true);
		}

		private static Type TypeFromPointerInternal(IntPtr classPointer, string typeName, bool throwOnFailure)
		{
			if (classPointer == IntPtr.Zero)
			{
				if (throwOnFailure)
				{
					throw new ArgumentException(typeName + " does not have a corresponding IL2CPP class pointer");
				}
				return null;
			}
			IntPtr intPtr = IL2CPP.il2cpp_class_get_type(classPointer);
			if (intPtr == IntPtr.Zero)
			{
				if (throwOnFailure)
				{
					throw new ArgumentException(typeName + " does not have a corresponding IL2CPP type pointer");
				}
				return null;
			}
			return Type.internal_from_handle(intPtr);
		}

		public static Type From(Type type)
		{
			return From(type, throwOnFailure: true);
		}

		public static Type From(Type type, bool throwOnFailure)
		{
			return TypeFromPointerInternal(Il2CppClassPointerStore.GetNativeClassPointer(type), type.Name, throwOnFailure);
		}

		public static Type Of<T>()
		{
			return Of<T>(throwOnFailure: true);
		}

		public static Type Of<T>(bool throwOnFailure)
		{
			return TypeFromPointerInternal(Il2CppClassPointerStore<T>.NativeClassPtr, typeof(T).Name, throwOnFailure);
		}
	}
	[Obsolete("Use Il2CppType.Of<T>()", false)]
	public static class Il2CppTypeOf<T>
	{
		[Obsolete("Use Il2CppType.Of<T>()", true)]
		public static Type Type => Il2CppType.Of<T>();
	}
	public class Il2CppValueField<T> where T : unmanaged
	{
		private readonly Il2CppObjectBase _obj;

		private readonly IntPtr _fieldPtr;

		internal Il2CppValueField(Il2CppObjectBase obj, string fieldName)
		{
			_obj = obj;
			_fieldPtr = IL2CPP.GetIl2CppField(obj.ObjectClass, fieldName);
		}

		public unsafe T Get()
		{
			return *GetPointerToData();
		}

		public unsafe void Set(T value)
		{
			*GetPointerToData() = value;
		}

		public static implicit operator T(Il2CppValueField<T> _this)
		{
			return _this.Get();
		}

		public static implicit operator Il2CppValueField<T>(T _)
		{
			throw null;
		}

		private unsafe T* GetPointerToData()
		{
			return (T*)(void*)(IL2CPP.Il2CppObjectBaseToPtrNotNull(_obj) + (int)IL2CPP.il2cpp_field_get_offset(_fieldPtr));
		}
	}
	public class Il2CppInterfaceCollection : List<INativeClassStruct>
	{
		public Il2CppInterfaceCollection(IEnumerable<INativeClassStruct> interfaces)
			: base(interfaces)
		{
		}

		public Il2CppInterfaceCollection(IEnumerable<Type> interfaces)
			: base(ResolveNativeInterfaces(interfaces))
		{
		}

		private unsafe static IEnumerable<INativeClassStruct> ResolveNativeInterfaces(IEnumerable<Type> interfaces)
		{
			return interfaces.Select(delegate(Type it)
			{
				IntPtr nativeClassPointer = Il2CppClassPointerStore.GetNativeClassPointer(it);
				if (nativeClassPointer == IntPtr.Zero)
				{
					throw new ArgumentException($"Type {it} doesn't have an IL2CPP class pointer, which means it's not an IL2CPP interface");
				}
				return UnityVersionHandler.Wrap((Il2CppClass*)(void*)nativeClassPointer);
			});
		}

		public static implicit operator Il2CppInterfaceCollection(INativeClassStruct[] interfaces)
		{
			return new Il2CppInterfaceCollection(interfaces);
		}

		public static implicit operator Il2CppInterfaceCollection(Type[] interfaces)
		{
			return new Il2CppInterfaceCollection(interfaces);
		}
	}
	public class RegisterTypeOptions
	{
		public static readonly RegisterTypeOptions Default = new RegisterTypeOptions();

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


		public Func<Type, Type[]> InterfacesResolver { get; init; }

		public Il2CppInterfaceCollection Interfaces { get; init; }
	}
	public static class ClassInjector
	{
		[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
		private unsafe delegate IntPtr InvokerDelegate(IntPtr methodPointer, Il2CppMethodInfo* methodInfo, IntPtr obj, IntPtr* args);

		[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
		private delegate void VoidCtorDelegate(IntPtr objectPointer);

		[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
		private unsafe delegate Il2CppMethodInfo* GenericGetMethodDelegate(Il2CppGenericMethod* gmethod, bool copyMethodPtr);

		private class DoHookDetour : IManagedDetour
		{
			private static readonly List<object> PinnedDelegates = new List<object>();

			public unsafe T Detour<T>(IntPtr from, T to) where T : Delegate
			{
				IntPtr* ptr = &from;
				PinnedDelegates.Add(to);
				DoHook((IntPtr)ptr, Marshal.GetFunctionPointerForDelegate(to));
				return Marshal.GetDelegateForFunctionPointer<T>(from);
			}
		}

		private static readonly HashSet<string> InjectedTypes = new HashSet<string>();

		private static readonly Dictionary<IntPtr, (MethodInfo, Dictionary<IntPtr, IntPtr>)> InflatedMethodFromContextDictionary = new Dictionary<IntPtr, (MethodInfo, Dictionary<IntPtr, IntPtr>)>();

		private static readonly ConcurrentDictionary<string, InvokerDelegate> InvokerCache = new ConcurrentDictionary<string, InvokerDelegate>();

		private static volatile GenericGetMethodDelegate ourOriginalGenericGetMethod;

		public static IManagedDetour Detour = new DoHookDetour();

		[Obsolete("Set Detour instead")]
		public static Action<IntPtr, IntPtr> DoHook;

		private static readonly ConcurrentDictionary<(Type type, FieldAttributes attrs), IntPtr> _injectedFieldTypes = new ConcurrentDictionary<(Type, FieldAttributes), IntPtr>();

		private static readonly VoidCtorDelegate FinalizeDelegate = Finalize;

		public static void ProcessNewObject(Il2CppObjectBase obj)
		{
			IntPtr pointer = obj.Pointer;
			GCHandle gcHandle = GCHandle.Alloc(obj, GCHandleType.Normal);
			AssignGcHandle(pointer, gcHandle);
		}

		public static IntPtr DerivedConstructorPointer<T>()
		{
			return IL2CPP.il2cpp_object_new(Il2CppClassPointerStore<T>.NativeClassPtr);
		}

		public static void DerivedConstructorBody(Il2CppObjectBase objectBase)
		{
			if (!objectBase.isWrapped)
			{
				FieldInfo[] array = objectBase.GetType().GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).Where(IsFieldEligible)
					.ToArray();
				foreach (FieldInfo fieldInfo in array)
				{
					fieldInfo.SetValue(objectBase, fieldInfo.FieldType.GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[2]
					{
						typeof(Il2CppObjectBase),
						typeof(string)
					}, Array.Empty<ParameterModifier>()).Invoke(new object[2] { objectBase, fieldInfo.Name }));
				}
				GCHandle gcHandle = GCHandle.Alloc(objectBase, GCHandleType.Normal);
				AssignGcHandle(objectBase.Pointer, gcHandle);
			}
		}

		public unsafe static void AssignGcHandle(IntPtr pointer, GCHandle gcHandle)
		{
			GCHandle.ToIntPtr(gcHandle);
			if (pointer == IntPtr.Zero)
			{
				throw new NullReferenceException("pointer");
			}
			ClassInjectorBase.GetInjectedData(pointer)->managedGcHandle = GCHandle.ToIntPtr(gcHandle);
		}

		public static bool IsTypeRegisteredInIl2Cpp<T>() where T : class
		{
			return IsTypeRegisteredInIl2Cpp(typeof(T));
		}

		public static bool IsTypeRegisteredInIl2Cpp(Type type)
		{
			if (Il2CppClassPointerStore.GetNativeClassPointer(type) != IntPtr.Zero)
			{
				return true;
			}
			lock (InjectedTypes)
			{
				if (InjectedTypes.Contains(type.FullName))
				{
					return true;
				}
			}
			return false;
		}

		[Obsolete("Use RegisterTypeInIl2Cpp<T>(RegisterTypeOptions)", true)]
		public static void RegisterTypeInIl2Cpp<T>(bool logSuccess) where T : class
		{
			RegisterTypeInIl2Cpp(typeof(T), new RegisterTypeOptions
			{
				LogSuccess = logSuccess
			});
		}

		[Obsolete("Use RegisterTypeInIl2Cpp(Type, RegisterTypeOptions)", true)]
		public static void RegisterTypeInIl2Cpp(Type type, bool logSuccess)
		{
			RegisterTypeInIl2Cpp(type, new RegisterTypeOptions
			{
				LogSuccess = logSuccess
			});
		}

		[Obsolete("Use RegisterTypeInIl2Cpp(Type, RegisterTypeOptions) or [Il2CppImplementsAttribute]", true)]
		public static void RegisterTypeInIl2CppWithInterfaces<T>(params Type[] interfaces) where T : class
		{
			RegisterTypeInIl2CppWithInterfaces(typeof(T), logSuccess: true, interfaces);
		}

		[Obsolete("Use RegisterTypeInIl2Cpp(Type, RegisterTypeOptions) or [Il2CppImplementsAttribute]", true)]
		public static void RegisterTypeInIl2CppWithInterfaces<T>(bool logSuccess, params Type[] interfaces) where T : class
		{
			RegisterTypeInIl2CppWithInterfaces(typeof(T), logSuccess, interfaces);
		}

		[Obsolete("Use RegisterTypeInIl2Cpp(Type, RegisterTypeOptions) or [Il2CppImplementsAttribute]", true)]
		public static void RegisterTypeInIl2CppWithInterfaces(Type type, bool logSuccess, params Type[] interfaces)
		{
			RegisterTypeInIl2Cpp(type, new RegisterTypeOptions
			{
				LogSuccess = logSuccess,
				Interfaces = interfaces
			});
		}

		[Obsolete("Use RegisterTypeInIl2Cpp(Type, RegisterTypeOptions)", true)]
		public static void RegisterTypeInIl2Cpp(Type type, bool logSuccess, params INativeClassStruct[] interfaces)
		{
			RegisterTypeInIl2Cpp(type, new RegisterTypeOptions
			{
				LogSuccess = logSuccess,
				Interfaces = interfaces
			});
		}

		public static void RegisterTypeInIl2Cpp<T>() where T : class
		{
			RegisterTypeInIl2Cpp(typeof(T));
		}

		public static void RegisterTypeInIl2Cpp(Type type)
		{
			RegisterTypeInIl2Cpp(type, RegisterTypeOptions.Default);
		}

		public static void RegisterTypeInIl2Cpp<T>(RegisterTypeOptions options) where T : class
		{
			RegisterTypeInIl2Cpp(typeof(T), options);
		}

		public unsafe static void RegisterTypeInIl2Cpp(Type type, RegisterTypeOptions options)
		{
			Il2CppInterfaceCollection il2CppInterfaceCollection = options.Interfaces;
			if (il2CppInterfaceCollection == null)
			{
				il2CppInterfaceCollection = type.GetCustomAttribute<Il2CppImplementsAttribute>()?.Interfaces ?? options.InterfacesResolver?.Invoke(type) ?? Array.Empty<Type>();
			}
			if (type == null)
			{
				throw new ArgumentException("Type argument cannot be null");
			}
			if (type.IsGenericType || type.IsGenericTypeDefinition)
			{
				throw new ArgumentException($"Type {type} is generic and can't be used in il2cpp");
			}
			if (Il2CppClassPointerStore.GetNativeClassPointer(type) != IntPtr.Zero)
			{
				return;
			}
			Type baseType = type.BaseType;
			if (baseType == null)
			{
				throw new ArgumentException($"Class {type} does not inherit from a class registered in il2cpp");
			}
			INativeClassStruct nativeClassStruct = UnityVersionHandler.Wrap((Il2CppClass*)(void*)Il2CppClassPointerStore.GetNativeClassPointer(baseType));
			if (nativeClassStruct == null)
			{
				RegisterTypeInIl2Cpp(baseType, new RegisterTypeOptions
				{
					LogSuccess = options.LogSuccess
				});
				nativeClassStruct = UnityVersionHandler.Wrap((Il2CppClass*)(void*)Il2CppClassPointerStore.GetNativeClassPointer(baseType));
			}
			InjectorHelpers.Setup();
			InjectorHelpers.ClassInit(nativeClassStruct.ClassPointer);
			if (nativeClassStruct.ValueType || nativeClassStruct.EnumType)
			{
				throw new ArgumentException($"Base class {baseType} is value type and can't be inherited from");
			}
			if (nativeClassStruct.IsGeneric)
			{
				throw new ArgumentException($"Base class {baseType} is generic and can't be inherited from");
			}
			if ((nativeClassStruct.Flags & Il2CppClassAttributes.TYPE_ATTRIBUTE_SEALED) != 0)
			{
				throw new ArgumentException($"Base class {baseType} is sealed and can't be inherited from");
			}
			if ((nativeClassStruct.Flags & Il2CppClassAttributes.TYPE_ATTRIBUTE_CLASS_SEMANTIC_MASK) != 0)
			{
				throw new ArgumentException($"Base class {baseType} is an interface and can't be inherited from");
			}
			if (il2CppInterfaceCollection.Any((INativeClassStruct i) => (i.Flags & Il2CppClassAttributes.TYPE_ATTRIBUTE_CLASS_SEMANTIC_MASK) == 0))
			{
				throw new ArgumentException($"Some of the interfaces in {il2CppInterfaceCollection} are not interfaces");
			}
			lock (InjectedTypes)
			{
				if (!InjectedTypes.Add(type.FullName))
				{
					throw new ArgumentException("Type with FullName " + type.FullName + " is already injected. Don't inject the same type twice, or use a different namespace");
				}
			}
			if (ourOriginalGenericGetMethod == null)
			{
				HookGenericMethodGetMethod();
			}
			int num = il2CppInterfaceCollection.Sum((INativeClassStruct i) => i.MethodCount);
			INativeClassStruct nativeClassStruct2 = UnityVersionHandler.NewClass(nativeClassStruct.VtableCount + num);
			nativeClassStruct2.Image = InjectorHelpers.InjectedImage.ImagePointer;
			nativeClassStruct2.Parent = nativeClassStruct.ClassPointer;
			nativeClassStruct2.ElementClass = (nativeClassStruct2.Class = (nativeClassStruct2.CastClass = nativeClassStruct2.ClassPointer));
			nativeClassStruct2.NativeSize = -1;
			nativeClassStruct2.ActualSize = (nativeClassStruct2.InstanceSize = nativeClassStruct.InstanceSize);
			nativeClassStruct2.Initialized = true;
			nativeClassStruct2.InitializedAndNoError = true;
			nativeClassStruct2.SizeInited = true;
			nativeClassStruct2.HasFinalize = true;
			nativeClassStruct2.IsVtableInitialized = true;
			nativeClassStruct2.Name = Marshal.StringToHGlobalAnsi(type.Name);
			nativeClassStruct2.Namespace = Marshal.StringToHGlobalAnsi(type.Namespace ?? string.Empty);
			nativeClassStruct2.ThisArg.Type = (nativeClassStruct2.ByValArg.Type = Il2CppTypeEnum.IL2CPP_TYPE_CLASS);
			nativeClassStruct2.ThisArg.ByRef = true;
			nativeClassStruct2.Flags = nativeClassStruct.Flags;
			FieldInfo[] array = type.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).Where(IsFieldEligible).ToArray();
			nativeClassStruct2.FieldCount = (ushort)array.Length;
			Il2CppFieldInfo* ptr = (Il2CppFieldInfo*)(void*)Marshal.AllocHGlobal(nativeClassStruct2.FieldCount * UnityVersionHandler.FieldInfoSize());
			int num2 = (int)nativeClassStruct2.InstanceSize;
			for (int j = 0; j < nativeClassStruct2.FieldCount; j++)
			{
				INativeFieldInfoStruct nativeFieldInfoStruct = UnityVersionHandler.Wrap(ptr + j * UnityVersionHandler.FieldInfoSize());
				nativeFieldInfoStruct.Name = Marshal.StringToHGlobalAnsi(array[j].Name);
				nativeFieldInfoStruct.Parent = nativeClassStruct2.ClassPointer;
				nativeFieldInfoStruct.Offset = num2;
				Type type2 = array[j].FieldType.GenericTypeArguments[0];
				FieldAttributes attributes = array[j].Attributes;
				IntPtr nativeClassPointer = Il2CppClassPointerStore.GetNativeClassPointer(type2);
				if (!_injectedFieldTypes.TryGetValue((type2, attributes), out var value))
				{
					INativeTypeStruct nativeTypeStruct = UnityVersionHandler.Wrap((Il2CppTypeStruct*)(void*)IL2CPP.il2cpp_class_get_type(nativeClassPointer));
					INativeTypeStruct nativeTypeStruct2 = UnityVersionHandler.NewType();
					nativeTypeStruct2.Data = nativeTypeStruct.Data;
					nativeTypeStruct2.Attrs = (ushort)attributes;
					nativeTypeStruct2.Type = nativeTypeStruct.Type;
					nativeTypeStruct2.ByRef = nativeTypeStruct.ByRef;
					nativeTypeStruct2.Pinned = nativeTypeStruct.Pinned;
					_injectedFieldTypes[(type2, attributes)] = nativeTypeStruct2.Pointer;
					value = nativeTypeStruct2.Pointer;
				}
				nativeFieldInfoStruct.Type = (Il2CppTypeStruct*)(void*)value;
				if (nativeClassPointer == IntPtr.Zero)
				{
					throw new Exception($"Type {type2} in {type}.{array[j].Name} doesn't exist in Il2Cpp");
				}
				if (IL2CPP.il2cpp_class_is_valuetype(nativeClassPointer))
				{
					uint align = 0u;
					int num3 = IL2CPP.il2cpp_class_value_size(nativeClassPointer, ref align);
					num2 += num3;
				}
				else
				{
					num2 += sizeof(Il2CppObject*);
				}
			}
			nativeClassStruct2.Fields = ptr;
			nativeClassStruct2.InstanceSize = (uint)(num2 + sizeof(InjectedClassData));
			nativeClassStruct2.ActualSize = nativeClassStruct2.InstanceSize;
			MethodInfo[] array2 = type.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).Where(IsMethodEligible).ToArray();
			int num4 = 2 + array2.Length;
			nativeClassStruct2.MethodCount = (ushort)num4;
			Il2CppMethodInfo** ptr2 = (Il2CppMethodInfo**)(void*)Marshal.AllocHGlobal(num4 * IntPtr.Size);
			nativeClassStruct2.Methods = ptr2;
			*ptr2 = ConvertStaticMethod(FinalizeDelegate, "Finalize", nativeClassStruct2);
			INativeMethodInfoStruct nativeMethodInfoStruct = UnityVersionHandler.Wrap(*ptr2);
			if (!type.IsAbstract)
			{
				ptr2[1] = ConvertStaticMethod(CreateEmptyCtor(type, array), ".ctor", nativeClassStruct2);
			}
			Dictionary<(string, int, bool), int> dictionary = new Dictionary<(string, int, bool), int>(array2.Length);
			for (int k = 0; k < array2.Length; k++)
			{
				MethodInfo methodInfo = array2[k];
				Il2CppMethodInfo* ptr3 = (ptr2[k + 2] = ConvertMethodInfo(methodInfo, nativeClassStruct2));
				if (methodInfo.IsGenericMethod)
				{
					InflatedMethodFromContextDictionary.Add((IntPtr)ptr3, (methodInfo, new Dictionary<IntPtr, IntPtr>()));
				}
				dictionary[(methodInfo.Name, methodInfo.GetParameters().Length, methodInfo.IsGenericMethod)] = k + 2;
			}
			VirtualInvokeData* ptr4 = (VirtualInvokeData*)(void*)nativeClassStruct2.VTable;
			VirtualInvokeData* ptr5 = (VirtualInvokeData*)(void*)nativeClassStruct.VTable;
			nativeClassStruct2.VtableCount = (ushort)(nativeClassStruct.VtableCount + num);
			if (nativeClassStruct2.Flags.HasFlag(Il2CppClassAttributes.TYPE_ATTRIBUTE_ABSTRACT) && IL2CPP.il2cpp_class_is_abstract((IntPtr)nativeClassStruct.Class))
			{
				nativeClassStruct2.Flags &= ~Il2CppClassAttributes.TYPE_ATTRIBUTE_ABSTRACT;
				int methodCount = nativeClassStruct.MethodCount;
				List<int> list = new List<int>();
				for (int l = 0; l < methodCount; l++)
				{
					INativeMethodInfoStruct nativeMethodInfoStruct2 = UnityVersionHandler.Wrap(nativeClassStruct.Methods[l]);
					if (nativeMethodInfoStruct2.Flags.HasFlag(Il2CppMethodFlags.METHOD_ATTRIBUTE_ABSTRACT))
					{
						string text = Marshal.PtrToStringAnsi(nativeMethodInfoStruct2.Name);
						Type[] array3 = new Type[nativeMethodInfoStruct2.ParametersCount];
						for (int m = 0; m < nativeMethodInfoStruct2.ParametersCount; m++)
						{
							Type type3 = SystemTypeFromIl2CppType(UnityVersionHandler.Wrap(nativeMethodInfoStruct2.Parameters, m).ParameterType);
							array3[m] = type3;
						}
						MethodInfo method = type.GetMethod(text, array3);
						int num5 = Array.IndexOf(array2, method);
						if (num5 < 0)
						{
							throw new ArgumentException(type.Name + " does not implement the abstract method " + text);
						}
						num5 += 2;
						list.Add(num5);
					}
				}
				int num6 = 0;
				int[] array4 = list.ToArray();
				for (int n = 0; n < nativeClassStruct2.VtableCount; n++)
				{
					if ((int)ptr5[n].methodPtr == 0)
					{
						INativeMethodInfoStruct nativeMethodInfoStruct3 = UnityVersionHandler.Wrap(ptr2[array4[num6]]);
						ptr4[n].method = ptr2[array4[num6]];
						ptr4[n].methodPtr = nativeMethodInfoStruct3.MethodPointer;
						num6++;
					}
				}
			}
			for (int num7 = 0; num7 < nativeClassStruct.VtableCount; num7++)
			{
				if (!(ptr5[num7].methodPtr == IntPtr.Zero))
				{
					ptr4[num7] = ptr5[num7];
					string text2 = Marshal.PtrToStringAnsi(UnityVersionHandler.Wrap(ptr4[num7].method).Name);
					MethodInfo method2 = type.GetMethod(text2, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					int num8 = Array.IndexOf(array2, method2);
					if (num8 > 0)
					{
						INativeMethodInfoStruct nativeMethodInfoStruct4 = UnityVersionHandler.Wrap(ptr2[num8 + 2]);
						ptr4[num7].method = ptr2[num8 + 2];
						ptr4[num7].methodPtr = nativeMethodInfoStruct4.MethodPointer;
					}
					if (text2 == "Finalize")
					{
						ptr4[num7].method = *ptr2;
						ptr4[num7].methodPtr = nativeMethodInfoStruct.MethodPointer;
					}
				}
			}
			int[] array5 = new int[il2CppInterfaceCollection.Count];
			ushort num9 = nativeClassStruct.VtableCount;
			for (int num10 = 0; num10 < il2CppInterfaceCollection.Count; num10++)
			{
				array5[num10] = num9;
				for (int num11 = 0; num11 < il2CppInterfaceCollection[num10].MethodCount; num11++)
				{
					INativeMethodInfoStruct nativeMethodInfoStruct5 = UnityVersionHandler.Wrap(il2CppInterfaceCollection[num10].Methods[num11]);
					string item = Marshal.PtrToStringAnsi(nativeMethodInfoStruct5.Name);
					if (!dictionary.TryGetValue((item, nativeMethodInfoStruct5.ParametersCount, nativeMethodInfoStruct5.IsGeneric), out var value2))
					{
						num9++;
						continue;
					}
					ptr4[(int)num9].methodPtr = UnityVersionHandler.Wrap(ptr4[(int)num9].method = ptr2[value2]).MethodPointer;
					num9++;
				}
			}
			int num12 = nativeClassStruct.InterfaceCount + il2CppInterfaceCollection.Count;
			nativeClassStruct2.InterfaceCount = (ushort)num12;
			nativeClassStruct2.ImplementedInterfaces = (Il2CppClass**)(void*)Marshal.AllocHGlobal(num12 * IntPtr.Size);
			for (int num13 = 0; num13 < nativeClassStruct.InterfaceCount; num13++)
			{
				nativeClassStruct2.ImplementedInterfaces[num13] = nativeClassStruct.ImplementedInterfaces[num13];
			}
			for (int num14 = nativeClassStruct.InterfaceCount; num14 < num12; num14++)
			{
				nativeClassStruct2.ImplementedInterfaces[num14] = il2CppInterfaceCollection[num14 - nativeClassStruct.InterfaceCount].ClassPointer;
			}
			int num15 = nativeClassStruct.InterfaceOffsetsCount + il2CppInterfaceCollection.Count;
			nativeClassStruct2.InterfaceOffsetsCount = (ushort)num15;
			nativeClassStruct2.InterfaceOffsets = (Il2CppRuntimeInterfaceOffsetPair*)(void*)Marshal.AllocHGlobal(num15 * Marshal.SizeOf<Il2CppRuntimeInterfaceOffsetPair>());
			for (int num16 = 0; num16 < nativeClassStruct.InterfaceOffsetsCount; num16++)
			{
				nativeClassStruct2.InterfaceOffsets[num16] = nativeClassStruct.InterfaceOffsets[num16];
			}
			for (int num17 = nativeClassStruct.InterfaceOffsetsCount; num17 < num15; num17++)
			{
				nativeClassStruct2.InterfaceOffsets[num17] = new Il2CppRuntimeInterfaceOffsetPair
				{
					interfaceType = il2CppInterfaceCollection[num17 - nativeClassStruct.InterfaceOffsetsCount].ClassPointer,
					offset = array5[num17 - nativeClassStruct.InterfaceOffsetsCount]
				};
			}
			int num18 = 1 + nativeClassStruct.TypeHierarchyDepth;
			nativeClassStruct2.TypeHierarchyDepth = (byte)num18;
			nativeClassStruct2.TypeHierarchy = (Il2CppClass**)(void*)Marshal.AllocHGlobal(num18 * IntPtr.Size);
			for (int num19 = 0; num19 < num18; num19++)
			{
				nativeClassStruct2.TypeHierarchy[num19] = nativeClassStruct.TypeHierarchy[num19];
			}
			nativeClassStruct2.TypeHierarchy[num18 - 1] = nativeClassStruct2.ClassPointer;
			nativeClassStruct2.ByValArg.Data = (nativeClassStruct2.ThisArg.Data = (IntPtr)InjectorHelpers.CreateClassToken(nativeClassStruct2.Pointer));
			RuntimeSpecificsStore.SetClassInfo(nativeClassStruct2.Pointer, useWeakRefs: true, wasInjected: true);
			Il2CppClassPointerStore.SetNativeClassPointer(type, nativeClassStruct2.Pointer);
			InjectorHelpers.AddTypeToLookup(type, nativeClassStruct2.Pointer);
			if (options.LogSuccess)
			{
				LogSupport.Info($"Registered mono type {type} in il2cpp domain");
			}
		}

		private static bool IsTypeSupported(Type type)
		{
			if (type.IsValueType || type == typeof(string) || type.IsGenericParameter)
			{
				return true;
			}
			if (type.IsByRef)
			{
				return IsTypeSupported(type.GetElementType());
			}
			return typeof(Il2CppObjectBase).IsAssignableFrom(type);
		}

		private static bool IsFieldEligible(FieldInfo field)
		{
			if (!field.FieldType.IsGenericType)
			{
				return false;
			}
			Type genericTypeDefinition = field.FieldType.GetGenericTypeDefinition();
			if (genericTypeDefinition != typeof(Il2CppReferenceField<>) && genericTypeDefinition != typeof(Il2CppValueField<>))
			{
				return false;
			}
			return IsTypeSupported(field.FieldType.GenericTypeArguments[0]);
		}

		private static bool IsMethodEligible(MethodInfo method)
		{
			MethodInfo method2 = method;
			if (method2.Name == "Finalize")
			{
				return false;
			}
			if (method2.IsStatic || method2.IsAbstract)
			{
				return false;
			}
			if (method2.CustomAttributes.Any((CustomAttributeData it) => typeof(HideFromIl2CppAttribute).IsAssignableFrom(it.AttributeType)))
			{
				return false;
			}
			if (method2.DeclaringType != null)
			{
				if ((from property in method2.DeclaringType.GetProperties(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
					where property.GetAccessors(nonPublic: true).Contains(method2)
					select property).Any((PropertyInfo property) => property.CustomAttributes.Any((CustomAttributeData it) => typeof(HideFromIl2CppAttribute).IsAssignableFrom(it.AttributeType))))
				{
					return false;
				}
				EventInfo[] events = method2.DeclaringType.GetEvents(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				foreach (EventInfo eventInfo in events)
				{
					if ((eventInfo.GetAddMethod(nonPublic: true) == method2 || eventInfo.GetRemoveMethod(nonPublic: true) == method2) && eventInfo.GetCustomAttribute<HideFromIl2CppAttribute>() != null)
					{
						return false;
					}
				}
			}
			if (!IsTypeSupported(method2.ReturnType))
			{
				LogSupport.Warning($"Method {method2} on type {method2.DeclaringType} has unsupported return type {method2.ReturnType}");
				return false;
			}
			ParameterInfo[] parameters = method2.GetParameters();
			foreach (ParameterInfo parameterInfo in parameters)
			{
				Type parameterType = parameterInfo.ParameterType;
				if (!IsTypeSupported(parameterType))
				{
					LogSupport.Warning($"Method {method2} on type {method2.DeclaringType} has unsupported parameter {parameterInfo} of type {parameterType}");
					return false;
				}
			}
			return true;
		}

		private unsafe static Il2CppMethodInfo* ConvertStaticMethod(VoidCtorDelegate voidCtor, string methodName, INativeClassStruct declaringClass)
		{
			INativeMethodInfoStruct nativeMethodInfoStruct = UnityVersionHandler.NewMethod();
			nativeMethodInfoStruct.Name = Marshal.StringToHGlobalAnsi(methodName);
			nativeMethodInfoStruct.Class = declaringClass.ClassPointer;
			nativeMethodInfoStruct.InvokerMethod = Marshal.GetFunctionPointerForDelegate<InvokerDelegate>(StaticVoidIntPtrInvoker);
			nativeMethodInfoStruct.MethodPointer = Marshal.GetFunctionPointerForDelegate(voidCtor);
			nativeMethodInfoStruct.Slot = ushort.MaxValue;
			nativeMethodInfoStruct.ReturnType = (Il2CppTypeStruct*)(void*)IL2CPP.il2cpp_class_get_type(Il2CppClassPointerStore<Void>.NativeClassPtr);
			nativeMethodInfoStruct.Flags = Il2CppMethodFlags.METHOD_ATTRIBUTE_PUBLIC | Il2CppMethodFlags.METHOD_ATTRIBUTE_HIDE_BY_SIG | Il2CppMethodFlags.METHOD_ATTRIBUTE_SPECIAL_NAME | Il2CppMethodFlags.METHOD_ATTRIBUTE_RT_SPECIAL_NAME;
			return nativeMethodInfoStruct.MethodInfoPointer;
		}

		private unsafe static Il2CppMethodInfo* ConvertMethodInfo(MethodInfo monoMethod, INativeClassStruct declaringClass)
		{
			INativeMethodInfoStruct nativeMethodInfoStruct = UnityVersionHandler.NewMethod();
			nativeMethodInfoStruct.Name = Marshal.StringToHGlobalAnsi(monoMethod.Name);
			nativeMethodInfoStruct.Class = declaringClass.ClassPointer;
			ParameterInfo[] parameters = monoMethod.GetParameters();
			if (parameters.Length != 0)
			{
				nativeMethodInfoStruct.ParametersCount = (byte)parameters.Length;
				Il2CppParameterInfo*[] array = UnityVersionHandler.NewMethodParameterArray(parameters.Length);
				nativeMethodInfoStruct.Parameters = array[0];
				for (int i = 0; i < parameters.Length; i++)
				{
					ParameterInfo parameterInfo = parameters[i];
					INativeParameterInfoStruct nativeParameterInfoStruct = UnityVersionHandler.Wrap(array[i]);
					if (UnityVersionHandler.ParameterInfoHasNamePosToken())
					{
						nativeParameterInfoStruct.Name = Marshal.StringToHGlobalAnsi(parameterInfo.Name);
						nativeParameterInfoStruct.Position = i;
						nativeParameterInfoStruct.Token = 0u;
					}
					Type parameterType = parameterInfo.ParameterType;
					if (!parameterType.IsGenericParameter)
					{
						if (parameterType.IsByRef)
						{
							Type elementType = parameterType.GetElementType();
							if (!elementType.IsGenericParameter)
							{
								INativeTypeStruct nativeTypeStruct = UnityVersionHandler.Wrap((Il2CppTypeStruct*)(void*)IL2CPP.il2cpp_class_get_type(Il2CppClassPointerStore.GetNativeClassPointer(elementType)));
								INativeTypeStruct nativeTypeStruct2 = UnityVersionHandler.NewType();
								nativeTypeStruct2.Data = nativeTypeStruct.Data;
								nativeTypeStruct2.Attrs = nativeTypeStruct.Attrs;
								nativeTypeStruct2.Type = nativeTypeStruct.Type;
								nativeTypeStruct2.ByRef = true;
								nativeTypeStruct2.Pinned = nativeTypeStruct.Pinned;
								nativeParameterInfoStruct.ParameterType = nativeTypeStruct2.TypePointer;
							}
							else
							{
								INativeTypeStruct nativeTypeStruct3 = UnityVersionHandler.NewType();
								nativeTypeStruct3.Type = Il2CppTypeEnum.IL2CPP_TYPE_MVAR;
								nativeTypeStruct3.ByRef = true;
								nativeParameterInfoStruct.ParameterType = nativeTypeStruct3.TypePointer;
							}
						}
						else
						{
							nativeParameterInfoStruct.ParameterType = (Il2CppTypeStruct*)(void*)IL2CPP.il2cpp_class_get_type(Il2CppClassPointerStore.GetNativeClassPointer(parameterType));
						}
					}
					else
					{
						INativeTypeStruct nativeTypeStruct4 = UnityVersionHandler.NewType();
						nativeTypeStruct4.Type = Il2CppTypeEnum.IL2CPP_TYPE_MVAR;
						nativeParameterInfoStruct.ParameterType = nativeTypeStruct4.TypePointer;
					}
				}
			}
			if (monoMethod.IsGenericMethod)
			{
				if (monoMethod.ContainsGenericParameters)
				{
					nativeMethodInfoStruct.IsGeneric = true;
				}
				else
				{
					nativeMethodInfoStruct.IsInflated = true;
				}
			}
			if (!monoMethod.ContainsGenericParameters)
			{
				nativeMethodInfoStruct.InvokerMethod = Marshal.GetFunctionPointerForDelegate(GetOrCreateInvoker(monoMethod));
				nativeMethodInfoStruct.MethodPointer = Marshal.GetFunctionPointerForDelegate(GetOrCreateTrampoline(monoMethod));
			}
			nativeMethodInfoStruct.Slot = ushort.MaxValue;
			if (!monoMethod.ReturnType.IsGenericParameter)
			{
				nativeMethodInfoStruct.ReturnType = (Il2CppTypeStruct*)(void*)IL2CPP.il2cpp_class_get_type(Il2CppClassPointerStore.GetNativeClassPointer(monoMethod.ReturnType));
			}
			else
			{
				INativeTypeStruct nativeTypeStruct5 = UnityVersionHandler.NewType();
				nativeTypeStruct5.Type = Il2CppTypeEnum.IL2CPP_TYPE_MVAR;
				nativeMethodInfoStruct.ReturnType = nativeTypeStruct5.TypePointer;
			}
			nativeMethodInfoStruct.Flags = Il2CppMethodFlags.METHOD_ATTRIBUTE_PUBLIC | Il2CppMethodFlags.METHOD_ATTRIBUTE_HIDE_BY_SIG;
			return nativeMethodInfoStruct.MethodInfoPointer;
		}

		private static VoidCtorDelegate CreateEmptyCtor(Type targetType, FieldInfo[] fieldsToInitialize)
		{
			DynamicMethod dynamicMethod = new DynamicMethod("FromIl2CppCtorDelegate", MethodAttributes.Public | MethodAttributes.Static, CallingConventions.Standard, typeof(void), new Type[1] { typeof(IntPtr) }, targetType, skipVisibility: true);
			ILGenerator iLGenerator = dynamicMethod.GetILGenerator();
			ConstructorInfo constructor = targetType.GetConstructor(new Type[1] { typeof(IntPtr) });
			if (constructor != null)
			{
				iLGenerator.Emit(OpCodes.Ldarg_0);
				iLGenerator.Emit(OpCodes.Newobj, constructor);
			}
			else
			{
				LocalBuilder local = iLGenerator.DeclareLocal(targetType);
				iLGenerator.Emit(OpCodes.Ldtoken, targetType);
				iLGenerator.Emit(OpCodes.Call, typeof(Type).GetMethod("GetTypeFromHandle", BindingFlags.Static | BindingFlags.Public));
				iLGenerator.Emit(OpCodes.Call, typeof(FormatterServices).GetMethod("GetUninitializedObject", BindingFlags.Static | BindingFlags.Public));
				iLGenerator.Emit(OpCodes.Stloc, local);
				iLGenerator.Emit(OpCodes.Ldloc, local);
				iLGenerator.Emit(OpCodes.Ldarg_0);
				iLGenerator.Emit(OpCodes.Call, typeof(Il2CppObjectBase).GetMethod("CreateGCHandle", BindingFlags.Instance | BindingFlags.NonPublic));
				iLGenerator.Emit(OpCodes.Ldloc, local);
				iLGenerator.Emit(OpCodes.Ldc_I4_1);
				iLGenerator.Emit(OpCodes.Stfld, typeof(Il2CppObjectBase).GetField("isWrapped", BindingFlags.Instance | BindingFlags.NonPublic));
				iLGenerator.Emit(OpCodes.Ldloc, local);
				iLGenerator.Emit(OpCodes.Call, targetType.GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, Type.EmptyTypes, Array.Empty<ParameterModifier>()));
				iLGenerator.Emit(OpCodes.Ldloc, local);
			}
			foreach (FieldInfo fieldInfo in fieldsToInitialize)
			{
				iLGenerator.Emit(OpCodes.Dup);
				iLGenerator.Emit(OpCodes.Dup);
				iLGenerator.Emit(OpCodes.Ldstr, fieldInfo.Name);
				iLGenerator.Emit(OpCodes.Newobj, fieldInfo.FieldType.GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[2]
				{
					typeof(Il2CppObjectBase),
					typeof(string)
				}, Array.Empty<ParameterModifier>()));
				iLGenerator.Emit(OpCodes.Stfld, fieldInfo);
			}
			iLGenerator.Emit(OpCodes.Call, typeof(ClassInjector).GetMethod("ProcessNewObject"));
			iLGenerator.Emit(OpCodes.Ret);
			VoidCtorDelegate obj = (VoidCtorDelegate)dynamicMethod.CreateDelegate(typeof(VoidCtorDelegate));
			GCHandle.Alloc(obj);
			return obj;
		}

		public static void Finalize(IntPtr ptr)
		{
			GCHandle.FromIntPtr(ClassInjectorBase.GetGcHandlePtrFromIl2CppObject(ptr)).Free();
		}

		private static InvokerDelegate GetOrCreateInvoker(MethodInfo monoMethod)
		{
			return InvokerCache.GetOrAdd(ExtractSignature(monoMethod), (string _, MethodInfo monoMethodInner) => CreateInvoker(monoMethodInner), monoMethod);
		}

		private static Delegate GetOrCreateTrampoline(MethodInfo monoMethod)
		{
			return CreateTrampoline(monoMethod);
		}

		private unsafe static InvokerDelegate CreateInvoker(MethodInfo monoMethod)
		{
			Type[] parameterTypes = new Type[4]
			{
				typeof(IntPtr),
				typeof(Il2CppMethodInfo*),
				typeof(IntPtr),
				typeof(IntPtr*)
			};
			DynamicMethod dynamicMethod = new DynamicMethod("Invoker_" + ExtractSignature(monoMethod), MethodAttributes.Public | MethodAttributes.Static, CallingConventions.Standard, typeof(IntPtr), parameterTypes, monoMethod.DeclaringType, skipVisibility: true);
			ILGenerator iLGenerator = dynamicMethod.GetILGenerator();
			iLGenerator.Emit(OpCodes.Ldarg_2);
			for (int i = 0; i < monoMethod.GetParameters().Length; i++)
			{
				ParameterInfo parameterInfo = monoMethod.GetParameters()[i];
				iLGenerator.Emit(OpCodes.Ldarg_3);
				iLGenerator.Emit(OpCodes.Ldc_I4, i * IntPtr.Size);
				iLGenerator.Emit(OpCodes.Add_Ovf_Un);
				Type type = parameterInfo.ParameterType.NativeType();
				iLGenerator.Emit(OpCodes.Ldobj, typeof(IntPtr));
				if (type != typeof(IntPtr))
				{
					iLGenerator.Emit(OpCodes.Ldobj, type);
				}
			}
			iLGenerator.Emit(OpCodes.Ldarg_0);
			iLGenerator.EmitCalli(OpCodes.Calli, CallingConvention.Cdecl, monoMethod.ReturnType.NativeType(), new Type[1] { typeof(IntPtr) }.Concat(from it in monoMethod.GetParameters()
				select it.ParameterType.NativeType()).ToArray());
			if (monoMethod.ReturnType == typeof(void))
			{
				iLGenerator.Emit(OpCodes.Ldc_I4_0);
				iLGenerator.Emit(OpCodes.Conv_I);
			}
			else if (monoMethod.ReturnType.IsValueType)
			{
				LocalBuilder local = iLGenerator.DeclareLocal(monoMethod.ReturnType);
				iLGenerator.Emit(OpCodes.Stloc, local);
				FieldInfo field = typeof(Il2CppClassPointerStore<>).MakeGenericType(monoMethod.ReturnType).GetField("NativeClassPtr");
				iLGenerator.Emit(OpCodes.Ldsfld, field);
				iLGenerator.Emit(OpCodes.Ldloca, local);
				iLGenerator.Emit(OpCodes.Call, typeof(IL2CPP).GetMethod("il2cpp_value_box"));
			}
			iLGenerator.Emit(OpCodes.Ret);
			return (InvokerDelegate)dynamicMethod.CreateDelegate(typeof(InvokerDelegate));
		}

		private unsafe static IntPtr StaticVoidIntPtrInvoker(IntPtr methodPointer, Il2CppMethodInfo* methodInfo, IntPtr obj, IntPtr* args)
		{
			Marshal.GetDelegateForFunctionPointer<VoidCtorDelegate>(methodPointer)(obj);
			return IntPtr.Zero;
		}

		private unsafe static Delegate CreateTrampoline(MethodInfo monoMethod)
		{
			Type[] parameterTypes = new Type[1] { typeof(IntPtr) }.Concat((from it in monoMethod.GetParameters()
				select it.ParameterType.NativeType()).Concat(new Type[1] { typeof(Il2CppMethodInfo*) })).ToArray();
			Type[] array = new Type[1] { monoMethod.DeclaringType }.Concat(from it in monoMethod.GetParameters()
				select it.ParameterType).ToArray();
			DynamicMethod dynamicMethod = new DynamicMethod("Trampoline_" + ExtractSignature(monoMethod) + monoMethod.DeclaringType?.ToString() + monoMethod.Name, MethodAttributes.Public | MethodAttributes.Static, CallingConventions.Standard, monoMethod.ReturnType.NativeType(), parameterTypes, monoMethod.DeclaringType, skipVisibility: true);
			Type orCreateDelegateType = DelegateSupport.GetOrCreateDelegateType(new DelegateSupport.MethodSignature(monoMethod, hasThis: true), monoMethod);
			ILGenerator body = dynamicMethod.GetILGenerator();
			body.BeginExceptionBlock();
			body.Emit(OpCodes.Ldarg_0);
			body.Emit(OpCodes.Call, typeof(ClassInjectorBase).GetMethod("GetMonoObjectFromIl2CppPointer"));
			body.Emit(OpCodes.Castclass, monoMethod.DeclaringType);
			LocalBuilder[] array2 = new LocalBuilder[array.Length];
			for (int i = 1; i < array.Length; i++)
			{
				Type type2 = array[i];
				if (type2.IsSubclassOf(typeof(ValueType)))
				{
					body.Emit(OpCodes.Ldc_I8, Il2CppClassPointerStore.GetNativeClassPointer(type2).ToInt64());
					body.Emit(OpCodes.Conv_I);
					body.Emit(Environment.Is64BitProcess ? OpCodes.Ldarg : OpCodes.Ldarga_S, i);
					body.Emit(OpCodes.Call, typeof(IL2CPP).GetMethod("il2cpp_value_box"));
				}
				else
				{
					body.Emit(OpCodes.Ldarg, i);
				}
				if (!type2.IsValueType)
				{
					if (type2.IsByRef)
					{
						Type elementType = type2.GetElementType();
						array2[i] = body.DeclareLocal(elementType);
						body.Emit(OpCodes.Ldind_I);
						HandleTypeConversion(elementType);
						body.Emit(OpCodes.Stloc, array2[i]);
						body.Emit(OpCodes.Ldloca, array2[i]);
					}
					else
					{
						HandleTypeConversion(type2);
					}
				}
			}
			body.Emit(OpCodes.Call, monoMethod);
			LocalBuilder localBuilder = null;
			if (monoMethod.ReturnType != typeof(void))
			{
				localBuilder = body.DeclareLocal(monoMethod.ReturnType);
				body.Emit(OpCodes.Stloc, localBuilder);
			}
			for (int j = 1; j < array.Length; j++)
			{
				LocalBuilder localBuilder2 = array2[j];
				if (localBuilder2 != null)
				{
					body.Emit(OpCodes.Ldarg_S, j);
					body.Emit(OpCodes.Ldloc, localBuilder2);
					Type elementType2 = array[j].GetElementType();
					if (elementType2 == typeof(string))
					{
						body.Emit(OpCodes.Call, typeof(IL2CPP).GetMethod("ManagedStringToIl2Cpp"));
					}
					else if (!elementType2.IsValueType)
					{
						body.Emit(OpCodes.Call, typeof(IL2CPP).GetMethod("Il2CppObjectBaseToPtr"));
					}
					body.Emit(InjectorHelpers.StIndOpcodes.TryGetValue(elementType2, out var value) ? value : OpCodes.Stind_I);
				}
			}
			if (localBuilder != null)
			{
				body.Emit(OpCodes.Ldloc, localBuilder);
				if (monoMethod.ReturnType == typeof(string))
				{
					body.Emit(OpCodes.Call, typeof(IL2CPP).GetMethod("ManagedStringToIl2Cpp"));
				}
				else if (!monoMethod.ReturnType.IsValueType)
				{
					body.Emit(OpCodes.Call, typeof(IL2CPP).GetMethod("Il2CppObjectBaseToPtr"));
				}
			}
			body.Emit(OpCodes.Ret);
			LocalBuilder local = body.DeclareLocal(typeof(Exception));
			body.BeginCatchBlock(typeof(Exception));
			body.Emit(OpCodes.Stloc, local);
			body.Emit(OpCodes.Ldstr, "Exception in IL2CPP-to-Managed trampoline, not passing it to il2cpp: ");
			body.Emit(OpCodes.Ldloc, local);
			body.Emit(OpCodes.Callvirt, typeof(object).GetMethod("ToString"));
			body.Emit(OpCodes.Call, typeof(string).GetMethod("Concat", new Type[2]
			{
				typeof(string),
				typeof(string)
			}));
			body.Emit(OpCodes.Call, typeof(LogSupport).GetMethod("Error"));
			body.EndExceptionBlock();
			if (monoMethod.ReturnType != typeof(void))
			{
				if (monoMethod.ReturnType.IsValueType)
				{
					if (monoMethod.ReturnType.IsPrimitive)
					{
						if (monoMethod.ReturnType == typeof(float))
						{
							body.Emit(OpCodes.Ldc_R4, 0);
						}
						else if (monoMethod.ReturnType == typeof(double))
						{
							body.Emit(OpCodes.Ldc_R8, 0);
						}
						else
						{
							body.Emit(OpCodes.Ldc_I4_0);
							if (monoMethod.ReturnType == typeof(long) || monoMethod.ReturnType == typeof(ulong))
							{
								body.Emit(OpCodes.Conv_I8);
							}
						}
					}
					else
					{
						LocalBuilder local2 = body.DeclareLocal(monoMethod.ReturnType);
						body.Emit(OpCodes.Ldloca_S, local2);
						body.Emit(OpCodes.Initobj, monoMethod.ReturnType);
						body.Emit(OpCodes.Ldloc_S, local2);
					}
				}
				else
				{
					body.Emit(OpCodes.Ldc_I4_0);
					body.Emit(OpCodes.Conv_I);
				}
			}
			body.Emit(OpCodes.Ret);
			Delegate @delegate = dynamicMethod.CreateDelegate(orCreateDelegateType);
			GCHandle.Alloc(@delegate);
			return @delegate;
			void HandleTypeConversion(Type type)
			{
				if (type == typeof(string))
				{
					body.Emit(OpCodes.Call, typeof(IL2CPP).GetMethod("Il2CppStringToManaged"));
				}
				else if (type.IsSubclassOf(typeof(Il2CppObjectBase)))
				{
					Label label = body.DefineLabel();
					Label label2 = body.DefineLabel();
					body.Emit(OpCodes.Dup);
					body.Emit(OpCodes.Brfalse, label);
					body.Emit(OpCodes.Newobj, type.GetConstructors().FirstOrDefault(delegate(ConstructorInfo ci)
					{
						ParameterInfo[] parameters = ci.GetParameters();
						return parameters.Length == 1 && parameters[0].ParameterType == typeof(IntPtr);
					}));
					body.Emit(OpCodes.Br, label2);
					body.MarkLabel(label);
					body.Emit(OpCodes.Pop);
					body.Emit(OpCodes.Ldnull);
					body.MarkLabel(label2);
				}
			}
		}

		private static string ExtractSignature(MethodInfo monoMethod)
		{
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.Append(monoMethod.ReturnType.NativeType().Name);
			stringBuilder.Append(monoMethod.IsStatic ? "" : "This");
			ParameterInfo[] parameters = monoMethod.GetParameters();
			foreach (ParameterInfo parameterInfo in parameters)
			{
				stringBuilder.Append(parameterInfo.ParameterType.NativeType().Name);
			}
			return stringBuilder.ToString();
		}

		private static Type NativeType(this Type type)
		{
			if (!type.IsValueType)
			{
				return typeof(IntPtr);
			}
			return type;
		}

		private unsafe static void HookGenericMethodGetMethod()
		{
			IntPtr il2CppExport = InjectorHelpers.GetIl2CppExport("il2cpp_object_get_virtual_method");
			LogSupport.Trace($"il2cpp_object_get_virtual_method entry address: {il2CppExport}");
			IntPtr intPtr = XrefScannerLowLevel.JumpTargets(il2CppExport).Single();
			LogSupport.Trace($"Xref scan target 1: {intPtr}");
			IntPtr intPtr2 = XrefScannerLowLevel.JumpTargets(intPtr).Last();
			LogSupport.Trace($"Xref scan target 2: {intPtr2}");
			if (!(intPtr2 == IntPtr.Zero))
			{
				List<IntPtr> list = XrefScannerLowLevel.JumpTargets(intPtr2).Take(2).ToList();
				if (list.Count == 1)
				{
					intPtr2 = list[0];
				}
				ourOriginalGenericGetMethod = Detour.Detour<GenericGetMethodDelegate>(intPtr2, GenericGetMethodPatch);
				LogSupport.Trace("il2cpp_class_from_il2cpp_type patched");
			}
		}

		private static Type RewriteType(Type type)
		{
			if (type.IsValueType && !type.IsEnum)
			{
				return type;
			}
			if (type.IsArray)
			{
				Type elementType = type.GetElementType();
				if (elementType.FullName == "System.String")
				{
					return typeof(Il2CppStringArray);
				}
				Type type2 = RewriteType(elementType);
				if (elementType.IsGenericParameter)
				{
					return typeof(Il2CppArrayBase<>).MakeGenericType(type2);
				}
				return (type2.IsValueType ? typeof(Il2CppStructArray<>) : typeof(Il2CppReferenceArray<>)).MakeGenericType(type2);
			}
			if (type.FullName.StartsWith("System"))
			{
				string fullName = "Il2Cpp" + type.FullName;
				Type type3 = Type.GetType(fullName + ", Il2Cpp" + type.Assembly.GetName().Name, throwOnError: false);
				if (type3 != null)
				{
					return type3;
				}
				return (from a in AppDomain.CurrentDomain.GetAssemblies()
					select a.GetType(fullName, throwOnError: false)).First((Type t) => t != null);
			}
			return type;
		}

		private unsafe static Type SystemTypeFromIl2CppType(Il2CppTypeStruct* typePointer)
		{
			INativeClassStruct nativeClassStruct = UnityVersionHandler.Wrap(InjectorHelpers.ClassFromIl2CppType(typePointer));
			INativeAssemblyStruct nativeAssemblyStruct = UnityVersionHandler.Wrap(UnityVersionHandler.Wrap(nativeClassStruct.Image).Assembly);
			StringBuilder stringBuilder = new StringBuilder();
			string value = Marshal.PtrToStringAnsi(nativeClassStruct.Namespace);
			if (!string.IsNullOrEmpty(value))
			{
				stringBuilder.Append(value);
				stringBuilder.Append('.');
			}
			stringBuilder.Append(Marshal.PtrToStringAnsi(nativeClassStruct.Name));
			stringBuilder.Append(", ");
			stringBuilder.Append(Marshal.PtrToStringAnsi(nativeAssemblyStruct.Name.Name));
			return RewriteType(Type.GetType(stringBuilder.ToString()) ?? throw new NullReferenceException($"Couldn't find System.Type for Il2Cpp type: {stringBuilder}"));
		}

		private unsafe static Il2CppMethodInfo* GenericGetMethodPatch(Il2CppGenericMethod* gmethod, bool copyMethodPtr)
		{
			if (InflatedMethodFromContextDictionary.TryGetValue((IntPtr)gmethod->methodDefinition, out (MethodInfo, Dictionary<IntPtr, IntPtr>) value))
			{
				Il2CppGenericInst* method_inst = gmethod->context.method_inst;
				if (value.Item2.TryGetValue((IntPtr)method_inst, out var value2))
				{
					return (Il2CppMethodInfo*)(void*)value2;
				}
				Type[] array = new Type[method_inst->type_argc];
				for (int i = 0; i < method_inst->type_argc; i++)
				{
					array[i] = SystemTypeFromIl2CppType(method_inst->type_argv[i]);
				}
				MethodInfo methodInfo = value.Item1.MakeGenericMethod(array);
				LogSupport.Trace("Inflated method: " + methodInfo.Name);
				value2 = (IntPtr)ConvertMethodInfo(methodInfo, UnityVersionHandler.Wrap(UnityVersionHandler.Wrap(gmethod->methodDefinition).Class));
				value.Item2.Add((IntPtr)method_inst, value2);
				return (Il2CppMethodInfo*)(void*)value2;
			}
			return ourOriginalGenericGetMethod(gmethod, copyMethodPtr);
		}
	}
	public interface IManagedDetour
	{
		T Detour<T>(IntPtr from, T to) where T : Delegate;
	}
	public static class EnumInjector
	{
		private static readonly ConcurrentDictionary<IntPtr, IntPtr> s_DefaultValueOverrides = new ConcurrentDictionary<IntPtr, IntPtr>();

		private static readonly IntPtr value__Cached = Marshal.StringToHGlobalAnsi("value__");

		internal unsafe static bool GetDefaultValueOverride(Il2CppFieldInfo* fieldInfo, out IntPtr defaultValueBlob)
		{
			return s_DefaultValueOverrides.TryGetValue((IntPtr)fieldInfo, out defaultValueBlob);
		}

		public static void InjectEnumValues<TEnum>(Dictionary<string, object> valuesToAdd) where TEnum : Enum
		{
			InjectEnumValues(typeof(TEnum), valuesToAdd);
		}

		public unsafe static void InjectEnumValues(Type type, Dictionary<string, object> valuesToAdd)
		{
			if (type == null)
			{
				throw new ArgumentException("Type argument cannot be null");
			}
			if (!type.IsEnum)
			{
				throw new ArgumentException("Type argument needs to be an enum");
			}
			IntPtr nativeClassPointer = Il2CppClassPointerStore.GetNativeClassPointer(type);
			if (nativeClassPointer == IntPtr.Zero)
			{
				throw new ArgumentException("Type needs to be an Il2Cpp enum");
			}
			InjectorHelpers.Setup();
			InjectorHelpers.ClassInit((Il2CppClass*)(void*)nativeClassPointer);
			INativeClassStruct nativeClassStruct = UnityVersionHandler.Wrap((Il2CppClass*)(void*)nativeClassPointer);
			int num = nativeClassStruct.FieldCount + valuesToAdd.Count;
			Il2CppFieldInfo* ptr = (Il2CppFieldInfo*)(void*)Marshal.AllocHGlobal(num * UnityVersionHandler.FieldInfoSize());
			int i;
			for (i = 0; i < nativeClassStruct.FieldCount; i++)
			{
				int num2 = i * UnityVersionHandler.FieldInfoSize();
				INativeFieldInfoStruct nativeFieldInfoStruct = UnityVersionHandler.Wrap(nativeClassStruct.Fields + num2);
				INativeFieldInfoStruct nativeFieldInfoStruct2 = UnityVersionHandler.Wrap(ptr + num2);
				nativeFieldInfoStruct2.Name = nativeFieldInfoStruct.Name;
				nativeFieldInfoStruct2.Type = nativeFieldInfoStruct.Type;
				nativeFieldInfoStruct2.Parent = nativeFieldInfoStruct.Parent;
				nativeFieldInfoStruct2.Offset = nativeFieldInfoStruct.Offset;
				if (s_DefaultValueOverrides.TryRemove((IntPtr)nativeFieldInfoStruct.FieldInfoPointer, out var value))
				{
					s_DefaultValueOverrides[(IntPtr)nativeFieldInfoStruct2.FieldInfoPointer] = value;
				}
			}
			INativeTypeStruct byValArg = UnityVersionHandler.Wrap(nativeClassStruct.ElementClass).ByValArg;
			foreach (KeyValuePair<string, object> item in valuesToAdd)
			{
				int num3 = i * UnityVersionHandler.FieldInfoSize();
				INativeFieldInfoStruct nativeFieldInfoStruct3 = UnityVersionHandler.Wrap(ptr + num3);
				nativeFieldInfoStruct3.Name = Marshal.StringToHGlobalAnsi(item.Key);
				nativeFieldInfoStruct3.Type = byValArg.TypePointer;
				nativeFieldInfoStruct3.Parent = nativeClassStruct.ClassPointer;
				nativeFieldInfoStruct3.Offset = 0;
				CreateOrUpdateFieldDefaultValue(nativeFieldInfoStruct3.FieldInfoPointer, byValArg.TypePointer, item.Value);
				i++;
			}
			nativeClassStruct.FieldCount = (ushort)num;
			nativeClassStruct.Fields = ptr;
			RuntimeType val = ((Il2CppObjectBase)(object)Il2CppType.TypeFromPointer(nativeClassPointer)).TryCast<RuntimeType>();
			if (val != (RuntimeType)null)
			{
				val.GenericCache = null;
			}
		}

		private static int GetEnumElementSize(Il2CppTypeEnum type)
		{
			return type switch
			{
				Il2CppTypeEnum.IL2CPP_TYPE_I1 => 1, 
				Il2CppTypeEnum.IL2CPP_TYPE_U1 => 1, 
				Il2CppTypeEnum.IL2CPP_TYPE_CHAR => 2, 
				Il2CppTypeEnum.IL2CPP_TYPE_I2 => 2, 
				Il2CppTypeEnum.IL2CPP_TYPE_U2 => 2, 
				Il2CppTypeEnum.IL2CPP_TYPE_I4 => 4, 
				Il2CppTypeEnum.IL2CPP_TYPE_U4 => 4, 
				Il2CppTypeEnum.IL2CPP_TYPE_I8 => 8, 
				Il2CppTypeEnum.IL2CPP_TYPE_U8 => 8, 
				_ => throw new ArgumentException($"The type provided {type} is invalid"), 
			};
		}

		private static IntPtr AllocateNewDefaultValueBlob(Il2CppTypeEnum type)
		{
			int enumElementSize = GetEnumElementSize(type);
			IntPtr result = Marshal.AllocHGlobal(enumElementSize);
			LogSupport.Trace($"Allocated default value blob at 0x{result.ToInt64():X2} of {enumElementSize} for {type}");
			return result;
		}

		private unsafe static IntPtr CreateOrUpdateFieldDefaultValue(Il2CppFieldInfo* field, Il2CppTypeStruct* type, object value)
		{
			Il2CppTypeEnum type2 = UnityVersionHandler.Wrap(type).Type;
			if (!GetDefaultValueOverride(field, out var defaultValueBlob))
			{
				defaultValueBlob = AllocateNewDefaultValueBlob(type2);
				s_DefaultValueOverrides[(IntPtr)field] = defaultValueBlob;
			}
			SetFieldDefaultValue(defaultValueBlob, type2, value);
			return defaultValueBlob;
		}

		private unsafe static void SetFieldDefaultValue(IntPtr blob, Il2CppTypeEnum type, object value)
		{
			long num = Convert.ToInt64(value);
			switch (type)
			{
			case Il2CppTypeEnum.IL2CPP_TYPE_I1:
				*(sbyte*)(void*)blob = (sbyte)num;
				break;
			case Il2CppTypeEnum.IL2CPP_TYPE_U1:
				*(byte*)(void*)blob = (byte)num;
				break;
			case Il2CppTypeEnum.IL2CPP_TYPE_CHAR:
				*(ushort*)(void*)blob = (ushort)num;
				break;
			case Il2CppTypeEnum.IL2CPP_TYPE_I2:
				*(short*)(void*)blob = (short)num;
				break;
			case Il2CppTypeEnum.IL2CPP_TYPE_U2:
				*(ushort*)(void*)blob = (ushort)num;
				break;
			case Il2CppTypeEnum.IL2CPP_TYPE_I4:
				*(int*)(void*)blob = (int)num;
				break;
			case Il2CppTypeEnum.IL2CPP_TYPE_U4:
				*(int*)(void*)blob = (int)num;
				break;
			case Il2CppTypeEnum.IL2CPP_TYPE_I8:
				*(long*)(void*)blob = num;
				break;
			case Il2CppTypeEnum.IL2CPP_TYPE_U8:
				*(long*)(void*)blob = num;
				break;
			default:
				throw new ArgumentException($"The type provided {type} is invalid");
			}
		}

		public static void RegisterEnumInIl2Cpp<TEnum>(bool logSuccess = true) where TEnum : Enum
		{
			RegisterEnumInIl2Cpp(typeof(TEnum), logSuccess);
		}

		public unsafe static void RegisterEnumInIl2Cpp(Type type, bool logSuccess = true)
		{
			if (type == null)
			{
				throw new ArgumentException("Type argument cannot be null");
			}
			if (!type.IsEnum)
			{
				throw new ArgumentException("Type argument needs to be an enum");
			}
			if (!(Il2CppClassPointerStore.GetNativeClassPointer(type) != IntPtr.Zero))
			{
				InjectorHelpers.Setup();
				INativeClassStruct nativeClassStruct = UnityVersionHandler.Wrap((Il2CppClass*)(void*)Il2CppClassPointerStore<Enum>.NativeClassPtr);
				InjectorHelpers.ClassInit(nativeClassStruct.ClassPointer);
				INativeClassStruct nativeClassStruct2 = UnityVersionHandler.NewClass(nativeClassStruct.VtableCount);
				INativeClassStruct nativeClassStruct3 = UnityVersionHandler.Wrap((Il2CppClass*)(void*)Il2CppClassPointerStore.GetNativeClassPointer(Enum.GetUnderlyingType(type)));
				nativeClassStruct2.Image = InjectorHelpers.InjectedImage.ImagePointer;
				nativeClassStruct2.Class = (nativeClassStruct2.CastClass = (nativeClassStruct2.ElementClass = nativeClassStruct3.ClassPointer));
				nativeClassStruct2.Parent = nativeClassStruct.ClassPointer;
				nativeClassStruct2.ActualSize = (nativeClassStruct2.InstanceSize = (uint)(nativeClassStruct.InstanceSize + GetEnumElementSize(nativeClassStruct3.ByValArg.Type)));
				nativeClassStruct2.NativeSize = -1;
				nativeClassStruct2.ValueType = true;
				nativeClassStruct2.EnumType = true;
				nativeClassStruct2.Initialized = true;
				nativeClassStruct2.InitializedAndNoError = true;
				nativeClassStruct2.SizeInited = true;
				nativeClassStruct2.HasFinalize = true;
				nativeClassStruct2.IsVtableInitialized = true;
				nativeClassStruct2.Name = Marshal.StringToHGlobalAnsi(type.Name);
				nativeClassStruct2.Namespace = Marshal.StringToHGlobalAnsi(type.Namespace ?? string.Empty);
				long num = InjectorHelpers.CreateClassToken(nativeClassStruct2.Pointer);
				nativeClassStruct2.ThisArg.Data = (nativeClassStruct2.ByValArg.Data = (IntPtr)num);
				nativeClassStruct2.ThisArg.Type = (nativeClassStruct2.ByValArg.Type = Il2CppTypeEnum.IL2CPP_TYPE_VALUETYPE);
				nativeClassStruct2.Flags = (Il2CppClassAttributes)type.Attributes;
				nativeClassStruct2.VtableCount = nativeClassStruct.VtableCount;
				VirtualInvokeData* ptr = (VirtualInvokeData*)(void*)nativeClassStruct2.VTable;
				VirtualInvokeData* ptr2 = (VirtualInvokeData*)(void*)nativeClassStruct.VTable;
				for (int i = 0; i < nativeClassStruct.VtableCount; i++)
				{
					ptr[i] = ptr2[i];
				}
				Array values = Enum.GetValues(type);
				string[] names = Enum.GetNames(type);
				nativeClassStruct2.FieldCount = (ushort)(values.Length + 1);
				Il2CppFieldInfo* ptr3 = (Il2CppFieldInfo*)(void*)Marshal.AllocHGlobal(nativeClassStruct2.FieldCount * UnityVersionHandler.FieldInfoSize());
				INativeFieldInfoStruct nativeFieldInfoStruct = UnityVersionHandler.Wrap(ptr3);
				nativeFieldInfoStruct.Name = value__Cached;
				nativeFieldInfoStruct.Parent = nativeClassStruct2.ClassPointer;
				nativeFieldInfoStruct.Offset = (int)nativeClassStruct.InstanceSize;
				INativeTypeStruct nativeTypeStruct = UnityVersionHandler.NewType();
				nativeTypeStruct.Data = nativeClassStruct3.ThisArg.Data;
				nativeTypeStruct.Attrs = 1541;
				nativeTypeStruct.Type = nativeClassStruct3.ThisArg.Type;
				nativeTypeStruct.ByRef = nativeClassStruct3.ThisArg.ByRef;
				nativeTypeStruct.Pinned = nativeClassStruct3.ThisArg.Pinned;
				nativeFieldInfoStruct.Type = nativeTypeStruct.TypePointer;
				INativeTypeStruct nativeTypeStruct2 = UnityVersionHandler.NewType();
				nativeTypeStruct2.Data = nativeClassStruct2.ThisArg.Data;
				nativeTypeStruct2.Attrs = 32869;
				nativeTypeStruct2.Type = Il2CppTypeEnum.IL2CPP_TYPE_VALUETYPE;
				nativeTypeStruct2.ByRef = false;
				nativeTypeStruct2.Pinned = false;
				for (int j = 1; j < nativeClassStruct2.FieldCount; j++)
				{
					object value = values.GetValue(j - 1);
					INativeFieldInfoStruct nativeFieldInfoStruct2 = UnityVersionHandler.Wrap(ptr3 + j * UnityVersionHandler.FieldInfoSize());
					nativeFieldInfoStruct2.Name = Marshal.StringToHGlobalAnsi(names[j - 1]);
					nativeFieldInfoStruct2.Type = nativeTypeStruct2.TypePointer;
					nativeFieldInfoStruct2.Parent = nativeClassStruct2.ClassPointer;
					nativeFieldInfoStruct2.Offset = 0;
					CreateOrUpdateFieldDefaultValue(nativeFieldInfoStruct2.FieldInfoPointer, nativeClassStruct3.ThisArg.TypePointer, value);
				}
				nativeClassStruct2.Fields = ptr3;
				nativeClassStruct2.TypeHierarchyDepth = (byte)(1 + nativeClassStruct.TypeHierarchyDepth);
				nativeClassStruct2.TypeHierarchy = (Il2CppClass**)(void*)Marshal.AllocHGlobal(nativeClassStruct2.TypeHierarchyDepth * sizeof(void*));
				for (int k = 0; k < nativeClassStruct2.TypeHierarchyDepth; k++)
				{
					nativeClassStruct2.TypeHierarchy[k] = nativeClassStruct.TypeHierarchy[k];
				}
				nativeClassStruct2.TypeHierarchy[nativeClassStruct2.TypeHierarchyDepth - 1] = nativeClassStruct2.ClassPointer;
				RuntimeSpecificsStore.SetClassInfo(nativeClassStruct2.Pointer, useWeakRefs: true, wasInjected: true);
				Il2CppClassPointerStore.SetNativeClassPointer(type, nativeClassStruct2.Pointer);
				InjectorHelpers.AddTypeToLookup(type, nativeClassStruct2.Pointer);
				if (logSuccess)
				{
					LogSupport.Info($"Registered managed enum {type} in il2cpp domain");
				}
			}
		}
	}
	public static class RuntimeReflectionHelper
	{
		public static IntPtr GetNestedTypeViaReflection(IntPtr enclosingClass, string nestedTypeName)
		{
			Type nestedType = Type.internal_from_handle(IL2CPP.il2cpp_class_get_type(enclosingClass)).GetNestedType(nestedTypeName, (BindingFlags)48);
			if (!(nestedType != (Type)null))
			{
				return IntPtr.Zero;
			}
			return IL2CPP.il2cpp_class_from_system_type(((Il2CppObjectBase)(object)nestedType).Pointer);
		}

		public static RuntimeTypeHandle GetRuntimeTypeHandle<T>()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			return Il2CppType.Of<T>().TypeHandle;
		}
	}
}
namespace UnhollowerRuntimeLib.XrefScans
{
	public readonly struct XrefInstance
	{
		public readonly XrefType Type;

		public readonly IntPtr Pointer;

		public readonly IntPtr FoundAt;

		public XrefInstance(XrefType type, IntPtr pointer, IntPtr foundAt)
		{
			Type = type;
			Pointer = pointer;
			FoundAt = foundAt;
		}

		internal XrefInstance RelativeToBase(long baseAddress)
		{
			return new XrefInstance(Type, (IntPtr)((long)Pointer - baseAddress), (IntPtr)((long)FoundAt - baseAddress));
		}

		public Object ReadAsObject()
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Expected O, but got Unknown
			if (Type != 0)
			{
				throw new InvalidOperationException("Can't read non-global xref as object");
			}
			IntPtr intPtr = Marshal.ReadIntPtr(Pointer);
			if (intPtr == IntPtr.Zero)
			{
				return null;
			}
			return new Object(intPtr);
		}

		public MethodBase TryResolve()
		{
			if (Type != XrefType.Method)
			{
				throw new InvalidOperationException("Can't resolve non-method xrefs");
			}
			return XrefScanMethodDb.TryResolvePointer(Pointer);
		}
	}
	internal static class XrefScanMetadataRuntimeUtil
	{
		[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
		internal delegate void InitMetadataForMethod(int metadataUsageToken);

		private static InitMetadataForMethod ourMetadataInitForMethodDelegate;

		private static IntPtr ourMetadataInitForMethodPointer;

		private unsafe static void FindMetadataInitForMethod()
		{
			ourMetadataInitForMethodPointer = XrefScannerLowLevel.JumpTargets(*(IntPtr*)(void*)IL2CPP.il2cpp_method_get_from_reflection(((Il2CppObjectBase)(object)AppDomain.CurrentDomain.GetAssemblies().Single((Assembly it) => it.GetSimpleName() == "UnityEngine.CoreModule").GetType("UnityEngine.Object")
				.GetConstructors((BindingFlags)40)
				.Single()).Pointer)).First();
			ourMetadataInitForMethodDelegate = Marshal.GetDelegateForFunctionPointer<InitMetadataForMethod>(ourMetadataInitForMethodPointer);
		}

		internal unsafe static bool CallMetadataInitForMethod(MethodBase method)
		{
			if (ourMetadataInitForMethodPointer == IntPtr.Zero)
			{
				FindMetadataInitForMethod();
			}
			object obj = UnhollowerUtils.GetIl2CppMethodInfoPointerFieldForGeneratedMethod(method)?.GetValue(null);
			if (obj == null)
			{
				return false;
			}
			IntPtr codeStart = *(IntPtr*)(void*)(IntPtr)obj;
			IntPtr intPtr = XrefScannerLowLevel.JumpTargets(codeStart).FirstOrDefault();
			if (intPtr != ourMetadataInitForMethodPointer || intPtr == IntPtr.Zero)
			{
				return false;
			}
			IntPtr intPtr2 = XrefScanUtilFinder.FindLastRcxReadAddressBeforeCallTo(codeStart, ourMetadataInitForMethodPointer);
			IntPtr intPtr3 = XrefScanUtilFinder.FindByteWriteTargetRightAfterCallTo(codeStart, ourMetadataInitForMethodPointer);
			if (intPtr2 == IntPtr.Zero || intPtr3 == IntPtr.Zero)
			{
				return false;
			}
			if (Marshal.ReadByte(intPtr3) == 0)
			{
				ourMetadataInitForMethodDelegate(Marshal.ReadInt32(intPtr2));
				Marshal.WriteByte(intPtr3, 1);
			}
			return true;
		}
	}
	public static class XrefScanMethodDb
	{
		private static readonly MethodAddressToTokenMap MethodMap;

		private static readonly MethodXrefScanCache XrefScanCache;

		private static readonly long GameAssemblyBase;

		private static XrefScanMetadataRuntimeUtil.InitMetadataForMethod ourMetadataInitForMethodDelegate;

		static XrefScanMethodDb()
		{
			MethodMap = new MethodAddressToTokenMap(GeneratedDatabasesUtil.GetDatabasePath("MethodAddressToToken.db"));
			XrefScanCache = new MethodXrefScanCache(GeneratedDatabasesUtil.GetDatabasePath("MethodXrefScanCache.db"));
			foreach (ProcessModule module in Process.GetCurrentProcess().Modules)
			{
				if (module.ModuleName == "GameAssembly.dll")
				{
					GameAssemblyBase = (long)module.BaseAddress;
					break;
				}
			}
		}

		public static MethodBase TryResolvePointer(IntPtr methodStart)
		{
			return MethodMap.Lookup((long)methodStart - GameAssemblyBase);
		}

		internal static IEnumerable<XrefInstance> ListUsers(CachedScanResultsAttribute attribute)
		{
			for (int i = attribute.RefRangeStart; i < attribute.RefRangeEnd; i++)
			{
				yield return XrefScanCache.GetAt(i).AsXrefInstance(GameAssemblyBase);
			}
		}

		internal static IEnumerable<XrefInstance> CachedXrefScan(CachedScanResultsAttribute attribute)
		{
			for (int i = attribute.XrefRangeStart; i < attribute.XrefRangeEnd; i++)
			{
				yield return XrefScanCache.GetAt(i).AsXrefInstance(GameAssemblyBase);
			}
		}

		internal static void CallMetadataInitForMethod(CachedScanResultsAttribute attribute)
		{
			if (attribute.MetadataInitFlagRva != 0L && attribute.MetadataInitTokenRva != 0L && Marshal.ReadByte((IntPtr)(GameAssemblyBase + attribute.MetadataInitFlagRva)) == 0)
			{
				if (ourMetadataInitForMethodDelegate == null)
				{
					ourMetadataInitForMethodDelegate = Marshal.GetDelegateForFunctionPointer<XrefScanMetadataRuntimeUtil.InitMetadataForMethod>((IntPtr)(GameAssemblyBase + XrefScanCache.Header.InitMethodMetadataRva));
				}
				int metadataUsageToken = Marshal.ReadInt32((IntPtr)(GameAssemblyBase + attribute.MetadataInitTokenRva));
				ourMetadataInitForMethodDelegate(metadataUsageToken);
				Marshal.WriteByte((IntPtr)(GameAssemblyBase + attribute.MetadataInitFlagRva), 1);
			}
		}

		[Obsolete("Type registration is no longer needed")]
		public static void RegisterType(Type type)
		{
		}

		[Obsolete("Type registration is no longer needed")]
		public static void RegisterType<T>()
		{
		}
	}
	public static class XrefScanner
	{
		public unsafe static IEnumerable<XrefInstance> XrefScan(MethodBase methodBase)
		{
			object obj = UnhollowerUtils.GetIl2CppMethodInfoPointerFieldForGeneratedMethod(methodBase)?.GetValue(null);
			if (obj == null)
			{
				return Enumerable.Empty<XrefInstance>();
			}
			CachedScanResultsAttribute customAttribute = methodBase.GetCustomAttribute<CachedScanResultsAttribute>(inherit: false);
			if (customAttribute == null)
			{
				XrefScanMetadataRuntimeUtil.CallMetadataInitForMethod(methodBase);
				return XrefScanImpl(DecoderForAddress(*(IntPtr*)(void*)(IntPtr)obj));
			}
			if (customAttribute.XrefRangeStart == customAttribute.XrefRangeEnd)
			{
				return Enumerable.Empty<XrefInstance>();
			}
			XrefScanMethodDb.CallMetadataInitForMethod(customAttribute);
			return from it in XrefScanMethodDb.CachedXrefScan(customAttribute)
				where it.Type == XrefType.Method || XrefGlobalClassFilter(it.Pointer)
				select it;
		}

		public static IEnumerable<XrefInstance> UsedBy(MethodBase methodBase)
		{
			CachedScanResultsAttribute customAttribute = methodBase.GetCustomAttribute<CachedScanResultsAttribute>(inherit: false);
			if (customAttribute == null || customAttribute.RefRangeStart == customAttribute.RefRangeEnd)
			{
				return Enumerable.Empty<XrefInstance>();
			}
			return XrefScanMethodDb.ListUsers(customAttribute);
		}

		internal unsafe static Decoder DecoderForAddress(IntPtr codeStart, int lengthLimit = 1000)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected O, but got Unknown
			if (codeStart == IntPtr.Zero)
			{
				throw new NullReferenceException("codeStart");
			}
			StreamCodeReader val = new StreamCodeReader((Stream)new UnmanagedMemoryStream((byte*)(void*)codeStart, lengthLimit, lengthLimit, FileAccess.Read));
			Decoder obj = Decoder.Create(IntPtr.Size * 8, (CodeReader)(object)val, (DecoderOptions)0);
			obj.IP = (ulong)(long)codeStart;
			return obj;
		}

		internal static IEnumerable<XrefInstance> XrefScanImpl(Decoder decoder, bool skipClassCheck = false)
		{
			Instruction instruction = default(Instruction);
			while (true)
			{
				decoder.Decode(ref instruction);
				if ((int)decoder.LastError == 2 || (int)((Instruction)(ref instruction)).FlowControl == 4 || (int)((Instruction)(ref instruction)).Mnemonic == 287 || (int)((Instruction)(ref instruction)).Mnemonic == 288)
				{
					break;
				}
				if ((int)((Instruction)(ref instruction)).Mnemonic == 59 || (int)((Instruction)(ref instruction)).Mnemonic == 308)
				{
					ulong num = ExtractTargetAddress(in instruction);
					if (num != 0L)
					{
						yield return new XrefInstance(XrefType.Method, (IntPtr)(long)num, (IntPtr)(long)((Instruction)(ref instruction)).IP);
					}
				}
				else
				{
					if ((int)((Instruction)(ref instruction)).FlowControl == 1 || !IsMoveMnemonic(((Instruction)(ref instruction)).Mnemonic))
					{
						continue;
					}
					XrefInstance? xrefInstance = null;
					try
					{
						if ((int)((Instruction)(ref instruction)).Op1Kind == 24 && ((Instruction)(ref instruction)).IsIPRelativeMemoryOperand)
						{
							IntPtr intPtr = (IntPtr)(long)((Instruction)(ref instruction)).IPRelativeMemoryAddress;
							if ((int)((Instruction)(ref instruction)).MemorySize != 5)
							{
								continue;
							}
							if (skipClassCheck || XrefGlobalClassFilter(intPtr))
							{
								xrefInstance = new XrefInstance(XrefType.Global, intPtr, (IntPtr)(long)((Instruction)(ref instruction)).IP);
							}
						}
					}
					catch (Exception ex)
					{
						LogSupport.Error(ex.ToString());
					}
					if (xrefInstance.HasValue)
					{
						yield return xrefInstance.Value;
					}
				}
			}
		}

		internal static bool XrefGlobalClassFilter(IntPtr movTarget)
		{
			IntPtr intPtr = (IntPtr)Marshal.ReadInt64(movTarget);
			if (intPtr != IntPtr.Zero)
			{
				IntPtr intPtr2 = (IntPtr)Marshal.ReadInt64(intPtr);
				if (!(intPtr2 == Il2CppClassPointerStore<string>.NativeClassPtr))
				{
					return intPtr2 == Il2CppClassPointerStore<Type>.NativeClassPtr;
				}
				return true;
			}
			return false;
		}

		internal static bool IsMoveMnemonic(Mnemonic mnemonic)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Invalid comparison between Unknown and I4
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Invalid comparison between Unknown and I4
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Invalid comparison between Unknown and I4
			if ((int)mnemonic >= 77 && ((int)mnemonic <= 92 || (int)mnemonic == 414))
			{
				return true;
			}
			return false;
		}

		internal static ulong ExtractTargetAddress(in Instruction instruction)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected I4, but got Unknown
			OpKind op0Kind = ((Instruction)(ref instruction)).Op0Kind;
			return (op0Kind - 1) switch
			{
				0 => ((Instruction)(ref instruction)).NearBranch16, 
				1 => ((Instruction)(ref instruction)).NearBranch32, 
				2 => ((Instruction)(ref instruction)).NearBranch64, 
				3 => ((Instruction)(ref instruction)).FarBranch16, 
				4 => ((Instruction)(ref instruction)).FarBranch32, 
				_ => 0uL, 
			};
		}
	}
	public static class XrefScannerLowLevel
	{
		public static IEnumerable<IntPtr> JumpTargets(IntPtr codeStart)
		{
			return JumpTargetsImpl(XrefScanner.DecoderForAddress(codeStart));
		}

		private static IEnumerable<IntPtr> JumpTargetsImpl(Decoder myDecoder)
		{
			Instruction instruction = default(Instruction);
			while (true)
			{
				myDecoder.Decode(ref instruction);
				if ((int)myDecoder.LastError == 2 || (int)((Instruction)(ref instruction)).FlowControl == 4)
				{
					break;
				}
				if ((int)((Instruction)(ref instruction)).FlowControl == 1 || (int)((Instruction)(ref instruction)).FlowControl == 5)
				{
					yield return (IntPtr)(long)ExtractTargetAddress(in instruction);
					if ((int)((Instruction)(ref instruction)).FlowControl == 1)
					{
						break;
					}
				}
				instruction = default(Instruction);
			}
		}

		public static IEnumerable<IntPtr> CallAndIndirectTargets(IntPtr pointer)
		{
			return CallAndIndirectTargetsImpl(XrefScanner.DecoderForAddress(pointer, 1048576));
		}

		private static IEnumerable<IntPtr> CallAndIndirectTargetsImpl(Decoder decoder)
		{
			Instruction instruction = default(Instruction);
			while (true)
			{
				decoder.Decode(ref instruction);
				if ((int)decoder.LastError == 2 || (int)((Instruction)(ref instruction)).FlowControl == 4 || (int)((Instruction)(ref instruction)).Mnemonic == 287 || (int)((Instruction)(ref instruction)).Mnemonic == 288)
				{
					break;
				}
				if ((int)((Instruction)(ref instruction)).Mnemonic == 59 || (int)((Instruction)(ref instruction)).Mnemonic == 308)
				{
					ulong num = XrefScanner.ExtractTargetAddress(in instruction);
					if (num != 0L)
					{
						yield return (IntPtr)(long)num;
					}
				}
				else if ((int)((Instruction)(ref instruction)).Mnemonic == 374 && (int)((Instruction)(ref instruction)).MemoryBase == 70)
				{
					ulong iPRelativeMemoryAddress = ((Instruction)(ref instruction)).IPRelativeMemoryAddress;
					if (iPRelativeMemoryAddress != 0L)
					{
						yield return (IntPtr)(long)iPRelativeMemoryAddress;
					}
				}
			}
		}

		private static ulong ExtractTargetAddress(in Instruction instruction)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected I4, but got Unknown
			OpKind op0Kind = ((Instruction)(ref instruction)).Op0Kind;
			return (op0Kind - 1) switch
			{
				0 => ((Instruction)(ref instruction)).NearBranch16, 
				1 => ((Instruction)(ref instruction)).NearBranch32, 
				2 => ((Instruction)(ref instruction)).NearBranch64, 
				3 => ((Instruction)(ref instruction)).FarBranch16, 
				4 => ((Instruction)(ref instruction)).FarBranch32, 
				_ => throw new ArgumentOutOfRangeException(), 
			};
		}
	}
	internal static class XrefScanUtilFinder
	{
		public static IntPtr FindLastRcxReadAddressBeforeCallTo(IntPtr codeStart, IntPtr callTarget)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Invalid comparison between Unknown and I4
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Invalid comparison between Unknown and I4
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Invalid comparison between Unknown and I4
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Invalid comparison between Unknown and I4
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Invalid comparison between Unknown and I4
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Invalid comparison between Unknown and I4
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Invalid comparison between Unknown and I4
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Invalid comparison between Unknown and I4
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Invalid comparison between Unknown and I4
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Invalid comparison between Unknown and I4
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Invalid comparison between Unknown and I4
			Decoder val = XrefScanner.DecoderForAddress(codeStart);
			IntPtr result = IntPtr.Zero;
			Instruction instruction = default(Instruction);
			while (true)
			{
				val.Decode(ref instruction);
				if ((int)val.LastError == 2)
				{
					return IntPtr.Zero;
				}
				if ((int)((Instruction)(ref instruction)).FlowControl == 4)
				{
					return IntPtr.Zero;
				}
				if ((int)((Instruction)(ref instruction)).FlowControl == 1)
				{
					continue;
				}
				if ((int)((Instruction)(ref instruction)).Mnemonic == 287 || (int)((Instruction)(ref instruction)).Mnemonic == 288)
				{
					return IntPtr.Zero;
				}
				if ((int)((Instruction)(ref instruction)).Mnemonic == 59 && (IntPtr)(long)ExtractTargetAddress(in instruction) == callTarget)
				{
					break;
				}
				if ((int)((Instruction)(ref instruction)).Mnemonic == 414 && (int)((Instruction)(ref instruction)).Op0Kind == 0 && (int)((Instruction)(ref instruction)).Op0Register == 38 && (int)((Instruction)(ref instruction)).Op1Kind == 24 && ((Instruction)(ref instruction)).IsIPRelativeMemoryOperand)
				{
					IntPtr intPtr = (IntPtr)(long)((Instruction)(ref instruction)).IPRelativeMemoryAddress;
					if ((int)((Instruction)(ref instruction)).MemorySize == 3 || (int)((Instruction)(ref instruction)).MemorySize == 11)
					{
						result = intPtr;
					}
				}
			}
			return result;
		}

		public static IntPtr FindByteWriteTargetRightAfterCallTo(IntPtr codeStart, IntPtr callTarget)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Invalid comparison between Unknown and I4
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Invalid comparison between Unknown and I4
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Invalid comparison between Unknown and I4
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Invalid comparison between Unknown and I4
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Invalid comparison between Unknown and I4
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Invalid comparison between Unknown and I4
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Invalid comparison between Unknown and I4
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Invalid comparison between Unknown and I4
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Invalid comparison between Unknown and I4
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Invalid comparison between Unknown and I4
			Decoder val = XrefScanner.DecoderForAddress(codeStart);
			bool flag = false;
			Instruction instruction = default(Instruction);
			while (true)
			{
				val.Decode(ref instruction);
				if ((int)val.LastError == 2)
				{
					return IntPtr.Zero;
				}
				if ((int)((Instruction)(ref instruction)).FlowControl == 4)
				{
					return IntPtr.Zero;
				}
				if ((int)((Instruction)(ref instruction)).FlowControl != 1)
				{
					if ((int)((Instruction)(ref instruction)).Mnemonic == 287 || (int)((Instruction)(ref instruction)).Mnemonic == 288)
					{
						return IntPtr.Zero;
					}
					if ((int)((Instruction)(ref instruction)).Mnemonic == 59 && (IntPtr)(long)ExtractTargetAddress(in instruction) == callTarget)
					{
						flag = true;
					}
					if ((int)((Instruction)(ref instruction)).Mnemonic == 414 && flag && (int)((Instruction)(ref instruction)).Op0Kind == 24 && ((int)((Instruction)(ref instruction)).MemorySize == 9 || (int)((Instruction)(ref instruction)).MemorySize == 1))
					{
						break;
					}
				}
			}
			return (IntPtr)(long)((Instruction)(ref instruction)).IPRelativeMemoryAddress;
		}

		private static ulong ExtractTargetAddress(in Instruction instruction)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected I4, but got Unknown
			OpKind op0Kind = ((Instruction)(ref instruction)).Op0Kind;
			return (op0Kind - 1) switch
			{
				0 => ((Instruction)(ref instruction)).NearBranch16, 
				1 => ((Instruction)(ref instruction)).NearBranch32, 
				2 => ((Instruction)(ref instruction)).NearBranch64, 
				3 => ((Instruction)(ref instruction)).FarBranch16, 
				4 => ((Instruction)(ref instruction)).FarBranch32, 
				_ => 0uL, 
			};
		}
	}
	public enum XrefType
	{
		Global,
		Method
	}
}
namespace UnhollowerRuntimeLib.Injection
{
	internal static class InjectorHelpers
	{
		[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
		internal unsafe delegate Il2CppClass* d_ClassFromName(Il2CppImage* image, IntPtr _namespace, IntPtr name);

		[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
		internal unsafe delegate Il2CppClass* d_GetTypeInfoFromTypeDefinitionIndex(int index);

		[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
		internal unsafe delegate Il2CppClass* d_ClassFromIl2CppType(Il2CppTypeStruct* type);

		[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
		internal unsafe delegate byte* d_ClassGetFieldDefaultValue(Il2CppFieldInfo* field, out Il2CppTypeStruct* type);

		[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
		internal unsafe delegate void d_ClassInit(Il2CppClass* klass);

		internal static INativeAssemblyStruct In

BepInExPack/BepInEx/core/UnhollowerRuntimeLib.dll

Decompiled a month ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using UnhollowerRuntimeLib;
using UnhollowerRuntimeLib.XrefScans;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("knah et al.")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.4.33.3")]
[assembly: AssemblyInformationalVersion("0.4.33.3")]
[assembly: AssemblyProduct("UnhollowerRuntimeLib")]
[assembly: AssemblyTitle("UnhollowerRuntimeLib")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.4.33.3")]
[assembly: TypeForwardedTo(typeof(ClassInjector))]
[assembly: TypeForwardedTo(typeof(DelegateSupport))]
[assembly: TypeForwardedTo(typeof(EnumInjector))]
[assembly: TypeForwardedTo(typeof(Il2CppType))]
[assembly: TypeForwardedTo(typeof(Il2CppTypeOf<>))]
[assembly: TypeForwardedTo(typeof(RuntimeReflectionHelper))]
[assembly: TypeForwardedTo(typeof(XrefInstance))]
[assembly: TypeForwardedTo(typeof(XrefScanMethodDb))]
[assembly: TypeForwardedTo(typeof(XrefScanner))]
[assembly: TypeForwardedTo(typeof(XrefScannerLowLevel))]
[assembly: TypeForwardedTo(typeof(XrefType))]
[module: UnverifiableCode]
namespace UnhollowerRuntimeLib;

public static class RuntimeLibMarker
{
}

BepInExPack/BepInEx/core/WasmDisassembler.dll

Decompiled a month 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.Versioning;
using Microsoft.CodeAnalysis;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("WasmDisassembler")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Simple, zero-dependency disassembler for WebAssembly bytecode")]
[assembly: AssemblyFileVersion("2022.0.2.0")]
[assembly: AssemblyInformationalVersion("2022.0.2")]
[assembly: AssemblyProduct("WasmDisassembler")]
[assembly: AssemblyTitle("WasmDisassembler")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/SamboyCoding/Cpp2IL.git")]
[assembly: AssemblyVersion("2022.0.2.0")]
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;
		}
	}
}
namespace WasmDisassembler
{
	public static class Disassembler
	{
		public static List<WasmInstruction> Disassemble(byte[] body, uint virtualAddress)
		{
			List<WasmInstruction> list = new List<WasmInstruction>();
			using MemoryStream memoryStream = new MemoryStream(body);
			using BinaryReader binaryReader = new BinaryReader(memoryStream);
			while (memoryStream.Position < memoryStream.Length)
			{
				uint num = virtualAddress + (uint)(int)memoryStream.Position;
				WasmMnemonic wasmMnemonic = (WasmMnemonic)binaryReader.ReadByte();
				if ((int)wasmMnemonic > 191)
				{
					throw new Exception($"Encountered invalid mnemonic {wasmMnemonic} at ip 0x{num:X}, byte array position {memoryStream.Position}.");
				}
				WasmInstruction item = binaryReader.ReadInstruction(wasmMnemonic);
				item.Ip = num;
				item.NextIp = virtualAddress + (uint)(int)memoryStream.Position;
				list.Add(item);
			}
			return list;
		}

		private static WasmInstruction ReadInstruction(this BinaryReader reader, WasmMnemonic mnemonic)
		{
			WasmInstruction wasmInstruction = default(WasmInstruction);
			wasmInstruction.Mnemonic = mnemonic;
			WasmInstruction result = wasmInstruction;
			Type[] operandTypes = mnemonic.GetOperandTypes();
			if (operandTypes.Length == 0)
			{
				result.Operands = Array.Empty<object>();
				return result;
			}
			result.Operands = operandTypes.Select(reader.ReadPrimitive).ToArray();
			return result;
		}

		private static Type[] GetOperandTypes(this WasmMnemonic mnemonic)
		{
			if ((int)mnemonic >= 40 && (int)mnemonic <= 62)
			{
				return new Type[2]
				{
					typeof(LEB128),
					typeof(LEB128)
				};
			}
			switch (mnemonic)
			{
			case WasmMnemonic.Block:
			case WasmMnemonic.Loop:
			case WasmMnemonic.If:
			case WasmMnemonic.Br:
			case WasmMnemonic.BrIf:
			case WasmMnemonic.LocalGet:
			case WasmMnemonic.LocalSet:
			case WasmMnemonic.LocalTee:
			case WasmMnemonic.GlobalGet:
			case WasmMnemonic.GlobalSet:
				return new Type[1] { typeof(byte) };
			case WasmMnemonic.Call:
			case WasmMnemonic.I32Const:
			case WasmMnemonic.I64Const:
				return new Type[1] { typeof(LEB128) };
			case WasmMnemonic.F32Const:
				return new Type[1] { typeof(float) };
			case WasmMnemonic.F64Const:
				return new Type[1] { typeof(double) };
			case WasmMnemonic.CallIndirect:
				return new Type[2]
				{
					typeof(LEB128),
					typeof(byte)
				};
			default:
				return Array.Empty<Type>();
			}
		}

		internal static object ReadPrimitive(this BinaryReader reader, Type type)
		{
			if (type == typeof(bool))
			{
				return reader.ReadBoolean();
			}
			if (type == typeof(char))
			{
				return reader.ReadChar();
			}
			if (type == typeof(int))
			{
				return reader.ReadInt32();
			}
			if (type == typeof(uint))
			{
				return reader.ReadUInt32();
			}
			if (type == typeof(short))
			{
				return reader.ReadInt16();
			}
			if (type == typeof(ushort))
			{
				return reader.ReadUInt16();
			}
			if (type == typeof(sbyte))
			{
				return reader.ReadSByte();
			}
			if (type == typeof(byte))
			{
				return reader.ReadByte();
			}
			if (type == typeof(long))
			{
				return reader.ReadInt64();
			}
			if (type == typeof(ulong))
			{
				return reader.ReadUInt64();
			}
			if (type == typeof(float))
			{
				return reader.ReadSingle();
			}
			if (type == typeof(double))
			{
				return reader.ReadDouble();
			}
			if (type == typeof(LEB128))
			{
				return reader.BaseStream.ReadLEB128Unsigned();
			}
			throw new Exception($"Bad primitive type: {type}");
		}
	}
	public static class LEB128
	{
		private const long SIGN_EXTEND_MASK = -1L;

		private const int INT64_BITSIZE = 64;

		public static void WriteLEB128Signed(this Stream stream, long value)
		{
			stream.WriteLEB128Signed(value, out var _);
		}

		public static void WriteLEB128Signed(this Stream stream, long value, out int bytes)
		{
			bytes = 0;
			bool flag = true;
			while (flag)
			{
				byte b = (byte)(value & 0x7F);
				value >>= 7;
				bool flag2 = (b & 0x40) != 0;
				flag = (value != 0L || flag2) && !(value == -1 && flag2);
				if (flag)
				{
					b = (byte)(b | 0x80u);
				}
				stream.WriteByte(b);
				bytes++;
			}
		}

		public static void WriteLEB128Unsigned(this Stream stream, ulong value)
		{
			stream.WriteLEB128Unsigned(value, out var _);
		}

		public static void WriteLEB128Unsigned(this Stream stream, ulong value, out int bytes)
		{
			bytes = 0;
			bool flag = true;
			while (flag)
			{
				byte b = (byte)(value & 0x7F);
				value >>= 7;
				flag = value != 0;
				if (flag)
				{
					b = (byte)(b | 0x80u);
				}
				stream.WriteByte(b);
				bytes++;
			}
		}

		public static long ReadLEB128Signed(this Stream stream)
		{
			int bytes;
			return stream.ReadLEB128Signed(out bytes);
		}

		public static long ReadLEB128Signed(this Stream stream, out int bytes)
		{
			bytes = 0;
			long num = 0L;
			int num2 = 0;
			bool flag = true;
			bool flag2 = false;
			while (flag)
			{
				int num3 = stream.ReadByte();
				if (num3 < 0)
				{
					throw new InvalidOperationException("Unexpected end of stream");
				}
				byte num4 = (byte)num3;
				bytes++;
				flag = (num4 & 0x80) != 0;
				flag2 = (num4 & 0x40) != 0;
				long num5 = (long)num4 & 0x7FL;
				num |= num5 << num2;
				num2 += 7;
			}
			if (num2 < 64 && flag2)
			{
				num |= -1L << num2;
			}
			return num;
		}

		public static ulong ReadLEB128Unsigned(this Stream stream)
		{
			int bytes;
			return stream.ReadLEB128Unsigned(out bytes);
		}

		public static ulong ReadLEB128Unsigned(this Stream stream, out int bytes)
		{
			bytes = 0;
			ulong num = 0uL;
			int num2 = 0;
			bool flag = true;
			while (flag)
			{
				int num3 = stream.ReadByte();
				if (num3 < 0)
				{
					throw new InvalidOperationException("Unexpected end of stream");
				}
				byte num4 = (byte)num3;
				bytes++;
				flag = (num4 & 0x80) != 0;
				ulong num5 = (ulong)num4 & 0x7FuL;
				num |= num5 << num2;
				num2 += 7;
			}
			return num;
		}
	}
	public struct WasmInstruction
	{
		public uint Ip;

		public uint NextIp;

		public WasmMnemonic Mnemonic;

		public object[] Operands;

		public override string ToString()
		{
			if (Operands.Length == 0)
			{
				return $"0x{Ip:X} {Mnemonic}";
			}
			return string.Format("0x{0:X} {1} {2}", Ip, Mnemonic, string.Join(", ", Operands));
		}
	}
	public enum WasmMnemonic : byte
	{
		Unreachable = 0,
		Nop = 1,
		Block = 2,
		Loop = 3,
		If = 4,
		Else = 5,
		Proposed_Try = 6,
		Proposed_Catch = 7,
		Proposed_Throw = 8,
		Proposed_Rethrow = 9,
		Proposed_BrOnExn = 10,
		End = 11,
		Br = 12,
		BrIf = 13,
		BrTable = 14,
		Return = 15,
		Call = 16,
		CallIndirect = 17,
		Proposed_ReturnCall = 18,
		Proposed_ReturnCallIndirect = 19,
		Reserved_14 = 20,
		Reserved_15 = 21,
		Reserved_16 = 22,
		Reserved_17 = 23,
		Reserved_18 = 24,
		Reserved_19 = 25,
		Drop = 26,
		Select = 27,
		Proposed_SelectT = 28,
		Reserved_1D = 29,
		Reserved_1E = 30,
		Reserved_1F = 31,
		LocalGet = 32,
		LocalSet = 33,
		LocalTee = 34,
		GlobalGet = 35,
		GlobalSet = 36,
		Proposed_TableGet = 37,
		Proposed_TableSet = 38,
		Reserved_27 = 39,
		I32Load = 40,
		I64Load = 41,
		F32Load = 42,
		F64Load = 43,
		I32Load8_S = 44,
		I32Load8_U = 45,
		I32Load16_S = 46,
		I32Load16_U = 47,
		I64Load8_S = 48,
		I64Load8_U = 49,
		I64Load16_S = 50,
		I64Load16_U = 51,
		I64Load32_S = 52,
		I64Load32_U = 53,
		I32Store = 54,
		I64Store = 55,
		F32Store = 56,
		F64Store = 57,
		I32Store8 = 58,
		I32Store16 = 59,
		I64Store8 = 60,
		I64Store16 = 61,
		I64Store32 = 62,
		MemorySize = 63,
		MemoryGrow = 64,
		I32Const = 65,
		I64Const = 66,
		F32Const = 67,
		F64Const = 68,
		I32Eqz = 69,
		I32Eq = 70,
		I32Ne = 71,
		I32Lt_S = 72,
		I32Lt_U = 73,
		I32Gt_S = 74,
		I32Gt_U = 75,
		I32Le_S = 76,
		I32Le_U = 77,
		I32Ge_S = 78,
		I32Ge_U = 79,
		I64Eqz = 80,
		I64Eq = 81,
		I64Ne = 82,
		I64Lt_S = 83,
		I64Lt_U = 84,
		I64Gt_S = 85,
		I64Gt_U = 86,
		I64Le_S = 87,
		I64Le_U = 88,
		I64Ge_S = 89,
		I64Ge_U = 90,
		F32Eq = 91,
		F32Ne = 92,
		F32Lt = 93,
		F32Gt = 94,
		F32Le = 95,
		F32Ge = 96,
		F64Eq = 97,
		F64Ne = 98,
		F64Lt = 99,
		F64Gt = 100,
		F64Le = 101,
		F64Ge = 102,
		I32Clz = 103,
		I32Ctz = 104,
		I32PopCnt = 105,
		I32Add = 106,
		I32Sub = 107,
		I32Mul = 108,
		I32Div_S = 109,
		I32Div_U = 110,
		I32Rem_S = 111,
		I32Rem_U = 112,
		I32And = 113,
		I32Or = 114,
		I32Xor = 115,
		I32Shl = 116,
		I32Shr_S = 117,
		I32Shr_U = 118,
		I32Rotl = 119,
		I32Rotr = 120,
		I64Clz = 121,
		I64Ctz = 122,
		I64PopCnt = 123,
		I64Add = 124,
		I64Sub = 125,
		I64Mul = 126,
		I64Div_S = 127,
		I64Div_U = 128,
		I64Rem_S = 129,
		I64Rem_U = 130,
		I64And = 131,
		I64Or = 132,
		I64Xor = 133,
		I64Shl = 134,
		I64Shr_S = 135,
		I64Shr_U = 136,
		I64Rotl = 137,
		I64Rotr = 138,
		F32Abs = 139,
		F32Neg = 140,
		F32Ceil = 141,
		F32Floor = 142,
		F32Trunc = 143,
		F32Nearest = 144,
		F32Sqrt = 145,
		F32Add = 146,
		F32Sub = 147,
		F32Mul = 148,
		F32Div = 149,
		F32Min = 150,
		F32Max = 151,
		F32Copysign = 152,
		F64Abs = 153,
		F64Neg = 154,
		F64Ceil = 155,
		F64Floor = 156,
		F64Trunc = 157,
		F64Nearest = 158,
		F64Sqrt = 159,
		F64Add = 160,
		F64Sub = 161,
		F64Mul = 162,
		F64Div = 163,
		F64Min = 164,
		F64Max = 165,
		F64Copysign = 166,
		I32Wrap_I64 = 167,
		I32Trunc_F32_S = 168,
		I32Trunc_F32_U = 169,
		I32Trunc_F64_S = 170,
		I32Trunc_F64_U = 171,
		I64Extend_I32_S = 172,
		I64Extend_I32_U = 173,
		I64Trunc_F32_S = 174,
		I64Trunc_F32_U = 175,
		I64Trunc_F64_S = 176,
		I64Trunc_F64_U = 177,
		F32Convert_I32_S = 178,
		F32Convert_I32_U = 179,
		F32Convert_I64_S = 180,
		F32Convert_I64_U = 181,
		F32Demote_F64 = 182,
		F64Convert_I32_S = 183,
		F64Convert_I32_U = 184,
		F64Convert_I64_S = 185,
		F64Convert_I64_U = 186,
		F64Promote_F32 = 187,
		I32Reinterpret_F32 = 188,
		I64Reinterpret_F64 = 189,
		F32Reinterpret_I32 = 190,
		F64Reinterpret_I64 = 191,
		LastValid = 191,
		Proposed_I32Extend8_S = 192,
		Proposed_I32Extend16_S = 193,
		Proposed_I64Extend8_S = 194,
		Proposed_I64Extend16_S = 195,
		Proposed_I64Extend32_S = 196,
		Proposed_RefNull = 208,
		Proposed_RefIsNull = 209,
		Proposed_RefFunc = 210,
		Proposed_FC_Extensions = 252,
		Proposed_SIMD = 253
	}
}

BepInExPack/mono/Managed/Microsoft.Bcl.AsyncInterfaces.dll

Decompiled a month ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using System.Threading.Tasks.Sources;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: CLSCompliant(true)]
[assembly: AssemblyDefaultAlias("Microsoft.Bcl.AsyncInterfaces")]
[assembly: AssemblyMetadata(".NETFrameworkAssembly", "")]
[assembly: AssemblyMetadata("Serviceable", "True")]
[assembly: AssemblyMetadata("PreferInbox", "True")]
[assembly: AssemblyCompany("Microsoft Corporation")]
[assembly: AssemblyCopyright("© Microsoft Corporation. All rights reserved.")]
[assembly: AssemblyDescription("Microsoft.Bcl.AsyncInterfaces")]
[assembly: AssemblyFileVersion("5.0.20.51904")]
[assembly: AssemblyInformationalVersion("5.0.0+cf258a14b70ad9069470a108f13765e0e5988f51")]
[assembly: AssemblyProduct("Microsoft® .NET")]
[assembly: AssemblyTitle("Microsoft.Bcl.AsyncInterfaces")]
[assembly: AssemblyMetadata("RepositoryUrl", "git://github.com/dotnet/runtime")]
[assembly: AssemblyVersion("5.0.0.0")]
[assembly: TypeForwardedTo(typeof(IAsyncEnumerable<>))]
[assembly: TypeForwardedTo(typeof(IAsyncEnumerator<>))]
[assembly: TypeForwardedTo(typeof(IAsyncDisposable))]
[assembly: TypeForwardedTo(typeof(AsyncIteratorMethodBuilder))]
[assembly: TypeForwardedTo(typeof(AsyncIteratorStateMachineAttribute))]
[assembly: TypeForwardedTo(typeof(ConfiguredAsyncDisposable))]
[assembly: TypeForwardedTo(typeof(ConfiguredCancelableAsyncEnumerable<>))]
[assembly: TypeForwardedTo(typeof(EnumeratorCancellationAttribute))]
[assembly: TypeForwardedTo(typeof(ManualResetValueTaskSourceCore<>))]
[assembly: TypeForwardedTo(typeof(TaskAsyncEnumerableExtensions))]

BepInExPack/mono/Managed/Microsoft.CSharp.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Dynamic;
using System.Globalization;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Security;
using System.Text;
using System.Threading;
using Microsoft.CSharp.RuntimeBinder.Errors;
using Microsoft.CSharp.RuntimeBinder.Semantics;
using Microsoft.CSharp.RuntimeBinder.Syntax;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("Microsoft.CSharp.dll")]
[assembly: AssemblyDescription("Microsoft.CSharp.dll")]
[assembly: AssemblyDefaultAlias("Microsoft.CSharp.dll")]
[assembly: AssemblyCompany("Mono development team")]
[assembly: AssemblyProduct("Mono Common Language Infrastructure")]
[assembly: AssemblyCopyright("(c) Various Mono authors")]
[assembly: SatelliteContractVersion("4.0.0.0")]
[assembly: AssemblyInformationalVersion("4.6.57.0")]
[assembly: AssemblyFileVersion("4.6.57.0")]
[assembly: NeutralResourcesLanguage("en-US")]
[assembly: CLSCompliant(true)]
[assembly: AssemblyDelaySign(true)]
[assembly: SecurityCritical]
[assembly: ComVisible(false)]
[assembly: AssemblyVersion("4.0.0.0")]
internal static class Consts
{
	public const string MonoCorlibVersion = "1A5E0066-58DC-428A-B21C-0AD6CDAE2789";

	public const string MonoVersion = "6.13.0.0";

	public const string MonoCompany = "Mono development team";

	public const string MonoProduct = "Mono Common Language Infrastructure";

	public const string MonoCopyright = "(c) Various Mono authors";

	public const string FxVersion = "4.0.0.0";

	public const string FxFileVersion = "4.6.57.0";

	public const string EnvironmentVersion = "4.0.30319.42000";

	public const string VsVersion = "0.0.0.0";

	public const string VsFileVersion = "11.0.0.0";

	private const string PublicKeyToken = "b77a5c561934e089";

	public const string AssemblyI18N = "I18N, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756";

	public const string AssemblyMicrosoft_JScript = "Microsoft.JScript, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblyMicrosoft_VisualStudio = "Microsoft.VisualStudio, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblyMicrosoft_VisualStudio_Web = "Microsoft.VisualStudio.Web, Version=0.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblyMicrosoft_VSDesigner = "Microsoft.VSDesigner, Version=0.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblyMono_Http = "Mono.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756";

	public const string AssemblyMono_Posix = "Mono.Posix, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756";

	public const string AssemblyMono_Security = "Mono.Security, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756";

	public const string AssemblyMono_Messaging_RabbitMQ = "Mono.Messaging.RabbitMQ, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756";

	public const string AssemblyCorlib = "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string AssemblySystem = "System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string AssemblySystem_Data = "System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string AssemblySystem_Design = "System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_DirectoryServices = "System.DirectoryServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_Drawing = "System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_Drawing_Design = "System.Drawing.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_Messaging = "System.Messaging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_Security = "System.Security, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_ServiceProcess = "System.ServiceProcess, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_Web = "System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_Windows_Forms = "System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string AssemblySystem_2_0 = "System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string AssemblySystemCore_3_5 = "System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string AssemblySystem_Core = "System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string WindowsBase_3_0 = "WindowsBase, Version=3.0.0.0, PublicKeyToken=31bf3856ad364e35";

	public const string AssemblyWindowsBase = "WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";

	public const string AssemblyPresentationCore_3_5 = "PresentationCore, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";

	public const string AssemblyPresentationCore_4_0 = "PresentationCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";

	public const string AssemblyPresentationFramework_3_5 = "PresentationFramework, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";

	public const string AssemblySystemServiceModel_3_0 = "System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";
}
internal static class SR
{
	public const string InternalCompilerError = "An unexpected exception occurred while binding a dynamic operation";

	public const string BindPropertyFailedMethodGroup = "The name '{0}' is bound to a method and cannot be used like a property";

	public const string BindPropertyFailedEvent = "The event '{0}' can only appear on the left hand side of +";

	public const string BindInvokeFailedNonDelegate = "Cannot invoke a non-delegate type";

	public const string NullReferenceOnMemberException = "Cannot perform runtime binding on a null reference";

	public const string BindCallToConditionalMethod = "Cannot dynamically invoke method '{0}' because it has a Conditional attribute";

	public const string BindToVoidMethodButExpectResult = "Cannot implicitly convert type 'void' to 'object'";

	public const string BadBinaryOps = "Operator '{0}' cannot be applied to operands of type '{1}' and '{2}'";

	public const string BadIndexLHS = "Cannot apply indexing with [] to an expression of type '{0}'";

	public const string BadIndexCount = "Wrong number of indices inside []; expected '{0}'";

	public const string BadUnaryOp = "Operator '{0}' cannot be applied to operand of type '{1}'";

	public const string NoImplicitConv = "Cannot implicitly convert type '{0}' to '{1}'";

	public const string NoExplicitConv = "Cannot convert type '{0}' to '{1}'";

	public const string ConstOutOfRange = "Constant value '{0}' cannot be converted to a '{1}'";

	public const string AmbigBinaryOps = "Operator '{0}' is ambiguous on operands of type '{1}' and '{2}'";

	public const string AmbigUnaryOp = "Operator '{0}' is ambiguous on an operand of type '{1}'";

	public const string ValueCantBeNull = "Cannot convert null to '{0}' because it is a non-nullable value type";

	public const string WrongNestedThis = "Cannot access a non-static member of outer type '{0}' via nested type '{1}'";

	public const string NoSuchMember = "'{0}' does not contain a definition for '{1}'";

	public const string ObjectRequired = "An object reference is required for the non-static field, method, or property '{0}'";

	public const string AmbigCall = "The call is ambiguous between the following methods or properties: '{0}' and '{1}'";

	public const string BadAccess = "'{0}' is inaccessible due to its protection level";

	public const string AssgLvalueExpected = "The left-hand side of an assignment must be a variable, property or indexer";

	public const string NoConstructors = "The type '{0}' has no constructors defined";

	public const string PropertyLacksGet = "The property or indexer '{0}' cannot be used in this context because it lacks the get accessor";

	public const string ObjectProhibited = "Member '{0}' cannot be accessed with an instance reference; qualify it with a type name instead";

	public const string AssgReadonly = "A readonly field cannot be assigned to (except in a constructor or a variable initializer)";

	public const string AssgReadonlyStatic = "A static readonly field cannot be assigned to (except in a static constructor or a variable initializer)";

	public const string AssgReadonlyProp = "Property or indexer '{0}' cannot be assigned to -- it is read only";

	public const string UnsafeNeeded = "Dynamic calls cannot be used in conjunction with pointers";

	public const string BadBoolOp = "In order to be applicable as a short circuit operator a user-defined logical operator ('{0}') must have the same return type as the type of its 2 parameters";

	public const string MustHaveOpTF = "The type ('{0}') must contain declarations of operator true and operator false";

	public const string ConstOutOfRangeChecked = "Constant value '{0}' cannot be converted to a '{1}' (use 'unchecked' syntax to override)";

	public const string AmbigMember = "Ambiguity between '{0}' and '{1}'";

	public const string NoImplicitConvCast = "Cannot implicitly convert type '{0}' to '{1}'. An explicit conversion exists (are you missing a cast?)";

	public const string InaccessibleGetter = "The property or indexer '{0}' cannot be used in this context because the get accessor is inaccessible";

	public const string InaccessibleSetter = "The property or indexer '{0}' cannot be used in this context because the set accessor is inaccessible";

	public const string BadArity = "Using the generic {1} '{0}' requires '{2}' type arguments";

	public const string TypeArgsNotAllowed = "The {1} '{0}' cannot be used with type arguments";

	public const string HasNoTypeVars = "The non-generic {1} '{0}' cannot be used with type arguments";

	public const string NewConstraintNotSatisfied = "'{2}' must be a non-abstract type with a public parameterless constructor in order to use it as parameter '{1}' in the generic type or method '{0}'";

	public const string GenericConstraintNotSatisfiedRefType = "The type '{3}' cannot be used as type parameter '{2}' in the generic type or method '{0}'. There is no implicit reference conversion from '{3}' to '{1}'.";

	public const string GenericConstraintNotSatisfiedNullableEnum = "The type '{3}' cannot be used as type parameter '{2}' in the generic type or method '{0}'. The nullable type '{3}' does not satisfy the constraint of '{1}'.";

	public const string GenericConstraintNotSatisfiedNullableInterface = "The type '{3}' cannot be used as type parameter '{2}' in the generic type or method '{0}'. The nullable type '{3}' does not satisfy the constraint of '{1}'. Nullable types can not satisfy any interface constraints.";

	public const string GenericConstraintNotSatisfiedValType = "The type '{3}' cannot be used as type parameter '{2}' in the generic type or method '{0}'. There is no boxing conversion from '{3}' to '{1}'.";

	public const string CantInferMethTypeArgs = "The type arguments for method '{0}' cannot be inferred from the usage. Try specifying the type arguments explicitly.";

	public const string RefConstraintNotSatisfied = "The type '{2}' must be a reference type in order to use it as parameter '{1}' in the generic type or method '{0}'";

	public const string ValConstraintNotSatisfied = "The type '{2}' must be a non-nullable value type in order to use it as parameter '{1}' in the generic type or method '{0}'";

	public const string AmbigUDConv = "Ambiguous user defined conversions '{0}' and '{1}' when converting from '{2}' to '{3}'";

	public const string BindToBogus = "'{0}' is not supported by the language";

	public const string CantCallSpecialMethod = "'{0}': cannot explicitly call operator or accessor";

	public const string ConvertToStaticClass = "Cannot convert to static type '{0}'";

	public const string IncrementLvalueExpected = "The operand of an increment or decrement operator must be a variable, property or indexer";

	public const string BadArgCount = "No overload for method '{0}' takes {1} arguments";

	public const string BadArgTypes = "The best overloaded method match for '{0}' has some invalid arguments";

	public const string BadProtectedAccess = "Cannot access protected member '{0}' via a qualifier of type '{1}'; the qualifier must be of type '{2}' (or derived from it)";

	public const string BindToBogusProp2 = "Property, indexer, or event '{0}' is not supported by the language; try directly calling accessor methods '{1}' or '{2}'";

	public const string BindToBogusProp1 = "Property, indexer, or event '{0}' is not supported by the language; try directly calling accessor method '{1}'";

	public const string BadDelArgCount = "Delegate '{0}' does not take '{1}' arguments";

	public const string BadDelArgTypes = "Delegate '{0}' has some invalid arguments";

	public const string ReturnNotLValue = "Cannot modify the return value of '{0}' because it is not a variable";

	public const string AssgReadonly2 = "Members of readonly field '{0}' cannot be modified (except in a constructor or a variable initializer)";

	public const string AssgReadonlyStatic2 = "Fields of static readonly field '{0}' cannot be assigned to (except in a static constructor or a variable initializer)";

	public const string BadCtorArgCount = "'{0}' does not contain a constructor that takes '{1}' arguments";

	public const string NonInvocableMemberCalled = "Non-invocable member '{0}' cannot be used like a method.";

	public const string BadNamedArgument = "The best overload for '{0}' does not have a parameter named '{1}'";

	public const string BadNamedArgumentForDelegateInvoke = "The delegate '{0}' does not have a parameter named '{1}'";

	public const string DuplicateNamedArgument = "Named argument '{0}' cannot be specified multiple times";

	public const string NamedArgumentUsedInPositional = "Named argument '{0}' specifies a parameter for which a positional argument has already been given";

	public const string TypeArgumentRequiredForStaticCall = "The first argument to dynamically-bound static or constructor call must be a Type";

	public const string DynamicArgumentNeedsValue = "The runtime binder cannot bind a metaobject without a value";

	public const string BindingNameCollision = "More than one type in the binding has the same full name.";

	public const string BadNonTrailingNamedArgument = "Named argument '{0}' is used out-of-position but is followed by an unnamed argument";

	internal static string GetString(string name, params object[] args)
	{
		return GetString(CultureInfo.InvariantCulture, name, args);
	}

	internal static string GetString(CultureInfo culture, string name, params object[] args)
	{
		return string.Format(culture, name, args);
	}

	internal static string GetString(string name)
	{
		return name;
	}

	internal static string GetString(CultureInfo culture, string name)
	{
		return name;
	}

	internal static string Format(string resourceFormat, params object[] args)
	{
		if (args != null)
		{
			return string.Format(CultureInfo.InvariantCulture, resourceFormat, args);
		}
		return resourceFormat;
	}

	internal static string Format(string resourceFormat, object p1)
	{
		return string.Format(CultureInfo.InvariantCulture, resourceFormat, p1);
	}

	internal static string Format(string resourceFormat, object p1, object p2)
	{
		return string.Format(CultureInfo.InvariantCulture, resourceFormat, p1, p2);
	}

	internal static string Format(CultureInfo ci, string resourceFormat, object p1, object p2)
	{
		return string.Format(ci, resourceFormat, p1, p2);
	}

	internal static string Format(string resourceFormat, object p1, object p2, object p3)
	{
		return string.Format(CultureInfo.InvariantCulture, resourceFormat, p1, p2, p3);
	}

	internal static string GetResourceString(string str)
	{
		return str;
	}
}
namespace System.Runtime.CompilerServices
{
	internal class FriendAccessAllowedAttribute : Attribute
	{
	}
}
namespace Microsoft.CSharp.RuntimeBinder
{
	internal readonly struct ArgumentObject
	{
		internal readonly object Value;

		internal readonly CSharpArgumentInfo Info;

		internal readonly Type Type;

		public ArgumentObject(object value, CSharpArgumentInfo info, Type type)
		{
			Value = value;
			Info = info;
			Type = type;
		}
	}
	[EditorBrowsable(EditorBrowsableState.Never)]
	public static class Binder
	{
		public static CallSiteBinder BinaryOperation(CSharpBinderFlags flags, ExpressionType operation, Type context, IEnumerable<CSharpArgumentInfo> argumentInfo)
		{
			bool isChecked = (flags & CSharpBinderFlags.CheckedContext) != 0;
			bool num = (flags & CSharpBinderFlags.BinaryOperationLogical) != 0;
			CSharpBinaryOperationFlags cSharpBinaryOperationFlags = CSharpBinaryOperationFlags.None;
			if (num)
			{
				cSharpBinaryOperationFlags |= CSharpBinaryOperationFlags.LogicalOperation;
			}
			return new CSharpBinaryOperationBinder(operation, isChecked, cSharpBinaryOperationFlags, context, argumentInfo);
		}

		public static CallSiteBinder Convert(CSharpBinderFlags flags, Type type, Type context)
		{
			CSharpConversionKind conversionKind = (((flags & CSharpBinderFlags.ConvertExplicit) != 0) ? CSharpConversionKind.ExplicitConversion : (((flags & CSharpBinderFlags.ConvertArrayIndex) != 0) ? CSharpConversionKind.ArrayCreationConversion : CSharpConversionKind.ImplicitConversion));
			bool isChecked = (flags & CSharpBinderFlags.CheckedContext) != 0;
			return new CSharpConvertBinder(type, conversionKind, isChecked, context);
		}

		public static CallSiteBinder GetIndex(CSharpBinderFlags flags, Type context, IEnumerable<CSharpArgumentInfo> argumentInfo)
		{
			return new CSharpGetIndexBinder(context, argumentInfo);
		}

		public static CallSiteBinder GetMember(CSharpBinderFlags flags, string name, Type context, IEnumerable<CSharpArgumentInfo> argumentInfo)
		{
			bool resultIndexed = (flags & CSharpBinderFlags.ResultIndexed) != 0;
			return new CSharpGetMemberBinder(name, resultIndexed, context, argumentInfo);
		}

		public static CallSiteBinder Invoke(CSharpBinderFlags flags, Type context, IEnumerable<CSharpArgumentInfo> argumentInfo)
		{
			bool num = (flags & CSharpBinderFlags.ResultDiscarded) != 0;
			CSharpCallFlags cSharpCallFlags = CSharpCallFlags.None;
			if (num)
			{
				cSharpCallFlags |= CSharpCallFlags.ResultDiscarded;
			}
			return new CSharpInvokeBinder(cSharpCallFlags, context, argumentInfo);
		}

		public static CallSiteBinder InvokeMember(CSharpBinderFlags flags, string name, IEnumerable<Type> typeArguments, Type context, IEnumerable<CSharpArgumentInfo> argumentInfo)
		{
			bool num = (flags & CSharpBinderFlags.InvokeSimpleName) != 0;
			bool flag = (flags & CSharpBinderFlags.InvokeSpecialName) != 0;
			bool flag2 = (flags & CSharpBinderFlags.ResultDiscarded) != 0;
			CSharpCallFlags cSharpCallFlags = CSharpCallFlags.None;
			if (num)
			{
				cSharpCallFlags |= CSharpCallFlags.SimpleNameCall;
			}
			if (flag)
			{
				cSharpCallFlags |= CSharpCallFlags.EventHookup;
			}
			if (flag2)
			{
				cSharpCallFlags |= CSharpCallFlags.ResultDiscarded;
			}
			return new CSharpInvokeMemberBinder(cSharpCallFlags, name, context, typeArguments, argumentInfo);
		}

		public static CallSiteBinder InvokeConstructor(CSharpBinderFlags flags, Type context, IEnumerable<CSharpArgumentInfo> argumentInfo)
		{
			return new CSharpInvokeConstructorBinder(CSharpCallFlags.None, context, argumentInfo);
		}

		public static CallSiteBinder IsEvent(CSharpBinderFlags flags, string name, Type context)
		{
			return new CSharpIsEventBinder(name, context);
		}

		public static CallSiteBinder SetIndex(CSharpBinderFlags flags, Type context, IEnumerable<CSharpArgumentInfo> argumentInfo)
		{
			bool isCompoundAssignment = (flags & CSharpBinderFlags.ValueFromCompoundAssignment) != 0;
			bool isChecked = (flags & CSharpBinderFlags.CheckedContext) != 0;
			return new CSharpSetIndexBinder(isCompoundAssignment, isChecked, context, argumentInfo);
		}

		public static CallSiteBinder SetMember(CSharpBinderFlags flags, string name, Type context, IEnumerable<CSharpArgumentInfo> argumentInfo)
		{
			bool isCompoundAssignment = (flags & CSharpBinderFlags.ValueFromCompoundAssignment) != 0;
			bool isChecked = (flags & CSharpBinderFlags.CheckedContext) != 0;
			return new CSharpSetMemberBinder(name, isCompoundAssignment, isChecked, context, argumentInfo);
		}

		public static CallSiteBinder UnaryOperation(CSharpBinderFlags flags, ExpressionType operation, Type context, IEnumerable<CSharpArgumentInfo> argumentInfo)
		{
			bool isChecked = (flags & CSharpBinderFlags.CheckedContext) != 0;
			return new CSharpUnaryOperationBinder(operation, isChecked, context, argumentInfo);
		}
	}
	internal static class BinderHelper
	{
		private static MethodInfo s_DoubleIsNaN;

		private static MethodInfo s_SingleIsNaN;

		internal static DynamicMetaObject Bind(ICSharpBinder action, RuntimeBinder binder, DynamicMetaObject[] args, IEnumerable<CSharpArgumentInfo> arginfos, DynamicMetaObject onBindingError)
		{
			Expression[] array = new Expression[args.Length];
			BindingRestrictions bindingRestrictions = BindingRestrictions.Empty;
			ICSharpInvokeOrInvokeMemberBinder callPayload = action as ICSharpInvokeOrInvokeMemberBinder;
			ParameterExpression parameterExpression = null;
			IEnumerator<CSharpArgumentInfo> enumerator = (arginfos ?? Array.Empty<CSharpArgumentInfo>()).GetEnumerator();
			for (int i = 0; i < args.Length; i++)
			{
				DynamicMetaObject dynamicMetaObject = args[i];
				CSharpArgumentInfo cSharpArgumentInfo = (enumerator.MoveNext() ? enumerator.Current : null);
				if (i == 0 && IsIncrementOrDecrementActionOnLocal(action))
				{
					object value = dynamicMetaObject.Value;
					parameterExpression = (ParameterExpression)(array[0] = Expression.Variable((value != null) ? value.GetType() : typeof(object), "t0"));
				}
				else
				{
					array[i] = dynamicMetaObject.Expression;
				}
				BindingRestrictions restrictions = DeduceArgumentRestriction(i, callPayload, dynamicMetaObject, cSharpArgumentInfo);
				bindingRestrictions = bindingRestrictions.Merge(restrictions);
				if (cSharpArgumentInfo != null && cSharpArgumentInfo.LiteralConstant)
				{
					if (dynamicMetaObject.Value is double && double.IsNaN((double)dynamicMetaObject.Value))
					{
						MethodInfo method = s_DoubleIsNaN ?? (s_DoubleIsNaN = typeof(double).GetMethod("IsNaN"));
						Expression expression = Expression.Call(null, method, dynamicMetaObject.Expression);
						bindingRestrictions = bindingRestrictions.Merge(BindingRestrictions.GetExpressionRestriction(expression));
					}
					else if (dynamicMetaObject.Value is float && float.IsNaN((float)dynamicMetaObject.Value))
					{
						MethodInfo method2 = s_SingleIsNaN ?? (s_SingleIsNaN = typeof(float).GetMethod("IsNaN"));
						Expression expression2 = Expression.Call(null, method2, dynamicMetaObject.Expression);
						bindingRestrictions = bindingRestrictions.Merge(BindingRestrictions.GetExpressionRestriction(expression2));
					}
					else
					{
						restrictions = BindingRestrictions.GetExpressionRestriction(Expression.Equal(dynamicMetaObject.Expression, Expression.Constant(dynamicMetaObject.Value, dynamicMetaObject.Expression.Type)));
						bindingRestrictions = bindingRestrictions.Merge(restrictions);
					}
				}
			}
			try
			{
				Expression expression3 = binder.Bind(action, array, args, out var deferredBinding);
				if (deferredBinding != null)
				{
					expression3 = ConvertResult(deferredBinding.Expression, action);
					bindingRestrictions = deferredBinding.Restrictions.Merge(bindingRestrictions);
					return new DynamicMetaObject(expression3, bindingRestrictions);
				}
				if (parameterExpression != null)
				{
					DynamicMetaObject dynamicMetaObject2 = args[0];
					expression3 = Expression.Block(new ParameterExpression[1] { parameterExpression }, Expression.Assign(parameterExpression, Expression.Convert(dynamicMetaObject2.Expression, dynamicMetaObject2.Value.GetType())), expression3, Expression.Assign(dynamicMetaObject2.Expression, Expression.Convert(parameterExpression, dynamicMetaObject2.Expression.Type)));
				}
				expression3 = ConvertResult(expression3, action);
				return new DynamicMetaObject(expression3, bindingRestrictions);
			}
			catch (RuntimeBinderException ex)
			{
				if (onBindingError != null)
				{
					return onBindingError;
				}
				return new DynamicMetaObject(Expression.Throw(Expression.New(typeof(RuntimeBinderException).GetConstructor(new Type[1] { typeof(string) }), Expression.Constant(ex.Message)), GetTypeForErrorMetaObject(action, args)), bindingRestrictions);
			}
		}

		public static void ValidateBindArgument(DynamicMetaObject argument, string paramName)
		{
			if (argument == null)
			{
				throw Error.ArgumentNull(paramName);
			}
			if (!argument.HasValue)
			{
				throw Error.DynamicArgumentNeedsValue(paramName);
			}
		}

		public static void ValidateBindArgument(DynamicMetaObject[] arguments, string paramName)
		{
			if (arguments != null)
			{
				for (int i = 0; i != arguments.Length; i++)
				{
					ValidateBindArgument(arguments[i], $"{paramName}[{i}]");
				}
			}
		}

		private static bool IsTypeOfStaticCall(int parameterIndex, ICSharpInvokeOrInvokeMemberBinder callPayload)
		{
			if (parameterIndex == 0 && callPayload != null)
			{
				return callPayload.StaticCall;
			}
			return false;
		}

		private static bool IsComObject(object obj)
		{
			if (obj != null)
			{
				return Marshal.IsComObject(obj);
			}
			return false;
		}

		private static bool IsTransparentProxy(object obj)
		{
			return false;
		}

		private static bool IsDynamicallyTypedRuntimeProxy(DynamicMetaObject argument, CSharpArgumentInfo info)
		{
			if (info != null && !info.UseCompileTimeType)
			{
				if (!IsComObject(argument.Value))
				{
					return IsTransparentProxy(argument.Value);
				}
				return true;
			}
			return false;
		}

		private static BindingRestrictions DeduceArgumentRestriction(int parameterIndex, ICSharpInvokeOrInvokeMemberBinder callPayload, DynamicMetaObject argument, CSharpArgumentInfo info)
		{
			if (argument.Value != null && !IsTypeOfStaticCall(parameterIndex, callPayload) && !IsDynamicallyTypedRuntimeProxy(argument, info))
			{
				return BindingRestrictions.GetTypeRestriction(argument.Expression, argument.RuntimeType);
			}
			return BindingRestrictions.GetInstanceRestriction(argument.Expression, argument.Value);
		}

		private static Expression ConvertResult(Expression binding, ICSharpBinder action)
		{
			if (action is CSharpInvokeConstructorBinder)
			{
				return binding;
			}
			if (binding.Type == typeof(void))
			{
				if (action is ICSharpInvokeOrInvokeMemberBinder iCSharpInvokeOrInvokeMemberBinder && iCSharpInvokeOrInvokeMemberBinder.ResultDiscarded)
				{
					return Expression.Block(binding, Expression.Default(action.ReturnType));
				}
				throw Error.BindToVoidMethodButExpectResult();
			}
			if (binding.Type.IsValueType && !action.ReturnType.IsValueType)
			{
				return Expression.Convert(binding, action.ReturnType);
			}
			return binding;
		}

		private static Type GetTypeForErrorMetaObject(ICSharpBinder action, DynamicMetaObject[] args)
		{
			if (action is CSharpInvokeConstructorBinder)
			{
				return args[0].Value as Type;
			}
			return action.ReturnType;
		}

		private static bool IsIncrementOrDecrementActionOnLocal(ICSharpBinder action)
		{
			if (action is CSharpUnaryOperationBinder cSharpUnaryOperationBinder)
			{
				if (cSharpUnaryOperationBinder.Operation != ExpressionType.Increment)
				{
					return cSharpUnaryOperationBinder.Operation == ExpressionType.Decrement;
				}
				return true;
			}
			return false;
		}

		internal static T[] Cons<T>(T sourceHead, T[] sourceTail)
		{
			if (sourceTail == null || sourceTail.Length != 0)
			{
				T[] array = new T[sourceTail.Length + 1];
				array[0] = sourceHead;
				sourceTail.CopyTo(array, 1);
				return array;
			}
			return new T[1] { sourceHead };
		}

		internal static T[] Cons<T>(T sourceHead, T[] sourceMiddle, T sourceLast)
		{
			if (sourceMiddle == null || sourceMiddle.Length != 0)
			{
				T[] array = new T[sourceMiddle.Length + 2];
				array[0] = sourceHead;
				array[^1] = sourceLast;
				sourceMiddle.CopyTo(array, 1);
				return array;
			}
			return new T[2] { sourceHead, sourceLast };
		}

		internal static T[] ToArray<T>(IEnumerable<T> source)
		{
			if (source != null)
			{
				return source.ToArray();
			}
			return Array.Empty<T>();
		}

		internal static CallInfo CreateCallInfo(ref IEnumerable<CSharpArgumentInfo> argInfos, int discard)
		{
			int num = 0;
			List<string> list = new List<string>();
			CSharpArgumentInfo[] array = (CSharpArgumentInfo[])(argInfos = ToArray(argInfos));
			foreach (CSharpArgumentInfo cSharpArgumentInfo in array)
			{
				if (cSharpArgumentInfo.NamedArgument)
				{
					list.Add(cSharpArgumentInfo.Name);
				}
				num++;
			}
			return new CallInfo(num - discard, list);
		}

		internal static string GetCLROperatorName(this ExpressionType p)
		{
			return p switch
			{
				ExpressionType.Add => "op_Addition", 
				ExpressionType.Subtract => "op_Subtraction", 
				ExpressionType.Multiply => "op_Multiply", 
				ExpressionType.Divide => "op_Division", 
				ExpressionType.Modulo => "op_Modulus", 
				ExpressionType.LeftShift => "op_LeftShift", 
				ExpressionType.RightShift => "op_RightShift", 
				ExpressionType.LessThan => "op_LessThan", 
				ExpressionType.GreaterThan => "op_GreaterThan", 
				ExpressionType.LessThanOrEqual => "op_LessThanOrEqual", 
				ExpressionType.GreaterThanOrEqual => "op_GreaterThanOrEqual", 
				ExpressionType.Equal => "op_Equality", 
				ExpressionType.NotEqual => "op_Inequality", 
				ExpressionType.And => "op_BitwiseAnd", 
				ExpressionType.ExclusiveOr => "op_ExclusiveOr", 
				ExpressionType.Or => "op_BitwiseOr", 
				ExpressionType.AddAssign => "op_Addition", 
				ExpressionType.SubtractAssign => "op_Subtraction", 
				ExpressionType.MultiplyAssign => "op_Multiply", 
				ExpressionType.DivideAssign => "op_Division", 
				ExpressionType.ModuloAssign => "op_Modulus", 
				ExpressionType.AndAssign => "op_BitwiseAnd", 
				ExpressionType.ExclusiveOrAssign => "op_ExclusiveOr", 
				ExpressionType.OrAssign => "op_BitwiseOr", 
				ExpressionType.LeftShiftAssign => "op_LeftShift", 
				ExpressionType.RightShiftAssign => "op_RightShift", 
				ExpressionType.Negate => "op_UnaryNegation", 
				ExpressionType.UnaryPlus => "op_UnaryPlus", 
				ExpressionType.Not => "op_LogicalNot", 
				ExpressionType.OnesComplement => "op_OnesComplement", 
				ExpressionType.IsTrue => "op_True", 
				ExpressionType.IsFalse => "op_False", 
				ExpressionType.Increment => "op_Increment", 
				ExpressionType.Decrement => "op_Decrement", 
				_ => null, 
			};
		}
	}
	[EditorBrowsable(EditorBrowsableState.Never)]
	public sealed class CSharpArgumentInfo
	{
		internal static readonly CSharpArgumentInfo None = new CSharpArgumentInfo(CSharpArgumentInfoFlags.None, null);

		private CSharpArgumentInfoFlags Flags { get; }

		internal string Name { get; }

		internal bool UseCompileTimeType => (Flags & CSharpArgumentInfoFlags.UseCompileTimeType) != 0;

		internal bool LiteralConstant => (Flags & CSharpArgumentInfoFlags.Constant) != 0;

		internal bool NamedArgument => (Flags & CSharpArgumentInfoFlags.NamedArgument) != 0;

		internal bool IsByRefOrOut => (Flags & (CSharpArgumentInfoFlags.IsRef | CSharpArgumentInfoFlags.IsOut)) != 0;

		internal bool IsOut => (Flags & CSharpArgumentInfoFlags.IsOut) != 0;

		internal bool IsStaticType => (Flags & CSharpArgumentInfoFlags.IsStaticType) != 0;

		private CSharpArgumentInfo(CSharpArgumentInfoFlags flags, string name)
		{
			Flags = flags;
			Name = name;
		}

		public static CSharpArgumentInfo Create(CSharpArgumentInfoFlags flags, string name)
		{
			return new CSharpArgumentInfo(flags, name);
		}
	}
	[Flags]
	[EditorBrowsable(EditorBrowsableState.Never)]
	public enum CSharpArgumentInfoFlags
	{
		None = 0,
		UseCompileTimeType = 1,
		Constant = 2,
		NamedArgument = 4,
		IsRef = 8,
		IsOut = 0x10,
		IsStaticType = 0x20
	}
	internal sealed class CSharpBinaryOperationBinder : BinaryOperationBinder, ICSharpBinder
	{
		private readonly CSharpBinaryOperationFlags _binopFlags;

		private readonly CSharpArgumentInfo[] _argumentInfo;

		private readonly RuntimeBinder _binder;

		[ExcludeFromCodeCoverage]
		public string Name => null;

		public BindingFlag BindingFlags => (BindingFlag)0;

		public bool IsBinderThatCanHaveRefReceiver => false;

		internal bool IsLogicalOperation => (_binopFlags & CSharpBinaryOperationFlags.LogicalOperation) != 0;

		public Expr DispatchPayload(RuntimeBinder runtimeBinder, ArgumentObject[] arguments, LocalVariableSymbol[] locals)
		{
			return runtimeBinder.BindBinaryOperation(this, arguments, locals);
		}

		public void PopulateSymbolTableWithName(Type callingType, ArgumentObject[] arguments)
		{
			string cLROperatorName = base.Operation.GetCLROperatorName();
			SymbolTable.PopulateSymbolTableWithName(cLROperatorName, null, arguments[0].Type);
			SymbolTable.PopulateSymbolTableWithName(cLROperatorName, null, arguments[1].Type);
		}

		CSharpArgumentInfo ICSharpBinder.GetArgumentInfo(int index)
		{
			return _argumentInfo[index];
		}

		public CSharpBinaryOperationBinder(ExpressionType operation, bool isChecked, CSharpBinaryOperationFlags binaryOperationFlags, Type callingContext, IEnumerable<CSharpArgumentInfo> argumentInfo)
			: base(operation)
		{
			_binopFlags = binaryOperationFlags;
			_argumentInfo = BinderHelper.ToArray(argumentInfo);
			_binder = new RuntimeBinder(callingContext, isChecked);
		}

		public override DynamicMetaObject FallbackBinaryOperation(DynamicMetaObject target, DynamicMetaObject arg, DynamicMetaObject errorSuggestion)
		{
			BinderHelper.ValidateBindArgument(target, "target");
			BinderHelper.ValidateBindArgument(arg, "arg");
			return BinderHelper.Bind(this, _binder, new DynamicMetaObject[2] { target, arg }, _argumentInfo, errorSuggestion);
		}
	}
	[Flags]
	internal enum CSharpBinaryOperationFlags
	{
		None = 0,
		MemberAccess = 1,
		LogicalOperation = 2
	}
	[Flags]
	[EditorBrowsable(EditorBrowsableState.Never)]
	public enum CSharpBinderFlags
	{
		None = 0,
		CheckedContext = 1,
		InvokeSimpleName = 2,
		InvokeSpecialName = 4,
		BinaryOperationLogical = 8,
		ConvertExplicit = 0x10,
		ConvertArrayIndex = 0x20,
		ResultIndexed = 0x40,
		ValueFromCompoundAssignment = 0x80,
		ResultDiscarded = 0x100
	}
	[Flags]
	internal enum CSharpCallFlags
	{
		None = 0,
		SimpleNameCall = 1,
		EventHookup = 2,
		ResultDiscarded = 4
	}
	internal enum CSharpConversionKind
	{
		ImplicitConversion,
		ExplicitConversion,
		ArrayCreationConversion
	}
	internal sealed class CSharpConvertBinder : ConvertBinder, ICSharpBinder
	{
		private readonly RuntimeBinder _binder;

		[ExcludeFromCodeCoverage]
		public string Name => null;

		public BindingFlag BindingFlags => (BindingFlag)0;

		public bool IsBinderThatCanHaveRefReceiver => false;

		private CSharpConversionKind ConversionKind { get; }

		public Expr DispatchPayload(RuntimeBinder runtimeBinder, ArgumentObject[] arguments, LocalVariableSymbol[] locals)
		{
			if (!base.Explicit)
			{
				return runtimeBinder.BindImplicitConversion(arguments, base.Type, locals, ConversionKind == CSharpConversionKind.ArrayCreationConversion);
			}
			return runtimeBinder.BindExplicitConversion(arguments, base.Type, locals);
		}

		public void PopulateSymbolTableWithName(Type callingType, ArgumentObject[] arguments)
		{
		}

		CSharpArgumentInfo ICSharpBinder.GetArgumentInfo(int index)
		{
			return CSharpArgumentInfo.None;
		}

		public CSharpConvertBinder(Type type, CSharpConversionKind conversionKind, bool isChecked, Type callingContext)
			: base(type, conversionKind == CSharpConversionKind.ExplicitConversion)
		{
			ConversionKind = conversionKind;
			_binder = new RuntimeBinder(callingContext, isChecked);
		}

		public override DynamicMetaObject FallbackConvert(DynamicMetaObject target, DynamicMetaObject errorSuggestion)
		{
			BinderHelper.ValidateBindArgument(target, "target");
			return BinderHelper.Bind(this, _binder, new DynamicMetaObject[1] { target }, null, errorSuggestion);
		}
	}
	internal sealed class CSharpGetIndexBinder : GetIndexBinder, ICSharpBinder
	{
		private readonly CSharpArgumentInfo[] _argumentInfo;

		private readonly RuntimeBinder _binder;

		public string Name => "$Item$";

		public BindingFlag BindingFlags => BindingFlag.BIND_RVALUEREQUIRED;

		public bool IsBinderThatCanHaveRefReceiver => true;

		public Expr DispatchPayload(RuntimeBinder runtimeBinder, ArgumentObject[] arguments, LocalVariableSymbol[] locals)
		{
			Expr optionalIndexerArguments = runtimeBinder.CreateArgumentListEXPR(arguments, locals, 1, arguments.Length);
			return runtimeBinder.BindProperty(this, arguments[0], locals[0], optionalIndexerArguments);
		}

		public void PopulateSymbolTableWithName(Type callingType, ArgumentObject[] arguments)
		{
			SymbolTable.PopulateSymbolTableWithName("$Item$", null, arguments[0].Type);
		}

		CSharpArgumentInfo ICSharpBinder.GetArgumentInfo(int index)
		{
			return _argumentInfo[index];
		}

		public CSharpGetIndexBinder(Type callingContext, IEnumerable<CSharpArgumentInfo> argumentInfo)
			: base(BinderHelper.CreateCallInfo(ref argumentInfo, 1))
		{
			_argumentInfo = argumentInfo as CSharpArgumentInfo[];
			_binder = new RuntimeBinder(callingContext);
		}

		public override DynamicMetaObject FallbackGetIndex(DynamicMetaObject target, DynamicMetaObject[] indexes, DynamicMetaObject errorSuggestion)
		{
			BinderHelper.ValidateBindArgument(target, "target");
			BinderHelper.ValidateBindArgument(indexes, "indexes");
			return BinderHelper.Bind(this, _binder, BinderHelper.Cons(target, indexes), _argumentInfo, errorSuggestion);
		}
	}
	internal sealed class CSharpGetMemberBinder : GetMemberBinder, IInvokeOnGetBinder, ICSharpBinder
	{
		private readonly CSharpArgumentInfo[] _argumentInfo;

		private readonly RuntimeBinder _binder;

		public BindingFlag BindingFlags => BindingFlag.BIND_RVALUEREQUIRED;

		public bool IsBinderThatCanHaveRefReceiver => false;

		bool IInvokeOnGetBinder.InvokeOnGet => !ResultIndexed;

		private bool ResultIndexed { get; }

		public Expr DispatchPayload(RuntimeBinder runtimeBinder, ArgumentObject[] arguments, LocalVariableSymbol[] locals)
		{
			return runtimeBinder.BindProperty(this, arguments[0], locals[0], null);
		}

		public void PopulateSymbolTableWithName(Type callingType, ArgumentObject[] arguments)
		{
			SymbolTable.PopulateSymbolTableWithName(base.Name, null, arguments[0].Type);
		}

		CSharpArgumentInfo ICSharpBinder.GetArgumentInfo(int index)
		{
			return _argumentInfo[index];
		}

		public CSharpGetMemberBinder(string name, bool resultIndexed, Type callingContext, IEnumerable<CSharpArgumentInfo> argumentInfo)
			: base(name, ignoreCase: false)
		{
			ResultIndexed = resultIndexed;
			_argumentInfo = BinderHelper.ToArray(argumentInfo);
			_binder = new RuntimeBinder(callingContext);
		}

		public override DynamicMetaObject FallbackGetMember(DynamicMetaObject target, DynamicMetaObject errorSuggestion)
		{
			BinderHelper.ValidateBindArgument(target, "target");
			return BinderHelper.Bind(this, _binder, new DynamicMetaObject[1] { target }, _argumentInfo, errorSuggestion);
		}

		[SpecialName]
		string ICSharpBinder.get_Name()
		{
			return base.Name;
		}
	}
	internal sealed class CSharpInvokeBinder : InvokeBinder, ICSharpInvokeOrInvokeMemberBinder, ICSharpBinder
	{
		private readonly CSharpCallFlags _flags;

		private readonly CSharpArgumentInfo[] _argumentInfo;

		private readonly RuntimeBinder _binder;

		public BindingFlag BindingFlags => (BindingFlag)0;

		public bool IsBinderThatCanHaveRefReceiver => true;

		bool ICSharpInvokeOrInvokeMemberBinder.StaticCall
		{
			get
			{
				if (_argumentInfo[0] != null)
				{
					return _argumentInfo[0].IsStaticType;
				}
				return false;
			}
		}

		string ICSharpBinder.Name => "Invoke";

		Type[] ICSharpInvokeOrInvokeMemberBinder.TypeArguments => Array.Empty<Type>();

		CSharpCallFlags ICSharpInvokeOrInvokeMemberBinder.Flags => _flags;

		bool ICSharpInvokeOrInvokeMemberBinder.ResultDiscarded => (_flags & CSharpCallFlags.ResultDiscarded) != 0;

		public Expr DispatchPayload(RuntimeBinder runtimeBinder, ArgumentObject[] arguments, LocalVariableSymbol[] locals)
		{
			return runtimeBinder.DispatchPayload(this, arguments, locals);
		}

		public void PopulateSymbolTableWithName(Type callingType, ArgumentObject[] arguments)
		{
			RuntimeBinder.PopulateSymbolTableWithPayloadInformation(this, callingType, arguments);
		}

		CSharpArgumentInfo ICSharpBinder.GetArgumentInfo(int index)
		{
			return _argumentInfo[index];
		}

		public CSharpInvokeBinder(CSharpCallFlags flags, Type callingContext, IEnumerable<CSharpArgumentInfo> argumentInfo)
			: base(BinderHelper.CreateCallInfo(ref argumentInfo, 1))
		{
			_flags = flags;
			_argumentInfo = argumentInfo as CSharpArgumentInfo[];
			_binder = new RuntimeBinder(callingContext);
		}

		public override DynamicMetaObject FallbackInvoke(DynamicMetaObject target, DynamicMetaObject[] args, DynamicMetaObject errorSuggestion)
		{
			BinderHelper.ValidateBindArgument(target, "target");
			BinderHelper.ValidateBindArgument(args, "args");
			return BinderHelper.Bind(this, _binder, BinderHelper.Cons(target, args), _argumentInfo, errorSuggestion);
		}
	}
	internal sealed class CSharpInvokeConstructorBinder : DynamicMetaObjectBinder, ICSharpInvokeOrInvokeMemberBinder, ICSharpBinder
	{
		private readonly CSharpArgumentInfo[] _argumentInfo;

		private readonly RuntimeBinder _binder;

		public BindingFlag BindingFlags => (BindingFlag)0;

		public bool IsBinderThatCanHaveRefReceiver => true;

		public CSharpCallFlags Flags { get; }

		public bool StaticCall => true;

		public Type[] TypeArguments => Array.Empty<Type>();

		public string Name => ".ctor";

		bool ICSharpInvokeOrInvokeMemberBinder.ResultDiscarded => false;

		public Expr DispatchPayload(RuntimeBinder runtimeBinder, ArgumentObject[] arguments, LocalVariableSymbol[] locals)
		{
			return runtimeBinder.DispatchPayload(this, arguments, locals);
		}

		public void PopulateSymbolTableWithName(Type callingType, ArgumentObject[] arguments)
		{
			RuntimeBinder.PopulateSymbolTableWithPayloadInformation(this, callingType, arguments);
		}

		CSharpArgumentInfo ICSharpBinder.GetArgumentInfo(int index)
		{
			return _argumentInfo[index];
		}

		public CSharpInvokeConstructorBinder(CSharpCallFlags flags, Type callingContext, IEnumerable<CSharpArgumentInfo> argumentInfo)
		{
			Flags = flags;
			_argumentInfo = BinderHelper.ToArray(argumentInfo);
			_binder = new RuntimeBinder(callingContext);
		}

		public override DynamicMetaObject Bind(DynamicMetaObject target, DynamicMetaObject[] args)
		{
			BinderHelper.ValidateBindArgument(target, "target");
			BinderHelper.ValidateBindArgument(args, "args");
			return BinderHelper.Bind(this, _binder, BinderHelper.Cons(target, args), _argumentInfo, null);
		}
	}
	internal sealed class CSharpInvokeMemberBinder : InvokeMemberBinder, ICSharpInvokeOrInvokeMemberBinder, ICSharpBinder
	{
		private readonly CSharpArgumentInfo[] _argumentInfo;

		private readonly RuntimeBinder _binder;

		public BindingFlag BindingFlags => (BindingFlag)0;

		public bool IsBinderThatCanHaveRefReceiver => true;

		bool ICSharpInvokeOrInvokeMemberBinder.StaticCall => _argumentInfo[0]?.IsStaticType ?? false;

		public CSharpCallFlags Flags { get; }

		public Type CallingContext { get; }

		public Type[] TypeArguments { get; }

		bool ICSharpInvokeOrInvokeMemberBinder.ResultDiscarded => (Flags & CSharpCallFlags.ResultDiscarded) != 0;

		public Expr DispatchPayload(RuntimeBinder runtimeBinder, ArgumentObject[] arguments, LocalVariableSymbol[] locals)
		{
			return runtimeBinder.DispatchPayload(this, arguments, locals);
		}

		public void PopulateSymbolTableWithName(Type callingType, ArgumentObject[] arguments)
		{
			RuntimeBinder.PopulateSymbolTableWithPayloadInformation(this, callingType, arguments);
		}

		public CSharpArgumentInfo GetArgumentInfo(int index)
		{
			return _argumentInfo[index];
		}

		public CSharpArgumentInfo[] ArgumentInfoArray()
		{
			CSharpArgumentInfo[] array = new CSharpArgumentInfo[_argumentInfo.Length];
			_argumentInfo.CopyTo(array, 0);
			return array;
		}

		public CSharpInvokeMemberBinder(CSharpCallFlags flags, string name, Type callingContext, IEnumerable<Type> typeArguments, IEnumerable<CSharpArgumentInfo> argumentInfo)
			: base(name, ignoreCase: false, BinderHelper.CreateCallInfo(ref argumentInfo, 1))
		{
			Flags = flags;
			CallingContext = callingContext;
			TypeArguments = BinderHelper.ToArray(typeArguments);
			_argumentInfo = BinderHelper.ToArray(argumentInfo);
			_binder = new RuntimeBinder(callingContext);
		}

		public override DynamicMetaObject FallbackInvokeMember(DynamicMetaObject target, DynamicMetaObject[] args, DynamicMetaObject errorSuggestion)
		{
			BinderHelper.ValidateBindArgument(target, "target");
			BinderHelper.ValidateBindArgument(args, "args");
			return BinderHelper.Bind(this, _binder, BinderHelper.Cons(target, args), _argumentInfo, errorSuggestion);
		}

		public override DynamicMetaObject FallbackInvoke(DynamicMetaObject target, DynamicMetaObject[] args, DynamicMetaObject errorSuggestion)
		{
			return new CSharpInvokeBinder(Flags, CallingContext, _argumentInfo).Defer(target, args);
		}

		[SpecialName]
		string ICSharpBinder.get_Name()
		{
			return base.Name;
		}
	}
	internal sealed class CSharpIsEventBinder : DynamicMetaObjectBinder, ICSharpBinder
	{
		private readonly RuntimeBinder _binder;

		public BindingFlag BindingFlags => (BindingFlag)0;

		public bool IsBinderThatCanHaveRefReceiver => false;

		public string Name { get; }

		public override Type ReturnType => typeof(bool);

		public Expr DispatchPayload(RuntimeBinder runtimeBinder, ArgumentObject[] arguments, LocalVariableSymbol[] locals)
		{
			return runtimeBinder.BindIsEvent(this, arguments, locals);
		}

		public void PopulateSymbolTableWithName(Type callingType, ArgumentObject[] arguments)
		{
			SymbolTable.PopulateSymbolTableWithName(Name, null, arguments[0].Info.IsStaticType ? (arguments[0].Value as Type) : arguments[0].Type);
		}

		CSharpArgumentInfo ICSharpBinder.GetArgumentInfo(int index)
		{
			return CSharpArgumentInfo.None;
		}

		public CSharpIsEventBinder(string name, Type callingContext)
		{
			Name = name;
			_binder = new RuntimeBinder(callingContext);
		}

		public override DynamicMetaObject Bind(DynamicMetaObject target, DynamicMetaObject[] args)
		{
			BinderHelper.ValidateBindArgument(target, "target");
			return BinderHelper.Bind(this, _binder, new DynamicMetaObject[1] { target }, null, null);
		}
	}
	internal sealed class CSharpSetIndexBinder : SetIndexBinder, ICSharpBinder
	{
		private readonly CSharpArgumentInfo[] _argumentInfo;

		private readonly RuntimeBinder _binder;

		public string Name => "$Item$";

		public BindingFlag BindingFlags => (BindingFlag)0;

		public bool IsBinderThatCanHaveRefReceiver => true;

		internal bool IsCompoundAssignment { get; }

		public Expr DispatchPayload(RuntimeBinder runtimeBinder, ArgumentObject[] arguments, LocalVariableSymbol[] locals)
		{
			return runtimeBinder.BindAssignment(this, arguments, locals);
		}

		public void PopulateSymbolTableWithName(Type callingType, ArgumentObject[] arguments)
		{
			SymbolTable.PopulateSymbolTableWithName("$Item$", null, arguments[0].Type);
		}

		CSharpArgumentInfo ICSharpBinder.GetArgumentInfo(int index)
		{
			return _argumentInfo[index];
		}

		public CSharpSetIndexBinder(bool isCompoundAssignment, bool isChecked, Type callingContext, IEnumerable<CSharpArgumentInfo> argumentInfo)
			: base(BinderHelper.CreateCallInfo(ref argumentInfo, 2))
		{
			IsCompoundAssignment = isCompoundAssignment;
			_argumentInfo = argumentInfo as CSharpArgumentInfo[];
			_binder = new RuntimeBinder(callingContext, isChecked);
		}

		public override DynamicMetaObject FallbackSetIndex(DynamicMetaObject target, DynamicMetaObject[] indexes, DynamicMetaObject value, DynamicMetaObject errorSuggestion)
		{
			BinderHelper.ValidateBindArgument(target, "target");
			BinderHelper.ValidateBindArgument(indexes, "indexes");
			BinderHelper.ValidateBindArgument(value, "value");
			return BinderHelper.Bind(this, _binder, BinderHelper.Cons(target, indexes, value), _argumentInfo, errorSuggestion);
		}
	}
	internal sealed class CSharpSetMemberBinder : SetMemberBinder, ICSharpBinder
	{
		private readonly CSharpArgumentInfo[] _argumentInfo;

		private readonly RuntimeBinder _binder;

		public BindingFlag BindingFlags => (BindingFlag)0;

		public bool IsBinderThatCanHaveRefReceiver => false;

		internal bool IsCompoundAssignment { get; }

		public Expr DispatchPayload(RuntimeBinder runtimeBinder, ArgumentObject[] arguments, LocalVariableSymbol[] locals)
		{
			return runtimeBinder.BindAssignment(this, arguments, locals);
		}

		public void PopulateSymbolTableWithName(Type callingType, ArgumentObject[] arguments)
		{
			SymbolTable.PopulateSymbolTableWithName(base.Name, null, arguments[0].Type);
		}

		CSharpArgumentInfo ICSharpBinder.GetArgumentInfo(int index)
		{
			return _argumentInfo[index];
		}

		public CSharpSetMemberBinder(string name, bool isCompoundAssignment, bool isChecked, Type callingContext, IEnumerable<CSharpArgumentInfo> argumentInfo)
			: base(name, ignoreCase: false)
		{
			IsCompoundAssignment = isCompoundAssignment;
			_argumentInfo = BinderHelper.ToArray(argumentInfo);
			_binder = new RuntimeBinder(callingContext, isChecked);
		}

		public override DynamicMetaObject FallbackSetMember(DynamicMetaObject target, DynamicMetaObject value, DynamicMetaObject errorSuggestion)
		{
			BinderHelper.ValidateBindArgument(target, "target");
			BinderHelper.ValidateBindArgument(value, "value");
			return BinderHelper.Bind(this, _binder, new DynamicMetaObject[2] { target, value }, _argumentInfo, errorSuggestion);
		}

		[SpecialName]
		string ICSharpBinder.get_Name()
		{
			return base.Name;
		}
	}
	internal sealed class CSharpUnaryOperationBinder : UnaryOperationBinder, ICSharpBinder
	{
		private readonly CSharpArgumentInfo[] _argumentInfo;

		private readonly RuntimeBinder _binder;

		[ExcludeFromCodeCoverage]
		public string Name => null;

		public BindingFlag BindingFlags => (BindingFlag)0;

		public bool IsBinderThatCanHaveRefReceiver => false;

		public Expr DispatchPayload(RuntimeBinder runtimeBinder, ArgumentObject[] arguments, LocalVariableSymbol[] locals)
		{
			return runtimeBinder.BindUnaryOperation(this, arguments, locals);
		}

		public void PopulateSymbolTableWithName(Type callingType, ArgumentObject[] arguments)
		{
			SymbolTable.PopulateSymbolTableWithName(base.Operation.GetCLROperatorName(), null, arguments[0].Type);
		}

		CSharpArgumentInfo ICSharpBinder.GetArgumentInfo(int index)
		{
			return _argumentInfo[index];
		}

		public CSharpUnaryOperationBinder(ExpressionType operation, bool isChecked, Type callingContext, IEnumerable<CSharpArgumentInfo> argumentInfo)
			: base(operation)
		{
			_argumentInfo = BinderHelper.ToArray(argumentInfo);
			_binder = new RuntimeBinder(callingContext, isChecked);
		}

		public override DynamicMetaObject FallbackUnaryOperation(DynamicMetaObject target, DynamicMetaObject errorSuggestion)
		{
			BinderHelper.ValidateBindArgument(target, "target");
			return BinderHelper.Bind(this, _binder, new DynamicMetaObject[1] { target }, _argumentInfo, errorSuggestion);
		}
	}
	internal static class Error
	{
		internal static Exception InternalCompilerError()
		{
			return new RuntimeBinderInternalCompilerException("An unexpected exception occurred while binding a dynamic operation");
		}

		internal static Exception BindPropertyFailedMethodGroup(object p0)
		{
			return new RuntimeBinderException(SR.Format("The name '{0}' is bound to a method and cannot be used like a property", p0));
		}

		internal static Exception BindPropertyFailedEvent(object p0)
		{
			return new RuntimeBinderException(SR.Format("The event '{0}' can only appear on the left hand side of +", p0));
		}

		internal static Exception BindInvokeFailedNonDelegate()
		{
			return new RuntimeBinderException("Cannot invoke a non-delegate type");
		}

		internal static Exception BindStaticRequiresType(string paramName)
		{
			return new ArgumentException("The first argument to dynamically-bound static or constructor call must be a Type", paramName);
		}

		internal static Exception NullReferenceOnMemberException()
		{
			return new RuntimeBinderException("Cannot perform runtime binding on a null reference");
		}

		internal static Exception BindCallToConditionalMethod(object p0)
		{
			return new RuntimeBinderException(SR.Format("Cannot dynamically invoke method '{0}' because it has a Conditional attribute", p0));
		}

		internal static Exception BindToVoidMethodButExpectResult()
		{
			return new RuntimeBinderException("Cannot implicitly convert type 'void' to 'object'");
		}

		internal static Exception ArgumentNull(string paramName)
		{
			return new ArgumentNullException(paramName);
		}

		internal static Exception DynamicArgumentNeedsValue(string paramName)
		{
			return new ArgumentException("The runtime binder cannot bind a metaobject without a value", paramName);
		}
	}
	internal sealed class ExpressionTreeCallRewriter : ExprVisitorBase
	{
		private sealed class ExpressionExpr : Expr
		{
			public readonly Expression Expression;

			public ExpressionExpr(Expression e)
				: base(ExpressionKind.NoOp)
			{
				Expression = e;
			}
		}

		private readonly Dictionary<ExprCall, Expression> _DictionaryOfParameters;

		private readonly Expression[] _ListOfParameters;

		private int _currentParameterIndex;

		private ExpressionTreeCallRewriter(Expression[] listOfParameters)
		{
			_DictionaryOfParameters = new Dictionary<ExprCall, Expression>();
			_ListOfParameters = listOfParameters;
		}

		public static Expression Rewrite(ExprBinOp binOp, Expression[] listOfParameters)
		{
			ExpressionTreeCallRewriter expressionTreeCallRewriter = new ExpressionTreeCallRewriter(listOfParameters);
			expressionTreeCallRewriter.Visit(binOp.OptionalLeftChild);
			ExprCall pExpr = (ExprCall)binOp.OptionalRightChild;
			return (expressionTreeCallRewriter.Visit(pExpr) as ExpressionExpr).Expression;
		}

		protected override Expr VisitSAVE(ExprBinOp pExpr)
		{
			ExprCall key = (ExprCall)pExpr.OptionalLeftChild;
			Expression value = _ListOfParameters[_currentParameterIndex++];
			_DictionaryOfParameters.Add(key, value);
			return null;
		}

		protected override Expr VisitCALL(ExprCall pExpr)
		{
			if (pExpr.PredefinedMethod == PREDEFMETH.PM_COUNT)
			{
				return pExpr;
			}
			Expression e;
			switch (pExpr.PredefinedMethod)
			{
			case PREDEFMETH.PM_EXPRESSION_LAMBDA:
				return GenerateLambda(pExpr);
			case PREDEFMETH.PM_EXPRESSION_CALL:
				e = GenerateCall(pExpr);
				break;
			case PREDEFMETH.PM_EXPRESSION_ARRAYINDEX:
			case PREDEFMETH.PM_EXPRESSION_ARRAYINDEX2:
				e = GenerateArrayIndex(pExpr);
				break;
			case PREDEFMETH.PM_EXPRESSION_CONVERT:
			case PREDEFMETH.PM_EXPRESSION_CONVERT_USER_DEFINED:
			case PREDEFMETH.PM_EXPRESSION_CONVERTCHECKED:
			case PREDEFMETH.PM_EXPRESSION_CONVERTCHECKED_USER_DEFINED:
				e = GenerateConvert(pExpr);
				break;
			case PREDEFMETH.PM_EXPRESSION_PROPERTY:
				e = GenerateProperty(pExpr);
				break;
			case PREDEFMETH.PM_EXPRESSION_FIELD:
				e = GenerateField(pExpr);
				break;
			case PREDEFMETH.PM_EXPRESSION_INVOKE:
				e = GenerateInvoke(pExpr);
				break;
			case PREDEFMETH.PM_EXPRESSION_NEW:
				e = GenerateNew(pExpr);
				break;
			case PREDEFMETH.PM_EXPRESSION_ADD:
			case PREDEFMETH.PM_EXPRESSION_ADDCHECKED:
			case PREDEFMETH.PM_EXPRESSION_AND:
			case PREDEFMETH.PM_EXPRESSION_ANDALSO:
			case PREDEFMETH.PM_EXPRESSION_DIVIDE:
			case PREDEFMETH.PM_EXPRESSION_EQUAL:
			case PREDEFMETH.PM_EXPRESSION_EXCLUSIVEOR:
			case PREDEFMETH.PM_EXPRESSION_GREATERTHAN:
			case PREDEFMETH.PM_EXPRESSION_GREATERTHANOREQUAL:
			case PREDEFMETH.PM_EXPRESSION_LEFTSHIFT:
			case PREDEFMETH.PM_EXPRESSION_LESSTHAN:
			case PREDEFMETH.PM_EXPRESSION_LESSTHANOREQUAL:
			case PREDEFMETH.PM_EXPRESSION_MODULO:
			case PREDEFMETH.PM_EXPRESSION_MULTIPLY:
			case PREDEFMETH.PM_EXPRESSION_MULTIPLYCHECKED:
			case PREDEFMETH.PM_EXPRESSION_NOTEQUAL:
			case PREDEFMETH.PM_EXPRESSION_OR:
			case PREDEFMETH.PM_EXPRESSION_ORELSE:
			case PREDEFMETH.PM_EXPRESSION_RIGHTSHIFT:
			case PREDEFMETH.PM_EXPRESSION_SUBTRACT:
			case PREDEFMETH.PM_EXPRESSION_SUBTRACTCHECKED:
				e = GenerateBinaryOperator(pExpr);
				break;
			case PREDEFMETH.PM_EXPRESSION_ADD_USER_DEFINED:
			case PREDEFMETH.PM_EXPRESSION_ADDCHECKED_USER_DEFINED:
			case PREDEFMETH.PM_EXPRESSION_AND_USER_DEFINED:
			case PREDEFMETH.PM_EXPRESSION_ANDALSO_USER_DEFINED:
			case PREDEFMETH.PM_EXPRESSION_DIVIDE_USER_DEFINED:
			case PREDEFMETH.PM_EXPRESSION_EQUAL_USER_DEFINED:
			case PREDEFMETH.PM_EXPRESSION_EXCLUSIVEOR_USER_DEFINED:
			case PREDEFMETH.PM_EXPRESSION_GREATERTHAN_USER_DEFINED:
			case PREDEFMETH.PM_EXPRESSION_GREATERTHANOREQUAL_USER_DEFINED:
			case PREDEFMETH.PM_EXPRESSION_LEFTSHIFT_USER_DEFINED:
			case PREDEFMETH.PM_EXPRESSION_LESSTHAN_USER_DEFINED:
			case PREDEFMETH.PM_EXPRESSION_LESSTHANOREQUAL_USER_DEFINED:
			case PREDEFMETH.PM_EXPRESSION_MODULO_USER_DEFINED:
			case PREDEFMETH.PM_EXPRESSION_MULTIPLY_USER_DEFINED:
			case PREDEFMETH.PM_EXPRESSION_MULTIPLYCHECKED_USER_DEFINED:
			case PREDEFMETH.PM_EXPRESSION_NOTEQUAL_USER_DEFINED:
			case PREDEFMETH.PM_EXPRESSION_OR_USER_DEFINED:
			case PREDEFMETH.PM_EXPRESSION_ORELSE_USER_DEFINED:
			case PREDEFMETH.PM_EXPRESSION_RIGHTSHIFT_USER_DEFINED:
			case PREDEFMETH.PM_EXPRESSION_SUBTRACT_USER_DEFINED:
			case PREDEFMETH.PM_EXPRESSION_SUBTRACTCHECKED_USER_DEFINED:
				e = GenerateUserDefinedBinaryOperator(pExpr);
				break;
			case PREDEFMETH.PM_EXPRESSION_NEGATE:
			case PREDEFMETH.PM_EXPRESSION_NEGATECHECKED:
			case PREDEFMETH.PM_EXPRESSION_NOT:
				e = GenerateUnaryOperator(pExpr);
				break;
			case PREDEFMETH.PM_EXPRESSION_UNARYPLUS_USER_DEFINED:
			case PREDEFMETH.PM_EXPRESSION_NEGATE_USER_DEFINED:
			case PREDEFMETH.PM_EXPRESSION_NEGATECHECKED_USER_DEFINED:
			case PREDEFMETH.PM_EXPRESSION_NOT_USER_DEFINED:
				e = GenerateUserDefinedUnaryOperator(pExpr);
				break;
			case PREDEFMETH.PM_EXPRESSION_CONSTANT_OBJECT_TYPE:
				e = GenerateConstantType(pExpr);
				break;
			case PREDEFMETH.PM_EXPRESSION_ASSIGN:
				e = GenerateAssignment(pExpr);
				break;
			default:
				throw Error.InternalCompilerError();
			}
			return new ExpressionExpr(e);
		}

		protected override Expr VisitWRAP(ExprWrap pExpr)
		{
			return new ExpressionExpr(GetExpression(pExpr));
		}

		private Expr GenerateLambda(ExprCall pExpr)
		{
			return Visit(((ExprList)pExpr.OptionalArguments).OptionalElement);
		}

		private Expression GenerateCall(ExprCall pExpr)
		{
			ExprList exprList = (ExprList)pExpr.OptionalArguments;
			ExprMethodInfo exprMethodInfo;
			ExprArrayInit arrinit;
			if (exprList.OptionalNextListNode is ExprList exprList2)
			{
				exprMethodInfo = (ExprMethodInfo)exprList2.OptionalElement;
				arrinit = (ExprArrayInit)exprList2.OptionalNextListNode;
			}
			else
			{
				exprMethodInfo = (ExprMethodInfo)exprList.OptionalNextListNode;
				arrinit = null;
			}
			Expression instance = null;
			MethodInfo methodInfo = exprMethodInfo.MethodInfo;
			Expression[] argumentsFromArrayInit = GetArgumentsFromArrayInit(arrinit);
			if (methodInfo == null)
			{
				throw Error.InternalCompilerError();
			}
			if (!methodInfo.IsStatic)
			{
				instance = GetExpression(((ExprList)pExpr.OptionalArguments).OptionalElement);
			}
			return Expression.Call(instance, methodInfo, argumentsFromArrayInit);
		}

		private Expression GenerateArrayIndex(ExprCall pExpr)
		{
			ExprList exprList = (ExprList)pExpr.OptionalArguments;
			Expression expression = GetExpression(exprList.OptionalElement);
			Expression[] indexes = ((pExpr.PredefinedMethod != PREDEFMETH.PM_EXPRESSION_ARRAYINDEX) ? GetArgumentsFromArrayInit((ExprArrayInit)exprList.OptionalNextListNode) : new Expression[1] { GetExpression(exprList.OptionalNextListNode) });
			return Expression.ArrayAccess(expression, indexes);
		}

		private Expression GenerateConvert(ExprCall pExpr)
		{
			PREDEFMETH predefinedMethod = pExpr.PredefinedMethod;
			Expression expression;
			Type associatedSystemType;
			if (predefinedMethod == PREDEFMETH.PM_EXPRESSION_CONVERT_USER_DEFINED || predefinedMethod == PREDEFMETH.PM_EXPRESSION_CONVERTCHECKED_USER_DEFINED)
			{
				ExprList exprList = (ExprList)pExpr.OptionalArguments;
				ExprList exprList2 = (ExprList)exprList.OptionalNextListNode;
				expression = GetExpression(exprList.OptionalElement);
				associatedSystemType = ((ExprTypeOf)exprList2.OptionalElement).SourceType.AssociatedSystemType;
				if (expression.Type.MakeByRefType() == associatedSystemType)
				{
					return expression;
				}
				MethodInfo methodInfo = ((ExprMethodInfo)exprList2.OptionalNextListNode).MethodInfo;
				if (predefinedMethod == PREDEFMETH.PM_EXPRESSION_CONVERT_USER_DEFINED)
				{
					return Expression.Convert(expression, associatedSystemType, methodInfo);
				}
				return Expression.ConvertChecked(expression, associatedSystemType, methodInfo);
			}
			ExprList exprList3 = (ExprList)pExpr.OptionalArguments;
			expression = GetExpression(exprList3.OptionalElement);
			associatedSystemType = ((ExprTypeOf)exprList3.OptionalNextListNode).SourceType.AssociatedSystemType;
			if (expression.Type.MakeByRefType() == associatedSystemType)
			{
				return expression;
			}
			if ((pExpr.Flags & EXPRFLAG.EXF_USERCALLABLE) != 0)
			{
				return Expression.Unbox(expression, associatedSystemType);
			}
			if (predefinedMethod == PREDEFMETH.PM_EXPRESSION_CONVERT)
			{
				return Expression.Convert(expression, associatedSystemType);
			}
			return Expression.ConvertChecked(expression, associatedSystemType);
		}

		private Expression GenerateProperty(ExprCall pExpr)
		{
			ExprList obj = (ExprList)pExpr.OptionalArguments;
			Expr optionalElement = obj.OptionalElement;
			Expr optionalNextListNode = obj.OptionalNextListNode;
			ExprPropertyInfo exprPropertyInfo;
			ExprArrayInit exprArrayInit;
			if (optionalNextListNode is ExprList exprList)
			{
				exprPropertyInfo = exprList.OptionalElement as ExprPropertyInfo;
				exprArrayInit = exprList.OptionalNextListNode as ExprArrayInit;
			}
			else
			{
				exprPropertyInfo = optionalNextListNode as ExprPropertyInfo;
				exprArrayInit = null;
			}
			PropertyInfo propertyInfo = exprPropertyInfo.PropertyInfo;
			if (propertyInfo == null)
			{
				throw Error.InternalCompilerError();
			}
			if (exprArrayInit == null)
			{
				return Expression.Property(GetExpression(optionalElement), propertyInfo);
			}
			return Expression.Property(GetExpression(optionalElement), propertyInfo, GetArgumentsFromArrayInit(exprArrayInit));
		}

		private Expression GenerateField(ExprCall pExpr)
		{
			ExprList exprList = (ExprList)pExpr.OptionalArguments;
			ExprFieldInfo obj = (ExprFieldInfo)exprList.OptionalNextListNode;
			Type type = obj.FieldType.AssociatedSystemType;
			FieldInfo fieldInfo = obj.Field.AssociatedFieldInfo;
			if (!type.IsGenericType && !type.IsNested)
			{
				type = fieldInfo.DeclaringType;
			}
			if (type.IsGenericType)
			{
				fieldInfo = type.GetField(fieldInfo.Name, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
			}
			return Expression.Field(GetExpression(exprList.OptionalElement), fieldInfo);
		}

		private Expression GenerateInvoke(ExprCall pExpr)
		{
			ExprList exprList = (ExprList)pExpr.OptionalArguments;
			return Expression.Invoke(GetExpression(exprList.OptionalElement), GetArgumentsFromArrayInit(exprList.OptionalNextListNode as ExprArrayInit));
		}

		private Expression GenerateNew(ExprCall pExpr)
		{
			ExprList exprList = (ExprList)pExpr.OptionalArguments;
			ConstructorInfo constructorInfo = ((ExprMethodInfo)exprList.OptionalElement).ConstructorInfo;
			Expression[] argumentsFromArrayInit = GetArgumentsFromArrayInit(exprList.OptionalNextListNode as ExprArrayInit);
			return Expression.New(constructorInfo, argumentsFromArrayInit);
		}

		private static Expression GenerateConstantType(ExprCall pExpr)
		{
			ExprList exprList = (ExprList)pExpr.OptionalArguments;
			return Expression.Constant(exprList.OptionalElement.Object, ((ExprTypeOf)exprList.OptionalNextListNode).SourceType.AssociatedSystemType);
		}

		private Expression GenerateAssignment(ExprCall pExpr)
		{
			ExprList exprList = (ExprList)pExpr.OptionalArguments;
			return Expression.Assign(GetExpression(exprList.OptionalElement), GetExpression(exprList.OptionalNextListNode));
		}

		private Expression GenerateBinaryOperator(ExprCall pExpr)
		{
			ExprList exprList = (ExprList)pExpr.OptionalArguments;
			Expression expression = GetExpression(exprList.OptionalElement);
			Expression expression2 = GetExpression(exprList.OptionalNextListNode);
			return pExpr.PredefinedMethod switch
			{
				PREDEFMETH.PM_EXPRESSION_ADD => Expression.Add(expression, expression2), 
				PREDEFMETH.PM_EXPRESSION_AND => Expression.And(expression, expression2), 
				PREDEFMETH.PM_EXPRESSION_DIVIDE => Expression.Divide(expression, expression2), 
				PREDEFMETH.PM_EXPRESSION_EQUAL => Expression.Equal(expression, expression2), 
				PREDEFMETH.PM_EXPRESSION_EXCLUSIVEOR => Expression.ExclusiveOr(expression, expression2), 
				PREDEFMETH.PM_EXPRESSION_GREATERTHAN => Expression.GreaterThan(expression, expression2), 
				PREDEFMETH.PM_EXPRESSION_GREATERTHANOREQUAL => Expression.GreaterThanOrEqual(expression, expression2), 
				PREDEFMETH.PM_EXPRESSION_LEFTSHIFT => Expression.LeftShift(expression, expression2), 
				PREDEFMETH.PM_EXPRESSION_LESSTHAN => Expression.LessThan(expression, expression2), 
				PREDEFMETH.PM_EXPRESSION_LESSTHANOREQUAL => Expression.LessThanOrEqual(expression, expression2), 
				PREDEFMETH.PM_EXPRESSION_MODULO => Expression.Modulo(expression, expression2), 
				PREDEFMETH.PM_EXPRESSION_MULTIPLY => Expression.Multiply(expression, expression2), 
				PREDEFMETH.PM_EXPRESSION_NOTEQUAL => Expression.NotEqual(expression, expression2), 
				PREDEFMETH.PM_EXPRESSION_OR => Expression.Or(expression, expression2), 
				PREDEFMETH.PM_EXPRESSION_RIGHTSHIFT => Expression.RightShift(expression, expression2), 
				PREDEFMETH.PM_EXPRESSION_SUBTRACT => Expression.Subtract(expression, expression2), 
				PREDEFMETH.PM_EXPRESSION_ORELSE => Expression.OrElse(expression, expression2), 
				PREDEFMETH.PM_EXPRESSION_ANDALSO => Expression.AndAlso(expression, expression2), 
				PREDEFMETH.PM_EXPRESSION_ADDCHECKED => Expression.AddChecked(expression, expression2), 
				PREDEFMETH.PM_EXPRESSION_MULTIPLYCHECKED => Expression.MultiplyChecked(expression, expression2), 
				PREDEFMETH.PM_EXPRESSION_SUBTRACTCHECKED => Expression.SubtractChecked(expression, expression2), 
				_ => throw Error.InternalCompilerError(), 
			};
		}

		private Expression GenerateUserDefinedBinaryOperator(ExprCall pExpr)
		{
			ExprList exprList = (ExprList)pExpr.OptionalArguments;
			Expression expression = GetExpression(exprList.OptionalElement);
			Expression expression2 = GetExpression(((ExprList)exprList.OptionalNextListNode).OptionalElement);
			exprList = (ExprList)exprList.OptionalNextListNode;
			bool liftToNull = false;
			MethodInfo methodInfo;
			if (exprList.OptionalNextListNode is ExprList exprList2)
			{
				liftToNull = ((ExprConstant)exprList2.OptionalElement).Val.Int32Val == 1;
				methodInfo = ((ExprMethodInfo)exprList2.OptionalNextListNode).MethodInfo;
			}
			else
			{
				methodInfo = ((ExprMethodInfo)exprList.OptionalNextListNode).MethodInfo;
			}
			return pExpr.PredefinedMethod switch
			{
				PREDEFMETH.PM_EXPRESSION_ADD_USER_DEFINED => Expression.Add(expression, expression2, methodInfo), 
				PREDEFMETH.PM_EXPRESSION_AND_USER_DEFINED => Expression.And(expression, expression2, methodInfo), 
				PREDEFMETH.PM_EXPRESSION_DIVIDE_USER_DEFINED => Expression.Divide(expression, expression2, methodInfo), 
				PREDEFMETH.PM_EXPRESSION_EQUAL_USER_DEFINED => Expression.Equal(expression, expression2, liftToNull, methodInfo), 
				PREDEFMETH.PM_EXPRESSION_EXCLUSIVEOR_USER_DEFINED => Expression.ExclusiveOr(expression, expression2, methodInfo), 
				PREDEFMETH.PM_EXPRESSION_GREATERTHAN_USER_DEFINED => Expression.GreaterThan(expression, expression2, liftToNull, methodInfo), 
				PREDEFMETH.PM_EXPRESSION_GREATERTHANOREQUAL_USER_DEFINED => Expression.GreaterThanOrEqual(expression, expression2, liftToNull, methodInfo), 
				PREDEFMETH.PM_EXPRESSION_LEFTSHIFT_USER_DEFINED => Expression.LeftShift(expression, expression2, methodInfo), 
				PREDEFMETH.PM_EXPRESSION_LESSTHAN_USER_DEFINED => Expression.LessThan(expression, expression2, liftToNull, methodInfo), 
				PREDEFMETH.PM_EXPRESSION_LESSTHANOREQUAL_USER_DEFINED => Expression.LessThanOrEqual(expression, expression2, liftToNull, methodInfo), 
				PREDEFMETH.PM_EXPRESSION_MODULO_USER_DEFINED => Expression.Modulo(expression, expression2, methodInfo), 
				PREDEFMETH.PM_EXPRESSION_MULTIPLY_USER_DEFINED => Expression.Multiply(expression, expression2, methodInfo), 
				PREDEFMETH.PM_EXPRESSION_NOTEQUAL_USER_DEFINED => Expression.NotEqual(expression, expression2, liftToNull, methodInfo), 
				PREDEFMETH.PM_EXPRESSION_OR_USER_DEFINED => Expression.Or(expression, expression2, methodInfo), 
				PREDEFMETH.PM_EXPRESSION_RIGHTSHIFT_USER_DEFINED => Expression.RightShift(expression, expression2, methodInfo), 
				PREDEFMETH.PM_EXPRESSION_SUBTRACT_USER_DEFINED => Expression.Subtract(expression, expression2, methodInfo), 
				PREDEFMETH.PM_EXPRESSION_ORELSE_USER_DEFINED => Expression.OrElse(expression, expression2, methodInfo), 
				PREDEFMETH.PM_EXPRESSION_ANDALSO_USER_DEFINED => Expression.AndAlso(expression, expression2, methodInfo), 
				PREDEFMETH.PM_EXPRESSION_ADDCHECKED_USER_DEFINED => Expression.AddChecked(expression, expression2, methodInfo), 
				PREDEFMETH.PM_EXPRESSION_MULTIPLYCHECKED_USER_DEFINED => Expression.MultiplyChecked(expression, expression2, methodInfo), 
				PREDEFMETH.PM_EXPRESSION_SUBTRACTCHECKED_USER_DEFINED => Expression.SubtractChecked(expression, expression2, methodInfo), 
				_ => throw Error.InternalCompilerError(), 
			};
		}

		private Expression GenerateUnaryOperator(ExprCall pExpr)
		{
			PREDEFMETH predefinedMethod = pExpr.PredefinedMethod;
			Expression expression = GetExpression(pExpr.OptionalArguments);
			return predefinedMethod switch
			{
				PREDEFMETH.PM_EXPRESSION_NOT => Expression.Not(expression), 
				PREDEFMETH.PM_EXPRESSION_NEGATE => Expression.Negate(expression), 
				PREDEFMETH.PM_EXPRESSION_NEGATECHECKED => Expression.NegateChecked(expression), 
				_ => throw Error.InternalCompilerError(), 
			};
		}

		private Expression GenerateUserDefinedUnaryOperator(ExprCall pExpr)
		{
			PREDEFMETH predefinedMethod = pExpr.PredefinedMethod;
			ExprList exprList = (ExprList)pExpr.OptionalArguments;
			Expression expression = GetExpression(exprList.OptionalElement);
			MethodInfo methodInfo = ((ExprMethodInfo)exprList.OptionalNextListNode).MethodInfo;
			return predefinedMethod switch
			{
				PREDEFMETH.PM_EXPRESSION_NOT_USER_DEFINED => Expression.Not(expression, methodInfo), 
				PREDEFMETH.PM_EXPRESSION_NEGATE_USER_DEFINED => Expression.Negate(expression, methodInfo), 
				PREDEFMETH.PM_EXPRESSION_UNARYPLUS_USER_DEFINED => Expression.UnaryPlus(expression, methodInfo), 
				PREDEFMETH.PM_EXPRESSION_NEGATECHECKED_USER_DEFINED => Expression.NegateChecked(expression, methodInfo), 
				_ => throw Error.InternalCompilerError(), 
			};
		}

		private Expression GetExpression(Expr pExpr)
		{
			if (pExpr is ExprWrap exprWrap)
			{
				return _DictionaryOfParameters[(ExprCall)exprWrap.OptionalExpression];
			}
			if (pExpr is ExprConstant)
			{
				return null;
			}
			ExprCall exprCall = (ExprCall)pExpr;
			switch (exprCall.PredefinedMethod)
			{
			case PREDEFMETH.PM_EXPRESSION_CALL:
				return GenerateCall(exprCall);
			case PREDEFMETH.PM_EXPRESSION_CONVERT:
			case PREDEFMETH.PM_EXPRESSION_CONVERT_USER_DEFINED:
			case PREDEFMETH.PM_EXPRESSION_CONVERTCHECKED:
			case PREDEFMETH.PM_EXPRESSION_CONVERTCHECKED_USER_DEFINED:
				return GenerateConvert(exprCall);
			case PREDEFMETH.PM_EXPRESSION_NEWARRAYINIT:
			{
				ExprList exprList = (ExprList)exprCall.OptionalArguments;
				return Expression.NewArrayInit(((ExprTypeOf)exprList.OptionalElement).SourceType.AssociatedSystemType, GetArgumentsFromArrayInit((ExprArrayInit)exprList.OptionalNextListNode));
			}
			case PREDEFMETH.PM_EXPRESSION_ARRAYINDEX:
			case PREDEFMETH.PM_EXPRESSION_ARRAYINDEX2:
				return GenerateArrayIndex(exprCall);
			case PREDEFMETH.PM_EXPRESSION_NEW:
				return GenerateNew(exprCall);
			case PREDEFMETH.PM_EXPRESSION_PROPERTY:
				return GenerateProperty(exprCall);
			case PREDEFMETH.PM_EXPRESSION_FIELD:
				return GenerateField(exprCall);
			case PREDEFMETH.PM_EXPRESSION_CONSTANT_OBJECT_TYPE:
				return GenerateConstantType(exprCall);
			case PREDEFMETH.PM_EXPRESSION_ASSIGN:
				return GenerateAssignment(exprCall);
			case PREDEFMETH.PM_EXPRESSION_ADD:
			case PREDEFMETH.PM_EXPRESSION_ADDCHECKED:
			case PREDEFMETH.PM_EXPRESSION_AND:
			case PREDEFMETH.PM_EXPRESSION_ANDALSO:
			case PREDEFMETH.PM_EXPRESSION_DIVIDE:
			case PREDEFMETH.PM_EXPRESSION_EQUAL:
			case PREDEFMETH.PM_EXPRESSION_EXCLUSIVEOR:
			case PREDEFMETH.PM_EXPRESSION_GREATERTHAN:
			case PREDEFMETH.PM_EXPRESSION_GREATERTHANOREQUAL:
			case PREDEFMETH.PM_EXPRESSION_LEFTSHIFT:
			case PREDEFMETH.PM_EXPRESSION_LESSTHAN:
			case PREDEFMETH.PM_EXPRESSION_LESSTHANOREQUAL:
			case PREDEFMETH.PM_EXPRESSION_MODULO:
			case PREDEFMETH.PM_EXPRESSION_MULTIPLY:
			case PREDEFMETH.PM_EXPRESSION_MULTIPLYCHECKED:
			case PREDEFMETH.PM_EXPRESSION_NOTEQUAL:
			case PREDEFMETH.PM_EXPRESSION_OR:
			case PREDEFMETH.PM_EXPRESSION_ORELSE:
			case PREDEFMETH.PM_EXPRESSION_RIGHTSHIFT:
			case PREDEFMETH.PM_EXPRESSION_SUBTRACT:
			case PREDEFMETH.PM_EXPRESSION_SUBTRACTCHECKED:
				return GenerateBinaryOperator(exprCall);
			case PREDEFMETH.PM_EXPRESSION_ADD_USER_DEFINED:
			case PREDEFMETH.PM_EXPRESSION_ADDCHECKED_USER_DEFINED:
			case PREDEFMETH.PM_EXPRESSION_AND_USER_DEFINED:
			case PREDEFMETH.PM_EXPRESSION_ANDALSO_USER_DEFINED:
			case PREDEFMETH.PM_EXPRESSION_DIVIDE_USER_DEFINED:
			case PREDEFMETH.PM_EXPRESSION_EQUAL_USER_DEFINED:
			case PREDEFMETH.PM_EXPRESSION_EXCLUSIVEOR_USER_DEFINED:
			case PREDEFMETH.PM_EXPRESSION_GREATERTHAN_USER_DEFINED:
			case PREDEFMETH.PM_EXPRESSION_GREATERTHANOREQUAL_USER_DEFINED:
			case PREDEFMETH.PM_EXPRESSION_LEFTSHIFT_USER_DEFINED:
			case PREDEFMETH.PM_EXPRESSION_LESSTHAN_USER_DEFINED:
			case PREDEFMETH.PM_EXPRESSION_LESSTHANOREQUAL_USER_DEFINED:
			case PREDEFMETH.PM_EXPRESSION_MODULO_USER_DEFINED:
			case PREDEFMETH.PM_EXPRESSION_MULTIPLY_USER_DEFINED:
			case PREDEFMETH.PM_EXPRESSION_MULTIPLYCHECKED_USER_DEFINED:
			case PREDEFMETH.PM_EXPRESSION_NOTEQUAL_USER_DEFINED:
			case PREDEFMETH.PM_EXPRESSION_OR_USER_DEFINED:
			case PREDEFMETH.PM_EXPRESSION_ORELSE_USER_DEFINED:
			case PREDEFMETH.PM_EXPRESSION_RIGHTSHIFT_USER_DEFINED:
			case PREDEFMETH.PM_EXPRESSION_SUBTRACT_USER_DEFINED:
			case PREDEFMETH.PM_EXPRESSION_SUBTRACTCHECKED_USER_DEFINED:
				return GenerateUserDefinedBinaryOperator(exprCall);
			case PREDEFMETH.PM_EXPRESSION_NEGATE:
			case PREDEFMETH.PM_EXPRESSION_NEGATECHECKED:
			case PREDEFMETH.PM_EXPRESSION_NOT:
				return GenerateUnaryOperator(exprCall);
			case PREDEFMETH.PM_EXPRESSION_UNARYPLUS_USER_DEFINED:
			case PREDEFMETH.PM_EXPRESSION_NEGATE_USER_DEFINED:
			case PREDEFMETH.PM_EXPRESSION_NEGATECHECKED_USER_DEFINED:
			case PREDEFMETH.PM_EXPRESSION_NOT_USER_DEFINED:
				return GenerateUserDefinedUnaryOperator(exprCall);
			default:
				throw Error.InternalCompilerError();
			}
		}

		private Expression[] GetArgumentsFromArrayInit(ExprArrayInit arrinit)
		{
			List<Expression> list = new List<Expression>();
			if (arrinit != null)
			{
				Expr expr = arrinit.OptionalArguments;
				while (expr != null)
				{
					Expr pExpr;
					if (expr is ExprList exprList)
					{
						pExpr = exprList.OptionalElement;
						expr = exprList.OptionalNextListNode;
					}
					else
					{
						pExpr = expr;
						expr = null;
					}
					list.Add(GetExpression(pExpr));
				}
			}
			return list.ToArray();
		}
	}
	internal interface ICSharpBinder
	{
		bool IsBinderThatCanHaveRefReceiver { get; }

		BindingFlag BindingFlags { get; }

		string Name { get; }

		Type ReturnType { get; }

		CSharpArgumentInfo GetArgumentInfo(int index);

		void PopulateSymbolTableWithName(Type callingType, ArgumentObject[] arguments);

		Expr DispatchPayload(RuntimeBinder runtimeBinder, ArgumentObject[] arguments, LocalVariableSymbol[] locals);
	}
	internal interface ICSharpInvokeOrInvokeMemberBinder : ICSharpBinder
	{
		bool StaticCall { get; }

		bool ResultDiscarded { get; }

		CSharpCallFlags Flags { get; }

		Type[] TypeArguments { get; }
	}
	internal readonly struct RuntimeBinder
	{
		private static readonly object s_bindLock = new object();

		private readonly ExpressionBinder _binder;

		public RuntimeBinder(Type contextType, bool isChecked = false)
		{
			AggregateSymbol context;
			if (contextType != null)
			{
				lock (s_bindLock)
				{
					context = ((AggregateType)SymbolTable.GetCTypeFromType(contextType)).OwningAggregate;
				}
			}
			else
			{
				context = null;
			}
			_binder = new ExpressionBinder(new BindingContext(context, isChecked));
		}

		public Expression Bind(ICSharpBinder payload, Expression[] parameters, DynamicMetaObject[] args, out DynamicMetaObject deferredBinding)
		{
			lock (s_bindLock)
			{
				return BindCore(payload, parameters, args, out deferredBinding);
			}
		}

		private Expression BindCore(ICSharpBinder payload, Expression[] parameters, DynamicMetaObject[] args, out DynamicMetaObject deferredBinding)
		{
			ArgumentObject[] array = CreateArgumentArray(payload, parameters, args);
			payload.PopulateSymbolTableWithName(array[0].Type, array);
			AddConversionsForArguments(array);
			Scope pScope = SymFactory.CreateScope();
			LocalVariableSymbol[] locals = PopulateLocalScope(payload, pScope, array, parameters);
			if (DeferBinding(payload, array, args, locals, out deferredBinding))
			{
				return null;
			}
			Expr pResult = payload.DispatchPayload(this, array, locals);
			return CreateExpressionTreeFromResult(parameters, pScope, pResult);
		}

		[Conditional("DEBUG")]
		internal static void EnsureLockIsTaken()
		{
		}

		private bool DeferBinding(ICSharpBinder payload, ArgumentObject[] arguments, DynamicMetaObject[] args, LocalVariableSymbol[] locals, out DynamicMetaObject deferredBinding)
		{
			if (payload is CSharpInvokeMemberBinder cSharpInvokeMemberBinder)
			{
				Type[] typeArguments = cSharpInvokeMemberBinder.TypeArguments;
				int arity = ((typeArguments != null) ? typeArguments.Length : 0);
				MemberLookup mem = new MemberLookup();
				Expr callingObject = CreateCallingObjectForCall(cSharpInvokeMemberBinder, arguments, locals);
				SymWithType symWithType = SymbolTable.LookupMember(cSharpInvokeMemberBinder.Name, callingObject, _binder.Context.ContextForMemberLookup, arity, mem, (cSharpInvokeMemberBinder.Flags & CSharpCallFlags.EventHookup) != 0, requireInvocable: true);
				if (symWithType != null && symWithType.Sym.getKind() != SYMKIND.SK_MethodSymbol)
				{
					CSharpGetMemberBinder cSharpGetMemberBinder = new CSharpGetMemberBinder(cSharpInvokeMemberBinder.Name, resultIndexed: false, cSharpInvokeMemberBinder.CallingContext, new CSharpArgumentInfo[1] { cSharpInvokeMemberBinder.GetArgumentInfo(0) });
					CSharpArgumentInfo[] array = cSharpInvokeMemberBinder.ArgumentInfoArray();
					array[0] = CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null);
					CSharpInvokeBinder cSharpInvokeBinder = new CSharpInvokeBinder(cSharpInvokeMemberBinder.Flags, cSharpInvokeMemberBinder.CallingContext, array);
					DynamicMetaObject[] array2 = new DynamicMetaObject[args.Length - 1];
					Array.Copy(args, 1, array2, 0, args.Length - 1);
					deferredBinding = cSharpInvokeBinder.Defer(cSharpGetMemberBinder.Defer(args[0]), array2);
					return true;
				}
			}
			deferredBinding = null;
			return false;
		}

		private static Expression CreateExpressionTreeFromResult(Expression[] parameters, Scope pScope, Expr pResult)
		{
			return ExpressionTreeCallRewriter.Rewrite(ExpressionTreeRewriter.Rewrite(GenerateBoundLambda(pScope, pResult)), parameters);
		}

		private Type GetArgumentType(ICSharpBinder p, CSharpArgumentInfo argInfo, Expression param, DynamicMetaObject arg, int index)
		{
			Type type = (argInfo.UseCompileTimeType ? param.Type : arg.LimitType);
			if (argInfo.IsByRefOrOut)
			{
				if (index != 0 || !p.IsBinderThatCanHaveRefReceiver)
				{
					type = type.MakeByRefType();
				}
			}
			else if (!argInfo.UseCompileTimeType)
			{
				CType cTypeFromType = SymbolTable.GetCTypeFromType(type);
				type = TypeManager.GetBestAccessibleType(_binder.Context.ContextForMemberLookup, cTypeFromType).AssociatedSystemType;
			}
			return type;
		}

		private ArgumentObject[] CreateArgumentArray(ICSharpBinder payload, Expression[] parameters, DynamicMetaObject[] args)
		{
			ArgumentObject[] array = new ArgumentObject[parameters.Length];
			for (int i = 0; i < parameters.Length; i++)
			{
				CSharpArgumentInfo argumentInfo = payload.GetArgumentInfo(i);
				array[i] = new ArgumentObject(args[i].Value, argumentInfo, GetArgumentType(payload, argumentInfo, parameters[i], args[i], i));
			}
			return array;
		}

		internal static void PopulateSymbolTableWithPayloadInformation(ICSharpInvokeOrInvokeMemberBinder callOrInvoke, Type callingType, ArgumentObject[] arguments)
		{
			Type type;
			if (callOrInvoke.StaticCall)
			{
				type = arguments[0].Value as Type;
				if (type == null)
				{
					throw Error.BindStaticRequiresType(arguments[0].Info.Name);
				}
			}
			else
			{
				type = callingType;
			}
			SymbolTable.PopulateSymbolTableWithName(callOrInvoke.Name, callOrInvoke.TypeArguments, type);
			if (callOrInvoke.Name.StartsWith("set_", StringComparison.Ordinal) || callOrInvoke.Name.StartsWith("get_", StringComparison.Ordinal))
			{
				SymbolTable.PopulateSymbolTableWithName(callOrInvoke.Name.Substring(4), callOrInvoke.TypeArguments, type);
			}
		}

		private static void AddConversionsForArguments(ArgumentObject[] arguments)
		{
			for (int i = 0; i < arguments.Length; i++)
			{
				SymbolTable.AddConversionsForType(arguments[i].Type);
			}
		}

		internal ExprWithArgs DispatchPayload(ICSharpInvokeOrInvokeMemberBinder payload, ArgumentObject[] arguments, LocalVariableSymbol[] locals)
		{
			return BindCall(payload, CreateCallingObjectForCall(payload, arguments, locals), arguments, locals);
		}

		private static LocalVariableSymbol[] PopulateLocalScope(ICSharpBinder payload, Scope pScope, ArgumentObject[] arguments, Expression[] parameterExpressions)
		{
			LocalVariableSymbol[] array = new LocalVariableSymbol[parameterExpressions.Length];
			for (int i = 0; i < parameterExpressions.Length; i++)
			{
				Expression expression = parameterExpressions[i];
				CType cType = SymbolTable.GetCTypeFromType(expression.Type);
				if ((i != 0 || !payload.IsBinderThatCanHaveRefReceiver) && expression is ParameterExpression parameterExpression && parameterExpression.IsByRef)
				{
					CSharpArgumentInfo info = arguments[i].Info;
					if (info.IsByRefOrOut)
					{
						cType = TypeManager.GetParameterModifier(cType, info.IsOut);
					}
				}
				LocalVariableSymbol localVariableSymbol = SymFactory.CreateLocalVar(NameManager.Add("p" + i), pScope, cType);
				array[i] = localVariableSymbol;
			}
			return array;
		}

		private static ExprBoundLambda GenerateBoundLambda(Scope pScope, Expr call)
		{
			return ExprFactory.CreateAnonymousMethod(SymbolLoader.GetPredefindType(PredefinedType.PT_FUNC), pScope, call);
		}

		private Expr CreateLocal(Type type, bool isOut, LocalVariableSymbol local)
		{
			CType dest = ((!isOut) ? SymbolTable.GetCTypeFromType(type) : TypeManager.GetParameterModifier(SymbolTable.GetCTypeFromType(type.GetElementType()), isOut: true));
			ExprLocal expr = ExprFactory.CreateLocal(local);
			Expr obj = _binder.tryConvert(expr, dest) ?? _binder.mustCast(expr, dest);
			obj.Flags |= EXPRFLAG.EXF_LVALUE;
			return obj;
		}

		internal Expr CreateArgumentListEXPR(ArgumentObject[] arguments, LocalVariableSymbol[] locals, int startIndex, int endIndex)
		{
			Expr first = null;
			Expr last = null;
			if (arguments != null)
			{
				for (int i = startIndex; i < endIndex; i++)
				{
					ArgumentObject argument = arguments[i];
					Expr expr = CreateArgumentEXPR(argument, locals[i]);
					if (first == null)
					{
						first = expr;
						last = first;
					}
					else
					{
						ExprFactory.AppendItemToList(expr, ref first, ref last);
					}
				}
			}
			return first;
		}

		private Expr CreateArgumentEXPR(ArgumentObject argument, LocalVariableSymbol local)
		{
			Expr expr = (argument.Info.LiteralConstant ? ((argument.Value != null) ? ExprFactory.CreateConstant(SymbolTable.GetCTypeFromType(argument.Type), ConstVal.Get(argument.Value)) : ((!argument.Info.UseCompileTimeType) ? ExprFactory.CreateNull() : ExprFactory.CreateConstant(SymbolTable.GetCTypeFromType(argument.Type), default(ConstVal)))) : ((argument.Info.UseCompileTimeType || argument.Value != null) ? CreateLocal(argument.Type, argument.Info.IsOut, local) : ExprFactory.CreateNull()));
			if (argument.Info.NamedArgument)
			{
				expr = ExprFactory.CreateNamedArgumentSpecification(NameManager.Add(argument.Info.Name), expr);
			}
			if (!argument.Info.UseCompileTimeType && argument.Value != null)
			{
				expr.RuntimeObject = argument.Value;
				expr.RuntimeObjectActualType = SymbolTable.GetCTypeFromType(argument.Value.GetType());
			}
			return expr;
		}

		private static ExprMemberGroup CreateMemberGroupExpr(string Name, Type[] typeArguments, Expr callingObject, SYMKIND kind)
		{
			Name name = NameManager.Add(Name);
			CType type = callingObject.Type;
			AggregateType aggregateType = ((type is ArrayType) ? SymbolLoader.GetPredefindType(PredefinedType.PT_ARRAY) : ((!(type is NullableType nullableType)) ? ((AggregateType)type) : nullableType.GetAts()));
			HashSet<CType> hashSet = new HashSet<CType>();
			List<CType> list = new List<CType>();
			symbmask_t mask = symbmask_t.MASK_MethodSymbol;
			switch (kind)
			{
			case SYMKIND.SK_PropertySymbol:
			case SYMKIND.SK_IndexerSymbol:
				mask = symbmask_t.MASK_PropertySymbol;
				break;
			case SYMKIND.SK_MethodSymbol:
				mask = symbmask_t.MASK_MethodSymbol;
				break;
			}
			bool flag = name == NameManager.GetPredefinedName(PredefinedName.PN_CTOR);
			foreach (AggregateType item in aggregateType.TypeHierarchy)
			{
				if (SymbolTable.AggregateContainsMethod(item.OwningAggregate, Name, mask) && hashSet.Add(item))
				{
					list.Add(item);
				}
				if (flag)
				{
					break;
				}
			}
			if (aggregateType.IsWindowsRuntimeType)
			{
				CType[] items = aggregateType.WinRTCollectionIfacesAll.Items;
				for (int i = 0; i < items.Length; i++)
				{
					AggregateType aggregateType2 = (AggregateType)items[i];
					if (SymbolTable.AggregateContainsMethod(aggregateType2.OwningAggregate, Name, mask) && hashSet.Add(aggregateType2))
					{
						list.Add(aggregateType2);
					}
				}
			}
			EXPRFLAG eXPRFLAG = EXPRFLAG.EXF_USERCALLABLE;
			if (Name == "Invoke" && callingObject.Type.IsDelegateType)
			{
				eXPRFLAG |= EXPRFLAG.EXF_GOTONOTBLOCKED;
			}
			if (Name == ".ctor")
			{
				eXPRFLAG |= EXPRFLAG.EXF_CTOR;
			}
			if (Name == "$Item$")
			{
				eXPRFLAG |= EXPRFLAG.EXF_INDEXER;
			}
			TypeArray typeArgs = ((typeArguments != null && typeArguments.Length != 0) ? TypeArray.Allocate(SymbolTable.GetCTypeArrayFromTypes(typeArguments)) : TypeArray.Empty);
			ExprMemberGroup exprMemberGroup = ExprFactory.CreateMemGroup(eXPRFLAG, name, typeArgs, kind, aggregateType, null, new CMemberLookupResults(TypeArray.Allocate(list.ToArray()), name));
			if (callingObject is ExprClass)
			{
				exprMemberGroup.OptionalLHS = callingObject;
			}
			else
			{
				exprMemberGroup.OptionalObject = callingObject;
			}
			return exprMemberGroup;
		}

		private Expr CreateProperty(SymWithType swt, Expr callingObject, BindingFlag flags)
		{
			PropertySymbol propertySymbol = swt.Prop();
			AggregateType type = swt.GetType();
			PropWithType pwt = new PropWithType(propertySymbol, type);
			ExprMemberGroup pMemGroup = CreateMemberGroupExpr(propertySymbol.name.Text, null, callingObject, SYMKIND.SK_PropertySymbol);
			return _binder.BindToProperty((callingObject is ExprClass) ? null : callingObject, pwt, flags, null, pMemGroup);
		}

		private ExprWithArgs CreateIndexer(SymWithType swt, Expr callingObject, Expr arguments, BindingFlag bindFlags)
		{
			ExprMemberGroup grp = CreateMemberGroupExpr((swt.Sym as IndexerSymbol).name.Text, null, callingObject, SYMKIND.SK_PropertySymbol);
			ExprWithArgs result = _binder.BindMethodGroupToArguments(bindFlags, grp, arguments);
			ReorderArgumentsForNamedAndOptional(callingObject, result);
			return result;
		}

		private Expr CreateArray(Expr callingObject, Expr optionalIndexerArguments)
		{
			return _binder.BindArrayIndexCore(callingObject, optionalIndexerArguments);
		}

		private Expr CreateField(SymWithType swt, Expr callingObject)
		{
			FieldSymbol field = swt.Field();
			AggregateType type = swt.GetType();
			FieldWithType fwt = new FieldWithType(field, type);
			return _binder.BindToField((callingObject is ExprClass) ? null : callingObject, fwt, (BindingFlag)0);
		}

		private Expr CreateCallingObjectForCall(ICSharpInvokeOrInvokeMemberBinder payload, ArgumentObject[] arguments, LocalVariableSymbol[] locals)
		{
			Expr expr;
			if (payload.StaticCall)
			{
				expr = ExprFactory.CreateClass(SymbolTable.GetCTypeFromType(arguments[0].Value as Type));
			}
			else
			{
				if (!arguments[0].Info.UseCompileTimeType && arguments[0].Value == null)
				{
					throw Error.NullReferenceOnMemberException();
				}
				expr = _binder.mustConvert(CreateArgumentEXPR(arguments[0], locals[0]), SymbolTable.GetCTypeFromType(arguments[0].Type));
				if (arguments[0].Type.IsValueType && expr is ExprCast)
				{
					expr.Flags |= EXPRFLAG.EXF_USERCALLABLE;
				}
			}
			return expr;
		}

		private ExprWithArgs BindCall(ICSharpInvokeOrInvokeMemberBinder payload, Expr callingObject, ArgumentObject[] arguments, LocalVariableSymbol[] locals)
		{
			if (payload is InvokeBinder && !callingObject.Type.IsDelegateType)
			{
				throw Error.BindInvokeFailedNonDelegate();
			}
			Type[] typeArguments = payload.TypeArguments;
			int arity = ((typeArguments != null) ? typeArguments.Length : 0);
			MemberLookup memberLookup = new MemberLookup();
			SymWithType symWithType = SymbolTable.LookupMember(payload.Name, callingObject, _binder.Context.ContextForMemberLookup, arity, memberLookup, (payload.Flags & CSharpCallFlags.EventHookup) != 0, requireInvocable: true);
			if (symWithType == null)
			{
				throw memberLookup.ReportErrors();
			}
			if (symWithType.Sym.getKind() != SYMKIND.SK_MethodSymbol)
			{
				throw Error.InternalCompilerError();
			}
			ExprMemberGroup exprMemberGroup = CreateMemberGroupExpr(payload.Name, payload.TypeArguments, callingObject, symWithType.Sym.getKind());
			if ((payload.Flags & CSharpCallFlags.SimpleNameCall) != 0)
			{
				callingObject.Flags |= EXPRFLAG.EXF_UNREALIZEDGOTO;
			}
			if ((payload.Flags & CSharpCallFlags.EventHookup) != 0)
			{
				memberLookup = new MemberLookup();
				SymWithType symWithType2 = SymbolTable.LookupMember(payload.Name.Split('_')[1], callingObject, _binder.Context.ContextForMemberLookup, arity, memberLookup, (payload.Flags & CSharpCallFlags.EventHookup) != 0, requireInvocable: true);
				if (symWithType2 == null)
				{
					throw memberLookup.ReportErrors();
				}
				CType typeSrc = null;
				if (symWithType2.Sym.getKind() == SYMKIND.SK_FieldSymbol)
				{
					typeSrc = symWithType2.Field().GetType();
				}
				else if (symWithType2.Sym.getKind() == SYMKIND.SK_EventSymbol)
				{
					typeSrc = symWithType2.Event().type;
				}
				Type associatedSystemType = TypeManager.SubstType(typeSrc, symWithType2.Ats).AssociatedSystemType;
				if (associatedSystemType != null)
				{
					BindImplicitConversion(new ArgumentObject[1] { arguments[1] }, associatedSystemType, locals, bIsArrayCreationConversion: false);
				}
				exprMemberGroup.Flags &= ~EXPRFLAG.EXF_USERCALLABLE;
				if (symWithType2.Sym.getKind() == SYMKIND.SK_EventSymbol && symWithType2.Event().IsWindowsRuntimeEvent)
				{
					return BindWinRTEventAccessor(new EventWithType(symWithType2.Event(), symWithType2.Ats), callingObject, arguments, locals, payload.Name.StartsWith("add_", StringComparison.Ordinal));
				}
			}
			if ((payload.Name.StartsWith("set_", StringComparison.Ordinal) && ((MethodSymbol)symWithType.Sym).Params.Count > 1) || (payload.Name.StartsWith("get_", StringComparison.Ordinal) && ((MethodSymbol)symWithType.Sym).Params.Count > 0))
			{
				exprMemberGroup.Flags &= ~EXPRFLAG.EXF_USERCALLABLE;
			}
			ExprCall exprCall = _binder.BindMethodGroupToArguments(BindingFlag.BIND_RVALUEREQUIRED | BindingFlag.BIND_STMTEXPRONLY, exprMemberGroup, CreateArgumentListEXPR(arguments, locals, 1, arguments.Length)) as ExprCall;
			CheckForConditionalMethodError(exprCall);
			ReorderArgumentsForNamedAndOptional(callingObject, exprCall);
			return exprCall;
		}

		private ExprWithArgs BindWinRTEventAccessor(EventWithType ewt, Expr callingObject, ArgumentObject[] arguments, LocalVariableSymbol[] locals, bool isAddAccessor)
		{
			Type associatedSystemType = ewt.Event().type.AssociatedSystemType;
			MethPropWithInst method = new MethPropWithInst(ewt.Event().methRemove, ewt.Ats);
			ExprMemberGroup exprMemberGroup = ExprFactory.CreateMemGroup(callingObject, method);
			exprMemberGroup.Flags &= ~EXPRFLAG.EXF_USERCALLABLE;
			Type eventRegistrationTokenType = SymbolTable.EventRegistrationTokenType;
			Type actionType = Expression.GetActionType(eventRegistrationTokenType);
			Expr expr = _binder.mustConvert(exprMemberGroup, SymbolTable.GetCTypeFromType(actionType));
			Expr expr2 = CreateArgumentEXPR(arguments[1], locals[1]);
			ExprList args;
			string text;
			if (isAddAccessor)
			{
				MethPropWithInst method2 = new MethPropWithInst(ewt.Event().methAdd, ewt.Ats);
				ExprMemberGroup exprMemberGroup2 = ExprFactory.CreateMemGroup(callingObject, method2);
				exprMemberGroup2.Flags &= ~EXPRFLAG.EXF_USERCALLABLE;
				Type funcType = Expression.GetFuncType(associatedSystemType, eventRegistrationTokenType);
				args = ExprFactory.CreateList(_binder.mustConvert(exprMemberGroup2, SymbolTable.GetCTypeFromType(funcType)), expr, expr2);
				text = NameManager.GetPredefinedName(PredefinedName.PN_ADDEVENTHANDLER).Text;
			}
			else
			{
				args = ExprFactory.CreateList(expr, expr2);
				text = NameManager.GetPredefinedName(PredefinedName.PN_REMOVEEVENTHANDLER).Text;
			}
			Type windowsRuntimeMarshalType = SymbolTable.WindowsRuntimeMarshalType;
			SymbolTable.PopulateSymbolTableWithName(text, new List<Type> { associatedSystemType }, windowsRuntimeMarshalType);
			ExprClass callingObject2 = ExprFactory.CreateClass(SymbolTable.GetCTypeFromType(windowsRuntimeMarshalType));
			ExprMemberGroup grp = CreateMemberGroupExpr(text, new Type[1] { associatedSystemType }, callingObject2, SYMKIND.SK_MethodSymbol);
			return _binder.BindMethodGroupToArguments(BindingFlag.BIND_RVALUEREQUIRED | BindingFlag.BIND_STMTEXPRONLY, grp, args);
		}

		private static void CheckForConditionalMethodError(ExprCall call)
		{
			MethodSymbol methodSymbol = call.MethWithInst.Meth();
			if (methodSymbol.AssociatedMemberInfo.GetCustomAttributes(typeof(ConditionalAttribute), inherit: true).Length != 0)
			{
				throw Error.BindCallToConditionalMethod(methodSymbol.name);
			}
		}

		private void ReorderArgumentsForNamedAndOptional(Expr callingObject, ExprWithArgs result)
		{
			Expr optionalArguments = result.OptionalArguments;
			AggregateType ats;
			ExprMemberGroup memberGroup;
			TypeArray typeArgsMeth;
			MethodOrPropertySymbol methodOrPropertySymbol;
			if (result is ExprCall exprCall)
			{
				ats = exprCall.MethWithInst.Ats;
				methodOrPropertySymbol = exprCall.MethWithInst.Meth();
				memberGroup = exprCall.MemberGroup;
				typeArgsMeth = exprCall.MethWithInst.TypeArgs;
			}
			else
			{
				ExprProperty obj = result as ExprProperty;
				ats = obj.PropWithTypeSlot.Ats;
				methodOrPropertySymbol = obj.PropWithTypeSlot.Prop();
				memberGroup = obj.MemberGroup;
				typeArgsMeth = null;
			}
			ArgInfos argInfos = new ArgInfos
			{
				carg = ExpressionBinder.CountArguments(optionalArguments)
			};
			ExpressionBinder.FillInArgInfoFromArgList(argInfos, optionalArguments);
			TypeArray typeArray = TypeManager.SubstTypeArray(methodOrPropertySymbol.Params, ats, typeArgsMeth);
			methodOrPropertySymbol = ExpressionBinder.GroupToArgsBinder.FindMostDerivedMethod(methodOrPropertySymbol, callingObject.Type);
			ExpressionBinder.GroupToArgsBinder.ReOrderArgsForNamedArguments(methodOrPropertySymbol, typeArray, ats, memberGroup, argInfos);
			Expr expr = null;
			for (int num = argInfos.carg - 1; num >= 0; num--)
			{
				Expr pArg = argInfos.prgexpr[num];
				pArg = StripNamedArgument(pArg);
				pArg = _binder.tryConvert(pArg, typeArray[num]);
				expr = ((expr == null) ? pArg : ExprFactory.CreateList(pArg, expr));
			}
			result.OptionalArguments = expr;
		}

		private Expr StripNamedArgument(Expr pArg)
		{
			if (pArg is ExprNamedArgumentSpecification exprNamedArgumentSpecification)
			{
				pArg = exprNamedArgumentSpecification.Value;
			}
			else if (pArg is ExprArrayInit exprArrayInit)
			{
				exprArrayInit.OptionalArguments = StripNamedArguments(exprArrayInit.OptionalArguments);
			}
			return pArg;
		}

		private Expr StripNamedArguments(Expr pArg)
		{
			ExprList exprList = pArg as ExprList;
			if (exprList != null)
			{
				while (true)
				{
					exprList.OptionalElement = StripNamedArgument(exprList.OptionalElement);
					if (!(exprList.OptionalNextListNode is ExprList exprList2))
					{
						break;
					}
					exprList = exprList2;
				}
				exprList.OptionalNextListNode = StripNamedArgument(exprList.OptionalNextListNode);
			}
			return StripNamedArgument(pArg);
		}

		internal Expr BindUnaryOperation(CSharpUnaryOperationBinder payload, ArgumentObject[] arguments, LocalVariableSymbol[] locals)
		{
			OperatorKind operatorKind = GetOperatorKind(payload.Operation);
			Expr expr = CreateArgumentEXPR(arguments[0], locals[0]);
			expr.ErrorString = Operators.GetDisplayName(GetOperatorKind(payload.Operation));
			if (operatorKind == OperatorKind.OP_TRUE || operatorKind == OperatorKind.OP_FALSE)
			{
				Expr expr2 = _binder.tryConvert(expr, SymbolLoader.GetPredefindType(PredefinedType.PT_BOOL));
				if (expr2 != null && operatorKind == OperatorKind.OP_FALSE)
				{
					expr2 = _binder.BindStandardUnaryOperator(OperatorKind.OP_LOGNOT, expr2);
				}
				return expr2 ?? _binder.bindUDUnop((operatorKind == OperatorKind.OP_TRUE) ? ExpressionKind.True : ExpressionKind.False, expr) ?? _binder.mustConvert(expr, SymbolLoader.GetPredefindType(PredefinedType.PT_BOOL));
			}
			return _binder.BindStandardUnaryOperator(operatorKind, expr);
		}

		internal Expr BindBinaryOperation(CSharpBinaryOperationBinder payload, ArgumentObject[] arguments, LocalVariableSymbol[] locals)
		{
			ExpressionKind expressionKind = Operators.GetExpressionKind(GetOperatorKind(payload.Operation, payload.IsLogicalOperation));
			Expr expr = CreateArgumentEXPR(arguments[0], locals[0]);
			Expr expr2 = CreateArgumentEXPR(arguments[1], locals[1]);
			expr.ErrorString = Operators.GetDisplayName(GetOperatorKind(payload.Operation, payload.IsLogicalOperation));
			expr2.ErrorString = Operators.GetDisplayName(GetOperatorKind(payload.Operation, payload.IsLogicalOperation));
			if (expressionKind > ExpressionKind.MultiOffset)
			{
				expressionKind -= 71;
			}
			return _binder.BindStandardBinop(expressionKind, expr, expr2);
		}

		private static OperatorKind GetOperatorKind(ExpressionType p)
		{
			return GetOperatorKind(p, bIsLogical: false);
		}

		private static OperatorKind GetOperatorKind(ExpressionType p, bool bIsLogical)
		{
			switch (p)
			{
			default:
				throw Error.InternalCompilerError();
			case ExpressionType.Add:
				return OperatorKind.OP_ADD;
			case ExpressionType.Subtract:
				return OperatorKind.OP_SUB;
			case ExpressionType.Multiply:
				return OperatorKind.OP_MUL;
			case ExpressionType.Divide:
				return OperatorKind.OP_DIV;
			case ExpressionType.Modulo:
				return OperatorKind.OP_MOD;
			case ExpressionType.LeftShift:
				return OperatorKind.OP_LSHIFT;
			case ExpressionType.RightShift:
				return OperatorKind.OP_RSHIFT;
			case ExpressionType.LessThan:
				return OperatorKind.OP_LT;
			case ExpressionType.GreaterThan:
				return OperatorKind.OP_GT;
			case ExpressionType.LessThanOrEqual:
				return OperatorKind.OP_LE;
			case ExpressionType.GreaterThanOrEqual:
				return OperatorKind.OP_GE;
			case ExpressionType.Equal:
				return OperatorKind.OP_EQ;
			case ExpressionType.NotEqual:
				return OperatorKind.OP_NEQ;
			case ExpressionType.And:
				if (!bIsLogical)
				{
					return OperatorKind.OP_BITAND;
				}
				return OperatorKind.OP_LOGAND;
			case ExpressionType.ExclusiveOr:
				return Operator

BepInExPack/mono/Managed/Mono.Posix.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Messaging;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters;
using System.Runtime.Serialization.Formatters.Binary;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using Mono.Unix;
using Mono.Unix.Native;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("Mono.Posix.dll")]
[assembly: AssemblyDescription("Unix Integration Classes")]
[assembly: CLSCompliant(true)]
[assembly: ComVisible(false)]
[assembly: AssemblyDelaySign(true)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("4.0.0.0")]
[module: UnverifiableCode]
internal static class Consts
{
	public const string MonoCorlibVersion = "1A5E0066-58DC-428A-B21C-0AD6CDAE2789";

	public const string MonoVersion = "6.13.0.0";

	public const string MonoCompany = "Mono development team";

	public const string MonoProduct = "Mono Common Language Infrastructure";

	public const string MonoCopyright = "(c) Various Mono authors";

	public const string FxVersion = "4.0.0.0";

	public const string FxFileVersion = "4.6.57.0";

	public const string EnvironmentVersion = "4.0.30319.42000";

	public const string VsVersion = "0.0.0.0";

	public const string VsFileVersion = "11.0.0.0";

	private const string PublicKeyToken = "b77a5c561934e089";

	public const string AssemblyI18N = "I18N, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756";

	public const string AssemblyMicrosoft_JScript = "Microsoft.JScript, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblyMicrosoft_VisualStudio = "Microsoft.VisualStudio, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblyMicrosoft_VisualStudio_Web = "Microsoft.VisualStudio.Web, Version=0.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblyMicrosoft_VSDesigner = "Microsoft.VSDesigner, Version=0.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblyMono_Http = "Mono.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756";

	public const string AssemblyMono_Posix = "Mono.Posix, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756";

	public const string AssemblyMono_Security = "Mono.Security, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756";

	public const string AssemblyMono_Messaging_RabbitMQ = "Mono.Messaging.RabbitMQ, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756";

	public const string AssemblyCorlib = "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string AssemblySystem = "System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string AssemblySystem_Data = "System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string AssemblySystem_Design = "System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_DirectoryServices = "System.DirectoryServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_Drawing = "System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_Drawing_Design = "System.Drawing.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_Messaging = "System.Messaging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_Security = "System.Security, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_ServiceProcess = "System.ServiceProcess, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_Web = "System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_Windows_Forms = "System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string AssemblySystem_2_0 = "System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string AssemblySystemCore_3_5 = "System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string AssemblySystem_Core = "System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string WindowsBase_3_0 = "WindowsBase, Version=3.0.0.0, PublicKeyToken=31bf3856ad364e35";

	public const string AssemblyWindowsBase = "WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";

	public const string AssemblyPresentationCore_3_5 = "PresentationCore, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";

	public const string AssemblyPresentationCore_4_0 = "PresentationCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";

	public const string AssemblyPresentationFramework_3_5 = "PresentationFramework, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";

	public const string AssemblySystemServiceModel_3_0 = "System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";
}
internal sealed class Locale
{
	private Locale()
	{
	}

	public static string GetText(string msg)
	{
		return msg;
	}

	public static string GetText(string fmt, params object[] args)
	{
		return string.Format(fmt, args);
	}
}
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Field | AttributeTargets.Delegate)]
internal class MapAttribute : Attribute
{
	private string nativeType;

	private string suppressFlags;

	public string NativeType => nativeType;

	public string SuppressFlags
	{
		get
		{
			return suppressFlags;
		}
		set
		{
			suppressFlags = value;
		}
	}

	public MapAttribute()
	{
	}

	public MapAttribute(string nativeType)
	{
		this.nativeType = nativeType;
	}
}
namespace Mono.Unix
{
	[Serializable]
	public class AbstractUnixEndPoint : EndPoint
	{
		private string path;

		public string Path
		{
			get
			{
				return path;
			}
			set
			{
				path = value;
			}
		}

		public override AddressFamily AddressFamily => AddressFamily.Unix;

		public AbstractUnixEndPoint(string path)
		{
			if (path == null)
			{
				throw new ArgumentNullException("path");
			}
			if (path == "")
			{
				throw new ArgumentException("Cannot be empty.", "path");
			}
			this.path = path;
		}

		public override EndPoint Create(SocketAddress socketAddress)
		{
			byte[] array = new byte[socketAddress.Size - 2 - 1];
			for (int i = 0; i < array.Length; i++)
			{
				array[i] = socketAddress[3 + i];
			}
			return new AbstractUnixEndPoint(Encoding.Default.GetString(array));
		}

		public override SocketAddress Serialize()
		{
			byte[] bytes = Encoding.Default.GetBytes(path);
			SocketAddress socketAddress = new SocketAddress(AddressFamily, 3 + bytes.Length);
			socketAddress[2] = 0;
			for (int i = 0; i < bytes.Length; i++)
			{
				socketAddress[i + 2 + 1] = bytes[i];
			}
			return socketAddress;
		}

		public override string ToString()
		{
			return path;
		}

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

		public override bool Equals(object o)
		{
			if (!(o is AbstractUnixEndPoint abstractUnixEndPoint))
			{
				return false;
			}
			return abstractUnixEndPoint.path == path;
		}
	}
	public class Catalog
	{
		private Catalog()
		{
		}

		[DllImport("intl", CallingConvention = CallingConvention.Cdecl)]
		private static extern IntPtr bindtextdomain(IntPtr domainname, IntPtr dirname);

		[DllImport("intl", CallingConvention = CallingConvention.Cdecl)]
		private static extern IntPtr bind_textdomain_codeset(IntPtr domainname, IntPtr codeset);

		[DllImport("intl", CallingConvention = CallingConvention.Cdecl)]
		private static extern IntPtr textdomain(IntPtr domainname);

		public static void Init(string package, string localedir)
		{
			MarshalStrings(package, out var p, localedir, out var p2, "UTF-8", out var p3);
			try
			{
				if (bindtextdomain(p, p2) == IntPtr.Zero)
				{
					throw new UnixIOException(Errno.ENOMEM);
				}
				if (bind_textdomain_codeset(p, p3) == IntPtr.Zero)
				{
					throw new UnixIOException(Errno.ENOMEM);
				}
				if (textdomain(p) == IntPtr.Zero)
				{
					throw new UnixIOException(Errno.ENOMEM);
				}
			}
			finally
			{
				UnixMarshal.FreeHeap(p);
				UnixMarshal.FreeHeap(p2);
				UnixMarshal.FreeHeap(p3);
			}
		}

		private static void MarshalStrings(string s1, out IntPtr p1, string s2, out IntPtr p2, string s3, out IntPtr p3)
		{
			p1 = (p2 = (p3 = IntPtr.Zero));
			bool flag = true;
			try
			{
				p1 = UnixMarshal.StringToHeap(s1);
				p2 = UnixMarshal.StringToHeap(s2);
				if (s3 != null)
				{
					p3 = UnixMarshal.StringToHeap(s3);
				}
				flag = false;
			}
			finally
			{
				if (flag)
				{
					UnixMarshal.FreeHeap(p1);
					UnixMarshal.FreeHeap(p2);
					UnixMarshal.FreeHeap(p3);
				}
			}
		}

		[DllImport("intl", CallingConvention = CallingConvention.Cdecl)]
		private static extern IntPtr gettext(IntPtr instring);

		public static string GetString(string s)
		{
			IntPtr intPtr = UnixMarshal.StringToHeap(s);
			try
			{
				IntPtr intPtr2 = gettext(intPtr);
				if (intPtr2 != intPtr)
				{
					return UnixMarshal.PtrToStringUnix(intPtr2);
				}
				return s;
			}
			finally
			{
				UnixMarshal.FreeHeap(intPtr);
			}
		}

		[DllImport("intl", CallingConvention = CallingConvention.Cdecl)]
		private static extern IntPtr ngettext(IntPtr singular, IntPtr plural, int n);

		public static string GetPluralString(string s, string p, int n)
		{
			MarshalStrings(s, out var p2, p, out var p3, null, out var _);
			try
			{
				IntPtr intPtr = ngettext(p2, p3, n);
				if (intPtr == p2)
				{
					return s;
				}
				if (intPtr == p3)
				{
					return p;
				}
				return UnixMarshal.PtrToStringUnix(intPtr);
			}
			finally
			{
				UnixMarshal.FreeHeap(p2);
				UnixMarshal.FreeHeap(p3);
			}
		}
	}
	public enum FileAccessPattern
	{
		Normal = 0,
		Sequential = 2,
		Random = 1,
		NoReuse = 5,
		PreLoad = 3,
		FlushCache = 4
	}
	[Flags]
	public enum FileAccessPermissions
	{
		UserReadWriteExecute = 0x1C0,
		UserRead = 0x100,
		UserWrite = 0x80,
		UserExecute = 0x40,
		GroupReadWriteExecute = 0x38,
		GroupRead = 0x20,
		GroupWrite = 0x10,
		GroupExecute = 8,
		OtherReadWriteExecute = 7,
		OtherRead = 4,
		OtherWrite = 2,
		OtherExecute = 1,
		DefaultPermissions = 0x1B6,
		AllPermissions = 0x1FF
	}
	public sealed class FileHandleOperations
	{
		private FileHandleOperations()
		{
		}

		public static void AdviseFileAccessPattern(int fd, FileAccessPattern pattern, long offset, long len)
		{
			UnixMarshal.ThrowExceptionForLastErrorIf(Syscall.posix_fadvise(fd, offset, len, (PosixFadviseAdvice)pattern));
		}

		public static void AdviseFileAccessPattern(int fd, FileAccessPattern pattern)
		{
			AdviseFileAccessPattern(fd, pattern, 0L, 0L);
		}

		public static void AdviseFileAccessPattern(FileStream file, FileAccessPattern pattern, long offset, long len)
		{
			if (file == null)
			{
				throw new ArgumentNullException("file");
			}
			UnixMarshal.ThrowExceptionForLastErrorIf(Syscall.posix_fadvise(file.Handle.ToInt32(), offset, len, (PosixFadviseAdvice)pattern));
		}

		public static void AdviseFileAccessPattern(FileStream file, FileAccessPattern pattern)
		{
			AdviseFileAccessPattern(file, pattern, 0L, 0L);
		}

		public static void AdviseFileAccessPattern(UnixStream stream, FileAccessPattern pattern, long offset, long len)
		{
			if (stream == null)
			{
				throw new ArgumentNullException("stream");
			}
			UnixMarshal.ThrowExceptionForLastErrorIf(Syscall.posix_fadvise(stream.Handle, offset, len, (PosixFadviseAdvice)pattern));
		}

		public static void AdviseFileAccessPattern(UnixStream stream, FileAccessPattern pattern)
		{
			AdviseFileAccessPattern(stream, pattern, 0L, 0L);
		}
	}
	[Flags]
	public enum FileSpecialAttributes
	{
		SetUserId = 0x800,
		SetGroupId = 0x400,
		Sticky = 0x200
	}
	public enum FileTypes
	{
		Directory = 16384,
		CharacterDevice = 8192,
		BlockDevice = 24576,
		RegularFile = 32768,
		Fifo = 4096,
		SymbolicLink = 40960,
		Socket = 49152
	}
	internal struct PeerCredData
	{
		public int pid;

		public int uid;

		public int gid;
	}
	public class PeerCred
	{
		private const int so_peercred = 10001;

		private PeerCredData data;

		public int ProcessID => data.pid;

		public int UserID => data.uid;

		public int GroupID => data.gid;

		public PeerCred(Socket sock)
		{
			if (sock.AddressFamily != AddressFamily.Unix)
			{
				throw new ArgumentException("Only Unix sockets are supported", "sock");
			}
			data = (PeerCredData)sock.GetSocketOption(SocketOptionLevel.Socket, (SocketOptionName)10001);
		}
	}
	public class StdioFileStream : Stream
	{
		public static readonly IntPtr InvalidFileStream = IntPtr.Zero;

		public static readonly IntPtr StandardInput = Stdlib.stdin;

		public static readonly IntPtr StandardOutput = Stdlib.stdout;

		public static readonly IntPtr StandardError = Stdlib.stderr;

		private bool canSeek;

		private bool canRead;

		private bool canWrite;

		private bool owner = true;

		private IntPtr file = InvalidFileStream;

		public IntPtr Handle
		{
			get
			{
				AssertNotDisposed();
				GC.KeepAlive(this);
				return file;
			}
		}

		public override bool CanRead => canRead;

		public override bool CanSeek => canSeek;

		public override bool CanWrite => canWrite;

		public override long Length
		{
			get
			{
				AssertNotDisposed();
				if (!CanSeek)
				{
					throw new NotSupportedException("File Stream doesn't support seeking");
				}
				long num = Stdlib.ftell(file);
				if (num == -1)
				{
					throw new NotSupportedException("Unable to obtain current file position");
				}
				UnixMarshal.ThrowExceptionForLastErrorIf(Stdlib.fseek(file, 0L, SeekFlags.SEEK_END));
				long num2 = Stdlib.ftell(file);
				if (num2 == -1)
				{
					UnixMarshal.ThrowExceptionForLastError();
				}
				UnixMarshal.ThrowExceptionForLastErrorIf(Stdlib.fseek(file, num, SeekFlags.SEEK_SET));
				GC.KeepAlive(this);
				return num2;
			}
		}

		public override long Position
		{
			get
			{
				AssertNotDisposed();
				if (!CanSeek)
				{
					throw new NotSupportedException("The stream does not support seeking");
				}
				long num = Stdlib.ftell(file);
				if (num == -1)
				{
					UnixMarshal.ThrowExceptionForLastError();
				}
				GC.KeepAlive(this);
				return num;
			}
			set
			{
				AssertNotDisposed();
				Seek(value, SeekOrigin.Begin);
			}
		}

		public StdioFileStream(IntPtr fileStream)
			: this(fileStream, ownsHandle: true)
		{
		}

		public StdioFileStream(IntPtr fileStream, bool ownsHandle)
		{
			InitStream(fileStream, ownsHandle);
		}

		public StdioFileStream(IntPtr fileStream, FileAccess access)
			: this(fileStream, access, ownsHandle: true)
		{
		}

		public StdioFileStream(IntPtr fileStream, FileAccess access, bool ownsHandle)
		{
			InitStream(fileStream, ownsHandle);
			InitCanReadWrite(access);
		}

		public StdioFileStream(string path)
		{
			if (path == null)
			{
				throw new ArgumentNullException("path");
			}
			InitStream(Fopen(path, "rb"), ownsHandle: true);
		}

		public StdioFileStream(string path, string mode)
		{
			if (path == null)
			{
				throw new ArgumentNullException("path");
			}
			InitStream(Fopen(path, mode), ownsHandle: true);
		}

		public StdioFileStream(string path, FileMode mode)
		{
			if (path == null)
			{
				throw new ArgumentNullException("path");
			}
			InitStream(Fopen(path, ToFopenMode(path, mode)), ownsHandle: true);
		}

		public StdioFileStream(string path, FileAccess access)
		{
			if (path == null)
			{
				throw new ArgumentNullException("path");
			}
			InitStream(Fopen(path, ToFopenMode(path, access)), ownsHandle: true);
			InitCanReadWrite(access);
		}

		public StdioFileStream(string path, FileMode mode, FileAccess access)
		{
			if (path == null)
			{
				throw new ArgumentNullException("path");
			}
			InitStream(Fopen(path, ToFopenMode(path, mode, access)), ownsHandle: true);
			InitCanReadWrite(access);
		}

		private static IntPtr Fopen(string path, string mode)
		{
			if (path.Length == 0)
			{
				throw new ArgumentException("path");
			}
			if (mode == null)
			{
				throw new ArgumentNullException("mode");
			}
			IntPtr intPtr = Stdlib.fopen(path, mode);
			if (intPtr == IntPtr.Zero)
			{
				throw new DirectoryNotFoundException("path", UnixMarshal.CreateExceptionForLastError());
			}
			return intPtr;
		}

		private void InitStream(IntPtr fileStream, bool ownsHandle)
		{
			if (InvalidFileStream == fileStream)
			{
				throw new ArgumentException(Locale.GetText("Invalid file stream"), "fileStream");
			}
			file = fileStream;
			owner = ownsHandle;
			try
			{
				if ((long)Stdlib.fseek(file, 0L, SeekFlags.SEEK_CUR) != -1)
				{
					canSeek = true;
				}
				Stdlib.fread(IntPtr.Zero, 0uL, 0uL, file);
				if (Stdlib.ferror(file) == 0)
				{
					canRead = true;
				}
				Stdlib.fwrite(IntPtr.Zero, 0uL, 0uL, file);
				if (Stdlib.ferror(file) == 0)
				{
					canWrite = true;
				}
				Stdlib.clearerr(file);
			}
			catch (Exception)
			{
				throw new ArgumentException(Locale.GetText("Invalid file stream"), "fileStream");
			}
			GC.KeepAlive(this);
		}

		private void InitCanReadWrite(FileAccess access)
		{
			canRead = canRead && (access == FileAccess.Read || access == FileAccess.ReadWrite);
			canWrite = canWrite && (access == FileAccess.Write || access == FileAccess.ReadWrite);
		}

		private static string ToFopenMode(string file, FileMode mode)
		{
			string result = NativeConvert.ToFopenMode(mode);
			AssertFileMode(file, mode);
			return result;
		}

		private static string ToFopenMode(string file, FileAccess access)
		{
			return NativeConvert.ToFopenMode(access);
		}

		private static string ToFopenMode(string file, FileMode mode, FileAccess access)
		{
			string result = NativeConvert.ToFopenMode(mode, access);
			bool flag = AssertFileMode(file, mode);
			if (mode == FileMode.OpenOrCreate && access == FileAccess.Read && !flag)
			{
				result = "w+b";
			}
			return result;
		}

		private static bool AssertFileMode(string file, FileMode mode)
		{
			bool flag = FileExists(file);
			if (mode == FileMode.CreateNew && flag)
			{
				throw new IOException("File exists and FileMode.CreateNew specified");
			}
			if ((mode == FileMode.Open || mode == FileMode.Truncate) && !flag)
			{
				throw new FileNotFoundException("File doesn't exist and FileMode.Open specified", file);
			}
			return flag;
		}

		private static bool FileExists(string file)
		{
			IntPtr intPtr = Stdlib.fopen(file, "r");
			bool result = intPtr != IntPtr.Zero;
			if (intPtr != IntPtr.Zero)
			{
				Stdlib.fclose(intPtr);
			}
			return result;
		}

		private void AssertNotDisposed()
		{
			if (file == InvalidFileStream)
			{
				throw new ObjectDisposedException("Invalid File Stream");
			}
			GC.KeepAlive(this);
		}

		public void SaveFilePosition(FilePosition pos)
		{
			AssertNotDisposed();
			UnixMarshal.ThrowExceptionForLastErrorIf(Stdlib.fgetpos(file, pos));
			GC.KeepAlive(this);
		}

		public void RestoreFilePosition(FilePosition pos)
		{
			AssertNotDisposed();
			if (pos == null)
			{
				throw new ArgumentNullException("value");
			}
			UnixMarshal.ThrowExceptionForLastErrorIf(Stdlib.fsetpos(file, pos));
			GC.KeepAlive(this);
		}

		public override void Flush()
		{
			AssertNotDisposed();
			if (Stdlib.fflush(file) != 0)
			{
				UnixMarshal.ThrowExceptionForLastError();
			}
			GC.KeepAlive(this);
		}

		public unsafe override int Read([In][Out] byte[] buffer, int offset, int count)
		{
			AssertNotDisposed();
			AssertValidBuffer(buffer, offset, count);
			if (!CanRead)
			{
				throw new NotSupportedException("Stream does not support reading");
			}
			ulong num;
			fixed (byte* ptr = &buffer[offset])
			{
				num = Stdlib.fread(ptr, 1uL, (ulong)count, file);
			}
			if (num != (ulong)count && Stdlib.ferror(file) != 0)
			{
				throw new IOException();
			}
			GC.KeepAlive(this);
			return (int)num;
		}

		private void AssertValidBuffer(byte[] buffer, int offset, int count)
		{
			if (buffer == null)
			{
				throw new ArgumentNullException("buffer");
			}
			if (offset < 0)
			{
				throw new ArgumentOutOfRangeException("offset", "< 0");
			}
			if (count < 0)
			{
				throw new ArgumentOutOfRangeException("count", "< 0");
			}
			if (offset > buffer.Length)
			{
				throw new ArgumentException("destination offset is beyond array size");
			}
			if (offset > buffer.Length - count)
			{
				throw new ArgumentException("would overrun buffer");
			}
		}

		public void Rewind()
		{
			AssertNotDisposed();
			Stdlib.rewind(file);
			GC.KeepAlive(this);
		}

		public override long Seek(long offset, SeekOrigin origin)
		{
			AssertNotDisposed();
			if (!CanSeek)
			{
				throw new NotSupportedException("The File Stream does not support seeking");
			}
			SeekFlags seekFlags = SeekFlags.SEEK_CUR;
			if (Stdlib.fseek(origin: origin switch
			{
				SeekOrigin.Begin => SeekFlags.SEEK_SET, 
				SeekOrigin.Current => SeekFlags.SEEK_CUR, 
				SeekOrigin.End => SeekFlags.SEEK_END, 
				_ => throw new ArgumentException("origin"), 
			}, stream: file, offset: offset) != 0)
			{
				throw new IOException("Unable to seek", UnixMarshal.CreateExceptionForLastError());
			}
			long num = Stdlib.ftell(file);
			if (num == -1)
			{
				throw new IOException("Unable to get current file position", UnixMarshal.CreateExceptionForLastError());
			}
			GC.KeepAlive(this);
			return num;
		}

		public override void SetLength(long value)
		{
			throw new NotSupportedException("ANSI C doesn't provide a way to truncate a file");
		}

		public unsafe override void Write(byte[] buffer, int offset, int count)
		{
			AssertNotDisposed();
			AssertValidBuffer(buffer, offset, count);
			if (!CanWrite)
			{
				throw new NotSupportedException("File Stream does not support writing");
			}
			ulong num;
			fixed (byte* ptr = &buffer[offset])
			{
				num = Stdlib.fwrite(ptr, 1uL, (ulong)count, file);
			}
			if (num != (ulong)count)
			{
				UnixMarshal.ThrowExceptionForLastError();
			}
			GC.KeepAlive(this);
		}

		~StdioFileStream()
		{
			Close();
		}

		public override void Close()
		{
			if (file == InvalidFileStream)
			{
				return;
			}
			if (owner)
			{
				if (Stdlib.fclose(file) != 0)
				{
					UnixMarshal.ThrowExceptionForLastError();
				}
			}
			else
			{
				Flush();
			}
			file = InvalidFileStream;
			canRead = false;
			canSeek = false;
			canWrite = false;
			GC.SuppressFinalize(this);
			GC.KeepAlive(this);
		}
	}
	public class UnixClient : MarshalByRefObject, IDisposable
	{
		private NetworkStream stream;

		private Socket client;

		private bool disposed;

		public Socket Client
		{
			get
			{
				return client;
			}
			set
			{
				client = value;
				stream = null;
			}
		}

		public PeerCred PeerCredential
		{
			get
			{
				CheckDisposed();
				return new PeerCred(client);
			}
		}

		public LingerOption LingerState
		{
			get
			{
				CheckDisposed();
				return (LingerOption)client.GetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Linger);
			}
			set
			{
				CheckDisposed();
				client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Linger, value);
			}
		}

		public int ReceiveBufferSize
		{
			get
			{
				CheckDisposed();
				return (int)client.GetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveBuffer);
			}
			set
			{
				CheckDisposed();
				client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveBuffer, value);
			}
		}

		public int ReceiveTimeout
		{
			get
			{
				CheckDisposed();
				return (int)client.GetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout);
			}
			set
			{
				CheckDisposed();
				client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, value);
			}
		}

		public int SendBufferSize
		{
			get
			{
				CheckDisposed();
				return (int)client.GetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendBuffer);
			}
			set
			{
				CheckDisposed();
				client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendBuffer, value);
			}
		}

		public int SendTimeout
		{
			get
			{
				CheckDisposed();
				return (int)client.GetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout);
			}
			set
			{
				CheckDisposed();
				client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, value);
			}
		}

		public UnixClient()
		{
			if (client != null)
			{
				client.Close();
				client = null;
			}
			client = new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.IP);
		}

		public UnixClient(string path)
			: this()
		{
			if (path == null)
			{
				throw new ArgumentNullException("ep");
			}
			Connect(path);
		}

		public UnixClient(UnixEndPoint ep)
			: this()
		{
			if (ep == null)
			{
				throw new ArgumentNullException("ep");
			}
			Connect(ep);
		}

		internal UnixClient(Socket sock)
		{
			Client = sock;
		}

		public void Close()
		{
			CheckDisposed();
			Dispose();
		}

		public void Connect(UnixEndPoint remoteEndPoint)
		{
			CheckDisposed();
			client.Connect(remoteEndPoint);
			stream = new NetworkStream(client, ownsSocket: true);
		}

		public void Connect(string path)
		{
			CheckDisposed();
			Connect(new UnixEndPoint(path));
		}

		public void Dispose()
		{
			Dispose(disposing: true);
			GC.SuppressFinalize(this);
		}

		protected virtual void Dispose(bool disposing)
		{
			if (disposed)
			{
				return;
			}
			if (disposing)
			{
				NetworkStream networkStream = stream;
				stream = null;
				if (networkStream != null)
				{
					networkStream.Close();
					networkStream = null;
				}
				else if (client != null)
				{
					client.Close();
				}
				client = null;
			}
			disposed = true;
		}

		public NetworkStream GetStream()
		{
			CheckDisposed();
			if (stream == null)
			{
				stream = new NetworkStream(client, ownsSocket: true);
			}
			return stream;
		}

		private void CheckDisposed()
		{
			if (disposed)
			{
				throw new ObjectDisposedException(GetType().FullName);
			}
		}

		~UnixClient()
		{
			Dispose(disposing: false);
		}
	}
	public sealed class UnixDirectoryInfo : UnixFileSystemInfo
	{
		public override string Name
		{
			get
			{
				string fileName = UnixPath.GetFileName(base.FullPath);
				if (fileName == null || fileName.Length == 0)
				{
					return base.FullPath;
				}
				return fileName;
			}
		}

		public UnixDirectoryInfo Parent
		{
			get
			{
				if (base.FullPath == "/")
				{
					return this;
				}
				string directoryName = UnixPath.GetDirectoryName(base.FullPath);
				if (directoryName == "")
				{
					throw new InvalidOperationException("Do not know parent directory for path `" + base.FullPath + "'");
				}
				return new UnixDirectoryInfo(directoryName);
			}
		}

		public UnixDirectoryInfo Root
		{
			get
			{
				string pathRoot = UnixPath.GetPathRoot(base.FullPath);
				if (pathRoot == null)
				{
					return null;
				}
				return new UnixDirectoryInfo(pathRoot);
			}
		}

		public UnixDirectoryInfo(string path)
			: base(path)
		{
		}

		internal UnixDirectoryInfo(string path, Stat stat)
			: base(path, stat)
		{
		}

		[CLSCompliant(false)]
		public void Create(FilePermissions mode)
		{
			UnixMarshal.ThrowExceptionForLastErrorIf(Syscall.mkdir(base.FullPath, mode));
			Refresh();
		}

		public void Create(FileAccessPermissions mode)
		{
			Create((FilePermissions)mode);
		}

		public void Create()
		{
			FilePermissions mode = FilePermissions.ACCESSPERMS;
			Create(mode);
		}

		public override void Delete()
		{
			Delete(recursive: false);
		}

		public void Delete(bool recursive)
		{
			if (recursive)
			{
				UnixFileSystemInfo[] fileSystemEntries = GetFileSystemEntries();
				foreach (UnixFileSystemInfo unixFileSystemInfo in fileSystemEntries)
				{
					if (unixFileSystemInfo is UnixDirectoryInfo unixDirectoryInfo)
					{
						unixDirectoryInfo.Delete(recursive: true);
					}
					else
					{
						unixFileSystemInfo.Delete();
					}
				}
			}
			UnixMarshal.ThrowExceptionForLastErrorIf(Syscall.rmdir(base.FullPath));
			Refresh();
		}

		public Dirent[] GetEntries()
		{
			IntPtr intPtr = Syscall.opendir(base.FullPath);
			if (intPtr == IntPtr.Zero)
			{
				UnixMarshal.ThrowExceptionForLastError();
			}
			bool flag = false;
			try
			{
				Dirent[] entries = GetEntries(intPtr);
				flag = true;
				return entries;
			}
			finally
			{
				int retval = Syscall.closedir(intPtr);
				if (flag)
				{
					UnixMarshal.ThrowExceptionForLastErrorIf(retval);
				}
			}
		}

		private static Dirent[] GetEntries(IntPtr dirp)
		{
			ArrayList arrayList = new ArrayList();
			int num;
			IntPtr result;
			do
			{
				Dirent dirent = new Dirent();
				num = Syscall.readdir_r(dirp, dirent, out result);
				if (num == 0 && result != IntPtr.Zero && dirent.d_name != "." && dirent.d_name != "..")
				{
					arrayList.Add(dirent);
				}
			}
			while (num == 0 && result != IntPtr.Zero);
			if (num != 0)
			{
				UnixMarshal.ThrowExceptionForLastErrorIf(num);
			}
			return (Dirent[])arrayList.ToArray(typeof(Dirent));
		}

		public Dirent[] GetEntries(Regex regex)
		{
			IntPtr intPtr = Syscall.opendir(base.FullPath);
			if (intPtr == IntPtr.Zero)
			{
				UnixMarshal.ThrowExceptionForLastError();
			}
			try
			{
				return GetEntries(intPtr, regex);
			}
			finally
			{
				UnixMarshal.ThrowExceptionForLastErrorIf(Syscall.closedir(intPtr));
			}
		}

		private static Dirent[] GetEntries(IntPtr dirp, Regex regex)
		{
			ArrayList arrayList = new ArrayList();
			int num;
			IntPtr result;
			do
			{
				Dirent dirent = new Dirent();
				num = Syscall.readdir_r(dirp, dirent, out result);
				if (num == 0 && result != IntPtr.Zero && regex.Match(dirent.d_name).Success && dirent.d_name != "." && dirent.d_name != "..")
				{
					arrayList.Add(dirent);
				}
			}
			while (num == 0 && result != IntPtr.Zero);
			if (num != 0)
			{
				UnixMarshal.ThrowExceptionForLastError();
			}
			return (Dirent[])arrayList.ToArray(typeof(Dirent));
		}

		public Dirent[] GetEntries(string regex)
		{
			Regex regex2 = new Regex(regex);
			return GetEntries(regex2);
		}

		public UnixFileSystemInfo[] GetFileSystemEntries()
		{
			Dirent[] entries = GetEntries();
			return GetFileSystemEntries(entries);
		}

		private UnixFileSystemInfo[] GetFileSystemEntries(Dirent[] dentries)
		{
			UnixFileSystemInfo[] array = new UnixFileSystemInfo[dentries.Length];
			for (int i = 0; i != array.Length; i++)
			{
				array[i] = UnixFileSystemInfo.GetFileSystemEntry(UnixPath.Combine(base.FullPath, dentries[i].d_name));
			}
			return array;
		}

		public UnixFileSystemInfo[] GetFileSystemEntries(Regex regex)
		{
			Dirent[] entries = GetEntries(regex);
			return GetFileSystemEntries(entries);
		}

		public UnixFileSystemInfo[] GetFileSystemEntries(string regex)
		{
			Regex regex2 = new Regex(regex);
			return GetFileSystemEntries(regex2);
		}

		public static string GetCurrentDirectory()
		{
			StringBuilder stringBuilder = new StringBuilder(16);
			IntPtr zero = IntPtr.Zero;
			do
			{
				stringBuilder.Capacity *= 2;
				zero = Syscall.getcwd(stringBuilder, (ulong)stringBuilder.Capacity);
			}
			while (zero == IntPtr.Zero && Stdlib.GetLastError() == Errno.ERANGE);
			if (zero == IntPtr.Zero)
			{
				UnixMarshal.ThrowExceptionForLastError();
			}
			return stringBuilder.ToString();
		}

		public static void SetCurrentDirectory(string path)
		{
			UnixMarshal.ThrowExceptionForLastErrorIf(Syscall.chdir(path));
		}
	}
	public enum UnixDriveType
	{
		Unknown,
		NoRootDirectory,
		Removable,
		Fixed,
		Network,
		CDRom,
		Ram
	}
	public sealed class UnixDriveInfo
	{
		private Statvfs stat;

		private string fstype;

		private string mount_point;

		private string block_device;

		public long AvailableFreeSpace
		{
			get
			{
				Refresh();
				return Convert.ToInt64(stat.f_bavail * stat.f_frsize);
			}
		}

		public string DriveFormat => fstype;

		public UnixDriveType DriveType => UnixDriveType.Unknown;

		public bool IsReady
		{
			get
			{
				bool flag = Refresh(throwException: false);
				if (mount_point == "/" || !flag)
				{
					return flag;
				}
				if (Syscall.statvfs(RootDirectory.Parent.FullName, out var buf) != 0)
				{
					return false;
				}
				return buf.f_fsid != stat.f_fsid;
			}
		}

		public string Name => mount_point;

		public UnixDirectoryInfo RootDirectory => new UnixDirectoryInfo(mount_point);

		public long TotalFreeSpace
		{
			get
			{
				Refresh();
				return (long)(stat.f_bfree * stat.f_frsize);
			}
		}

		public long TotalSize
		{
			get
			{
				Refresh();
				return (long)(stat.f_frsize * stat.f_blocks);
			}
		}

		public string VolumeLabel => block_device;

		public long MaximumFilenameLength
		{
			get
			{
				Refresh();
				return Convert.ToInt64(stat.f_namemax);
			}
		}

		public UnixDriveInfo(string mountPoint)
		{
			if (mountPoint == null)
			{
				throw new ArgumentNullException("mountPoint");
			}
			Fstab fstab = Syscall.getfsfile(mountPoint);
			if (fstab != null)
			{
				FromFstab(fstab);
				return;
			}
			mount_point = mountPoint;
			block_device = "";
			fstype = "Unknown";
		}

		private void FromFstab(Fstab fstab)
		{
			fstype = fstab.fs_vfstype;
			mount_point = fstab.fs_file;
			block_device = fstab.fs_spec;
		}

		public static UnixDriveInfo GetForSpecialFile(string specialFile)
		{
			if (specialFile == null)
			{
				throw new ArgumentNullException("specialFile");
			}
			Fstab fstab = Syscall.getfsspec(specialFile);
			if (fstab == null)
			{
				throw new ArgumentException("specialFile isn't valid: " + specialFile);
			}
			return new UnixDriveInfo(fstab);
		}

		private UnixDriveInfo(Fstab fstab)
		{
			FromFstab(fstab);
		}

		public static UnixDriveInfo[] GetDrives()
		{
			ArrayList arrayList = new ArrayList();
			lock (Syscall.fstab_lock)
			{
				if (Syscall.setfsent() != 1)
				{
					throw new IOException("Error calling setfsent(3)", new UnixIOException());
				}
				try
				{
					Fstab fstab;
					while ((fstab = Syscall.getfsent()) != null)
					{
						if (fstab.fs_file != null && fstab.fs_file.StartsWith("/"))
						{
							arrayList.Add(new UnixDriveInfo(fstab));
						}
					}
				}
				finally
				{
					Syscall.endfsent();
				}
			}
			return (UnixDriveInfo[])arrayList.ToArray(typeof(UnixDriveInfo));
		}

		public override string ToString()
		{
			return VolumeLabel;
		}

		private void Refresh()
		{
			Refresh(throwException: true);
		}

		private bool Refresh(bool throwException)
		{
			int num = Syscall.statvfs(mount_point, out stat);
			if (num == -1 && throwException)
			{
				Errno lastError = Stdlib.GetLastError();
				throw new InvalidOperationException(UnixMarshal.GetErrorDescription(lastError), new UnixIOException(lastError));
			}
			if (num == -1)
			{
				return false;
			}
			return true;
		}
	}
	[Serializable]
	public class UnixEncoding : Encoding
	{
		[Serializable]
		private class UnixDecoder : Decoder
		{
			private uint leftOverBits;

			private uint leftOverCount;

			public UnixDecoder()
			{
				leftOverBits = 0u;
				leftOverCount = 0u;
			}

			public override int GetCharCount(byte[] bytes, int index, int count)
			{
				return InternalGetCharCount(bytes, index, count, leftOverBits, leftOverCount, throwOnInvalid: true, flush: false);
			}

			public override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex)
			{
				return InternalGetChars(bytes, byteIndex, byteCount, chars, charIndex, ref leftOverBits, ref leftOverCount, throwOnInvalid: true, flush: false);
			}
		}

		[Serializable]
		private class UnixEncoder : Encoder
		{
			private uint leftOver;

			public UnixEncoder()
			{
				leftOver = 0u;
			}

			public override int GetByteCount(char[] chars, int index, int count, bool flush)
			{
				return InternalGetByteCount(chars, index, count, leftOver, flush);
			}

			public override int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteCount, bool flush)
			{
				return InternalGetBytes(chars, charIndex, charCount, bytes, byteCount, ref leftOver, flush);
			}
		}

		public static readonly Encoding Instance = new UnixEncoding();

		public static readonly char EscapeByte = '\0';

		private static int InternalGetByteCount(char[] chars, int index, int count, uint leftOver, bool flush)
		{
			if (chars == null)
			{
				throw new ArgumentNullException("chars");
			}
			if (index < 0 || index > chars.Length)
			{
				throw new ArgumentOutOfRangeException("index", _("ArgRange_Array"));
			}
			if (count < 0 || count > chars.Length - index)
			{
				throw new ArgumentOutOfRangeException("count", _("ArgRange_Array"));
			}
			int num = 0;
			uint num2 = leftOver;
			while (count > 0)
			{
				char c = chars[index];
				if (num2 == 0)
				{
					if (c == EscapeByte && count > 1)
					{
						num++;
						index++;
						count--;
					}
					else if (c < '\u0080')
					{
						num++;
					}
					else if (c < 'ࠀ')
					{
						num += 2;
					}
					else if (c >= '\ud800' && c <= '\udbff')
					{
						num2 = c;
					}
					else
					{
						num += 3;
					}
				}
				else
				{
					if (c < '\udc00' || c > '\udfff')
					{
						num += 3;
						num2 = 0u;
						continue;
					}
					num += 4;
					num2 = 0u;
				}
				index++;
				count--;
			}
			if (flush && num2 != 0)
			{
				num += 3;
			}
			return num;
		}

		public override int GetByteCount(char[] chars, int index, int count)
		{
			return InternalGetByteCount(chars, index, count, 0u, flush: true);
		}

		public override int GetByteCount(string s)
		{
			if (s == null)
			{
				throw new ArgumentNullException("s");
			}
			int num = 0;
			int num2 = s.Length;
			int num3 = 0;
			while (num2 > 0)
			{
				char c = s[num++];
				if (c == EscapeByte && num2 > 1)
				{
					num3++;
					num++;
					num2--;
				}
				else if (c < '\u0080')
				{
					num3++;
				}
				else if (c < 'ࠀ')
				{
					num3 += 2;
				}
				else if (c >= '\ud800' && c <= '\udbff' && num2 > 1)
				{
					uint num4 = s[num];
					if (num4 >= 56320 && num4 <= 57343)
					{
						num3 += 4;
						num++;
						num2--;
					}
					else
					{
						num3 += 3;
					}
				}
				else
				{
					num3 += 3;
				}
				num2--;
			}
			return num3;
		}

		private static int InternalGetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex, ref uint leftOver, bool flush)
		{
			if (chars == null)
			{
				throw new ArgumentNullException("chars");
			}
			if (bytes == null)
			{
				throw new ArgumentNullException("bytes");
			}
			if (charIndex < 0 || charIndex > chars.Length)
			{
				throw new ArgumentOutOfRangeException("charIndex", _("ArgRange_Array"));
			}
			if (charCount < 0 || charCount > chars.Length - charIndex)
			{
				throw new ArgumentOutOfRangeException("charCount", _("ArgRange_Array"));
			}
			if (byteIndex < 0 || byteIndex > bytes.Length)
			{
				throw new ArgumentOutOfRangeException("byteIndex", _("ArgRange_Array"));
			}
			int num = bytes.Length;
			uint num2 = leftOver;
			int num3 = byteIndex;
			while (charCount > 0)
			{
				char c = chars[charIndex++];
				charCount--;
				uint num4;
				if (num2 == 0)
				{
					if (c >= '\ud800' && c <= '\udbff')
					{
						num2 = c;
						continue;
					}
					if (c == EscapeByte)
					{
						if (num3 >= num)
						{
							throw new ArgumentException(_("Arg_InsufficientSpace"), "bytes");
						}
						if (--charCount >= 0)
						{
							bytes[num3++] = (byte)chars[charIndex++];
						}
						continue;
					}
					num4 = c;
				}
				else if (c >= '\udc00' && c <= '\udfff')
				{
					num4 = (uint)((int)(num2 - 55296 << 10) + (c - 56320) + 65536);
					num2 = 0u;
				}
				else
				{
					num4 = num2;
					num2 = 0u;
					charIndex--;
					charCount++;
				}
				if (num4 < 128)
				{
					if (num3 >= num)
					{
						throw new ArgumentException(_("Arg_InsufficientSpace"), "bytes");
					}
					bytes[num3++] = (byte)num4;
					continue;
				}
				if (num4 < 2048)
				{
					if (num3 + 2 > num)
					{
						throw new ArgumentException(_("Arg_InsufficientSpace"), "bytes");
					}
					bytes[num3++] = (byte)(0xC0u | (num4 >> 6));
					bytes[num3++] = (byte)(0x80u | (num4 & 0x3Fu));
					continue;
				}
				if (num4 < 65536)
				{
					if (num3 + 3 > num)
					{
						throw new ArgumentException(_("Arg_InsufficientSpace"), "bytes");
					}
					bytes[num3++] = (byte)(0xE0u | (num4 >> 12));
					bytes[num3++] = (byte)(0x80u | ((num4 >> 6) & 0x3Fu));
					bytes[num3++] = (byte)(0x80u | (num4 & 0x3Fu));
					continue;
				}
				if (num3 + 4 > num)
				{
					throw new ArgumentException(_("Arg_InsufficientSpace"), "bytes");
				}
				bytes[num3++] = (byte)(0xF0u | (num4 >> 18));
				bytes[num3++] = (byte)(0x80u | ((num4 >> 12) & 0x3Fu));
				bytes[num3++] = (byte)(0x80u | ((num4 >> 6) & 0x3Fu));
				bytes[num3++] = (byte)(0x80u | (num4 & 0x3Fu));
			}
			if (flush && num2 != 0)
			{
				if (num3 + 3 > num)
				{
					throw new ArgumentException(_("Arg_InsufficientSpace"), "bytes");
				}
				bytes[num3++] = (byte)(0xE0u | (num2 >> 12));
				bytes[num3++] = (byte)(0x80u | ((num2 >> 6) & 0x3Fu));
				bytes[num3++] = (byte)(0x80u | (num2 & 0x3Fu));
				num2 = 0u;
			}
			leftOver = num2;
			return num3 - byteIndex;
		}

		public override int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex)
		{
			uint leftOver = 0u;
			return InternalGetBytes(chars, charIndex, charCount, bytes, byteIndex, ref leftOver, flush: true);
		}

		public unsafe override int GetBytes(string s, int charIndex, int charCount, byte[] bytes, int byteIndex)
		{
			if (s == null)
			{
				throw new ArgumentNullException("s");
			}
			if (bytes == null)
			{
				throw new ArgumentNullException("bytes");
			}
			if (charIndex < 0 || charIndex > s.Length)
			{
				throw new ArgumentOutOfRangeException("charIndex", _("ArgRange_StringIndex"));
			}
			if (charCount < 0 || charCount > s.Length - charIndex)
			{
				throw new ArgumentOutOfRangeException("charCount", _("ArgRange_StringRange"));
			}
			if (byteIndex < 0 || byteIndex > bytes.Length)
			{
				throw new ArgumentOutOfRangeException("byteIndex", _("ArgRange_Array"));
			}
			fixed (char* ptr = s)
			{
				fixed (byte* ptr2 = bytes)
				{
					return GetBytes(ptr + charIndex, charCount, ptr2 + byteIndex, bytes.Length - byteIndex);
				}
			}
		}

		public unsafe override int GetBytes(char* chars, int charCount, byte* bytes, int byteCount)
		{
			if ((bytes == null && byteCount != 0) || (chars == null && charCount != 0))
			{
				throw new ArgumentNullException((bytes == null && byteCount != 0) ? "bytes" : "chars");
			}
			if (charCount < 0 || byteCount < 0)
			{
				throw new ArgumentOutOfRangeException((charCount < 0) ? "charCount" : "byteCount");
			}
			int num = 0;
			int num2 = 0;
			while (charCount > 0)
			{
				char c = chars[num2++];
				uint num3;
				if (c >= '\ud800' && c <= '\udbff' && charCount > 1)
				{
					num3 = chars[num2];
					if (num3 >= 56320 && num3 <= 57343)
					{
						num3 = (uint)((int)(num3 - 56320) + (c - 55296 << 10) + 65536);
						num2++;
						charCount--;
					}
					else
					{
						num3 = c;
					}
				}
				else
				{
					if (c == EscapeByte && charCount > 1)
					{
						if (num >= byteCount)
						{
							throw new ArgumentException(_("Arg_InsufficientSpace"), "bytes");
						}
						charCount -= 2;
						if (charCount >= 0)
						{
							bytes[num++] = (byte)chars[num2++];
						}
						continue;
					}
					num3 = c;
				}
				charCount--;
				if (num3 < 128)
				{
					if (num >= byteCount)
					{
						throw new ArgumentException(_("Arg_InsufficientSpace"), "bytes");
					}
					bytes[num++] = (byte)num3;
					continue;
				}
				if (num3 < 2048)
				{
					if (num + 2 > byteCount)
					{
						throw new ArgumentException(_("Arg_InsufficientSpace"), "bytes");
					}
					bytes[num++] = (byte)(0xC0u | (num3 >> 6));
					bytes[num++] = (byte)(0x80u | (num3 & 0x3Fu));
					continue;
				}
				if (num3 < 65536)
				{
					if (num + 3 > byteCount)
					{
						throw new ArgumentException(_("Arg_InsufficientSpace"), "bytes");
					}
					bytes[num++] = (byte)(0xE0u | (num3 >> 12));
					bytes[num++] = (byte)(0x80u | ((num3 >> 6) & 0x3Fu));
					bytes[num++] = (byte)(0x80u | (num3 & 0x3Fu));
					continue;
				}
				if (num + 4 > byteCount)
				{
					throw new ArgumentException(_("Arg_InsufficientSpace"), "bytes");
				}
				bytes[num++] = (byte)(0xF0u | (num3 >> 18));
				bytes[num++] = (byte)(0x80u | ((num3 >> 12) & 0x3Fu));
				bytes[num++] = (byte)(0x80u | ((num3 >> 6) & 0x3Fu));
				bytes[num++] = (byte)(0x80u | (num3 & 0x3Fu));
			}
			return num;
		}

		private static int InternalGetCharCount(byte[] bytes, int index, int count, uint leftOverBits, uint leftOverCount, bool throwOnInvalid, bool flush)
		{
			if (bytes == null)
			{
				throw new ArgumentNullException("bytes");
			}
			if (index < 0 || index > bytes.Length)
			{
				throw new ArgumentOutOfRangeException("index", _("ArgRange_Array"));
			}
			if (count < 0 || count > bytes.Length - index)
			{
				throw new ArgumentOutOfRangeException("count", _("ArgRange_Array"));
			}
			int num = 0;
			int num2 = 0;
			uint num3 = leftOverBits;
			uint num4 = leftOverCount & 0xFu;
			uint num5 = (leftOverCount >> 4) & 0xFu;
			while (count > 0)
			{
				uint num6 = bytes[index++];
				num++;
				count--;
				if (num5 == 0)
				{
					if (num6 < 128)
					{
						num2++;
						num = 0;
					}
					else if ((num6 & 0xE0) == 192)
					{
						num3 = num6 & 0x1Fu;
						num4 = 1u;
						num5 = 2u;
					}
					else if ((num6 & 0xF0) == 224)
					{
						num3 = num6 & 0xFu;
						num4 = 1u;
						num5 = 3u;
					}
					else if ((num6 & 0xF8) == 240)
					{
						num3 = num6 & 7u;
						num4 = 1u;
						num5 = 4u;
					}
					else if ((num6 & 0xFC) == 248)
					{
						num3 = num6 & 3u;
						num4 = 1u;
						num5 = 5u;
					}
					else if ((num6 & 0xFE) == 252)
					{
						num3 = num6 & 3u;
						num4 = 1u;
						num5 = 6u;
					}
					else
					{
						num2 += num * 2;
						num = 0;
					}
				}
				else if ((num6 & 0xC0) == 128)
				{
					num3 = (num3 << 6) | (num6 & 0x3Fu);
					if (++num4 < num5)
					{
						continue;
					}
					if (num3 < 65536)
					{
						bool flag = false;
						switch (num5)
						{
						case 2u:
							flag = num3 <= 127;
							break;
						case 3u:
							flag = num3 <= 2047;
							break;
						case 4u:
							flag = num3 <= 65535;
							break;
						case 5u:
							flag = num3 <= 2097151;
							break;
						case 6u:
							flag = num3 <= 67108863;
							break;
						}
						num2 = ((!flag) ? (num2 + 1) : (num2 + num * 2));
					}
					else if (num3 < 1114112)
					{
						num2 += 2;
					}
					else if (throwOnInvalid)
					{
						num2 += num * 2;
					}
					num5 = 0u;
					num = 0;
				}
				else
				{
					if (num6 < 128)
					{
						index--;
						count++;
						num--;
					}
					num2 += num * 2;
					num5 = 0u;
					num = 0;
				}
			}
			if (flush && num5 != 0 && throwOnInvalid)
			{
				num2 += num * 2;
			}
			return num2;
		}

		public override int GetCharCount(byte[] bytes, int index, int count)
		{
			return InternalGetCharCount(bytes, index, count, 0u, 0u, throwOnInvalid: true, flush: true);
		}

		private static int InternalGetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex, ref uint leftOverBits, ref uint leftOverCount, bool throwOnInvalid, bool flush)
		{
			if (bytes == null)
			{
				throw new ArgumentNullException("bytes");
			}
			if (chars == null)
			{
				throw new ArgumentNullException("chars");
			}
			if (byteIndex < 0 || byteIndex > bytes.Length)
			{
				throw new ArgumentOutOfRangeException("byteIndex", _("ArgRange_Array"));
			}
			if (byteCount < 0 || byteCount > bytes.Length - byteIndex)
			{
				throw new ArgumentOutOfRangeException("byteCount", _("ArgRange_Array"));
			}
			if (charIndex < 0 || charIndex > chars.Length)
			{
				throw new ArgumentOutOfRangeException("charIndex", _("ArgRange_Array"));
			}
			if (charIndex == chars.Length)
			{
				return 0;
			}
			byte[] array = new byte[6];
			int next_raw = 0;
			int num = chars.Length;
			int posn = charIndex;
			uint num2 = leftOverBits;
			uint num3 = leftOverCount & 0xFu;
			uint num4 = (leftOverCount >> 4) & 0xFu;
			while (byteCount > 0)
			{
				uint num5 = bytes[byteIndex++];
				array[next_raw++] = (byte)num5;
				byteCount--;
				if (num4 == 0)
				{
					if (num5 < 128)
					{
						if (posn >= num)
						{
							throw new ArgumentException(_("Arg_InsufficientSpace"), "chars");
						}
						next_raw = 0;
						chars[posn++] = (char)num5;
					}
					else if ((num5 & 0xE0) == 192)
					{
						num2 = num5 & 0x1Fu;
						num3 = 1u;
						num4 = 2u;
					}
					else if ((num5 & 0xF0) == 224)
					{
						num2 = num5 & 0xFu;
						num3 = 1u;
						num4 = 3u;
					}
					else if ((num5 & 0xF8) == 240)
					{
						num2 = num5 & 7u;
						num3 = 1u;
						num4 = 4u;
					}
					else if ((num5 & 0xFC) == 248)
					{
						num2 = num5 & 3u;
						num3 = 1u;
						num4 = 5u;
					}
					else if ((num5 & 0xFE) == 252)
					{
						num2 = num5 & 3u;
						num3 = 1u;
						num4 = 6u;
					}
					else
					{
						next_raw = 0;
						chars[posn++] = EscapeByte;
						chars[posn++] = (char)num5;
					}
				}
				else if ((num5 & 0xC0) == 128)
				{
					num2 = (num2 << 6) | (num5 & 0x3Fu);
					if (++num3 < num4)
					{
						continue;
					}
					if (num2 < 65536)
					{
						bool flag = false;
						switch (num4)
						{
						case 2u:
							flag = num2 <= 127;
							break;
						case 3u:
							flag = num2 <= 2047;
							break;
						case 4u:
							flag = num2 <= 65535;
							break;
						case 5u:
							flag = num2 <= 2097151;
							break;
						case 6u:
							flag = num2 <= 67108863;
							break;
						}
						if (flag)
						{
							CopyRaw(array, ref next_raw, chars, ref posn, num);
						}
						else
						{
							if (posn >= num)
							{
								throw new ArgumentException(_("Arg_InsufficientSpace"), "chars");
							}
							chars[posn++] = (char)num2;
						}
					}
					else if (num2 < 1114112)
					{
						if (posn + 2 > num)
						{
							throw new ArgumentException(_("Arg_InsufficientSpace"), "chars");
						}
						num2 -= 65536;
						chars[posn++] = (char)((num2 >> 10) + 55296);
						chars[posn++] = (char)((num2 & 0x3FF) + 56320);
					}
					else if (throwOnInvalid)
					{
						CopyRaw(array, ref next_raw, chars, ref posn, num);
					}
					num4 = 0u;
					next_raw = 0;
				}
				else
				{
					if (num5 < 128)
					{
						byteIndex--;
						byteCount++;
						next_raw--;
					}
					CopyRaw(array, ref next_raw, chars, ref posn, num);
					num4 = 0u;
					next_raw = 0;
				}
			}
			if (flush && num4 != 0 && throwOnInvalid)
			{
				CopyRaw(array, ref next_raw, chars, ref posn, num);
			}
			leftOverBits = num2;
			leftOverCount = num3 | (num4 << 4);
			return posn - charIndex;
		}

		private static void CopyRaw(byte[] raw, ref int next_raw, char[] chars, ref int posn, int length)
		{
			if (posn + next_raw * 2 > length)
			{
				throw new ArgumentException(_("Arg_InsufficientSpace"), "chars");
			}
			for (int i = 0; i < next_raw; i++)
			{
				chars[posn++] = EscapeByte;
				chars[posn++] = (char)raw[i];
			}
			next_raw = 0;
		}

		public override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex)
		{
			uint leftOverBits = 0u;
			uint leftOverCount = 0u;
			return InternalGetChars(bytes, byteIndex, byteCount, chars, charIndex, ref leftOverBits, ref leftOverCount, throwOnInvalid: true, flush: true);
		}

		public override int GetMaxByteCount(int charCount)
		{
			if (charCount < 0)
			{
				throw new ArgumentOutOfRangeException("charCount", _("ArgRange_NonNegative"));
			}
			return charCount * 4;
		}

		public override int GetMaxCharCount(int byteCount)
		{
			if (byteCount < 0)
			{
				throw new ArgumentOutOfRangeException("byteCount", _("ArgRange_NonNegative"));
			}
			return byteCount;
		}

		public override Decoder GetDecoder()
		{
			return new UnixDecoder();
		}

		public override Encoder GetEncoder()
		{
			return new UnixEncoder();
		}

		public override byte[] GetPreamble()
		{
			return new byte[0];
		}

		public override bool Equals(object value)
		{
			if (value is UnixEncoding)
			{
				return true;
			}
			return false;
		}

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

		public override byte[] GetBytes(string s)
		{
			if (s == null)
			{
				throw new ArgumentNullException("s");
			}
			byte[] array = new byte[GetByteCount(s)];
			GetBytes(s, 0, s.Length, array, 0);
			return array;
		}

		private static string _(string arg)
		{
			return arg;
		}
	}
	[Serializable]
	public class UnixEndPoint : EndPoint
	{
		private string filename;

		public string Filename
		{
			get
			{
				return filename;
			}
			set
			{
				filename = value;
			}
		}

		public override AddressFamily AddressFamily => AddressFamily.Unix;

		public UnixEndPoint(string filename)
		{
			if (filename == null)
			{
				throw new ArgumentNullException("filename");
			}
			if (filename == "")
			{
				throw new ArgumentException("Cannot be empty.", "filename");
			}
			this.filename = filename;
		}

		public override EndPoint Create(SocketAddress socketAddress)
		{
			int num = socketAddress.Size - 2;
			byte[] array = new byte[num];
			for (int i = 0; i < array.Length; i++)
			{
				array[i] = socketAddress[i + 2];
				if (array[i] == 0)
				{
					num = i;
					break;
				}
			}
			if (num == 0)
			{
				return new UnixEndPoint("dummy")
				{
					filename = ""
				};
			}
			return new UnixEndPoint(Encoding.Default.GetString(array, 0, num));
		}

		public override SocketAddress Serialize()
		{
			byte[] bytes = Encoding.Default.GetBytes(filename);
			SocketAddress socketAddress = new SocketAddress(AddressFamily, 2 + bytes.Length + 1);
			for (int i = 0; i < bytes.Length; i++)
			{
				socketAddress[2 + i] = bytes[i];
			}
			socketAddress[2 + bytes.Length] = 0;
			return socketAddress;
		}

		public override string ToString()
		{
			return filename;
		}

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

		public override bool Equals(object o)
		{
			if (!(o is UnixEndPoint unixEndPoint))
			{
				return false;
			}
			return unixEndPoint.filename == filename;
		}
	}
	public sealed class UnixEnvironment
	{
		public static string CurrentDirectory
		{
			get
			{
				return UnixDirectoryInfo.GetCurrentDirectory();
			}
			set
			{
				UnixDirectoryInfo.SetCurrentDirectory(value);
			}
		}

		public static string MachineName
		{
			get
			{
				if (Syscall.uname(out var buf) != 0)
				{
					throw UnixMarshal.CreateExceptionForLastError();
				}
				return buf.nodename;
			}
			set
			{
				UnixMarshal.ThrowExceptionForLastErrorIf(Syscall.sethostname(value));
			}
		}

		public static string UserName => UnixUserInfo.GetRealUser().UserName;

		public static UnixGroupInfo RealGroup => new UnixGroupInfo(RealGroupId);

		public static long RealGroupId => Syscall.getgid();

		public static UnixUserInfo RealUser => new UnixUserInfo(RealUserId);

		public static long RealUserId => Syscall.getuid();

		public static UnixGroupInfo EffectiveGroup
		{
			get
			{
				return new UnixGroupInfo(EffectiveGroupId);
			}
			set
			{
				EffectiveGroupId = value.GroupId;
			}
		}

		public static long EffectiveGroupId
		{
			get
			{
				return Syscall.getegid();
			}
			set
			{
				Syscall.setegid(Convert.ToUInt32(value));
			}
		}

		public static UnixUserInfo EffectiveUser
		{
			get
			{
				return new UnixUserInfo(EffectiveUserId);
			}
			set
			{
				EffectiveUserId = value.UserId;
			}
		}

		public static long EffectiveUserId
		{
			get
			{
				return Syscall.geteuid();
			}
			set
			{
				Syscall.seteuid(Convert.ToUInt32(value));
			}
		}

		public static string Login => UnixUserInfo.GetRealUser().UserName;

		private UnixEnvironment()
		{
		}

		[CLSCompliant(false)]
		public static long GetConfigurationValue(SysconfName name)
		{
			long num = Syscall.sysconf(name);
			if (num == -1 && Stdlib.GetLastError() != 0)
			{
				UnixMarshal.ThrowExceptionForLastError();
			}
			return num;
		}

		[CLSCompliant(false)]
		public static string GetConfigurationString(ConfstrName name)
		{
			ulong num = Syscall.confstr(name, null, 0uL);
			if (num == ulong.MaxValue)
			{
				UnixMarshal.ThrowExceptionForLastError();
			}
			if (num == 0L)
			{
				return "";
			}
			StringBuilder stringBuilder = new StringBuilder((int)num + 1);
			num = Syscall.confstr(name, stringBuilder, num);
			if (num == ulong.MaxValue)
			{
				UnixMarshal.ThrowExceptionForLastError();
			}
			return stringBuilder.ToString();
		}

		public static void SetNiceValue(int inc)
		{
			UnixMarshal.ThrowExceptionForLastErrorIf(Syscall.nice(inc));
		}

		public static int CreateSession()
		{
			int num = Syscall.setsid();
			UnixMarshal.ThrowExceptionForLastErrorIf(num);
			return num;
		}

		public static void SetProcessGroup()
		{
			UnixMarshal.ThrowExceptionForLastErrorIf(Syscall.setpgrp());
		}

		public static int GetProcessGroup()
		{
			return Syscall.getpgrp();
		}

		public static UnixGroupInfo[] GetSupplementaryGroups()
		{
			uint[] array = _GetSupplementaryGroupIds();
			UnixGroupInfo[] array2 = new UnixGroupInfo[array.Length];
			for (int i = 0; i < array2.Length; i++)
			{
				array2[i] = new UnixGroupInfo(array[i]);
			}
			return array2;
		}

		private static uint[] _GetSupplementaryGroupIds()
		{
			int num = Syscall.getgroups(0, new uint[0]);
			if (num == -1)
			{
				UnixMarshal.ThrowExceptionForLastError();
			}
			uint[] array = new uint[num];
			UnixMarshal.ThrowExceptionForLastErrorIf(Syscall.getgroups(array));
			return array;
		}

		public static void SetSupplementaryGroups(UnixGroupInfo[] groups)
		{
			uint[] array = new uint[groups.Length];
			for (int i = 0; i < array.Length; i++)
			{
				array[i] = Convert.ToUInt32(groups[i].GroupId);
			}
			UnixMarshal.ThrowExceptionForLastErrorIf(Syscall.setgroups(array));
		}

		public static long[] GetSupplementaryGroupIds()
		{
			uint[] array = _GetSupplementaryGroupIds();
			long[] array2 = new long[array.Length];
			for (int i = 0; i < array2.Length; i++)
			{
				array2[i] = array[i];
			}
			return array2;
		}

		public static void SetSupplementaryGroupIds(long[] list)
		{
			uint[] array = new uint[list.Length];
			for (int i = 0; i < array.Length; i++)
			{
				array[i] = Convert.ToUInt32(list[i]);
			}
			UnixMarshal.ThrowExceptionForLastErrorIf(Syscall.setgroups(array));
		}

		public static int GetParentProcessId()
		{
			return Syscall.getppid();
		}

		public static UnixProcess GetParentProcess()
		{
			return new UnixProcess(GetParentProcessId());
		}

		public static string[] GetUserShells()
		{
			ArrayList arrayList = new ArrayList();
			lock (Syscall.usershell_lock)
			{
				try
				{
					if (Syscall.setusershell() != 0)
					{
						UnixMarshal.ThrowExceptionForLastError();
					}
					string value;
					while ((value = Syscall.getusershell()) != null)
					{
						arrayList.Add(value);
					}
				}
				finally
				{
					Syscall.endusershell();
				}
			}
			return (string[])arrayList.ToArray(typeof(string));
		}
	}
	public sealed class UnixFileInfo : UnixFileSystemInfo
	{
		public override string Name => UnixPath.GetFileName(base.FullPath);

		public string DirectoryName => UnixPath.GetDirectoryName(base.FullPath);

		public UnixDirectoryInfo Directory => new UnixDirectoryInfo(DirectoryName);

		public UnixFileInfo(string path)
			: base(path)
		{
		}

		internal UnixFileInfo(string path, Stat stat)
			: base(path, stat)
		{
		}

		public override void Delete()
		{
			UnixMarshal.ThrowExceptionForLastErrorIf(Syscall.unlink(base.FullPath));
			Refresh();
		}

		public UnixStream Create()
		{
			FilePermissions mode = FilePermissions.S_IRUSR | FilePermissions.S_IWUSR | FilePermissions.S_IRGRP | FilePermissions.S_IROTH;
			return Create(mode);
		}

		[CLSCompliant(false)]
		public UnixStream Create(FilePermissions mode)
		{
			int num = Syscall.creat(base.FullPath, mode);
			if (num < 0)
			{
				UnixMarshal.ThrowExceptionForLastError();
			}
			Refresh();
			return new UnixStream(num);
		}

		public UnixStream Create(FileAccessPermissions mode)
		{
			return Create((FilePermissions)mode);
		}

		[CLSCompliant(false)]
		public UnixStream Open(OpenFlags flags)
		{
			if ((flags & OpenFlags.O_CREAT) != 0)
			{
				throw new ArgumentException("Cannot specify OpenFlags.O_CREAT without providing FilePermissions.  Use the Open(OpenFlags, FilePermissions) method instead");
			}
			int num = Syscall.open(base.FullPath, flags);
			if (num < 0)
			{
				UnixMarshal.ThrowExceptionForLastError();
			}
			return new UnixStream(num);
		}

		[CLSCompliant(false)]
		public UnixStream Open(OpenFlags flags, FilePermissions mode)
		{
			int num = Syscall.open(base.FullPath, flags, mode);
			if (num < 0)
			{
				UnixMarshal.ThrowExceptionForLastError();
			}
			return new UnixStream(num);
		}

		public UnixStream Open(FileMode mode)
		{
			OpenFlags flags = NativeConvert.ToOpenFlags(mode, FileAccess.ReadWrite);
			return Open(flags);
		}

		public UnixStream Open(FileMode mode, FileAccess access)
		{
			OpenFlags flags = NativeConvert.ToOpenFlags(mode, access);
			return Open(flags);
		}

		[CLSCompliant(false)]
		public UnixStream Open(FileMode mode, FileAccess access, FilePermissions perms)
		{
			OpenFlags flags = NativeConvert.ToOpenFlags(mode, access);
			int num = Syscall.open(base.FullPath, flags, perms);
			if (num < 0)
			{
				UnixMarshal.ThrowExceptionForLastError();
			}
			return new UnixStream(num);
		}

		public UnixStream OpenRead()
		{
			return Open(FileMode.Open, FileAccess.Read);
		}

		public UnixStream OpenWrite()
		{
			return Open(FileMode.OpenOrCreate, FileAccess.Write);
		}
	}
	public abstract class UnixFileSystemInfo
	{
		private Stat stat;

		private string fullPath;

		private string originalPath;

		private bool valid;

		internal const FileSpecialAttributes AllSpecialAttributes = FileSpecialAttributes.SetUserId | FileSpecialAttributes.SetGroupId | FileSpecialAttributes.Sticky;

		internal const FileTypes AllFileTypes = (FileTypes)61440;

		protected string FullPath
		{
			get
			{
				return fullPath;
			}
			set
			{
				if (fullPath != value)
				{
					UnixPath.CheckPath(value);
					valid = false;
					fullPath = value;
				}
			}
		}

		protected string OriginalPath
		{
			get
			{
				return originalPath;
			}
			set
			{
				originalPath = value;
			}
		}

		public virtual string FullName => FullPath;

		public abstract string Name { get; }

		public bool Exists
		{
			get
			{
				Refresh(force: true);
				return valid;
			}
		}

		public long Device
		{
			get
			{
				AssertValid();
				return Convert.ToInt64(stat.st_dev);
			}
		}

		public long Inode
		{
			get
			{
				AssertValid();
				return Convert.ToInt64(stat.st_ino);
			}
		}

		[CLSCompliant(false)]
		public FilePermissions Protection
		{
			get
			{
				AssertValid();
				return stat.st_mode;
			}
			set
			{
				UnixMarshal.ThrowExceptionForLastErrorIf(Syscall.chmod(FullPath, value));
			}
		}

		public FileTypes FileType
		{
			get
			{
				AssertValid();
				return (FileTypes)(stat.st_mode & FilePermissions.S_IFMT);
			}
		}

		public FileAccessPermissions FileAccessPermissions
		{
			get
			{
				AssertValid();
				return (FileAccessPermissions)(stat.st_mode & FilePermissions.ACCESSPERMS);
			}
			set
			{
				AssertValid();
				int st_mode = (int)stat.st_mode;
				st_mode &= -512;
				st_mode |= (int)value;
				Protection = (FilePermissions)st_mode;
			}
		}

		public FileSpecialAttributes FileSpecialAttributes
		{
			get
			{
				AssertValid();
				return (FileSpecialAttributes)(stat.st_mode & (FilePermissions.S_ISUID | FilePermissions.S_ISGID | FilePermissions.S_ISVTX));
			}
			set
			{
				AssertValid();
				int st_mode = (int)stat.st_mode;
				st_mode &= -3585;
				st_mode |= (int)value;
				Protection = (FilePermissions)st_mode;
			}
		}

		public long LinkCount
		{
			get
			{
				AssertValid();
				return Convert.ToInt64(stat.st_nlink);
			}
		}

		public UnixUserInfo OwnerUser
		{
			get
			{
				AssertValid();
				return new UnixUserInfo(stat.st_uid);
			}
		}

		public long OwnerUserId
		{
			get
			{
				AssertValid();
				return stat.st_uid;
			}
		}

		public UnixGroupInfo OwnerGroup
		{
			get
			{
				AssertValid();
				return new UnixGroupInfo(stat.st_gid);
			}
		}

		public long OwnerGroupId
		{
			get
			{
				AssertValid();
				return stat.st_gid;
			}
		}

		public long DeviceType
		{
			get
			{
				AssertValid();
				return Convert.ToInt64(stat.st_rdev);
			}
		}

		public long Length
		{
			get
			{
				AssertValid();
				return stat.st_size;
			}
		}

		public long BlockSize
		{
			get
			{
				AssertValid();
				return stat.st_blksize;
			}
		}

		public long BlocksAllocated
		{
			get
			{
				AssertValid();
				return stat.st_blocks;
			}
		}

		public DateTime LastAccessTime
		{
			get
			{
				AssertValid();
				return NativeConvert.ToDateTime(stat.st_atime, stat.st_atime_nsec);
			}
		}

		public DateTime LastAccessTimeUtc => LastAccessTime.ToUniversalTime();

		public DateTime LastWriteTime
		{
			get
			{
				AssertValid();
				return NativeConvert.ToDateTime(stat.st_mtime, stat.st_mtime_nsec);
			}
		}

		public DateTime LastWriteTimeUtc => LastWriteTime.ToUniversalTime();

		public DateTime LastStatusChangeTime
		{
			get
			{
				AssertValid();
				return NativeConvert.ToDateTime(stat.st_ctime, stat.st_ctime_nsec);
			}
		}

		public DateTime LastStatusChangeTimeUtc => LastStatusChangeTime.ToUniversalTime();

		public bool IsDirectory
		{
			get
			{
				AssertValid();
				return IsFileType(stat.st_mode, FilePermissions.S_IFDIR);
			}
		}

		public bool IsCharacterDevice
		{
			get
			{
				AssertValid();
				return IsFileType(stat.st_mode, FilePermissions.S_IFCHR);
			}
		}

		public bool IsBlockDevice
		{
			get
			{
				AssertValid();
				return IsFileType(stat.st_mode, FilePermissions.S_IFBLK);
			}
		}

		public bool IsRegularFile
		{
			get
			{
				AssertValid();
				return IsFileType(stat.st_mode, FilePermissions.S_IFREG);
			}
		}

		public bool IsFifo
		{
			get
			{
				AssertValid();
				return IsFileType(stat.st_mode, FilePermissions.S_IFIFO);
			}
		}

		public bool IsSymbolicLink
		{
			get
			{
				AssertValid();
				return IsFileType(stat.st_mode, FilePermissions.S_IFLNK);
			}
		}

		public bool IsSocket
		{
			get
			{
				AssertValid();
				return IsFileType(stat.st_mode, FilePermissions.S_IFSOCK);
			}
		}

		public bool IsSetUser
		{
			get
			{
				AssertValid();
				return IsSet(stat.st_mode, FilePermissions.S_ISUID);
			}
		}

		public bool IsSetGroup
		{
			get
			{
				AssertValid();
				return IsSet(stat.st_mode, FilePermissions.S_ISGID);
			}
		}

		public bool IsSticky
		{
			get
			{
				AssertValid();
				return IsSet(stat.st_mode, FilePermissions.S_ISVTX);
			}
		}

		protected UnixFileSystemInfo(string path)
		{
			UnixPath.CheckPath(path);
			originalPath = path;
			fullPath = UnixPath.GetFullPath(path);
			Refresh(force: true);
		}

		internal UnixFileSystemInfo(string path, Stat stat)
		{
			originalPath = path;
			fullPath = UnixPath.GetFullPath(path);
			this.stat = stat;
			valid = true;
		}

		private void AssertValid()
		{
			Refresh(force: false);
			if (!valid)
			{
				throw new InvalidOperationException("Path doesn't exist!");
			}
		}

		internal static bool IsFileType(FilePermissions mode, FilePermissions type)
		{
			return (mode & FilePermissions.S_IFMT) == type;
		}

		internal static bool IsSet(FilePermissions mode, FilePermissions type)
		{
			return (mode & type) == type;
		}

		[CLSCompliant(false)]
		public bool CanAccess(AccessModes mode)
		{
			return Syscall.access(FullPath, mode) == 0;
		}

		public UnixFileSystemInfo CreateLink(string path)
		{
			UnixMarshal.ThrowExceptionForLastErrorIf(Syscall.link(FullName, path));
			return GetFileSystemEntry(path);
		}

		public UnixSymbolicLinkInfo CreateSymbolicLink(string path)
		{
			UnixMarshal.ThrowExceptionForLastErrorIf(Syscall.symlink(FullName, path));
			return new UnixSymbolicLinkInfo(path);
		}

		public abstract void Delete();

		[CLSCompliant(false)]
		public long GetConfigurationValue(PathconfName name)
		{
			long num = Syscall.pathconf(FullPath, name);
			if (num == -1 && Stdlib.GetLastError() != 0)
			{
				UnixMarshal.ThrowExceptionForLastError();
			}
			return num;
		}

		public void Refresh()
		{
			Refresh(force: true);
		}

		internal void Refresh(bool force)
		{
			if (!valid || force)
			{
				valid = GetFileStatus(FullPath, out stat);
			}
		}

		protected virtual bool GetFileStatus(string path, out Stat stat)
		{
			return Syscall.stat(path, out stat) == 0;
		}

		public void SetLength(long length)
		{
			int num;
			do
			{
				num = Syscall.truncate(FullPath, length);
			}
			while (UnixMarshal.ShouldRetrySyscall(num));
			UnixMarshal.ThrowExceptionForLastErrorIf(num);
		}

		public virtual void SetOwner(long owner, long group)
		{
			int owner2 = Convert.ToInt32(owner);
			int group2 = Convert.ToInt32(group);
			UnixMarshal.ThrowExceptionForLastErrorIf(Syscall.chown(FullPath, owner2, group2));
		}

		public void SetOwner(string owner)
		{
			Passwd passwd = Syscall.getpwnam(owner);
			if (passwd == null)
			{
				throw new ArgumentException(Locale.GetText("invalid username"), "owner");
			}
			uint pw_uid = passwd.pw_uid;
			uint pw_gid = passwd.pw_gid;
			SetOwner(pw_uid, pw_gid);
		}

		public void SetOwner(string owner, string group)
		{
			long owner2 = -1L;
			if (owner != null)
			{
				owner2 = new UnixUserInfo(owner).UserId;
			}
			long group2 = -1L;
			if (group != null)
			{
				group2 = new UnixGroupInfo(group).GroupId;
			}
			SetOwner(owner2, group2);
		}

		public void SetOwner(UnixUserInfo owner)
		{
			long group;
			long owner2 = (group = -1L);
			if (owner != null)
			{
				owner2 = owner.UserId;
				group = owner.GroupId;
			}
			SetOwner(owner2, group);
		}

		public void SetOwner(UnixUserInfo owner, UnixGroupInfo group)
		{
			long group2;
			long owner2 = (group2 = -1L);
			if (owner != null)
			{
				owner2 = owner.UserId;
			}
			if (group != null)
			{
				group2 = owner.GroupId;
			}
			SetOwner(owner2, group2);
		}

		public override string ToString()
		{
			return FullPath;
		}

		public Stat ToStat()
		{
			AssertValid();
			return stat;
		}

		public static UnixFileSystemInfo GetFileSystemEntry(string path)
		{
			if (TryGetFileSystemEntry(path, out var entry))
			{
				return entry;
			}
			UnixMarshal.ThrowExceptionForLastError();
			throw new DirectoryNotFoundException("UnixMarshal.ThrowExceptionForLastError didn't throw?!");
		}

		public static bool TryGetFileSystemEntry(string path, out UnixFileSystemInfo entry)
		{
			if (Syscall.lstat(path, out var buf) == -1)
			{
				if (Stdlib.GetLastError() == Errno.ENOENT)
				{
					entry = new UnixFileInfo(path);
					return true;
				}
				entry = null;
				return false;
			}
			if (IsFileType(buf.st_mode, FilePermissions.S_IFDIR))
			{
				entry = new UnixDirectoryInfo(path, buf);
			}
			else if (IsFileType(buf.st_mode, FilePermissions.S_IFLNK))
			{
				entry = new UnixSymbolicLinkInfo(path, buf);
			}
			else
			{
				entry = new UnixFileInfo(path, buf);
			}
			return true;
		}
	}
	public sealed class UnixGroupInfo
	{
		private Mono.Unix.Native.Group group;

		public string GroupName => group.gr_name;

		public string Password => group.gr_passwd;

		public long GroupId => group.gr_gid;

		public UnixGroupInfo(string group)
		{
			this.group = new Mono.Unix.Native.Group();
			if (Syscall.getgrnam_r(group, this.group, out var grbufp) != 0 || grbufp == null)
			{
				throw new ArgumentException(Locale.GetText("invalid group name"), "group");
			}
		}

		public UnixGroupInfo(long group)
		{
			this.group = new Mono.Unix.Native.Group();
			if (Syscall.getgrgid_r(Convert.ToUInt32(group), this.group, out var grbufp) != 0 || grbufp == null)
			{
				throw new ArgumentException(Locale.GetText("invalid group id"), "group");
			}
		}

		public UnixGroupInfo(Mono.Unix.Native.Group group)
		{
			this.group = CopyGroup(group);
		}

		private static Mono.Unix.Native.Group CopyGroup(Mono.Unix.Native.Group group)
		{
			return new Mono.Unix.Native.Group
			{
				gr_gid = group.gr_gid,
				gr_mem = group.gr_mem,
				gr_name = group.gr_name,
				gr_passwd = group.gr_passwd
			};
		}

		public UnixUserInfo[] GetMembers()
		{
			ArrayList arrayList = new ArrayList(group.gr_mem.Length);
			for (int i = 0; i < group.gr_mem.Length; i++)
			{
				try
				{
					arrayList.Add(new UnixUserInfo(group.gr_mem[i]));
				}
				catch (ArgumentException)
				{
				}
			}
			return (UnixUserInfo[])arrayList.ToArray(typeof(UnixUserInfo));
		}

		public string[] GetMemberNames()
		{
			return (string[])group.gr_mem.Clone();
		}

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

		public override bool Equals(object obj)
		{
			if (obj == null || GetType() != obj.GetType())
			{
				return false;
			}
			return group.Equals(((UnixGroupInfo)obj).group);
		}

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

		public Mono.Unix.Native.Group ToGroup()
		{
			return CopyGroup(group);
		}

		public static UnixGroupInfo[] GetLocalGroups()
		{
			ArrayList arrayList = new ArrayList();
			lock (Syscall.grp_lock)
			{
				if (Syscall.setgrent() != 0)
				{
					UnixMarshal.ThrowExceptionForLastError();
				}
				try
				{
					Mono.Unix.Native.Group group;
					while ((group = Syscall.getgrent()) != null)
					{
						arrayList.Add(new UnixGroupInfo(group));
					}
					if (Stdlib.GetLastError() != 0)
					{
						UnixMarshal.ThrowExceptionForLastError();
					}
				}
				finally
				{
					Syscall.endgrent();
				}
			}
			return (UnixGroupInfo[])arrayList.ToArray(typeof(UnixGroupInfo));
		}
	}
	[Serializable]
	public class UnixIOException : IOException
	{
		private int errno;

		public int NativeErrorCode => errno;

		public Errno ErrorCode => NativeConvert.ToErrno(errno);

		public UnixIOException()
			: this(Marshal.GetLastWin32Error())
		{
		}

		public UnixIOException(int errno)
			: base(GetMessage(NativeConvert.ToErrno(errno)))
		{
			this.errno = errno;
		}

		public UnixIOException(int errno, Exception inner)
			: base(GetMessage(NativeConvert.ToErrno(errno)), inner)
		{
			this.errno = errno;
		}

		public UnixIOException(Errno errno)
			: base(GetMessage(errno))
		{
			this.errno = NativeConvert.FromErrno(errno);
		}

		public UnixIOException(Errno errno, Exception inner)
			: base(GetMessage(errno), inner)
		{
			this.errno = NativeConvert.FromErrno(errno);
		}

		public UnixIOException(string message)
			: base(message)
		{
			errno = 0;
		}

		public UnixIOException(string message, Exception inner)
			: base(message, inner)
		{
			errno = 0;
		}

		protected UnixIOException(SerializationInfo info, StreamingContext context)
			: base(info, context)
		{
		}

		private static string GetMessage(Errno errno)
		{
			return $"{UnixMarshal.GetErrorDescription(errno)} [{errno}].";
		}
	}
	public class UnixListener : MarshalByRefObject, IDisposable
	{
		private bool disposed;

		private bool listening;

		private Socket server;

		private EndPoint savedEP;

		public EndPoint LocalEndpoint => savedEP;

		protected Socket Server => server;

		private void Init(UnixEndPoint ep)
		{
			listening = false;
			string filename = ep.Filename;
			if (File.Exists(filename))
			{
				Socket socket = new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.IP);
				try
				{
					socket.Connect(ep);
					socket.Close();
					throw new InvalidOperationException("There's already a server listening on " + filename);
				}
				catch (SocketException)
				{
				}
				File.Delete(filename);
			}
			server = new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.IP);
			server.Bind(ep);
			savedEP = server.LocalEndPoint;
		}

		public UnixListener(string path)
		{
			if (!Directory.Exists(Path.GetDirectoryName(path)))
			{
				Directory.CreateDirectory(Path.GetDirectoryName(path));
			}
			Init(new UnixEndPoint(path));
		}

		public UnixListener(UnixEndPoint localEndPoint)
		{
			if (localEndPoint == null)
			{
				throw new ArgumentNullException("localendPoint");
			}
			Init(localEndPoint);
		}

		public Socket AcceptSocket()
		{
			CheckDisposed();
			if (!listening)
			{
				throw new InvalidOperationException("Socket is not listening");
			}
			return server.Accept();
		}

		public UnixClient AcceptUnixClient()
		{
			CheckDisposed();
			if (!listening)
			{
				throw new InvalidOperationException("Socket is not listening");
			}
			return new UnixClient(AcceptSocket());
		}

		~UnixListener()
		{
			Dispose(disposing: false);
		}

		public bool Pending()
		{
			CheckDisposed();
			if (!listening)
			{
				throw new InvalidOperationException("Socket is not listening");
			}
			return server.Poll(1000, SelectMode.SelectRead);
		}

		public void Start()
		{
			Start(5);
		}

		public void Start(int backlog)
		{
			CheckDisposed();
			if (!listening)
			{
				server.Listen(backlog);
				listening = true;
			}
		}

		public void Stop()
		{
			CheckDisposed();
			Dispose(disposing: true);
		}

		public void Dispose()
		{
			Dispose(disposing: true);
			GC.SuppressFinalize(this);
		}

		protected void Dispose(bool disposing)
		{
			if (disposed)
			{
				return;
			}
			if (disposing)
			{
				try
				{
					File.Delete(((UnixEndPoint)savedEP).Filename);
				}
				catch
				{
				}
				if (server != null)
				{
					server.Close();
				}
				server = null;
			}
			disposed = true;
		}

		private void CheckDisposed()
		{
			if (disposed)
			{
				throw new ObjectDisposedException(GetType().FullName);
			}
		}
	}
	internal class ErrorMarshal
	{
		internal delegate string ErrorTranslator(Errno errno);

		internal static readonly ErrorTranslator Translate;

		static ErrorMarshal()
		{
			try
			{
				Translate = strerror_r;
				Translate(Errno.ERANGE);
			}
			catch (EntryPointNotFoundException)
			{
				Translate = strerror;
			}
		}

		private static string strerror(Errno errno)
		{
			return Stdlib.strerror(errno);
		}

		private static string strerror_r(Errno errno)
		{
			StringBuilder stringBuilder = new StringBuilder(16);
			int num = 0;
			do
			{
				stringBuilder.Capacity *= 2;
				num = Syscall.strerror_r(errno, stringBuilder);
			}
			while (num == -1 && Stdlib.GetLastError() == Errno.ERANGE);
			if (num == -1)
			{
				int num2 = (int)errno;
				return "** Unknown error code: " + num2 + "**";
			}
			return stringBuilder.ToString();
		}
	}
	public sealed class UnixMarshal
	{
		private UnixMarshal()
		{
		}

		[CLSCompliant(false)]
		public static string GetErrorDescription(Errno errno)
		{
			return ErrorMarshal.Translate(errno);
		}

		public static IntPtr AllocHeap(long size)
		{
			if (size < 0)
			{
				throw new ArgumentOutOfRangeException("size", "< 0");
			}
			return Stdlib.malloc((ulong)size);
		}

		public static IntPtr ReAllocHeap(IntPtr ptr, long size)
		{
			if (size < 0)
			{
				throw new ArgumentOutOfRangeException("size", "< 0");
			}
			return Stdlib.realloc(ptr, (ulong)size);
		}

		public static void FreeHeap(IntPtr ptr)
		{
			Stdlib.free(ptr);
		}

		public unsafe static string PtrToStringUnix(IntPtr p)
		{
			if (p == IntPtr.Zero)
			{
				return null;
			}
			int length = checked((int)Stdlib.strlen(p));
			return new string((sbyte*)(void*)p, 0, length, UnixEncoding.Instance);
		}

		public static string PtrToString(IntPtr p)
		{
			if (p == IntPtr.Zero)
			{
				return null;
			}
			return PtrToString(p, UnixEncoding.Instance);
		}

		public unsafe static string PtrToString(IntPtr p, Encoding encoding)
		{
			if (p == IntPtr.Zero)
			{
				return null;
			}
			if (encoding == null)
			{
				throw new ArgumentNullException("encoding");
			}
			int stringByteLength = GetStringByteLength(p, encoding);
			string text = new string((sbyte*)(void*)p, 0, stringByteLength, encoding);
			stringByteLength = text.Length;
			while (stringByteLength > 0 && text[stringByteLength - 1] == '\0')
			{
				stringByteLength--;
			}
			if (stringByteLength == text.Length)
			{
				return text;
			}
			return text.Substring(0, stringByteLength);
		}

		private static int GetStringByteLength(IntPtr p, Encoding encoding)
		{
			Type type = encoding.GetType();
			int num = -1;
			num = ((typeof(UTF8Encoding).IsAssignableFrom(type) || typeof(UTF7Encoding).IsAssignableFrom(type) || typeof(UnixEncoding).IsAssignableFrom(type) || typeof(ASCIIEncoding).IsAssignableFrom(type)) ? checked((int)Stdlib.strlen(p)) : (typeof(UnicodeEncoding).IsAssignableFrom(type) ? GetInt16BufferLength(p) : ((!typeof(UTF32Encoding).IsAssignableFrom(type)) ? GetRandomBufferLength(p, encoding.GetMaxByteCount(1)) : GetInt32BufferLength(p))));
			if (num == -1)
			{
				throw new NotSupportedException("Unable to determine native string buffer length");
			}
			return num;
		}

		private static int GetInt16BufferLength(IntPtr p)
		{
			int i;
			for (i = 0; Marshal.ReadInt16(p, i * 2) != 0; i = checked(i + 1))
			{
			}
			return checked(i * 2);
		}

		private static int GetInt32BufferLength(IntPtr p)
		{
			int i;
			for (i = 0; Marshal.ReadInt32(p, i * 4) != 0; i = checked(i + 1))
			{
			}
			return checked(i * 4);
		}

		private static int GetRandomBufferLength(IntPtr p, int nullLength)
		{
			switch (nullLength)
			{
			case 1:
				return checked((int)Stdlib.strlen(p));
			case 2:
				return GetInt16BufferLength(p);
			case 4:
				return GetInt32BufferLength(p);
			default:
			{
				int result = 0;
				int num = 0;
				do
				{
					num = ((Marshal.ReadByte(p, result++) == 0) ? (num + 1) : 0);
				}
				while (num != nullLength);
				return result;
			}
			}
		}

		public static string[] PtrToStringArray(IntPtr stringArray)
		{
			return PtrToStringArray(stringArray, UnixEncoding.Instance);
		}

		public static string[] PtrToStringArray(IntPtr stringArray, Encoding encoding)
		{
			if (stringArray == IntPtr.Zero)
			{
				return new string[0];
			}
			return PtrToStringArray(CountStrings(stringArray), stringArray, encoding);
		}

		private static int CountStrings(IntPtr stringArray)
		{
			int i;
			for (i = 0; Marshal.ReadIntPtr(stringArray, i * IntPtr.Size) != IntPtr.Zero; i++)
			{
			}
			return i;
		}

		public static string[] PtrToStringArray(int count, IntPtr stringArray)
		{
			return PtrToStringArray(count, stringArray, UnixEncoding.Instance);
		}

		public static string[] PtrToStringArray(int count, IntPtr stringArray, Encoding encoding)
		{
			if (count < 0)
			{
				throw new ArgumentOutOfRangeException("count", "< 0");
			}
			if (encoding == null)
			{
				throw new ArgumentNullException("encoding");
			}
			if (stringArray == IntPtr.Zero)
			{
				return new string[count];
			}
			string[] array = new string[count];
			for (int i = 0; i < count; i++)
			{
				IntPtr p = Marshal.ReadIntPtr(stringArray, i * IntPtr.Size);
				array[i] = PtrToString(p, encoding);
			}
			return array;
		}

		public static IntPtr StringToHeap(string s)
		{
			return StringToHeap(s, UnixEncoding.Instance);
		}

		public static IntPtr StringToHeap(string s, Encoding encoding)
		{
			if (s == null)
			{
				return IntPtr.Zero;
			}
			return StringToHeap(s, 0, s.Length, encoding);
		}

		public static IntPtr StringToHeap(string s, int index, int count)
		{
			return StringToHeap(s, index, count, UnixEncoding.Instance);
		}

		public unsafe static IntPtr StringToHeap(string s, int index, int count, Encoding encoding)
		{
			if (s == null)
			{
				return IntPtr.Zero;
			}
			if (encoding == null)
			{
				throw new ArgumentNullException("encoding");
			}
			if (index < 0 || count < 0)
			{
				throw new ArgumentOutOfRangeException((index < 0) ? "index" : "count", "Non - negative number required.");
			}
			if (s.Length - index < count)
			{
				throw new ArgumentOutOfRangeException("s", "Index and count must refer to a location within the string.");
			}
			int maxByteCount = encoding.GetMaxByteCount(1);
			int byteCount = encoding.GetByteCount(s);
			int num = checked(byteCount + maxByteCount);
			IntPtr intPtr = AllocHeap(num);
			if (intPtr == IntPtr.Zero)
			{
				throw new UnixIOException(Errno.ENOMEM);
			}
			fixed (char* ptr2 = s)
			{
				byte* ptr = (byte*)(void*)intPtr;
				int bytes;
				try
				{
					bytes = encoding.GetBytes(ptr2 + index, count, ptr, num);
				}
				catch
				{
					FreeHeap(intPtr);
					throw;
				}
				if (bytes != byteCount)
				{
					FreeHeap(intPtr);
					throw new NotSupportedException("encoding.GetBytes() doesn't equal encoding.GetByteCount()!");
				}
				ptr += byteCount;
				for (int i = 0; i < maxByteCount; i++)
				{
					ptr[i] = 0;
				}
			}
			return intPtr;
		}

		public static bool ShouldRetrySyscall(int r)
		{
			if (r == -1 && Stdlib.GetLastError() == Errno.EINTR)
			{
				return true;
			}
			return false;
		}

		[CLSCompliant(false)]
		public static bool ShouldRetrySyscall(int r, out Errno errno)
		{
			errno = (Errno)0;
			if (r == -1 && (errno = Stdlib.GetLastError()) == Errno.EINTR)
			{
				return true;
			}
			return false;
		}

		internal static string EscapeFormatString(string message, char[] permitted)
		{
			if (message == null)
			{
				return "";
			}
			StringBuilder stringBuilder = new StringBuilder(message.Length);
			for (int i = 0; i < message.Length; i++)
			{
				char c = message[i];
				stringBuilder.Append(c);
				if (c == '%' && i + 1 < message.Length)
				{
					char c2 = message[i + 1];
					if (c2 == '%' || IsCharPresent(permitted, c2))
					{
						stringBuilder.Append(c2);
					}
					else
					{
						stringBuilder.Append('%').Append(c2);
					}
					i++;
				}
				else if (c == '%')
				{
					stringBuilder.Append('%');
				}
			}
			return stringBuilder.ToString();
		}

		private static bool IsCharPresent(char[] array, char c)
		{
			if (array == null)
			{
				return false;
			}
			for (int i = 0; i < array.Length; i++)
			{
				if (array[i] == c)
				{
					return true;
				}
			}
			return false;
		}

		internal static Exception CreateExceptionForError(Errno errno)
		{
			string errorDescription = GetErrorDescription(errno);
			UnixIOException ex = new UnixIOException(errno);
			switch (errno)
			{
			case Errno.EBADF:
			case Errno.EINVAL:
				return new ArgumentException(errorDescription, ex);
			case Errno.ERANGE:
				return new ArgumentOutOfRangeException(errorDescription);
			case Errno.ENOTDIR:
				return new DirectoryNotFoundException(errorDescription, ex);
			case Errno.ENOENT:
				return new FileNotFoundException(errorDescription, ex);
			case Errno.EPERM:
			case Errno.EOPNOTSUPP:
				return new InvalidOperationException(errorDescription, ex);
			case Errno.ENOEXEC:
				return new InvalidProgramException(errorDescription, ex);
			case Errno.EIO:
			case Errno.ENXIO:
			case Errno.ENOSPC:
			case Errno.ESPIPE:
			case Errno.EROFS:
			case Errno.ENOTEMPTY:
				return new IOException(errorDescription, ex);
			case Errno.EFAULT:
				return new NullReferenceException(errorDescription, ex);
			case Errno.EOVERFLOW:
				return new OverflowException(errorDescription, ex);
			case Errno.ENAMETOOLONG:
				return new PathTooLongException(errorDescription, ex);
			case Errno.EACCES:
			case Errno.EISDIR:
				return new UnauthorizedAccessException(errorDescription, ex);
			default:
				return ex;
			}
		}

		internal static Exception CreateExceptionForLastError()
		{
			return CreateExceptionForError(Stdlib.GetLastError());
		}

		[CLSCompliant(false)]
		public static void ThrowExceptionForError(Errno errno)
		{
			throw CreateExceptionForError(errno);
		}

		public static void ThrowExceptionForLastError()
		{
			throw CreateExceptionForLastError();
		}

		[CLSCompliant(false)]
		public static void ThrowExceptionForErrorIf(int retval, Errno errno)
		{
			if (retval == -1)
			{
				ThrowExceptionForError(errno);
			}
		}

		public static void ThrowExceptionForLastErrorIf(int retval)
		{
			if (retval == -1)
			{
				ThrowExceptionForLastError();
			}
		}
	}
	public sealed class UnixPath
	{
		public static readonly char DirectorySeparatorChar = '/';

		public static readonly char AltDirectorySeparatorChar = '/';

		public static readonly char PathSeparator = ':';

		public static readonly char VolumeSeparatorChar = '/';

		private static readonly char[] _InvalidPathChars = new char[0];

		private UnixPath()
		{
		}

		public static char[] GetInvalidPathChars()
		{
			return (char[])_InvalidPathChars.Clone();
		}

		public static string Combine(string path1, params string[] paths)
		{
			if (path1 == null)
			{
				throw new ArgumentNullException("path1");
			}
			if (paths == null)
			{
				throw new ArgumentNullException("paths");
			}
			if (path1.IndexOfAny(_InvalidPathChars) != -1)
			{
				throw new ArgumentException("Illegal characters in path", "path1");
			}
			int num = path1.Length;
			int num2 = -1;
			for (int i = 0; i < paths.Length; i++)
			{
				if (paths[i] == null)
				{
					throw new ArgumentNullException("paths[" + i + "]");
				}
				if (paths[i].IndexOfAny(_InvalidPathChars) != -1)
				{
					throw new ArgumentException("Illegal characters in path", "paths[" + i + "]");
				}
				if (IsPathRooted(paths[i]))
				{
					num = 0;
					num2 = i;
				}
				num += paths[i].Length + 1;
			}
			StringBuilder stringBuilder = new StringBuilder(num);
			if (num2 == -1)
			{
				stringBuilder.Append(path1);
				num2 = 0;
			}
			for (int j = num2; j < paths.Length; j++)
			{
				Combine(stringBuilder, paths[j]);
			}
			return stringBuilder.ToString();
		}

		private static void Combine(StringBuilder path, string part)
		{
			if (path.Length > 0 && part.Length > 0)
			{
				char c = path[path.Length - 1];
				if (c != DirectorySeparatorChar && c != AltDirectorySeparatorChar && c != VolumeSeparatorChar)
				{
					path.Append(DirectorySeparatorChar);
				}
			}
			path.Append(part);
		}

		public static string GetDirectoryName(string path)
		{
			CheckPath(path);
			int num = path.LastIndexOf(DirectorySeparatorChar);
			if (num > 0)
			{
				return path.Substring(0, num);
			}
			if (num == 0)
			{
				return "/";
			}
			return "";
		}

		public static string GetFileName(string path)
		{
			if (path == null || path.Length == 0)
			{
				return path;
			}
			int num = path.LastIndexOf(DirectorySeparatorChar);
			if (num >= 0)
			{
				return path.Substring(num + 1);
			}
			return path;
		}

		public static string GetFullPath(string path)
		{
			path = _GetFullPath(path);
			return GetCanonicalPath(path);
		}

		private static string _GetFullPath(string path)
		{
			if (path == null)
			{
				throw new ArgumentNullException("path");
			}
			if (!IsPathRooted(path))
			{
				path = UnixDirectoryInfo.GetCurrentDirectory() + DirectorySeparatorChar + path;
			}
			return path;
		}

		public static string GetCanonicalPath(string path)
		{
			GetPathComponents(path, out var components, out var lastIndex);
			string text = string.Join("/", components, 0, lastIndex);
			if (!IsPathRooted(path))
			{
				return text;
			}
			return "/" + text;
		}

		private static void GetPathComponents(string path, out string[] components, out int lastIndex)
		{
			string[] array = path.Split(DirectorySeparatorChar);
			int num = 0;
			for (int i = 0; i < array.Length; i++)
			{
				if (!(array[i] == ".") && !(array[i] == string.Empty))
				{
					if (array[i] == "..")
					{
						num = ((num == 0) ? (num + 1) : (num - 1));
					}
					else
					{
						array[num++] = array[i];
					}
				}
			}
			components = array;
			lastIndex = num;
		}

		public static string GetPathRoot(string path)
		{
			if (path == null)
			{
				return null;
			}
			if (!IsPathRooted(path))
			{
				return "";
			}
			return "/";
		}

		public static string GetCompleteRealPath(string path)
		{
			if (path == null)
			{
				throw new ArgumentNullException("path");
			}
			GetPathComponents(path, out var components, out var lastIndex);
			StringBuilder stringBuilder = new StringBuilder();
			if (components.Length != 0)
			{
				string text = (IsPathRooted(path) ? "/" : "");
				text += components[0];
				stringBuilder.Append(GetRealPath(text));
			}
			for (int i = 1; i < lastIndex; i++)
			{
				stringBuilder.Append("/").Append(components[i]);
				string realPath = GetRealPath(stringBuilder.ToString());
				stringBuilder.Remove(0, stringBuilder.Length);
				stringBuilder.Append(realPath);
			}
			return stringBuilder.ToString();
		}

		public static string GetRealPath(string path)
		{
			while (true)
			{
				string text = ReadSymbolicLink(path);
				if (text == null)
				{
					break;
				}
				if (IsPathRooted(text))
				{
					path = text;
					continue;
				}
				path = GetDirectoryName(path) + DirectorySeparatorChar + text;
				path = GetCanonicalPath(path);
			}
			return path;
		}

		internal static string ReadSymbolicLink(string path)
		{
			string text = TryReadLink(path);
			if (text == null)
			{
				Errno lastError = Stdlib.GetLastError();
				if (lastError != Errno.EINVAL)
				{
					UnixMarshal.ThrowExceptionForError(lastError);
				}
			}
			return text;
		}

		public static string TryReadLink(string path)
		{
			byte[] array = new byte[256];
			checked
			{
				long num;
				while (true)
				{
					num = Syscall.readlink(path, array);
					if (num < 0)
					{
						return null;
					}
					if (num != array.Length)
					{
						break;
					}
					array = new byte[array.LongLength * 2];
				}
				return UnixEncoding.Instance.GetString(array, 0, (int)num);
			}
		}

		public static string TryReadLinkAt(int dirfd, string path)
		{
			byte[] array = new byte[256];
			checked
			{
				long num;
				while (true)
				{
					num = Syscall.readlinkat(dirfd, path, array);
					if (num < 0)
					{
						return null;
					}
					if (num != array.Length)
					{
						break;
					}
					array = new byte[array.LongLength * 2];
				}
				return UnixEncoding.Instance.GetString(array, 0, (int)num);
			}
		}

		public static string ReadLink(string path)
		{
			string text = TryReadLink(path);
			if (text == null)
			{
				UnixMarshal.ThrowExceptionForLastError();
			}
			return text;
		}

		public static string ReadLinkAt(int dirfd, string path)
		{
			string text = TryReadLinkAt(dirfd, path);
			if (text == null)
			{
				UnixMarshal.ThrowExceptionForLastError();
			}
			return text;
		}

		public static bool IsPathRooted(string path)
		{
			if (path == null || path.Length == 0)
			{
				return false;
			}
			return path[0] == DirectorySeparatorChar;
		}

		internal static void CheckPath(string path)
		{
			if (path == null)
			{
				throw new ArgumentNullException();
			}
			if (path.Length == 0)
			{
				throw new ArgumentException("Path cannot contain a zero-length string", "path");
			}
			if (path.IndexOfAny(_InvalidPathChars) != -1)
			{
				throw new ArgumentException("Invalid characters in path.", "path");
			}
		}
	}
	public struct UnixPipes : IEquatable<UnixPipes>
	{
		public UnixStream Reading;

		public UnixStream Writing;

		public UnixPipes(UnixStream reading, UnixStream writing)
		{
			Reading = reading;
			Writing = writing;
		}

		public static UnixPipes CreatePipes()
		{
			UnixMarshal.ThrowExceptionForLastErrorIf(Syscall.pipe(out var reading, out var writing));
			return new UnixPipes(new UnixStream(reading), new UnixStream(writing));
		}

		public override bool Equals(object value)
		{
			if (value == null || value.GetType() != GetType())
			{
				return false;
			}
			UnixPipes unixPipes = (UnixPipes)value;
			if (Reading.Handle == unixPipes.Reading.Handle)
			{
				return Writing.Handle == unixPipes.Writing.Handle;
			}
			return false;
		}

		public bool Equals(UnixPipes value)
		{
			if (Reading.Handle == value.Reading.Handle)
			{
				return Writing.Handle == value.Writing.Handle;
			}
			return false;
		}

		public override int GetHashCode()
		{
			return Reading.Handle.GetHashCode() ^ Writing.Handle.GetHashCode();
		}

		public static bool operator ==(UnixPipes lhs, UnixPipes rhs)
		{
			return lhs.Equals(rhs);
		}

		public static bool operator !=(UnixPipes lhs, UnixPipes rhs)
		{
			return !lhs.Equals(rhs);
		}
	}
	public sealed class UnixProcess
	{
		private int pid;

		public int Id => pid;

		public bool HasExited => Syscall.WIFEXITED(GetProcessStatus());

		public int ExitCode
		{
			get
			{
				if (!HasExited)
				{
					throw new InvalidOperationException(Locale.GetText("Process hasn't exited"));
				}
				return Syscall.WEXITSTATUS(GetProcessStatus());
			}
		}

		public bool HasSignaled => Syscall.WIFSIGNALED(GetProcessStatus());

		public Signum TerminationSignal
		{
			get
			{
				if (!HasSignaled)
				{
					throw new InvalidOperationException(Locale.GetText("Process wasn't terminated by a signal"));
				}
				return Syscall.WTERMSIG(GetProcessStatus());
			}
		}

		public bool HasStopped => Syscall.WIFSTOPPED(GetProcessStatus());

		public Signum StopSignal
		{
			get
			{
				if (!HasStopped)
				{
					throw new InvalidOperationException(Locale.GetText("Process isn't stopped"));
				}
				return Syscall.WSTOPSIG(GetProcessStatus());
			}
		}

		public int ProcessGroupId
		{
			get
			{
				return Syscall.getpgid(pid);
			}
			set
			{
				UnixMarshal.ThrowExceptionForLastErrorIf(Syscall.setpgid(pid, value));
			}
		}

		public int SessionId
		{
			get
			{
				int num = Syscall.getsid(pid);
				UnixMarshal.ThrowExceptionForLastErrorIf(num);
				return num;
			}
		}

		internal UnixProcess(int pid)
		{
			this.pid = pid;
		}

		private int GetProcessStatus()
		{
			int status;
			int num = Syscall.waitpid(pid, out status, WaitOptions.WNOHANG | WaitOptions.WUNTRACED);
			UnixMarshal.ThrowExceptionForLastErrorIf(num);
			return num;
		}

		public static UnixProcess GetCurrentProcess()
		{
			return new UnixProcess(GetCurrentProcessId());
		}

		public static int GetCurrentProcessId()
		{
			return Syscall.getpid();
		}

		public void Kill()
		{
			Signal(Signum.SIGKILL);
		}

		[CLSCompliant(false)]
		public void Signal(Signum signal)
		{
			UnixMarshal.ThrowExceptionForLastErrorIf(Syscall.kill(pid, signal));
		}

		public void WaitForExit()
		{
			int num;
			do
			{
				num = Syscall.waitpid(pid, out var _, (WaitOptions)0);
			}
			while (UnixMarshal.ShouldRetrySyscall(num));
			UnixMarshal.ThrowExceptionForLastErrorIf(num);
		}
	}
	public class UnixSignal : WaitHandle
	{
		[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
		private delegate int Mono_Posix_RuntimeIsShuttingDown();

		[Map]
		private struct SignalInfo
		{
			public int signum;

			public int count;

			public int read_fd;

			public int write_fd;

			public int pipecnt;

			public int pipelock;

			public int have_handler;

			public IntPtr handler;
		}

		private int signum;

		private IntPtr signal_info;

		private static Mono_Posix_RuntimeIsShuttingDown ShuttingDown;

		public Signum Signum
		{
			get
			{
				if (IsRealTimeSignal)
				{
					throw new InvalidOperationException("This signal is a RealTimeSignum");
				}
				return NativeConvert.ToSignum(signum);
			}
		}

		public RealTimeSignum RealTimeSignum
		{
			get
			{
				if (!IsRealTimeSignal)
				{
					throw new InvalidOperationException("This signal is not a RealTimeSignum");
				}
				return NativeConvert.ToRealTimeSignum(signum - GetSIGRTMIN());
			}
		}

		public bool IsRealTimeSignal
		{
			get
			{
				AssertValid();
				int sIGRTMIN = GetSIGRTMIN();
				if (sIGRTMIN == -1)
				{
					return false;
				}
				return signum >= sIGRTMIN;
			}
		}

		private unsafe SignalInfo* Info
		{
			get
			{
				AssertValid();
				return (SignalInfo*)(void*)signal_info;
			}
		}

		public bool IsSet => Count > 0;

		public unsafe int Count
		{
			get
			{
				return Info->count;
			}
			set
			{
				Interlocked.Exchange(ref Info->count, value);
			}
		}

		static UnixSignal()
		{
			ShuttingDown = RuntimeShuttingDownCallback;
			Stdlib.VersionCheck();
		}

		public UnixSignal(Signum signum)
		{
			this.signum = NativeConvert.FromSignum(signum);
			signal_info = install(this.signum);
			if (signal_info == IntPtr.Zero)
			{
				throw new ArgumentException("Unable to handle signal", "signum");
			}
		}

		public UnixSignal(RealTimeSignum rtsig)
		{
			signum = NativeConvert.FromRealTimeSignum(rtsig);
			signal_info = install(signum);
			Errno lastError = Stdlib.GetLastError();
			if (signal_info == IntPtr.Zero)
			{
				if (lastError == Errno.EADDRINUSE)
				{
					throw new ArgumentException("Signal registered outside of Mono.Posix", "signum");
				}
				throw new ArgumentException("Unable to handle signal", "signum");
			}
		}

		[DllImport("MonoPosixHelper", CallingConvention = CallingConvention.Cdecl, EntryPoint = "Mono_Unix_UnixSignal_install", SetLastError = true)]
		private static extern IntPtr install(int signum);

		[DllImport("MonoPosixHelper", CallingConvention = CallingConvention.Cdecl, EntryPoint = "Mono_Unix_UnixSignal_uninstall")]
		private static extern int uninstall(IntPtr info);

		private static int RuntimeShuttingDownCallback()
		{
			if (!Environment.HasShutdownStarted)
			{
				return 0;
			}
			return 1;
		}

		[DllImport("MonoPosixHelper", CallingConvention = CallingConvention.Cdecl, EntryPoint = "Mono_Unix_UnixSignal_WaitAny")]
		private static extern int WaitAny(IntPtr[] infos, int count, int timeout, Mono_Posix_RuntimeIsShuttingDown shutting_down);

		[DllImport("MonoPosixHelper", CallingConvention = CallingConvention.Cd

BepInExPack/mono/Managed/Mono.Security.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration.Assemblies;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Net;
using System.Net.Security;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Security;
using System.Security.Authentication;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using System.Security.Permissions;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Mono.Math;
using Mono.Math.Prime;
using Mono.Math.Prime.Generator;
using Mono.Net.Security;
using Mono.Security.Cryptography;
using Mono.Security.X509;
using Mono.Security.X509.Extensions;
using Mono.Xml;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyCompany("MONO development team")]
[assembly: AssemblyCopyright("(c) 2003-2004 Various Authors")]
[assembly: AssemblyDescription("Mono.Security.dll")]
[assembly: AssemblyProduct("MONO CLI")]
[assembly: AssemblyTitle("Mono.Security.dll")]
[assembly: CLSCompliant(true)]
[assembly: ComVisible(false)]
[assembly: NeutralResourcesLanguage("en-US")]
[assembly: AssemblyDelaySign(true)]
[assembly: InternalsVisibleTo("System, PublicKey=00000000000000000400000000000000")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("4.0.0.0")]
[module: UnverifiableCode]
internal static class AssemblyRef
{
	internal const string SystemConfiguration = "System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	internal const string System = "System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";

	public const string EcmaPublicKey = "b77a5c561934e089";

	public const string FrameworkPublicKeyFull = "00000000000000000400000000000000";

	public const string FrameworkPublicKeyFull2 = "00000000000000000400000000000000";

	public const string MicrosoftPublicKey = "b03f5f7f11d50a3a";

	public const string MicrosoftJScript = "Microsoft.JScript, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string MicrosoftVSDesigner = "Microsoft.VSDesigner, Version=0.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string SystemData = "System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string SystemDesign = "System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string SystemDrawing = "System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string SystemWeb = "System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string SystemWebExtensions = "System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";

	public const string SystemWindowsForms = "System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";
}
internal static class Consts
{
	public const string MonoCorlibVersion = "1A5E0066-58DC-428A-B21C-0AD6CDAE2789";

	public const string MonoVersion = "6.13.0.0";

	public const string MonoCompany = "Mono development team";

	public const string MonoProduct = "Mono Common Language Infrastructure";

	public const string MonoCopyright = "(c) Various Mono authors";

	public const string FxVersion = "4.0.0.0";

	public const string FxFileVersion = "4.6.57.0";

	public const string EnvironmentVersion = "4.0.30319.42000";

	public const string VsVersion = "0.0.0.0";

	public const string VsFileVersion = "11.0.0.0";

	private const string PublicKeyToken = "b77a5c561934e089";

	public const string AssemblyI18N = "I18N, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756";

	public const string AssemblyMicrosoft_JScript = "Microsoft.JScript, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblyMicrosoft_VisualStudio = "Microsoft.VisualStudio, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblyMicrosoft_VisualStudio_Web = "Microsoft.VisualStudio.Web, Version=0.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblyMicrosoft_VSDesigner = "Microsoft.VSDesigner, Version=0.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblyMono_Http = "Mono.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756";

	public const string AssemblyMono_Posix = "Mono.Posix, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756";

	public const string AssemblyMono_Security = "Mono.Security, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756";

	public const string AssemblyMono_Messaging_RabbitMQ = "Mono.Messaging.RabbitMQ, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756";

	public const string AssemblyCorlib = "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string AssemblySystem = "System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string AssemblySystem_Data = "System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string AssemblySystem_Design = "System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_DirectoryServices = "System.DirectoryServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_Drawing = "System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_Drawing_Design = "System.Drawing.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_Messaging = "System.Messaging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_Security = "System.Security, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_ServiceProcess = "System.ServiceProcess, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_Web = "System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_Windows_Forms = "System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string AssemblySystem_2_0 = "System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string AssemblySystemCore_3_5 = "System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string AssemblySystem_Core = "System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string WindowsBase_3_0 = "WindowsBase, Version=3.0.0.0, PublicKeyToken=31bf3856ad364e35";

	public const string AssemblyWindowsBase = "WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";

	public const string AssemblyPresentationCore_3_5 = "PresentationCore, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";

	public const string AssemblyPresentationCore_4_0 = "PresentationCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";

	public const string AssemblyPresentationFramework_3_5 = "PresentationFramework, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";

	public const string AssemblySystemServiceModel_3_0 = "System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";
}
internal sealed class Locale
{
	private Locale()
	{
	}

	public static string GetText(string msg)
	{
		return msg;
	}

	public static string GetText(string fmt, params object[] args)
	{
		return string.Format(fmt, args);
	}
}
namespace Mono.Xml
{
	[CLSCompliant(false)]
	public class MiniParser
	{
		public interface IReader
		{
			int Read();
		}

		public interface IAttrList
		{
			int Length { get; }

			bool IsEmpty { get; }

			string[] Names { get; }

			string[] Values { get; }

			string GetName(int i);

			string GetValue(int i);

			string GetValue(string name);

			void ChangeValue(string name, string newValue);
		}

		public interface IMutableAttrList : IAttrList
		{
			void Clear();

			void Add(string name, string value);

			void CopyFrom(IAttrList attrs);

			void Remove(int i);

			void Remove(string name);
		}

		public interface IHandler
		{
			void OnStartParsing(MiniParser parser);

			void OnStartElement(string name, IAttrList attrs);

			void OnEndElement(string name);

			void OnChars(string ch);

			void OnEndParsing(MiniParser parser);
		}

		public class HandlerAdapter : IHandler
		{
			public void OnStartParsing(MiniParser parser)
			{
			}

			public void OnStartElement(string name, IAttrList attrs)
			{
			}

			public void OnEndElement(string name)
			{
			}

			public void OnChars(string ch)
			{
			}

			public void OnEndParsing(MiniParser parser)
			{
			}
		}

		private enum CharKind : byte
		{
			LEFT_BR = 0,
			RIGHT_BR = 1,
			SLASH = 2,
			PI_MARK = 3,
			EQ = 4,
			AMP = 5,
			SQUOTE = 6,
			DQUOTE = 7,
			BANG = 8,
			LEFT_SQBR = 9,
			SPACE = 10,
			RIGHT_SQBR = 11,
			TAB = 12,
			CR = 13,
			EOL = 14,
			CHARS = 15,
			UNKNOWN = 31
		}

		private enum ActionCode : byte
		{
			START_ELEM = 0,
			END_ELEM = 1,
			END_NAME = 2,
			SET_ATTR_NAME = 3,
			SET_ATTR_VAL = 4,
			SEND_CHARS = 5,
			START_CDATA = 6,
			END_CDATA = 7,
			ERROR = 8,
			STATE_CHANGE = 9,
			FLUSH_CHARS_STATE_CHANGE = 10,
			ACC_CHARS_STATE_CHANGE = 11,
			ACC_CDATA = 12,
			PROC_CHAR_REF = 13,
			UNKNOWN = 15
		}

		public class AttrListImpl : IMutableAttrList, IAttrList
		{
			protected ArrayList names;

			protected ArrayList values;

			public int Length => names.Count;

			public bool IsEmpty => Length != 0;

			public string[] Names => names.ToArray(typeof(string)) as string[];

			public string[] Values => values.ToArray(typeof(string)) as string[];

			public AttrListImpl()
				: this(0)
			{
			}

			public AttrListImpl(int initialCapacity)
			{
				if (initialCapacity <= 0)
				{
					names = new ArrayList();
					values = new ArrayList();
				}
				else
				{
					names = new ArrayList(initialCapacity);
					values = new ArrayList(initialCapacity);
				}
			}

			public AttrListImpl(IAttrList attrs)
				: this(attrs?.Length ?? 0)
			{
				if (attrs != null)
				{
					CopyFrom(attrs);
				}
			}

			public string GetName(int i)
			{
				string result = null;
				if (i >= 0 && i < Length)
				{
					result = names[i] as string;
				}
				return result;
			}

			public string GetValue(int i)
			{
				string result = null;
				if (i >= 0 && i < Length)
				{
					result = values[i] as string;
				}
				return result;
			}

			public string GetValue(string name)
			{
				return GetValue(names.IndexOf(name));
			}

			public void ChangeValue(string name, string newValue)
			{
				int num = names.IndexOf(name);
				if (num >= 0 && num < Length)
				{
					values[num] = newValue;
				}
			}

			public void Clear()
			{
				names.Clear();
				values.Clear();
			}

			public void Add(string name, string value)
			{
				names.Add(name);
				values.Add(value);
			}

			public void Remove(int i)
			{
				if (i >= 0)
				{
					names.RemoveAt(i);
					values.RemoveAt(i);
				}
			}

			public void Remove(string name)
			{
				Remove(names.IndexOf(name));
			}

			public void CopyFrom(IAttrList attrs)
			{
				if (attrs != null && this == attrs)
				{
					Clear();
					int length = attrs.Length;
					for (int i = 0; i < length; i++)
					{
						Add(attrs.GetName(i), attrs.GetValue(i));
					}
				}
			}
		}

		public class XMLError : Exception
		{
			protected string descr;

			protected int line;

			protected int column;

			public int Line => line;

			public int Column => column;

			public XMLError()
				: this("Unknown")
			{
			}

			public XMLError(string descr)
				: this(descr, -1, -1)
			{
			}

			public XMLError(string descr, int line, int column)
				: base(descr)
			{
				this.descr = descr;
				this.line = line;
				this.column = column;
			}

			public override string ToString()
			{
				return $"{descr} @ (line = {line}, col = {column})";
			}
		}

		private static readonly int INPUT_RANGE = 13;

		private static readonly ushort[] tbl = new ushort[262]
		{
			2305, 43264, 63616, 10368, 6272, 14464, 18560, 22656, 26752, 34944,
			39040, 47232, 30848, 2177, 10498, 6277, 14595, 18561, 22657, 26753,
			35088, 39041, 43137, 47233, 30849, 64004, 4352, 43266, 64258, 2177,
			10369, 14465, 18561, 22657, 26753, 34945, 39041, 47233, 30849, 14597,
			2307, 10499, 6403, 18691, 22787, 26883, 35075, 39171, 43267, 47363,
			30979, 63747, 64260, 8710, 4615, 41480, 2177, 14465, 18561, 22657,
			26753, 34945, 39041, 47233, 30849, 6400, 2307, 10499, 14595, 18691,
			22787, 26883, 35075, 39171, 43267, 47363, 30979, 63747, 6400, 2177,
			10369, 14465, 18561, 22657, 26753, 34945, 39041, 43137, 47233, 30849,
			63617, 2561, 23818, 11274, 7178, 15370, 19466, 27658, 35850, 39946,
			43783, 48138, 31754, 64522, 64265, 8198, 4103, 43272, 2177, 14465,
			18561, 22657, 26753, 34945, 39041, 47233, 30849, 64265, 17163, 43276,
			2178, 10370, 6274, 14466, 22658, 26754, 34946, 39042, 47234, 30850,
			2317, 23818, 11274, 7178, 15370, 19466, 27658, 35850, 39946, 44042,
			48138, 31754, 64522, 26894, 30991, 43275, 2180, 10372, 6276, 14468,
			18564, 22660, 34948, 39044, 47236, 63620, 17163, 43276, 2178, 10370,
			6274, 14466, 22658, 26754, 34946, 39042, 47234, 30850, 63618, 9474,
			35088, 2182, 6278, 14470, 18566, 22662, 26758, 39046, 43142, 47238,
			30854, 63622, 25617, 23822, 2830, 11022, 6926, 15118, 19214, 35598,
			39694, 43790, 47886, 31502, 64270, 29713, 23823, 2831, 11023, 6927,
			15119, 19215, 27407, 35599, 39695, 43791, 47887, 64271, 38418, 6400,
			1555, 9747, 13843, 17939, 22035, 26131, 34323, 42515, 46611, 30227,
			62995, 8198, 4103, 43281, 64265, 2177, 14465, 18561, 22657, 26753,
			34945, 39041, 47233, 30849, 46858, 3090, 11282, 7186, 15378, 19474,
			23570, 27666, 35858, 39954, 44050, 31762, 64530, 3091, 11283, 7187,
			15379, 19475, 23571, 27667, 35859, 39955, 44051, 48147, 31763, 64531,
			65535, 65535
		};

		protected static string[] errors = new string[8] { "Expected element", "Invalid character in tag", "No '='", "Invalid character entity", "Invalid attr value", "Empty tag", "No end tag", "Bad entity ref" };

		protected int line;

		protected int col;

		protected int[] twoCharBuff;

		protected bool splitCData;

		public MiniParser()
		{
			twoCharBuff = new int[2];
			splitCData = false;
			Reset();
		}

		public void Reset()
		{
			line = 0;
			col = 0;
		}

		protected static bool StrEquals(string str, StringBuilder sb, int sbStart, int len)
		{
			if (len != str.Length)
			{
				return false;
			}
			for (int i = 0; i < len; i++)
			{
				if (str[i] != sb[sbStart + i])
				{
					return false;
				}
			}
			return true;
		}

		protected void FatalErr(string descr)
		{
			throw new XMLError(descr, line, col);
		}

		protected static int Xlat(int charCode, int state)
		{
			int num = state * INPUT_RANGE;
			int num2 = System.Math.Min(tbl.Length - num, INPUT_RANGE);
			while (--num2 >= 0)
			{
				ushort num3 = tbl[num];
				if (charCode == num3 >> 12)
				{
					return num3 & 0xFFF;
				}
				num++;
			}
			return 4095;
		}

		public void Parse(IReader reader, IHandler handler)
		{
			if (reader == null)
			{
				throw new ArgumentNullException("reader");
			}
			if (handler == null)
			{
				handler = new HandlerAdapter();
			}
			AttrListImpl attrListImpl = new AttrListImpl();
			string text = null;
			Stack stack = new Stack();
			string text2 = null;
			line = 1;
			col = 0;
			int num = 0;
			int num2 = 0;
			StringBuilder stringBuilder = new StringBuilder();
			bool flag = false;
			bool flag2 = false;
			bool flag3 = false;
			int num3 = 0;
			handler.OnStartParsing(this);
			while (true)
			{
				col++;
				num = reader.Read();
				if (num == -1)
				{
					break;
				}
				int num4 = "<>/?=&'\"![ ]\t\r\n".IndexOf((char)num) & 0xF;
				switch (num4)
				{
				case 13:
					continue;
				case 12:
					num4 = 10;
					break;
				}
				if (num4 == 14)
				{
					col = 0;
					line++;
					num4 = 10;
				}
				int num5 = Xlat(num4, num2);
				num2 = num5 & 0xFF;
				if (num == 10 && (num2 == 14 || num2 == 15))
				{
					continue;
				}
				num5 >>= 8;
				if (num2 >= 128)
				{
					if (num2 == 255)
					{
						FatalErr("State dispatch error.");
					}
					else
					{
						FatalErr(errors[num2 ^ 0x80]);
					}
				}
				switch (num5)
				{
				case 9:
					break;
				case 0:
					handler.OnStartElement(text2, attrListImpl);
					if (num != 47)
					{
						stack.Push(text2);
					}
					else
					{
						handler.OnEndElement(text2);
					}
					attrListImpl.Clear();
					break;
				case 1:
				{
					text2 = stringBuilder.ToString();
					stringBuilder = new StringBuilder();
					string text6 = null;
					if (stack.Count == 0 || text2 != (text6 = stack.Pop() as string))
					{
						if (text6 == null)
						{
							FatalErr("Tag stack underflow");
						}
						else
						{
							FatalErr($"Expected end tag '{text2}' but found '{text6}'");
						}
					}
					handler.OnEndElement(text2);
					break;
				}
				case 2:
					text2 = stringBuilder.ToString();
					stringBuilder = new StringBuilder();
					if (num != 47 && num != 62)
					{
						break;
					}
					goto case 0;
				case 3:
					text = stringBuilder.ToString();
					stringBuilder = new StringBuilder();
					break;
				case 4:
					if (text == null)
					{
						FatalErr("Internal error.");
					}
					attrListImpl.Add(text, stringBuilder.ToString());
					stringBuilder = new StringBuilder();
					text = null;
					break;
				case 5:
					handler.OnChars(stringBuilder.ToString());
					stringBuilder = new StringBuilder();
					break;
				case 6:
				{
					string text5 = "CDATA[";
					flag2 = false;
					flag3 = false;
					switch (num)
					{
					case 45:
						num = reader.Read();
						if (num != 45)
						{
							FatalErr("Invalid comment");
						}
						col++;
						flag2 = true;
						twoCharBuff[0] = -1;
						twoCharBuff[1] = -1;
						break;
					default:
						flag3 = true;
						num3 = 0;
						break;
					case 91:
					{
						for (int i = 0; i < text5.Length; i++)
						{
							if (reader.Read() != text5[i])
							{
								col += i + 1;
								break;
							}
						}
						col += text5.Length;
						flag = true;
						break;
					}
					}
					break;
				}
				case 7:
				{
					int num20 = 0;
					num = 93;
					while (true)
					{
						switch (num)
						{
						case 93:
							goto IL_033d;
						default:
						{
							for (int k = 0; k < num20; k++)
							{
								stringBuilder.Append(']');
							}
							stringBuilder.Append((char)num);
							num2 = 18;
							break;
						}
						case 62:
						{
							for (int j = 0; j < num20 - 2; j++)
							{
								stringBuilder.Append(']');
							}
							flag = false;
							break;
						}
						}
						break;
						IL_033d:
						num = reader.Read();
						num20++;
					}
					col += num20;
					break;
				}
				case 8:
					FatalErr($"Error {num2}");
					break;
				case 10:
					stringBuilder = new StringBuilder();
					if (num == 60)
					{
						break;
					}
					goto case 11;
				case 11:
					stringBuilder.Append((char)num);
					break;
				case 12:
					if (flag2)
					{
						if (num == 62 && twoCharBuff[0] == 45 && twoCharBuff[1] == 45)
						{
							flag2 = false;
							num2 = 0;
						}
						else
						{
							twoCharBuff[0] = twoCharBuff[1];
							twoCharBuff[1] = num;
						}
					}
					else if (flag3)
					{
						if (num == 60 || num == 62)
						{
							num3 ^= 1;
						}
						if (num == 62 && num3 != 0)
						{
							flag3 = false;
							num2 = 0;
						}
					}
					else
					{
						if (splitCData && stringBuilder.Length > 0 && flag)
						{
							handler.OnChars(stringBuilder.ToString());
							stringBuilder = new StringBuilder();
						}
						flag = false;
						stringBuilder.Append((char)num);
					}
					break;
				case 13:
				{
					num = reader.Read();
					int num6 = col + 1;
					if (num == 35)
					{
						int num7 = 10;
						int num8 = 0;
						int num9 = 0;
						num = reader.Read();
						num6++;
						if (num == 120)
						{
							num = reader.Read();
							num6++;
							num7 = 16;
						}
						NumberStyles style = ((num7 == 16) ? NumberStyles.HexNumber : NumberStyles.Integer);
						while (true)
						{
							int num10 = -1;
							if (char.IsNumber((char)num) || "abcdef".IndexOf(char.ToLower((char)num)) != -1)
							{
								try
								{
									num10 = int.Parse(new string((char)num, 1), style);
								}
								catch (FormatException)
								{
									num10 = -1;
								}
							}
							if (num10 == -1)
							{
								break;
							}
							num8 *= num7;
							num8 += num10;
							num9++;
							num = reader.Read();
							num6++;
						}
						if (num == 59 && num9 > 0)
						{
							stringBuilder.Append((char)num8);
						}
						else
						{
							FatalErr("Bad char ref");
						}
					}
					else
					{
						string text3 = "aglmopqstu";
						string text4 = "&'\"><";
						int num11 = 0;
						int num12 = 15;
						int num13 = 0;
						int length = stringBuilder.Length;
						while (true)
						{
							if (num11 != 15)
							{
								num11 = text3.IndexOf((char)num) & 0xF;
							}
							if (num11 == 15)
							{
								FatalErr(errors[7]);
							}
							stringBuilder.Append((char)num);
							int num14 = "U㾏侏ཟク\ue1f4⊙\ueeff\ueeffo"[num11];
							int num15 = (num14 >> 4) & 0xF;
							int num16 = num14 & 0xF;
							int num17 = num14 >> 12;
							int num18 = (num14 >> 8) & 0xF;
							num = reader.Read();
							num6++;
							num11 = 15;
							if (num15 != 15 && num == text3[num15])
							{
								if (num17 < 14)
								{
									num12 = num17;
								}
								num13 = 12;
							}
							else if (num16 != 15 && num == text3[num16])
							{
								if (num18 < 14)
								{
									num12 = num18;
								}
								num13 = 8;
							}
							else if (num == 59)
							{
								if (num12 != 15 && num13 != 0 && ((num14 >> num13) & 0xF) == 14)
								{
									break;
								}
								continue;
							}
							num11 = 0;
						}
						int num19 = num6 - col - 1;
						if (num19 > 0 && num19 < 5 && (StrEquals("amp", stringBuilder, length, num19) || StrEquals("apos", stringBuilder, length, num19) || StrEquals("quot", stringBuilder, length, num19) || StrEquals("lt", stringBuilder, length, num19) || StrEquals("gt", stringBuilder, length, num19)))
						{
							stringBuilder.Length = length;
							stringBuilder.Append(text4[num12]);
						}
						else
						{
							FatalErr(errors[7]);
						}
					}
					col = num6;
					break;
				}
				default:
					FatalErr($"Unexpected action code - {num5}.");
					break;
				}
			}
			if (num2 != 0)
			{
				FatalErr("Unexpected EOF");
			}
			handler.OnEndParsing(this);
		}
	}
	[CLSCompliant(false)]
	public class SecurityParser : MiniParser, MiniParser.IHandler, MiniParser.IReader
	{
		private SecurityElement root;

		private string xmldoc;

		private int pos;

		private SecurityElement current;

		private Stack stack;

		public SecurityParser()
		{
			stack = new Stack();
		}

		public void LoadXml(string xml)
		{
			root = null;
			xmldoc = xml;
			pos = 0;
			stack.Clear();
			Parse(this, this);
		}

		public SecurityElement ToXml()
		{
			return root;
		}

		public int Read()
		{
			if (pos >= xmldoc.Length)
			{
				return -1;
			}
			return xmldoc[pos++];
		}

		public void OnStartParsing(MiniParser parser)
		{
		}

		public void OnStartElement(string name, IAttrList attrs)
		{
			SecurityElement securityElement = new SecurityElement(name);
			if (root == null)
			{
				root = securityElement;
				current = securityElement;
			}
			else
			{
				((SecurityElement)stack.Peek()).AddChild(securityElement);
			}
			stack.Push(securityElement);
			current = securityElement;
			int length = attrs.Length;
			for (int i = 0; i < length; i++)
			{
				current.AddAttribute(attrs.GetName(i), SecurityElement.Escape(attrs.GetValue(i)));
			}
		}

		public void OnEndElement(string name)
		{
			current = (SecurityElement)stack.Pop();
		}

		public void OnChars(string ch)
		{
			current.Text = SecurityElement.Escape(ch);
		}

		public void OnEndParsing(MiniParser parser)
		{
		}
	}
}
namespace Mono.Security
{
	public class ASN1
	{
		private byte m_nTag;

		private byte[] m_aValue;

		private ArrayList elist;

		public int Count
		{
			get
			{
				if (elist == null)
				{
					return 0;
				}
				return elist.Count;
			}
		}

		public byte Tag => m_nTag;

		public int Length
		{
			get
			{
				if (m_aValue != null)
				{
					return m_aValue.Length;
				}
				return 0;
			}
		}

		public byte[] Value
		{
			get
			{
				if (m_aValue == null)
				{
					GetBytes();
				}
				return (byte[])m_aValue.Clone();
			}
			set
			{
				if (value != null)
				{
					m_aValue = (byte[])value.Clone();
				}
			}
		}

		public ASN1 this[int index]
		{
			get
			{
				try
				{
					if (elist == null || index >= elist.Count)
					{
						return null;
					}
					return (ASN1)elist[index];
				}
				catch (ArgumentOutOfRangeException)
				{
					return null;
				}
			}
		}

		public ASN1()
			: this(0, null)
		{
		}

		public ASN1(byte tag)
			: this(tag, null)
		{
		}

		public ASN1(byte tag, byte[] data)
		{
			m_nTag = tag;
			m_aValue = data;
		}

		public ASN1(byte[] data)
		{
			m_nTag = data[0];
			int num = 0;
			int num2 = data[1];
			if (num2 > 128)
			{
				num = num2 - 128;
				num2 = 0;
				for (int i = 0; i < num; i++)
				{
					num2 *= 256;
					num2 += data[i + 2];
				}
			}
			else if (num2 == 128)
			{
				throw new NotSupportedException("Undefined length encoding.");
			}
			m_aValue = new byte[num2];
			Buffer.BlockCopy(data, 2 + num, m_aValue, 0, num2);
			if ((m_nTag & 0x20) == 32)
			{
				int anPos = 0;
				Decode(m_aValue, ref anPos, m_aValue.Length);
			}
		}

		private bool CompareArray(byte[] array1, byte[] array2)
		{
			bool flag = array1.Length == array2.Length;
			if (flag)
			{
				for (int i = 0; i < array1.Length; i++)
				{
					if (array1[i] != array2[i])
					{
						return false;
					}
				}
			}
			return flag;
		}

		public bool Equals(byte[] asn1)
		{
			return CompareArray(GetBytes(), asn1);
		}

		public bool CompareValue(byte[] value)
		{
			return CompareArray(m_aValue, value);
		}

		public ASN1 Add(ASN1 asn1)
		{
			if (asn1 != null)
			{
				if (elist == null)
				{
					elist = new ArrayList();
				}
				elist.Add(asn1);
			}
			return asn1;
		}

		public virtual byte[] GetBytes()
		{
			byte[] array = null;
			if (Count > 0)
			{
				int num = 0;
				ArrayList arrayList = new ArrayList();
				foreach (ASN1 item in elist)
				{
					byte[] bytes = item.GetBytes();
					arrayList.Add(bytes);
					num += bytes.Length;
				}
				array = new byte[num];
				int num2 = 0;
				for (int i = 0; i < elist.Count; i++)
				{
					byte[] array2 = (byte[])arrayList[i];
					Buffer.BlockCopy(array2, 0, array, num2, array2.Length);
					num2 += array2.Length;
				}
			}
			else if (m_aValue != null)
			{
				array = m_aValue;
			}
			int num3 = 0;
			byte[] array3;
			if (array != null)
			{
				int num4 = array.Length;
				if (num4 > 127)
				{
					if (num4 <= 255)
					{
						array3 = new byte[3 + num4];
						Buffer.BlockCopy(array, 0, array3, 3, num4);
						num3 = 129;
						array3[2] = (byte)num4;
					}
					else if (num4 <= 65535)
					{
						array3 = new byte[4 + num4];
						Buffer.BlockCopy(array, 0, array3, 4, num4);
						num3 = 130;
						array3[2] = (byte)(num4 >> 8);
						array3[3] = (byte)num4;
					}
					else if (num4 <= 16777215)
					{
						array3 = new byte[5 + num4];
						Buffer.BlockCopy(array, 0, array3, 5, num4);
						num3 = 131;
						array3[2] = (byte)(num4 >> 16);
						array3[3] = (byte)(num4 >> 8);
						array3[4] = (byte)num4;
					}
					else
					{
						array3 = new byte[6 + num4];
						Buffer.BlockCopy(array, 0, array3, 6, num4);
						num3 = 132;
						array3[2] = (byte)(num4 >> 24);
						array3[3] = (byte)(num4 >> 16);
						array3[4] = (byte)(num4 >> 8);
						array3[5] = (byte)num4;
					}
				}
				else
				{
					array3 = new byte[2 + num4];
					Buffer.BlockCopy(array, 0, array3, 2, num4);
					num3 = num4;
				}
				if (m_aValue == null)
				{
					m_aValue = array;
				}
			}
			else
			{
				array3 = new byte[2];
			}
			array3[0] = m_nTag;
			array3[1] = (byte)num3;
			return array3;
		}

		protected void Decode(byte[] asn1, ref int anPos, int anLength)
		{
			while (anPos < anLength - 1)
			{
				DecodeTLV(asn1, ref anPos, out var tag, out var length, out var content);
				if (tag != 0)
				{
					ASN1 aSN = Add(new ASN1(tag, content));
					if ((tag & 0x20) == 32)
					{
						int anPos2 = anPos;
						aSN.Decode(asn1, ref anPos2, anPos2 + length);
					}
					anPos += length;
				}
			}
		}

		protected void DecodeTLV(byte[] asn1, ref int pos, out byte tag, out int length, out byte[] content)
		{
			tag = asn1[pos++];
			length = asn1[pos++];
			if ((length & 0x80) == 128)
			{
				int num = length & 0x7F;
				length = 0;
				for (int i = 0; i < num; i++)
				{
					length = length * 256 + asn1[pos++];
				}
			}
			content = new byte[length];
			Buffer.BlockCopy(asn1, pos, content, 0, length);
		}

		public ASN1 Element(int index, byte anTag)
		{
			try
			{
				if (elist == null || index >= elist.Count)
				{
					return null;
				}
				ASN1 aSN = (ASN1)elist[index];
				if (aSN.Tag == anTag)
				{
					return aSN;
				}
				return null;
			}
			catch (ArgumentOutOfRangeException)
			{
				return null;
			}
		}

		public override string ToString()
		{
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.AppendFormat("Tag: {0} {1}", m_nTag.ToString("X2"), Environment.NewLine);
			stringBuilder.AppendFormat("Length: {0} {1}", Value.Length, Environment.NewLine);
			stringBuilder.Append("Value: ");
			stringBuilder.Append(Environment.NewLine);
			for (int i = 0; i < Value.Length; i++)
			{
				stringBuilder.AppendFormat("{0} ", Value[i].ToString("X2"));
				if ((i + 1) % 16 == 0)
				{
					stringBuilder.AppendFormat(Environment.NewLine);
				}
			}
			return stringBuilder.ToString();
		}

		public void SaveToFile(string filename)
		{
			if (filename == null)
			{
				throw new ArgumentNullException("filename");
			}
			using FileStream fileStream = File.Create(filename);
			byte[] bytes = GetBytes();
			fileStream.Write(bytes, 0, bytes.Length);
		}
	}
	public static class ASN1Convert
	{
		public static ASN1 FromDateTime(DateTime dt)
		{
			if (dt.Year < 2050)
			{
				return new ASN1(23, Encoding.ASCII.GetBytes(dt.ToUniversalTime().ToString("yyMMddHHmmss", CultureInfo.InvariantCulture) + "Z"));
			}
			return new ASN1(24, Encoding.ASCII.GetBytes(dt.ToUniversalTime().ToString("yyyyMMddHHmmss", CultureInfo.InvariantCulture) + "Z"));
		}

		public static ASN1 FromInt32(int value)
		{
			byte[] bytes = BitConverterLE.GetBytes(value);
			Array.Reverse(bytes);
			int i;
			for (i = 0; i < bytes.Length && bytes[i] == 0; i++)
			{
			}
			ASN1 aSN = new ASN1(2);
			switch (i)
			{
			case 0:
				aSN.Value = bytes;
				break;
			case 4:
				aSN.Value = new byte[1];
				break;
			default:
			{
				byte[] array = new byte[4 - i];
				Buffer.BlockCopy(bytes, i, array, 0, array.Length);
				aSN.Value = array;
				break;
			}
			}
			return aSN;
		}

		public static ASN1 FromOid(string oid)
		{
			if (oid == null)
			{
				throw new ArgumentNullException("oid");
			}
			return new ASN1(CryptoConfig.EncodeOID(oid));
		}

		public static ASN1 FromUnsignedBigInteger(byte[] big)
		{
			if (big == null)
			{
				throw new ArgumentNullException("big");
			}
			if (big[0] >= 128)
			{
				int num = big.Length + 1;
				byte[] array = new byte[num];
				Buffer.BlockCopy(big, 0, array, 1, num - 1);
				big = array;
			}
			return new ASN1(2, big);
		}

		public static int ToInt32(ASN1 asn1)
		{
			if (asn1 == null)
			{
				throw new ArgumentNullException("asn1");
			}
			if (asn1.Tag != 2)
			{
				throw new FormatException("Only integer can be converted");
			}
			int num = 0;
			for (int i = 0; i < asn1.Value.Length; i++)
			{
				num = (num << 8) + asn1.Value[i];
			}
			return num;
		}

		public static string ToOid(ASN1 asn1)
		{
			if (asn1 == null)
			{
				throw new ArgumentNullException("asn1");
			}
			byte[] value = asn1.Value;
			StringBuilder stringBuilder = new StringBuilder();
			byte b = (byte)(value[0] / 40);
			byte b2 = (byte)(value[0] % 40);
			if (b > 2)
			{
				b2 += (byte)((b - 2) * 40);
				b = 2;
			}
			stringBuilder.Append(b.ToString(CultureInfo.InvariantCulture));
			stringBuilder.Append(".");
			stringBuilder.Append(b2.ToString(CultureInfo.InvariantCulture));
			ulong num = 0uL;
			for (b = 1; b < value.Length; b++)
			{
				num = (num << 7) | (byte)(value[b] & 0x7Fu);
				if ((value[b] & 0x80) != 128)
				{
					stringBuilder.Append(".");
					stringBuilder.Append(num.ToString(CultureInfo.InvariantCulture));
					num = 0uL;
				}
			}
			return stringBuilder.ToString();
		}

		public static DateTime ToDateTime(ASN1 time)
		{
			if (time == null)
			{
				throw new ArgumentNullException("time");
			}
			string text = Encoding.ASCII.GetString(time.Value);
			string format = null;
			switch (text.Length)
			{
			case 11:
				format = "yyMMddHHmmZ";
				break;
			case 13:
				text = ((Convert.ToInt16(text.Substring(0, 2), CultureInfo.InvariantCulture) < 50) ? ("20" + text) : ("19" + text));
				format = "yyyyMMddHHmmssZ";
				break;
			case 15:
				format = "yyyyMMddHHmmssZ";
				break;
			case 17:
			{
				string text2 = ((Convert.ToInt16(text.Substring(0, 2), CultureInfo.InvariantCulture) >= 50) ? "19" : "20");
				char c = ((text[12] == '+') ? '-' : '+');
				text = $"{text2}{text.Substring(0, 12)}{c}{text[13]}{text[14]}:{text[15]}{text[16]}";
				format = "yyyyMMddHHmmsszzz";
				break;
			}
			}
			return DateTime.ParseExact(text, format, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal);
		}
	}
	internal sealed class BitConverterLE
	{
		private BitConverterLE()
		{
		}

		private unsafe static byte[] GetUShortBytes(byte* bytes)
		{
			if (!BitConverter.IsLittleEndian)
			{
				return new byte[2]
				{
					bytes[1],
					*bytes
				};
			}
			return new byte[2]
			{
				*bytes,
				bytes[1]
			};
		}

		private unsafe static byte[] GetUIntBytes(byte* bytes)
		{
			if (!BitConverter.IsLittleEndian)
			{
				return new byte[4]
				{
					bytes[3],
					bytes[2],
					bytes[1],
					*bytes
				};
			}
			return new byte[4]
			{
				*bytes,
				bytes[1],
				bytes[2],
				bytes[3]
			};
		}

		private unsafe static byte[] GetULongBytes(byte* bytes)
		{
			if (!BitConverter.IsLittleEndian)
			{
				return new byte[8]
				{
					bytes[7],
					bytes[6],
					bytes[5],
					bytes[4],
					bytes[3],
					bytes[2],
					bytes[1],
					*bytes
				};
			}
			return new byte[8]
			{
				*bytes,
				bytes[1],
				bytes[2],
				bytes[3],
				bytes[4],
				bytes[5],
				bytes[6],
				bytes[7]
			};
		}

		internal static byte[] GetBytes(bool value)
		{
			return new byte[1] { (byte)(value ? 1 : 0) };
		}

		internal unsafe static byte[] GetBytes(char value)
		{
			return GetUShortBytes((byte*)(&value));
		}

		internal unsafe static byte[] GetBytes(short value)
		{
			return GetUShortBytes((byte*)(&value));
		}

		internal unsafe static byte[] GetBytes(int value)
		{
			return GetUIntBytes((byte*)(&value));
		}

		internal unsafe static byte[] GetBytes(long value)
		{
			return GetULongBytes((byte*)(&value));
		}

		internal unsafe static byte[] GetBytes(ushort value)
		{
			return GetUShortBytes((byte*)(&value));
		}

		internal unsafe static byte[] GetBytes(uint value)
		{
			return GetUIntBytes((byte*)(&value));
		}

		internal unsafe static byte[] GetBytes(ulong value)
		{
			return GetULongBytes((byte*)(&value));
		}

		internal unsafe static byte[] GetBytes(float value)
		{
			return GetUIntBytes((byte*)(&value));
		}

		internal unsafe static byte[] GetBytes(double value)
		{
			return GetULongBytes((byte*)(&value));
		}

		private unsafe static void UShortFromBytes(byte* dst, byte[] src, int startIndex)
		{
			if (BitConverter.IsLittleEndian)
			{
				*dst = src[startIndex];
				dst[1] = src[startIndex + 1];
			}
			else
			{
				*dst = src[startIndex + 1];
				dst[1] = src[startIndex];
			}
		}

		private unsafe static void UIntFromBytes(byte* dst, byte[] src, int startIndex)
		{
			if (BitConverter.IsLittleEndian)
			{
				*dst = src[startIndex];
				dst[1] = src[startIndex + 1];
				dst[2] = src[startIndex + 2];
				dst[3] = src[startIndex + 3];
			}
			else
			{
				*dst = src[startIndex + 3];
				dst[1] = src[startIndex + 2];
				dst[2] = src[startIndex + 1];
				dst[3] = src[startIndex];
			}
		}

		private unsafe static void ULongFromBytes(byte* dst, byte[] src, int startIndex)
		{
			if (BitConverter.IsLittleEndian)
			{
				for (int i = 0; i < 8; i++)
				{
					dst[i] = src[startIndex + i];
				}
			}
			else
			{
				for (int j = 0; j < 8; j++)
				{
					dst[j] = src[startIndex + (7 - j)];
				}
			}
		}

		internal static bool ToBoolean(byte[] value, int startIndex)
		{
			return value[startIndex] != 0;
		}

		internal unsafe static char ToChar(byte[] value, int startIndex)
		{
			char result = default(char);
			UShortFromBytes((byte*)(&result), value, startIndex);
			return result;
		}

		internal unsafe static short ToInt16(byte[] value, int startIndex)
		{
			short result = default(short);
			UShortFromBytes((byte*)(&result), value, startIndex);
			return result;
		}

		internal unsafe static int ToInt32(byte[] value, int startIndex)
		{
			int result = default(int);
			UIntFromBytes((byte*)(&result), value, startIndex);
			return result;
		}

		internal unsafe static long ToInt64(byte[] value, int startIndex)
		{
			long result = default(long);
			ULongFromBytes((byte*)(&result), value, startIndex);
			return result;
		}

		internal unsafe static ushort ToUInt16(byte[] value, int startIndex)
		{
			ushort result = default(ushort);
			UShortFromBytes((byte*)(&result), value, startIndex);
			return result;
		}

		internal unsafe static uint ToUInt32(byte[] value, int startIndex)
		{
			uint result = default(uint);
			UIntFromBytes((byte*)(&result), value, startIndex);
			return result;
		}

		internal unsafe static ulong ToUInt64(byte[] value, int startIndex)
		{
			ulong result = default(ulong);
			ULongFromBytes((byte*)(&result), value, startIndex);
			return result;
		}

		internal unsafe static float ToSingle(byte[] value, int startIndex)
		{
			float result = default(float);
			UIntFromBytes((byte*)(&result), value, startIndex);
			return result;
		}

		internal unsafe static double ToDouble(byte[] value, int startIndex)
		{
			double result = default(double);
			ULongFromBytes((byte*)(&result), value, startIndex);
			return result;
		}
	}
	public sealed class PKCS7
	{
		public class Oid
		{
			public const string rsaEncryption = "1.2.840.113549.1.1.1";

			public const string data = "1.2.840.113549.1.7.1";

			public const string signedData = "1.2.840.113549.1.7.2";

			public const string envelopedData = "1.2.840.113549.1.7.3";

			public const string signedAndEnvelopedData = "1.2.840.113549.1.7.4";

			public const string digestedData = "1.2.840.113549.1.7.5";

			public const string encryptedData = "1.2.840.113549.1.7.6";

			public const string contentType = "1.2.840.113549.1.9.3";

			public const string messageDigest = "1.2.840.113549.1.9.4";

			public const string signingTime = "1.2.840.113549.1.9.5";

			public const string countersignature = "1.2.840.113549.1.9.6";
		}

		public class ContentInfo
		{
			private string contentType;

			private ASN1 content;

			public ASN1 ASN1 => GetASN1();

			public ASN1 Content
			{
				get
				{
					return content;
				}
				set
				{
					content = value;
				}
			}

			public string ContentType
			{
				get
				{
					return contentType;
				}
				set
				{
					contentType = value;
				}
			}

			public ContentInfo()
			{
				content = new ASN1(160);
			}

			public ContentInfo(string oid)
				: this()
			{
				contentType = oid;
			}

			public ContentInfo(byte[] data)
				: this(new ASN1(data))
			{
			}

			public ContentInfo(ASN1 asn1)
			{
				if (asn1.Tag != 48 || (asn1.Count < 1 && asn1.Count > 2))
				{
					throw new ArgumentException("Invalid ASN1");
				}
				if (asn1[0].Tag != 6)
				{
					throw new ArgumentException("Invalid contentType");
				}
				contentType = ASN1Convert.ToOid(asn1[0]);
				if (asn1.Count > 1)
				{
					if (asn1[1].Tag != 160)
					{
						throw new ArgumentException("Invalid content");
					}
					content = asn1[1];
				}
			}

			internal ASN1 GetASN1()
			{
				ASN1 aSN = new ASN1(48);
				aSN.Add(ASN1Convert.FromOid(contentType));
				if (content != null && content.Count > 0)
				{
					aSN.Add(content);
				}
				return aSN;
			}

			public byte[] GetBytes()
			{
				return GetASN1().GetBytes();
			}
		}

		public class EncryptedData
		{
			private byte _version;

			private ContentInfo _content;

			private ContentInfo _encryptionAlgorithm;

			private byte[] _encrypted;

			public ASN1 ASN1 => GetASN1();

			public ContentInfo ContentInfo => _content;

			public ContentInfo EncryptionAlgorithm => _encryptionAlgorithm;

			public byte[] EncryptedContent
			{
				get
				{
					if (_encrypted == null)
					{
						return null;
					}
					return (byte[])_encrypted.Clone();
				}
			}

			public byte Version
			{
				get
				{
					return _version;
				}
				set
				{
					_version = value;
				}
			}

			public EncryptedData()
			{
				_version = 0;
			}

			public EncryptedData(byte[] data)
				: this(new ASN1(data))
			{
			}

			public EncryptedData(ASN1 asn1)
				: this()
			{
				if (asn1.Tag != 48 || asn1.Count < 2)
				{
					throw new ArgumentException("Invalid EncryptedData");
				}
				if (asn1[0].Tag != 2)
				{
					throw new ArgumentException("Invalid version");
				}
				_version = asn1[0].Value[0];
				ASN1 aSN = asn1[1];
				if (aSN.Tag != 48)
				{
					throw new ArgumentException("missing EncryptedContentInfo");
				}
				ASN1 aSN2 = aSN[0];
				if (aSN2.Tag != 6)
				{
					throw new ArgumentException("missing EncryptedContentInfo.ContentType");
				}
				_content = new ContentInfo(ASN1Convert.ToOid(aSN2));
				ASN1 aSN3 = aSN[1];
				if (aSN3.Tag != 48)
				{
					throw new ArgumentException("missing EncryptedContentInfo.ContentEncryptionAlgorithmIdentifier");
				}
				_encryptionAlgorithm = new ContentInfo(ASN1Convert.ToOid(aSN3[0]));
				_encryptionAlgorithm.Content = aSN3[1];
				ASN1 aSN4 = aSN[2];
				if (aSN4.Tag != 128)
				{
					throw new ArgumentException("missing EncryptedContentInfo.EncryptedContent");
				}
				_encrypted = aSN4.Value;
			}

			internal ASN1 GetASN1()
			{
				return null;
			}

			public byte[] GetBytes()
			{
				return GetASN1().GetBytes();
			}
		}

		public class EnvelopedData
		{
			private byte _version;

			private ContentInfo _content;

			private ContentInfo _encryptionAlgorithm;

			private ArrayList _recipientInfos;

			private byte[] _encrypted;

			public ArrayList RecipientInfos => _recipientInfos;

			public ASN1 ASN1 => GetASN1();

			public ContentInfo ContentInfo => _content;

			public ContentInfo EncryptionAlgorithm => _encryptionAlgorithm;

			public byte[] EncryptedContent
			{
				get
				{
					if (_encrypted == null)
					{
						return null;
					}
					return (byte[])_encrypted.Clone();
				}
			}

			public byte Version
			{
				get
				{
					return _version;
				}
				set
				{
					_version = value;
				}
			}

			public EnvelopedData()
			{
				_version = 0;
				_content = new ContentInfo();
				_encryptionAlgorithm = new ContentInfo();
				_recipientInfos = new ArrayList();
			}

			public EnvelopedData(byte[] data)
				: this(new ASN1(data))
			{
			}

			public EnvelopedData(ASN1 asn1)
				: this()
			{
				if (asn1[0].Tag != 48 || asn1[0].Count < 3)
				{
					throw new ArgumentException("Invalid EnvelopedData");
				}
				if (asn1[0][0].Tag != 2)
				{
					throw new ArgumentException("Invalid version");
				}
				_version = asn1[0][0].Value[0];
				ASN1 aSN = asn1[0][1];
				if (aSN.Tag != 49)
				{
					throw new ArgumentException("missing RecipientInfos");
				}
				for (int i = 0; i < aSN.Count; i++)
				{
					ASN1 data = aSN[i];
					_recipientInfos.Add(new RecipientInfo(data));
				}
				ASN1 aSN2 = asn1[0][2];
				if (aSN2.Tag != 48)
				{
					throw new ArgumentException("missing EncryptedContentInfo");
				}
				ASN1 aSN3 = aSN2[0];
				if (aSN3.Tag != 6)
				{
					throw new ArgumentException("missing EncryptedContentInfo.ContentType");
				}
				_content = new ContentInfo(ASN1Convert.ToOid(aSN3));
				ASN1 aSN4 = aSN2[1];
				if (aSN4.Tag != 48)
				{
					throw new ArgumentException("missing EncryptedContentInfo.ContentEncryptionAlgorithmIdentifier");
				}
				_encryptionAlgorithm = new ContentInfo(ASN1Convert.ToOid(aSN4[0]));
				_encryptionAlgorithm.Content = aSN4[1];
				ASN1 aSN5 = aSN2[2];
				if (aSN5.Tag != 128)
				{
					throw new ArgumentException("missing EncryptedContentInfo.EncryptedContent");
				}
				_encrypted = aSN5.Value;
			}

			internal ASN1 GetASN1()
			{
				return new ASN1(48);
			}

			public byte[] GetBytes()
			{
				return GetASN1().GetBytes();
			}
		}

		public class RecipientInfo
		{
			private int _version;

			private string _oid;

			private byte[] _key;

			private byte[] _ski;

			private string _issuer;

			private byte[] _serial;

			public string Oid => _oid;

			public byte[] Key
			{
				get
				{
					if (_key == null)
					{
						return null;
					}
					return (byte[])_key.Clone();
				}
			}

			public byte[] SubjectKeyIdentifier
			{
				get
				{
					if (_ski == null)
					{
						return null;
					}
					return (byte[])_ski.Clone();
				}
			}

			public string Issuer => _issuer;

			public byte[] Serial
			{
				get
				{
					if (_serial == null)
					{
						return null;
					}
					return (byte[])_serial.Clone();
				}
			}

			public int Version => _version;

			public RecipientInfo()
			{
			}

			public RecipientInfo(ASN1 data)
			{
				if (data.Tag != 48)
				{
					throw new ArgumentException("Invalid RecipientInfo");
				}
				ASN1 aSN = data[0];
				if (aSN.Tag != 2)
				{
					throw new ArgumentException("missing Version");
				}
				_version = aSN.Value[0];
				ASN1 aSN2 = data[1];
				if (aSN2.Tag == 128 && _version == 3)
				{
					_ski = aSN2.Value;
				}
				else
				{
					_issuer = X501.ToString(aSN2[0]);
					_serial = aSN2[1].Value;
				}
				ASN1 aSN3 = data[2];
				_oid = ASN1Convert.ToOid(aSN3[0]);
				ASN1 aSN4 = data[3];
				_key = aSN4.Value;
			}
		}

		public class SignedData
		{
			private byte version;

			private string hashAlgorithm;

			private ContentInfo contentInfo;

			private Mono.Security.X509.X509CertificateCollection certs;

			private ArrayList crls;

			private SignerInfo signerInfo;

			private bool mda;

			private bool signed;

			public ASN1 ASN1 => GetASN1();

			public Mono.Security.X509.X509CertificateCollection Certificates => certs;

			public ContentInfo ContentInfo => contentInfo;

			public ArrayList Crls => crls;

			public string HashName
			{
				get
				{
					return hashAlgorithm;
				}
				set
				{
					hashAlgorithm = value;
					signerInfo.HashName = value;
				}
			}

			public SignerInfo SignerInfo => signerInfo;

			public byte Version
			{
				get
				{
					return version;
				}
				set
				{
					version = value;
				}
			}

			public bool UseAuthenticatedAttributes
			{
				get
				{
					return mda;
				}
				set
				{
					mda = value;
				}
			}

			public SignedData()
			{
				version = 1;
				contentInfo = new ContentInfo();
				certs = new Mono.Security.X509.X509CertificateCollection();
				crls = new ArrayList();
				signerInfo = new SignerInfo();
				mda = true;
				signed = false;
			}

			public SignedData(byte[] data)
				: this(new ASN1(data))
			{
			}

			public SignedData(ASN1 asn1)
			{
				if (asn1[0].Tag != 48 || asn1[0].Count < 4)
				{
					throw new ArgumentException("Invalid SignedData");
				}
				if (asn1[0][0].Tag != 2)
				{
					throw new ArgumentException("Invalid version");
				}
				version = asn1[0][0].Value[0];
				contentInfo = new ContentInfo(asn1[0][2]);
				int num = 3;
				certs = new Mono.Security.X509.X509CertificateCollection();
				if (asn1[0][num].Tag == 160)
				{
					for (int i = 0; i < asn1[0][num].Count; i++)
					{
						certs.Add(new Mono.Security.X509.X509Certificate(asn1[0][num][i].GetBytes()));
					}
					num++;
				}
				crls = new ArrayList();
				if (asn1[0][num].Tag == 161)
				{
					for (int j = 0; j < asn1[0][num].Count; j++)
					{
						crls.Add(asn1[0][num][j].GetBytes());
					}
					num++;
				}
				if (asn1[0][num].Count > 0)
				{
					signerInfo = new SignerInfo(asn1[0][num]);
				}
				else
				{
					signerInfo = new SignerInfo();
				}
				if (signerInfo.HashName != null)
				{
					HashName = OidToName(signerInfo.HashName);
				}
				mda = signerInfo.AuthenticatedAttributes.Count > 0;
			}

			public bool VerifySignature(AsymmetricAlgorithm aa)
			{
				if (aa == null)
				{
					return false;
				}
				RSAPKCS1SignatureDeformatter rSAPKCS1SignatureDeformatter = new RSAPKCS1SignatureDeformatter(aa);
				rSAPKCS1SignatureDeformatter.SetHashAlgorithm(this.hashAlgorithm);
				HashAlgorithm hashAlgorithm = HashAlgorithm.Create(this.hashAlgorithm);
				byte[] signature = signerInfo.Signature;
				byte[] array = null;
				if (mda)
				{
					ASN1 aSN = new ASN1(49);
					foreach (ASN1 authenticatedAttribute in signerInfo.AuthenticatedAttributes)
					{
						aSN.Add(authenticatedAttribute);
					}
					array = hashAlgorithm.ComputeHash(aSN.GetBytes());
				}
				else
				{
					array = hashAlgorithm.ComputeHash(contentInfo.Content[0].Value);
				}
				if (array != null && signature != null)
				{
					return rSAPKCS1SignatureDeformatter.VerifySignature(array, signature);
				}
				return false;
			}

			internal string OidToName(string oid)
			{
				return oid switch
				{
					"1.3.14.3.2.26" => "SHA1", 
					"1.2.840.113549.2.2" => "MD2", 
					"1.2.840.113549.2.5" => "MD5", 
					"2.16.840.1.101.3.4.1" => "SHA256", 
					"2.16.840.1.101.3.4.2" => "SHA384", 
					"2.16.840.1.101.3.4.3" => "SHA512", 
					_ => oid, 
				};
			}

			internal ASN1 GetASN1()
			{
				ASN1 aSN = new ASN1(48);
				byte[] data = new byte[1] { version };
				aSN.Add(new ASN1(2, data));
				ASN1 aSN2 = aSN.Add(new ASN1(49));
				if (hashAlgorithm != null)
				{
					string oid = CryptoConfig.MapNameToOID(hashAlgorithm);
					aSN2.Add(AlgorithmIdentifier(oid));
				}
				ASN1 aSN3 = contentInfo.ASN1;
				aSN.Add(aSN3);
				if (!signed && hashAlgorithm != null)
				{
					if (mda)
					{
						ASN1 value = Attribute("1.2.840.113549.1.9.3", aSN3[0]);
						signerInfo.AuthenticatedAttributes.Add(value);
						byte[] data2 = HashAlgorithm.Create(hashAlgorithm).ComputeHash(aSN3[1][0].Value);
						ASN1 aSN4 = new ASN1(48);
						ASN1 value2 = Attribute("1.2.840.113549.1.9.4", aSN4.Add(new ASN1(4, data2)));
						signerInfo.AuthenticatedAttributes.Add(value2);
					}
					else
					{
						RSAPKCS1SignatureFormatter rSAPKCS1SignatureFormatter = new RSAPKCS1SignatureFormatter(signerInfo.Key);
						rSAPKCS1SignatureFormatter.SetHashAlgorithm(hashAlgorithm);
						byte[] rgbHash = HashAlgorithm.Create(hashAlgorithm).ComputeHash(aSN3[1][0].Value);
						signerInfo.Signature = rSAPKCS1SignatureFormatter.CreateSignature(rgbHash);
					}
					signed = true;
				}
				if (certs.Count > 0)
				{
					ASN1 aSN5 = aSN.Add(new ASN1(160));
					foreach (Mono.Security.X509.X509Certificate cert in certs)
					{
						aSN5.Add(new ASN1(cert.RawData));
					}
				}
				if (crls.Count > 0)
				{
					ASN1 aSN6 = aSN.Add(new ASN1(161));
					foreach (byte[] crl in crls)
					{
						aSN6.Add(new ASN1(crl));
					}
				}
				ASN1 aSN7 = aSN.Add(new ASN1(49));
				if (signerInfo.Key != null)
				{
					aSN7.Add(signerInfo.ASN1);
				}
				return aSN;
			}

			public byte[] GetBytes()
			{
				return GetASN1().GetBytes();
			}
		}

		public class SignerInfo
		{
			private byte version;

			private Mono.Security.X509.X509Certificate x509;

			private string hashAlgorithm;

			private AsymmetricAlgorithm key;

			private ArrayList authenticatedAttributes;

			private ArrayList unauthenticatedAttributes;

			private byte[] signature;

			private string issuer;

			private byte[] serial;

			private byte[] ski;

			public string IssuerName => issuer;

			public byte[] SerialNumber
			{
				get
				{
					if (serial == null)
					{
						return null;
					}
					return (byte[])serial.Clone();
				}
			}

			public byte[] SubjectKeyIdentifier
			{
				get
				{
					if (ski == null)
					{
						return null;
					}
					return (byte[])ski.Clone();
				}
			}

			public ASN1 ASN1 => GetASN1();

			public ArrayList AuthenticatedAttributes => authenticatedAttributes;

			public Mono.Security.X509.X509Certificate Certificate
			{
				get
				{
					return x509;
				}
				set
				{
					x509 = value;
				}
			}

			public string HashName
			{
				get
				{
					return hashAlgorithm;
				}
				set
				{
					hashAlgorithm = value;
				}
			}

			public AsymmetricAlgorithm Key
			{
				get
				{
					return key;
				}
				set
				{
					key = value;
				}
			}

			public byte[] Signature
			{
				get
				{
					if (signature == null)
					{
						return null;
					}
					return (byte[])signature.Clone();
				}
				set
				{
					if (value != null)
					{
						signature = (byte[])value.Clone();
					}
				}
			}

			public ArrayList UnauthenticatedAttributes => unauthenticatedAttributes;

			public byte Version
			{
				get
				{
					return version;
				}
				set
				{
					version = value;
				}
			}

			public SignerInfo()
			{
				version = 1;
				authenticatedAttributes = new ArrayList();
				unauthenticatedAttributes = new ArrayList();
			}

			public SignerInfo(byte[] data)
				: this(new ASN1(data))
			{
			}

			public SignerInfo(ASN1 asn1)
				: this()
			{
				if (asn1[0].Tag != 48 || asn1[0].Count < 5)
				{
					throw new ArgumentException("Invalid SignedData");
				}
				if (asn1[0][0].Tag != 2)
				{
					throw new ArgumentException("Invalid version");
				}
				version = asn1[0][0].Value[0];
				ASN1 aSN = asn1[0][1];
				if (aSN.Tag == 128 && version == 3)
				{
					ski = aSN.Value;
				}
				else
				{
					issuer = X501.ToString(aSN[0]);
					serial = aSN[1].Value;
				}
				ASN1 aSN2 = asn1[0][2];
				hashAlgorithm = ASN1Convert.ToOid(aSN2[0]);
				int num = 3;
				ASN1 aSN3 = asn1[0][num];
				if (aSN3.Tag == 160)
				{
					num++;
					for (int i = 0; i < aSN3.Count; i++)
					{
						authenticatedAttributes.Add(aSN3[i]);
					}
				}
				num++;
				ASN1 aSN4 = asn1[0][num++];
				if (aSN4.Tag == 4)
				{
					signature = aSN4.Value;
				}
				ASN1 aSN5 = asn1[0][num];
				if (aSN5 != null && aSN5.Tag == 161)
				{
					for (int j = 0; j < aSN5.Count; j++)
					{
						unauthenticatedAttributes.Add(aSN5[j]);
					}
				}
			}

			internal ASN1 GetASN1()
			{
				if (key == null || hashAlgorithm == null)
				{
					return null;
				}
				byte[] data = new byte[1] { version };
				ASN1 aSN = new ASN1(48);
				aSN.Add(new ASN1(2, data));
				aSN.Add(IssuerAndSerialNumber(x509));
				string oid = CryptoConfig.MapNameToOID(hashAlgorithm);
				aSN.Add(AlgorithmIdentifier(oid));
				ASN1 aSN2 = null;
				if (authenticatedAttributes.Count > 0)
				{
					aSN2 = aSN.Add(new ASN1(160));
					authenticatedAttributes.Sort(new SortedSet());
					foreach (ASN1 authenticatedAttribute in authenticatedAttributes)
					{
						aSN2.Add(authenticatedAttribute);
					}
				}
				if (key is RSA)
				{
					aSN.Add(AlgorithmIdentifier("1.2.840.113549.1.1.1"));
					if (aSN2 != null)
					{
						RSAPKCS1SignatureFormatter rSAPKCS1SignatureFormatter = new RSAPKCS1SignatureFormatter(key);
						rSAPKCS1SignatureFormatter.SetHashAlgorithm(hashAlgorithm);
						byte[] bytes = aSN2.GetBytes();
						bytes[0] = 49;
						byte[] rgbHash = HashAlgorithm.Create(hashAlgorithm).ComputeHash(bytes);
						signature = rSAPKCS1SignatureFormatter.CreateSignature(rgbHash);
					}
					aSN.Add(new ASN1(4, signature));
					if (unauthenticatedAttributes.Count > 0)
					{
						ASN1 aSN3 = aSN.Add(new ASN1(161));
						unauthenticatedAttributes.Sort(new SortedSet());
						foreach (ASN1 unauthenticatedAttribute in unauthenticatedAttributes)
						{
							aSN3.Add(unauthenticatedAttribute);
						}
					}
					return aSN;
				}
				if (key is DSA)
				{
					throw new NotImplementedException("not yet");
				}
				throw new CryptographicException("Unknown assymetric algorithm");
			}

			public byte[] GetBytes()
			{
				return GetASN1().GetBytes();
			}
		}

		internal class SortedSet : IComparer
		{
			public int Compare(object x, object y)
			{
				if (x == null)
				{
					if (y != null)
					{
						return -1;
					}
					return 0;
				}
				if (y == null)
				{
					return 1;
				}
				ASN1 obj = x as ASN1;
				ASN1 aSN = y as ASN1;
				if (obj == null || aSN == null)
				{
					throw new ArgumentException(Locale.GetText("Invalid objects."));
				}
				byte[] bytes = obj.GetBytes();
				byte[] bytes2 = aSN.GetBytes();
				for (int i = 0; i < bytes.Length && i != bytes2.Length; i++)
				{
					if (bytes[i] != bytes2[i])
					{
						if (bytes[i] >= bytes2[i])
						{
							return 1;
						}
						return -1;
					}
				}
				if (bytes.Length > bytes2.Length)
				{
					return 1;
				}
				if (bytes.Length < bytes2.Length)
				{
					return -1;
				}
				return 0;
			}
		}

		private PKCS7()
		{
		}

		public static ASN1 Attribute(string oid, ASN1 value)
		{
			ASN1 aSN = new ASN1(48);
			aSN.Add(ASN1Convert.FromOid(oid));
			aSN.Add(new ASN1(49)).Add(value);
			return aSN;
		}

		public static ASN1 AlgorithmIdentifier(string oid)
		{
			ASN1 aSN = new ASN1(48);
			aSN.Add(ASN1Convert.FromOid(oid));
			aSN.Add(new ASN1(5));
			return aSN;
		}

		public static ASN1 AlgorithmIdentifier(string oid, ASN1 parameters)
		{
			ASN1 aSN = new ASN1(48);
			aSN.Add(ASN1Convert.FromOid(oid));
			aSN.Add(parameters);
			return aSN;
		}

		public static ASN1 IssuerAndSerialNumber(Mono.Security.X509.X509Certificate x509)
		{
			ASN1 asn = null;
			ASN1 asn2 = null;
			ASN1 aSN = new ASN1(x509.RawData);
			int num = 0;
			bool flag = false;
			while (num < aSN[0].Count)
			{
				ASN1 aSN2 = aSN[0][num++];
				if (aSN2.Tag == 2)
				{
					asn2 = aSN2;
				}
				else if (aSN2.Tag == 48)
				{
					if (flag)
					{
						asn = aSN2;
						break;
					}
					flag = true;
				}
			}
			ASN1 aSN3 = new ASN1(48);
			aSN3.Add(asn);
			aSN3.Add(asn2);
			return aSN3;
		}
	}
	public sealed class StrongName
	{
		internal class StrongNameSignature
		{
			private byte[] hash;

			private byte[] signature;

			private uint signaturePosition;

			private uint signatureLength;

			private uint metadataPosition;

			private uint metadataLength;

			private byte cliFlag;

			private uint cliFlagPosition;

			public byte[] Hash
			{
				get
				{
					return hash;
				}
				set
				{
					hash = value;
				}
			}

			public byte[] Signature
			{
				get
				{
					return signature;
				}
				set
				{
					signature = value;
				}
			}

			public uint MetadataPosition
			{
				get
				{
					return metadataPosition;
				}
				set
				{
					metadataPosition = value;
				}
			}

			public uint MetadataLength
			{
				get
				{
					return metadataLength;
				}
				set
				{
					metadataLength = value;
				}
			}

			public uint SignaturePosition
			{
				get
				{
					return signaturePosition;
				}
				set
				{
					signaturePosition = value;
				}
			}

			public uint SignatureLength
			{
				get
				{
					return signatureLength;
				}
				set
				{
					signatureLength = value;
				}
			}

			public byte CliFlag
			{
				get
				{
					return cliFlag;
				}
				set
				{
					cliFlag = value;
				}
			}

			public uint CliFlagPosition
			{
				get
				{
					return cliFlagPosition;
				}
				set
				{
					cliFlagPosition = value;
				}
			}
		}

		internal enum StrongNameOptions
		{
			Metadata,
			Signature
		}

		private RSA rsa;

		private byte[] publicKey;

		private byte[] keyToken;

		private string tokenAlgorithm;

		public bool CanSign
		{
			get
			{
				if (rsa == null)
				{
					return false;
				}
				if (RSA is RSAManaged)
				{
					return !(rsa as RSAManaged).PublicOnly;
				}
				try
				{
					RSAParameters rSAParameters = rsa.ExportParameters(includePrivateParameters: true);
					return rSAParameters.D != null && rSAParameters.P != null && rSAParameters.Q != null;
				}
				catch (CryptographicException)
				{
					return false;
				}
			}
		}

		public RSA RSA
		{
			get
			{
				if (rsa == null)
				{
					rsa = RSA.Create();
				}
				return rsa;
			}
			set
			{
				rsa = value;
				InvalidateCache();
			}
		}

		public byte[] PublicKey
		{
			get
			{
				if (publicKey == null)
				{
					byte[] array = CryptoConvert.ToCapiKeyBlob(rsa, includePrivateKey: false);
					publicKey = new byte[32 + (rsa.KeySize >> 3)];
					publicKey[0] = array[4];
					publicKey[1] = array[5];
					publicKey[2] = array[6];
					publicKey[3] = array[7];
					publicKey[4] = 4;
					publicKey[5] = 128;
					publicKey[6] = 0;
					publicKey[7] = 0;
					byte[] bytes = BitConverterLE.GetBytes(publicKey.Length - 12);
					publicKey[8] = bytes[0];
					publicKey[9] = bytes[1];
					publicKey[10] = bytes[2];
					publicKey[11] = bytes[3];
					publicKey[12] = 6;
					Buffer.BlockCopy(array, 1, publicKey, 13, publicKey.Length - 13);
					publicKey[23] = 49;
				}
				return (byte[])publicKey.Clone();
			}
		}

		public byte[] PublicKeyToken
		{
			get
			{
				if (keyToken == null)
				{
					byte[] array = PublicKey;
					if (array == null)
					{
						return null;
					}
					byte[] array2 = GetHashAlgorithm(TokenAlgorithm).ComputeHash(array);
					keyToken = new byte[8];
					Buffer.BlockCopy(array2, array2.Length - 8, keyToken, 0, 8);
					Array.Reverse(keyToken, 0, 8);
				}
				return (byte[])keyToken.Clone();
			}
		}

		public string TokenAlgorithm
		{
			get
			{
				if (tokenAlgorithm == null)
				{
					tokenAlgorithm = "SHA1";
				}
				return tokenAlgorithm;
			}
			set
			{
				string text = value.ToUpper(CultureInfo.InvariantCulture);
				if (text == "SHA1" || text == "MD5")
				{
					tokenAlgorithm = value;
					InvalidateCache();
					return;
				}
				throw new ArgumentException("Unsupported hash algorithm for token");
			}
		}

		public StrongName()
		{
		}

		public StrongName(int keySize)
		{
			rsa = new RSAManaged(keySize);
		}

		public StrongName(byte[] data)
		{
			if (data == null)
			{
				throw new ArgumentNullException("data");
			}
			if (data.Length == 16)
			{
				int num = 0;
				int num2 = 0;
				while (num < data.Length)
				{
					num2 += data[num++];
				}
				if (num2 == 4)
				{
					publicKey = (byte[])data.Clone();
				}
			}
			else
			{
				RSA = CryptoConvert.FromCapiKeyBlob(data);
				if (rsa == null)
				{
					throw new ArgumentException("data isn't a correctly encoded RSA public key");
				}
			}
		}

		public StrongName(RSA rsa)
		{
			if (rsa == null)
			{
				throw new ArgumentNullException("rsa");
			}
			RSA = rsa;
		}

		private void InvalidateCache()
		{
			publicKey = null;
			keyToken = null;
		}

		private static HashAlgorithm GetHashAlgorithm(string algorithm)
		{
			return HashAlgorithm.Create(algorithm);
		}

		public byte[] GetBytes()
		{
			return CryptoConvert.ToCapiPrivateKeyBlob(RSA);
		}

		private uint RVAtoPosition(uint r, int sections, byte[] headers)
		{
			for (int i = 0; i < sections; i++)
			{
				uint num = BitConverterLE.ToUInt32(headers, i * 40 + 20);
				uint num2 = BitConverterLE.ToUInt32(headers, i * 40 + 12);
				int num3 = (int)BitConverterLE.ToUInt32(headers, i * 40 + 8);
				if (num2 <= r && r < num2 + num3)
				{
					return num + r - num2;
				}
			}
			return 0u;
		}

		private static StrongNameSignature Error(string a)
		{
			return null;
		}

		private static byte[] ReadMore(Stream stream, byte[] a, int newSize)
		{
			int num = a.Length;
			Array.Resize(ref a, newSize);
			if (newSize <= num)
			{
				return a;
			}
			int num2 = newSize - num;
			if (stream.Read(a, num, num2) != num2)
			{
				return null;
			}
			return a;
		}

		internal StrongNameSignature StrongHash(Stream stream, StrongNameOptions options)
		{
			byte[] array = new byte[64];
			int num = 0;
			int num2 = stream.Read(array, 0, 64);
			if (num2 == 64 && array[0] == 77 && array[1] == 90)
			{
				num = BitConverterLE.ToInt32(array, 60);
				if (num < 64)
				{
					return Error("peHeader_lt_64");
				}
				array = ReadMore(stream, array, num);
				if (array == null)
				{
					return Error("read_mz2_failed");
				}
			}
			else
			{
				if (num2 < 4 || array[0] != 80 || array[1] != 69 || array[2] != 0 || array[3] != 0)
				{
					return Error("read_mz_or_mzsig_failed");
				}
				stream.Position = 0L;
				array = new byte[0];
			}
			int num3 = 2;
			int num4 = 24 + num3;
			byte[] array2 = new byte[num4];
			if (stream.Read(array2, 0, num4) != num4 || array2[0] != 80 || array2[1] != 69 || array2[2] != 0 || array2[3] != 0)
			{
				return Error("read_minimumHeadersSize_or_pesig_failed");
			}
			num3 = BitConverterLE.ToUInt16(array2, 20);
			if (num3 < 2)
			{
				return Error($"sizeOfOptionalHeader_lt_2 ${num3}");
			}
			int num5 = 24 + num3;
			if (num5 < 24)
			{
				return Error("headers_overflow");
			}
			array2 = ReadMore(stream, array2, num5);
			if (array2 == null)
			{
				return Error("read_pe2_failed");
			}
			uint num6 = BitConverterLE.ToUInt16(array2, 24);
			int num7 = 0;
			bool flag = false;
			switch (num6)
			{
			case 523u:
				num7 = 16;
				break;
			case 263u:
				flag = true;
				break;
			default:
				return Error("bad_magic_value");
			case 267u:
				break;
			}
			uint num8 = 0u;
			if (!flag)
			{
				if (num3 >= 116 + num7 + 4)
				{
					num8 = BitConverterLE.ToUInt32(array2, 116 + num7);
				}
				for (int i = 64; i < num3 && i < 68; i++)
				{
					array2[24 + i] = 0;
				}
				for (int j = 128 + num7; j < num3 && j < 136 + num7; j++)
				{
					array2[24 + j] = 0;
				}
			}
			int num9 = BitConverterLE.ToUInt16(array2, 6);
			byte[] array3 = new byte[num9 * 40];
			if (stream.Read(array3, 0, array3.Length) != array3.Length)
			{
				return Error("read_section_headers_failed");
			}
			uint num10 = 0u;
			uint num11 = 0u;
			uint num12 = 0u;
			uint num13 = 0u;
			if (15 < num8 && num3 >= 216 + num7)
			{
				uint r = BitConverterLE.ToUInt32(array2, 232 + num7);
				uint num14 = RVAtoPosition(r, num9, array3);
				int num15 = BitConverterLE.ToInt32(array2, 236 + num7);
				byte[] array4 = new byte[num15];
				stream.Position = num14;
				if (stream.Read(array4, 0, num15) != num15)
				{
					return Error("read_cli_header_failed");
				}
				uint r2 = BitConverterLE.ToUInt32(array4, 32);
				num10 = RVAtoPosition(r2, num9, array3);
				num11 = BitConverterLE.ToUInt32(array4, 36);
				uint r3 = BitConverterLE.ToUInt32(array4, 8);
				num12 = RVAtoPosition(r3, num9, array3);
				num13 = BitConverterLE.ToUInt32(array4, 12);
			}
			StrongNameSignature strongNameSignature = new StrongNameSignature();
			strongNameSignature.SignaturePosition = num10;
			strongNameSignature.SignatureLength = num11;
			strongNameSignature.MetadataPosition = num12;
			strongNameSignature.MetadataLength = num13;
			using HashAlgorithm hashAlgorithm = HashAlgorithm.Create(TokenAlgorithm);
			if (options == StrongNameOptions.Metadata)
			{
				hashAlgorithm.Initialize();
				byte[] buffer = new byte[num13];
				stream.Position = num12;
				if (stream.Read(buffer, 0, (int)num13) != (int)num13)
				{
					return Error("read_cli_metadata_failed");
				}
				strongNameSignature.Hash = hashAlgorithm.ComputeHash(buffer);
				return strongNameSignature;
			}
			using (CryptoStream cryptoStream = new CryptoStream(Stream.Null, hashAlgorithm, CryptoStreamMode.Write))
			{
				cryptoStream.Write(array, 0, array.Length);
				cryptoStream.Write(array2, 0, array2.Length);
				cryptoStream.Write(array3, 0, array3.Length);
				for (int k = 0; k < num9; k++)
				{
					uint num16 = BitConverterLE.ToUInt32(array3, k * 40 + 20);
					int num17 = BitConverterLE.ToInt32(array3, k * 40 + 16);
					byte[] array5 = new byte[num17];
					stream.Position = num16;
					if (stream.Read(array5, 0, num17) != num17)
					{
						return Error("read_section_failed");
					}
					if (num16 <= num10 && num10 < (uint)((int)num16 + num17))
					{
						int num18 = (int)(num10 - num16);
						if (num18 > 0)
						{
							cryptoStream.Write(array5, 0, num18);
						}
						strongNameSignature.Signature = new byte[num11];
						Buffer.BlockCopy(array5, num18, strongNameSignature.Signature, 0, (int)num11);
						Array.Reverse(strongNameSignature.Signature);
						int num19 = (int)(num18 + num11);
						int num20 = num17 - num19;
						if (num20 > 0)
						{
							cryptoStream.Write(array5, num19, num20);
						}
					}
					else
					{
						cryptoStream.Write(array5, 0, num17);
					}
				}
			}
			strongNameSignature.Hash = hashAlgorithm.Hash;
			return strongNameSignature;
		}

		public byte[] Hash(string fileName)
		{
			using FileStream stream = File.OpenRead(fileName);
			return StrongHash(stream, StrongNameOptions.Metadata).Hash;
		}

		public bool Sign(string fileName)
		{
			StrongNameSignature strongNameSignature;
			using (FileStream stream = File.OpenRead(fileName))
			{
				strongNameSignature = StrongHash(stream, StrongNameOptions.Signature);
			}
			if (strongNameSignature.Hash == null)
			{
				return false;
			}
			byte[] array = null;
			try
			{
				RSAPKCS1SignatureFormatter rSAPKCS1SignatureFormatter = new RSAPKCS1SignatureFormatter(rsa);
				rSAPKCS1SignatureFormatter.SetHashAlgorithm(TokenAlgorithm);
				array = rSAPKCS1SignatureFormatter.CreateSignature(strongNameSignature.Hash);
				Array.Reverse(array);
			}
			catch (CryptographicException)
			{
				return false;
			}
			using (FileStream fileStream = File.OpenWrite(fileName))
			{
				fileStream.Position = strongNameSignature.SignaturePosition;
				fileStream.Write(array, 0, array.Length);
			}
			return true;
		}

		public bool Verify(string fileName)
		{
			using FileStream stream = File.OpenRead(fileName);
			return Verify(stream);
		}

		public bool Verify(Stream stream)
		{
			StrongNameSignature strongNameSignature = StrongHash(stream, StrongNameOptions.Signature);
			if (strongNameSignature.Hash == null)
			{
				return false;
			}
			try
			{
				AssemblyHashAlgorithm algorithm = AssemblyHashAlgorithm.SHA1;
				if (tokenAlgorithm == "MD5")
				{
					algorithm = AssemblyHashAlgorithm.MD5;
				}
				return Verify(rsa, algorithm, strongNameSignature.Hash, strongNameSignature.Signature);
			}
			catch (CryptographicException)
			{
				return false;
			}
		}

		private static bool Verify(RSA rsa, AssemblyHashAlgorithm algorithm, byte[] hash, byte[] signature)
		{
			RSAPKCS1SignatureDeformatter rSAPKCS1SignatureDeformatter = new RSAPKCS1SignatureDeformatter(rsa);
			switch (algorithm)
			{
			case AssemblyHashAlgorithm.MD5:
				rSAPKCS1SignatureDeformatter.SetHashAlgorithm("MD5");
				break;
			default:
				rSAPKCS1SignatureDeformatter.SetHashAlgorithm("SHA1");
				break;
			}
			return rSAPKCS1SignatureDeformatter.VerifySignature(hash, signature);
		}
	}
}
namespace Mono.Security.X509
{
	public class PKCS5
	{
		public const string pbeWithMD2AndDESCBC = "1.2.840.113549.1.5.1";

		public const string pbeWithMD5AndDESCBC = "1.2.840.113549.1.5.3";

		public const string pbeWithMD2AndRC2CBC = "1.2.840.113549.1.5.4";

		public const string pbeWithMD5AndRC2CBC = "1.2.840.113549.1.5.6";

		public const string pbeWithSHA1AndDESCBC = "1.2.840.113549.1.5.10";

		public const string pbeWithSHA1AndRC2CBC = "1.2.840.113549.1.5.11";
	}
	public class PKCS9
	{
		public const string friendlyName = "1.2.840.113549.1.9.20";

		public const string localKeyId = "1.2.840.113549.1.9.21";
	}
	internal class SafeBag
	{
		private string _bagOID;

		private ASN1 _asn1;

		public string BagOID => _bagOID;

		public ASN1 ASN1 => _asn1;

		public SafeBag(string bagOID, ASN1 asn1)
		{
			_bagOID = bagOID;
			_asn1 = asn1;
		}
	}
	public class PKCS12 : ICloneable
	{
		public class DeriveBytes
		{
			public enum Purpose
			{
				Key,
				IV,
				MAC
			}

			private static byte[] keyDiversifier = new byte[64]
			{
				1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
				1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
				1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
				1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
				1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
				1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
				1, 1, 1, 1
			};

			private static byte[] ivDiversifier = new byte[64]
			{
				2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
				2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
				2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
				2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
				2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
				2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
				2, 2, 2, 2
			};

			private static byte[] macDiversifier = new byte[64]
			{
				3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
				3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
				3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
				3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
				3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
				3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
				3, 3, 3, 3
			};

			private string _hashName;

			private int _iterations;

			private byte[] _password;

			private byte[] _salt;

			public string HashName
			{
				get
				{
					return _hashName;
				}
				set
				{
					_hashName = value;
				}
			}

			public int IterationCount
			{
				get
				{
					return _iterations;
				}
				set
				{
					_iterations = value;
				}
			}

			public byte[] Password
			{
				get
				{
					return (byte[])_password.Clone();
				}
				set
				{
					if (value == null)
					{
						_password = new byte[0];
					}
					else
					{
						_password = (byte[])value.Clone();
					}
				}
			}

			public byte[] Salt
			{
				get
				{
					return (byte[])_salt.Clone();
				}
				set
				{
					if (value != null)
					{
						_salt = (byte[])value.Clone();
					}
					else
					{
						_salt = null;
					}
				}
			}

			private void Adjust(byte[] a, int aOff, byte[] b)
			{
				int num = (b[^1] & 0xFF) + (a[aOff + b.Length - 1] & 0xFF) + 1;
				a[aOff + b.Length - 1] = (byte)num;
				num >>= 8;
				for (int num2 = b.Length - 2; num2 >= 0; num2--)
				{
					num += (b[num2] & 0xFF) + (a[aOff + num2] & 0xFF);
					a[aOff + num2] = (byte)num;
					num >>= 8;
				}
			}

			private byte[] Derive(byte[] diversifier, int n)
			{
				HashAlgorithm hashAlgorithm = PKCS1.CreateFromName(_hashName);
				int num = hashAlgorithm.HashSize >> 3;
				int num2 = 64;
				byte[] array = new byte[n];
				byte[] array2;
				if (_salt != null && _salt.Length != 0)
				{
					array2 = new byte[num2 * ((_salt.Length + num2 - 1) / num2)];
					for (int i = 0; i != array2.Length; i++)
					{
						array2[i] = _salt[i % _salt.Length];
					}
				}
				else
				{
					array2 = new byte[0];
				}
				byte[] array3;
				if (_password != null && _password.Length != 0)
				{
					array3 = new byte[num2 * ((_password.Length + num2 - 1) / num2)];
					for (int j = 0; j != array3.Length; j++)
					{
						array3[j] = _password[j % _password.Length];
					}
				}
				else
				{
					array3 = new byte[0];
				}
				byte[] array4 = new byte[array2.Length + array3.Length];
				Buffer.BlockCopy(array2, 0, array4, 0, array2.Length);
				Buffer.BlockCopy(array3, 0, array4, array2.Length, array3.Length);
				byte[] array5 = new byte[num2];
				int num3 = (n + num - 1) / num;
				for (int k = 1; k <= num3; k++)
				{
					hashAlgorithm.TransformBlock(diversifier, 0, diversifier.Length, diversifier, 0);
					hashAlgorithm.TransformFinalBlock(array4, 0, array4.Length);
					byte[] array6 = hashAlgorithm.Hash;
					hashAlgorithm.Initialize();
					for (int l = 1; l != _iterations; l++)
					{
						array6 = hashAlgorithm.ComputeHash(array6, 0, array6.Length);
					}
					for (int m = 0; m != array5.Length; m++)
					{
						array5[m] = array6[m % array6.Length];
					}
					for (int num4 = 0; num4 != array4.Length / num2; num4++)
					{
						Adjust(array4, num4 * num2, array5);
					}
					if (k == num3)
					{
						Buffer.BlockCopy(array6, 0, array, (k - 1) * num, array.Length - (k - 1) * num);
					}
					else
					{
						Buffer.BlockCopy(array6, 0, array, (k - 1) * num, array6.Length);
					}
				}
				return array;
			}

			public byte[] DeriveKey(int size)
			{
				return Derive(keyDiversifier, size);
			}

			public byte[] DeriveIV(int size)
			{
				return Derive(ivDiversifier, size);
			}

			public byte[] DeriveMAC(int size)
			{
				return Derive(macDiversifier, size);
			}
		}

		public const string pbeWithSHAAnd128BitRC4 = "1.2.840.113549.1.12.1.1";

		public const string pbeWithSHAAnd40BitRC4 = "1.2.840.113549.1.12.1.2";

		public const string pbeWithSHAAnd3KeyTripleDESCBC = "1.2.840.113549.1.12.1.3";

		public const string pbeWithSHAAnd2KeyTripleDESCBC = "1.2.840.113549.1.12.1.4";

		public const string pbeWithSHAAnd128BitRC2CBC = "1.2.840.113549.1.12.1.5";

		public const string pbeWithSHAAnd40BitRC2CBC = "1.2.840.113549.1.12.1.6";

		public const string keyBag = "1.2.840.113549.1.12.10.1.1";

		public const string pkcs8ShroudedKeyBag = "1.2.840.113549.1.12.10.1.2";

		public const string certBag = "1.2.840.113549.1.12.10.1.3";

		public const string crlBag = "1.2.840.113549.1.12.10.1.4";

		public const string secretBag = "1.2.840.113549.1.12.10.1.5";

		public const string safeContentsBag = "1.2.840.113549.1.12.10.1.6";

		public const string x509Certificate = "1.2.840.113549.1.9.22.1";

		public const string sdsiCertificate = "1.2.840.113549.1.9.22.2";

		public const string x509Crl = "1.2.840.113549.1.9.23.1";

		private const int recommendedIterationCount = 2000;

		private byte[] _password;

		private ArrayList _keyBags;

		private ArrayList _secretBags;

		private X509CertificateCollection _certs;

		private bool _keyBagsChanged;

		private bool _secretBagsChanged;

		private bool _certsChanged;

		private int _iterations;

		private ArrayList _safeBags;

		private RandomNumberGenerator _rng;

		public const int CryptoApiPasswordLimit = 32;

		private static int password_max_length = int.MaxValue;

		public string Password
		{
			set
			{
				if (_password != null)
				{
					Array.Clear(_password, 0, _password.Length);
				}
				_password = null;
				if (value == null)
				{
					return;
				}
				if (value.Length > 0)
				{
					int num = value.Length;
					int num2 = 0;
					if (num < MaximumPasswordLength)
					{
						if (value[num - 1] != 0)
						{
							num2 = 1;
						}
					}
					else
					{
						num = MaximumPasswordLength;
					}
					_password = new byte[num + num2 << 1];
					Encoding.BigEndianUnicode.GetBytes(value, 0, num, _password, 0);
				}
				else
				{
					_password = new byte[2];
				}
			}
		}

		public int IterationCount
		{
			get
			{
				return _iterations;
			}
			set
			{
				_iterations = value;
			}
		}

		public ArrayList Keys
		{
			get
			{
				if (_keyBagsChanged)
				{
					_keyBags.Clear();
					foreach (SafeBag safeBag in _safeBags)
					{
						if (safeBag.BagOID.Equals("1.2.840.113549.1.12.10.1.1"))
						{
							byte[] privateKey = new PKCS8.PrivateKeyInfo(safeBag.ASN1[1].Value).PrivateKey;
							switch (privateKey[0])
							{
							case 2:
								_keyBags.Add(PKCS8.PrivateKeyInfo.DecodeDSA(privateKey, default(DSAParameters)));
								break;
							case 48:
								_keyBags.Add(PKCS8.PrivateKeyInfo.DecodeRSA(privateKey));
								break;
							}
							Array.Clear(privateKey, 0, privateKey.Length);
						}
						else if (safeBag.BagOID.Equals("1.2.840.113549.1.12.10.1.2"))
						{
							PKCS8.EncryptedPrivateKeyInfo encryptedPrivateKeyInfo = new PKCS8.EncryptedPrivateKeyInfo(safeBag.ASN1[1].Value);
							byte[] array = Decrypt(encryptedPrivateKeyInfo.Algorithm, encryptedPrivateKeyInfo.Salt, encryptedPrivateKeyInfo.IterationCount, encryptedPrivateKeyInfo.EncryptedData);
							byte[] privateKey2 = new PKCS8.PrivateKeyInfo(array).PrivateKey;
							switch (privateKey2[0])
							{
							case 2:
								_keyBags.Add(PKCS8.PrivateKeyInfo.DecodeDSA(privateKey2, default(DSAParameters)));
								break;
							case 48:
								_keyBags.Add(PKCS8.PrivateKeyInfo.DecodeRSA(privateKey2));
								break;
							}
							Array.Clear(privateKey2, 0, privateKey2.Length);
							Array.Clear(array, 0, array.Length);
						}
					}
					_keyBagsChanged = false;
				}
				return ArrayList.ReadOnly(_keyBags);
			}
		}

		public ArrayList Secrets
		{
			get
			{
				if (_secretBagsChanged)
				{
					_secretBags.Clear();
					foreach (SafeBag safeBag in _safeBags)
					{
						if (safeBag.BagOID.Equals("1.2.840.113549.1.12.10.1.5"))
						{
							byte[] value = safeBag.ASN1[1].Value;
							_secretBags.Add(value);
						}
					}
					_secretBagsChanged = false;
				}
				return ArrayList.ReadOnly(_secretBags);
			}
		}

		public X509CertificateCollection Certificates
		{
			get
			{
				if (_certsChanged)
				{
					_certs.Clear();
					foreach (SafeBag safeBag in _safeBags)
					{
						if (safeBag.BagOID.Equals("1.2.840.113549.1.12.10.1.3"))
						{
							PKCS7.ContentInfo contentInfo = new PKCS7.ContentInfo(safeBag.ASN1[1].Value);
							_certs.Add(new X509Certificate(contentInfo.Content[0].Value));
						}
					}
					_certsChanged = false;
				}
				return _certs;
			}
		}

		internal RandomNumberGenerator RNG
		{
			get
			{
				if (_rng == null)
				{
					_rng = RandomNumberGenerator.Create();
				}
				return _rng;
			}
		}

		public static int MaximumPasswordLength
		{
			get
			{
				return password_max_length;
			}
			set
			{
				if (value < 32)
				{
					throw new ArgumentOutOfRangeException(Locale.GetText("Maximum password length cannot be less than {0}.", 32));
				}
				password_max_length = value;
			}
		}

		public PKCS12()
		{
			_iterations = 2000;
			_keyBags = new ArrayList();
			_secretBags = new ArrayList();
			_certs = new X509CertificateCollection();
			_keyBagsChanged = false;
			_secretBagsChanged = false;
			_certsChanged = false;
			_safeBags = new ArrayList();
		}

		public PKCS12(byte[] data)
			: this()
		{
			Password = null;
			Decode(data);
		}

		public PKCS12(byte[] data, string password)
			: this()
		{
			Password = password;
			Decode(data);
		}

		public PKCS12(byte[] data, byte[] password)
			: this()
		{
			_password = password;
			Decode(data);
		}

		private void Decode(byte[] data)
		{
			ASN1 aSN = new ASN1(data);
			if (aSN.Tag != 48)
			{
				throw new ArgumentException("invalid data");
			}
			if (aSN[0].Tag != 2)
			{
				throw new ArgumentException("invalid PFX version");
			}
			PKCS7.ContentInfo contentInfo = new PKCS7.ContentInfo(aSN[1]);
			if (contentInfo.ContentType != "1.2.840.113549.1.7.1")
			{
				throw new ArgumentException("invalid authenticated safe");
			}
			if (aSN.Count > 2)
			{
				ASN1 aSN2 = aSN[2];
				if (aSN2.Tag != 48)
				{
					throw new ArgumentException("invalid MAC");
				}
				ASN1 aSN3 = aSN2[0];
				if (aSN3.Tag != 48)
				{
					throw new ArgumentException("invalid MAC");
				}
				if (ASN1Convert.ToOid(aSN3[0][0]) != "1.3.14.3.2.26")
				{
					throw new ArgumentException("unsupported HMAC");
				}
				byte[] value = aSN3[1].Value;
				ASN1 aSN4 = aSN2[1];
				if (aSN4.Tag != 4)
				{
					throw new ArgumentException("missing MAC salt");
				}
				_iterations = 1;
				if (aSN2.Count > 2)
				{
					ASN1 aSN5 = aSN2[2];
					if (aSN5.Tag != 2)
					{
						throw new ArgumentException("invalid MAC iteration");
					}
					_iterations = ASN1Convert.ToInt32(aSN5);
				}
				byte[] value2 = contentInfo.Content[0].Value;
				byte[] actual = MAC(_password, aSN4.Value, _iterations, value2);
				if (!Compare(value, actual))
				{
					byte[] password = new byte[2];
					actual = MAC(password, aSN4.Value, _iterations, value2);
					if (!Compare(value, actual))
					{
						throw new CryptographicException("Invalid MAC - file may have been tampered with!");
					}
					_password = password;
				}
			}
			ASN1 aSN6 = new ASN1(contentInfo.Content[0].Value);
			for (int i = 0; i < aSN6.Count; i++)
			{
				PKCS7.ContentInfo contentInfo2 = new PKCS7.ContentInfo(aSN6[i]);
				switch (contentInfo2.ContentType)
				{
				case "1.2.840.113549.1.7.1":
				{
					ASN1 aSN8 = new ASN1(contentInfo2.Content[0].Value);
					for (int k = 0; k < aSN8.Count; k++)
					{
						ASN1 safeBag2 = aSN8[k];
						ReadSafeBag(safeBag2);
					}
					break;
				}
				case "1.2.840.113549.1.7.6":
				{
					PKCS7.EncryptedData ed = new PKCS7.EncryptedData(contentInfo2.Content[0]);
					ASN1 aSN7 = new ASN1(Decrypt(ed));
					for (int j = 0; j < aSN7.Count; j++)
					{
						ASN1 safeBag = aSN7[j];
						ReadSafeBag(safeBag);
					}
					break;
				}
				case "1.2.840.113549.1.7.3":
					throw new NotImplementedException("public key encrypted");
				default:
					throw new ArgumentException("unknown authenticatedSafe");
				}
			}
		}

		~PKCS12()
		{
			if (_password != null)
			{
				Array.Clear(_password, 0, _password.Length);
			}
			_password = null;
		}

		private bool Compare(byte[] expected, byte[] actual)
		{
			bool result = false;
			if (expected.Length == actual.Length)
			{
				for (int i = 0; i < expected.Length; i++)
				{
					if (expected[i] != actual[i])
					{
						return false;
					}
				}
				result = true;
			}
			return result;
		}

		private SymmetricAlgorithm GetSymmetricAlgorithm(string algorithmOid, byte[] salt, int iterationCount)
		{
			string text = null;
			int size = 8;
			int num = 8;
			DeriveBytes deriveBytes = new DeriveBytes();
			deriveBytes.Password = _password;
			deriveBytes.Salt = salt;
			deriveBytes.IterationCount = iterationCount;
			switch (algorithmOid)
			{
			case "1.2.840.113549.1.5.1":
				deriveBytes.HashName = "MD2";
				text = "DES";
				break;
			case "1.2.840.113549.1.5.3":
				deriveBytes.HashName = "MD5";
				text = "DES";
				break;
			case "1.2.840.113549.1.5.4":
				deriveBytes.HashName = "MD2";
				text = "RC2";
				size = 4;
				break;
			case "1.2.840.113549.1.5.6":
				deriveBytes.HashName = "MD5";
				text = "RC2";
				size = 4;
				break;
			case "1.2.840.113549.1.5.10":
				deriveBytes.HashName = "SHA1";
				text = "DES";
				break;
			case "1.2.840.113549.1.5.11":
				deriveBytes.HashName = "SHA1";
				text = "RC2";
				size = 4;
				break;
			case "1.2.840.113549.1.12.1.1":
				deriveBytes.HashName = "SHA1";
				text = "RC4";
				size = 16;
				num = 0;
				break;
			case "1.2.840.113549.1.12.1.2":
				deriveBytes.HashName = "SHA1";
				text = "RC4";
				size = 5;
				num = 0;
				break;
			case "1.2.840.113549.1.12.1.3":
				deriveBytes.HashName = "SHA1";
				text = "TripleDES";
				size = 24;
				break;
			case "1.2.840.113549.1.12.1.4":
				deriveBytes.HashName = "SHA1";
				text = "TripleDES";
				size = 16;
				break;
			case "1.2.840.113549.1.12.1.5":
				deriveBytes.HashName = "SHA1";
				text = "RC2";
				size = 16;
				break;
			case "1.2.840.113549.1.12.1.6":
				deriveBytes.HashName = "SHA1";
				text = "RC2";
				size = 5;
				break;
			default:
				throw new NotSupportedException("unknown oid " + text);
			}
			SymmetricAlgorithm symmetricAlgorithm = null;
			symmetricAlgorithm = SymmetricAlgorithm.Create(text);
			symmetricAlgorithm.Key = deriveBytes.DeriveKey(size);
			if (num > 0)
			{
				symmetricAlgorithm.IV = deriveBytes.DeriveIV(num);
				symmetricAlgorithm.Mode = CipherMode.CBC;
			}
			return symmetricAlgorithm;
		}

		public byte[] Decrypt(string algorithmOid, byte[] salt, int iterationCount, byte[] encryptedData)
		{
			SymmetricAlgorithm symmetricAlgorithm = null;
			byte[] array = null;
			try
			{
				symmetricAlgorithm = GetSymmetricAlgorithm(algorithmOid, salt, iterationCount);
				return symmetricAlgorithm.CreateDecryptor().TransformFinalBlock(encryptedData, 0, encryptedData.Length);
			}
			finally
			{
				symmetricAlgorithm?.Clear();
			}
		}

		public byte[] Decrypt(PKCS7.EncryptedData ed)
		{
			return Decrypt(ed.EncryptionAlgorithm.ContentType, ed.EncryptionAlgorithm.Content[0].Value, ASN1Convert.ToInt32(ed.EncryptionAlgorithm.Content[1]), ed.EncryptedContent);
		}

		public byte[] Encrypt(string algorithmOid, byte[] salt, int iterationCount, byte[] data)
		{
			byte[] array = null;
			using SymmetricAlgorithm symmetricAlgorithm = GetSymmetricAlgorithm(algorithmOid, salt, iterationCount);
			return symmetricAlgorithm.CreateEncryptor().TransformFinalBlock(data, 0, data.Length);
		}

		private DSAParameters GetExistingParameters(out bool found)
		{
			foreach (X509Certificate certificate in Certificates)
			{
				if (certificate.KeyAlgorithmParameters != null)
				{
					DSA dSA = certificate.DSA;
					if (dSA != null)
					{
						found = true;
						return dSA.ExportParameters(includePrivateParameters: false);
					}
				}
			}
			found = false;
			return default(DSAParameters);
		}

		private void AddPrivateKey(PKCS8.PrivateKeyInfo pki)
		{
			byte[] privateKey = pki.PrivateKey;
			try
			{
				switch (pki.Algorithm)
				{
				case "1.2.840.113549.1.1.1":
					_keyBags.Add(PKCS8.PrivateKeyInfo.DecodeRSA(privateKey));
					break;
				case "1.2.840.10040.4.1":
				{
					bool found;
					DSAParameters existingParameters = GetExistingParameters(out found);
					if (found)
					{
						_keyBags.Add(PKCS8.PrivateKeyInfo.DecodeDSA(privateKey, existingParameters));
					}
					break;
				}
				default:
					throw new CryptographicException("Unknown private key format");
				}
			}
			finally
			{
				Array.Clear(privateKey, 0, privateKey.Length);
			}
		}

		private void ReadSafeBag(ASN1 safeBag)
		{
			if (safeBag.Tag != 48)
			{
				throw new ArgumentException("invalid safeBag");
			}
			ASN1 aSN = safeBag[0];
			if (aSN.Tag != 6)
			{
				throw new ArgumentException("invalid safeBag id");
			}
			ASN1 aSN2 = safeBag[1];
			string text = ASN1Convert.ToOid(aSN);
			switch (text)
			{
			case "1.2.840.113549.1.12.10.1.1":
				AddPrivateKey(new PKCS8.PrivateKeyInfo(aSN2.Value));
				break;
			case "1.2.840.113549.1.12.10.1.2":
			{
				PKCS8.EncryptedPrivateKeyInfo encryptedPrivateKeyInfo = new PKCS8.EncryptedPrivateKeyInfo(aSN2.Value);
				byte[] array = Decrypt(encryptedPrivateKeyInfo.Algorithm, encryptedPrivateKeyInfo.Salt, encryptedPrivateKeyInfo.IterationCount, encryptedPrivateKeyInfo.EncryptedData);
				AddPrivateKey(new PKCS8.PrivateKeyInfo(array));
				Array.Clear(array, 0, array.Length);
				break;
			}
			case "1.2.840.113549.1.12.10.1.3":
			{
				PKCS7.ContentInfo contentInfo = new PKCS7.ContentInfo(aSN2.Value);
				if (contentInfo.ContentType != "1.2.840.113549.1.9.22.1")
				{
					throw new NotSupportedException("unsupport certificate type");
				}
				X509Certificate value2 = new X509Certificate(contentInfo.Content[0].Value);
				_certs.Add(value2);
				break;
			}
			case "1.2.840.113549.1.12.10.1.5":
			{
				byte[] value = aSN2.Value;
				_secretBags.Add(value);
				break;
			}
			default:
				throw new ArgumentException("unknown safeBag oid");
			case "1.2.840.113549.1.12.10.1.4":
			case "1.2.840.113549.1.12.10.1.6":
				break;
			}
			if (safeBag.Count > 2)
			{
				ASN1 aSN3 = safeBag[2];
				if (aSN3.Tag != 49)
				{
					throw new ArgumentException("invalid safeBag attributes id");
				}
				for (int i = 0; i < aSN3.Count; i++)
				{
					ASN1 aSN4 = aSN3[i];
					if (aSN4.Tag != 48)
					{
						throw new ArgumentException("invalid PKCS12 attributes id");
					}
					ASN1 aSN5 = aSN4[0];
					if (aSN5.Tag != 6)
					{
						throw new ArgumentException("invalid attribute id");
					}
					string text2 = ASN1Convert.ToOid(aSN5);
					ASN1 aSN6 = aSN4[1];
					for (int j = 0; j < aSN6.Count; j++)
					{
						ASN1 aSN7 = aSN6[j];
						if (!(text2 == "1.2.840.113549.1.9.20"))
						{
							if (text2 == "1.2.840.113549.1.9.21" && aSN7.Tag != 4)
							{
								throw new ArgumentException("invalid attribute value id");
							}
						}
						else if (aSN7.Tag != 30)
						{
							throw new ArgumentException("invalid attribute value id");
						}
					}
				}
			}
			_safeBags.Add(new SafeBag(text, safeBag));
		}

		private ASN1 Pkcs8ShroudedKeyBagSafeBag(AsymmetricAlgorithm aa, IDictionary attributes)
		{
			PKCS8.PrivateKeyInfo privateKeyInfo = new PKCS8.PrivateKeyInfo();
			if (aa is RSA)
			{
				privateKeyInfo.Algorithm = "1.2.840.113549.1.1.1";
				privateKeyInfo.PrivateKey = PKCS8.PrivateKeyInfo.Encode((RSA)aa);
			}
			else
			{
				if (!(aa is DSA))
				{
					throw new CryptographicException("Unknown asymmetric algorithm {0}", aa.ToString());
				}
				privateKeyInfo.Algorithm = null;
				privateKeyInfo.PrivateKey = PKCS8.PrivateKeyInfo.Encode((DSA)aa);
			}
			PKCS8.EncryptedPrivateKeyInfo encryptedPrivateKeyInfo = new PKCS8.EncryptedPrivateKeyInfo();
			encryptedPrivateKeyInfo.Algorithm = "1.2.840.113549.1.12.1.3";
			encryptedPrivateKeyInfo.IterationCount = _iterations;
			encryptedPrivateKeyInfo.EncryptedData = Encrypt("1.2.840.113549.1.12.1.3", encryptedPrivateKeyInfo.Salt, _iterations, privateKeyInfo.GetBytes());
			ASN1 aSN = new ASN1(48);
			aSN.Add(ASN1Convert.FromOid("1.2.840.113549.1.12.10.1.2"));
			ASN1 aSN2 = new ASN1(160);
			aSN2.Add(new ASN1(encryptedPrivateKeyInfo.GetBytes()));
			aSN.Add(aSN2);
			if (attributes != null)
			{
				ASN1 aSN3 = new ASN1(49);
				IDictionaryEnumerator enumerator = attributes.GetEnumerator();
				while (enumerator.MoveNext())
				{
					string text = (string)enumerator.Key;
					if (!(text == "1.2.840.113549.1.9.20"))
					{
						if (!(text == "1.2.840.113549.1.9.21"))
						{
							continue;
						}
						ArrayList arrayList = (ArrayList)enumerator.Value;
						if (arrayList.Count <= 0)
						{
							continue;
						}
						ASN1 aSN4 = new ASN1(48);
						aSN4.Add(ASN1Convert.FromOid("1.2.840.113549.1.9.21"));
						ASN1 aSN5 = new ASN1(49);
						foreach (byte[] item in arrayList)
						{
							ASN1 aSN6 = new ASN1(4);
							aSN6.Value = item;
							aSN5.Add(aSN6);
						}
						aSN4.Add(aSN5);
						aSN3.Add(aSN4);
						continue;
					}
					ArrayList arrayList2 = (ArrayList)enumerator.Value;
					if (arrayList2.Count <= 0)
					{
						continue;
					}
					ASN1 aSN7 = new ASN1(48);
					aSN7.Add(ASN1Convert.FromOid("1.2.840.113549.1.9.20"));
					ASN1 aSN8 = new ASN1(49);
					foreach (byte[] item2 in arrayList2)
					{
						ASN1 aSN9 = new ASN1(30);
						aSN9.Value = item2;
						aSN8.Add(aSN9);
					}
					aSN7.Add(aSN8);
					aSN3.Add(aSN7);
				}
				if (aSN3.Count > 0)
				{
					aSN.Add(aSN3);
				}
			}
			return aSN;
		}

		private ASN1 KeyBagSafeBag(AsymmetricAlgorithm aa, IDictionary attributes)
		{
			PKCS8.PrivateKeyInfo privateKeyInfo = new PKCS8.PrivateKeyInfo();
			if (aa is RSA)
			{
				privateKeyInfo.Algorithm = "1.2.840.113549.1.1.1";
				privateKeyInfo.PrivateKey = PKCS8.PrivateKeyInfo.Encode((RSA)aa);
			}
			else
			{
				if (!(aa is DSA))
				{
					throw new CryptographicException("Unknown asymmetric algorithm {0}", aa.ToString());
				}
				privateKeyInfo.Algorithm = null;
				privateKeyInfo.PrivateKey = PKCS8.PrivateKeyInfo.Encode((DSA)aa);
			}
			ASN1 aSN = new ASN1(48);
			aSN.Add(ASN1Convert.FromOid("1.2.840.113549.1.12.10.1.1"));
			ASN1 aSN2 = new ASN1(160);
			aSN2.Add(new ASN1(privateKeyInfo.GetBytes()));
			aSN.Add(aSN2);
			if (attributes != null)
			{
				ASN1 aSN3 = new ASN1(49);
				IDictionaryEnumerator enumerator = attributes.GetEnumerator();
				while (enumerator.MoveNext())
				{
					string text = (string)enumerator.Key;
					if (!(text == "1.2.840.113549.1.9.20"))
					{
						if (!(text == "1.2.840.113549.1.9.21"))
						{
							continue;
						}
						ArrayList arrayList = (ArrayList)enumerator.Value;
						if (arrayList.Count <= 0)
						{
							continue;
						}
						ASN1 aSN4 = new ASN1(48);
						aSN4.Add(ASN1Convert.FromOid("1.2.840.113549.1.9.21"));
						ASN1 aSN5 = new ASN1(49);
						foreach (byte[] item in arrayList)
						{
							ASN1 aSN6 = new ASN1(4);
							aSN6.Value = item;
							aSN5.Add(aSN6);
						}
						aSN4.Add(aSN5);
						aSN3.Add(aSN4);
						continue;
					}
					ArrayList arrayList2 = (ArrayList)enumerator.Value;
					if (arrayList2.Count <= 0)
					{
						continue;
					}
					ASN1 aSN7 = new ASN1(48);
					aSN7.Add(ASN1Convert.FromOid("1.2.840.113549.1.9.20"));
					ASN1 aSN8 = new ASN1(49);
					foreach (byte[] item2 in arrayList2)
					{
						ASN1 aSN9 = new ASN1(30);
						aSN9.Value = item2;
						aSN8.Add(aSN9);
					}
					aSN7.Add(aSN8);
					aSN3.Add(aSN7);
				}
				if (aSN3.Count > 0)
				{
					aSN.Add(aSN3);
				}
			}
			return aSN;
		}

		private ASN1 SecretBagSafeBag(byte[] secret, IDictionary attributes)
		{
			ASN1 aSN = new ASN1(48);
			aSN.Add(ASN1Convert.FromOid("1.2.840.113549.1.12.10.1.5"));
			ASN1 asn = new ASN1(128, secret);
			aSN.Add(asn);
			if (attributes != null)
			{
				ASN1 aSN2 = new ASN1(49);
				IDictionaryEnumerator enumerator = attributes.GetEnumerator();
				while (enumerator.MoveNext())
				{
					string text = (string)enumerator.Key;
					if (!(text == "1.2.840.113549.1.9.20"))
					{
						if (!(text == "1.2.840.113549.1.9.21"))
						{
							continue;
						}
						ArrayList arrayList = (ArrayList)enumerator.Value;
						if (arrayList.Count <= 0)
						{
							continue;
						}
						ASN1 aSN3 = new ASN1(48);
						aSN3.Add(ASN1Convert.FromOid("1.2.840.113549.1.9.21"));
						ASN1 aSN4 = new ASN1(49);
						foreach (byte[] item in arrayList)
						{
							ASN1 aSN5 = new ASN1(4);
							aSN5.Value = item;
							aSN4.Add(aSN5);
						}
						aSN3.Add(aSN4);
						aSN2.Add(aSN3);
						continue;
					}
					ArrayList arrayList2 = (ArrayList)enumerator.Value;
					if (arrayList2.Count <= 0)
					{
						continue;
					}
					ASN1 aSN6 = new ASN1(48);
					aSN6.Add(ASN1Convert.FromOid("1.2.840.113549.1.9.20"));
					ASN1 aSN7 = new ASN1(49);
					foreach (byte[] item2 in arrayList2)
					{
						ASN1 aSN8 = new ASN1(30);
						aSN8.Value = item2;
						aSN7.Add(aSN8);
					}
					aSN6.Add(aSN7);
					aSN2.Add(aSN6);
				}
				if (aSN2.Count > 0)
				{
					aSN.Add(aSN2);
				}
			}
			return aSN;
		}

		private ASN1 CertificateSafeBag(X509Certificate x509, IDictionary attributes)
		{
			ASN1 asn = new ASN1(4, x509.RawData);
			PKCS7.ContentInfo contentInfo = new PKCS7.ContentInfo();
			contentInfo.ContentType = "1.2.840.113549.1.9.22.1";
			contentInfo.Content.Add(asn);
			ASN1 aSN = new ASN1(160);
			aSN.Add(contentInfo.ASN1);
			ASN1 aSN2 = new ASN1(48);
			aSN2.Add(ASN1Convert.FromOid("1.2.840.113549.1.12.10.1.3"));
			aSN2.Add(aSN);
			if (attributes != null)
			{
				ASN1 aSN3 = new ASN1(49);
				IDictionaryEnumerator enumerator = attributes.GetEnumerator();
				while (enumerator.MoveNext())
				{
					string text = (string)enumerator.Key;
					if (!(text == "1.2.840.113549.1.9.20"))
					{
						if (!(text == "1.2.840.113549.1.9.21"))
						{
							continue;
						}
						ArrayList arrayList = (ArrayList)enumerator.Value;
						if (arrayList.Count <= 0)
						{
							continue;
						}
						ASN1 aSN4 = new ASN1(48);
						aSN4.Add(ASN1Convert.FromOid("1.2.840.113549.1.9.21"));
						ASN1 aSN5 = new ASN1(49);
						foreach (byte[] item in arrayList)
						{
							ASN1 aSN6 = new ASN1(4);
							aSN6.Value = item;
							aSN5.Add(aSN6);
						}
						aSN4.Add(aSN5);
						aSN3.Add(aSN4);
						continue;
					}
					ArrayList arrayList2 = (ArrayList)enumerator.Value;
					if (arrayList2.Count <= 0)
					{
						continue;
					}
					ASN1 aSN7 = new ASN1(48);
					aSN7.Add(ASN1Convert.FromOid("1.2.840.113549.1.9.20"));
					ASN1 aSN8 = new ASN1(49);
					foreach (byte[] item2 in arrayList2)
					{
						ASN1 aSN9 = new ASN1(30);
						aSN9.Value = item2;
						aSN8.Add(aSN9);
					}
					aSN7.Add(aSN8);
					aSN3.Add(aSN7);
				}
				if (aSN3.Count > 0)
				{
					aSN2.Add(aSN3);
				}
			}
			return aSN2;
		}

		private byte[] MAC(byte[] password, byte[] salt, int iterations, byte[] data)
		{
			DeriveBytes deriveBytes = new DeriveBytes();
			deriveBytes.HashName = "SHA1";
			deriveBytes.Password = password;
			deriveBytes.Salt = salt;
			deriveBytes.IterationCount = iterations;
			HMACSHA1 obj = (HMACSHA1)System.Security.Cryptography.HMAC.Create();
			obj.Key = deriveBytes.DeriveMAC(20);
			return obj.ComputeHash(data, 0, data.Length);
		}

		public byte[] GetBytes()
		{
			ASN1 aSN = new ASN1(48);
			ArrayList arrayList = new ArrayList();
			foreach (SafeBag safeBag5 in _safeBags)
			{
				if (safeBag5.BagOID.Equals("1.2.840.113549.1.12.10.1.3"))
				{
					PKCS7.ContentInfo contentInfo = new PKCS7.ContentInfo(safeBag5.ASN1[1].Value);
					arrayList.Add(new X509Certificate(contentInfo.Content[0].Value));
				}
			}
			ArrayList arrayList2 = new ArrayList();
			ArrayList arrayList3 = new ArrayList();
			foreach (X509Certificate certificate in Certificates)
			{
				bool flag = false;
				foreach (X509Certificate item in arrayList)
				{
					if (Compare(certificate.RawData, item.RawData))
					{
						flag = true;
					}
				}
				if (!flag)
				{
					arrayList2.Add(certificate);
				}
			}
			foreach (X509Certificate item2 in arrayList)
			{
				bool flag2 = false;
				foreach (X509Certificate certificate2 in Certificates)
				{
					if (Compare(item2.RawData, certificate2.RawData))
					{
						flag2 = true;
					}
				}
				if (!flag2)
				{
					arrayList3.Add(item2);
				}
			}
			foreach (X509Certificate item3 in arrayList3)
			{
				RemoveCertificate(item3);
			}
			foreach (X509Certificate item4 in arrayList2)
			{
				AddCertificate(item4);
			}
			if (_safeBags.Count > 0)
			{
				ASN1 aSN2 = new ASN1(48);
				foreach (SafeBag safeBag6 in _safeBags)
				{
					if (safeBag6.BagOID.Equals("1.2.840.113549.1.12.10.

BepInExPack/mono/Managed/mscorlib.dll

Decompiled a month ago
#define DEBUG
using System;
using System.Buffers;
using System.Buffers.Binary;
using System.Buffers.Text;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Configuration.Assemblies;
using System.Diagnostics;
using System.Diagnostics.Contracts;
using System.Diagnostics.SymbolStore;
using System.Diagnostics.Tracing;
using System.Globalization;
using System.IO;
using System.IO.Enumeration;
using System.Numerics;
using System.Numerics.Hashing;
using System.Reflection;
using System.Reflection.Emit;
using System.Resources;
using System.Runtime;
using System.Runtime.CompilerServices;
using System.Runtime.ConstrainedExecution;
using System.Runtime.ExceptionServices;
using System.Runtime.Hosting;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Activation;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Contexts;
using System.Runtime.Remoting.Lifetime;
using System.Runtime.Remoting.Messaging;
using System.Runtime.Remoting.Metadata;
using System.Runtime.Remoting.Proxies;
using System.Runtime.Remoting.Services;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Versioning;
using System.Security;
using System.Security.AccessControl;
using System.Security.Claims;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using System.Security.Permissions;
using System.Security.Policy;
using System.Security.Principal;
using System.Security.Util;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Threading.Tasks.Sources;
using Internal.Cryptography;
using Internal.Runtime.Augments;
using Internal.Threading.Tasks.Tracing;
using Microsoft.CodeAnalysis;
using Microsoft.Win32;
using Microsoft.Win32.SafeHandles;
using Mono;
using Mono.Globalization.Unicode;
using Mono.Interop;
using Mono.Math;
using Mono.Math.Prime;
using Mono.Math.Prime.Generator;
using Mono.Security;
using Mono.Security.Cryptography;
using Mono.Xml;

[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("mscorlib.dll")]
[assembly: AssemblyDescription("mscorlib.dll")]
[assembly: AssemblyDefaultAlias("mscorlib.dll")]
[assembly: AssemblyCompany("Mono development team")]
[assembly: AssemblyProduct("Mono Common Language Infrastructure")]
[assembly: AssemblyCopyright("(c) Various Mono authors")]
[assembly: AssemblyInformationalVersion("4.6.57.0")]
[assembly: SatelliteContractVersion("4.0.0.0")]
[assembly: NeutralResourcesLanguage("en-US")]
[assembly: CLSCompliant(true)]
[assembly: AssemblyDelaySign(true)]
[assembly: AssemblyKeyFile("../ecma.pub")]
[assembly: ComCompatibleVersion(1, 0, 3300, 0)]
[assembly: AllowPartiallyTrustedCallers]
[assembly: AssemblyFileVersion("4.6.57.0")]
[assembly: ComVisible(false)]
[assembly: CompilationRelaxations(CompilationRelaxations.NoStringInterning)]
[assembly: DefaultDependency(LoadHint.Always)]
[assembly: StringFreezing]
[assembly: InternalsVisibleTo("System, PublicKey=00000000000000000400000000000000")]
[assembly: InternalsVisibleTo("System.Core, PublicKey=00000000000000000400000000000000")]
[assembly: InternalsVisibleTo("System.Security, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")]
[assembly: InternalsVisibleTo("System.Runtime.WindowsRuntime, PublicKey=00000000000000000400000000000000")]
[assembly: InternalsVisibleTo("System.Runtime.WindowsRuntime.UI.Xaml, PublicKey=00000000000000000400000000000000")]
[assembly: InternalsVisibleTo("System.Net.Http, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")]
[assembly: Guid("BED7F4EA-1A96-11D2-8F08-00A0C9A6186D")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("4.0.0.0")]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class IsUnmanagedAttribute : Attribute
	{
	}
}
internal static class Interop
{
	internal class BCrypt
	{
		internal enum NTSTATUS : uint
		{
			STATUS_SUCCESS = 0u,
			STATUS_NOT_FOUND = 3221226021u,
			STATUS_INVALID_PARAMETER = 3221225485u,
			STATUS_NO_MEMORY = 3221225495u
		}

		internal const int BCRYPT_USE_SYSTEM_PREFERRED_RNG = 2;

		[DllImport("BCrypt.dll", CharSet = CharSet.Unicode)]
		internal unsafe static extern NTSTATUS BCryptGenRandom(IntPtr hAlgorithm, byte* pbBuffer, int cbBuffer, int dwFlags);
	}

	internal static class Kernel32
	{
		internal struct REG_TZI_FORMAT
		{
			internal int Bias;

			internal int StandardBias;

			internal int DaylightBias;

			internal SYSTEMTIME StandardDate;

			internal SYSTEMTIME DaylightDate;

			internal REG_TZI_FORMAT(in TIME_ZONE_INFORMATION tzi)
			{
				Bias = tzi.Bias;
				StandardDate = tzi.StandardDate;
				StandardBias = tzi.StandardBias;
				DaylightDate = tzi.DaylightDate;
				DaylightBias = tzi.DaylightBias;
			}
		}

		internal struct SYSTEMTIME
		{
			internal ushort Year;

			internal ushort Month;

			internal ushort DayOfWeek;

			internal ushort Day;

			internal ushort Hour;

			internal ushort Minute;

			internal ushort Second;

			internal ushort Milliseconds;

			internal bool Equals(in SYSTEMTIME other)
			{
				if (Year == other.Year && Month == other.Month && DayOfWeek == other.DayOfWeek && Day == other.Day && Hour == other.Hour && Minute == other.Minute && Second == other.Second)
				{
					return Milliseconds == other.Milliseconds;
				}
				return false;
			}
		}

		[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
		internal struct TIME_DYNAMIC_ZONE_INFORMATION
		{
			internal int Bias;

			internal unsafe fixed char StandardName[32];

			internal SYSTEMTIME StandardDate;

			internal int StandardBias;

			internal unsafe fixed char DaylightName[32];

			internal SYSTEMTIME DaylightDate;

			internal int DaylightBias;

			internal unsafe fixed char TimeZoneKeyName[128];

			internal byte DynamicDaylightTimeDisabled;

			internal unsafe string GetTimeZoneKeyName()
			{
				fixed (char* value = TimeZoneKeyName)
				{
					return new string(value);
				}
			}
		}

		[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
		internal struct TIME_ZONE_INFORMATION
		{
			internal int Bias;

			internal unsafe fixed char StandardName[32];

			internal SYSTEMTIME StandardDate;

			internal int StandardBias;

			internal unsafe fixed char DaylightName[32];

			internal SYSTEMTIME DaylightDate;

			internal int DaylightBias;

			internal unsafe TIME_ZONE_INFORMATION(in TIME_DYNAMIC_ZONE_INFORMATION dtzi)
			{
				fixed (TIME_ZONE_INFORMATION* ptr = &this)
				{
					fixed (TIME_DYNAMIC_ZONE_INFORMATION* ptr2 = &dtzi)
					{
						*ptr = *(TIME_ZONE_INFORMATION*)ptr2;
					}
				}
			}

			internal unsafe string GetStandardName()
			{
				fixed (char* value = StandardName)
				{
					return new string(value);
				}
			}

			internal unsafe string GetDaylightName()
			{
				fixed (char* value = DaylightName)
				{
					return new string(value);
				}
			}
		}

		internal enum FILE_INFO_BY_HANDLE_CLASS : uint
		{
			FileBasicInfo,
			FileStandardInfo,
			FileNameInfo,
			FileRenameInfo,
			FileDispositionInfo,
			FileAllocationInfo,
			FileEndOfFileInfo,
			FileStreamInfo,
			FileCompressionInfo,
			FileAttributeTagInfo,
			FileIdBothDirectoryInfo,
			FileIdBothDirectoryRestartInfo,
			FileIoPriorityHintInfo,
			FileRemoteProtocolInfo,
			FileFullDirectoryInfo,
			FileFullDirectoryRestartInfo
		}

		internal struct FILE_TIME
		{
			internal uint dwLowDateTime;

			internal uint dwHighDateTime;

			internal FILE_TIME(long fileTime)
			{
				dwLowDateTime = (uint)fileTime;
				dwHighDateTime = (uint)(fileTime >> 32);
			}

			internal long ToTicks()
			{
				return (long)(((ulong)dwHighDateTime << 32) + dwLowDateTime);
			}

			internal DateTime ToDateTimeUtc()
			{
				return DateTime.FromFileTimeUtc(ToTicks());
			}

			internal DateTimeOffset ToDateTimeOffset()
			{
				return DateTimeOffset.FromFileTime(ToTicks());
			}
		}

		internal enum FINDEX_INFO_LEVELS : uint
		{
			FindExInfoStandard,
			FindExInfoBasic,
			FindExInfoMaxInfoLevel
		}

		internal enum FINDEX_SEARCH_OPS : uint
		{
			FindExSearchNameMatch,
			FindExSearchLimitToDirectories,
			FindExSearchLimitToDevices,
			FindExSearchMaxSearchOp
		}

		internal class FileAttributes
		{
			internal const int FILE_ATTRIBUTE_NORMAL = 128;

			internal const int FILE_ATTRIBUTE_READONLY = 1;

			internal const int FILE_ATTRIBUTE_DIRECTORY = 16;

			internal const int FILE_ATTRIBUTE_REPARSE_POINT = 1024;
		}

		internal class IOReparseOptions
		{
			internal const uint IO_REPARSE_TAG_FILE_PLACEHOLDER = 2147483669u;

			internal const uint IO_REPARSE_TAG_MOUNT_POINT = 2684354563u;
		}

		internal class FileOperations
		{
			internal const int OPEN_EXISTING = 3;

			internal const int COPY_FILE_FAIL_IF_EXISTS = 1;

			internal const int FILE_ACTION_ADDED = 1;

			internal const int FILE_ACTION_REMOVED = 2;

			internal const int FILE_ACTION_MODIFIED = 3;

			internal const int FILE_ACTION_RENAMED_OLD_NAME = 4;

			internal const int FILE_ACTION_RENAMED_NEW_NAME = 5;

			internal const int FILE_FLAG_BACKUP_SEMANTICS = 33554432;

			internal const int FILE_FLAG_FIRST_PIPE_INSTANCE = 524288;

			internal const int FILE_FLAG_OVERLAPPED = 1073741824;

			internal const int FILE_LIST_DIRECTORY = 1;
		}

		internal enum GET_FILEEX_INFO_LEVELS : uint
		{
			GetFileExInfoStandard,
			GetFileExMaxInfoLevel
		}

		internal class GenericOperations
		{
			internal const int GENERIC_READ = int.MinValue;

			internal const int GENERIC_WRITE = 1073741824;
		}

		internal struct SECURITY_ATTRIBUTES
		{
			internal uint nLength;

			internal IntPtr lpSecurityDescriptor;

			internal BOOL bInheritHandle;
		}

		internal struct FILE_BASIC_INFO
		{
			internal long CreationTime;

			internal long LastAccessTime;

			internal long LastWriteTime;

			internal long ChangeTime;

			internal uint FileAttributes;
		}

		internal struct WIN32_FILE_ATTRIBUTE_DATA
		{
			internal int dwFileAttributes;

			internal FILE_TIME ftCreationTime;

			internal FILE_TIME ftLastAccessTime;

			internal FILE_TIME ftLastWriteTime;

			internal uint nFileSizeHigh;

			internal uint nFileSizeLow;

			internal void PopulateFrom(ref WIN32_FIND_DATA findData)
			{
				dwFileAttributes = (int)findData.dwFileAttributes;
				ftCreationTime = findData.ftCreationTime;
				ftLastAccessTime = findData.ftLastAccessTime;
				ftLastWriteTime = findData.ftLastWriteTime;
				nFileSizeHigh = findData.nFileSizeHigh;
				nFileSizeLow = findData.nFileSizeLow;
			}
		}

		[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
		internal struct WIN32_FIND_DATA
		{
			internal uint dwFileAttributes;

			internal FILE_TIME ftCreationTime;

			internal FILE_TIME ftLastAccessTime;

			internal FILE_TIME ftLastWriteTime;

			internal uint nFileSizeHigh;

			internal uint nFileSizeLow;

			internal uint dwReserved0;

			internal uint dwReserved1;

			private unsafe fixed char _cFileName[260];

			private unsafe fixed char _cAlternateFileName[14];

			internal unsafe ReadOnlySpan<char> cFileName
			{
				get
				{
					fixed (char* pointer = _cFileName)
					{
						return new ReadOnlySpan<char>(pointer, 260);
					}
				}
			}
		}

		internal const int LOAD_LIBRARY_AS_DATAFILE = 2;

		internal const int MAX_PATH = 260;

		internal const uint MUI_PREFERRED_UI_LANGUAGES = 16u;

		internal const uint TIME_ZONE_ID_INVALID = uint.MaxValue;

		internal const uint SEM_FAILCRITICALERRORS = 1u;

		private const int FORMAT_MESSAGE_IGNORE_INSERTS = 512;

		private const int FORMAT_MESSAGE_FROM_HMODULE = 2048;

		private const int FORMAT_MESSAGE_FROM_SYSTEM = 4096;

		private const int FORMAT_MESSAGE_ARGUMENT_ARRAY = 8192;

		private const int ERROR_INSUFFICIENT_BUFFER = 122;

		private const int InitialBufferSize = 256;

		private const int BufferSizeIncreaseFactor = 4;

		private const int MaxAllowedBufferSize = 66560;

		internal const int REPLACEFILE_IGNORE_MERGE_ERRORS = 2;

		[DllImport("kernel32.dll", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
		internal static extern bool FreeLibrary(IntPtr hModule);

		[DllImport("kernel32.dll", CharSet = CharSet.Unicode, EntryPoint = "LoadLibraryExW", SetLastError = true)]
		internal static extern SafeLibraryHandle LoadLibraryEx(string libFilename, IntPtr reserved, int flags);

		[DllImport("kernel32.dll", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
		internal static extern bool GetFileMUIPath(uint flags, string filePath, [Out] StringBuilder language, ref int languageLength, [Out] StringBuilder fileMuiPath, ref int fileMuiPathLength, ref long enumerator);

		[DllImport("kernel32.dll", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
		internal static extern uint GetDynamicTimeZoneInformation(out TIME_DYNAMIC_ZONE_INFORMATION pTimeZoneInformation);

		[DllImport("kernel32.dll", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
		internal static extern uint GetTimeZoneInformation(out TIME_ZONE_INFORMATION lpTimeZoneInformation);

		[DllImport("kernel32.dll", SetLastError = true)]
		[return: MarshalAs(UnmanagedType.Bool)]
		internal static extern bool CloseHandle(IntPtr handle);

		internal static int CopyFile(string src, string dst, bool failIfExists)
		{
			int flags = (failIfExists ? 1 : 0);
			int cancel = 0;
			if (!CopyFileEx(src, dst, IntPtr.Zero, IntPtr.Zero, ref cancel, flags))
			{
				return Marshal.GetLastWin32Error();
			}
			return 0;
		}

		[DllImport("kernel32.dll", BestFitMapping = false, CharSet = CharSet.Unicode, EntryPoint = "CopyFileExW", SetLastError = true)]
		private static extern bool CopyFileExPrivate(string src, string dst, IntPtr progressRoutine, IntPtr progressData, ref int cancel, int flags);

		internal static bool CopyFileEx(string src, string dst, IntPtr progressRoutine, IntPtr progressData, ref int cancel, int flags)
		{
			src = PathInternal.EnsureExtendedPrefixIfNeeded(src);
			dst = PathInternal.EnsureExtendedPrefixIfNeeded(dst);
			return CopyFileExPrivate(src, dst, progressRoutine, progressData, ref cancel, flags);
		}

		[DllImport("kernel32.dll", BestFitMapping = false, CharSet = CharSet.Unicode, EntryPoint = "CreateDirectoryW", SetLastError = true)]
		private static extern bool CreateDirectoryPrivate(string path, ref SECURITY_ATTRIBUTES lpSecurityAttributes);

		internal static bool CreateDirectory(string path, ref SECURITY_ATTRIBUTES lpSecurityAttributes)
		{
			path = PathInternal.EnsureExtendedPrefix(path);
			return CreateDirectoryPrivate(path, ref lpSecurityAttributes);
		}

		[DllImport("kernel32.dll", BestFitMapping = false, CharSet = CharSet.Unicode, EntryPoint = "CreateFileW", ExactSpelling = true, SetLastError = true)]
		private unsafe static extern IntPtr CreateFilePrivate(string lpFileName, int dwDesiredAccess, FileShare dwShareMode, SECURITY_ATTRIBUTES* securityAttrs, FileMode dwCreationDisposition, int dwFlagsAndAttributes, IntPtr hTemplateFile);

		internal unsafe static SafeFileHandle CreateFile(string lpFileName, int dwDesiredAccess, FileShare dwShareMode, ref SECURITY_ATTRIBUTES securityAttrs, FileMode dwCreationDisposition, int dwFlagsAndAttributes, IntPtr hTemplateFile)
		{
			lpFileName = PathInternal.EnsureExtendedPrefixIfNeeded(lpFileName);
			fixed (SECURITY_ATTRIBUTES* securityAttrs2 = &securityAttrs)
			{
				IntPtr intPtr = CreateFilePrivate(lpFileName, dwDesiredAccess, dwShareMode, securityAttrs2, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile);
				try
				{
					return new SafeFileHandle(intPtr, ownsHandle: true);
				}
				catch
				{
					CloseHandle(intPtr);
					throw;
				}
			}
		}

		internal static SafeFileHandle CreateFile(string lpFileName, int dwDesiredAccess, FileShare dwShareMode, FileMode dwCreationDisposition, int dwFlagsAndAttributes)
		{
			IntPtr intPtr = CreateFile_IntPtr(lpFileName, dwDesiredAccess, dwShareMode, dwCreationDisposition, dwFlagsAndAttributes);
			try
			{
				return new SafeFileHandle(intPtr, ownsHandle: true);
			}
			catch
			{
				CloseHandle(intPtr);
				throw;
			}
		}

		internal unsafe static IntPtr CreateFile_IntPtr(string lpFileName, int dwDesiredAccess, FileShare dwShareMode, FileMode dwCreationDisposition, int dwFlagsAndAttributes)
		{
			lpFileName = PathInternal.EnsureExtendedPrefixIfNeeded(lpFileName);
			return CreateFilePrivate(lpFileName, dwDesiredAccess, dwShareMode, null, dwCreationDisposition, dwFlagsAndAttributes, IntPtr.Zero);
		}

		[DllImport("kernel32.dll", BestFitMapping = false, CharSet = CharSet.Unicode, EntryPoint = "DeleteFileW", SetLastError = true)]
		private static extern bool DeleteFilePrivate(string path);

		internal static bool DeleteFile(string path)
		{
			path = PathInternal.EnsureExtendedPrefixIfNeeded(path);
			return DeleteFilePrivate(path);
		}

		[DllImport("kernel32.dll", BestFitMapping = false, CharSet = CharSet.Unicode, EntryPoint = "DeleteVolumeMountPointW", SetLastError = true)]
		internal static extern bool DeleteVolumeMountPointPrivate(string mountPoint);

		internal static bool DeleteVolumeMountPoint(string mountPoint)
		{
			mountPoint = PathInternal.EnsureExtendedPrefixIfNeeded(mountPoint);
			return DeleteVolumeMountPointPrivate(mountPoint);
		}

		[DllImport("kernel32.dll", BestFitMapping = false, CharSet = CharSet.Unicode, EntryPoint = "FindFirstFileExW", SetLastError = true)]
		private static extern SafeFindHandle FindFirstFileExPrivate(string lpFileName, FINDEX_INFO_LEVELS fInfoLevelId, ref WIN32_FIND_DATA lpFindFileData, FINDEX_SEARCH_OPS fSearchOp, IntPtr lpSearchFilter, int dwAdditionalFlags);

		internal static SafeFindHandle FindFirstFile(string fileName, ref WIN32_FIND_DATA data)
		{
			fileName = PathInternal.EnsureExtendedPrefixIfNeeded(fileName);
			return FindFirstFileExPrivate(fileName, FINDEX_INFO_LEVELS.FindExInfoBasic, ref data, FINDEX_SEARCH_OPS.FindExSearchNameMatch, IntPtr.Zero, 0);
		}

		[DllImport("kernel32.dll", BestFitMapping = false, CharSet = CharSet.Unicode, EntryPoint = "FindNextFileW", SetLastError = true)]
		internal static extern bool FindNextFile(SafeFindHandle hndFindFile, ref WIN32_FIND_DATA lpFindFileData);

		[DllImport("kernel32.dll", BestFitMapping = true, CharSet = CharSet.Unicode, EntryPoint = "FormatMessageW", SetLastError = true)]
		private unsafe static extern int FormatMessage(int dwFlags, IntPtr lpSource, uint dwMessageId, int dwLanguageId, char* lpBuffer, int nSize, IntPtr[] arguments);

		internal static string GetMessage(int errorCode)
		{
			return GetMessage(IntPtr.Zero, errorCode);
		}

		internal static string GetMessage(IntPtr moduleHandle, int errorCode)
		{
			Span<char> buffer = stackalloc char[256];
			do
			{
				if (TryGetErrorMessage(moduleHandle, errorCode, buffer, out var errorMsg))
				{
					return errorMsg;
				}
				buffer = new char[buffer.Length * 4];
			}
			while (buffer.Length < 66560);
			return $"Unknown error (0x{errorCode:x})";
		}

		private unsafe static bool TryGetErrorMessage(IntPtr moduleHandle, int errorCode, Span<char> buffer, out string errorMsg)
		{
			int num = 12800;
			if (moduleHandle != IntPtr.Zero)
			{
				num |= 0x800;
			}
			int num2;
			fixed (char* lpBuffer = &MemoryMarshal.GetReference(buffer))
			{
				num2 = FormatMessage(num, moduleHandle, (uint)errorCode, 0, lpBuffer, buffer.Length, null);
			}
			if (num2 != 0)
			{
				int num3;
				for (num3 = num2; num3 > 0; num3--)
				{
					char c = buffer[num3 - 1];
					if (c > ' ' && c != '.')
					{
						break;
					}
				}
				errorMsg = buffer.Slice(0, num3).ToString();
			}
			else
			{
				if (Marshal.GetLastWin32Error() == 122)
				{
					errorMsg = "";
					return false;
				}
				errorMsg = $"Unknown error (0x{errorCode:x})";
			}
			return true;
		}

		[DllImport("kernel32.dll", BestFitMapping = false, CharSet = CharSet.Unicode, EntryPoint = "GetFileAttributesExW", SetLastError = true)]
		private static extern bool GetFileAttributesExPrivate(string name, GET_FILEEX_INFO_LEVELS fileInfoLevel, ref WIN32_FILE_ATTRIBUTE_DATA lpFileInformation);

		internal static bool GetFileAttributesEx(string name, GET_FILEEX_INFO_LEVELS fileInfoLevel, ref WIN32_FILE_ATTRIBUTE_DATA lpFileInformation)
		{
			name = PathInternal.EnsureExtendedPrefixIfNeeded(name);
			return GetFileAttributesExPrivate(name, fileInfoLevel, ref lpFileInformation);
		}

		[DllImport("kernel32.dll", SetLastError = true)]
		internal static extern int GetLogicalDrives();

		[DllImport("kernel32.dll", BestFitMapping = false, CharSet = CharSet.Unicode, EntryPoint = "MoveFileExW", SetLastError = true)]
		private static extern bool MoveFileExPrivate(string src, string dst, uint flags);

		internal static bool MoveFile(string src, string dst)
		{
			src = PathInternal.EnsureExtendedPrefixIfNeeded(src);
			dst = PathInternal.EnsureExtendedPrefixIfNeeded(dst);
			return MoveFileExPrivate(src, dst, 2u);
		}

		[DllImport("kernel32.dll", BestFitMapping = false, CharSet = CharSet.Unicode, EntryPoint = "RemoveDirectoryW", SetLastError = true)]
		private static extern bool RemoveDirectoryPrivate(string path);

		internal static bool RemoveDirectory(string path)
		{
			path = PathInternal.EnsureExtendedPrefixIfNeeded(path);
			return RemoveDirectoryPrivate(path);
		}

		[DllImport("kernel32.dll", BestFitMapping = false, CharSet = CharSet.Unicode, EntryPoint = "ReplaceFileW", SetLastError = true)]
		private static extern bool ReplaceFilePrivate(string replacedFileName, string replacementFileName, string backupFileName, int dwReplaceFlags, IntPtr lpExclude, IntPtr lpReserved);

		internal static bool ReplaceFile(string replacedFileName, string replacementFileName, string backupFileName, int dwReplaceFlags, IntPtr lpExclude, IntPtr lpReserved)
		{
			replacedFileName = PathInternal.EnsureExtendedPrefixIfNeeded(replacedFileName);
			replacementFileName = PathInternal.EnsureExtendedPrefixIfNeeded(replacementFileName);
			backupFileName = PathInternal.EnsureExtendedPrefixIfNeeded(backupFileName);
			return ReplaceFilePrivate(replacedFileName, replacementFileName, backupFileName, dwReplaceFlags, lpExclude, lpReserved);
		}

		[DllImport("kernel32.dll", BestFitMapping = false, CharSet = CharSet.Unicode, EntryPoint = "SetFileAttributesW", SetLastError = true)]
		private static extern bool SetFileAttributesPrivate(string name, int attr);

		internal static bool SetFileAttributes(string name, int attr)
		{
			name = PathInternal.EnsureExtendedPrefixIfNeeded(name);
			return SetFileAttributesPrivate(name, attr);
		}

		[DllImport("kernel32.dll", ExactSpelling = true, SetLastError = true)]
		internal static extern bool SetFileInformationByHandle(SafeFileHandle hFile, FILE_INFO_BY_HANDLE_CLASS FileInformationClass, ref FILE_BASIC_INFO lpFileInformation, uint dwBufferSize);

		internal unsafe static bool SetFileTime(SafeFileHandle hFile, long creationTime = -1L, long lastAccessTime = -1L, long lastWriteTime = -1L, long changeTime = -1L, uint fileAttributes = 0u)
		{
			FILE_BASIC_INFO fILE_BASIC_INFO = default(FILE_BASIC_INFO);
			fILE_BASIC_INFO.CreationTime = creationTime;
			fILE_BASIC_INFO.LastAccessTime = lastAccessTime;
			fILE_BASIC_INFO.LastWriteTime = lastWriteTime;
			fILE_BASIC_INFO.ChangeTime = changeTime;
			fILE_BASIC_INFO.FileAttributes = fileAttributes;
			FILE_BASIC_INFO lpFileInformation = fILE_BASIC_INFO;
			return SetFileInformationByHandle(hFile, FILE_INFO_BY_HANDLE_CLASS.FileBasicInfo, ref lpFileInformation, (uint)sizeof(FILE_BASIC_INFO));
		}

		[DllImport("kernel32.dll", ExactSpelling = true, SetLastError = true)]
		internal static extern bool SetThreadErrorMode(uint dwNewMode, out uint lpOldMode);
	}

	internal class User32
	{
		[DllImport("user32.dll", CharSet = CharSet.Unicode, EntryPoint = "LoadStringW", SetLastError = true)]
		internal static extern int LoadString(SafeLibraryHandle handle, int id, [Out] StringBuilder buffer, int bufferLength);
	}

	internal enum BOOL
	{
		FALSE,
		TRUE
	}

	internal enum BOOLEAN : byte
	{
		FALSE,
		TRUE
	}

	internal class Errors
	{
		internal const int ERROR_SUCCESS = 0;

		internal const int ERROR_INVALID_FUNCTION = 1;

		internal const int ERROR_FILE_NOT_FOUND = 2;

		internal const int ERROR_PATH_NOT_FOUND = 3;

		internal const int ERROR_ACCESS_DENIED = 5;

		internal const int ERROR_INVALID_HANDLE = 6;

		internal const int ERROR_NOT_ENOUGH_MEMORY = 8;

		internal const int ERROR_INVALID_DATA = 13;

		internal const int ERROR_INVALID_DRIVE = 15;

		internal const int ERROR_NO_MORE_FILES = 18;

		internal const int ERROR_NOT_READY = 21;

		internal const int ERROR_BAD_COMMAND = 22;

		internal const int ERROR_BAD_LENGTH = 24;

		internal const int ERROR_SHARING_VIOLATION = 32;

		internal const int ERROR_LOCK_VIOLATION = 33;

		internal const int ERROR_HANDLE_EOF = 38;

		internal const int ERROR_BAD_NETPATH = 53;

		internal const int ERROR_BAD_NET_NAME = 67;

		internal const int ERROR_FILE_EXISTS = 80;

		internal const int ERROR_INVALID_PARAMETER = 87;

		internal const int ERROR_BROKEN_PIPE = 109;

		internal const int ERROR_SEM_TIMEOUT = 121;

		internal const int ERROR_CALL_NOT_IMPLEMENTED = 120;

		internal const int ERROR_INSUFFICIENT_BUFFER = 122;

		internal const int ERROR_INVALID_NAME = 123;

		internal const int ERROR_NEGATIVE_SEEK = 131;

		internal const int ERROR_DIR_NOT_EMPTY = 145;

		internal const int ERROR_BAD_PATHNAME = 161;

		internal const int ERROR_LOCK_FAILED = 167;

		internal const int ERROR_BUSY = 170;

		internal const int ERROR_ALREADY_EXISTS = 183;

		internal const int ERROR_BAD_EXE_FORMAT = 193;

		internal const int ERROR_ENVVAR_NOT_FOUND = 203;

		internal const int ERROR_FILENAME_EXCED_RANGE = 206;

		internal const int ERROR_EXE_MACHINE_TYPE_MISMATCH = 216;

		internal const int ERROR_PIPE_BUSY = 231;

		internal const int ERROR_NO_DATA = 232;

		internal const int ERROR_PIPE_NOT_CONNECTED = 233;

		internal const int ERROR_MORE_DATA = 234;

		internal const int ERROR_NO_MORE_ITEMS = 259;

		internal const int ERROR_DIRECTORY = 267;

		internal const int ERROR_PARTIAL_COPY = 299;

		internal const int ERROR_ARITHMETIC_OVERFLOW = 534;

		internal const int ERROR_PIPE_CONNECTED = 535;

		internal const int ERROR_PIPE_LISTENING = 536;

		internal const int ERROR_OPERATION_ABORTED = 995;

		internal const int ERROR_IO_INCOMPLETE = 996;

		internal const int ERROR_IO_PENDING = 997;

		internal const int ERROR_NO_TOKEN = 1008;

		internal const int ERROR_DLL_INIT_FAILED = 1114;

		internal const int ERROR_COUNTER_TIMEOUT = 1121;

		internal const int ERROR_NO_ASSOCIATION = 1155;

		internal const int ERROR_DDE_FAIL = 1156;

		internal const int ERROR_DLL_NOT_FOUND = 1157;

		internal const int ERROR_NOT_FOUND = 1168;

		internal const int ERROR_NETWORK_UNREACHABLE = 1231;

		internal const int ERROR_NON_ACCOUNT_SID = 1257;

		internal const int ERROR_NOT_ALL_ASSIGNED = 1300;

		internal const int ERROR_UNKNOWN_REVISION = 1305;

		internal const int ERROR_INVALID_OWNER = 1307;

		internal const int ERROR_INVALID_PRIMARY_GROUP = 1308;

		internal const int ERROR_NO_SUCH_PRIVILEGE = 1313;

		internal const int ERROR_PRIVILEGE_NOT_HELD = 1314;

		internal const int ERROR_INVALID_ACL = 1336;

		internal const int ERROR_INVALID_SECURITY_DESCR = 1338;

		internal const int ERROR_INVALID_SID = 1337;

		internal const int ERROR_BAD_IMPERSONATION_LEVEL = 1346;

		internal const int ERROR_CANT_OPEN_ANONYMOUS = 1347;

		internal const int ERROR_NO_SECURITY_ON_OBJECT = 1350;

		internal const int ERROR_CLASS_ALREADY_EXISTS = 1410;

		internal const int ERROR_TRUSTED_RELATIONSHIP_FAILURE = 1789;

		internal const int ERROR_RESOURCE_LANG_NOT_FOUND = 1815;

		internal const int EFail = -2147467259;

		internal const int E_FILENOTFOUND = -2147024894;
	}

	internal static class Libraries
	{
		internal const string Advapi32 = "advapi32.dll";

		internal const string BCrypt = "BCrypt.dll";

		internal const string CoreComm_L1_1_1 = "api-ms-win-core-comm-l1-1-1.dll";

		internal const string Crypt32 = "crypt32.dll";

		internal const string Error_L1 = "api-ms-win-core-winrt-error-l1-1-0.dll";

		internal const string HttpApi = "httpapi.dll";

		internal const string IpHlpApi = "iphlpapi.dll";

		internal const string Kernel32 = "kernel32.dll";

		internal const string Memory_L1_3 = "api-ms-win-core-memory-l1-1-3.dll";

		internal const string Mswsock = "mswsock.dll";

		internal const string NCrypt = "ncrypt.dll";

		internal const string NtDll = "ntdll.dll";

		internal const string Odbc32 = "odbc32.dll";

		internal const string OleAut32 = "oleaut32.dll";

		internal const string PerfCounter = "perfcounter.dll";

		internal const string RoBuffer = "api-ms-win-core-winrt-robuffer-l1-1-0.dll";

		internal const string Secur32 = "secur32.dll";

		internal const string Shell32 = "shell32.dll";

		internal const string SspiCli = "sspicli.dll";

		internal const string User32 = "user32.dll";

		internal const string Version = "version.dll";

		internal const string WebSocket = "websocket.dll";

		internal const string WinHttp = "winhttp.dll";

		internal const string Ws2_32 = "ws2_32.dll";

		internal const string Wtsapi32 = "wtsapi32.dll";

		internal const string CompressionNative = "clrcompression.dll";

		internal const string ErrorHandling = "api-ms-win-core-errorhandling-l1-1-0.dll";

		internal const string Handle = "api-ms-win-core-handle-l1-1-0.dll";

		internal const string IO = "api-ms-win-core-io-l1-1-0.dll";

		internal const string Memory = "api-ms-win-core-memory-l1-1-0.dll";

		internal const string ProcessEnvironment = "api-ms-win-core-processenvironment-l1-1-0.dll";

		internal const string ProcessThreads = "api-ms-win-core-processthreads-l1-1-0.dll";

		internal const string RealTime = "api-ms-win-core-realtime-l1-1-0.dll";

		internal const string SysInfo = "api-ms-win-core-sysinfo-l1-2-0.dll";

		internal const string ThreadPool = "api-ms-win-core-threadpool-l1-2-0.dll";

		internal const string Localization = "api-ms-win-core-localization-l1-2-1.dll";
	}

	internal struct LongFileTime
	{
		internal long TicksSince1601;

		internal DateTimeOffset ToDateTimeOffset()
		{
			return new DateTimeOffset(DateTime.FromFileTimeUtc(TicksSince1601));
		}
	}

	internal struct UNICODE_STRING
	{
		internal ushort Length;

		internal ushort MaximumLength;

		internal IntPtr Buffer;
	}

	internal class NtDll
	{
		[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
		public struct FILE_FULL_DIR_INFORMATION
		{
			public uint NextEntryOffset;

			public uint FileIndex;

			public LongFileTime CreationTime;

			public LongFileTime LastAccessTime;

			public LongFileTime LastWriteTime;

			public LongFileTime ChangeTime;

			public long EndOfFile;

			public long AllocationSize;

			public FileAttributes FileAttributes;

			public uint FileNameLength;

			public uint EaSize;

			private char _fileName;

			public unsafe ReadOnlySpan<char> FileName
			{
				get
				{
					fixed (char* pointer = &_fileName)
					{
						return new ReadOnlySpan<char>(pointer, (int)FileNameLength / 2);
					}
				}
			}

			public unsafe static FILE_FULL_DIR_INFORMATION* GetNextInfo(FILE_FULL_DIR_INFORMATION* info)
			{
				if (info == null)
				{
					return null;
				}
				uint nextEntryOffset = info->NextEntryOffset;
				if (nextEntryOffset == 0)
				{
					return null;
				}
				return (FILE_FULL_DIR_INFORMATION*)((byte*)info + nextEntryOffset);
			}
		}

		public enum FILE_INFORMATION_CLASS : uint
		{
			FileDirectoryInformation = 1u,
			FileFullDirectoryInformation,
			FileBothDirectoryInformation,
			FileBasicInformation,
			FileStandardInformation,
			FileInternalInformation,
			FileEaInformation,
			FileAccessInformation,
			FileNameInformation,
			FileRenameInformation,
			FileLinkInformation,
			FileNamesInformation,
			FileDispositionInformation,
			FilePositionInformation,
			FileFullEaInformation,
			FileModeInformation,
			FileAlignmentInformation,
			FileAllInformation,
			FileAllocationInformation,
			FileEndOfFileInformation,
			FileAlternateNameInformation,
			FileStreamInformation,
			FilePipeInformation,
			FilePipeLocalInformation,
			FilePipeRemoteInformation,
			FileMailslotQueryInformation,
			FileMailslotSetInformation,
			FileCompressionInformation,
			FileObjectIdInformation,
			FileCompletionInformation,
			FileMoveClusterInformation,
			FileQuotaInformation,
			FileReparsePointInformation,
			FileNetworkOpenInformation,
			FileAttributeTagInformation,
			FileTrackingInformation,
			FileIdBothDirectoryInformation,
			FileIdFullDirectoryInformation,
			FileValidDataLengthInformation,
			FileShortNameInformation,
			FileIoCompletionNotificationInformation,
			FileIoStatusBlockRangeInformation,
			FileIoPriorityHintInformation,
			FileSfioReserveInformation,
			FileSfioVolumeInformation,
			FileHardLinkInformation,
			FileProcessIdsUsingFileInformation,
			FileNormalizedNameInformation,
			FileNetworkPhysicalNameInformation,
			FileIdGlobalTxDirectoryInformation,
			FileIsRemoteDeviceInformation,
			FileUnusedInformation,
			FileNumaNodeInformation,
			FileStandardLinkInformation,
			FileRemoteProtocolInformation,
			FileRenameInformationBypassAccessCheck,
			FileLinkInformationBypassAccessCheck,
			FileVolumeNameInformation,
			FileIdInformation,
			FileIdExtdDirectoryInformation,
			FileReplaceCompletionInformation,
			FileHardLinkFullIdInformation,
			FileIdExtdBothDirectoryInformation,
			FileDispositionInformationEx,
			FileRenameInformationEx,
			FileRenameInformationExBypassAccessCheck,
			FileDesiredStorageClassInformation,
			FileStatInformation
		}

		public struct IO_STATUS_BLOCK
		{
			[StructLayout(LayoutKind.Explicit)]
			public struct IO_STATUS
			{
				[FieldOffset(0)]
				public uint Status;

				[FieldOffset(0)]
				public IntPtr Pointer;
			}

			public IO_STATUS Status;

			public IntPtr Information;
		}

		public struct OBJECT_ATTRIBUTES
		{
			public uint Length;

			public IntPtr RootDirectory;

			public unsafe UNICODE_STRING* ObjectName;

			public ObjectAttributes Attributes;

			public unsafe void* SecurityDescriptor;

			public unsafe void* SecurityQualityOfService;

			public unsafe OBJECT_ATTRIBUTES(UNICODE_STRING* objectName, ObjectAttributes attributes, IntPtr rootDirectory)
			{
				Length = (uint)sizeof(OBJECT_ATTRIBUTES);
				RootDirectory = rootDirectory;
				ObjectName = objectName;
				Attributes = attributes;
				SecurityDescriptor = null;
				SecurityQualityOfService = null;
			}
		}

		[Flags]
		public enum ObjectAttributes : uint
		{
			OBJ_INHERIT = 2u,
			OBJ_PERMANENT = 0x10u,
			OBJ_EXCLUSIVE = 0x20u,
			OBJ_CASE_INSENSITIVE = 0x40u,
			OBJ_OPENIF = 0x80u,
			OBJ_OPENLINK = 0x100u
		}

		public enum CreateDisposition : uint
		{
			FILE_SUPERSEDE,
			FILE_OPEN,
			FILE_CREATE,
			FILE_OPEN_IF,
			FILE_OVERWRITE,
			FILE_OVERWRITE_IF
		}

		public enum CreateOptions : uint
		{
			FILE_DIRECTORY_FILE = 1u,
			FILE_WRITE_THROUGH = 2u,
			FILE_SEQUENTIAL_ONLY = 4u,
			FILE_NO_INTERMEDIATE_BUFFERING = 8u,
			FILE_SYNCHRONOUS_IO_ALERT = 0x10u,
			FILE_SYNCHRONOUS_IO_NONALERT = 0x20u,
			FILE_NON_DIRECTORY_FILE = 0x40u,
			FILE_CREATE_TREE_CONNECTION = 0x80u,
			FILE_COMPLETE_IF_OPLOCKED = 0x100u,
			FILE_NO_EA_KNOWLEDGE = 0x200u,
			FILE_RANDOM_ACCESS = 0x800u,
			FILE_DELETE_ON_CLOSE = 0x1000u,
			FILE_OPEN_BY_FILE_ID = 0x2000u,
			FILE_OPEN_FOR_BACKUP_INTENT = 0x4000u,
			FILE_NO_COMPRESSION = 0x8000u,
			FILE_OPEN_REQUIRING_OPLOCK = 0x10000u,
			FILE_DISALLOW_EXCLUSIVE = 0x20000u,
			FILE_SESSION_AWARE = 0x40000u,
			FILE_RESERVE_OPFILTER = 0x100000u,
			FILE_OPEN_REPARSE_POINT = 0x200000u,
			FILE_OPEN_NO_RECALL = 0x400000u
		}

		[Flags]
		public enum DesiredAccess : uint
		{
			FILE_READ_DATA = 1u,
			FILE_LIST_DIRECTORY = 1u,
			FILE_WRITE_DATA = 2u,
			FILE_ADD_FILE = 2u,
			FILE_APPEND_DATA = 4u,
			FILE_ADD_SUBDIRECTORY = 4u,
			FILE_CREATE_PIPE_INSTANCE = 4u,
			FILE_READ_EA = 8u,
			FILE_WRITE_EA = 0x10u,
			FILE_EXECUTE = 0x20u,
			FILE_TRAVERSE = 0x20u,
			FILE_DELETE_CHILD = 0x40u,
			FILE_READ_ATTRIBUTES = 0x80u,
			FILE_WRITE_ATTRIBUTES = 0x100u,
			FILE_ALL_ACCESS = 0xF01FFu,
			DELETE = 0x10000u,
			READ_CONTROL = 0x20000u,
			WRITE_DAC = 0x40000u,
			WRITE_OWNER = 0x80000u,
			SYNCHRONIZE = 0x100000u,
			STANDARD_RIGHTS_READ = 0x20000u,
			STANDARD_RIGHTS_WRITE = 0x20000u,
			STANDARD_RIGHTS_EXECUTE = 0x20000u,
			FILE_GENERIC_READ = 0x80000000u,
			FILE_GENERIC_WRITE = 0x40000000u,
			FILE_GENERIC_EXECUTE = 0x20000000u
		}

		[DllImport("ntdll.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
		private unsafe static extern int NtCreateFile(out IntPtr FileHandle, DesiredAccess DesiredAccess, ref OBJECT_ATTRIBUTES ObjectAttributes, out IO_STATUS_BLOCK IoStatusBlock, long* AllocationSize, FileAttributes FileAttributes, FileShare ShareAccess, CreateDisposition CreateDisposition, CreateOptions CreateOptions, void* EaBuffer, uint EaLength);

		internal unsafe static (int status, IntPtr handle) CreateFile(ReadOnlySpan<char> path, IntPtr rootDirectory, CreateDisposition createDisposition, DesiredAccess desiredAccess = DesiredAccess.SYNCHRONIZE | DesiredAccess.FILE_GENERIC_READ, FileShare shareAccess = FileShare.ReadWrite | FileShare.Delete, FileAttributes fileAttributes = (FileAttributes)0, CreateOptions createOptions = CreateOptions.FILE_SYNCHRONOUS_IO_NONALERT, ObjectAttributes objectAttributes = NtDll.ObjectAttributes.OBJ_CASE_INSENSITIVE)
		{
			checked
			{
				fixed (char* ptr = &MemoryMarshal.GetReference(path))
				{
					UNICODE_STRING uNICODE_STRING = default(UNICODE_STRING);
					uNICODE_STRING.Length = (ushort)(path.Length * 2);
					uNICODE_STRING.MaximumLength = (ushort)(path.Length * 2);
					uNICODE_STRING.Buffer = (IntPtr)ptr;
					UNICODE_STRING uNICODE_STRING2 = uNICODE_STRING;
					OBJECT_ATTRIBUTES ObjectAttributes = new OBJECT_ATTRIBUTES(&uNICODE_STRING2, objectAttributes, rootDirectory);
					IntPtr FileHandle;
					IO_STATUS_BLOCK IoStatusBlock;
					return (NtCreateFile(out FileHandle, desiredAccess, ref ObjectAttributes, out IoStatusBlock, null, fileAttributes, shareAccess, createDisposition, createOptions, null, 0u), FileHandle);
				}
			}
		}

		[DllImport("ntdll.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
		public unsafe static extern int NtQueryDirectoryFile(IntPtr FileHandle, IntPtr Event, IntPtr ApcRoutine, IntPtr ApcContext, out IO_STATUS_BLOCK IoStatusBlock, IntPtr FileInformation, uint Length, FILE_INFORMATION_CLASS FileInformationClass, BOOLEAN ReturnSingleEntry, UNICODE_STRING* FileName, BOOLEAN RestartScan);

		[DllImport("ntdll.dll", ExactSpelling = true)]
		public static extern uint RtlNtStatusToDosError(int Status);
	}

	internal class StatusOptions
	{
		internal const uint STATUS_SUCCESS = 0u;

		internal const uint STATUS_SOME_NOT_MAPPED = 263u;

		internal const uint STATUS_NO_MORE_FILES = 2147483654u;

		internal const uint STATUS_INVALID_PARAMETER = 3221225485u;

		internal const uint STATUS_NO_MEMORY = 3221225495u;

		internal const uint STATUS_OBJECT_NAME_NOT_FOUND = 3221225524u;

		internal const uint STATUS_NONE_MAPPED = 3221225587u;

		internal const uint STATUS_INSUFFICIENT_RESOURCES = 3221225626u;

		internal const uint STATUS_ACCESS_DENIED = 3221225506u;

		internal const uint STATUS_ACCOUNT_RESTRICTION = 3221225582u;
	}

	internal class Advapi32
	{
		internal class RegistryOptions
		{
			internal const int REG_OPTION_NON_VOLATILE = 0;

			internal const int REG_OPTION_VOLATILE = 1;

			internal const int REG_OPTION_CREATE_LINK = 2;

			internal const int REG_OPTION_BACKUP_RESTORE = 4;
		}

		internal class RegistryView
		{
			internal const int KEY_WOW64_64KEY = 256;

			internal const int KEY_WOW64_32KEY = 512;
		}

		internal class RegistryOperations
		{
			internal const int KEY_QUERY_VALUE = 1;

			internal const int KEY_SET_VALUE = 2;

			internal const int KEY_CREATE_SUB_KEY = 4;

			internal const int KEY_ENUMERATE_SUB_KEYS = 8;

			internal const int KEY_NOTIFY = 16;

			internal const int KEY_CREATE_LINK = 32;

			internal const int KEY_READ = 131097;

			internal const int KEY_WRITE = 131078;

			internal const int SYNCHRONIZE = 1048576;

			internal const int READ_CONTROL = 131072;

			internal const int STANDARD_RIGHTS_READ = 131072;

			internal const int STANDARD_RIGHTS_WRITE = 131072;
		}

		internal class RegistryValues
		{
			internal const int REG_NONE = 0;

			internal const int REG_SZ = 1;

			internal const int REG_EXPAND_SZ = 2;

			internal const int REG_BINARY = 3;

			internal const int REG_DWORD = 4;

			internal const int REG_DWORD_LITTLE_ENDIAN = 4;

			internal const int REG_DWORD_BIG_ENDIAN = 5;

			internal const int REG_LINK = 6;

			internal const int REG_MULTI_SZ = 7;

			internal const int REG_QWORD = 11;
		}

		[DllImport("advapi32.dll")]
		internal static extern int RegCloseKey(IntPtr hKey);

		[DllImport("advapi32.dll", BestFitMapping = false, CharSet = CharSet.Unicode, EntryPoint = "RegConnectRegistryW")]
		internal static extern int RegConnectRegistry(string machineName, SafeRegistryHandle key, out SafeRegistryHandle result);

		[DllImport("advapi32.dll", BestFitMapping = false, CharSet = CharSet.Unicode, EntryPoint = "RegCreateKeyExW")]
		internal static extern int RegCreateKeyEx(SafeRegistryHandle hKey, string lpSubKey, int Reserved, string lpClass, int dwOptions, int samDesired, ref Kernel32.SECURITY_ATTRIBUTES secAttrs, out SafeRegistryHandle hkResult, out int lpdwDisposition);

		[DllImport("advapi32.dll", BestFitMapping = false, CharSet = CharSet.Unicode, EntryPoint = "RegDeleteKeyExW")]
		internal static extern int RegDeleteKeyEx(SafeRegistryHandle hKey, string lpSubKey, int samDesired, int Reserved);

		[DllImport("advapi32.dll", BestFitMapping = false, CharSet = CharSet.Unicode, EntryPoint = "RegDeleteValueW")]
		internal static extern int RegDeleteValue(SafeRegistryHandle hKey, string lpValueName);

		[DllImport("advapi32.dll", BestFitMapping = false, CharSet = CharSet.Unicode, EntryPoint = "RegEnumKeyExW")]
		internal static extern int RegEnumKeyEx(SafeRegistryHandle hKey, int dwIndex, char[] lpName, ref int lpcbName, int[] lpReserved, [Out] StringBuilder lpClass, int[] lpcbClass, long[] lpftLastWriteTime);

		[DllImport("advapi32.dll", BestFitMapping = false, CharSet = CharSet.Unicode, EntryPoint = "RegEnumValueW")]
		internal static extern int RegEnumValue(SafeRegistryHandle hKey, int dwIndex, char[] lpValueName, ref int lpcbValueName, IntPtr lpReserved_MustBeZero, int[] lpType, byte[] lpData, int[] lpcbData);

		[DllImport("advapi32.dll")]
		internal static extern int RegFlushKey(SafeRegistryHandle hKey);

		[DllImport("advapi32.dll", BestFitMapping = false, CharSet = CharSet.Unicode, EntryPoint = "RegOpenKeyExW")]
		internal static extern int RegOpenKeyEx(SafeRegistryHandle hKey, string lpSubKey, int ulOptions, int samDesired, out SafeRegistryHandle hkResult);

		[DllImport("advapi32.dll", BestFitMapping = false, CharSet = CharSet.Unicode, EntryPoint = "RegOpenKeyExW")]
		internal static extern int RegOpenKeyEx(IntPtr hKey, string lpSubKey, int ulOptions, int samDesired, out SafeRegistryHandle hkResult);

		[DllImport("advapi32.dll", BestFitMapping = false, CharSet = CharSet.Unicode, EntryPoint = "RegQueryInfoKeyW")]
		internal static extern int RegQueryInfoKey(SafeRegistryHandle hKey, [Out] StringBuilder lpClass, int[] lpcbClass, IntPtr lpReserved_MustBeZero, ref int lpcSubKeys, int[] lpcbMaxSubKeyLen, int[] lpcbMaxClassLen, ref int lpcValues, int[] lpcbMaxValueNameLen, int[] lpcbMaxValueLen, int[] lpcbSecurityDescriptor, int[] lpftLastWriteTime);

		[DllImport("advapi32.dll", BestFitMapping = false, CharSet = CharSet.Unicode, EntryPoint = "RegQueryValueExW")]
		internal static extern int RegQueryValueEx(SafeRegistryHandle hKey, string lpValueName, int[] lpReserved, ref int lpType, [Out] byte[] lpData, ref int lpcbData);

		[DllImport("advapi32.dll", BestFitMapping = false, CharSet = CharSet.Unicode, EntryPoint = "RegQueryValueExW")]
		internal static extern int RegQueryValueEx(SafeRegistryHandle hKey, string lpValueName, int[] lpReserved, ref int lpType, ref int lpData, ref int lpcbData);

		[DllImport("advapi32.dll", BestFitMapping = false, CharSet = CharSet.Unicode, EntryPoint = "RegQueryValueExW")]
		internal static extern int RegQueryValueEx(SafeRegistryHandle hKey, string lpValueName, int[] lpReserved, ref int lpType, ref long lpData, ref int lpcbData);

		[DllImport("advapi32.dll", BestFitMapping = false, CharSet = CharSet.Unicode, EntryPoint = "RegQueryValueExW")]
		internal static extern int RegQueryValueEx(SafeRegistryHandle hKey, string lpValueName, int[] lpReserved, ref int lpType, [Out] char[] lpData, ref int lpcbData);

		[DllImport("advapi32.dll", BestFitMapping = false, CharSet = CharSet.Unicode, EntryPoint = "RegQueryValueExW")]
		internal static extern int RegQueryValueEx(SafeRegistryHandle hKey, string lpValueName, int[] lpReserved, ref int lpType, [Out] StringBuilder lpData, ref int lpcbData);

		[DllImport("advapi32.dll", BestFitMapping = false, CharSet = CharSet.Unicode, EntryPoint = "RegSetValueExW")]
		internal static extern int RegSetValueEx(SafeRegistryHandle hKey, string lpValueName, int Reserved, RegistryValueKind dwType, byte[] lpData, int cbData);

		[DllImport("advapi32.dll", BestFitMapping = false, CharSet = CharSet.Unicode, EntryPoint = "RegSetValueExW")]
		internal static extern int RegSetValueEx(SafeRegistryHandle hKey, string lpValueName, int Reserved, RegistryValueKind dwType, char[] lpData, int cbData);

		[DllImport("advapi32.dll", BestFitMapping = false, CharSet = CharSet.Unicode, EntryPoint = "RegSetValueExW")]
		internal static extern int RegSetValueEx(SafeRegistryHandle hKey, string lpValueName, int Reserved, RegistryValueKind dwType, ref int lpData, int cbData);

		[DllImport("advapi32.dll", BestFitMapping = false, CharSet = CharSet.Unicode, EntryPoint = "RegSetValueExW")]
		internal static extern int RegSetValueEx(SafeRegistryHandle hKey, string lpValueName, int Reserved, RegistryValueKind dwType, ref long lpData, int cbData);

		[DllImport("advapi32.dll", BestFitMapping = false, CharSet = CharSet.Unicode, EntryPoint = "RegSetValueExW")]
		internal static extern int RegSetValueEx(SafeRegistryHandle hKey, string lpValueName, int Reserved, RegistryValueKind dwType, string lpData, int cbData);

		[DllImport("advapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
		public static extern IntPtr RegisterServiceCtrlHandler(string serviceName, Delegate callback);

		[DllImport("advapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
		public static extern IntPtr RegisterServiceCtrlHandlerEx(string serviceName, Delegate callback, IntPtr userData);
	}

	internal static class mincore
	{
		[DllImport("api-ms-win-core-heap-l1-1-0.dll")]
		internal static extern IntPtr GetProcessHeap();

		[DllImport("api-ms-win-core-heap-l1-1-0.dll")]
		internal static extern IntPtr HeapAlloc(IntPtr hHeap, uint dwFlags, UIntPtr dwBytes);

		[DllImport("api-ms-win-core-heap-l1-1-0.dll")]
		internal static extern int HeapFree(IntPtr hHeap, uint dwFlags, IntPtr lpMem);

		[DllImport("api-ms-win-core-threadpool-l1-2-0.dll", SetLastError = true)]
		internal static extern SafeThreadPoolIOHandle CreateThreadpoolIo(SafeHandle fl, IntPtr pfnio, IntPtr context, IntPtr pcbe);

		[DllImport("api-ms-win-core-threadpool-l1-2-0.dll")]
		internal static extern void CloseThreadpoolIo(IntPtr pio);

		[DllImport("api-ms-win-core-threadpool-l1-2-0.dll")]
		internal static extern void StartThreadpoolIo(SafeThreadPoolIOHandle pio);

		[DllImport("api-ms-win-core-threadpool-l1-2-0.dll")]
		internal static extern void CancelThreadpoolIo(SafeThreadPoolIOHandle pio);
	}

	internal delegate void NativeIoCompletionCallback(IntPtr instance, IntPtr context, IntPtr overlapped, uint ioResult, UIntPtr numberOfBytesTransferred, IntPtr io);

	internal unsafe static void GetRandomBytes(byte* buffer, int length)
	{
		switch (BCrypt.BCryptGenRandom(IntPtr.Zero, buffer, length, 2))
		{
		case BCrypt.NTSTATUS.STATUS_NO_MEMORY:
			throw new OutOfMemoryException();
		default:
			throw new InvalidOperationException();
		case BCrypt.NTSTATUS.STATUS_SUCCESS:
			break;
		}
	}

	internal static IntPtr MemAlloc(UIntPtr sizeInBytes)
	{
		IntPtr intPtr = mincore.HeapAlloc(mincore.GetProcessHeap(), 0u, sizeInBytes);
		if (intPtr == IntPtr.Zero)
		{
			throw new OutOfMemoryException();
		}
		return intPtr;
	}

	internal static void MemFree(IntPtr allocatedMemory)
	{
		mincore.HeapFree(mincore.GetProcessHeap(), 0u, allocatedMemory);
	}
}
internal static class AssemblyRef
{
	internal const string SystemConfiguration = "System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	internal const string System = "System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";

	public const string EcmaPublicKey = "b77a5c561934e089";

	public const string FrameworkPublicKeyFull = "00000000000000000400000000000000";

	public const string FrameworkPublicKeyFull2 = "00000000000000000400000000000000";

	public const string MicrosoftPublicKey = "b03f5f7f11d50a3a";

	public const string MicrosoftJScript = "Microsoft.JScript, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string MicrosoftVSDesigner = "Microsoft.VSDesigner, Version=0.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string SystemData = "System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string SystemDesign = "System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string SystemDrawing = "System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string SystemWeb = "System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string SystemWebExtensions = "System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";

	public const string SystemWindowsForms = "System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";
}
internal static class Consts
{
	public const string MonoCorlibVersion = "1A5E0066-58DC-428A-B21C-0AD6CDAE2789";

	public const string MonoVersion = "6.13.0.0";

	public const string MonoCompany = "Mono development team";

	public const string MonoProduct = "Mono Common Language Infrastructure";

	public const string MonoCopyright = "(c) Various Mono authors";

	public const string FxVersion = "4.0.0.0";

	public const string FxFileVersion = "4.6.57.0";

	public const string EnvironmentVersion = "4.0.30319.42000";

	public const string VsVersion = "0.0.0.0";

	public const string VsFileVersion = "11.0.0.0";

	private const string PublicKeyToken = "b77a5c561934e089";

	public const string AssemblyI18N = "I18N, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756";

	public const string AssemblyMicrosoft_JScript = "Microsoft.JScript, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblyMicrosoft_VisualStudio = "Microsoft.VisualStudio, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblyMicrosoft_VisualStudio_Web = "Microsoft.VisualStudio.Web, Version=0.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblyMicrosoft_VSDesigner = "Microsoft.VSDesigner, Version=0.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblyMono_Http = "Mono.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756";

	public const string AssemblyMono_Posix = "Mono.Posix, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756";

	public const string AssemblyMono_Security = "Mono.Security, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756";

	public const string AssemblyMono_Messaging_RabbitMQ = "Mono.Messaging.RabbitMQ, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756";

	public const string AssemblyCorlib = "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string AssemblySystem = "System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string AssemblySystem_Data = "System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string AssemblySystem_Design = "System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_DirectoryServices = "System.DirectoryServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_Drawing = "System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_Drawing_Design = "System.Drawing.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_Messaging = "System.Messaging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_Security = "System.Security, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_ServiceProcess = "System.ServiceProcess, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_Web = "System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_Windows_Forms = "System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string AssemblySystem_2_0 = "System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string AssemblySystemCore_3_5 = "System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string AssemblySystem_Core = "System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string WindowsBase_3_0 = "WindowsBase, Version=3.0.0.0, PublicKeyToken=31bf3856ad364e35";

	public const string AssemblyWindowsBase = "WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";

	public const string AssemblyPresentationCore_3_5 = "PresentationCore, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";

	public const string AssemblyPresentationCore_4_0 = "PresentationCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";

	public const string AssemblyPresentationFramework_3_5 = "PresentationFramework, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";

	public const string AssemblySystemServiceModel_3_0 = "System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";
}
internal sealed class Locale
{
	private Locale()
	{
	}

	public static string GetText(string msg)
	{
		return msg;
	}

	public static string GetText(string fmt, params object[] args)
	{
		return string.Format(fmt, args);
	}
}
internal static class SR
{
	public const string RTL = "RTL_False";

	public const string ContinueButtonText = "Continue";

	public const string DebugMessageTruncated = "{0}...\n<truncated>";

	public const string DebugAssertTitleShort = "Assertion Failed";

	public const string DebugAssertTitle = "Assertion Failed: Cancel=Debug, OK=Continue";

	public const string NotSupported = "This operation is not supported.";

	public const string DebugLaunchFailed = "Cannot launch the debugger.  Make sure that a Microsoft (R) .NET Framework debugger is properly installed.";

	public const string DebugLaunchFailedTitle = "Microsoft .NET Framework Debug Launch Failure";

	public const string ObjectDisposed = "Object {0} has been disposed and can no longer be used.";

	public const string ExceptionOccurred = "An exception occurred writing trace output to log file '{0}'. {1}";

	public const string MustAddListener = "Only TraceListeners can be added to a TraceListenerCollection.";

	public const string ToStringNull = "(null)";

	public const string EnumConverterInvalidValue = "The value '{0}' is not a valid value for the enum '{1}'.";

	public const string ConvertFromException = "{0} cannot convert from {1}.";

	public const string ConvertToException = "'{0}' is unable to convert '{1}' to '{2}'.";

	public const string ConvertInvalidPrimitive = "{0} is not a valid value for {1}.";

	public const string ErrorMissingPropertyAccessors = "Accessor methods for the {0} property are missing.";

	public const string ErrorInvalidPropertyType = "Invalid type for the {0} property.";

	public const string ErrorMissingEventAccessors = "Accessor methods for the {0} event are missing.";

	public const string ErrorInvalidEventHandler = "Invalid event handler for the {0} event.";

	public const string ErrorInvalidEventType = "Invalid type for the {0} event.";

	public const string InvalidMemberName = "Invalid member name.";

	public const string ErrorBadExtenderType = "The {0} extender provider is not compatible with the {1} type.";

	public const string NullableConverterBadCtorArg = "The specified type is not a nullable type.";

	public const string TypeDescriptorExpectedElementType = "Expected types in the collection to be of type {0}.";

	public const string TypeDescriptorSameAssociation = "Cannot create an association when the primary and secondary objects are the same.";

	public const string TypeDescriptorAlreadyAssociated = "The primary and secondary objects are already associated with each other.";

	public const string TypeDescriptorProviderError = "The type description provider {0} has returned null from {1} which is illegal.";

	public const string TypeDescriptorUnsupportedRemoteObject = "The object {0} is being remoted by a proxy that does not support interface discovery.  This type of remoted object is not supported.";

	public const string TypeDescriptorArgsCountMismatch = "The number of elements in the Type and Object arrays must match.";

	public const string ErrorCreateSystemEvents = "Failed to create system events window thread.";

	public const string ErrorCreateTimer = "Cannot create timer.";

	public const string ErrorKillTimer = "Cannot end timer.";

	public const string ErrorSystemEventsNotSupported = "System event notifications are not supported under the current context. Server processes, for example, may not support global system event notifications.";

	public const string ErrorGetTempPath = "Cannot get temporary file name";

	public const string CHECKOUTCanceled = "The checkout was canceled by the user.";

	public const string ErrorInvalidServiceInstance = "The service instance must derive from or implement {0}.";

	public const string ErrorServiceExists = "The service {0} already exists in the service container.";

	public const string Argument_InvalidNumberStyles = "An undefined NumberStyles value is being used.";

	public const string Argument_InvalidHexStyle = "With the AllowHexSpecifier bit set in the enum bit field, the only other valid bits that can be combined into the enum value must be a subset of those in HexNumber.";

	public const string Argument_ByteArrayLengthMustBeAMultipleOf4 = "The Byte[] length must be a multiple of 4.";

	public const string Argument_InvalidCharactersInString = "The string contained an invalid character.";

	public const string Argument_ParsedStringWasInvalid = "The parsed string was invalid.";

	public const string Argument_MustBeBigInt = "The parameter must be a BigInteger.";

	public const string Format_InvalidFormatSpecifier = "Format specifier was invalid.";

	public const string Format_TooLarge = "The value is too large to be represented by this format specifier.";

	public const string ArgumentOutOfRange_MustBeLessThanUInt32MaxValue = "The value must be less than UInt32.MaxValue (2^32).";

	public const string ArgumentOutOfRange_MustBeNonNeg = "The number must be greater than or equal to zero.";

	public const string NotSupported_NumberStyle = "The NumberStyle option is not supported.";

	public const string Overflow_BigIntInfinity = "BigInteger cannot represent infinity.";

	public const string Overflow_NotANumber = "The value is not a number.";

	public const string Overflow_ParseBigInteger = "The value could not be parsed.";

	public const string Overflow_Int32 = "Value was either too large or too small for an Int32.";

	public const string Overflow_Int64 = "Value was either too large or too small for an Int64.";

	public const string Overflow_UInt32 = "Value was either too large or too small for a UInt32.";

	public const string Overflow_UInt64 = "Value was either too large or too small for a UInt64.";

	public const string Overflow_Decimal = "Value was either too large or too small for a Decimal.";

	public const string Argument_FrameworkNameTooShort = "FrameworkName cannot have less than two components or more than three components.";

	public const string Argument_FrameworkNameInvalid = "FrameworkName is invalid.";

	public const string Argument_FrameworkNameInvalidVersion = "FrameworkName version component is invalid.";

	public const string Argument_FrameworkNameMissingVersion = "FrameworkName version component is missing.";

	public const string ArgumentNull_Key = "Key cannot be null.";

	public const string Argument_InvalidValue = "Argument {0} should be larger than {1}.";

	public const string Arg_MultiRank = "Multi dimension array is not supported on this operation.";

	public const string Barrier_ctor_ArgumentOutOfRange = "The participantCount argument must be non-negative and less than or equal to 32767.";

	public const string Barrier_AddParticipants_NonPositive_ArgumentOutOfRange = "The participantCount argument must be a positive value.";

	public const string Barrier_AddParticipants_Overflow_ArgumentOutOfRange = "Adding participantCount participants would result in the number of participants exceeding the maximum number allowed.";

	public const string Barrier_InvalidOperation_CalledFromPHA = "This method may not be called from within the postPhaseAction.";

	public const string Barrier_RemoveParticipants_NonPositive_ArgumentOutOfRange = "The participantCount argument must be a positive value.";

	public const string Barrier_RemoveParticipants_ArgumentOutOfRange = "The participantCount argument must be less than or equal the number of participants.";

	public const string Barrier_RemoveParticipants_InvalidOperation = "The participantCount argument is greater than the number of participants that haven't yet arrived at the barrier in this phase.";

	public const string Barrier_SignalAndWait_ArgumentOutOfRange = "The specified timeout must represent a value between -1 and Int32.MaxValue, inclusive.";

	public const string Barrier_SignalAndWait_InvalidOperation_ZeroTotal = "The barrier has no registered participants.";

	public const string Barrier_SignalAndWait_InvalidOperation_ThreadsExceeded = "The number of threads using the barrier exceeded the total number of registered participants.";

	public const string Barrier_Dispose = "The barrier has been disposed.";

	public const string BarrierPostPhaseException = "The postPhaseAction failed with an exception.";

	public const string UriTypeConverter_ConvertFrom_CannotConvert = "{0} cannot convert from {1}.";

	public const string UriTypeConverter_ConvertTo_CannotConvert = "{0} cannot convert {1} to {2}.";

	public const string ISupportInitializeDescr = "Specifies support for transacted initialization.";

	public const string CantModifyListSortDescriptionCollection = "Once a ListSortDescriptionCollection has been created it can't be modified.";

	public const string Argument_NullComment = "The 'Comment' property of the CodeCommentStatement '{0}' cannot be null.";

	public const string InvalidPrimitiveType = "Invalid Primitive Type: {0}. Consider using CodeObjectCreateExpression.";

	public const string Cannot_Specify_Both_Compiler_Path_And_Version = "Cannot specify both the '{0}' and '{1}' CodeDom provider options to choose a compiler. Please remove one of them.";

	public const string CodeGenOutputWriter = "The output writer for code generation and the writer supplied don't match and cannot be used. This is generally caused by a bad implementation of a CodeGenerator derived class.";

	public const string CodeGenReentrance = "This code generation API cannot be called while the generator is being used to generate something else.";

	public const string InvalidLanguageIdentifier = "The identifier:\"{0}\" on the property:\"{1}\" of type:\"{2}\" is not a valid language-independent identifier name. Check to see if CodeGenerator.IsValidLanguageIndependentIdentifier allows the identifier name.";

	public const string InvalidTypeName = "The type name:\"{0}\" on the property:\"{1}\" of type:\"{2}\" is not a valid language-independent type name.";

	public const string Empty_attribute = "The '{0}' attribute cannot be an empty string.";

	public const string Invalid_nonnegative_integer_attribute = "The '{0}' attribute must be a non-negative integer.";

	public const string CodeDomProvider_NotDefined = "There is no CodeDom provider defined for the language.";

	public const string Language_Names_Cannot_Be_Empty = "You need to specify a non-empty String for a language name in the CodeDom configuration section.";

	public const string Extension_Names_Cannot_Be_Empty_Or_Non_Period_Based = "An extension name in the CodeDom configuration section must be a non-empty string which starts with a period.";

	public const string Unable_To_Locate_Type = "The CodeDom provider type \"{0}\" could not be located.";

	public const string NotSupported_CodeDomAPI = "This CodeDomProvider does not support this method.";

	public const string ArityDoesntMatch = "The total arity specified in '{0}' does not match the number of TypeArguments supplied.  There were '{1}' TypeArguments supplied.";

	public const string PartialTrustErrorTextReplacement = "<The original value of this property potentially contains file system information and has been suppressed.>";

	public const string PartialTrustIllegalProvider = "When used in partial trust, langID must be C#, VB, J#, or JScript, and the language provider must be in the global assembly cache.";

	public const string IllegalAssemblyReference = "Assembly references cannot begin with '-', or contain a '/' or '\\'.";

	public const string NullOrEmpty_Value_in_Property = "The '{0}' property cannot contain null or empty strings.";

	public const string AutoGen_Comment_Line1 = "auto-generated>";

	public const string AutoGen_Comment_Line2 = "This code was generated by a tool.";

	public const string AutoGen_Comment_Line3 = "Runtime Version:";

	public const string AutoGen_Comment_Line4 = "Changes to this file may cause incorrect behavior and will be lost if";

	public const string AutoGen_Comment_Line5 = "the code is regenerated.";

	public const string CantContainNullEntries = "Array '{0}' cannot contain null entries.";

	public const string InvalidPathCharsInChecksum = "The CodeChecksumPragma file name '{0}' contains invalid path characters.";

	public const string InvalidRegion = "The region directive '{0}' contains invalid characters.  RegionText cannot contain any new line characters.";

	public const string Provider_does_not_support_options = "This CodeDomProvider type does not have a constructor that takes providerOptions - \"{0}\"";

	public const string MetaExtenderName = "{0} on {1}";

	public const string InvalidEnumArgument = "The value of argument '{0}' ({1}) is invalid for Enum type '{2}'.";

	public const string InvalidArgument = "'{1}' is not a valid value for '{0}'.";

	public const string InvalidNullArgument = "Null is not a valid value for {0}.";

	public const string LicExceptionTypeOnly = "A valid license cannot be granted for the type {0}. Contact the manufacturer of the component for more information.";

	public const string LicExceptionTypeAndInstance = "An instance of type '{1}' was being created, and a valid license could not be granted for the type '{0}'. Please,  contact the manufacturer of the component for more information.";

	public const string LicMgrContextCannotBeChanged = "The CurrentContext property of the LicenseManager is currently locked and cannot be changed.";

	public const string LicMgrAlreadyLocked = "The CurrentContext property of the LicenseManager is already locked by another user.";

	public const string LicMgrDifferentUser = "The CurrentContext property of the LicenseManager can only be unlocked with the same contextUser.";

	public const string InvalidElementType = "Element type {0} is not supported.";

	public const string InvalidIdentifier = "Identifier '{0}' is not valid.";

	public const string ExecFailedToCreate = "Failed to create file {0}.";

	public const string ExecTimeout = "Timed out waiting for a program to execute. The command being executed was {0}.";

	public const string ExecBadreturn = "An invalid return code was encountered waiting for a program to execute. The command being executed was {0}.";

	public const string ExecCantGetRetCode = "Unable to get the return code for a program being executed. The command that was being executed was '{0}'.";

	public const string ExecCantExec = "Cannot execute a program. The command being executed was {0}.";

	public const string ExecCantRevert = "Cannot execute a program. Impersonation failed.";

	public const string CompilerNotFound = "Compiler executable file {0} cannot be found.";

	public const string DuplicateFileName = "The file name '{0}' was already in the collection.";

	public const string CollectionReadOnly = "Collection is read-only.";

	public const string BitVectorFull = "Bit vector is full.";

	public const string ArrayConverterText = "{0} Array";

	public const string CollectionConverterText = "(Collection)";

	public const string MultilineStringConverterText = "(Text)";

	public const string CultureInfoConverterDefaultCultureString = "(Default)";

	public const string CultureInfoConverterInvalidCulture = "The {0} culture cannot be converted to a CultureInfo object on this computer.";

	public const string InvalidPrimitive = "The text {0} is not a valid {1}.";

	public const string TimerInvalidInterval = "'{0}' is not a valid value for 'Interval'. 'Interval' must be greater than {1}.";

	public const string TraceSwitchLevelTooHigh = "Attempted to set {0} to a value that is too high.  Setting level to TraceLevel.Verbose";

	public const string TraceSwitchLevelTooLow = "Attempted to set {0} to a value that is too low.  Setting level to TraceLevel.Off";

	public const string TraceSwitchInvalidLevel = "The Level must be set to a value in the enumeration TraceLevel.";

	public const string TraceListenerIndentSize = "The IndentSize property must be non-negative.";

	public const string TraceListenerFail = "Fail:";

	public const string TraceAsTraceSource = "Trace";

	public const string InvalidLowBoundArgument = "'{1}' is not a valid value for '{0}'. '{0}' must be greater than {2}.";

	public const string DuplicateComponentName = "Duplicate component name '{0}'.  Component names must be unique and case-insensitive.";

	public const string NotImplemented = "{0}: Not implemented";

	public const string OutOfMemory = "Could not allocate needed memory.";

	public const string EOF = "End of data stream encountered.";

	public const string IOError = "Unknown input/output failure.";

	public const string BadChar = "Unexpected Character: '{0}'.";

	public const string toStringNone = "(none)";

	public const string toStringUnknown = "(unknown)";

	public const string InvalidEnum = "{0} is not a valid {1} value.";

	public const string IndexOutOfRange = "Index {0} is out of range.";

	public const string ErrorPropertyAccessorException = "Property accessor '{0}' on object '{1}' threw the following exception:'{2}'";

	public const string InvalidOperation = "Invalid operation.";

	public const string EmptyStack = "Stack has no items in it.";

	public const string PerformanceCounterDesc = "Represents a Windows performance counter component.";

	public const string PCCategoryName = "Category name of the performance counter object.";

	public const string PCCounterName = "Counter name of the performance counter object.";

	public const string PCInstanceName = "Instance name of the performance counter object.";

	public const string PCMachineName = "Specifies the machine from where to read the performance data.";

	public const string PCInstanceLifetime = "Specifies the lifetime of the instance.";

	public const string PropertyCategoryAction = "Action";

	public const string PropertyCategoryAppearance = "Appearance";

	public const string PropertyCategoryAsynchronous = "Asynchronous";

	public const string PropertyCategoryBehavior = "Behavior";

	public const string PropertyCategoryData = "Data";

	public const string PropertyCategoryDDE = "DDE";

	public const string PropertyCategoryDesign = "Design";

	public const string PropertyCategoryDragDrop = "Drag Drop";

	public const string PropertyCategoryFocus = "Focus";

	public const string PropertyCategoryFont = "Font";

	public const string PropertyCategoryFormat = "Format";

	public const string PropertyCategoryKey = "Key";

	public const string PropertyCategoryList = "List";

	public const string PropertyCategoryLayout = "Layout";

	public const string PropertyCategoryDefault = "Misc";

	public const string PropertyCategoryMouse = "Mouse";

	public const string PropertyCategoryPosition = "Position";

	public const string PropertyCategoryText = "Text";

	public const string PropertyCategoryScale = "Scale";

	public const string PropertyCategoryWindowStyle = "Window Style";

	public const string PropertyCategoryConfig = "Configurations";

	public const string ArgumentNull_ArrayWithNullElements = "The array cannot contain null elements.";

	public const string OnlyAllowedOnce = "This operation is only allowed once per object.";

	public const string BeginIndexNotNegative = "Start index cannot be less than 0 or greater than input length.";

	public const string LengthNotNegative = "Length cannot be less than 0 or exceed input length.";

	public const string UnimplementedState = "Unimplemented state.";

	public const string UnexpectedOpcode = "Unexpected opcode in regular expression generation: {0}.";

	public const string NoResultOnFailed = "Result cannot be called on a failed Match.";

	public const string UnterminatedBracket = "Unterminated [] set.";

	public const string TooManyParens = "Too many )'s.";

	public const string NestedQuantify = "Nested quantifier {0}.";

	public const string QuantifyAfterNothing = "Quantifier {x,y} following nothing.";

	public const string InternalError = "Internal error in ScanRegex.";

	public const string IllegalRange = "Illegal {x,y} with x > y.";

	public const string NotEnoughParens = "Not enough )'s.";

	public const string BadClassInCharRange = "Cannot include class \\{0} in character range.";

	public const string ReversedCharRange = "[x-y] range in reverse order.";

	public const string UndefinedReference = "(?({0}) ) reference to undefined group.";

	public const string MalformedReference = "(?({0}) ) malformed.";

	public const string UnrecognizedGrouping = "Unrecognized grouping construct.";

	public const string UnterminatedComment = "Unterminated (?#...) comment.";

	public const string IllegalEndEscape = "Illegal \\ at end of pattern.";

	public const string MalformedNameRef = "Malformed \\k<...> named back reference.";

	public const string UndefinedBackref = "Reference to undefined group number {0}.";

	public const string UndefinedNameRef = "Reference to undefined group name {0}.";

	public const string TooFewHex = "Insufficient hexadecimal digits.";

	public const string MissingControl = "Missing control character.";

	public const string UnrecognizedControl = "Unrecognized control character.";

	public const string UnrecognizedEscape = "Unrecognized escape sequence \\{0}.";

	public const string IllegalCondition = "Illegal conditional (?(...)) expression.";

	public const string TooManyAlternates = "Too many | in (?()|).";

	public const string MakeException = "parsing \"{0}\" - {1}";

	public const string IncompleteSlashP = "Incomplete \\p{X} character escape.";

	public const string MalformedSlashP = "Malformed \\p{X} character escape.";

	public const string InvalidGroupName = "Invalid group name: Group names must begin with a word character.";

	public const string CapnumNotZero = "Capture number cannot be zero.";

	public const string AlternationCantCapture = "Alternation conditions do not capture and cannot be named.";

	public const string AlternationCantHaveComment = "Alternation conditions cannot be comments.";

	public const string CaptureGroupOutOfRange = "Capture group numbers must be less than or equal to Int32.MaxValue.";

	public const string SubtractionMustBeLast = "A subtraction must be the last element in a character class.";

	public const string UnknownProperty = "Unknown property '{0}'.";

	public const string ReplacementError = "Replacement pattern error.";

	public const string CountTooSmall = "Count cannot be less than -1.";

	public const string EnumNotStarted = "Enumeration has either not started or has already finished.";

	public const string Arg_InvalidArrayType = "Target array type is not compatible with the type of items in the collection.";

	public const string RegexMatchTimeoutException_Occurred = "The RegEx engine has timed out while trying to match a pattern to an input string. This can occur for many reasons, including very large inputs or excessive backtracking caused by nested quantifiers, back-references and other factors.";

	public const string IllegalDefaultRegexMatchTimeoutInAppDomain = "AppDomain data '{0}' contains an invalid value or object for specifying a default matching timeout for System.Text.RegularExpressions.Regex.";

	public const string FileObject_AlreadyOpen = "The file is already open.  Call Close before trying to open the FileObject again.";

	public const string FileObject_Closed = "The FileObject is currently closed.  Try opening it.";

	public const string FileObject_NotWhileWriting = "File information cannot be queried while open for writing.";

	public const string FileObject_FileDoesNotExist = "File information cannot be queried if the file does not exist.";

	public const string FileObject_MustBeClosed = "This operation can only be done when the FileObject is closed.";

	public const string FileObject_MustBeFileName = "You must specify a file name, not a relative or absolute path.";

	public const string FileObject_InvalidInternalState = "FileObject's open mode wasn't set to a valid value.  This FileObject is corrupt.";

	public const string FileObject_PathNotSet = "The path has not been set, or is an empty string.  Please ensure you specify some path.";

	public const string FileObject_Reading = "The file is currently open for reading.  Close the file and reopen it before attempting this.";

	public const string FileObject_Writing = "The file is currently open for writing.  Close the file and reopen it before attempting this.";

	public const string FileObject_InvalidEnumeration = "Enumerator is positioned before the first line or after the last line of the file.";

	public const string FileObject_NoReset = "Reset is not supported on a FileLineEnumerator.";

	public const string DirectoryObject_MustBeDirName = "You must specify a directory name, not a relative or absolute path.";

	public const string DirectoryObjectPathDescr = "The fully qualified, or relative path to the directory you wish to read from. E.g., \"c:\\temp\".";

	public const string FileObjectDetectEncodingDescr = "Determines whether the file will be parsed to see if it has a byte order mark indicating its encoding.  If it does, this will be used rather than the current specified encoding.";

	public const string FileObjectEncodingDescr = "The encoding to use when reading the file. UTF-8 is the default.";

	public const string FileObjectPathDescr = "The fully qualified, or relative path to the file you wish to read from. E.g., \"myfile.txt\".";

	public const string Arg_EnumIllegalVal = "Illegal enum value: {0}.";

	public const string Arg_OutOfRange_NeedNonNegNum = "Non-negative number required.";

	public const string Argument_InvalidPermissionState = "Invalid permission state.";

	public const string Argument_InvalidOidValue = "The OID value was invalid.";

	public const string Argument_WrongType = "Operation on type '{0}' attempted with target of incorrect type.";

	public const string Arg_EmptyOrNullString = "String cannot be empty or null.";

	public const string Arg_EmptyOrNullArray = "Array cannot be empty or null.";

	public const string Argument_InvalidClassAttribute = "The value of \"class\" attribute is invalid.";

	public const string Argument_InvalidNameType = "The value of \"nameType\" is invalid.";

	public const string InvalidOperation_DuplicateItemNotAllowed = "Duplicate items are not allowed in the collection.";

	public const string Cryptography_Asn_MismatchedOidInCollection = "The AsnEncodedData object does not have the same OID for the collection.";

	public const string Cryptography_Cms_Envelope_Empty_Content = "Cannot create CMS enveloped for empty content.";

	public const string Cryptography_Cms_Invalid_Recipient_Info_Type = "The recipient info type {0} is not valid.";

	public const string Cryptography_Cms_Invalid_Subject_Identifier_Type = "The subject identifier type {0} is not valid.";

	public const string Cryptography_Cms_Invalid_Subject_Identifier_Type_Value_Mismatch = "The subject identifier type {0} does not match the value data type {1}.";

	public const string Cryptography_Cms_Key_Agree_Date_Not_Available = "The Date property is not available for none KID key agree recipient.";

	public const string Cryptography_Cms_Key_Agree_Other_Key_Attribute_Not_Available = "The OtherKeyAttribute property is not available for none KID key agree recipient.";

	public const string Cryptography_Cms_MessageNotSigned = "The CMS message is not signed.";

	public const string Cryptography_Cms_MessageNotSignedByNoSignature = "The CMS message is not signed by NoSignature.";

	public const string Cryptography_Cms_MessageNotEncrypted = "The CMS message is not encrypted.";

	public const string Cryptography_Cms_Not_Supported = "The Cryptographic Message Standard (CMS) is not supported on this platform.";

	public const string Cryptography_Cms_RecipientCertificateNotFound = "The recipient certificate is not specified.";

	public const string Cryptography_Cms_Sign_Empty_Content = "Cannot create CMS signature for empty content.";

	public const string Cryptography_Cms_Sign_No_Signature_First_Signer = "CmsSigner has to be the first signer with NoSignature.";

	public const string Cryptography_DpApi_InvalidMemoryLength = "The length of the data should be a multiple of 16 bytes.";

	public const string Cryptography_InvalidHandle = "{0} is an invalid handle.";

	public const string Cryptography_InvalidContextHandle = "The chain context handle is invalid.";

	public const string Cryptography_InvalidStoreHandle = "The store handle is invalid.";

	public const string Cryptography_Oid_InvalidValue = "The OID value is invalid.";

	public const string Cryptography_Pkcs9_ExplicitAddNotAllowed = "The PKCS 9 attribute cannot be explicitly added to the collection.";

	public const string Cryptography_Pkcs9_InvalidOid = "The OID does not represent a valid PKCS 9 attribute.";

	public const string Cryptography_Pkcs9_MultipleSigningTimeNotAllowed = "Cannot add multiple PKCS 9 signing time attributes.";

	public const string Cryptography_Pkcs9_AttributeMismatch = "The parameter should be a PKCS 9 attribute.";

	public const string Cryptography_X509_AddFailed = "Adding certificate with index '{0}' failed.";

	public const string Cryptography_X509_BadEncoding = "Input data cannot be coded as a valid certificate.";

	public const string Cryptography_X509_ExportFailed = "The certificate export operation failed.";

	public const string Cryptography_X509_ExtensionMismatch = "The parameter should be an X509Extension.";

	public const string Cryptography_X509_InvalidFindType = "Invalid find type.";

	public const string Cryptography_X509_InvalidFindValue = "Invalid find value.";

	public const string Cryptography_X509_InvalidEncodingFormat = "Invalid encoding format.";

	public const string Cryptography_X509_InvalidContentType = "Invalid content type.";

	public const string Cryptography_X509_KeyMismatch = "The public key of the certificate does not match the value specified.";

	public const string Cryptography_X509_RemoveFailed = "Removing certificate with index '{0}' failed.";

	public const string Cryptography_X509_StoreNotOpen = "The X509 certificate store has not been opened.";

	public const string Environment_NotInteractive = "The current session is not interactive.";

	public const string NotSupported_InvalidKeyImpl = "Only asymmetric keys that implement ICspAsymmetricAlgorithm are supported.";

	public const string NotSupported_KeyAlgorithm = "The certificate key algorithm is not supported.";

	public const string NotSupported_PlatformRequiresNT = "This operation is only supported on Windows 2000, Windows XP, and higher.";

	public const string NotSupported_UnreadableStream = "Stream does not support reading.";

	public const string Security_InvalidValue = "The {0} value was invalid.";

	public const string Unknown_Error = "Unknown error.";

	public const string security_ServiceNameCollection_EmptyServiceName = "A service name must not be null or empty.";

	public const string security_ExtendedProtectionPolicy_UseDifferentConstructorForNever = "To construct a policy with PolicyEnforcement.Never, the single-parameter constructor must be used.";

	public const string security_ExtendedProtectionPolicy_NoEmptyServiceNameCollection = "The ServiceNameCollection must contain at least one service name.";

	public const string security_ExtendedProtection_NoOSSupport = "This operation requires OS support for extended protection.";

	public const string net_nonClsCompliantException = "A non-CLS Compliant Exception (i.e. an object that does not derive from System.Exception) was thrown.";

	public const string net_illegalConfigWith = "The '{0}' attribute cannot appear when '{1}' is present.";

	public const string net_illegalConfigWithout = "The '{0}' attribute can only appear when '{1}' is present.";

	public const string net_resubmitcanceled = "An error occurred on an automatic resubmission of the request.";

	public const string net_redirect_perm = "WebPermission demand failed for redirect URI.";

	public const string net_resubmitprotofailed = "Cannot handle redirect from HTTP/HTTPS protocols to other dissimilar ones.";

	public const string net_invalidversion = "This protocol version is not supported.";

	public const string net_toolong = "The size of {0} is too long. It cannot be longer than {1} characters.";

	public const string net_connclosed = "The underlying connection was closed: {0}.";

	public const string net_mutualauthfailed = "The requirement for mutual authentication was not met by the remote server.";

	public const string net_invasync = "Cannot block a call on this socket while an earlier asynchronous call is in progress.";

	public const string net_inasync = "An asynchronous call is already in progress. It must be completed or canceled before you can call this method.";

	public const string net_mustbeuri = "The {0} parameter must represent a valid Uri (see inner exception).";

	public const string net_format_shexp = "The shell expression '{0}' could not be parsed because it is formatted incorrectly.";

	public const string net_cannot_load_proxy_helper = "Failed to load the proxy script runtime environment from the Microsoft.JScript assembly.";

	public const string net_io_no_0timeouts = "NetworkStream does not support a 0 millisecond timeout, use a value greater than zero for the timeout instead.";

	public const string net_tooManyRedirections = "Too many automatic redirections were attempted.";

	public const string net_authmodulenotregistered = "The supplied authentication module is not registered.";

	public const string net_authschemenotregistered = "There is no registered module for this authentication scheme.";

	public const string net_proxyschemenotsupported = "The ServicePointManager does not support proxies with the {0} scheme.";

	public const string net_maxsrvpoints = "The maximum number of service points was exceeded.";

	public const string net_notconnected = "The operation is not allowed on non-connected sockets.";

	public const string net_notstream = "The operation is not allowed on non-stream oriented sockets.";

	public const string net_nocontentlengthonget = "Content-Length or Chunked Encoding cannot be set for an operation that does not write data.";

	public const string net_contentlengthmissing = "When performing a write operation with AllowWriteStreamBuffering set to false, you must either set ContentLength to a non-negative number or set SendChunked to true.";

	public const string net_nonhttpproxynotallowed = "The URI scheme for the supplied IWebProxy has the illegal value '{0}'. Only 'http' is supported.";

	public const string net_need_writebuffering = "This request requires buffering data to succeed.";

	public const string net_nodefaultcreds = "Default credentials cannot be supplied for the {0} authentication scheme.";

	public const string net_stopped = "Not listening. You must call the Start() method before calling this method.";

	public const string net_udpconnected = "Cannot send packets to an arbitrary host while connected.";

	public const string net_no_concurrent_io_allowed = "The stream does not support concurrent IO read or write operations.";

	public const string net_needmorethreads = "There were not enough free threads in the ThreadPool to complete the operation.";

	public const string net_MethodNotSupportedException = "This method is not supported by this class.";

	public const string net_ProtocolNotSupportedException = "The '{0}' protocol is not supported by this class.";

	public const string net_SelectModeNotSupportedException = "The '{0}' select mode is not supported by this class.";

	public const string net_InvalidSocketHandle = "The socket handle is not valid.";

	public const string net_InvalidAddressFamily = "The AddressFamily {0} is not valid for the {1} end point, use {2} instead.";

	public const string net_InvalidEndPointAddressFamily = "The supplied EndPoint of AddressFamily {0} is not valid for this Socket, use {1} instead.";

	public const string net_InvalidSocketAddressSize = "The supplied {0} is an invalid size for the {1} end point.";

	public const string net_invalidAddressList = "None of the discovered or specified addresses match the socket address family.";

	public const string net_invalidPingBufferSize = "The buffer length must not exceed 65500 bytes.";

	public const string net_cant_perform_during_shutdown = "This operation cannot be performed while the AppDomain is shutting down.";

	public const string net_cant_create_environment = "Unable to create another web proxy script environment at this time.";

	public const string net_protocol_invalid_family = "'{0}' Client can only accept InterNetwork or InterNetworkV6 addresses.";

	public const string net_protocol_invalid_multicast_family = "Multicast family is not the same as the family of the '{0}' Client.";

	public const string net_empty_osinstalltype = "The Registry value '{0}' was either empty or not a string type.";

	public const string net_unknown_osinstalltype = "Unknown Windows installation type '{0}'.";

	public const string net_cant_determine_osinstalltype = "Can't determine OS installation type: Can't read key '{0}'. Exception message: {1}";

	public const string net_osinstalltype = "Current OS installation type is '{0}'.";

	public const string net_entire_body_not_written = "You must write ContentLength bytes to the request stream before calling [Begin]GetResponse.";

	public const string net_must_provide_request_body = "You must provide a request body if you set ContentLength>0 or SendChunked==true.  Do this by calling [Begin]GetRequestStream before [Begin]GetResponse.";

	public const string net_sockets_zerolist = "The parameter {0} must contain one or more elements.";

	public const string net_sockets_blocking = "The operation is not allowed on a non-blocking Socket.";

	public const string net_sockets_useblocking = "Use the Blocking property to change the status of the Socket.";

	public const string net_sockets_select = "The operation is not allowed on objects of type {0}. Use only objects of type {1}.";

	public const string net_sockets_toolarge_select = "The {0} list contains too many items; a maximum of {1} is allowed.";

	public const string net_sockets_empty_select = "All lists are either null or empty.";

	public const string net_sockets_mustbind = "You must call the Bind method before performing this operation.";

	public const string net_sockets_mustlisten = "You must call the Listen method before performing this operation.";

	public const string net_sockets_mustnotlisten = "You may not perform this operation after calling the Listen method.";

	public const string net_sockets_mustnotbebound = "The socket must not be bound or connected.";

	public const string net_sockets_namedmustnotbebound = "{0}: The socket must not be bound or connected.";

	public const string net_sockets_invalid_socketinformation = "The specified value for the socket information is invalid.";

	public const string net_sockets_invalid_ipaddress_length = "The number of specified IP addresses has to be greater than 0.";

	public const string net_sockets_invalid_optionValue = "The specified value is not a valid '{0}'.";

	public const string net_sockets_invalid_optionValue_all = "The specified value is not valid.";

	public const string net_sockets_invalid_dnsendpoint = "The parameter {0} must not be of type DnsEndPoint.";

	public const string net_sockets_disconnectedConnect = "Once the socket has been disconnected, you can only reconnect again asynchronously, and only to a different EndPoint.  BeginConnect must be called on a thread that won't exit until the operation has been completed.";

	public const string net_sockets_disconnectedAccept = "Once the socket has been disconnected, you can only accept again asynchronously.  BeginAccept must be called on a thread that won't exit until the operation has been completed.";

	public const string net_tcplistener_mustbestopped = "The TcpListener must not be listening before performing this operation.";

	public const string net_sockets_no_duplicate_async = "BeginConnect cannot be called while another asynchronous operation is in progress on the same Socket.";

	public const string net_socketopinprogress = "An asynchronous socket operation is already in progress using this SocketAsyncEventArgs instance.";

	public const string net_buffercounttoosmall = "The Buffer space specified by the Count property is insufficient for the AcceptAsync method.";

	public const string net_multibuffernotsupported = "Multiple buffers cannot be used with this method.";

	public const string net_ambiguousbuffers = "Buffer and BufferList properties cannot both be non-null.";

	public const string net_sockets_ipv6only = "This operation is only valid for IPv6 Sockets.";

	public const string net_perfcounter_initialized_success = "System.Net performance counters initialization completed successful.";

	public const string net_perfcounter_initialized_error = "System.Net performance counters initialization completed with errors. See System.Net trace file for more information.";

	public const string net_perfcounter_nocategory = "Performance counter category '{0}' doesn't exist. No System.Net performance counter values available.";

	public const string net_perfcounter_initialization_started = "System.Net performance counter initialization started.";

	public const string net_perfcounter_cant_queue_workitem = "Can't queue counter initialization logic on a thread pool thread. System.Net performance counters will not be available.";

	public const string net_config_proxy = "Error creating the Web Proxy specified in the 'system.net/defaultProxy' configuration section.";

	public const string net_config_proxy_module_not_public = "The specified proxy module type is not public.";

	public const string net_config_authenticationmodules = "Error creating the modules specified in the 'system.net/authenticationModules' configuration section.";

	public const string net_config_webrequestmodules = "Error creating the modules specified in the 'system.net/webRequestModules' configuration section.";

	public const string net_config_requestcaching = "Error creating the Web Request caching policy specified in the 'system.net/requestCaching' configuration section.";

	public const string net_config_section_permission = "Insufficient permissions for setting the configuration section '{0}'.";

	public const string net_config_element_permission = "Insufficient permissions for setting the configuration element '{0}'.";

	public const string net_config_property_permission = "Insufficient permissions for setting the configuration property '{0}'.";

	public const string net_WebResponseParseError_InvalidHeaderName = "Header name is invalid";

	public const string net_WebResponseParseError_InvalidContentLength = "'Content-Length' header value is invalid";

	public const string net_WebResponseParseError_IncompleteHeaderLine = "Invalid header name";

	public const string net_WebResponseParseError_CrLfError = "CR must be followed by LF";

	public const string net_WebResponseParseError_InvalidChunkFormat = "Response chunk format is invalid";

	public const string net_WebResponseParseError_UnexpectedServerResponse = "Unexpected server response received";

	public const string net_webstatus_Success = "Status success";

	public const string net_webstatus_ReceiveFailure = "An unexpected error occurred on a receive";

	public const string net_webstatus_SendFailure = "An unexpected error occurred on a send";

	public const string net_webstatus_PipelineFailure = "A pipeline failure occurred";

	public const string net_webstatus_RequestCanceled = "The request was canceled";

	public const string net_webstatus_ConnectionClosed = "The connection was closed unexpectedly";

	public const string net_webstatus_TrustFailure = "Could not establish trust relationship for the SSL/TLS secure channel";

	public const string net_webstatus_SecureChannelFailure = "Could not create SSL/TLS secure channel";

	public const string net_webstatus_ServerProtocolViolation = "The server committed a protocol violation";

	public const string net_webstatus_KeepAliveFailure = "A connection that was expected to be kept alive was closed by the server";

	public const string net_webstatus_ProxyNameResolutionFailure = "The proxy name could not be resolved";

	public const string net_webstatus_MessageLengthLimitExceeded = "The message length limit was exceeded";

	public const string net_webstatus_CacheEntryNotFound = "The request cache-only policy does not allow a network request and the response is not found in cache";

	public const string net_webstatus_RequestProhibitedByCachePolicy = "The request could not be satisfied using a cache-only policy";

	public const string net_webstatus_RequestProhibitedByProxy = "The IWebProxy object associated with the request did not allow the request to proceed";

	public const string net_httpstatuscode_NoContent = "No Content";

	public const string net_httpstatuscode_NonAuthoritativeInformation = "Non Authoritative Information";

	public const string net_httpstatuscode_ResetContent = "Reset Content";

	public const string net_httpstatuscode_PartialContent = "Partial Content";

	public const string net_httpstatuscode_MultipleChoices = "Multiple Choices Redirect";

	public const string net_httpstatuscode_Ambiguous = "Ambiguous Redirect";

	public const string net_httpstatuscode_MovedPermanently = "Moved Permanently Redirect";

	public const string net_httpstatuscode_Moved = "Moved Redirect";

	public const string net_httpstatuscode_Found = "Found Redirect";

	public const string net_httpstatuscode_Redirect = "Redirect";

	public const string net_httpstatuscode_SeeOther = "See Other";

	public const string net_httpstatuscode_RedirectMethod = "Redirect Method";

	public const string net_httpstatuscode_NotModified = "Not Modified";

	public const string net_httpstatuscode_UseProxy = "Use Proxy Redirect";

	public const string net_httpstatuscode_TemporaryRedirect = "Temporary Redirect";

	public const string net_httpstatuscode_RedirectKeepVerb = "Redirect Keep Verb";

	public const string net_httpstatuscode_BadRequest = "Bad Request";

	public const string net_httpstatuscode_Unauthorized = "Unauthorized";

	public const string net_httpstatuscode_PaymentRequired = "Payment Required";

	public const string net_httpstatuscode_Forbidden = "Forbidden";

	public const string net_httpstatuscode_NotFound = "Not Found";

	public const string net_httpstatuscode_MethodNotAllowed = "Method Not Allowed";

	public const string net_httpstatuscode_NotAc

BepInExPack/mono/Managed/netstandard.dll

Decompiled a month ago
using System;
using System.Buffers;
using System.Buffers.Binary;
using System.Buffers.Text;
using System.CodeDom.Compiler;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.ComponentModel.Design.Serialization;
using System.Configuration.Assemblies;
using System.Data;
using System.Data.Common;
using System.Data.SqlTypes;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Diagnostics.Contracts;
using System.Diagnostics.SymbolStore;
using System.Diagnostics.Tracing;
using System.Drawing;
using System.Dynamic;
using System.Globalization;
using System.IO;
using System.IO.Compression;
using System.IO.Enumeration;
using System.IO.IsolatedStorage;
using System.IO.MemoryMappedFiles;
using System.IO.Pipes;
using System.Linq;
using System.Linq.Expressions;
using System.Net;
using System.Net.Cache;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Net.Mail;
using System.Net.Mime;
using System.Net.NetworkInformation;
using System.Net.Security;
using System.Net.Sockets;
using System.Net.WebSockets;
using System.Numerics;
using System.Reflection;
using System.Reflection.Emit;
using System.Resources;
using System.Runtime;
using System.Runtime.CompilerServices;
using System.Runtime.ConstrainedExecution;
using System.Runtime.ExceptionServices;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Serialization.Json;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Authentication;
using System.Security.Authentication.ExtendedProtection;
using System.Security.Claims;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using System.Security.Permissions;
using System.Security.Principal;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Threading.Tasks.Sources;
using System.Timers;
using System.Transactions;
using System.Web;
using System.Windows.Input;
using System.Xml;
using System.Xml.Linq;
using System.Xml.Resolvers;
using System.Xml.Schema;
using System.Xml.Serialization;
using System.Xml.XPath;
using System.Xml.Xsl;
using Microsoft.Win32.SafeHandles;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("netstandard")]
[assembly: AssemblyDescription("netstandard")]
[assembly: AssemblyDefaultAlias("netstandard")]
[assembly: AssemblyCompany("Mono development team")]
[assembly: AssemblyProduct("Mono Common Language Infrastructure")]
[assembly: AssemblyCopyright("(c) Various Mono authors")]
[assembly: AssemblyInformationalVersion("2.1.0.0")]
[assembly: AssemblyFileVersion("2.1.0.0")]
[assembly: AssemblyVersion("2.1.0.0")]
[assembly: TypeForwardedTo(typeof(CriticalHandleMinusOneIsInvalid))]
[assembly: TypeForwardedTo(typeof(CriticalHandleZeroOrMinusOneIsInvalid))]
[assembly: TypeForwardedTo(typeof(SafeFileHandle))]
[assembly: TypeForwardedTo(typeof(SafeHandleMinusOneIsInvalid))]
[assembly: TypeForwardedTo(typeof(SafeHandleZeroOrMinusOneIsInvalid))]
[assembly: TypeForwardedTo(typeof(SafeMemoryMappedFileHandle))]
[assembly: TypeForwardedTo(typeof(SafeMemoryMappedViewHandle))]
[assembly: TypeForwardedTo(typeof(SafePipeHandle))]
[assembly: TypeForwardedTo(typeof(SafeProcessHandle))]
[assembly: TypeForwardedTo(typeof(SafeWaitHandle))]
[assembly: TypeForwardedTo(typeof(SafeX509ChainHandle))]
[assembly: TypeForwardedTo(typeof(AccessViolationException))]
[assembly: TypeForwardedTo(typeof(Action))]
[assembly: TypeForwardedTo(typeof(Action<>))]
[assembly: TypeForwardedTo(typeof(Action<, , , , , , , , , >))]
[assembly: TypeForwardedTo(typeof(Action<, , , , , , , , , , >))]
[assembly: TypeForwardedTo(typeof(Action<, , , , , , , , , , , >))]
[assembly: TypeForwardedTo(typeof(Action<, , , , , , , , , , , , >))]
[assembly: TypeForwardedTo(typeof(Action<, , , , , , , , , , , , , >))]
[assembly: TypeForwardedTo(typeof(Action<, , , , , , , , , , , , , , >))]
[assembly: TypeForwardedTo(typeof(Action<, , , , , , , , , , , , , , , >))]
[assembly: TypeForwardedTo(typeof(Action<, >))]
[assembly: TypeForwardedTo(typeof(Action<, , >))]
[assembly: TypeForwardedTo(typeof(Action<, , , >))]
[assembly: TypeForwardedTo(typeof(Action<, , , , >))]
[assembly: TypeForwardedTo(typeof(Action<, , , , , >))]
[assembly: TypeForwardedTo(typeof(Action<, , , , , , >))]
[assembly: TypeForwardedTo(typeof(Action<, , , , , , , >))]
[assembly: TypeForwardedTo(typeof(Action<, , , , , , , , >))]
[assembly: TypeForwardedTo(typeof(Activator))]
[assembly: TypeForwardedTo(typeof(AggregateException))]
[assembly: TypeForwardedTo(typeof(AppContext))]
[assembly: TypeForwardedTo(typeof(AppDomain))]
[assembly: TypeForwardedTo(typeof(AppDomainUnloadedException))]
[assembly: TypeForwardedTo(typeof(ApplicationException))]
[assembly: TypeForwardedTo(typeof(ApplicationId))]
[assembly: TypeForwardedTo(typeof(ArgumentException))]
[assembly: TypeForwardedTo(typeof(ArgumentNullException))]
[assembly: TypeForwardedTo(typeof(ArgumentOutOfRangeException))]
[assembly: TypeForwardedTo(typeof(ArithmeticException))]
[assembly: TypeForwardedTo(typeof(Array))]
[assembly: TypeForwardedTo(typeof(ArraySegment<>))]
[assembly: TypeForwardedTo(typeof(ArrayTypeMismatchException))]
[assembly: TypeForwardedTo(typeof(AssemblyLoadEventArgs))]
[assembly: TypeForwardedTo(typeof(AssemblyLoadEventHandler))]
[assembly: TypeForwardedTo(typeof(AsyncCallback))]
[assembly: TypeForwardedTo(typeof(Attribute))]
[assembly: TypeForwardedTo(typeof(AttributeTargets))]
[assembly: TypeForwardedTo(typeof(AttributeUsageAttribute))]
[assembly: TypeForwardedTo(typeof(BadImageFormatException))]
[assembly: TypeForwardedTo(typeof(Base64FormattingOptions))]
[assembly: TypeForwardedTo(typeof(BitConverter))]
[assembly: TypeForwardedTo(typeof(bool))]
[assembly: TypeForwardedTo(typeof(Buffer))]
[assembly: TypeForwardedTo(typeof(ArrayBufferWriter<>))]
[assembly: TypeForwardedTo(typeof(ArrayPool<>))]
[assembly: TypeForwardedTo(typeof(BinaryPrimitives))]
[assembly: TypeForwardedTo(typeof(BuffersExtensions))]
[assembly: TypeForwardedTo(typeof(IBufferWriter<>))]
[assembly: TypeForwardedTo(typeof(IMemoryOwner<>))]
[assembly: TypeForwardedTo(typeof(IPinnable))]
[assembly: TypeForwardedTo(typeof(MemoryHandle))]
[assembly: TypeForwardedTo(typeof(MemoryManager<>))]
[assembly: TypeForwardedTo(typeof(MemoryPool<>))]
[assembly: TypeForwardedTo(typeof(OperationStatus))]
[assembly: TypeForwardedTo(typeof(ReadOnlySequence<>))]
[assembly: TypeForwardedTo(typeof(ReadOnlySequenceSegment<>))]
[assembly: TypeForwardedTo(typeof(ReadOnlySpanAction<, >))]
[assembly: TypeForwardedTo(typeof(SequenceReader<>))]
[assembly: TypeForwardedTo(typeof(SequenceReaderExtensions))]
[assembly: TypeForwardedTo(typeof(SpanAction<, >))]
[assembly: TypeForwardedTo(typeof(StandardFormat))]
[assembly: TypeForwardedTo(typeof(Base64))]
[assembly: TypeForwardedTo(typeof(Utf8Formatter))]
[assembly: TypeForwardedTo(typeof(Utf8Parser))]
[assembly: TypeForwardedTo(typeof(byte))]
[assembly: TypeForwardedTo(typeof(CannotUnloadAppDomainException))]
[assembly: TypeForwardedTo(typeof(char))]
[assembly: TypeForwardedTo(typeof(CharEnumerator))]
[assembly: TypeForwardedTo(typeof(CLSCompliantAttribute))]
[assembly: TypeForwardedTo(typeof(GeneratedCodeAttribute))]
[assembly: TypeForwardedTo(typeof(IndentedTextWriter))]
[assembly: TypeForwardedTo(typeof(ArrayList))]
[assembly: TypeForwardedTo(typeof(BitArray))]
[assembly: TypeForwardedTo(typeof(CaseInsensitiveComparer))]
[assembly: TypeForwardedTo(typeof(CaseInsensitiveHashCodeProvider))]
[assembly: TypeForwardedTo(typeof(CollectionBase))]
[assembly: TypeForwardedTo(typeof(Comparer))]
[assembly: TypeForwardedTo(typeof(BlockingCollection<>))]
[assembly: TypeForwardedTo(typeof(ConcurrentBag<>))]
[assembly: TypeForwardedTo(typeof(ConcurrentDictionary<, >))]
[assembly: TypeForwardedTo(typeof(ConcurrentQueue<>))]
[assembly: TypeForwardedTo(typeof(ConcurrentStack<>))]
[assembly: TypeForwardedTo(typeof(EnumerablePartitionerOptions))]
[assembly: TypeForwardedTo(typeof(IProducerConsumerCollection<>))]
[assembly: TypeForwardedTo(typeof(OrderablePartitioner<>))]
[assembly: TypeForwardedTo(typeof(Partitioner))]
[assembly: TypeForwardedTo(typeof(Partitioner<>))]
[assembly: TypeForwardedTo(typeof(DictionaryBase))]
[assembly: TypeForwardedTo(typeof(DictionaryEntry))]
[assembly: TypeForwardedTo(typeof(CollectionExtensions))]
[assembly: TypeForwardedTo(typeof(Comparer<>))]
[assembly: TypeForwardedTo(typeof(Dictionary<, >))]
[assembly: TypeForwardedTo(typeof(EqualityComparer<>))]
[assembly: TypeForwardedTo(typeof(HashSet<>))]
[assembly: TypeForwardedTo(typeof(IAsyncEnumerable<>))]
[assembly: TypeForwardedTo(typeof(IAsyncEnumerator<>))]
[assembly: TypeForwardedTo(typeof(ICollection<>))]
[assembly: TypeForwardedTo(typeof(IComparer<>))]
[assembly: TypeForwardedTo(typeof(IDictionary<, >))]
[assembly: TypeForwardedTo(typeof(IEnumerable<>))]
[assembly: TypeForwardedTo(typeof(IEnumerator<>))]
[assembly: TypeForwardedTo(typeof(IEqualityComparer<>))]
[assembly: TypeForwardedTo(typeof(IList<>))]
[assembly: TypeForwardedTo(typeof(IReadOnlyCollection<>))]
[assembly: TypeForwardedTo(typeof(IReadOnlyDictionary<, >))]
[assembly: TypeForwardedTo(typeof(IReadOnlyList<>))]
[assembly: TypeForwardedTo(typeof(ISet<>))]
[assembly: TypeForwardedTo(typeof(KeyNotFoundException))]
[assembly: TypeForwardedTo(typeof(KeyValuePair))]
[assembly: TypeForwardedTo(typeof(KeyValuePair<, >))]
[assembly: TypeForwardedTo(typeof(LinkedList<>))]
[assembly: TypeForwardedTo(typeof(LinkedListNode<>))]
[assembly: TypeForwardedTo(typeof(List<>))]
[assembly: TypeForwardedTo(typeof(Queue<>))]
[assembly: TypeForwardedTo(typeof(SortedDictionary<, >))]
[assembly: TypeForwardedTo(typeof(SortedList<, >))]
[assembly: TypeForwardedTo(typeof(SortedSet<>))]
[assembly: TypeForwardedTo(typeof(Stack<>))]
[assembly: TypeForwardedTo(typeof(Hashtable))]
[assembly: TypeForwardedTo(typeof(ICollection))]
[assembly: TypeForwardedTo(typeof(IComparer))]
[assembly: TypeForwardedTo(typeof(IDictionary))]
[assembly: TypeForwardedTo(typeof(IDictionaryEnumerator))]
[assembly: TypeForwardedTo(typeof(IEnumerable))]
[assembly: TypeForwardedTo(typeof(IEnumerator))]
[assembly: TypeForwardedTo(typeof(IEqualityComparer))]
[assembly: TypeForwardedTo(typeof(IHashCodeProvider))]
[assembly: TypeForwardedTo(typeof(IList))]
[assembly: TypeForwardedTo(typeof(IStructuralComparable))]
[assembly: TypeForwardedTo(typeof(IStructuralEquatable))]
[assembly: TypeForwardedTo(typeof(Collection<>))]
[assembly: TypeForwardedTo(typeof(KeyedCollection<, >))]
[assembly: TypeForwardedTo(typeof(ObservableCollection<>))]
[assembly: TypeForwardedTo(typeof(ReadOnlyCollection<>))]
[assembly: TypeForwardedTo(typeof(ReadOnlyDictionary<, >))]
[assembly: TypeForwardedTo(typeof(ReadOnlyObservableCollection<>))]
[assembly: TypeForwardedTo(typeof(Queue))]
[assembly: TypeForwardedTo(typeof(ReadOnlyCollectionBase))]
[assembly: TypeForwardedTo(typeof(SortedList))]
[assembly: TypeForwardedTo(typeof(BitVector32))]
[assembly: TypeForwardedTo(typeof(CollectionsUtil))]
[assembly: TypeForwardedTo(typeof(HybridDictionary))]
[assembly: TypeForwardedTo(typeof(INotifyCollectionChanged))]
[assembly: TypeForwardedTo(typeof(IOrderedDictionary))]
[assembly: TypeForwardedTo(typeof(ListDictionary))]
[assembly: TypeForwardedTo(typeof(NameObjectCollectionBase))]
[assembly: TypeForwardedTo(typeof(NameValueCollection))]
[assembly: TypeForwardedTo(typeof(NotifyCollectionChangedAction))]
[assembly: TypeForwardedTo(typeof(NotifyCollectionChangedEventArgs))]
[assembly: TypeForwardedTo(typeof(NotifyCollectionChangedEventHandler))]
[assembly: TypeForwardedTo(typeof(OrderedDictionary))]
[assembly: TypeForwardedTo(typeof(StringCollection))]
[assembly: TypeForwardedTo(typeof(StringDictionary))]
[assembly: TypeForwardedTo(typeof(StringEnumerator))]
[assembly: TypeForwardedTo(typeof(Stack))]
[assembly: TypeForwardedTo(typeof(StructuralComparisons))]
[assembly: TypeForwardedTo(typeof(Comparison<>))]
[assembly: TypeForwardedTo(typeof(AddingNewEventArgs))]
[assembly: TypeForwardedTo(typeof(AddingNewEventHandler))]
[assembly: TypeForwardedTo(typeof(AmbientValueAttribute))]
[assembly: TypeForwardedTo(typeof(ArrayConverter))]
[assembly: TypeForwardedTo(typeof(AsyncCompletedEventArgs))]
[assembly: TypeForwardedTo(typeof(AsyncCompletedEventHandler))]
[assembly: TypeForwardedTo(typeof(AsyncOperation))]
[assembly: TypeForwardedTo(typeof(AsyncOperationManager))]
[assembly: TypeForwardedTo(typeof(AttributeCollection))]
[assembly: TypeForwardedTo(typeof(AttributeProviderAttribute))]
[assembly: TypeForwardedTo(typeof(BackgroundWorker))]
[assembly: TypeForwardedTo(typeof(BaseNumberConverter))]
[assembly: TypeForwardedTo(typeof(BindableAttribute))]
[assembly: TypeForwardedTo(typeof(BindableSupport))]
[assembly: TypeForwardedTo(typeof(BindingDirection))]
[assembly: TypeForwardedTo(typeof(BindingList<>))]
[assembly: TypeForwardedTo(typeof(BooleanConverter))]
[assembly: TypeForwardedTo(typeof(BrowsableAttribute))]
[assembly: TypeForwardedTo(typeof(ByteConverter))]
[assembly: TypeForwardedTo(typeof(CancelEventArgs))]
[assembly: TypeForwardedTo(typeof(CancelEventHandler))]
[assembly: TypeForwardedTo(typeof(CategoryAttribute))]
[assembly: TypeForwardedTo(typeof(CharConverter))]
[assembly: TypeForwardedTo(typeof(CollectionChangeAction))]
[assembly: TypeForwardedTo(typeof(CollectionChangeEventArgs))]
[assembly: TypeForwardedTo(typeof(CollectionChangeEventHandler))]
[assembly: TypeForwardedTo(typeof(CollectionConverter))]
[assembly: TypeForwardedTo(typeof(ComplexBindingPropertiesAttribute))]
[assembly: TypeForwardedTo(typeof(Component))]
[assembly: TypeForwardedTo(typeof(ComponentCollection))]
[assembly: TypeForwardedTo(typeof(ComponentConverter))]
[assembly: TypeForwardedTo(typeof(ComponentEditor))]
[assembly: TypeForwardedTo(typeof(ComponentResourceManager))]
[assembly: TypeForwardedTo(typeof(Container))]
[assembly: TypeForwardedTo(typeof(ContainerFilterService))]
[assembly: TypeForwardedTo(typeof(CultureInfoConverter))]
[assembly: TypeForwardedTo(typeof(CustomTypeDescriptor))]
[assembly: TypeForwardedTo(typeof(DataErrorsChangedEventArgs))]
[assembly: TypeForwardedTo(typeof(DataObjectAttribute))]
[assembly: TypeForwardedTo(typeof(DataObjectFieldAttribute))]
[assembly: TypeForwardedTo(typeof(DataObjectMethodAttribute))]
[assembly: TypeForwardedTo(typeof(DataObjectMethodType))]
[assembly: TypeForwardedTo(typeof(DateTimeConverter))]
[assembly: TypeForwardedTo(typeof(DateTimeOffsetConverter))]
[assembly: TypeForwardedTo(typeof(DecimalConverter))]
[assembly: TypeForwardedTo(typeof(DefaultBindingPropertyAttribute))]
[assembly: TypeForwardedTo(typeof(DefaultEventAttribute))]
[assembly: TypeForwardedTo(typeof(DefaultPropertyAttribute))]
[assembly: TypeForwardedTo(typeof(DefaultValueAttribute))]
[assembly: TypeForwardedTo(typeof(DescriptionAttribute))]
[assembly: TypeForwardedTo(typeof(ActiveDesignerEventArgs))]
[assembly: TypeForwardedTo(typeof(ActiveDesignerEventHandler))]
[assembly: TypeForwardedTo(typeof(CheckoutException))]
[assembly: TypeForwardedTo(typeof(CommandID))]
[assembly: TypeForwardedTo(typeof(ComponentChangedEventArgs))]
[assembly: TypeForwardedTo(typeof(ComponentChangedEventHandler))]
[assembly: TypeForwardedTo(typeof(ComponentChangingEventArgs))]
[assembly: TypeForwardedTo(typeof(ComponentChangingEventHandler))]
[assembly: TypeForwardedTo(typeof(ComponentEventArgs))]
[assembly: TypeForwardedTo(typeof(ComponentEventHandler))]
[assembly: TypeForwardedTo(typeof(ComponentRenameEventArgs))]
[assembly: TypeForwardedTo(typeof(ComponentRenameEventHandler))]
[assembly: TypeForwardedTo(typeof(DesignerCollection))]
[assembly: TypeForwardedTo(typeof(DesignerEventArgs))]
[assembly: TypeForwardedTo(typeof(DesignerEventHandler))]
[assembly: TypeForwardedTo(typeof(DesignerOptionService))]
[assembly: TypeForwardedTo(typeof(DesignerTransaction))]
[assembly: TypeForwardedTo(typeof(DesignerTransactionCloseEventArgs))]
[assembly: TypeForwardedTo(typeof(DesignerTransactionCloseEventHandler))]
[assembly: TypeForwardedTo(typeof(DesignerVerb))]
[assembly: TypeForwardedTo(typeof(DesignerVerbCollection))]
[assembly: TypeForwardedTo(typeof(DesigntimeLicenseContext))]
[assembly: TypeForwardedTo(typeof(DesigntimeLicenseContextSerializer))]
[assembly: TypeForwardedTo(typeof(HelpContextType))]
[assembly: TypeForwardedTo(typeof(HelpKeywordAttribute))]
[assembly: TypeForwardedTo(typeof(HelpKeywordType))]
[assembly: TypeForwardedTo(typeof(IComponentChangeService))]
[assembly: TypeForwardedTo(typeof(IComponentDiscoveryService))]
[assembly: TypeForwardedTo(typeof(IComponentInitializer))]
[assembly: TypeForwardedTo(typeof(IDesigner))]
[assembly: TypeForwardedTo(typeof(IDesignerEventService))]
[assembly: TypeForwardedTo(typeof(IDesignerFilter))]
[assembly: TypeForwardedTo(typeof(IDesignerHost))]
[assembly: TypeForwardedTo(typeof(IDesignerHostTransactionState))]
[assembly: TypeForwardedTo(typeof(IDesignerOptionService))]
[assembly: TypeForwardedTo(typeof(IDictionaryService))]
[assembly: TypeForwardedTo(typeof(IEventBindingService))]
[assembly: TypeForwardedTo(typeof(IExtenderListService))]
[assembly: TypeForwardedTo(typeof(IExtenderProviderService))]
[assembly: TypeForwardedTo(typeof(IHelpService))]
[assembly: TypeForwardedTo(typeof(IInheritanceService))]
[assembly: TypeForwardedTo(typeof(IMenuCommandService))]
[assembly: TypeForwardedTo(typeof(IReferenceService))]
[assembly: TypeForwardedTo(typeof(IResourceService))]
[assembly: TypeForwardedTo(typeof(IRootDesigner))]
[assembly: TypeForwardedTo(typeof(ISelectionService))]
[assembly: TypeForwardedTo(typeof(IServiceContainer))]
[assembly: TypeForwardedTo(typeof(ITreeDesigner))]
[assembly: TypeForwardedTo(typeof(ITypeDescriptorFilterService))]
[assembly: TypeForwardedTo(typeof(ITypeDiscoveryService))]
[assembly: TypeForwardedTo(typeof(ITypeResolutionService))]
[assembly: TypeForwardedTo(typeof(MenuCommand))]
[assembly: TypeForwardedTo(typeof(SelectionTypes))]
[assembly: TypeForwardedTo(typeof(ComponentSerializationService))]
[assembly: TypeForwardedTo(typeof(ContextStack))]
[assembly: TypeForwardedTo(typeof(DefaultSerializationProviderAttribute))]
[assembly: TypeForwardedTo(typeof(DesignerLoader))]
[assembly: TypeForwardedTo(typeof(DesignerSerializerAttribute))]
[assembly: TypeForwardedTo(typeof(IDesignerLoaderHost))]
[assembly: TypeForwardedTo(typeof(IDesignerLoaderHost2))]
[assembly: TypeForwardedTo(typeof(IDesignerLoaderService))]
[assembly: TypeForwardedTo(typeof(IDesignerSerializationManager))]
[assembly: TypeForwardedTo(typeof(IDesignerSerializationProvider))]
[assembly: TypeForwardedTo(typeof(IDesignerSerializationService))]
[assembly: TypeForwardedTo(typeof(INameCreationService))]
[assembly: TypeForwardedTo(typeof(InstanceDescriptor))]
[assembly: TypeForwardedTo(typeof(MemberRelationship))]
[assembly: TypeForwardedTo(typeof(MemberRelationshipService))]
[assembly: TypeForwardedTo(typeof(ResolveNameEventArgs))]
[assembly: TypeForwardedTo(typeof(ResolveNameEventHandler))]
[assembly: TypeForwardedTo(typeof(RootDesignerSerializerAttribute))]
[assembly: TypeForwardedTo(typeof(SerializationStore))]
[assembly: TypeForwardedTo(typeof(ServiceContainer))]
[assembly: TypeForwardedTo(typeof(ServiceCreatorCallback))]
[assembly: TypeForwardedTo(typeof(StandardCommands))]
[assembly: TypeForwardedTo(typeof(StandardToolWindows))]
[assembly: TypeForwardedTo(typeof(TypeDescriptionProviderService))]
[assembly: TypeForwardedTo(typeof(ViewTechnology))]
[assembly: TypeForwardedTo(typeof(DesignerAttribute))]
[assembly: TypeForwardedTo(typeof(DesignerCategoryAttribute))]
[assembly: TypeForwardedTo(typeof(DesignerSerializationVisibility))]
[assembly: TypeForwardedTo(typeof(DesignerSerializationVisibilityAttribute))]
[assembly: TypeForwardedTo(typeof(DesignOnlyAttribute))]
[assembly: TypeForwardedTo(typeof(DesignTimeVisibleAttribute))]
[assembly: TypeForwardedTo(typeof(DisplayNameAttribute))]
[assembly: TypeForwardedTo(typeof(DoubleConverter))]
[assembly: TypeForwardedTo(typeof(DoWorkEventArgs))]
[assembly: TypeForwardedTo(typeof(DoWorkEventHandler))]
[assembly: TypeForwardedTo(typeof(EditorAttribute))]
[assembly: TypeForwardedTo(typeof(EditorBrowsableAttribute))]
[assembly: TypeForwardedTo(typeof(EditorBrowsableState))]
[assembly: TypeForwardedTo(typeof(EnumConverter))]
[assembly: TypeForwardedTo(typeof(EventDescriptor))]
[assembly: TypeForwardedTo(typeof(EventDescriptorCollection))]
[assembly: TypeForwardedTo(typeof(EventHandlerList))]
[assembly: TypeForwardedTo(typeof(ExpandableObjectConverter))]
[assembly: TypeForwardedTo(typeof(ExtenderProvidedPropertyAttribute))]
[assembly: TypeForwardedTo(typeof(GuidConverter))]
[assembly: TypeForwardedTo(typeof(HandledEventArgs))]
[assembly: TypeForwardedTo(typeof(HandledEventHandler))]
[assembly: TypeForwardedTo(typeof(IBindingList))]
[assembly: TypeForwardedTo(typeof(IBindingListView))]
[assembly: TypeForwardedTo(typeof(ICancelAddNew))]
[assembly: TypeForwardedTo(typeof(IChangeTracking))]
[assembly: TypeForwardedTo(typeof(IComNativeDescriptorHandler))]
[assembly: TypeForwardedTo(typeof(IComponent))]
[assembly: TypeForwardedTo(typeof(IContainer))]
[assembly: TypeForwardedTo(typeof(ICustomTypeDescriptor))]
[assembly: TypeForwardedTo(typeof(IDataErrorInfo))]
[assembly: TypeForwardedTo(typeof(IEditableObject))]
[assembly: TypeForwardedTo(typeof(IExtenderProvider))]
[assembly: TypeForwardedTo(typeof(IIntellisenseBuilder))]
[assembly: TypeForwardedTo(typeof(IListSource))]
[assembly: TypeForwardedTo(typeof(ImmutableObjectAttribute))]
[assembly: TypeForwardedTo(typeof(INestedContainer))]
[assembly: TypeForwardedTo(typeof(INestedSite))]
[assembly: TypeForwardedTo(typeof(InheritanceAttribute))]
[assembly: TypeForwardedTo(typeof(InheritanceLevel))]
[assembly: TypeForwardedTo(typeof(InitializationEventAttribute))]
[assembly: TypeForwardedTo(typeof(INotifyDataErrorInfo))]
[assembly: TypeForwardedTo(typeof(INotifyPropertyChanged))]
[assembly: TypeForwardedTo(typeof(INotifyPropertyChanging))]
[assembly: TypeForwardedTo(typeof(InstallerTypeAttribute))]
[assembly: TypeForwardedTo(typeof(InstanceCreationEditor))]
[assembly: TypeForwardedTo(typeof(Int16Converter))]
[assembly: TypeForwardedTo(typeof(Int32Converter))]
[assembly: TypeForwardedTo(typeof(Int64Converter))]
[assembly: TypeForwardedTo(typeof(InvalidAsynchronousStateException))]
[assembly: TypeForwardedTo(typeof(InvalidEnumArgumentException))]
[assembly: TypeForwardedTo(typeof(IRaiseItemChangedEvents))]
[assembly: TypeForwardedTo(typeof(IRevertibleChangeTracking))]
[assembly: TypeForwardedTo(typeof(ISite))]
[assembly: TypeForwardedTo(typeof(ISupportInitialize))]
[assembly: TypeForwardedTo(typeof(ISupportInitializeNotification))]
[assembly: TypeForwardedTo(typeof(ISynchronizeInvoke))]
[assembly: TypeForwardedTo(typeof(ITypeDescriptorContext))]
[assembly: TypeForwardedTo(typeof(ITypedList))]
[assembly: TypeForwardedTo(typeof(License))]
[assembly: TypeForwardedTo(typeof(LicenseContext))]
[assembly: TypeForwardedTo(typeof(LicenseException))]
[assembly: TypeForwardedTo(typeof(LicenseManager))]
[assembly: TypeForwardedTo(typeof(LicenseProvider))]
[assembly: TypeForwardedTo(typeof(LicenseProviderAttribute))]
[assembly: TypeForwardedTo(typeof(LicenseUsageMode))]
[assembly: TypeForwardedTo(typeof(LicFileLicenseProvider))]
[assembly: TypeForwardedTo(typeof(ListBindableAttribute))]
[assembly: TypeForwardedTo(typeof(ListChangedEventArgs))]
[assembly: TypeForwardedTo(typeof(ListChangedEventHandler))]
[assembly: TypeForwardedTo(typeof(ListChangedType))]
[assembly: TypeForwardedTo(typeof(ListSortDescription))]
[assembly: TypeForwardedTo(typeof(ListSortDescriptionCollection))]
[assembly: TypeForwardedTo(typeof(ListSortDirection))]
[assembly: TypeForwardedTo(typeof(LocalizableAttribute))]
[assembly: TypeForwardedTo(typeof(LookupBindingPropertiesAttribute))]
[assembly: TypeForwardedTo(typeof(MarshalByValueComponent))]
[assembly: TypeForwardedTo(typeof(MaskedTextProvider))]
[assembly: TypeForwardedTo(typeof(MaskedTextResultHint))]
[assembly: TypeForwardedTo(typeof(MemberDescriptor))]
[assembly: TypeForwardedTo(typeof(MergablePropertyAttribute))]
[assembly: TypeForwardedTo(typeof(MultilineStringConverter))]
[assembly: TypeForwardedTo(typeof(NestedContainer))]
[assembly: TypeForwardedTo(typeof(NotifyParentPropertyAttribute))]
[assembly: TypeForwardedTo(typeof(NullableConverter))]
[assembly: TypeForwardedTo(typeof(ParenthesizePropertyNameAttribute))]
[assembly: TypeForwardedTo(typeof(PasswordPropertyTextAttribute))]
[assembly: TypeForwardedTo(typeof(ProgressChangedEventArgs))]
[assembly: TypeForwardedTo(typeof(ProgressChangedEventHandler))]
[assembly: TypeForwardedTo(typeof(PropertyChangedEventArgs))]
[assembly: TypeForwardedTo(typeof(PropertyChangedEventHandler))]
[assembly: TypeForwardedTo(typeof(PropertyChangingEventArgs))]
[assembly: TypeForwardedTo(typeof(PropertyChangingEventHandler))]
[assembly: TypeForwardedTo(typeof(PropertyDescriptor))]
[assembly: TypeForwardedTo(typeof(PropertyDescriptorCollection))]
[assembly: TypeForwardedTo(typeof(PropertyTabAttribute))]
[assembly: TypeForwardedTo(typeof(PropertyTabScope))]
[assembly: TypeForwardedTo(typeof(ProvidePropertyAttribute))]
[assembly: TypeForwardedTo(typeof(ReadOnlyAttribute))]
[assembly: TypeForwardedTo(typeof(RecommendedAsConfigurableAttribute))]
[assembly: TypeForwardedTo(typeof(ReferenceConverter))]
[assembly: TypeForwardedTo(typeof(RefreshEventArgs))]
[assembly: TypeForwardedTo(typeof(RefreshEventHandler))]
[assembly: TypeForwardedTo(typeof(RefreshProperties))]
[assembly: TypeForwardedTo(typeof(RefreshPropertiesAttribute))]
[assembly: TypeForwardedTo(typeof(RunInstallerAttribute))]
[assembly: TypeForwardedTo(typeof(RunWorkerCompletedEventArgs))]
[assembly: TypeForwardedTo(typeof(RunWorkerCompletedEventHandler))]
[assembly: TypeForwardedTo(typeof(SByteConverter))]
[assembly: TypeForwardedTo(typeof(SettingsBindableAttribute))]
[assembly: TypeForwardedTo(typeof(SingleConverter))]
[assembly: TypeForwardedTo(typeof(StringConverter))]
[assembly: TypeForwardedTo(typeof(SyntaxCheck))]
[assembly: TypeForwardedTo(typeof(TimeSpanConverter))]
[assembly: TypeForwardedTo(typeof(ToolboxItemAttribute))]
[assembly: TypeForwardedTo(typeof(ToolboxItemFilterAttribute))]
[assembly: TypeForwardedTo(typeof(ToolboxItemFilterType))]
[assembly: TypeForwardedTo(typeof(TypeConverter))]
[assembly: TypeForwardedTo(typeof(TypeConverterAttribute))]
[assembly: TypeForwardedTo(typeof(TypeDescriptionProvider))]
[assembly: TypeForwardedTo(typeof(TypeDescriptionProviderAttribute))]
[assembly: TypeForwardedTo(typeof(TypeDescriptor))]
[assembly: TypeForwardedTo(typeof(TypeListConverter))]
[assembly: TypeForwardedTo(typeof(UInt16Converter))]
[assembly: TypeForwardedTo(typeof(UInt32Converter))]
[assembly: TypeForwardedTo(typeof(UInt64Converter))]
[assembly: TypeForwardedTo(typeof(WarningException))]
[assembly: TypeForwardedTo(typeof(Win32Exception))]
[assembly: TypeForwardedTo(typeof(AssemblyHashAlgorithm))]
[assembly: TypeForwardedTo(typeof(AssemblyVersionCompatibility))]
[assembly: TypeForwardedTo(typeof(Console))]
[assembly: TypeForwardedTo(typeof(ConsoleCancelEventArgs))]
[assembly: TypeForwardedTo(typeof(ConsoleCancelEventHandler))]
[assembly: TypeForwardedTo(typeof(ConsoleColor))]
[assembly: TypeForwardedTo(typeof(ConsoleKey))]
[assembly: TypeForwardedTo(typeof(ConsoleKeyInfo))]
[assembly: TypeForwardedTo(typeof(ConsoleModifiers))]
[assembly: TypeForwardedTo(typeof(ConsoleSpecialKey))]
[assembly: TypeForwardedTo(typeof(ContextBoundObject))]
[assembly: TypeForwardedTo(typeof(ContextMarshalException))]
[assembly: TypeForwardedTo(typeof(ContextStaticAttribute))]
[assembly: TypeForwardedTo(typeof(Convert))]
[assembly: TypeForwardedTo(typeof(Converter<, >))]
[assembly: TypeForwardedTo(typeof(AcceptRejectRule))]
[assembly: TypeForwardedTo(typeof(CommandBehavior))]
[assembly: TypeForwardedTo(typeof(CommandType))]
[assembly: TypeForwardedTo(typeof(CatalogLocation))]
[assembly: TypeForwardedTo(typeof(DataAdapter))]
[assembly: TypeForwardedTo(typeof(DataColumnMapping))]
[assembly: TypeForwardedTo(typeof(DataColumnMappingCollection))]
[assembly: TypeForwardedTo(typeof(DataTableMapping))]
[assembly: TypeForwardedTo(typeof(DataTableMappingCollection))]
[assembly: TypeForwardedTo(typeof(DbColumn))]
[assembly: TypeForwardedTo(typeof(DbCommand))]
[assembly: TypeForwardedTo(typeof(DbCommandBuilder))]
[assembly: TypeForwardedTo(typeof(DbConnection))]
[assembly: TypeForwardedTo(typeof(DbConnectionStringBuilder))]
[assembly: TypeForwardedTo(typeof(DbDataAdapter))]
[assembly: TypeForwardedTo(typeof(DbDataReader))]
[assembly: TypeForwardedTo(typeof(DbDataReaderExtensions))]
[assembly: TypeForwardedTo(typeof(DbDataRecord))]
[assembly: TypeForwardedTo(typeof(DbDataSourceEnumerator))]
[assembly: TypeForwardedTo(typeof(DbEnumerator))]
[assembly: TypeForwardedTo(typeof(DbException))]
[assembly: TypeForwardedTo(typeof(DbMetaDataCollectionNames))]
[assembly: TypeForwardedTo(typeof(DbMetaDataColumnNames))]
[assembly: TypeForwardedTo(typeof(DbParameter))]
[assembly: TypeForwardedTo(typeof(DbParameterCollection))]
[assembly: TypeForwardedTo(typeof(DbProviderFactories))]
[assembly: TypeForwardedTo(typeof(DbProviderFactory))]
[assembly: TypeForwardedTo(typeof(DbProviderSpecificTypePropertyAttribute))]
[assembly: TypeForwardedTo(typeof(DbTransaction))]
[assembly: TypeForwardedTo(typeof(GroupByBehavior))]
[assembly: TypeForwardedTo(typeof(IDbColumnSchemaGenerator))]
[assembly: TypeForwardedTo(typeof(IdentifierCase))]
[assembly: TypeForwardedTo(typeof(RowUpdatedEventArgs))]
[assembly: TypeForwardedTo(typeof(RowUpdatingEventArgs))]
[assembly: TypeForwardedTo(typeof(SchemaTableColumn))]
[assembly: TypeForwardedTo(typeof(SchemaTableOptionalColumn))]
[assembly: TypeForwardedTo(typeof(SupportedJoinOperators))]
[assembly: TypeForwardedTo(typeof(ConflictOption))]
[assembly: TypeForwardedTo(typeof(ConnectionState))]
[assembly: TypeForwardedTo(typeof(Constraint))]
[assembly: TypeForwardedTo(typeof(ConstraintCollection))]
[assembly: TypeForwardedTo(typeof(ConstraintException))]
[assembly: TypeForwardedTo(typeof(DataColumn))]
[assembly: TypeForwardedTo(typeof(DataColumnChangeEventArgs))]
[assembly: TypeForwardedTo(typeof(DataColumnChangeEventHandler))]
[assembly: TypeForwardedTo(typeof(DataColumnCollection))]
[assembly: TypeForwardedTo(typeof(DataException))]
[assembly: TypeForwardedTo(typeof(DataReaderExtensions))]
[assembly: TypeForwardedTo(typeof(DataRelation))]
[assembly: TypeForwardedTo(typeof(DataRelationCollection))]
[assembly: TypeForwardedTo(typeof(DataRow))]
[assembly: TypeForwardedTo(typeof(DataRowAction))]
[assembly: TypeForwardedTo(typeof(DataRowBuilder))]
[assembly: TypeForwardedTo(typeof(DataRowChangeEventArgs))]
[assembly: TypeForwardedTo(typeof(DataRowChangeEventHandler))]
[assembly: TypeForwardedTo(typeof(DataRowCollection))]
[assembly: TypeForwardedTo(typeof(DataRowComparer))]
[assembly: TypeForwardedTo(typeof(DataRowComparer<>))]
[assembly: TypeForwardedTo(typeof(DataRowExtensions))]
[assembly: TypeForwardedTo(typeof(DataRowState))]
[assembly: TypeForwardedTo(typeof(DataRowVersion))]
[assembly: TypeForwardedTo(typeof(DataRowView))]
[assembly: TypeForwardedTo(typeof(DataSet))]
[assembly: TypeForwardedTo(typeof(DataSetDateTime))]
[assembly: TypeForwardedTo(typeof(DataSysDescriptionAttribute))]
[assembly: TypeForwardedTo(typeof(DataTable))]
[assembly: TypeForwardedTo(typeof(DataTableClearEventArgs))]
[assembly: TypeForwardedTo(typeof(DataTableClearEventHandler))]
[assembly: TypeForwardedTo(typeof(DataTableCollection))]
[assembly: TypeForwardedTo(typeof(DataTableExtensions))]
[assembly: TypeForwardedTo(typeof(DataTableNewRowEventArgs))]
[assembly: TypeForwardedTo(typeof(DataTableNewRowEventHandler))]
[assembly: TypeForwardedTo(typeof(DataTableReader))]
[assembly: TypeForwardedTo(typeof(DataView))]
[assembly: TypeForwardedTo(typeof(DataViewManager))]
[assembly: TypeForwardedTo(typeof(DataViewRowState))]
[assembly: TypeForwardedTo(typeof(DataViewSetting))]
[assembly: TypeForwardedTo(typeof(DataViewSettingCollection))]
[assembly: TypeForwardedTo(typeof(DBConcurrencyException))]
[assembly: TypeForwardedTo(typeof(DbType))]
[assembly: TypeForwardedTo(typeof(DeletedRowInaccessibleException))]
[assembly: TypeForwardedTo(typeof(DuplicateNameException))]
[assembly: TypeForwardedTo(typeof(EnumerableRowCollection))]
[assembly: TypeForwardedTo(typeof(EnumerableRowCollection<>))]
[assembly: TypeForwardedTo(typeof(EnumerableRowCollectionExtensions))]
[assembly: TypeForwardedTo(typeof(EvaluateException))]
[assembly: TypeForwardedTo(typeof(FillErrorEventArgs))]
[assembly: TypeForwardedTo(typeof(FillErrorEventHandler))]
[assembly: TypeForwardedTo(typeof(ForeignKeyConstraint))]
[assembly: TypeForwardedTo(typeof(IColumnMapping))]
[assembly: TypeForwardedTo(typeof(IColumnMappingCollection))]
[assembly: TypeForwardedTo(typeof(IDataAdapter))]
[assembly: TypeForwardedTo(typeof(IDataParameter))]
[assembly: TypeForwardedTo(typeof(IDataParameterCollection))]
[assembly: TypeForwardedTo(typeof(IDataReader))]
[assembly: TypeForwardedTo(typeof(IDataRecord))]
[assembly: TypeForwardedTo(typeof(IDbCommand))]
[assembly: TypeForwardedTo(typeof(IDbConnection))]
[assembly: TypeForwardedTo(typeof(IDbDataAdapter))]
[assembly: TypeForwardedTo(typeof(IDbDataParameter))]
[assembly: TypeForwardedTo(typeof(IDbTransaction))]
[assembly: TypeForwardedTo(typeof(InRowChangingEventException))]
[assembly: TypeForwardedTo(typeof(InternalDataCollectionBase))]
[assembly: TypeForwardedTo(typeof(InvalidConstraintException))]
[assembly: TypeForwardedTo(typeof(InvalidExpressionException))]
[assembly: TypeForwardedTo(typeof(System.Data.IsolationLevel))]
[assembly: TypeForwardedTo(typeof(ITableMapping))]
[assembly: TypeForwardedTo(typeof(ITableMappingCollection))]
[assembly: TypeForwardedTo(typeof(KeyRestrictionBehavior))]
[assembly: TypeForwardedTo(typeof(LoadOption))]
[assembly: TypeForwardedTo(typeof(MappingType))]
[assembly: TypeForwardedTo(typeof(MergeFailedEventArgs))]
[assembly: TypeForwardedTo(typeof(MergeFailedEventHandler))]
[assembly: TypeForwardedTo(typeof(MissingMappingAction))]
[assembly: TypeForwardedTo(typeof(MissingPrimaryKeyException))]
[assembly: TypeForwardedTo(typeof(MissingSchemaAction))]
[assembly: TypeForwardedTo(typeof(NoNullAllowedException))]
[assembly: TypeForwardedTo(typeof(OrderedEnumerableRowCollection<>))]
[assembly: TypeForwardedTo(typeof(ParameterDirection))]
[assembly: TypeForwardedTo(typeof(PropertyCollection))]
[assembly: TypeForwardedTo(typeof(ReadOnlyException))]
[assembly: TypeForwardedTo(typeof(RowNotInTableException))]
[assembly: TypeForwardedTo(typeof(Rule))]
[assembly: TypeForwardedTo(typeof(SchemaSerializationMode))]
[assembly: TypeForwardedTo(typeof(SchemaType))]
[assembly: TypeForwardedTo(typeof(SerializationFormat))]
[assembly: TypeForwardedTo(typeof(SqlDbType))]
[assembly: TypeForwardedTo(typeof(INullable))]
[assembly: TypeForwardedTo(typeof(SqlAlreadyFilledException))]
[assembly: TypeForwardedTo(typeof(SqlBinary))]
[assembly: TypeForwardedTo(typeof(SqlBoolean))]
[assembly: TypeForwardedTo(typeof(SqlByte))]
[assembly: TypeForwardedTo(typeof(SqlBytes))]
[assembly: TypeForwardedTo(typeof(SqlChars))]
[assembly: TypeForwardedTo(typeof(SqlCompareOptions))]
[assembly: TypeForwardedTo(typeof(SqlDateTime))]
[assembly: TypeForwardedTo(typeof(SqlDecimal))]
[assembly: TypeForwardedTo(typeof(SqlDouble))]
[assembly: TypeForwardedTo(typeof(SqlGuid))]
[assembly: TypeForwardedTo(typeof(SqlInt16))]
[assembly: TypeForwardedTo(typeof(SqlInt32))]
[assembly: TypeForwardedTo(typeof(SqlInt64))]
[assembly: TypeForwardedTo(typeof(SqlMoney))]
[assembly: TypeForwardedTo(typeof(SqlNotFilledException))]
[assembly: TypeForwardedTo(typeof(SqlNullValueException))]
[assembly: TypeForwardedTo(typeof(SqlSingle))]
[assembly: TypeForwardedTo(typeof(SqlString))]
[assembly: TypeForwardedTo(typeof(SqlTruncateException))]
[assembly: TypeForwardedTo(typeof(SqlTypeException))]
[assembly: TypeForwardedTo(typeof(SqlXml))]
[assembly: TypeForwardedTo(typeof(StorageState))]
[assembly: TypeForwardedTo(typeof(StateChangeEventArgs))]
[assembly: TypeForwardedTo(typeof(StateChangeEventHandler))]
[assembly: TypeForwardedTo(typeof(StatementCompletedEventArgs))]
[assembly: TypeForwardedTo(typeof(StatementCompletedEventHandler))]
[assembly: TypeForwardedTo(typeof(StatementType))]
[assembly: TypeForwardedTo(typeof(StrongTypingException))]
[assembly: TypeForwardedTo(typeof(SyntaxErrorException))]
[assembly: TypeForwardedTo(typeof(TypedTableBase<>))]
[assembly: TypeForwardedTo(typeof(TypedTableBaseExtensions))]
[assembly: TypeForwardedTo(typeof(UniqueConstraint))]
[assembly: TypeForwardedTo(typeof(UpdateRowSource))]
[assembly: TypeForwardedTo(typeof(UpdateStatus))]
[assembly: TypeForwardedTo(typeof(VersionNotFoundException))]
[assembly: TypeForwardedTo(typeof(XmlReadMode))]
[assembly: TypeForwardedTo(typeof(XmlWriteMode))]
[assembly: TypeForwardedTo(typeof(DataMisalignedException))]
[assembly: TypeForwardedTo(typeof(DateTime))]
[assembly: TypeForwardedTo(typeof(DateTimeKind))]
[assembly: TypeForwardedTo(typeof(DateTimeOffset))]
[assembly: TypeForwardedTo(typeof(DayOfWeek))]
[assembly: TypeForwardedTo(typeof(DBNull))]
[assembly: TypeForwardedTo(typeof(decimal))]
[assembly: TypeForwardedTo(typeof(Delegate))]
[assembly: TypeForwardedTo(typeof(BooleanSwitch))]
[assembly: TypeForwardedTo(typeof(AllowNullAttribute))]
[assembly: TypeForwardedTo(typeof(DisallowNullAttribute))]
[assembly: TypeForwardedTo(typeof(DoesNotReturnAttribute))]
[assembly: TypeForwardedTo(typeof(DoesNotReturnIfAttribute))]
[assembly: TypeForwardedTo(typeof(ExcludeFromCodeCoverageAttribute))]
[assembly: TypeForwardedTo(typeof(MaybeNullAttribute))]
[assembly: TypeForwardedTo(typeof(MaybeNullWhenAttribute))]
[assembly: TypeForwardedTo(typeof(NotNullAttribute))]
[assembly: TypeForwardedTo(typeof(NotNullIfNotNullAttribute))]
[assembly: TypeForwardedTo(typeof(NotNullWhenAttribute))]
[assembly: TypeForwardedTo(typeof(SuppressMessageAttribute))]
[assembly: TypeForwardedTo(typeof(ConditionalAttribute))]
[assembly: TypeForwardedTo(typeof(Contract))]
[assembly: TypeForwardedTo(typeof(ContractAbbreviatorAttribute))]
[assembly: TypeForwardedTo(typeof(ContractArgumentValidatorAttribute))]
[assembly: TypeForwardedTo(typeof(ContractClassAttribute))]
[assembly: TypeForwardedTo(typeof(ContractClassForAttribute))]
[assembly: TypeForwardedTo(typeof(ContractFailedEventArgs))]
[assembly: TypeForwardedTo(typeof(ContractFailureKind))]
[assembly: TypeForwardedTo(typeof(ContractInvariantMethodAttribute))]
[assembly: TypeForwardedTo(typeof(ContractOptionAttribute))]
[assembly: TypeForwardedTo(typeof(ContractPublicPropertyNameAttribute))]
[assembly: TypeForwardedTo(typeof(ContractReferenceAssemblyAttribute))]
[assembly: TypeForwardedTo(typeof(ContractRuntimeIgnoredAttribute))]
[assembly: TypeForwardedTo(typeof(ContractVerificationAttribute))]
[assembly: TypeForwardedTo(typeof(PureAttribute))]
[assembly: TypeForwardedTo(typeof(CorrelationManager))]
[assembly: TypeForwardedTo(typeof(DataReceivedEventArgs))]
[assembly: TypeForwardedTo(typeof(DataReceivedEventHandler))]
[assembly: TypeForwardedTo(typeof(Debug))]
[assembly: TypeForwardedTo(typeof(DebuggableAttribute))]
[assembly: TypeForwardedTo(typeof(Debugger))]
[assembly: TypeForwardedTo(typeof(DebuggerBrowsableAttribute))]
[assembly: TypeForwardedTo(typeof(DebuggerBrowsableState))]
[assembly: TypeForwardedTo(typeof(DebuggerDisplayAttribute))]
[assembly: TypeForwardedTo(typeof(DebuggerHiddenAttribute))]
[assembly: TypeForwardedTo(typeof(DebuggerNonUserCodeAttribute))]
[assembly: TypeForwardedTo(typeof(DebuggerStepperBoundaryAttribute))]
[assembly: TypeForwardedTo(typeof(DebuggerStepThroughAttribute))]
[assembly: TypeForwardedTo(typeof(DebuggerTypeProxyAttribute))]
[assembly: TypeForwardedTo(typeof(DebuggerVisualizerAttribute))]
[assembly: TypeForwardedTo(typeof(DefaultTraceListener))]
[assembly: TypeForwardedTo(typeof(DelimitedListTraceListener))]
[assembly: TypeForwardedTo(typeof(EventTypeFilter))]
[assembly: TypeForwardedTo(typeof(FileVersionInfo))]
[assembly: TypeForwardedTo(typeof(MonitoringDescriptionAttribute))]
[assembly: TypeForwardedTo(typeof(Process))]
[assembly: TypeForwardedTo(typeof(ProcessModule))]
[assembly: TypeForwardedTo(typeof(ProcessModuleCollection))]
[assembly: TypeForwardedTo(typeof(ProcessPriorityClass))]
[assembly: TypeForwardedTo(typeof(ProcessStartInfo))]
[assembly: TypeForwardedTo(typeof(ProcessThread))]
[assembly: TypeForwardedTo(typeof(ProcessThreadCollection))]
[assembly: TypeForwardedTo(typeof(ProcessWindowStyle))]
[assembly: TypeForwardedTo(typeof(SourceFilter))]
[assembly: TypeForwardedTo(typeof(SourceLevels))]
[assembly: TypeForwardedTo(typeof(SourceSwitch))]
[assembly: TypeForwardedTo(typeof(StackFrame))]
[assembly: TypeForwardedTo(typeof(StackFrameExtensions))]
[assembly: TypeForwardedTo(typeof(StackTrace))]
[assembly: TypeForwardedTo(typeof(Stopwatch))]
[assembly: TypeForwardedTo(typeof(Switch))]
[assembly: TypeForwardedTo(typeof(SwitchAttribute))]
[assembly: TypeForwardedTo(typeof(SwitchLevelAttribute))]
[assembly: TypeForwardedTo(typeof(ISymbolBinder))]
[assembly: TypeForwardedTo(typeof(ISymbolBinder1))]
[assembly: TypeForwardedTo(typeof(ISymbolDocument))]
[assembly: TypeForwardedTo(typeof(ISymbolDocumentWriter))]
[assembly: TypeForwardedTo(typeof(ISymbolMethod))]
[assembly: TypeForwardedTo(typeof(ISymbolNamespace))]
[assembly: TypeForwardedTo(typeof(ISymbolReader))]
[assembly: TypeForwardedTo(typeof(ISymbolScope))]
[assembly: TypeForwardedTo(typeof(ISymbolVariable))]
[assembly: TypeForwardedTo(typeof(ISymbolWriter))]
[assembly: TypeForwardedTo(typeof(SymAddressKind))]
[assembly: TypeForwardedTo(typeof(SymbolToken))]
[assembly: TypeForwardedTo(typeof(SymDocumentType))]
[assembly: TypeForwardedTo(typeof(SymLanguageType))]
[assembly: TypeForwardedTo(typeof(SymLanguageVendor))]
[assembly: TypeForwardedTo(typeof(TextWriterTraceListener))]
[assembly: TypeForwardedTo(typeof(ThreadPriorityLevel))]
[assembly: TypeForwardedTo(typeof(System.Diagnostics.ThreadState))]
[assembly: TypeForwardedTo(typeof(ThreadWaitReason))]
[assembly: TypeForwardedTo(typeof(Trace))]
[assembly: TypeForwardedTo(typeof(TraceEventCache))]
[assembly: TypeForwardedTo(typeof(TraceEventType))]
[assembly: TypeForwardedTo(typeof(TraceFilter))]
[assembly: TypeForwardedTo(typeof(TraceLevel))]
[assembly: TypeForwardedTo(typeof(TraceListener))]
[assembly: TypeForwardedTo(typeof(TraceListenerCollection))]
[assembly: TypeForwardedTo(typeof(TraceOptions))]
[assembly: TypeForwardedTo(typeof(TraceSource))]
[assembly: TypeForwardedTo(typeof(TraceSwitch))]
[assembly: TypeForwardedTo(typeof(DiagnosticCounter))]
[assembly: TypeForwardedTo(typeof(EventActivityOptions))]
[assembly: TypeForwardedTo(typeof(EventAttribute))]
[assembly: TypeForwardedTo(typeof(EventChannel))]
[assembly: TypeForwardedTo(typeof(EventCommand))]
[assembly: TypeForwardedTo(typeof(EventCommandEventArgs))]
[assembly: TypeForwardedTo(typeof(EventCounter))]
[assembly: TypeForwardedTo(typeof(EventDataAttribute))]
[assembly: TypeForwardedTo(typeof(EventFieldAttribute))]
[assembly: TypeForwardedTo(typeof(EventFieldFormat))]
[assembly: TypeForwardedTo(typeof(EventFieldTags))]
[assembly: TypeForwardedTo(typeof(EventIgnoreAttribute))]
[assembly: TypeForwardedTo(typeof(EventKeywords))]
[assembly: TypeForwardedTo(typeof(EventLevel))]
[assembly: TypeForwardedTo(typeof(EventListener))]
[assembly: TypeForwardedTo(typeof(EventManifestOptions))]
[assembly: TypeForwardedTo(typeof(EventOpcode))]
[assembly: TypeForwardedTo(typeof(EventSource))]
[assembly: TypeForwardedTo(typeof(EventSourceAttribute))]
[assembly: TypeForwardedTo(typeof(EventSourceCreatedEventArgs))]
[assembly: TypeForwardedTo(typeof(EventSourceException))]
[assembly: TypeForwardedTo(typeof(EventSourceOptions))]
[assembly: TypeForwardedTo(typeof(EventSourceSettings))]
[assembly: TypeForwardedTo(typeof(EventTags))]
[assembly: TypeForwardedTo(typeof(EventTask))]
[assembly: TypeForwardedTo(typeof(EventWrittenEventArgs))]
[assembly: TypeForwardedTo(typeof(IncrementingEventCounter))]
[assembly: TypeForwardedTo(typeof(IncrementingPollingCounter))]
[assembly: TypeForwardedTo(typeof(NonEventAttribute))]
[assembly: TypeForwardedTo(typeof(PollingCounter))]
[assembly: TypeForwardedTo(typeof(DivideByZeroException))]
[assembly: TypeForwardedTo(typeof(DllNotFoundException))]
[assembly: TypeForwardedTo(typeof(double))]
[assembly: TypeForwardedTo(typeof(Color))]
[assembly: TypeForwardedTo(typeof(ColorConverter))]
[assembly: TypeForwardedTo(typeof(KnownColor))]
[assembly: TypeForwardedTo(typeof(Point))]
[assembly: TypeForwardedTo(typeof(PointConverter))]
[assembly: TypeForwardedTo(typeof(PointF))]
[assembly: TypeForwardedTo(typeof(Rectangle))]
[assembly: TypeForwardedTo(typeof(RectangleConverter))]
[assembly: TypeForwardedTo(typeof(RectangleF))]
[assembly: TypeForwardedTo(typeof(Size))]
[assembly: TypeForwardedTo(typeof(SizeConverter))]
[assembly: TypeForwardedTo(typeof(SizeF))]
[assembly: TypeForwardedTo(typeof(SizeFConverter))]
[assembly: TypeForwardedTo(typeof(DuplicateWaitObjectException))]
[assembly: TypeForwardedTo(typeof(BinaryOperationBinder))]
[assembly: TypeForwardedTo(typeof(BindingRestrictions))]
[assembly: TypeForwardedTo(typeof(CallInfo))]
[assembly: TypeForwardedTo(typeof(ConvertBinder))]
[assembly: TypeForwardedTo(typeof(CreateInstanceBinder))]
[assembly: TypeForwardedTo(typeof(DeleteIndexBinder))]
[assembly: TypeForwardedTo(typeof(DeleteMemberBinder))]
[assembly: TypeForwardedTo(typeof(DynamicMetaObject))]
[assembly: TypeForwardedTo(typeof(DynamicMetaObjectBinder))]
[assembly: TypeForwardedTo(typeof(DynamicObject))]
[assembly: TypeForwardedTo(typeof(ExpandoObject))]
[assembly: TypeForwardedTo(typeof(GetIndexBinder))]
[assembly: TypeForwardedTo(typeof(GetMemberBinder))]
[assembly: TypeForwardedTo(typeof(IDynamicMetaObjectProvider))]
[assembly: TypeForwardedTo(typeof(IInvokeOnGetBinder))]
[assembly: TypeForwardedTo(typeof(InvokeBinder))]
[assembly: TypeForwardedTo(typeof(InvokeMemberBinder))]
[assembly: TypeForwardedTo(typeof(SetIndexBinder))]
[assembly: TypeForwardedTo(typeof(SetMemberBinder))]
[assembly: TypeForwardedTo(typeof(UnaryOperationBinder))]
[assembly: TypeForwardedTo(typeof(EntryPointNotFoundException))]
[assembly: TypeForwardedTo(typeof(Enum))]
[assembly: TypeForwardedTo(typeof(Environment))]
[assembly: TypeForwardedTo(typeof(EnvironmentVariableTarget))]
[assembly: TypeForwardedTo(typeof(EventArgs))]
[assembly: TypeForwardedTo(typeof(EventHandler))]
[assembly: TypeForwardedTo(typeof(EventHandler<>))]
[assembly: TypeForwardedTo(typeof(Exception))]
[assembly: TypeForwardedTo(typeof(ExecutionEngineException))]
[assembly: TypeForwardedTo(typeof(FieldAccessException))]
[assembly: TypeForwardedTo(typeof(FileStyleUriParser))]
[assembly: TypeForwardedTo(typeof(FlagsAttribute))]
[assembly: TypeForwardedTo(typeof(FormatException))]
[assembly: TypeForwardedTo(typeof(FormattableString))]
[assembly: TypeForwardedTo(typeof(FtpStyleUriParser))]
[assembly: TypeForwardedTo(typeof(Func<>))]
[assembly: TypeForwardedTo(typeof(Func<, , , , , , , , , >))]
[assembly: TypeForwardedTo(typeof(Func<, , , , , , , , , , >))]
[assembly: TypeForwardedTo(typeof(Func<, , , , , , , , , , , >))]
[assembly: TypeForwardedTo(typeof(Func<, , , , , , , , , , , , >))]
[assembly: TypeForwardedTo(typeof(Func<, , , , , , , , , , , , , >))]
[assembly: TypeForwardedTo(typeof(Func<, , , , , , , , , , , , , , >))]
[assembly: TypeForwardedTo(typeof(Func<, , , , , , , , , , , , , , , >))]
[assembly: TypeForwardedTo(typeof(Func<, , , , , , , , , , , , , , , , >))]
[assembly: TypeForwardedTo(typeof(Func<, >))]
[assembly: TypeForwardedTo(typeof(Func<, , >))]
[assembly: TypeForwardedTo(typeof(Func<, , , >))]
[assembly: TypeForwardedTo(typeof(Func<, , , , >))]
[assembly: TypeForwardedTo(typeof(Func<, , , , , >))]
[assembly: TypeForwardedTo(typeof(Func<, , , , , , >))]
[assembly: TypeForwardedTo(typeof(Func<, , , , , , , >))]
[assembly: TypeForwardedTo(typeof(Func<, , , , , , , , >))]
[assembly: TypeForwardedTo(typeof(GC))]
[assembly: TypeForwardedTo(typeof(GCCollectionMode))]
[assembly: TypeForwardedTo(typeof(GCNotificationStatus))]
[assembly: TypeForwardedTo(typeof(GenericUriParser))]
[assembly: TypeForwardedTo(typeof(GenericUriParserOptions))]
[assembly: TypeForwardedTo(typeof(Calendar))]
[assembly: TypeForwardedTo(typeof(CalendarAlgorithmType))]
[assembly: TypeForwardedTo(typeof(CalendarWeekRule))]
[assembly: TypeForwardedTo(typeof(CharUnicodeInfo))]
[assembly: TypeForwardedTo(typeof(ChineseLunisolarCalendar))]
[assembly: TypeForwardedTo(typeof(CompareInfo))]
[assembly: TypeForwardedTo(typeof(CompareOptions))]
[assembly: TypeForwardedTo(typeof(CultureInfo))]
[assembly: TypeForwardedTo(typeof(CultureNotFoundException))]
[assembly: TypeForwardedTo(typeof(CultureTypes))]
[assembly: TypeForwardedTo(typeof(DateTimeFormatInfo))]
[assembly: TypeForwardedTo(typeof(DateTimeStyles))]
[assembly: TypeForwardedTo(typeof(DaylightTime))]
[assembly: TypeForwardedTo(typeof(DigitShapes))]
[assembly: TypeForwardedTo(typeof(EastAsianLunisolarCalendar))]
[assembly: TypeForwardedTo(typeof(GlobalizationExtensions))]
[assembly: TypeForwardedTo(typeof(GregorianCalendar))]
[assembly: TypeForwardedTo(typeof(GregorianCalendarTypes))]
[assembly: TypeForwardedTo(typeof(HebrewCalendar))]
[assembly: TypeForwardedTo(typeof(HijriCalendar))]
[assembly: TypeForwardedTo(typeof(IdnMapping))]
[assembly: TypeForwardedTo(typeof(ISOWeek))]
[assembly: TypeForwardedTo(typeof(JapaneseCalendar))]
[assembly: TypeForwardedTo(typeof(JapaneseLunisolarCalendar))]
[assembly: TypeForwardedTo(typeof(JulianCalendar))]
[assembly: TypeForwardedTo(typeof(KoreanCalendar))]
[assembly: TypeForwardedTo(typeof(KoreanLunisolarCalendar))]
[assembly: TypeForwardedTo(typeof(NumberFormatInfo))]
[assembly: TypeForwardedTo(typeof(NumberStyles))]
[assembly: TypeForwardedTo(typeof(PersianCalendar))]
[assembly: TypeForwardedTo(typeof(RegionInfo))]
[assembly: TypeForwardedTo(typeof(SortKey))]
[assembly: TypeForwardedTo(typeof(SortVersion))]
[assembly: TypeForwardedTo(typeof(StringInfo))]
[assembly: TypeForwardedTo(typeof(TaiwanCalendar))]
[assembly: TypeForwardedTo(typeof(TaiwanLunisolarCalendar))]
[assembly: TypeForwardedTo(typeof(TextElementEnumerator))]
[assembly: TypeForwardedTo(typeof(TextInfo))]
[assembly: TypeForwardedTo(typeof(ThaiBuddhistCalendar))]
[assembly: TypeForwardedTo(typeof(TimeSpanStyles))]
[assembly: TypeForwardedTo(typeof(UmAlQuraCalendar))]
[assembly: TypeForwardedTo(typeof(UnicodeCategory))]
[assembly: TypeForwardedTo(typeof(GopherStyleUriParser))]
[assembly: TypeForwardedTo(typeof(Guid))]
[assembly: TypeForwardedTo(typeof(HashCode))]
[assembly: TypeForwardedTo(typeof(HttpStyleUriParser))]
[assembly: TypeForwardedTo(typeof(IAsyncDisposable))]
[assembly: TypeForwardedTo(typeof(IAsyncResult))]
[assembly: TypeForwardedTo(typeof(ICloneable))]
[assembly: TypeForwardedTo(typeof(IComparable))]
[assembly: TypeForwardedTo(typeof(IComparable<>))]
[assembly: TypeForwardedTo(typeof(IConvertible))]
[assembly: TypeForwardedTo(typeof(ICustomFormatter))]
[assembly: TypeForwardedTo(typeof(IDisposable))]
[assembly: TypeForwardedTo(typeof(IEquatable<>))]
[assembly: TypeForwardedTo(typeof(IFormatProvider))]
[assembly: TypeForwardedTo(typeof(IFormattable))]
[assembly: TypeForwardedTo(typeof(Index))]
[assembly: TypeForwardedTo(typeof(IndexOutOfRangeException))]
[assembly: TypeForwardedTo(typeof(InsufficientExecutionStackException))]
[assembly: TypeForwardedTo(typeof(InsufficientMemoryException))]
[assembly: TypeForwardedTo(typeof(short))]
[assembly: TypeForwardedTo(typeof(int))]
[assembly: TypeForwardedTo(typeof(long))]
[assembly: TypeForwardedTo(typeof(IntPtr))]
[assembly: TypeForwardedTo(typeof(InvalidCastException))]
[assembly: TypeForwardedTo(typeof(InvalidOperationException))]
[assembly: TypeForwardedTo(typeof(InvalidProgramException))]
[assembly: TypeForwardedTo(typeof(InvalidTimeZoneException))]
[assembly: TypeForwardedTo(typeof(BinaryReader))]
[assembly: TypeForwardedTo(typeof(BinaryWriter))]
[assembly: TypeForwardedTo(typeof(BufferedStream))]
[assembly: TypeForwardedTo(typeof(BrotliDecoder))]
[assembly: TypeForwardedTo(typeof(BrotliEncoder))]
[assembly: TypeForwardedTo(typeof(BrotliStream))]
[assembly: TypeForwardedTo(typeof(CompressionLevel))]
[assembly: TypeForwardedTo(typeof(CompressionMode))]
[assembly: TypeForwardedTo(typeof(DeflateStream))]
[assembly: TypeForwardedTo(typeof(GZipStream))]
[assembly: TypeForwardedTo(typeof(ZipArchive))]
[assembly: TypeForwardedTo(typeof(ZipArchiveEntry))]
[assembly: TypeForwardedTo(typeof(ZipArchiveMode))]
[assembly: TypeForwardedTo(typeof(ZipFile))]
[assembly: TypeForwardedTo(typeof(ZipFileExtensions))]
[assembly: TypeForwardedTo(typeof(Directory))]
[assembly: TypeForwardedTo(typeof(DirectoryInfo))]
[assembly: TypeForwardedTo(typeof(DirectoryNotFoundException))]
[assembly: TypeForwardedTo(typeof(DriveInfo))]
[assembly: TypeForwardedTo(typeof(DriveNotFoundException))]
[assembly: TypeForwardedTo(typeof(DriveType))]
[assembly: TypeForwardedTo(typeof(EndOfStreamException))]
[assembly: TypeForwardedTo(typeof(FileSystemEntry))]
[assembly: TypeForwardedTo(typeof(FileSystemEnumerable<>))]
[assembly: TypeForwardedTo(typeof(FileSystemEnumerator<>))]
[assembly: TypeForwardedTo(typeof(FileSystemName))]
[assembly: TypeForwardedTo(typeof(EnumerationOptions))]
[assembly: TypeForwardedTo(typeof(ErrorEventArgs))]
[assembly: TypeForwardedTo(typeof(ErrorEventHandler))]
[assembly: TypeForwardedTo(typeof(File))]
[assembly: TypeForwardedTo(typeof(FileAccess))]
[assembly: TypeForwardedTo(typeof(FileAttributes))]
[assembly: TypeForwardedTo(typeof(FileInfo))]
[assembly: TypeForwardedTo(typeof(FileLoadException))]
[assembly: TypeForwardedTo(typeof(FileMode))]
[assembly: TypeForwardedTo(typeof(FileNotFoundException))]
[assembly: TypeForwardedTo(typeof(FileOptions))]
[assembly: TypeForwardedTo(typeof(FileShare))]
[assembly: TypeForwardedTo(typeof(FileStream))]
[assembly: TypeForwardedTo(typeof(FileSystemEventArgs))]
[assembly: TypeForwardedTo(typeof(FileSystemEventHandler))]
[assembly: TypeForwardedTo(typeof(FileSystemInfo))]
[assembly: TypeForwardedTo(typeof(FileSystemWatcher))]
[assembly: TypeForwardedTo(typeof(HandleInheritability))]
[assembly: TypeForwardedTo(typeof(InternalBufferOverflowException))]
[assembly: TypeForwardedTo(typeof(InvalidDataException))]
[assembly: TypeForwardedTo(typeof(IOException))]
[assembly: TypeForwardedTo(typeof(INormalizeForIsolatedStorage))]
[assembly: TypeForwardedTo(typeof(IsolatedStorage))]
[assembly: TypeForwardedTo(typeof(IsolatedStorageException))]
[assembly: TypeForwardedTo(typeof(IsolatedStorageFile))]
[assembly: TypeForwardedTo(typeof(IsolatedStorageFileStream))]
[assembly: TypeForwardedTo(typeof(IsolatedStorageScope))]
[assembly: TypeForwardedTo(typeof(MatchCasing))]
[assembly: TypeForwardedTo(typeof(MatchType))]
[assembly: TypeForwardedTo(typeof(MemoryMappedFile))]
[assembly: TypeForwardedTo(typeof(MemoryMappedFileAccess))]
[assembly: TypeForwardedTo(typeof(MemoryMappedFileOptions))]
[assembly: TypeForwardedTo(typeof(MemoryMappedFileRights))]
[assembly: TypeForwardedTo(typeof(MemoryMappedViewAccessor))]
[assembly: TypeForwardedTo(typeof(MemoryMappedViewStream))]
[assembly: TypeForwardedTo(typeof(MemoryStream))]
[assembly: TypeForwardedTo(typeof(NotifyFilters))]
[assembly: TypeForwardedTo(typeof(Path))]
[assembly: TypeForwardedTo(typeof(PathTooLongException))]
[assembly: TypeForwardedTo(typeof(AnonymousPipeClientStream))]
[assembly: TypeForwardedTo(typeof(AnonymousPipeServerStream))]
[assembly: TypeForwardedTo(typeof(NamedPipeClientStream))]
[assembly: TypeForwardedTo(typeof(NamedPipeServerStream))]
[assembly: TypeForwardedTo(typeof(PipeDirection))]
[assembly: TypeForwardedTo(typeof(PipeOptions))]
[assembly: TypeForwardedTo(typeof(PipeStream))]
[assembly: TypeForwardedTo(typeof(PipeStreamImpersonationWorker))]
[assembly: TypeForwardedTo(typeof(PipeTransmissionMode))]
[assembly: TypeForwardedTo(typeof(RenamedEventArgs))]
[assembly: TypeForwardedTo(typeof(RenamedEventHandler))]
[assembly: TypeForwardedTo(typeof(SearchOption))]
[assembly: TypeForwardedTo(typeof(SeekOrigin))]
[assembly: TypeForwardedTo(typeof(Stream))]
[assembly: TypeForwardedTo(typeof(StreamReader))]
[assembly: TypeForwardedTo(typeof(StreamWriter))]
[assembly: TypeForwardedTo(typeof(StringReader))]
[assembly: TypeForwardedTo(typeof(StringWriter))]
[assembly: TypeForwardedTo(typeof(TextReader))]
[assembly: TypeForwardedTo(typeof(TextWriter))]
[assembly: TypeForwardedTo(typeof(UnmanagedMemoryAccessor))]
[assembly: TypeForwardedTo(typeof(UnmanagedMemoryStream))]
[assembly: TypeForwardedTo(typeof(WaitForChangedResult))]
[assembly: TypeForwardedTo(typeof(WatcherChangeTypes))]
[assembly: TypeForwardedTo(typeof(IObservable<>))]
[assembly: TypeForwardedTo(typeof(IObserver<>))]
[assembly: TypeForwardedTo(typeof(IProgress<>))]
[assembly: TypeForwardedTo(typeof(IServiceProvider))]
[assembly: TypeForwardedTo(typeof(Lazy<>))]
[assembly: TypeForwardedTo(typeof(Lazy<, >))]
[assembly: TypeForwardedTo(typeof(LdapStyleUriParser))]
[assembly: TypeForwardedTo(typeof(Enumerable))]
[assembly: TypeForwardedTo(typeof(EnumerableExecutor))]
[assembly: TypeForwardedTo(typeof(EnumerableExecutor<>))]
[assembly: TypeForwardedTo(typeof(EnumerableQuery))]
[assembly: TypeForwardedTo(typeof(EnumerableQuery<>))]
[assembly: TypeForwardedTo(typeof(BinaryExpression))]
[assembly: TypeForwardedTo(typeof(BlockExpression))]
[assembly: TypeForwardedTo(typeof(CatchBlock))]
[assembly: TypeForwardedTo(typeof(ConditionalExpression))]
[assembly: TypeForwardedTo(typeof(ConstantExpression))]
[assembly: TypeForwardedTo(typeof(DebugInfoExpression))]
[assembly: TypeForwardedTo(typeof(DefaultExpression))]
[assembly: TypeForwardedTo(typeof(DynamicExpression))]
[assembly: TypeForwardedTo(typeof(DynamicExpressionVisitor))]
[assembly: TypeForwardedTo(typeof(ElementInit))]
[assembly: TypeForwardedTo(typeof(Expression))]
[assembly: TypeForwardedTo(typeof(Expression<>))]
[assembly: TypeForwardedTo(typeof(ExpressionType))]
[assembly: TypeForwardedTo(typeof(ExpressionVisitor))]
[assembly: TypeForwardedTo(typeof(GotoExpression))]
[assembly: TypeForwardedTo(typeof(GotoExpressionKind))]
[assembly: TypeForwardedTo(typeof(IArgumentProvider))]
[assembly: TypeForwardedTo(typeof(IDynamicExpression))]
[assembly: TypeForwardedTo(typeof(IndexExpression))]
[assembly: TypeForwardedTo(typeof(InvocationExpression))]
[assembly: TypeForwardedTo(typeof(LabelExpression))]
[assembly: TypeForwardedTo(typeof(LabelTarget))]
[assembly: TypeForwardedTo(typeof(LambdaExpression))]
[assembly: TypeForwardedTo(typeof(ListInitExpression))]
[assembly: TypeForwardedTo(typeof(LoopExpression))]
[assembly: TypeForwardedTo(typeof(MemberAssignment))]
[assembly: TypeForwardedTo(typeof(MemberBinding))]
[assembly: TypeForwardedTo(typeof(MemberBindingType))]
[assembly: TypeForwardedTo(typeof(MemberExpression))]
[assembly: TypeForwardedTo(typeof(MemberInitExpression))]
[assembly: TypeForwardedTo(typeof(MemberListBinding))]
[assembly: TypeForwardedTo(typeof(MemberMemberBinding))]
[assembly: TypeForwardedTo(typeof(MethodCallExpression))]
[assembly: TypeForwardedTo(typeof(NewArrayExpression))]
[assembly: TypeForwardedTo(typeof(NewExpression))]
[assembly: TypeForwardedTo(typeof(ParameterExpression))]
[assembly: TypeForwardedTo(typeof(RuntimeVariablesExpression))]
[assembly: TypeForwardedTo(typeof(SwitchCase))]
[assembly: TypeForwardedTo(typeof(SwitchExpression))]
[assembly: TypeForwardedTo(typeof(SymbolDocumentInfo))]
[assembly: TypeForwardedTo(typeof(TryExpression))]
[assembly: TypeForwardedTo(typeof(TypeBinaryExpression))]
[assembly: TypeForwardedTo(typeof(UnaryExpression))]
[assembly: TypeForwardedTo(typeof(IGrouping<, >))]
[assembly: TypeForwardedTo(typeof(ILookup<, >))]
[assembly: TypeForwardedTo(typeof(IOrderedEnumerable<>))]
[assembly: TypeForwardedTo(typeof(IOrderedQueryable))]
[assembly: TypeForwardedTo(typeof(IOrderedQueryable<>))]
[assembly: TypeForwardedTo(typeof(IQueryable))]
[assembly: TypeForwardedTo(typeof(IQueryable<>))]
[assembly: TypeForwardedTo(typeof(IQueryProvider))]
[assembly: TypeForwardedTo(typeof(Lookup<, >))]
[assembly: TypeForwardedTo(typeof(OrderedParallelQuery<>))]
[assembly: TypeForwardedTo(typeof(ParallelEnumerable))]
[assembly: TypeForwardedTo(typeof(ParallelExecutionMode))]
[assembly: TypeForwardedTo(typeof(ParallelMergeOptions))]
[assembly: TypeForwardedTo(typeof(ParallelQuery))]
[assembly: TypeForwardedTo(typeof(ParallelQuery<>))]
[assembly: TypeForwardedTo(typeof(Queryable))]
[assembly: TypeForwardedTo(typeof(LoaderOptimization))]
[assembly: TypeForwardedTo(typeof(LoaderOptimizationAttribute))]
[assembly: TypeForwardedTo(typeof(LocalDataStoreSlot))]
[assembly: TypeForwardedTo(typeof(MarshalByRefObject))]
[assembly: TypeForwardedTo(typeof(Math))]
[assembly: TypeForwardedTo(typeof(MathF))]
[assembly: TypeForwardedTo(typeof(MemberAccessException))]
[assembly: TypeForwardedTo(typeof(Memory<>))]
[assembly: TypeForwardedTo(typeof(MemoryExtensions))]
[assembly: TypeForwardedTo(typeof(MethodAccessException))]
[assembly: TypeForwardedTo(typeof(MidpointRounding))]
[assembly: TypeForwardedTo(typeof(MissingFieldException))]
[assembly: TypeForwardedTo(typeof(MissingMemberException))]
[assembly: TypeForwardedTo(typeof(MissingMethodException))]
[assembly: TypeForwardedTo(typeof(ModuleHandle))]
[assembly: TypeForwardedTo(typeof(MTAThreadAttribute))]
[assembly: TypeForwardedTo(typeof(MulticastDelegate))]
[assembly: TypeForwardedTo(typeof(MulticastNotSupportedException))]
[assembly: TypeForwardedTo(typeof(AuthenticationManager))]
[assembly: TypeForwardedTo(typeof(AuthenticationSchemes))]
[assembly: TypeForwardedTo(typeof(AuthenticationSchemeSelector))]
[assembly: TypeForwardedTo(typeof(Authorization))]
[assembly: TypeForwardedTo(typeof(BindIPEndPoint))]
[assembly: TypeForwardedTo(typeof(HttpCacheAgeControl))]
[assembly: TypeForwardedTo(typeof(HttpRequestCacheLevel))]
[assembly: TypeForwardedTo(typeof(HttpRequestCachePolicy))]
[assembly: TypeForwardedTo(typeof(RequestCacheLevel))]
[assembly: TypeForwardedTo(typeof(RequestCachePolicy))]
[assembly: TypeForwardedTo(typeof(Cookie))]
[assembly: TypeForwardedTo(typeof(CookieCollection))]
[assembly: TypeForwardedTo(typeof(CookieContainer))]
[assembly: TypeForwardedTo(typeof(CookieException))]
[assembly: TypeForwardedTo(typeof(CredentialCache))]
[assembly: TypeForwardedTo(typeof(DecompressionMethods))]
[assembly: TypeForwardedTo(typeof(Dns))]
[assembly: TypeForwardedTo(typeof(DnsEndPoint))]
[assembly: TypeForwardedTo(typeof(DownloadDataCompletedEventArgs))]
[assembly: TypeForwardedTo(typeof(DownloadDataCompletedEventHandler))]
[assembly: TypeForwardedTo(typeof(DownloadProgressChangedEventArgs))]
[assembly: TypeForwardedTo(typeof(DownloadProgressChangedEventHandler))]
[assembly: TypeForwardedTo(typeof(DownloadStringCompletedEventArgs))]
[assembly: TypeForwardedTo(typeof(DownloadStringCompletedEventHandler))]
[assembly: TypeForwardedTo(typeof(EndPoint))]
[assembly: TypeForwardedTo(typeof(FileWebRequest))]
[assembly: TypeForwardedTo(typeof(FileWebResponse))]
[assembly: TypeForwardedTo(typeof(FtpStatusCode))]
[assembly: TypeForwardedTo(typeof(FtpWebRequest))]
[assembly: TypeForwardedTo(typeof(FtpWebResponse))]
[assembly: TypeForwardedTo(typeof(GlobalProxySelection))]
[assembly: TypeForwardedTo(typeof(ByteArrayContent))]
[assembly: TypeForwardedTo(typeof(ClientCertificateOption))]
[assembly: TypeForwardedTo(typeof(DelegatingHandler))]
[assembly: TypeForwardedTo(typeof(FormUrlEncodedContent))]
[assembly: TypeForwardedTo(typeof(AuthenticationHeaderValue))]
[assembly: TypeForwardedTo(typeof(CacheControlHeaderValue))]
[assembly: TypeForwardedTo(typeof(ContentDispositionHeaderValue))]
[assembly: TypeForwardedTo(typeof(ContentRangeHeaderValue))]
[assembly: TypeForwardedTo(typeof(EntityTagHeaderValue))]
[assembly: TypeForwardedTo(typeof(HttpContentHeaders))]
[assembly: TypeForwardedTo(typeof(HttpHeaders))]
[assembly: TypeForwardedTo(typeof(HttpHeaderValueCollection<>))]
[assembly: TypeForwardedTo(typeof(HttpRequestHeaders))]
[assembly: TypeForwardedTo(typeof(HttpResponseHeaders))]
[assembly: TypeForwardedTo(typeof(MediaTypeHeaderValue))]
[assembly: TypeForwardedTo(typeof(MediaTypeWithQualityHeaderValue))]
[assembly: TypeForwardedTo(typeof(NameValueHeaderValue))]
[assembly: TypeForwardedTo(typeof(NameValueWithParametersHeaderValue))]
[assembly: TypeForwardedTo(typeof(ProductHeaderValue))]
[assembly: TypeForwardedTo(typeof(ProductInfoHeaderValue))]
[assembly: TypeForwardedTo(typeof(RangeConditionHeaderValue))]
[assembly: TypeForwardedTo(typeof(RangeHeaderValue))]
[assembly: TypeForwardedTo(typeof(RangeItemHeaderValue))]
[assembly: TypeForwardedTo(typeof(RetryConditionHeaderValue))]
[assembly: TypeForwardedTo(typeof(StringWithQualityHeaderValue))]
[assembly: TypeForwardedTo(typeof(TransferCodingHeaderValue))]
[assembly: TypeForwardedTo(typeof(TransferCodingWithQualityHeaderValue))]
[assembly: TypeForwardedTo(typeof(ViaHeaderValue))]
[assembly: TypeForwardedTo(typeof(WarningHeaderValue))]
[assembly: TypeForwardedTo(typeof(HttpClient))]
[assembly: TypeForwardedTo(typeof(HttpClientHandler))]
[assembly: TypeForwardedTo(typeof(HttpCompletionOption))]
[assembly: TypeForwardedTo(typeof(HttpContent))]
[assembly: TypeForwardedTo(typeof(HttpMessageHandler))]
[assembly: TypeForwardedTo(typeof(HttpMessageInvoker))]
[assembly: TypeForwardedTo(typeof(HttpMethod))]
[assembly: TypeForwardedTo(typeof(HttpRequestException))]
[assembly: TypeForwardedTo(typeof(HttpRequestMessage))]
[assembly: TypeForwardedTo(typeof(HttpResponseMessage))]
[assembly: TypeForwardedTo(typeof(MessageProcessingHandler))]
[assembly: TypeForwardedTo(typeof(MultipartContent))]
[assembly: TypeForwardedTo(typeof(MultipartFormDataContent))]
[assembly: TypeForwardedTo(typeof(ReadOnlyMemoryContent))]
[assembly: TypeForwardedTo(typeof(StreamContent))]
[assembly: TypeForwardedTo(typeof(StringContent))]
[assembly: TypeForwardedTo(typeof(HttpContinueDelegate))]
[assembly: TypeForwardedTo(typeof(HttpListener))]
[assembly: TypeForwardedTo(typeof(HttpListenerBasicIdentity))]
[assembly: TypeForwardedTo(typeof(HttpListenerContext))]
[assembly: TypeForwardedTo(typeof(HttpListenerException))]
[assembly: TypeForwardedTo(typeof(HttpListenerPrefixCollection))]
[assembly: TypeForwardedTo(typeof(HttpListenerRequest))]
[assembly: TypeForwardedTo(typeof(HttpListenerResponse))]
[assembly: TypeForwardedTo(typeof(HttpListenerTimeoutManager))]
[assembly: TypeForwardedTo(typeof(HttpRequestHeader))]
[assembly: TypeForwardedTo(typeof(HttpResponseHeader))]
[assembly: TypeForwardedTo(typeof(HttpStatusCode))]
[assembly: TypeForwardedTo(typeof(HttpVersion))]
[assembly: TypeForwardedTo(typeof(HttpWebRequest))]
[assembly: TypeForwardedTo(typeof(HttpWebResponse))]
[assembly: TypeForwardedTo(typeof(IAuthenticationModule))]
[assembly: TypeForwardedTo(typeof(ICredentialPolicy))]
[assembly: TypeForwardedTo(typeof(ICredentials))]
[assembly: TypeForwardedTo(typeof(ICredentialsByHost))]
[assembly: TypeForwardedTo(typeof(IPAddress))]
[assembly: TypeForwardedTo(typeof(IPEndPoint))]
[assembly: TypeForwardedTo(typeof(IPHostEntry))]
[assembly: TypeForwardedTo(typeof(IWebProxy))]
[assembly: TypeForwardedTo(typeof(IWebProxyScript))]
[assembly: TypeForwardedTo(typeof(IWebRequestCreate))]
[assembly: TypeForwardedTo(typeof(AlternateView))]
[assembly: TypeForwardedTo(typeof(AlternateViewCollection))]
[assembly: TypeForwardedTo(typeof(Attachment))]
[assembly: TypeForwardedTo(typeof(AttachmentBase))]
[assembly: TypeForwardedTo(typeof(AttachmentCollection))]
[assembly: TypeForwardedTo(typeof(DeliveryNotificationOptions))]
[assembly: TypeForwardedTo(typeof(LinkedResource))]
[assembly: TypeForwardedTo(typeof(LinkedResourceCollection))]
[assembly: TypeForwardedTo(typeof(MailAddress))]
[assembly: TypeForwardedTo(typeof(MailAddressCollection))]
[assembly: TypeForwardedTo(typeof(MailMessage))]
[assembly: TypeForwardedTo(typeof(MailPriority))]
[assembly: TypeForwardedTo(typeof(SendCompletedEventHandler))]
[assembly: TypeForwardedTo(typeof(SmtpClient))]
[assembly: TypeForwardedTo(typeof(SmtpDeliveryFormat))]
[assembly: TypeForwardedTo(typeof(SmtpDeliveryMethod))]
[assembly: TypeForwardedTo(typeof(SmtpException))]
[assembly: TypeForwardedTo(typeof(SmtpFailedRecipientException))]
[assembly: TypeForwardedTo(typeof(SmtpFailedRecipientsException))]
[assembly: TypeForwardedTo(typeof(SmtpStatusCode))]
[assembly: TypeForwardedTo(typeof(ContentDisposition))]
[assembly: TypeForwardedTo(typeof(ContentType))]
[assembly: TypeForwardedTo(typeof(DispositionTypeNames))]
[assembly: TypeForwardedTo(typeof(MediaTypeNames))]
[assembly: TypeForwardedTo(typeof(TransferEncoding))]
[assembly: TypeForwardedTo(typeof(NetworkCredential))]
[assembly: TypeForwardedTo(typeof(DuplicateAddressDetectionState))]
[assembly: TypeForwardedTo(typeof(GatewayIPAddressInformation))]
[assembly: TypeForwardedTo(typeof(GatewayIPAddressInformationCollection))]
[assembly: TypeForwardedTo(typeof(IcmpV4Statistics))]
[assembly: TypeForwardedTo(typeof(IcmpV6Statistics))]
[assembly: TypeForwardedTo(typeof(IPAddressCollection))]
[assembly: TypeForwardedTo(typeof(IPAddressInformation))]
[assembly: TypeForwardedTo(typeof(IPAddressInformationCollection))]
[assembly: TypeForwardedTo(typeof(IPGlobalProperties))]
[assembly: TypeForwardedTo(typeof(IPGlobalStatistics))]
[assembly: TypeForwardedTo(typeof(IPInterfaceProperties))]
[assembly: TypeForwardedTo(typeof(IPInterfaceStatistics))]
[assembly: TypeForwardedTo(typeof(IPStatus))]
[assembly: TypeForwardedTo(typeof(IPv4InterfaceProperties))]
[assembly: TypeForwardedTo(typeof(IPv4InterfaceStatistics))]
[assembly: TypeForwardedTo(typeof(IPv6InterfaceProperties))]
[assembly: TypeForwardedTo(typeof(MulticastIPAddressInformation))]
[assembly: TypeForwardedTo(typeof(MulticastIPAddressInformationCollection))]
[assembly: TypeForwardedTo(typeof(NetBiosNodeType))]
[assembly: TypeForwardedTo(typeof(NetworkAddressChangedEventHandler))]
[assembly: TypeForwardedTo(typeof(NetworkAvailabilityChangedEventHandler))]
[assembly: TypeForwardedTo(typeof(NetworkAvailabilityEventArgs))]
[assembly: TypeForwardedTo(typeof(NetworkChange))]
[assembly: TypeForwardedTo(typeof(NetworkInformationException))]
[assembly: TypeForwardedTo(typeof(NetworkInterface))]
[assembly: TypeForwardedTo(typeof(NetworkInterfaceComponent))]
[assembly: TypeForwardedTo(typeof(NetworkInterfaceType))]
[assembly: TypeForwardedTo(typeof(OperationalStatus))]
[assembly: TypeForwardedTo(typeof(PhysicalAddress))]
[assembly: TypeForwardedTo(typeof(Ping))]
[assembly: TypeForwardedTo(typeof(PingCompletedEventArgs))]
[assembly: TypeForwardedTo(typeof(PingCompletedEventHandler))]
[assembly: TypeForwardedTo(typeof(PingException))]
[assembly: TypeForwardedTo(typeof(PingOptions))]
[assembly: TypeForwardedTo(typeof(PingReply))]
[assembly: TypeForwardedTo(typeof(PrefixOrigin))]
[assembly: TypeForwardedTo(typeof(ScopeLevel))]
[assembly: TypeForwardedTo(typeof(SuffixOrigin))]
[assembly: TypeForwardedTo(typeof(TcpConnectionInformation))]
[assembly: TypeForwardedTo(typeof(TcpState))]
[assembly: TypeForwardedTo(typeof(TcpStatistics))]
[assembly: TypeForwardedTo(typeof(UdpStatistics))]
[assembly: TypeForwardedTo(typeof(UnicastIPAddressInformation))]
[assembly: TypeForwardedTo(typeof(UnicastIPAddressInformationCollection))]
[assembly: TypeForwardedTo(typeof(OpenReadCompletedEventArgs))]
[assembly: TypeForwardedTo(typeof(OpenReadCompletedEventHandler))]
[assembly: TypeForwardedTo(typeof(OpenWriteCompletedEventArgs))]
[assembly: TypeForwardedTo(typeof(OpenWriteCompletedEventHandler))]
[assembly: TypeForwardedTo(typeof(ProtocolViolationException))]
[assembly: TypeForwardedTo(typeof(AuthenticatedStream))]
[assembly: TypeForwardedTo(typeof(AuthenticationLevel))]
[assembly: TypeForwardedTo(typeof(EncryptionPolicy))]
[assembly: TypeForwardedTo(typeof(LocalCertificateSelectionCallback))]
[assembly: TypeForwardedTo(typeof(NegotiateStream))]
[assembly: TypeForwardedTo(typeof(ProtectionLevel))]
[assembly: TypeForwardedTo(typeof(RemoteCertificateValidationCallback))]
[assembly: TypeForwardedTo(typeof(ServerCertificateSelectionCallback))]
[assembly: TypeForwardedTo(typeof(SslApplicationProtocol))]
[assembly: TypeForwardedTo(typeof(SslClientAuthenticationOptions))]
[assembly: TypeForwardedTo(typeof(SslPolicyErrors))]
[assembly: TypeForwardedTo(typeof(SslServerAuthenticationOptions))]
[assembly: TypeForwardedTo(typeof(SslStream))]
[assembly: TypeForwardedTo(typeof(SecurityProtocolType))]
[assembly: TypeForwardedTo(typeof(ServicePoint))]
[assembly: TypeForwardedTo(typeof(ServicePointManager))]
[assembly: TypeForwardedTo(typeof(SocketAddress))]
[assembly: TypeForwardedTo(typeof(AddressFamily))]
[assembly: TypeForwardedTo(typeof(IOControlCode))]
[assembly: TypeForwardedTo(typeof(IPPacketInformation))]
[assembly: TypeForwardedTo(typeof(IPProtectionLevel))]
[assembly: TypeForwardedTo(typeof(IPv6MulticastOption))]
[assembly: TypeForwardedTo(typeof(LingerOption))]
[assembly: TypeForwardedTo(typeof(MulticastOption))]
[assembly: TypeForwardedTo(typeof(NetworkStream))]
[assembly: TypeForwardedTo(typeof(ProtocolFamily))]
[assembly: TypeForwardedTo(typeof(ProtocolType))]
[assembly: TypeForwardedTo(typeof(SelectMode))]
[assembly: TypeForwardedTo(typeof(SendPacketsElement))]
[assembly: TypeForwardedTo(typeof(Socket))]
[assembly: TypeForwardedTo(typeof(SocketAsyncEventArgs))]
[assembly: TypeForwardedTo(typeof(SocketAsyncOperation))]
[assembly: TypeForwardedTo(typeof(SocketError))]
[assembly: TypeForwardedTo(typeof(SocketException))]
[assembly: TypeForwardedTo(typeof(SocketFlags))]
[assembly: TypeForwardedTo(typeof(SocketInformation))]
[assembly: TypeForwardedTo(typeof(SocketInformationOptions))]
[assembly: TypeForwardedTo(typeof(SocketOptionLevel))]
[assembly: TypeForwardedTo(typeof(SocketOptionName))]
[assembly: TypeForwardedTo(typeof(SocketReceiveFromResult))]
[assembly: TypeForwardedTo(typeof(SocketReceiveMessageFromResult))]
[assembly: TypeForwardedTo(typeof(SocketShutdown))]
[assembly: TypeForwardedTo(typeof(SocketTaskExtensions))]
[assembly: TypeForwardedTo(typeof(SocketType))]
[assembly: TypeForwardedTo(typeof(TcpClient))]
[assembly: TypeForwardedTo(typeof(TcpListener))]
[assembly: TypeForwardedTo(typeof(TransmitFileOptions))]
[assembly: TypeForwardedTo(typeof(UdpClient))]
[assembly: TypeForwardedTo(typeof(UdpReceiveResult))]
[assembly: TypeForwardedTo(typeof(UnixDomainSocketEndPoint))]
[assembly: TypeForwardedTo(typeof(TransportContext))]
[assembly: TypeForwardedTo(typeof(UploadDataCompletedEventArgs))]
[assembly: TypeForwardedTo(typeof(UploadDataCompletedEventHandler))]
[assembly: TypeForwardedTo(typeof(UploadFileCompletedEventArgs))]
[assembly: TypeForwardedTo(typeof(UploadFileCompletedEventHandler))]
[assembly: TypeForwardedTo(typeof(UploadProgressChangedEventArgs))]
[assembly: TypeForwardedTo(typeof(UploadProgressChangedEventHandler))]
[assembly: TypeForwardedTo(typeof(UploadStringCompletedEventArgs))]
[assembly: TypeForwardedTo(typeof(UploadStringCompletedEventHandler))]
[assembly: TypeForwardedTo(typeof(UploadValuesCompletedEventArgs))]
[assembly: TypeForwardedTo(typeof(UploadValuesCompletedEventHandler))]
[assembly: TypeForwardedTo(typeof(WebClient))]
[assembly: TypeForwardedTo(typeof(WebException))]
[assembly: TypeForwardedTo(typeof(WebExceptionStatus))]
[assembly: TypeForwardedTo(typeof(WebHeaderCollection))]
[assembly: TypeForwardedTo(typeof(WebProxy))]
[assembly: TypeForwardedTo(typeof(WebRequest))]
[assembly: TypeForwardedTo(typeof(WebRequestMethods))]
[assembly: TypeForwardedTo(typeof(WebResponse))]
[assembly: TypeForwardedTo(typeof(ClientWebSocket))]
[assembly: TypeForwardedTo(typeof(ClientWebSocketOptions))]
[assembly: TypeForwardedTo(typeof(HttpListenerWebSocketContext))]
[assembly: TypeForwardedTo(typeof(ValueWebSocketReceiveResult))]
[assembly: TypeForwardedTo(typeof(WebSocket))]
[assembly: TypeForwardedTo(typeof(WebSocketCloseStatus))]
[assembly: TypeForwardedTo(typeof(WebSocketContext))]
[assembly: TypeForwardedTo(typeof(WebSocketError))]
[assembly: TypeForwardedTo(typeof(WebSocketException))]
[assembly: TypeForwardedTo(typeof(WebSocketMessageType))]
[assembly: TypeForwardedTo(typeof(WebSocketReceiveResult))]
[assembly: TypeForwardedTo(typeof(WebSocketState))]
[assembly: TypeForwardedTo(typeof(WebUtility))]
[assembly: TypeForwardedTo(typeof(NetPipeStyleUriParser))]
[assembly: TypeForwardedTo(typeof(NetTcpStyleUriParser))]
[assembly: TypeForwardedTo(typeof(NewsStyleUriParser))]
[assembly: TypeForwardedTo(typeof(NonSerializedAttribute))]
[assembly: TypeForwardedTo(typeof(NotFiniteNumberException))]
[assembly: TypeForwardedTo(typeof(NotImplementedException))]
[assembly: TypeForwardedTo(typeof(NotSupportedException))]
[assembly: TypeForwardedTo(typeof(Nullable))]
[assembly: TypeForwardedTo(typeof(Nullable<>))]
[assembly: TypeForwardedTo(typeof(NullReferenceException))]
[assembly: TypeForwardedTo(typeof(BigInteger))]
[assembly: TypeForwardedTo(typeof(Complex))]
[assembly: TypeForwardedTo(typeof(Matrix3x2))]
[assembly: TypeForwardedTo(typeof(Matrix4x4))]
[assembly: TypeForwardedTo(typeof(Plane))]
[assembly: TypeForwardedTo(typeof(Quaternion))]
[assembly: TypeForwardedTo(typeof(Vector))]
[assembly: TypeForwardedTo(typeof(Vector<>))]
[assembly: TypeForwardedTo(typeof(Vector2))]
[assembly: TypeForwardedTo(typeof(Vector3))]
[assembly: TypeForwardedTo(typeof(Vector4))]
[assembly: TypeForwardedTo(typeof(object))]
[assembly: TypeForwardedTo(typeof(ObjectDisposedException))]
[assembly: TypeForwardedTo(typeof(ObsoleteAttribute))]
[assembly: TypeForwardedTo(typeof(OperatingSystem))]
[assembly: TypeForwardedTo(typeof(OperationCanceledException))]
[assembly: TypeForwardedTo(typeof(OutOfMemoryException))]
[assembly: TypeForwardedTo(typeof(OverflowException))]
[assembly: TypeForwardedTo(typeof(ParamArrayAttribute))]
[assembly: TypeForwardedTo(typeof(PlatformID))]
[assembly: TypeForwardedTo(typeof(PlatformNotSupportedException))]
[assembly: TypeForwardedTo(typeof(Predicate<>))]
[assembly: TypeForwardedTo(typeof(Progress<>))]
[assembly: TypeForwardedTo(typeof(Random))]
[assembly: TypeForwardedTo(typeof(Range))]
[assembly: TypeForwardedTo(typeof(RankException))]
[assembly: TypeForwardedTo(typeof(ReadOnlyMemory<>))]
[assembly: TypeForwardedTo(typeof(ReadOnlySpan<>))]
[assembly: TypeForwardedTo(typeof(AmbiguousMatchException))]
[assembly: TypeForwardedTo(typeof(Assembly))]
[assembly: TypeForwardedTo(typeof(AssemblyAlgorithmIdAttribute))]
[assembly: TypeForwardedTo(typeof(AssemblyCompanyAttribute))]
[assembly: TypeForwardedTo(typeof(AssemblyConfigurationAttribute))]
[assembly: TypeForwardedTo(typeof(AssemblyContentType))]
[assembly: TypeForwardedTo(typeof(AssemblyCopyrightAttribute))]
[assembly: TypeForwardedTo(typeof(AssemblyCultureAttribute))]
[assembly: TypeForwardedTo(typeof(AssemblyDefaultAliasAttribute))]
[assembly: TypeForwardedTo(typeof(AssemblyDelaySignAttribute))]
[assembly: TypeForwardedTo(typeof(AssemblyDescriptionAttribute))]
[assembly: TypeForwardedTo(typeof(AssemblyFileVersionAttribute))]
[assembly: TypeForwardedTo(typeof(AssemblyFlagsAttribute))]
[assembly: TypeForwardedTo(typeof(AssemblyInformationalVersionAttribute))]
[assembly: TypeForwardedTo(typeof(AssemblyKeyFileAttribute))]
[assembly: TypeForwardedTo(typeof(AssemblyKeyNameAttribute))]
[assembly: TypeForwardedTo(typeof(AssemblyMetadataAttribute))]
[assembly: TypeForwardedTo(typeof(AssemblyName))]
[assembly: TypeForwardedTo(typeof(AssemblyNameFlags))]
[assembly: TypeForwardedTo(typeof(AssemblyNameProxy))]
[assembly: TypeForwardedTo(typeof(AssemblyProductAttribute))]
[assembly: TypeForwardedTo(typeof(AssemblySignatureKeyAttribute))]
[assembly: TypeForwardedTo(typeof(AssemblyTitleAttribute))]
[assembly: TypeForwardedTo(typeof(AssemblyTrademarkAttribute))]
[assembly: TypeForwardedTo(typeof(AssemblyVersionAttribute))]
[assembly: TypeForwardedTo(typeof(Binder))]
[assembly: TypeForwardedTo(typeof(BindingFlags))]
[assembly: TypeForwardedTo(typeof(CallingConventions))]
[assembly: TypeForwardedTo(typeof(ConstructorInfo))]
[assembly: TypeForwardedTo(typeof(CustomAttributeData))]
[assembly: TypeForwardedTo(typeof(CustomAttributeExtensions))]
[assembly: TypeForwardedTo(typeof(CustomAttributeFormatException))]
[assembly: TypeForwardedTo(typeof(CustomAttributeNamedArgument))]
[assembly: TypeForwardedTo(typeof(CustomAttributeTypedArgument))]
[assembly: TypeForwardedTo(typeof(DefaultMemberAttribute))]
[assembly: TypeForwardedTo(typeof(DispatchProxy))]
[assembly: TypeForwardedTo(typeof(AssemblyBuilder))]
[assembly: TypeForwardedTo(typeof(AssemblyBuilderAccess))]
[assembly: TypeForwardedTo(typeof(ConstructorBuilder))]
[assembly: TypeForwardedTo(typeof(CustomAttributeBuilder))]
[assembly: TypeForwardedTo(typeof(DynamicILInfo))]
[assembly: TypeForwardedTo(typeof(DynamicMethod))]
[assembly: TypeForwardedTo(typeof(EnumBuilder))]
[assembly: TypeForwardedTo(typeof(EventBuilder))]
[assembly: TypeForwardedTo(typeof(EventToken))]
[assembly: TypeForwardedTo(typeof(ExceptionHandler))]
[assembly: TypeForwardedTo(typeof(FieldBuilder))]
[assembly: TypeForwardedTo(typeof(FieldToken))]
[assembly: TypeForwardedTo(typeof(FlowControl))]
[assembly: TypeForwardedTo(typeof(GenericTypeParameterBuilder))]
[assembly: TypeForwardedTo(typeof(ILGenerator))]
[assembly: TypeForwardedTo(typeof(Label))]
[assembly: TypeForwardedTo(typeof(LocalBuilder))]
[assembly: TypeForwardedTo(typeof(MethodBuilder))]
[assembly: TypeForwardedTo(typeof(MethodToken))]
[assembly: TypeForwardedTo(typeof(ModuleBuilder))]
[assembly: TypeForwardedTo(typeof(OpCode))]
[assembly: TypeForwardedTo(typeof(OpCodes))]
[assembly: TypeForwardedTo(typeof(OpCodeType))]
[assembly: TypeForwardedTo(typeof(OperandType))]
[assembly: TypeForwardedTo(typeof(PackingSize))]
[assembly: TypeForwardedTo(typeof(ParameterBuilder))]
[assembly: TypeForwardedTo(typeof(ParameterToken))]
[assembly: TypeForwardedTo(typeof(PropertyBuilder))]
[assembly: TypeForwardedTo(typeof(PropertyToken))]
[assembly: TypeForwardedTo(typeof(SignatureHelper))]
[assembly: TypeForwardedTo(typeof(SignatureToken))]
[assembly: TypeForwardedTo(typeof(StackBehaviour))]
[assembly: TypeForwardedTo(typeof(StringToken))]
[assembly: TypeForwardedTo(typeof(TypeBuilder))]
[assembly: TypeForwardedTo(typeof(TypeToken))]
[assembly: TypeForwardedTo(typeof(EventAttributes))]
[assembly: TypeForwardedTo(typeof(EventInfo))]
[assembly: TypeForwardedTo(typeof(ExceptionHandlingClause))]
[assembly: TypeForwardedTo(typeof(ExceptionHandlingClauseOptions))]
[assembly: TypeForwardedTo(typeof(FieldAttributes))]
[assembly: TypeForwardedTo(typeof(FieldInfo))]
[assembly: TypeForwardedTo(typeof(GenericParameterAttributes))]
[assembly: TypeForwardedTo(typeof(ICustomAttributeProvider))]
[assembly: TypeForwardedTo(typeof(ImageFileMachine))]
[assembly: TypeForwardedTo(typeof(InterfaceMapping))]
[assembly: TypeForwardedTo(typeof(IntrospectionExtensions))]
[assembly: TypeForwardedTo(typeof(InvalidFilterCriteriaException))]
[assembly: TypeForwardedTo(typeof(IReflect))]
[assembly: TypeForwardedTo(typeof(IReflectableType))]
[assembly: TypeForwardedTo(typeof(LocalVariableInfo))]
[assembly: TypeForwardedTo(typeof(ManifestResourceInfo))]
[assembly: TypeForwardedTo(typeof(MemberFilter))]
[assembly: TypeForwardedTo(typeof(MemberInfo))]
[assembly: TypeForwardedTo(typeof(MemberTypes))]
[assembly: TypeForwardedTo(typeof(MethodAttributes))]
[assembly: TypeForwardedTo(typeof(MethodBase))]
[assembly: TypeForwardedTo(typeof(MethodBody))]
[assembly: TypeForwardedTo(typeof(MethodImplAttributes))]
[assembly: TypeForwardedTo(typeof(MethodInfo))]
[assembly: TypeForwardedTo(typeof(Missing))]
[assembly: TypeForwardedTo(typeof(Module))]
[assembly: TypeForwardedTo(typeof(ModuleResolveEventHandler))]
[assembly: TypeForwardedTo(typeof(ObfuscateAssemblyAttribute))]
[assembly: TypeForwardedTo(typeof(ObfuscationAttribute))]
[assembly: TypeForwardedTo(typeof(ParameterAttributes))]
[assembly: TypeForwardedTo(typeof(ParameterInfo))]
[assembly: TypeForwardedTo(typeof(ParameterModifier))]
[assembly: TypeForwardedTo(typeof(Pointer))]
[assembly: TypeForwardedTo(typeof(PortableExecutableKinds))]
[assembly: TypeForwardedTo(typeof(ProcessorArchitecture))]
[assembly: TypeForwardedTo(typeof(PropertyAttributes))]
[assembly: TypeForwardedTo(typeof(PropertyInfo))]
[assembly: TypeForwardedTo(typeof(ReflectionContext))]
[assembly: TypeForwardedTo(typeof(ReflectionTypeLoadException))]
[assembly: TypeForwardedTo(typeof(ResourceAttributes))]
[assembly: TypeForwardedTo(typeof(ResourceLocation))]
[assembly: TypeForwardedTo(typeof(RuntimeReflectionExtensions))]
[assembly: TypeForwardedTo(typeof(StrongNameKeyPair))]
[assembly: TypeForwardedTo(typeof(TargetException))]
[assembly: TypeForwardedTo(typeof(TargetInvocationException))]
[assembly: TypeForwardedTo(typeof(TargetParameterCountException))]
[assembly: TypeForwardedTo(typeof(TypeAttributes))]
[assembly: TypeForwardedTo(typeof(TypeDelegator))]
[assembly: TypeForwardedTo(typeof(TypeFilter))]
[assembly: TypeForwardedTo(typeof(TypeInfo))]
[assembly: TypeForwardedTo(typeof(ResolveEventArgs))]
[assembly: TypeForwardedTo(typeof(ResolveEventHandler))]
[assembly: TypeForwardedTo(typeof(IResourceReader))]
[assembly: TypeForwardedTo(typeof(IResourceWriter))]
[assembly: TypeForwardedTo(typeof(MissingManifestResourceException))]
[assembly: TypeForwardedTo(typeof(MissingSatelliteAssemblyException))]
[assembly: TypeForwardedTo(typeof(NeutralResourcesLanguageAttribute))]
[assembly: TypeForwardedTo(typeof(ResourceManager))]
[assembly: TypeForwardedTo(typeof(ResourceReader))]
[assembly: TypeForwardedTo(typeof(ResourceSet))]
[assembly: TypeForwardedTo(typeof(ResourceWriter))]
[assembly: TypeForwardedTo(typeof(SatelliteContractVersionAttribute))]
[assembly: TypeForwardedTo(typeof(UltimateResourceFallbackLocation))]
[assembly: TypeForwardedTo(typeof(AmbiguousImplementationException))]
[assembly: TypeForwardedTo(typeof(AssemblyTargetedPatchBandAttribute))]
[assembly: TypeForwardedTo(typeof(AccessedThroughPropertyAttribute))]
[assembly: TypeForwardedTo(typeof(AsyncIteratorMethodBuilder))]
[assembly: TypeForwardedTo(typeof(AsyncIteratorStateMachineAttribute))]
[assembly: TypeForwardedTo(typeof(AsyncMethodBuilderAttribute))]
[assembly: TypeForwardedTo(typeof(AsyncStateMachineAttribute))]
[assembly: TypeForwardedTo(typeof(AsyncTaskMethodBuilder))]
[assembly: TypeForwardedTo(typeof(AsyncTaskMethodBuilder<>))]
[assembly: TypeForwardedTo(typeof(AsyncValueTaskMethodBuilder))]
[assembly: TypeForwardedTo(typeof(AsyncValueTaskMethodBuilder<>))]
[assembly: TypeForwardedTo(typeof(AsyncVoidMethodBuilder))]
[assembly: TypeForwardedTo(typeof(CallConvCdecl))]
[assembly: TypeForwardedTo(typeof(CallConvFastcall))]
[assembly: TypeForwardedTo(typeof(CallConvStdcall))]
[assembly: TypeForwardedTo(typeof(CallConvThiscall))]
[assembly: TypeForwardedTo(typeof(CallerFilePathAttribute))]
[assembly: TypeForwardedTo(typeof(CallerLineNumberAttribute))]
[assembly: TypeForwardedTo(typeof(CallerMemberNameAttribute))]
[assembly: TypeForwardedTo(typeof(CallSite))]
[assembly: TypeForwardedTo(typeof(CallSite<>))]
[assembly: TypeForwardedTo(typeof(CallSiteBinder))]
[assembly: TypeForwardedTo(typeof(CallSiteHelpers))]
[assembly: TypeForwardedTo(typeof(CompilationRelaxations))]
[assembly: TypeForwardedTo(typeof(CompilationRelaxationsAttribute))]
[assembly: TypeForwardedTo(typeof(CompilerGeneratedAttribute))]
[assembly: TypeForwardedTo(typeof(CompilerGlobalScopeAttribute))]
[assembly: TypeForwardedTo(typeof(CompilerMarshalOverride))]
[assembly: TypeForwardedTo(typeof(ConditionalWeakTable<, >))]
[assembly: TypeForwardedTo(typeof(ConfiguredAsyncDisposable))]
[assembly: TypeForwardedTo(typeof(ConfiguredCancelableAsyncEnumerable<>))]
[assembly: TypeForwardedTo(typeof(ConfiguredTaskAwaitable))]
[assembly: TypeForwardedTo(typeof(ConfiguredTaskAwaitable<>))]
[assembly: TypeForwardedTo(typeof(ConfiguredValueTaskAwaitable))]
[assembly: TypeForwardedTo(typeof(ConfiguredValueTaskAwaitable<>))]
[assembly: TypeForwardedTo(typeof(ContractHelper))]
[assembly: TypeForwardedTo(typeof(CustomConstantAttribute))]
[assembly: TypeForwardedTo(typeof(DateTimeConstantAttribute))]
[assembly: TypeForwardedTo(typeof(DebugInfoGenerator))]
[assembly: TypeForwardedTo(typeof(DecimalConstantAttribute))]
[assembly: TypeForwardedTo(typeof(DefaultDependencyAttribute))]
[assembly: TypeForwardedTo(typeof(DependencyAttribute))]
[assembly: TypeForwardedTo(typeof(DisablePrivateReflectionAttribute))]
[assembly: TypeForwardedTo(typeof(DiscardableAttribute))]
[assembly: TypeForwardedTo(typeof(DynamicAttribute))]
[assembly: TypeForwardedTo(typeof(EnumeratorCancellationAttribute))]
[assembly: TypeForwardedTo(typeof(ExtensionAttribute))]
[assembly: TypeForwardedTo(typeof(FixedAddressValueTypeAttribute))]
[assembly: TypeForwardedTo(typeof(FixedBufferAttribute))]
[assembly: TypeForwardedTo(typeof(FormattableStringFactory))]
[assembly: TypeForwardedTo(typeof(HasCopySemanticsAttribute))]
[assembly: TypeForwardedTo(typeof(IAsyncStateMachine))]
[assembly: TypeForwardedTo(typeof(ICriticalNotifyCompletion))]
[assembly: TypeForwardedTo(typeof(IndexerNameAttribute))]
[assembly: TypeForwardedTo(typeof(INotifyCompletion))]
[assembly: TypeForwardedTo(typeof(InternalsVisibleToAttribute))]
[assembly: TypeForwardedTo(typeof(IRuntimeVariables))]
[assembly: TypeForwardedTo(typeof(IsBoxed))]
[assembly: TypeForwardedTo(typeof(IsByRefLikeAttribute))]
[assembly: TypeForwardedTo(typeof(IsByValue))]
[assembly: TypeForwardedTo(typeof(IsConst))]
[assembly: TypeForwardedTo(typeof(IsCopyConstructed))]
[assembly: TypeForwardedTo(typeof(IsExplicitlyDereferenced))]
[assembly: TypeForwardedTo(typeof(IsImplicitlyDereferenced))]
[assembly: TypeForwardedTo(typeof(IsJitIntrinsic))]
[assembly: TypeForwardedTo(typeof(IsLong))]
[assembly: TypeForwardedTo(typeof(IsPinned))]
[assembly: TypeForwardedTo(typeof(IsReadOnlyAttribute))]
[assembly: TypeForwardedTo(typeof(IsSignUnspecifiedByte))]
[assembly: TypeForwardedTo(typeof(IStrongBox))]
[assembly: TypeForwardedTo(typeof(IsUdtReturn))]
[assembly: TypeForwardedTo(typeof(IsVolatile))]
[assembly: TypeForwardedTo(typeof(IteratorStateMachineAttribute))]
[assembly: TypeForwardedTo(typeof(ITuple))]
[assembly: TypeForwardedTo(typeof(IUnknownConstantAttribute))]
[assembly: TypeForwardedTo(typeof(LoadHint))]
[assembly: TypeForwardedTo(typeof(MethodCodeType))]
[assembly: TypeForwardedTo(typeof(MethodImplAttribute))]
[assembly: TypeForwardedTo(typeof(MethodImplOptions))]
[assembly: TypeForwardedTo(typeof(NativeCppClassAttribute))]
[assembly: TypeForwardedTo(typeof(ReadOnlyCollectionBuilder<>))]
[assembly: TypeForwardedTo(typeof(ReferenceAssemblyAttribute))]
[assembly: TypeForwardedTo(typeof(RequiredAttributeAttribute))]
[assembly: TypeForwardedTo(typeof(RuleCache<>))]
[assembly: TypeForwardedTo(typeof(RuntimeCompatibilityAttribute))]
[assembly: TypeForwardedTo(typeof(RuntimeFeature))]
[assembly: TypeForwardedTo(typeof(RuntimeHelpers))]
[assembly: TypeForwardedTo(typeof(RuntimeWrappedException))]
[assembly: TypeForwardedTo(typeof(ScopelessEnumAttribute))]
[assembly: TypeForwardedTo(typeof(SpecialNameAttribute))]
[assembly: TypeForwardedTo(typeof(StateMachineAttribute))]
[assembly: TypeForwardedTo(typeof(StringFreezingAttribute))]
[assembly: TypeForwardedTo(typeof(StrongBox<>))]
[assembly: TypeForwardedTo(typeof(SuppressIldasmAttribute))]
[assembly: TypeForwardedTo(typeof(SwitchExpressionException))]
[assembly: TypeForwardedTo(typeof(TaskAwaiter))]
[assembly: TypeForwardedTo(typeof(TaskAwaiter<>))]
[assembly: TypeForwardedTo(typeof(TupleElementNamesAttribute))]
[assembly: TypeForwardedTo(typeof(TypeForwardedFromAttribute))]
[assembly: TypeForwardedTo(typeof(TypeForwardedToAttribute))]
[assembly: TypeForwardedTo(typeof(UnsafeValueTypeAttribute))]
[assembly: TypeForwardedTo(typeof(ValueTaskAwaiter))]
[assembly: TypeForwardedTo(typeof(ValueTaskAwaiter<>))]
[assembly: TypeForwardedTo(typeof(YieldAwaitable))]
[assembly: TypeForwardedTo(typeof(Cer))]
[assembly: TypeForwardedTo(typeof(Consistency))]
[assembly: TypeForwardedTo(typeof(CriticalFinalizerObject))]
[assembly: TypeForwardedTo(typeof(PrePrepareMethodAttribute))]
[assembly: TypeForwardedTo(typeof(ReliabilityContractAttribute))]
[assembly: TypeForwardedTo(typeof(ExceptionDispatchInfo))]
[assembly: TypeForwardedTo(typeof(FirstChanceExceptionEventArgs))]
[assembly: TypeForwardedTo(typeof(HandleProcessCorruptedStateExceptionsAttribute))]
[assembly: TypeForwardedTo(typeof(GCLargeObjectHeapCompactionMode))]
[assembly: TypeForwardedTo(typeof(GCLatencyMode))]
[assembly: TypeForwardedTo(typeof(GCSettings))]
[assembly: TypeForwardedTo(typeof(AllowReversePInvokeCallsAttribute))]
[assembly: TypeForwardedTo(typeof(Architecture))]
[assembly: TypeForwardedTo(typeof(ArrayWithOffset))]
[assembly: TypeForwardedTo(typeof(AutomationProxyAttribute))]
[assembly: TypeForwardedTo(typeof(BestFitMappingAttribute))]
[assembly: TypeForwardedTo(typeof(BStrWrapper))]
[assembly: TypeForwardedTo(typeof(CallingConvention))]
[assembly: TypeForwardedTo(typeof(CharSet))]
[assembly: TypeForwardedTo(typeof(ClassInterfaceAttribute))]
[assembly: TypeForwardedTo(typeof(ClassInterfaceType))]
[assembly: TypeForwardedTo(typeof(CoClassAttribute))]
[assembly: TypeForwardedTo(typeof(ComAliasNameAttribute))]
[assembly: TypeForwardedTo(typeof(ComAwareEventInfo))]
[assembly: TypeForwardedTo(typeof(ComCompatibleVersionAttribute))]
[assembly: TypeForwardedTo(typeof(ComConversionLossAttribute))]
[assembly: TypeForwardedTo(typeof(ComDefaultInterfaceAttribute))]
[assembly: TypeForwardedTo(typeof(ComEventInterfaceAttribute))]
[assembly: TypeForwardedTo(typeof(ComEventsHelper))]
[assembly: TypeForwardedTo(typeof(COMException))]
[assembly: TypeForwardedTo(typeof(ComImportAttribute))]
[assembly: TypeForwardedTo(typeof(ComInterfaceType))]
[assembly: TypeForwardedTo(typeof(ComMemberType))]
[assembly: TypeForwardedTo(typeof(ComRegisterFunctionAttribute))]
[assembly: TypeForwardedTo(typeof(ComSourceInterfacesAttribute))]
[assembly: TypeForwardedTo(typeof(ADVF))]
[assembly: TypeForwardedTo(typeof(BIND_OPTS))]
[assembly: TypeForwardedTo(typeof(BINDPTR))]
[assembly: TypeForwardedTo(typeof(CALLCONV))]
[assembly: TypeForwardedTo(typeof(CONNECTDATA))]
[assembly: TypeForwardedTo(typeof(DATADIR))]
[assembly: TypeForwardedTo(typeof(DESCKIND))]
[assembly: TypeForwardedTo(typeof(DISPPARAMS))]
[assembly: TypeForwardedTo(typeof(DVASPECT))]
[assembly: TypeForwardedTo(typeof(ELEMDESC))]
[assembly: TypeForwardedTo(typeof(EXCEPINFO))]
[assembly: TypeForwardedTo(typeof(FILETIME))]
[assembly: TypeForwardedTo(typeof(FORMATETC))]
[assembly: TypeForwardedTo(typeof(FUNCDESC))]
[assembly: TypeForwardedTo(typeof(FUNCFLAGS))]
[assembly: TypeForwardedTo(typeof(FUNCKIND))]
[assembly: TypeForwardedTo(typeof(IAdviseSink))]
[assembly: TypeForwardedTo(typeof(IBindCtx))]
[assembly: TypeForwardedTo(typeof(IConnectionPoint))]
[assembly: TypeForwardedTo(typeof(IConnectionPointContainer))]
[assembly: TypeForwardedTo(typeof(IDataObject))]
[assembly: TypeForwardedTo(typeof(IDLDESC))]
[assembly: TypeForwardedTo(typeof(IDLFLAG))]
[assembly: TypeForwardedTo(typeof(IEnumConnectionPoints))]
[assembly: TypeForwardedTo(typeof(IEnumConnections))]
[assembly: TypeForwardedTo(typeof(IEnumFORMATETC))]
[assembly: TypeForwardedTo(typeof(IEnumMoniker))]
[assembly: TypeForwardedTo(typeof(IEnumSTATDATA))]
[assembly: TypeForwardedTo(typeof(IEnumString))]
[assembly: TypeForwardedTo(typeof(IEnumVARIANT))]
[assembly: TypeForwardedTo(typeof(IMoniker))]
[assembly: TypeForwardedTo(typeof(IMPLTYPEFLAGS))]
[assembly: TypeForwardedTo(typeof(INVOKEKIND))]
[assembly: TypeForwardedTo(typeof(IPersistFile))]
[assembly: TypeForwardedTo(typeof(IRunningObjectTable))]
[assembly: TypeForwardedTo(typeof(IStream))]
[assembly: TypeForwardedTo(typeof(ITypeComp))]
[assembly: TypeForwardedTo(typeof(ITypeInfo))]
[assembly: TypeForwardedTo(typeof(ITypeInfo2))]
[assembly: TypeForwardedTo(typeof(ITypeLib))]
[assembly: TypeForwardedTo(typeof(ITypeLib2))]
[assembly: TypeForwardedTo(typeof(LIBFLAGS))]
[assembly: TypeForwardedTo(typeof(PARAMDESC))]
[assembly: TypeForwardedTo(typeof(PARAMFLAG))]
[assembly: TypeForwardedTo(typeof(STATDATA))]
[assembly: TypeForwardedTo(typeof(STATSTG))]
[assembly: TypeForwardedTo(typeof(STGMEDIUM))]
[assembly: TypeForwardedTo(typeof(SYSKIND))]
[assembly: TypeForwardedTo(typeof(TYMED))]
[assembly: TypeForwardedTo(typeof(TYPEATTR))]
[assembly: TypeForwardedTo(typeof(TYPEDESC))]
[assembly: TypeForwardedTo(typeof(TYPEFLAGS))]
[assembly: TypeForwardedTo(typeof(TYPEKIND))]
[assembly: TypeForwardedTo(typeof(TYPELIBATTR))]
[assembly: TypeForwardedTo(typeof(VARDESC))]
[assembly: TypeForwardedTo(typeof(VARFLAGS))]
[assembly: TypeForwardedTo(typeof(VARKIND))]
[assembly: TypeForwardedTo(typeof(ComUnregisterFunctionAttribute))]
[assembly: TypeForwardedTo(typeof(ComVisibleAttribute))]
[assembly: TypeForwardedTo(typeof(CriticalHandle))]
[assembly: TypeForwardedTo(typeof(CurrencyWrapper))]
[assembly: TypeForwardedTo(typeof(CustomQueryInterfaceMode))]
[assembly: TypeForwardedTo(typeof(CustomQueryInterfaceResult))]
[assembly: TypeForwardedTo(typeof(DefaultCharSetAttribute))]
[assembly: TypeForwardedTo(typeof(DefaultDllImportSearchPathsAttribute))]
[assembly: TypeForwardedTo(typeof(DefaultParameterValueAttribute))]
[assembly: TypeForwardedTo(typeof(DispatchWrapper))]
[assembly: TypeForwardedTo(typeof(DispIdAttribute))]
[assembly: TypeForwardedTo(typeof(DllImportAttribute))]
[assembly: TypeForwardedTo(typeof(DllImportSearchPath))]
[assembly: TypeForwardedTo(typeof(ErrorWrapper))]
[assembly: TypeForwardedTo(typeof(ExternalException))]
[assembly: TypeForwardedTo(typeof(FieldOffsetAttribute))]
[assembly: TypeForwardedTo(typeof(GCHandle))]
[assembly: TypeForwardedTo(typeof(GCHandleType))]
[assembly: TypeForwardedTo(typeof(GuidAttribute))]
[assembly: TypeForwardedTo(typeof(HandleCollector))]
[assembly: TypeForwardedTo(typeof(HandleRef))]
[assembly: TypeForwardedTo(typeof(ICustomAdapter))]
[assembly: TypeForwardedTo(typeof(ICustomFactory))]
[assembly: TypeForwardedTo(typeof(ICustomMarshaler))]
[assembly: TypeForwardedTo(typeof(ICustomQueryInterface))]
[assembly: TypeForwardedTo(typeof(ImportedFromTypeLibAttribute))]
[assembly: TypeForwardedTo(typeof(InAttribute))]
[assembly: TypeForwardedTo(typeof(InterfaceTypeAttribute))]
[assembly: TypeForwardedTo(typeof(InvalidComObjectException))]
[assembly: TypeForwardedTo(typeof(InvalidOleVariantTypeException))]
[assembly: TypeForwardedTo(typeof(LayoutKind))]
[assembly: TypeForwardedTo(typeof(LCIDConversionAttribute))]
[assembly: TypeForwardedTo(typeof(ManagedToNativeComInteropStubAttribute))]
[assembly: TypeForwardedTo(typeof(Marshal))]
[assembly: TypeForwardedTo(typeof(MarshalAsAttribute))]
[assembly: TypeForwardedTo(typeof(MarshalDirectiveException))]
[assembly: TypeForwardedTo(typeof(MemoryMarshal))]
[assembly: TypeForwardedTo(typeof(OptionalAttribute))]
[assembly: TypeForwardedTo(typeof(OSPlatform))]
[assembly: TypeForwardedTo(typeof(OutAttribute))]
[assembly: TypeForwardedTo(typeof(PreserveSigAttribute))]
[assembly: TypeForwardedTo(typeof(PrimaryInteropAssemblyAttribute))]
[assembly: TypeForwardedTo(typeof(ProgIdAttribute))]
[assembly: TypeForwardedTo(typeof(RuntimeEnvironment))]
[assembly: TypeForwardedTo(typeof(RuntimeInformation))]
[assembly: TypeForwardedTo(typeof(SafeArrayRankMismatchException))]
[assembly: TypeForwardedTo(typeof(SafeArrayTypeMismatchException))]
[assembly: TypeForwardedTo(typeof(SafeBuffer))]
[assembly: TypeForwardedTo(typeof(SafeHandle))]
[assembly: TypeForwardedTo(typeof(SEHException))]
[assembly: TypeForwardedTo(typeof(SequenceMarshal))]
[assembly: TypeForwardedTo(typeof(StructLayoutAttribute))]
[assembly: TypeForwardedTo(typeof(TypeIdentifierAttribute))]
[assembly: TypeForwardedTo(typeof(TypeLibFuncAttribute))]
[assembly: TypeForwardedTo(typeof(TypeLibFuncFlags))]
[assembly: TypeForwardedTo(typeof(TypeLibImportClassAttribute))]
[assembly: TypeForwardedTo(typeof(TypeLibTypeAttribute))]
[assembly: TypeForwardedTo(typeof(TypeLibTypeFlags))]
[assembly: TypeForwardedTo(typeof(TypeLibVarAttribute))]
[assembly: TypeForwardedTo(typeof(TypeLibVarFlags))]
[assembly: TypeForwardedTo(typeof(TypeLibVersionAttribute))]
[assembly: TypeForwardedTo(typeof(UnknownWrapper))]
[assembly: TypeForwardedTo(typeof(UnmanagedFunctionPointerAttribute))]
[assembly: TypeForwardedTo(typeof(UnmanagedType))]
[assembly: TypeForwardedTo(typeof(VarEnum))]
[assembly: TypeForwardedTo(typeof(VariantWrapper))]
[assembly: TypeForwardedTo(typeof(MemoryFailPoint))]
[assembly: TypeForwardedTo(typeof(CollectionDataContractAttribute))]
[assembly: TypeForwardedTo(typeof(ContractNamespaceAttribute))]
[assembly: TypeForwardedTo(typeof(DataContractAttribute))]
[assembly: TypeForwardedTo(typeof(DataContractResolver))]
[assembly: TypeForwardedTo(typeof(DataContractSerializer))]
[assembly: TypeForwardedTo(typeof(DataContractSerializerExtensions))]
[assembly: TypeForwardedTo(typeof(DataContractSerializerSettings))]
[assembly: TypeForwardedTo(typeof(DataMemberAttribute))]
[assembly: TypeForwardedTo(typeof(DateTimeFormat))]
[assembly: TypeForwardedTo(typeof(EmitTypeInformation))]
[assembly: TypeForwardedTo(typeof(EnumMemberAttribute))]
[assembly: TypeForwardedTo(typeof(ExportOptions))]
[assembly: TypeForwardedTo(typeof(ExtensionDataObject))]
[assembly: TypeForwardedTo(typeof(Formatter))]
[assembly: TypeForwardedTo(typeof(FormatterConverter))]
[assembly: TypeForwardedTo(typeof(BinaryFormatter))]
[assembly: TypeForwardedTo(typeof(FormatterAssemblyStyle))]
[assembly: TypeForwardedTo(typeof(FormatterTypeStyle))]
[assembly: TypeForwardedTo(typeof(IFieldInfo))]
[assembly: TypeForwardedTo(typeof(TypeFilterLevel))]
[assembly: TypeForwardedTo(typeof(FormatterServices))]
[assembly: TypeForwardedTo(typeof(IDeserializationCallback))]
[assembly: TypeForwardedTo(typeof(IExtensibleDataObject))]
[assembly: TypeForwardedTo(typeof(IFormatter))]
[assembly: TypeForwardedTo(typeof(IFormatterConverter))]
[assembly: TypeForwardedTo(typeof(IgnoreDataMemberAttribute))]
[assembly: TypeForwardedTo(typeof(InvalidDa

BepInExPack/mono/Managed/System.Buffers.dll

Decompiled a month ago
using System;
using System.Buffers;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyDefaultAlias("System.Buffers")]
[assembly: AssemblyCompany("Microsoft Corporation")]
[assembly: AssemblyCopyright("© Microsoft Corporation. All rights reserved.")]
[assembly: AssemblyDescription("System.Buffers")]
[assembly: AssemblyFileVersion("4.700.19.46205")]
[assembly: AssemblyInformationalVersion("4.7.0+a5b5f2e1e369972c8ff1e2183979fab6099f52ef")]
[assembly: AssemblyProduct("Microsoft® .NET Framework")]
[assembly: AssemblyTitle("System.Buffers")]
[assembly: CLSCompliant(true)]
[assembly: AssemblyVersion("4.0.3.0")]
[assembly: TypeForwardedTo(typeof(ArrayPool<>))]

BepInExPack/mono/Managed/System.Configuration.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Configuration.Internal;
using System.Configuration.Provider;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Security;
using System.Security.Cryptography;
using System.Security.Cryptography.Xml;
using System.Security.Permissions;
using System.Text;
using System.Text.RegularExpressions;
using System.Xml;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("System.Configuration.dll")]
[assembly: AssemblyDescription("System.Configuration.dll")]
[assembly: AssemblyDefaultAlias("System.Configuration.dll")]
[assembly: AssemblyCompany("Mono development team")]
[assembly: AssemblyProduct("Mono Common Language Infrastructure")]
[assembly: AssemblyCopyright("(c) Various Mono authors")]
[assembly: SatelliteContractVersion("4.0.0.0")]
[assembly: AssemblyInformationalVersion("4.6.57.0")]
[assembly: CLSCompliant(true)]
[assembly: NeutralResourcesLanguage("en-US")]
[assembly: ComVisible(false)]
[assembly: AllowPartiallyTrustedCallers]
[assembly: AssemblyDelaySign(true)]
[assembly: InternalsVisibleTo("System.Web, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")]
[assembly: AssemblyFileVersion("4.6.57.0")]
[assembly: ComCompatibleVersion(1, 0, 3300, 0)]
[assembly: AssemblyVersion("4.0.0.0")]
internal static class Consts
{
	public const string MonoCorlibVersion = "1A5E0066-58DC-428A-B21C-0AD6CDAE2789";

	public const string MonoVersion = "6.13.0.0";

	public const string MonoCompany = "Mono development team";

	public const string MonoProduct = "Mono Common Language Infrastructure";

	public const string MonoCopyright = "(c) Various Mono authors";

	public const string FxVersion = "4.0.0.0";

	public const string FxFileVersion = "4.6.57.0";

	public const string EnvironmentVersion = "4.0.30319.42000";

	public const string VsVersion = "0.0.0.0";

	public const string VsFileVersion = "11.0.0.0";

	private const string PublicKeyToken = "b77a5c561934e089";

	public const string AssemblyI18N = "I18N, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756";

	public const string AssemblyMicrosoft_JScript = "Microsoft.JScript, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblyMicrosoft_VisualStudio = "Microsoft.VisualStudio, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblyMicrosoft_VisualStudio_Web = "Microsoft.VisualStudio.Web, Version=0.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblyMicrosoft_VSDesigner = "Microsoft.VSDesigner, Version=0.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblyMono_Http = "Mono.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756";

	public const string AssemblyMono_Posix = "Mono.Posix, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756";

	public const string AssemblyMono_Security = "Mono.Security, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756";

	public const string AssemblyMono_Messaging_RabbitMQ = "Mono.Messaging.RabbitMQ, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756";

	public const string AssemblyCorlib = "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string AssemblySystem = "System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string AssemblySystem_Data = "System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string AssemblySystem_Design = "System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_DirectoryServices = "System.DirectoryServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_Drawing = "System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_Drawing_Design = "System.Drawing.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_Messaging = "System.Messaging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_Security = "System.Security, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_ServiceProcess = "System.ServiceProcess, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_Web = "System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_Windows_Forms = "System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string AssemblySystem_2_0 = "System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string AssemblySystemCore_3_5 = "System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string AssemblySystem_Core = "System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string WindowsBase_3_0 = "WindowsBase, Version=3.0.0.0, PublicKeyToken=31bf3856ad364e35";

	public const string AssemblyWindowsBase = "WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";

	public const string AssemblyPresentationCore_3_5 = "PresentationCore, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";

	public const string AssemblyPresentationCore_4_0 = "PresentationCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";

	public const string AssemblyPresentationFramework_3_5 = "PresentationFramework, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";

	public const string AssemblySystemServiceModel_3_0 = "System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";
}
internal sealed class Locale
{
	private Locale()
	{
	}

	public static string GetText(string msg)
	{
		return msg;
	}

	public static string GetText(string fmt, params object[] args)
	{
		return string.Format(fmt, args);
	}
}
internal class ConfigXmlTextReader : XmlTextReader, IConfigErrorInfo
{
	private readonly string fileName;

	public string Filename => fileName;

	public ConfigXmlTextReader(Stream s, string fileName)
		: base(s)
	{
		if (fileName == null)
		{
			throw new ArgumentNullException("fileName");
		}
		this.fileName = fileName;
	}

	public ConfigXmlTextReader(TextReader input, string fileName)
		: base(input)
	{
		if (fileName == null)
		{
			throw new ArgumentNullException("fileName");
		}
		this.fileName = fileName;
	}
}
namespace System
{
	[AttributeUsage(AttributeTargets.All, AllowMultiple = true)]
	internal class MonoTODOAttribute : Attribute
	{
		private string comment;

		public string Comment => comment;

		public MonoTODOAttribute()
		{
		}

		public MonoTODOAttribute(string comment)
		{
			this.comment = comment;
		}
	}
	[AttributeUsage(AttributeTargets.All, AllowMultiple = true)]
	internal class MonoDocumentationNoteAttribute : MonoTODOAttribute
	{
		public MonoDocumentationNoteAttribute(string comment)
			: base(comment)
		{
		}
	}
	[AttributeUsage(AttributeTargets.All, AllowMultiple = true)]
	internal class MonoExtensionAttribute : MonoTODOAttribute
	{
		public MonoExtensionAttribute(string comment)
			: base(comment)
		{
		}
	}
	[AttributeUsage(AttributeTargets.All, AllowMultiple = true)]
	internal class MonoInternalNoteAttribute : MonoTODOAttribute
	{
		public MonoInternalNoteAttribute(string comment)
			: base(comment)
		{
		}
	}
	[AttributeUsage(AttributeTargets.All, AllowMultiple = true)]
	internal class MonoLimitationAttribute : MonoTODOAttribute
	{
		public MonoLimitationAttribute(string comment)
			: base(comment)
		{
		}
	}
	[AttributeUsage(AttributeTargets.All, AllowMultiple = true)]
	internal class MonoNotSupportedAttribute : MonoTODOAttribute
	{
		public MonoNotSupportedAttribute(string comment)
			: base(comment)
		{
		}
	}
}
namespace System.Configuration
{
	public sealed class AppSettingsSection : ConfigurationSection
	{
		private static ConfigurationPropertyCollection _properties;

		private static readonly ConfigurationProperty _propFile;

		private static readonly ConfigurationProperty _propSettings;

		[ConfigurationProperty("file", DefaultValue = "")]
		public string File
		{
			get
			{
				return (string)base[_propFile];
			}
			set
			{
				base[_propFile] = value;
			}
		}

		[ConfigurationProperty("", Options = ConfigurationPropertyOptions.IsDefaultCollection)]
		public KeyValueConfigurationCollection Settings => (KeyValueConfigurationCollection)base[_propSettings];

		protected internal override ConfigurationPropertyCollection Properties => _properties;

		static AppSettingsSection()
		{
			_propFile = new ConfigurationProperty("file", typeof(string), "", new StringConverter(), null, ConfigurationPropertyOptions.None);
			_propSettings = new ConfigurationProperty("", typeof(KeyValueConfigurationCollection), null, null, null, ConfigurationPropertyOptions.IsDefaultCollection);
			_properties = new ConfigurationPropertyCollection();
			_properties.Add(_propFile);
			_properties.Add(_propSettings);
		}

		protected internal override bool IsModified()
		{
			return Settings.IsModified();
		}

		[MonoInternalNote("file path?  do we use a System.Configuration api for opening it?  do we keep it open?  do we open it writable?")]
		protected internal override void DeserializeElement(XmlReader reader, bool serializeCollectionKey)
		{
			base.DeserializeElement(reader, serializeCollectionKey);
			if (!(File != ""))
			{
				return;
			}
			try
			{
				string text = File;
				if (!Path.IsPathRooted(text))
				{
					text = Path.Combine(Path.GetDirectoryName(base.Configuration.FilePath), text);
				}
				FileStream fileStream = System.IO.File.OpenRead(text);
				XmlReader reader2 = new ConfigXmlTextReader(fileStream, text);
				base.DeserializeElement(reader2, serializeCollectionKey);
				fileStream.Close();
			}
			catch
			{
			}
		}

		protected internal override void Reset(ConfigurationElement parentSection)
		{
			if (parentSection is AppSettingsSection appSettingsSection)
			{
				Settings.Reset(appSettingsSection.Settings);
			}
		}

		[MonoTODO]
		protected internal override string SerializeSection(ConfigurationElement parentElement, string name, ConfigurationSaveMode saveMode)
		{
			if (File == "")
			{
				return base.SerializeSection(parentElement, name, saveMode);
			}
			throw new NotImplementedException();
		}

		protected internal override object GetRuntimeObject()
		{
			KeyValueInternalCollection keyValueInternalCollection = new KeyValueInternalCollection();
			string[] allKeys = Settings.AllKeys;
			foreach (string key in allKeys)
			{
				KeyValueConfigurationElement keyValueConfigurationElement = Settings[key];
				keyValueInternalCollection.Add(keyValueConfigurationElement.Key, keyValueConfigurationElement.Value);
			}
			if (!ConfigurationManager.ConfigurationSystem.SupportsUserConfig)
			{
				keyValueInternalCollection.SetReadOnly();
			}
			return keyValueInternalCollection;
		}
	}
	public sealed class CallbackValidator : ConfigurationValidatorBase
	{
		private Type type;

		private ValidatorCallback callback;

		public CallbackValidator(Type type, ValidatorCallback callback)
		{
			this.type = type;
			this.callback = callback;
		}

		public override bool CanValidate(Type type)
		{
			return type == this.type;
		}

		public override void Validate(object value)
		{
			callback(value);
		}
	}
	[AttributeUsage(AttributeTargets.Property)]
	public sealed class CallbackValidatorAttribute : ConfigurationValidatorAttribute
	{
		private string callbackMethodName = "";

		private Type type;

		private ConfigurationValidatorBase instance;

		public string CallbackMethodName
		{
			get
			{
				return callbackMethodName;
			}
			set
			{
				callbackMethodName = value;
				instance = null;
			}
		}

		public Type Type
		{
			get
			{
				return type;
			}
			set
			{
				type = value;
				instance = null;
			}
		}

		public override ConfigurationValidatorBase ValidatorInstance => instance;
	}
	internal class ClientConfigurationSystem : IInternalConfigSystem
	{
		private Configuration cfg;

		private Configuration Configuration
		{
			get
			{
				if (cfg == null)
				{
					Assembly entryAssembly = Assembly.GetEntryAssembly();
					try
					{
						cfg = ConfigurationManager.OpenExeConfigurationInternal(ConfigurationUserLevel.None, entryAssembly, null);
					}
					catch (Exception inner)
					{
						throw new ConfigurationErrorsException("Error Initializing the configuration system.", inner);
					}
				}
				return cfg;
			}
		}

		bool IInternalConfigSystem.SupportsUserConfig => false;

		object IInternalConfigSystem.GetSection(string configKey)
		{
			return Configuration.GetSection(configKey)?.GetRuntimeObject();
		}

		void IInternalConfigSystem.RefreshConfig(string sectionName)
		{
		}
	}
	public sealed class CommaDelimitedStringCollection : StringCollection
	{
		private bool modified;

		private bool readOnly;

		private int originalStringHash;

		public bool IsModified
		{
			get
			{
				if (modified)
				{
					return true;
				}
				string text = ToString();
				if (text == null)
				{
					return false;
				}
				return text.GetHashCode() != originalStringHash;
			}
		}

		public new bool IsReadOnly => readOnly;

		public new string this[int index]
		{
			get
			{
				return base[index];
			}
			set
			{
				if (readOnly)
				{
					throw new ConfigurationErrorsException("The configuration is read only");
				}
				base[index] = value;
				modified = true;
			}
		}

		public new void Add(string value)
		{
			if (readOnly)
			{
				throw new ConfigurationErrorsException("The configuration is read only");
			}
			base.Add(value);
			modified = true;
		}

		public new void AddRange(string[] range)
		{
			if (readOnly)
			{
				throw new ConfigurationErrorsException("The configuration is read only");
			}
			base.AddRange(range);
			modified = true;
		}

		public new void Clear()
		{
			if (readOnly)
			{
				throw new ConfigurationErrorsException("The configuration is read only");
			}
			base.Clear();
			modified = true;
		}

		public CommaDelimitedStringCollection Clone()
		{
			CommaDelimitedStringCollection commaDelimitedStringCollection = new CommaDelimitedStringCollection();
			string[] array = new string[base.Count];
			CopyTo(array, 0);
			commaDelimitedStringCollection.AddRange(array);
			commaDelimitedStringCollection.originalStringHash = originalStringHash;
			return commaDelimitedStringCollection;
		}

		public new void Insert(int index, string value)
		{
			if (readOnly)
			{
				throw new ConfigurationErrorsException("The configuration is read only");
			}
			base.Insert(index, value);
			modified = true;
		}

		public new void Remove(string value)
		{
			if (readOnly)
			{
				throw new ConfigurationErrorsException("The configuration is read only");
			}
			base.Remove(value);
			modified = true;
		}

		public void SetReadOnly()
		{
			readOnly = true;
		}

		public override string ToString()
		{
			if (base.Count == 0)
			{
				return null;
			}
			string[] array = new string[base.Count];
			CopyTo(array, 0);
			return string.Join(",", array);
		}

		internal void UpdateStringHash()
		{
			string text = ToString();
			if (text == null)
			{
				originalStringHash = 0;
			}
			else
			{
				originalStringHash = text.GetHashCode();
			}
		}
	}
	public sealed class CommaDelimitedStringCollectionConverter : ConfigurationConverterBase
	{
		public override object ConvertFrom(ITypeDescriptorContext ctx, CultureInfo ci, object data)
		{
			CommaDelimitedStringCollection commaDelimitedStringCollection = new CommaDelimitedStringCollection();
			string[] array = ((string)data).Split(',');
			foreach (string text in array)
			{
				commaDelimitedStringCollection.Add(text.Trim());
			}
			commaDelimitedStringCollection.UpdateStringHash();
			return commaDelimitedStringCollection;
		}

		public override object ConvertTo(ITypeDescriptorContext ctx, CultureInfo ci, object value, Type type)
		{
			if (value == null)
			{
				return null;
			}
			if (!typeof(StringCollection).IsAssignableFrom(value.GetType()))
			{
				throw new ArgumentException();
			}
			return value.ToString();
		}
	}
	internal class ConfigNameValueCollection : NameValueCollection
	{
		private bool modified;

		public bool IsModified => modified;

		public ConfigNameValueCollection()
		{
		}

		public ConfigNameValueCollection(ConfigNameValueCollection col)
			: base(col.Count, col)
		{
		}

		public void ResetModified()
		{
			modified = false;
		}

		public override void Set(string name, string value)
		{
			base.Set(name, value);
			modified = true;
		}
	}
	internal abstract class ConfigInfo
	{
		public string Name;

		public string TypeName;

		protected Type Type;

		private string streamName;

		public ConfigInfo Parent;

		public IInternalConfigHost ConfigHost;

		public string XPath
		{
			get
			{
				StringBuilder stringBuilder = new StringBuilder(Name);
				for (ConfigInfo parent = Parent; parent != null; parent = parent.Parent)
				{
					stringBuilder.Insert(0, parent.Name + "/");
				}
				return stringBuilder.ToString();
			}
		}

		public string StreamName
		{
			get
			{
				return streamName;
			}
			set
			{
				streamName = value;
			}
		}

		public virtual object CreateInstance()
		{
			if (Type == null)
			{
				Type = ConfigHost.GetConfigType(TypeName, throwOnError: true);
			}
			return Activator.CreateInstance(Type, nonPublic: true);
		}

		public abstract bool HasConfigContent(Configuration cfg);

		public abstract bool HasDataContent(Configuration cfg);

		protected void ThrowException(string text, XmlReader reader)
		{
			throw new ConfigurationErrorsException(text, reader);
		}

		public abstract void ReadConfig(Configuration cfg, string streamName, XmlReader reader);

		public abstract void WriteConfig(Configuration cfg, XmlWriter writer, ConfigurationSaveMode mode);

		public abstract void ReadData(Configuration config, XmlReader reader, bool overrideAllowed);

		public abstract void WriteData(Configuration config, XmlWriter writer, ConfigurationSaveMode mode);

		internal abstract void Merge(ConfigInfo data);

		internal abstract bool HasValues(Configuration config, ConfigurationSaveMode mode);

		internal abstract void ResetModified(Configuration config);
	}
	internal class ConfigurationXmlDocument : XmlDocument
	{
		public override XmlElement CreateElement(string prefix, string localName, string namespaceURI)
		{
			if (namespaceURI == "http://schemas.microsoft.com/.NetConfiguration/v2.0")
			{
				return base.CreateElement(string.Empty, localName, string.Empty);
			}
			return base.CreateElement(prefix, localName, namespaceURI);
		}
	}
	public sealed class Configuration
	{
		private Configuration parent;

		private Hashtable elementData = new Hashtable();

		private string streamName;

		private ConfigurationSectionGroup rootSectionGroup;

		private ConfigurationLocationCollection locations;

		private SectionGroupInfo rootGroup;

		private IConfigSystem system;

		private bool hasFile;

		private string rootNamespace;

		private string configPath;

		private string locationConfigPath;

		private string locationSubPath;

		private ContextInformation evaluationContext;

		internal Configuration Parent
		{
			get
			{
				return parent;
			}
			set
			{
				parent = value;
			}
		}

		internal string FileName => streamName;

		internal IInternalConfigHost ConfigHost => system.Host;

		internal string LocationConfigPath => locationConfigPath;

		internal string ConfigPath => configPath;

		public AppSettingsSection AppSettings => (AppSettingsSection)GetSection("appSettings");

		public ConnectionStringsSection ConnectionStrings => (ConnectionStringsSection)GetSection("connectionStrings");

		public string FilePath
		{
			get
			{
				if (streamName == null && parent != null)
				{
					return parent.FilePath;
				}
				return streamName;
			}
		}

		public bool HasFile => hasFile;

		public ContextInformation EvaluationContext
		{
			get
			{
				if (evaluationContext == null)
				{
					object ctx = system.Host.CreateConfigurationContext(configPath, GetLocationSubPath());
					evaluationContext = new ContextInformation(this, ctx);
				}
				return evaluationContext;
			}
		}

		public ConfigurationLocationCollection Locations
		{
			get
			{
				if (locations == null)
				{
					locations = new ConfigurationLocationCollection();
				}
				return locations;
			}
		}

		public bool NamespaceDeclared
		{
			get
			{
				return rootNamespace != null;
			}
			set
			{
				rootNamespace = (value ? "http://schemas.microsoft.com/.NetConfiguration/v2.0" : null);
			}
		}

		public ConfigurationSectionGroup RootSectionGroup
		{
			get
			{
				if (rootSectionGroup == null)
				{
					rootSectionGroup = new ConfigurationSectionGroup();
					rootSectionGroup.Initialize(this, rootGroup);
				}
				return rootSectionGroup;
			}
		}

		public ConfigurationSectionGroupCollection SectionGroups => RootSectionGroup.SectionGroups;

		public ConfigurationSectionCollection Sections => RootSectionGroup.Sections;

		internal static event ConfigurationSaveEventHandler SaveStart;

		internal static event ConfigurationSaveEventHandler SaveEnd;

		internal Configuration(Configuration parent, string locationSubPath)
		{
			this.parent = parent;
			system = parent.system;
			rootGroup = parent.rootGroup;
			this.locationSubPath = locationSubPath;
			configPath = parent.ConfigPath;
		}

		internal Configuration(InternalConfigurationSystem system, string locationSubPath)
		{
			hasFile = true;
			this.system = system;
			system.InitForConfiguration(ref locationSubPath, out configPath, out locationConfigPath);
			Configuration configuration = null;
			if (locationSubPath != null)
			{
				configuration = new Configuration(system, locationSubPath);
				if (locationConfigPath != null)
				{
					configuration = configuration.FindLocationConfiguration(locationConfigPath, configuration);
				}
			}
			Init(system, configPath, configuration);
		}

		internal Configuration FindLocationConfiguration(string relativePath, Configuration defaultConfiguration)
		{
			Configuration configuration = defaultConfiguration;
			if (!string.IsNullOrEmpty(LocationConfigPath))
			{
				Configuration parentWithFile = GetParentWithFile();
				if (parentWithFile != null)
				{
					string configPathFromLocationSubPath = system.Host.GetConfigPathFromLocationSubPath(configPath, relativePath);
					configuration = parentWithFile.FindLocationConfiguration(configPathFromLocationSubPath, defaultConfiguration);
				}
			}
			string text = configPath.Substring(1) + "/";
			if (relativePath.StartsWith(text, StringComparison.Ordinal))
			{
				relativePath = relativePath.Substring(text.Length);
			}
			ConfigurationLocation configurationLocation = Locations.FindBest(relativePath);
			if (configurationLocation == null)
			{
				return configuration;
			}
			configurationLocation.SetParentConfiguration(configuration);
			return configurationLocation.OpenConfiguration();
		}

		internal void Init(IConfigSystem system, string configPath, Configuration parent)
		{
			this.system = system;
			this.configPath = configPath;
			streamName = system.Host.GetStreamName(configPath);
			this.parent = parent;
			if (parent != null)
			{
				rootGroup = parent.rootGroup;
			}
			else
			{
				rootGroup = new SectionGroupInfo();
				rootGroup.StreamName = streamName;
			}
			try
			{
				if (streamName != null)
				{
					Load();
				}
			}
			catch (XmlException ex)
			{
				throw new ConfigurationErrorsException(ex.Message, ex, streamName, 0);
			}
		}

		internal Configuration GetParentWithFile()
		{
			Configuration configuration = Parent;
			while (configuration != null && !configuration.HasFile)
			{
				configuration = configuration.Parent;
			}
			return configuration;
		}

		internal string GetLocationSubPath()
		{
			Configuration configuration = parent;
			string text = null;
			while (configuration != null)
			{
				text = configuration.locationSubPath;
				if (!string.IsNullOrEmpty(text))
				{
					return text;
				}
				configuration = configuration.parent;
			}
			return text;
		}

		public ConfigurationSection GetSection(string sectionName)
		{
			string[] array = sectionName.Split('/');
			if (array.Length == 1)
			{
				return Sections[array[0]];
			}
			ConfigurationSectionGroup configurationSectionGroup = SectionGroups[array[0]];
			int num = 1;
			while (configurationSectionGroup != null && num < array.Length - 1)
			{
				configurationSectionGroup = configurationSectionGroup.SectionGroups[array[num]];
				num++;
			}
			return configurationSectionGroup?.Sections[array[^1]];
		}

		public ConfigurationSectionGroup GetSectionGroup(string sectionGroupName)
		{
			string[] array = sectionGroupName.Split('/');
			ConfigurationSectionGroup configurationSectionGroup = SectionGroups[array[0]];
			int num = 1;
			while (configurationSectionGroup != null && num < array.Length)
			{
				configurationSectionGroup = configurationSectionGroup.SectionGroups[array[num]];
				num++;
			}
			return configurationSectionGroup;
		}

		internal ConfigurationSection GetSectionInstance(SectionInfo config, bool createDefaultInstance)
		{
			object obj = elementData[config];
			ConfigurationSection configurationSection = obj as ConfigurationSection;
			if (configurationSection != null || !createDefaultInstance)
			{
				return configurationSection;
			}
			object obj2 = config.CreateInstance();
			configurationSection = obj2 as ConfigurationSection;
			if (configurationSection == null)
			{
				configurationSection = new DefaultSection
				{
					SectionHandler = (IConfigurationSectionHandler)((obj2 is IConfigurationSectionHandler) ? obj2 : null)
				};
			}
			configurationSection.Configuration = this;
			ConfigurationSection configurationSection2 = null;
			if (parent != null)
			{
				configurationSection2 = parent.GetSectionInstance(config, createDefaultInstance: true);
				configurationSection.SectionInformation.SetParentSection(configurationSection2);
			}
			configurationSection.SectionInformation.ConfigFilePath = FilePath;
			configurationSection.ConfigContext = system.Host.CreateDeprecatedConfigContext(configPath);
			string text2 = (configurationSection.RawXml = obj as string);
			configurationSection.Reset(configurationSection2);
			if (text2 != null)
			{
				XmlTextReader xmlTextReader = new ConfigXmlTextReader(new StringReader(text2), FilePath);
				configurationSection.DeserializeSection(xmlTextReader);
				xmlTextReader.Close();
				if (!string.IsNullOrEmpty(configurationSection.SectionInformation.ConfigSource) && !string.IsNullOrEmpty(FilePath))
				{
					configurationSection.DeserializeConfigSource(Path.GetDirectoryName(FilePath));
				}
			}
			elementData[config] = configurationSection;
			return configurationSection;
		}

		internal ConfigurationSectionGroup GetSectionGroupInstance(SectionGroupInfo group)
		{
			ConfigurationSectionGroup configurationSectionGroup = group.CreateInstance() as ConfigurationSectionGroup;
			configurationSectionGroup?.Initialize(this, group);
			return configurationSectionGroup;
		}

		internal void SetConfigurationSection(SectionInfo config, ConfigurationSection sec)
		{
			elementData[config] = sec;
		}

		internal void SetSectionXml(SectionInfo config, string data)
		{
			elementData[config] = data;
		}

		internal string GetSectionXml(SectionInfo config)
		{
			return elementData[config] as string;
		}

		internal void CreateSection(SectionGroupInfo group, string name, ConfigurationSection sec)
		{
			if (group.HasChild(name))
			{
				throw new ConfigurationErrorsException("Cannot add a ConfigurationSection. A section or section group already exists with the name '" + name + "'");
			}
			if (!HasFile && !sec.SectionInformation.AllowLocation)
			{
				throw new ConfigurationErrorsException("The configuration section <" + name + "> cannot be defined inside a <location> element.");
			}
			if (!system.Host.IsDefinitionAllowed(configPath, sec.SectionInformation.AllowDefinition, sec.SectionInformation.AllowExeDefinition))
			{
				object obj = ((sec.SectionInformation.AllowExeDefinition != ConfigurationAllowExeDefinition.MachineToApplication) ? ((object)sec.SectionInformation.AllowExeDefinition) : ((object)sec.SectionInformation.AllowDefinition));
				throw new ConfigurationErrorsException("The section <" + name + "> can't be defined in this configuration file (the allowed definition context is '" + obj?.ToString() + "').");
			}
			if (sec.SectionInformation.Type == null)
			{
				sec.SectionInformation.Type = system.Host.GetConfigTypeName(sec.GetType());
			}
			SectionInfo sectionInfo = new SectionInfo(name, sec.SectionInformation);
			sectionInfo.StreamName = streamName;
			sectionInfo.ConfigHost = system.Host;
			group.AddChild(sectionInfo);
			elementData[sectionInfo] = sec;
			sec.Configuration = this;
		}

		internal void CreateSectionGroup(SectionGroupInfo parentGroup, string name, ConfigurationSectionGroup sec)
		{
			if (parentGroup.HasChild(name))
			{
				throw new ConfigurationErrorsException("Cannot add a ConfigurationSectionGroup. A section or section group already exists with the name '" + name + "'");
			}
			if (sec.Type == null)
			{
				sec.Type = system.Host.GetConfigTypeName(sec.GetType());
			}
			sec.SetName(name);
			SectionGroupInfo sectionGroupInfo = new SectionGroupInfo(name, sec.Type);
			sectionGroupInfo.StreamName = streamName;
			sectionGroupInfo.ConfigHost = system.Host;
			parentGroup.AddChild(sectionGroupInfo);
			elementData[sectionGroupInfo] = sec;
			sec.Initialize(this, sectionGroupInfo);
		}

		internal void RemoveConfigInfo(ConfigInfo config)
		{
			elementData.Remove(config);
		}

		public void Save()
		{
			Save(ConfigurationSaveMode.Modified, forceSaveAll: false);
		}

		public void Save(ConfigurationSaveMode saveMode)
		{
			Save(saveMode, forceSaveAll: false);
		}

		public void Save(ConfigurationSaveMode saveMode, bool forceSaveAll)
		{
			if (!forceSaveAll && saveMode != ConfigurationSaveMode.Full && !HasValues(saveMode))
			{
				ResetModified();
				return;
			}
			ConfigurationSaveEventHandler saveStart = Configuration.SaveStart;
			ConfigurationSaveEventHandler saveEnd = Configuration.SaveEnd;
			object writeContext = null;
			Exception ex = null;
			Stream stream = system.Host.OpenStreamForWrite(streamName, null, ref writeContext);
			try
			{
				saveStart?.Invoke(this, new ConfigurationSaveEventArgs(streamName, start: true, null, writeContext));
				Save(stream, saveMode, forceSaveAll);
				system.Host.WriteCompleted(streamName, success: true, writeContext);
			}
			catch (Exception ex2)
			{
				ex = ex2;
				system.Host.WriteCompleted(streamName, success: false, writeContext);
				throw;
			}
			finally
			{
				stream.Close();
				saveEnd?.Invoke(this, new ConfigurationSaveEventArgs(streamName, start: false, ex, writeContext));
			}
		}

		public void SaveAs(string filename)
		{
			SaveAs(filename, ConfigurationSaveMode.Modified, forceSaveAll: false);
		}

		public void SaveAs(string filename, ConfigurationSaveMode saveMode)
		{
			SaveAs(filename, saveMode, forceSaveAll: false);
		}

		[MonoInternalNote("Detect if file has changed")]
		public void SaveAs(string filename, ConfigurationSaveMode saveMode, bool forceSaveAll)
		{
			if (!forceSaveAll && saveMode != ConfigurationSaveMode.Full && !HasValues(saveMode))
			{
				ResetModified();
				return;
			}
			string directoryName = Path.GetDirectoryName(Path.GetFullPath(filename));
			if (!Directory.Exists(directoryName))
			{
				Directory.CreateDirectory(directoryName);
			}
			Save(new FileStream(filename, FileMode.OpenOrCreate, FileAccess.Write), saveMode, forceSaveAll);
		}

		private void Save(Stream stream, ConfigurationSaveMode mode, bool forceUpdateAll)
		{
			XmlTextWriter xmlTextWriter = new XmlTextWriter(new StreamWriter(stream));
			xmlTextWriter.Formatting = Formatting.Indented;
			try
			{
				xmlTextWriter.WriteStartDocument();
				if (rootNamespace != null)
				{
					xmlTextWriter.WriteStartElement("configuration", rootNamespace);
				}
				else
				{
					xmlTextWriter.WriteStartElement("configuration");
				}
				if (rootGroup.HasConfigContent(this))
				{
					rootGroup.WriteConfig(this, xmlTextWriter, mode);
				}
				foreach (ConfigurationLocation location in Locations)
				{
					if (location.OpenedConfiguration == null)
					{
						xmlTextWriter.WriteRaw("\n");
						xmlTextWriter.WriteRaw(location.XmlContent);
						continue;
					}
					xmlTextWriter.WriteStartElement("location");
					xmlTextWriter.WriteAttributeString("path", location.Path);
					if (!location.AllowOverride)
					{
						xmlTextWriter.WriteAttributeString("allowOverride", "false");
					}
					location.OpenedConfiguration.SaveData(xmlTextWriter, mode, forceUpdateAll);
					xmlTextWriter.WriteEndElement();
				}
				SaveData(xmlTextWriter, mode, forceUpdateAll);
				xmlTextWriter.WriteEndElement();
				ResetModified();
			}
			finally
			{
				xmlTextWriter.Flush();
				xmlTextWriter.Close();
			}
		}

		private void SaveData(XmlTextWriter tw, ConfigurationSaveMode mode, bool forceUpdateAll)
		{
			rootGroup.WriteRootData(tw, this, mode);
		}

		private bool HasValues(ConfigurationSaveMode mode)
		{
			foreach (ConfigurationLocation location in Locations)
			{
				if (location.OpenedConfiguration != null && location.OpenedConfiguration.HasValues(mode))
				{
					return true;
				}
			}
			return rootGroup.HasValues(this, mode);
		}

		private void ResetModified()
		{
			foreach (ConfigurationLocation location in Locations)
			{
				if (location.OpenedConfiguration != null)
				{
					location.OpenedConfiguration.ResetModified();
				}
			}
			rootGroup.ResetModified(this);
		}

		private bool Load()
		{
			if (string.IsNullOrEmpty(streamName))
			{
				return true;
			}
			Stream stream = null;
			try
			{
				stream = system.Host.OpenStreamForRead(streamName);
				if (stream == null)
				{
					return false;
				}
			}
			catch
			{
				return false;
			}
			using (XmlTextReader reader = new ConfigXmlTextReader(stream, streamName))
			{
				ReadConfigFile(reader, streamName);
			}
			ResetModified();
			return true;
		}

		private void ReadConfigFile(XmlReader reader, string fileName)
		{
			reader.MoveToContent();
			if (reader.NodeType != XmlNodeType.Element || reader.Name != "configuration")
			{
				ThrowException("Configuration file does not have a valid root element", reader);
			}
			if (reader.HasAttributes)
			{
				while (reader.MoveToNextAttribute())
				{
					if (reader.LocalName == "xmlns")
					{
						rootNamespace = reader.Value;
					}
					else
					{
						ThrowException($"Unrecognized attribute '{reader.LocalName}' in root element", reader);
					}
				}
			}
			reader.MoveToElement();
			if (reader.IsEmptyElement)
			{
				reader.Skip();
				return;
			}
			reader.ReadStartElement();
			reader.MoveToContent();
			if (reader.LocalName == "configSections")
			{
				if (reader.HasAttributes)
				{
					ThrowException("Unrecognized attribute in <configSections>.", reader);
				}
				rootGroup.ReadConfig(this, fileName, reader);
			}
			rootGroup.ReadRootData(reader, this, overrideAllowed: true);
		}

		internal void ReadData(XmlReader reader, bool allowOverride)
		{
			rootGroup.ReadData(this, reader, allowOverride);
		}

		private void ThrowException(string text, XmlReader reader)
		{
			throw new ConfigurationErrorsException(text, streamName, (reader as IXmlLineInfo)?.LineNumber ?? 0);
		}
	}
	public enum ConfigurationAllowDefinition
	{
		MachineOnly = 0,
		MachineToWebRoot = 100,
		MachineToApplication = 200,
		Everywhere = 300
	}
	public enum ConfigurationAllowExeDefinition
	{
		MachineOnly = 0,
		MachineToApplication = 100,
		MachineToLocalUser = 300,
		MachineToRoamingUser = 200
	}
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property)]
	public sealed class ConfigurationCollectionAttribute : Attribute
	{
		private string addItemName = "add";

		private string clearItemsName = "clear";

		private string removeItemName = "remove";

		private ConfigurationElementCollectionType collectionType;

		private Type itemType;

		public string AddItemName
		{
			get
			{
				return addItemName;
			}
			set
			{
				addItemName = value;
			}
		}

		public string ClearItemsName
		{
			get
			{
				return clearItemsName;
			}
			set
			{
				clearItemsName = value;
			}
		}

		public string RemoveItemName
		{
			get
			{
				return removeItemName;
			}
			set
			{
				removeItemName = value;
			}
		}

		public ConfigurationElementCollectionType CollectionType
		{
			get
			{
				return collectionType;
			}
			set
			{
				collectionType = value;
			}
		}

		[MonoInternalNote("Do something with this in ConfigurationElementCollection")]
		public Type ItemType => itemType;

		public ConfigurationCollectionAttribute(Type itemType)
		{
			this.itemType = itemType;
		}
	}
	public abstract class ConfigurationConverterBase : TypeConverter
	{
		public override bool CanConvertFrom(ITypeDescriptorContext ctx, Type type)
		{
			if (type == typeof(string))
			{
				return true;
			}
			return base.CanConvertFrom(ctx, type);
		}

		public override bool CanConvertTo(ITypeDescriptorContext ctx, Type type)
		{
			if (type == typeof(string))
			{
				return true;
			}
			return base.CanConvertTo(ctx, type);
		}
	}
	public abstract class ConfigurationElement
	{
		private class SaveContext
		{
			public readonly ConfigurationElement Element;

			public readonly ConfigurationElement Parent;

			public readonly ConfigurationSaveMode Mode;

			public SaveContext(ConfigurationElement element, ConfigurationElement parent, ConfigurationSaveMode mode)
			{
				Element = element;
				Parent = parent;
				Mode = mode;
			}

			public bool HasValues()
			{
				if (Mode == ConfigurationSaveMode.Full)
				{
					return true;
				}
				return Element.HasValues(Parent, Mode);
			}

			public bool HasValue(PropertyInformation prop)
			{
				if (Mode == ConfigurationSaveMode.Full)
				{
					return true;
				}
				return Element.HasValue(Parent, prop, Mode);
			}
		}

		private string rawXml;

		private bool modified;

		private ElementMap map;

		private ConfigurationPropertyCollection keyProps;

		private ConfigurationElementCollection defaultCollection;

		private bool readOnly;

		private ElementInformation elementInfo;

		private ConfigurationElementProperty elementProperty;

		private Configuration _configuration;

		private bool elementPresent;

		private ConfigurationLockCollection lockAllAttributesExcept;

		private ConfigurationLockCollection lockAllElementsExcept;

		private ConfigurationLockCollection lockAttributes;

		private ConfigurationLockCollection lockElements;

		private bool lockItem;

		private SaveContext saveContext;

		internal Configuration Configuration
		{
			get
			{
				return _configuration;
			}
			set
			{
				_configuration = value;
			}
		}

		public ElementInformation ElementInformation
		{
			get
			{
				if (elementInfo == null)
				{
					elementInfo = new ElementInformation(this, null);
				}
				return elementInfo;
			}
		}

		internal string RawXml
		{
			get
			{
				return rawXml;
			}
			set
			{
				if (rawXml == null || value != null)
				{
					rawXml = value;
				}
			}
		}

		protected internal virtual ConfigurationElementProperty ElementProperty
		{
			get
			{
				if (elementProperty == null)
				{
					elementProperty = new ConfigurationElementProperty(ElementInformation.Validator);
				}
				return elementProperty;
			}
		}

		protected ContextInformation EvaluationContext
		{
			get
			{
				if (Configuration != null)
				{
					return Configuration.EvaluationContext;
				}
				throw new ConfigurationErrorsException("This element is not currently associated with any context.");
			}
		}

		public ConfigurationLockCollection LockAllAttributesExcept
		{
			get
			{
				if (lockAllAttributesExcept == null)
				{
					lockAllAttributesExcept = new ConfigurationLockCollection(this, ConfigurationLockType.Attribute | ConfigurationLockType.Exclude);
				}
				return lockAllAttributesExcept;
			}
		}

		public ConfigurationLockCollection LockAllElementsExcept
		{
			get
			{
				if (lockAllElementsExcept == null)
				{
					lockAllElementsExcept = new ConfigurationLockCollection(this, ConfigurationLockType.Element | ConfigurationLockType.Exclude);
				}
				return lockAllElementsExcept;
			}
		}

		public ConfigurationLockCollection LockAttributes
		{
			get
			{
				if (lockAttributes == null)
				{
					lockAttributes = new ConfigurationLockCollection(this, ConfigurationLockType.Attribute);
				}
				return lockAttributes;
			}
		}

		public ConfigurationLockCollection LockElements
		{
			get
			{
				if (lockElements == null)
				{
					lockElements = new ConfigurationLockCollection(this, ConfigurationLockType.Element);
				}
				return lockElements;
			}
		}

		public bool LockItem
		{
			get
			{
				return lockItem;
			}
			set
			{
				lockItem = value;
			}
		}

		protected internal object this[ConfigurationProperty prop]
		{
			get
			{
				return this[prop.Name];
			}
			set
			{
				this[prop.Name] = value;
			}
		}

		protected internal object this[string propertyName]
		{
			get
			{
				return (ElementInformation.Properties[propertyName] ?? throw new InvalidOperationException("Property '" + propertyName + "' not found in configuration element")).Value;
			}
			set
			{
				PropertyInformation propertyInformation = ElementInformation.Properties[propertyName];
				if (propertyInformation == null)
				{
					throw new InvalidOperationException("Property '" + propertyName + "' not found in configuration element");
				}
				SetPropertyValue(propertyInformation.Property, value, ignoreLocks: false);
				propertyInformation.Value = value;
				modified = true;
			}
		}

		protected internal virtual ConfigurationPropertyCollection Properties
		{
			get
			{
				if (map == null)
				{
					map = ElementMap.GetMap(GetType());
				}
				return map.Properties;
			}
		}

		internal bool IsElementPresent => elementPresent;

		internal virtual void InitFromProperty(PropertyInformation propertyInfo)
		{
			elementInfo = new ElementInformation(this, propertyInfo);
			Init();
		}

		protected internal virtual void Init()
		{
		}

		[MonoTODO]
		protected virtual void ListErrors(IList errorList)
		{
			throw new NotImplementedException();
		}

		[MonoTODO]
		protected void SetPropertyValue(ConfigurationProperty prop, object value, bool ignoreLocks)
		{
			try
			{
				if (value != null)
				{
					prop.Validate(value);
				}
			}
			catch (Exception inner)
			{
				throw new ConfigurationErrorsException($"The value for the property '{prop.Name}' on type {ElementInformation.Type} is not valid.", inner);
			}
		}

		internal ConfigurationPropertyCollection GetKeyProperties()
		{
			if (keyProps != null)
			{
				return keyProps;
			}
			ConfigurationPropertyCollection configurationPropertyCollection = new ConfigurationPropertyCollection();
			foreach (ConfigurationProperty property in Properties)
			{
				if (property.IsKey)
				{
					configurationPropertyCollection.Add(property);
				}
			}
			return keyProps = configurationPropertyCollection;
		}

		internal ConfigurationElementCollection GetDefaultCollection()
		{
			if (defaultCollection != null)
			{
				return defaultCollection;
			}
			ConfigurationProperty configurationProperty = null;
			foreach (ConfigurationProperty property in Properties)
			{
				if (property.IsDefaultCollection)
				{
					configurationProperty = property;
					break;
				}
			}
			if (configurationProperty != null)
			{
				defaultCollection = this[configurationProperty] as ConfigurationElementCollection;
			}
			return defaultCollection;
		}

		public override bool Equals(object compareTo)
		{
			if (!(compareTo is ConfigurationElement configurationElement))
			{
				return false;
			}
			if (GetType() != configurationElement.GetType())
			{
				return false;
			}
			foreach (ConfigurationProperty property in Properties)
			{
				if (!object.Equals(this[property], configurationElement[property]))
				{
					return false;
				}
			}
			return true;
		}

		public override int GetHashCode()
		{
			int num = 0;
			foreach (ConfigurationProperty property in Properties)
			{
				object obj = this[property];
				if (obj != null)
				{
					num += obj.GetHashCode();
				}
			}
			return num;
		}

		internal virtual bool HasLocalModifications()
		{
			foreach (PropertyInformation property in ElementInformation.Properties)
			{
				if (property.ValueOrigin == PropertyValueOrigin.SetHere && property.IsModified)
				{
					return true;
				}
			}
			return false;
		}

		protected internal virtual void DeserializeElement(XmlReader reader, bool serializeCollectionKey)
		{
			Hashtable hashtable = new Hashtable();
			reader.MoveToContent();
			elementPresent = true;
			while (reader.MoveToNextAttribute())
			{
				PropertyInformation propertyInformation = ElementInformation.Properties[reader.LocalName];
				if (propertyInformation == null || (serializeCollectionKey && !propertyInformation.IsKey))
				{
					if (reader.LocalName == "lockAllAttributesExcept")
					{
						LockAllAttributesExcept.SetFromList(reader.Value);
					}
					else if (reader.LocalName == "lockAllElementsExcept")
					{
						LockAllElementsExcept.SetFromList(reader.Value);
					}
					else if (reader.LocalName == "lockAttributes")
					{
						LockAttributes.SetFromList(reader.Value);
					}
					else if (reader.LocalName == "lockElements")
					{
						LockElements.SetFromList(reader.Value);
					}
					else if (reader.LocalName == "lockItem")
					{
						LockItem = reader.Value.ToLowerInvariant() == "true";
					}
					else if (!(reader.LocalName == "xmlns") && (!(this is ConfigurationSection) || !(reader.LocalName == "configSource")) && !OnDeserializeUnrecognizedAttribute(reader.LocalName, reader.Value))
					{
						throw new ConfigurationErrorsException("Unrecognized attribute '" + reader.LocalName + "'.", reader);
					}
					continue;
				}
				if (hashtable.ContainsKey(propertyInformation))
				{
					throw new ConfigurationErrorsException("The attribute '" + propertyInformation.Name + "' may only appear once in this element.", reader);
				}
				string text = null;
				try
				{
					text = reader.Value;
					ValidateValue(propertyInformation.Property, text);
					propertyInformation.SetStringValue(text);
				}
				catch (ConfigurationErrorsException)
				{
					throw;
				}
				catch (ConfigurationException)
				{
					throw;
				}
				catch (Exception ex2)
				{
					throw new ConfigurationErrorsException($"The value for the property '{propertyInformation.Name}' is not valid. The error is: {ex2.Message}", reader);
				}
				hashtable[propertyInformation] = propertyInformation.Name;
				if (reader is ConfigXmlTextReader configXmlTextReader)
				{
					propertyInformation.Source = configXmlTextReader.Filename;
					propertyInformation.LineNumber = configXmlTextReader.LineNumber;
				}
			}
			reader.MoveToElement();
			if (reader.IsEmptyElement)
			{
				reader.Skip();
			}
			else
			{
				int depth = reader.Depth;
				reader.ReadStartElement();
				reader.MoveToContent();
				do
				{
					if (reader.NodeType != XmlNodeType.Element)
					{
						reader.Skip();
						continue;
					}
					PropertyInformation propertyInformation2 = ElementInformation.Properties[reader.LocalName];
					if (propertyInformation2 == null || (serializeCollectionKey && !propertyInformation2.IsKey))
					{
						if (OnDeserializeUnrecognizedElement(reader.LocalName, reader))
						{
							continue;
						}
						if (propertyInformation2 == null)
						{
							ConfigurationElementCollection configurationElementCollection = GetDefaultCollection();
							if (configurationElementCollection != null && configurationElementCollection.OnDeserializeUnrecognizedElement(reader.LocalName, reader))
							{
								continue;
							}
						}
						throw new ConfigurationErrorsException("Unrecognized element '" + reader.LocalName + "'.", reader);
					}
					if (!propertyInformation2.IsElement)
					{
						throw new ConfigurationErrorsException("Property '" + propertyInformation2.Name + "' is not a ConfigurationElement.");
					}
					if (hashtable.Contains(propertyInformation2))
					{
						throw new ConfigurationErrorsException("The element <" + propertyInformation2.Name + "> may only appear once in this section.", reader);
					}
					((ConfigurationElement)propertyInformation2.Value).DeserializeElement(reader, serializeCollectionKey);
					hashtable[propertyInformation2] = propertyInformation2.Name;
					if (depth == reader.Depth)
					{
						reader.Read();
					}
				}
				while (depth < reader.Depth);
			}
			modified = false;
			foreach (PropertyInformation property in ElementInformation.Properties)
			{
				if (!string.IsNullOrEmpty(property.Name) && property.IsRequired && !hashtable.ContainsKey(property) && ElementInformation.Properties[property.Name] == null)
				{
					object obj = OnRequiredPropertyNotFound(property.Name);
					if (!object.Equals(obj, property.DefaultValue))
					{
						property.Value = obj;
						property.IsModified = false;
					}
				}
			}
			PostDeserialize();
		}

		protected virtual bool OnDeserializeUnrecognizedAttribute(string name, string value)
		{
			return false;
		}

		protected virtual bool OnDeserializeUnrecognizedElement(string elementName, XmlReader reader)
		{
			return false;
		}

		protected virtual object OnRequiredPropertyNotFound(string name)
		{
			throw new ConfigurationErrorsException("Required attribute '" + name + "' not found.");
		}

		protected virtual void PreSerialize(XmlWriter writer)
		{
		}

		protected virtual void PostDeserialize()
		{
		}

		protected internal virtual void InitializeDefault()
		{
		}

		protected internal virtual bool IsModified()
		{
			if (modified)
			{
				return true;
			}
			foreach (PropertyInformation property in ElementInformation.Properties)
			{
				if (property.IsElement && property.Value is ConfigurationElement configurationElement && configurationElement.IsModified())
				{
					modified = true;
					break;
				}
			}
			return modified;
		}

		protected internal virtual void SetReadOnly()
		{
			readOnly = true;
		}

		public virtual bool IsReadOnly()
		{
			return readOnly;
		}

		protected internal virtual void Reset(ConfigurationElement parentElement)
		{
			elementPresent = false;
			if (parentElement != null)
			{
				ElementInformation.Reset(parentElement.ElementInformation);
			}
			else
			{
				InitializeDefault();
			}
		}

		protected internal virtual void ResetModified()
		{
			modified = false;
			foreach (PropertyInformation property in ElementInformation.Properties)
			{
				property.IsModified = false;
				if (property.Value is ConfigurationElement configurationElement)
				{
					configurationElement.ResetModified();
				}
			}
		}

		protected internal virtual bool SerializeElement(XmlWriter writer, bool serializeCollectionKey)
		{
			PreSerialize(writer);
			if (serializeCollectionKey)
			{
				ConfigurationPropertyCollection keyProperties = GetKeyProperties();
				foreach (ConfigurationProperty item in keyProperties)
				{
					writer.WriteAttributeString(item.Name, item.ConvertToString(this[item.Name]));
				}
				return keyProperties.Count > 0;
			}
			bool flag = false;
			foreach (PropertyInformation property in ElementInformation.Properties)
			{
				if (!property.IsElement)
				{
					if (saveContext == null)
					{
						throw new InvalidOperationException();
					}
					if (saveContext.HasValue(property))
					{
						writer.WriteAttributeString(property.Name, property.GetStringValue());
						flag = true;
					}
				}
			}
			foreach (PropertyInformation property2 in ElementInformation.Properties)
			{
				if (property2.IsElement)
				{
					ConfigurationElement configurationElement = (ConfigurationElement)property2.Value;
					if (configurationElement != null)
					{
						flag = configurationElement.SerializeToXmlElement(writer, property2.Name) || flag;
					}
				}
			}
			return flag;
		}

		protected internal virtual bool SerializeToXmlElement(XmlWriter writer, string elementName)
		{
			if (saveContext == null)
			{
				throw new InvalidOperationException();
			}
			if (!saveContext.HasValues())
			{
				return false;
			}
			if (elementName != null && elementName != "")
			{
				writer.WriteStartElement(elementName);
			}
			bool result = SerializeElement(writer, serializeCollectionKey: false);
			if (elementName != null && elementName != "")
			{
				writer.WriteEndElement();
			}
			return result;
		}

		protected internal virtual void Unmerge(ConfigurationElement sourceElement, ConfigurationElement parentElement, ConfigurationSaveMode saveMode)
		{
			if (parentElement != null && sourceElement.GetType() != parentElement.GetType())
			{
				throw new ConfigurationErrorsException("Can't unmerge two elements of different type");
			}
			bool flag = saveMode == ConfigurationSaveMode.Minimal || saveMode == ConfigurationSaveMode.Modified;
			foreach (PropertyInformation property in sourceElement.ElementInformation.Properties)
			{
				if (property.ValueOrigin == PropertyValueOrigin.Default)
				{
					continue;
				}
				PropertyInformation propertyInformation2 = ElementInformation.Properties[property.Name];
				object value = property.Value;
				if (parentElement == null || !parentElement.HasValue(property.Name))
				{
					propertyInformation2.Value = value;
				}
				else
				{
					if (value == null)
					{
						continue;
					}
					object obj = parentElement[property.Name];
					if (!property.IsElement)
					{
						if (!object.Equals(value, obj) || saveMode == ConfigurationSaveMode.Full || (saveMode == ConfigurationSaveMode.Modified && property.ValueOrigin == PropertyValueOrigin.SetHere))
						{
							propertyInformation2.Value = value;
						}
						continue;
					}
					ConfigurationElement configurationElement = (ConfigurationElement)value;
					if (!flag || configurationElement.IsModified())
					{
						if (obj == null)
						{
							propertyInformation2.Value = value;
							continue;
						}
						ConfigurationElement parentElement2 = (ConfigurationElement)obj;
						((ConfigurationElement)propertyInformation2.Value).Unmerge(configurationElement, parentElement2, saveMode);
					}
				}
			}
		}

		internal bool HasValue(string propName)
		{
			PropertyInformation propertyInformation = ElementInformation.Properties[propName];
			if (propertyInformation != null)
			{
				return propertyInformation.ValueOrigin != PropertyValueOrigin.Default;
			}
			return false;
		}

		internal bool IsReadFromConfig(string propName)
		{
			PropertyInformation propertyInformation = ElementInformation.Properties[propName];
			if (propertyInformation != null)
			{
				return propertyInformation.ValueOrigin == PropertyValueOrigin.SetHere;
			}
			return false;
		}

		private void ValidateValue(ConfigurationProperty p, string value)
		{
			ConfigurationValidatorBase validator;
			if (p != null && (validator = p.Validator) != null)
			{
				if (!validator.CanValidate(p.Type))
				{
					throw new ConfigurationErrorsException($"Validator does not support type {p.Type}");
				}
				validator.Validate(p.ConvertFromString(value));
			}
		}

		internal bool HasValue(ConfigurationElement parent, PropertyInformation prop, ConfigurationSaveMode mode)
		{
			if (prop.ValueOrigin == PropertyValueOrigin.Default)
			{
				return false;
			}
			if (mode == ConfigurationSaveMode.Modified && prop.ValueOrigin == PropertyValueOrigin.SetHere && prop.IsModified)
			{
				return true;
			}
			object obj = ((parent != null && parent.HasValue(prop.Name)) ? parent[prop.Name] : prop.DefaultValue);
			if (!prop.IsElement)
			{
				return !object.Equals(prop.Value, obj);
			}
			ConfigurationElement obj2 = (ConfigurationElement)prop.Value;
			ConfigurationElement parent2 = (ConfigurationElement)obj;
			return obj2.HasValues(parent2, mode);
		}

		internal virtual bool HasValues(ConfigurationElement parent, ConfigurationSaveMode mode)
		{
			if (mode == ConfigurationSaveMode.Full)
			{
				return true;
			}
			if (modified && mode == ConfigurationSaveMode.Modified)
			{
				return true;
			}
			foreach (PropertyInformation property in ElementInformation.Properties)
			{
				if (HasValue(parent, property, mode))
				{
					return true;
				}
			}
			return false;
		}

		internal virtual void PrepareSave(ConfigurationElement parent, ConfigurationSaveMode mode)
		{
			saveContext = new SaveContext(this, parent, mode);
			foreach (PropertyInformation property in ElementInformation.Properties)
			{
				if (property.IsElement)
				{
					ConfigurationElement configurationElement = (ConfigurationElement)property.Value;
					if (parent == null || !parent.HasValue(property.Name))
					{
						configurationElement.PrepareSave(null, mode);
						continue;
					}
					ConfigurationElement parent2 = (ConfigurationElement)parent[property.Name];
					configurationElement.PrepareSave(parent2, mode);
				}
			}
		}
	}
	internal class ElementMap
	{
		private static readonly Hashtable elementMaps = Hashtable.Synchronized(new Hashtable());

		private readonly ConfigurationPropertyCollection properties;

		private readonly ConfigurationCollectionAttribute collectionAttribute;

		public ConfigurationCollectionAttribute CollectionAttribute => collectionAttribute;

		public bool HasProperties => properties.Count > 0;

		public ConfigurationPropertyCollection Properties => properties;

		public static ElementMap GetMap(Type t)
		{
			if (elementMaps[t] is ElementMap result)
			{
				return result;
			}
			ElementMap elementMap = new ElementMap(t);
			elementMaps[t] = elementMap;
			return elementMap;
		}

		public ElementMap(Type t)
		{
			properties = new ConfigurationPropertyCollection();
			collectionAttribute = Attribute.GetCustomAttribute(t, typeof(ConfigurationCollectionAttribute)) as ConfigurationCollectionAttribute;
			PropertyInfo[] array = t.GetProperties(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
			foreach (PropertyInfo propertyInfo in array)
			{
				if (Attribute.GetCustomAttribute(propertyInfo, typeof(ConfigurationPropertyAttribute)) is ConfigurationPropertyAttribute configurationPropertyAttribute)
				{
					string name = ((configurationPropertyAttribute.Name != null) ? configurationPropertyAttribute.Name : propertyInfo.Name);
					ConfigurationValidatorBase validator = ((Attribute.GetCustomAttribute(propertyInfo, typeof(ConfigurationValidatorAttribute)) is ConfigurationValidatorAttribute configurationValidatorAttribute) ? configurationValidatorAttribute.ValidatorInstance : null);
					TypeConverterAttribute typeConverterAttribute = (TypeConverterAttribute)Attribute.GetCustomAttribute(propertyInfo, typeof(TypeConverterAttribute));
					ConfigurationProperty property = new ConfigurationProperty(typeConverter: (typeConverterAttribute != null) ? ((TypeConverter)Activator.CreateInstance(Type.GetType(typeConverterAttribute.ConverterTypeName), nonPublic: true)) : null, name: name, type: propertyInfo.PropertyType, defaultValue: configurationPropertyAttribute.DefaultValue, validator: validator, options: configurationPropertyAttribute.Options)
					{
						CollectionAttribute = (Attribute.GetCustomAttribute(propertyInfo, typeof(ConfigurationCollectionAttribute)) as ConfigurationCollectionAttribute)
					};
					properties.Add(property);
				}
			}
		}
	}
	[DebuggerDisplay("Count = {Count}")]
	public abstract class ConfigurationElementCollection : ConfigurationElement, ICollection, IEnumerable
	{
		private sealed class ConfigurationRemoveElement : ConfigurationElement
		{
			private readonly ConfigurationPropertyCollection properties = new ConfigurationPropertyCollection();

			private readonly ConfigurationElement _origElement;

			private readonly ConfigurationElementCollection _origCollection;

			internal object KeyValue
			{
				get
				{
					foreach (ConfigurationProperty property in Properties)
					{
						_origElement[property] = base[property];
					}
					return _origCollection.GetElementKey(_origElement);
				}
			}

			protected internal override ConfigurationPropertyCollection Properties => properties;

			internal ConfigurationRemoveElement(ConfigurationElement origElement, ConfigurationElementCollection origCollection)
			{
				_origElement = origElement;
				_origCollection = origCollection;
				foreach (ConfigurationProperty property in origElement.Properties)
				{
					if (property.IsKey)
					{
						properties.Add(property);
					}
				}
			}
		}

		private ArrayList list = new ArrayList();

		private ArrayList removed;

		private ArrayList inherited;

		private bool emitClear;

		private bool modified;

		private IComparer comparer;

		private int inheritedLimitIndex;

		private string addElementName = "add";

		private string clearElementName = "clear";

		private string removeElementName = "remove";

		public virtual ConfigurationElementCollectionType CollectionType => ConfigurationElementCollectionType.AddRemoveClearMap;

		private bool IsBasic
		{
			get
			{
				if (CollectionType != 0)
				{
					return CollectionType == ConfigurationElementCollectionType.BasicMapAlternate;
				}
				return true;
			}
		}

		private bool IsAlternate
		{
			get
			{
				if (CollectionType != ConfigurationElementCollectionType.AddRemoveClearMapAlternate)
				{
					return CollectionType == ConfigurationElementCollectionType.BasicMapAlternate;
				}
				return true;
			}
		}

		public int Count => list.Count;

		protected virtual string ElementName => string.Empty;

		public bool EmitClear
		{
			get
			{
				return emitClear;
			}
			set
			{
				emitClear = value;
			}
		}

		public bool IsSynchronized => false;

		public object SyncRoot => this;

		protected virtual bool ThrowOnDuplicate
		{
			get
			{
				if (CollectionType != ConfigurationElementCollectionType.AddRemoveClearMap && CollectionType != ConfigurationElementCollectionType.AddRemoveClearMapAlternate)
				{
					return false;
				}
				return true;
			}
		}

		protected internal string AddElementName
		{
			get
			{
				return addElementName;
			}
			set
			{
				addElementName = value;
			}
		}

		protected internal string ClearElementName
		{
			get
			{
				return clearElementName;
			}
			set
			{
				clearElementName = value;
			}
		}

		protected internal string RemoveElementName
		{
			get
			{
				return removeElementName;
			}
			set
			{
				removeElementName = value;
			}
		}

		protected ConfigurationElementCollection()
		{
		}

		protected ConfigurationElementCollection(IComparer comparer)
		{
			this.comparer = comparer;
		}

		internal override void InitFromProperty(PropertyInformation propertyInfo)
		{
			ConfigurationCollectionAttribute configurationCollectionAttribute = propertyInfo.Property.CollectionAttribute;
			if (configurationCollectionAttribute == null)
			{
				configurationCollectionAttribute = Attribute.GetCustomAttribute(propertyInfo.Type, typeof(ConfigurationCollectionAttribute)) as ConfigurationCollectionAttribute;
			}
			if (configurationCollectionAttribute != null)
			{
				addElementName = configurationCollectionAttribute.AddItemName;
				clearElementName = configurationCollectionAttribute.ClearItemsName;
				removeElementName = configurationCollectionAttribute.RemoveItemName;
			}
			base.InitFromProperty(propertyInfo);
		}

		protected virtual void BaseAdd(ConfigurationElement element)
		{
			BaseAdd(element, ThrowOnDuplicate);
		}

		protected void BaseAdd(ConfigurationElement element, bool throwIfExists)
		{
			if (IsReadOnly())
			{
				throw new ConfigurationErrorsException("Collection is read only.");
			}
			if (IsAlternate)
			{
				list.Insert(inheritedLimitIndex, element);
				inheritedLimitIndex++;
			}
			else
			{
				int num = IndexOfKey(GetElementKey(element));
				if (num >= 0)
				{
					if (element.Equals(list[num]))
					{
						return;
					}
					if (throwIfExists)
					{
						throw new ConfigurationErrorsException("Duplicate element in collection");
					}
					list.RemoveAt(num);
				}
				list.Add(element);
			}
			modified = true;
		}

		protected virtual void BaseAdd(int index, ConfigurationElement element)
		{
			if (ThrowOnDuplicate && BaseIndexOf(element) != -1)
			{
				throw new ConfigurationErrorsException("Duplicate element in collection");
			}
			if (IsReadOnly())
			{
				throw new ConfigurationErrorsException("Collection is read only.");
			}
			if (IsAlternate && index > inheritedLimitIndex)
			{
				throw new ConfigurationErrorsException("Can't insert new elements below the inherited elements.");
			}
			if (!IsAlternate && index <= inheritedLimitIndex)
			{
				throw new ConfigurationErrorsException("Can't insert new elements above the inherited elements.");
			}
			list.Insert(index, element);
			modified = true;
		}

		protected internal void BaseClear()
		{
			if (IsReadOnly())
			{
				throw new ConfigurationErrorsException("Collection is read only.");
			}
			list.Clear();
			modified = true;
		}

		protected internal ConfigurationElement BaseGet(int index)
		{
			return (ConfigurationElement)list[index];
		}

		protected internal ConfigurationElement BaseGet(object key)
		{
			int num = IndexOfKey(key);
			if (num != -1)
			{
				return (ConfigurationElement)list[num];
			}
			return null;
		}

		protected internal object[] BaseGetAllKeys()
		{
			object[] array = new object[list.Count];
			for (int i = 0; i < list.Count; i++)
			{
				array[i] = BaseGetKey(i);
			}
			return array;
		}

		protected internal object BaseGetKey(int index)
		{
			if (index < 0 || index >= list.Count)
			{
				throw new ConfigurationErrorsException($"Index {index} is out of range");
			}
			return GetElementKey((ConfigurationElement)list[index]).ToString();
		}

		protected int BaseIndexOf(ConfigurationElement element)
		{
			return list.IndexOf(element);
		}

		private int IndexOfKey(object key)
		{
			for (int i = 0; i < list.Count; i++)
			{
				if (CompareKeys(GetElementKey((ConfigurationElement)list[i]), key))
				{
					return i;
				}
			}
			return -1;
		}

		protected internal bool BaseIsRemoved(object key)
		{
			if (removed == null)
			{
				return false;
			}
			foreach (ConfigurationElement item in removed)
			{
				if (CompareKeys(GetElementKey(item), key))
				{
					return true;
				}
			}
			return false;
		}

		protected internal void BaseRemove(object key)
		{
			if (IsReadOnly())
			{
				throw new ConfigurationErrorsException("Collection is read only.");
			}
			int num = IndexOfKey(key);
			if (num != -1)
			{
				BaseRemoveAt(num);
				modified = true;
			}
		}

		protected internal void BaseRemoveAt(int index)
		{
			if (IsReadOnly())
			{
				throw new ConfigurationErrorsException("Collection is read only.");
			}
			ConfigurationElement configurationElement = (ConfigurationElement)list[index];
			if (!IsElementRemovable(configurationElement))
			{
				throw new ConfigurationErrorsException("Element can't be removed from element collection.");
			}
			if (inherited != null && inherited.Contains(configurationElement))
			{
				throw new ConfigurationErrorsException("Inherited items can't be removed.");
			}
			list.RemoveAt(index);
			if (IsAlternate && inheritedLimitIndex > 0)
			{
				inheritedLimitIndex--;
			}
			modified = true;
		}

		private bool CompareKeys(object key1, object key2)
		{
			if (comparer != null)
			{
				return comparer.Compare(key1, key2) == 0;
			}
			return object.Equals(key1, key2);
		}

		public void CopyTo(ConfigurationElement[] array, int index)
		{
			list.CopyTo(array, index);
		}

		protected abstract ConfigurationElement CreateNewElement();

		protected virtual ConfigurationElement CreateNewElement(string elementName)
		{
			return CreateNewElement();
		}

		private ConfigurationElement CreateNewElementInternal(string elementName)
		{
			ConfigurationElement configurationElement = ((elementName != null) ? CreateNewElement(elementName) : CreateNewElement());
			configurationElement.Init();
			return configurationElement;
		}

		public override bool Equals(object compareTo)
		{
			if (!(compareTo is ConfigurationElementCollection configurationElementCollection))
			{
				return false;
			}
			if (GetType() != configurationElementCollection.GetType())
			{
				return false;
			}
			if (Count != configurationElementCollection.Count)
			{
				return false;
			}
			for (int i = 0; i < Count; i++)
			{
				if (!BaseGet(i).Equals(configurationElementCollection.BaseGet(i)))
				{
					return false;
				}
			}
			return true;
		}

		protected abstract object GetElementKey(ConfigurationElement element);

		public override int GetHashCode()
		{
			int num = 0;
			for (int i = 0; i < Count; i++)
			{
				num += BaseGet(i).GetHashCode();
			}
			return num;
		}

		void ICollection.CopyTo(Array arr, int index)
		{
			list.CopyTo(arr, index);
		}

		public IEnumerator GetEnumerator()
		{
			return list.GetEnumerator();
		}

		protected virtual bool IsElementName(string elementName)
		{
			return false;
		}

		protected virtual bool IsElementRemovable(ConfigurationElement element)
		{
			return !IsReadOnly();
		}

		protected internal override bool IsModified()
		{
			if (modified)
			{
				return true;
			}
			for (int i = 0; i < list.Count; i++)
			{
				if (((ConfigurationElement)list[i]).IsModified())
				{
					modified = true;
					break;
				}
			}
			return modified;
		}

		[MonoTODO]
		public override bool IsReadOnly()
		{
			return base.IsReadOnly();
		}

		internal override void PrepareSave(ConfigurationElement parentElement, ConfigurationSaveMode mode)
		{
			ConfigurationElementCollection configurationElementCollection = (ConfigurationElementCollection)parentElement;
			base.PrepareSave(parentElement, mode);
			for (int i = 0; i < list.Count; i++)
			{
				ConfigurationElement configurationElement = (ConfigurationElement)list[i];
				object elementKey = GetElementKey(configurationElement);
				ConfigurationElement parent = configurationElementCollection?.BaseGet(elementKey);
				configurationElement.PrepareSave(parent, mode);
			}
		}

		internal override bool HasValues(ConfigurationElement parentElement, ConfigurationSaveMode mode)
		{
			ConfigurationElementCollection configurationElementCollection = (ConfigurationElementCollection)parentElement;
			if (mode == ConfigurationSaveMode.Full)
			{
				return list.Count > 0;
			}
			for (int i = 0; i < list.Count; i++)
			{
				ConfigurationElement configurationElement = (ConfigurationElement)list[i];
				object elementKey = GetElementKey(configurationElement);
				ConfigurationElement parent = configurationElementCollection?.BaseGet(elementKey);
				if (configurationElement.HasValues(parent, mode))
				{
					return true;
				}
			}
			return false;
		}

		protected internal override void Reset(ConfigurationElement parentElement)
		{
			bool isBasic = IsBasic;
			ConfigurationElementCollection configurationElementCollection = (ConfigurationElementCollection)parentElement;
			for (int i = 0; i < configurationElementCollection.Count; i++)
			{
				ConfigurationElement parentElement2 = configurationElementCollection.BaseGet(i);
				ConfigurationElement configurationElement = CreateNewElementInternal(null);
				configurationElement.Reset(parentElement2);
				BaseAdd(configurationElement);
				if (isBasic)
				{
					if (inherited == null)
					{
						inherited = new ArrayList();
					}
					inherited.Add(configurationElement);
				}
			}
			if (IsAlternate)
			{
				inheritedLimitIndex = 0;
			}
			else
			{
				inheritedLimitIndex = Count - 1;
			}
			modified = false;
		}

		protected internal override void ResetModified()
		{
			modified = false;
			for (int i = 0; i < list.Count; i++)
			{
				((ConfigurationElement)list[i]).ResetModified();
			}
		}

		[MonoTODO]
		protected internal override void SetReadOnly()
		{
			base.SetReadOnly();
		}

		protected internal override bool SerializeElement(XmlWriter writer, bool serializeCollectionKey)
		{
			if (serializeCollectionKey)
			{
				return base.SerializeElement(writer, serializeCollectionKey);
			}
			bool flag = false;
			if (IsBasic)
			{
				for (int i = 0; i < list.Count; i++)
				{
					ConfigurationElement configurationElement = (ConfigurationElement)list[i];
					flag = ((!(ElementName != string.Empty)) ? (configurationElement.SerializeElement(writer, serializeCollectionKey: false) || flag) : (configurationElement.SerializeToXmlElement(writer, ElementName) || flag));
				}
			}
			else
			{
				if (emitClear)
				{
					writer.WriteElementString(clearElementName, "");
					flag = true;
				}
				if (removed != null)
				{
					for (int j = 0; j < removed.Count; j++)
					{
						writer.WriteStartElement(removeElementName);
						((ConfigurationElement)removed[j]).SerializeElement(writer, serializeCollectionKey: true);
						writer.WriteEndElement();
					}
					flag = flag || removed.Count > 0;
				}
				for (int k = 0; k < list.Count; k++)
				{
					((ConfigurationElement)list[k]).SerializeToXmlElement(writer, addElementName);
				}
				flag = flag || list.Count > 0;
			}
			return flag;
		}

		protected override bool OnDeserializeUnrecognizedElement(string elementName, XmlReader reader)
		{
			if (IsBasic)
			{
				ConfigurationElement configurationElement = null;
				if (elementName == ElementName)
				{
					configurationElement = CreateNewElementInternal(null);
				}
				if (IsElementName(elementName))
				{
					configurationElement = CreateNewElementInternal(elementName);
				}
				if (configurationElement != null)
				{
					configurationElement.DeserializeElement(reader, serializeCollectionKey: false);
					BaseAdd(configurationElement);
					modified = false;
					return true;
				}
			}
			else
			{
				if (elementName == clearElementName)
				{
					reader.MoveToContent();
					if (reader.MoveToNextAttribute())
					{
						throw new ConfigurationErrorsException("Unrecognized attribute '" + reader.LocalName + "'.");
					}
					reader.MoveToElement();
					reader.Skip();
					BaseClear();
					emitClear = true;
					modified = false;
					return true;
				}
				if (elementName == removeElementName)
				{
					ConfigurationRemoveElement configurationRemoveElement = new ConfigurationRemoveElement(CreateNewElementInternal(null), this);
					configurationRemoveElement.DeserializeElement(reader, serializeCollectionKey: true);
					BaseRemove(configurationRemoveElement.KeyValue);
					modified = false;
					return true;
				}
				if (elementName == addElementName)
				{
					ConfigurationElement configurationElement2 = CreateNewElementInternal(null);
					configurationElement2.DeserializeElement(reader, serializeCollectionKey: false);
					BaseAdd(configurationElement2);
					modified = false;
					return true;
				}
			}
			return false;
		}

		protected internal override void Unmerge(ConfigurationElement sourceElement, ConfigurationElement parentElement, ConfigurationSaveMode saveMode)
		{
			ConfigurationElementCollection configurationElementCollection = (ConfigurationElementCollection)sourceElement;
			ConfigurationElementCollection configurationElementCollection2 = (ConfigurationElementCollection)parentElement;
			for (int i = 0; i < configurationElementCollection.Count; i++)
			{
				ConfigurationElement configurationElement = configurationElementCollection.BaseGet(i);
				object elementKey = configurationElementCollection.GetElementKey(configurationElement);
				ConfigurationElement configurationElement2 = configurationElementCollection2?.BaseGet(elementKey);
				ConfigurationElement configurationElement3 = CreateNewElementInternal(null);
				if (configurationElement2 != null && saveMode != ConfigurationSaveMode.Full)
				{
					configurationElement3.Unmerge(configurationElement, configurationElement2, saveMode);
					if (configurationElement3.HasValues(configurationElement2, saveMode))
					{
						BaseAdd(configurationElement3);
					}
				}
				else
				{
					configurationElement3.Unmerge(configurationElement, null, ConfigurationSaveMode.Full);
					BaseAdd(configurationElement3);
				}
			}
			if (saveMode == ConfigurationSaveMode.Full)
			{
				EmitClear = true;
			}
			else
			{
				if (configurationElementCollection2 == null)
				{
					return;
				}
				for (int j = 0; j < configurationElementCollection2.Count; j++)
				{
					ConfigurationElement configurationElement4 = configurationElementCollection2.BaseGet(j);
					object elementKey2 = configurationElementCollection2.GetElementKey(configurationElement4);
					if (configurationElementCollection.IndexOfKey(elementKey2) == -1)
					{
						if (removed == null)
						{
							removed = new ArrayList();
						}
						removed.Add(configurationElement4);
					}
				}
			}
		}
	}
	public enum ConfigurationElementCollectionType
	{
		BasicMap,
		AddRemoveClearMap,
		BasicMapAlternate,
		AddRemoveClearMapAlternate
	}
	public sealed class ConfigurationElementProperty
	{
		private ConfigurationValidatorBase validator;

		public ConfigurationValidatorBase Validator => validator;

		public ConfigurationElementProperty(ConfigurationValidatorBase validator)
		{
			this.validator = validator;
		}
	}
	[Serializable]
	public class ConfigurationErrorsException : ConfigurationException
	{
		private readonly string filename;

		private readonly int line;

		public override string BareMessage => ((ConfigurationException)this).BareMessage;

		public ICollection Errors
		{
			get
			{
				throw new NotImplementedException();
			}
		}

		public override string Filename => filename;

		public override int Line => line;

		public override string Message
		{
			get
			{
				if (!string.IsNullOrEmpty(filename))
				{
					if (line != 0)
					{
						return ((ConfigurationException)this).BareMessage + " (" + filename + " line " + line + ")";
					}
					return ((ConfigurationException)this).BareMessage + " (" + filename + ")";
				}
				if (line != 0)
				{
					return ((ConfigurationException)this).BareMessage + " (line " + line + ")";
				}
				return ((ConfigurationException)this).BareMessage;
			}
		}

		public ConfigurationErrorsException()
		{
		}

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

		protected ConfigurationErrorsException(SerializationInfo info, StreamingContext context)
			: base(info, context)
		{
			filename = info.GetString("ConfigurationErrors_Filename");
			line = info.GetInt32("ConfigurationErrors_Line");
		}

		public ConfigurationErrorsException(string message, Exception inner)
			: base(message, inner)
		{
		}

		public ConfigurationErrorsException(string message, XmlNode node)
			: this(message, null, GetFilename(node), GetLineNumber(node))
		{
		}

		public ConfigurationErrorsException(string message, Exception inner, XmlNode node)
			: this(message, inner, GetFilename(node), GetLineNumber(node))
		{
		}

		public ConfigurationErrorsException(string message, XmlReader reader)
			: this(message, null, GetFilename(reader), GetLineNumber(reader))
		{
		}

		public ConfigurationErrorsException(string message, Exception inner, XmlReader reader)
			: this(message, inner, GetFilename(reader), GetLineNumber(reader))
		{
		}

		public ConfigurationErrorsException(string message, string filename, int line)
			: this(message, null, filename, line)
		{
		}

		public ConfigurationErrorsException(string message, Exception inner, string filename, int line)
			: base(message, inner)
		{
			this.filename = filename;
			this.line = line;
		}

		public static string GetFilename(XmlReader reader)
		{
			if (reader is IConfigErrorInfo)
			{
				return ((IConfigErrorInfo)reader).Filename;
			}
			return reader?.BaseURI;
		}

		public static int GetLineNumber(XmlReader reader)
		{
			if (reader is IConfigErrorInfo)
			{
				return ((IConfigErrorInfo)reader).LineNumber;
			}
			if (!(reader is IXmlLineInfo xmlLineInfo))
			{
				return 0;
			}
			return xmlLineInfo.LineNumber;
		}

		public static string GetFilename(XmlNode node)
		{
			if (!(node is IConfigErrorInfo))
			{
				return null;
			}
			return ((IConfigErrorInfo)node).Filename;
		}

		public static int GetLineNumber(XmlNode node)
		{
			if (!(node is IConfigErrorInfo))
			{
				return 0;
			}
			return ((IConfigErrorInfo)node).LineNumber;
		}

		public override void GetObjectData(SerializationInfo info, StreamingContext context)
		{
			((ConfigurationException)this).GetObjectData(info, context);
			info.AddValue("ConfigurationErrors_Filename", filename);
			info.AddValue("ConfigurationErrors_Line", line);
		}
	}
	public class ConfigurationFileMap : ICloneable
	{
		private string machineConfigFilename;

		public string MachineConfigFilename
		{
			get
			{
				return machineConfigFilename;
			}
			set
			{
				machineConfigFilename = value;
			}
		}

		public ConfigurationFileMap()
		{
			machineConfigFilename = RuntimeEnvironment.SystemConfigurationFile;
		}

		public ConfigurationFileMap(string machineConfigFilename)
		{
			this.machineConfigFilename = machineConfigFilename;
		}

		public virtual object Clone()
		{
			return new ConfigurationFileMap(machineConfigFilename);
		}
	}
	public class ConfigurationLocation
	{
		private static readonly char[] pathTrimChars = new char[1] { '/' };

		private string path;

		private Configuration configuration;

		private Configuration parent;

		private string xmlContent;

		private bool parentResolved;

		private bool allowOverride;

		public string Path => path;

		internal bool AllowOverride => allowOverride;

		internal string XmlContent => xmlContent;

		internal Configuration OpenedConfiguration => configuration;

		internal ConfigurationLocation()
		{
		}

		internal ConfigurationLocation(string path, string xmlContent, Configuration parent, bool allowOverride)
		{
			if (!string.IsNullOrEmpty(path))
			{
				switch (path[0])
				{
				case ' ':
				case '.':
				case '/':
				case '\\':
					throw new ConfigurationErrorsException("<location> path attribute must be a relative virtual path.  It cannot start with any of ' ' '.' '/' or '\\'.");
				}
				path = path.TrimEnd(pathTrimChars);
			}
			this.path = path;
			this.xmlContent = xmlContent;
			this.parent = parent;
			this.allowOverride = allowOverride;
		}

		public Configuration OpenConfiguration()
		{
			if (configuration == null)
			{
				if (!parentResolved)
				{
					Configuration parentWithFile = parent.GetParentWithFile();
					if (parentWithFile != null)
					{
						string configPathFromLocationSubPath = parent.ConfigHost.GetConfigPathFromLocationSubPath(parent.LocationConfigPath, path);
						parent = parentWithFile.FindLocationConfiguration(configPathFromLocationSubPath, parent);
					}
				}
				configuration = new Configuration(parent, path);
				using (XmlTextReader reader = new ConfigXmlTextReader(new StringReader(xmlContent), path))
				{
					configuration.ReadData(reader, allowOverride);
				}
				xmlContent = null;
			}
			return configuration;
		}

		internal void SetParentConfiguration(Configuration parent)
		{
			if (!parentResolved)
			{
				parentResolved = true;
				this.parent = parent;
				if (configuration != null)
				{
					configuration.Parent = parent;
				}
			}
		}
	}
	public class ConfigurationLocationCollection : ReadOnlyCollectionBase
	{
		public ConfigurationLocation this[int index] => base.InnerList[index] as ConfigurationLocation;

		internal ConfigurationLocationCollection()
		{
		}

		internal void Add(ConfigurationLocation loc)
		{
			base.InnerList.Add(loc);
		}

		internal ConfigurationLocation Find(string location)
		{
			foreach (ConfigurationLocation inner in base.InnerList)
			{
				if (string.Compare(inner.Path, location, StringComparison.OrdinalIgnoreCase) == 0)
				{
					return inner;
				}
			}
			return null;
		}

		internal ConfigurationLocation FindBest(string location)
		{
			if (string.IsNullOrEmpty(location))
			{
				return null;
			}
			ConfigurationLocation configurationLocation = null;
			int length = location.Length;
			int num = 0;
			foreach (ConfigurationLocation inner in base.InnerList)
			{
				string path = inner.Path;
				if (string.IsNullOrEmpty(path))
				{
					continue;
				}
				int length2 = path.Length;
				if (!location.StartsWith(path, StringComparison.OrdinalIgnoreCase))
				{
					continue;
				}
				if (length == length2)
				{
					return inner;
				}
				if (length <= length2 || location[length2] == '/')
				{
					if (configurationLocation == null)
					{
						configurationLocation = inner;
					}
					else if (num < length2)
					{
						configurationLocation = inner;
						num = length2;
					}
				}
			}
			return configurationLocation;
		}
	}
	[Flags]
	internal enum ConfigurationLockType
	{
		Attribute = 1,
		Element = 2,
		Exclude = 0x10
	}
	public sealed class ConfigurationLockCollection : ICollection, IEnumerable
	{
		private ArrayList names;

		private ConfigurationElement element;

		private ConfigurationLockType lockType;

		private bool is_modified;

		private Hashtable valid_name_hash;

		private string valid_names;

		public string AttributeList
		{
			get
			{
				string[] array = new string[names.Count];
				names.CopyTo(array, 0);
				return string.Join(",", array);
			}
		}

		public int Count => names.Count;

		[MonoTODO]
		public bool HasParentElements => false;

		[MonoTODO]
		public bool IsModified
		{
			get
			{
				return is_modified;
			}
			internal set
			{
				is_modified = value;
			}
		}

		[MonoTODO]
		public bool IsSynchronized => false;

		[MonoTODO]
		public object SyncRoot => this;

		internal ConfigurationLockCollection(ConfigurationElement element, ConfigurationLockType lockType)
		{
			names = new ArrayList();
			this.element = element;
			this.lockType = lockType;
		}

		private void CheckName(string name)
		{
			bool flag = (lockType & ConfigurationLockType.Attribute) == ConfigurationLockType.Attribute;
			if (valid_name_hash == null)
			{
				valid_name_hash = new Hashtable();
				foreach (ConfigurationProperty property in element.Properties)
				{
					if (flag != property.IsElement)
					{
						valid_name_hash.Add(property.Name, true);
					}
				}
				if (!flag)
				{
					ConfigurationElementCollection defaultCollection = element.GetDefaultCollection();
					valid_name_hash.Add(defaultCollection.AddElementName, true);
					valid_name_hash.Add(defaultCollection.ClearElementName, true);
					valid_name_hash.Add(defaultCollection.RemoveElementName, true);
				}
				string[] array = new string[valid_name_hash.Keys.Count];
				valid_name_hash.Keys.CopyTo(array, 0);
				valid_names = string.Join(",", array);
			}
			if (valid_name_hash[name] == null)
			{
				throw new ConfigurationErrorsException(string.Format("The {2} '{0}' is not valid in the locked list for this section.  The following {3} can be locked: '{1}'", name, valid_names, flag ? "attribute" : "element", flag ? "attributes" : "elements"));
			}
		}

		public void Add(string name)
		{
			CheckName(name);
			if (!names.Contains(name))
			{
				names.Add(name);
				is_modified = true;
			}
		}

		public void Clear()
		{
			names.Clear();
			is_modified = true;
		}

		public bool Contains(string name)
		{
			return names.Contains(name);
		}

		public void CopyTo(string[] array, int index)
		{
			names.CopyTo(array, index);
		}

		public IEnumerator GetEnumerator()
		{
			return names.GetEnumerator();
		}

		[MonoInternalNote("we can't possibly *always* return false here...")]
		public bool IsReadOnly(string name)
		{
			for (int i = 0; i < names.Count; i++)
			{
				if ((string)names[i] == name)
				{
					return false;
				}
			}
			throw new ConfigurationErrorsException($"The entry '{name}' is not in the collection.");
		}

		public void Remove(string name)
		{
			names.Remove(name);
			is_modified = true;
		}

		public void SetFromList(string attributeList)
		{
			Clear();
			char[] separator = new char[1] { ',' };
			string[] array = attributeList.Split(separator);
			foreach (string text in array)
			{
				Add(text.Trim());
			}
		}

		void ICollection.CopyTo(Array array, int index)
		{
			names.CopyTo(array, index);
		}
	}
	public static class ConfigurationManager
	{
		private static InternalConfigurationFactory configFactory = new InternalConfigurationFactory();

		private static IInternalConfigSystem configSystem = new ClientConfigurationSystem();

		private static object lockobj = new object();

		internal static IInternalConfigConfigurationFactory ConfigurationFactory => configFactory;

		internal static IInternalConfigSystem ConfigurationSystem => configSystem;

		public static NameValueCollection AppSettings => (NameValueCollection)GetSection("appSettings");

		public static ConnectionStringSettingsCollection ConnectionStrings => ((ConnectionStringsSection)GetSection("connectionStrings")).ConnectionStrings;

		[MonoTODO("Evidence and version still needs work")]
		private static string GetAssemblyInfo(Assembly a)
		{
			object[] customAttributes = a.GetCustomAttributes(typeof(AssemblyProductAttribute), inherit: false);
			string arg = ((customAttributes == null || customAttributes.Length == 0) ? AppDomain.CurrentDomain.FriendlyName : ((AssemblyProductAttribute)customAttributes[0]).Product);
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.Append("evidencehere");
			string arg2 = stringBuilder.ToString();
			customAttributes = a.GetCustomAttributes(typeof(AssemblyVersionAttribute), inherit: false);
			return Path.Combine(path2: (customAttributes == null || customAttributes.Length == 0) ? "1.0.0.0" : ((AssemblyVersionAttribute)customAttributes[0]).Version, path1: $"{arg}_{arg2}");
		}

		internal static Configuration OpenExeConfigurationInternal(ConfigurationUserLevel userLevel, Assembly calling_assembly, string exePath)
		{
			ExeConfigurationFileMap exeConfigurationFileMap = new ExeConfigurationFileMap();
			if (userLevel != 0)
			{
				if (userLevel != ConfigurationUserLevel.PerUserRoaming)
				{
					if (userLevel != ConfigurationUserLevel.PerUserRoamingAndLocal)
					{
						goto IL_00ea;
					}
					exeConfigurationFileMap.LocalUserConfigFilename = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), GetAssemblyInfo(calling_assembly));
					exeConfigurationFileMap.LocalUserConfigFilename = Path.Combine(exeConfigurationFileMap.LocalUserConfigFilename, "user.config");
				}
				exeConfigurationFileMap.RoamingUserConfigFilename = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), GetAssemblyInfo(calling_assembly));
				exeConfigurationFileMap.RoamingUserConfigFilename = Path.Combine(exeConfigurationFileMap.RoamingUserConfigFilename, "user.config");
			}
			if (exePath == null || exePath.Length == 0)
			{
				exeConfigurationFileMap.ExeConfigFilename = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
			}
			else
			{
				if (!Path.IsPathRooted(exePath))
				{
					exePath = Path.GetFullPath(exePath);
				}
				if (!File.Exists(exePath))
				{
					Exception inner = new ArgumentException("The specified path does not exist.", "exePath");
					throw new ConfigurationErrorsException("Error Initializing the configuration system:", inner);
				}
				exeConfigurationFileMap.ExeConfigFilename = exePath + ".config";
			}
			goto IL_00ea;
			IL_00ea:
			return ConfigurationFactory.Create(typeof(ExeConfigurationHost), exeConfigurationFileMap, userLevel);
		}

		public static Configuration OpenExeConfiguration(ConfigurationUserLevel userLevel)
		{
			return OpenExeConfigurationInternal(userLevel, Assembly.GetEntryAssembly() ?? Assembly.GetCallingAssembly(), null);
		}

		public static Configuration OpenExeConfiguration(string exePath)
		{
			return OpenExeConfigurationInternal(ConfigurationUserLevel.None, Assembly.GetEntryAssembly() ?? Assembly.GetCallingAssembly(), exePath);
		}

		[MonoLimitation("ConfigurationUserLevel parameter is not supported.")]
		public static Configuration OpenMappedExeConfiguration(ExeConfigurationFileMap fileMap, ConfigurationUserLevel userLevel)
		{
			return ConfigurationFactory.Create(typeof(ExeConfigurationHost), fileMap, userLevel);
		}

		public static Configuration OpenMachineConfiguration()
		{
			ConfigurationFileMap configurationFileMap = new ConfigurationFileMap();
			return ConfigurationFactory.Create(typeof(MachineConfigurationHost), configurationFileMap);
		}

		public static Configuration OpenMappedMachineConfiguration(ConfigurationFileMap fileMap)
		{
			return ConfigurationFactory.Create(typeof(MachineConfigurationHost), fileMap);
		}

		public static object GetSection(string sectionName)
		{
			object section = ConfigurationSystem.GetSection(sectionName);
			if (section is ConfigurationSection)
			{
				return ((ConfigurationSection)section).GetRuntimeObject();
			}
			return section;
		}

		public static void RefreshSection(string sectionName)
		{
			ConfigurationSystem.RefreshConfig(sectionName);
		}

		internal static IInternalConfigSystem ChangeConfigurationSystem(IInternalConfigSystem newSystem)
		{
			if (newSystem == null)
			{
				throw new ArgumentNullException("newSystem");
			}
			lock (lockobj)
			{
				IInternalConfigSystem result = configSystem;
				configSystem = newSystem;
				return result;
			}
		}
	}
	[Serializable]
	public sealed class ConfigurationPermission : CodeAccessPermission, IUnrestrictedPermission
	{
		private bool unrestricted;

		public ConfigurationPermission(PermissionState state)
		{
			unrestricted = state == PermissionState.Unrestricted;
		}

		public override IPermission Copy()
		{
			return (IPermission)(object)new ConfigurationPermission(unrestricted ? PermissionState.Unrestricted : PermissionState.None);
		}

		public override void FromXml(SecurityElement securityElement)
		{
			if (securityElement == null)
			{
				throw new ArgumentNullException("securityElement");
			}
			if (securityElement.Tag != "IPermission")
			{
				throw new ArgumentException("securityElement");
			}
			string text = securityElement.Attribute("Unrestricted");
			if (text != null)
			{
				unrestricted = string.Compare(text, "true", StringComparison.InvariantCultureIgnoreCase) == 0;
			}
		}

		public override IPermission Intersect(IPermission target)
		{
			if (target == null)
			{
				return null;
			}
			if (!(target is ConfigurationPermission configurationPermission))
			{
				throw new ArgumentException("target");
			}
			return (IPermission)(object)new ConfigurationPermission((unrestricted && configurationPermission.IsUnrestricted()) ? PermissionState.Unrestricted : PermissionState.None);
		}

		public override IPermission Union(IPermission target)
		{
			if (target == null)
			{
				return ((CodeAccessPermission)this).Copy();
			}
			if (!(target is ConfigurationPermission configurationPermission))
			{
				throw new ArgumentException("target");
			}
			return (IPermission)(object)new ConfigurationPermission((unrestricted || configurationPermission.IsUnrestricted()) ? PermissionState.Unrestricted : PermissionState.None);
		}

		public override bool IsSubsetOf(IPermission target)
		{
			if (target == null)
			{
				return !unrestricted;
			}
			if (!(target is ConfigurationPermission configurationPermission))
			{
				throw new ArgumentException("target");
			}
			if (unrestricted)
			{
				return configurationPermission.IsUnrestricted();
			}
			return true;
		}

		public bool IsUnrestricted()
		{
			return unrestricted;
		}

		public override SecurityElement ToXml()
		{
			SecurityElement securityElement = new SecurityElement("IPermission");
			securityElement.AddAttribute("class", ((object)this).GetType().AssemblyQualifiedName);
			securityElement.AddAttribute("version", "1");
			if (unrestricted)
			{
				securityElement.AddAttribute("Unrestricted", "true");
			}
			return securityElement;
		}
	}
	[Serializable]
	[AttributeUsage(AttributeTargets.All, AllowMultiple = true, Inherited = false)]
	public sealed class ConfigurationPermissionAttribute : CodeAccessSecurityAttribute
	{
		public ConfigurationPermissionAttribute(SecurityAction action)
			: base(action)
		{
		}

		public override IPermission CreatePermission()
		{
			return (IPermission)(object)new ConfigurationPermission(base.Unrestricted ? PermissionState.Unrestricted : PermissionState.None);
		}
	}
	public sealed class ConfigurationProperty
	{
		internal static readonly object NoDefaultValue = new object();

		private string name;

		private Type type;

		private object default_value;

		private TypeConverter converter;

		private ConfigurationValidatorBase validation;

		private ConfigurationPropertyOptions flags;

		private string description;

		private ConfigurationCollectionAttribute collectionAttribute;

		public TypeConverter Converter => converter;

		public object DefaultValue => default_value;

		public bool IsKey => (flags & ConfigurationPropertyOptions.IsKey) != 0;

		public bool IsRequired => (flags & ConfigurationPropertyOptions.IsRequired) != 0;

		public bool IsDefaultCollection => (flags & ConfigurationPropertyOptions.IsDefaultCollection) != 0;

		public string Name => name;

		public string Description => description;

		public Type Type => type;

		public ConfigurationValidatorBase Validator => validation;

		internal bool IsElement => typeof(ConfigurationElement).IsAssignableFrom(type);

		internal ConfigurationCollectionAttribute CollectionAttribute
		{
			get
			{
				return collectionAttribute;
			}
			set
			{
				collectionAttribute = value;
			}
		}

		public ConfigurationProperty(string name, Type type)
			: this(name, type, NoDefaultValue, TypeDescriptor.GetConverter(type), new DefaultValidator(), ConfigurationPropertyOptions.None, null)
		{
		}

		public ConfigurationProperty(string name, Type type, object defaultValue)
			: this(name, type, defaultValue, TypeDescriptor.GetConverter(type), new DefaultValidator(), ConfigurationPropertyOptions.None, null)
		{
		}

		public ConfigurationProperty(string name, Type type, object defaultValue, ConfigurationPropertyOptions options)
			: this(name, type, defaultValue, TypeDescriptor.GetConverter(type), new DefaultValidator(), options, null)
		{
		}

		public ConfigurationProperty(string name, Type type, object defaultValue, TypeConverter typeConverter, ConfigurationValidatorBase validator, ConfigurationPropertyOptions options)
			: this(name, type, defaultValue, typeConverter, validator, options, null)
		{
		}

		public ConfigurationProperty(string name, Type type, object defaultValue, TypeConverter typeConverter, ConfigurationValidatorBase validator, ConfigurationPropertyOptions options, string description)
		{
			this.name = name;
			converter = ((typeConverter != null) ? typeConverter : TypeDescriptor.GetConverter(type));
			if (defaultValue != null)
			{
				if (defaultValue == NoDefaultValue)
				{
					defaultValue = Type.GetTypeCode(type) switch
					{
						TypeCode.Object => null, 
						TypeCode.String => string.Empty, 
						_ => Activator.CreateInstance(type), 
					};
				}
				else if (!type.IsAssignableFrom(defaultValue.GetType()))
				{
					if (!converter.CanConvertFrom(defaultValue.GetType()))
					{
						throw new ConfigurationErrorsException($"The default value for property '{name}' has a different type than the one of the property itself: expected {type} but was {defaultValue.GetType()}");
					}
					defaultValue = converter.ConvertFrom(defaultValue);
				}
			}
			default_value = defaultValue;
			flags = options;
			this.type = type;
			validation = ((validator != null) ? validator : new DefaultValidator());
			this.description = description;
		}

		internal object ConvertFromString(string value)
		{
			if (converter != null)
			{
				return converter.ConvertFromInvariantString(value);
			}
			throw new NotImplementedException();
		}

		internal string ConvertToString(object value)
		{
			if (converter != null)
			{
				return converter.ConvertToInvariantString(value);
			}
			throw new NotImplementedException();
		}

		internal void Validate(object value)
		{
			if (validation != null)
			{
				validation.Validate(value);
			}
		}
	}
	[AttributeUsage(AttributeTargets.Property)]
	public sealed class ConfigurationPropertyAttribute : Attribute
	{
		private string name;

		private object default_value = ConfigurationProperty.NoDefaultValue;

		private ConfigurationPropertyOptions flags;

		public bool IsKey
		{
			get
			{
				return (flags & ConfigurationPropertyOptions.IsKey) != 0;
			}
			set
			{
				if (value)
				{
					flags |= ConfigurationPropertyOptions.IsKey;
				}
				else
				{
					flags &= ~ConfigurationPropertyOptions.IsKey;
				}
			}
		}

		public bool IsDefaultCollection
		{
			get
			{
				return (flags & ConfigurationPropertyOptions.IsDefaultCollection) != 0;
			}
			set
			{
				if (value)
				{
					flags |= ConfigurationPropertyOptions.IsDefaultCollection;
				}
				else
				{
					flags &= ~ConfigurationPropertyOptions.IsDefaultCollection;
				}
			}
		}

		public object DefaultValue
		{
			get
			{
				return default_value;
			}
			set
			{
				default_value = value;
			}
		}

		public ConfigurationPropertyOptions Options
		{
			get
			{
				return flags;
			}
			set
			{
				flags = value;
			}
		}

		public string Name => name;

		public bool IsRequired
		{
			get
			{
				return (flags & ConfigurationPropertyOpti

BepInExPack/mono/Managed/System.Core.dll

Decompiled a month ago
using System;
using System.Buffers;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Diagnostics.Tracing;
using System.Dynamic;
using System.Dynamic.Utils;
using System.Globalization;
using System.IO;
using System.IO.MemoryMappedFiles;
using System.Linq;
using System.Linq.Expressions;
using System.Linq.Expressions.Compiler;
using System.Linq.Parallel;
using System.Reflection;
using System.Reflection.Emit;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.ExceptionServices;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Security;
using System.Security.AccessControl;
using System.Security.Cryptography;
using System.Security.Permissions;
using System.Security.Principal;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Win32.SafeHandles;
using Mono.Security.Cryptography;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("System.Core.dll")]
[assembly: AssemblyDescription("System.Core.dll")]
[assembly: AssemblyDefaultAlias("System.Core.dll")]
[assembly: AssemblyCompany("Mono development team")]
[assembly: AssemblyProduct("Mono Common Language Infrastructure")]
[assembly: AssemblyCopyright("(c) Various Mono authors")]
[assembly: SatelliteContractVersion("4.0.0.0")]
[assembly: AssemblyInformationalVersion("4.6.57.0")]
[assembly: AssemblyFileVersion("4.6.57.0")]
[assembly: NeutralResourcesLanguage("en-US")]
[assembly: CLSCompliant(true)]
[assembly: AssemblyDelaySign(true)]
[assembly: AssemblyKeyFile("../ecma.pub")]
[assembly: AllowPartiallyTrustedCallers]
[assembly: DefaultDependency(LoadHint.Always)]
[assembly: SecurityCritical]
[assembly: StringFreezing]
[assembly: ComVisible(false)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("4.0.0.0")]
[assembly: TypeForwardedTo(typeof(Action))]
[assembly: TypeForwardedTo(typeof(Action<, >))]
[assembly: TypeForwardedTo(typeof(Action<, , >))]
[assembly: TypeForwardedTo(typeof(Action<, , , >))]
[assembly: TypeForwardedTo(typeof(Func<>))]
[assembly: TypeForwardedTo(typeof(Func<, >))]
[assembly: TypeForwardedTo(typeof(Func<, , >))]
[assembly: TypeForwardedTo(typeof(Func<, , , >))]
[assembly: TypeForwardedTo(typeof(Func<, , , , >))]
[assembly: TypeForwardedTo(typeof(InvalidTimeZoneException))]
[assembly: TypeForwardedTo(typeof(Lazy<>))]
[assembly: TypeForwardedTo(typeof(ExtensionAttribute))]
[assembly: TypeForwardedTo(typeof(Aes))]
[assembly: TypeForwardedTo(typeof(LazyThreadSafetyMode))]
[assembly: TypeForwardedTo(typeof(LockRecursionException))]
[assembly: TypeForwardedTo(typeof(TimeZoneInfo))]
[assembly: TypeForwardedTo(typeof(TimeZoneNotFoundException))]
[module: UnverifiableCode]
internal static class Interop
{
	internal enum BOOL
	{
		FALSE,
		TRUE
	}

	internal class Errors
	{
		internal const int ERROR_SUCCESS = 0;

		internal const int ERROR_INVALID_FUNCTION = 1;

		internal const int ERROR_FILE_NOT_FOUND = 2;

		internal const int ERROR_PATH_NOT_FOUND = 3;

		internal const int ERROR_ACCESS_DENIED = 5;

		internal const int ERROR_INVALID_HANDLE = 6;

		internal const int ERROR_NOT_ENOUGH_MEMORY = 8;

		internal const int ERROR_INVALID_DATA = 13;

		internal const int ERROR_INVALID_DRIVE = 15;

		internal const int ERROR_NO_MORE_FILES = 18;

		internal const int ERROR_NOT_READY = 21;

		internal const int ERROR_BAD_COMMAND = 22;

		internal const int ERROR_BAD_LENGTH = 24;

		internal const int ERROR_SHARING_VIOLATION = 32;

		internal const int ERROR_LOCK_VIOLATION = 33;

		internal const int ERROR_HANDLE_EOF = 38;

		internal const int ERROR_BAD_NETPATH = 53;

		internal const int ERROR_BAD_NET_NAME = 67;

		internal const int ERROR_FILE_EXISTS = 80;

		internal const int ERROR_INVALID_PARAMETER = 87;

		internal const int ERROR_BROKEN_PIPE = 109;

		internal const int ERROR_SEM_TIMEOUT = 121;

		internal const int ERROR_CALL_NOT_IMPLEMENTED = 120;

		internal const int ERROR_INSUFFICIENT_BUFFER = 122;

		internal const int ERROR_INVALID_NAME = 123;

		internal const int ERROR_NEGATIVE_SEEK = 131;

		internal const int ERROR_DIR_NOT_EMPTY = 145;

		internal const int ERROR_BAD_PATHNAME = 161;

		internal const int ERROR_LOCK_FAILED = 167;

		internal const int ERROR_BUSY = 170;

		internal const int ERROR_ALREADY_EXISTS = 183;

		internal const int ERROR_BAD_EXE_FORMAT = 193;

		internal const int ERROR_ENVVAR_NOT_FOUND = 203;

		internal const int ERROR_FILENAME_EXCED_RANGE = 206;

		internal const int ERROR_EXE_MACHINE_TYPE_MISMATCH = 216;

		internal const int ERROR_PIPE_BUSY = 231;

		internal const int ERROR_NO_DATA = 232;

		internal const int ERROR_PIPE_NOT_CONNECTED = 233;

		internal const int ERROR_MORE_DATA = 234;

		internal const int ERROR_NO_MORE_ITEMS = 259;

		internal const int ERROR_DIRECTORY = 267;

		internal const int ERROR_PARTIAL_COPY = 299;

		internal const int ERROR_ARITHMETIC_OVERFLOW = 534;

		internal const int ERROR_PIPE_CONNECTED = 535;

		internal const int ERROR_PIPE_LISTENING = 536;

		internal const int ERROR_OPERATION_ABORTED = 995;

		internal const int ERROR_IO_INCOMPLETE = 996;

		internal const int ERROR_IO_PENDING = 997;

		internal const int ERROR_NO_TOKEN = 1008;

		internal const int ERROR_DLL_INIT_FAILED = 1114;

		internal const int ERROR_COUNTER_TIMEOUT = 1121;

		internal const int ERROR_NO_ASSOCIATION = 1155;

		internal const int ERROR_DDE_FAIL = 1156;

		internal const int ERROR_DLL_NOT_FOUND = 1157;

		internal const int ERROR_NOT_FOUND = 1168;

		internal const int ERROR_NETWORK_UNREACHABLE = 1231;

		internal const int ERROR_NON_ACCOUNT_SID = 1257;

		internal const int ERROR_NOT_ALL_ASSIGNED = 1300;

		internal const int ERROR_UNKNOWN_REVISION = 1305;

		internal const int ERROR_INVALID_OWNER = 1307;

		internal const int ERROR_INVALID_PRIMARY_GROUP = 1308;

		internal const int ERROR_NO_SUCH_PRIVILEGE = 1313;

		internal const int ERROR_PRIVILEGE_NOT_HELD = 1314;

		internal const int ERROR_INVALID_ACL = 1336;

		internal const int ERROR_INVALID_SECURITY_DESCR = 1338;

		internal const int ERROR_INVALID_SID = 1337;

		internal const int ERROR_BAD_IMPERSONATION_LEVEL = 1346;

		internal const int ERROR_CANT_OPEN_ANONYMOUS = 1347;

		internal const int ERROR_NO_SECURITY_ON_OBJECT = 1350;

		internal const int ERROR_CLASS_ALREADY_EXISTS = 1410;

		internal const int ERROR_TRUSTED_RELATIONSHIP_FAILURE = 1789;

		internal const int ERROR_RESOURCE_LANG_NOT_FOUND = 1815;

		internal const int EFail = -2147467259;

		internal const int E_FILENOTFOUND = -2147024894;
	}

	internal static class Libraries
	{
		internal const string Advapi32 = "advapi32.dll";

		internal const string BCrypt = "BCrypt.dll";

		internal const string CoreComm_L1_1_1 = "api-ms-win-core-comm-l1-1-1.dll";

		internal const string Crypt32 = "crypt32.dll";

		internal const string Error_L1 = "api-ms-win-core-winrt-error-l1-1-0.dll";

		internal const string HttpApi = "httpapi.dll";

		internal const string IpHlpApi = "iphlpapi.dll";

		internal const string Kernel32 = "kernel32.dll";

		internal const string Memory_L1_3 = "api-ms-win-core-memory-l1-1-3.dll";

		internal const string Mswsock = "mswsock.dll";

		internal const string NCrypt = "ncrypt.dll";

		internal const string NtDll = "ntdll.dll";

		internal const string Odbc32 = "odbc32.dll";

		internal const string OleAut32 = "oleaut32.dll";

		internal const string PerfCounter = "perfcounter.dll";

		internal const string RoBuffer = "api-ms-win-core-winrt-robuffer-l1-1-0.dll";

		internal const string Secur32 = "secur32.dll";

		internal const string Shell32 = "shell32.dll";

		internal const string SspiCli = "sspicli.dll";

		internal const string User32 = "user32.dll";

		internal const string Version = "version.dll";

		internal const string WebSocket = "websocket.dll";

		internal const string WinHttp = "winhttp.dll";

		internal const string Ws2_32 = "ws2_32.dll";

		internal const string Wtsapi32 = "wtsapi32.dll";

		internal const string CompressionNative = "clrcompression.dll";
	}

	internal static class Advapi32
	{
		[DllImport("advapi32.dll", SetLastError = true)]
		[return: MarshalAs(UnmanagedType.Bool)]
		internal static extern bool ImpersonateNamedPipeClient(SafePipeHandle hNamedPipe);

		[DllImport("advapi32.dll", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
		internal static extern bool RevertToSelf();
	}

	internal class Kernel32
	{
		internal class IOReparseOptions
		{
			internal const uint IO_REPARSE_TAG_FILE_PLACEHOLDER = 2147483669u;

			internal const uint IO_REPARSE_TAG_MOUNT_POINT = 2684354563u;
		}

		internal class FileOperations
		{
			internal const int OPEN_EXISTING = 3;

			internal const int COPY_FILE_FAIL_IF_EXISTS = 1;

			internal const int FILE_ACTION_ADDED = 1;

			internal const int FILE_ACTION_REMOVED = 2;

			internal const int FILE_ACTION_MODIFIED = 3;

			internal const int FILE_ACTION_RENAMED_OLD_NAME = 4;

			internal const int FILE_ACTION_RENAMED_NEW_NAME = 5;

			internal const int FILE_FLAG_BACKUP_SEMANTICS = 33554432;

			internal const int FILE_FLAG_FIRST_PIPE_INSTANCE = 524288;

			internal const int FILE_FLAG_OVERLAPPED = 1073741824;

			internal const int FILE_LIST_DIRECTORY = 1;
		}

		internal class FileTypes
		{
			internal const int FILE_TYPE_UNKNOWN = 0;

			internal const int FILE_TYPE_DISK = 1;

			internal const int FILE_TYPE_CHAR = 2;

			internal const int FILE_TYPE_PIPE = 3;
		}

		internal class GenericOperations
		{
			internal const int GENERIC_READ = int.MinValue;

			internal const int GENERIC_WRITE = 1073741824;
		}

		internal class HandleOptions
		{
			internal const int DUPLICATE_SAME_ACCESS = 2;

			internal const int STILL_ACTIVE = 259;

			internal const int TOKEN_ADJUST_PRIVILEGES = 32;
		}

		internal class PipeOptions
		{
			internal const int PIPE_ACCESS_INBOUND = 1;

			internal const int PIPE_ACCESS_OUTBOUND = 2;

			internal const int PIPE_ACCESS_DUPLEX = 3;

			internal const int PIPE_TYPE_BYTE = 0;

			internal const int PIPE_TYPE_MESSAGE = 4;

			internal const int PIPE_READMODE_BYTE = 0;

			internal const int PIPE_READMODE_MESSAGE = 2;

			internal const int PIPE_UNLIMITED_INSTANCES = 255;
		}

		internal struct SECURITY_ATTRIBUTES
		{
			internal uint nLength;

			internal IntPtr lpSecurityDescriptor;

			internal BOOL bInheritHandle;
		}

		internal class SecurityOptions
		{
			internal const int SECURITY_SQOS_PRESENT = 1048576;

			internal const int SECURITY_ANONYMOUS = 0;

			internal const int SECURITY_IDENTIFICATION = 65536;

			internal const int SECURITY_IMPERSONATION = 131072;

			internal const int SECURITY_DELEGATION = 196608;
		}

		internal const uint SEM_FAILCRITICALERRORS = 1u;

		private const int FORMAT_MESSAGE_IGNORE_INSERTS = 512;

		private const int FORMAT_MESSAGE_FROM_HMODULE = 2048;

		private const int FORMAT_MESSAGE_FROM_SYSTEM = 4096;

		private const int FORMAT_MESSAGE_ARGUMENT_ARRAY = 8192;

		private const int ERROR_INSUFFICIENT_BUFFER = 122;

		private const int InitialBufferSize = 256;

		private const int BufferSizeIncreaseFactor = 4;

		private const int MaxAllowedBufferSize = 66560;

		internal const int MAX_PATH = 260;

		internal const int CREDUI_MAX_USERNAME_LENGTH = 513;

		[DllImport("kernel32.dll", SetLastError = true)]
		internal unsafe static extern bool CancelIoEx(SafeHandle handle, NativeOverlapped* lpOverlapped);

		[DllImport("kernel32.dll", SetLastError = true)]
		[return: MarshalAs(UnmanagedType.Bool)]
		internal static extern bool CloseHandle(IntPtr handle);

		[DllImport("kernel32.dll", SetLastError = true)]
		[return: MarshalAs(UnmanagedType.Bool)]
		internal unsafe static extern bool ConnectNamedPipe(SafePipeHandle handle, NativeOverlapped* overlapped);

		[DllImport("kernel32.dll", SetLastError = true)]
		[return: MarshalAs(UnmanagedType.Bool)]
		internal static extern bool ConnectNamedPipe(SafePipeHandle handle, IntPtr overlapped);

		[DllImport("kernel32.dll", BestFitMapping = false, CharSet = CharSet.Unicode, EntryPoint = "CreateNamedPipeW", SetLastError = true)]
		internal static extern SafePipeHandle CreateNamedPipe(string pipeName, int openMode, int pipeMode, int maxInstances, int outBufferSize, int inBufferSize, int defaultTimeout, ref SECURITY_ATTRIBUTES securityAttributes);

		[DllImport("kernel32.dll", BestFitMapping = false, CharSet = CharSet.Unicode, EntryPoint = "CreateFileW", SetLastError = true)]
		internal static extern SafePipeHandle CreateNamedPipeClient(string lpFileName, int dwDesiredAccess, FileShare dwShareMode, ref SECURITY_ATTRIBUTES secAttrs, FileMode dwCreationDisposition, int dwFlagsAndAttributes, IntPtr hTemplateFile);

		[DllImport("kernel32.dll", SetLastError = true)]
		internal static extern bool CreatePipe(out SafePipeHandle hReadPipe, out SafePipeHandle hWritePipe, ref SECURITY_ATTRIBUTES lpPipeAttributes, int nSize);

		[DllImport("kernel32.dll", SetLastError = true)]
		[return: MarshalAs(UnmanagedType.Bool)]
		internal static extern bool DisconnectNamedPipe(SafePipeHandle hNamedPipe);

		[DllImport("kernel32.dll", SetLastError = true)]
		[return: MarshalAs(UnmanagedType.Bool)]
		internal static extern bool DuplicateHandle(IntPtr hSourceProcessHandle, SafePipeHandle hSourceHandle, IntPtr hTargetProcessHandle, out SafePipeHandle lpTargetHandle, uint dwDesiredAccess, [MarshalAs(UnmanagedType.Bool)] bool bInheritHandle, uint dwOptions);

		[DllImport("kernel32.dll", SetLastError = true)]
		[return: MarshalAs(UnmanagedType.Bool)]
		internal static extern bool FlushFileBuffers(SafeHandle hHandle);

		[DllImport("kernel32.dll", BestFitMapping = true, CharSet = CharSet.Unicode, EntryPoint = "FormatMessageW", SetLastError = true)]
		private unsafe static extern int FormatMessage(int dwFlags, IntPtr lpSource, uint dwMessageId, int dwLanguageId, char* lpBuffer, int nSize, IntPtr[] arguments);

		internal static string GetMessage(int errorCode)
		{
			return GetMessage(IntPtr.Zero, errorCode);
		}

		internal unsafe static string GetMessage(IntPtr moduleHandle, int errorCode)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			Span<char> buffer = new Span<char>((void*)stackalloc byte[512], 256);
			do
			{
				if (TryGetErrorMessage(moduleHandle, errorCode, buffer, out var errorMsg))
				{
					return errorMsg;
				}
				buffer = Span<char>.op_Implicit(new char[buffer.Length * 4]);
			}
			while (buffer.Length < 66560);
			return $"Unknown error (0x{errorCode:x})";
		}

		private unsafe static bool TryGetErrorMessage(IntPtr moduleHandle, int errorCode, Span<char> buffer, out string errorMsg)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			int num = 12800;
			if (moduleHandle != IntPtr.Zero)
			{
				num |= 0x800;
			}
			int num2;
			fixed (char* lpBuffer = &MemoryMarshal.GetReference<char>(buffer))
			{
				num2 = FormatMessage(num, moduleHandle, (uint)errorCode, 0, lpBuffer, buffer.Length, null);
			}
			if (num2 != 0)
			{
				int num3;
				for (num3 = num2; num3 > 0; num3--)
				{
					char c = buffer[num3 - 1];
					if (c > ' ' && c != '.')
					{
						break;
					}
				}
				errorMsg = ((object)buffer.Slice(0, num3)).ToString();
			}
			else
			{
				if (Marshal.GetLastWin32Error() == 122)
				{
					errorMsg = "";
					return false;
				}
				errorMsg = $"Unknown error (0x{errorCode:x})";
			}
			return true;
		}

		[DllImport("kernel32.dll", SetLastError = true)]
		internal static extern IntPtr GetCurrentProcess();

		[DllImport("kernel32.dll", SetLastError = true)]
		internal static extern int GetFileType(SafeHandle hFile);

		[DllImport("kernel32.dll", BestFitMapping = false, CharSet = CharSet.Unicode, EntryPoint = "GetNamedPipeHandleStateW", SetLastError = true)]
		[return: MarshalAs(UnmanagedType.Bool)]
		internal static extern bool GetNamedPipeHandleState(SafePipeHandle hNamedPipe, out int lpState, IntPtr lpCurInstances, IntPtr lpMaxCollectionCount, IntPtr lpCollectDataTimeout, IntPtr lpUserName, int nMaxUserNameSize);

		[DllImport("kernel32.dll", BestFitMapping = false, CharSet = CharSet.Unicode, EntryPoint = "GetNamedPipeHandleStateW", SetLastError = true)]
		[return: MarshalAs(UnmanagedType.Bool)]
		internal static extern bool GetNamedPipeHandleState(SafePipeHandle hNamedPipe, IntPtr lpState, IntPtr lpCurInstances, IntPtr lpMaxCollectionCount, IntPtr lpCollectDataTimeout, [Out] StringBuilder lpUserName, int nMaxUserNameSize);

		[DllImport("kernel32.dll", EntryPoint = "GetNamedPipeHandleStateW", SetLastError = true)]
		[return: MarshalAs(UnmanagedType.Bool)]
		internal static extern bool GetNamedPipeHandleState(SafePipeHandle hNamedPipe, IntPtr lpState, out int lpCurInstances, IntPtr lpMaxCollectionCount, IntPtr lpCollectDataTimeout, IntPtr lpUserName, int nMaxUserNameSize);

		[DllImport("kernel32.dll", SetLastError = true)]
		[return: MarshalAs(UnmanagedType.Bool)]
		internal static extern bool GetNamedPipeInfo(SafePipeHandle hNamedPipe, out int lpFlags, IntPtr lpOutBufferSize, IntPtr lpInBufferSize, IntPtr lpMaxInstances);

		[DllImport("kernel32.dll", SetLastError = true)]
		[return: MarshalAs(UnmanagedType.Bool)]
		internal static extern bool GetNamedPipeInfo(SafePipeHandle hNamedPipe, IntPtr lpFlags, out int lpOutBufferSize, IntPtr lpInBufferSize, IntPtr lpMaxInstances);

		[DllImport("kernel32.dll", SetLastError = true)]
		[return: MarshalAs(UnmanagedType.Bool)]
		internal static extern bool GetNamedPipeInfo(SafePipeHandle hNamedPipe, IntPtr lpFlags, IntPtr lpOutBufferSize, out int lpInBufferSize, IntPtr lpMaxInstances);

		[DllImport("kernel32.dll", SetLastError = true)]
		internal unsafe static extern int ReadFile(SafeHandle handle, byte* bytes, int numBytesToRead, out int numBytesRead, IntPtr mustBeZero);

		[DllImport("kernel32.dll", SetLastError = true)]
		internal unsafe static extern int ReadFile(SafeHandle handle, byte* bytes, int numBytesToRead, IntPtr numBytesRead_mustBeZero, NativeOverlapped* overlapped);

		[DllImport("kernel32.dll", SetLastError = true)]
		[return: MarshalAs(UnmanagedType.Bool)]
		internal unsafe static extern bool SetNamedPipeHandleState(SafePipeHandle hNamedPipe, int* lpMode, IntPtr lpMaxCollectionCount, IntPtr lpCollectDataTimeout);

		[DllImport("kernel32.dll", BestFitMapping = false, CharSet = CharSet.Unicode, EntryPoint = "WaitNamedPipeW", SetLastError = true)]
		[return: MarshalAs(UnmanagedType.Bool)]
		internal static extern bool WaitNamedPipe(string name, int timeout);

		[DllImport("kernel32.dll", SetLastError = true)]
		internal unsafe static extern int WriteFile(SafeHandle handle, byte* bytes, int numBytesToWrite, out int numBytesWritten, IntPtr mustBeZero);

		[DllImport("kernel32.dll", SetLastError = true)]
		internal unsafe static extern int WriteFile(SafeHandle handle, byte* bytes, int numBytesToWrite, IntPtr numBytesWritten_mustBeZero, NativeOverlapped* lpOverlapped);
	}
}
internal static class Consts
{
	public const string MonoCorlibVersion = "1A5E0066-58DC-428A-B21C-0AD6CDAE2789";

	public const string MonoVersion = "6.13.0.0";

	public const string MonoCompany = "Mono development team";

	public const string MonoProduct = "Mono Common Language Infrastructure";

	public const string MonoCopyright = "(c) Various Mono authors";

	public const string FxVersion = "4.0.0.0";

	public const string FxFileVersion = "4.6.57.0";

	public const string EnvironmentVersion = "4.0.30319.42000";

	public const string VsVersion = "0.0.0.0";

	public const string VsFileVersion = "11.0.0.0";

	private const string PublicKeyToken = "b77a5c561934e089";

	public const string AssemblyI18N = "I18N, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756";

	public const string AssemblyMicrosoft_JScript = "Microsoft.JScript, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblyMicrosoft_VisualStudio = "Microsoft.VisualStudio, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblyMicrosoft_VisualStudio_Web = "Microsoft.VisualStudio.Web, Version=0.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblyMicrosoft_VSDesigner = "Microsoft.VSDesigner, Version=0.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblyMono_Http = "Mono.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756";

	public const string AssemblyMono_Posix = "Mono.Posix, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756";

	public const string AssemblyMono_Security = "Mono.Security, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756";

	public const string AssemblyMono_Messaging_RabbitMQ = "Mono.Messaging.RabbitMQ, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756";

	public const string AssemblyCorlib = "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string AssemblySystem = "System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string AssemblySystem_Data = "System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string AssemblySystem_Design = "System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_DirectoryServices = "System.DirectoryServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_Drawing = "System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_Drawing_Design = "System.Drawing.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_Messaging = "System.Messaging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_Security = "System.Security, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_ServiceProcess = "System.ServiceProcess, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_Web = "System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_Windows_Forms = "System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string AssemblySystem_2_0 = "System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string AssemblySystemCore_3_5 = "System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string AssemblySystem_Core = "System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string WindowsBase_3_0 = "WindowsBase, Version=3.0.0.0, PublicKeyToken=31bf3856ad364e35";

	public const string AssemblyWindowsBase = "WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";

	public const string AssemblyPresentationCore_3_5 = "PresentationCore, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";

	public const string AssemblyPresentationCore_4_0 = "PresentationCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";

	public const string AssemblyPresentationFramework_3_5 = "PresentationFramework, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";

	public const string AssemblySystemServiceModel_3_0 = "System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";
}
internal static class SR
{
	public const string ReducibleMustOverrideReduce = "reducible nodes must override Expression.Reduce()";

	public const string MustReduceToDifferent = "node cannot reduce to itself or null";

	public const string ReducedNotCompatible = "cannot assign from the reduced node type to the original node type";

	public const string SetterHasNoParams = "Setter must have parameters.";

	public const string PropertyCannotHaveRefType = "Property cannot have a managed pointer type.";

	public const string IndexesOfSetGetMustMatch = "Indexing parameters of getter and setter must match.";

	public const string AccessorsCannotHaveVarArgs = "Accessor method should not have VarArgs.";

	public const string AccessorsCannotHaveByRefArgs = "Accessor indexes cannot be passed ByRef.";

	public const string BoundsCannotBeLessThanOne = "Bounds count cannot be less than 1";

	public const string TypeMustNotBeByRef = "Type must not be ByRef";

	public const string TypeMustNotBePointer = "Type must not be a pointer type";

	public const string SetterMustBeVoid = "Setter should have void type.";

	public const string PropertyTypeMustMatchGetter = "Property type must match the value type of getter";

	public const string PropertyTypeMustMatchSetter = "Property type must match the value type of setter";

	public const string BothAccessorsMustBeStatic = "Both accessors must be static.";

	public const string OnlyStaticFieldsHaveNullInstance = "Static field requires null instance, non-static field requires non-null instance.";

	public const string OnlyStaticPropertiesHaveNullInstance = "Static property requires null instance, non-static property requires non-null instance.";

	public const string OnlyStaticMethodsHaveNullInstance = "Static method requires null instance, non-static method requires non-null instance.";

	public const string PropertyTypeCannotBeVoid = "Property cannot have a void type.";

	public const string InvalidUnboxType = "Can only unbox from an object or interface type to a value type.";

	public const string ExpressionMustBeWriteable = "Expression must be writeable";

	public const string ArgumentMustNotHaveValueType = "Argument must not have a value type.";

	public const string MustBeReducible = "must be reducible node";

	public const string AllTestValuesMustHaveSameType = "All test values must have the same type.";

	public const string AllCaseBodiesMustHaveSameType = "All case bodies and the default body must have the same type.";

	public const string DefaultBodyMustBeSupplied = "Default body must be supplied if case bodies are not System.Void.";

	public const string LabelMustBeVoidOrHaveExpression = "Label type must be System.Void if an expression is not supplied";

	public const string LabelTypeMustBeVoid = "Type must be System.Void for this label argument";

	public const string QuotedExpressionMustBeLambda = "Quoted expression must be a lambda";

	public const string VariableMustNotBeByRef = "Variable '{0}' uses unsupported type '{1}'. Reference types are not supported for variables.";

	public const string DuplicateVariable = "Found duplicate parameter '{0}'. Each ParameterExpression in the list must be a unique object.";

	public const string StartEndMustBeOrdered = "Start and End must be well ordered";

	public const string FaultCannotHaveCatchOrFinally = "fault cannot be used with catch or finally clauses";

	public const string TryMustHaveCatchFinallyOrFault = "try must have at least one catch, finally, or fault clause";

	public const string BodyOfCatchMustHaveSameTypeAsBodyOfTry = "Body of catch must have the same type as body of try.";

	public const string ExtensionNodeMustOverrideProperty = "Extension node must override the property {0}.";

	public const string UserDefinedOperatorMustBeStatic = "User-defined operator method '{0}' must be static.";

	public const string UserDefinedOperatorMustNotBeVoid = "User-defined operator method '{0}' must not be void.";

	public const string CoercionOperatorNotDefined = "No coercion operator is defined between types '{0}' and '{1}'.";

	public const string UnaryOperatorNotDefined = "The unary operator {0} is not defined for the type '{1}'.";

	public const string BinaryOperatorNotDefined = "The binary operator {0} is not defined for the types '{1}' and '{2}'.";

	public const string ReferenceEqualityNotDefined = "Reference equality is not defined for the types '{0}' and '{1}'.";

	public const string OperandTypesDoNotMatchParameters = "The operands for operator '{0}' do not match the parameters of method '{1}'.";

	public const string OverloadOperatorTypeDoesNotMatchConversionType = "The return type of overload method for operator '{0}' does not match the parameter type of conversion method '{1}'.";

	public const string ConversionIsNotSupportedForArithmeticTypes = "Conversion is not supported for arithmetic types without operator overloading.";

	public const string ArgumentMustBeArray = "Argument must be array";

	public const string ArgumentMustBeBoolean = "Argument must be boolean";

	public const string EqualityMustReturnBoolean = "The user-defined equality method '{0}' must return a boolean value.";

	public const string ArgumentMustBeFieldInfoOrPropertyInfo = "Argument must be either a FieldInfo or PropertyInfo";

	public const string ArgumentMustBeFieldInfoOrPropertyInfoOrMethod = "Argument must be either a FieldInfo, PropertyInfo or MethodInfo";

	public const string ArgumentMustBeInstanceMember = "Argument must be an instance member";

	public const string ArgumentMustBeInteger = "Argument must be of an integer type";

	public const string ArgumentMustBeArrayIndexType = "Argument for array index must be of type Int32";

	public const string ArgumentMustBeSingleDimensionalArrayType = "Argument must be single-dimensional, zero-based array type";

	public const string ArgumentTypesMustMatch = "Argument types do not match";

	public const string CannotAutoInitializeValueTypeElementThroughProperty = "Cannot auto initialize elements of value type through property '{0}', use assignment instead";

	public const string CannotAutoInitializeValueTypeMemberThroughProperty = "Cannot auto initialize members of value type through property '{0}', use assignment instead";

	public const string IncorrectTypeForTypeAs = "The type used in TypeAs Expression must be of reference or nullable type, {0} is neither";

	public const string CoalesceUsedOnNonNullType = "Coalesce used with type that cannot be null";

	public const string ExpressionTypeCannotInitializeArrayType = "An expression of type '{0}' cannot be used to initialize an array of type '{1}'";

	public const string ArgumentTypeDoesNotMatchMember = " Argument type '{0}' does not match the corresponding member type '{1}'";

	public const string ArgumentMemberNotDeclOnType = " The member '{0}' is not declared on type '{1}' being created";

	public const string ExpressionTypeDoesNotMatchReturn = "Expression of type '{0}' cannot be used for return type '{1}'";

	public const string ExpressionTypeDoesNotMatchAssignment = "Expression of type '{0}' cannot be used for assignment to type '{1}'";

	public const string ExpressionTypeDoesNotMatchLabel = "Expression of type '{0}' cannot be used for label of type '{1}'";

	public const string ExpressionTypeNotInvocable = "Expression of type '{0}' cannot be invoked";

	public const string FieldNotDefinedForType = "Field '{0}' is not defined for type '{1}'";

	public const string InstanceFieldNotDefinedForType = "Instance field '{0}' is not defined for type '{1}'";

	public const string FieldInfoNotDefinedForType = "Field '{0}.{1}' is not defined for type '{2}'";

	public const string IncorrectNumberOfIndexes = "Incorrect number of indexes";

	public const string IncorrectNumberOfLambdaDeclarationParameters = "Incorrect number of parameters supplied for lambda declaration";

	public const string IncorrectNumberOfMembersForGivenConstructor = " Incorrect number of members for constructor";

	public const string IncorrectNumberOfArgumentsForMembers = "Incorrect number of arguments for the given members ";

	public const string LambdaTypeMustBeDerivedFromSystemDelegate = "Lambda type parameter must be derived from System.MulticastDelegate";

	public const string MemberNotFieldOrProperty = "Member '{0}' not field or property";

	public const string MethodContainsGenericParameters = "Method {0} contains generic parameters";

	public const string MethodIsGeneric = "Method {0} is a generic method definition";

	public const string MethodNotPropertyAccessor = "The method '{0}.{1}' is not a property accessor";

	public const string PropertyDoesNotHaveGetter = "The property '{0}' has no 'get' accessor";

	public const string PropertyDoesNotHaveSetter = "The property '{0}' has no 'set' accessor";

	public const string PropertyDoesNotHaveAccessor = "The property '{0}' has no 'get' or 'set' accessors";

	public const string NotAMemberOfType = "'{0}' is not a member of type '{1}'";

	public const string NotAMemberOfAnyType = "'{0}' is not a member of any type";

	public const string UnsupportedExpressionType = "The expression type '{0}' is not supported";

	public const string ParameterExpressionNotValidAsDelegate = "ParameterExpression of type '{0}' cannot be used for delegate parameter of type '{1}'";

	public const string PropertyNotDefinedForType = "Property '{0}' is not defined for type '{1}'";

	public const string InstancePropertyNotDefinedForType = "Instance property '{0}' is not defined for type '{1}'";

	public const string InstancePropertyWithoutParameterNotDefinedForType = "Instance property '{0}' that takes no argument is not defined for type '{1}'";

	public const string InstancePropertyWithSpecifiedParametersNotDefinedForType = "Instance property '{0}{1}' is not defined for type '{2}'";

	public const string InstanceAndMethodTypeMismatch = "Method '{0}' declared on type '{1}' cannot be called with instance of type '{2}'";

	public const string TypeContainsGenericParameters = "Type {0} contains generic parameters";

	public const string TypeIsGeneric = "Type {0} is a generic type definition";

	public const string TypeMissingDefaultConstructor = "Type '{0}' does not have a default constructor";

	public const string ElementInitializerMethodNotAdd = "Element initializer method must be named 'Add'";

	public const string ElementInitializerMethodNoRefOutParam = "Parameter '{0}' of element initializer method '{1}' must not be a pass by reference parameter";

	public const string ElementInitializerMethodWithZeroArgs = "Element initializer method must have at least 1 parameter";

	public const string ElementInitializerMethodStatic = "Element initializer method must be an instance method";

	public const string TypeNotIEnumerable = "Type '{0}' is not IEnumerable";

	public const string UnhandledBinary = "Unhandled binary: {0}";

	public const string UnhandledBinding = "Unhandled binding ";

	public const string UnhandledBindingType = "Unhandled Binding Type: {0}";

	public const string UnhandledUnary = "Unhandled unary: {0}";

	public const string UnknownBindingType = "Unknown binding type";

	public const string UserDefinedOpMustHaveConsistentTypes = "The user-defined operator method '{1}' for operator '{0}' must have identical parameter and return types.";

	public const string UserDefinedOpMustHaveValidReturnType = "The user-defined operator method '{1}' for operator '{0}' must return the same type as its parameter or a derived type.";

	public const string LogicalOperatorMustHaveBooleanOperators = "The user-defined operator method '{1}' for operator '{0}' must have associated boolean True and False operators.";

	public const string MethodWithArgsDoesNotExistOnType = "No method '{0}' on type '{1}' is compatible with the supplied arguments.";

	public const string GenericMethodWithArgsDoesNotExistOnType = "No generic method '{0}' on type '{1}' is compatible with the supplied type arguments and arguments. No type arguments should be provided if the method is non-generic. ";

	public const string MethodWithMoreThanOneMatch = "More than one method '{0}' on type '{1}' is compatible with the supplied arguments.";

	public const string PropertyWithMoreThanOneMatch = "More than one property '{0}' on type '{1}' is compatible with the supplied arguments.";

	public const string IncorrectNumberOfTypeArgsForFunc = "An incorrect number of type arguments were specified for the declaration of a Func type.";

	public const string IncorrectNumberOfTypeArgsForAction = "An incorrect number of type arguments were specified for the declaration of an Action type.";

	public const string ArgumentCannotBeOfTypeVoid = "Argument type cannot be System.Void.";

	public const string OutOfRange = "{0} must be greater than or equal to {1}";

	public const string LabelTargetAlreadyDefined = "Cannot redefine label '{0}' in an inner block.";

	public const string LabelTargetUndefined = "Cannot jump to undefined label '{0}'.";

	public const string ControlCannotLeaveFinally = "Control cannot leave a finally block.";

	public const string ControlCannotLeaveFilterTest = "Control cannot leave a filter test.";

	public const string AmbiguousJump = "Cannot jump to ambiguous label '{0}'.";

	public const string ControlCannotEnterTry = "Control cannot enter a try block.";

	public const string ControlCannotEnterExpression = "Control cannot enter an expression--only statements can be jumped into.";

	public const string NonLocalJumpWithValue = "Cannot jump to non-local label '{0}' with a value. Only jumps to labels defined in outer blocks can pass values.";

	public const string CannotCompileConstant = "CompileToMethod cannot compile constant '{0}' because it is a non-trivial value, such as a live object. Instead, create an expression tree that can construct this value.";

	public const string CannotCompileDynamic = "Dynamic expressions are not supported by CompileToMethod. Instead, create an expression tree that uses System.Runtime.CompilerServices.CallSite.";

	public const string InvalidLvalue = "Invalid lvalue for assignment: {0}.";

	public const string UndefinedVariable = "variable '{0}' of type '{1}' referenced from scope '{2}', but it is not defined";

	public const string CannotCloseOverByRef = "Cannot close over byref parameter '{0}' referenced in lambda '{1}'";

	public const string UnexpectedVarArgsCall = "Unexpected VarArgs call to method '{0}'";

	public const string RethrowRequiresCatch = "Rethrow statement is valid only inside a Catch block.";

	public const string TryNotAllowedInFilter = "Try expression is not allowed inside a filter body.";

	public const string MustRewriteToSameNode = "When called from '{0}', rewriting a node of type '{1}' must return a non-null value of the same type. Alternatively, override '{2}' and change it to not visit children of this type.";

	public const string MustRewriteChildToSameType = "Rewriting child expression from type '{0}' to type '{1}' is not allowed, because it would change the meaning of the operation. If this is intentional, override '{2}' and change it to allow this rewrite.";

	public const string MustRewriteWithoutMethod = "Rewritten expression calls operator method '{0}', but the original node had no operator method. If this is intentional, override '{1}' and change it to allow this rewrite.";

	public const string InvalidNullValue = "The value null is not of type '{0}' and cannot be used in this collection.";

	public const string InvalidObjectType = "The value '{0}' is not of type '{1}' and cannot be used in this collection.";

	public const string TryNotSupportedForMethodsWithRefArgs = "TryExpression is not supported as an argument to method '{0}' because it has an argument with by-ref type. Construct the tree so the TryExpression is not nested inside of this expression.";

	public const string TryNotSupportedForValueTypeInstances = "TryExpression is not supported as a child expression when accessing a member on type '{0}' because it is a value type. Construct the tree so the TryExpression is not nested inside of this expression.";

	public const string EnumerationIsDone = "Enumeration has either not started or has already finished.";

	public const string TestValueTypeDoesNotMatchComparisonMethodParameter = "Test value of type '{0}' cannot be used for the comparison method parameter of type '{1}'";

	public const string SwitchValueTypeDoesNotMatchComparisonMethodParameter = "Switch value of type '{0}' cannot be used for the comparison method parameter of type '{1}'";

	public const string PdbGeneratorNeedsExpressionCompiler = "DebugInfoGenerator created by CreatePdbGenerator can only be used with LambdaExpression.CompileToMethod.";

	public const string InvalidArgumentValue = "Invalid argument value";

	public const string NonEmptyCollectionRequired = "Non-empty collection required";

	public const string CollectionModifiedWhileEnumerating = "Collection was modified; enumeration operation may not execute.";

	public const string ExpressionMustBeReadable = "Expression must be readable";

	public const string ExpressionTypeDoesNotMatchMethodParameter = "Expression of type '{0}' cannot be used for parameter of type '{1}' of method '{2}'";

	public const string ExpressionTypeDoesNotMatchParameter = "Expression of type '{0}' cannot be used for parameter of type '{1}'";

	public const string ExpressionTypeDoesNotMatchConstructorParameter = "Expression of type '{0}' cannot be used for constructor parameter of type '{1}'";

	public const string IncorrectNumberOfMethodCallArguments = "Incorrect number of arguments supplied for call to method '{0}'";

	public const string IncorrectNumberOfLambdaArguments = "Incorrect number of arguments supplied for lambda invocation";

	public const string IncorrectNumberOfConstructorArguments = "Incorrect number of arguments for constructor";

	public const string NonStaticConstructorRequired = "The constructor should not be static";

	public const string NonAbstractConstructorRequired = "Can't compile a NewExpression with a constructor declared on an abstract class";

	public const string FirstArgumentMustBeCallSite = "First argument of delegate must be CallSite";

	public const string NoOrInvalidRuleProduced = "No or Invalid rule produced";

	public const string TypeMustBeDerivedFromSystemDelegate = "Type must be derived from System.Delegate";

	public const string TypeParameterIsNotDelegate = "Type parameter is {0}. Expected a delegate.";

	public const string ArgumentTypeCannotBeVoid = "Argument type cannot be void";

	public const string ArgCntMustBeGreaterThanNameCnt = "Argument count must be greater than number of named arguments.";

	public const string BinderNotCompatibleWithCallSite = "The result type '{0}' of the binder '{1}' is not compatible with the result type '{2}' expected by the call site.";

	public const string BindingCannotBeNull = "Bind cannot return null.";

	public const string DynamicBinderResultNotAssignable = "The result type '{0}' of the dynamic binding produced by binder '{1}' is not compatible with the result type '{2}' expected by the call site.";

	public const string DynamicBindingNeedsRestrictions = "The result of the dynamic binding produced by the object with type '{0}' for the binder '{1}' needs at least one restriction.";

	public const string DynamicObjectResultNotAssignable = "The result type '{0}' of the dynamic binding produced by the object with type '{1}' for the binder '{2}' is not compatible with the result type '{3}' expected by the call site.";

	public const string InvalidMetaObjectCreated = "An IDynamicMetaObjectProvider {0} created an invalid DynamicMetaObject instance.";

	public const string AmbiguousMatchInExpandoObject = "More than one key matching '{0}' was found in the ExpandoObject.";

	public const string CollectionReadOnly = "Collection is read-only.";

	public const string KeyDoesNotExistInExpando = "The specified key '{0}' does not exist in the ExpandoObject.";

	public const string SameKeyExistsInExpando = "An element with the same key '{0}' already exists in the ExpandoObject.";

	public const string Arg_KeyNotFoundWithKey = "The given key '{0}' was not present in the dictionary.";

	public const string EmptyEnumerable = "Enumeration yielded no results";

	public const string MoreThanOneElement = "Sequence contains more than one element";

	public const string MoreThanOneMatch = "Sequence contains more than one matching element";

	public const string NoElements = "Sequence contains no elements";

	public const string NoMatch = "Sequence contains no matching element";

	public const string ParallelPartitionable_NullReturn = "The return value must not be null.";

	public const string ParallelPartitionable_IncorretElementCount = "The returned array's length must equal the number of partitions requested.";

	public const string ParallelPartitionable_NullElement = "Elements returned must not be null.";

	public const string PLINQ_CommonEnumerator_Current_NotStarted = "Enumeration has not started. MoveNext must be called to initiate enumeration.";

	public const string PLINQ_ExternalCancellationRequested = "The query has been canceled via the token supplied to WithCancellation.";

	public const string PLINQ_DisposeRequested = "The query enumerator has been disposed.";

	public const string ParallelQuery_DuplicateTaskScheduler = "The WithTaskScheduler operator may be used at most once in a query.";

	public const string ParallelQuery_DuplicateDOP = "The WithDegreeOfParallelism operator may be used at most once in a query.";

	public const string ParallelQuery_DuplicateExecutionMode = "The WithExecutionMode operator may be used at most once in a query.";

	public const string PartitionerQueryOperator_NullPartitionList = "Partitioner returned null instead of a list of partitions.";

	public const string PartitionerQueryOperator_WrongNumberOfPartitions = "Partitioner returned a wrong number of partitions.";

	public const string PartitionerQueryOperator_NullPartition = "Partitioner returned a null partition.";

	public const string ParallelQuery_DuplicateWithCancellation = "The WithCancellation operator may by used at most once in a query.";

	public const string ParallelQuery_DuplicateMergeOptions = "The WithMergeOptions operator may be used at most once in a query.";

	public const string PLINQ_EnumerationPreviouslyFailed = "The query enumerator previously threw an exception.";

	public const string ParallelQuery_PartitionerNotOrderable = "AsOrdered may not be used with a partitioner that is not orderable.";

	public const string ParallelQuery_InvalidAsOrderedCall = "AsOrdered may only be called on the result of AsParallel, ParallelEnumerable.Range, or ParallelEnumerable.Repeat.";

	public const string ParallelQuery_InvalidNonGenericAsOrderedCall = "Non-generic AsOrdered may only be called on the result of the non-generic AsParallel.";

	public const string ParallelEnumerable_BinaryOpMustUseAsParallel = "The second data source of a binary operator must be of type System.Linq.ParallelQuery<T> rather than System.Collections.Generic.IEnumerable<T>. To fix this problem, use the AsParallel() extension method to convert the right data source to System.Linq.ParallelQuery<T>.";

	public const string ParallelEnumerable_WithQueryExecutionMode_InvalidMode = "The executionMode argument contains an invalid value.";

	public const string ParallelEnumerable_WithMergeOptions_InvalidOptions = "The mergeOptions argument contains an invalid value.";

	public const string ArgumentNotIEnumerableGeneric = "{0} is not IEnumerable<>";

	public const string ArgumentNotValid = "Argument {0} is not valid";

	public const string NoMethodOnType = "There is no method '{0}' on type '{1}'";

	public const string NoMethodOnTypeMatchingArguments = "There is no method '{0}' on type '{1}' that matches the specified arguments";

	public const string EnumeratingNullEnumerableExpression = "Cannot enumerate a query created from a null IEnumerable<>";

	public const string ArgumentOutOfRange_NeedNonNegNum = "Non negative number is required.";

	public const string ArgumentOutOfRange_NeedValidPipeAccessRights = "Invalid PipeAccessRights value.";

	public const string Argument_InvalidOffLen = "Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection.";

	public const string Argument_NeedNonemptyPipeName = "pipeName cannot be an empty string.";

	public const string Argument_NonContainerInvalidAnyFlag = "This flag may not be set on a pipe.";

	public const string Argument_EmptyServerName = "serverName cannot be an empty string.  Use \\\\\\\".\\\\\\\" for current machine.";

	public const string Argument_InvalidHandle = "Invalid handle.";

	public const string ArgumentNull_Buffer = "Buffer cannot be null.";

	public const string ArgumentNull_ServerName = "serverName cannot be null. Use \\\".\\\" for current machine.";

	public const string ArgumentOutOfRange_AnonymousReserved = "The pipeName \\\"anonymous\\\" is reserved.";

	public const string ArgumentOutOfRange_TransmissionModeByteOrMsg = "For named pipes, transmission mode can be TransmissionMode.Byte or PipeTransmissionMode.Message. For anonymous pipes, transmission mode can be TransmissionMode.Byte.";

	public const string ArgumentOutOfRange_DirectionModeInOutOrInOut = "For named pipes, the pipe direction can be PipeDirection.In, PipeDirection.Out or PipeDirection.InOut. For anonymous pipes, the pipe direction can be PipeDirection.In or PipeDirection.Out.";

	public const string ArgumentOutOfRange_ImpersonationInvalid = "TokenImpersonationLevel.None, TokenImpersonationLevel.Anonymous, TokenImpersonationLevel.Identification, TokenImpersonationLevel.Impersonation or TokenImpersonationLevel.Delegation required.";

	public const string ArgumentOutOfRange_OptionsInvalid = "options contains an invalid flag.";

	public const string ArgumentOutOfRange_HandleInheritabilityNoneOrInheritable = "HandleInheritability.None or HandleInheritability.Inheritable required.";

	public const string ArgumentOutOfRange_InvalidTimeout = "Timeout must be non-negative or equal to -1 (Timeout.Infinite)";

	public const string ArgumentOutOfRange_MaxNumServerInstances = "maxNumberOfServerInstances must either be a value between 1 and 254, or NamedPipeServerStream.MaxAllowedServerInstances (to obtain the maximum number allowed by system resources).";

	public const string ArgumentOutOfRange_NeedPosNum = "Positive number required.";

	public const string InvalidOperation_PipeNotYetConnected = "Pipe hasn't been connected yet.";

	public const string InvalidOperation_PipeDisconnected = "Pipe is in a disconnected state.";

	public const string InvalidOperation_PipeHandleNotSet = "Pipe handle has not been set.  Did your PipeStream implementation call InitializeHandle?";

	public const string InvalidOperation_PipeNotAsync = "Pipe is not opened in asynchronous mode.";

	public const string InvalidOperation_PipeReadModeNotMessage = "ReadMode is not of PipeTransmissionMode.Message.";

	public const string InvalidOperation_PipeAlreadyConnected = "Already in a connected state.";

	public const string InvalidOperation_PipeAlreadyDisconnected = "Already in a disconnected state.";

	public const string IO_EOF_ReadBeyondEOF = "Unable to read beyond the end of the stream.";

	public const string IO_FileNotFound = "Unable to find the specified file.";

	public const string IO_FileNotFound_FileName = "Could not find file '{0}'.";

	public const string IO_AlreadyExists_Name = "Cannot create \\\"{0}\\\" because a file or directory with the same name already exists.";

	public const string IO_FileExists_Name = "The file '{0}' already exists.";

	public const string IO_IO_PipeBroken = "Pipe is broken.";

	public const string IO_OperationAborted = "IO operation was aborted unexpectedly.";

	public const string IO_SharingViolation_File = "The process cannot access the file '{0}' because it is being used by another process.";

	public const string IO_SharingViolation_NoFileName = "The process cannot access the file because it is being used by another process.";

	public const string IO_PipeBroken = "Pipe is broken.";

	public const string IO_InvalidPipeHandle = "Invalid pipe handle.";

	public const string IO_PathNotFound_Path = "Could not find a part of the path '{0}'.";

	public const string IO_PathNotFound_NoPathName = "Could not find a part of the path.";

	public const string IO_PathTooLong = "The specified file name or path is too long, or a component of the specified path is too long.";

	public const string NotSupported_UnreadableStream = "Stream does not support reading.";

	public const string NotSupported_UnseekableStream = "Stream does not support seeking.";

	public const string NotSupported_UnwritableStream = "Stream does not support writing.";

	public const string NotSupported_AnonymousPipeUnidirectional = "Anonymous pipes can only be in one direction.";

	public const string NotSupported_AnonymousPipeMessagesNotSupported = "Anonymous pipes do not support PipeTransmissionMode.Message ReadMode.";

	public const string ObjectDisposed_PipeClosed = "Cannot access a closed pipe.";

	public const string UnauthorizedAccess_IODenied_Path = "Access to the path '{0}' is denied.";

	public const string UnauthorizedAccess_IODenied_NoPathName = "Access to the path is denied.";

	public const string ArgumentOutOfRange_FileLengthTooBig = "Specified file length was too large for the file system.";

	public const string PlatformNotSupported_MessageTransmissionMode = "Message transmission mode is not supported on this platform.";

	public const string PlatformNotSupported_RemotePipes = "Access to remote named pipes is not supported on this platform.";

	public const string PlatformNotSupported_InvalidPipeNameChars = "The name of a pipe on this platform must be a valid file name or a valid absolute path to a file name.";

	public const string ObjectDisposed_StreamClosed = "Cannot access a closed Stream.";

	public const string PlatformNotSupported_OperatingSystemError = "The operating system returned error '{0}' indicating that the operation is not supported.";

	public const string IO_AllPipeInstancesAreBusy = "All pipe instances are busy.";

	public const string IO_PathTooLong_Path = "The path '{0}' is too long, or a component of the specified path is too long.";

	public const string UnauthorizedAccess_NotOwnedByCurrentUser = "Could not connect to the pipe because it was not owned by the current user.";

	public const string UnauthorizedAccess_ClientIsNotCurrentUser = "Client connection (user id {0}) was refused because it was not owned by the current user (id {1}).";

	public const string net_invalidversion = "This protocol version is not supported.";

	public const string net_noseek = "This stream does not support seek operations.";

	public const string net_invasync = "Cannot block a call on this socket while an earlier asynchronous call is in progress.";

	public const string net_io_timeout_use_gt_zero = "Timeout can be only be set to 'System.Threading.Timeout.Infinite' or a value > 0.";

	public const string net_notconnected = "The operation is not allowed on non-connected sockets.";

	public const string net_notstream = "The operation is not allowed on non-stream oriented sockets.";

	public const string net_stopped = "Not listening. You must call the Start() method before calling this method.";

	public const string net_udpconnected = "Cannot send packets to an arbitrary host while connected.";

	public const string net_readonlystream = "The stream does not support writing.";

	public const string net_writeonlystream = "The stream does not support reading.";

	public const string net_InvalidAddressFamily = "The AddressFamily {0} is not valid for the {1} end point, use {2} instead.";

	public const string net_InvalidEndPointAddressFamily = "The supplied EndPoint of AddressFamily {0} is not valid for this Socket, use {1} instead.";

	public const string net_InvalidSocketAddressSize = "The supplied {0} is an invalid size for the {1} end point.";

	public const string net_invalidAddressList = "None of the discovered or specified addresses match the socket address family.";

	public const string net_completed_result = "This operation cannot be performed on a completed asynchronous result object.";

	public const string net_protocol_invalid_family = "'{0}' Client can only accept InterNetwork or InterNetworkV6 addresses.";

	public const string net_protocol_invalid_multicast_family = "Multicast family is not the same as the family of the '{0}' Client.";

	public const string net_sockets_zerolist = "The parameter {0} must contain one or more elements.";

	public const string net_sockets_blocking = "The operation is not allowed on a non-blocking Socket.";

	public const string net_sockets_useblocking = "Use the Blocking property to change the status of the Socket.";

	public const string net_sockets_select = "The operation is not allowed on objects of type {0}. Use only objects of type {1}.";

	public const string net_sockets_toolarge_select = "The {0} list contains too many items; a maximum of {1} is allowed.";

	public const string net_sockets_empty_select = "All lists are either null or empty.";

	public const string net_sockets_mustbind = "You must call the Bind method before performing this operation.";

	public const string net_sockets_mustlisten = "You must call the Listen method before performing this operation.";

	public const string net_sockets_mustnotlisten = "You may not perform this operation after calling the Listen method.";

	public const string net_sockets_mustnotbebound = "The socket must not be bound or connected.";

	public const string net_sockets_namedmustnotbebound = "{0}: The socket must not be bound or connected.";

	public const string net_sockets_invalid_ipaddress_length = "The number of specified IP addresses has to be greater than 0.";

	public const string net_sockets_invalid_optionValue = "The specified value is not a valid '{0}'.";

	public const string net_sockets_invalid_optionValue_all = "The specified value is not valid.";

	public const string net_sockets_invalid_dnsendpoint = "The parameter {0} must not be of type DnsEndPoint.";

	public const string net_sockets_disconnectedConnect = "Once the socket has been disconnected, you can only reconnect again asynchronously, and only to a different EndPoint.  BeginConnect must be called on a thread that won't exit until the operation has been completed.";

	public const string net_sockets_disconnectedAccept = "Once the socket has been disconnected, you can only accept again asynchronously.  BeginAccept must be called on a thread that won't exit until the operation has been completed.";

	public const string net_tcplistener_mustbestopped = "The TcpListener must not be listening before performing this operation.";

	public const string net_socketopinprogress = "An asynchronous socket operation is already in progress using this SocketAsyncEventArgs instance.";

	public const string net_buffercounttoosmall = "The Buffer space specified by the Count property is insufficient for the AcceptAsync method.";

	public const string net_multibuffernotsupported = "Multiple buffers cannot be used with this method.";

	public const string net_ambiguousbuffers = "Buffer and BufferList properties cannot both be non-null.";

	public const string net_io_writefailure = "Unable to write data to the transport connection: {0}.";

	public const string net_io_readfailure = "Unable to read data from the transport connection: {0}.";

	public const string net_io_invalidasyncresult = "The IAsyncResult object was not returned from the corresponding asynchronous method on this class.";

	public const string net_io_invalidendcall = "{0} can only be called once for each asynchronous operation.";

	public const string net_value_cannot_be_negative = "The specified value cannot be negative.";

	public const string ArgumentOutOfRange_Bounds_Lower_Upper = "Argument must be between {0} and {1}.";

	public const string net_sockets_connect_multiconnect_notsupported = "Sockets on this platform are invalid for use after a failed connection attempt.";

	public const string net_sockets_dualmode_receivefrom_notsupported = "This platform does not support packet information for dual-mode sockets.  If packet information is not required, use Socket.Receive.  If packet information is required set Socket.DualMode to false.";

	public const string net_sockets_accept_receive_notsupported = "This platform does not support receiving data with Socket.AcceptAsync.  Instead, make a separate call to Socket.ReceiveAsync.";

	public const string net_sockets_duplicateandclose_notsupported = "This platform does not support Socket.DuplicateAndClose.  Instead, create a new socket.";

	public const string net_sockets_transmitfileoptions_notsupported = "This platform does not support TransmitFileOptions other than TransmitFileOptions.UseDefaultWorkerThread.";

	public const string ArgumentOutOfRange_PathLengthInvalid = "The path '{0}' is of an invalid length for use with domain sockets on this platform.  The length must be between 1 and {1} characters, inclusive.";

	public const string net_io_readwritefailure = "Unable to transfer data on the transport connection: {0}.";

	public const string PlatformNotSupported_AcceptSocket = "Accepting into an existing Socket is not supported on this platform.";

	public const string PlatformNotSupported_IOControl = "Socket.IOControl handles Windows-specific control codes and is not supported on this platform.";

	public const string PlatformNotSupported_IPProtectionLevel = "IP protection level cannot be controlled on this platform.";

	public const string InvalidOperation_BufferNotExplicitArray = "This operation may only be performed when the buffer was set using the SetBuffer overload that accepts an array.";

	public const string InvalidOperation_IncorrectToken = "The result of the operation was already consumed and may not be used again.";

	public const string InvalidOperation_MultipleContinuations = "Another continuation was already registered.";

	public const string Argument_InvalidOidValue = "The OID value was invalid.";

	public const string Argument_InvalidValue = "Value was invalid.";

	public const string Arg_CryptographyException = "Error occurred during a cryptographic operation.";

	public const string Cryptography_ArgECDHKeySizeMismatch = "The keys from both parties must be the same size to generate a secret agreement.";

	public const string Cryptography_ArgECDHRequiresECDHKey = "Keys used with the ECDiffieHellmanCng algorithm must have an algorithm group of ECDiffieHellman.";

	public const string Cryptography_TlsRequiresLabelAndSeed = "The TLS key derivation function requires both the label and seed properties to be set.";

	public const string Cryptography_TlsRequires64ByteSeed = "The TLS key derivation function requires a seed value of exactly 64 bytes.";

	public const string Cryptography_BadHashSize_ForAlgorithm = "The provided value of {0} bytes does not match the expected size of {1} bytes for the algorithm ({2}).";

	public const string Cryptography_Config_EncodedOIDError = "Encoded OID length is too large (greater than 0x7f bytes).";

	public const string Cryptography_CSP_NoPrivateKey = "Object contains only the public half of a key pair. A private key must also be provided.";

	public const string Cryptography_Der_Invalid_Encoding = "ASN1 corrupted data.";

	public const string Cryptography_DSA_KeyGenNotSupported = "DSA keys can be imported, but new key generation is not supported on this platform.";

	public const string Cryptography_Encryption_MessageTooLong = "The message exceeds the maximum allowable length for the chosen options ({0}).";

	public const string Cryptography_ECXmlSerializationFormatRequired = "XML serialization of an elliptic curve key requires using an overload which specifies the XML format to be used.";

	public const string Cryptography_ECC_NamedCurvesOnly = "Only named curves are supported on this platform.";

	public const string Cryptography_HashAlgorithmNameNullOrEmpty = "The hash algorithm name cannot be null or empty.";

	public const string Cryptography_InvalidOID = "Object identifier (OID) is unknown.";

	public const string Cryptography_CurveNotSupported = "The specified curve '{0}' or its parameters are not valid for this platform.";

	public const string Cryptography_InvalidCurveOid = "The specified Oid is not valid. The Oid.FriendlyName or Oid.Value property must be set.";

	public const string Cryptography_InvalidCurveKeyParameters = "The specified key parameters are not valid. Q.X and Q.Y are required fields. Q.X, Q.Y must be the same length. If D is specified it must be the same length as Q.X and Q.Y for named curves or the same length as Order for explicit curves.";

	public const string Cryptography_InvalidDsaParameters_MissingFields = "The specified DSA parameters are not valid; P, Q, G and Y are all required.";

	public const string Cryptography_InvalidDsaParameters_MismatchedPGY = "The specified DSA parameters are not valid; P, G and Y must be the same length (the key size).";

	public const string Cryptography_InvalidDsaParameters_MismatchedQX = "The specified DSA parameters are not valid; Q and X (if present) must be the same length.";

	public const string Cryptography_InvalidDsaParameters_MismatchedPJ = "The specified DSA parameters are not valid; J (if present) must be shorter than P.";

	public const string Cryptography_InvalidDsaParameters_SeedRestriction_ShortKey = "The specified DSA parameters are not valid; Seed, if present, must be 20 bytes long for keys shorter than 1024 bits.";

	public const string Cryptography_InvalidDsaParameters_QRestriction_ShortKey = "The specified DSA parameters are not valid; Q must be 20 bytes long for keys shorter than 1024 bits.";

	public const string Cryptography_InvalidDsaParameters_QRestriction_LargeKey = "The specified DSA parameters are not valid; Q's length must be one of 20, 32 or 64 bytes.";

	public const string Cryptography_InvalidECCharacteristic2Curve = "The specified Characteristic2 curve parameters are not valid. Polynomial, A, B, G.X, G.Y, and Order are required. A, B, G.X, G.Y must be the same length, and the same length as Q.X, Q.Y and D if those are specified. Seed, Cofactor and Hash are optional. Other parameters are not allowed.";

	public const string Cryptography_InvalidECPrimeCurve = "The specified prime curve parameters are not valid. Prime, A, B, G.X, G.Y and Order are required and must be the same length, and the same length as Q.X, Q.Y and D if those are specified. Seed, Cofactor and Hash are optional. Other parameters are not allowed.";

	public const string Cryptography_InvalidECNamedCurve = "The specified named curve parameters are not valid. Only the Oid parameter must be set.";

	public const string Cryptography_InvalidKeySize = "Specified key is not a valid size for this algorithm.";

	public const string Cryptography_InvalidKey_SemiWeak = "Specified key is a known semi-weak key for '{0}' and cannot be used.";

	public const string Cryptography_InvalidKey_Weak = "Specified key is a known weak key for '{0}' and cannot be used.";

	public const string Cryptography_InvalidIVSize = "Specified initialization vector (IV) does not match the block size for this algorithm.";

	public const string Cryptography_InvalidOperation = "This operation is not supported for this class.";

	public const string Cryptography_InvalidPadding = "Padding is invalid and cannot be removed.";

	public const string Cryptography_InvalidRsaParameters = "The specified RSA parameters are not valid; both Exponent and Modulus are required fields.";

	public const string Cryptography_InvalidPaddingMode = "Specified padding mode is not valid for this algorithm.";

	public const string Cryptography_Invalid_IA5String = "The string contains a character not in the 7 bit ASCII character set.";

	public const string Cryptography_KeyTooSmall = "The key is too small for the requested operation.";

	public const string Cryptography_MissingIV = "The cipher mode specified requires that an initialization vector (IV) be used.";

	public const string Cryptography_MissingKey = "No asymmetric key object has been associated with this formatter object.";

	public const string Cryptography_MissingOID = "Required object identifier (OID) cannot be found.";

	public const string Cryptography_MustTransformWholeBlock = "TransformBlock may only process bytes in block sized increments.";

	public const string Cryptography_NotValidPrivateKey = "Key is not a valid private key.";

	public const string Cryptography_NotValidPublicOrPrivateKey = "Key is not a valid public or private key.";

	public const string Cryptography_OAEP_Decryption_Failed = "Error occurred while decoding OAEP padding.";

	public const string Cryptography_OpenInvalidHandle = "Cannot open an invalid handle.";

	public const string Cryptography_PartialBlock = "The input data is not a complete block.";

	public const string Cryptography_PasswordDerivedBytes_FewBytesSalt = "Salt is not at least eight bytes.";

	public const string Cryptography_RC2_EKS40 = "EffectiveKeySize value must be at least 40 bits.";

	public const string Cryptography_RC2_EKSKS = "KeySize value must be at least as large as the EffectiveKeySize value.";

	public const string Cryptography_RC2_EKSKS2 = "EffectiveKeySize must be the same as KeySize in this implementation.";

	public const string Cryptography_Rijndael_BlockSize = "BlockSize must be 128 in this implementation.";

	public const string Cryptography_RSA_DecryptWrongSize = "The length of the data to decrypt is not valid for the size of this key.";

	public const string Cryptography_SignHash_WrongSize = "The provided hash value is not the expected size for the specified hash algorithm.";

	public const string Cryptography_TransformBeyondEndOfBuffer = "Attempt to transform beyond end of buffer.";

	public const string Cryptography_CipherModeNotSupported = "The specified CipherMode '{0}' is not supported.";

	public const string Cryptography_UnknownHashAlgorithm = "'{0}' is not a known hash algorithm.";

	public const string Cryptography_UnknownPaddingMode = "Unknown padding mode used.";

	public const string Cryptography_UnexpectedTransformTruncation = "CNG provider unexpectedly terminated encryption or decryption prematurely.";

	public const string Cryptography_Unmapped_System_Typed_Error = "The system cryptographic library returned error '{0}' of type '{1}'";

	public const string Cryptography_UnsupportedPaddingMode = "The specified PaddingMode is not supported.";

	public const string NotSupported_Method = "Method not supported.";

	public const string NotSupported_SubclassOverride = "Method not supported. Derived class must override.";

	public const string Cryptography_AlgorithmTypesMustBeVisible = "Algorithms added to CryptoConfig must be accessable from outside their assembly.";

	public const string Cryptography_AddNullOrEmptyName = "CryptoConfig cannot add a mapping for a null or empty name.";

	public const string Argument_Invalid_SafeHandleInvalidOrClosed = "The method cannot be called with an invalid or closed SafeHandle.";

	public const string Cryptography_ArgExpectedECDiffieHellmanCngPublicKey = "DeriveKeyMaterial requires an ECDiffieHellmanCngPublicKey.";

	public const string Cryptography_ArgDSARequiresDSAKey = "Keys used with the DSACng algorithm must have an algorithm group of DSA.";

	public const string Cryptography_ArgECDsaRequiresECDsaKey = "Keys used with the ECDsaCng algorithm must have an algorithm group of ECDsa.";

	public const string Cryptography_ArgRSARequiresRSAKey = "Keys used with the RSACng algorithm must have an algorithm group of RSA.";

	public const string Cryptography_CngKeyWrongAlgorithm = "This key is for algorithm '{0}'. Expected '{1}'.";

	public const string Cryptography_InvalidAlgorithmGroup = "The algorithm group '{0}' is invalid.";

	public const string Cryptography_InvalidAlgorithmName = "The algorithm name '{0}' is invalid.";

	public const string Cryptography_InvalidCipherMode = "Specified cipher mode is not valid for this algorithm.";

	public const string Cryptography_InvalidKeyBlobFormat = "The key blob format '{0}' is invalid.";

	public const string Cryptography_InvalidProviderName = "The provider name '{0}' is invalid.";

	public const string Cryptography_KeyBlobParsingError = "Key Blob not in expected format.";

	public const string Cryptography_OpenEphemeralKeyHandleWithoutEphemeralFlag = "The CNG key handle being opened was detected to be ephemeral, but the EphemeralKey open option was not specified.";

	public const string Cryptography_WeakKey = "Specified key is a known weak key for this algorithm and cannot be used.";

	public const string PlatformNotSupported_CryptographyCng = "Windows Cryptography Next Generation (CNG) is not supported on this platform.";

	public const string CountdownEvent_Increment_AlreadyZero = "The event is already signaled and cannot be incremented.";

	public const string CountdownEvent_Increment_AlreadyMax = "The increment operation would cause the CurrentCount to overflow.";

	public const string CountdownEvent_Decrement_BelowZero = "Invalid attempt made to decrement the event's count below zero.";

	public const string Common_OperationCanceled = "The operation was canceled.";

	public const string Barrier_Dispose = "The barrier has been disposed.";

	public const string Barrier_SignalAndWait_InvalidOperation_ZeroTotal = "The barrier has no registered participants.";

	public const string Barrier_SignalAndWait_ArgumentOutOfRange = "The specified timeout must represent a value between -1 and Int32.MaxValue, inclusive.";

	public const string Barrier_RemoveParticipants_InvalidOperation = "The participantCount argument is greater than the number of participants that haven't yet arrived at the barrier in this phase.";

	public const string Barrier_RemoveParticipants_ArgumentOutOfRange = "The participantCount argument must be less than or equal the number of participants.";

	public const string Barrier_RemoveParticipants_NonPositive_ArgumentOutOfRange = "The participantCount argument must be a positive value.";

	public const string Barrier_InvalidOperation_CalledFromPHA = "This method may not be called from within the postPhaseAction.";

	public const string Barrier_AddParticipants_NonPositive_ArgumentOutOfRange = "The participantCount argument must be a positive value.";

	public const string Barrier_SignalAndWait_InvalidOperation_ThreadsExceeded = "The number of threads using the barrier exceeded the total number of registered participants.";

	public const string BarrierPostPhaseException = "The postPhaseAction failed with an exception.";

	public const string Barrier_ctor_ArgumentOutOfRange = "The participantCount argument must be non-negative and less than or equal to 32767.";

	public const string Barrier_AddParticipants_Overflow_ArgumentOutOfRange = "Adding participantCount participants would result in the number of participants exceeding the maximum number allowed.";

	public const string SynchronizationLockException_IncorrectDispose = "The lock is being disposed while still being used. It either is being held by a thread and/or has active waiters waiting to acquire the lock.";

	public const string SynchronizationLockException_MisMatchedWrite = "The write lock is being released without being held.";

	public const string LockRecursionException_UpgradeAfterReadNotAllowed = "Upgradeable lock may not be acquired with read lock held.";

	public const string LockRecursionException_UpgradeAfterWriteNotAllowed = "Upgradeable lock may not be acquired with write lock held in this mode. Acquiring Upgradeable lock gives the ability to read along with an option to upgrade to a writer.";

	public const string SynchronizationLockException_MisMatchedUpgrade = "The upgradeable lock is being released without being held.";

	public const string SynchronizationLockException_MisMatchedRead = "The read lock is being released without being held.";

	public const string LockRecursionException_WriteAfterReadNotAllowed = "Write lock may not be acquired with read lock held. This pattern is prone to deadlocks. Please ensure that read locks are released before taking a write lock. If an upgrade is necessary, use an upgrade lock in place of the read lock.";

	public const string LockRecursionException_RecursiveWriteNotAllowed = "Recursive write lock acquisitions not allowed in this mode.";

	public const string LockRecursionException_ReadAfterWriteNotAllowed = "A read lock may not be acquired with the write lock held in this mode.";

	public const string LockRecursionException_RecursiveUpgradeNotAllowed = "Recursive upgradeable lock acquisitions not allowed in this mode.";

	public const string LockRecursionException_RecursiveReadNotAllowed = "Recursive read lock acquisitions not allowed in this mode.";

	public const string Overflow_UInt16 = "Value was either too large or too small for a UInt16.";

	public const string ReaderWriterLock_Timeout = "The operation has timed out. {0}";

	public const string ArgumentOutOfRange_TimeoutMilliseconds = "Timeout value in milliseconds must be nonnegative and less than or equal to Int32.MaxValue, or -1 for an infinite timeout.";

	public const string ReaderWriterLock_NotOwner = "Attempt to release a lock that is not owned by the calling thread. {0}";

	public const string ExceptionFromHResult = "(Exception from HRESULT: 0x{0:X})";

	public const string ReaderWriterLock_InvalidLockCookie = "The specified lock cookie is invalid for this operation. {0}";

	public const string ReaderWriterLock_RestoreLockWithOwnedLocks = "ReaderWriterLock.RestoreLock was called without releasing all locks acquired since the call to ReleaseLock.";

	public const string HostExecutionContextManager_InvalidOperation_NotNewCaptureContext = "Cannot apply a context that has been marshaled across AppDomains, that was not acquired through a Capture operation or that has already been the argument to a Set call.";

	public const string HostExecutionContextManager_InvalidOperation_CannotOverrideSetWithoutRevert = "Must override both HostExecutionContextManager.SetHostExecutionContext and HostExecutionContextManager.Revert.";

	public const string HostExecutionContextManager_InvalidOperation_CannotUseSwitcherOtherThread = "Undo operation must be performed on the thread where the corresponding context was Set.";

	public const string Arg_NonZeroLowerBound = "The lower bound of target array must be zero.";

	public const string Arg_WrongType = "The value '{0}' is not of type '{1}' and cannot be used in this generic collection.";

	public const string Arg_ArrayPlusOffTooSmall = "Destination array is not long enough to copy all the items in the collection. Check array index and length.";

	public const string ArgumentOutOfRange_SmallCapacity = "capacity was less than the current size.";

	public const string Argument_AddingDuplicate = "An item with the same key has already been added. Key: {0}";

	public const string InvalidOperation_ConcurrentOperationsNotSupported = "Operations that change non-concurrent collections must have exclusive access. A concurrent update was performed on this collection and corrupted its state. The collection's state is no longer correct.";

	public const string InvalidOperation_EmptyQueue = "Queue empty.";

	public const string InvalidOperation_EnumOpCantHappen = "Enumeration has either not started or has already finished.";

	public const string InvalidOperation_EnumFailedVersion = "Collection was modified; enumeration operation may not execute.";

	public const string InvalidOperation_EmptyStack = "Stack empty.";

	public const string InvalidOperation_EnumNotStarted = "Enumeration has not started. Call MoveNext.";

	public const string InvalidOperation_EnumEnded = "Enumeration already finished.";

	public const string NotSupported_KeyCollectionSet = "Mutating a key collection derived from a dictionary is not allowed.";

	public const string NotSupported_ValueCollectionSet = "Mutating a value collection derived from a dictionary is not allowed.";

	public const string Arg_ArrayLengthsDiffer = "Array lengths must be the same.";

	public const string Arg_BitArrayTypeUnsupported = "Only supported array types for CopyTo on BitArrays are Boolean[], Int32[] and Byte[].";

	public const string Arg_HSCapacityOverflow = "HashSet capacity is too big.";

	public const string Arg_HTCapacityOverflow = "Hashtable's capacity overflowed and went negative. Check load factor, capacity and the current size of the table.";

	public const string Arg_InsufficientSpace = "Insufficient space in the target location to copy the information.";

	public const string Arg_RankMultiDimNotSupported = "Only single dimensional arrays are supported for the requested action.";

	public const string Argument_ArrayTooLarge = "The input array length must not exceed Int32.MaxValue / {0}. Otherwise BitArray.Length would exceed Int32.MaxValue.";

	public const string Argument_InvalidArrayType = "Target array type is not compatible with the type of items in the collection.";

	public const string ArgumentOutOfRange_BiggerThanCollection = "Must be less than or equal to the size of the collection.";

	public const string ArgumentOutOfRange_Index = "Index was out of range. Must be non-negative and less than the size of the collection.";

	public const string ExternalLinkedListNode = "The LinkedList node does not belong to current LinkedList.";

	public const string LinkedListEmpty = "The LinkedList is empty.";

	public const string LinkedListNodeIsAttached = "The LinkedList node already belongs to a LinkedList.";

	public const string NotSupported_SortedListNestedWrite = "This operation is not supported on SortedList nested types because they require modifying the original SortedList.";

	public const string SortedSet_LowerValueGreaterThanUpperValue = "Must be less than or equal to upperValue.";

	public const string Serialization_InvalidOnDeser = "OnDeserialization method was called while the object was not being deserialized.";

	public const string Serialization_MismatchedCount = "The serialized Count information doesn't match the number of items.";

	public const string Serialization_MissingKeys = "The keys for this dictionary are missing.";

	public const string Serialization_MissingValues = "The values for this dictionary are missing.";

	public const string Argument_MapNameEmptyString = "Map name cannot be an empty string.";

	public const string Argument_EmptyFile = "A positive capacity must be specified for a Memory Mapped File backed by an empty file.";

	public const string Argument_NewMMFWriteAccessNotAllowed = "MemoryMappedFileAccess.Write is not permitted when creating new memory mapped files. Use MemoryMappedFileAccess.ReadWrite instead.";

	public const string Argument_ReadAccessWithLargeCapacity = "When specifying MemoryMappedFileAccess.Read access, the capacity must not be larger than the file size.";

	public const string Argument_NewMMFAppendModeNotAllowed = "FileMode.Append is not permitted when creating new memory mapped files. Instead, use MemoryMappedFileView to ensure write-only access within a specified region.";

	public const string Argument_NewMMFTruncateModeNotAllowed = "FileMode.Truncate is not permitted when creating new memory mapped files.";

	public const string ArgumentNull_MapName = "Map name cannot be null.";

	public const string ArgumentNull_FileStream = "fileStream cannot be null.";

	public const string ArgumentOutOfRange_CapacityLargerThanLogicalAddressSpaceNotAllowed = "The capacity cannot be greater than the size of the system's logical address space.";

	public const string ArgumentOutOfRange_NeedPositiveNumber = "A positive number is required.";

	public const string ArgumentOutOfRange_PositiveOrDefaultCapacityRequired = "The capacity must be greater than or equal to 0. 0 represents the size of the file being mapped.";

	public const string ArgumentOutOfRange_PositiveOrDefaultSizeRequired = "The size must be greater than or equal to 0. If 0 is specified, the view extends from the specified offset to the end of the file mapping.";

	public const string ArgumentOutOfRange_CapacityGEFileSizeRequired = "The capacity may not be smaller than the file size.";

	public const string IO_NotEnoughMemory = "Not enough memory to map view.";

	public const string InvalidOperation_CantCreateFileMapping = "Cannot create file mapping.";

	public const string NotSupported_MMViewStreamsFixedLength = "MemoryMappedViewStreams are fixed length.";

	public const string ObjectDisposed_ViewAccessorClosed = "Cannot access a closed accessor.";

	public const string ObjectDisposed_StreamIsClosed = "Cannot access a closed Stream.";

	public const string PlatformNotSupported_NamedMaps = "Named maps are not supported.";

	public const string MethodBuilderDoesNotHaveTypeBuilder = "MethodBuilder does not have a valid TypeBuilder";

	public const string Cryptography_NonCompliantFIPSAlgorithm = "This implementation is not part of the Windows Platform FIPS validated cryptographic algorithms.";

	public const string InvalidOperation_ViewIsNull = "The underlying MemoryMappedView object is null.";

	public const string ArgumentOutOfRange_InvalidPipeAccessRights = "Invalid PipeAccessRights flag.";

	public const string ArgumentOutOfRange_AdditionalAccessLimited = "additionalAccessRights is limited to the PipeAccessRights.ChangePermissions, PipeAccessRights.TakeOwnership, and PipeAccessRights.AccessSystemSecurity flags when creating NamedPipeServerStreams.";

	public const string InterfaceType_Must_Be_Interface = "The type '{0}' must be an interface, not a class.";

	public const string BaseType_Cannot_Be_Sealed = "The base type '{0}' cannot be sealed.";

	public const string BaseType_Cannot_Be_Abstract = "The base type '{0}' cannot be abstract.";

	public const string BaseType_Must_Have_Default_Ctor = "The base type '{0}' must have a public parameterless constructor.";

	public const string Cryptography_Cert_AlreadyHasPrivateKey = "The certificate already has an associated private key.";

	public const string Cryptography_PrivateKey_WrongAlgorithm = "The provided key does not match the public key algorithm for this certificate.";

	public const string Cryptography_PrivateKey_DoesNotMatch = "The provided key does not match the public key for this certificate.";

	internal static string GetString(string name, params object[] args)
	{
		return GetString(CultureInfo.InvariantCulture, name, args);
	}

	internal static string GetString(CultureInfo culture, string name, params object[] args)
	{
		return string.Format(culture, name, args);
	}

	internal static string GetString(string name)
	{
		return name;
	}

	internal static string GetString(CultureInfo culture, string name)
	{
		return name;
	}

	internal static string Format(string resourceFormat, params object[] args)
	{
		if (args != null)
		{
			return string.Format(CultureInfo.InvariantCulture, resourceFormat, args);
		}
		return resourceFormat;
	}

	internal static string Format(string resourceFormat, object p1)
	{
		return string.Format(CultureInfo.InvariantCulture, resourceFormat, p1);
	}

	internal static string Format(string resourceFormat, object p1, object p2)
	{
		return string.Format(CultureInfo.InvariantCulture, resourceFormat, p1, p2);
	}

	internal static string Format(CultureInfo ci, string resourceFormat, object p1, object p2)
	{
		return string.Format(ci, resourceFormat, p1, p2);
	}

	internal static string Format(string resourceFormat, object p1, object p2, object p3)
	{
		return string.Format(CultureInfo.InvariantCulture, resourceFormat, p1, p2, p3);
	}

	internal static string GetResourceString(string str)
	{
		return str;
	}
}
namespace Microsoft.Win32.SafeHandles
{
	public sealed class SafePipeHandle : SafeHandleZeroOrMinusOneIsInvalid
	{
		private const int DefaultInvalidHandle = 0;

		protected override bool ReleaseHandle()
		{
			return global::Interop.Kernel32.CloseHandle(handle);
		}

		internal SafePipeHandle()
			: this(new IntPtr(0), ownsHandle: true)
		{
		}

		public SafePipeHandle(IntPtr preexistingHandle, bool ownsHandle)
			: base(ownsHandle)
		{
			SetHandle(preexistingHandle);
		}

		internal void SetHandle(int descriptor)
		{
			SetHandle((IntPtr)descriptor);
		}
	}
	public sealed class SafeMemoryMappedFileHandle : SafeHandleZeroOrMinusOneIsInvalid
	{
		public SafeMemoryMappedFileHandle(IntPtr preexistingHandle, bool ownsHandle)
			: base(ownsHandle)
		{
			handle = preexistingHandle;
		}

		protected override bool ReleaseHandle()
		{
			MemoryMapImpl.CloseMapping(handle);
			handle = IntPtr.Zero;
			return true;
		}
	}
	public sealed class SafeMemoryMappedViewHandle : SafeBuffer
	{
		private IntPtr mmap_handle;

		internal SafeMemoryMappedViewHandle(IntPtr mmap_handle, IntPtr base_address, long size)
			: base(ownsHandle: true)
		{
			this.mmap_handle = mmap_handle;
			handle = base_address;
			Initialize((ulong)size);
		}

		internal void Flush()
		{
			MemoryMapImpl.Flush(mmap_handle);
		}

		protected override bool ReleaseHandle()
		{
			if (handle != (IntPtr)(-1))
			{
				return MemoryMapImpl.Unmap(mmap_handle);
			}
			throw new NotImplementedException();
		}
	}
	public abstract class SafeNCryptHandle : SafeHandleZeroOrMinusOneIsInvalid
	{
		public override bool IsInvalid
		{
			get
			{
				throw new NotImplementedException();
			}
		}

		protected SafeNCryptHandle()
			: base(ownsHandle: true)
		{
		}

		protected SafeNCryptHandle(IntPtr handle, SafeHandle parentHandle)
			: base(ownsHandle: false)
		{
			throw new NotImplementedException();
		}

		protected override bool ReleaseHandle()
		{
			return false;
		}

		protected abstract bool ReleaseNativeHandle();
	}
	public sealed class SafeNCryptKeyHandle : SafeNCryptHandle
	{
		public SafeNCryptKeyHandle()
		{
		}

		public SafeNCryptKeyHandle(IntPtr handle, SafeHandle parentHandle)
			: base(handle, parentHandle)
		{
		}

		protected override bool ReleaseNativeHandle()
		{
			return false;
		}
	}
	public sealed class SafeNCryptProviderHandle : SafeNCryptHandle
	{
		protected override bool ReleaseNativeHandle()
		{
			return false;
		}
	}
	public sealed class SafeNCryptSecretHandle : SafeNCryptHandle
	{
		protected override bool ReleaseNativeHandle()
		{
			return false;
		}
	}
}
namespace System
{
	internal static class NotImplemented
	{
		internal static Exception ByDesign => new NotImplementedException();

		internal static Exception ByDesignWithMessage(string message)
		{
			return new NotImplementedException(message);
		}

		internal static Exception ActiveIssue(string issue)
		{
			return new NotImplementedException();
		}
	}
	[AttributeUsage(AttributeTargets.All, AllowMultiple = true)]
	internal class MonoTODOAttribute : Attribute
	{
		private string comment;

		public string Comment => comment;

		public MonoTODOAttribute()
		{
		}

		public MonoTODOAttribute(string comment)
		{
			this.comment = comment;
		}
	}
	[AttributeUsage(AttributeTargets.All, AllowMultiple = true)]
	internal class MonoDocumentationNoteAttribute : MonoTODOAttribute
	{
		public MonoDocumentationNoteAttribute(string comment)
			: base(comment)
		{
		}
	}
	[AttributeUsage(AttributeTargets.All, AllowMultiple = true)]
	internal class MonoExtensionAttribute : MonoTODOAttribute
	{
		public MonoExtensionAttribute(string comment)
			: base(comment)
		{
		}
	}
	[AttributeUsage(AttributeTargets.All, AllowMultiple = true)]
	internal class MonoInternalNoteAttribute : MonoTODOAttribute
	{
		public MonoInternalNoteAttribute(string comment)
			: base(comment)
		{
		}
	}
	[AttributeUsage(AttributeTargets.All, AllowMultiple = true)]
	internal class MonoLimitationAttribute : MonoTODOAttribute
	{
		public MonoLimitationAttribute(string comment)
			: base(comment)
		{
		}
	}
	[AttributeUsage(AttributeTargets.All, AllowMultiple = true)]
	internal class MonoNotSupportedAttribute : MonoTODOAttribute
	{
		public MonoNotSupportedAttribute(string comment)
			: base(comment)
		{
		}
	}
	public delegate void Action<in T1, in T2, in T3, in T4, in T5, in T6, in T7, in T8, in T9>(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9);
	public delegate void Action<in T1, in T2, in T3, in T4, in T5, in T6, in T7, in T8, in T9, in T10>(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10);
	public delegate void Action<in T1, in T2, in T3, in T4, in T5, in T6, in T7, in T8, in T9, in T10, in T11>(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11);
	public delegate void Action<in T1, in T2, in T3, in T4, in T5, in T6, in T7, in T8, in T9, in T10, in T11, in T12>(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12);
	public delegate void Action<in T1, in T2, in T3, in T4, in T5, in T6, in T7, in T8, in T9, in T10, in T11, in T12, in T13>(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13);
	public delegate void Action<in T1, in T2, in T3, in T4, in T5, in T6, in T7, in T8, in T9, in T10, in T11, in T12, in T13, in T14>(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14);
	public delegate void Action<in T1, in T2, in T3, in T4, in T5, in T6, in T7, in T8, in T9, in T10, in T11, in T12, in T13, in T14, in T15>(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15);
	public delegate void Action<in T1, in T2, in T3, in T4, in T5, in T6, in T7, in T8, in T9, in T10, in T11, in T12, in T13, in T14, in T15, in T16>(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15, T16 arg16);
	public delegate TResult Func<in T1, in T2, in T3, in T4, in T5, in T6, in T7, in T8, in T9, out TResult>(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9);
	public delegate TResult Func<in T1, in T2, in T3, in T4, in T5, in T6, in T7, in T8, in T9, in T10, out TResult>(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10);
	public delegate TResult Func<in T1, in T2, in T3, in T4, in T5, in T6, in T7, in T8, in T9, in T10, in T11, out TResult>(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11);
	public delegate TResult Func<in T1, in T2, in T3, in T4, in T5, in T6, in T7, in T8, in T9, in T10, in T11, in T12, out TResult>(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12);
	public delegate TResult Func<in T1, in T2, in T3, in T4, in T5, in T6, in T7, in T8, in T9, in T10, in T11, in T12, in T13, out TResult>(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13);
	public delegate TResult Func<in T1, in T2, in T3, in T4, in T5, in T6, in T7, in T8, in T9, in T10, in T11, in T12, in T13, in T14, out TResult>(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14);
	public delegate TResult Func<in T1, in T2, in T3, in T4, in T5, in T6, in T7, in T8, in T9, in T10, in T11, in T12, in T13, in T14, in T15, out TResult>(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15);
	public delegate TResult Func<in T1, in T2, in T3, in T4, in T5, in T6, in T7, in T8, in T9, in T10, in T11, in T12, in T13, in T14, in T15, in T16, out TResult>(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15, T16 arg16);
	internal static class MonoUtil
	{
		public static readonly bool IsUnix;

		static MonoUtil()
		{
			int platform = (int)Environment.OSVersion.Platform;
			IsUnix = platform == 4 || platform == 128 || platform == 6;
		}
	}
}
namespace System.Security.Cryptography
{
	[DebuggerDisplay("ECCurve: {Oid}")]
	public struct ECCurve
	{
		public enum ECCurveType
		{
			Implicit,
			PrimeShortWeierstrass,
			PrimeTwistedEdwards,
			PrimeMontgomery,
			Characteristic2,
			Named
		}

		public static class NamedCurves
		{
			private const string ECDSA_P256_OID_VALUE = "1.2.840.10045.3.1.7";

			private const string ECDSA_P384_OID_VALUE = "1.3.132.0.34";

			private const string ECDSA_P521_OID_VALUE = "1.3.132.0.35";

			public static ECCurve brainpoolP160r1 => CreateFromFriendlyName("brainpoolP160r1");

			public static ECCurve brainpoolP160t1 => CreateFromFriendlyName("brainpoolP160t1");

			public static ECCurve brainpoolP192r1 => CreateFromFriendlyName("brainpoolP192r1");

			public static ECCurve brainpoolP192t1 => CreateFromFriendlyName("brainpoolP192t1");

			public static ECCurve brainpoolP224r1 => CreateFromFriendlyName("brainpoolP224r1");

			public static ECCurve brainpoolP224t1 => CreateFromFriendlyName("brainpoolP224t1");

			public static ECCurve brainpoolP256r1 => CreateFromFriendlyName("brainpoolP256r1");

			public static ECCurve brainpoolP256t1 => CreateFromFriendlyName("brainpoolP256t1");

			public static ECCurve brainpoolP320r1 => CreateFromFriendlyName("brainpoolP320r1");

			public static ECCurve brainpoolP320t1 => CreateFromFriendlyName("brainpoolP320t1");

			public static ECCurve brainpoolP384r1 => CreateFromFriendlyName("brainpoolP384r1");

			public static ECCurve brainpoolP384t1 => CreateFromFriendlyName("brainpoolP384t1");

			public static ECCurve brainpoolP512r1 => CreateFromFriendlyName("brainpoolP512r1");

			public static ECCurve brainpoolP512t1 => CreateFromFriendlyName("brainpoolP512t1");

			public static ECCurve nistP256 => CreateFromValueAndName("1.2.840.10045.3.1.7", "nistP256");

			public static ECCurve nistP384 => CreateFromValueAndName("1.3.132.0.34", "nistP384");

			public static ECCurve nistP521 => CreateFromValueAndName("1.3.132.0.35", "nistP521");
		}

		public byte[] A;

		public byte[] B;

		public ECPoint G;

		public byte[] Order;

		public byte[] Cofactor;

		public byte[] Seed;

		public ECCurveType CurveType;

		public HashAlgorithmName? Hash;

		public byte[] Polynomial;

		public byte[] Prime;

		private Oid _oid;

		public Oid Oid
		{
			get
			{
				return new Oid(_oid.Value, _oid.FriendlyName);
			}
			private set
			{
				if (value == null)
				{
					throw new ArgumentNullException("Oid");
				}
				if (string.IsNullOrEmpty(value.Value) && string.IsNullOrEmpty(value.FriendlyName))
				{
					throw new ArgumentException($"The specified Oid is not valid. The Oid.FriendlyName or Oid.Value property must be set.");
				}
				_oid = value;
			}
		}

		public bool IsPrime
		{
			get
			{
				if (CurveType != ECCurveType.PrimeShortWeierstrass && CurveType != ECCurveType.PrimeMontgomery)
				{
					return CurveType == ECCurveType.PrimeTwistedEdwards;
				}
				return true;
			}
		}

		public bool IsCharacteristic2 => CurveType == ECCurveType.Characteristic2;

		public bool IsExplicit
		{
			get
			{
				if (!IsPrime)
				{
					return IsCharacteristic2;
				}
				return true;
			}
		}

		public bool IsNamed => CurveType == ECCurveType.Named;

		private static ECCurve Create(Oid oid)
		{
			ECCurve result = default(ECCurve);
			result.CurveType = ECCurveType.Named;
			result.Oid = oid;
			return result;
		}

		public static ECCurve CreateFromOid(Oid curveOid)
		{
			return Create(new Oid(curveOid.Value, curveOid.FriendlyName));
		}

		public static ECCurve CreateFromFriendlyName(string oidFriendlyName)
		{
			if (oidFriendlyName == null)
			{
				throw new ArgumentNullException("oidFriendlyName");
			}
			return CreateFromValueAndName(null, oidFriendlyName);
		}

		public static ECCurve CreateFromValue(string oidValue)
		{
			if (oidValue == null)
			{
				throw new ArgumentNullException("oidValue");
			}
			return CreateFromValueAndName(oidValue, null);
		}

		private static ECCurve CreateFromValueAndName(string oidValue, string oidFriendlyName)
		{
			return Create(new Oid(oidValue, oidFriendlyName));
		}

		public void Validate()
		{
			if (IsNamed)
			{
				if (HasAnyExplicitParameters())
				{
					throw new CryptographicException("The specified named curve parameters are not valid. Only the Oid parameter must be set.");
				}
				if (Oid == null || (string.IsNullOrEmpty(Oid.FriendlyName) && string.IsNullOrEmpty(Oid.Value)))
				{
					throw new CryptographicException("The specified Oid is not valid. The Oid.FriendlyName or Oid.Value property must be set.");
				}
			}
			else if (IsExplicit)
			{
				bool flag = false;
				if (A == null || B == null || B.Length != A.Length || G.X == null || G.X.Length != A.Length || G.Y == null || G.Y.Length != A.Length || Order == null || Order.Length == 0 || Cofactor == null || Cofactor.Length == 0)
				{
					flag = true;
				}
				if (IsPrime)
				{
					if (!flag && (Prime == null || Prime.Length != A.Length))
					{
						flag = true;
					}
					if (flag)
					{
						throw new CryptographicException("The specified prime curve parameters are not valid. Prime, A, B, G.X, G.Y and Order are required and must be the same length, and the same length as Q.X, Q.Y and D if those are specified. Seed, Cofactor and Hash are optional. Other parameters are not allowed.");
					}
				}
				else if (IsCharacteristic2)
				{
					if (!flag && (Polynomial == null || Polynomial.Length == 0))
					{
						flag = true;
					}
					if (flag)

BepInExPack/mono/Managed/System.Data.dll

Decompiled a month ago
using System;
using System.Buffers;
using System.CodeDom;
using System.CodeDom.Compiler;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
using System.ComponentModel.Design.Serialization;
using System.Configuration;
using System.Data;
using System.Data.Common;
using System.Data.Odbc;
using System.Data.OleDb;
using System.Data.ProviderBase;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Data.SqlClient.SNI;
using System.Data.SqlTypes;
using System.Diagnostics;
using System.Diagnostics.Tracing;
using System.Dynamic;
using System.EnterpriseServices;
using System.Globalization;
using System.IO;
using System.IO.Pipes;
using System.Linq;
using System.Net;
using System.Net.Security;
using System.Net.Sockets;
using System.Numerics;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.ConstrainedExecution;
using System.Runtime.ExceptionServices;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Security;
using System.Security.Authentication;
using System.Security.Cryptography.X509Certificates;
using System.Security.Permissions;
using System.Security.Principal;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Transactions;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;
using System.Xml.Serialization.Advanced;
using System.Xml.XPath;
using Microsoft.SqlServer.Server;
using Microsoft.Win32;
using Microsoft.Win32.SafeHandles;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("System.Data.dll")]
[assembly: AssemblyDescription("System.Data.dll")]
[assembly: AssemblyDefaultAlias("System.Data.dll")]
[assembly: AssemblyCompany("Mono development team")]
[assembly: AssemblyProduct("Mono Common Language Infrastructure")]
[assembly: AssemblyCopyright("(c) Various Mono authors")]
[assembly: SatelliteContractVersion("4.0.0.0")]
[assembly: AssemblyInformationalVersion("4.6.57.0")]
[assembly: CLSCompliant(true)]
[assembly: NeutralResourcesLanguage("en-US")]
[assembly: ComVisible(false)]
[assembly: AllowPartiallyTrustedCallers]
[assembly: AssemblyDelaySign(true)]
[assembly: AssemblyFileVersion("4.6.57.0")]
[assembly: InternalsVisibleTo("System.Design, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")]
[assembly: InternalsVisibleTo("System.Web, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("4.0.0.0")]
[module: UnverifiableCode]
internal static class Interop
{
	internal static class Odbc
	{
		[DllImport("odbc32.dll")]
		internal static extern ODBC32.RetCode SQLAllocHandle(ODBC32.SQL_HANDLE HandleType, IntPtr InputHandle, out IntPtr OutputHandle);

		[DllImport("odbc32.dll")]
		internal static extern ODBC32.RetCode SQLAllocHandle(ODBC32.SQL_HANDLE HandleType, OdbcHandle InputHandle, out IntPtr OutputHandle);

		[DllImport("odbc32.dll")]
		internal static extern ODBC32.RetCode SQLBindCol(OdbcStatementHandle StatementHandle, ushort ColumnNumber, ODBC32.SQL_C TargetType, HandleRef TargetValue, IntPtr BufferLength, IntPtr StrLen_or_Ind);

		[DllImport("odbc32.dll")]
		internal static extern ODBC32.RetCode SQLBindCol(OdbcStatementHandle StatementHandle, ushort ColumnNumber, ODBC32.SQL_C TargetType, IntPtr TargetValue, IntPtr BufferLength, IntPtr StrLen_or_Ind);

		[DllImport("odbc32.dll")]
		internal static extern ODBC32.RetCode SQLBindParameter(OdbcStatementHandle StatementHandle, ushort ParameterNumber, short ParamDirection, ODBC32.SQL_C SQLCType, short SQLType, IntPtr cbColDef, IntPtr ibScale, HandleRef rgbValue, IntPtr BufferLength, HandleRef StrLen_or_Ind);

		[DllImport("odbc32.dll")]
		internal static extern ODBC32.RetCode SQLCancel(OdbcStatementHandle StatementHandle);

		[DllImport("odbc32.dll")]
		internal static extern ODBC32.RetCode SQLCloseCursor(OdbcStatementHandle StatementHandle);

		[DllImport("odbc32.dll")]
		internal static extern ODBC32.RetCode SQLColAttributeW(OdbcStatementHandle StatementHandle, short ColumnNumber, short FieldIdentifier, CNativeBuffer CharacterAttribute, short BufferLength, out short StringLength, out IntPtr NumericAttribute);

		[DllImport("odbc32.dll", CharSet = CharSet.Unicode)]
		internal static extern ODBC32.RetCode SQLColumnsW(OdbcStatementHandle StatementHandle, string CatalogName, short NameLen1, string SchemaName, short NameLen2, string TableName, short NameLen3, string ColumnName, short NameLen4);

		[DllImport("odbc32.dll")]
		internal static extern ODBC32.RetCode SQLDisconnect(IntPtr ConnectionHandle);

		[DllImport("odbc32.dll", CharSet = CharSet.Unicode)]
		internal static extern ODBC32.RetCode SQLDriverConnectW(OdbcConnectionHandle hdbc, IntPtr hwnd, string connectionstring, short cbConnectionstring, IntPtr connectionstringout, short cbConnectionstringoutMax, out short cbConnectionstringout, short fDriverCompletion);

		[DllImport("odbc32.dll")]
		internal static extern ODBC32.RetCode SQLEndTran(ODBC32.SQL_HANDLE HandleType, IntPtr Handle, short CompletionType);

		[DllImport("odbc32.dll", CharSet = CharSet.Unicode)]
		internal static extern ODBC32.RetCode SQLExecDirectW(OdbcStatementHandle StatementHandle, string StatementText, int TextLength);

		[DllImport("odbc32.dll")]
		internal static extern ODBC32.RetCode SQLExecute(OdbcStatementHandle StatementHandle);

		[DllImport("odbc32.dll")]
		internal static extern ODBC32.RetCode SQLFetch(OdbcStatementHandle StatementHandle);

		[DllImport("odbc32.dll")]
		internal static extern ODBC32.RetCode SQLFreeHandle(ODBC32.SQL_HANDLE HandleType, IntPtr StatementHandle);

		[DllImport("odbc32.dll")]
		internal static extern ODBC32.RetCode SQLFreeStmt(OdbcStatementHandle StatementHandle, ODBC32.STMT Option);

		[DllImport("odbc32.dll")]
		internal static extern ODBC32.RetCode SQLGetConnectAttrW(OdbcConnectionHandle ConnectionHandle, ODBC32.SQL_ATTR Attribute, byte[] Value, int BufferLength, out int StringLength);

		[DllImport("odbc32.dll")]
		internal static extern ODBC32.RetCode SQLGetData(OdbcStatementHandle StatementHandle, ushort ColumnNumber, ODBC32.SQL_C TargetType, CNativeBuffer TargetValue, IntPtr BufferLength, out IntPtr StrLen_or_Ind);

		[DllImport("odbc32.dll")]
		internal static extern ODBC32.RetCode SQLGetDescFieldW(OdbcDescriptorHandle StatementHandle, short RecNumber, ODBC32.SQL_DESC FieldIdentifier, CNativeBuffer ValuePointer, int BufferLength, out int StringLength);

		[DllImport("odbc32.dll", CharSet = CharSet.Unicode)]
		internal static extern ODBC32.RetCode SQLGetDiagRecW(ODBC32.SQL_HANDLE HandleType, OdbcHandle Handle, short RecNumber, StringBuilder rchState, out int NativeError, StringBuilder MessageText, short BufferLength, out short TextLength);

		[DllImport("odbc32.dll", CharSet = CharSet.Unicode)]
		internal static extern ODBC32.RetCode SQLGetDiagFieldW(ODBC32.SQL_HANDLE HandleType, OdbcHandle Handle, short RecNumber, short DiagIdentifier, StringBuilder rchState, short BufferLength, out short StringLength);

		[DllImport("odbc32.dll")]
		internal static extern ODBC32.RetCode SQLGetFunctions(OdbcConnectionHandle hdbc, ODBC32.SQL_API fFunction, out short pfExists);

		[DllImport("odbc32.dll")]
		internal static extern ODBC32.RetCode SQLGetInfoW(OdbcConnectionHandle hdbc, ODBC32.SQL_INFO fInfoType, byte[] rgbInfoValue, short cbInfoValueMax, out short pcbInfoValue);

		[DllImport("odbc32.dll")]
		internal static extern ODBC32.RetCode SQLGetInfoW(OdbcConnectionHandle hdbc, ODBC32.SQL_INFO fInfoType, byte[] rgbInfoValue, short cbInfoValueMax, IntPtr pcbInfoValue);

		[DllImport("odbc32.dll")]
		internal static extern ODBC32.RetCode SQLGetStmtAttrW(OdbcStatementHandle StatementHandle, ODBC32.SQL_ATTR Attribute, out IntPtr Value, int BufferLength, out int StringLength);

		[DllImport("odbc32.dll")]
		internal static extern ODBC32.RetCode SQLGetTypeInfo(OdbcStatementHandle StatementHandle, short fSqlType);

		[DllImport("odbc32.dll")]
		internal static extern ODBC32.RetCode SQLMoreResults(OdbcStatementHandle StatementHandle);

		[DllImport("odbc32.dll")]
		internal static extern ODBC32.RetCode SQLNumResultCols(OdbcStatementHandle StatementHandle, out short ColumnCount);

		[DllImport("odbc32.dll", CharSet = CharSet.Unicode)]
		internal static extern ODBC32.RetCode SQLPrepareW(OdbcStatementHandle StatementHandle, string StatementText, int TextLength);

		[DllImport("odbc32.dll", CharSet = CharSet.Unicode)]
		internal static extern ODBC32.RetCode SQLPrimaryKeysW(OdbcStatementHandle StatementHandle, string CatalogName, short NameLen1, string SchemaName, short NameLen2, string TableName, short NameLen3);

		[DllImport("odbc32.dll", CharSet = CharSet.Unicode)]
		internal static extern ODBC32.RetCode SQLProcedureColumnsW(OdbcStatementHandle StatementHandle, string CatalogName, short NameLen1, string SchemaName, short NameLen2, string ProcName, short NameLen3, string ColumnName, short NameLen4);

		[DllImport("odbc32.dll", CharSet = CharSet.Unicode)]
		internal static extern ODBC32.RetCode SQLProceduresW(OdbcStatementHandle StatementHandle, string CatalogName, short NameLen1, string SchemaName, short NameLen2, string ProcName, short NameLen3);

		[DllImport("odbc32.dll")]
		internal static extern ODBC32.RetCode SQLRowCount(OdbcStatementHandle StatementHandle, out IntPtr RowCount);

		[DllImport("odbc32.dll")]
		internal static extern ODBC32.RetCode SQLSetConnectAttrW(OdbcConnectionHandle ConnectionHandle, ODBC32.SQL_ATTR Attribute, IDtcTransaction Value, int StringLength);

		[DllImport("odbc32.dll", CharSet = CharSet.Unicode)]
		internal static extern ODBC32.RetCode SQLSetConnectAttrW(OdbcConnectionHandle ConnectionHandle, ODBC32.SQL_ATTR Attribute, string Value, int StringLength);

		[DllImport("odbc32.dll")]
		internal static extern ODBC32.RetCode SQLSetConnectAttrW(OdbcConnectionHandle ConnectionHandle, ODBC32.SQL_ATTR Attribute, IntPtr Value, int StringLength);

		[DllImport("odbc32.dll")]
		internal static extern ODBC32.RetCode SQLSetConnectAttrW(IntPtr ConnectionHandle, ODBC32.SQL_ATTR Attribute, IntPtr Value, int StringLength);

		[DllImport("odbc32.dll")]
		internal static extern ODBC32.RetCode SQLSetDescFieldW(OdbcDescriptorHandle StatementHandle, short ColumnNumber, ODBC32.SQL_DESC FieldIdentifier, HandleRef CharacterAttribute, int BufferLength);

		[DllImport("odbc32.dll")]
		internal static extern ODBC32.RetCode SQLSetDescFieldW(OdbcDescriptorHandle StatementHandle, short ColumnNumber, ODBC32.SQL_DESC FieldIdentifier, IntPtr CharacterAttribute, int BufferLength);

		[DllImport("odbc32.dll")]
		internal static extern ODBC32.RetCode SQLSetEnvAttr(OdbcEnvironmentHandle EnvironmentHandle, ODBC32.SQL_ATTR Attribute, IntPtr Value, ODBC32.SQL_IS StringLength);

		[DllImport("odbc32.dll")]
		internal static extern ODBC32.RetCode SQLSetStmtAttrW(OdbcStatementHandle StatementHandle, int Attribute, IntPtr Value, int StringLength);

		[DllImport("odbc32.dll", CharSet = CharSet.Unicode)]
		internal static extern ODBC32.RetCode SQLSpecialColumnsW(OdbcStatementHandle StatementHandle, ODBC32.SQL_SPECIALCOLS IdentifierType, string CatalogName, short NameLen1, string SchemaName, short NameLen2, string TableName, short NameLen3, ODBC32.SQL_SCOPE Scope, ODBC32.SQL_NULLABILITY Nullable);

		[DllImport("odbc32.dll", CharSet = CharSet.Unicode)]
		internal static extern ODBC32.RetCode SQLStatisticsW(OdbcStatementHandle StatementHandle, string CatalogName, short NameLen1, string SchemaName, short NameLen2, string TableName, short NameLen3, short Unique, short Reserved);

		[DllImport("odbc32.dll", CharSet = CharSet.Unicode)]
		internal static extern ODBC32.RetCode SQLTablesW(OdbcStatementHandle StatementHandle, string CatalogName, short NameLen1, string SchemaName, short NameLen2, string TableName, short NameLen3, string TableType, short NameLen4);
	}

	internal static class Libraries
	{
		internal const string Advapi32 = "advapi32.dll";

		internal const string BCrypt = "BCrypt.dll";

		internal const string CoreComm_L1_1_1 = "api-ms-win-core-comm-l1-1-1.dll";

		internal const string Crypt32 = "crypt32.dll";

		internal const string Error_L1 = "api-ms-win-core-winrt-error-l1-1-0.dll";

		internal const string HttpApi = "httpapi.dll";

		internal const string IpHlpApi = "iphlpapi.dll";

		internal const string Kernel32 = "kernel32.dll";

		internal const string Memory_L1_3 = "api-ms-win-core-memory-l1-1-3.dll";

		internal const string Mswsock = "mswsock.dll";

		internal const string NCrypt = "ncrypt.dll";

		internal const string NtDll = "ntdll.dll";

		internal const string Odbc32 = "odbc32.dll";

		internal const string OleAut32 = "oleaut32.dll";

		internal const string PerfCounter = "perfcounter.dll";

		internal const string RoBuffer = "api-ms-win-core-winrt-robuffer-l1-1-0.dll";

		internal const string Secur32 = "secur32.dll";

		internal const string Shell32 = "shell32.dll";

		internal const string SspiCli = "sspicli.dll";

		internal const string User32 = "user32.dll";

		internal const string Version = "version.dll";

		internal const string WebSocket = "websocket.dll";

		internal const string WinHttp = "winhttp.dll";

		internal const string Ws2_32 = "ws2_32.dll";

		internal const string Wtsapi32 = "wtsapi32.dll";

		internal const string CompressionNative = "clrcompression.dll";
	}

	internal class Kernel32
	{
		public const int LOAD_LIBRARY_AS_DATAFILE = 2;

		public const int LOAD_LIBRARY_SEARCH_SYSTEM32 = 2048;

		[DllImport("kernel32.dll", ExactSpelling = true, SetLastError = true)]
		public static extern bool FreeLibrary([In] IntPtr hModule);

		[DllImport("kernel32.dll", BestFitMapping = false, CharSet = CharSet.Ansi)]
		public static extern IntPtr GetProcAddress(SafeLibraryHandle hModule, string lpProcName);

		[DllImport("kernel32.dll", BestFitMapping = false, CharSet = CharSet.Ansi)]
		public static extern IntPtr GetProcAddress(IntPtr hModule, string lpProcName);

		[DllImport("kernel32.dll", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
		public static extern SafeLibraryHandle LoadLibraryExW([In] string lpwLibFileName, [In] IntPtr hFile, [In] uint dwFlags);
	}
}
internal class SqlDependencyProcessDispatcher : MarshalByRefObject
{
	private class SqlConnectionContainer
	{
		private SqlConnection _con;

		private SqlCommand _com;

		private SqlParameter _conversationGuidParam;

		private SqlParameter _timeoutParam;

		private SqlConnectionContainerHashHelper _hashHelper;

		private string _queue;

		private string _receiveQuery;

		private string _beginConversationQuery;

		private string _endConversationQuery;

		private string _concatQuery;

		private readonly int _defaultWaitforTimeout = 60000;

		private string _escapedQueueName;

		private string _sprocName;

		private string _dialogHandle;

		private string _cachedServer;

		private string _cachedDatabase;

		private volatile bool _errorState;

		private volatile bool _stop;

		private volatile bool _stopped;

		private volatile bool _serviceQueueCreated;

		private int _startCount;

		private Timer _retryTimer;

		private Dictionary<string, int> _appDomainKeyHash;

		internal string Database
		{
			get
			{
				if (_cachedDatabase == null)
				{
					_cachedDatabase = _con.Database;
				}
				return _cachedDatabase;
			}
		}

		internal SqlConnectionContainerHashHelper HashHelper => _hashHelper;

		internal bool InErrorState => _errorState;

		internal string Queue => _queue;

		internal string Server => _cachedServer;

		internal SqlConnectionContainer(SqlConnectionContainerHashHelper hashHelper, string appDomainKey, bool useDefaults)
		{
			bool flag = false;
			try
			{
				_hashHelper = hashHelper;
				string text = null;
				if (useDefaults)
				{
					text = Guid.NewGuid().ToString();
					_queue = "SqlQueryNotificationService-" + text;
					_hashHelper.ConnectionStringBuilder.ApplicationName = _queue;
				}
				else
				{
					_queue = _hashHelper.Queue;
				}
				_con = new SqlConnection(_hashHelper.ConnectionStringBuilder.ConnectionString);
				_ = (SqlConnectionString)_con.ConnectionOptions;
				_con.Open();
				_cachedServer = _con.DataSource;
				_escapedQueueName = SqlConnection.FixupDatabaseTransactionName(_queue);
				_appDomainKeyHash = new Dictionary<string, int>();
				_com = new SqlCommand
				{
					Connection = _con,
					CommandText = "select is_broker_enabled from sys.databases where database_id=db_id()"
				};
				if (!(bool)_com.ExecuteScalar())
				{
					throw SQL.SqlDependencyDatabaseBrokerDisabled();
				}
				_conversationGuidParam = new SqlParameter("@p1", SqlDbType.UniqueIdentifier);
				_timeoutParam = new SqlParameter("@p2", SqlDbType.Int)
				{
					Value = 0
				};
				_com.Parameters.Add(_timeoutParam);
				flag = true;
				_receiveQuery = "WAITFOR(RECEIVE TOP (1) message_type_name, conversation_handle, cast(message_body AS XML) as message_body from " + _escapedQueueName + "), TIMEOUT @p2;";
				if (useDefaults)
				{
					_sprocName = SqlConnection.FixupDatabaseTransactionName("SqlQueryNotificationStoredProcedure-" + text);
					CreateQueueAndService(restart: false);
				}
				else
				{
					_com.CommandText = _receiveQuery;
					_endConversationQuery = "END CONVERSATION @p1; ";
					_concatQuery = _endConversationQuery + _receiveQuery;
				}
				IncrementStartCount(appDomainKey, out var _);
				SynchronouslyQueryServiceBrokerQueue();
				_timeoutParam.Value = _defaultWaitforTimeout;
				AsynchronouslyQueryServiceBrokerQueue();
			}
			catch (Exception e)
			{
				if (!ADP.IsCatchableExceptionType(e))
				{
					throw;
				}
				ADP.TraceExceptionWithoutRethrow(e);
				if (flag)
				{
					TearDownAndDispose();
				}
				else
				{
					if (_com != null)
					{
						_com.Dispose();
						_com = null;
					}
					if (_con != null)
					{
						_con.Dispose();
						_con = null;
					}
				}
				throw;
			}
		}

		internal bool AppDomainUnload(string appDomainKey)
		{
			lock (_appDomainKeyHash)
			{
				if (_appDomainKeyHash.ContainsKey(appDomainKey))
				{
					int num = _appDomainKeyHash[appDomainKey];
					bool appDomainStop = false;
					while (num > 0)
					{
						Stop(appDomainKey, out appDomainStop);
						num--;
					}
				}
			}
			return _stopped;
		}

		private void AsynchronouslyQueryServiceBrokerQueue()
		{
			AsyncCallback callback = AsyncResultCallback;
			_com.BeginExecuteReader(CommandBehavior.Default, callback, null);
		}

		private void AsyncResultCallback(IAsyncResult asyncResult)
		{
			try
			{
				using (SqlDataReader reader = _com.EndExecuteReader(asyncResult))
				{
					ProcessNotificationResults(reader);
				}
				if (!_stop)
				{
					AsynchronouslyQueryServiceBrokerQueue();
				}
				else
				{
					TearDownAndDispose();
				}
			}
			catch (Exception e)
			{
				if (!ADP.IsCatchableExceptionType(e))
				{
					_errorState = true;
					throw;
				}
				if (!_stop)
				{
					ADP.TraceExceptionWithoutRethrow(e);
				}
				if (_stop)
				{
					TearDownAndDispose();
					return;
				}
				_errorState = true;
				Restart(null);
			}
		}

		private void CreateQueueAndService(bool restart)
		{
			SqlCommand sqlCommand = new SqlCommand
			{
				Connection = _con
			};
			SqlTransaction sqlTransaction = null;
			try
			{
				sqlTransaction = (sqlCommand.Transaction = _con.BeginTransaction());
				string text = SqlServerEscapeHelper.MakeStringLiteral(_queue);
				sqlCommand.CommandText = "CREATE PROCEDURE " + _sprocName + " AS BEGIN BEGIN TRANSACTION; RECEIVE TOP(0) conversation_handle FROM " + _escapedQueueName + "; IF (SELECT COUNT(*) FROM " + _escapedQueueName + " WHERE message_type_name = 'http://schemas.microsoft.com/SQL/ServiceBroker/DialogTimer') > 0 BEGIN if ((SELECT COUNT(*) FROM sys.services WHERE name = " + text + ") > 0)   DROP SERVICE " + _escapedQueueName + "; if (OBJECT_ID(" + text + ", 'SQ') IS NOT NULL)   DROP QUEUE " + _escapedQueueName + "; DROP PROCEDURE " + _sprocName + "; END COMMIT TRANSACTION; END";
				if (!restart)
				{
					sqlCommand.ExecuteNonQuery();
				}
				else
				{
					try
					{
						sqlCommand.ExecuteNonQuery();
					}
					catch (Exception e)
					{
						if (!ADP.IsCatchableExceptionType(e))
						{
							throw;
						}
						ADP.TraceExceptionWithoutRethrow(e);
						try
						{
							if (sqlTransaction != null)
							{
								sqlTransaction.Rollback();
								sqlTransaction = null;
							}
						}
						catch (Exception e2)
						{
							if (!ADP.IsCatchableExceptionType(e2))
							{
								throw;
							}
							ADP.TraceExceptionWithoutRethrow(e2);
						}
					}
					if (sqlTransaction == null)
					{
						sqlTransaction = (sqlCommand.Transaction = _con.BeginTransaction());
					}
				}
				sqlCommand.CommandText = "IF OBJECT_ID(" + text + ", 'SQ') IS NULL BEGIN CREATE QUEUE " + _escapedQueueName + " WITH ACTIVATION (PROCEDURE_NAME=" + _sprocName + ", MAX_QUEUE_READERS=1, EXECUTE AS OWNER); END; IF (SELECT COUNT(*) FROM sys.services WHERE NAME=" + text + ") = 0 BEGIN CREATE SERVICE " + _escapedQueueName + " ON QUEUE " + _escapedQueueName + " ([http://schemas.microsoft.com/SQL/Notifications/PostQueryNotification]); IF (SELECT COUNT(*) FROM sys.database_principals WHERE name='sql_dependency_subscriber' AND type='R') <> 0 BEGIN GRANT SEND ON SERVICE::" + _escapedQueueName + " TO sql_dependency_subscriber; END;  END; BEGIN DIALOG @dialog_handle FROM SERVICE " + _escapedQueueName + " TO SERVICE " + text;
				SqlParameter sqlParameter = new SqlParameter
				{
					ParameterName = "@dialog_handle",
					DbType = DbType.Guid,
					Direction = ParameterDirection.Output
				};
				sqlCommand.Parameters.Add(sqlParameter);
				sqlCommand.ExecuteNonQuery();
				_dialogHandle = ((Guid)sqlParameter.Value).ToString();
				_beginConversationQuery = "BEGIN CONVERSATION TIMER ('" + _dialogHandle + "') TIMEOUT = 120; " + _receiveQuery;
				_com.CommandText = _beginConversationQuery;
				_endConversationQuery = "END CONVERSATION @p1; ";
				_concatQuery = _endConversationQuery + _com.CommandText;
				sqlTransaction.Commit();
				sqlTransaction = null;
				_serviceQueueCreated = true;
			}
			finally
			{
				if (sqlTransaction != null)
				{
					try
					{
						sqlTransaction.Rollback();
						sqlTransaction = null;
					}
					catch (Exception e3)
					{
						if (!ADP.IsCatchableExceptionType(e3))
						{
							throw;
						}
						ADP.TraceExceptionWithoutRethrow(e3);
					}
				}
			}
		}

		internal void IncrementStartCount(string appDomainKey, out bool appDomainStart)
		{
			appDomainStart = false;
			Interlocked.Increment(ref _startCount);
			lock (_appDomainKeyHash)
			{
				if (_appDomainKeyHash.ContainsKey(appDomainKey))
				{
					_appDomainKeyHash[appDomainKey] += 1;
					return;
				}
				_appDomainKeyHash[appDomainKey] = 1;
				appDomainStart = true;
			}
		}

		private void ProcessNotificationResults(SqlDataReader reader)
		{
			Guid guid = Guid.Empty;
			try
			{
				if (_stop)
				{
					return;
				}
				while (reader.Read())
				{
					string @string = reader.GetString(0);
					guid = reader.GetGuid(1);
					if (string.Compare(@string, "http://schemas.microsoft.com/SQL/Notifications/QueryNotification", StringComparison.OrdinalIgnoreCase) == 0)
					{
						SqlXml sqlXml = reader.GetSqlXml(2);
						if (sqlXml == null)
						{
							continue;
						}
						SqlNotification sqlNotification = SqlNotificationParser.ProcessMessage(sqlXml);
						if (sqlNotification == null)
						{
							continue;
						}
						string key = sqlNotification.Key;
						int num = key.IndexOf(';');
						if (num < 0)
						{
							continue;
						}
						string key2 = key.Substring(0, num);
						SqlDependencyPerAppDomainDispatcher sqlDependencyPerAppDomainDispatcher;
						lock (s_staticInstance._sqlDependencyPerAppDomainDispatchers)
						{
							sqlDependencyPerAppDomainDispatcher = s_staticInstance._sqlDependencyPerAppDomainDispatchers[key2];
						}
						if (sqlDependencyPerAppDomainDispatcher == null)
						{
							continue;
						}
						try
						{
							sqlDependencyPerAppDomainDispatcher.InvalidateCommandID(sqlNotification);
						}
						catch (Exception e)
						{
							if (!ADP.IsCatchableExceptionType(e))
							{
								throw;
							}
							ADP.TraceExceptionWithoutRethrow(e);
						}
					}
					else
					{
						guid = Guid.Empty;
					}
				}
			}
			finally
			{
				if (guid == Guid.Empty)
				{
					_com.CommandText = _beginConversationQuery ?? _receiveQuery;
					if (_com.Parameters.Count > 1)
					{
						_com.Parameters.Remove(_conversationGuidParam);
					}
				}
				else
				{
					_com.CommandText = _concatQuery;
					_conversationGuidParam.Value = guid;
					if (_com.Parameters.Count == 1)
					{
						_com.Parameters.Add(_conversationGuidParam);
					}
				}
			}
		}

		private void Restart(object unused)
		{
			try
			{
				lock (this)
				{
					if (!_stop)
					{
						try
						{
							_con.Close();
						}
						catch (Exception e)
						{
							if (!ADP.IsCatchableExceptionType(e))
							{
								throw;
							}
							ADP.TraceExceptionWithoutRethrow(e);
						}
					}
				}
				lock (this)
				{
					if (!_stop)
					{
						_con.Open();
					}
				}
				lock (this)
				{
					if (!_stop && _serviceQueueCreated)
					{
						bool flag = false;
						try
						{
							CreateQueueAndService(restart: true);
						}
						catch (Exception e2)
						{
							if (!ADP.IsCatchableExceptionType(e2))
							{
								throw;
							}
							ADP.TraceExceptionWithoutRethrow(e2);
							flag = true;
						}
						if (flag)
						{
							s_staticInstance.Invalidate(Server, new SqlNotification(SqlNotificationInfo.Error, SqlNotificationSource.Client, SqlNotificationType.Change, null));
						}
					}
				}
				lock (this)
				{
					if (!_stop)
					{
						_timeoutParam.Value = 0;
						SynchronouslyQueryServiceBrokerQueue();
						_timeoutParam.Value = _defaultWaitforTimeout;
						AsynchronouslyQueryServiceBrokerQueue();
						_errorState = false;
						Timer retryTimer = _retryTimer;
						if (retryTimer != null)
						{
							_retryTimer = null;
							retryTimer.Dispose();
						}
					}
				}
				if (_stop)
				{
					TearDownAndDispose();
				}
			}
			catch (Exception e3)
			{
				if (!ADP.IsCatchableExceptionType(e3))
				{
					throw;
				}
				ADP.TraceExceptionWithoutRethrow(e3);
				try
				{
					s_staticInstance.Invalidate(Server, new SqlNotification(SqlNotificationInfo.Error, SqlNotificationSource.Client, SqlNotificationType.Change, null));
				}
				catch (Exception e4)
				{
					if (!ADP.IsCatchableExceptionType(e4))
					{
						throw;
					}
					ADP.TraceExceptionWithoutRethrow(e4);
				}
				try
				{
					_con.Close();
				}
				catch (Exception e5)
				{
					if (!ADP.IsCatchableExceptionType(e5))
					{
						throw;
					}
					ADP.TraceExceptionWithoutRethrow(e5);
				}
				if (!_stop)
				{
					_retryTimer = new Timer(Restart, null, _defaultWaitforTimeout, -1);
				}
			}
		}

		internal bool Stop(string appDomainKey, out bool appDomainStop)
		{
			appDomainStop = false;
			if (appDomainKey != null)
			{
				lock (_appDomainKeyHash)
				{
					if (_appDomainKeyHash.ContainsKey(appDomainKey))
					{
						int num = _appDomainKeyHash[appDomainKey];
						if (num > 0)
						{
							_appDomainKeyHash[appDomainKey] = num - 1;
						}
						if (1 == num)
						{
							_appDomainKeyHash.Remove(appDomainKey);
							appDomainStop = true;
						}
					}
				}
			}
			if (Interlocked.Decrement(ref _startCount) == 0)
			{
				lock (this)
				{
					try
					{
						_com.Cancel();
					}
					catch (Exception e)
					{
						if (!ADP.IsCatchableExceptionType(e))
						{
							throw;
						}
						ADP.TraceExceptionWithoutRethrow(e);
					}
					_stop = true;
				}
				Stopwatch stopwatch = Stopwatch.StartNew();
				while (true)
				{
					lock (this)
					{
						if (!_stopped)
						{
							if (!_errorState && stopwatch.Elapsed.Seconds < 30)
							{
								goto IL_0127;
							}
							Timer retryTimer = _retryTimer;
							_retryTimer = null;
							retryTimer?.Dispose();
							TearDownAndDispose();
						}
					}
					break;
					IL_0127:
					Thread.Sleep(1);
				}
			}
			return _stopped;
		}

		private void SynchronouslyQueryServiceBrokerQueue()
		{
			using SqlDataReader reader = _com.ExecuteReader();
			ProcessNotificationResults(reader);
		}

		private void TearDownAndDispose()
		{
			lock (this)
			{
				try
				{
					if (_con.State == ConnectionState.Closed || ConnectionState.Broken == _con.State)
					{
						return;
					}
					if (_com.Parameters.Count > 1)
					{
						try
						{
							_com.CommandText = _endConversationQuery;
							_com.Parameters.Remove(_timeoutParam);
							_com.ExecuteNonQuery();
						}
						catch (Exception e)
						{
							if (!ADP.IsCatchableExceptionType(e))
							{
								throw;
							}
							ADP.TraceExceptionWithoutRethrow(e);
						}
					}
					if (!_serviceQueueCreated || _errorState)
					{
						return;
					}
					_com.CommandText = "BEGIN TRANSACTION; DROP SERVICE " + _escapedQueueName + "; DROP QUEUE " + _escapedQueueName + "; DROP PROCEDURE " + _sprocName + "; COMMIT TRANSACTION;";
					try
					{
						_com.ExecuteNonQuery();
					}
					catch (Exception e2)
					{
						if (!ADP.IsCatchableExceptionType(e2))
						{
							throw;
						}
						ADP.TraceExceptionWithoutRethrow(e2);
					}
				}
				finally
				{
					_stopped = true;
					_con.Dispose();
				}
			}
		}
	}

	private class SqlNotificationParser
	{
		[Flags]
		private enum MessageAttributes
		{
			None = 0,
			Type = 1,
			Source = 2,
			Info = 4,
			All = 7
		}

		private const string RootNode = "QueryNotification";

		private const string MessageNode = "Message";

		private const string InfoAttribute = "info";

		private const string SourceAttribute = "source";

		private const string TypeAttribute = "type";

		internal static SqlNotification ProcessMessage(SqlXml xmlMessage)
		{
			using XmlReader xmlReader = xmlMessage.CreateReader();
			_ = string.Empty;
			MessageAttributes messageAttributes = MessageAttributes.None;
			SqlNotificationType type = SqlNotificationType.Unknown;
			SqlNotificationInfo info = SqlNotificationInfo.Unknown;
			SqlNotificationSource source = SqlNotificationSource.Unknown;
			string key = string.Empty;
			xmlReader.Read();
			if (XmlNodeType.Element == xmlReader.NodeType && "QueryNotification" == xmlReader.LocalName && 3 <= xmlReader.AttributeCount)
			{
				while (MessageAttributes.All != messageAttributes && xmlReader.MoveToNextAttribute())
				{
					try
					{
						switch (xmlReader.LocalName)
						{
						case "type":
							try
							{
								SqlNotificationType sqlNotificationType = (SqlNotificationType)Enum.Parse(typeof(SqlNotificationType), xmlReader.Value, ignoreCase: true);
								if (Enum.IsDefined(typeof(SqlNotificationType), sqlNotificationType))
								{
									type = sqlNotificationType;
								}
							}
							catch (Exception e2)
							{
								if (!ADP.IsCatchableExceptionType(e2))
								{
									throw;
								}
								ADP.TraceExceptionWithoutRethrow(e2);
							}
							messageAttributes |= MessageAttributes.Type;
							break;
						case "source":
							try
							{
								SqlNotificationSource sqlNotificationSource = (SqlNotificationSource)Enum.Parse(typeof(SqlNotificationSource), xmlReader.Value, ignoreCase: true);
								if (Enum.IsDefined(typeof(SqlNotificationSource), sqlNotificationSource))
								{
									source = sqlNotificationSource;
								}
							}
							catch (Exception e3)
							{
								if (!ADP.IsCatchableExceptionType(e3))
								{
									throw;
								}
								ADP.TraceExceptionWithoutRethrow(e3);
							}
							messageAttributes |= MessageAttributes.Source;
							break;
						case "info":
							try
							{
								string value = xmlReader.Value;
								switch (value)
								{
								case "set options":
									info = SqlNotificationInfo.Options;
									break;
								case "previous invalid":
									info = SqlNotificationInfo.PreviousFire;
									break;
								case "query template limit":
									info = SqlNotificationInfo.TemplateLimit;
									break;
								default:
								{
									SqlNotificationInfo sqlNotificationInfo = (SqlNotificationInfo)Enum.Parse(typeof(SqlNotificationInfo), value, ignoreCase: true);
									if (Enum.IsDefined(typeof(SqlNotificationInfo), sqlNotificationInfo))
									{
										info = sqlNotificationInfo;
									}
									break;
								}
								}
							}
							catch (Exception e)
							{
								if (!ADP.IsCatchableExceptionType(e))
								{
									throw;
								}
								ADP.TraceExceptionWithoutRethrow(e);
							}
							messageAttributes |= MessageAttributes.Info;
							break;
						}
					}
					catch (ArgumentException e4)
					{
						ADP.TraceExceptionWithoutRethrow(e4);
						return null;
					}
				}
				if (MessageAttributes.All != messageAttributes)
				{
					return null;
				}
				if (!xmlReader.Read())
				{
					return null;
				}
				if (XmlNodeType.Element != xmlReader.NodeType || string.Compare(xmlReader.LocalName, "Message", StringComparison.OrdinalIgnoreCase) != 0)
				{
					return null;
				}
				if (!xmlReader.Read())
				{
					return null;
				}
				if (xmlReader.NodeType != XmlNodeType.Text)
				{
					return null;
				}
				using (XmlTextReader xmlTextReader = new XmlTextReader(xmlReader.Value, XmlNodeType.Element, null))
				{
					if (!xmlTextReader.Read())
					{
						return null;
					}
					if (xmlTextReader.NodeType != XmlNodeType.Text)
					{
						return null;
					}
					key = xmlTextReader.Value;
					xmlTextReader.Close();
				}
				return new SqlNotification(info, source, type, key);
			}
			return null;
		}
	}

	private class SqlConnectionContainerHashHelper
	{
		private DbConnectionPoolIdentity _identity;

		private string _connectionString;

		private string _queue;

		private SqlConnectionStringBuilder _connectionStringBuilder;

		internal SqlConnectionStringBuilder ConnectionStringBuilder => _connectionStringBuilder;

		internal DbConnectionPoolIdentity Identity => _identity;

		internal string Queue => _queue;

		internal SqlConnectionContainerHashHelper(DbConnectionPoolIdentity identity, string connectionString, string queue, SqlConnectionStringBuilder connectionStringBuilder)
		{
			_identity = identity;
			_connectionString = connectionString;
			_queue = queue;
			_connectionStringBuilder = connectionStringBuilder;
		}

		public override bool Equals(object value)
		{
			SqlConnectionContainerHashHelper sqlConnectionContainerHashHelper = (SqlConnectionContainerHashHelper)value;
			bool flag = false;
			if (sqlConnectionContainerHashHelper == null)
			{
				return false;
			}
			if (this == sqlConnectionContainerHashHelper)
			{
				return true;
			}
			if ((_identity != null && sqlConnectionContainerHashHelper._identity == null) || (_identity == null && sqlConnectionContainerHashHelper._identity != null))
			{
				return false;
			}
			if (_identity == null && sqlConnectionContainerHashHelper._identity == null)
			{
				if (sqlConnectionContainerHashHelper._connectionString == _connectionString && string.Equals(sqlConnectionContainerHashHelper._queue, _queue, StringComparison.OrdinalIgnoreCase))
				{
					return true;
				}
				return false;
			}
			if (sqlConnectionContainerHashHelper._identity.Equals(_identity) && sqlConnectionContainerHashHelper._connectionString == _connectionString && string.Equals(sqlConnectionContainerHashHelper._queue, _queue, StringComparison.OrdinalIgnoreCase))
			{
				return true;
			}
			return false;
		}

		public override int GetHashCode()
		{
			int num = 0;
			if (_identity != null)
			{
				num = _identity.GetHashCode();
			}
			if (_queue != null)
			{
				return _connectionString.GetHashCode() + _queue.GetHashCode() + num;
			}
			return _connectionString.GetHashCode() + num;
		}
	}

	private static SqlDependencyProcessDispatcher s_staticInstance = new SqlDependencyProcessDispatcher(null);

	private Dictionary<SqlConnectionContainerHashHelper, SqlConnectionContainer> _connectionContainers;

	private Dictionary<string, SqlDependencyPerAppDomainDispatcher> _sqlDependencyPerAppDomainDispatchers;

	internal static SqlDependencyProcessDispatcher SingletonProcessDispatcher => s_staticInstance;

	private SqlDependencyProcessDispatcher(object dummyVariable)
	{
		_connectionContainers = new Dictionary<SqlConnectionContainerHashHelper, SqlConnectionContainer>();
		_sqlDependencyPerAppDomainDispatchers = new Dictionary<string, SqlDependencyPerAppDomainDispatcher>();
	}

	public SqlDependencyProcessDispatcher()
	{
	}

	private static SqlConnectionContainerHashHelper GetHashHelper(string connectionString, out SqlConnectionStringBuilder connectionStringBuilder, out DbConnectionPoolIdentity identity, out string user, string queue)
	{
		connectionStringBuilder = new SqlConnectionStringBuilder(connectionString)
		{
			Pooling = false,
			Enlist = false,
			ConnectRetryCount = 0
		};
		if (queue != null)
		{
			connectionStringBuilder.ApplicationName = queue;
		}
		if (connectionStringBuilder.IntegratedSecurity)
		{
			identity = DbConnectionPoolIdentity.GetCurrent();
			user = null;
		}
		else
		{
			identity = null;
			user = connectionStringBuilder.UserID;
		}
		return new SqlConnectionContainerHashHelper(identity, connectionStringBuilder.ConnectionString, queue, connectionStringBuilder);
	}

	public override object InitializeLifetimeService()
	{
		return null;
	}

	private void Invalidate(string server, SqlNotification sqlNotification)
	{
		lock (_sqlDependencyPerAppDomainDispatchers)
		{
			foreach (KeyValuePair<string, SqlDependencyPerAppDomainDispatcher> sqlDependencyPerAppDomainDispatcher in _sqlDependencyPerAppDomainDispatchers)
			{
				SqlDependencyPerAppDomainDispatcher value = sqlDependencyPerAppDomainDispatcher.Value;
				try
				{
					value.InvalidateServer(server, sqlNotification);
				}
				catch (Exception e)
				{
					if (!ADP.IsCatchableExceptionType(e))
					{
						throw;
					}
					ADP.TraceExceptionWithoutRethrow(e);
				}
			}
		}
	}

	internal void QueueAppDomainUnloading(string appDomainKey)
	{
		ThreadPool.QueueUserWorkItem(AppDomainUnloading, appDomainKey);
	}

	private void AppDomainUnloading(object state)
	{
		string text = (string)state;
		lock (_connectionContainers)
		{
			List<SqlConnectionContainerHashHelper> list = new List<SqlConnectionContainerHashHelper>();
			foreach (KeyValuePair<SqlConnectionContainerHashHelper, SqlConnectionContainer> connectionContainer in _connectionContainers)
			{
				SqlConnectionContainer value = connectionContainer.Value;
				if (value.AppDomainUnload(text))
				{
					list.Add(value.HashHelper);
				}
			}
			foreach (SqlConnectionContainerHashHelper item in list)
			{
				_connectionContainers.Remove(item);
			}
		}
		lock (_sqlDependencyPerAppDomainDispatchers)
		{
			_sqlDependencyPerAppDomainDispatchers.Remove(text);
		}
	}

	internal bool StartWithDefault(string connectionString, out string server, out DbConnectionPoolIdentity identity, out string user, out string database, ref string service, string appDomainKey, SqlDependencyPerAppDomainDispatcher dispatcher, out bool errorOccurred, out bool appDomainStart)
	{
		return Start(connectionString, out server, out identity, out user, out database, ref service, appDomainKey, dispatcher, out errorOccurred, out appDomainStart, useDefaults: true);
	}

	internal bool Start(string connectionString, string queue, string appDomainKey, SqlDependencyPerAppDomainDispatcher dispatcher)
	{
		string server;
		DbConnectionPoolIdentity identity;
		bool errorOccurred;
		return Start(connectionString, out server, out identity, out server, out server, ref queue, appDomainKey, dispatcher, out errorOccurred, out errorOccurred, useDefaults: false);
	}

	private bool Start(string connectionString, out string server, out DbConnectionPoolIdentity identity, out string user, out string database, ref string queueService, string appDomainKey, SqlDependencyPerAppDomainDispatcher dispatcher, out bool errorOccurred, out bool appDomainStart, bool useDefaults)
	{
		server = null;
		identity = null;
		user = null;
		database = null;
		errorOccurred = false;
		appDomainStart = false;
		lock (_sqlDependencyPerAppDomainDispatchers)
		{
			if (!_sqlDependencyPerAppDomainDispatchers.ContainsKey(appDomainKey))
			{
				_sqlDependencyPerAppDomainDispatchers[appDomainKey] = dispatcher;
			}
		}
		SqlConnectionStringBuilder connectionStringBuilder;
		SqlConnectionContainerHashHelper hashHelper = GetHashHelper(connectionString, out connectionStringBuilder, out identity, out user, queueService);
		bool result = false;
		SqlConnectionContainer sqlConnectionContainer = null;
		lock (_connectionContainers)
		{
			if (!_connectionContainers.ContainsKey(hashHelper))
			{
				sqlConnectionContainer = new SqlConnectionContainer(hashHelper, appDomainKey, useDefaults);
				_connectionContainers.Add(hashHelper, sqlConnectionContainer);
				result = true;
				appDomainStart = true;
			}
			else
			{
				sqlConnectionContainer = _connectionContainers[hashHelper];
				if (sqlConnectionContainer.InErrorState)
				{
					errorOccurred = true;
				}
				else
				{
					sqlConnectionContainer.IncrementStartCount(appDomainKey, out appDomainStart);
				}
			}
		}
		if (useDefaults && !errorOccurred)
		{
			server = sqlConnectionContainer.Server;
			database = sqlConnectionContainer.Database;
			queueService = sqlConnectionContainer.Queue;
		}
		return result;
	}

	internal bool Stop(string connectionString, out string server, out DbConnectionPoolIdentity identity, out string user, out string database, ref string queueService, string appDomainKey, out bool appDomainStop)
	{
		server = null;
		identity = null;
		user = null;
		database = null;
		appDomainStop = false;
		SqlConnectionStringBuilder connectionStringBuilder;
		SqlConnectionContainerHashHelper hashHelper = GetHashHelper(connectionString, out connectionStringBuilder, out identity, out user, queueService);
		bool result = false;
		lock (_connectionContainers)
		{
			if (_connectionContainers.ContainsKey(hashHelper))
			{
				SqlConnectionContainer sqlConnectionContainer = _connectionContainers[hashHelper];
				server = sqlConnectionContainer.Server;
				database = sqlConnectionContainer.Database;
				queueService = sqlConnectionContainer.Queue;
				if (sqlConnectionContainer.Stop(appDomainKey, out appDomainStop))
				{
					result = true;
					_connectionContainers.Remove(hashHelper);
				}
			}
		}
		return result;
	}
}
internal static class AssemblyRef
{
	internal const string SystemConfiguration = "System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	internal const string System = "System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";

	public const string EcmaPublicKey = "b77a5c561934e089";

	public const string FrameworkPublicKeyFull = "00000000000000000400000000000000";

	public const string FrameworkPublicKeyFull2 = "00000000000000000400000000000000";

	public const string MicrosoftPublicKey = "b03f5f7f11d50a3a";

	public const string MicrosoftJScript = "Microsoft.JScript, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string MicrosoftVSDesigner = "Microsoft.VSDesigner, Version=0.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string SystemData = "System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string SystemDesign = "System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string SystemDrawing = "System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string SystemWeb = "System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string SystemWebExtensions = "System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";

	public const string SystemWindowsForms = "System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";
}
internal static class Consts
{
	public const string MonoCorlibVersion = "1A5E0066-58DC-428A-B21C-0AD6CDAE2789";

	public const string MonoVersion = "6.13.0.0";

	public const string MonoCompany = "Mono development team";

	public const string MonoProduct = "Mono Common Language Infrastructure";

	public const string MonoCopyright = "(c) Various Mono authors";

	public const string FxVersion = "4.0.0.0";

	public const string FxFileVersion = "4.6.57.0";

	public const string EnvironmentVersion = "4.0.30319.42000";

	public const string VsVersion = "0.0.0.0";

	public const string VsFileVersion = "11.0.0.0";

	private const string PublicKeyToken = "b77a5c561934e089";

	public const string AssemblyI18N = "I18N, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756";

	public const string AssemblyMicrosoft_JScript = "Microsoft.JScript, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblyMicrosoft_VisualStudio = "Microsoft.VisualStudio, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblyMicrosoft_VisualStudio_Web = "Microsoft.VisualStudio.Web, Version=0.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblyMicrosoft_VSDesigner = "Microsoft.VSDesigner, Version=0.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblyMono_Http = "Mono.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756";

	public const string AssemblyMono_Posix = "Mono.Posix, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756";

	public const string AssemblyMono_Security = "Mono.Security, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756";

	public const string AssemblyMono_Messaging_RabbitMQ = "Mono.Messaging.RabbitMQ, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756";

	public const string AssemblyCorlib = "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string AssemblySystem = "System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string AssemblySystem_Data = "System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string AssemblySystem_Design = "System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_DirectoryServices = "System.DirectoryServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_Drawing = "System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_Drawing_Design = "System.Drawing.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_Messaging = "System.Messaging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_Security = "System.Security, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_ServiceProcess = "System.ServiceProcess, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_Web = "System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_Windows_Forms = "System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string AssemblySystem_2_0 = "System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string AssemblySystemCore_3_5 = "System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string AssemblySystem_Core = "System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string WindowsBase_3_0 = "WindowsBase, Version=3.0.0.0, PublicKeyToken=31bf3856ad364e35";

	public const string AssemblyWindowsBase = "WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";

	public const string AssemblyPresentationCore_3_5 = "PresentationCore, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";

	public const string AssemblyPresentationCore_4_0 = "PresentationCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";

	public const string AssemblyPresentationFramework_3_5 = "PresentationFramework, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";

	public const string AssemblySystemServiceModel_3_0 = "System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";
}
internal sealed class Locale
{
	private Locale()
	{
	}

	public static string GetText(string msg)
	{
		return msg;
	}

	public static string GetText(string fmt, params object[] args)
	{
		return string.Format(fmt, args);
	}
}
internal static class SR
{
	public const string ADP_CollectionIndexString = "An {0} with {1} '{2}' is not contained by this {3}.";

	public const string ADP_CollectionInvalidType = "The {0} only accepts non-null {1} type objects, not {2} objects.";

	public const string ADP_CollectionIsNotParent = "The {0} is already contained by another {1}.";

	public const string ADP_CollectionNullValue = "The {0} only accepts non-null {1} type objects.";

	public const string ADP_CollectionRemoveInvalidObject = "Attempted to remove an {0} that is not contained by this {1}.";

	public const string ADP_CollectionUniqueValue = "The {0}.{1} is required to be unique, '{2}' already exists in the collection.";

	public const string ADP_ConnectionStateMsg_Closed = "The connection's current state is closed.";

	public const string ADP_ConnectionStateMsg_Connecting = "The connection's current state is connecting.";

	public const string ADP_ConnectionStateMsg_Open = "The connection's current state is open.";

	public const string ADP_ConnectionStateMsg_OpenExecuting = "The connection's current state is executing.";

	public const string ADP_ConnectionStateMsg_OpenFetching = "The connection's current state is fetching.";

	public const string ADP_ConnectionStateMsg = "The connection's current state: {0}.";

	public const string ADP_ConnectionStringSyntax = "Format of the initialization string does not conform to specification starting at index {0}.";

	public const string ADP_DataReaderClosed = "Invalid attempt to call {0} when reader is closed.";

	public const string ADP_EmptyString = "Expecting non-empty string for '{0}' parameter.";

	public const string ADP_InvalidEnumerationValue = "The {0} enumeration value, {1}, is invalid.";

	public const string ADP_InvalidKey = "Invalid keyword, contain one or more of 'no characters', 'control characters', 'leading or trailing whitespace' or 'leading semicolons'.";

	public const string ADP_InvalidValue = "The value contains embedded nulls (\\\\u0000).";

	public const string Xml_SimpleTypeNotSupported = "DataSet doesn't support 'union' or 'list' as simpleType.";

	public const string Xml_MissingAttribute = "Invalid {0} syntax: missing required '{1}' attribute.";

	public const string Xml_ValueOutOfRange = "Value '{1}' is invalid for attribute '{0}'.";

	public const string Xml_AttributeValues = "The value of attribute '{0}' should be '{1}' or '{2}'.";

	public const string Xml_RelationParentNameMissing = "Parent table name is missing in relation '{0}'.";

	public const string Xml_RelationChildNameMissing = "Child table name is missing in relation '{0}'.";

	public const string Xml_RelationTableKeyMissing = "Parent table key is missing in relation '{0}'.";

	public const string Xml_RelationChildKeyMissing = "Child table key is missing in relation '{0}'.";

	public const string Xml_UndefinedDatatype = "Undefined data type: '{0}'.";

	public const string Xml_DatatypeNotDefined = "Data type not defined.";

	public const string Xml_InvalidField = "Invalid XPath selection inside field node. Cannot find: {0}.";

	public const string Xml_InvalidSelector = "Invalid XPath selection inside selector node: {0}.";

	public const string Xml_InvalidKey = "Invalid 'Key' node inside constraint named: {0}.";

	public const string Xml_DuplicateConstraint = "The constraint name {0} is already used in the schema.";

	public const string Xml_CannotConvert = " Cannot convert '{0}' to type '{1}'.";

	public const string Xml_MissingRefer = "Missing '{0}' part in '{1}' constraint named '{2}'.";

	public const string Xml_MismatchKeyLength = "Invalid Relation definition: different length keys.";

	public const string Xml_CircularComplexType = "DataSet doesn't allow the circular reference in the ComplexType named '{0}'.";

	public const string Xml_CannotInstantiateAbstract = "DataSet cannot instantiate an abstract ComplexType for the node {0}.";

	public const string Xml_MultipleTargetConverterError = "An error occurred with the multiple target converter while writing an Xml Schema.  See the inner exception for details.";

	public const string Xml_MultipleTargetConverterEmpty = "An error occurred with the multiple target converter while writing an Xml Schema.  A null or empty string was returned.";

	public const string Xml_MergeDuplicateDeclaration = "Duplicated declaration '{0}'.";

	public const string Xml_MissingTable = "Cannot load diffGram. Table '{0}' is missing in the destination dataset.";

	public const string Xml_MissingSQL = "Cannot load diffGram. The 'sql' node is missing.";

	public const string Xml_ColumnConflict = "Column name '{0}' is defined for different mapping types.";

	public const string Xml_InvalidPrefix = "Prefix '{0}' is not valid, because it contains special characters.";

	public const string Xml_NestedCircular = "Circular reference in self-nested table '{0}'.";

	public const string Xml_FoundEntity = "DataSet cannot expand entities. Use XmlValidatingReader and set the EntityHandling property accordingly.";

	public const string Xml_PolymorphismNotSupported = "Type '{0}' does not implement IXmlSerializable interface therefore can not proceed with serialization.";

	public const string Xml_CanNotDeserializeObjectType = "Unable to proceed with deserialization. Data does not implement IXMLSerializable, therefore polymorphism is not supported.";

	public const string Xml_DataTableInferenceNotSupported = "DataTable does not support schema inference from Xml.";

	public const string Xml_MultipleParentRows = "Cannot proceed with serializing DataTable '{0}'. It contains a DataRow which has multiple parent rows on the same Foreign Key.";

	public const string Xml_IsDataSetAttributeMissingInSchema = "IsDataSet attribute is missing in input Schema.";

	public const string Xml_TooManyIsDataSetAtributeInSchema = "Cannot determine the DataSet Element. IsDataSet attribute exist more than once.";

	public const string Xml_DynamicWithoutXmlSerializable = "DataSet will not serialize types that implement IDynamicMetaObjectProvider but do not also implement IXmlSerializable.";

	public const string Expr_NYI = "The feature not implemented. {0}.";

	public const string Expr_MissingOperand = "Syntax error: Missing operand after '{0}' operator.";

	public const string Expr_TypeMismatch = "Type mismatch in expression '{0}'.";

	public const string Expr_ExpressionTooComplex = "Expression is too complex.";

	public const string Expr_UnboundName = "Cannot find column [{0}].";

	public const string Expr_InvalidString = "The expression contains an invalid string constant: {0}.";

	public const string Expr_UndefinedFunction = "The expression contains undefined function call {0}().";

	public const string Expr_Syntax = "Syntax error in the expression.";

	public const string Expr_FunctionArgumentCount = "Invalid number of arguments: function {0}().";

	public const string Expr_MissingRightParen = "The expression is missing the closing parenthesis.";

	public const string Expr_UnknownToken = "Cannot interpret token '{0}' at position {1}.";

	public const string Expr_UnknownToken1 = "Expected {0}, but actual token at the position {2} is {1}.";

	public const string Expr_DatatypeConvertion = "Cannot convert from {0} to {1}.";

	public const string Expr_DatavalueConvertion = "Cannot convert value '{0}' to Type: {1}.";

	public const string Expr_InvalidName = "Invalid column name [{0}].";

	public const string Expr_InvalidDate = "The expression contains invalid date constant '{0}'.";

	public const string Expr_NonConstantArgument = "Only constant expressions are allowed in the expression list for the IN operator.";

	public const string Expr_InvalidPattern = "Error in Like operator: the string pattern '{0}' is invalid.";

	public const string Expr_InWithoutParentheses = "Syntax error: The items following the IN keyword must be separated by commas and be enclosed in parentheses.";

	public const string Expr_ArgumentType = "Type mismatch in function argument: {0}(), argument {1}, expected {2}.";

	public const string Expr_ArgumentTypeInteger = "Type mismatch in function argument: {0}(), argument {1}, expected one of the Integer types.";

	public const string Expr_TypeMismatchInBinop = "Cannot perform '{0}' operation on {1} and {2}.";

	public const string Expr_AmbiguousBinop = "Operator '{0}' is ambiguous on operands of type '{1}' and '{2}'. Cannot mix signed and unsigned types. Please use explicit Convert() function.";

	public const string Expr_InWithoutList = "Syntax error: The IN keyword must be followed by a non-empty list of expressions separated by commas, and also must be enclosed in parentheses.";

	public const string Expr_UnsupportedOperator = "The expression contains unsupported operator '{0}'.";

	public const string Expr_InvalidNameBracketing = "The expression contains invalid name: '{0}'.";

	public const string Expr_MissingOperandBefore = "Syntax error: Missing operand before '{0}' operator.";

	public const string Expr_TooManyRightParentheses = "The expression has too many closing parentheses.";

	public const string Expr_UnresolvedRelation = "The table [{0}] involved in more than one relation. You must explicitly mention a relation name in the expression '{1}'.";

	public const string Expr_AggregateArgument = "Syntax error in aggregate argument: Expecting a single column argument with possible 'Child' qualifier.";

	public const string Expr_AggregateUnbound = "Unbound reference in the aggregate expression '{0}'.";

	public const string Expr_EvalNoContext = "Cannot evaluate non-constant expression without current row.";

	public const string Expr_ExpressionUnbound = "Unbound reference in the expression '{0}'.";

	public const string Expr_ComputeNotAggregate = "Cannot evaluate. Expression '{0}' is not an aggregate.";

	public const string Expr_FilterConvertion = "Filter expression '{0}' does not evaluate to a Boolean term.";

	public const string Expr_InvalidType = "Invalid type name '{0}'.";

	public const string Expr_LookupArgument = "Syntax error in Lookup expression: Expecting keyword 'Parent' followed by a single column argument with possible relation qualifier: Parent[(<relation_name>)].<column_name>.";

	public const string Expr_InvokeArgument = "Need a row or a table to Invoke DataFilter.";

	public const string Expr_ArgumentOutofRange = "{0}() argument is out of range.";

	public const string Expr_IsSyntax = "Syntax error: Invalid usage of 'Is' operator. Correct syntax: <expression> Is [Not] Null.";

	public const string Expr_Overflow = "Value is either too large or too small for Type '{0}'.";

	public const string Expr_BindFailure = "Cannot find the parent relation '{0}'.";

	public const string Expr_InvalidHoursArgument = "'hours' argument is out of range. Value must be between -14 and +14.";

	public const string Expr_InvalidMinutesArgument = "'minutes' argument is out of range. Value must be between -59 and +59.";

	public const string Expr_InvalidTimeZoneRange = "Provided range for time one exceeds total of 14 hours.";

	public const string Expr_MismatchKindandTimeSpan = "Kind property of provided DateTime argument, does not match 'hours' and 'minutes' arguments.";

	public const string Expr_UnsupportedType = "A DataColumn of type '{0}' does not support expression.";

	public const string Data_EnforceConstraints = "Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.";

	public const string Data_CannotModifyCollection = "Collection itself is not modifiable.";

	public const string Data_CaseInsensitiveNameConflict = "The given name '{0}' matches at least two names in the collection object with different cases, but does not match either of them with the same case.";

	public const string Data_NamespaceNameConflict = "The given name '{0}' matches at least two names in the collection object with different namespaces.";

	public const string Data_InvalidOffsetLength = "Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection.";

	public const string Data_ArgumentOutOfRange = "'{0}' argument is out of range.";

	public const string Data_ArgumentNull = "'{0}' argument cannot be null.";

	public const string Data_ArgumentContainsNull = "'{0}' argument contains null value.";

	public const string DataColumns_OutOfRange = "Cannot find column {0}.";

	public const string DataColumns_Add1 = "Column '{0}' already belongs to this DataTable.";

	public const string DataColumns_Add2 = "Column '{0}' already belongs to another DataTable.";

	public const string DataColumns_Add3 = "Cannot have more than one SimpleContent columns in a DataTable.";

	public const string DataColumns_Add4 = "Cannot add a SimpleContent column to a table containing element columns or nested relations.";

	public const string DataColumns_AddDuplicate = "A column named '{0}' already belongs to this DataTable.";

	public const string DataColumns_AddDuplicate2 = "Cannot add a column named '{0}': a nested table with the same name already belongs to this DataTable.";

	public const string DataColumns_AddDuplicate3 = "A column named '{0}' already belongs to this DataTable: cannot set a nested table name to the same name.";

	public const string DataColumns_Remove = "Cannot remove a column that doesn't belong to this table.";

	public const string DataColumns_RemovePrimaryKey = "Cannot remove this column, because it's part of the primary key.";

	public const string DataColumns_RemoveChildKey = "Cannot remove this column, because it is part of the parent key for relationship {0}.";

	public const string DataColumns_RemoveConstraint = "Cannot remove this column, because it is a part of the constraint {0} on the table {1}.";

	public const string DataColumn_AutoIncrementAndExpression = "Cannot set AutoIncrement property for a computed column.";

	public const string DataColumn_AutoIncrementAndDefaultValue = "Cannot set AutoIncrement property for a column with DefaultValue set.";

	public const string DataColumn_DefaultValueAndAutoIncrement = "Cannot set a DefaultValue on an AutoIncrement column.";

	public const string DataColumn_AutoIncrementSeed = "AutoIncrementStep must be a non-zero value.";

	public const string DataColumn_NameRequired = "ColumnName is required when it is part of a DataTable.";

	public const string DataColumn_ChangeDataType = "Cannot change DataType of a column once it has data.";

	public const string DataColumn_NullDataType = "Column requires a valid DataType.";

	public const string DataColumn_DefaultValueDataType = "The DefaultValue for column {0} is of type {1} and cannot be converted to {2}.";

	public const string DataColumn_DefaultValueDataType1 = "The DefaultValue for the column is of type {0} and cannot be converted to {1}.";

	public const string DataColumn_DefaultValueColumnDataType = "The DefaultValue for column {0} is of type {1}, but the column is of type {2}.";

	public const string DataColumn_ReadOnlyAndExpression = "Cannot change ReadOnly property for the expression column.";

	public const string DataColumn_UniqueAndExpression = "Cannot change Unique property for the expression column.";

	public const string DataColumn_ExpressionAndUnique = "Cannot create an expression on a column that has AutoIncrement or Unique.";

	public const string DataColumn_ExpressionAndReadOnly = "Cannot set expression because column cannot be made ReadOnly.";

	public const string DataColumn_ExpressionAndConstraint = "Cannot set Expression property on column {0}, because it is a part of a constraint.";

	public const string DataColumn_ExpressionInConstraint = "Cannot create a constraint based on Expression column {0}.";

	public const string DataColumn_ExpressionCircular = "Cannot set Expression property due to circular reference in the expression.";

	public const string DataColumn_NullKeyValues = "Column '{0}' has null values in it.";

	public const string DataColumn_NullValues = "Column '{0}' does not allow nulls.";

	public const string DataColumn_ReadOnly = "Column '{0}' is read only.";

	public const string DataColumn_NonUniqueValues = "Column '{0}' contains non-unique values.";

	public const string DataColumn_NotInTheTable = "Column '{0}' does not belong to table {1}.";

	public const string DataColumn_NotInAnyTable = "Column must belong to a table.";

	public const string DataColumn_SetFailed = "Couldn't store <{0}> in {1} Column.  Expected type is {2}.";

	public const string DataColumn_CannotSetToNull = "Cannot set Column '{0}' to be null. Please use DBNull instead.";

	public const string DataColumn_LongerThanMaxLength = "Cannot set column '{0}'. The value violates the MaxLength limit of this column.";

	public const string DataColumn_HasToBeStringType = "MaxLength applies to string data type only. You cannot set Column '{0}' property MaxLength to be non-negative number.";

	public const string DataColumn_CannotSetMaxLength = "Cannot set Column '{0}' property MaxLength to '{1}'. There is at least one string in the table longer than the new limit.";

	public const string DataColumn_CannotSetMaxLength2 = "Cannot set Column '{0}' property MaxLength. The Column is SimpleContent.";

	public const string DataColumn_CannotSimpleContentType = "Cannot set Column '{0}' property DataType to {1}. The Column is SimpleContent.";

	public const string DataColumn_CannotSimpleContent = "Cannot set Column '{0}' property MappingType to SimpleContent. The Column DataType is {1}.";

	public const string DataColumn_ExceedMaxLength = "Column '{0}' exceeds the MaxLength limit.";

	public const string DataColumn_NotAllowDBNull = "Column '{0}' does not allow DBNull.Value.";

	public const string DataColumn_CannotChangeNamespace = "Cannot change the Column '{0}' property Namespace. The Column is SimpleContent.";

	public const string DataColumn_AutoIncrementCannotSetIfHasData = "Cannot change AutoIncrement of a DataColumn with type '{0}' once it has data.";

	public const string DataColumn_NotInTheUnderlyingTable = "Column '{0}' does not belong to underlying table '{1}'.";

	public const string DataColumn_InvalidDataColumnMapping = "DataColumn with type '{0}' is a complexType. Can not serialize value of a complex type as Attribute";

	public const string DataColumn_CannotSetDateTimeModeForNonDateTimeColumns = "The DateTimeMode can be set only on DataColumns of type DateTime.";

	public const string DataColumn_DateTimeMode = "Cannot change DateTimeMode from '{0}' to '{1}' once the table has data.";

	public const string DataColumn_INullableUDTwithoutStaticNull = "Type '{0}' does not contain static Null property or field.";

	public const string DataColumn_UDTImplementsIChangeTrackingButnotIRevertible = "Type '{0}' does not implement IRevertibleChangeTracking; therefore can not proceed with RejectChanges().";

	public const string DataColumn_SetAddedAndModifiedCalledOnNonUnchanged = "SetAdded and SetModified can only be called on DataRows with Unchanged DataRowState.";

	public const string DataColumn_OrdinalExceedMaximun = "Ordinal '{0}' exceeds the maximum number.";

	public const string DataColumn_NullableTypesNotSupported = "DataSet does not support System.Nullable<>.";

	public const string DataConstraint_NoName = "Cannot change the name of a constraint to empty string when it is in the ConstraintCollection.";

	public const string DataConstraint_Violation = "Cannot enforce constraints on constraint {0}.";

	public const string DataConstraint_ViolationValue = "Column '{0}' is constrained to be unique.  Value '{1}' is already present.";

	public const string DataConstraint_NotInTheTable = "Constraint '{0}' does not belong to this DataTable.";

	public const string DataConstraint_OutOfRange = "Cannot find constraint {0}.";

	public const string DataConstraint_Duplicate = "Constraint matches constraint named {0} already in collection.";

	public const string DataConstraint_DuplicateName = "A Constraint named '{0}' already belongs to this DataTable.";

	public const string DataConstraint_UniqueViolation = "These columns don't currently have unique values.";

	public const string DataConstraint_ForeignTable = "These columns don't point to this table.";

	public const string DataConstraint_ParentValues = "This constraint cannot be enabled as not all values have corresponding parent values.";

	public const string DataConstraint_AddFailed = "This constraint cannot be added since ForeignKey doesn't belong to table {0}.";

	public const string DataConstraint_RemoveFailed = "Cannot remove a constraint that doesn't belong to this table.";

	public const string DataConstraint_NeededForForeignKeyConstraint = "Cannot remove unique constraint '{0}'. Remove foreign key constraint '{1}' first.";

	public const string DataConstraint_CascadeDelete = "Cannot delete this row because constraints are enforced on relation {0}, and deleting this row will strand child rows.";

	public const string DataConstraint_CascadeUpdate = "Cannot make this change because constraints are enforced on relation {0}, and changing this value will strand child rows.";

	public const string DataConstraint_ClearParentTable = "Cannot clear table {0} because ForeignKeyConstraint {1} enforces constraints and there are child rows in {2}.";

	public const string DataConstraint_ForeignKeyViolation = "ForeignKeyConstraint {0} requires the child key values ({1}) to exist in the parent table.";

	public const string DataConstraint_BadObjectPropertyAccess = "Property not accessible because '{0}'.";

	public const string DataConstraint_RemoveParentRow = "Cannot remove this row because it has child rows, and constraints on relation {0} are enforced.";

	public const string DataConstraint_AddPrimaryKeyConstraint = "Cannot add primary key constraint since primary key is already set for the table.";

	public const string DataConstraint_CantAddConstraintToMultipleNestedTable = "Cannot add constraint to DataTable '{0}' which is a child table in two nested relations.";

	public const string DataKey_TableMismatch = "Cannot create a Key from Columns that belong to different tables.";

	public const string DataKey_NoColumns = "Cannot have 0 columns.";

	public const string DataKey_TooManyColumns = "Cannot have more than {0} columns.";

	public const string DataKey_DuplicateColumns = "Cannot create a Key when the same column is listed more than once: '{0}'";

	public const string DataKey_RemovePrimaryKey = "Cannot remove unique constraint since it's the primary key of a table.";

	public const string DataKey_RemovePrimaryKey1 = "Cannot remove unique constraint since it's the primary key of table {0}.";

	public const string DataRelation_ColumnsTypeMismatch = "Parent Columns and Child Columns don't have type-matching columns.";

	public const string DataRelation_KeyColumnsIdentical = "ParentKey and ChildKey are identical.";

	public const string DataRelation_KeyLengthMismatch = "ParentColumns and ChildColumns should be the same length.";

	public const string DataRelation_KeyZeroLength = "ParentColumns and ChildColumns must not be zero length.";

	public const string DataRelation_ForeignRow = "The row doesn't belong to the same DataSet as this relation.";

	public const string DataRelation_NoName = "RelationName is required when it is part of a DataSet.";

	public const string DataRelation_ForeignTable = "GetChildRows requires a row whose Table is {0}, but the specified row's Table is {1}.";

	public const string DataRelation_ForeignDataSet = "This relation should connect two tables in this DataSet to be added to this DataSet.";

	public const string DataRelation_GetParentRowTableMismatch = "GetParentRow requires a row whose Table is {0}, but the specified row's Table is {1}.";

	public const string DataRelation_SetParentRowTableMismatch = "SetParentRow requires a child row whose Table is {0}, but the specified row's Table is {1}.";

	public const string DataRelation_DataSetMismatch = "Cannot have a relationship between tables in different DataSets.";

	public const string DataRelation_TablesInDifferentSets = "Cannot create a relation between tables in different DataSets.";

	public const string DataRelation_AlreadyExists = "A relation already exists for these child columns.";

	public const string DataRelation_DoesNotExist = "This relation doesn't belong to this relation collection.";

	public const string DataRelation_AlreadyInOtherDataSet = "This relation already belongs to another DataSet.";

	public const string DataRelation_AlreadyInTheDataSet = "This relation already belongs to this DataSet.";

	public const string DataRelation_DuplicateName = "A Relation named '{0}' already belongs to this DataSet.";

	public const string DataRelation_NotInTheDataSet = "Relation {0} does not belong to this DataSet.";

	public const string DataRelation_OutOfRange = "Cannot find relation {0}.";

	public const string DataRelation_TableNull = "Cannot create a collection on a null table.";

	public const string DataRelation_TableWasRemoved = "The table this collection displays relations for has been removed from its DataSet.";

	public const string DataRelation_ChildTableMismatch = "Cannot add a relation to this table's ParentRelation collection where this table isn't the child table.";

	public const string DataRelation_ParentTableMismatch = "Cannot add a relation to this table's ChildRelation collection where this table isn't the parent table.";

	public const string DataRelation_RelationNestedReadOnly = "Cannot set the 'Nested' property to false for this relation.";

	public const string DataRelation_TableCantBeNestedInTwoTables = "The same table '{0}' cannot be the child table in two nested relations.";

	public const string DataRelation_LoopInNestedRelations = "The table ({0}) cannot be the child table to itself in nested relations.";

	public const string DataRelation_CaseLocaleMismatch = "Cannot add a DataRelation or Constraint that has different Locale or CaseSensitive settings between its parent and child tables.";

	public const string DataRelation_ParentOrChildColumnsDoNotHaveDataSet = "Cannot create a DataRelation if Parent or Child Columns are not in a DataSet.";

	public const string DataRelation_InValidNestedRelation = "Nested table '{0}' which inherits its namespace cannot have multiple parent tables in different namespaces.";

	public const string DataRelation_InValidNamespaceInNestedRelation = "Nested table '{0}' with empty namespace cannot have multiple parent tables in different namespaces.";

	public const string DataRow_NotInTheDataSet = "The row doesn't belong to the same DataSet as this relation.";

	public const string DataRow_NotInTheTable = "Cannot perform this operation on a row not in the table.";

	public const string DataRow_ParentRowNotInTheDataSet = "This relation and child row don't belong to same DataSet.";

	public const string DataRow_EditInRowChanging = "Cannot change a proposed value in the RowChanging event.";

	public const string DataRow_EndEditInRowChanging = "Cannot call EndEdit() inside an OnRowChanging event.";

	public const string DataRow_BeginEditInRowChanging = "Cannot call BeginEdit() inside the RowChanging event.";

	public const string DataRow_CancelEditInRowChanging = "Cannot call CancelEdit() inside an OnRowChanging event.  Throw an exception to cancel this update.";

	public const string DataRow_DeleteInRowDeleting = "Cannot call Delete inside an OnRowDeleting event.  Throw an exception to cancel this delete.";

	public const string DataRow_ValuesArrayLength = "Input array is longer than the number of columns in this table.";

	public const string DataRow_NoCurrentData = "There is no Current data to access.";

	public const string DataRow_NoOriginalData = "There is no Original data to access.";

	public const string DataRow_NoProposedData = "There is no Proposed data to access.";

	public const string DataRow_RemovedFromTheTable = "This row has been removed from a table and does not have any data.  BeginEdit() will allow creation of new data in this row.";

	public const string DataRow_DeletedRowInaccessible = "Deleted row information cannot be accessed through the row.";

	public const string DataRow_InvalidVersion = "Version must be Original, Current, or Proposed.";

	public const string DataRow_OutOfRange = "There is no row at position {0}.";

	public const string DataRow_RowInsertOutOfRange = "The row insert position {0} is invalid.";

	public const string DataRow_RowInsertMissing = "Values are missing in the rowOrder sequence for table '{0}'.";

	public const string DataRow_RowOutOfRange = "The given DataRow is not in the current DataRowCollection.";

	public const string DataRow_AlreadyInOtherCollection = "This row already belongs to another table.";

	public const string DataRow_AlreadyInTheCollection = "This row already belongs to this table.";

	public const string DataRow_AlreadyDeleted = "Cannot delete this row since it's already deleted.";

	public const string DataRow_Empty = "This row is empty.";

	public const string DataRow_AlreadyRemoved = "Cannot remove a row that's already been removed.";

	public const string DataRow_MultipleParents = "A child row has multiple parents.";

	public const string DataRow_InvalidRowBitPattern = "Unrecognized row state bit pattern.";

	public const string DataSet_SetNameToEmpty = "Cannot change the name of the DataSet to an empty string.";

	public const string DataSet_SetDataSetNameConflicting = "The name '{0}' is invalid. A DataSet cannot have the same name of the DataTable.";

	public const string DataSet_UnsupportedSchema = "The schema namespace is invalid. Please use this one instead: {0}.";

	public const string DataSet_CannotChangeCaseLocale = "Cannot change CaseSensitive or Locale property. This change would lead to at least one DataRelation or Constraint to have different Locale or CaseSensitive settings between its related tables.";

	public const string DataSet_CannotChangeSchemaSerializationMode = "SchemaSerializationMode property can be set only if it is overridden by derived DataSet.";

	public const string DataTable_ForeignPrimaryKey = "PrimaryKey columns do not belong to this table.";

	public const string DataTable_CannotAddToSimpleContent = "Cannot add a nested relation or an element column to a table containing a SimpleContent column.";

	public const string DataTable_NoName = "TableName is required when it is part of a DataSet.";

	public const string DataTable_MultipleSimpleContentColumns = "DataTable already has a simple content column.";

	public const string DataTable_MissingPrimaryKey = "Table doesn't have a primary key.";

	public const string DataTable_InvalidSortString = " {0} isn't a valid Sort string entry.";

	public const string DataTable_CanNotSerializeDataTableHierarchy = "Cannot serialize the DataTable. A DataTable being used in one or more DataColumn expressions is not a descendant of current DataTable.";

	public const string DataTable_CanNotRemoteDataTable = "This DataTable can only be remoted as part of DataSet. One or more Expression Columns has reference to other DataTable(s).";

	public const string DataTable_CanNotSetRemotingFormat = "Cannot have different remoting format property value for DataSet and DataTable.";

	public const string DataTable_CanNotSerializeDataTableWithEmptyName = "Cannot serialize the DataTable. DataTable name is not set.";

	public const string DataTable_DuplicateName = "A DataTable named '{0}' already belongs to this DataSet.";

	public const string DataTable_DuplicateName2 = "A DataTable named '{0}' with the same Namespace '{1}' already belongs to this DataSet.";

	public const string DataTable_SelfnestedDatasetConflictingName = "The table ({0}) cannot be the child table to itself in a nested relation: the DataSet name conflicts with the table name.";

	public const string DataTable_DatasetConflictingName = "The name '{0}' is invalid. A DataTable cannot have the same name of the DataSet.";

	public const string DataTable_AlreadyInOtherDataSet = "DataTable already belongs to another DataSet.";

	public const string DataTable_AlreadyInTheDataSet = "DataTable already belongs to this DataSet.";

	public const string DataTable_NotInTheDataSet = "Table {0} does not belong to this DataSet.";

	public const string DataTable_OutOfRange = "Cannot find table {0}.";

	public const string DataTable_InRelation = "Cannot remove a table that has existing relations.  Remove relations first.";

	public const string DataTable_InConstraint = "Cannot remove table {0}, because it referenced in ForeignKeyConstraint {1}.  Remove the constraint first.";

	public const string DataTable_TableNotFound = "DataTable '{0}' does not match to any DataTable in source.";

	public const string DataMerge_MissingDefinition = "Target DataSet missing definition for {0}.";

	public const string DataMerge_MissingConstraint = "Target DataSet missing {0} {1}.";

	public const string DataMerge_DataTypeMismatch = "<target>.{0} and <source>.{0} have conflicting properties: DataType property mismatch.";

	public const string DataMerge_PrimaryKeyMismatch = "<target>.PrimaryKey and <source>.PrimaryKey have different Length.";

	public const string DataMerge_PrimaryKeyColumnsMismatch = "Mismatch columns in the PrimaryKey : <target>.{0} versus <source>.{1}.";

	public const string DataMerge_ReltionKeyColumnsMismatch = "Relation {0} cannot be merged, because keys have mismatch columns.";

	public const string DataMerge_MissingColumnDefinition = "Target table {0} missing definition for column {1}.";

	public const string DataIndex_RecordStateRange = "The RowStates parameter must be set to a valid combination of values from the DataViewRowState enumeration.";

	public const string DataIndex_FindWithoutSortOrder = "Find finds a row based on a Sort order, and no Sort order is specified.";

	public const string DataIndex_KeyLength = "Expecting {0} value(s) for the key being indexed, but received {1} value(s).";

	public const string DataStorage_AggregateException = "Invalid usage of aggregate function {0}() and Type: {1}.";

	public const string DataStorage_InvalidStorageType = "Invalid storage type: {0}.";

	public const string DataStorage_ProblematicChars = "The DataSet Xml persistency does not support the value '{0}' as Char value, please use Byte storage instead.";

	public const string DataStorage_SetInvalidDataType = "Type of value has a mismatch with column type";

	public const string DataStorage_IComparableNotDefined = " Type '{0}' does not implement IComparable interface. Comparison cannot be done.";

	public const string DataView_SetFailed = "Cannot set {0}.";

	public const string DataView_SetDataSetFailed = "Cannot change DataSet on a DataViewManager that's already the default view for a DataSet.";

	public const string DataView_SetRowStateFilter = "RowStateFilter cannot show ModifiedOriginals and ModifiedCurrents at the same time.";

	public const string DataView_SetTable = "Cannot change Table property on a DefaultView or a DataView coming from a DataViewManager.";

	public const string DataView_CanNotSetDataSet = "Cannot change DataSet property once it is set.";

	public const string DataView_CanNotUseDataViewManager = "DataSet must be set prior to using DataViewManager.";

	public const string DataView_CanNotSetTable = "Cannot change Table property once it is set.";

	public const string DataView_CanNotUse = "DataTable must be set prior to using DataView.";

	public const string DataView_CanNotBindTable = "Cannot bind to DataTable with no name.";

	public const string DataView_SetIListObject = "Cannot set an object into this list.";

	public const string DataView_AddNewNotAllowNull = "Cannot call AddNew on a DataView where AllowNew is false.";

	public const string DataView_NotOpen = "DataView is not open.";

	public const string DataView_CreateChildView = "The relation is not parented to the table to which this DataView points.";

	public const string DataView_CanNotDelete = "Cannot delete on a DataSource where AllowDelete is false.";

	public const string DataView_CanNotEdit = "Cannot edit on a DataSource where AllowEdit is false.";

	public const string DataView_GetElementIndex = "Index {0} is either negative or above rows count.";

	public const string DataView_AddExternalObject = "Cannot add external objects to this list.";

	public const string DataView_CanNotClear = "Cannot clear this list.";

	public const string DataView_InsertExternalObject = "Cannot insert external objects to this list.";

	public const string DataView_RemoveExternalObject = "Cannot remove objects not in the list.";

	public const string DataROWView_PropertyNotFound = "{0} is neither a DataColumn nor a DataRelation for table {1}.";

	public const string Range_Argument = "Min ({0}) must be less than or equal to max ({1}) in a Range object.";

	public const string Range_NullRange = "This is a null range.";

	public const string RecordManager_MinimumCapacity = "MinimumCapacity must be non-negative.";

	public const string SqlConvert_ConvertFailed = " Cannot convert object of type '{0}' to object of type '{1}'.";

	public const string DataSet_DefaultDataException = "Data Exception.";

	public const string DataSet_DefaultConstraintException = "Constraint Exception.";

	public const string DataSet_DefaultDeletedRowInaccessibleException = "Deleted rows inaccessible.";

	public const string DataSet_DefaultDuplicateNameException = "Duplicate name not allowed.";

	public const string DataSet_DefaultInRowChangingEventException = "Operation not supported in the RowChanging event.";

	public const string DataSet_DefaultInvalidConstraintException = "Invalid constraint.";

	public const string DataSet_DefaultMissingPrimaryKeyException = "Missing primary key.";

	public const string DataSet_DefaultNoNullAllowedException = "Null not allowed.";

	public const string DataSet_DefaultReadOnlyException = "Column is marked read only.";

	public const string DataSet_DefaultRowNotInTableException = "Row not found in table.";

	public const string DataSet_DefaultVersionNotFoundException = "Version not found.";

	public const string Load_ReadOnlyDataModified = "ReadOnly Data is Modified.";

	public const string DataTableReader_InvalidDataTableReader = "DataTableReader is invalid for current DataTable '{0}'.";

	public const string DataTableReader_SchemaInvalidDataTableReader = "Schema of current DataTable '{0}' in DataTableReader has changed, DataTableReader is invalid.";

	public const string DataTableReader_CannotCreateDataReaderOnEmptyDataSet = "DataTableReader Cannot be created. There is no DataTable in DataSet.";

	public const string DataTableReader_DataTableReaderArgumentIsEmpty = "Cannot create DataTableReader. Argument is Empty.";

	public const string DataTableReader_ArgumentContainsNullValue = "Cannot create DataTableReader. Arguments contain null value.";

	public const string DataTableReader_InvalidRowInDataTableReader = "Current DataRow is either in Deleted or Detached state.";

	public const string DataTableReader_DataTableCleared = "Current DataTable '{0}' is empty. There is no DataRow in DataTable.";

	public const string RbTree_InvalidState = "DataTable internal index is corrupted: '{0}'.";

	public const string RbTree_EnumerationBroken = "Collection was modified; enumeration operation might not execute.";

	public const string NamedSimpleType_InvalidDuplicateNamedSimpleTypeDelaration = "Simple type '{0}' has already be declared with different '{1}'.";

	public const string DataDom_Foliation = "Invalid foliation.";

	public const string DataDom_TableNameChange = "Cannot change the table name once the associated DataSet is mapped to a loaded XML document.";

	public const string DataDom_TableNamespaceChange = "Cannot change the table namespace once the associated DataSet is mapped to a loaded XML document.";

	public const string DataDom_ColumnNameChange = "Cannot change the column name once the associated DataSet is mapped to a loaded XML document.";

	public const string DataDom_ColumnNamespaceChange = "Cannot change the column namespace once the associated DataSet is mapped to a loaded XML document.";

	public const string DataDom_ColumnMappingChange = "Cannot change the ColumnMapping property once the associated DataSet is mapped to a loaded XML document.";

	public const string DataDom_TableColumnsChange = "Cannot add or remove columns from the table once the DataSet is mapped to a loaded XML document.";

	public const string DataDom_DataSetTablesChange = "Cannot add or remove tables from the DataSet once the DataSet is mapped to a loaded XML document.";

	public const string DataDom_DataSetNestedRelationsChange = "Cannot add, remove, or change Nested relations from the DataSet once the DataSet is mapped to a loaded XML document.";

	public const string DataDom_DataSetNull = "The DataSet parameter is invalid. It cannot be null.";

	public const string DataDom_DataSetNameChange = "Cannot change the DataSet name once the DataSet is mapped to a loaded XML document.";

	public const string DataDom_CloneNode = "This type of node cannot be cloned: {0}.";

	public const string DataDom_MultipleLoad = "Cannot load XmlDataDocument if it already contains data. Please use a new XmlDataDocument.";

	public const string DataDom_MultipleDataSet = "DataSet can be associated with at most one XmlDataDocument. Cannot associate the DataSet with the current XmlDataDocument because the DataSet is already associated with another XmlDataDocument.";

	public const string DataDom_NotSupport_GetElementById = "GetElementById() is not supported on DataDocument.";

	public const string DataDom_NotSupport_EntRef = "Cannot create entity references on DataDocument.";

	public const string DataDom_NotSupport_Clear = "Clear function on DateSet and DataTable is not supported on XmlDataDocument.";

	public const string ADP_EmptyArray = "Expecting non-empty array for '{0}' parameter.";

	public const string SQL_WrongType = "Expecting argument of type {1}, but received type {0}.";

	public const string ADP_InvalidConnectionOptionValue = "Invalid value for key '{0}'.";

	public const string ADP_KeywordNotSupported = "Keyword not supported: '{0}'.";

	public const string ADP_InternalProviderError = "Internal .Net Framework Data Provider error {0}.";

	public const string ADP_NoQuoteChange = "The QuotePrefix and QuoteSuffix properties cannot be changed once an Insert, Update, or Delete command has been generated.";

	public const string ADP_MissingSourceCommand = "The DataAdapter.SelectCommand property needs to be initialized.";

	public const string ADP_MissingSourceCommandConnection = "The DataAdapter.SelectCommand.Connection property needs to be initialized;";

	public const string ADP_InvalidMultipartName = "{0} \"{1}\".";

	public const string ADP_InvalidMultipartNameQuoteUsage = "{0} \"{1}\", incorrect usage of quotes.";

	public const string ADP_InvalidMultipartNameToManyParts = "{0} \"{1}\", the current limit of \"{2}\" is insufficient.";

	public const string ADP_ColumnSchemaExpression = "The column mapping from SourceColumn '{0}' failed because the DataColumn '{1}' is a computed column.";

	public const string ADP_ColumnSchemaMismatch = "Inconvertible type mismatch between SourceColumn '{0}' of {1} and the DataColumn '{2}' of {3}.";

	public const string ADP_ColumnSchemaMissing1 = "Missing the DataColumn '{0}' for the SourceColumn '{2}'.";

	public const string ADP_ColumnSchemaMissing2 = "Missing the DataColumn '{0}' in the DataTable '{1}' for the SourceColumn '{2}'.";

	public const string ADP_InvalidSourceColumn = "SourceColumn is required to be a non-empty string.";

	public const string ADP_MissingColumnMapping = "Missing SourceColumn mapping for '{0}'.";

	public const string ADP_NotSupportedEnumerationValue = "The {0} enumeration value, {1}, is not supported by the {2} method.";

	public const string ADP_MissingTableSchema = "Missing the '{0}' DataTable for the '{1}' SourceTable.";

	public const string ADP_InvalidSourceTable = "SourceTable is required to be a non-empty string";

	public const string ADP_MissingTableMapping = "Missing SourceTable mapping: '{0}'";

	public const string ADP_ConnectionRequired_Insert = "Update requires the InsertCommand to have a connection object. The Connection property of the InsertCommand has not been initialized.";

	public const string ADP_ConnectionRequired_Update = "Update requires the UpdateCommand to have a connection object. The Connection property of the UpdateCommand has not been initialized.";

	public const string ADP_ConnectionRequired_Delete = "Update requires the DeleteCommand to have a connection object. The Connection property of the DeleteCommand has not been initialized.";

	public const string ADP_ConnectionRequired_Batch = "Update requires a connection object.  The Connection property has not been initialized.";

	public const string ADP_ConnectionRequired_Clone = "Update requires the command clone to have a connection object. The Connection property of the command clone has not been initialized.";

	public const string ADP_OpenConnectionRequired_Insert = "Update requires the {0}Command to have an open connection object. {1}";

	public const string ADP_OpenConnectionRequired_Update = "Update requires the {0}Command to have an open connection object. {1}";

	public const string ADP_OpenConnectionRequired_Delete = "Update requires the {0}Command to have an open connection object. {1}";

	public const string ADP_OpenConnectionRequired_Clone = "Update requires the updating command to have an open connection object. {1}";

	public const string ADP_MissingSelectCommand = "The SelectCommand property has not been initialized before calling '{0}'.";

	public const string ADP_UnwantedStatementType = "The StatementType {0} is not expected here.";

	public const string ADP_FillSchemaRequiresSourceTableName = "FillSchema: expected a non-empty string for the SourceTable name.";

	public const string ADP_FillRequiresSourceTableName = "Fill: expected a non-empty string for the SourceTable name.";

	public const string ADP_FillChapterAutoIncrement = "Hierarchical chapter columns must map to an AutoIncrement DataColumn.";

	public const string ADP_MissingDataReaderFieldType = "DataReader.GetFieldType({0}) returned null.";

	public const string ADP_OnlyOneTableForStartRecordOrMaxRecords = "Only specify one item in the dataTables array when using non-zero values for startRecords or maxRecords.";

	public const string ADP_UpdateRequiresSourceTable = "Update unable to find TableMapping['{0}'] or DataTable '{0}'.";

	public const string ADP_UpdateRequiresSourceTableName = "Update: expected a non-empty SourceTable name.";

	public const string ADP_UpdateRequiresCommandClone = "Update requires the command clone to be valid.";

	public const string ADP_UpdateRequiresCommandSelect = "Auto SQL generation during Update requires a valid SelectCommand.";

	public const string ADP_UpdateRequiresCommandInsert = "Update requires a valid InsertCommand when passed DataRow collection with new rows.";

	public const string ADP_UpdateRequiresCommandUpdate = "Update requires a valid UpdateCommand when passed DataRow collection with modified rows.";

	public const string ADP_UpdateRequiresCommandDelete = "Update requires a valid DeleteCommand when passed DataRow collection with deleted rows.";

	public const string ADP_UpdateMismatchRowTable = "DataRow[{0}] is from a different DataTable than DataRow[0].";

	public const string ADP_RowUpdatedErrors = "RowUpdatedEvent: Errors occurred; no additional is information available.";

	public const string ADP_RowUpdatingErrors = "RowUpdatingEvent: Errors occurred; no additional is information available.";

	public const string ADP_ResultsNotAllowedDuringBatch = "When batching, the command's UpdatedRowSource property value of UpdateRowSource.FirstReturnedRecord or UpdateRowSource.Both is invalid.";

	public const string ADP_UpdateConcurrencyViolation_Update = "Concurrency violation: the UpdateCommand affected {0} of the expected {1} records.";

	public const string ADP_UpdateConcurrencyViolation_Delete = "Concurrency violation: the DeleteCommand affected {0} of the expected {1} records.";

	public const string ADP_UpdateConcurrencyViolation_Batch = "Concurrency violation: the batched command affected {0} of the expected {1} records.";

	public const string ADP_InvalidSourceBufferIndex = "Invalid source buffer (size of {0}) offset: {1}";

	public const string ADP_InvalidDestinationBufferIndex = "Invalid destination buffer (size of {0}) offset: {1}";

	public const string ADP_StreamClosed = "Invalid attempt to {0} when stream is closed.";

	public const string ADP_InvalidSeekOrigin = "Specified SeekOrigin value is invalid.";

	public const string ADP_DynamicSQLJoinUnsupported = "Dynamic SQL generation is not supported against multiple base tables.";

	public const string ADP_DynamicSQLNoTableInfo = "Dynamic SQL generation is not supported against a SelectCommand that does not return any base table information.";

	public const string ADP_DynamicSQLNoKeyInfoDelete = "Dynamic SQL generation for the DeleteCommand is not supported against a SelectCommand that does not return any key column information.";

	public const string ADP_DynamicSQLNoKeyInfoUpdate = "Dynamic SQL generation for the UpdateCommand is not supported against a SelectCommand that does not return any key column information.";

	public const string ADP_DynamicSQLNoKeyInfoRowVersionDelete = "Dynamic SQL generation for the DeleteCommand is not supported against a SelectCommand that does not contain a row version column.";

	public const string ADP_DynamicSQLNoKeyInfoRowVersionUpdate = "Dynamic SQL generation for the UpdateCommand is not supported against a SelectCommand that does not contain a row version column.";

	public const string ADP_DynamicSQLNestedQuote = "Dynamic SQL generation not supported against table names '{0}' that contain the QuotePrefix or QuoteSuffix character '{1}'.";

	public const string SQL_InvalidBufferSizeOrIndex = "Buffer offset '{1}' plus the bytes available '{0}' is greater than the length of the passed in buffer.";

	public const string SQL_InvalidDataLength = "Data length '{0}' is less than 0.";

	public const string SqlMisc_NullString = "Null";

	public const string SqlMisc_MessageString = "Message";

	public const string SqlMisc_ArithOverflowMessage = "Arithmetic Overflow.";

	public const string SqlMisc_DivideByZeroMessage = "Divide by zero error encountered.";

	public const string SqlMisc_NullValueMessage = "Data is Null. This method or property cannot be called on Null values.";

	public const string SqlMisc_TruncationMessage = "Numeric arithmetic causes truncation.";

	public const string SqlMisc_DateTimeOverflowMessage = "SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.";

	public const string SqlMisc_ConcatDiffCollationMessage = "Two strings to be concatenated have different collation.";

	public const string SqlMisc_CompareDiffCollationMessage = "Two strings to be compared have different collation.";

	public const string SqlMisc_InvalidFlagMessage = "Invalid flag value.";

	public const string SqlMisc_NumeToDecOverflowMessage = "Conversion from SqlDecimal to Decimal overflows.";

	public const string SqlMisc_ConversionOverflowMessage = "Conversion overflows.";

	public const string SqlMisc_InvalidDateTimeMessage = "Invalid SqlDateTime.";

	public const string SqlMisc_TimeZoneSpecifiedMessage = "A time zone was specified. SqlDateTime does not support time zones.";

	public const string SqlMisc_InvalidArraySizeMessage = "Invalid array size.";

	public const string SqlMisc_InvalidPrecScaleMessage = "Invalid numeric precision/scale.";

	public const string SqlMisc_FormatMessage = "The input wasn't in a correct format.";

	public const string SqlMisc_SqlTypeMessage = "SqlType error.";

	public const string SqlMisc_NoBufferMessage = "There is no buffer. Read or write operation failed.";

	public const string SqlMisc_BufferInsufficientMessage = "The buffer is insufficient. Read or write operation failed.";

	public const string SqlMisc_WriteNonZeroOffsetOnNullMessage = "Cannot write to non-zero offset, because current value is Null.";

	public const string SqlMisc_WriteOff

BepInExPack/mono/Managed/System.dll

Decompiled a month ago
using System;
using System.Buffers;
using System.Buffers.Binary;
using System.CodeDom;
using System.CodeDom.Compiler;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.ComponentModel.Design.Serialization;
using System.Configuration;
using System.Configuration.Internal;
using System.Configuration.Provider;
using System.Diagnostics;
using System.Diagnostics.Tracing;
using System.Globalization;
using System.IO;
using System.IO.Compression;
using System.IO.CoreFX;
using System.IO.Enumeration;
using System.IO.Ports;
using System.Linq;
using System.Net;
using System.Net.Cache;
using System.Net.Configuration;
using System.Net.Http;
using System.Net.Mail;
using System.Net.Mime;
using System.Net.NetworkInformation;
using System.Net.Security;
using System.Net.Sockets;
using System.Net.WebSockets;
using System.Numerics;
using System.Reflection;
using System.Reflection.Emit;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.ConstrainedExecution;
using System.Runtime.ExceptionServices;
using System.Runtime.InteropServices;
using System.Runtime.Remoting.Messaging;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Security;
using System.Security.AccessControl;
using System.Security.Authentication;
using System.Security.Authentication.ExtendedProtection;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using System.Security.Permissions;
using System.Security.Policy;
using System.Security.Principal;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Threading.Tasks.Sources;
using System.Timers;
using System.Xml;
using System.Xml.Serialization;
using System.Xml.XPath;
using Internal.Cryptography;
using Internal.Cryptography.Pal;
using Microsoft.CSharp;
using Microsoft.VisualBasic;
using Microsoft.Win32;
using Microsoft.Win32.SafeHandles;
using Mono;
using Mono.Audio;
using Mono.Btls;
using Mono.Http;
using Mono.Net;
using Mono.Net.Dns;
using Mono.Net.Security;
using Mono.Net.Security.Private;
using Mono.Security;
using Mono.Security.Authenticode;
using Mono.Security.Cryptography;
using Mono.Security.Interface;
using Mono.Security.Protocol.Ntlm;
using Mono.Security.X509;
using Mono.Security.X509.Extensions;
using ObjCRuntimeInternal;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("System.dll")]
[assembly: AssemblyDescription("System.dll")]
[assembly: AssemblyDefaultAlias("System.dll")]
[assembly: AssemblyCompany("Mono development team")]
[assembly: AssemblyProduct("Mono Common Language Infrastructure")]
[assembly: AssemblyCopyright("(c) Various Mono authors")]
[assembly: AssemblyFileVersion("4.6.57.0")]
[assembly: SatelliteContractVersion("4.0.0.0")]
[assembly: AssemblyInformationalVersion("4.6.57.0")]
[assembly: CLSCompliant(true)]
[assembly: NeutralResourcesLanguage("en-US")]
[assembly: ComVisible(false)]
[assembly: AllowPartiallyTrustedCallers]
[assembly: AssemblyDelaySign(true)]
[assembly: AssemblyKeyFile("../ecma.pub")]
[assembly: InternalsVisibleTo("System.ComponentModel.DataAnnotations, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")]
[assembly: InternalsVisibleTo("System.Data, PublicKey=00000000000000000400000000000000")]
[assembly: InternalsVisibleTo("System.Net.Http, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")]
[assembly: InternalsVisibleTo("System.Net.Http.WebRequest, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")]
[assembly: InternalsVisibleTo("Mono.Btls.Interface, PublicKey=002400000480000094000000060200000024000052534131000400000100010079159977d2d03a8e6bea7a2e74e8d1afcc93e8851974952bb480a12c9134474d04062447c37e0e68c080536fcf3c3fbe2ff9c979ce998475e506e8ce82dd5b0f350dc10e93bf2eeecf874b24770c5081dbea7447fddafa277b22de47d6ffea449674a4f9fccf84d15069089380284dbdd35f46cdff12a1bd78e4ef0065d016df")]
[assembly: InternalsVisibleTo("Mono.Security, PublicKey=002400000480000094000000060200000024000052534131000400000100010079159977d2d03a8e6bea7a2e74e8d1afcc93e8851974952bb480a12c9134474d04062447c37e0e68c080536fcf3c3fbe2ff9c979ce998475e506e8ce82dd5b0f350dc10e93bf2eeecf874b24770c5081dbea7447fddafa277b22de47d6ffea449674a4f9fccf84d15069089380284dbdd35f46cdff12a1bd78e4ef0065d016df")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("4.0.0.0")]
[assembly: TypeForwardedTo(typeof(Queue<>))]
[assembly: TypeForwardedTo(typeof(Stack<>))]
[assembly: TypeForwardedTo(typeof(FileSystemName))]
[assembly: TypeForwardedTo(typeof(CryptographicOperations))]
[module: UnverifiableCode]
internal static class Interop
{
	internal static class Crypt32
	{
		internal struct CRYPT_OID_INFO
		{
			public int cbSize;

			public IntPtr pszOID;

			public IntPtr pwszName;

			public OidGroup dwGroupId;

			public int AlgId;

			public int cbData;

			public IntPtr pbData;

			public string OID => Marshal.PtrToStringAnsi(pszOID);

			public string Name => Marshal.PtrToStringUni(pwszName);
		}

		internal enum CryptOidInfoKeyType
		{
			CRYPT_OID_INFO_OID_KEY = 1,
			CRYPT_OID_INFO_NAME_KEY,
			CRYPT_OID_INFO_ALGID_KEY,
			CRYPT_OID_INFO_SIGN_KEY,
			CRYPT_OID_INFO_CNG_ALGID_KEY,
			CRYPT_OID_INFO_CNG_SIGN_KEY
		}

		internal static class AuthType
		{
			internal const uint AUTHTYPE_CLIENT = 1u;

			internal const uint AUTHTYPE_SERVER = 2u;
		}

		internal static class CertChainPolicyIgnoreFlags
		{
			internal const uint CERT_CHAIN_POLICY_IGNORE_NOT_TIME_VALID_FLAG = 1u;

			internal const uint CERT_CHAIN_POLICY_IGNORE_CTL_NOT_TIME_VALID_FLAG = 2u;

			internal const uint CERT_CHAIN_POLICY_IGNORE_NOT_TIME_NESTED_FLAG = 4u;

			internal const uint CERT_CHAIN_POLICY_IGNORE_INVALID_BASIC_CONSTRAINTS_FLAG = 8u;

			internal const uint CERT_CHAIN_POLICY_ALLOW_UNKNOWN_CA_FLAG = 16u;

			internal const uint CERT_CHAIN_POLICY_IGNORE_WRONG_USAGE_FLAG = 32u;

			internal const uint CERT_CHAIN_POLICY_IGNORE_INVALID_NAME_FLAG = 64u;

			internal const uint CERT_CHAIN_POLICY_IGNORE_INVALID_POLICY_FLAG = 128u;

			internal const uint CERT_CHAIN_POLICY_IGNORE_END_REV_UNKNOWN_FLAG = 256u;

			internal const uint CERT_CHAIN_POLICY_IGNORE_CTL_SIGNER_REV_UNKNOWN_FLAG = 512u;

			internal const uint CERT_CHAIN_POLICY_IGNORE_CA_REV_UNKNOWN_FLAG = 1024u;

			internal const uint CERT_CHAIN_POLICY_IGNORE_ROOT_REV_UNKNOWN_FLAG = 2048u;

			internal const uint CERT_CHAIN_POLICY_IGNORE_ALL = 4095u;
		}

		internal static class CertChainPolicy
		{
			internal const int CERT_CHAIN_POLICY_BASE = 1;

			internal const int CERT_CHAIN_POLICY_AUTHENTICODE = 2;

			internal const int CERT_CHAIN_POLICY_AUTHENTICODE_TS = 3;

			internal const int CERT_CHAIN_POLICY_SSL = 4;

			internal const int CERT_CHAIN_POLICY_BASIC_CONSTRAINTS = 5;

			internal const int CERT_CHAIN_POLICY_NT_AUTH = 6;

			internal const int CERT_CHAIN_POLICY_MICROSOFT_ROOT = 7;

			internal const int CERT_CHAIN_POLICY_EV = 8;
		}

		internal static class CertChainPolicyErrors
		{
			internal const uint TRUST_E_CERT_SIGNATURE = 2148098052u;

			internal const uint CRYPT_E_REVOKED = 2148081680u;

			internal const uint CERT_E_UNTRUSTEDROOT = 2148204809u;

			internal const uint CERT_E_UNTRUSTEDTESTROOT = 2148204813u;

			internal const uint CERT_E_CHAINING = 2148204810u;

			internal const uint CERT_E_WRONG_USAGE = 2148204816u;

			internal const uint CERT_E_EXPIRE = 2148204801u;

			internal const uint CERT_E_INVALID_NAME = 2148204820u;

			internal const uint CERT_E_INVALID_POLICY = 2148204819u;

			internal const uint TRUST_E_BASIC_CONSTRAINTS = 2148098073u;

			internal const uint CERT_E_CRITICAL = 2148204805u;

			internal const uint CERT_E_VALIDITYPERIODNESTING = 2148204802u;

			internal const uint CRYPT_E_NO_REVOCATION_CHECK = 2148081682u;

			internal const uint CRYPT_E_REVOCATION_OFFLINE = 2148081683u;

			internal const uint CERT_E_PURPOSE = 2148204806u;

			internal const uint CERT_E_REVOKED = 2148204812u;

			internal const uint CERT_E_REVOCATION_FAILURE = 2148204814u;

			internal const uint CERT_E_CN_NO_MATCH = 2148204815u;

			internal const uint CERT_E_ROLE = 2148204803u;
		}

		[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
		internal struct CERT_CONTEXT
		{
			internal uint dwCertEncodingType;

			internal IntPtr pbCertEncoded;

			internal uint cbCertEncoded;

			internal IntPtr pCertInfo;

			internal IntPtr hCertStore;
		}

		[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
		internal struct SSL_EXTRA_CERT_CHAIN_POLICY_PARA
		{
			internal uint cbSize;

			internal uint dwAuthType;

			internal uint fdwChecks;

			internal unsafe char* pwszServerName;
		}

		[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
		internal struct CERT_CHAIN_POLICY_PARA
		{
			public uint cbSize;

			public uint dwFlags;

			public unsafe SSL_EXTRA_CERT_CHAIN_POLICY_PARA* pvExtraPolicyPara;
		}

		[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
		internal struct CERT_CHAIN_POLICY_STATUS
		{
			public uint cbSize;

			public uint dwError;

			public int lChainIndex;

			public int lElementIndex;

			public unsafe void* pvExtraPolicyStatus;
		}

		internal static CRYPT_OID_INFO FindOidInfo(CryptOidInfoKeyType keyType, string key, OidGroup group, bool fallBackToAllGroups)
		{
			IntPtr intPtr = IntPtr.Zero;
			try
			{
				intPtr = keyType switch
				{
					CryptOidInfoKeyType.CRYPT_OID_INFO_OID_KEY => Marshal.StringToCoTaskMemAnsi(key), 
					CryptOidInfoKeyType.CRYPT_OID_INFO_NAME_KEY => Marshal.StringToCoTaskMemUni(key), 
					_ => throw new NotSupportedException(), 
				};
				if (!OidGroupWillNotUseActiveDirectory(group))
				{
					OidGroup group2 = group | (OidGroup)(-2147483648);
					IntPtr intPtr2 = CryptFindOIDInfo(keyType, intPtr, group2);
					if (intPtr2 != IntPtr.Zero)
					{
						return Marshal.PtrToStructure<CRYPT_OID_INFO>(intPtr2);
					}
				}
				IntPtr intPtr3 = CryptFindOIDInfo(keyType, intPtr, group);
				if (intPtr3 != IntPtr.Zero)
				{
					return Marshal.PtrToStructure<CRYPT_OID_INFO>(intPtr3);
				}
				if (fallBackToAllGroups && group != 0)
				{
					IntPtr intPtr4 = CryptFindOIDInfo(keyType, intPtr, OidGroup.All);
					if (intPtr4 != IntPtr.Zero)
					{
						return Marshal.PtrToStructure<CRYPT_OID_INFO>(intPtr4);
					}
				}
				CRYPT_OID_INFO result = default(CRYPT_OID_INFO);
				result.AlgId = -1;
				return result;
			}
			finally
			{
				if (intPtr != IntPtr.Zero)
				{
					Marshal.FreeCoTaskMem(intPtr);
				}
			}
		}

		private static bool OidGroupWillNotUseActiveDirectory(OidGroup group)
		{
			if (group != OidGroup.HashAlgorithm && group != OidGroup.EncryptionAlgorithm && group != OidGroup.PublicKeyAlgorithm && group != OidGroup.SignatureAlgorithm && group != OidGroup.Attribute && group != OidGroup.ExtensionOrAttribute)
			{
				return group == OidGroup.KeyDerivationFunction;
			}
			return true;
		}

		[DllImport("crypt32.dll", CharSet = CharSet.Unicode)]
		private static extern IntPtr CryptFindOIDInfo(CryptOidInfoKeyType dwKeyType, IntPtr pvKey, OidGroup group);

		[DllImport("crypt32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
		[return: MarshalAs(UnmanagedType.Bool)]
		internal static extern bool CertFreeCertificateContext(IntPtr pCertContext);

		[DllImport("crypt32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
		[return: MarshalAs(UnmanagedType.Bool)]
		internal static extern bool CertVerifyCertificateChainPolicy(IntPtr pszPolicyOID, SafeX509ChainHandle pChainContext, [In] ref CERT_CHAIN_POLICY_PARA pPolicyPara, [In][Out] ref CERT_CHAIN_POLICY_STATUS pPolicyStatus);
	}

	internal enum BOOL
	{
		FALSE,
		TRUE
	}

	internal static class Libraries
	{
		internal const string Advapi32 = "advapi32.dll";

		internal const string BCrypt = "BCrypt.dll";

		internal const string CoreComm_L1_1_1 = "api-ms-win-core-comm-l1-1-1.dll";

		internal const string Crypt32 = "crypt32.dll";

		internal const string Error_L1 = "api-ms-win-core-winrt-error-l1-1-0.dll";

		internal const string HttpApi = "httpapi.dll";

		internal const string IpHlpApi = "iphlpapi.dll";

		internal const string Kernel32 = "kernel32.dll";

		internal const string Memory_L1_3 = "api-ms-win-core-memory-l1-1-3.dll";

		internal const string Mswsock = "mswsock.dll";

		internal const string NCrypt = "ncrypt.dll";

		internal const string NtDll = "ntdll.dll";

		internal const string Odbc32 = "odbc32.dll";

		internal const string OleAut32 = "oleaut32.dll";

		internal const string PerfCounter = "perfcounter.dll";

		internal const string RoBuffer = "api-ms-win-core-winrt-robuffer-l1-1-0.dll";

		internal const string Secur32 = "secur32.dll";

		internal const string Shell32 = "shell32.dll";

		internal const string SspiCli = "sspicli.dll";

		internal const string User32 = "user32.dll";

		internal const string Version = "version.dll";

		internal const string WebSocket = "websocket.dll";

		internal const string WinHttp = "winhttp.dll";

		internal const string Ws2_32 = "ws2_32.dll";

		internal const string Wtsapi32 = "wtsapi32.dll";

		internal const string CompressionNative = "clrcompression.dll";
	}

	internal enum SECURITY_STATUS
	{
		OK = 0,
		ContinueNeeded = 590610,
		CompleteNeeded = 590611,
		CompAndContinue = 590612,
		ContextExpired = 590615,
		CredentialsNeeded = 590624,
		Renegotiate = 590625,
		OutOfMemory = -2146893056,
		InvalidHandle = -2146893055,
		Unsupported = -2146893054,
		TargetUnknown = -2146893053,
		InternalError = -2146893052,
		PackageNotFound = -2146893051,
		NotOwner = -2146893050,
		CannotInstall = -2146893049,
		InvalidToken = -2146893048,
		CannotPack = -2146893047,
		QopNotSupported = -2146893046,
		NoImpersonation = -2146893045,
		LogonDenied = -2146893044,
		UnknownCredentials = -2146893043,
		NoCredentials = -2146893042,
		MessageAltered = -2146893041,
		OutOfSequence = -2146893040,
		NoAuthenticatingAuthority = -2146893039,
		IncompleteMessage = -2146893032,
		IncompleteCredentials = -2146893024,
		BufferNotEnough = -2146893023,
		WrongPrincipal = -2146893022,
		TimeSkew = -2146893020,
		UntrustedRoot = -2146893019,
		IllegalMessage = -2146893018,
		CertUnknown = -2146893017,
		CertExpired = -2146893016,
		AlgorithmMismatch = -2146893007,
		SecurityQosFailed = -2146893006,
		SmartcardLogonRequired = -2146892994,
		UnsupportedPreauth = -2146892989,
		BadBinding = -2146892986,
		DowngradeDetected = -2146892976,
		ApplicationProtocolMismatch = -2146892953
	}

	internal enum ApplicationProtocolNegotiationStatus
	{
		None,
		Success,
		SelectedClientOnly
	}

	internal enum ApplicationProtocolNegotiationExt
	{
		None,
		NPN,
		ALPN
	}

	[StructLayout(LayoutKind.Sequential)]
	internal class SecPkgContext_ApplicationProtocol
	{
		private const int MaxProtocolIdSize = 255;

		public ApplicationProtocolNegotiationStatus ProtoNegoStatus;

		public ApplicationProtocolNegotiationExt ProtoNegoExt;

		public byte ProtocolIdSize;

		[MarshalAs(UnmanagedType.ByValArray, SizeConst = 255)]
		public byte[] ProtocolId;

		public byte[] Protocol => new Span<byte>(ProtocolId, 0, (int)ProtocolIdSize).ToArray();
	}

	internal class Kernel32
	{
		internal class IOReparseOptions
		{
			internal const uint IO_REPARSE_TAG_FILE_PLACEHOLDER = 2147483669u;

			internal const uint IO_REPARSE_TAG_MOUNT_POINT = 2684354563u;
		}

		internal class FileOperations
		{
			internal const int OPEN_EXISTING = 3;

			internal const int COPY_FILE_FAIL_IF_EXISTS = 1;

			internal const int FILE_ACTION_ADDED = 1;

			internal const int FILE_ACTION_REMOVED = 2;

			internal const int FILE_ACTION_MODIFIED = 3;

			internal const int FILE_ACTION_RENAMED_OLD_NAME = 4;

			internal const int FILE_ACTION_RENAMED_NEW_NAME = 5;

			internal const int FILE_FLAG_BACKUP_SEMANTICS = 33554432;

			internal const int FILE_FLAG_FIRST_PIPE_INSTANCE = 524288;

			internal const int FILE_FLAG_OVERLAPPED = 1073741824;

			internal const int FILE_LIST_DIRECTORY = 1;
		}

		internal struct SECURITY_ATTRIBUTES
		{
			internal uint nLength;

			internal IntPtr lpSecurityDescriptor;

			internal BOOL bInheritHandle;
		}

		internal const uint SEM_FAILCRITICALERRORS = 1u;

		[DllImport("kernel32.dll", SetLastError = true)]
		[return: MarshalAs(UnmanagedType.Bool)]
		internal static extern bool CloseHandle(IntPtr handle);

		[DllImport("kernel32.dll", BestFitMapping = false, CharSet = CharSet.Unicode, EntryPoint = "CreateFileW", ExactSpelling = true, SetLastError = true)]
		private unsafe static extern IntPtr CreateFilePrivate(string lpFileName, int dwDesiredAccess, FileShare dwShareMode, SECURITY_ATTRIBUTES* securityAttrs, FileMode dwCreationDisposition, int dwFlagsAndAttributes, IntPtr hTemplateFile);

		internal unsafe static SafeFileHandle CreateFile(string lpFileName, int dwDesiredAccess, FileShare dwShareMode, ref SECURITY_ATTRIBUTES securityAttrs, FileMode dwCreationDisposition, int dwFlagsAndAttributes, IntPtr hTemplateFile)
		{
			lpFileName = System.IO.PathInternal.EnsureExtendedPrefixIfNeeded(lpFileName);
			fixed (SECURITY_ATTRIBUTES* securityAttrs2 = &securityAttrs)
			{
				IntPtr intPtr = CreateFilePrivate(lpFileName, dwDesiredAccess, dwShareMode, securityAttrs2, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile);
				try
				{
					return new SafeFileHandle(intPtr, ownsHandle: true);
				}
				catch
				{
					CloseHandle(intPtr);
					throw;
				}
			}
		}

		internal static SafeFileHandle CreateFile(string lpFileName, int dwDesiredAccess, FileShare dwShareMode, FileMode dwCreationDisposition, int dwFlagsAndAttributes)
		{
			IntPtr intPtr = CreateFile_IntPtr(lpFileName, dwDesiredAccess, dwShareMode, dwCreationDisposition, dwFlagsAndAttributes);
			try
			{
				return new SafeFileHandle(intPtr, ownsHandle: true);
			}
			catch
			{
				CloseHandle(intPtr);
				throw;
			}
		}

		internal unsafe static IntPtr CreateFile_IntPtr(string lpFileName, int dwDesiredAccess, FileShare dwShareMode, FileMode dwCreationDisposition, int dwFlagsAndAttributes)
		{
			lpFileName = System.IO.PathInternal.EnsureExtendedPrefixIfNeeded(lpFileName);
			return CreateFilePrivate(lpFileName, dwDesiredAccess, dwShareMode, null, dwCreationDisposition, dwFlagsAndAttributes, IntPtr.Zero);
		}

		[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
		internal unsafe static extern bool ReadDirectoryChangesW(SafeFileHandle hDirectory, byte[] lpBuffer, uint nBufferLength, [MarshalAs(UnmanagedType.Bool)] bool bWatchSubtree, int dwNotifyFilter, out int lpBytesReturned, NativeOverlapped* lpOverlapped, IntPtr lpCompletionRoutine);
	}

	internal static class SspiCli
	{
		[StructLayout(LayoutKind.Sequential, Pack = 1)]
		internal struct CredHandle
		{
			private IntPtr dwLower;

			private IntPtr dwUpper;

			public bool IsZero
			{
				get
				{
					if (dwLower == IntPtr.Zero)
					{
						return dwUpper == IntPtr.Zero;
					}
					return false;
				}
			}

			internal void SetToInvalid()
			{
				dwLower = IntPtr.Zero;
				dwUpper = IntPtr.Zero;
			}

			public override string ToString()
			{
				return dwLower.ToString("x") + ":" + dwUpper.ToString("x");
			}
		}

		internal enum ContextAttribute
		{
			SECPKG_ATTR_SIZES = 0,
			SECPKG_ATTR_NAMES = 1,
			SECPKG_ATTR_LIFESPAN = 2,
			SECPKG_ATTR_DCE_INFO = 3,
			SECPKG_ATTR_STREAM_SIZES = 4,
			SECPKG_ATTR_AUTHORITY = 6,
			SECPKG_ATTR_PACKAGE_INFO = 10,
			SECPKG_ATTR_NEGOTIATION_INFO = 12,
			SECPKG_ATTR_UNIQUE_BINDINGS = 25,
			SECPKG_ATTR_ENDPOINT_BINDINGS = 26,
			SECPKG_ATTR_CLIENT_SPECIFIED_TARGET = 27,
			SECPKG_ATTR_APPLICATION_PROTOCOL = 35,
			SECPKG_ATTR_REMOTE_CERT_CONTEXT = 83,
			SECPKG_ATTR_LOCAL_CERT_CONTEXT = 84,
			SECPKG_ATTR_ROOT_STORE = 85,
			SECPKG_ATTR_ISSUER_LIST_EX = 89,
			SECPKG_ATTR_CONNECTION_INFO = 90,
			SECPKG_ATTR_UI_INFO = 104
		}

		[Flags]
		internal enum ContextFlags
		{
			Zero = 0,
			Delegate = 1,
			MutualAuth = 2,
			ReplayDetect = 4,
			SequenceDetect = 8,
			Confidentiality = 0x10,
			UseSessionKey = 0x20,
			AllocateMemory = 0x100,
			Connection = 0x800,
			InitExtendedError = 0x4000,
			AcceptExtendedError = 0x8000,
			InitStream = 0x8000,
			AcceptStream = 0x10000,
			InitIntegrity = 0x10000,
			AcceptIntegrity = 0x20000,
			InitManualCredValidation = 0x80000,
			InitUseSuppliedCreds = 0x80,
			InitIdentify = 0x20000,
			AcceptIdentify = 0x80000,
			ProxyBindings = 0x4000000,
			AllowMissingBindings = 0x10000000,
			UnverifiedTargetName = 0x20000000
		}

		internal enum Endianness
		{
			SECURITY_NETWORK_DREP = 0,
			SECURITY_NATIVE_DREP = 0x10
		}

		internal enum CredentialUse
		{
			SECPKG_CRED_INBOUND = 1,
			SECPKG_CRED_OUTBOUND,
			SECPKG_CRED_BOTH
		}

		internal struct CERT_CHAIN_ELEMENT
		{
			public uint cbSize;

			public IntPtr pCertContext;
		}

		internal struct SecPkgContext_IssuerListInfoEx
		{
			public SafeHandle aIssuers;

			public uint cIssuers;

			public unsafe SecPkgContext_IssuerListInfoEx(SafeHandle handle, byte[] nativeBuffer)
			{
				aIssuers = handle;
				fixed (byte* ptr = nativeBuffer)
				{
					cIssuers = *(uint*)(ptr + IntPtr.Size);
				}
			}
		}

		internal struct SCHANNEL_CRED
		{
			[Flags]
			public enum Flags
			{
				Zero = 0,
				SCH_CRED_NO_SYSTEM_MAPPER = 2,
				SCH_CRED_NO_SERVERNAME_CHECK = 4,
				SCH_CRED_MANUAL_CRED_VALIDATION = 8,
				SCH_CRED_NO_DEFAULT_CREDS = 0x10,
				SCH_CRED_AUTO_CRED_VALIDATION = 0x20,
				SCH_SEND_AUX_RECORD = 0x200000,
				SCH_USE_STRONG_CRYPTO = 0x400000
			}

			public const int CurrentVersion = 4;

			public int dwVersion;

			public int cCreds;

			public IntPtr paCred;

			public IntPtr hRootStore;

			public int cMappers;

			public IntPtr aphMappers;

			public int cSupportedAlgs;

			public IntPtr palgSupportedAlgs;

			public int grbitEnabledProtocols;

			public int dwMinimumCipherStrength;

			public int dwMaximumCipherStrength;

			public int dwSessionLifespan;

			public Flags dwFlags;

			public int reserved;
		}

		internal struct SecBuffer
		{
			public int cbBuffer;

			public SecurityBufferType BufferType;

			public IntPtr pvBuffer;

			public unsafe static readonly int Size = sizeof(SecBuffer);
		}

		internal struct SecBufferDesc
		{
			public readonly int ulVersion;

			public readonly int cBuffers;

			public unsafe void* pBuffers;

			public unsafe SecBufferDesc(int count)
			{
				ulVersion = 0;
				cBuffers = count;
				pBuffers = null;
			}
		}

		[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
		internal struct SEC_WINNT_AUTH_IDENTITY_W
		{
			internal string User;

			internal int UserLength;

			internal string Domain;

			internal int DomainLength;

			internal string Password;

			internal int PasswordLength;

			internal int Flags;
		}

		internal const uint SECQOP_WRAP_NO_ENCRYPT = 2147483649u;

		internal const int SEC_I_RENEGOTIATE = 590625;

		internal const int SECPKG_NEGOTIATION_COMPLETE = 0;

		internal const int SECPKG_NEGOTIATION_OPTIMISTIC = 1;

		[DllImport("sspicli.dll", ExactSpelling = true, SetLastError = true)]
		internal static extern int EncryptMessage(ref CredHandle contextHandle, [In] uint qualityOfProtection, [In][Out] ref SecBufferDesc inputOutput, [In] uint sequenceNumber);

		[DllImport("sspicli.dll", ExactSpelling = true, SetLastError = true)]
		internal unsafe static extern int DecryptMessage([In] ref CredHandle contextHandle, [In][Out] ref SecBufferDesc inputOutput, [In] uint sequenceNumber, uint* qualityOfProtection);

		[DllImport("sspicli.dll", ExactSpelling = true, SetLastError = true)]
		internal static extern int QuerySecurityContextToken(ref CredHandle phContext, out SecurityContextTokenHandle handle);

		[DllImport("sspicli.dll", ExactSpelling = true, SetLastError = true)]
		internal static extern int FreeContextBuffer([In] IntPtr contextBuffer);

		[DllImport("sspicli.dll", ExactSpelling = true, SetLastError = true)]
		internal static extern int FreeCredentialsHandle(ref CredHandle handlePtr);

		[DllImport("sspicli.dll", ExactSpelling = true, SetLastError = true)]
		internal static extern int DeleteSecurityContext(ref CredHandle handlePtr);

		[DllImport("sspicli.dll", ExactSpelling = true, SetLastError = true)]
		internal unsafe static extern int AcceptSecurityContext(ref CredHandle credentialHandle, [In] void* inContextPtr, [In] SecBufferDesc* inputBuffer, [In] ContextFlags inFlags, [In] Endianness endianness, ref CredHandle outContextPtr, [In][Out] ref SecBufferDesc outputBuffer, [In][Out] ref ContextFlags attributes, out long timeStamp);

		[DllImport("sspicli.dll", ExactSpelling = true, SetLastError = true)]
		internal unsafe static extern int QueryContextAttributesW(ref CredHandle contextHandle, [In] ContextAttribute attribute, [In] void* buffer);

		[DllImport("sspicli.dll", ExactSpelling = true, SetLastError = true)]
		internal static extern int SetContextAttributesW(ref CredHandle contextHandle, [In] ContextAttribute attribute, [In] byte[] buffer, [In] int bufferSize);

		[DllImport("sspicli.dll", ExactSpelling = true, SetLastError = true)]
		internal static extern int EnumerateSecurityPackagesW(out int pkgnum, out SafeFreeContextBuffer_SECURITY handle);

		[DllImport("sspicli.dll", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
		internal unsafe static extern int AcquireCredentialsHandleW([In] string principal, [In] string moduleName, [In] int usage, [In] void* logonID, [In] ref SEC_WINNT_AUTH_IDENTITY_W authdata, [In] void* keyCallback, [In] void* keyArgument, ref CredHandle handlePtr, out long timeStamp);

		[DllImport("sspicli.dll", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
		internal unsafe static extern int AcquireCredentialsHandleW([In] string principal, [In] string moduleName, [In] int usage, [In] void* logonID, [In] IntPtr zero, [In] void* keyCallback, [In] void* keyArgument, ref CredHandle handlePtr, out long timeStamp);

		[DllImport("sspicli.dll", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
		internal unsafe static extern int AcquireCredentialsHandleW([In] string principal, [In] string moduleName, [In] int usage, [In] void* logonID, [In] SafeSspiAuthDataHandle authdata, [In] void* keyCallback, [In] void* keyArgument, ref CredHandle handlePtr, out long timeStamp);

		[DllImport("sspicli.dll", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
		internal unsafe static extern int AcquireCredentialsHandleW([In] string principal, [In] string moduleName, [In] int usage, [In] void* logonID, [In] ref SCHANNEL_CRED authData, [In] void* keyCallback, [In] void* keyArgument, ref CredHandle handlePtr, out long timeStamp);

		[DllImport("sspicli.dll", ExactSpelling = true, SetLastError = true)]
		internal unsafe static extern int InitializeSecurityContextW(ref CredHandle credentialHandle, [In] void* inContextPtr, [In] byte* targetName, [In] ContextFlags inFlags, [In] int reservedI, [In] Endianness endianness, [In] SecBufferDesc* inputBuffer, [In] int reservedII, ref CredHandle outContextPtr, [In][Out] ref SecBufferDesc outputBuffer, [In][Out] ref ContextFlags attributes, out long timeStamp);

		[DllImport("sspicli.dll", ExactSpelling = true, SetLastError = true)]
		internal unsafe static extern int CompleteAuthToken([In] void* inContextPtr, [In][Out] ref SecBufferDesc inputBuffers);

		[DllImport("sspicli.dll", ExactSpelling = true, SetLastError = true)]
		internal unsafe static extern int ApplyControlToken([In] void* inContextPtr, [In][Out] ref SecBufferDesc inputBuffers);

		[DllImport("sspicli.dll", ExactSpelling = true, SetLastError = true)]
		internal static extern SECURITY_STATUS SspiFreeAuthIdentity([In] IntPtr authData);

		[DllImport("sspicli.dll", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
		internal static extern SECURITY_STATUS SspiEncodeStringsAsAuthIdentity([In] string userName, [In] string domainName, [In] string password, out SafeSspiAuthDataHandle authData);
	}
}
namespace Mono
{
	internal class CFType
	{
		[DllImport("/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation", EntryPoint = "CFGetTypeID")]
		public static extern IntPtr GetTypeID(IntPtr typeRef);
	}
	internal class CFObject : IDisposable, INativeObject
	{
		public const string CoreFoundationLibrary = "/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation";

		private const string SystemLibrary = "/usr/lib/libSystem.dylib";

		public IntPtr Handle { get; private set; }

		[DllImport("/usr/lib/libSystem.dylib")]
		public static extern IntPtr dlopen(string path, int mode);

		[DllImport("/usr/lib/libSystem.dylib")]
		private static extern IntPtr dlsym(IntPtr handle, string symbol);

		[DllImport("/usr/lib/libSystem.dylib")]
		public static extern void dlclose(IntPtr handle);

		public static IntPtr GetIndirect(IntPtr handle, string symbol)
		{
			return dlsym(handle, symbol);
		}

		public static CFString GetStringConstant(IntPtr handle, string symbol)
		{
			IntPtr intPtr = dlsym(handle, symbol);
			if (intPtr == IntPtr.Zero)
			{
				return null;
			}
			IntPtr intPtr2 = Marshal.ReadIntPtr(intPtr);
			if (intPtr2 == IntPtr.Zero)
			{
				return null;
			}
			return new CFString(intPtr2, own: false);
		}

		public static IntPtr GetIntPtr(IntPtr handle, string symbol)
		{
			IntPtr intPtr = dlsym(handle, symbol);
			if (intPtr == IntPtr.Zero)
			{
				return IntPtr.Zero;
			}
			return Marshal.ReadIntPtr(intPtr);
		}

		public static IntPtr GetCFObjectHandle(IntPtr handle, string symbol)
		{
			IntPtr intPtr = dlsym(handle, symbol);
			if (intPtr == IntPtr.Zero)
			{
				return IntPtr.Zero;
			}
			return Marshal.ReadIntPtr(intPtr);
		}

		public CFObject(IntPtr handle, bool own)
		{
			Handle = handle;
			if (!own)
			{
				Retain();
			}
		}

		~CFObject()
		{
			Dispose(disposing: false);
		}

		[DllImport("/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation")]
		internal static extern IntPtr CFRetain(IntPtr handle);

		private void Retain()
		{
			CFRetain(Handle);
		}

		[DllImport("/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation")]
		internal static extern void CFRelease(IntPtr handle);

		private void Release()
		{
			CFRelease(Handle);
		}

		protected virtual void Dispose(bool disposing)
		{
			if (Handle != IntPtr.Zero)
			{
				Release();
				Handle = IntPtr.Zero;
			}
		}

		public void Dispose()
		{
			Dispose(disposing: true);
			GC.SuppressFinalize(this);
		}
	}
	internal class CFArray : CFObject
	{
		private static readonly IntPtr kCFTypeArrayCallbacks;

		public int Count => (int)CFArrayGetCount(base.Handle);

		public IntPtr this[int index] => CFArrayGetValueAtIndex(base.Handle, (IntPtr)index);

		public CFArray(IntPtr handle, bool own)
			: base(handle, own)
		{
		}

		[DllImport("/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation")]
		private static extern IntPtr CFArrayCreate(IntPtr allocator, IntPtr values, IntPtr numValues, IntPtr callbacks);

		static CFArray()
		{
			IntPtr intPtr = CFObject.dlopen("/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation", 0);
			if (intPtr == IntPtr.Zero)
			{
				return;
			}
			try
			{
				kCFTypeArrayCallbacks = CFObject.GetIndirect(intPtr, "kCFTypeArrayCallBacks");
			}
			finally
			{
				CFObject.dlclose(intPtr);
			}
		}

		public static CFArray FromNativeObjects(params INativeObject[] values)
		{
			return new CFArray(Create(values), own: true);
		}

		public unsafe static IntPtr Create(params IntPtr[] values)
		{
			if (values == null)
			{
				throw new ArgumentNullException("values");
			}
			fixed (IntPtr* ptr = values)
			{
				return CFArrayCreate(IntPtr.Zero, (IntPtr)ptr, (IntPtr)values.Length, kCFTypeArrayCallbacks);
			}
		}

		internal unsafe static CFArray CreateArray(params IntPtr[] values)
		{
			if (values == null)
			{
				throw new ArgumentNullException("values");
			}
			fixed (IntPtr* ptr = values)
			{
				return new CFArray(CFArrayCreate(IntPtr.Zero, (IntPtr)ptr, (IntPtr)values.Length, kCFTypeArrayCallbacks), own: false);
			}
		}

		public static CFArray CreateArray(params INativeObject[] values)
		{
			return new CFArray(Create(values), own: true);
		}

		public static IntPtr Create(params INativeObject[] values)
		{
			if (values == null)
			{
				throw new ArgumentNullException("values");
			}
			IntPtr[] array = new IntPtr[values.Length];
			for (int i = 0; i < array.Length; i++)
			{
				array[i] = values[i].Handle;
			}
			return Create(array);
		}

		[DllImport("/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation")]
		private static extern IntPtr CFArrayGetCount(IntPtr handle);

		[DllImport("/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation")]
		private static extern IntPtr CFArrayGetValueAtIndex(IntPtr handle, IntPtr index);

		public static T[] ArrayFromHandle<T>(IntPtr handle, Func<IntPtr, T> creation) where T : class, INativeObject
		{
			if (handle == IntPtr.Zero)
			{
				return null;
			}
			IntPtr intPtr = CFArrayGetCount(handle);
			T[] array = new T[(int)intPtr];
			for (uint num = 0u; num < (uint)(int)intPtr; num++)
			{
				array[num] = creation(CFArrayGetValueAtIndex(handle, (IntPtr)num));
			}
			return array;
		}
	}
	internal class CFNumber : CFObject
	{
		public CFNumber(IntPtr handle, bool own)
			: base(handle, own)
		{
		}

		[DllImport("/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation")]
		[return: MarshalAs(UnmanagedType.I1)]
		private static extern bool CFNumberGetValue(IntPtr handle, IntPtr type, [MarshalAs(UnmanagedType.I1)] out bool value);

		public static bool AsBool(IntPtr handle)
		{
			if (handle == IntPtr.Zero)
			{
				return false;
			}
			CFNumberGetValue(handle, (IntPtr)1, out bool value);
			return value;
		}

		public static implicit operator bool(CFNumber number)
		{
			return AsBool(number.Handle);
		}

		[DllImport("/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation")]
		[return: MarshalAs(UnmanagedType.I1)]
		private static extern bool CFNumberGetValue(IntPtr handle, IntPtr type, out int value);

		public static int AsInt32(IntPtr handle)
		{
			if (handle == IntPtr.Zero)
			{
				return 0;
			}
			CFNumberGetValue(handle, (IntPtr)9, out int value);
			return value;
		}

		[DllImport("/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation")]
		private static extern IntPtr CFNumberCreate(IntPtr allocator, IntPtr theType, IntPtr valuePtr);

		public static CFNumber FromInt32(int number)
		{
			return new CFNumber(CFNumberCreate(IntPtr.Zero, (IntPtr)9, (IntPtr)number), own: true);
		}

		public static implicit operator int(CFNumber number)
		{
			return AsInt32(number.Handle);
		}
	}
	internal struct CFRange
	{
		public IntPtr Location;

		public IntPtr Length;

		public CFRange(int loc, int len)
		{
			Location = (IntPtr)loc;
			Length = (IntPtr)len;
		}
	}
	internal class CFString : CFObject
	{
		private string str;

		public int Length
		{
			get
			{
				if (str != null)
				{
					return str.Length;
				}
				return (int)CFStringGetLength(base.Handle);
			}
		}

		public CFString(IntPtr handle, bool own)
			: base(handle, own)
		{
		}

		[DllImport("/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation")]
		private static extern IntPtr CFStringCreateWithCharacters(IntPtr alloc, IntPtr chars, IntPtr length);

		public unsafe static CFString Create(string value)
		{
			IntPtr intPtr;
			fixed (char* ptr = value)
			{
				intPtr = CFStringCreateWithCharacters(IntPtr.Zero, (IntPtr)ptr, (IntPtr)value.Length);
			}
			if (intPtr == IntPtr.Zero)
			{
				return null;
			}
			return new CFString(intPtr, own: true);
		}

		[DllImport("/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation")]
		private static extern IntPtr CFStringGetLength(IntPtr handle);

		[DllImport("/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation")]
		private static extern int CFStringCompare(IntPtr theString1, IntPtr theString2, int compareOptions);

		public static int Compare(IntPtr string1, IntPtr string2, int compareOptions = 0)
		{
			return CFStringCompare(string1, string2, compareOptions);
		}

		[DllImport("/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation")]
		private static extern IntPtr CFStringGetCharactersPtr(IntPtr handle);

		[DllImport("/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation")]
		private static extern IntPtr CFStringGetCharacters(IntPtr handle, CFRange range, IntPtr buffer);

		public unsafe static string AsString(IntPtr handle)
		{
			if (handle == IntPtr.Zero)
			{
				return null;
			}
			int num = (int)CFStringGetLength(handle);
			if (num == 0)
			{
				return string.Empty;
			}
			IntPtr intPtr = CFStringGetCharactersPtr(handle);
			IntPtr intPtr2 = IntPtr.Zero;
			if (intPtr == IntPtr.Zero)
			{
				CFRange range = new CFRange(0, num);
				intPtr2 = Marshal.AllocHGlobal(num * 2);
				CFStringGetCharacters(handle, range, intPtr2);
				intPtr = intPtr2;
			}
			string result = new string((char*)(void*)intPtr, 0, num);
			if (intPtr2 != IntPtr.Zero)
			{
				Marshal.FreeHGlobal(intPtr2);
			}
			return result;
		}

		public override string ToString()
		{
			if (str == null)
			{
				str = AsString(base.Handle);
			}
			return str;
		}

		public static implicit operator string(CFString str)
		{
			return str.ToString();
		}

		public static implicit operator CFString(string str)
		{
			return Create(str);
		}
	}
	internal class CFData : CFObject
	{
		public IntPtr Length => CFDataGetLength(base.Handle);

		public IntPtr Bytes => CFDataGetBytePtr(base.Handle);

		public byte this[long idx]
		{
			get
			{
				if (idx < 0 || (ulong)idx > (ulong)(long)Length)
				{
					throw new ArgumentException("idx");
				}
				return Marshal.ReadByte(new IntPtr(Bytes.ToInt64() + idx));
			}
			set
			{
				throw new NotImplementedException("NSData arrays can not be modified, use an NSMutableData instead");
			}
		}

		public CFData(IntPtr handle, bool own)
			: base(handle, own)
		{
		}

		[DllImport("/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation")]
		private static extern IntPtr CFDataCreate(IntPtr allocator, IntPtr bytes, IntPtr length);

		public unsafe static CFData FromData(byte[] buffer)
		{
			fixed (byte* ptr = buffer)
			{
				return FromData((IntPtr)ptr, (IntPtr)buffer.Length);
			}
		}

		public static CFData FromData(IntPtr buffer, IntPtr length)
		{
			return new CFData(CFDataCreate(IntPtr.Zero, buffer, length), own: true);
		}

		[DllImport("/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation")]
		internal static extern IntPtr CFDataGetLength(IntPtr theData);

		[DllImport("/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation")]
		internal static extern IntPtr CFDataGetBytePtr(IntPtr theData);
	}
	internal class CFDictionary : CFObject
	{
		private static readonly IntPtr KeyCallbacks;

		private static readonly IntPtr ValueCallbacks;

		public IntPtr this[IntPtr key] => GetValue(key);

		static CFDictionary()
		{
			IntPtr intPtr = CFObject.dlopen("/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation", 0);
			if (intPtr == IntPtr.Zero)
			{
				return;
			}
			try
			{
				KeyCallbacks = CFObject.GetIndirect(intPtr, "kCFTypeDictionaryKeyCallBacks");
				ValueCallbacks = CFObject.GetIndirect(intPtr, "kCFTypeDictionaryValueCallBacks");
			}
			finally
			{
				CFObject.dlclose(intPtr);
			}
		}

		public CFDictionary(IntPtr handle, bool own)
			: base(handle, own)
		{
		}

		public static CFDictionary FromObjectAndKey(IntPtr obj, IntPtr key)
		{
			return new CFDictionary(CFDictionaryCreate(IntPtr.Zero, new IntPtr[1] { key }, new IntPtr[1] { obj }, (IntPtr)1, KeyCallbacks, ValueCallbacks), own: true);
		}

		public static CFDictionary FromKeysAndObjects(IList<Tuple<IntPtr, IntPtr>> items)
		{
			IntPtr[] array = new IntPtr[items.Count];
			IntPtr[] array2 = new IntPtr[items.Count];
			for (int i = 0; i < items.Count; i++)
			{
				array[i] = items[i].Item1;
				array2[i] = items[i].Item2;
			}
			return new CFDictionary(CFDictionaryCreate(IntPtr.Zero, array, array2, (IntPtr)items.Count, KeyCallbacks, ValueCallbacks), own: true);
		}

		[DllImport("/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation")]
		private static extern IntPtr CFDictionaryCreate(IntPtr allocator, IntPtr[] keys, IntPtr[] vals, IntPtr len, IntPtr keyCallbacks, IntPtr valCallbacks);

		[DllImport("/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation")]
		private static extern IntPtr CFDictionaryGetValue(IntPtr handle, IntPtr key);

		[DllImport("/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation")]
		private static extern IntPtr CFDictionaryCreateCopy(IntPtr allocator, IntPtr handle);

		public CFDictionary Copy()
		{
			return new CFDictionary(CFDictionaryCreateCopy(IntPtr.Zero, base.Handle), own: true);
		}

		public CFMutableDictionary MutableCopy()
		{
			return new CFMutableDictionary(CFDictionaryCreateMutableCopy(IntPtr.Zero, IntPtr.Zero, base.Handle), own: true);
		}

		[DllImport("/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation")]
		private static extern IntPtr CFDictionaryCreateMutableCopy(IntPtr allocator, IntPtr capacity, IntPtr theDict);

		public IntPtr GetValue(IntPtr key)
		{
			return CFDictionaryGetValue(base.Handle, key);
		}
	}
	internal class CFMutableDictionary : CFDictionary
	{
		public CFMutableDictionary(IntPtr handle, bool own)
			: base(handle, own)
		{
		}

		public void SetValue(IntPtr key, IntPtr val)
		{
			CFDictionarySetValue(base.Handle, key, val);
		}

		public static CFMutableDictionary Create()
		{
			IntPtr intPtr = CFDictionaryCreateMutable(IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
			if (intPtr == IntPtr.Zero)
			{
				throw new InvalidOperationException();
			}
			return new CFMutableDictionary(intPtr, own: true);
		}

		[DllImport("/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation")]
		private static extern void CFDictionarySetValue(IntPtr handle, IntPtr key, IntPtr val);

		[DllImport("/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation")]
		private static extern IntPtr CFDictionaryCreateMutable(IntPtr allocator, IntPtr capacity, IntPtr keyCallback, IntPtr valueCallbacks);
	}
	internal class CFBoolean : INativeObject, IDisposable
	{
		private IntPtr handle;

		public static readonly CFBoolean True;

		public static readonly CFBoolean False;

		public IntPtr Handle => handle;

		public bool Value => CFBooleanGetValue(handle);

		static CFBoolean()
		{
			IntPtr intPtr = CFObject.dlopen("/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation", 0);
			if (intPtr == IntPtr.Zero)
			{
				return;
			}
			try
			{
				True = new CFBoolean(CFObject.GetCFObjectHandle(intPtr, "kCFBooleanTrue"), owns: false);
				False = new CFBoolean(CFObject.GetCFObjectHandle(intPtr, "kCFBooleanFalse"), owns: false);
			}
			finally
			{
				CFObject.dlclose(intPtr);
			}
		}

		internal CFBoolean(IntPtr handle, bool owns)
		{
			this.handle = handle;
			if (!owns)
			{
				CFObject.CFRetain(handle);
			}
		}

		~CFBoolean()
		{
			Dispose(disposing: false);
		}

		public void Dispose()
		{
			Dispose(disposing: true);
			GC.SuppressFinalize(this);
		}

		protected virtual void Dispose(bool disposing)
		{
			if (handle != IntPtr.Zero)
			{
				CFObject.CFRelease(handle);
				handle = IntPtr.Zero;
			}
		}

		public static implicit operator bool(CFBoolean value)
		{
			return value.Value;
		}

		public static explicit operator CFBoolean(bool value)
		{
			return FromBoolean(value);
		}

		public static CFBoolean FromBoolean(bool value)
		{
			if (!value)
			{
				return False;
			}
			return True;
		}

		[DllImport("/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation")]
		[return: MarshalAs(UnmanagedType.I1)]
		private static extern bool CFBooleanGetValue(IntPtr boolean);

		public static bool GetValue(IntPtr boolean)
		{
			return CFBooleanGetValue(boolean);
		}
	}
	internal class CFDate : INativeObject, IDisposable
	{
		private IntPtr handle;

		public IntPtr Handle => handle;

		internal CFDate(IntPtr handle, bool owns)
		{
			this.handle = handle;
			if (!owns)
			{
				CFObject.CFRetain(handle);
			}
		}

		~CFDate()
		{
			Dispose(disposing: false);
		}

		[DllImport("/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation")]
		private static extern IntPtr CFDateCreate(IntPtr allocator, double at);

		public static CFDate Create(DateTime date)
		{
			DateTime dateTime = new DateTime(2001, 1, 1);
			double totalSeconds = (date - dateTime).TotalSeconds;
			IntPtr intPtr = CFDateCreate(IntPtr.Zero, totalSeconds);
			if (intPtr == IntPtr.Zero)
			{
				throw new NotSupportedException();
			}
			return new CFDate(intPtr, owns: true);
		}

		public void Dispose()
		{
			Dispose(disposing: true);
			GC.SuppressFinalize(this);
		}

		protected virtual void Dispose(bool disposing)
		{
			if (handle != IntPtr.Zero)
			{
				CFObject.CFRelease(handle);
				handle = IntPtr.Zero;
			}
		}
	}
	internal class SystemCertificateProvider : ISystemCertificateProvider
	{
		private static MonoTlsProvider provider;

		private static int initialized;

		private static X509PalImpl x509pal;

		private static object syncRoot = new object();

		public MonoTlsProvider Provider
		{
			get
			{
				EnsureInitialized();
				return provider;
			}
		}

		public X509PalImpl X509Pal
		{
			get
			{
				EnsureInitialized();
				return x509pal;
			}
		}

		private static X509PalImpl GetX509Pal()
		{
			MonoTlsProvider obj = provider;
			if (((obj != null) ? new Guid?(obj.ID) : null) == MonoTlsProviderFactory.BtlsId)
			{
				return new X509PalImplBtls(provider);
			}
			return new X509PalImplMono();
		}

		private static void EnsureInitialized()
		{
			lock (syncRoot)
			{
				if (Interlocked.CompareExchange(ref initialized, 1, 0) == 0)
				{
					provider = MonoTlsProviderFactory.GetProvider();
					x509pal = GetX509Pal();
				}
			}
		}

		public X509CertificateImpl Import(byte[] data, CertificateImportFlags importFlags = 0)
		{
			//IL_000b: 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_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			if (data == null || data.Length == 0)
			{
				return null;
			}
			X509CertificateImpl val = null;
			if ((importFlags & 1) == 0)
			{
				val = X509Pal.Import(data);
				if (val != null)
				{
					return val;
				}
			}
			if ((importFlags & 2) != 0)
			{
				return null;
			}
			return (X509CertificateImpl)(object)X509Pal.ImportFallback(data);
		}

		X509CertificateImpl ISystemCertificateProvider.Import(byte[] data, SafePasswordHandle password, X509KeyStorageFlags keyStorageFlags, CertificateImportFlags importFlags)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			return (X509CertificateImpl)(object)Import(data, password, keyStorageFlags, importFlags);
		}

		public X509Certificate2Impl Import(byte[] data, SafePasswordHandle password, X509KeyStorageFlags keyStorageFlags, CertificateImportFlags importFlags = 0)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: 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)
			if (data == null || data.Length == 0)
			{
				return null;
			}
			X509Certificate2Impl x509Certificate2Impl = null;
			if ((importFlags & 1) == 0)
			{
				x509Certificate2Impl = X509Pal.Import(data, password, keyStorageFlags);
				if (x509Certificate2Impl != null)
				{
					return x509Certificate2Impl;
				}
			}
			if ((importFlags & 2) != 0)
			{
				return null;
			}
			return X509Pal.ImportFallback(data, password, keyStorageFlags);
		}

		X509CertificateImpl ISystemCertificateProvider.Import(X509Certificate cert, CertificateImportFlags importFlags)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			return (X509CertificateImpl)(object)Import(cert, importFlags);
		}

		public X509Certificate2Impl Import(X509Certificate cert, CertificateImportFlags importFlags = 0)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			if (cert.Impl == null)
			{
				return null;
			}
			if (cert.Impl is X509Certificate2Impl x509Certificate2Impl)
			{
				return (X509Certificate2Impl)(object)((X509CertificateImpl)x509Certificate2Impl).Clone();
			}
			if ((importFlags & 1) == 0)
			{
				X509Certificate2Impl x509Certificate2Impl2 = X509Pal.Import(cert);
				if (x509Certificate2Impl2 != null)
				{
					return x509Certificate2Impl2;
				}
			}
			if ((importFlags & 2) != 0)
			{
				return null;
			}
			return X509Pal.ImportFallback(cert.GetRawCertData());
		}
	}
	internal class SystemDependencyProvider : ISystemDependencyProvider
	{
		private static SystemDependencyProvider instance;

		private static object syncRoot = new object();

		public static SystemDependencyProvider Instance
		{
			get
			{
				Initialize();
				return instance;
			}
		}

		ISystemCertificateProvider ISystemDependencyProvider.CertificateProvider => (ISystemCertificateProvider)(object)CertificateProvider;

		public SystemCertificateProvider CertificateProvider { get; }

		public X509PalImpl X509Pal => CertificateProvider.X509Pal;

		internal static void Initialize()
		{
			lock (syncRoot)
			{
				if (instance == null)
				{
					instance = new SystemDependencyProvider();
				}
			}
		}

		private SystemDependencyProvider()
		{
			CertificateProvider = new SystemCertificateProvider();
			DependencyInjector.Register((ISystemDependencyProvider)(object)this);
		}
	}
	internal static class X509Pal
	{
		public static X509PalImpl Instance => SystemDependencyProvider.Instance.X509Pal;
	}
	internal class X509PalImplMono : X509PalImpl
	{
		public override X509CertificateImpl Import(byte[] data)
		{
			return (X509CertificateImpl)(object)ImportFallback(data);
		}

		public override X509Certificate2Impl Import(byte[] data, SafePasswordHandle password, X509KeyStorageFlags keyStorageFlags)
		{
			return ImportFallback(data, password, keyStorageFlags);
		}

		public override X509Certificate2Impl Import(X509Certificate cert)
		{
			return null;
		}
	}
	internal abstract class X509PalImpl
	{
		private static byte[] signedData = new byte[9] { 42, 134, 72, 134, 247, 13, 1, 7, 2 };

		public bool SupportsLegacyBasicConstraintsExtension => false;

		public abstract X509CertificateImpl Import(byte[] data);

		public abstract X509Certificate2Impl Import(byte[] data, SafePasswordHandle password, X509KeyStorageFlags keyStorageFlags);

		public abstract X509Certificate2Impl Import(X509Certificate cert);

		private static byte[] PEM(string type, byte[] data)
		{
			string @string = Encoding.ASCII.GetString(data);
			string text = $"-----BEGIN {type}-----";
			string value = $"-----END {type}-----";
			int num = @string.IndexOf(text) + text.Length;
			int num2 = @string.IndexOf(value, num);
			return Convert.FromBase64String(@string.Substring(num, num2 - num));
		}

		protected static byte[] ConvertData(byte[] data)
		{
			if (data == null || data.Length == 0)
			{
				return data;
			}
			if (data[0] != 48)
			{
				try
				{
					return PEM("CERTIFICATE", data);
				}
				catch
				{
				}
			}
			return data;
		}

		internal X509Certificate2Impl ImportFallback(byte[] data)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Expected O, but got Unknown
			data = ConvertData(data);
			SafePasswordHandle val = new SafePasswordHandle((string)null);
			try
			{
				return new X509Certificate2ImplMono(data, val, X509KeyStorageFlags.DefaultKeySet);
			}
			finally
			{
				((IDisposable)val)?.Dispose();
			}
		}

		internal X509Certificate2Impl ImportFallback(byte[] data, SafePasswordHandle password, X509KeyStorageFlags keyStorageFlags)
		{
			return new X509Certificate2ImplMono(data, password, keyStorageFlags);
		}

		public X509ContentType GetCertContentType(byte[] rawData)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			if (rawData == null || rawData.Length == 0)
			{
				throw new ArgumentException("rawData");
			}
			if (rawData[0] == 48)
			{
				try
				{
					ASN1 val = new ASN1(rawData);
					if (val.Count == 3 && val[0].Tag == 48 && val[1].Tag == 48 && val[2].Tag == 3)
					{
						return X509ContentType.Cert;
					}
					if (val.Count == 3 && val[0].Tag == 2 && val[1].Tag == 48 && val[2].Tag == 48)
					{
						return X509ContentType.Pfx;
					}
					if (val.Count > 0 && val[0].Tag == 6 && val[0].CompareValue(signedData))
					{
						return X509ContentType.Pkcs7;
					}
					return X509ContentType.Unknown;
				}
				catch (Exception)
				{
					return X509ContentType.Unknown;
				}
			}
			if (Encoding.ASCII.GetString(rawData).IndexOf("-----BEGIN CERTIFICATE-----") >= 0)
			{
				return X509ContentType.Cert;
			}
			try
			{
				new AuthenticodeDeformatter(rawData);
				return X509ContentType.Authenticode;
			}
			catch
			{
				return X509ContentType.Unknown;
			}
		}

		public X509ContentType GetCertContentType(string fileName)
		{
			if (fileName == null)
			{
				throw new ArgumentNullException("fileName");
			}
			if (fileName.Length == 0)
			{
				throw new ArgumentException("fileName");
			}
			byte[] rawData = File.ReadAllBytes(fileName);
			return GetCertContentType(rawData);
		}
	}
}
namespace Mono.Audio
{
	internal abstract class AudioData
	{
		protected const int buffer_size = 4096;

		private bool stopped;

		public abstract int Channels { get; }

		public abstract int Rate { get; }

		public abstract AudioFormat Format { get; }

		public virtual bool IsStopped
		{
			get
			{
				return stopped;
			}
			set
			{
				stopped = value;
			}
		}

		public virtual void Setup(AudioDevice dev)
		{
			dev.SetFormat(Format, Channels, Rate);
		}

		public abstract void Play(AudioDevice dev);
	}
	internal class WavData : AudioData
	{
		private Stream stream;

		private short channels;

		private ushort frame_divider;

		private int sample_rate;

		private int data_len;

		private long data_offset;

		private AudioFormat format;

		public override int Channels => channels;

		public override int Rate => sample_rate;

		public override AudioFormat Format => format;

		public WavData(Stream data)
		{
			stream = data;
			byte[] array = new byte[44];
			int num = stream.Read(array, 0, 12);
			if (num != 12 || array[0] != 82 || array[1] != 73 || array[2] != 70 || array[3] != 70 || array[8] != 87 || array[9] != 65 || array[10] != 86 || array[11] != 69)
			{
				throw new Exception("incorrect format" + num);
			}
			num = stream.Read(array, 0, 8);
			if (num == 8 && array[0] == 102 && array[1] == 109 && array[2] == 116 && array[3] == 32)
			{
				int num2 = array[4];
				num2 |= array[5] << 8;
				num2 |= array[6] << 16;
				num2 |= array[7] << 24;
				num = stream.Read(array, 0, num2);
				if (num2 == num)
				{
					int num3 = 0;
					if ((array[num3++] | (array[num3++] << 8)) != 1)
					{
						throw new Exception("incorrect format (not PCM)");
					}
					channels = (short)(array[num3++] | (array[num3++] << 8));
					sample_rate = array[num3++];
					sample_rate |= array[num3++] << 8;
					sample_rate |= array[num3++] << 16;
					sample_rate |= array[num3++] << 24;
					_ = array[num3++] | (array[num3++] << 8) | (array[num3++] << 16);
					_ = array[num3++];
					num3 += 2;
					switch (array[num3++] | (array[num3++] << 8))
					{
					case 8:
						frame_divider = 1;
						format = AudioFormat.U8;
						break;
					case 16:
						frame_divider = 2;
						format = AudioFormat.S16_LE;
						break;
					default:
						throw new Exception("bits per sample");
					}
					num = stream.Read(array, 0, 8);
					if (num == 8)
					{
						if (array[0] == 102 && array[1] == 97 && array[2] == 99 && array[3] == 116)
						{
							int num4 = array[4];
							num4 |= array[5] << 8;
							num4 |= array[6] << 16;
							num4 |= array[7] << 24;
							num = stream.Read(array, 0, num4);
							num = stream.Read(array, 0, 8);
						}
						if (array[0] != 100 || array[1] != 97 || array[2] != 116 || array[3] != 97)
						{
							throw new Exception("incorrect format (data/fact chunck)");
						}
						int num5 = array[4];
						num5 |= array[5] << 8;
						num5 |= array[6] << 16;
						num5 |= array[7] << 24;
						data_len = num5;
						data_offset = stream.Position;
					}
					return;
				}
				throw new Exception("Error: Can't Read " + num2 + " bytes from stream (" + num + " bytes read");
			}
			throw new Exception("incorrect format (fmt)");
		}

		public override void Play(AudioDevice dev)
		{
			int num = 0;
			int num2 = 0;
			int chunkSize = (int)dev.ChunkSize;
			int num3 = data_len;
			byte[] array = new byte[data_len];
			byte[] array2 = new byte[chunkSize];
			stream.Position = data_offset;
			stream.Read(array, 0, data_len);
			while (!IsStopped && num3 >= 0)
			{
				Buffer.BlockCopy(array, num2, array2, 0, chunkSize);
				num = dev.PlaySample(array2, chunkSize / (frame_divider * channels));
				if (num > 0)
				{
					num2 += num * frame_divider * channels;
					num3 -= num * frame_divider * channels;
				}
			}
		}
	}
	internal class AuData : AudioData
	{
		private Stream stream;

		private short channels;

		private ushort frame_divider;

		private int sample_rate;

		private int data_len;

		private AudioFormat format;

		public override int Channels => channels;

		public override int Rate => sample_rate;

		public override AudioFormat Format => format;

		public AuData(Stream data)
		{
			stream = data;
			byte[] array = new byte[24];
			int num = stream.Read(array, 0, 24);
			if (num != 24 || array[0] != 46 || array[1] != 115 || array[2] != 110 || array[3] != 100)
			{
				throw new Exception("incorrect format" + num);
			}
			int num2 = array[7];
			num2 |= array[6] << 8;
			num2 |= array[5] << 16;
			num2 |= array[4] << 24;
			data_len = array[11];
			data_len |= array[10] << 8;
			data_len |= array[9] << 16;
			data_len |= array[8] << 24;
			int num3 = array[15];
			num3 |= array[14] << 8;
			num3 |= array[13] << 16;
			num3 |= array[12] << 24;
			sample_rate = array[19];
			sample_rate |= array[18] << 8;
			sample_rate |= array[17] << 16;
			sample_rate |= array[16] << 24;
			int num4 = array[23];
			num4 |= array[22] << 8;
			num4 |= array[21] << 16;
			num4 |= array[20] << 24;
			channels = (short)num4;
			if (num2 < 24 || (num4 != 1 && num4 != 2))
			{
				throw new Exception("incorrect format offset" + num2);
			}
			if (num2 != 24)
			{
				for (int i = 24; i < num2; i++)
				{
					stream.ReadByte();
				}
			}
			if (num3 == 1)
			{
				frame_divider = 1;
				format = AudioFormat.MU_LAW;
				if (data_len == -1)
				{
					data_len = (int)stream.Length - num2;
				}
				return;
			}
			throw new Exception("incorrect format encoding" + num3);
		}

		public override void Play(AudioDevice dev)
		{
			int num = 0;
			int num2 = 0;
			int chunkSize = (int)dev.ChunkSize;
			int num3 = data_len;
			byte[] array = new byte[data_len];
			byte[] array2 = new byte[chunkSize];
			stream.Position = 0L;
			stream.Read(array, 0, data_len);
			while (!IsStopped && num3 >= 0)
			{
				Buffer.BlockCopy(array, num2, array2, 0, chunkSize);
				num = dev.PlaySample(array2, chunkSize / (frame_divider * channels));
				if (num > 0)
				{
					num2 += num * frame_divider * channels;
					num3 -= num * frame_divider * channels;
				}
			}
		}
	}
	internal enum AudioFormat
	{
		S8,
		U8,
		S16_LE,
		S16_BE,
		U16_LE,
		U16_BE,
		S24_LE,
		S24_BE,
		U24_LE,
		U24_BE,
		S32_LE,
		S32_BE,
		U32_LE,
		U32_BE,
		FLOAT_LE,
		FLOAT_BE,
		FLOAT64_LE,
		FLOAT64_BE,
		IEC958_SUBFRAME_LE,
		IEC958_SUBFRAME_BE,
		MU_LAW,
		A_LAW,
		IMA_ADPCM,
		MPEG,
		GSM
	}
	internal class AudioDevice
	{
		protected uint chunk_size;

		public uint ChunkSize => chunk_size;

		private static AudioDevice TryAlsa(string name)
		{
			try
			{
				return new AlsaDevice(name);
			}
			catch
			{
				return null;
			}
		}

		public static AudioDevice CreateDevice(string name)
		{
			AudioDevice audioDevice = TryAlsa(name);
			if (audioDevice == null)
			{
				audioDevice = new AudioDevice();
			}
			return audioDevice;
		}

		public virtual bool SetFormat(AudioFormat format, int channels, int rate)
		{
			return true;
		}

		public virtual int PlaySample(byte[] buffer, int num_frames)
		{
			return num_frames;
		}

		public virtual int XRunRecovery(int err)
		{
			return err;
		}

		public virtual void Wait()
		{
		}
	}
	internal class AlsaDevice : AudioDevice, IDisposable
	{
		private IntPtr handle;

		private IntPtr hw_param;

		private IntPtr sw_param;

		[DllImport("libasound")]
		private static extern int snd_pcm_open(ref IntPtr handle, string pcm_name, int stream, int mode);

		[DllImport("libasound")]
		private static extern int snd_pcm_close(IntPtr handle);

		[DllImport("libasound")]
		private static extern int snd_pcm_drain(IntPtr handle);

		[DllImport("libasound")]
		private static extern int snd_pcm_writei(IntPtr handle, byte[] buf, int size);

		[DllImport("libasound")]
		private static extern int snd_pcm_set_params(IntPtr handle, int format, int access, int channels, int rate, int soft_resample, int latency);

		[DllImport("libasound")]
		private static extern int snd_pcm_state(IntPtr handle);

		[DllImport("libasound")]
		private static extern int snd_pcm_prepare(IntPtr handle);

		[DllImport("libasound")]
		private static extern int snd_pcm_hw_params(IntPtr handle, IntPtr param);

		[DllImport("libasound")]
		private static extern int snd_pcm_hw_params_malloc(ref IntPtr param);

		[DllImport("libasound")]
		private static extern void snd_pcm_hw_params_free(IntPtr param);

		[DllImport("libasound")]
		private static extern int snd_pcm_hw_params_any(IntPtr handle, IntPtr param);

		[DllImport("libasound")]
		private static extern int snd_pcm_hw_params_set_access(IntPtr handle, IntPtr param, int access);

		[DllImport("libasound")]
		private static extern int snd_pcm_hw_params_set_format(IntPtr handle, IntPtr param, int format);

		[DllImport("libasound")]
		private static extern int snd_pcm_hw_params_set_channels(IntPtr handle, IntPtr param, uint channel);

		[DllImport("libasound")]
		private static extern int snd_pcm_hw_params_set_rate_near(IntPtr handle, IntPtr param, ref uint rate, ref int dir);

		[DllImport("libasound")]
		private static extern int snd_pcm_hw_params_set_period_time_near(IntPtr handle, IntPtr param, ref uint period, ref int dir);

		[DllImport("libasound")]
		private static extern int snd_pcm_hw_params_get_period_size(IntPtr param, ref uint period, ref int dir);

		[DllImport("libasound")]
		private static extern int snd_pcm_hw_params_set_buffer_size_near(IntPtr handle, IntPtr param, ref uint buff_size);

		[DllImport("libasound")]
		private static extern int snd_pcm_hw_params_get_buffer_time_max(IntPtr param, ref uint buffer_time, ref int dir);

		[DllImport("libasound")]
		private static extern int snd_pcm_hw_params_set_buffer_time_near(IntPtr handle, IntPtr param, ref uint BufferTime, ref int dir);

		[DllImport("libasound")]
		private static extern int snd_pcm_hw_params_get_buffer_size(IntPtr param, ref uint BufferSize);

		[DllImport("libasound")]
		private static extern int snd_pcm_sw_params(IntPtr handle, IntPtr param);

		[DllImport("libasound")]
		private static extern int snd_pcm_sw_params_malloc(ref IntPtr param);

		[DllImport("libasound")]
		private static extern void snd_pcm_sw_params_free(IntPtr param);

		[DllImport("libasound")]
		private static extern int snd_pcm_sw_params_current(IntPtr handle, IntPtr param);

		[DllImport("libasound")]
		private static extern int snd_pcm_sw_params_set_avail_min(IntPtr handle, IntPtr param, uint frames);

		[DllImport("libasound")]
		private static extern int snd_pcm_sw_params_set_start_threshold(IntPtr handle, IntPtr param, uint StartThreshold);

		public AlsaDevice(string name)
		{
			if (name == null)
			{
				name = "default";
			}
			int num = snd_pcm_open(ref handle, name, 0, 0);
			if (num < 0)
			{
				throw new Exception("no open " + num);
			}
		}

		~AlsaDevice()
		{
			Dispose(disposing: false);
		}

		public void Dispose()
		{
			Dispose(disposing: true);
			GC.SuppressFinalize(this);
		}

		protected virtual void Dispose(bool disposing)
		{
			if (sw_param != IntPtr.Zero)
			{
				snd_pcm_sw_params_free(sw_param);
			}
			if (hw_param != IntPtr.Zero)
			{
				snd_pcm_hw_params_free(hw_param);
			}
			if (handle != IntPtr.Zero)
			{
				snd_pcm_close(handle);
			}
			sw_param = IntPtr.Zero;
			hw_param = IntPtr.Zero;
			handle = IntPtr.Zero;
		}

		public override bool SetFormat(AudioFormat format, int channels, int rate)
		{
			uint period = 0u;
			uint period2 = 0u;
			uint BufferSize = 0u;
			uint buffer_time = 0u;
			int num = 0;
			uint rate2 = (uint)rate;
			if (snd_pcm_hw_params_malloc(ref hw_param) == 0)
			{
				snd_pcm_hw_params_any(handle, hw_param);
				snd_pcm_hw_params_set_access(handle, hw_param, 3);
				snd_pcm_hw_params_set_format(handle, hw_param, (int)format);
				snd_pcm_hw_params_set_channels(handle, hw_param, (uint)channels);
				num = 0;
				snd_pcm_hw_params_set_rate_near(handle, hw_param, ref rate2, ref num);
				num = 0;
				snd_pcm_hw_params_get_buffer_time_max(hw_param, ref buffer_time, ref num);
				if (buffer_time > 500000)
				{
					buffer_time = 500000u;
				}
				if (buffer_time != 0)
				{
					period = buffer_time / 4;
				}
				num = 0;
				snd_pcm_hw_params_set_period_time_near(handle, hw_param, ref period, ref num);
				num = 0;
				snd_pcm_hw_params_set_buffer_time_near(handle, hw_param, ref buffer_time, ref num);
				snd_pcm_hw_params_get_period_size(hw_param, ref period2, ref num);
				chunk_size = period2;
				snd_pcm_hw_params_get_buffer_size(hw_param, ref BufferSize);
				snd_pcm_hw_params(handle, hw_param);
			}
			else
			{
				Console.WriteLine("failed to alloc Alsa hw param struct");
			}
			int num2 = snd_pcm_sw_params_malloc(ref sw_param);
			if (num2 == 0)
			{
				snd_pcm_sw_params_current(handle, sw_param);
				snd_pcm_sw_params_set_avail_min(handle, sw_param, chunk_size);
				snd_pcm_sw_params_set_start_threshold(handle, sw_param, BufferSize);
				snd_pcm_sw_params(handle, sw_param);
			}
			else
			{
				Console.WriteLine("failed to alloc Alsa sw param struct");
			}
			if (hw_param != IntPtr.Zero)
			{
				snd_pcm_hw_params_free(hw_param);
				hw_param = IntPtr.Zero;
			}
			if (sw_param != IntPtr.Zero)
			{
				snd_pcm_sw_params_free(sw_param);
				sw_param = IntPtr.Zero;
			}
			return num2 == 0;
		}

		public override int PlaySample(byte[] buffer, int num_frames)
		{
			int num;
			do
			{
				num = snd_pcm_writei(handle, buffer, num_frames);
				if (num < 0)
				{
					XRunRecovery(num);
				}
			}
			while (num < 0);
			return num;
		}

		public override int XRunRecovery(int err)
		{
			int result = 0;
			if (-32 == err)
			{
				result = snd_pcm_prepare(handle);
			}
			return result;
		}

		public override void Wait()
		{
			snd_pcm_drain(handle);
		}
	}
	internal class Win32SoundPlayer : IDisposable
	{
		private enum SoundFlags : uint
		{
			SND_SYNC = 0u,
			SND_ASYNC = 1u,
			SND_NODEFAULT = 2u,
			SND_MEMORY = 4u,
			SND_LOOP = 8u,
			SND_FILENAME = 0x20000u
		}

		private byte[] _buffer;

		private bool _disposed;

		public Stream Stream
		{
			set
			{
				Stop();
				if (value != null)
				{
					_buffer = new byte[value.Length];
					value.Read(_buffer, 0, _buffer.Length);
				}
				else
				{
					_buffer = new byte[0];
				}
			}
		}

		public Win32SoundPlayer(Stream s)
		{
			if (s != null)
			{
				_buffer = new byte[s.Length];
				s.Read(_buffer, 0, _buffer.Length);
			}
			else
			{
				_buffer = new byte[0];
			}
		}

		[DllImport("winmm.dll", SetLastError = true)]
		private static extern bool PlaySound(byte[] ptrToSound, UIntPtr hmod, SoundFlags flags);

		public void Dispose()
		{
			Dispose(disposing: true);
			GC.SuppressFinalize(this);
		}

		~Win32SoundPlayer()
		{
			Dispose(disposing: false);
		}

		protected virtual void Dispose(bool disposing)
		{
			if (!_disposed)
			{
				Stop();
				_disposed = true;
			}
		}

		public void Play()
		{
			PlaySound(_buffer, UIntPtr.Zero, (SoundFlags)5u);
		}

		public void PlayLooping()
		{
			PlaySound(_buffer, UIntPtr.Zero, (SoundFlags)13u);
		}

		public void PlaySync()
		{
			PlaySound(_buffer, UIntPtr.Zero, (SoundFlags)6u);
		}

		public void Stop()
		{
			PlaySound(null, UIntPtr.Zero, SoundFlags.SND_SYNC);
		}
	}
}
namespace Mono.Util
{
	[Conditional("MONOTOUCH")]
	[Conditional("FULL_AOT_RUNTIME")]
	[AttributeUsage(AttributeTargets.Method)]
	internal sealed class MonoPInvokeCallbackAttribute : Attribute
	{
		public MonoPInvokeCallbackAttribute(Type t)
		{
		}
	}
}
namespace Mono.Net
{
	internal struct CFStreamClientContext
	{
		public IntPtr Version;

		public IntPtr Info;

		public IntPtr Retain;

		public IntPtr Release;

		public IntPtr CopyDescription;
	}
	internal class CFUrl : CFObject
	{
		public CFUrl(IntPtr handle, bool own)
			: base(handle, own)
		{
		}

		[DllImport("/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation")]
		private static extern IntPtr CFURLCreateWithString(IntPtr allocator, IntPtr str, IntPtr baseURL);

		public static CFUrl Create(string absolute)
		{
			if (string.IsNullOrEmpty(absolute))
			{
				return null;
			}
			CFString cFString = CFString.Create(absolute);
			IntPtr intPtr = CFURLCreateWithString(IntPtr.Zero, cFString.Handle, IntPtr.Zero);
			cFString.Dispose();
			if (intPtr == IntPtr.Zero)
			{
				return null;
			}
			return new CFUrl(intPtr, own: true);
		}
	}
	internal class CFRunLoop : CFObject
	{
		public static CFRunLoop CurrentRunLoop => new CFRunLoop(CFRunLoopGetCurrent(), own: false);

		[DllImport("/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation")]
		private static extern void CFRunLoopAddSource(IntPtr rl, IntPtr source, IntPtr mode);

		[DllImport("/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation")]
		private static extern void CFRunLoopRemoveSource(IntPtr rl, IntPtr source, IntPtr mode);

		[DllImport("/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation")]
		private static extern int CFRunLoopRunInMode(IntPtr mode, double seconds, bool returnAfterSourceHandled);

		[DllImport("/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation")]
		private static extern IntPtr CFRunLoopGetCurrent();

		[DllImport("/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation")]
		private static extern void CFRunLoopStop(IntPtr rl);

		public CFRunLoop(IntPtr handle, bool own)
			: base(handle, own)
		{
		}

		public void AddSource(IntPtr source, CFString mode)
		{
			CFRunLoopAddSource(base.Handle, source, mode.Handle);
		}

		public void RemoveSource(IntPtr source, CFString mode)
		{
			CFRunLoopRemoveSource(base.Handle, source, mode.Handle);
		}

		public int RunInMode(CFString mode, double seconds, bool returnAfterSourceHandled)
		{
			return CFRunLoopRunInMode(mode.Handle, seconds, returnAfterSourceHandled);
		}

		public void Stop()
		{
			CFRunLoopStop(base.Handle);
		}
	}
	internal enum CFProxyType
	{
		None,
		AutoConfigurationUrl,
		AutoConfigurationJavaScript,
		FTP,
		HTTP,
		HTTPS,
		SOCKS
	}
	internal class CFProxy
	{
		private static IntPtr kCFProxyAutoConfigurationJavaScriptKey;

		private static IntPtr kCFProxyAutoConfigurationURLKey;

		private static IntPtr kCFProxyHostNameKey;

		private static IntPtr kCFProxyPasswordKey;

		private static IntPtr kCFProxyPortNumberKey;

		private static IntPtr kCFProxyTypeKey;

		private static IntPtr kCFProxyUsernameKey;

		private static IntPtr kCFProxyTypeAutoConfigurationURL;

		private static IntPtr kCFProxyTypeAutoConfigurationJavaScript;

		private static IntPtr kCFProxyTypeFTP;

		private static IntPtr kCFProxyTypeHTTP;

		private static IntPtr kCFProxyTypeHTTPS;

		private static IntPtr kCFProxyTypeSOCKS;

		private CFDictionary settings;

		public IntPtr AutoConfigurationJavaScript
		{
			get
			{
				if (kCFProxyAutoConfigurationJavaScriptKey == IntPtr.Zero)
				{
					return IntPtr.Zero;
				}
				return settings[kCFProxyAutoConfigurationJavaScriptKey];
			}
		}

		public IntPtr AutoConfigurationUrl
		{
			get
			{
				if (kCFProxyAutoConfigurationURLKey == IntPtr.Zero)
				{
					return IntPtr.Zero;
				}
				return settings[kCFProxyAutoConfigurationURLKey];
			}
		}

		public string HostName
		{
			get
			{
				if (kCFProxyHostNameKey == IntPtr.Zero)
				{
					return null;
				}
				return CFString.AsString(settings[kCFProxyHostNameKey]);
			}
		}

		public string Password
		{
			get
			{
				if (kCFProxyPasswordKey == IntPtr.Zero)
				{
					return null;
				}
				return CFString.AsString(settings[kCFProxyPasswordKey]);
			}
		}

		public int Port
		{
			get
			{
				if (kCFProxyPortNumberKey == IntPtr.Zero)
				{
					return 0;
				}
				return CFNumber.AsInt32(settings[kCFProxyPortNumberKey]);
			}
		}

		public CFProxyType ProxyType
		{
			get
			{
				if (kCFProxyTypeKey == IntPtr.Zero)
				{
					return CFProxyType.None;
				}
				return CFProxyTypeToEnum(settings[kCFProxyTypeKey]);
			}
		}

		public string Username
		{
			get
			{
				if (kCFProxyUsernameKey == IntPtr.Zero)
				{
					return null;
				}
				return CFString.AsString(settings[kCFProxyUsernameKey]);
			}
		}

		static CFProxy()
		{
			IntPtr handle = CFObject.dlopen("/System/Library/Frameworks/CoreServices.framework/Frameworks/CFNetwork.framework/CFNetwork", 0);
			kCFProxyAutoConfigurationJavaScriptKey = CFObject.GetCFObjectHandle(handle, "kCFProxyAutoConfigurationJavaScriptKey");
			kCFProxyAutoConfigurationURLKey = CFObject.GetCFObjectHandle(handle, "kCFProxyAutoConfigurationURLKey");
			kCFProxyHostNameKey = CFObject.GetCFObjectHandle(handle, "kCFProxyHostNameKey");
			kCFProxyPasswordKey = CFObject.GetCFObjectHandle(handle, "kCFProxyPasswordKey");
			kCFProxyPortNumberKey = CFObject.GetCFObjectHandle(handle, "kCFProxyPortNumberKey");
			kCFProxyTypeKey = CFObject.GetCFObjectHandle(handle, "kCFProxyTypeKey");
			kCFProxyUsernameKey = CFObject.GetCFObjectHandle(handle, "kCFProxyUsernameKey");
			kCFProxyTypeAutoConfigurationURL = CFObject.GetCFObjectHandle(handle, "kCFProxyTypeAutoConfigurationURL");
			kCFProxyTypeAutoConfigurationJavaScript = CFObject.GetCFObjectHandle(handle, "kCFProxyTypeAutoConfigurationJavaScript");
			kCFProxyTypeFTP = CFObject.GetCFObjectHandle(handle, "kCFProxyTypeFTP");
			kCFProxyTypeHTTP = CFObject.GetCFObjectHandle(handle, "kCFProxyTypeHTTP");
			kCFProxyTypeHTTPS = CFObject.GetCFObjectHandle(handle, "kCFProxyTypeHTTPS");
			kCFProxyTypeSOCKS = CFObject.GetCFObjectHandle(handle, "kCFProxyTypeSOCKS");
			CFObject.dlclose(handle);
		}

		internal CFProxy(CFDictionary settings)
		{
			this.settings = settings;
		}

		private static CFProxyType CFProxyTypeToEnum(IntPtr type)
		{
			if (type == kCFProxyTypeAutoConfigurationJavaScript)
			{
				return CFProxyType.AutoConfigurationJavaScript;
			}
			if (type == kCFProxyTypeAutoConfigurationURL)
			{
				return CFProxyType.AutoConfigurationUrl;
			}
			if (type == kCFProxyTypeFTP)
			{
				return CFProxyType.FTP;
			}
			if (type == kCFProxyTypeHTTP)
			{
				return CFProxyType.HTTP;
			}
			if (type == kCFProxyTypeHTTPS)
			{
				return CFProxyType.HTTPS;
			}
			if (type == kCFProxyTypeSOCKS)
			{
				return CFProxyType.SOCKS;
			}
			if (CFString.Compare(type, kCFProxyTypeAutoConfigurationJavaScript) == 0)
			{
				return CFProxyType.AutoConfigurationJavaScript;
			}
			if (CFString.Compare(type, kCFProxyTypeAutoConfigurationURL) == 0)
			{
				return CFProxyType.AutoConfigurationUrl;
			}
			if (CFString.Compare(type, kCFProxyTypeFTP) == 0)
			{
				return CFProxyType.FTP;
			}
			if (CFString.Compare(type, kCFProxyTypeHTTP) == 0)
			{
				return CFProxyType.HTTP;
			}
			if (CFString.Compare(type, kCFProxyTypeHTTPS) == 0)
			{
				return CFProxyType.HTTPS;
			}
			if (CFString.Compare(type, kCFProxyTypeSOCKS) == 0)
			{
				return CFProxyType.SOCKS;
			}
			return CFProxyType.None;
		}
	}
	internal class CFProxySettings
	{
		private static IntPtr kCFNetworkProxiesHTTPEnable;

		private static IntPtr kCFNetworkProxiesHTTPPort;

		private static IntPtr kCFNetworkProxiesHTTPProxy;

		private static IntPtr kCFNetworkProxiesProxyAutoConfigEnable;

		private static IntPtr kCFNetworkProxiesProxyAutoConfigJavaScript;

		private static IntPtr kCFNetworkProxiesProxyAutoConfigURLString;

		private CFDictionary settings;

		public CFDictionary Dictionary => settings;

		public bool HTTPEnable
		{
			get
			{
				if (kCFNetworkProxiesHTTPEnable == IntPtr.Zero)
				{
					return false;
				}
				return CFNumber.AsBool(settings[kCFNetworkProxiesHTTPEnable]);
			}
		}

		public int HTTPPort
		{
			get
			{
				if (kCFNetworkProxiesHTTPPort == IntPtr.Zero)
				{
					return 0;
				}
				return CFNumber.AsInt32(settings[kCFNetworkProxiesHTTPPort]);
			}
		}

		public string HTTPProxy
		{
			get
			{
				if (kCFNetworkProxiesHTTPProxy == IntPtr.Zero)
				{
					return null;
				}
				return CFString.AsString(settings[kCFNetworkProxiesHTTPProxy]);
			}
		}

		public bool ProxyAutoConfigEnable
		{
			get
			{
				if (kCFNetworkProxiesProxyAutoConfigEnable == IntPtr.Zero)
				{
					return false;
				}
				return CFNumber.AsBool(settings[kCFNetworkProxiesProxyAutoConfigEnable]);
			}
		}

		public string ProxyAutoConfigJavaScript
		{
			get
			{
				if (kCFNetworkProxiesProxyAutoConfigJavaScript == IntPtr.Zero)
				{
					return null;
				}
				return CFString.AsString(settings[kCFNetworkProxiesProxyAutoConfigJavaScript]);
			}
		}

		public string ProxyAutoConfigURLString
		{
			get
			{
				if (kCFNetworkProxiesProxyAutoConfigURLString == IntPtr.Zero)
				{
					return null;
				}
				return CFString.AsString(settings[kCFNetworkProxiesProxyAutoConfigURLString]);
			}
		}

		static CFProxySettings()
		{
			IntPtr handle = CFObject.dlopen("/System/Library/Frameworks/CoreServices.framework/Frameworks/CFNetwork.framework/CFNetwork", 0);
			kCFNetworkProxiesHTTPEnable = CFObject.GetCFObjectHandle(handle, "kCFNetworkProxiesHTTPEnable");
			kCFNetworkProxiesHTTPPort = CFObject.GetCFObjectHandle(handle, "kCFNetworkProxiesHTTPPort");
			kCFNetworkProxiesHTTPProxy = CFObject.GetCFObjectHandle(handle, "kCFNetworkProxiesHTTPProxy");
			kCFNetworkProxiesProxyAutoConfigEnable = CFObject.GetCFObjectHandle(handle, "kCFNetworkProxiesProxyAutoConfigEnable");
			kCFNetworkProxiesProxyAutoConfigJavaScript = CFObject.GetCFObjectHandle(handle, "kCFNetworkProxiesProxyAutoConfigJavaScript");
			kCFNetworkProxiesProxyAutoConfigURLString = CFObject.GetCFObjectHandle(handle, "kCFNetworkProxiesProxyAutoConfigURLString");
			CFObject.dlclose(handle);
		}

		public CFProxySettings(CFDictionary settings)
		{
			this.settings = settings;
		}
	}
	internal static class CFNetwork
	{
		private class GetProxyData : IDisposable
		{
			public IntPtr script;

			public IntPtr targetUri;

			public IntPtr error;

			public IntPtr result;

			public ManualResetEvent evt = new ManualResetEvent(initialState: false);

			public void Dispose()
			{
				evt.Close();
			}
		}

		private delegate void CFProxyAutoConfigurationResultCallback(IntPtr client, IntPtr proxyList, IntPtr error);

		private class CFWebProxy : IWebProxy
		{
			private ICredentials credentials;

			private bool userSpecified;

			public ICredentials Credentials
			{
				get
				{
					return credentials;
				}
				set
				{
					userSpecified = true;
					credentials = value;
				}
			}

			private static Uri GetProxyUri(CFProxy proxy, out NetworkCredential credentials)
			{
				string text;
				switch (proxy.ProxyType)
				{
				case CFProxyType.FTP:
					text = "ftp://";
					break;
				case CFProxyType.HTTP:
				case CFProxyType.HTTPS:
					text = "http://";
					break;
				default:
					credentials = null;
					return null;
				}
				string username = proxy.Username;
				string password = proxy.Password;
				string hostName = proxy.HostName;
				int port = proxy.Port;
				if (username != null)
				{
					credentials = new NetworkCredential(username, password);
				}
				else
				{
					credentials = null;
				}
				return new Uri(text + hostName + ((port != 0) ? (":" + port) : string.Empty), UriKind.Absolute);
			}

			private static Uri GetProxyUriFromScript(IntPtr script, Uri targetUri, out NetworkCredential credentials)
			{
				return SelectProxy(GetProxiesForAutoConfigurationScript(script, targetUri), targetUri, out credentials);
			}

			private static Uri ExecuteProxyAutoConfigurationURL(IntPtr proxyAutoConfigURL, Uri targetUri, out NetworkCredential credentials)
			{
				return SelectProxy(CFNetwork.ExecuteProxyAutoConfigurationURL(proxyAutoConfigURL, targetUri), targetUri, out credentials);
			}

			private static Uri SelectProxy(CFProxy[] proxies, Uri targetUri, out NetworkCredential credentials)
			{
				if (proxies == null)
				{
					credentials = null;
					return targetUri;
				}
				for (int i = 0; i < proxies.Length; i++)
				{
					switch (proxies[i].ProxyType)
					{
					case CFProxyType.FTP:
					case CFProxyType.HTTP:
					case CFProxyType.HTTPS:
						return GetProxyUri(proxies[i], out credentials);
					case CFProxyType.None:
						credentials = null;
						return targetUri;
					}
				}
				credentials = null;
				return null;
			}

			public Uri GetProxy(Uri targetUri)
			{
				NetworkCredential networkCredential = null;
				Uri uri = null;
				if (targetUri == null)
				{
					throw new ArgumentNullException("targetUri");
				}
				try
				{
					CFProxySettings systemProxySettings = GetSystemProxySettings();
					CFProxy[] proxiesForUri = GetProxiesForUri(targetUri, systemProxySettings);
					if (proxiesForUri != null)
					{
						for (int i = 0; i < proxiesForUri.Length; i++)
						{
							if (!(uri == null))
							{
								break;
							}
							switch (proxiesForUri[i].ProxyType)
							{
							case CFProxyType.AutoConfigurationJavaScript:
								uri = GetProxyUriFromScript(proxiesForUri[i].AutoConfigurationJavaScript, targetUri, out networkCredential);
								break;
							case CFProxyType.AutoConfigurationUrl:
								uri = ExecuteProxyAutoConfigurationURL(proxiesForUri[i].AutoConfigurationUrl, targetUri, out networkCredential);
								break;
							case CFProxyType.FTP:
							case CFProxyType.HTTP:
							case CFProxyType.HTTPS:
								uri = GetProxyUri(proxiesForUri[i], out networkCredential);
								break;
							case CFProxyType.None:
								uri = targetUri;
								break;
							}
						}
						if (uri == null)
						{
							uri = targetUri;
						}
					}
					else
					{
						uri = targetUri;
					}
				}
				catch
				{
					uri = targetUri;
				}
				if (!userSpecified)
				{
					credentials = networkCredential;
				}
				return uri;
			}

			public bool IsBypassed(Uri targetUri)
			{
				if (targetUri == null)
				{
					throw new ArgumentNullException("targetUri");
				}
				return GetProxy(targetUri) == targetUri;
			}
		}

		public const string CFNetworkLibrary = "/System/Library/Frameworks/CoreServices.framework/Frameworks/CFNetwork.framework/CFNetwork";

		private static object lock_obj = new object();

		private static Queue<GetProxyData> get_proxy_queue;

		private static AutoResetEvent proxy_event;

		[DllImport("/System/Library/Frameworks/CoreServices.framework/Frameworks/CFNetwork.framework/CFNetwork", EntryPoint = "CFNetworkCopyProxiesForAutoConfigurationScript")]
		private static extern IntPtr CFNetworkCopyProxiesForAutoConfigurationScriptSequential(IntPtr proxyAutoConfigurationScript, IntPtr targetURL, out IntPtr error);

		[DllImport("/System/Library/Frameworks/CoreServices.framework/Frameworks/CFNetwork.framework/CFNetwork")]
		private static extern IntPtr CFNetworkExecuteProxyAutoConfigurationURL(IntPtr proxyAutoConfigURL, IntPtr targetURL, CFProxyAutoConfigurationResultCallback cb, ref CFStreamClientContext clientContext);

		private static void CFNetworkCopyProxiesForAutoConfigurationScriptThread()
		{
			bool flag = true;
			while (true)
			{
				proxy_event.WaitOne();
				do
				{
					GetProxyData getProxyData;
					lock (lock_obj)
					{
						if (get_proxy_queue.Count == 0)
						{
							break;
						}
						getProxyData = get_proxy_queue.Dequeue();
						flag = get_proxy_queue.Count > 0;
						goto IL_0050;
					}
					IL_0050:
					getProxyData.result = CFNetworkCopyProxiesForAutoConfigurationScriptSequential(getProxyData.script, getProxyData.targetUri, out getProxyData.error);
					getProxyData.evt.Set();
				}
				while (flag);
			}
		}

		private static IntPtr CFNetworkCopyProxiesForAutoConfigurationScript(IntPtr proxyAutoConfigurationScript, IntPtr targetURL, out IntPtr error)
		{
			using GetProxyData getProxyData = new GetProxyData();
			getProxyData.script = proxyAutoConfigurationScript;
			getProxyData.targetUri = targetURL;
			lock (lock_obj)
			{
				if (get_proxy_queue == null)
				{
					get_proxy_queue = new Queue<GetProxyData>();
					proxy_event = new AutoResetEvent(initialState: false);
					Thread thread = new Thread(CFNetworkCopyProxiesForAutoConfigurationScriptThread);
					thread.IsBackground = true;
					thread.Start();
				}
				get_proxy_queue.Enqueue(getProxyData);
				proxy_event.Set();
			}
			getProxyData.evt.WaitOne();
			error = getProxyData.error;
			return getProxyData.result;
		}

		private static CFArray CopyProxiesForAutoConfigurationScript(IntPtr proxyAutoConfigurationScript, CFUrl targetURL)
		{
			IntPtr error = IntPtr.Zero;
			IntPtr intPtr = CFNetworkCopyProxiesForAutoConfigurationScript(proxyAutoConfigurationScript, targetURL.Handle, out error);
			if (intPtr == IntPtr.Zero)
			{
				return null;
			}
			return new CFArray(intPtr, own: true);
		}

		public static CFProxy[] GetProxiesForAutoConfigurationScript(IntPtr proxyAutoConfigurationScript, CFUrl targetURL)
		{
			if (proxyAutoConfigurationScript == IntPtr.Zero)
			{
				throw new ArgumentNullException("proxyAutoConfigurationScript");
			}
			if (targetURL == null)
			{
				throw new ArgumentNullException("targetURL");
			}
			CFArray cFArray = CopyProxiesForAutoConfigurationScript(proxyAutoConfigurationScript, targetURL);
			if (cFArray == null)
			{
				return null;
			}
			CFProxy[] array = new CFProxy[cFArray.Count];
			for (int i = 0; i < array.Length; i++)
			{
				CFDictionary settings = new CFDictionary(cFArray[i], own: false);
				array[i] = new CFProxy(settings);
			}
			cFArray.Dispose();
			return array;
		}

		public static CFProxy[] GetProxiesForAutoConfigurationScript(IntPtr proxyAutoConfigurationScript, Uri targetUri)
		{
			if (proxyAutoConfigurationScript == IntPtr.Zero)
			{
				throw new ArgumentNullException("proxyAutoConfigurationScript");
			}
			if (targetUri == null)
			{
				throw new ArgumentNullException("targetUri");
			}
			CFUrl cFUrl = CFUrl.Create(targetUri.AbsoluteUri);
			CFProxy[] proxiesForAutoConfigurationScript = GetProxiesForAutoConfigurationScript(proxyAutoConfigurationScript, cFUrl);
			cFUrl.Dispose();
			return proxiesForAutoConfigurationScript;
		}

		public static CFProxy[] ExecuteProxyAutoConfigurationURL(IntPtr proxyAutoConfigURL, Uri targetURL)
		{
			CFUrl cFUrl = CFUrl.Create(targetURL.AbsoluteUri);
			if (cFUrl == null)
			{
				return null;
			}
			CFProxy[] proxies = null;
			CFRunLoop runLoop = CFRunLoop.CurrentRunLoop;
			CFProxyAutoConfigurationResultCallback cb = delegate(IntPtr client, IntPtr proxyList, IntPtr error)
			{
				if (proxyList != IntPtr.Zero)
				{
					CFArray cFArray = new CFArray(proxyList, own: false);
					proxies = new CFProxy[cFArray.Count];
					for (int i = 0; i < proxies.Length; i++)
					{
						CFDictionary settings = new CFDictionary(cFArray[i], own: false);
						proxies[i] = new CFProxy(settings);
					}
					cFArray.Dispose();
				}
				runLoop.Stop();
			};
			CFStreamClientContext clientContext = default(CFStreamClientContext);
			IntPtr source = CFNetworkExecuteProxyAutoConfigurationURL(proxyAutoConfigURL, cFUrl.Handle, cb, ref clientContext);
			CFString mode = CFString.Create("Mono.MacProxy");
			runLoop.AddSource(source, mode);
			runLoop.RunInMode(mode, double.MaxValue, returnAfterSourceHandled: false);
			runLoop.RemoveSource(source, mode);
			return proxies;
		}

		[DllImport("/System/Library/Frameworks/CoreServices.framework/Frameworks/CFNetwork.framework/CFNetwork")]
		private static extern IntPtr CFNetworkCopyProxiesForURL(IntPtr url, IntPtr proxySettings);

		private static CFArray CopyProxiesForURL(CFUrl url, CFDictionary proxySettings)
		{
			IntPtr intPtr = CFNetworkCopyProxiesForURL(url.Handle, proxySettings?.Handle ?? IntPtr.Zero);
			if (intPtr == IntPtr.Zero)
			{
				return null;
			}
			return new CFArray(intPtr, own: true);
		}

		public static CFProxy[] GetProxiesForURL(CFUrl url, CFProxySettings proxySettings)
		{
			if (url == null || url.Handle == IntPtr.Zero)
			{
				throw new ArgumentNullException("url");
			}
			if (proxySettings == null)
			{
				proxySettings = GetSystemProxySettings();
			}
			CFArray cFArray = CopyProxiesForURL(url, proxySettings.Dictionary);
			if (cFArray == null)
			{
				return null;
			}
			CFProxy[] array = new CFProxy[cFArray.Count];
			for (int i = 0; i < array.Length; i++)
			{
				CFDictionary settings = new CFDictionary(cFArray[i], own: false);
				array[i] = new CFProxy(settings);
			}
			cFArray.Dispose();
			return array;
		}

		public static CFProxy[] GetProxiesForUri(Uri uri, CFProxySettings proxySettings)
		{
			if (uri == null)
			{
				throw new ArgumentNullException("uri");
			}
			CFUrl cFUrl = CFUrl.Create(uri.AbsoluteUri);
			if (cFUrl == null)
			{
				return null;
			}
			CFProxy[] proxiesForURL = GetProxiesForURL(cFUrl, proxySettings);
			cFUrl.Dispose();
			return proxiesForURL;
		}

		[DllImport("/System/Library/Frameworks/CoreServices.framework/Frameworks/CFNetwork.framework/CFNetwork")]
		private static extern IntPtr CFNetworkCopySystemProxySettings();

		public static CFProxySettings GetSystemProxySettings()
		{
			IntPtr intPtr = CFNetworkCopySystemProxySettings();
			if (intPtr == IntPtr.Zero)
			{
				return null;
			}
			return new CFProxySettings(new CFDictionary(intPtr, own: true));
		}

		public static IWebProxy GetDefaultProxy()
		{
			return new CFWebProxy();
		}
	}
}
namespace Mono.Net.Security
{
	internal class BufferOffsetSize
	{
		public byte[] Buffer;

		public int Offset;

		public int Size;

		public int TotalBytes;

		public bool Complete;

		public int EndOffset => Offset + Size;

		public int Remaining => Buffer.Length - Offset - Size;

		public BufferOffsetSize(byte[] buffer, int offset, int size)
		{
			if (buffer == null)
			{
				throw new ArgumentNullException("buffer");
			}
			if (offset < 0)
			{
				throw new ArgumentOutOfRangeException("offset");
			}
			if (size < 0 || offset + size > buffer.Length)
			{
				throw new ArgumentOutOfRangeException("size");
			}
			Buffer = buffer;
			Offset = offset;
			Size = size;
			Complete = false;
		}

		public override string ToString()
		{
			return $"[BufferOffsetSize: {Offset} {Size}]";
		}
	}
	internal class BufferOffsetSize2 : BufferOffsetSize
	{
		public readonly int InitialSize;

		public BufferOffsetSize2(int size)
			: base(new byte[size], 0, 0)
		{
			InitialSize = size;
		}

		public void Reset()
		{
			Offset = (Size = 0);
			TotalBytes = 0;
			Buffer = new byte[InitialSize];
			Complete = false;
		}

		public void MakeRoom(int size)
		{
			if (base.Remaining < size)
			{
				int num = size - base.Remaining;
				if (Offset == 0 && Size == 0)
				{
					Buffer = new byte[size];
					return;
				}
				byte[] array = new byte[Buffer.Length + num];
				Buffer.CopyTo(array, 0);
				Buffer = array;
			}
		}

		public void AppendData(byte[] buffer, int offset, int size)
		{
			MakeRoom(size);
			System.Buffer.BlockCopy(buffer, offset, Buffer, base.EndOffset, size);
			Size += size;
		}
	}
	internal enum AsyncOperationStatus
	{
		Initialize,
		Continue,
		ReadDone,
		Complete
	}
	internal class AsyncProtocolResult
	{
		public int UserResult { get; }

		public ExceptionDispatchInfo Error { get; }

		public AsyncProtocolResult(int result)
		{
			UserResult = result;
		}

		public AsyncProtocolResult(ExceptionDispatchInfo error)
		{
			Error = error;
		}
	}
	internal abstract class AsyncProtocolRequest
	{
		private int Started;

		private int RequestedSize;

		private int WriteRequested;

		private readonly object locker = new object();

		private static int next_id;

		public MobileAuthenticatedStream Parent { get; }

		public bool RunSynchronously { get; }

		public int ID => ++next_id;

		public string Name => GetType().Name;

		public int UserResult { get; protected set; }

		public AsyncProtocolRequest(MobileAuthenticatedStream parent, bool sync)
		{
			Parent = parent;
			RunSynchronously = sync;
		}

		[Conditional("MONO_TLS_DEBUG")]
		protected void Debug(string message, params object[] args)
		{
		}

		internal void RequestRead(int size)
		{
			lock (locker)
			{
				RequestedSize += size;
			}
		}

		internal void RequestWrite()
		{
			WriteRequested = 1;
		}

		internal async Task<AsyncProtocolResult> StartOperation(CancellationToken cancellationToken)
		{
			if (Interlocked.CompareExchange(ref Started, 1, 0) != 0)
			{
				throw new InvalidOperationException();
			}
			try
			{
				await ProcessOperation(cancellationToken).ConfigureAwait(continueOnCapturedContext: false);
				return new AsyncProtocolResult(UserResult);
			}
			catch (Exception exception)
			{
				return new AsyncProtocolResult(Parent.SetException(exception));
			}
		}

		private async Task ProcessOperation(CancellationToken cancellationToken)
		{
			AsyncOperationStatus status = AsyncOperationStatus.Initialize;
			while (status != AsyncOperationStatus.Complete)
			{
				cancellationToken.ThrowIfCancellationRequested();
				int? num = await InnerRead(cancellationToken).ConfigureAwait(continueOnCapturedContext: false);
				if (num.HasValue)
				{
					if (num == 0)
					{
						status = AsyncOperationStatus.ReadDone;
					}
					else if (num < 0)
					{
						throw new IOException("Remote prematurely closed connection.");
					}
				}
				if ((uint)status <= 2u)
				{
					AsyncOperationStatus newStatus;
					try
					{
						newStatus = Run(status);
					}
					catch (Exception e)
					{
						throw MobileAuthenticatedStream.GetSSPIException(e);
					}
					if (Interlocked.Exchange(ref WriteRequested, 0) != 0)
					{
						await Parent.InnerWrite(RunSynchronously, cancellationToken).ConfigureAwait(continueOnCapturedContext: false);
					}
					status = newStatus;
					continue;
				}
				throw new InvalidOperationException();
			}
		}

		private async Task<int?> InnerRead(CancellationToken cancellationToken)
		{
			int? totalRead = null;
			int requestedSize2 = Interlocked.Exchange(ref RequestedSize, 0);
			while (requestedSize2 > 0)
			{
				int num = await Parent.InnerRead(RunSynchronously, requestedSize2, cancellationToken).ConfigureAwait(continueOnCapturedContext: false);
				if (num <= 0)
				{
					return num;
				}
				if (num > requestedSize2)
				{
					throw new InvalidOperationException();
				}
				totalRead += num;
				requestedSize2 -= num;
				int num2 = Interlocked.Exchange(ref RequestedSize, 0);
				requestedSize2 += num2;
			}
			return totalRead;
		}

		protected abstract AsyncOperationStatus Run(AsyncOperationStatus status);

		public override string ToString()
		{
			return $"[{Name}]";
		}
	}
	internal class AsyncHandshakeRequest : AsyncProtocolRequest
	{
		public AsyncHandshakeRequest(MobileAuthenticatedStream parent, bool sync)
			: base(parent, sync)
		{
		}

		protected override AsyncOperationStatus Run(AsyncOperationStatus status)
		{
			return base.Parent.ProcessHandshake(status, renegotiate: false);
		}
	}
	internal abstract class AsyncReadOrWriteRequest : AsyncProtocolRequest
	{
		protected BufferOffsetSize UserBuffer { get; }

		protected int CurrentSize { get; set; }

		public AsyncReadOrWriteRequest(MobileAuthenticatedStream parent, bool sync, byte[] buffer, int offset, int size)
			: base(parent, sync)
		{
			UserBuffer = new BufferOffsetSize(buffer, offset, size);
		}

		public override string ToString()
		{
			return $"[{base.Name}: {UserBuffer}]";
		}
	}
	internal class AsyncReadRequest : AsyncReadOrWriteRequest
	{
		public AsyncReadRequest(MobileAuthenticatedStream parent, bool sync, byte[] buffer, int offset, int size)
			: base(parent, sync, buffer, offset, size)
		{
		}

		protected override AsyncOperationStatus Run(AsyncOperationStatus status)
		{
			var (num, flag) = base.Parent.ProcessRead(base.UserBuffer);
			if (num < 0)
			{
				base.UserResult = -1;
				return AsyncOperationStatus.Complete;
			}
			base.CurrentSize += num;
			base.UserBuffer.Offset += num;
			base.UserBuffer.Size -= num;
			if (flag && base.CurrentSize == 0)
			{
				return AsyncOperationStatus.Continue;
			}
			base.UserResult = base.CurrentSize;
			return AsyncOperationStatus.Complete;
		}
	}
	internal class AsyncWriteRequest : AsyncReadOrWriteRequest
	{
		public AsyncWriteRequest(MobileAuthenticatedStream parent, bool sync, byte[] buffer, int offset, int size)
			: base(parent, sync, buffer, offset, size)
		{
		}

		protected override AsyncOperationStatus Run(AsyncOperationStatus status)
		{
			if (base.UserBuffer.Size == 0)
			{
				base.UserResult = base.CurrentSize;
				return AsyncOperationStatus.Complete;
			}
			var (num, flag) = base.Parent.ProcessWrite(base.UserBuffer);
			if (num < 0)
			{
				base.UserResult = -1;
				return AsyncOperationStatus.Complete;
			}
			base.CurrentSize += num;
			base.UserBuffer.Offset += num;
			base.UserBuffer.Size -= num;
			if (flag)
			{
				return AsyncOperationStatus.Continue;
			}
			base.UserResult = base.CurrentSize;
			return AsyncOperationStatus.Complete;
		}
	}
	internal class AsyncShutdownRequest : AsyncProtocolRequest
	{
		public AsyncShutdownRequest(MobileAuthenticatedStream parent)
			: base(parent, sync: false)
		{
		}

		protected override AsyncOperationStatus Run(AsyncOperationStatus status)
		{
			return base.Parent.ProcessShutdown(status);
		}
	}
	internal class AsyncRenegotiateRequest : AsyncProtocolRequest
	{
		public AsyncRenegotiateRequest(MobileAuthenticatedStream parent)
			: base(parent, sync: false)
		{
		}

		protected override AsyncOperationStatus Run(AsyncOperationStatus status)
		{
			return base.Parent.ProcessHandshake(status, renegotiate: true);
		}
	}
	internal delegate bool ServerCertValidationCallbackWrapper(ServerCertValidationCallback callback, X509Certificate certificate, X509Chain chain, MonoSslPolicyErrors sslPolicyErrors);
	internal class ChainValidationHelper : ICertificateValidator
	{
		private readonly WeakReference<SslStream> owner;

		private readonly MonoTlsSettings settings;

		private readonly MobileTlsProvider provider;

		private readonly ServerCertValidationCallback certValidationCallback;

		private readonly LocalCertSelectionCallback certSelectionCallback;

		private readonly MonoTlsStream tlsStream;

		private readonly HttpWebRequest request;

		public MonoTlsProvider Provider => (MonoTlsProvider)(object)provider;

		public MonoTlsSettings Settings => settings;

		public bool HasCertificateSelectionCallback => certSelectionCallback != null;

		internal static ChainValidationHelper GetInternalValidator(SslStream owner, MobileTlsProvider provider, MonoTlsSettings settings)
		{
			if (settings == null)
			{
				return new ChainValidationHelper(owner, provider, null, cloneSettings: false, null);
			}
			if (settings.CertificateValidator != null)
			{
				return (ChainValidationHelper)(object)settings.CertificateValidator;
			}
			return new ChainValidationHelper(owner, provider, settings, cloneSettings: false, null);
		}

		internal static ICertificateValidator GetDefaultValidator(MonoTlsSettings settings)
		{
			MobileTlsProvider providerInternal = MonoTlsProviderFactory.GetProviderInternal();
			if (settings == null)
			{
				return (ICertificateValidator)(object)new ChainValidationHelper(null, providerInternal, null, cloneSettings: false, null);
			}
			if (settings.CertificateValidator != null)
			{
				throw new NotSupportedException();
			}
			return (ICertificateValidator)(object)new ChainValidationHelper(null, providerInternal, settings, cloneSettings: false, null);
		}

		internal static ChainValidationHelper Create(MobileTlsProvider provider, ref MonoTlsSettings settings, MonoTlsStream stream)
		{
			ChainValidationHelper chainValidationHelper = new ChainValidationHelper(null, provider, settings, cloneSettings:

BepInExPack/mono/Managed/System.IO.Compression.dll

Decompiled a month ago
using System;
using System.Buffers;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Globalization;
using System.IO.Compression;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Win32.SafeHandles;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("System.IO.Compression.dll")]
[assembly: AssemblyDescription("System.IO.Compression.dll")]
[assembly: AssemblyDefaultAlias("System.IO.Compression.dll")]
[assembly: AssemblyCompany("Mono development team")]
[assembly: AssemblyProduct("Mono Common Language Infrastructure")]
[assembly: AssemblyCopyright("(c) Various Mono authors")]
[assembly: AssemblyInformationalVersion("4.6.57.0")]
[assembly: AssemblyFileVersion("4.6.57.0")]
[assembly: AssemblyDelaySign(true)]
[assembly: CLSCompliant(true)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("4.0.0.0")]
[assembly: TypeForwardedTo(typeof(CompressionLevel))]
[assembly: TypeForwardedTo(typeof(CompressionMode))]
[assembly: TypeForwardedTo(typeof(DeflateStream))]
[assembly: TypeForwardedTo(typeof(GZipStream))]
[module: UnverifiableCode]
internal static class Consts
{
	public const string MonoCorlibVersion = "1A5E0066-58DC-428A-B21C-0AD6CDAE2789";

	public const string MonoVersion = "6.13.0.0";

	public const string MonoCompany = "Mono development team";

	public const string MonoProduct = "Mono Common Language Infrastructure";

	public const string MonoCopyright = "(c) Various Mono authors";

	public const string FxVersion = "4.0.0.0";

	public const string FxFileVersion = "4.6.57.0";

	public const string EnvironmentVersion = "4.0.30319.42000";

	public const string VsVersion = "0.0.0.0";

	public const string VsFileVersion = "11.0.0.0";

	private const string PublicKeyToken = "b77a5c561934e089";

	public const string AssemblyI18N = "I18N, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756";

	public const string AssemblyMicrosoft_JScript = "Microsoft.JScript, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblyMicrosoft_VisualStudio = "Microsoft.VisualStudio, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblyMicrosoft_VisualStudio_Web = "Microsoft.VisualStudio.Web, Version=0.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblyMicrosoft_VSDesigner = "Microsoft.VSDesigner, Version=0.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblyMono_Http = "Mono.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756";

	public const string AssemblyMono_Posix = "Mono.Posix, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756";

	public const string AssemblyMono_Security = "Mono.Security, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756";

	public const string AssemblyMono_Messaging_RabbitMQ = "Mono.Messaging.RabbitMQ, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756";

	public const string AssemblyCorlib = "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string AssemblySystem = "System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string AssemblySystem_Data = "System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string AssemblySystem_Design = "System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_DirectoryServices = "System.DirectoryServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_Drawing = "System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_Drawing_Design = "System.Drawing.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_Messaging = "System.Messaging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_Security = "System.Security, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_ServiceProcess = "System.ServiceProcess, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_Web = "System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_Windows_Forms = "System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string AssemblySystem_2_0 = "System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string AssemblySystemCore_3_5 = "System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string AssemblySystem_Core = "System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string WindowsBase_3_0 = "WindowsBase, Version=3.0.0.0, PublicKeyToken=31bf3856ad364e35";

	public const string AssemblyWindowsBase = "WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";

	public const string AssemblyPresentationCore_3_5 = "PresentationCore, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";

	public const string AssemblyPresentationCore_4_0 = "PresentationCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";

	public const string AssemblyPresentationFramework_3_5 = "PresentationFramework, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";

	public const string AssemblySystemServiceModel_3_0 = "System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";
}
internal static class SR
{
	public const string ArgumentOutOfRange_Enum = "Enum value was out of legal range.";

	public const string ArgumentOutOfRange_NeedPosNum = "Positive number required.";

	public const string CannotReadFromDeflateStream = "Reading from the compression stream is not supported.";

	public const string CannotWriteToDeflateStream = "Writing to the compression stream is not supported.";

	public const string GenericInvalidData = "Found invalid data while decoding.";

	public const string InvalidArgumentOffsetCount = "Offset plus count is larger than the length of target array.";

	public const string InvalidBeginCall = "Only one asynchronous reader or writer is allowed time at one time.";

	public const string InvalidBlockLength = "Block length does not match with its complement.";

	public const string InvalidHuffmanData = "Failed to construct a huffman tree using the length array. The stream might be corrupted.";

	public const string NotSupported = "This operation is not supported.";

	public const string NotSupported_UnreadableStream = "Stream does not support reading.";

	public const string NotSupported_UnwritableStream = "Stream does not support writing.";

	public const string ObjectDisposed_StreamClosed = "Can not access a closed Stream.";

	public const string UnknownBlockType = "Unknown block type. Stream might be corrupted.";

	public const string UnknownState = "Decoder is in some unknown state. This might be caused by corrupted data.";

	public const string ZLibErrorDLLLoadError = "The underlying compression routine could not be loaded correctly.";

	public const string ZLibErrorInconsistentStream = "The stream state of the underlying compression routine is inconsistent.";

	public const string ZLibErrorIncorrectInitParameters = "The underlying compression routine received incorrect initialization parameters.";

	public const string ZLibErrorNotEnoughMemory = "The underlying compression routine could not reserve sufficient memory.";

	public const string ZLibErrorVersionMismatch = "The version of the underlying compression routine does not match expected version.";

	public const string ZLibErrorUnexpected = "The underlying compression routine returned an unexpected error code.";

	public const string ArgumentNeedNonNegative = "The argument must be non-negative.";

	public const string CannotBeEmpty = "String cannot be empty.";

	public const string CDCorrupt = "Central Directory corrupt.";

	public const string CentralDirectoryInvalid = "Central Directory is invalid.";

	public const string CreateInReadMode = "Cannot create entries on an archive opened in read mode.";

	public const string CreateModeCapabilities = "Cannot use create mode on a non-writable stream.";

	public const string CreateModeCreateEntryWhileOpen = "Entries cannot be created while previously created entries are still open.";

	public const string CreateModeWriteOnceAndOneEntryAtATime = "Entries in create mode may only be written to once, and only one entry may be held open at a time.";

	public const string DateTimeOutOfRange = "The DateTimeOffset specified cannot be converted into a Zip file timestamp.";

	public const string DeletedEntry = "Cannot modify deleted entry.";

	public const string DeleteOnlyInUpdate = "Delete can only be used when the archive is in Update mode.";

	public const string DeleteOpenEntry = "Cannot delete an entry currently open for writing.";

	public const string EntriesInCreateMode = "Cannot access entries in Create mode.";

	public const string EntryNameEncodingNotSupported = "The specified entry name encoding is not supported.";

	public const string EntryNamesTooLong = "Entry names cannot require more than 2^16 bits.";

	public const string EntryTooLarge = "Entries larger than 4GB are not supported in Update mode.";

	public const string EOCDNotFound = "End of Central Directory record could not be found.";

	public const string FieldTooBigCompressedSize = "Compressed Size cannot be held in an Int64.";

	public const string FieldTooBigLocalHeaderOffset = "Local Header Offset cannot be held in an Int64.";

	public const string FieldTooBigNumEntries = "Number of Entries cannot be held in an Int64.";

	public const string FieldTooBigOffsetToCD = "Offset to Central Directory cannot be held in an Int64.";

	public const string FieldTooBigOffsetToZip64EOCD = "Offset to Zip64 End Of Central Directory record cannot be held in an Int64.";

	public const string FieldTooBigStartDiskNumber = "Start Disk Number cannot be held in an Int64.";

	public const string FieldTooBigUncompressedSize = "Uncompressed Size cannot be held in an Int64.";

	public const string FrozenAfterWrite = "Cannot modify entry in Create mode after entry has been opened for writing.";

	public const string HiddenStreamName = "A stream from ZipArchiveEntry has been disposed.";

	public const string LengthAfterWrite = "Length properties are unavailable once an entry has been opened for writing.";

	public const string LocalFileHeaderCorrupt = "A local file header is corrupt.";

	public const string NumEntriesWrong = "Number of entries expected in End Of Central Directory does not correspond to number of entries in Central Directory.";

	public const string OffsetLengthInvalid = "The offset and length parameters are not valid for the array that was given.";

	public const string ReadingNotSupported = "This stream from ZipArchiveEntry does not support reading.";

	public const string ReadModeCapabilities = "Cannot use read mode on a non-readable stream.";

	public const string ReadOnlyArchive = "Cannot modify read-only archive.";

	public const string SeekingNotSupported = "This stream from ZipArchiveEntry does not support seeking.";

	public const string SetLengthRequiresSeekingAndWriting = "SetLength requires a stream that supports seeking and writing.";

	public const string SplitSpanned = "Split or spanned archives are not supported.";

	public const string UnexpectedEndOfStream = "Zip file corrupt: unexpected end of stream reached.";

	public const string UnsupportedCompression = "The archive entry was compressed using an unsupported compression method.";

	public const string UnsupportedCompressionMethod = "The archive entry was compressed using {0} and is not supported.";

	public const string UpdateModeCapabilities = "Update mode requires a stream with read, write, and seek capabilities.";

	public const string UpdateModeOneStream = "Entries cannot be opened multiple times in Update mode.";

	public const string WritingNotSupported = "This stream from ZipArchiveEntry does not support writing.";

	public const string Zip64EOCDNotWhereExpected = "Zip 64 End of Central Directory Record not where indicated.";

	public const string Argument_InvalidPathChars = "Illegal characters in path '{0}'.";

	public const string Stream_FalseCanRead = "Stream does not support reading.";

	public const string Stream_FalseCanWrite = "Stream does not support writing.";

	public const string BrotliEncoder_Create = "Failed to create BrotliEncoder instance";

	public const string BrotliEncoder_Disposed = "Can not access a closed Encoder.";

	public const string BrotliEncoder_Quality = "Provided BrotliEncoder Quality of {0} is not between the minimum value of {1} and the maximum value of {2}";

	public const string BrotliEncoder_Window = "Provided BrotliEncoder Window of {0} is not between the minimum value of {1} and the maximum value of {2}";

	public const string BrotliEncoder_InvalidSetParameter = "The BrotliEncoder {0} can not be changed at current encoder state.";

	public const string BrotliDecoder_Create = "Failed to create BrotliDecoder instance";

	public const string BrotliDecoder_Error = "Decoder threw unexpected error: {0}";

	public const string BrotliDecoder_Disposed = "Can not access a closed Decoder.";

	public const string BrotliStream_Compress_UnsupportedOperation = "Can not perform Read operations on a BrotliStream constructed with CompressionMode.Compress.";

	public const string BrotliStream_Compress_InvalidData = "Encoder ran into invalid data.";

	public const string BrotliStream_Decompress_UnsupportedOperation = "Can not perform Write operations on a BrotliStream constructed with CompressionMode.Decompress.";

	public const string BrotliStream_Decompress_InvalidData = "Decoder ran into invalid data.";

	public const string BrotliStream_Decompress_InvalidStream = "BrotliStream.BaseStream returned more bytes than requested in Read.";

	internal static string GetString(string name, params object[] args)
	{
		return GetString(CultureInfo.InvariantCulture, name, args);
	}

	internal static string GetString(CultureInfo culture, string name, params object[] args)
	{
		return string.Format(culture, name, args);
	}

	internal static string GetString(string name)
	{
		return name;
	}

	internal static string GetString(CultureInfo culture, string name)
	{
		return name;
	}

	internal static string Format(string resourceFormat, params object[] args)
	{
		if (args != null)
		{
			return string.Format(CultureInfo.InvariantCulture, resourceFormat, args);
		}
		return resourceFormat;
	}

	internal static string Format(string resourceFormat, object p1)
	{
		return string.Format(CultureInfo.InvariantCulture, resourceFormat, p1);
	}

	internal static string Format(string resourceFormat, object p1, object p2)
	{
		return string.Format(CultureInfo.InvariantCulture, resourceFormat, p1, p2);
	}

	internal static string Format(CultureInfo ci, string resourceFormat, object p1, object p2)
	{
		return string.Format(ci, resourceFormat, p1, p2);
	}

	internal static string Format(string resourceFormat, object p1, object p2, object p3)
	{
		return string.Format(CultureInfo.InvariantCulture, resourceFormat, p1, p2, p3);
	}

	internal static string GetResourceString(string str)
	{
		return str;
	}
}
internal static class Interop
{
	internal static class Brotli
	{
		internal static SafeBrotliEncoderHandle BrotliEncoderCreateInstance(IntPtr allocFunc, IntPtr freeFunc, IntPtr opaque)
		{
			throw new PlatformNotSupportedException();
		}

		internal static bool BrotliEncoderSetParameter(SafeBrotliEncoderHandle state, BrotliEncoderParameter parameter, uint value)
		{
			throw new PlatformNotSupportedException();
		}

		internal unsafe static bool BrotliEncoderCompressStream(SafeBrotliEncoderHandle state, BrotliEncoderOperation op, ref IntPtr availableIn, byte** nextIn, ref IntPtr availableOut, byte** nextOut, out IntPtr totalOut)
		{
			throw new PlatformNotSupportedException();
		}

		internal static bool BrotliEncoderHasMoreOutput(SafeBrotliEncoderHandle state)
		{
			throw new PlatformNotSupportedException();
		}

		internal static void BrotliEncoderDestroyInstance(IntPtr state)
		{
			throw new PlatformNotSupportedException();
		}

		internal unsafe static bool BrotliEncoderCompress(int quality, int window, int v, IntPtr availableInput, byte* inBytes, ref IntPtr availableOutput, byte* outBytes)
		{
			throw new PlatformNotSupportedException();
		}

		internal static SafeBrotliDecoderHandle BrotliDecoderCreateInstance(IntPtr allocFunc, IntPtr freeFunc, IntPtr opaque)
		{
			throw new PlatformNotSupportedException();
		}

		internal unsafe static int BrotliDecoderDecompressStream(SafeBrotliDecoderHandle state, ref IntPtr availableIn, byte** nextIn, ref IntPtr availableOut, byte** nextOut, out IntPtr totalOut)
		{
			throw new PlatformNotSupportedException();
		}

		internal unsafe static bool BrotliDecoderDecompress(IntPtr availableInput, byte* inBytes, ref IntPtr availableOutput, byte* outBytes)
		{
			throw new PlatformNotSupportedException();
		}

		internal static void BrotliDecoderDestroyInstance(IntPtr state)
		{
			throw new PlatformNotSupportedException();
		}

		internal static bool BrotliDecoderIsFinished(SafeBrotliDecoderHandle state)
		{
			throw new PlatformNotSupportedException();
		}
	}
}
namespace System.Runtime.CompilerServices
{
	internal class FriendAccessAllowedAttribute : Attribute
	{
	}
}
namespace System.IO.Compression
{
	public sealed class BrotliStream : Stream
	{
		[StructLayout(LayoutKind.Auto)]
		[CompilerGenerated]
		private struct <FinishReadAsyncMemory>d__41 : IAsyncStateMachine
		{
			public int <>1__state;

			public AsyncValueTaskMethodBuilder<int> <>t__builder;

			public BrotliStream <>4__this;

			public CancellationToken cancellationToken;

			public Memory<byte> buffer;

			private int <totalWritten>5__2;

			private ConfiguredValueTaskAwaiter<int> <>u__1;

			private void MoveNext()
			{
				//IL_013c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0141: Unknown result type (might be due to invalid IL or missing references)
				//IL_0149: Unknown result type (might be due to invalid IL or missing references)
				//IL_0025: Unknown result type (might be due to invalid IL or missing references)
				//IL_002c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0223: 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_0034: Invalid comparison between Unknown and I4
				//IL_019d: Unknown result type (might be due to invalid IL or missing references)
				//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
				//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
				//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
				//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
				//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
				//IL_01be: Invalid comparison between Unknown and I4
				//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
				//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
				//IL_0103: Unknown result type (might be due to invalid IL or missing references)
				//IL_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)
				//IL_0121: 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_005c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0061: Unknown result type (might be due to invalid IL or missing references)
				//IL_006b: Unknown result type (might be due to invalid IL or missing references)
				//IL_020b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0210: Unknown result type (might be due to invalid IL or missing references)
				int num = <>1__state;
				BrotliStream brotliStream = <>4__this;
				int result;
				try
				{
					if (num != 0)
					{
						brotliStream.AsyncOperationStarting();
					}
					try
					{
						OperationStatus val;
						if (num != 0)
						{
							<totalWritten>5__2 = 0;
							_ = Memory<byte>.Empty;
							val = (OperationStatus)1;
							goto IL_0215;
						}
						ConfiguredValueTaskAwaiter<int> awaiter = <>u__1;
						<>u__1 = default(ConfiguredValueTaskAwaiter<int>);
						num = (<>1__state = -1);
						goto IL_0158;
						IL_0215:
						int num2;
						if (buffer.Length > 0 && (int)val != 0)
						{
							if ((int)val == 2)
							{
								if (brotliStream._bufferCount > 0 && brotliStream._bufferOffset != 0)
								{
									MemoryExtensions.AsSpan<byte>(brotliStream._buffer, brotliStream._bufferOffset, brotliStream._bufferCount).CopyTo(Span<byte>.op_Implicit(brotliStream._buffer));
								}
								brotliStream._bufferOffset = 0;
								num2 = 0;
								goto IL_00ab;
							}
							goto IL_017a;
						}
						goto IL_0229;
						IL_00ab:
						bool flag = brotliStream._bufferCount < brotliStream._buffer.Length;
						if (flag)
						{
							awaiter = brotliStream._stream.ReadAsync(new Memory<byte>(brotliStream._buffer, brotliStream._bufferCount, brotliStream._buffer.Length - brotliStream._bufferCount), default(CancellationToken)).ConfigureAwait(false).GetAwaiter();
							if (!awaiter.IsCompleted)
							{
								num = (<>1__state = 0);
								<>u__1 = awaiter;
								<>t__builder.AwaitUnsafeOnCompleted<ConfiguredValueTaskAwaiter<int>, <FinishReadAsyncMemory>d__41>(ref awaiter, ref this);
								return;
							}
							goto IL_0158;
						}
						goto IL_0167;
						IL_0158:
						flag = (num2 = awaiter.GetResult()) > 0;
						goto IL_0167;
						IL_0167:
						if (flag)
						{
							brotliStream._bufferCount += num2;
							if (brotliStream._bufferCount > brotliStream._buffer.Length)
							{
								throw new InvalidDataException("BrotliStream.BaseStream returned more bytes than requested in Read.");
							}
							goto IL_00ab;
						}
						if (brotliStream._bufferCount > 0)
						{
							goto IL_017a;
						}
						goto IL_0229;
						IL_0229:
						result = <totalWritten>5__2;
						goto end_IL_0018;
						IL_017a:
						cancellationToken.ThrowIfCancellationRequested();
						val = brotliStream._decoder.Decompress(Span<byte>.op_Implicit(MemoryExtensions.AsSpan<byte>(brotliStream._buffer, brotliStream._bufferOffset, brotliStream._bufferCount)), buffer.Span, out var bytesConsumed, out var bytesWritten);
						if ((int)val == 3)
						{
							throw new InvalidOperationException("Decoder ran into invalid data.");
						}
						if (bytesConsumed > 0)
						{
							brotliStream._bufferOffset += bytesConsumed;
							brotliStream._bufferCount -= bytesConsumed;
						}
						if (bytesWritten > 0)
						{
							<totalWritten>5__2 += bytesWritten;
							buffer = buffer.Slice(bytesWritten);
						}
						goto IL_0215;
						end_IL_0018:;
					}
					finally
					{
						if (num < 0)
						{
							brotliStream.AsyncOperationCompleting();
						}
					}
				}
				catch (Exception exception)
				{
					<>1__state = -2;
					<>t__builder.SetException(exception);
					return;
				}
				<>1__state = -2;
				<>t__builder.SetResult(result);
			}

			void IAsyncStateMachine.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				this.MoveNext();
			}

			[DebuggerHidden]
			private void SetStateMachine(IAsyncStateMachine stateMachine)
			{
				<>t__builder.SetStateMachine(stateMachine);
			}

			void IAsyncStateMachine.SetStateMachine(IAsyncStateMachine stateMachine)
			{
				//ILSpy generated this explicit interface implementation from .override directive in SetStateMachine
				this.SetStateMachine(stateMachine);
			}
		}

		private const int DefaultInternalBufferSize = 65520;

		private Stream _stream;

		private readonly byte[] _buffer;

		private readonly bool _leaveOpen;

		private readonly CompressionMode _mode;

		private int _activeAsyncOperation;

		private BrotliDecoder _decoder;

		private int _bufferOffset;

		private int _bufferCount;

		private BrotliEncoder _encoder;

		public Stream BaseStream => _stream;

		public override bool CanRead
		{
			get
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				if ((int)_mode == 0 && _stream != null)
				{
					return _stream.CanRead;
				}
				return false;
			}
		}

		public override bool CanWrite
		{
			get
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_0007: Invalid comparison between Unknown and I4
				if ((int)_mode == 1 && _stream != null)
				{
					return _stream.CanWrite;
				}
				return false;
			}
		}

		public override bool CanSeek => false;

		public override long Length
		{
			get
			{
				throw new NotSupportedException();
			}
		}

		public override long Position
		{
			get
			{
				throw new NotSupportedException();
			}
			set
			{
				throw new NotSupportedException();
			}
		}

		private bool AsyncOperationIsActive => _activeAsyncOperation != 0;

		public BrotliStream(Stream stream, CompressionMode mode)
			: this(stream, mode, leaveOpen: false)
		{
		}//IL_0002: Unknown result type (might be due to invalid IL or missing references)


		public BrotliStream(Stream stream, CompressionMode mode, bool leaveOpen)
		{
			//IL_0014: 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_0019: Invalid comparison between Unknown and I4
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			if (stream == null)
			{
				throw new ArgumentNullException("stream");
			}
			if ((int)mode != 0)
			{
				if ((int)mode != 1)
				{
					throw new ArgumentException("Enum value was out of legal range.", "mode");
				}
				if (!stream.CanWrite)
				{
					throw new ArgumentException("Stream does not support writing.", "stream");
				}
			}
			else if (!stream.CanRead)
			{
				throw new ArgumentException("Stream does not support reading.", "stream");
			}
			_mode = mode;
			_stream = stream;
			_leaveOpen = leaveOpen;
			_buffer = new byte[65520];
		}

		private void EnsureNotDisposed()
		{
			if (_stream == null)
			{
				throw new ObjectDisposedException("stream", "Can not access a closed Stream.");
			}
		}

		protected override void Dispose(bool disposing)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Invalid comparison between Unknown and I4
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (disposing && _stream != null)
				{
					if ((int)_mode == 1)
					{
						WriteCore(ReadOnlySpan<byte>.Empty, isFinalBlock: true);
					}
					if (!_leaveOpen)
					{
						_stream.Dispose();
					}
				}
			}
			finally
			{
				_stream = null;
				_encoder.Dispose();
				_decoder.Dispose();
				base.Dispose(disposing);
			}
		}

		private static void ValidateParameters(byte[] array, int offset, int count)
		{
			if (array == null)
			{
				throw new ArgumentNullException("array");
			}
			if (offset < 0)
			{
				throw new ArgumentOutOfRangeException("offset", "Positive number required.");
			}
			if (count < 0)
			{
				throw new ArgumentOutOfRangeException("count", "Positive number required.");
			}
			if (array.Length - offset < count)
			{
				throw new ArgumentException("Offset plus count is larger than the length of target array.");
			}
		}

		public override long Seek(long offset, SeekOrigin origin)
		{
			throw new NotSupportedException();
		}

		public override void SetLength(long value)
		{
			throw new NotSupportedException();
		}

		private void EnsureNoActiveAsyncOperation()
		{
			if (AsyncOperationIsActive)
			{
				ThrowInvalidBeginCall();
			}
		}

		private void AsyncOperationStarting()
		{
			if (Interlocked.CompareExchange(ref _activeAsyncOperation, 1, 0) != 0)
			{
				ThrowInvalidBeginCall();
			}
		}

		private void AsyncOperationCompleting()
		{
			Interlocked.CompareExchange(ref _activeAsyncOperation, 0, 1);
		}

		private static void ThrowInvalidBeginCall()
		{
			throw new InvalidOperationException("Only one asynchronous reader or writer is allowed time at one time.");
		}

		public override int Read(byte[] buffer, int offset, int count)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			ValidateParameters(buffer, offset, count);
			return ((Stream)this).Read(new Span<byte>(buffer, offset, count));
		}

		public int Read(Span<byte> buffer)
		{
			//IL_0001: 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_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Invalid comparison between Unknown and I4
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: 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_010f: Invalid comparison between Unknown and I4
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: 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)
			if ((int)_mode != 0)
			{
				throw new InvalidOperationException("Can not perform Read operations on a BrotliStream constructed with CompressionMode.Compress.");
			}
			EnsureNotDisposed();
			int num = 0;
			OperationStatus val = (OperationStatus)1;
			while (buffer.Length > 0 && (int)val != 0)
			{
				if ((int)val == 2)
				{
					if (_bufferCount > 0 && _bufferOffset != 0)
					{
						MemoryExtensions.AsSpan<byte>(_buffer, _bufferOffset, _bufferCount).CopyTo(Span<byte>.op_Implicit(_buffer));
					}
					_bufferOffset = 0;
					int num2 = 0;
					while (_bufferCount < _buffer.Length && (num2 = _stream.Read(_buffer, _bufferCount, _buffer.Length - _bufferCount)) > 0)
					{
						_bufferCount += num2;
						if (_bufferCount > _buffer.Length)
						{
							throw new InvalidDataException("BrotliStream.BaseStream returned more bytes than requested in Read.");
						}
					}
					if (_bufferCount <= 0)
					{
						break;
					}
				}
				val = _decoder.Decompress(Span<byte>.op_Implicit(MemoryExtensions.AsSpan<byte>(_buffer, _bufferOffset, _bufferCount)), buffer, out var bytesConsumed, out var bytesWritten);
				if ((int)val == 3)
				{
					throw new InvalidOperationException("Decoder ran into invalid data.");
				}
				if (bytesConsumed > 0)
				{
					_bufferOffset += bytesConsumed;
					_bufferCount -= bytesConsumed;
				}
				if (bytesWritten > 0)
				{
					num += bytesWritten;
					buffer = buffer.Slice(bytesWritten);
				}
			}
			return num;
		}

		public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback asyncCallback, object asyncState)
		{
			return System.Threading.Tasks.TaskToApm.Begin(ReadAsync(buffer, offset, count, CancellationToken.None), asyncCallback, asyncState);
		}

		public override int EndRead(IAsyncResult asyncResult)
		{
			return System.Threading.Tasks.TaskToApm.End<int>(asyncResult);
		}

		public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
		{
			//IL_000c: 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)
			ValidateParameters(buffer, offset, count);
			return ((Stream)this).ReadAsync(new Memory<byte>(buffer, offset, count), cancellationToken).AsTask();
		}

		public ValueTask<int> ReadAsync(Memory<byte> buffer, CancellationToken cancellationToken = default(CancellationToken))
		{
			//IL_0001: 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_002e: Unknown result type (might be due to invalid IL or missing references)
			if ((int)_mode != 0)
			{
				throw new InvalidOperationException("Can not perform Read operations on a BrotliStream constructed with CompressionMode.Compress.");
			}
			EnsureNoActiveAsyncOperation();
			EnsureNotDisposed();
			if (cancellationToken.IsCancellationRequested)
			{
				return new ValueTask<int>(Task.FromCanceled<int>(cancellationToken));
			}
			return FinishReadAsyncMemory(buffer, cancellationToken);
		}

		[AsyncStateMachine(typeof(<FinishReadAsyncMemory>d__41))]
		private ValueTask<int> FinishReadAsyncMemory(Memory<byte> buffer, CancellationToken cancellationToken)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			<FinishReadAsyncMemory>d__41 <FinishReadAsyncMemory>d__ = default(<FinishReadAsyncMemory>d__41);
			<FinishReadAsyncMemory>d__.<>4__this = this;
			<FinishReadAsyncMemory>d__.buffer = buffer;
			<FinishReadAsyncMemory>d__.cancellationToken = cancellationToken;
			<FinishReadAsyncMemory>d__.<>t__builder = AsyncValueTaskMethodBuilder<int>.Create();
			<FinishReadAsyncMemory>d__.<>1__state = -1;
			<FinishReadAsyncMemory>d__.<>t__builder.Start<<FinishReadAsyncMemory>d__41>(ref <FinishReadAsyncMemory>d__);
			return <FinishReadAsyncMemory>d__.<>t__builder.Task;
		}

		public BrotliStream(Stream stream, CompressionLevel compressionLevel)
			: this(stream, compressionLevel, leaveOpen: false)
		{
		}//IL_0002: Unknown result type (might be due to invalid IL or missing references)


		public BrotliStream(Stream stream, CompressionLevel compressionLevel, bool leaveOpen)
			: this(stream, (CompressionMode)1, leaveOpen)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			_encoder.SetQuality(BrotliUtils.GetQualityFromCompressionLevel(compressionLevel));
		}

		public override void Write(byte[] buffer, int offset, int count)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			ValidateParameters(buffer, offset, count);
			WriteCore(new ReadOnlySpan<byte>(buffer, offset, count));
		}

		public void Write(ReadOnlySpan<byte> buffer)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			WriteCore(buffer);
		}

		internal void WriteCore(ReadOnlySpan<byte> buffer, bool isFinalBlock = false)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Invalid comparison between Unknown and I4
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Invalid comparison between Unknown and I4
			//IL_0035: 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_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_0044: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			if ((int)_mode != 1)
			{
				throw new InvalidOperationException("Can not perform Write operations on a BrotliStream constructed with CompressionMode.Decompress.");
			}
			EnsureNotDisposed();
			OperationStatus val = (OperationStatus)1;
			Span<byte> destination = default(Span<byte>);
			destination..ctor(_buffer);
			while ((int)val == 1)
			{
				int bytesConsumed = 0;
				int bytesWritten = 0;
				val = _encoder.Compress(buffer, destination, out bytesConsumed, out bytesWritten, isFinalBlock);
				if ((int)val == 3)
				{
					throw new InvalidOperationException("Encoder ran into invalid data.");
				}
				if (bytesWritten > 0)
				{
					_stream.Write(Span<byte>.op_Implicit(destination.Slice(0, bytesWritten)));
				}
				if (bytesConsumed > 0)
				{
					buffer = buffer.Slice(bytesConsumed);
				}
			}
		}

		public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback asyncCallback, object asyncState)
		{
			return System.Threading.Tasks.TaskToApm.Begin(WriteAsync(buffer, offset, count, CancellationToken.None), asyncCallback, asyncState);
		}

		public override void EndWrite(IAsyncResult asyncResult)
		{
			System.Threading.Tasks.TaskToApm.End(asyncResult);
		}

		public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
		{
			//IL_000c: 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)
			ValidateParameters(buffer, offset, count);
			ValueTask val = ((Stream)this).WriteAsync(new ReadOnlyMemory<byte>(buffer, offset, count), cancellationToken);
			return ((ValueTask)(ref val)).AsTask();
		}

		public ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, CancellationToken cancellationToken = default(CancellationToken))
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Invalid comparison between Unknown and I4
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			if ((int)_mode != 1)
			{
				throw new InvalidOperationException("Can not perform Write operations on a BrotliStream constructed with CompressionMode.Decompress.");
			}
			EnsureNoActiveAsyncOperation();
			EnsureNotDisposed();
			return new ValueTask(cancellationToken.IsCancellationRequested ? Task.FromCanceled<int>(cancellationToken) : WriteAsyncMemoryCore(buffer, cancellationToken));
		}

		private async Task WriteAsyncMemoryCore(ReadOnlyMemory<byte> buffer, CancellationToken cancellationToken)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			AsyncOperationStarting();
			try
			{
				OperationStatus lastResult = (OperationStatus)1;
				Memory<byte> destination = default(Memory<byte>);
				while ((int)lastResult == 1)
				{
					destination..ctor(_buffer);
					int bytesConsumed = 0;
					int bytesWritten = 0;
					lastResult = _encoder.Compress(buffer, destination, out bytesConsumed, out bytesWritten, isFinalBlock: false);
					if ((int)lastResult == 3)
					{
						throw new InvalidOperationException("Encoder ran into invalid data.");
					}
					if (bytesConsumed > 0)
					{
						buffer = buffer.Slice(bytesConsumed);
					}
					if (bytesWritten > 0)
					{
						ValueTask val = _stream.WriteAsync(new ReadOnlyMemory<byte>(_buffer, 0, bytesWritten), cancellationToken);
						await ((ValueTask)(ref val)).ConfigureAwait(false);
					}
				}
			}
			finally
			{
				AsyncOperationCompleting();
			}
		}

		public override void Flush()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Invalid comparison between Unknown and I4
			//IL_0030: 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_007f: Invalid comparison between Unknown and I4
			//IL_0048: 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_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Invalid comparison between Unknown and I4
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			EnsureNotDisposed();
			if ((int)_mode != 1 || _encoder._state == null || _encoder._state.IsClosed)
			{
				return;
			}
			OperationStatus val = (OperationStatus)1;
			Span<byte> destination = default(Span<byte>);
			destination..ctor(_buffer);
			while ((int)val == 1)
			{
				int bytesWritten = 0;
				val = _encoder.Flush(destination, out bytesWritten);
				if ((int)val == 3)
				{
					throw new InvalidDataException("Encoder ran into invalid data.");
				}
				if (bytesWritten > 0)
				{
					_stream.Write(Span<byte>.op_Implicit(destination.Slice(0, bytesWritten)));
				}
			}
		}

		public override Task FlushAsync(CancellationToken cancellationToken)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Invalid comparison between Unknown and I4
			EnsureNoActiveAsyncOperation();
			EnsureNotDisposed();
			if (cancellationToken.IsCancellationRequested)
			{
				return Task.FromCanceled(cancellationToken);
			}
			if ((int)_mode == 1)
			{
				return FlushAsyncCore(cancellationToken);
			}
			return Task.CompletedTask;
		}

		private async Task FlushAsyncCore(CancellationToken cancellationToken)
		{
			AsyncOperationStarting();
			try
			{
				if (_encoder._state == null || _encoder._state.IsClosed)
				{
					return;
				}
				OperationStatus lastResult = (OperationStatus)1;
				Memory<byte> destination = default(Memory<byte>);
				while ((int)lastResult == 1)
				{
					destination..ctor(_buffer);
					int bytesWritten = 0;
					lastResult = _encoder.Flush(destination, out bytesWritten);
					if ((int)lastResult == 3)
					{
						throw new InvalidDataException("Encoder ran into invalid data.");
					}
					if (bytesWritten > 0)
					{
						ValueTask val = _stream.WriteAsync(Memory<byte>.op_Implicit(destination.Slice(0, bytesWritten)), cancellationToken);
						await ((ValueTask)(ref val)).ConfigureAwait(false);
					}
				}
			}
			finally
			{
				AsyncOperationCompleting();
			}
		}
	}
	internal static class BrotliUtils
	{
		public const int WindowBits_Min = 10;

		public const int WindowBits_Default = 22;

		public const int WindowBits_Max = 24;

		public const int Quality_Min = 0;

		public const int Quality_Default = 11;

		public const int Quality_Max = 11;

		public const int MaxInputSize = 2147483132;

		internal static int GetQualityFromCompressionLevel(CompressionLevel level)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected I4, but got Unknown
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected I4, but got Unknown
			return (int)level switch
			{
				0 => 11, 
				2 => 0, 
				1 => 1, 
				_ => (int)level, 
			};
		}
	}
	public struct BrotliDecoder : IDisposable
	{
		private SafeBrotliDecoderHandle _state;

		private bool _disposed;

		internal void InitializeDecoder()
		{
			_state = global::Interop.Brotli.BrotliDecoderCreateInstance(IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
			if (_state.IsInvalid)
			{
				throw new IOException("Failed to create BrotliDecoder instance");
			}
		}

		internal void EnsureInitialized()
		{
			EnsureNotDisposed();
			if (_state == null)
			{
				InitializeDecoder();
			}
		}

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

		private void EnsureNotDisposed()
		{
			if (_disposed)
			{
				throw new ObjectDisposedException("BrotliDecoder", "Can not access a closed Decoder.");
			}
		}

		public unsafe OperationStatus Decompress(ReadOnlySpan<byte> source, Span<byte> destination, out int bytesConsumed, out int bytesWritten)
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			EnsureInitialized();
			bytesConsumed = 0;
			bytesWritten = 0;
			if (!global::Interop.Brotli.BrotliDecoderIsFinished(_state))
			{
				IntPtr availableOut = (IntPtr)destination.Length;
				IntPtr availableIn = (IntPtr)source.Length;
				while ((int)availableOut > 0)
				{
					fixed (byte* ptr = &MemoryMarshal.GetReference<byte>(source))
					{
						fixed (byte* ptr3 = &MemoryMarshal.GetReference<byte>(destination))
						{
							byte* ptr2 = ptr;
							byte* ptr4 = ptr3;
							IntPtr totalOut;
							int num = global::Interop.Brotli.BrotliDecoderDecompressStream(_state, ref availableIn, &ptr2, ref availableOut, &ptr4, out totalOut);
							if (num == 0)
							{
								return (OperationStatus)3;
							}
							bytesConsumed += source.Length - (int)availableIn;
							bytesWritten += destination.Length - (int)availableOut;
							switch (num)
							{
							case 1:
								return (OperationStatus)0;
							case 3:
								return (OperationStatus)1;
							}
							source = source.Slice(source.Length - (int)availableIn);
							destination = destination.Slice(destination.Length - (int)availableOut);
							if (num == 2 && source.Length == 0)
							{
								return (OperationStatus)2;
							}
						}
					}
				}
				return (OperationStatus)1;
			}
			return (OperationStatus)0;
		}

		public unsafe static bool TryDecompress(ReadOnlySpan<byte> source, Span<byte> destination, out int bytesWritten)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			fixed (byte* inBytes = &MemoryMarshal.GetReference<byte>(source))
			{
				fixed (byte* outBytes = &MemoryMarshal.GetReference<byte>(destination))
				{
					IntPtr availableOutput = (IntPtr)destination.Length;
					bool result = global::Interop.Brotli.BrotliDecoderDecompress((IntPtr)source.Length, inBytes, ref availableOutput, outBytes);
					bytesWritten = (int)availableOutput;
					return result;
				}
			}
		}
	}
	public struct BrotliEncoder : IDisposable
	{
		internal SafeBrotliEncoderHandle _state;

		private bool _disposed;

		public BrotliEncoder(int quality, int window)
		{
			_disposed = false;
			_state = global::Interop.Brotli.BrotliEncoderCreateInstance(IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
			if (_state.IsInvalid)
			{
				throw new IOException("Failed to create BrotliEncoder instance");
			}
			SetQuality(quality);
			SetWindow(window);
		}

		internal void InitializeEncoder()
		{
			EnsureNotDisposed();
			_state = global::Interop.Brotli.BrotliEncoderCreateInstance(IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
			if (_state.IsInvalid)
			{
				throw new IOException("Failed to create BrotliEncoder instance");
			}
		}

		internal void EnsureInitialized()
		{
			EnsureNotDisposed();
			if (_state == null)
			{
				InitializeEncoder();
			}
		}

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

		private void EnsureNotDisposed()
		{
			if (_disposed)
			{
				throw new ObjectDisposedException("BrotliEncoder", "Can not access a closed Encoder.");
			}
		}

		internal void SetQuality(int quality)
		{
			EnsureNotDisposed();
			if (_state == null || _state.IsInvalid || _state.IsClosed)
			{
				InitializeEncoder();
			}
			if (quality < 0 || quality > 11)
			{
				throw new ArgumentOutOfRangeException("quality", SR.Format("Provided BrotliEncoder Quality of {0} is not between the minimum value of {1} and the maximum value of {2}", quality, 0, 11));
			}
			if (!global::Interop.Brotli.BrotliEncoderSetParameter(_state, BrotliEncoderParameter.Quality, (uint)quality))
			{
				throw new InvalidOperationException(SR.Format("The BrotliEncoder {0} can not be changed at current encoder state.", "Quality"));
			}
		}

		internal void SetWindow(int window)
		{
			EnsureNotDisposed();
			if (_state == null || _state.IsInvalid || _state.IsClosed)
			{
				InitializeEncoder();
			}
			if (window < 10 || window > 24)
			{
				throw new ArgumentOutOfRangeException("window", SR.Format("Provided BrotliEncoder Window of {0} is not between the minimum value of {1} and the maximum value of {2}", window, 10, 24));
			}
			if (!global::Interop.Brotli.BrotliEncoderSetParameter(_state, BrotliEncoderParameter.LGWin, (uint)window))
			{
				throw new InvalidOperationException(SR.Format("The BrotliEncoder {0} can not be changed at current encoder state.", "Window"));
			}
		}

		public static int GetMaxCompressedLength(int length)
		{
			if (length < 0 || length > 2147483132)
			{
				throw new ArgumentOutOfRangeException("length");
			}
			if (length == 0)
			{
				return 1;
			}
			int num = length >> 24;
			int num2 = (((length & 0xFFFFFF) > 1048576) ? 4 : 3);
			int num3 = 2 + 4 * num + num2 + 1;
			return length + num3;
		}

		internal OperationStatus Flush(Memory<byte> destination, out int bytesWritten)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			return Flush(destination.Span, out bytesWritten);
		}

		public OperationStatus Flush(Span<byte> destination, out int bytesWritten)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			int bytesConsumed;
			return Compress(ReadOnlySpan<byte>.Empty, destination, out bytesConsumed, out bytesWritten, BrotliEncoderOperation.Flush);
		}

		internal OperationStatus Compress(ReadOnlyMemory<byte> source, Memory<byte> destination, out int bytesConsumed, out int bytesWritten, bool isFinalBlock)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			return Compress(source.Span, destination.Span, out bytesConsumed, out bytesWritten, isFinalBlock);
		}

		public OperationStatus Compress(ReadOnlySpan<byte> source, Span<byte> destination, out int bytesConsumed, out int bytesWritten, bool isFinalBlock)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			return Compress(source, destination, out bytesConsumed, out bytesWritten, isFinalBlock ? BrotliEncoderOperation.Finish : BrotliEncoderOperation.Process);
		}

		internal unsafe OperationStatus Compress(ReadOnlySpan<byte> source, Span<byte> destination, out int bytesConsumed, out int bytesWritten, BrotliEncoderOperation operation)
		{
			//IL_002c: 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_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			EnsureInitialized();
			bytesWritten = 0;
			bytesConsumed = 0;
			IntPtr availableOut = (IntPtr)destination.Length;
			IntPtr availableIn = (IntPtr)source.Length;
			while ((int)availableOut > 0)
			{
				fixed (byte* ptr = &MemoryMarshal.GetReference<byte>(source))
				{
					fixed (byte* ptr3 = &MemoryMarshal.GetReference<byte>(destination))
					{
						byte* ptr2 = ptr;
						byte* ptr4 = ptr3;
						if (!global::Interop.Brotli.BrotliEncoderCompressStream(_state, operation, ref availableIn, &ptr2, ref availableOut, &ptr4, out var _))
						{
							return (OperationStatus)3;
						}
						bytesConsumed += source.Length - (int)availableIn;
						bytesWritten += destination.Length - (int)availableOut;
						if ((int)availableOut == destination.Length && !global::Interop.Brotli.BrotliEncoderHasMoreOutput(_state) && (int)availableIn == 0)
						{
							return (OperationStatus)0;
						}
						source = source.Slice(source.Length - (int)availableIn);
						destination = destination.Slice(destination.Length - (int)availableOut);
					}
				}
			}
			return (OperationStatus)1;
		}

		public static bool TryCompress(ReadOnlySpan<byte> source, Span<byte> destination, out int bytesWritten)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			return TryCompress(source, destination, out bytesWritten, 11, 22);
		}

		public unsafe static bool TryCompress(ReadOnlySpan<byte> source, Span<byte> destination, out int bytesWritten, int quality, int window)
		{
			//IL_0067: 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)
			if (quality < 0 || quality > 11)
			{
				throw new ArgumentOutOfRangeException("quality", SR.Format("Provided BrotliEncoder Quality of {0} is not between the minimum value of {1} and the maximum value of {2}", quality, 0, 11));
			}
			if (window < 10 || window > 24)
			{
				throw new ArgumentOutOfRangeException("window", SR.Format("Provided BrotliEncoder Window of {0} is not between the minimum value of {1} and the maximum value of {2}", window, 10, 24));
			}
			fixed (byte* inBytes = &MemoryMarshal.GetReference<byte>(source))
			{
				fixed (byte* outBytes = &MemoryMarshal.GetReference<byte>(destination))
				{
					IntPtr availableOutput = (IntPtr)destination.Length;
					bool result = global::Interop.Brotli.BrotliEncoderCompress(quality, window, 0, (IntPtr)source.Length, inBytes, ref availableOutput, outBytes);
					bytesWritten = (int)availableOutput;
					return result;
				}
			}
		}
	}
	internal enum BrotliEncoderOperation
	{
		Process,
		Flush,
		Finish,
		EmitMetadata
	}
	internal enum BrotliEncoderParameter
	{
		Mode,
		Quality,
		LGWin,
		LGBlock,
		LCModeling,
		SizeHint
	}
	internal enum BlockType
	{
		Uncompressed,
		Static,
		Dynamic
	}
	internal sealed class CopyEncoder
	{
		private const int PaddingSize = 5;

		private const int MaxUncompressedBlockSize = 65536;

		public void GetBlock(DeflateInput input, OutputBuffer output, bool isFinal)
		{
			int num = 0;
			if (input != null)
			{
				num = Math.Min(input.Count, output.FreeBytes - 5 - output.BitsInBuffer);
				if (num > 65531)
				{
					num = 65531;
				}
			}
			if (isFinal)
			{
				output.WriteBits(3, 1u);
			}
			else
			{
				output.WriteBits(3, 0u);
			}
			output.FlushBits();
			WriteLenNLen((ushort)num, output);
			if (input != null && num > 0)
			{
				output.WriteBytes(input.Buffer, input.StartIndex, num);
				input.ConsumeBytes(num);
			}
		}

		private void WriteLenNLen(ushort len, OutputBuffer output)
		{
			output.WriteUInt16(len);
			ushort value = (ushort)(~len);
			output.WriteUInt16(value);
		}
	}
	internal sealed class DeflateInput
	{
		internal readonly struct InputState
		{
			internal readonly int _count;

			internal readonly int _startIndex;

			internal InputState(int count, int startIndex)
			{
				_count = count;
				_startIndex = startIndex;
			}
		}

		internal byte[] Buffer { get; set; }

		internal int Count { get; set; }

		internal int StartIndex { get; set; }

		internal void ConsumeBytes(int n)
		{
			StartIndex += n;
			Count -= n;
		}

		internal InputState DumpState()
		{
			return new InputState(Count, StartIndex);
		}

		internal void RestoreState(InputState state)
		{
			Count = state._count;
			StartIndex = state._startIndex;
		}
	}
	internal sealed class DeflateManagedStream : Stream
	{
		internal const int DefaultBufferSize = 8192;

		private Stream _stream;

		private CompressionMode _mode;

		private bool _leaveOpen;

		private System.IO.Compression.InflaterManaged _inflater;

		private DeflaterManaged _deflater;

		private byte[] _buffer;

		private int _asyncOperations;

		private IFileFormatWriter _formatWriter;

		private bool _wroteHeader;

		private bool _wroteBytes;

		public override bool CanRead
		{
			get
			{
				//IL_000b: Unknown result type (might be due to invalid IL or missing references)
				if (_stream == null)
				{
					return false;
				}
				if ((int)_mode == 0)
				{
					return _stream.CanRead;
				}
				return false;
			}
		}

		public override bool CanWrite
		{
			get
			{
				//IL_000b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0011: Invalid comparison between Unknown and I4
				if (_stream == null)
				{
					return false;
				}
				if ((int)_mode == 1)
				{
					return _stream.CanWrite;
				}
				return false;
			}
		}

		public override bool CanSeek => false;

		public override long Length
		{
			get
			{
				throw new NotSupportedException("This operation is not supported.");
			}
		}

		public override long Position
		{
			get
			{
				throw new NotSupportedException("This operation is not supported.");
			}
			set
			{
				throw new NotSupportedException("This operation is not supported.");
			}
		}

		internal DeflateManagedStream(Stream stream, ZipArchiveEntry.CompressionMethodValues method)
		{
			if (stream == null)
			{
				throw new ArgumentNullException("stream");
			}
			if (!stream.CanRead)
			{
				throw new ArgumentException("Stream does not support reading.", "stream");
			}
			InitializeInflater(stream, leaveOpen: false, null, method);
		}

		internal void InitializeInflater(Stream stream, bool leaveOpen, IFileFormatReader reader = null, ZipArchiveEntry.CompressionMethodValues method = ZipArchiveEntry.CompressionMethodValues.Deflate)
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			if (!stream.CanRead)
			{
				throw new ArgumentException("Stream does not support reading.", "stream");
			}
			_inflater = new System.IO.Compression.InflaterManaged(reader, method == ZipArchiveEntry.CompressionMethodValues.Deflate64);
			_stream = stream;
			_mode = (CompressionMode)0;
			_leaveOpen = leaveOpen;
			_buffer = new byte[8192];
		}

		internal void SetFileFormatWriter(IFileFormatWriter writer)
		{
			if (writer != null)
			{
				_formatWriter = writer;
			}
		}

		public override void Flush()
		{
			EnsureNotDisposed();
		}

		public override Task FlushAsync(CancellationToken cancellationToken)
		{
			EnsureNotDisposed();
			if (!cancellationToken.IsCancellationRequested)
			{
				return Task.CompletedTask;
			}
			return Task.FromCanceled(cancellationToken);
		}

		public override long Seek(long offset, SeekOrigin origin)
		{
			throw new NotSupportedException("This operation is not supported.");
		}

		public override void SetLength(long value)
		{
			throw new NotSupportedException("This operation is not supported.");
		}

		public override int Read(byte[] array, int offset, int count)
		{
			EnsureDecompressionMode();
			ValidateParameters(array, offset, count);
			EnsureNotDisposed();
			int num = offset;
			int num2 = count;
			while (true)
			{
				int num3 = _inflater.Inflate(array, num, num2);
				num += num3;
				num2 -= num3;
				if (num2 == 0 || _inflater.Finished())
				{
					break;
				}
				int num4 = _stream.Read(_buffer, 0, _buffer.Length);
				if (num4 <= 0)
				{
					break;
				}
				if (num4 > _buffer.Length)
				{
					throw new InvalidDataException("Found invalid data while decoding.");
				}
				_inflater.SetInput(_buffer, 0, num4);
			}
			return count - num2;
		}

		private void ValidateParameters(byte[] array, int offset, int count)
		{
			if (array == null)
			{
				throw new ArgumentNullException("array");
			}
			if (offset < 0)
			{
				throw new ArgumentOutOfRangeException("offset");
			}
			if (count < 0)
			{
				throw new ArgumentOutOfRangeException("count");
			}
			if (array.Length - offset < count)
			{
				throw new ArgumentException("Offset plus count is larger than the length of target array.");
			}
		}

		private void EnsureNotDisposed()
		{
			if (_stream == null)
			{
				ThrowStreamClosedException();
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private static void ThrowStreamClosedException()
		{
			throw new ObjectDisposedException(null, "Can not access a closed Stream.");
		}

		private void EnsureDecompressionMode()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			if ((int)_mode != 0)
			{
				ThrowCannotReadFromDeflateManagedStreamException();
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private static void ThrowCannotReadFromDeflateManagedStreamException()
		{
			throw new InvalidOperationException("Reading from the compression stream is not supported.");
		}

		private void EnsureCompressionMode()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Invalid comparison between Unknown and I4
			if ((int)_mode != 1)
			{
				ThrowCannotWriteToDeflateManagedStreamException();
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private static void ThrowCannotWriteToDeflateManagedStreamException()
		{
			throw new InvalidOperationException("Writing to the compression stream is not supported.");
		}

		public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback asyncCallback, object asyncState)
		{
			return System.Threading.Tasks.TaskToApm.Begin(ReadAsync(buffer, offset, count, CancellationToken.None), asyncCallback, asyncState);
		}

		public override int EndRead(IAsyncResult asyncResult)
		{
			return System.Threading.Tasks.TaskToApm.End<int>(asyncResult);
		}

		public override Task<int> ReadAsync(byte[] array, int offset, int count, CancellationToken cancellationToken)
		{
			EnsureDecompressionMode();
			if (_asyncOperations != 0)
			{
				throw new InvalidOperationException("Only one asynchronous reader or writer is allowed time at one time.");
			}
			ValidateParameters(array, offset, count);
			EnsureNotDisposed();
			if (cancellationToken.IsCancellationRequested)
			{
				return Task.FromCanceled<int>(cancellationToken);
			}
			Interlocked.Increment(ref _asyncOperations);
			Task<int> task = null;
			try
			{
				int num = _inflater.Inflate(array, offset, count);
				if (num != 0)
				{
					return Task.FromResult(num);
				}
				if (_inflater.Finished())
				{
					return Task.FromResult(0);
				}
				task = _stream.ReadAsync(_buffer, 0, _buffer.Length, cancellationToken);
				if (task == null)
				{
					throw new InvalidOperationException("Stream does not support reading.");
				}
				return ReadAsyncCore(task, array, offset, count, cancellationToken);
			}
			finally
			{
				if (task == null)
				{
					Interlocked.Decrement(ref _asyncOperations);
				}
			}
		}

		private async Task<int> ReadAsyncCore(Task<int> readTask, byte[] array, int offset, int count, CancellationToken cancellationToken)
		{
			try
			{
				int num;
				while (true)
				{
					num = await readTask.ConfigureAwait(continueOnCapturedContext: false);
					EnsureNotDisposed();
					if (num <= 0)
					{
						return 0;
					}
					if (num > _buffer.Length)
					{
						throw new InvalidDataException("Found invalid data while decoding.");
					}
					cancellationToken.ThrowIfCancellationRequested();
					_inflater.SetInput(_buffer, 0, num);
					num = _inflater.Inflate(array, offset, count);
					if (num != 0 || _inflater.Finished())
					{
						break;
					}
					readTask = _stream.ReadAsync(_buffer, 0, _buffer.Length, cancellationToken);
					if (readTask == null)
					{
						throw new InvalidOperationException("Stream does not support reading.");
					}
				}
				return num;
			}
			finally
			{
				Interlocked.Decrement(ref _asyncOperations);
			}
		}

		public override void Write(byte[] array, int offset, int count)
		{
			EnsureCompressionMode();
			ValidateParameters(array, offset, count);
			EnsureNotDisposed();
			DoMaintenance(array, offset, count);
			WriteDeflaterOutput();
			_deflater.SetInput(array, offset, count);
			WriteDeflaterOutput();
		}

		private void WriteDeflaterOutput()
		{
			while (!_deflater.NeedsInput())
			{
				int deflateOutput = _deflater.GetDeflateOutput(_buffer);
				if (deflateOutput > 0)
				{
					_stream.Write(_buffer, 0, deflateOutput);
				}
			}
		}

		private void DoMaintenance(byte[] array, int offset, int count)
		{
			if (count <= 0)
			{
				return;
			}
			_wroteBytes = true;
			if (_formatWriter != null)
			{
				if (!_wroteHeader)
				{
					byte[] header = _formatWriter.GetHeader();
					_stream.Write(header, 0, header.Length);
					_wroteHeader = true;
				}
				_formatWriter.UpdateWithBytesRead(array, offset, count);
			}
		}

		private void PurgeBuffers(bool disposing)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Invalid comparison between Unknown and I4
			if (!disposing || _stream == null)
			{
				return;
			}
			Flush();
			if ((int)_mode != 1)
			{
				return;
			}
			if (_wroteBytes)
			{
				WriteDeflaterOutput();
				bool flag;
				do
				{
					flag = _deflater.Finish(_buffer, out var bytesRead);
					if (bytesRead > 0)
					{
						_stream.Write(_buffer, 0, bytesRead);
					}
				}
				while (!flag);
			}
			else
			{
				int bytesRead2;
				while (!_deflater.Finish(_buffer, out bytesRead2))
				{
				}
			}
			if (_formatWriter != null && _wroteHeader)
			{
				byte[] footer = _formatWriter.GetFooter();
				_stream.Write(footer, 0, footer.Length);
			}
		}

		protected override void Dispose(bool disposing)
		{
			try
			{
				PurgeBuffers(disposing);
			}
			finally
			{
				try
				{
					if (disposing && !_leaveOpen && _stream != null)
					{
						_stream.Dispose();
					}
				}
				finally
				{
					_stream = null;
					try
					{
						_deflater?.Dispose();
						_inflater?.Dispose();
					}
					finally
					{
						_deflater = null;
						_inflater = null;
						base.Dispose(disposing);
					}
				}
			}
		}

		public override Task WriteAsync(byte[] array, int offset, int count, CancellationToken cancellationToken)
		{
			EnsureCompressionMode();
			if (_asyncOperations != 0)
			{
				throw new InvalidOperationException("Only one asynchronous reader or writer is allowed time at one time.");
			}
			ValidateParameters(array, offset, count);
			EnsureNotDisposed();
			if (cancellationToken.IsCancellationRequested)
			{
				return Task.FromCanceled<int>(cancellationToken);
			}
			return WriteAsyncCore(array, offset, count, cancellationToken);
		}

		private async Task WriteAsyncCore(byte[] array, int offset, int count, CancellationToken cancellationToken)
		{
			Interlocked.Increment(ref _asyncOperations);
			try
			{
				await base.WriteAsync(array, offset, count, cancellationToken).ConfigureAwait(continueOnCapturedContext: false);
			}
			finally
			{
				Interlocked.Decrement(ref _asyncOperations);
			}
		}

		public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback asyncCallback, object asyncState)
		{
			return System.Threading.Tasks.TaskToApm.Begin(WriteAsync(buffer, offset, count, CancellationToken.None), asyncCallback, asyncState);
		}

		public override void EndWrite(IAsyncResult asyncResult)
		{
			System.Threading.Tasks.TaskToApm.End(asyncResult);
		}
	}
	internal sealed class DeflaterManaged : IDisposable
	{
		private enum DeflaterState
		{
			NotStarted,
			SlowDownForIncompressible1,
			SlowDownForIncompressible2,
			StartingSmallData,
			CompressThenCheck,
			CheckingForIncompressible,
			HandlingSmallData
		}

		private const int MinBlockSize = 256;

		private const int MaxHeaderFooterGoo = 120;

		private const int CleanCopySize = 8072;

		private const double BadCompressionThreshold = 1.0;

		private readonly FastEncoder _deflateEncoder;

		private readonly CopyEncoder _copyEncoder;

		private readonly DeflateInput _input;

		private readonly OutputBuffer _output;

		private DeflaterState _processingState;

		private DeflateInput _inputFromHistory;

		internal DeflaterManaged()
		{
			_deflateEncoder = new FastEncoder();
			_copyEncoder = new CopyEncoder();
			_input = new DeflateInput();
			_output = new OutputBuffer();
			_processingState = DeflaterState.NotStarted;
		}

		internal bool NeedsInput()
		{
			if (_input.Count == 0)
			{
				return _deflateEncoder.BytesInHistory == 0;
			}
			return false;
		}

		internal void SetInput(byte[] inputBuffer, int startIndex, int count)
		{
			_input.Buffer = inputBuffer;
			_input.Count = count;
			_input.StartIndex = startIndex;
			if (count > 0 && count < 256)
			{
				switch (_processingState)
				{
				case DeflaterState.NotStarted:
				case DeflaterState.CheckingForIncompressible:
					_processingState = DeflaterState.StartingSmallData;
					break;
				case DeflaterState.CompressThenCheck:
					_processingState = DeflaterState.HandlingSmallData;
					break;
				}
			}
		}

		internal int GetDeflateOutput(byte[] outputBuffer)
		{
			_output.UpdateBuffer(outputBuffer);
			switch (_processingState)
			{
			case DeflaterState.NotStarted:
			{
				DeflateInput.InputState state3 = _input.DumpState();
				OutputBuffer.BufferState state4 = _output.DumpState();
				_deflateEncoder.GetBlockHeader(_output);
				_deflateEncoder.GetCompressedData(_input, _output);
				if (!UseCompressed(_deflateEncoder.LastCompressionRatio))
				{
					_input.RestoreState(state3);
					_output.RestoreState(state4);
					_copyEncoder.GetBlock(_input, _output, isFinal: false);
					FlushInputWindows();
					_processingState = DeflaterState.CheckingForIncompressible;
				}
				else
				{
					_processingState = DeflaterState.CompressThenCheck;
				}
				break;
			}
			case DeflaterState.CompressThenCheck:
				_deflateEncoder.GetCompressedData(_input, _output);
				if (!UseCompressed(_deflateEncoder.LastCompressionRatio))
				{
					_processingState = DeflaterState.SlowDownForIncompressible1;
					_inputFromHistory = _deflateEncoder.UnprocessedInput;
				}
				break;
			case DeflaterState.SlowDownForIncompressible1:
				_deflateEncoder.GetBlockFooter(_output);
				_processingState = DeflaterState.SlowDownForIncompressible2;
				goto case DeflaterState.SlowDownForIncompressible2;
			case DeflaterState.SlowDownForIncompressible2:
				if (_inputFromHistory.Count > 0)
				{
					_copyEncoder.GetBlock(_inputFromHistory, _output, isFinal: false);
				}
				if (_inputFromHistory.Count == 0)
				{
					_deflateEncoder.FlushInput();
					_processingState = DeflaterState.CheckingForIncompressible;
				}
				break;
			case DeflaterState.CheckingForIncompressible:
			{
				DeflateInput.InputState state = _input.DumpState();
				OutputBuffer.BufferState state2 = _output.DumpState();
				_deflateEncoder.GetBlock(_input, _output, 8072);
				if (!UseCompressed(_deflateEncoder.LastCompressionRatio))
				{
					_input.RestoreState(state);
					_output.RestoreState(state2);
					_copyEncoder.GetBlock(_input, _output, isFinal: false);
					FlushInputWindows();
				}
				break;
			}
			case DeflaterState.StartingSmallData:
				_deflateEncoder.GetBlockHeader(_output);
				_processingState = DeflaterState.HandlingSmallData;
				goto case DeflaterState.HandlingSmallData;
			case DeflaterState.HandlingSmallData:
				_deflateEncoder.GetCompressedData(_input, _output);
				break;
			}
			return _output.BytesWritten;
		}

		internal bool Finish(byte[] outputBuffer, out int bytesRead)
		{
			if (_processingState == DeflaterState.NotStarted)
			{
				bytesRead = 0;
				return true;
			}
			_output.UpdateBuffer(outputBuffer);
			if (_processingState == DeflaterState.CompressThenCheck || _processingState == DeflaterState.HandlingSmallData || _processingState == DeflaterState.SlowDownForIncompressible1)
			{
				_deflateEncoder.GetBlockFooter(_output);
			}
			WriteFinal();
			bytesRead = _output.BytesWritten;
			return true;
		}

		private bool UseCompressed(double ratio)
		{
			return ratio <= 1.0;
		}

		private void FlushInputWindows()
		{
			_deflateEncoder.FlushInput();
		}

		private void WriteFinal()
		{
			_copyEncoder.GetBlock(null, _output, isFinal: true);
		}

		public void Dispose()
		{
		}
	}
	internal sealed class FastEncoder
	{
		private readonly FastEncoderWindow _inputWindow;

		private readonly Match _currentMatch;

		private double _lastCompressionRatio;

		internal int BytesInHistory => _inputWindow.BytesAvailable;

		internal DeflateInput UnprocessedInput => _inputWindow.UnprocessedInput;

		internal double LastCompressionRatio => _lastCompressionRatio;

		public FastEncoder()
		{
			_inputWindow = new FastEncoderWindow();
			_currentMatch = new Match();
		}

		internal void FlushInput()
		{
			_inputWindow.FlushWindow();
		}

		internal void GetBlock(DeflateInput input, OutputBuffer output, int maxBytesToCopy)
		{
			WriteDeflatePreamble(output);
			GetCompressedOutput(input, output, maxBytesToCopy);
			WriteEndOfBlock(output);
		}

		internal void GetCompressedData(DeflateInput input, OutputBuffer output)
		{
			GetCompressedOutput(input, output, -1);
		}

		internal void GetBlockHeader(OutputBuffer output)
		{
			WriteDeflatePreamble(output);
		}

		internal void GetBlockFooter(OutputBuffer output)
		{
			WriteEndOfBlock(output);
		}

		private void GetCompressedOutput(DeflateInput input, OutputBuffer output, int maxBytesToCopy)
		{
			int bytesWritten = output.BytesWritten;
			int num = 0;
			int num2 = BytesInHistory + input.Count;
			do
			{
				int num3 = ((input.Count < _inputWindow.FreeWindowSpace) ? input.Count : _inputWindow.FreeWindowSpace);
				if (maxBytesToCopy >= 1)
				{
					num3 = Math.Min(num3, maxBytesToCopy - num);
				}
				if (num3 > 0)
				{
					_inputWindow.CopyBytes(input.Buffer, input.StartIndex, num3);
					input.ConsumeBytes(num3);
					num += num3;
				}
				GetCompressedOutput(output);
			}
			while (SafeToWriteTo(output) && InputAvailable(input) && (maxBytesToCopy < 1 || num < maxBytesToCopy));
			int num4 = output.BytesWritten - bytesWritten;
			int num5 = BytesInHistory + input.Count;
			int num6 = num2 - num5;
			if (num4 != 0)
			{
				_lastCompressionRatio = (double)num4 / (double)num6;
			}
		}

		private void GetCompressedOutput(OutputBuffer output)
		{
			while (_inputWindow.BytesAvailable > 0 && SafeToWriteTo(output))
			{
				_inputWindow.GetNextSymbolOrMatch(_currentMatch);
				if (_currentMatch.State == MatchState.HasSymbol)
				{
					WriteChar(_currentMatch.Symbol, output);
					continue;
				}
				if (_currentMatch.State == MatchState.HasMatch)
				{
					WriteMatch(_currentMatch.Length, _currentMatch.Position, output);
					continue;
				}
				WriteChar(_currentMatch.Symbol, output);
				WriteMatch(_currentMatch.Length, _currentMatch.Position, output);
			}
		}

		private bool InputAvailable(DeflateInput input)
		{
			if (input.Count <= 0)
			{
				return BytesInHistory > 0;
			}
			return true;
		}

		private bool SafeToWriteTo(OutputBuffer output)
		{
			return output.FreeBytes > 16;
		}

		private void WriteEndOfBlock(OutputBuffer output)
		{
			uint num = FastEncoderStatics.FastEncoderLiteralCodeInfo[256];
			int n = (int)(num & 0x1F);
			output.WriteBits(n, num >> 5);
		}

		internal static void WriteMatch(int matchLen, int matchPos, OutputBuffer output)
		{
			uint num = FastEncoderStatics.FastEncoderLiteralCodeInfo[254 + matchLen];
			int num2 = (int)(num & 0x1F);
			if (num2 <= 16)
			{
				output.WriteBits(num2, num >> 5);
			}
			else
			{
				output.WriteBits(16, (num >> 5) & 0xFFFFu);
				output.WriteBits(num2 - 16, num >> 21);
			}
			num = FastEncoderStatics.FastEncoderDistanceCodeInfo[FastEncoderStatics.GetSlot(matchPos)];
			output.WriteBits((int)(num & 0xF), num >> 8);
			int num3 = (int)((num >> 4) & 0xF);
			if (num3 != 0)
			{
				output.WriteBits(num3, (uint)matchPos & FastEncoderStatics.BitMask[num3]);
			}
		}

		internal static void WriteChar(byte b, OutputBuffer output)
		{
			uint num = FastEncoderStatics.FastEncoderLiteralCodeInfo[b];
			output.WriteBits((int)(num & 0x1F), num >> 5);
		}

		internal static void WriteDeflatePreamble(OutputBuffer output)
		{
			output.WriteBytes(FastEncoderStatics.FastEncoderTreeStructureData, 0, FastEncoderStatics.FastEncoderTreeStructureData.Length);
			output.WriteBits(9, 34u);
		}
	}
	internal static class FastEncoderStatics
	{
		internal static readonly byte[] FastEncoderTreeStructureData = new byte[98]
		{
			236, 189, 7, 96, 28, 73, 150, 37, 38, 47,
			109, 202, 123, 127, 74, 245, 74, 215, 224, 116,
			161, 8, 128, 96, 19, 36, 216, 144, 64, 16,
			236, 193, 136, 205, 230, 146, 236, 29, 105, 71,
			35, 41, 171, 42, 129, 202, 101, 86, 101, 93,
			102, 22, 64, 204, 237, 157, 188, 247, 222, 123,
			239, 189, 247, 222, 123, 239, 189, 247, 186, 59,
			157, 78, 39, 247, 223, 255, 63, 92, 102, 100,
			1, 108, 246, 206, 74, 218, 201, 158, 33, 128,
			170, 200, 31, 63, 126, 124, 31, 63
		};

		internal static readonly byte[] BFinalFastEncoderTreeStructureData = new byte[98]
		{
			237, 189, 7, 96, 28, 73, 150, 37, 38, 47,
			109, 202, 123, 127, 74, 245, 74, 215, 224, 116,
			161, 8, 128, 96, 19, 36, 216, 144, 64, 16,
			236, 193, 136, 205, 230, 146, 236, 29, 105, 71,
			35, 41, 171, 42, 129, 202, 101, 86, 101, 93,
			102, 22, 64, 204, 237, 157, 188, 247, 222, 123,
			239, 189, 247, 222, 123, 239, 189, 247, 186, 59,
			157, 78, 39, 247, 223, 255, 63, 92, 102, 100,
			1, 108, 246, 206, 74, 218, 201, 158, 33, 128,
			170, 200, 31, 63, 126, 124, 31, 63
		};

		internal static readonly uint[] FastEncoderLiteralCodeInfo = new uint[513]
		{
			55278u, 317422u, 186350u, 448494u, 120814u, 382958u, 251886u, 514030u, 14318u, 51180u,
			294u, 276462u, 145390u, 407534u, 79854u, 341998u, 210926u, 473070u, 47086u, 309230u,
			178158u, 440302u, 112622u, 374766u, 243694u, 505838u, 30702u, 292846u, 161774u, 423918u,
			6125u, 96238u, 1318u, 358382u, 9194u, 116716u, 227310u, 489454u, 137197u, 25578u,
			2920u, 3817u, 23531u, 5098u, 1127u, 7016u, 3175u, 12009u, 1896u, 5992u,
			3944u, 7913u, 8040u, 16105u, 21482u, 489u, 232u, 8681u, 4585u, 4328u,
			12777u, 13290u, 2280u, 63470u, 325614u, 6376u, 2537u, 1256u, 10729u, 5352u,
			6633u, 29674u, 56299u, 3304u, 15339u, 194542u, 14825u, 3050u, 1513u, 19434u,
			9705u, 10220u, 5609u, 13801u, 3561u, 11242u, 75756u, 48107u, 456686u, 129006u,
			42988u, 31723u, 391150u, 64491u, 260078u, 522222u, 4078u, 806u, 615u, 2663u,
			1639u, 1830u, 7400u, 744u, 3687u, 166u, 108524u, 11753u, 1190u, 359u,
			2407u, 678u, 1383u, 71661u, 1702u, 422u, 1446u, 3431u, 4840u, 2792u,
			7657u, 6888u, 2027u, 202733u, 26604u, 38893u, 169965u, 266222u, 135150u, 397294u,
			69614u, 331758u, 200686u, 462830u, 36846u, 298990u, 167918u, 430062u, 102382u, 364526u,
			233454u, 495598u, 20462u, 282606u, 151534u, 413678u, 85998u, 348142u, 217070u, 479214u,
			53230u, 315374u, 184302u, 446446u, 118766u, 380910u, 249838u, 511982u, 12270u, 274414u,
			143342u, 405486u, 77806u, 339950u, 208878u, 471022u, 45038u, 307182u, 176110u, 438254u,
			110574u, 372718u, 241646u, 503790u, 28654u, 290798u, 159726u, 421870u, 94190u, 356334u,
			225262u, 487406u, 61422u, 323566u, 192494u, 454638u, 126958u, 389102u, 258030u, 520174u,
			8174u, 270318u, 139246u, 401390u, 73710u, 335854u, 204782u, 466926u, 40942u, 303086u,
			172014u, 434158u, 106478u, 368622u, 237550u, 499694u, 24558u, 286702u, 155630u, 417774u,
			90094u, 352238u, 221166u, 483310u, 57326u, 319470u, 188398u, 450542u, 122862u, 385006u,
			253934u, 516078u, 16366u, 278510u, 147438u, 409582u, 81902u, 344046u, 212974u, 475118u,
			49134u, 311278u, 180206u, 442350u, 114670u, 376814u, 245742u, 507886u, 32750u, 294894u,
			163822u, 425966u, 98286u, 104429u, 235501u, 22509u, 360430u, 153581u, 229358u, 88045u,
			491502u, 219117u, 65518u, 327662u, 196590u, 458734u, 131054u, 132u, 3u, 388u,
			68u, 324u, 197u, 709u, 453u, 966u, 1990u, 38u, 1062u, 935u,
			2983u, 1959u, 4007u, 551u, 1575u, 2599u, 3623u, 104u, 2152u, 4200u,
			6248u, 873u, 4969u, 9065u, 13161u, 1770u, 9962u, 18154u, 26346u, 5867u,
			14059u, 22251u, 30443u, 38635u, 46827u, 55019u, 63211u, 15852u, 32236u, 48620u,
			65004u, 81388u, 97772u, 114156u, 130540u, 27629u, 60397u, 93165u, 125933u, 158701u,
			191469u, 224237u, 257005u, 1004u, 17388u, 33772u, 50156u, 66540u, 82924u, 99308u,
			115692u, 7150u, 39918u, 72686u, 105454u, 138222u, 170990u, 203758u, 236526u, 269294u,
			302062u, 334830u, 367598u, 400366u, 433134u, 465902u, 498670u, 92144u, 223216u, 354288u,
			485360u, 616432u, 747504u, 878576u, 1009648u, 1140720u, 1271792u, 1402864u, 1533936u, 1665008u,
			1796080u, 1927152u, 2058224u, 34799u, 100335u, 165871u, 231407u, 296943u, 362479u, 428015u,
			493551u, 559087u, 624623u, 690159u, 755695u, 821231u, 886767u, 952303u, 1017839u, 59376u,
			190448u, 321520u, 452592u, 583664u, 714736u, 845808u, 976880u, 1107952u, 1239024u, 1370096u,
			1501168u, 1632240u, 1763312u, 1894384u, 2025456u, 393203u, 917491u, 1441779u, 1966067u, 2490355u,
			3014643u, 3538931u, 4063219u, 4587507u, 5111795u, 5636083u, 6160371u, 6684659u, 7208947u, 7733235u,
			8257523u, 8781811u, 9306099u, 9830387u, 10354675u, 10878963u, 11403251u, 11927539u, 12451827u, 12976115u,
			13500403u, 14024691u, 14548979u, 15073267u, 15597555u, 16121843u, 16646131u, 262131u, 786419u, 1310707u,
			1834995u, 2359283u, 2883571u, 3407859u, 3932147u, 4456435u, 4980723u, 5505011u, 6029299u, 6553587u,
			7077875u, 7602163u, 8126451u, 8650739u, 9175027u, 9699315u, 10223603u, 10747891u, 11272179u, 11796467u,
			12320755u, 12845043u, 13369331u, 13893619u, 14417907u, 14942195u, 15466483u, 15990771u, 16515059u, 524275u,
			1048563u, 1572851u, 2097139u, 2621427u, 3145715u, 3670003u, 4194291u, 4718579u, 5242867u, 5767155u,
			6291443u, 6815731u, 7340019u, 7864307u, 8388595u, 8912883u, 9437171u, 9961459u, 10485747u, 11010035u,
			11534323u, 12058611u, 12582899u, 13107187u, 13631475u, 14155763u, 14680051u, 15204339u, 15728627u, 16252915u,
			16777203u, 124913u, 255985u, 387057u, 518129u, 649201u, 780273u, 911345u, 1042417u, 1173489u,
			1304561u, 1435633u, 1566705u, 1697777u, 1828849u, 1959921u, 2090993u, 2222065u, 2353137u, 2484209u,
			2615281u, 2746353u, 2877425u, 3008497u, 3139569u, 3270641u, 3401713u, 3532785u, 3663857u, 3794929u,
			3926001u, 4057073u, 18411u
		};

		internal static readonly uint[] FastEncoderDistanceCodeInfo = new uint[32]
		{
			3846u, 130826u, 261899u, 524043u, 65305u, 16152u, 48936u, 32552u, 7991u, 24375u,
			3397u, 12102u, 84u, 7509u, 2148u, 869u, 1140u, 4981u, 3204u, 644u,
			2708u, 1684u, 3748u, 420u, 2484u, 2997u, 1476u, 7109u, 2005u, 6101u,
			0u, 256u
		};

		internal static readonly uint[] BitMask = new uint[16]
		{
			0u, 1u, 3u, 7u, 15u, 31u, 63u, 127u, 255u, 511u,
			1023u, 2047u, 4095u, 8191u, 16383u, 32767u
		};

		internal static readonly byte[] ExtraLengthBits = new byte[29]
		{
			0, 0, 0, 0, 0, 0, 0, 0, 1, 1,
			1, 1, 2, 2, 2, 2, 3, 3, 3, 3,
			4, 4, 4, 4, 5, 5, 5, 5, 0
		};

		internal static readonly byte[] ExtraDistanceBits = new byte[32]
		{
			0, 0, 0, 0, 1, 1, 2, 2, 3, 3,
			4, 4, 5, 5, 6, 6, 7, 7, 8, 8,
			9, 9, 10, 10, 11, 11, 12, 12, 13, 13,
			0, 0
		};

		internal const int NumChars = 256;

		internal const int NumLengthBaseCodes = 29;

		internal const int NumDistBaseCodes = 30;

		internal const uint FastEncoderPostTreeBitBuf = 34u;

		internal const int FastEncoderPostTreeBitCount = 9;

		internal const uint NoCompressionHeader = 0u;

		internal const int NoCompressionHeaderBitCount = 3;

		internal const uint BFinalNoCompressionHeader = 1u;

		internal const int BFinalNoCompressionHeaderBitCount = 3;

		internal const int MaxCodeLen = 16;

		private static readonly byte[] s_distLookup = CreateDistanceLookup();

		private static byte[] CreateDistanceLookup()
		{
			byte[] array = new byte[512];
			int num = 0;
			int i;
			for (i = 0; i < 16; i++)
			{
				for (int j = 0; j < 1 << (int)ExtraDistanceBits[i]; j++)
				{
					array[num++] = (byte)i;
				}
			}
			num >>= 7;
			for (; i < 30; i++)
			{
				for (int k = 0; k < 1 << ExtraDistanceBits[i] - 7; k++)
				{
					array[256 + num++] = (byte)i;
				}
			}
			return array;
		}

		internal static int GetSlot(int pos)
		{
			return s_distLookup[(pos < 256) ? pos : (256 + (pos >> 7))];
		}

		public static uint BitReverse(uint code, int length)
		{
			uint num = 0u;
			do
			{
				num |= code & 1u;
				num <<= 1;
				code >>= 1;
			}
			while (--length > 0);
			return num >> 1;
		}
	}
	internal sealed class FastEncoderWindow
	{
		private byte[] _window;

		private int _bufPos;

		private int _bufEnd;

		private const int FastEncoderHashShift = 4;

		private const int FastEncoderHashtableSize = 2048;

		private const int FastEncoderHashMask = 2047;

		private const int FastEncoderWindowSize = 8192;

		private const int FastEncoderWindowMask = 8191;

		private const int FastEncoderMatch3DistThreshold = 16384;

		internal const int MaxMatch = 258;

		internal const int MinMatch = 3;

		private const int SearchDepth = 32;

		private const int GoodLength = 4;

		private const int NiceLength = 32;

		private const int LazyMatchThreshold = 6;

		private ushort[] _prev;

		private ushort[] _lookup;

		public int BytesAvailable => _bufEnd - _bufPos;

		public DeflateInput UnprocessedInput => new DeflateInput
		{
			Buffer = _window,
			StartIndex = _bufPos,
			Count = _bufEnd - _bufPos
		};

		public int FreeWindowSpace => 16384 - _bufEnd;

		public FastEncoderWindow()
		{
			ResetWindow();
		}

		public void FlushWindow()
		{
			ResetWindow();
		}

		private void ResetWindow()
		{
			_window = new byte[16646];
			_prev = new ushort[8450];
			_lookup = new ushort[2048];
			_bufPos = 8192;
			_bufEnd = _bufPos;
		}

		public void CopyBytes(byte[] inputBuffer, int startIndex, int count)
		{
			Array.Copy(inputBuffer, startIndex, _window, _bufEnd, count);
			_bufEnd += count;
		}

		public void MoveWindows()
		{
			Array.Copy(_window, _bufPos - 8192, _window, 0, 8192);
			for (int i = 0; i < 2048; i++)
			{
				int num = _lookup[i] - 8192;
				if (num <= 0)
				{
					_lookup[i] = 0;
				}
				else
				{
					_lookup[i] = (ushort)num;
				}
			}
			for (int i = 0; i < 8192; i++)
			{
				long num2 = (long)_prev[i] - 8192L;
				if (num2 <= 0)
				{
					_prev[i] = 0;
				}
				else
				{
					_prev[i] = (ushort)num2;
				}
			}
			_bufPos = 8192;
			_bufEnd = _bufPos;
		}

		private uint HashValue(uint hash, byte b)
		{
			return (hash << 4) ^ b;
		}

		private uint InsertString(ref uint hash)
		{
			hash = HashValue(hash, _window[_bufPos + 2]);
			uint num = _lookup[hash & 0x7FF];
			_lookup[hash & 0x7FF] = (ushort)_bufPos;
			_prev[_bufPos & 0x1FFF] = (ushort)num;
			return num;
		}

		private void InsertStrings(ref uint hash, int matchLen)
		{
			if (_bufEnd - _bufPos <= matchLen)
			{
				_bufPos += matchLen - 1;
				return;
			}
			while (--matchLen > 0)
			{
				InsertString(ref hash);
				_bufPos++;
			}
		}

		internal bool GetNextSymbolOrMatch(Match match)
		{
			uint hash = HashValue(0u, _window[_bufPos]);
			hash = HashValue(hash, _window[_bufPos + 1]);
			int matchPos = 0;
			int num;
			if (_bufEnd - _bufPos <= 3)
			{
				num = 0;
			}
			else
			{
				int num2 = (int)InsertString(ref hash);
				if (num2 != 0)
				{
					num = FindMatch(num2, out matchPos, 32, 32);
					if (_bufPos + num > _bufEnd)
					{
						num = _bufEnd - _bufPos;
					}
				}
				else
				{
					num = 0;
				}
			}
			if (num < 3)
			{
				match.State = MatchState.HasSymbol;
				match.Symbol = _window[_bufPos];
				_bufPos++;
			}
			else
			{
				_bufPos++;
				if (num <= 6)
				{
					int matchPos2 = 0;
					int num3 = (int)InsertString(ref hash);
					int num4;
					if (num3 != 0)
					{
						num4 = FindMatch(num3, out matchPos2, (num < 4) ? 32 : 8, 32);
						if (_bufPos + num4 > _bufEnd)
						{
							num4 = _bufEnd - _bufPos;
						}
					}
					else
					{
						num4 = 0;
					}
					if (num4 > num)
					{
						match.State = MatchState.HasSymbolAndMatch;
						match.Symbol = _window[_bufPos - 1];
						match.Position = matchPos2;
						match.Length = num4;
						_bufPos++;
						num = num4;
						InsertStrings(ref hash, num);
					}
					else
					{
						match.State = MatchState.HasMatch;
						match.Position = matchPos;
						match.Length = num;
						num--;
						_bufPos++;
						InsertStrings(ref hash, num);
					}
				}
				else
				{
					match.State = MatchState.HasMatch;
					match.Position = matchPos;
					match.Length = num;
					InsertStrings(ref hash, num);
				}
			}
			if (_bufPos == 16384)
			{
				MoveWindows();
			}
			return true;
		}

		private int FindMatch(int search, out int matchPos, int searchDepth, int niceLength)
		{
			int num = 0;
			int num2 = 0;
			int num3 = _bufPos - 8192;
			byte b = _window[_bufPos];
			while (search > num3)
			{
				if (_window[search + num] == b)
				{
					int i;
					for (i = 0; i < 258 && _window[_bufPos + i] == _window[search + i]; i++)
					{
					}
					if (i > num)
					{
						num = i;
						num2 = search;
						if (i > 32)
						{
							break;
						}
						b = _window[_bufPos + i];
					}
				}
				if (--searchDepth == 0)
				{
					break;
				}
				search = _prev[search & 0x1FFF];
			}
			matchPos = _bufPos - num2 - 1;
			if (num == 3 && matchPos >= 16384)
			{
				return 0;
			}
			return num;
		}

		[Conditional("DEBUG")]
		private void DebugAssertVerifyHashes()
		{
		}

		[Conditional("DEBUG")]
		private void DebugAssertRecalculatedHashesAreEqual(int position1, int position2, string message = "")
		{
		}
	}
	internal interface IFileFormatWriter
	{
		byte[] GetHeader();

		void UpdateWithBytesRead(byte[] buffer, int offset, int bytesToCopy);

		byte[] GetFooter();
	}
	internal interface IFileFormatReader
	{
		bool ReadHeader(System.IO.Compression.InputBuffer input);

		bool ReadFooter(System.IO.Compression.InputBuffer input);

		void UpdateWithBytesRead(byte[] buffer, int offset, int bytesToCopy);

		void Validate();
	}
	internal sealed class HuffmanTree
	{
		internal const int MaxLiteralTreeElements = 288;

		internal const int MaxDistTreeElements = 32;

		internal const int EndOfBlockCode = 256;

		internal const int NumberOfCodeLengthTreeElements = 19;

		private readonly int _tableBits;

		private readonly short[] _table;

		private readonly short[] _left;

		private readonly short[] _right;

		private readonly byte[] _codeLengthArray;

		private readonly int _tableMask;

		public static System.IO.Compression.HuffmanTree StaticLiteralLengthTree { get; } = new System.IO.Compression.HuffmanTree(GetStaticLiteralTreeLength());


		public static System.IO.Compression.HuffmanTree StaticDistanceTree { get; } = new System.IO.Compression.HuffmanTree(GetStaticDistanceTreeLength());


		public HuffmanTree(byte[] codeLengths)
		{
			_codeLengthArray = codeLengths;
			if (_codeLengthArray.Length == 288)
			{
				_tableBits = 9;
			}
			else
			{
				_tableBits = 7;
			}
			_tableMask = (1 << _tableBits) - 1;
			_table = new short[1 << _tableBits];
			_left = new short[2 * _codeLengthArray.Length];
			_right = new short[2 * _codeLengthArray.Length];
			CreateTable();
		}

		private static byte[] GetStaticLiteralTreeLength()
		{
			byte[] array = new byte[288];
			for (int i = 0; i <= 143; i++)
			{
				array[i] = 8;
			}
			for (int j = 144; j <= 255; j++)
			{
				array[j] = 9;
			}
			for (int k = 256; k <= 279; k++)
			{
				array[k] = 7;
			}
			for (int l = 280; l <= 287; l++)
			{
				array[l] = 8;
			}
			return array;
		}

		private static byte[] GetStaticDistanceTreeLength()
		{
			byte[] array = new byte[32];
			for (int i = 0; i < 32; i++)
			{
				array[i] = 5;
			}
			return array;
		}

		private uint[] CalculateHuffmanCode()
		{
			uint[] array = new uint[17];
			byte[] codeLengthArray = _codeLengthArray;
			foreach (int num in codeLengthArray)
			{
				array[num]++;
			}
			array[0] = 0u;
			uint[] array2 = new uint[17];
			uint num2 = 0u;
			for (int j = 1; j <= 16; j++)
			{
				num2 = (array2[j] = num2 + array[j - 1] << 1);
			}
			uint[] array3 = new uint[288];
			for (int k = 0; k < _codeLengthArray.Length; k++)
			{
				int num3 = _codeLengthArray[k];
				if (num3 > 0)
				{
					array3[k] = FastEncoderStatics.BitReverse(array2[num3], num3);
					array2[num3]++;
				}
			}
			return array3;
		}

		private void CreateTable()
		{
			uint[] array = CalculateHuffmanCode();
			short num = (short)_codeLengthArray.Length;
			for (int i = 0; i < _codeLengthArray.Length; i++)
			{
				int num2 = _codeLengthArray[i];
				if (num2 <= 0)
				{
					continue;
				}
				int num3 = (int)array[i];
				if (num2 <= _tableBits)
				{
					int num4 = 1 << num2;
					if (num3 >= num4)
					{
						throw new InvalidDataException("Failed to construct a huffman tree using the length array. The stream might be corrupted.");
					}
					int num5 = 1 << _tableBits - num2;
					for (int j = 0; j < num5; j++)
					{
						_table[num3] = (short)i;
						num3 += num4;
					}
					continue;
				}
				int num6 = num2 - _tableBits;
				int num7 = 1 << _tableBits;
				int num8 = num3 & ((1 << _tableBits) - 1);
				short[] array2 = _table;
				do
				{
					short num9 = array2[num8];
					if (num9 == 0)
					{
						array2[num8] = (short)(-num);
						num9 = (short)(-num);
						num++;
					}
					if (num9 > 0)
					{
						throw new InvalidDataException("Failed to construct a huffman tree using the length array. The stream might be corrupted.");
					}
					array2 = (((num3 & num7) != 0) ? _right : _left);
					num8 = -num9;
					num7 <<= 1;
					num6--;
				}
				while (num6 != 0);
				array2[num8] = (short)i;
			}
		}

		public int GetNextSymbol(System.IO.Compression.InputBuffer input)
		{
			uint num = input.TryLoad16Bits();
			if (input.AvailableBits == 0)
			{
				return -1;
			}
			int num2 = _table[num & _tableMask];
			if (num2 < 0)
			{
				uint num3 = (uint)(1 << _tableBits);
				do
				{
					num2 = -num2;
					num2 = (((num & num3) != 0) ? _right[num2] : _left[num2]);
					num3 <<= 1;
				}
				while (num2 < 0);
			}
			int num4 = _codeLengthArray[num2];
			if (num4 <= 0)
			{
				throw new InvalidDataException("Failed to construct a huffman tree using the length array. The stream might be corrupted.");
			}
			if (num4 > input.AvailableBits)
			{
				return -1;
			}
			input.SkipBits(num4);
			return num2;
		}
	}
	internal sealed class InflaterManaged
	{
		private static readonly byte[] s_extraLengthBits = new byte[29]
		{
			0, 0, 0, 0, 0, 0, 0, 0, 1, 1,
			1, 1, 2, 2, 2, 2, 3, 3, 3, 3,
			4, 4, 4, 4, 5, 5, 5, 5, 16
		};

		private static readonly int[] s_lengthBase = new int[29]
		{
			3, 4, 5, 6, 7, 8, 9, 10, 11, 13,
			15, 17, 19, 23, 27, 31, 35, 43, 51, 59,
			67, 83, 99, 115, 131, 163, 195, 227, 3
		};

		private static readonly int[] s_distanceBasePosition = new int[32]
		{
			1, 2, 3, 4, 5, 7, 9, 13, 17, 25,
			33, 49, 65, 97, 129, 193, 257, 385, 513, 769,
			1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577,
			32769, 49153
		};

		private static readonly byte[] s_codeOrder = new byte[19]
		{
			16, 17, 18, 0, 8, 7, 9, 6, 10, 5,
			11, 4, 12, 3, 13, 2, 14, 1, 15
		};

		private static readonly byte[] s_staticDistanceTreeTable = new byte[32]
		{
			0, 16, 8, 24, 4, 20, 12, 28, 2, 18,
			10, 26, 6, 22, 14, 30, 1, 17, 9, 25,
			5, 21, 13, 29, 3, 19, 11, 27, 7, 23,
			15, 31
		};

		private readonly System.IO.Compression.OutputWindow _output;

		private readonly System.IO.Compression.InputBuffer _input;

		private System.IO.Compression.HuffmanTree _literalLengthTree;

		private System.IO.Compression.HuffmanTree _distanceTree;

		private System.IO.Compression.InflaterState _state;

		private bool _hasFormatReader;

		private int _bfinal;

		private System.IO.Compression.BlockType _blockType;

		private readonly byte[] _blockLengthBuffer = new byte[4];

		private int _blockLength;

		private int _length;

		private int _distanceCode;

		private int _extraBits;

		private int _loopCounter;

		private int _literalLengthCodeCount;

		private int _distanceCodeCount;

		private int _codeLengthCodeCount;

		private int _codeArraySize;

		private int _lengthCode;

		private readonly byte[] _codeList;

		private readonly byte[] _codeLengthTreeCodeLength;

		private readonly bool _deflate64;

		private System.IO.Compression.HuffmanTree _codeLengthTree;

		private IFileFormatReader _formatReader;

		public int AvailableOutput => _output.AvailableBytes;

		internal InflaterManaged(IFileFormatReader reader, bool deflate64)
		{
			_output = new System.IO.Compression.OutputWindow();
			_input = new System.IO.Compression.InputBuffer();
			_codeList = new byte[320];
			_codeLengthTreeCodeLength = new byte[19];
			_deflate64 = deflate64;
			if (reader != null)
			{
				_formatReader = reader;
				_hasFormatReader = true;
			}
			Reset();
		}

		private void Reset()
		{
			_state = ((!_hasFormatReader) ? System.IO.Compression.InflaterState.ReadingBFinal : System.IO.Compression.InflaterState.ReadingHeader);
		}

		public void SetInput(byte[] inputBytes, int offset, int length)
		{
			_input.SetInput(inputBytes, offset, length);
		}

		public bool Finished()
		{
			if (_state != System.IO.Compression.InflaterState.Done)
			{
				return _state == System.IO.Compression.InflaterState.VerifyingFooter;
			}
			return true;
		}

		public int Inflate(byte[] bytes, int offset, int length)
		{
			int num = 0;
			do
			{
				int num2 = _output.CopyTo(bytes, offset, length);
				if (num2 > 0)
				{
					if (_hasFormatReader)
					{
						_formatReader.UpdateWithBytesRead(bytes, offset, num2);
					}
					offset += num2;
					num += num2;
					length -= num2;
				}
			}
			while (length != 0 && !Finished() && Decode());
			if (_state == System.IO.Compression.InflaterState.VerifyingFooter && _output.AvailableBytes == 0)
			{
				_formatReader.Validate();
			}
			return num;
		}

		private bool Decode()
		{
			bool end_of_block_code_seen = false;
			bool flag = false;
			if (Finished())
			{
				return true;
			}
			if (_hasFormatReader)
			{
				if (_state == System.IO.Compression.InflaterState.ReadingHeader)
				{
					if (!_formatReader.ReadHeader(_input))
					{
						return false;
					}
					_state = System.IO.Compression.InflaterState.ReadingBFinal;
				}
				else if (_state == System.IO.Compression.InflaterState.StartReadingFooter || _state == System.IO.Compression.InflaterState.ReadingFooter)
				{
					if (!_formatReader.ReadFooter(_input))
					{
						return false;
					}
					_state = System.IO.Compression.InflaterState.VerifyingFooter;
					return true;
				}
			}
			if (_state == System.IO.Compression.InflaterState.ReadingBFinal)
			{
				if (!_input.EnsureBitsAvailable(1))
				{
					return false;
				}
				_bfinal = _input.GetBits(1);
				_state = System.IO.Compression.InflaterState.ReadingBType;
			}
			if (_state == System.IO.Compression.InflaterState.ReadingBType)
			{
				if (!_input.EnsureBitsAvailable(2))
				{
					_state = System.IO.Compression.InflaterState.ReadingBType;
					return false;
				}
				_blockType = (System.IO.Compression.BlockType)_input.GetBits(2);
				if (_blockType == System.IO.Compression.BlockType.Dynamic)
				{
					_state = System.IO.Compression.InflaterState.ReadingNumLitCodes;
				}
				else if (_blockType == System.IO.Compression.BlockType.Static)
				{
					_literalLengthTree = System.IO.Compression.Huffm

BepInExPack/mono/Managed/System.IO.Compression.FileSystem.dll

Decompiled a month ago
using System.Buffers;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using System.Text;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("System.IO.Compression.FileSystem.dll")]
[assembly: AssemblyDescription("System.IO.Compression.FileSystem.dll")]
[assembly: AssemblyDefaultAlias("System.IO.Compression.FileSystem.dll")]
[assembly: AssemblyCompany("Mono development team")]
[assembly: AssemblyProduct("Mono Common Language Infrastructure")]
[assembly: AssemblyCopyright("(c) Various Mono authors")]
[assembly: AssemblyInformationalVersion("4.6.57.0")]
[assembly: AssemblyFileVersion("4.6.57.0")]
[assembly: AssemblyDelaySign(true)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("4.0.0.0")]
[module: UnverifiableCode]
internal static class Consts
{
	public const string MonoCorlibVersion = "1A5E0066-58DC-428A-B21C-0AD6CDAE2789";

	public const string MonoVersion = "6.13.0.0";

	public const string MonoCompany = "Mono development team";

	public const string MonoProduct = "Mono Common Language Infrastructure";

	public const string MonoCopyright = "(c) Various Mono authors";

	public const string FxVersion = "4.0.0.0";

	public const string FxFileVersion = "4.6.57.0";

	public const string EnvironmentVersion = "4.0.30319.42000";

	public const string VsVersion = "0.0.0.0";

	public const string VsFileVersion = "11.0.0.0";

	private const string PublicKeyToken = "b77a5c561934e089";

	public const string AssemblyI18N = "I18N, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756";

	public const string AssemblyMicrosoft_JScript = "Microsoft.JScript, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblyMicrosoft_VisualStudio = "Microsoft.VisualStudio, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblyMicrosoft_VisualStudio_Web = "Microsoft.VisualStudio.Web, Version=0.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblyMicrosoft_VSDesigner = "Microsoft.VSDesigner, Version=0.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblyMono_Http = "Mono.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756";

	public const string AssemblyMono_Posix = "Mono.Posix, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756";

	public const string AssemblyMono_Security = "Mono.Security, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756";

	public const string AssemblyMono_Messaging_RabbitMQ = "Mono.Messaging.RabbitMQ, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756";

	public const string AssemblyCorlib = "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string AssemblySystem = "System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string AssemblySystem_Data = "System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string AssemblySystem_Design = "System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_DirectoryServices = "System.DirectoryServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_Drawing = "System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_Drawing_Design = "System.Drawing.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_Messaging = "System.Messaging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_Security = "System.Security, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_ServiceProcess = "System.ServiceProcess, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_Web = "System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_Windows_Forms = "System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string AssemblySystem_2_0 = "System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string AssemblySystemCore_3_5 = "System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string AssemblySystem_Core = "System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string WindowsBase_3_0 = "WindowsBase, Version=3.0.0.0, PublicKeyToken=31bf3856ad364e35";

	public const string AssemblyWindowsBase = "WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";

	public const string AssemblyPresentationCore_3_5 = "PresentationCore, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";

	public const string AssemblyPresentationCore_4_0 = "PresentationCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";

	public const string AssemblyPresentationFramework_3_5 = "PresentationFramework, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";

	public const string AssemblySystemServiceModel_3_0 = "System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";
}
internal class SR
{
	public const string IO_DirectoryNameWithData = "Zip entry name ends in directory separator character but contains data.";

	public const string IO_ExtractingResultsInOutside = "Extracting Zip entry would have resulted in a file outside the specified destination directory.";
}
namespace System.IO
{
	internal static class PathInternal
	{
		private static readonly bool s_isCaseSensitive = GetIsCaseSensitive();

		internal static StringComparison StringComparison
		{
			get
			{
				if (!s_isCaseSensitive)
				{
					return StringComparison.OrdinalIgnoreCase;
				}
				return StringComparison.Ordinal;
			}
		}

		internal static bool IsCaseSensitive => s_isCaseSensitive;

		private static bool GetIsCaseSensitive()
		{
			try
			{
				string text = Path.Combine(Path.GetTempPath(), "CASESENSITIVETEST" + Guid.NewGuid().ToString("N"));
				using (new FileStream(text, FileMode.CreateNew, FileAccess.ReadWrite, FileShare.None, 4096, FileOptions.DeleteOnClose))
				{
					return !File.Exists(text.ToLowerInvariant());
				}
			}
			catch (Exception)
			{
				return false;
			}
		}
	}
}
namespace System.IO.Compression
{
	public static class ZipFile
	{
		private const char PathSeparator = '/';

		public static ZipArchive OpenRead(string archiveFileName)
		{
			return Open(archiveFileName, ZipArchiveMode.Read);
		}

		public static ZipArchive Open(string archiveFileName, ZipArchiveMode mode)
		{
			return Open(archiveFileName, mode, null);
		}

		public static ZipArchive Open(string archiveFileName, ZipArchiveMode mode, Encoding entryNameEncoding)
		{
			FileMode mode2;
			FileAccess access;
			FileShare share;
			switch (mode)
			{
			case ZipArchiveMode.Read:
				mode2 = FileMode.Open;
				access = FileAccess.Read;
				share = FileShare.Read;
				break;
			case ZipArchiveMode.Create:
				mode2 = FileMode.CreateNew;
				access = FileAccess.Write;
				share = FileShare.None;
				break;
			case ZipArchiveMode.Update:
				mode2 = FileMode.OpenOrCreate;
				access = FileAccess.ReadWrite;
				share = FileShare.None;
				break;
			default:
				throw new ArgumentOutOfRangeException("mode");
			}
			FileStream fileStream = new FileStream(archiveFileName, mode2, access, share, 4096, useAsync: false);
			try
			{
				return new ZipArchive(fileStream, mode, leaveOpen: false, entryNameEncoding);
			}
			catch
			{
				fileStream.Dispose();
				throw;
			}
		}

		public static void CreateFromDirectory(string sourceDirectoryName, string destinationArchiveFileName)
		{
			DoCreateFromDirectory(sourceDirectoryName, destinationArchiveFileName, null, includeBaseDirectory: false, null);
		}

		public static void CreateFromDirectory(string sourceDirectoryName, string destinationArchiveFileName, CompressionLevel compressionLevel, bool includeBaseDirectory)
		{
			DoCreateFromDirectory(sourceDirectoryName, destinationArchiveFileName, compressionLevel, includeBaseDirectory, null);
		}

		public static void CreateFromDirectory(string sourceDirectoryName, string destinationArchiveFileName, CompressionLevel compressionLevel, bool includeBaseDirectory, Encoding entryNameEncoding)
		{
			DoCreateFromDirectory(sourceDirectoryName, destinationArchiveFileName, compressionLevel, includeBaseDirectory, entryNameEncoding);
		}

		public static void ExtractToDirectory(string sourceArchiveFileName, string destinationDirectoryName)
		{
			ExtractToDirectory(sourceArchiveFileName, destinationDirectoryName, null);
		}

		public static void ExtractToDirectory(string sourceArchiveFileName, string destinationDirectoryName, bool overwrite)
		{
			ExtractToDirectory(sourceArchiveFileName, destinationDirectoryName, null, overwrite);
		}

		public static void ExtractToDirectory(string sourceArchiveFileName, string destinationDirectoryName, Encoding entryNameEncoding)
		{
			ExtractToDirectory(sourceArchiveFileName, destinationDirectoryName, entryNameEncoding, overwrite: false);
		}

		public static void ExtractToDirectory(string sourceArchiveFileName, string destinationDirectoryName, Encoding entryNameEncoding, bool overwrite)
		{
			if (sourceArchiveFileName == null)
			{
				throw new ArgumentNullException("sourceArchiveFileName");
			}
			using ZipArchive source = Open(sourceArchiveFileName, ZipArchiveMode.Read, entryNameEncoding);
			source.ExtractToDirectory(destinationDirectoryName, overwrite);
		}

		private static void DoCreateFromDirectory(string sourceDirectoryName, string destinationArchiveFileName, CompressionLevel? compressionLevel, bool includeBaseDirectory, Encoding entryNameEncoding)
		{
			sourceDirectoryName = Path.GetFullPath(sourceDirectoryName);
			destinationArchiveFileName = Path.GetFullPath(destinationArchiveFileName);
			using ZipArchive zipArchive = Open(destinationArchiveFileName, ZipArchiveMode.Create, entryNameEncoding);
			bool flag = true;
			DirectoryInfo directoryInfo = new DirectoryInfo(sourceDirectoryName);
			string fullName = directoryInfo.FullName;
			if (includeBaseDirectory && directoryInfo.Parent != null)
			{
				fullName = directoryInfo.Parent.FullName;
			}
			char[] buffer = ArrayPool<char>.Shared.Rent(260);
			try
			{
				foreach (FileSystemInfo item in directoryInfo.EnumerateFileSystemInfos("*", SearchOption.AllDirectories))
				{
					flag = false;
					int length = item.FullName.Length - fullName.Length;
					if (item is FileInfo)
					{
						string entryName = EntryFromPath(item.FullName, fullName.Length, length, ref buffer);
						ZipFileExtensions.DoCreateEntryFromFile(zipArchive, item.FullName, entryName, compressionLevel);
					}
					else if (item is DirectoryInfo possiblyEmptyDir && IsDirEmpty(possiblyEmptyDir))
					{
						string entryName2 = EntryFromPath(item.FullName, fullName.Length, length, ref buffer, appendPathSeparator: true);
						zipArchive.CreateEntry(entryName2);
					}
				}
				if (includeBaseDirectory && flag)
				{
					zipArchive.CreateEntry(EntryFromPath(directoryInfo.Name, 0, directoryInfo.Name.Length, ref buffer, appendPathSeparator: true));
				}
			}
			finally
			{
				ArrayPool<char>.Shared.Return(buffer, false);
			}
		}

		private static string EntryFromPath(string entry, int offset, int length, ref char[] buffer, bool appendPathSeparator = false)
		{
			while (length > 0 && (entry[offset] == Path.DirectorySeparatorChar || entry[offset] == Path.AltDirectorySeparatorChar))
			{
				offset++;
				length--;
			}
			if (length == 0)
			{
				if (!appendPathSeparator)
				{
					return string.Empty;
				}
				return '/'.ToString();
			}
			int num = (appendPathSeparator ? (length + 1) : length);
			EnsureCapacity(ref buffer, num);
			entry.CopyTo(offset, buffer, 0, length);
			for (int i = 0; i < length; i++)
			{
				char c = buffer[i];
				if (c == Path.DirectorySeparatorChar || c == Path.AltDirectorySeparatorChar)
				{
					buffer[i] = '/';
				}
			}
			if (appendPathSeparator)
			{
				buffer[length] = '/';
			}
			return new string(buffer, 0, num);
		}

		private static void EnsureCapacity(ref char[] buffer, int min)
		{
			if (buffer.Length < min)
			{
				int num = buffer.Length * 2;
				if (num < min)
				{
					num = min;
				}
				ArrayPool<char>.Shared.Return(buffer, false);
				buffer = ArrayPool<char>.Shared.Rent(num);
			}
		}

		private static bool IsDirEmpty(DirectoryInfo possiblyEmptyDir)
		{
			using IEnumerator<string> enumerator = Directory.EnumerateFileSystemEntries(possiblyEmptyDir.FullName).GetEnumerator();
			return !enumerator.MoveNext();
		}
	}
	[EditorBrowsable(EditorBrowsableState.Never)]
	public static class ZipFileExtensions
	{
		public static ZipArchiveEntry CreateEntryFromFile(this ZipArchive destination, string sourceFileName, string entryName)
		{
			return DoCreateEntryFromFile(destination, sourceFileName, entryName, null);
		}

		public static ZipArchiveEntry CreateEntryFromFile(this ZipArchive destination, string sourceFileName, string entryName, CompressionLevel compressionLevel)
		{
			return DoCreateEntryFromFile(destination, sourceFileName, entryName, compressionLevel);
		}

		public static void ExtractToDirectory(this ZipArchive source, string destinationDirectoryName)
		{
			source.ExtractToDirectory(destinationDirectoryName, overwrite: false);
		}

		public static void ExtractToDirectory(this ZipArchive source, string destinationDirectoryName, bool overwrite)
		{
			if (source == null)
			{
				throw new ArgumentNullException("source");
			}
			if (destinationDirectoryName == null)
			{
				throw new ArgumentNullException("destinationDirectoryName");
			}
			string text = Directory.CreateDirectory(destinationDirectoryName).FullName;
			if (!text.EndsWith(Path.DirectorySeparatorChar))
			{
				text += Path.DirectorySeparatorChar;
			}
			foreach (ZipArchiveEntry entry in source.Entries)
			{
				string fullPath = Path.GetFullPath(Path.Combine(text, entry.FullName));
				if (!fullPath.StartsWith(text, System.IO.PathInternal.StringComparison))
				{
					throw new IOException("Extracting Zip entry would have resulted in a file outside the specified destination directory.");
				}
				if (Path.GetFileName(fullPath).Length == 0)
				{
					if (entry.Length != 0L)
					{
						throw new IOException("Zip entry name ends in directory separator character but contains data.");
					}
					Directory.CreateDirectory(fullPath);
				}
				else
				{
					Directory.CreateDirectory(Path.GetDirectoryName(fullPath));
					entry.ExtractToFile(fullPath, overwrite);
				}
			}
		}

		internal static ZipArchiveEntry DoCreateEntryFromFile(ZipArchive destination, string sourceFileName, string entryName, CompressionLevel? compressionLevel)
		{
			if (destination == null)
			{
				throw new ArgumentNullException("destination");
			}
			if (sourceFileName == null)
			{
				throw new ArgumentNullException("sourceFileName");
			}
			if (entryName == null)
			{
				throw new ArgumentNullException("entryName");
			}
			using Stream stream = new FileStream(sourceFileName, FileMode.Open, FileAccess.Read, FileShare.Read, 4096, useAsync: false);
			ZipArchiveEntry zipArchiveEntry = (compressionLevel.HasValue ? destination.CreateEntry(entryName, compressionLevel.Value) : destination.CreateEntry(entryName));
			DateTime dateTime = File.GetLastWriteTime(sourceFileName);
			if (dateTime.Year < 1980 || dateTime.Year > 2107)
			{
				dateTime = new DateTime(1980, 1, 1, 0, 0, 0);
			}
			zipArchiveEntry.LastWriteTime = dateTime;
			using (Stream destination2 = zipArchiveEntry.Open())
			{
				stream.CopyTo(destination2);
			}
			return zipArchiveEntry;
		}

		public static void ExtractToFile(this ZipArchiveEntry source, string destinationFileName)
		{
			source.ExtractToFile(destinationFileName, overwrite: false);
		}

		public static void ExtractToFile(this ZipArchiveEntry source, string destinationFileName, bool overwrite)
		{
			if (source == null)
			{
				throw new ArgumentNullException("source");
			}
			if (destinationFileName == null)
			{
				throw new ArgumentNullException("destinationFileName");
			}
			FileMode mode = ((!overwrite) ? FileMode.CreateNew : FileMode.Create);
			using (Stream destination = new FileStream(destinationFileName, mode, FileAccess.Write, FileShare.None, 4096, useAsync: false))
			{
				using Stream stream = source.Open();
				stream.CopyTo(destination);
			}
			File.SetLastWriteTime(destinationFileName, source.LastWriteTime.DateTime);
		}
	}
}

BepInExPack/mono/Managed/System.Memory.dll

Decompiled a month ago
using System;
using System.Buffers;
using System.Buffers.Binary;
using System.Buffers.Text;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyDefaultAlias("System.Memory")]
[assembly: AssemblyCompany("Microsoft Corporation")]
[assembly: AssemblyCopyright("© Microsoft Corporation. All rights reserved.")]
[assembly: AssemblyDescription("System.Memory")]
[assembly: AssemblyFileVersion("4.700.19.46205")]
[assembly: AssemblyInformationalVersion("4.7.0+a5b5f2e1e369972c8ff1e2183979fab6099f52ef")]
[assembly: AssemblyProduct("Microsoft® .NET Framework")]
[assembly: AssemblyTitle("System.Memory")]
[assembly: CLSCompliant(true)]
[assembly: AssemblyVersion("4.0.2.0")]
[assembly: TypeForwardedTo(typeof(BinaryPrimitives))]
[assembly: TypeForwardedTo(typeof(BuffersExtensions))]
[assembly: TypeForwardedTo(typeof(IBufferWriter<>))]
[assembly: TypeForwardedTo(typeof(IMemoryOwner<>))]
[assembly: TypeForwardedTo(typeof(IPinnable))]
[assembly: TypeForwardedTo(typeof(MemoryHandle))]
[assembly: TypeForwardedTo(typeof(MemoryManager<>))]
[assembly: TypeForwardedTo(typeof(MemoryPool<>))]
[assembly: TypeForwardedTo(typeof(OperationStatus))]
[assembly: TypeForwardedTo(typeof(ReadOnlySequence<>))]
[assembly: TypeForwardedTo(typeof(ReadOnlySequenceSegment<>))]
[assembly: TypeForwardedTo(typeof(StandardFormat))]
[assembly: TypeForwardedTo(typeof(Base64))]
[assembly: TypeForwardedTo(typeof(Utf8Formatter))]
[assembly: TypeForwardedTo(typeof(Utf8Parser))]
[assembly: TypeForwardedTo(typeof(Memory<>))]
[assembly: TypeForwardedTo(typeof(MemoryExtensions))]
[assembly: TypeForwardedTo(typeof(ReadOnlyMemory<>))]
[assembly: TypeForwardedTo(typeof(ReadOnlySpan<>))]
[assembly: TypeForwardedTo(typeof(MemoryMarshal))]
[assembly: TypeForwardedTo(typeof(SequenceMarshal))]
[assembly: TypeForwardedTo(typeof(SequencePosition))]
[assembly: TypeForwardedTo(typeof(Span<>))]

BepInExPack/mono/Managed/System.Net.Http.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Net.Cache;
using System.Net.Http.Headers;
using System.Net.Mail;
using System.Net.Security;
using System.Net.Sockets;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.Authentication;
using System.Security.Cryptography.X509Certificates;
using System.Security.Permissions;
using System.Security.Principal;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("System.Net.Http.dll")]
[assembly: AssemblyDescription("System.Net.Http.dll")]
[assembly: AssemblyDefaultAlias("System.Net.Http.dll")]
[assembly: AssemblyCompany("Mono development team")]
[assembly: AssemblyProduct("Mono Common Language Infrastructure")]
[assembly: AssemblyCopyright("(c) Various Mono authors")]
[assembly: SatelliteContractVersion("4.0.0.0")]
[assembly: AssemblyInformationalVersion("4.6.57.0")]
[assembly: AssemblyFileVersion("4.6.57.0")]
[assembly: NeutralResourcesLanguage("en-US")]
[assembly: CLSCompliant(true)]
[assembly: AssemblyDelaySign(true)]
[assembly: ComVisible(false)]
[assembly: InternalsVisibleTo("System.Net.Http.WebRequest, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("4.0.0.0")]
[module: UnverifiableCode]
namespace System.Net.Http
{
	internal static class CancellationHelper
	{
		private static readonly string s_cancellationMessage = new OperationCanceledException().Message;

		internal static bool ShouldWrapInOperationCanceledException(Exception exception, CancellationToken cancellationToken)
		{
			if (!(exception is OperationCanceledException))
			{
				return cancellationToken.IsCancellationRequested;
			}
			return false;
		}

		internal static Exception CreateOperationCanceledException(Exception innerException, CancellationToken cancellationToken)
		{
			return new TaskCanceledException(s_cancellationMessage, innerException, cancellationToken);
		}

		private static void ThrowOperationCanceledException(Exception innerException, CancellationToken cancellationToken)
		{
			throw CreateOperationCanceledException(innerException, cancellationToken);
		}

		internal static void ThrowIfCancellationRequested(CancellationToken cancellationToken)
		{
			if (cancellationToken.IsCancellationRequested)
			{
				ThrowOperationCanceledException(null, cancellationToken);
			}
		}
	}
	internal static class ConnectHelper
	{
		internal sealed class CertificateCallbackMapper
		{
			public readonly Func<HttpRequestMessage, X509Certificate2, X509Chain, SslPolicyErrors, bool> FromHttpClientHandler;

			public readonly RemoteCertificateValidationCallback ForSocketsHttpHandler;

			public CertificateCallbackMapper(Func<HttpRequestMessage, X509Certificate2, X509Chain, SslPolicyErrors, bool> fromHttpClientHandler)
			{
				FromHttpClientHandler = fromHttpClientHandler;
				ForSocketsHttpHandler = (object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) => FromHttpClientHandler(sender as HttpRequestMessage, certificate as X509Certificate2, chain, sslPolicyErrors);
			}
		}

		private sealed class ConnectEventArgs : SocketAsyncEventArgs
		{
			public AsyncTaskMethodBuilder Builder { get; private set; }

			public CancellationToken CancellationToken { get; private set; }

			public void Initialize(CancellationToken cancellationToken)
			{
				CancellationToken = cancellationToken;
				AsyncTaskMethodBuilder builder = default(AsyncTaskMethodBuilder);
				_ = builder.Task;
				Builder = builder;
			}

			public void Clear()
			{
				CancellationToken = default(CancellationToken);
			}

			protected override void OnCompleted(SocketAsyncEventArgs _)
			{
				switch (base.SocketError)
				{
				case SocketError.Success:
					Builder.SetResult();
					return;
				case SocketError.OperationAborted:
				case SocketError.ConnectionAborted:
					if (CancellationToken.IsCancellationRequested)
					{
						Builder.SetException(CancellationHelper.CreateOperationCanceledException(null, CancellationToken));
						return;
					}
					break;
				}
				Builder.SetException(new SocketException((int)base.SocketError));
			}
		}

		[StructLayout(LayoutKind.Auto)]
		[CompilerGenerated]
		private struct <ConnectAsync>d__2 : IAsyncStateMachine
		{
			public int <>1__state;

			public AsyncValueTaskMethodBuilder<(Socket, Stream)> <>t__builder;

			public CancellationToken cancellationToken;

			public string host;

			public int port;

			private ConnectEventArgs <saea>5__2;

			private CancellationTokenRegistration <>7__wrap2;

			private ConfiguredTaskAwaitable.ConfiguredTaskAwaiter <>u__1;

			private void MoveNext()
			{
				int num = <>1__state;
				(Socket, Stream) result;
				try
				{
					if (num != 0 && !s_connectEventArgs.TryDequeue(ref <saea>5__2))
					{
						<saea>5__2 = new ConnectEventArgs();
					}
					try
					{
						if (num != 0)
						{
							<saea>5__2.Initialize(cancellationToken);
							<saea>5__2.RemoteEndPoint = new DnsEndPoint(host, port);
							if (!Socket.ConnectAsync(SocketType.Stream, ProtocolType.Tcp, <saea>5__2))
							{
								if (<saea>5__2.SocketError != 0)
								{
									throw new SocketException((int)<saea>5__2.SocketError);
								}
								goto IL_015b;
							}
							<>7__wrap2 = cancellationToken.Register(delegate(object s)
							{
								Socket.CancelConnectAsync((SocketAsyncEventArgs)s);
							}, <saea>5__2);
						}
						try
						{
							ConfiguredTaskAwaitable.ConfiguredTaskAwaiter awaiter;
							if (num != 0)
							{
								awaiter = <saea>5__2.Builder.Task.ConfigureAwait(continueOnCapturedContext: false).GetAwaiter();
								if (!awaiter.IsCompleted)
								{
									num = (<>1__state = 0);
									<>u__1 = awaiter;
									<>t__builder.AwaitUnsafeOnCompleted<ConfiguredTaskAwaitable.ConfiguredTaskAwaiter, <ConnectAsync>d__2>(ref awaiter, ref this);
									return;
								}
							}
							else
							{
								awaiter = <>u__1;
								<>u__1 = default(ConfiguredTaskAwaitable.ConfiguredTaskAwaiter);
								num = (<>1__state = -1);
							}
							awaiter.GetResult();
						}
						finally
						{
							if (num < 0)
							{
								((IDisposable)<>7__wrap2).Dispose();
							}
						}
						<>7__wrap2 = default(CancellationTokenRegistration);
						goto IL_015b;
						IL_015b:
						Socket connectSocket = <saea>5__2.ConnectSocket;
						connectSocket.NoDelay = true;
						result = (connectSocket, new NetworkStream(connectSocket, ownsSocket: true));
					}
					catch (Exception ex)
					{
						throw CancellationHelper.ShouldWrapInOperationCanceledException(ex, cancellationToken) ? CancellationHelper.CreateOperationCanceledException(ex, cancellationToken) : new HttpRequestException(ex.Message, ex);
					}
					finally
					{
						if (num < 0)
						{
							<saea>5__2.Clear();
							if (!s_connectEventArgs.TryEnqueue(<saea>5__2))
							{
								<saea>5__2.Dispose();
							}
						}
					}
				}
				catch (Exception exception)
				{
					<>1__state = -2;
					<saea>5__2 = null;
					<>t__builder.SetException(exception);
					return;
				}
				<>1__state = -2;
				<saea>5__2 = null;
				<>t__builder.SetResult(result);
			}

			void IAsyncStateMachine.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				this.MoveNext();
			}

			[DebuggerHidden]
			private void SetStateMachine(IAsyncStateMachine stateMachine)
			{
				<>t__builder.SetStateMachine(stateMachine);
			}

			void IAsyncStateMachine.SetStateMachine(IAsyncStateMachine stateMachine)
			{
				//ILSpy generated this explicit interface implementation from .override directive in SetStateMachine
				this.SetStateMachine(stateMachine);
			}
		}

		[StructLayout(LayoutKind.Auto)]
		[CompilerGenerated]
		private struct <EstablishSslConnectionAsyncCore>d__5 : IAsyncStateMachine
		{
			public int <>1__state;

			public AsyncValueTaskMethodBuilder<SslStream> <>t__builder;

			public Stream stream;

			public CancellationToken cancellationToken;

			public SslClientAuthenticationOptions sslOptions;

			private SslStream <sslStream>5__2;

			private CancellationTokenRegistration <ctr>5__3;

			private ConfiguredTaskAwaitable.ConfiguredTaskAwaiter <>u__1;

			private void MoveNext()
			{
				int num = <>1__state;
				SslStream result;
				try
				{
					if (num != 0)
					{
						<sslStream>5__2 = new SslStream(stream);
						<ctr>5__3 = cancellationToken.Register(delegate(object s)
						{
							((Stream)s).Dispose();
						}, stream);
					}
					try
					{
						ConfiguredTaskAwaitable.ConfiguredTaskAwaiter awaiter;
						if (num != 0)
						{
							awaiter = <sslStream>5__2.AuthenticateAsClientAsync(sslOptions, cancellationToken).ConfigureAwait(continueOnCapturedContext: false).GetAwaiter();
							if (!awaiter.IsCompleted)
							{
								num = (<>1__state = 0);
								<>u__1 = awaiter;
								<>t__builder.AwaitUnsafeOnCompleted<ConfiguredTaskAwaitable.ConfiguredTaskAwaiter, <EstablishSslConnectionAsyncCore>d__5>(ref awaiter, ref this);
								return;
							}
						}
						else
						{
							awaiter = <>u__1;
							<>u__1 = default(ConfiguredTaskAwaitable.ConfiguredTaskAwaiter);
							num = (<>1__state = -1);
						}
						awaiter.GetResult();
					}
					catch (Exception ex)
					{
						<sslStream>5__2.Dispose();
						if (CancellationHelper.ShouldWrapInOperationCanceledException(ex, cancellationToken))
						{
							throw CancellationHelper.CreateOperationCanceledException(ex, cancellationToken);
						}
						throw new HttpRequestException("The SSL connection could not be established, see inner exception.", ex);
					}
					finally
					{
						if (num < 0)
						{
							<ctr>5__3.Dispose();
						}
					}
					if (cancellationToken.IsCancellationRequested)
					{
						<sslStream>5__2.Dispose();
						throw CancellationHelper.CreateOperationCanceledException(null, cancellationToken);
					}
					result = <sslStream>5__2;
				}
				catch (Exception exception)
				{
					<>1__state = -2;
					<sslStream>5__2 = null;
					<ctr>5__3 = default(CancellationTokenRegistration);
					<>t__builder.SetException(exception);
					return;
				}
				<>1__state = -2;
				<sslStream>5__2 = null;
				<ctr>5__3 = default(CancellationTokenRegistration);
				<>t__builder.SetResult(result);
			}

			void IAsyncStateMachine.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				this.MoveNext();
			}

			[DebuggerHidden]
			private void SetStateMachine(IAsyncStateMachine stateMachine)
			{
				<>t__builder.SetStateMachine(stateMachine);
			}

			void IAsyncStateMachine.SetStateMachine(IAsyncStateMachine stateMachine)
			{
				//ILSpy generated this explicit interface implementation from .override directive in SetStateMachine
				this.SetStateMachine(stateMachine);
			}
		}

		private static readonly Segment<ConnectEventArgs> s_connectEventArgs = new Segment<ConnectEventArgs>(Segment<ConnectEventArgs>.RoundUpToPowerOf2(Math.Max(2, Environment.ProcessorCount)));

		[AsyncStateMachine(typeof(<ConnectAsync>d__2))]
		public static ValueTask<(Socket, Stream)> ConnectAsync(string host, int port, CancellationToken cancellationToken)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			<ConnectAsync>d__2 <ConnectAsync>d__ = default(<ConnectAsync>d__2);
			<ConnectAsync>d__.host = host;
			<ConnectAsync>d__.port = port;
			<ConnectAsync>d__.cancellationToken = cancellationToken;
			<ConnectAsync>d__.<>t__builder = AsyncValueTaskMethodBuilder<(Socket, Stream)>.Create();
			<ConnectAsync>d__.<>1__state = -1;
			<ConnectAsync>d__.<>t__builder.Start<<ConnectAsync>d__2>(ref <ConnectAsync>d__);
			return <ConnectAsync>d__.<>t__builder.Task;
		}

		public static ValueTask<SslStream> EstablishSslConnectionAsync(SslClientAuthenticationOptions sslOptions, HttpRequestMessage request, Stream stream, CancellationToken cancellationToken)
		{
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			RemoteCertificateValidationCallback remoteCertificateValidationCallback = sslOptions.RemoteCertificateValidationCallback;
			if (remoteCertificateValidationCallback != null && remoteCertificateValidationCallback.Target is CertificateCallbackMapper certificateCallbackMapper)
			{
				sslOptions = SslClientAuthenticationOptionsExtensions.ShallowClone(sslOptions);
				Func<HttpRequestMessage, X509Certificate2, X509Chain, SslPolicyErrors, bool> localFromHttpClientHandler = certificateCallbackMapper.FromHttpClientHandler;
				HttpRequestMessage localRequest = request;
				sslOptions.RemoteCertificateValidationCallback = (object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) => localFromHttpClientHandler(localRequest, certificate as X509Certificate2, chain, sslPolicyErrors);
			}
			return EstablishSslConnectionAsyncCore(stream, sslOptions, cancellationToken);
		}

		[AsyncStateMachine(typeof(<EstablishSslConnectionAsyncCore>d__5))]
		private static ValueTask<SslStream> EstablishSslConnectionAsyncCore(Stream stream, SslClientAuthenticationOptions sslOptions, CancellationToken cancellationToken)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			<EstablishSslConnectionAsyncCore>d__5 <EstablishSslConnectionAsyncCore>d__ = default(<EstablishSslConnectionAsyncCore>d__5);
			<EstablishSslConnectionAsyncCore>d__.stream = stream;
			<EstablishSslConnectionAsyncCore>d__.sslOptions = sslOptions;
			<EstablishSslConnectionAsyncCore>d__.cancellationToken = cancellationToken;
			<EstablishSslConnectionAsyncCore>d__.<>t__builder = AsyncValueTaskMethodBuilder<SslStream>.Create();
			<EstablishSslConnectionAsyncCore>d__.<>1__state = -1;
			<EstablishSslConnectionAsyncCore>d__.<>t__builder.Start<<EstablishSslConnectionAsyncCore>d__5>(ref <EstablishSslConnectionAsyncCore>d__);
			return <EstablishSslConnectionAsyncCore>d__.<>t__builder.Task;
		}
	}
	public class HttpClientHandler : HttpMessageHandler
	{
		private readonly IMonoHttpClientHandler _delegatingHandler;

		private ClientCertificateOption _clientCertificateOptions;

		public static Func<HttpRequestMessage, X509Certificate2, X509Chain, SslPolicyErrors, bool> DangerousAcceptAnyServerCertificateValidator
		{
			get
			{
				throw new PlatformNotSupportedException();
			}
		}

		public virtual bool SupportsAutomaticDecompression => _delegatingHandler.SupportsAutomaticDecompression;

		public virtual bool SupportsProxy => true;

		public virtual bool SupportsRedirectConfiguration => true;

		public bool UseCookies
		{
			get
			{
				return _delegatingHandler.UseCookies;
			}
			set
			{
				_delegatingHandler.UseCookies = value;
			}
		}

		public CookieContainer CookieContainer
		{
			get
			{
				return _delegatingHandler.CookieContainer;
			}
			set
			{
				_delegatingHandler.CookieContainer = value;
			}
		}

		public ClientCertificateOption ClientCertificateOptions
		{
			get
			{
				return _clientCertificateOptions;
			}
			set
			{
				switch (value)
				{
				case ClientCertificateOption.Manual:
					ThrowForModifiedManagedSslOptionsIfStarted();
					_clientCertificateOptions = value;
					_delegatingHandler.SslOptions.LocalCertificateSelectionCallback = (object sender, string targetHost, X509CertificateCollection localCertificates, X509Certificate remoteCertificate, string[] acceptableIssuers) => CertificateHelper.GetEligibleClientCertificate(ClientCertificates);
					break;
				case ClientCertificateOption.Automatic:
					ThrowForModifiedManagedSslOptionsIfStarted();
					_clientCertificateOptions = value;
					_delegatingHandler.SslOptions.LocalCertificateSelectionCallback = (object sender, string targetHost, X509CertificateCollection localCertificates, X509Certificate remoteCertificate, string[] acceptableIssuers) => CertificateHelper.GetEligibleClientCertificate();
					break;
				default:
					throw new ArgumentOutOfRangeException("value");
				}
			}
		}

		public X509CertificateCollection ClientCertificates
		{
			get
			{
				if (ClientCertificateOptions != 0)
				{
					throw new InvalidOperationException(SR.Format("The {0} property must be set to '{1}' to use this property.", (object)"ClientCertificateOptions", (object)"Manual"));
				}
				return _delegatingHandler.SslOptions.ClientCertificates ?? (_delegatingHandler.SslOptions.ClientCertificates = new X509CertificateCollection());
			}
		}

		public Func<HttpRequestMessage, X509Certificate2, X509Chain, SslPolicyErrors, bool> ServerCertificateCustomValidationCallback
		{
			get
			{
				return (_delegatingHandler.SslOptions.RemoteCertificateValidationCallback?.Target as ConnectHelper.CertificateCallbackMapper)?.FromHttpClientHandler;
			}
			set
			{
				ThrowForModifiedManagedSslOptionsIfStarted();
				_delegatingHandler.SslOptions.RemoteCertificateValidationCallback = ((value != null) ? new ConnectHelper.CertificateCallbackMapper(value).ForSocketsHttpHandler : null);
			}
		}

		public bool CheckCertificateRevocationList
		{
			get
			{
				return _delegatingHandler.SslOptions.CertificateRevocationCheckMode == X509RevocationMode.Online;
			}
			set
			{
				ThrowForModifiedManagedSslOptionsIfStarted();
				_delegatingHandler.SslOptions.CertificateRevocationCheckMode = (value ? X509RevocationMode.Online : X509RevocationMode.NoCheck);
			}
		}

		public SslProtocols SslProtocols
		{
			get
			{
				return _delegatingHandler.SslOptions.EnabledSslProtocols;
			}
			set
			{
				ThrowForModifiedManagedSslOptionsIfStarted();
				_delegatingHandler.SslOptions.EnabledSslProtocols = value;
			}
		}

		public DecompressionMethods AutomaticDecompression
		{
			get
			{
				return _delegatingHandler.AutomaticDecompression;
			}
			set
			{
				_delegatingHandler.AutomaticDecompression = value;
			}
		}

		public bool UseProxy
		{
			get
			{
				return _delegatingHandler.UseProxy;
			}
			set
			{
				_delegatingHandler.UseProxy = value;
			}
		}

		public IWebProxy Proxy
		{
			get
			{
				return _delegatingHandler.Proxy;
			}
			set
			{
				_delegatingHandler.Proxy = value;
			}
		}

		public ICredentials DefaultProxyCredentials
		{
			get
			{
				return _delegatingHandler.DefaultProxyCredentials;
			}
			set
			{
				_delegatingHandler.DefaultProxyCredentials = value;
			}
		}

		public bool PreAuthenticate
		{
			get
			{
				return _delegatingHandler.PreAuthenticate;
			}
			set
			{
				_delegatingHandler.PreAuthenticate = value;
			}
		}

		public bool UseDefaultCredentials
		{
			get
			{
				return _delegatingHandler.Credentials == CredentialCache.DefaultCredentials;
			}
			set
			{
				if (value)
				{
					_delegatingHandler.Credentials = CredentialCache.DefaultCredentials;
				}
				else if (_delegatingHandler.Credentials == CredentialCache.DefaultCredentials)
				{
					_delegatingHandler.Credentials = null;
				}
			}
		}

		public ICredentials Credentials
		{
			get
			{
				return _delegatingHandler.Credentials;
			}
			set
			{
				_delegatingHandler.Credentials = value;
			}
		}

		public bool AllowAutoRedirect
		{
			get
			{
				return _delegatingHandler.AllowAutoRedirect;
			}
			set
			{
				_delegatingHandler.AllowAutoRedirect = value;
			}
		}

		public int MaxAutomaticRedirections
		{
			get
			{
				return _delegatingHandler.MaxAutomaticRedirections;
			}
			set
			{
				_delegatingHandler.MaxAutomaticRedirections = value;
			}
		}

		public int MaxConnectionsPerServer
		{
			get
			{
				return _delegatingHandler.MaxConnectionsPerServer;
			}
			set
			{
				_delegatingHandler.MaxConnectionsPerServer = value;
			}
		}

		public int MaxResponseHeadersLength
		{
			get
			{
				return _delegatingHandler.MaxResponseHeadersLength;
			}
			set
			{
				_delegatingHandler.MaxResponseHeadersLength = value;
			}
		}

		public long MaxRequestContentBufferSize
		{
			get
			{
				return _delegatingHandler.MaxRequestContentBufferSize;
			}
			set
			{
				_delegatingHandler.MaxRequestContentBufferSize = value;
			}
		}

		public IDictionary<string, object> Properties => _delegatingHandler.Properties;

		private static IMonoHttpClientHandler CreateDefaultHandler()
		{
			return new MonoWebRequestHandler();
		}

		public HttpClientHandler()
			: this(CreateDefaultHandler())
		{
		}

		internal HttpClientHandler(IMonoHttpClientHandler handler)
		{
			_delegatingHandler = handler;
			ClientCertificateOptions = ClientCertificateOption.Manual;
		}

		protected override void Dispose(bool disposing)
		{
			if (disposing)
			{
				_delegatingHandler.Dispose();
			}
			base.Dispose(disposing);
		}

		private void ThrowForModifiedManagedSslOptionsIfStarted()
		{
			_delegatingHandler.SslOptions = _delegatingHandler.SslOptions;
		}

		internal void SetWebRequestTimeout(TimeSpan timeout)
		{
			_delegatingHandler.SetWebRequestTimeout(timeout);
		}

		protected internal override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
		{
			return _delegatingHandler.SendAsync(request, cancellationToken);
		}
	}
	internal interface IMonoHttpClientHandler : IDisposable
	{
		bool SupportsAutomaticDecompression { get; }

		bool UseCookies { get; set; }

		CookieContainer CookieContainer { get; set; }

		SslClientAuthenticationOptions SslOptions { get; set; }

		DecompressionMethods AutomaticDecompression { get; set; }

		bool UseProxy { get; set; }

		IWebProxy Proxy { get; set; }

		ICredentials DefaultProxyCredentials { get; set; }

		bool PreAuthenticate { get; set; }

		ICredentials Credentials { get; set; }

		bool AllowAutoRedirect { get; set; }

		int MaxAutomaticRedirections { get; set; }

		int MaxConnectionsPerServer { get; set; }

		int MaxResponseHeadersLength { get; set; }

		long MaxRequestContentBufferSize { get; set; }

		IDictionary<string, object> Properties { get; }

		Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken);

		void SetWebRequestTimeout(TimeSpan timeout);
	}
	internal class MonoWebRequestHandler : IMonoHttpClientHandler, IDisposable
	{
		private static long groupCounter;

		private bool allowAutoRedirect;

		private DecompressionMethods automaticDecompression;

		private CookieContainer cookieContainer;

		private ICredentials credentials;

		private int maxAutomaticRedirections;

		private long maxRequestContentBufferSize;

		private bool preAuthenticate;

		private IWebProxy proxy;

		private bool useCookies;

		private bool useProxy;

		private SslClientAuthenticationOptions sslOptions;

		private bool allowPipelining;

		private RequestCachePolicy cachePolicy;

		private AuthenticationLevel authenticationLevel;

		private TimeSpan continueTimeout;

		private TokenImpersonationLevel impersonationLevel;

		private int maxResponseHeadersLength;

		private int readWriteTimeout;

		private RemoteCertificateValidationCallback serverCertificateValidationCallback;

		private bool unsafeAuthenticatedConnectionSharing;

		private bool sentRequest;

		private string connectionGroupName;

		private TimeSpan? timeout;

		private bool disposed;

		public bool AllowAutoRedirect
		{
			get
			{
				return allowAutoRedirect;
			}
			set
			{
				EnsureModifiability();
				allowAutoRedirect = value;
			}
		}

		public DecompressionMethods AutomaticDecompression
		{
			get
			{
				return automaticDecompression;
			}
			set
			{
				EnsureModifiability();
				automaticDecompression = value;
			}
		}

		public CookieContainer CookieContainer
		{
			get
			{
				return cookieContainer ?? (cookieContainer = new CookieContainer());
			}
			set
			{
				EnsureModifiability();
				cookieContainer = value;
			}
		}

		public ICredentials Credentials
		{
			get
			{
				return credentials;
			}
			set
			{
				EnsureModifiability();
				credentials = value;
			}
		}

		public int MaxAutomaticRedirections
		{
			get
			{
				return maxAutomaticRedirections;
			}
			set
			{
				EnsureModifiability();
				if (value <= 0)
				{
					throw new ArgumentOutOfRangeException();
				}
				maxAutomaticRedirections = value;
			}
		}

		public long MaxRequestContentBufferSize
		{
			get
			{
				return maxRequestContentBufferSize;
			}
			set
			{
				EnsureModifiability();
				if (value < 0)
				{
					throw new ArgumentOutOfRangeException();
				}
				maxRequestContentBufferSize = value;
			}
		}

		public bool PreAuthenticate
		{
			get
			{
				return preAuthenticate;
			}
			set
			{
				EnsureModifiability();
				preAuthenticate = value;
			}
		}

		public IWebProxy Proxy
		{
			get
			{
				return proxy;
			}
			set
			{
				EnsureModifiability();
				if (!UseProxy)
				{
					throw new InvalidOperationException();
				}
				proxy = value;
			}
		}

		public virtual bool SupportsAutomaticDecompression => true;

		public virtual bool SupportsProxy => true;

		public virtual bool SupportsRedirectConfiguration => true;

		public bool UseCookies
		{
			get
			{
				return useCookies;
			}
			set
			{
				EnsureModifiability();
				useCookies = value;
			}
		}

		public bool UseProxy
		{
			get
			{
				return useProxy;
			}
			set
			{
				EnsureModifiability();
				useProxy = value;
			}
		}

		public bool AllowPipelining
		{
			get
			{
				return allowPipelining;
			}
			set
			{
				EnsureModifiability();
				allowPipelining = value;
			}
		}

		public RequestCachePolicy CachePolicy
		{
			get
			{
				return cachePolicy;
			}
			set
			{
				EnsureModifiability();
				cachePolicy = value;
			}
		}

		public AuthenticationLevel AuthenticationLevel
		{
			get
			{
				return authenticationLevel;
			}
			set
			{
				EnsureModifiability();
				authenticationLevel = value;
			}
		}

		[MonoTODO]
		public TimeSpan ContinueTimeout
		{
			get
			{
				return continueTimeout;
			}
			set
			{
				EnsureModifiability();
				continueTimeout = value;
			}
		}

		public TokenImpersonationLevel ImpersonationLevel
		{
			get
			{
				return impersonationLevel;
			}
			set
			{
				EnsureModifiability();
				impersonationLevel = value;
			}
		}

		public int MaxResponseHeadersLength
		{
			get
			{
				return maxResponseHeadersLength;
			}
			set
			{
				EnsureModifiability();
				maxResponseHeadersLength = value;
			}
		}

		public int ReadWriteTimeout
		{
			get
			{
				return readWriteTimeout;
			}
			set
			{
				EnsureModifiability();
				readWriteTimeout = value;
			}
		}

		public RemoteCertificateValidationCallback ServerCertificateValidationCallback
		{
			get
			{
				return serverCertificateValidationCallback;
			}
			set
			{
				EnsureModifiability();
				serverCertificateValidationCallback = value;
			}
		}

		public bool UnsafeAuthenticatedConnectionSharing
		{
			get
			{
				return unsafeAuthenticatedConnectionSharing;
			}
			set
			{
				EnsureModifiability();
				unsafeAuthenticatedConnectionSharing = value;
			}
		}

		public SslClientAuthenticationOptions SslOptions
		{
			get
			{
				//IL_000b: 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_0012: Expected O, but got Unknown
				//IL_0017: Expected O, but got Unknown
				SslClientAuthenticationOptions obj = sslOptions;
				if (obj == null)
				{
					SslClientAuthenticationOptions val = new SslClientAuthenticationOptions();
					SslClientAuthenticationOptions val2 = val;
					sslOptions = val;
					obj = val2;
				}
				return obj;
			}
			set
			{
				EnsureModifiability();
				sslOptions = value;
			}
		}

		public ICredentials DefaultProxyCredentials
		{
			get
			{
				throw new NotImplementedException();
			}
			set
			{
				throw new NotImplementedException();
			}
		}

		public int MaxConnectionsPerServer
		{
			get
			{
				throw new NotImplementedException();
			}
			set
			{
				throw new NotImplementedException();
			}
		}

		public IDictionary<string, object> Properties
		{
			get
			{
				throw new NotImplementedException();
			}
		}

		public MonoWebRequestHandler()
		{
			allowAutoRedirect = true;
			maxAutomaticRedirections = 50;
			maxRequestContentBufferSize = 2147483647L;
			useCookies = true;
			useProxy = true;
			allowPipelining = true;
			authenticationLevel = AuthenticationLevel.MutualAuthRequested;
			cachePolicy = WebRequest.DefaultCachePolicy;
			continueTimeout = TimeSpan.FromMilliseconds(350.0);
			impersonationLevel = TokenImpersonationLevel.Delegation;
			maxResponseHeadersLength = HttpWebRequest.DefaultMaximumResponseHeadersLength;
			readWriteTimeout = 300000;
			serverCertificateValidationCallback = null;
			unsafeAuthenticatedConnectionSharing = false;
			connectionGroupName = "HttpClientHandler" + Interlocked.Increment(ref groupCounter);
		}

		internal void EnsureModifiability()
		{
			if (sentRequest)
			{
				throw new InvalidOperationException("This instance has already started one or more requests. Properties can only be modified before sending the first request.");
			}
		}

		public void Dispose()
		{
			Dispose(disposing: true);
		}

		protected virtual void Dispose(bool disposing)
		{
			if (disposing && !disposed)
			{
				Volatile.Write(ref disposed, value: true);
				ServicePointManager.CloseConnectionGroup(connectionGroupName);
			}
		}

		private bool GetConnectionKeepAlive(HttpRequestHeaders headers)
		{
			return headers.Connection.Any((string l) => string.Equals(l, "Keep-Alive", StringComparison.OrdinalIgnoreCase));
		}

		internal virtual HttpWebRequest CreateWebRequest(HttpRequestMessage request)
		{
			HttpWebRequest httpWebRequest = new HttpWebRequest(request.RequestUri);
			httpWebRequest.ThrowOnError = false;
			httpWebRequest.AllowWriteStreamBuffering = false;
			if (request.Version == HttpVersion.Version20)
			{
				httpWebRequest.ProtocolVersion = HttpVersion.Version11;
			}
			else
			{
				httpWebRequest.ProtocolVersion = request.Version;
			}
			httpWebRequest.ConnectionGroupName = connectionGroupName;
			httpWebRequest.Method = request.Method.Method;
			if (httpWebRequest.ProtocolVersion == HttpVersion.Version10)
			{
				httpWebRequest.KeepAlive = GetConnectionKeepAlive(request.Headers);
			}
			else
			{
				httpWebRequest.KeepAlive = request.Headers.ConnectionClose != true;
			}
			if (allowAutoRedirect)
			{
				httpWebRequest.AllowAutoRedirect = true;
				httpWebRequest.MaximumAutomaticRedirections = maxAutomaticRedirections;
			}
			else
			{
				httpWebRequest.AllowAutoRedirect = false;
			}
			httpWebRequest.AutomaticDecompression = automaticDecompression;
			httpWebRequest.PreAuthenticate = preAuthenticate;
			if (useCookies)
			{
				httpWebRequest.CookieContainer = CookieContainer;
			}
			httpWebRequest.Credentials = credentials;
			if (useProxy)
			{
				httpWebRequest.Proxy = proxy;
			}
			else
			{
				httpWebRequest.Proxy = null;
			}
			httpWebRequest.ServicePoint.Expect100Continue = request.Headers.ExpectContinue == true;
			if (timeout.HasValue)
			{
				httpWebRequest.Timeout = (int)timeout.Value.TotalMilliseconds;
			}
			WebHeaderCollection headers = httpWebRequest.Headers;
			foreach (KeyValuePair<string, IEnumerable<string>> header in request.Headers)
			{
				IEnumerable<string> enumerable = header.Value;
				if (header.Key == "Host")
				{
					httpWebRequest.Host = request.Headers.Host;
					continue;
				}
				if (header.Key == "Transfer-Encoding")
				{
					enumerable = enumerable.Where((string l) => l != "chunked");
				}
				string singleHeaderString = PlatformHelper.GetSingleHeaderString(header.Key, enumerable);
				if (singleHeaderString != null)
				{
					headers.AddInternal(header.Key, singleHeaderString);
				}
			}
			return httpWebRequest;
		}

		private HttpResponseMessage CreateResponseMessage(HttpWebResponse wr, HttpRequestMessage requestMessage, CancellationToken cancellationToken)
		{
			HttpResponseMessage httpResponseMessage = new HttpResponseMessage(wr.StatusCode);
			httpResponseMessage.RequestMessage = requestMessage;
			httpResponseMessage.ReasonPhrase = wr.StatusDescription;
			httpResponseMessage.Content = PlatformHelper.CreateStreamContent(wr.GetResponseStream(), cancellationToken);
			WebHeaderCollection headers = wr.Headers;
			for (int i = 0; i < headers.Count; i++)
			{
				string key = headers.GetKey(i);
				string[] values = headers.GetValues(i);
				HttpHeaders httpHeaders = ((!PlatformHelper.IsContentHeader(key)) ? ((HttpHeaders)httpResponseMessage.Headers) : ((HttpHeaders)httpResponseMessage.Content.Headers));
				httpHeaders.TryAddWithoutValidation(key, values);
			}
			requestMessage.RequestUri = wr.ResponseUri;
			return httpResponseMessage;
		}

		private static bool MethodHasBody(HttpMethod method)
		{
			switch (method.Method)
			{
			case "HEAD":
			case "GET":
			case "MKCOL":
			case "CONNECT":
			case "TRACE":
				return false;
			default:
				return true;
			}
		}

		public async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
		{
			if (disposed)
			{
				throw new ObjectDisposedException(GetType().ToString());
			}
			Volatile.Write(ref sentRequest, value: true);
			HttpWebRequest wrequest = CreateWebRequest(request);
			HttpWebResponse wresponse = null;
			try
			{
				using (cancellationToken.Register(delegate(object l)
				{
					((HttpWebRequest)l).Abort();
				}, wrequest))
				{
					HttpContent content = request.Content;
					if (content != null)
					{
						WebHeaderCollection headers = wrequest.Headers;
						foreach (KeyValuePair<string, IEnumerable<string>> header in content.Headers)
						{
							foreach (string item in header.Value)
							{
								headers.AddInternal(header.Key, item);
							}
						}
						if (request.Headers.TransferEncodingChunked == true)
						{
							wrequest.SendChunked = true;
						}
						else
						{
							long? contentLength = content.Headers.ContentLength;
							if (contentLength.HasValue)
							{
								wrequest.ContentLength = contentLength.Value;
							}
							else
							{
								if (MaxRequestContentBufferSize == 0L)
								{
									throw new InvalidOperationException("The content length of the request content can't be determined. Either set TransferEncodingChunked to true, load content into buffer, or set MaxRequestContentBufferSize.");
								}
								await content.LoadIntoBufferAsync(MaxRequestContentBufferSize).ConfigureAwait(continueOnCapturedContext: false);
								wrequest.ContentLength = content.Headers.ContentLength.Value;
							}
						}
						wrequest.ResendContentFactory = content.CopyToAsync;
						using Stream stream = await wrequest.GetRequestStreamAsync().ConfigureAwait(continueOnCapturedContext: false);
						await request.Content.CopyToAsync(stream).ConfigureAwait(continueOnCapturedContext: false);
					}
					else if (MethodHasBody(request.Method))
					{
						wrequest.ContentLength = 0L;
					}
					wresponse = (HttpWebResponse)(await wrequest.GetResponseAsync().ConfigureAwait(continueOnCapturedContext: false));
				}
			}
			catch (WebException ex)
			{
				if (ex.Status != WebExceptionStatus.RequestCanceled)
				{
					throw new HttpRequestException("An error occurred while sending the request", ex);
				}
			}
			catch (IOException inner)
			{
				throw new HttpRequestException("An error occurred while sending the request", inner);
			}
			if (cancellationToken.IsCancellationRequested)
			{
				TaskCompletionSource<HttpResponseMessage> taskCompletionSource = new TaskCompletionSource<HttpResponseMessage>();
				taskCompletionSource.SetCanceled();
				return await taskCompletionSource.Task;
			}
			return CreateResponseMessage(wresponse, request, cancellationToken);
		}

		void IMonoHttpClientHandler.SetWebRequestTimeout(TimeSpan timeout)
		{
			this.timeout = timeout;
		}
	}
	internal static class PlatformHelper
	{
		internal static bool IsContentHeader(string name)
		{
			return HttpHeaders.GetKnownHeaderKind(name) == HttpHeaderKind.Content;
		}

		internal static string GetSingleHeaderString(string name, IEnumerable<string> values)
		{
			return HttpHeaders.GetSingleHeaderString(name, values);
		}

		internal static StreamContent CreateStreamContent(Stream stream, CancellationToken cancellationToken)
		{
			return new StreamContent(stream, cancellationToken);
		}
	}
	public class ByteArrayContent : HttpContent
	{
		private readonly byte[] content;

		private readonly int offset;

		private readonly int count;

		public ByteArrayContent(byte[] content)
		{
			if (content == null)
			{
				throw new ArgumentNullException("content");
			}
			this.content = content;
			count = content.Length;
		}

		public ByteArrayContent(byte[] content, int offset, int count)
			: this(content)
		{
			if (offset < 0 || offset > this.count)
			{
				throw new ArgumentOutOfRangeException("offset");
			}
			if (count < 0 || count > this.count - offset)
			{
				throw new ArgumentOutOfRangeException("count");
			}
			this.offset = offset;
			this.count = count;
		}

		protected override Task<Stream> CreateContentReadStreamAsync()
		{
			return Task.FromResult((Stream)new MemoryStream(content, offset, count));
		}

		protected override Task SerializeToStreamAsync(Stream stream, TransportContext context)
		{
			return stream.WriteAsync(content, offset, count);
		}

		protected internal override bool TryComputeLength(out long length)
		{
			length = count;
			return true;
		}
	}
	public enum ClientCertificateOption
	{
		Manual,
		Automatic
	}
	public abstract class DelegatingHandler : HttpMessageHandler
	{
		private bool disposed;

		private HttpMessageHandler handler;

		public HttpMessageHandler InnerHandler
		{
			get
			{
				return handler;
			}
			set
			{
				if (value == null)
				{
					throw new ArgumentNullException("InnerHandler");
				}
				handler = value;
			}
		}

		protected DelegatingHandler()
		{
		}

		protected DelegatingHandler(HttpMessageHandler innerHandler)
		{
			if (innerHandler == null)
			{
				throw new ArgumentNullException("innerHandler");
			}
			InnerHandler = innerHandler;
		}

		protected override void Dispose(bool disposing)
		{
			if (disposing && !disposed)
			{
				disposed = true;
				if (InnerHandler != null)
				{
					InnerHandler.Dispose();
				}
			}
			base.Dispose(disposing);
		}

		protected internal override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
		{
			if (InnerHandler == null)
			{
				throw new InvalidOperationException("The inner handler has not been assigned.");
			}
			return InnerHandler.SendAsync(request, cancellationToken);
		}
	}
	public class FormUrlEncodedContent : ByteArrayContent
	{
		public FormUrlEncodedContent(IEnumerable<KeyValuePair<string, string>> nameValueCollection)
			: base(EncodeContent(nameValueCollection))
		{
			base.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded");
		}

		private static byte[] EncodeContent(IEnumerable<KeyValuePair<string, string>> nameValueCollection)
		{
			if (nameValueCollection == null)
			{
				throw new ArgumentNullException("nameValueCollection");
			}
			List<byte> list = new List<byte>();
			foreach (KeyValuePair<string, string> item in nameValueCollection)
			{
				if (list.Count != 0)
				{
					list.Add(38);
				}
				byte[] array = SerializeValue(item.Key);
				if (array != null)
				{
					list.AddRange(array);
				}
				list.Add(61);
				array = SerializeValue(item.Value);
				if (array != null)
				{
					list.AddRange(array);
				}
			}
			return list.ToArray();
		}

		private static byte[] SerializeValue(string value)
		{
			if (value == null)
			{
				return null;
			}
			value = Uri.EscapeDataString(value).Replace("%20", "+");
			return Encoding.ASCII.GetBytes(value);
		}
	}
	public class HttpClient : HttpMessageInvoker
	{
		private static readonly TimeSpan TimeoutDefault = TimeSpan.FromSeconds(100.0);

		private Uri base_address;

		private CancellationTokenSource cts;

		private bool disposed;

		private HttpRequestHeaders headers;

		private long buffer_size;

		private TimeSpan timeout;

		public Uri BaseAddress
		{
			get
			{
				return base_address;
			}
			set
			{
				base_address = value;
			}
		}

		public HttpRequestHeaders DefaultRequestHeaders => headers ?? (headers = new HttpRequestHeaders());

		public long MaxResponseContentBufferSize
		{
			get
			{
				return buffer_size;
			}
			set
			{
				if (value <= 0)
				{
					throw new ArgumentOutOfRangeException();
				}
				buffer_size = value;
			}
		}

		public TimeSpan Timeout
		{
			get
			{
				return timeout;
			}
			set
			{
				if (value != System.Threading.Timeout.InfiniteTimeSpan && (value <= TimeSpan.Zero || value.TotalMilliseconds > 2147483647.0))
				{
					throw new ArgumentOutOfRangeException();
				}
				timeout = value;
			}
		}

		public HttpClient()
			: this(new HttpClientHandler(), disposeHandler: true)
		{
		}

		public HttpClient(HttpMessageHandler handler)
			: this(handler, disposeHandler: true)
		{
		}

		public HttpClient(HttpMessageHandler handler, bool disposeHandler)
			: base(handler, disposeHandler)
		{
			buffer_size = 2147483647L;
			timeout = TimeoutDefault;
			cts = new CancellationTokenSource();
		}

		public void CancelPendingRequests()
		{
			using CancellationTokenSource cancellationTokenSource = Interlocked.Exchange(ref cts, new CancellationTokenSource());
			cancellationTokenSource.Cancel();
		}

		protected override void Dispose(bool disposing)
		{
			if (disposing && !disposed)
			{
				disposed = true;
				cts.Cancel();
				cts.Dispose();
			}
			base.Dispose(disposing);
		}

		public Task<HttpResponseMessage> DeleteAsync(string requestUri)
		{
			return SendAsync(new HttpRequestMessage(HttpMethod.Delete, requestUri));
		}

		public Task<HttpResponseMessage> DeleteAsync(string requestUri, CancellationToken cancellationToken)
		{
			return SendAsync(new HttpRequestMessage(HttpMethod.Delete, requestUri), cancellationToken);
		}

		public Task<HttpResponseMessage> DeleteAsync(Uri requestUri)
		{
			return SendAsync(new HttpRequestMessage(HttpMethod.Delete, requestUri));
		}

		public Task<HttpResponseMessage> DeleteAsync(Uri requestUri, CancellationToken cancellationToken)
		{
			return SendAsync(new HttpRequestMessage(HttpMethod.Delete, requestUri), cancellationToken);
		}

		public Task<HttpResponseMessage> GetAsync(string requestUri)
		{
			return SendAsync(new HttpRequestMessage(HttpMethod.Get, requestUri));
		}

		public Task<HttpResponseMessage> GetAsync(string requestUri, CancellationToken cancellationToken)
		{
			return SendAsync(new HttpRequestMessage(HttpMethod.Get, requestUri), cancellationToken);
		}

		public Task<HttpResponseMessage> GetAsync(string requestUri, HttpCompletionOption completionOption)
		{
			return SendAsync(new HttpRequestMessage(HttpMethod.Get, requestUri), completionOption);
		}

		public Task<HttpResponseMessage> GetAsync(string requestUri, HttpCompletionOption completionOption, CancellationToken cancellationToken)
		{
			return SendAsync(new HttpRequestMessage(HttpMethod.Get, requestUri), completionOption, cancellationToken);
		}

		public Task<HttpResponseMessage> GetAsync(Uri requestUri)
		{
			return SendAsync(new HttpRequestMessage(HttpMethod.Get, requestUri));
		}

		public Task<HttpResponseMessage> GetAsync(Uri requestUri, CancellationToken cancellationToken)
		{
			return SendAsync(new HttpRequestMessage(HttpMethod.Get, requestUri), cancellationToken);
		}

		public Task<HttpResponseMessage> GetAsync(Uri requestUri, HttpCompletionOption completionOption)
		{
			return SendAsync(new HttpRequestMessage(HttpMethod.Get, requestUri), completionOption);
		}

		public Task<HttpResponseMessage> GetAsync(Uri requestUri, HttpCompletionOption completionOption, CancellationToken cancellationToken)
		{
			return SendAsync(new HttpRequestMessage(HttpMethod.Get, requestUri), completionOption, cancellationToken);
		}

		public Task<HttpResponseMessage> PostAsync(string requestUri, HttpContent content)
		{
			return SendAsync(new HttpRequestMessage(HttpMethod.Post, requestUri)
			{
				Content = content
			});
		}

		public Task<HttpResponseMessage> PostAsync(string requestUri, HttpContent content, CancellationToken cancellationToken)
		{
			return SendAsync(new HttpRequestMessage(HttpMethod.Post, requestUri)
			{
				Content = content
			}, cancellationToken);
		}

		public Task<HttpResponseMessage> PostAsync(Uri requestUri, HttpContent content)
		{
			return SendAsync(new HttpRequestMessage(HttpMethod.Post, requestUri)
			{
				Content = content
			});
		}

		public Task<HttpResponseMessage> PostAsync(Uri requestUri, HttpContent content, CancellationToken cancellationToken)
		{
			return SendAsync(new HttpRequestMessage(HttpMethod.Post, requestUri)
			{
				Content = content
			}, cancellationToken);
		}

		public Task<HttpResponseMessage> PutAsync(Uri requestUri, HttpContent content)
		{
			return SendAsync(new HttpRequestMessage(HttpMethod.Put, requestUri)
			{
				Content = content
			});
		}

		public Task<HttpResponseMessage> PutAsync(Uri requestUri, HttpContent content, CancellationToken cancellationToken)
		{
			return SendAsync(new HttpRequestMessage(HttpMethod.Put, requestUri)
			{
				Content = content
			}, cancellationToken);
		}

		public Task<HttpResponseMessage> PutAsync(string requestUri, HttpContent content)
		{
			return SendAsync(new HttpRequestMessage(HttpMethod.Put, requestUri)
			{
				Content = content
			});
		}

		public Task<HttpResponseMessage> PutAsync(string requestUri, HttpContent content, CancellationToken cancellationToken)
		{
			return SendAsync(new HttpRequestMessage(HttpMethod.Put, requestUri)
			{
				Content = content
			}, cancellationToken);
		}

		public Task<HttpResponseMessage> SendAsync(HttpRequestMessage request)
		{
			return SendAsync(request, HttpCompletionOption.ResponseContentRead, CancellationToken.None);
		}

		public Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, HttpCompletionOption completionOption)
		{
			return SendAsync(request, completionOption, CancellationToken.None);
		}

		public override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
		{
			return SendAsync(request, HttpCompletionOption.ResponseContentRead, cancellationToken);
		}

		public Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationToken cancellationToken)
		{
			if (request == null)
			{
				throw new ArgumentNullException("request");
			}
			if (request.SetIsUsed())
			{
				throw new InvalidOperationException("Cannot send the same request message multiple times");
			}
			Uri requestUri = request.RequestUri;
			if (requestUri == null)
			{
				if (base_address == null)
				{
					throw new InvalidOperationException("The request URI must either be an absolute URI or BaseAddress must be set");
				}
				request.RequestUri = base_address;
			}
			else if (!requestUri.IsAbsoluteUri || (requestUri.Scheme == Uri.UriSchemeFile && requestUri.OriginalString.StartsWith("/", StringComparison.Ordinal)))
			{
				if (base_address == null)
				{
					throw new InvalidOperationException("The request URI must either be an absolute URI or BaseAddress must be set");
				}
				request.RequestUri = new Uri(base_address, requestUri);
			}
			if (headers != null)
			{
				request.Headers.AddHeaders(headers);
			}
			return SendAsyncWorker(request, completionOption, cancellationToken);
		}

		private async Task<HttpResponseMessage> SendAsyncWorker(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationToken cancellationToken)
		{
			using CancellationTokenSource lcts = CancellationTokenSource.CreateLinkedTokenSource(cts.Token, cancellationToken);
			if (handler is HttpClientHandler httpClientHandler)
			{
				httpClientHandler.SetWebRequestTimeout(timeout);
			}
			lcts.CancelAfter(timeout);
			HttpResponseMessage response = await (base.SendAsync(request, lcts.Token) ?? throw new InvalidOperationException("Handler failed to return a value")).ConfigureAwait(continueOnCapturedContext: false);
			if (response == null)
			{
				throw new InvalidOperationException("Handler failed to return a response");
			}
			if (response.Content != null && (completionOption & HttpCompletionOption.ResponseHeadersRead) == 0)
			{
				await response.Content.LoadIntoBufferAsync(MaxResponseContentBufferSize).ConfigureAwait(continueOnCapturedContext: false);
			}
			return response;
		}

		public async Task<byte[]> GetByteArrayAsync(string requestUri)
		{
			using HttpResponseMessage resp = await GetAsync(requestUri, HttpCompletionOption.ResponseContentRead).ConfigureAwait(continueOnCapturedContext: false);
			resp.EnsureSuccessStatusCode();
			return await resp.Content.ReadAsByteArrayAsync().ConfigureAwait(continueOnCapturedContext: false);
		}

		public async Task<byte[]> GetByteArrayAsync(Uri requestUri)
		{
			using HttpResponseMessage resp = await GetAsync(requestUri, HttpCompletionOption.ResponseContentRead).ConfigureAwait(continueOnCapturedContext: false);
			resp.EnsureSuccessStatusCode();
			return await resp.Content.ReadAsByteArrayAsync().ConfigureAwait(continueOnCapturedContext: false);
		}

		public async Task<Stream> GetStreamAsync(string requestUri)
		{
			HttpResponseMessage obj = await GetAsync(requestUri, HttpCompletionOption.ResponseHeadersRead).ConfigureAwait(continueOnCapturedContext: false);
			obj.EnsureSuccessStatusCode();
			return await obj.Content.ReadAsStreamAsync().ConfigureAwait(continueOnCapturedContext: false);
		}

		public async Task<Stream> GetStreamAsync(Uri requestUri)
		{
			HttpResponseMessage obj = await GetAsync(requestUri, HttpCompletionOption.ResponseHeadersRead).ConfigureAwait(continueOnCapturedContext: false);
			obj.EnsureSuccessStatusCode();
			return await obj.Content.ReadAsStreamAsync().ConfigureAwait(continueOnCapturedContext: false);
		}

		public async Task<string> GetStringAsync(string requestUri)
		{
			using HttpResponseMessage resp = await GetAsync(requestUri, HttpCompletionOption.ResponseContentRead).ConfigureAwait(continueOnCapturedContext: false);
			resp.EnsureSuccessStatusCode();
			return await resp.Content.ReadAsStringAsync().ConfigureAwait(continueOnCapturedContext: false);
		}

		public async Task<string> GetStringAsync(Uri requestUri)
		{
			using HttpResponseMessage resp = await GetAsync(requestUri, HttpCompletionOption.ResponseContentRead).ConfigureAwait(continueOnCapturedContext: false);
			resp.EnsureSuccessStatusCode();
			return await resp.Content.ReadAsStringAsync().ConfigureAwait(continueOnCapturedContext: false);
		}

		public Task<HttpResponseMessage> PatchAsync(string requestUri, HttpContent content)
		{
			throw new PlatformNotSupportedException();
		}

		public Task<HttpResponseMessage> PatchAsync(string requestUri, HttpContent content, CancellationToken cancellationToken)
		{
			throw new PlatformNotSupportedException();
		}

		public Task<HttpResponseMessage> PatchAsync(Uri requestUri, HttpContent content)
		{
			throw new PlatformNotSupportedException();
		}

		public Task<HttpResponseMessage> PatchAsync(Uri requestUri, HttpContent content, CancellationToken cancellationToken)
		{
			throw new PlatformNotSupportedException();
		}
	}
	public enum HttpCompletionOption
	{
		ResponseContentRead,
		ResponseHeadersRead
	}
	public abstract class HttpContent : IDisposable
	{
		private sealed class FixedMemoryStream : MemoryStream
		{
			private readonly long maxSize;

			public FixedMemoryStream(long maxSize)
			{
				this.maxSize = maxSize;
			}

			private void CheckOverflow(int count)
			{
				if (Length + count > maxSize)
				{
					throw new HttpRequestException($"Cannot write more bytes to the buffer than the configured maximum buffer size: {maxSize}");
				}
			}

			public override void WriteByte(byte value)
			{
				CheckOverflow(1);
				base.WriteByte(value);
			}

			public override void Write(byte[] buffer, int offset, int count)
			{
				CheckOverflow(count);
				base.Write(buffer, offset, count);
			}
		}

		private FixedMemoryStream buffer;

		private Stream stream;

		private bool disposed;

		private HttpContentHeaders headers;

		public HttpContentHeaders Headers => headers ?? (headers = new HttpContentHeaders(this));

		internal long? LoadedBufferLength
		{
			get
			{
				if (buffer != null)
				{
					return buffer.Length;
				}
				return null;
			}
		}

		internal void CopyTo(Stream stream)
		{
			CopyToAsync(stream).Wait();
		}

		public Task CopyToAsync(Stream stream)
		{
			return CopyToAsync(stream, null);
		}

		public Task CopyToAsync(Stream stream, TransportContext context)
		{
			if (stream == null)
			{
				throw new ArgumentNullException("stream");
			}
			if (buffer != null)
			{
				return buffer.CopyToAsync(stream);
			}
			return SerializeToStreamAsync(stream, context);
		}

		protected virtual async Task<Stream> CreateContentReadStreamAsync()
		{
			await LoadIntoBufferAsync().ConfigureAwait(continueOnCapturedContext: false);
			return buffer;
		}

		private static FixedMemoryStream CreateFixedMemoryStream(long maxBufferSize)
		{
			return new FixedMemoryStream(maxBufferSize);
		}

		public void Dispose()
		{
			Dispose(disposing: true);
		}

		protected virtual void Dispose(bool disposing)
		{
			if (disposing && !disposed)
			{
				disposed = true;
				if (buffer != null)
				{
					buffer.Dispose();
				}
			}
		}

		public Task LoadIntoBufferAsync()
		{
			return LoadIntoBufferAsync(2147483647L);
		}

		public async Task LoadIntoBufferAsync(long maxBufferSize)
		{
			if (disposed)
			{
				throw new ObjectDisposedException(GetType().ToString());
			}
			if (buffer == null)
			{
				buffer = CreateFixedMemoryStream(maxBufferSize);
				await SerializeToStreamAsync(buffer, null).ConfigureAwait(continueOnCapturedContext: false);
				buffer.Seek(0L, SeekOrigin.Begin);
			}
		}

		public async Task<Stream> ReadAsStreamAsync()
		{
			if (disposed)
			{
				throw new ObjectDisposedException(GetType().ToString());
			}
			if (buffer != null)
			{
				return new MemoryStream(buffer.GetBuffer(), 0, (int)buffer.Length, writable: false);
			}
			if (stream == null)
			{
				stream = await CreateContentReadStreamAsync().ConfigureAwait(continueOnCapturedContext: false);
			}
			return stream;
		}

		public async Task<byte[]> ReadAsByteArrayAsync()
		{
			await LoadIntoBufferAsync().ConfigureAwait(continueOnCapturedContext: false);
			return buffer.ToArray();
		}

		public async Task<string> ReadAsStringAsync()
		{
			await LoadIntoBufferAsync().ConfigureAwait(continueOnCapturedContext: false);
			if (buffer.Length == 0L)
			{
				return string.Empty;
			}
			byte[] array = buffer.GetBuffer();
			int num = (int)buffer.Length;
			int preambleLength = 0;
			Encoding encoding;
			if (headers != null && headers.ContentType != null && headers.ContentType.CharSet != null)
			{
				encoding = Encoding.GetEncoding(headers.ContentType.CharSet);
				preambleLength = StartsWith(array, num, encoding.GetPreamble());
			}
			else
			{
				encoding = GetEncodingFromBuffer(array, num, ref preambleLength) ?? Encoding.UTF8;
			}
			return encoding.GetString(array, preambleLength, num - preambleLength);
		}

		private static Encoding GetEncodingFromBuffer(byte[] buffer, int length, ref int preambleLength)
		{
			Encoding[] array = new Encoding[3]
			{
				Encoding.UTF8,
				Encoding.UTF32,
				Encoding.Unicode
			};
			foreach (Encoding encoding in array)
			{
				if ((preambleLength = StartsWith(buffer, length, encoding.GetPreamble())) != 0)
				{
					return encoding;
				}
			}
			return null;
		}

		private static int StartsWith(byte[] array, int length, byte[] value)
		{
			if (length < value.Length)
			{
				return 0;
			}
			for (int i = 0; i < value.Length; i++)
			{
				if (array[i] != value[i])
				{
					return 0;
				}
			}
			return value.Length;
		}

		internal Task SerializeToStreamAsync_internal(Stream stream, TransportContext context)
		{
			return SerializeToStreamAsync(stream, context);
		}

		protected abstract Task SerializeToStreamAsync(Stream stream, TransportContext context);

		protected internal abstract bool TryComputeLength(out long length);
	}
	public abstract class HttpMessageHandler : IDisposable
	{
		public void Dispose()
		{
			Dispose(disposing: true);
		}

		protected virtual void Dispose(bool disposing)
		{
		}

		protected internal abstract Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken);
	}
	public class HttpMessageInvoker : IDisposable
	{
		private protected HttpMessageHandler handler;

		private readonly bool disposeHandler;

		public HttpMessageInvoker(HttpMessageHandler handler)
			: this(handler, disposeHandler: true)
		{
		}

		public HttpMessageInvoker(HttpMessageHandler handler, bool disposeHandler)
		{
			if (handler == null)
			{
				throw new ArgumentNullException("handler");
			}
			this.handler = handler;
			this.disposeHandler = disposeHandler;
		}

		public void Dispose()
		{
			Dispose(disposing: true);
		}

		protected virtual void Dispose(bool disposing)
		{
			if (disposing && disposeHandler && handler != null)
			{
				handler.Dispose();
				handler = null;
			}
		}

		public virtual Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
		{
			return handler.SendAsync(request, cancellationToken);
		}
	}
	public class HttpMethod : IEquatable<HttpMethod>
	{
		private static readonly HttpMethod delete_method = new HttpMethod("DELETE");

		private static readonly HttpMethod get_method = new HttpMethod("GET");

		private static readonly HttpMethod head_method = new HttpMethod("HEAD");

		private static readonly HttpMethod options_method = new HttpMethod("OPTIONS");

		private static readonly HttpMethod post_method = new HttpMethod("POST");

		private static readonly HttpMethod put_method = new HttpMethod("PUT");

		private static readonly HttpMethod trace_method = new HttpMethod("TRACE");

		private readonly string method;

		public static HttpMethod Delete => delete_method;

		public static HttpMethod Get => get_method;

		public static HttpMethod Head => head_method;

		public string Method => method;

		public static HttpMethod Options => options_method;

		public static HttpMethod Post => post_method;

		public static HttpMethod Put => put_method;

		public static HttpMethod Trace => trace_method;

		public static HttpMethod Patch
		{
			get
			{
				throw new PlatformNotSupportedException();
			}
		}

		public HttpMethod(string method)
		{
			if (string.IsNullOrEmpty(method))
			{
				throw new ArgumentException("method");
			}
			Parser.Token.Check(method);
			this.method = method;
		}

		public static bool operator ==(HttpMethod left, HttpMethod right)
		{
			if ((object)left == null || (object)right == null)
			{
				return (object)left == right;
			}
			return left.Equals(right);
		}

		public static bool operator !=(HttpMethod left, HttpMethod right)
		{
			return !(left == right);
		}

		public bool Equals(HttpMethod other)
		{
			return string.Equals(method, other.method, StringComparison.OrdinalIgnoreCase);
		}

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

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

		public override string ToString()
		{
			return method;
		}
	}
	[Serializable]
	public class HttpRequestException : Exception
	{
		public HttpRequestException()
		{
		}

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

		public HttpRequestException(string message, Exception inner)
			: base(message, inner)
		{
		}
	}
	public class HttpRequestMessage : IDisposable
	{
		private HttpRequestHeaders headers;

		private HttpMethod method;

		private Version version;

		private Dictionary<string, object> properties;

		private Uri uri;

		private bool is_used;

		private bool disposed;

		public HttpContent Content { get; set; }

		public HttpRequestHeaders Headers => headers ?? (headers = new HttpRequestHeaders());

		public HttpMethod Method
		{
			get
			{
				return method;
			}
			set
			{
				if (value == null)
				{
					throw new ArgumentNullException("method");
				}
				method = value;
			}
		}

		public IDictionary<string, object> Properties => properties ?? (properties = new Dictionary<string, object>());

		public Uri RequestUri
		{
			get
			{
				return uri;
			}
			set
			{
				if (value != null && value.IsAbsoluteUri && !IsAllowedAbsoluteUri(value))
				{
					throw new ArgumentException("Only http or https scheme is allowed");
				}
				uri = value;
			}
		}

		public Version Version
		{
			get
			{
				return version ?? HttpVersion.Version11;
			}
			set
			{
				if (value == null)
				{
					throw new ArgumentNullException("Version");
				}
				version = value;
			}
		}

		public HttpRequestMessage()
		{
			method = HttpMethod.Get;
		}

		public HttpRequestMessage(HttpMethod method, string requestUri)
			: this(method, string.IsNullOrEmpty(requestUri) ? null : new Uri(requestUri, UriKind.RelativeOrAbsolute))
		{
		}

		public HttpRequestMessage(HttpMethod method, Uri requestUri)
		{
			Method = method;
			RequestUri = requestUri;
		}

		private static bool IsAllowedAbsoluteUri(Uri uri)
		{
			if (uri.Scheme == Uri.UriSchemeHttp || uri.Scheme == Uri.UriSchemeHttps)
			{
				return true;
			}
			if (uri.Scheme == Uri.UriSchemeFile && uri.OriginalString.StartsWith("/", StringComparison.Ordinal))
			{
				return true;
			}
			return false;
		}

		public void Dispose()
		{
			Dispose(disposing: true);
		}

		protected virtual void Dispose(bool disposing)
		{
			if (disposing && !disposed)
			{
				disposed = true;
				if (Content != null)
				{
					Content.Dispose();
				}
			}
		}

		internal bool SetIsUsed()
		{
			if (is_used)
			{
				return true;
			}
			is_used = true;
			return false;
		}

		public override string ToString()
		{
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.Append("Method: ").Append(method);
			stringBuilder.Append(", RequestUri: '").Append((RequestUri != null) ? RequestUri.ToString() : "<null>");
			stringBuilder.Append("', Version: ").Append(Version);
			stringBuilder.Append(", Content: ").Append((Content != null) ? Content.ToString() : "<null>");
			stringBuilder.Append(", Headers:\r\n{\r\n").Append(Headers);
			if (Content != null)
			{
				stringBuilder.Append(Content.Headers);
			}
			stringBuilder.Append("}");
			return stringBuilder.ToString();
		}
	}
	public class HttpResponseMessage : IDisposable
	{
		private HttpResponseHeaders headers;

		private HttpResponseHeaders trailingHeaders;

		private string reasonPhrase;

		private HttpStatusCode statusCode;

		private Version version;

		private bool disposed;

		public HttpContent Content { get; set; }

		public HttpResponseHeaders Headers => headers ?? (headers = new HttpResponseHeaders());

		public bool IsSuccessStatusCode
		{
			get
			{
				if (statusCode >= HttpStatusCode.OK)
				{
					return statusCode < HttpStatusCode.MultipleChoices;
				}
				return false;
			}
		}

		public string ReasonPhrase
		{
			get
			{
				return reasonPhrase ?? HttpStatusDescription.Get(statusCode);
			}
			set
			{
				reasonPhrase = value;
			}
		}

		public HttpRequestMessage RequestMessage { get; set; }

		public HttpStatusCode StatusCode
		{
			get
			{
				return statusCode;
			}
			set
			{
				if (value < (HttpStatusCode)0)
				{
					throw new ArgumentOutOfRangeException();
				}
				statusCode = value;
			}
		}

		public Version Version
		{
			get
			{
				return version ?? HttpVersion.Version11;
			}
			set
			{
				if (value == null)
				{
					throw new ArgumentNullException("Version");
				}
				version = value;
			}
		}

		public HttpResponseHeaders TrailingHeaders
		{
			get
			{
				if (trailingHeaders == null)
				{
					trailingHeaders = new HttpResponseHeaders();
				}
				return trailingHeaders;
			}
		}

		public HttpResponseMessage()
			: this(HttpStatusCode.OK)
		{
		}

		public HttpResponseMessage(HttpStatusCode statusCode)
		{
			StatusCode = statusCode;
		}

		public void Dispose()
		{
			Dispose(disposing: true);
		}

		protected virtual void Dispose(bool disposing)
		{
			if (disposing && !disposed)
			{
				disposed = true;
				if (Content != null)
				{
					Content.Dispose();
				}
			}
		}

		public HttpResponseMessage EnsureSuccessStatusCode()
		{
			if (IsSuccessStatusCode)
			{
				return this;
			}
			throw new HttpRequestException($"{(int)statusCode} ({ReasonPhrase})");
		}

		public override string ToString()
		{
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.Append("StatusCode: ").Append((int)StatusCode);
			stringBuilder.Append(", ReasonPhrase: '").Append(ReasonPhrase ?? "<null>");
			stringBuilder.Append("', Version: ").Append(Version);
			stringBuilder.Append(", Content: ").Append((Content != null) ? Content.ToString() : "<null>");
			stringBuilder.Append(", Headers:\r\n{\r\n").Append(Headers);
			if (Content != null)
			{
				stringBuilder.Append(Content.Headers);
			}
			stringBuilder.Append("}");
			return stringBuilder.ToString();
		}
	}
	public abstract class MessageProcessingHandler : DelegatingHandler
	{
		protected MessageProcessingHandler()
		{
		}

		protected MessageProcessingHandler(HttpMessageHandler innerHandler)
			: base(innerHandler)
		{
		}

		protected abstract HttpRequestMessage ProcessRequest(HttpRequestMessage request, CancellationToken cancellationToken);

		protected abstract HttpResponseMessage ProcessResponse(HttpResponseMessage response, CancellationToken cancellationToken);

		protected internal sealed override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
		{
			request = ProcessRequest(request, cancellationToken);
			return ProcessResponse(await base.SendAsync(request, cancellationToken).ConfigureAwait(continueOnCapturedContext: false), cancellationToken);
		}
	}
	public class MultipartContent : HttpContent, IEnumerable<HttpContent>, IEnumerable
	{
		private List<HttpContent> nested_content;

		private readonly string boundary;

		public MultipartContent()
			: this("mixed")
		{
		}

		public MultipartContent(string subtype)
			: this(subtype, Guid.NewGuid().ToString("D", CultureInfo.InvariantCulture))
		{
		}

		public MultipartContent(string subtype, string boundary)
		{
			if (string.IsNullOrWhiteSpace(subtype))
			{
				throw new ArgumentException("boundary");
			}
			if (string.IsNullOrWhiteSpace(boundary))
			{
				throw new ArgumentException("boundary");
			}
			if (boundary.Length > 70)
			{
				throw new ArgumentOutOfRangeException("boundary");
			}
			if (boundary.Last() == ' ' || !IsValidRFC2049(boundary))
			{
				throw new ArgumentException("boundary");
			}
			this.boundary = boundary;
			nested_content = new List<HttpContent>(2);
			base.Headers.ContentType = new MediaTypeHeaderValue("multipart/" + subtype)
			{
				Parameters = 
				{
					new NameValueHeaderValue("boundary", "\"" + boundary + "\"")
				}
			};
		}

		private static bool IsValidRFC2049(string s)
		{
			foreach (char c in s)
			{
				if ((c < 'a' || c > 'z') && (c < 'A' || c > 'Z') && (c < '0' || c > '9'))
				{
					switch (c)
					{
					case '\'':
					case '(':
					case ')':
					case '+':
					case ',':
					case '-':
					case '.':
					case '/':
					case ':':
					case '=':
					case '?':
						continue;
					}
					return false;
				}
			}
			return true;
		}

		public virtual void Add(HttpContent content)
		{
			if (content == null)
			{
				throw new ArgumentNullException("content");
			}
			if (nested_content == null)
			{
				nested_content = new List<HttpContent>();
			}
			nested_content.Add(content);
		}

		protected override void Dispose(bool disposing)
		{
			if (disposing)
			{
				foreach (HttpContent item in nested_content)
				{
					item.Dispose();
				}
				nested_content = null;
			}
			base.Dispose(disposing);
		}

		protected override async Task SerializeToStreamAsync(Stream stream, TransportContext context)
		{
			StringBuilder sb = new StringBuilder();
			sb.Append('-').Append('-');
			sb.Append(boundary);
			sb.Append('\r').Append('\n');
			byte[] bytes;
			for (int i = 0; i < nested_content.Count; i++)
			{
				HttpContent c = nested_content[i];
				foreach (KeyValuePair<string, IEnumerable<string>> header in c.Headers)
				{
					sb.Append(header.Key);
					sb.Append(':').Append(' ');
					foreach (string item in header.Value)
					{
						sb.Append(item);
					}
					sb.Append('\r').Append('\n');
				}
				sb.Append('\r').Append('\n');
				bytes = Encoding.ASCII.GetBytes(sb.ToString());
				sb.Clear();
				await stream.WriteAsync(bytes, 0, bytes.Length).ConfigureAwait(continueOnCapturedContext: false);
				await c.SerializeToStreamAsync_internal(stream, context).ConfigureAwait(continueOnCapturedContext: false);
				if (i != nested_content.Count - 1)
				{
					sb.Append('\r').Append('\n');
					sb.Append('-').Append('-');
					sb.Append(boundary);
					sb.Append('\r').Append('\n');
				}
			}
			sb.Append('\r').Append('\n');
			sb.Append('-').Append('-');
			sb.Append(boundary);
			sb.Append('-').Append('-');
			sb.Append('\r').Append('\n');
			bytes = Encoding.ASCII.GetBytes(sb.ToString());
			await stream.WriteAsync(bytes, 0, bytes.Length).ConfigureAwait(continueOnCapturedContext: false);
		}

		protected internal override bool TryComputeLength(out long length)
		{
			length = 12 + 2 * boundary.Length;
			for (int i = 0; i < nested_content.Count; i++)
			{
				HttpContent httpContent = nested_content[i];
				foreach (KeyValuePair<string, IEnumerable<string>> header in httpContent.Headers)
				{
					length += header.Key.Length;
					length += 4L;
					foreach (string item in header.Value)
					{
						length += item.Length;
					}
				}
				if (!httpContent.TryComputeLength(out var length2))
				{
					return false;
				}
				length += 2L;
				length += length2;
				if (i != nested_content.Count - 1)
				{
					length += 6L;
					length += boundary.Length;
				}
			}
			return true;
		}

		public IEnumerator<HttpContent> GetEnumerator()
		{
			return nested_content.GetEnumerator();
		}

		IEnumerator IEnumerable.GetEnumerator()
		{
			return nested_content.GetEnumerator();
		}
	}
	public class MultipartFormDataContent : MultipartContent
	{
		public MultipartFormDataContent()
			: base("form-data")
		{
		}

		public MultipartFormDataContent(string boundary)
			: base("form-data", boundary)
		{
		}

		public override void Add(HttpContent content)
		{
			base.Add(content);
			AddContentDisposition(content, null, null);
		}

		public void Add(HttpContent content, string name)
		{
			base.Add(content);
			if (string.IsNullOrWhiteSpace(name))
			{
				throw new ArgumentException("name");
			}
			AddContentDisposition(content, name, null);
		}

		public void Add(HttpContent content, string name, string fileName)
		{
			base.Add(content);
			if (string.IsNullOrWhiteSpace(name))
			{
				throw new ArgumentException("name");
			}
			if (string.IsNullOrWhiteSpace(fileName))
			{
				throw new ArgumentException("fileName");
			}
			AddContentDisposition(content, name, fileName);
		}

		private void AddContentDisposition(HttpContent content, string name, string fileName)
		{
			HttpContentHeaders httpContentHeaders = content.Headers;
			if (httpContentHeaders.ContentDisposition == null)
			{
				httpContentHeaders.ContentDisposition = new ContentDispositionHeaderValue("form-data")
				{
					Name = name,
					FileName = fileName,
					FileNameStar = fileName
				};
			}
		}
	}
	public class StreamContent : HttpContent
	{
		private readonly Stream content;

		private readonly int bufferSize;

		private readonly CancellationToken cancellationToken;

		private readonly long startPosition;

		private bool contentCopied;

		public StreamContent(Stream content)
			: this(content, 16384)
		{
		}

		public StreamContent(Stream content, int bufferSize)
		{
			if (content == null)
			{
				throw new ArgumentNullException("content");
			}
			if (bufferSize <= 0)
			{
				throw new ArgumentOutOfRangeException("bufferSize");
			}
			this.content = content;
			this.bufferSize = bufferSize;
			if (content.CanSeek)
			{
				startPosition = content.Position;
			}
		}

		internal StreamContent(Stream content, CancellationToken cancellationToken)
			: this(content)
		{
			this.cancellationToken = cancellationToken;
		}

		protected override Task<Stream> CreateContentReadStreamAsync()
		{
			return Task.FromResult(content);
		}

		protected override void Dispose(bool disposing)
		{
			if (disposing)
			{
				content.Dispose();
			}
			base.Dispose(disposing);
		}

		protected override Task SerializeToStreamAsync(Stream stream, TransportContext context)
		{
			if (contentCopied)
			{
				if (!content.CanSeek)
				{
					throw new InvalidOperationException("The stream was already consumed. It cannot be read again.");
				}
				content.Seek(startPosition, SeekOrigin.Begin);
			}
			else
			{
				contentCopied = true;
			}
			return content.CopyToAsync(stream, bufferSize, cancellationToken);
		}

		protected internal override bool TryComputeLength(out long length)
		{
			if (!content.CanSeek)
			{
				length = 0L;
				return false;
			}
			length = content.Length - startPosition;
			return true;
		}
	}
	public class StringContent : ByteArrayContent
	{
		public StringContent(string content)
			: this(content, null, null)
		{
		}

		public StringContent(string content, Encoding encoding)
			: this(content, encoding, null)
		{
		}

		public StringContent(string content, Encoding encoding, string mediaType)
			: base(GetByteArray(content, encoding))
		{
			base.Headers.ContentType = new MediaTypeHeaderValue(mediaType ?? "text/plain")
			{
				CharSet = (encoding ?? Encoding.UTF8).WebName
			};
		}

		private static byte[] GetByteArray(string content, Encoding encoding)
		{
			return (encoding ?? Encoding.UTF8).GetBytes(content);
		}
	}
	public sealed class ReadOnlyMemoryContent : HttpContent
	{
		public ReadOnlyMemoryContent(ReadOnlyMemory<byte> content)
		{
			throw new PlatformNotSupportedException();
		}

		protected override Task SerializeToStreamAsync(Stream stream, TransportContext context)
		{
			throw new PlatformNotSupportedException();
		}

		protected internal override bool TryComputeLength(out long length)
		{
			throw new PlatformNotSupportedException();
		}
	}
}
namespace System.Net.Http.Headers
{
	public class AuthenticationHeaderValue : ICloneable
	{
		public string Parameter { get; private set; }

		public string Scheme { get; private set; }

		public AuthenticationHeaderValue(string scheme)
			: this(scheme, null)
		{
		}

		public AuthenticationHeaderValue(string scheme, string parameter)
		{
			Parser.Token.Check(scheme);
			Scheme = scheme;
			Parameter = parameter;
		}

		private AuthenticationHeaderValue()
		{
		}

		object ICloneable.Clone()
		{
			return MemberwiseClone();
		}

		public override bool Equals(object obj)
		{
			if (obj is AuthenticationHeaderValue authenticationHeaderValue && string.Equals(authenticationHeaderValue.Scheme, Scheme, StringComparison.OrdinalIgnoreCase))
			{
				return authenticationHeaderValue.Parameter == Parameter;
			}
			return false;
		}

		public override int GetHashCode()
		{
			int num = Scheme.ToLowerInvariant().GetHashCode();
			if (!string.IsNullOrEmpty(Parameter))
			{
				num ^= Parameter.ToLowerInvariant().GetHashCode();
			}
			return num;
		}

		public static AuthenticationHeaderValue Parse(string input)
		{
			if (TryParse(input, out var parsedValue))
			{
				return parsedValue;
			}
			throw new FormatException(input);
		}

		public static bool TryParse(string input, out AuthenticationHeaderValue parsedValue)
		{
			if (TryParseElement(new Lexer(input), out parsedValue, out var t) && (Token.Type)t == Token.Type.End)
			{
				return true;
			}
			parsedValue = null;
			return false;
		}

		internal static bool TryParse(string input, int minimalCount, out List<AuthenticationHeaderValue> result)
		{
			return CollectionParser.TryParse(input, minimalCount, (ElementTryParser<AuthenticationHeaderValue>)TryParseElement, out result);
		}

		private static bool TryParseElement(Lexer lexer, out AuthenticationHeaderValue parsedValue, out Token t)
		{
			t = lexer.Scan();
			if ((Token.Type)t != Token.Type.Token)
			{
				parsedValue = null;
				return false;
			}
			parsedValue = new AuthenticationHeaderValue();
			parsedValue.Scheme = lexer.GetStringValue(t);
			t = lexer.Scan();
			if ((Token.Type)t == Token.Type.Token)
			{
				parsedValue.Parameter = lexer.GetRemainingStringValue(t.StartPosition);
				t = new Token(Token.Type.End, 0, 0);
			}
			return true;
		}

		public override string ToString()
		{
			if (Parameter == null)
			{
				return Scheme;
			}
			return Scheme + " " + Parameter;
		}
	}
	public class CacheControlHeaderValue : ICloneable
	{
		private List<NameValueHeaderValue> extensions;

		private List<string> no_cache_headers;

		private List<string> private_headers;

		public ICollection<NameValueHeaderValue> Extensions => extensions ?? (extensions = new List<NameValueHeaderValue>());

		public TimeSpan? MaxAge { get; set; }

		public bool MaxStale { get; set; }

		public TimeSpan? MaxStaleLimit { get; set; }

		public TimeSpan? MinFresh { get; set; }

		public bool MustRevalidate { get; set; }

		public bool NoCache { get; set; }

		public ICollection<string> NoCacheHeaders => no_cache_headers ?? (no_cache_headers = new List<string>());

		public bool NoStore { get; set; }

		public bool NoTransform { get; set; }

		public bool OnlyIfCached { get; set; }

		public bool Private { get; set; }

		public ICollection<string> PrivateHeaders => private_headers ?? (private_headers = new List<string>());

		public bool ProxyRevalidate { get; set; }

		public bool Public { get; set; }

		public TimeSpan? SharedMaxAge { get; set; }

		object ICloneable.Clone()
		{
			CacheControlHeaderValue cacheControlHeaderValue = (CacheControlHeaderValue)MemberwiseClone();
			if (extensions != null)
			{
				cacheControlHeaderValue.extensions = new List<NameValueHeaderValue>();
				foreach (NameValueHeaderValue extension in extensions)
				{
					cacheControlHeaderValue.extensions.Add(extension);
				}
			}
			if (no_cache_headers != null)
			{
				cacheControlHeaderValue.no_cache_headers = new List<string>();
				foreach (string no_cache_header in no_cache_headers)
				{
					cacheControlHeaderValue.no_cache_headers.Add(no_cache_header);
				}
			}
			if (private_headers != null)
			{
				cacheControlHeaderValue.private_headers = new List<string>();
				foreach (string private_header in private_headers)
				{
					cacheControlHeaderValue.private_headers.Add(private_header);
				}
			}
			return cacheControlHeaderValue;
		}

		public override bool Equals(object obj)
		{
			if (!(obj is CacheControlHeaderValue cacheControlHeaderValue))
			{
				return false;
			}
			TimeSpan? maxAge = MaxAge;
			TimeSpan? maxAge2 = cacheControlHeaderValue.MaxAge;
			if (maxAge.HasValue == maxAge2.HasValue && (!maxAge.HasValue || !(maxAge.GetValueOrDefault() != maxAge2.GetValueOrDefault())) && MaxStale == cacheControlHeaderValue.MaxStale && !(MaxStaleLimit != cacheControlHeaderValue.MaxStaleLimit))
			{
				maxAge = MinFresh;
				maxAge2 = cacheControlHeaderValue.MinFresh;
				if (maxAge.HasValue == maxAge2.HasValue && (!maxAge.HasValue || !(maxAge.GetValueOrDefault() != maxAge2.GetValueOrDefault())) && MustRevalidate == cacheControlHeaderValue.MustRevalidate && NoCache == cacheControlHeaderValue.NoCache && NoStore == cacheControlHeaderValue.NoStore && NoTransform == cacheControlHeaderValue.NoTransform && OnlyIfCached == cacheControlHeaderValue.OnlyIfCached && Private == cacheControlHeaderValue.Private && ProxyRevalidate == cacheControlHeaderValue.ProxyRevalidate && Public == cacheControlHeaderValue.Public && !(SharedMaxAge != cacheControlHeaderValue.SharedMaxAge))
				{
					if (extensions.SequenceEqual(cacheControlHeaderValue.extensions) && no_cache_headers.SequenceEqual(cacheControlHeaderValue.no_cache_headers))
					{
						return private_headers.SequenceEqual(cacheControlHeaderValue.private_headers);
					}
					return false;
				}
			}
			return false;
		}

		public override int GetHashCode()
		{
			return (((((((((((((((29 * 29 + HashCodeCalculator.Calculate(extensions)) * 29 + MaxAge.GetHashCode()) * 29 + MaxStale.GetHashCode()) * 29 + MaxStaleLimit.GetHashCode()) * 29 + MinFresh.GetHashCode()) * 29 + MustRevalidate.GetHashCode()) * 29 + HashCodeCalculator.Calculate(no_cache_headers)) * 29 + NoCache.GetHashCode()) * 29 + NoStore.GetHashCode()) * 29 + NoTransform.GetHashCode()) * 29 + OnlyIfCached.GetHashCode()) * 29 + Private.GetHashCode()) * 29 + HashCodeCalculator.Calculate(private_headers)) * 29 + ProxyRevalidate.GetHashCode()) * 29 + Public.GetHashCode()) * 29 + SharedMaxAge.GetHashCode();
		}

		public static CacheControlHeaderValue Parse(string input)
		{
			if (TryParse(input, out var parsedValue))
			{
				return parsedValue;
			}
			throw new FormatException(input);
		}

		public static bool TryParse(string input, out CacheControlHeaderValue parsedValue)
		{
			parsedValue = null;
			if (input == null)
			{
				return true;
			}
			CacheControlHeaderValue cacheControlHeaderValue = new CacheControlHeaderValue();
			Lexer lexer = new Lexer(input);
			Token token;
			do
			{
				token = lexer.Scan();
				if ((Token.Type)token != Token.Type.Token)
				{
					return false;
				}
				string stringValue = lexer.GetStringValue(token);
				bool flag = false;
				switch (stringValue)
				{
				case "no-store":
					cacheControlHeaderValue.NoStore = true;
					break;
				case "no-transform":
					cacheControlHeaderValue.NoTransform = true;
					break;
				case "only-if-cached":
					cacheControlHeaderValue.OnlyIfCached = true;
					break;
				case "public":
					cacheControlHeaderValue.Public = true;
					break;
				case "must-revalidate":
					cacheControlHeaderValue.MustRevalidate = true;
					break;
				case "proxy-revalidate":
					cacheControlHeaderValue.ProxyRevalidate = true;
					break;
				case "max-stale":
				{
					cacheControlHeaderValue.MaxStale = true;
					token = lexer.Scan();
					if ((Token.Type)token != Token.Type.SeparatorEqual)
					{
						flag = true;
						break;
					}
					token = lexer.Scan();
					if ((Token.Type)token != Token.Type.Token)
					{
						return false;
					}
					TimeSpan? maxStaleLimit = lexer.TryGetTimeSpanValue(token);
					if (!maxStaleLimit.HasValue)
					{
						return false;
					}
					cacheControlHeaderValue.MaxStaleLimit = maxStaleLimit;
					break;
				}
				case "max-age":
				case "s-maxage":
				case "min-fresh":
				{
					token = lexer.Scan();
					if ((Token.Type)token != Token.Type.SeparatorEqual)
					{
						return false;
					}
					token = lexer.Scan();
					if ((Token.Type)token != Token.Type.Token)
					{
						return false;
					}
					TimeSpan? maxStaleLimit = lexer.TryGetTimeSpanValue(token);
					if (!maxStaleLimit.HasValue)
					{
						return false;
					}
					switch (stringValue.Length)
					{
					case 7:
						cacheControlHeaderValue.MaxAge = maxStaleLimit;
						break;
					case 8:
						cacheControlHeaderValue.SharedMaxAge = maxStaleLimit;
						break;
					default:
						cacheControlHeaderValue.MinFresh = maxStaleLimit;
						break;
					}
					break;
				}
				case "private":
				case "no-cache":
				{
					if (stringValue.Length == 7)
					{
						cacheControlHeaderValue.Private = true;
					}
					else
					{
						cacheControlHeaderValue.NoCache = true;
					}
					token = lexer.Scan();
					if ((Token.Type)token != Token.Type.SeparatorEqual)
					{
						flag = true;
						break;
					}
					token = lexer.Scan();
					if ((Token.Type)token != Token.Type.QuotedString)
					{
						return false;
					}
					string[] array = lexer.GetQuotedStringValue(token).Split(',');
					for (int i = 0; i < array.Length; i++)
					{
						string item = array[i].Trim('\t', ' ');
						if (stringValue.Length == 7)
						{
							cacheControlHeaderValue.PrivateHeaders.Add(item);
							continue;
						}
						cacheControlHeaderValue.NoCache = true;
						cacheControlHeaderValue.NoCacheHeaders.Add(item);
					}
					break;
				}
				default:
				{
					string stringValue2 = lexer.GetStringValue(token);
					string value = null;
					token = lexer.Scan();
					if ((Token.Type)token == Token.Type.SeparatorEqual)
					{
						token = lexer.Scan();
						Token.Type kind = token.Kind;
						if ((uint)(kind - 2) > 1u)
						{
							return false;
						}
						value = lexer.GetStringValue(token);
					}
					else
					{
						flag = true;
					}
					cacheControlHeaderValue.Extensions.Add(NameValueHeaderValue.Create(stringValue2, value));
					break;
				}
				}
				if (!flag)
				{
					token = lexer.Scan();
				}
			}
			while ((Token.Type)token == Token.Type.SeparatorComma);
			if ((Token.Type)token != Token.Type.End)
			{
				return false;
			}
			parsedValue = cacheControlHeaderValue;
			return true;
		}

		public override string ToString()
		{
			StringBuilder stringBuilder = new StringBuilder();
			if (NoStore)
			{
				stringBuilder.Append("no-store");
				stringBuilder.Append(", ");
			}
			if (NoTransform)
			{
				stringBuilder.Append("no-transform");
				stringBuilder.Append(", ");
			}
			if (OnlyIfCached)
			{
				stringBuilder.Append("only-if-cached");
				stringBuilder.Append(", ");
			}
			if (Public)
			{
				stringBuilder.Append("public");
				stringBuilder.Append(", ");
			}
			if (MustRevalidate)
			{
				stringBuilder.Append("must-revalidate");
				stringBuilder.Append(", ");
			}
			if (ProxyRevalidate)
			{
				stringBuilder.Append("proxy-revalidate");
				stringBuilder.Append(", ");
			}
			if (NoCache)
			{
				stringBuilder.Append("no-cache");
				if (no_cache_headers != null)
				{
					stringBuilder.Append("=\"");
					no_cache_headers.ToStringBuilder(stringBuilder);
					stringBuilder.Append("\"");
				}
				stringBuilder.Append(", ");
			}
			if (MaxAge.HasValue)
			{
				stringBuilder.Append("max-age=");
				stringBuilder.Append(MaxAge.Value.TotalSeconds.ToString(CultureInfo.InvariantCulture));
				stringBuilder.Append(", ");
			}
			if (SharedMaxAge.HasValue)
			{
				stringBuilder.Append("s-maxage=");
				stringBuilder.Append(SharedMaxAge.Value.TotalSeconds.ToString(CultureInfo.InvariantCulture));
				stringBuilder.Append(", ");
			}
			if (MaxStale)
			{
				stringBuilder.Append("max-stale");
				if (MaxStaleLimit.HasValue)
				{
					stringBuilder.Append("=");
					stringBuilder.Append(MaxStaleLimit.Value.TotalSeconds.ToString(CultureInfo.InvariantCulture));
				}
				stringBuilder.Append(", ");
			}
			if (MinFresh.HasValue)
			{
				stringBuilder.Append("min-fresh=");
				stringBuilder.Append(MinFresh.Value.TotalSeconds.ToString(CultureInfo.InvariantCulture));
				stringBuilder.Append(", ");
			}
			if (Private)
			{
				stringBuilder.Append("private");
				if (private_headers != null)
				{
					stringBuilder.Append("=\"");
					private_headers.ToStringBuilder(stringBuilder);
					stringBuilder.Append("\"");
				}
				stringBuilder.Append(", ");
			}
			extensions.ToStringBuilder(stringBuilder);
			if (stringBuilder.Length > 2 && stringBuilder[stringBuilder.Length - 2] == ',' && stringBuilder[stringBuilder.Length - 1] == ' ')
			{
				stringBuilder.Remove(stringBuilder.Length - 2, 2);
			}
			return stringBuilder.ToString();
		}
	}
	internal static class CollectionExtensions
	{
		public static bool SequenceEqual<TSource>(this List<TSource> first, List<TSource> second)
		{
			if (first == null)
			{
				if (second != null)
				{
					return second.Count == 0;
				}
				return true;
			}
			if (second == null)
			{
				if (first != null)
				{
					return first.Count == 0;
				}
				return true;
			}
			return Enumerable.SequenceEqual(first, second);
		}

		public static void SetValue(this List<NameValueHeaderValue> parameters, string key, string value)
		{
			for (int i = 0; i < parameters.Count; i++)
			{
				if (string.Equals(parameters[i].Name, key, StringComparison.OrdinalIgnoreCase))
				{
					if (value == null)
					{
						parameters.RemoveAt(i);
					}
					else
					{
						parameters[i].Value = value;
					}
					return;
				}
			}
			if (!string.IsNullOrEmpty(value))
			{
				parameters.Add(new NameValueHeaderValue(key, value));
			}
		}

		public static string ToString<T>(this List<T> list)
		{
			if (list == null || list.Count == 0)
			{
				return null;
			}
			StringBuilder stringBuilder = new StringBuilder();
			for (int i = 0; i < list.Count; i++)
			{
				stringBuilder.Append("; ");
				stringBuilder.Append(list[i]);
			}
			return stringBuilder.ToString();
		}

		public static void ToStringBuilder<T>(this List<T> list, StringBuilder sb)
		{
			if (list == null || list.Count == 0)
			{
				return;
			}
			for (int i = 0; i < list.Count; i++)
			{
				if (i > 0)
				{
					sb.Append(", ");
				}
				sb.Append(list[i]);
			}
		}
	}
	internal delegate bool ElementTryParser<T>(Lexer lexer, out T parsedValue, out Token token);
	internal static class CollectionParser
	{
		public static bool TryParse<T>(string input, int minimalCount, ElementTryParser<T> parser, out List<T> result) where T : class
		{
			Lexer lexer = new Lexer(input);
			result = new List<T>();
			Token token;
			do
			{
				if (!parser(lexer, out var parsedValue, out token))
				{
					return false;
				}
				if (parsedValue != null)
				{
					result.Add(parsedValue);
				}
			}
			while ((Token.Type)token == Token.Type.SeparatorComma);
			if ((Token.Type)token == Token.Type.End)
			{
				if (minimalCount > result.Count)
				{
					result = null;
					return false;
				}
				return true;
			}
			result = null;
			return false;
		}

		public static bool TryParse(string input, int minimalCount, out List<string> result)
		{
			return TryParse(input, minimalCount, (ElementTryParser<string>)TryParseStringElement, out result);
		}

		public static bool TryParseRepetition(string input, int minimalCount, out List<string> result)
		{
			return TryParseRepetition(input, minimalCount, (ElementTryParser<string>)TryParseStringElement, out result);
		}

		private static bool TryParseStringElement(Lexer lexer, out string parsedValue, out Token t)
		{
			t = lexer.Scan();
			if ((Token.Type)t == Token.Type.Token)
			{
				parsedValue = lexer.GetStringValue(t);
				if (parsedValue.Length == 0)
				{
					parsedValue = null;
				}
				t = lexer.Scan();
			}
			else
			{
				parsedValue = null;
			}
			return true;
		}

		public static bool TryParseRepetition<T>(string input, int minimalCount, ElementTryParser<T> parser, out List<T> result) where T : class
		{
			Lexer lexer = new Lexer(input);
			result = new List<T>();
			Token token;
			do
			{
				if (!parser(lexer, out var parsedValue, out token))
				{
					return false;
				}
				if (parsedValue != null)
				{
					result.Add(parsedValue);
				}
			}
			while ((Token.Type)token != Token.Type.End);
			if (minimalCount > result.Count)
			{
				return false;
			}
			return true;
		}
	}
	public class ContentDispositionHeaderValue : ICloneable
	{
		private string dispositionType;

		private List<NameValueHeaderValue> parameters;

		public DateTimeOffset? CreationDate
		{
			get
			{
				return GetDateValue("creation-date");
			}
			set
			{
				SetDateValue("creation-date", value);
			}
		}

		public string DispositionType
		{
			get
			{
				return dispositionType;
			}
			set
			{
				Parser.Token.Check(value);
				dispositionType = value;
			}
		}

		public string FileName
		{
			get
			{
				string text = FindParameter("filename");
				if (text == null)
				{
					return null;
				}
				return DecodeValue(text, extendedNotation: false);
			}
			set
			{
				if (value != null)
				{
					value = EncodeBase64Value(value);
				}
				SetValue("filename", value);
			}
		}

		public string FileNameStar
		{
			get
			{
				string text = FindParameter("filename*");
				if (text == null)
				{
					return null;
				}
				return DecodeValue(text, extendedNotation: true);
			}
			set
			{
				if (value != null)
				{
					value = EncodeRFC5987(value);
				}
				SetValue("filename*", value);
			}
		}

		public DateTimeOffset? ModificationDate
		{
			get
			{
				return GetDateValue("modification-date");
			}
			set
			{
				SetDateValue("modification-date", value);
			}
		}

		public string Name
		{
			get
			{
				string text = FindParameter("name");
				if (text == null)
				{
					return null;
				}
				return DecodeValue(text, extendedNotation: false);
			}
			set
			{
				if (value != null)
				{
					value = EncodeBase64Value(value);
				}
				SetValue("name", value);
			}
		}

		public ICollection<NameValueHeaderValue> Parameters => parameters ?? (parameters = new List<NameValueHeaderValue>());

		public DateTimeOffset? ReadDate
		{
			get
			{
				return GetDateValue("read-date");
			}
			set
			{
				SetDateValue("read-date", value);
			}
		}

		public long? Size
		{
			get
			{
				if (Parser.Long.TryParse(FindParameter("size"), out var result))
				{
					return result;
				}
				return null;
			}
			set
			{
				if (!value.HasValue)
				{
					SetValue("size", null);
					return;
				}
				if (value < 0)
				{
					throw new ArgumentOutOfRangeException("value");
				}
				SetValue("size", value.Value.ToString(CultureInfo.InvariantCulture));
			}
		}

		private ContentDispositionHeaderValue()
		{
		}

		public ContentDispositionHeaderValue(string dispositionType)
		{
			DispositionType = dispositionType;
		}

		protected ContentDispositionHeaderValue(ContentDispositionHeaderValue source)
		{
			if (source == null)
			{
				throw new ArgumentNullException("source");
			}
			dispositionType = source.dispositionType;
			if (source.parameters == null)
			{
				return;
			}
			foreach (NameValueHeaderValue parameter in source.parameters)
			{
				Parameters.Add(new NameValueHeaderValue(parameter));
			}
		}

		object ICloneable.Clone()
		{
			return new ContentDispositionHeaderValue(this);
		}

		public override bool Equals(object obj)
		{
			if (obj is ContentDispositionHeaderValue contentDispositionHeaderValue && string.Equals(contentDispositionHeaderValue.dispositionType, dispositionType, StringComparison.OrdinalIgnoreCase))
			{
				return contentDispositionHeaderValue.parameters.SequenceEqual(parameters);
			}
			return false;
		}

		private string FindParameter(string name)
		{
			if (parameters == null)
			{
				return null;
			}
			foreach (NameValueHeaderValue parameter in parameters)
			{
				if (string.Equals(parameter.Name, name, StringComparison.OrdinalIgnoreCase))
				{
					return parameter.Value;
				}
			}
			return null;
		}

		private DateTimeOffset? GetDateValue(string name)
		{
			string text = FindParameter(name);
			if (text == null || text == null)
			{
				return null;
			}
			if (text.Length < 3)
			{
				return null;
			}
			if (text[0] == '"')
			{
				text = text.Substring(1, text.Length - 2);
			}
			if (Lexer.TryGetDateValue(text, out var value))
			{
				return value;
			}
			return null;
		}

		private static string EncodeBase64Value(string value)
		{
			bool flag = value.Length > 1 && value[0] == '"' && value[value.Length - 1] == '"';
			if (flag)
			{
				value = value.Substring(1, value.Length - 2);
			}
			for (int i = 0; i < value.Length; i++)
			{
				if (value[i] > '\u007f')
				{
					Encoding uTF = Encoding.UTF8;
					return $"\"=?{uTF.WebName}?B?{Convert.ToBase64String(uTF.GetBytes(value))}?=\"";
				}
			}
			if (flag || !Lexer.IsValidToken(value))
			{
				return "\"" + value + "\"";
			}
			return value;
		}

		private static string EncodeRFC5987(string value)
		{
			Encoding uTF = Encoding.UTF8;
			StringBuilder stringBuilder = new StringBuilder(value.Length + 11);
			stringBuilder.Append(uTF.WebName);
			stringBuilder.Append('\'');
			stringBuilder.Append('\'');
			foreach (char c in value)
			{
				if (c > '\u007f')
				{
					byte[] bytes = uTF.GetBytes(new char[1] { c });
					foreach (byte b in bytes)
					{
						stringBuilder.Append('%');
						stringBuilder.Append(b.ToString("X2"));
					}
				}
				else if (!Lexer.IsValidCharacter(c) || c == '*' || c == '?' || c == '%')
				{
					stringBuilder.Append(Uri.HexEscape(c));
				}
				else
				{
					stringBuilder.Append(c);
				}
			}
			return stringBuilder.ToString();
		}

		private static string DecodeValue(string value, bool extendedNotation)
		{
			if (value.Length < 2)
			{
				return value;
			}
			string[] array;
			Encoding encoding;
			if (value[0] == '"')
			{
				array = value.Split('?');
				if (array.Length != 5 || array[0] != "\"=" || array[4] != "=\"" || (array[2] != "B" && array[2] != "b"))
				{
					return value;
				}
				try
				{
					encoding = Encoding.GetEncoding(array[1]);
					return encoding.GetString(Convert.FromBase64String(array[3]));
				}
				catch
				{
					return value;
				}
			}
			if (!extendedNotation)
			{
				return value;
			}
			array = value.Split('\'');
			if (array.Length != 3)
			{
				return null;
			}
			try
			{
				encoding = Encoding.GetEncoding(array[0]);
			}
			catch
			{
				return null;
			}
			value = array[2];
			if (value.IndexOf('%') < 0)
			{
				return value;
			}
			StringBuilder stringBuilder = new StringBuilder();
			byte[] array2 = null;
			int num = 0;
			int index = 0;
			while (index < value.Length)
			{
				char c = value[index];
				if (c == '%')
				{
					char c2 = c;
					c = Uri.HexUnescape(value, ref index);
					if (c != c2)
					{
						if (array2 == null)
						{
							array2 = new byte[value.Length - index + 1];
						}
						array2[num++] = (byte)c;
						continue;
					}
				}
				else
				{
					index++;
				}
				if (num != 0)
				{
					stringBuilder.Append(encoding.GetChars(array2, 0, num));
					num = 0;
				}
				stringBuilder.Append(c);
			}
			if (num != 0)
			{
				stringBuilder.Append(encoding.GetChars(array2, 0, num));
			}
			return stringBuilder.ToString();
		}

		public override int GetHashCode()
		{
			return dispositionType.ToLowerInvariant().GetHashCode() ^ HashCodeCalculator.Calculate(parameters);
		}

		public static ContentDispositionHeaderValue Parse(string input)
		{
			if (TryParse(input, out var parsedValue))
			{
				return parsedValue;
			}
			throw new FormatException(input);
		}

		private void SetDateValue(string key, DateTimeOffset? value)
		{
			SetValue(key, (!value.HasValue) ? null : ("\"" + value.Value.ToString("r", CultureInfo.InvariantCulture) + "\""));
		}

		private void SetValue(string key, string value)
		{
			if (parameters == null)
			{
				parameters = new List<NameValueHeaderValue>();
			}
			parameters.SetValue(key, value);
		}

		public override string ToString()
		{
			return dispositionType + CollectionExtensions.ToString(parameters);
		}

		public static bool TryParse(string input, out ContentDispositionHeaderValue parsedValue)
		{
			parsedValue = null;
			Lexer lexer = new Lexer(input);
			Token token = lexer.Scan();
			if (token.Kind != Token.Type.Token)
			{
				return false;
			}
			List<NameValueHeaderValue> result = null;
			string stringValue = lexer.GetStringValue(token);
			token = lexer.Scan();
			switch (token.Kind)
			{
			case Token.Type.SeparatorSemicolon:
				if (!NameValueHeaderValue.TryParseParameters(lexer, out result, out token) || (Token.Type)token != Token.Type.End)
				{
					return false;
				}
				break;
			default:
				return false;
			case Token.Type.End:
				break;
			}
			parsedValue = new ContentDispositionHeaderValue
			{
				dispositionType = stringValue,
				parameters = result
			};
			return true;
		}
	}
	public class ContentRangeHeaderValue : ICloneable
	{
		private string unit = "bytes";

		public long? From { get; private set; }

		public bool HasLength => Length.HasValue;

		public bool HasRange => From.HasValue;

		public long? Length { get; private set; }

		public long? To { get; private set; }

		public string Unit
		{
			get
			{
				return unit;
			}
			set
			{
				if (value == null)
				{
					throw new ArgumentNullException("Unit");
				}
				Parser.Token.Check(value);
				unit = value;
			}
		}

		private ContentRangeHeaderValue()
		{
		}

		public ContentRangeHeaderValue(long length)
		{
			if (length < 0)
			{
				throw new ArgumentOutOfRangeException("length");
			}
			Length = length;
		}

		public ContentRangeHeaderValue(long from, long to)
		{
			if (from < 0 || from > to)
			{
				throw new ArgumentOutOfRangeException("from");
			}
			From = from;
			To = to;
		}

		public ContentRangeHeaderValue(long from, long to, long length)
			: this(from, to)
		{
			if (length < 0)
			{
				throw new ArgumentOutOfRangeException("length");
			}
			if (to > length)
			{
				throw new ArgumentOutOfRangeException("to");
			}
			Length = length;
		}

		object ICloneable.Clone()
		{
			return MemberwiseClone();
		}

		public override bool Equals(object obj)
		{
			if (!(obj is ContentRangeHeaderValue contentRangeHeaderValue))
			{
				return false;
			}
			if (contentRangeHeaderValue.Length == Length && contentRangeHeaderValue.From == From && contentRangeHeaderValue.To == To)
			{
				return string.Equals(contentRangeHeaderValue.u

BepInExPack/mono/Managed/System.Numerics.dll

Decompiled a month ago
using System;
using System.Buffers;
using System.Diagnostics;
using System.Globalization;
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;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("System.Numerics.dll")]
[assembly: AssemblyDescription("System.Numerics.dll")]
[assembly: AssemblyDefaultAlias("System.Numerics.dll")]
[assembly: AssemblyCompany("Mono development team")]
[assembly: AssemblyProduct("Mono Common Language Infrastructure")]
[assembly: AssemblyCopyright("(c) Various Mono authors")]
[assembly: SatelliteContractVersion("4.0.0.0")]
[assembly: AssemblyInformationalVersion("4.6.57.0")]
[assembly: AssemblyFileVersion("4.6.57.0")]
[assembly: NeutralResourcesLanguage("en-US")]
[assembly: CLSCompliant(true)]
[assembly: AssemblyDelaySign(true)]
[assembly: SecurityCritical]
[assembly: ComVisible(false)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("4.0.0.0")]
[module: UnverifiableCode]
internal static class Consts
{
	public const string MonoCorlibVersion = "1A5E0066-58DC-428A-B21C-0AD6CDAE2789";

	public const string MonoVersion = "6.12.0.0";

	public const string MonoCompany = "Mono development team";

	public const string MonoProduct = "Mono Common Language Infrastructure";

	public const string MonoCopyright = "(c) Various Mono authors";

	public const string FxVersion = "4.0.0.0";

	public const string FxFileVersion = "4.6.57.0";

	public const string EnvironmentVersion = "4.0.30319.42000";

	public const string VsVersion = "0.0.0.0";

	public const string VsFileVersion = "11.0.0.0";

	private const string PublicKeyToken = "b77a5c561934e089";

	public const string AssemblyI18N = "I18N, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756";

	public const string AssemblyMicrosoft_JScript = "Microsoft.JScript, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblyMicrosoft_VisualStudio = "Microsoft.VisualStudio, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblyMicrosoft_VisualStudio_Web = "Microsoft.VisualStudio.Web, Version=0.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblyMicrosoft_VSDesigner = "Microsoft.VSDesigner, Version=0.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblyMono_Http = "Mono.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756";

	public const string AssemblyMono_Posix = "Mono.Posix, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756";

	public const string AssemblyMono_Security = "Mono.Security, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756";

	public const string AssemblyMono_Messaging_RabbitMQ = "Mono.Messaging.RabbitMQ, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756";

	public const string AssemblyCorlib = "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string AssemblySystem = "System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string AssemblySystem_Data = "System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string AssemblySystem_Design = "System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_DirectoryServices = "System.DirectoryServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_Drawing = "System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_Drawing_Design = "System.Drawing.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_Messaging = "System.Messaging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_Security = "System.Security, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_ServiceProcess = "System.ServiceProcess, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_Web = "System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_Windows_Forms = "System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string AssemblySystem_2_0 = "System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string AssemblySystemCore_3_5 = "System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string AssemblySystem_Core = "System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string WindowsBase_3_0 = "WindowsBase, Version=3.0.0.0, PublicKeyToken=31bf3856ad364e35";

	public const string AssemblyWindowsBase = "WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";

	public const string AssemblyPresentationCore_3_5 = "PresentationCore, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";

	public const string AssemblyPresentationCore_4_0 = "PresentationCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";

	public const string AssemblyPresentationFramework_3_5 = "PresentationFramework, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";

	public const string AssemblySystemServiceModel_3_0 = "System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";
}
internal static class SR
{
	public const string Argument_BadFormatSpecifier = "Format specifier was invalid.";

	public const string Argument_InvalidNumberStyles = "An undefined NumberStyles value is being used.";

	public const string Argument_InvalidHexStyle = "With the AllowHexSpecifier bit set in the enum bit field, the only other valid bits that can be combined into the enum value must be a subset of those in HexNumber.";

	public const string Argument_MustBeBigInt = "The parameter must be a BigInteger.";

	public const string Format_TooLarge = "The value is too large to be represented by this format specifier.";

	public const string ArgumentOutOfRange_MustBeNonNeg = "The number must be greater than or equal to zero.";

	public const string Overflow_BigIntInfinity = "BigInteger cannot represent infinity.";

	public const string Overflow_NotANumber = "The value is not a number.";

	public const string Overflow_ParseBigInteger = "The value could not be parsed.";

	public const string Overflow_Int32 = "Value was either too large or too small for an Int32.";

	public const string Overflow_Int64 = "Value was either too large or too small for an Int64.";

	public const string Overflow_UInt32 = "Value was either too large or too small for a UInt32.";

	public const string Overflow_UInt64 = "Value was either too large or too small for a UInt64.";

	public const string Overflow_Decimal = "Value was either too large or too small for a Decimal.";

	public const string Arg_ArgumentOutOfRangeException = "Index was out of bounds:";

	public const string Arg_ElementsInSourceIsGreaterThanDestination = "Number of elements in source vector is greater than the destination array";

	public const string Arg_NullArgumentNullRef = "The method was called with a null array argument.";

	public const string Arg_TypeNotSupported = "Specified type is not supported";

	public const string ArgumentException_BufferNotFromPool = "The buffer is not associated with this pool and may not be returned to it.";

	public const string Overflow_Negative_Unsigned = "Negative values do not have an unsigned representation.";

	internal static string GetString(string name, params object[] args)
	{
		return GetString(CultureInfo.InvariantCulture, name, args);
	}

	internal static string GetString(CultureInfo culture, string name, params object[] args)
	{
		return string.Format(culture, name, args);
	}

	internal static string GetString(string name)
	{
		return name;
	}

	internal static string GetString(CultureInfo culture, string name)
	{
		return name;
	}

	internal static string Format(string resourceFormat, params object[] args)
	{
		if (args != null)
		{
			return string.Format(CultureInfo.InvariantCulture, resourceFormat, args);
		}
		return resourceFormat;
	}

	internal static string Format(string resourceFormat, object p1)
	{
		return string.Format(CultureInfo.InvariantCulture, resourceFormat, p1);
	}

	internal static string Format(string resourceFormat, object p1, object p2)
	{
		return string.Format(CultureInfo.InvariantCulture, resourceFormat, p1, p2);
	}

	internal static string Format(CultureInfo ci, string resourceFormat, object p1, object p2)
	{
		return string.Format(ci, resourceFormat, p1, p2);
	}

	internal static string Format(string resourceFormat, object p1, object p2, object p3)
	{
		return string.Format(CultureInfo.InvariantCulture, resourceFormat, p1, p2, p3);
	}

	internal static string GetResourceString(string str)
	{
		return str;
	}
}
namespace System.Numerics
{
	public struct Matrix3x2 : IEquatable<Matrix3x2>
	{
		public float M11;

		public float M12;

		public float M21;

		public float M22;

		public float M31;

		public float M32;

		private static readonly Matrix3x2 _identity = new Matrix3x2(1f, 0f, 0f, 1f, 0f, 0f);

		public static Matrix3x2 Identity => _identity;

		public bool IsIdentity
		{
			get
			{
				if (M11 == 1f && M22 == 1f && M12 == 0f && M21 == 0f && M31 == 0f)
				{
					return M32 == 0f;
				}
				return false;
			}
		}

		public Vector2 Translation
		{
			get
			{
				return new Vector2(M31, M32);
			}
			set
			{
				M31 = value.X;
				M32 = value.Y;
			}
		}

		public Matrix3x2(float m11, float m12, float m21, float m22, float m31, float m32)
		{
			M11 = m11;
			M12 = m12;
			M21 = m21;
			M22 = m22;
			M31 = m31;
			M32 = m32;
		}

		public static Matrix3x2 CreateTranslation(Vector2 position)
		{
			Matrix3x2 result = default(Matrix3x2);
			result.M11 = 1f;
			result.M12 = 0f;
			result.M21 = 0f;
			result.M22 = 1f;
			result.M31 = position.X;
			result.M32 = position.Y;
			return result;
		}

		public static Matrix3x2 CreateTranslation(float xPosition, float yPosition)
		{
			Matrix3x2 result = default(Matrix3x2);
			result.M11 = 1f;
			result.M12 = 0f;
			result.M21 = 0f;
			result.M22 = 1f;
			result.M31 = xPosition;
			result.M32 = yPosition;
			return result;
		}

		public static Matrix3x2 CreateScale(float xScale, float yScale)
		{
			Matrix3x2 result = default(Matrix3x2);
			result.M11 = xScale;
			result.M12 = 0f;
			result.M21 = 0f;
			result.M22 = yScale;
			result.M31 = 0f;
			result.M32 = 0f;
			return result;
		}

		public static Matrix3x2 CreateScale(float xScale, float yScale, Vector2 centerPoint)
		{
			float m = centerPoint.X * (1f - xScale);
			float m2 = centerPoint.Y * (1f - yScale);
			Matrix3x2 result = default(Matrix3x2);
			result.M11 = xScale;
			result.M12 = 0f;
			result.M21 = 0f;
			result.M22 = yScale;
			result.M31 = m;
			result.M32 = m2;
			return result;
		}

		public static Matrix3x2 CreateScale(Vector2 scales)
		{
			Matrix3x2 result = default(Matrix3x2);
			result.M11 = scales.X;
			result.M12 = 0f;
			result.M21 = 0f;
			result.M22 = scales.Y;
			result.M31 = 0f;
			result.M32 = 0f;
			return result;
		}

		public static Matrix3x2 CreateScale(Vector2 scales, Vector2 centerPoint)
		{
			float m = centerPoint.X * (1f - scales.X);
			float m2 = centerPoint.Y * (1f - scales.Y);
			Matrix3x2 result = default(Matrix3x2);
			result.M11 = scales.X;
			result.M12 = 0f;
			result.M21 = 0f;
			result.M22 = scales.Y;
			result.M31 = m;
			result.M32 = m2;
			return result;
		}

		public static Matrix3x2 CreateScale(float scale)
		{
			Matrix3x2 result = default(Matrix3x2);
			result.M11 = scale;
			result.M12 = 0f;
			result.M21 = 0f;
			result.M22 = scale;
			result.M31 = 0f;
			result.M32 = 0f;
			return result;
		}

		public static Matrix3x2 CreateScale(float scale, Vector2 centerPoint)
		{
			float m = centerPoint.X * (1f - scale);
			float m2 = centerPoint.Y * (1f - scale);
			Matrix3x2 result = default(Matrix3x2);
			result.M11 = scale;
			result.M12 = 0f;
			result.M21 = 0f;
			result.M22 = scale;
			result.M31 = m;
			result.M32 = m2;
			return result;
		}

		public static Matrix3x2 CreateSkew(float radiansX, float radiansY)
		{
			float m = MathF.Tan(radiansX);
			float m2 = MathF.Tan(radiansY);
			Matrix3x2 result = default(Matrix3x2);
			result.M11 = 1f;
			result.M12 = m2;
			result.M21 = m;
			result.M22 = 1f;
			result.M31 = 0f;
			result.M32 = 0f;
			return result;
		}

		public static Matrix3x2 CreateSkew(float radiansX, float radiansY, Vector2 centerPoint)
		{
			float num = MathF.Tan(radiansX);
			float num2 = MathF.Tan(radiansY);
			float m = (0f - centerPoint.Y) * num;
			float m2 = (0f - centerPoint.X) * num2;
			Matrix3x2 result = default(Matrix3x2);
			result.M11 = 1f;
			result.M12 = num2;
			result.M21 = num;
			result.M22 = 1f;
			result.M31 = m;
			result.M32 = m2;
			return result;
		}

		public static Matrix3x2 CreateRotation(float radians)
		{
			radians = MathF.IEEERemainder(radians, (float)Math.PI * 2f);
			float num;
			float num2;
			if (radians > -1.7453294E-05f && radians < 1.7453294E-05f)
			{
				num = 1f;
				num2 = 0f;
			}
			else if (radians > 1.570779f && radians < 1.5708138f)
			{
				num = 0f;
				num2 = 1f;
			}
			else if (radians < -3.1415753f || radians > 3.1415753f)
			{
				num = -1f;
				num2 = 0f;
			}
			else if (radians > -1.5708138f && radians < -1.570779f)
			{
				num = 0f;
				num2 = -1f;
			}
			else
			{
				num = MathF.Cos(radians);
				num2 = MathF.Sin(radians);
			}
			Matrix3x2 result = default(Matrix3x2);
			result.M11 = num;
			result.M12 = num2;
			result.M21 = 0f - num2;
			result.M22 = num;
			result.M31 = 0f;
			result.M32 = 0f;
			return result;
		}

		public static Matrix3x2 CreateRotation(float radians, Vector2 centerPoint)
		{
			radians = MathF.IEEERemainder(radians, (float)Math.PI * 2f);
			float num;
			float num2;
			if (radians > -1.7453294E-05f && radians < 1.7453294E-05f)
			{
				num = 1f;
				num2 = 0f;
			}
			else if (radians > 1.570779f && radians < 1.5708138f)
			{
				num = 0f;
				num2 = 1f;
			}
			else if (radians < -3.1415753f || radians > 3.1415753f)
			{
				num = -1f;
				num2 = 0f;
			}
			else if (radians > -1.5708138f && radians < -1.570779f)
			{
				num = 0f;
				num2 = -1f;
			}
			else
			{
				num = MathF.Cos(radians);
				num2 = MathF.Sin(radians);
			}
			float m = centerPoint.X * (1f - num) + centerPoint.Y * num2;
			float m2 = centerPoint.Y * (1f - num) - centerPoint.X * num2;
			Matrix3x2 result = default(Matrix3x2);
			result.M11 = num;
			result.M12 = num2;
			result.M21 = 0f - num2;
			result.M22 = num;
			result.M31 = m;
			result.M32 = m2;
			return result;
		}

		public float GetDeterminant()
		{
			return M11 * M22 - M21 * M12;
		}

		public static bool Invert(Matrix3x2 matrix, out Matrix3x2 result)
		{
			float num = matrix.M11 * matrix.M22 - matrix.M21 * matrix.M12;
			if (MathF.Abs(num) < float.Epsilon)
			{
				result = new Matrix3x2(float.NaN, float.NaN, float.NaN, float.NaN, float.NaN, float.NaN);
				return false;
			}
			float num2 = 1f / num;
			result.M11 = matrix.M22 * num2;
			result.M12 = (0f - matrix.M12) * num2;
			result.M21 = (0f - matrix.M21) * num2;
			result.M22 = matrix.M11 * num2;
			result.M31 = (matrix.M21 * matrix.M32 - matrix.M31 * matrix.M22) * num2;
			result.M32 = (matrix.M31 * matrix.M12 - matrix.M11 * matrix.M32) * num2;
			return true;
		}

		public static Matrix3x2 Lerp(Matrix3x2 matrix1, Matrix3x2 matrix2, float amount)
		{
			Matrix3x2 result = default(Matrix3x2);
			result.M11 = matrix1.M11 + (matrix2.M11 - matrix1.M11) * amount;
			result.M12 = matrix1.M12 + (matrix2.M12 - matrix1.M12) * amount;
			result.M21 = matrix1.M21 + (matrix2.M21 - matrix1.M21) * amount;
			result.M22 = matrix1.M22 + (matrix2.M22 - matrix1.M22) * amount;
			result.M31 = matrix1.M31 + (matrix2.M31 - matrix1.M31) * amount;
			result.M32 = matrix1.M32 + (matrix2.M32 - matrix1.M32) * amount;
			return result;
		}

		public static Matrix3x2 Negate(Matrix3x2 value)
		{
			Matrix3x2 result = default(Matrix3x2);
			result.M11 = 0f - value.M11;
			result.M12 = 0f - value.M12;
			result.M21 = 0f - value.M21;
			result.M22 = 0f - value.M22;
			result.M31 = 0f - value.M31;
			result.M32 = 0f - value.M32;
			return result;
		}

		public static Matrix3x2 Add(Matrix3x2 value1, Matrix3x2 value2)
		{
			Matrix3x2 result = default(Matrix3x2);
			result.M11 = value1.M11 + value2.M11;
			result.M12 = value1.M12 + value2.M12;
			result.M21 = value1.M21 + value2.M21;
			result.M22 = value1.M22 + value2.M22;
			result.M31 = value1.M31 + value2.M31;
			result.M32 = value1.M32 + value2.M32;
			return result;
		}

		public static Matrix3x2 Subtract(Matrix3x2 value1, Matrix3x2 value2)
		{
			Matrix3x2 result = default(Matrix3x2);
			result.M11 = value1.M11 - value2.M11;
			result.M12 = value1.M12 - value2.M12;
			result.M21 = value1.M21 - value2.M21;
			result.M22 = value1.M22 - value2.M22;
			result.M31 = value1.M31 - value2.M31;
			result.M32 = value1.M32 - value2.M32;
			return result;
		}

		public static Matrix3x2 Multiply(Matrix3x2 value1, Matrix3x2 value2)
		{
			Matrix3x2 result = default(Matrix3x2);
			result.M11 = value1.M11 * value2.M11 + value1.M12 * value2.M21;
			result.M12 = value1.M11 * value2.M12 + value1.M12 * value2.M22;
			result.M21 = value1.M21 * value2.M11 + value1.M22 * value2.M21;
			result.M22 = value1.M21 * value2.M12 + value1.M22 * value2.M22;
			result.M31 = value1.M31 * value2.M11 + value1.M32 * value2.M21 + value2.M31;
			result.M32 = value1.M31 * value2.M12 + value1.M32 * value2.M22 + value2.M32;
			return result;
		}

		public static Matrix3x2 Multiply(Matrix3x2 value1, float value2)
		{
			Matrix3x2 result = default(Matrix3x2);
			result.M11 = value1.M11 * value2;
			result.M12 = value1.M12 * value2;
			result.M21 = value1.M21 * value2;
			result.M22 = value1.M22 * value2;
			result.M31 = value1.M31 * value2;
			result.M32 = value1.M32 * value2;
			return result;
		}

		public static Matrix3x2 operator -(Matrix3x2 value)
		{
			Matrix3x2 result = default(Matrix3x2);
			result.M11 = 0f - value.M11;
			result.M12 = 0f - value.M12;
			result.M21 = 0f - value.M21;
			result.M22 = 0f - value.M22;
			result.M31 = 0f - value.M31;
			result.M32 = 0f - value.M32;
			return result;
		}

		public static Matrix3x2 operator +(Matrix3x2 value1, Matrix3x2 value2)
		{
			Matrix3x2 result = default(Matrix3x2);
			result.M11 = value1.M11 + value2.M11;
			result.M12 = value1.M12 + value2.M12;
			result.M21 = value1.M21 + value2.M21;
			result.M22 = value1.M22 + value2.M22;
			result.M31 = value1.M31 + value2.M31;
			result.M32 = value1.M32 + value2.M32;
			return result;
		}

		public static Matrix3x2 operator -(Matrix3x2 value1, Matrix3x2 value2)
		{
			Matrix3x2 result = default(Matrix3x2);
			result.M11 = value1.M11 - value2.M11;
			result.M12 = value1.M12 - value2.M12;
			result.M21 = value1.M21 - value2.M21;
			result.M22 = value1.M22 - value2.M22;
			result.M31 = value1.M31 - value2.M31;
			result.M32 = value1.M32 - value2.M32;
			return result;
		}

		public static Matrix3x2 operator *(Matrix3x2 value1, Matrix3x2 value2)
		{
			Matrix3x2 result = default(Matrix3x2);
			result.M11 = value1.M11 * value2.M11 + value1.M12 * value2.M21;
			result.M12 = value1.M11 * value2.M12 + value1.M12 * value2.M22;
			result.M21 = value1.M21 * value2.M11 + value1.M22 * value2.M21;
			result.M22 = value1.M21 * value2.M12 + value1.M22 * value2.M22;
			result.M31 = value1.M31 * value2.M11 + value1.M32 * value2.M21 + value2.M31;
			result.M32 = value1.M31 * value2.M12 + value1.M32 * value2.M22 + value2.M32;
			return result;
		}

		public static Matrix3x2 operator *(Matrix3x2 value1, float value2)
		{
			Matrix3x2 result = default(Matrix3x2);
			result.M11 = value1.M11 * value2;
			result.M12 = value1.M12 * value2;
			result.M21 = value1.M21 * value2;
			result.M22 = value1.M22 * value2;
			result.M31 = value1.M31 * value2;
			result.M32 = value1.M32 * value2;
			return result;
		}

		public static bool operator ==(Matrix3x2 value1, Matrix3x2 value2)
		{
			if (value1.M11 == value2.M11 && value1.M22 == value2.M22 && value1.M12 == value2.M12 && value1.M21 == value2.M21 && value1.M31 == value2.M31)
			{
				return value1.M32 == value2.M32;
			}
			return false;
		}

		public static bool operator !=(Matrix3x2 value1, Matrix3x2 value2)
		{
			if (value1.M11 == value2.M11 && value1.M12 == value2.M12 && value1.M21 == value2.M21 && value1.M22 == value2.M22 && value1.M31 == value2.M31)
			{
				return value1.M32 != value2.M32;
			}
			return true;
		}

		public bool Equals(Matrix3x2 other)
		{
			if (M11 == other.M11 && M22 == other.M22 && M12 == other.M12 && M21 == other.M21 && M31 == other.M31)
			{
				return M32 == other.M32;
			}
			return false;
		}

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

		public override string ToString()
		{
			CultureInfo currentCulture = CultureInfo.CurrentCulture;
			return string.Format(currentCulture, "{{ {{M11:{0} M12:{1}}} {{M21:{2} M22:{3}}} {{M31:{4} M32:{5}}} }}", M11.ToString(currentCulture), M12.ToString(currentCulture), M21.ToString(currentCulture), M22.ToString(currentCulture), M31.ToString(currentCulture), M32.ToString(currentCulture));
		}

		public override int GetHashCode()
		{
			return M11.GetHashCode() + M12.GetHashCode() + M21.GetHashCode() + M22.GetHashCode() + M31.GetHashCode() + M32.GetHashCode();
		}
	}
	public struct Matrix4x4 : IEquatable<Matrix4x4>
	{
		private struct CanonicalBasis
		{
			public Vector3 Row0;

			public Vector3 Row1;

			public Vector3 Row2;
		}

		private struct VectorBasis
		{
			public unsafe Vector3* Element0;

			public unsafe Vector3* Element1;

			public unsafe Vector3* Element2;
		}

		public float M11;

		public float M12;

		public float M13;

		public float M14;

		public float M21;

		public float M22;

		public float M23;

		public float M24;

		public float M31;

		public float M32;

		public float M33;

		public float M34;

		public float M41;

		public float M42;

		public float M43;

		public float M44;

		private static readonly Matrix4x4 _identity = new Matrix4x4(1f, 0f, 0f, 0f, 0f, 1f, 0f, 0f, 0f, 0f, 1f, 0f, 0f, 0f, 0f, 1f);

		public static Matrix4x4 Identity => _identity;

		public bool IsIdentity
		{
			get
			{
				if (M11 == 1f && M22 == 1f && M33 == 1f && M44 == 1f && M12 == 0f && M13 == 0f && M14 == 0f && M21 == 0f && M23 == 0f && M24 == 0f && M31 == 0f && M32 == 0f && M34 == 0f && M41 == 0f && M42 == 0f)
				{
					return M43 == 0f;
				}
				return false;
			}
		}

		public Vector3 Translation
		{
			get
			{
				return new Vector3(M41, M42, M43);
			}
			set
			{
				M41 = value.X;
				M42 = value.Y;
				M43 = value.Z;
			}
		}

		public Matrix4x4(float m11, float m12, float m13, float m14, float m21, float m22, float m23, float m24, float m31, float m32, float m33, float m34, float m41, float m42, float m43, float m44)
		{
			M11 = m11;
			M12 = m12;
			M13 = m13;
			M14 = m14;
			M21 = m21;
			M22 = m22;
			M23 = m23;
			M24 = m24;
			M31 = m31;
			M32 = m32;
			M33 = m33;
			M34 = m34;
			M41 = m41;
			M42 = m42;
			M43 = m43;
			M44 = m44;
		}

		public Matrix4x4(Matrix3x2 value)
		{
			M11 = value.M11;
			M12 = value.M12;
			M13 = 0f;
			M14 = 0f;
			M21 = value.M21;
			M22 = value.M22;
			M23 = 0f;
			M24 = 0f;
			M31 = 0f;
			M32 = 0f;
			M33 = 1f;
			M34 = 0f;
			M41 = value.M31;
			M42 = value.M32;
			M43 = 0f;
			M44 = 1f;
		}

		public static Matrix4x4 CreateBillboard(Vector3 objectPosition, Vector3 cameraPosition, Vector3 cameraUpVector, Vector3 cameraForwardVector)
		{
			Vector3 left = new Vector3(objectPosition.X - cameraPosition.X, objectPosition.Y - cameraPosition.Y, objectPosition.Z - cameraPosition.Z);
			float num = left.LengthSquared();
			left = ((!(num < 0.0001f)) ? Vector3.Multiply(left, 1f / MathF.Sqrt(num)) : (-cameraForwardVector));
			Vector3 vector = Vector3.Normalize(Vector3.Cross(cameraUpVector, left));
			Vector3 vector2 = Vector3.Cross(left, vector);
			Matrix4x4 result = default(Matrix4x4);
			result.M11 = vector.X;
			result.M12 = vector.Y;
			result.M13 = vector.Z;
			result.M14 = 0f;
			result.M21 = vector2.X;
			result.M22 = vector2.Y;
			result.M23 = vector2.Z;
			result.M24 = 0f;
			result.M31 = left.X;
			result.M32 = left.Y;
			result.M33 = left.Z;
			result.M34 = 0f;
			result.M41 = objectPosition.X;
			result.M42 = objectPosition.Y;
			result.M43 = objectPosition.Z;
			result.M44 = 1f;
			return result;
		}

		public static Matrix4x4 CreateConstrainedBillboard(Vector3 objectPosition, Vector3 cameraPosition, Vector3 rotateAxis, Vector3 cameraForwardVector, Vector3 objectForwardVector)
		{
			Vector3 left = new Vector3(objectPosition.X - cameraPosition.X, objectPosition.Y - cameraPosition.Y, objectPosition.Z - cameraPosition.Z);
			float num = left.LengthSquared();
			left = ((!(num < 0.0001f)) ? Vector3.Multiply(left, 1f / MathF.Sqrt(num)) : (-cameraForwardVector));
			Vector3 vector = rotateAxis;
			Vector3 vector3;
			Vector3 vector2;
			if (MathF.Abs(Vector3.Dot(rotateAxis, left)) > 0.99825466f)
			{
				vector2 = objectForwardVector;
				if (MathF.Abs(Vector3.Dot(rotateAxis, vector2)) > 0.99825466f)
				{
					vector2 = ((MathF.Abs(rotateAxis.Z) > 0.99825466f) ? new Vector3(1f, 0f, 0f) : new Vector3(0f, 0f, -1f));
				}
				vector3 = Vector3.Normalize(Vector3.Cross(rotateAxis, vector2));
				vector2 = Vector3.Normalize(Vector3.Cross(vector3, rotateAxis));
			}
			else
			{
				vector3 = Vector3.Normalize(Vector3.Cross(rotateAxis, left));
				vector2 = Vector3.Normalize(Vector3.Cross(vector3, vector));
			}
			Matrix4x4 result = default(Matrix4x4);
			result.M11 = vector3.X;
			result.M12 = vector3.Y;
			result.M13 = vector3.Z;
			result.M14 = 0f;
			result.M21 = vector.X;
			result.M22 = vector.Y;
			result.M23 = vector.Z;
			result.M24 = 0f;
			result.M31 = vector2.X;
			result.M32 = vector2.Y;
			result.M33 = vector2.Z;
			result.M34 = 0f;
			result.M41 = objectPosition.X;
			result.M42 = objectPosition.Y;
			result.M43 = objectPosition.Z;
			result.M44 = 1f;
			return result;
		}

		public static Matrix4x4 CreateTranslation(Vector3 position)
		{
			Matrix4x4 result = default(Matrix4x4);
			result.M11 = 1f;
			result.M12 = 0f;
			result.M13 = 0f;
			result.M14 = 0f;
			result.M21 = 0f;
			result.M22 = 1f;
			result.M23 = 0f;
			result.M24 = 0f;
			result.M31 = 0f;
			result.M32 = 0f;
			result.M33 = 1f;
			result.M34 = 0f;
			result.M41 = position.X;
			result.M42 = position.Y;
			result.M43 = position.Z;
			result.M44 = 1f;
			return result;
		}

		public static Matrix4x4 CreateTranslation(float xPosition, float yPosition, float zPosition)
		{
			Matrix4x4 result = default(Matrix4x4);
			result.M11 = 1f;
			result.M12 = 0f;
			result.M13 = 0f;
			result.M14 = 0f;
			result.M21 = 0f;
			result.M22 = 1f;
			result.M23 = 0f;
			result.M24 = 0f;
			result.M31 = 0f;
			result.M32 = 0f;
			result.M33 = 1f;
			result.M34 = 0f;
			result.M41 = xPosition;
			result.M42 = yPosition;
			result.M43 = zPosition;
			result.M44 = 1f;
			return result;
		}

		public static Matrix4x4 CreateScale(float xScale, float yScale, float zScale)
		{
			Matrix4x4 result = default(Matrix4x4);
			result.M11 = xScale;
			result.M12 = 0f;
			result.M13 = 0f;
			result.M14 = 0f;
			result.M21 = 0f;
			result.M22 = yScale;
			result.M23 = 0f;
			result.M24 = 0f;
			result.M31 = 0f;
			result.M32 = 0f;
			result.M33 = zScale;
			result.M34 = 0f;
			result.M41 = 0f;
			result.M42 = 0f;
			result.M43 = 0f;
			result.M44 = 1f;
			return result;
		}

		public static Matrix4x4 CreateScale(float xScale, float yScale, float zScale, Vector3 centerPoint)
		{
			float m = centerPoint.X * (1f - xScale);
			float m2 = centerPoint.Y * (1f - yScale);
			float m3 = centerPoint.Z * (1f - zScale);
			Matrix4x4 result = default(Matrix4x4);
			result.M11 = xScale;
			result.M12 = 0f;
			result.M13 = 0f;
			result.M14 = 0f;
			result.M21 = 0f;
			result.M22 = yScale;
			result.M23 = 0f;
			result.M24 = 0f;
			result.M31 = 0f;
			result.M32 = 0f;
			result.M33 = zScale;
			result.M34 = 0f;
			result.M41 = m;
			result.M42 = m2;
			result.M43 = m3;
			result.M44 = 1f;
			return result;
		}

		public static Matrix4x4 CreateScale(Vector3 scales)
		{
			Matrix4x4 result = default(Matrix4x4);
			result.M11 = scales.X;
			result.M12 = 0f;
			result.M13 = 0f;
			result.M14 = 0f;
			result.M21 = 0f;
			result.M22 = scales.Y;
			result.M23 = 0f;
			result.M24 = 0f;
			result.M31 = 0f;
			result.M32 = 0f;
			result.M33 = scales.Z;
			result.M34 = 0f;
			result.M41 = 0f;
			result.M42 = 0f;
			result.M43 = 0f;
			result.M44 = 1f;
			return result;
		}

		public static Matrix4x4 CreateScale(Vector3 scales, Vector3 centerPoint)
		{
			float m = centerPoint.X * (1f - scales.X);
			float m2 = centerPoint.Y * (1f - scales.Y);
			float m3 = centerPoint.Z * (1f - scales.Z);
			Matrix4x4 result = default(Matrix4x4);
			result.M11 = scales.X;
			result.M12 = 0f;
			result.M13 = 0f;
			result.M14 = 0f;
			result.M21 = 0f;
			result.M22 = scales.Y;
			result.M23 = 0f;
			result.M24 = 0f;
			result.M31 = 0f;
			result.M32 = 0f;
			result.M33 = scales.Z;
			result.M34 = 0f;
			result.M41 = m;
			result.M42 = m2;
			result.M43 = m3;
			result.M44 = 1f;
			return result;
		}

		public static Matrix4x4 CreateScale(float scale)
		{
			Matrix4x4 result = default(Matrix4x4);
			result.M11 = scale;
			result.M12 = 0f;
			result.M13 = 0f;
			result.M14 = 0f;
			result.M21 = 0f;
			result.M22 = scale;
			result.M23 = 0f;
			result.M24 = 0f;
			result.M31 = 0f;
			result.M32 = 0f;
			result.M33 = scale;
			result.M34 = 0f;
			result.M41 = 0f;
			result.M42 = 0f;
			result.M43 = 0f;
			result.M44 = 1f;
			return result;
		}

		public static Matrix4x4 CreateScale(float scale, Vector3 centerPoint)
		{
			float m = centerPoint.X * (1f - scale);
			float m2 = centerPoint.Y * (1f - scale);
			float m3 = centerPoint.Z * (1f - scale);
			Matrix4x4 result = default(Matrix4x4);
			result.M11 = scale;
			result.M12 = 0f;
			result.M13 = 0f;
			result.M14 = 0f;
			result.M21 = 0f;
			result.M22 = scale;
			result.M23 = 0f;
			result.M24 = 0f;
			result.M31 = 0f;
			result.M32 = 0f;
			result.M33 = scale;
			result.M34 = 0f;
			result.M41 = m;
			result.M42 = m2;
			result.M43 = m3;
			result.M44 = 1f;
			return result;
		}

		public static Matrix4x4 CreateRotationX(float radians)
		{
			float num = MathF.Cos(radians);
			float num2 = MathF.Sin(radians);
			Matrix4x4 result = default(Matrix4x4);
			result.M11 = 1f;
			result.M12 = 0f;
			result.M13 = 0f;
			result.M14 = 0f;
			result.M21 = 0f;
			result.M22 = num;
			result.M23 = num2;
			result.M24 = 0f;
			result.M31 = 0f;
			result.M32 = 0f - num2;
			result.M33 = num;
			result.M34 = 0f;
			result.M41 = 0f;
			result.M42 = 0f;
			result.M43 = 0f;
			result.M44 = 1f;
			return result;
		}

		public static Matrix4x4 CreateRotationX(float radians, Vector3 centerPoint)
		{
			float num = MathF.Cos(radians);
			float num2 = MathF.Sin(radians);
			float m = centerPoint.Y * (1f - num) + centerPoint.Z * num2;
			float m2 = centerPoint.Z * (1f - num) - centerPoint.Y * num2;
			Matrix4x4 result = default(Matrix4x4);
			result.M11 = 1f;
			result.M12 = 0f;
			result.M13 = 0f;
			result.M14 = 0f;
			result.M21 = 0f;
			result.M22 = num;
			result.M23 = num2;
			result.M24 = 0f;
			result.M31 = 0f;
			result.M32 = 0f - num2;
			result.M33 = num;
			result.M34 = 0f;
			result.M41 = 0f;
			result.M42 = m;
			result.M43 = m2;
			result.M44 = 1f;
			return result;
		}

		public static Matrix4x4 CreateRotationY(float radians)
		{
			float num = MathF.Cos(radians);
			float num2 = MathF.Sin(radians);
			Matrix4x4 result = default(Matrix4x4);
			result.M11 = num;
			result.M12 = 0f;
			result.M13 = 0f - num2;
			result.M14 = 0f;
			result.M21 = 0f;
			result.M22 = 1f;
			result.M23 = 0f;
			result.M24 = 0f;
			result.M31 = num2;
			result.M32 = 0f;
			result.M33 = num;
			result.M34 = 0f;
			result.M41 = 0f;
			result.M42 = 0f;
			result.M43 = 0f;
			result.M44 = 1f;
			return result;
		}

		public static Matrix4x4 CreateRotationY(float radians, Vector3 centerPoint)
		{
			float num = MathF.Cos(radians);
			float num2 = MathF.Sin(radians);
			float m = centerPoint.X * (1f - num) - centerPoint.Z * num2;
			float m2 = centerPoint.Z * (1f - num) + centerPoint.X * num2;
			Matrix4x4 result = default(Matrix4x4);
			result.M11 = num;
			result.M12 = 0f;
			result.M13 = 0f - num2;
			result.M14 = 0f;
			result.M21 = 0f;
			result.M22 = 1f;
			result.M23 = 0f;
			result.M24 = 0f;
			result.M31 = num2;
			result.M32 = 0f;
			result.M33 = num;
			result.M34 = 0f;
			result.M41 = m;
			result.M42 = 0f;
			result.M43 = m2;
			result.M44 = 1f;
			return result;
		}

		public static Matrix4x4 CreateRotationZ(float radians)
		{
			float num = MathF.Cos(radians);
			float num2 = MathF.Sin(radians);
			Matrix4x4 result = default(Matrix4x4);
			result.M11 = num;
			result.M12 = num2;
			result.M13 = 0f;
			result.M14 = 0f;
			result.M21 = 0f - num2;
			result.M22 = num;
			result.M23 = 0f;
			result.M24 = 0f;
			result.M31 = 0f;
			result.M32 = 0f;
			result.M33 = 1f;
			result.M34 = 0f;
			result.M41 = 0f;
			result.M42 = 0f;
			result.M43 = 0f;
			result.M44 = 1f;
			return result;
		}

		public static Matrix4x4 CreateRotationZ(float radians, Vector3 centerPoint)
		{
			float num = MathF.Cos(radians);
			float num2 = MathF.Sin(radians);
			float m = centerPoint.X * (1f - num) + centerPoint.Y * num2;
			float m2 = centerPoint.Y * (1f - num) - centerPoint.X * num2;
			Matrix4x4 result = default(Matrix4x4);
			result.M11 = num;
			result.M12 = num2;
			result.M13 = 0f;
			result.M14 = 0f;
			result.M21 = 0f - num2;
			result.M22 = num;
			result.M23 = 0f;
			result.M24 = 0f;
			result.M31 = 0f;
			result.M32 = 0f;
			result.M33 = 1f;
			result.M34 = 0f;
			result.M41 = m;
			result.M42 = m2;
			result.M43 = 0f;
			result.M44 = 1f;
			return result;
		}

		public static Matrix4x4 CreateFromAxisAngle(Vector3 axis, float angle)
		{
			float x = axis.X;
			float y = axis.Y;
			float z = axis.Z;
			float num = MathF.Sin(angle);
			float num2 = MathF.Cos(angle);
			float num3 = x * x;
			float num4 = y * y;
			float num5 = z * z;
			float num6 = x * y;
			float num7 = x * z;
			float num8 = y * z;
			Matrix4x4 result = default(Matrix4x4);
			result.M11 = num3 + num2 * (1f - num3);
			result.M12 = num6 - num2 * num6 + num * z;
			result.M13 = num7 - num2 * num7 - num * y;
			result.M14 = 0f;
			result.M21 = num6 - num2 * num6 - num * z;
			result.M22 = num4 + num2 * (1f - num4);
			result.M23 = num8 - num2 * num8 + num * x;
			result.M24 = 0f;
			result.M31 = num7 - num2 * num7 + num * y;
			result.M32 = num8 - num2 * num8 - num * x;
			result.M33 = num5 + num2 * (1f - num5);
			result.M34 = 0f;
			result.M41 = 0f;
			result.M42 = 0f;
			result.M43 = 0f;
			result.M44 = 1f;
			return result;
		}

		public static Matrix4x4 CreatePerspectiveFieldOfView(float fieldOfView, float aspectRatio, float nearPlaneDistance, float farPlaneDistance)
		{
			if (fieldOfView <= 0f || fieldOfView >= (float)Math.PI)
			{
				throw new ArgumentOutOfRangeException("fieldOfView");
			}
			if (nearPlaneDistance <= 0f)
			{
				throw new ArgumentOutOfRangeException("nearPlaneDistance");
			}
			if (farPlaneDistance <= 0f)
			{
				throw new ArgumentOutOfRangeException("farPlaneDistance");
			}
			if (nearPlaneDistance >= farPlaneDistance)
			{
				throw new ArgumentOutOfRangeException("nearPlaneDistance");
			}
			float num = 1f / MathF.Tan(fieldOfView * 0.5f);
			float m = num / aspectRatio;
			Matrix4x4 result = default(Matrix4x4);
			result.M11 = m;
			result.M12 = (result.M13 = (result.M14 = 0f));
			result.M22 = num;
			result.M21 = (result.M23 = (result.M24 = 0f));
			result.M31 = (result.M32 = 0f);
			float num2 = (result.M33 = (float.IsPositiveInfinity(farPlaneDistance) ? (-1f) : (farPlaneDistance / (nearPlaneDistance - farPlaneDistance))));
			result.M34 = -1f;
			result.M41 = (result.M42 = (result.M44 = 0f));
			result.M43 = nearPlaneDistance * num2;
			return result;
		}

		public static Matrix4x4 CreatePerspective(float width, float height, float nearPlaneDistance, float farPlaneDistance)
		{
			if (nearPlaneDistance <= 0f)
			{
				throw new ArgumentOutOfRangeException("nearPlaneDistance");
			}
			if (farPlaneDistance <= 0f)
			{
				throw new ArgumentOutOfRangeException("farPlaneDistance");
			}
			if (nearPlaneDistance >= farPlaneDistance)
			{
				throw new ArgumentOutOfRangeException("nearPlaneDistance");
			}
			Matrix4x4 result = default(Matrix4x4);
			result.M11 = 2f * nearPlaneDistance / width;
			result.M12 = (result.M13 = (result.M14 = 0f));
			result.M22 = 2f * nearPlaneDistance / height;
			result.M21 = (result.M23 = (result.M24 = 0f));
			float num = (result.M33 = (float.IsPositiveInfinity(farPlaneDistance) ? (-1f) : (farPlaneDistance / (nearPlaneDistance - farPlaneDistance))));
			result.M31 = (result.M32 = 0f);
			result.M34 = -1f;
			result.M41 = (result.M42 = (result.M44 = 0f));
			result.M43 = nearPlaneDistance * num;
			return result;
		}

		public static Matrix4x4 CreatePerspectiveOffCenter(float left, float right, float bottom, float top, float nearPlaneDistance, float farPlaneDistance)
		{
			if (nearPlaneDistance <= 0f)
			{
				throw new ArgumentOutOfRangeException("nearPlaneDistance");
			}
			if (farPlaneDistance <= 0f)
			{
				throw new ArgumentOutOfRangeException("farPlaneDistance");
			}
			if (nearPlaneDistance >= farPlaneDistance)
			{
				throw new ArgumentOutOfRangeException("nearPlaneDistance");
			}
			Matrix4x4 result = default(Matrix4x4);
			result.M11 = 2f * nearPlaneDistance / (right - left);
			result.M12 = (result.M13 = (result.M14 = 0f));
			result.M22 = 2f * nearPlaneDistance / (top - bottom);
			result.M21 = (result.M23 = (result.M24 = 0f));
			result.M31 = (left + right) / (right - left);
			result.M32 = (top + bottom) / (top - bottom);
			float num = (result.M33 = (float.IsPositiveInfinity(farPlaneDistance) ? (-1f) : (farPlaneDistance / (nearPlaneDistance - farPlaneDistance))));
			result.M34 = -1f;
			result.M43 = nearPlaneDistance * num;
			result.M41 = (result.M42 = (result.M44 = 0f));
			return result;
		}

		public static Matrix4x4 CreateOrthographic(float width, float height, float zNearPlane, float zFarPlane)
		{
			Matrix4x4 result = default(Matrix4x4);
			result.M11 = 2f / width;
			result.M12 = (result.M13 = (result.M14 = 0f));
			result.M22 = 2f / height;
			result.M21 = (result.M23 = (result.M24 = 0f));
			result.M33 = 1f / (zNearPlane - zFarPlane);
			result.M31 = (result.M32 = (result.M34 = 0f));
			result.M41 = (result.M42 = 0f);
			result.M43 = zNearPlane / (zNearPlane - zFarPlane);
			result.M44 = 1f;
			return result;
		}

		public static Matrix4x4 CreateOrthographicOffCenter(float left, float right, float bottom, float top, float zNearPlane, float zFarPlane)
		{
			Matrix4x4 result = default(Matrix4x4);
			result.M11 = 2f / (right - left);
			result.M12 = (result.M13 = (result.M14 = 0f));
			result.M22 = 2f / (top - bottom);
			result.M21 = (result.M23 = (result.M24 = 0f));
			result.M33 = 1f / (zNearPlane - zFarPlane);
			result.M31 = (result.M32 = (result.M34 = 0f));
			result.M41 = (left + right) / (left - right);
			result.M42 = (top + bottom) / (bottom - top);
			result.M43 = zNearPlane / (zNearPlane - zFarPlane);
			result.M44 = 1f;
			return result;
		}

		public static Matrix4x4 CreateLookAt(Vector3 cameraPosition, Vector3 cameraTarget, Vector3 cameraUpVector)
		{
			Vector3 vector = Vector3.Normalize(cameraPosition - cameraTarget);
			Vector3 vector2 = Vector3.Normalize(Vector3.Cross(cameraUpVector, vector));
			Vector3 vector3 = Vector3.Cross(vector, vector2);
			Matrix4x4 result = default(Matrix4x4);
			result.M11 = vector2.X;
			result.M12 = vector3.X;
			result.M13 = vector.X;
			result.M14 = 0f;
			result.M21 = vector2.Y;
			result.M22 = vector3.Y;
			result.M23 = vector.Y;
			result.M24 = 0f;
			result.M31 = vector2.Z;
			result.M32 = vector3.Z;
			result.M33 = vector.Z;
			result.M34 = 0f;
			result.M41 = 0f - Vector3.Dot(vector2, cameraPosition);
			result.M42 = 0f - Vector3.Dot(vector3, cameraPosition);
			result.M43 = 0f - Vector3.Dot(vector, cameraPosition);
			result.M44 = 1f;
			return result;
		}

		public static Matrix4x4 CreateWorld(Vector3 position, Vector3 forward, Vector3 up)
		{
			Vector3 vector = Vector3.Normalize(-forward);
			Vector3 vector2 = Vector3.Normalize(Vector3.Cross(up, vector));
			Vector3 vector3 = Vector3.Cross(vector, vector2);
			Matrix4x4 result = default(Matrix4x4);
			result.M11 = vector2.X;
			result.M12 = vector2.Y;
			result.M13 = vector2.Z;
			result.M14 = 0f;
			result.M21 = vector3.X;
			result.M22 = vector3.Y;
			result.M23 = vector3.Z;
			result.M24 = 0f;
			result.M31 = vector.X;
			result.M32 = vector.Y;
			result.M33 = vector.Z;
			result.M34 = 0f;
			result.M41 = position.X;
			result.M42 = position.Y;
			result.M43 = position.Z;
			result.M44 = 1f;
			return result;
		}

		public static Matrix4x4 CreateFromQuaternion(Quaternion quaternion)
		{
			float num = quaternion.X * quaternion.X;
			float num2 = quaternion.Y * quaternion.Y;
			float num3 = quaternion.Z * quaternion.Z;
			float num4 = quaternion.X * quaternion.Y;
			float num5 = quaternion.Z * quaternion.W;
			float num6 = quaternion.Z * quaternion.X;
			float num7 = quaternion.Y * quaternion.W;
			float num8 = quaternion.Y * quaternion.Z;
			float num9 = quaternion.X * quaternion.W;
			Matrix4x4 result = default(Matrix4x4);
			result.M11 = 1f - 2f * (num2 + num3);
			result.M12 = 2f * (num4 + num5);
			result.M13 = 2f * (num6 - num7);
			result.M14 = 0f;
			result.M21 = 2f * (num4 - num5);
			result.M22 = 1f - 2f * (num3 + num);
			result.M23 = 2f * (num8 + num9);
			result.M24 = 0f;
			result.M31 = 2f * (num6 + num7);
			result.M32 = 2f * (num8 - num9);
			result.M33 = 1f - 2f * (num2 + num);
			result.M34 = 0f;
			result.M41 = 0f;
			result.M42 = 0f;
			result.M43 = 0f;
			result.M44 = 1f;
			return result;
		}

		public static Matrix4x4 CreateFromYawPitchRoll(float yaw, float pitch, float roll)
		{
			return CreateFromQuaternion(Quaternion.CreateFromYawPitchRoll(yaw, pitch, roll));
		}

		public static Matrix4x4 CreateShadow(Vector3 lightDirection, Plane plane)
		{
			Plane plane2 = Plane.Normalize(plane);
			float num = plane2.Normal.X * lightDirection.X + plane2.Normal.Y * lightDirection.Y + plane2.Normal.Z * lightDirection.Z;
			float num2 = 0f - plane2.Normal.X;
			float num3 = 0f - plane2.Normal.Y;
			float num4 = 0f - plane2.Normal.Z;
			float num5 = 0f - plane2.D;
			Matrix4x4 result = default(Matrix4x4);
			result.M11 = num2 * lightDirection.X + num;
			result.M21 = num3 * lightDirection.X;
			result.M31 = num4 * lightDirection.X;
			result.M41 = num5 * lightDirection.X;
			result.M12 = num2 * lightDirection.Y;
			result.M22 = num3 * lightDirection.Y + num;
			result.M32 = num4 * lightDirection.Y;
			result.M42 = num5 * lightDirection.Y;
			result.M13 = num2 * lightDirection.Z;
			result.M23 = num3 * lightDirection.Z;
			result.M33 = num4 * lightDirection.Z + num;
			result.M43 = num5 * lightDirection.Z;
			result.M14 = 0f;
			result.M24 = 0f;
			result.M34 = 0f;
			result.M44 = num;
			return result;
		}

		public static Matrix4x4 CreateReflection(Plane value)
		{
			value = Plane.Normalize(value);
			float x = value.Normal.X;
			float y = value.Normal.Y;
			float z = value.Normal.Z;
			float num = -2f * x;
			float num2 = -2f * y;
			float num3 = -2f * z;
			Matrix4x4 result = default(Matrix4x4);
			result.M11 = num * x + 1f;
			result.M12 = num2 * x;
			result.M13 = num3 * x;
			result.M14 = 0f;
			result.M21 = num * y;
			result.M22 = num2 * y + 1f;
			result.M23 = num3 * y;
			result.M24 = 0f;
			result.M31 = num * z;
			result.M32 = num2 * z;
			result.M33 = num3 * z + 1f;
			result.M34 = 0f;
			result.M41 = num * value.D;
			result.M42 = num2 * value.D;
			result.M43 = num3 * value.D;
			result.M44 = 1f;
			return result;
		}

		public float GetDeterminant()
		{
			float m = M11;
			float m2 = M12;
			float m3 = M13;
			float m4 = M14;
			float m5 = M21;
			float m6 = M22;
			float m7 = M23;
			float m8 = M24;
			float m9 = M31;
			float m10 = M32;
			float m11 = M33;
			float m12 = M34;
			float m13 = M41;
			float m14 = M42;
			float m15 = M43;
			float m16 = M44;
			float num = m11 * m16 - m12 * m15;
			float num2 = m10 * m16 - m12 * m14;
			float num3 = m10 * m15 - m11 * m14;
			float num4 = m9 * m16 - m12 * m13;
			float num5 = m9 * m15 - m11 * m13;
			float num6 = m9 * m14 - m10 * m13;
			return m * (m6 * num - m7 * num2 + m8 * num3) - m2 * (m5 * num - m7 * num4 + m8 * num5) + m3 * (m5 * num2 - m6 * num4 + m8 * num6) - m4 * (m5 * num3 - m6 * num5 + m7 * num6);
		}

		public static bool Invert(Matrix4x4 matrix, out Matrix4x4 result)
		{
			float m = matrix.M11;
			float m2 = matrix.M12;
			float m3 = matrix.M13;
			float m4 = matrix.M14;
			float m5 = matrix.M21;
			float m6 = matrix.M22;
			float m7 = matrix.M23;
			float m8 = matrix.M24;
			float m9 = matrix.M31;
			float m10 = matrix.M32;
			float m11 = matrix.M33;
			float m12 = matrix.M34;
			float m13 = matrix.M41;
			float m14 = matrix.M42;
			float m15 = matrix.M43;
			float m16 = matrix.M44;
			float num = m11 * m16 - m12 * m15;
			float num2 = m10 * m16 - m12 * m14;
			float num3 = m10 * m15 - m11 * m14;
			float num4 = m9 * m16 - m12 * m13;
			float num5 = m9 * m15 - m11 * m13;
			float num6 = m9 * m14 - m10 * m13;
			float num7 = m6 * num - m7 * num2 + m8 * num3;
			float num8 = 0f - (m5 * num - m7 * num4 + m8 * num5);
			float num9 = m5 * num2 - m6 * num4 + m8 * num6;
			float num10 = 0f - (m5 * num3 - m6 * num5 + m7 * num6);
			float num11 = m * num7 + m2 * num8 + m3 * num9 + m4 * num10;
			if (MathF.Abs(num11) < float.Epsilon)
			{
				result = new Matrix4x4(float.NaN, float.NaN, float.NaN, float.NaN, float.NaN, float.NaN, float.NaN, float.NaN, float.NaN, float.NaN, float.NaN, float.NaN, float.NaN, float.NaN, float.NaN, float.NaN);
				return false;
			}
			float num12 = 1f / num11;
			result.M11 = num7 * num12;
			result.M21 = num8 * num12;
			result.M31 = num9 * num12;
			result.M41 = num10 * num12;
			result.M12 = (0f - (m2 * num - m3 * num2 + m4 * num3)) * num12;
			result.M22 = (m * num - m3 * num4 + m4 * num5) * num12;
			result.M32 = (0f - (m * num2 - m2 * num4 + m4 * num6)) * num12;
			result.M42 = (m * num3 - m2 * num5 + m3 * num6) * num12;
			float num13 = m7 * m16 - m8 * m15;
			float num14 = m6 * m16 - m8 * m14;
			float num15 = m6 * m15 - m7 * m14;
			float num16 = m5 * m16 - m8 * m13;
			float num17 = m5 * m15 - m7 * m13;
			float num18 = m5 * m14 - m6 * m13;
			result.M13 = (m2 * num13 - m3 * num14 + m4 * num15) * num12;
			result.M23 = (0f - (m * num13 - m3 * num16 + m4 * num17)) * num12;
			result.M33 = (m * num14 - m2 * num16 + m4 * num18) * num12;
			result.M43 = (0f - (m * num15 - m2 * num17 + m3 * num18)) * num12;
			float num19 = m7 * m12 - m8 * m11;
			float num20 = m6 * m12 - m8 * m10;
			float num21 = m6 * m11 - m7 * m10;
			float num22 = m5 * m12 - m8 * m9;
			float num23 = m5 * m11 - m7 * m9;
			float num24 = m5 * m10 - m6 * m9;
			result.M14 = (0f - (m2 * num19 - m3 * num20 + m4 * num21)) * num12;
			result.M24 = (m * num19 - m3 * num22 + m4 * num23) * num12;
			result.M34 = (0f - (m * num20 - m2 * num22 + m4 * num24)) * num12;
			result.M44 = (m * num21 - m2 * num23 + m3 * num24) * num12;
			return true;
		}

		public unsafe static bool Decompose(Matrix4x4 matrix, out Vector3 scale, out Quaternion rotation, out Vector3 translation)
		{
			bool result = true;
			fixed (Vector3* ptr = &scale)
			{
				float* ptr2 = (float*)ptr;
				VectorBasis vectorBasis = default(VectorBasis);
				Vector3** ptr3 = (Vector3**)(&vectorBasis);
				Matrix4x4 identity = Identity;
				CanonicalBasis canonicalBasis = default(CanonicalBasis);
				Vector3* ptr4 = &canonicalBasis.Row0;
				canonicalBasis.Row0 = new Vector3(1f, 0f, 0f);
				canonicalBasis.Row1 = new Vector3(0f, 1f, 0f);
				canonicalBasis.Row2 = new Vector3(0f, 0f, 1f);
				translation = new Vector3(matrix.M41, matrix.M42, matrix.M43);
				*ptr3 = (Vector3*)(&identity.M11);
				ptr3[1] = (Vector3*)(&identity.M21);
				ptr3[2] = (Vector3*)(&identity.M31);
				*(*ptr3) = new Vector3(matrix.M11, matrix.M12, matrix.M13);
				*ptr3[1] = new Vector3(matrix.M21, matrix.M22, matrix.M23);
				*ptr3[2] = new Vector3(matrix.M31, matrix.M32, matrix.M33);
				scale.X = (*ptr3)->Length();
				scale.Y = ptr3[1]->Length();
				scale.Z = ptr3[2]->Length();
				float num = *ptr2;
				float num2 = ptr2[1];
				float num3 = ptr2[2];
				uint num4;
				uint num5;
				uint num6;
				if (num < num2)
				{
					if (num2 < num3)
					{
						num4 = 2u;
						num5 = 1u;
						num6 = 0u;
					}
					else
					{
						num4 = 1u;
						if (num < num3)
						{
							num5 = 2u;
							num6 = 0u;
						}
						else
						{
							num5 = 0u;
							num6 = 2u;
						}
					}
				}
				else if (num < num3)
				{
					num4 = 2u;
					num5 = 0u;
					num6 = 1u;
				}
				else
				{
					num4 = 0u;
					if (num2 < num3)
					{
						num5 = 2u;
						num6 = 1u;
					}
					else
					{
						num5 = 1u;
						num6 = 2u;
					}
				}
				if (ptr2[num4] < 0.0001f)
				{
					*ptr3[num4] = ptr4[num4];
				}
				*ptr3[num4] = Vector3.Normalize(*ptr3[num4]);
				if (ptr2[num5] < 0.0001f)
				{
					float num7 = MathF.Abs(ptr3[num4]->X);
					float num8 = MathF.Abs(ptr3[num4]->Y);
					float num9 = MathF.Abs(ptr3[num4]->Z);
					uint num10 = ((num7 < num8) ? ((!(num8 < num9)) ? ((!(num7 < num9)) ? 2u : 0u) : 0u) : ((num7 < num9) ? 1u : ((num8 < num9) ? 1u : 2u)));
					*ptr3[num5] = Vector3.Cross(*ptr3[num4], ptr4[num10]);
				}
				*ptr3[num5] = Vector3.Normalize(*ptr3[num5]);
				if (ptr2[num6] < 0.0001f)
				{
					*ptr3[num6] = Vector3.Cross(*ptr3[num4], *ptr3[num5]);
				}
				*ptr3[num6] = Vector3.Normalize(*ptr3[num6]);
				float num11 = identity.GetDeterminant();
				if (num11 < 0f)
				{
					ptr2[num4] = 0f - ptr2[num4];
					*ptr3[num4] = -(*ptr3[num4]);
					num11 = 0f - num11;
				}
				num11 -= 1f;
				num11 *= num11;
				if (0.0001f < num11)
				{
					rotation = Quaternion.Identity;
					result = false;
				}
				else
				{
					rotation = Quaternion.CreateFromRotationMatrix(identity);
				}
			}
			return result;
		}

		public static Matrix4x4 Transform(Matrix4x4 value, Quaternion rotation)
		{
			float num = rotation.X + rotation.X;
			float num2 = rotation.Y + rotation.Y;
			float num3 = rotation.Z + rotation.Z;
			float num4 = rotation.W * num;
			float num5 = rotation.W * num2;
			float num6 = rotation.W * num3;
			float num7 = rotation.X * num;
			float num8 = rotation.X * num2;
			float num9 = rotation.X * num3;
			float num10 = rotation.Y * num2;
			float num11 = rotation.Y * num3;
			float num12 = rotation.Z * num3;
			float num13 = 1f - num10 - num12;
			float num14 = num8 - num6;
			float num15 = num9 + num5;
			float num16 = num8 + num6;
			float num17 = 1f - num7 - num12;
			float num18 = num11 - num4;
			float num19 = num9 - num5;
			float num20 = num11 + num4;
			float num21 = 1f - num7 - num10;
			Matrix4x4 result = default(Matrix4x4);
			result.M11 = value.M11 * num13 + value.M12 * num14 + value.M13 * num15;
			result.M12 = value.M11 * num16 + value.M12 * num17 + value.M13 * num18;
			result.M13 = value.M11 * num19 + value.M12 * num20 + value.M13 * num21;
			result.M14 = value.M14;
			result.M21 = value.M21 * num13 + value.M22 * num14 + value.M23 * num15;
			result.M22 = value.M21 * num16 + value.M22 * num17 + value.M23 * num18;
			result.M23 = value.M21 * num19 + value.M22 * num20 + value.M23 * num21;
			result.M24 = value.M24;
			result.M31 = value.M31 * num13 + value.M32 * num14 + value.M33 * num15;
			result.M32 = value.M31 * num16 + value.M32 * num17 + value.M33 * num18;
			result.M33 = value.M31 * num19 + value.M32 * num20 + value.M33 * num21;
			result.M34 = value.M34;
			result.M41 = value.M41 * num13 + value.M42 * num14 + value.M43 * num15;
			result.M42 = value.M41 * num16 + value.M42 * num17 + value.M43 * num18;
			result.M43 = value.M41 * num19 + value.M42 * num20 + value.M43 * num21;
			result.M44 = value.M44;
			return result;
		}

		public static Matrix4x4 Transpose(Matrix4x4 matrix)
		{
			Matrix4x4 result = default(Matrix4x4);
			result.M11 = matrix.M11;
			result.M12 = matrix.M21;
			result.M13 = matrix.M31;
			result.M14 = matrix.M41;
			result.M21 = matrix.M12;
			result.M22 = matrix.M22;
			result.M23 = matrix.M32;
			result.M24 = matrix.M42;
			result.M31 = matrix.M13;
			result.M32 = matrix.M23;
			result.M33 = matrix.M33;
			result.M34 = matrix.M43;
			result.M41 = matrix.M14;
			result.M42 = matrix.M24;
			result.M43 = matrix.M34;
			result.M44 = matrix.M44;
			return result;
		}

		public static Matrix4x4 Lerp(Matrix4x4 matrix1, Matrix4x4 matrix2, float amount)
		{
			Matrix4x4 result = default(Matrix4x4);
			result.M11 = matrix1.M11 + (matrix2.M11 - matrix1.M11) * amount;
			result.M12 = matrix1.M12 + (matrix2.M12 - matrix1.M12) * amount;
			result.M13 = matrix1.M13 + (matrix2.M13 - matrix1.M13) * amount;
			result.M14 = matrix1.M14 + (matrix2.M14 - matrix1.M14) * amount;
			result.M21 = matrix1.M21 + (matrix2.M21 - matrix1.M21) * amount;
			result.M22 = matrix1.M22 + (matrix2.M22 - matrix1.M22) * amount;
			result.M23 = matrix1.M23 + (matrix2.M23 - matrix1.M23) * amount;
			result.M24 = matrix1.M24 + (matrix2.M24 - matrix1.M24) * amount;
			result.M31 = matrix1.M31 + (matrix2.M31 - matrix1.M31) * amount;
			result.M32 = matrix1.M32 + (matrix2.M32 - matrix1.M32) * amount;
			result.M33 = matrix1.M33 + (matrix2.M33 - matrix1.M33) * amount;
			result.M34 = matrix1.M34 + (matrix2.M34 - matrix1.M34) * amount;
			result.M41 = matrix1.M41 + (matrix2.M41 - matrix1.M41) * amount;
			result.M42 = matrix1.M42 + (matrix2.M42 - matrix1.M42) * amount;
			result.M43 = matrix1.M43 + (matrix2.M43 - matrix1.M43) * amount;
			result.M44 = matrix1.M44 + (matrix2.M44 - matrix1.M44) * amount;
			return result;
		}

		public static Matrix4x4 Negate(Matrix4x4 value)
		{
			Matrix4x4 result = default(Matrix4x4);
			result.M11 = 0f - value.M11;
			result.M12 = 0f - value.M12;
			result.M13 = 0f - value.M13;
			result.M14 = 0f - value.M14;
			result.M21 = 0f - value.M21;
			result.M22 = 0f - value.M22;
			result.M23 = 0f - value.M23;
			result.M24 = 0f - value.M24;
			result.M31 = 0f - value.M31;
			result.M32 = 0f - value.M32;
			result.M33 = 0f - value.M33;
			result.M34 = 0f - value.M34;
			result.M41 = 0f - value.M41;
			result.M42 = 0f - value.M42;
			result.M43 = 0f - value.M43;
			result.M44 = 0f - value.M44;
			return result;
		}

		public static Matrix4x4 Add(Matrix4x4 value1, Matrix4x4 value2)
		{
			Matrix4x4 result = default(Matrix4x4);
			result.M11 = value1.M11 + value2.M11;
			result.M12 = value1.M12 + value2.M12;
			result.M13 = value1.M13 + value2.M13;
			result.M14 = value1.M14 + value2.M14;
			result.M21 = value1.M21 + value2.M21;
			result.M22 = value1.M22 + value2.M22;
			result.M23 = value1.M23 + value2.M23;
			result.M24 = value1.M24 + value2.M24;
			result.M31 = value1.M31 + value2.M31;
			result.M32 = value1.M32 + value2.M32;
			result.M33 = value1.M33 + value2.M33;
			result.M34 = value1.M34 + value2.M34;
			result.M41 = value1.M41 + value2.M41;
			result.M42 = value1.M42 + value2.M42;
			result.M43 = value1.M43 + value2.M43;
			result.M44 = value1.M44 + value2.M44;
			return result;
		}

		public static Matrix4x4 Subtract(Matrix4x4 value1, Matrix4x4 value2)
		{
			Matrix4x4 result = default(Matrix4x4);
			result.M11 = value1.M11 - value2.M11;
			result.M12 = value1.M12 - value2.M12;
			result.M13 = value1.M13 - value2.M13;
			result.M14 = value1.M14 - value2.M14;
			result.M21 = value1.M21 - value2.M21;
			result.M22 = value1.M22 - value2.M22;
			result.M23 = value1.M23 - value2.M23;
			result.M24 = value1.M24 - value2.M24;
			result.M31 = value1.M31 - value2.M31;
			result.M32 = value1.M32 - value2.M32;
			result.M33 = value1.M33 - value2.M33;
			result.M34 = value1.M34 - value2.M34;
			result.M41 = value1.M41 - value2.M41;
			result.M42 = value1.M42 - value2.M42;
			result.M43 = value1.M43 - value2.M43;
			result.M44 = value1.M44 - value2.M44;
			return result;
		}

		public static Matrix4x4 Multiply(Matrix4x4 value1, Matrix4x4 value2)
		{
			Matrix4x4 result = default(Matrix4x4);
			result.M11 = value1.M11 * value2.M11 + value1.M12 * value2.M21 + value1.M13 * value2.M31 + value1.M14 * value2.M41;
			result.M12 = value1.M11 * value2.M12 + value1.M12 * value2.M22 + value1.M13 * value2.M32 + value1.M14 * value2.M42;
			result.M13 = value1.M11 * value2.M13 + value1.M12 * value2.M23 + value1.M13 * value2.M33 + value1.M14 * value2.M43;
			result.M14 = value1.M11 * value2.M14 + value1.M12 * value2.M24 + value1.M13 * value2.M34 + value1.M14 * value2.M44;
			result.M21 = value1.M21 * value2.M11 + value1.M22 * value2.M21 + value1.M23 * value2.M31 + value1.M24 * value2.M41;
			result.M22 = value1.M21 * value2.M12 + value1.M22 * value2.M22 + value1.M23 * value2.M32 + value1.M24 * value2.M42;
			result.M23 = value1.M21 * value2.M13 + value1.M22 * value2.M23 + value1.M23 * value2.M33 + value1.M24 * value2.M43;
			result.M24 = value1.M21 * value2.M14 + value1.M22 * value2.M24 + value1.M23 * value2.M34 + value1.M24 * value2.M44;
			result.M31 = value1.M31 * value2.M11 + value1.M32 * value2.M21 + value1.M33 * value2.M31 + value1.M34 * value2.M41;
			result.M32 = value1.M31 * value2.M12 + value1.M32 * value2.M22 + value1.M33 * value2.M32 + value1.M34 * value2.M42;
			result.M33 = value1.M31 * value2.M13 + value1.M32 * value2.M23 + value1.M33 * value2.M33 + value1.M34 * value2.M43;
			result.M34 = value1.M31 * value2.M14 + value1.M32 * value2.M24 + value1.M33 * value2.M34 + value1.M34 * value2.M44;
			result.M41 = value1.M41 * value2.M11 + value1.M42 * value2.M21 + value1.M43 * value2.M31 + value1.M44 * value2.M41;
			result.M42 = value1.M41 * value2.M12 + value1.M42 * value2.M22 + value1.M43 * value2.M32 + value1.M44 * value2.M42;
			result.M43 = value1.M41 * value2.M13 + value1.M42 * value2.M23 + value1.M43 * value2.M33 + value1.M44 * value2.M43;
			result.M44 = value1.M41 * value2.M14 + value1.M42 * value2.M24 + value1.M43 * value2.M34 + value1.M44 * value2.M44;
			return result;
		}

		public static Matrix4x4 Multiply(Matrix4x4 value1, float value2)
		{
			Matrix4x4 result = default(Matrix4x4);
			result.M11 = value1.M11 * value2;
			result.M12 = value1.M12 * value2;
			result.M13 = value1.M13 * value2;
			result.M14 = value1.M14 * value2;
			result.M21 = value1.M21 * value2;
			result.M22 = value1.M22 * value2;
			result.M23 = value1.M23 * value2;
			result.M24 = value1.M24 * value2;
			result.M31 = value1.M31 * value2;
			result.M32 = value1.M32 * value2;
			result.M33 = value1.M33 * value2;
			result.M34 = value1.M34 * value2;
			result.M41 = value1.M41 * value2;
			result.M42 = value1.M42 * value2;
			result.M43 = value1.M43 * value2;
			result.M44 = value1.M44 * value2;
			return result;
		}

		public static Matrix4x4 operator -(Matrix4x4 value)
		{
			Matrix4x4 result = default(Matrix4x4);
			result.M11 = 0f - value.M11;
			result.M12 = 0f - value.M12;
			result.M13 = 0f - value.M13;
			result.M14 = 0f - value.M14;
			result.M21 = 0f - value.M21;
			result.M22 = 0f - value.M22;
			result.M23 = 0f - value.M23;
			result.M24 = 0f - value.M24;
			result.M31 = 0f - value.M31;
			result.M32 = 0f - value.M32;
			result.M33 = 0f - value.M33;
			result.M34 = 0f - value.M34;
			result.M41 = 0f - value.M41;
			result.M42 = 0f - value.M42;
			result.M43 = 0f - value.M43;
			result.M44 = 0f - value.M44;
			return result;
		}

		public static Matrix4x4 operator +(Matrix4x4 value1, Matrix4x4 value2)
		{
			Matrix4x4 result = default(Matrix4x4);
			result.M11 = value1.M11 + value2.M11;
			result.M12 = value1.M12 + value2.M12;
			result.M13 = value1.M13 + value2.M13;
			result.M14 = value1.M14 + value2.M14;
			result.M21 = value1.M21 + value2.M21;
			result.M22 = value1.M22 + value2.M22;
			result.M23 = value1.M23 + value2.M23;
			result.M24 = value1.M24 + value2.M24;
			result.M31 = value1.M31 + value2.M31;
			result.M32 = value1.M32 + value2.M32;
			result.M33 = value1.M33 + value2.M33;
			result.M34 = value1.M34 + value2.M34;
			result.M41 = value1.M41 + value2.M41;
			result.M42 = value1.M42 + value2.M42;
			result.M43 = value1.M43 + value2.M43;
			result.M44 = value1.M44 + value2.M44;
			return result;
		}

		public static Matrix4x4 operator -(Matrix4x4 value1, Matrix4x4 value2)
		{
			Matrix4x4 result = default(Matrix4x4);
			result.M11 = value1.M11 - value2.M11;
			result.M12 = value1.M12 - value2.M12;
			result.M13 = value1.M13 - value2.M13;
			result.M14 = value1.M14 - value2.M14;
			result.M21 = value1.M21 - value2.M21;
			result.M22 = value1.M22 - value2.M22;
			result.M23 = value1.M23 - value2.M23;
			result.M24 = value1.M24 - value2.M24;
			result.M31 = value1.M31 - value2.M31;
			result.M32 = value1.M32 - value2.M32;
			result.M33 = value1.M33 - value2.M33;
			result.M34 = value1.M34 - value2.M34;
			result.M41 = value1.M41 - value2.M41;
			result.M42 = value1.M42 - value2.M42;
			result.M43 = value1.M43 - value2.M43;
			result.M44 = value1.M44 - value2.M44;
			return result;
		}

		public static Matrix4x4 operator *(Matrix4x4 value1, Matrix4x4 value2)
		{
			Matrix4x4 result = default(Matrix4x4);
			result.M11 = value1.M11 * value2.M11 + value1.M12 * value2.M21 + value1.M13 * value2.M31 + value1.M14 * value2.M41;
			result.M12 = value1.M11 * value2.M12 + value1.M12 * value2.M22 + value1.M13 * value2.M32 + value1.M14 * value2.M42;
			result.M13 = value1.M11 * value2.M13 + value1.M12 * value2.M23 + value1.M13 * value2.M33 + value1.M14 * value2.M43;
			result.M14 = value1.M11 * value2.M14 + value1.M12 * value2.M24 + value1.M13 * value2.M34 + value1.M14 * value2.M44;
			result.M21 = value1.M21 * value2.M11 + value1.M22 * value2.M21 + value1.M23 * value2.M31 + value1.M24 * value2.M41;
			result.M22 = value1.M21 * value2.M12 + value1.M22 * value2.M22 + value1.M23 * value2.M32 + value1.M24 * value2.M42;
			result.M23 = value1.M21 * value2.M13 + value1.M22 * value2.M23 + value1.M23 * value2.M33 + value1.M24 * value2.M43;
			result.M24 = value1.M21 * value2.M14 + value1.M22 * value2.M24 + value1.M23 * value2.M34 + value1.M24 * value2.M44;
			result.M31 = value1.M31 * value2.M11 + value1.M32 * value2.M21 + value1.M33 * value2.M31 + value1.M34 * value2.M41;
			result.M32 = value1.M31 * value2.M12 + value1.M32 * value2.M22 + value1.M33 * value2.M32 + value1.M34 * value2.M42;
			result.M33 = value1.M31 * value2.M13 + value1.M32 * value2.M23 + value1.M33 * value2.M33 + value1.M34 * value2.M43;
			result.M34 = value1.M31 * value2.M14 + value1.M32 * value2.M24 + value1.M33 * value2.M34 + value1.M34 * value2.M44;
			result.M41 = value1.M41 * value2.M11 + value1.M42 * value2.M21 + value1.M43 * value2.M31 + value1.M44 * value2.M41;
			result.M42 = value1.M41 * value2.M12 + value1.M42 * value2.M22 + value1.M43 * value2.M32 + value1.M44 * value2.M42;
			result.M43 = value1.M41 * value2.M13 + value1.M42 * value2.M23 + value1.M43 * value2.M33 + value1.M44 * value2.M43;
			result.M44 = value1.M41 * value2.M14 + value1.M42 * value2.M24 + value1.M43 * value2.M34 + value1.M44 * value2.M44;
			return result;
		}

		public static Matrix4x4 operator *(Matrix4x4 value1, float value2)
		{
			Matrix4x4 result = default(Matrix4x4);
			result.M11 = value1.M11 * value2;
			result.M12 = value1.M12 * value2;
			result.M13 = value1.M13 * value2;
			result.M14 = value1.M14 * value2;
			result.M21 = value1.M21 * value2;
			result.M22 = value1.M22 * value2;
			result.M23 = value1.M23 * value2;
			result.M24 = value1.M24 * value2;
			result.M31 = value1.M31 * value2;
			result.M32 = value1.M32 * value2;
			result.M33 = value1.M33 * value2;
			result.M34 = value1.M34 * value2;
			result.M41 = value1.M41 * value2;
			result.M42 = value1.M42 * value2;
			result.M43 = value1.M43 * value2;
			result.M44 = value1.M44 * value2;
			return result;
		}

		public static bool operator ==(Matrix4x4 value1, Matrix4x4 value2)
		{
			if (value1.M11 == value2.M11 && value1.M22 == value2.M22 && value1.M33 == value2.M33 && value1.M44 == value2.M44 && value1.M12 == value2.M12 && value1.M13 == value2.M13 && value1.M14 == value2.M14 && value1.M21 == value2.M21 && value1.M23 == value2.M23 && value1.M24 == value2.M24 && value1.M31 == value2.M31 && value1.M32 == value2.M32 && value1.M34 == value2.M34 && value1.M41 == value2.M41 && value1.M42 == value2.M42)
			{
				return value1.M43 == value2.M43;
			}
			return false;
		}

		public static bool operator !=(Matrix4x4 value1, Matrix4x4 value2)
		{
			if (value1.M11 == value2.M11 && value1.M12 == value2.M12 && value1.M13 == value2.M13 && value1.M14 == value2.M14 && value1.M21 == value2.M21 && value1.M22 == value2.M22 && value1.M23 == value2.M23 && value1.M24 == value2.M24 && value1.M31 == value2.M31 && value1.M32 == value2.M32 && value1.M33 == value2.M33 && value1.M34 == value2.M34 && value1.M41 == value2.M41 && value1.M42 == value2.M42 && value1.M43 == value2.M43)
			{
				return value1.M44 != value2.M44;
			}
			return true;
		}

		public bool Equals(Matrix4x4 other)
		{
			if (M11 == other.M11 && M22 == other.M22 && M33 == other.M33 && M44 == other.M44 && M12 == other.M12 && M13 == other.M13 && M14 == other.M14 && M21 == other.M21 && M23 == other.M23 && M24 == other.M24 && M31 == other.M31 && M32 == other.M32 && M34 == other.M34 && M41 == other.M41 && M42 == other.M42)
			{
				return M43 == other.M43;
			}
			return false;
		}

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

		public override string ToString()
		{
			CultureInfo currentCulture = CultureInfo.CurrentCulture;
			return string.Format(currentCulture, "{{ {{M11:{0} M12:{1} M13:{2} M14:{3}}} {{M21:{4} M22:{5} M23:{6} M24:{7}}} {{M31:{8} M32:{9} M33:{10} M34:{11}}} {{M41:{12} M42:{13} M43:{14} M44:{15}}} }}", M11.ToString(currentCulture), M12.ToString(currentCulture), M13.ToString(currentCulture), M14.ToString(currentCulture), M21.ToString(currentCulture), M22.ToString(currentCulture), M23.ToString(currentCulture), M24.ToString(currentCulture), M31.ToString(currentCulture), M32.ToString(currentCulture), M33.ToString(currentCulture), M34.ToString(currentCulture), M41.ToString(currentCulture), M42.ToString(currentCulture), M43.ToString(currentCulture), M44.ToString(currentCulture));
		}

		public override int GetHashCode()
		{
			return M11.GetHashCode() + M12.GetHashCode() + M13.GetHashCode() + M14.GetHashCode() + M21.GetHashCode() + M22.GetHashCode() + M23.GetHashCode() + M24.GetHashCode() + M31.GetHashCode() + M32.GetHashCode() + M33.GetHashCode() + M34.GetHashCode() + M41.GetHashCode() + M42.GetHashCode() + M43.GetHashCode() + M44.GetHashCode();
		}
	}
	public struct Plane : IEquatable<Plane>
	{
		public Vector3 Normal;

		public float D;

		public Plane(float x, float y, float z, float d)
		{
			Normal = new Vector3(x, y, z);
			D = d;
		}

		public Plane(Vector3 normal, float d)
		{
			Normal = normal;
			D = d;
		}

		public Plane(Vector4 value)
		{
			Normal = new Vector3(value.X, value.Y, value.Z);
			D = value.W;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static Plane CreateFromVertices(Vector3 point1, Vector3 point2, Vector3 point3)
		{
			if (Vector.IsHardwareAccelerated)
			{
				Vector3 vector = point2 - point1;
				Vector3 vector2 = point3 - point1;
				Vector3 vector3 = Vector3.Normalize(Vector3.Cross(vector, vector2));
				float d = 0f - Vector3.Dot(vector3, point1);
				return new Plane(vector3, d);
			}
			float num = point2.X - point1.X;
			float num2 = point2.Y - point1.Y;
			float num3 = point2.Z - point1.Z;
			float num4 = point3.X - point1.X;
			float num5 = point3.Y - point1.Y;
			float num6 = point3.Z - point1.Z;
			float num7 = num2 * num6 - num3 * num5;
			float num8 = num3 * num4 - num * num6;
			float num9 = num * num5 - num2 * num4;
			float num10 = num7 * num7 + num8 * num8 + num9 * num9;
			float num11 = 1f / MathF.Sqrt(num10);
			Vector3 normal = new Vector3(num7 * num11, num8 * num11, num9 * num11);
			return new Plane(normal, 0f - (normal.X * point1.X + normal.Y * point1.Y + normal.Z * point1.Z));
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static Plane Normalize(Plane value)
		{
			if (Vector.IsHardwareAccelerated)
			{
				float num = value.Normal.LengthSquared();
				if (MathF.Abs(num - 1f) < 1.1920929E-07f)
				{
					return value;
				}
				float num2 = MathF.Sqrt(num);
				return new Plane(value.Normal / num2, value.D / num2);
			}
			float num3 = value.Normal.X * value.Normal.X + value.Normal.Y * value.Normal.Y + value.Normal.Z * value.Normal.Z;
			if (MathF.Abs(num3 - 1f) < 1.1920929E-07f)
			{
				return value;
			}
			float num4 = 1f / MathF.Sqrt(num3);
			return new Plane(value.Normal.X * num4, value.Normal.Y * num4, value.Normal.Z * num4, value.D * num4);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static Plane Transform(Plane plane, Matrix4x4 matrix)
		{
			Matrix4x4.Invert(matrix, out var result);
			float x = plane.Normal.X;
			float y = plane.Normal.Y;
			float z = plane.Normal.Z;
			float d = plane.D;
			return new Plane(x * result.M11 + y * result.M12 + z * result.M13 + d * result.M14, x * result.M21 + y * result.M22 + z * result.M23 + d * result.M24, x * result.M31 + y * result.M32 + z * result.M33 + d * result.M34, x * result.M41 + y * result.M42 + z * result.M43 + d * result.M44);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static Plane Transform(Plane plane, Quaternion rotation)
		{
			float num = rotation.X + rotation.X;
			float num2 = rotation.Y + rotation.Y;
			float num3 = rotation.Z + rotation.Z;
			float num4 = rotation.W * num;
			float num5 = rotation.W * num2;
			float num6 = rotation.W * num3;
			float num7 = rotation.X * num;
			float num8 = rotation.X * num2;
			float num9 = rotation.X * num3;
			float num10 = rotation.Y * num2;
			float num11 = rotation.Y * num3;
			float num12 = rotation.Z * num3;
			float num13 = 1f - num10 - num12;
			float num14 = num8 - num6;
			float num15 = num9 + num5;
			float num16 = num8 + num6;
			float num17 = 1f - num7 - num12;
			float num18 = num11 - num4;
			float num19 = num9 - num5;
			float num20 = num11 + num4;
			float num21 = 1f - num7 - num10;
			float x = plane.Normal.X;
			float y = plane.Normal.Y;
			float z = plane.Normal.Z;
			return new Plane(x * num13 + y * num14 + z * num15, x * num16 + y * num17 + z * num18, x * num19 + y * num20 + z * num21, plane.D);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static float Dot(Plane plane, Vector4 value)
		{
			return plane.Normal.X * value.X + plane.Normal.Y * value.Y + plane.Normal.Z * value.Z + plane.D * value.W;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static float DotCoordinate(Plane plane, Vector3 value)
		{
			if (Vector.IsHardwareAccelerated)
			{
				return Vector3.Dot(plane.Normal, value) + plane.D;
			}
			return plane.Normal.X * value.X + plane.Normal.Y * value.Y + plane.Normal.Z * value.Z + plane.D;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static float DotNormal(Plane plane, Vector3 value)
		{
			if (Vector.IsHardwareAccelerated)
			{
				return Vector3.Dot(plane.Normal, value);
			}
			return plane.Normal.X * value.X + plane.Normal.Y * value.Y + plane.Normal.Z * value.Z;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static bool operator ==(Plane value1, Plane value2)
		{
			if (value1.Normal.X == value2.Normal.X && value1.Normal.Y == value2.Normal.Y && value1.Normal.Z == value2.Normal.Z)
			{
				return value1.D == value2.D;
			}
			return false;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static bool operator !=(Plane value1, Plane value2)
		{
			if (value1.Normal.X == value2.Normal.X && value1.Normal.Y == value2.Normal.Y && value1.Normal.Z == value2.Normal.Z)
			{
				return value1.D != value2.D;
			}
			return true;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public bool Equals(Plane other)
		{
			if (Vector.IsHardwareAccelerated)
			{
				if (Normal.Equals(other.Normal))
				{
					return D == other.D;
				}
				return false;
			}
			if (Normal.X == other.Normal.X && Normal.Y == other.Normal.Y && Normal.Z == other.Normal.Z)
			{
				return D == other.D;
			}
			return false;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public override bool Equals(object obj)
		{
			if (obj is Plane)
			{
				return Equals((Plane)obj);
			}
			return false;
		}

		public override string ToString()
		{
			CultureInfo currentCulture = CultureInfo.CurrentCulture;
			return string.Format(currentCulture, "{{Normal:{0} D:{1}}}", Normal.ToString(), D.ToString(currentCulture));
		}

		public override int GetHashCode()
		{
			return Normal.GetHashCode() + D.GetHashCode();
		}
	}
	public struct Quaternion : IEquatable<Quaternion>
	{
		public float X;

		public float Y;

		public float Z;

		public float W;

		public static Quaternion Identity => new Quaternion(0f, 0f, 0f, 1f);

		public bool IsIdentity
		{
			get
			{
				if (X == 0f && Y == 0f && Z == 0f)
				{
					return W == 1f;
				}
				return false;
			}
		}

		public Quaternion(float x, float y, float z, float w)
		{
			X = x;
			Y = y;
			Z = z;
			W = w;
		}

		public Quaternion(Vector3 vectorPart, float scalarPart)
		{
			X = vectorPart.X;
			Y = vectorPart.Y;
			Z = vectorPart.Z;
			W = scalarPart;
		}

		public float Length()
		{
			return MathF.Sqrt(X * X + Y * Y + Z * Z + W * W);
		}

		public float LengthSquared()
		{
			return X * X + Y * Y + Z * Z + W * W;
		}

		public static Quaternion Normalize(Quaternion value)
		{
			float num = value.X * value.X + value.Y * value.Y + value.Z * value.Z + value.W * value.W;
			float num2 = 1f / MathF.Sqrt(num);
			Quaternion result = default(Quaternion);
			result.X = value.X * num2;
			result.Y = value.Y * num2;
			result.Z = value.Z * num2;
			result.W = value.W * num2;
			return result;
		}

		public static Quaternion Conjugate(Quaternion value)
		{
			Quaternion result = default(Quaternion);
			result.X = 0f - value.X;
			result.Y = 0f - value.Y;
			result.Z = 0f - value.Z;
			result.W = value.W;
			return result;
		}

		public static Quaternion Inverse(Quaternion value)
		{
			float num = value.X * value.X + value.Y * value.Y + value.Z * value.Z + value.W * value.W;
			float num2 = 1f / num;
			Quaternion result = default(Quaternion);
			result.X = (0f - value.X) * num2;
			result.Y = (0f - value.Y) * num2;
			result.Z = (0f - value.Z) * num2;
			result.W = value.W * num2;
			return result;
		}

		public static Quaternion CreateFromAxisAngle(Vector3 axis, float angle)
		{
			float num = angle * 0.5f;
			float num2 = MathF.Sin(num);
			float w = MathF.Cos(num);
			Quaternion result = default(Quaternion);
			result.X = axis.X * num2;
			result.Y = axis.Y * num2;
			result.Z = axis.Z * num2;
			result.W = w;
			return result;
		}

		public static Quaternion CreateFromYawPitchRoll(float yaw, float pitch, float roll)
		{
			float num = roll * 0.5f;
			float num2 = MathF.Sin(num);
			float num3 = MathF.Cos(num);
			float num4 = pitch * 0.5f;
			float num5 = MathF.Sin(num4);
			float num6 = MathF.Cos(num4);
			float num7 = yaw * 0.5f;
			float num8 = MathF.Sin(num7);
			float num9 = MathF.Cos(num7);
			Quaternion result = default(Quaternion);
			result.X = num9 * num5 * num3 + num8 * num6 * num2;
			result.Y = num8 * num6 * num3 - num9 * num5 * num2;
			result.Z = num9 * num6 * num2 - num8 * num5 * num3;
			result.W = num9 * num6 * num3 + num8 * num5 * num2;
			return result;
		}

		public static Quaternion CreateFromRotationMatrix(Matrix4x4 matrix)
		{
			float num = matrix.M11 + matrix.M22 + matrix.M33;
			Quaternion result = default(Quaternion);
			if (num > 0f)
			{
				float num2 = MathF.Sqrt(num + 1f);
				result.W = num2 * 0.5f;
				num2 = 0.5f / num2;
				result.X = (matrix.M23 - matrix.M32) * num2;
				result.Y = (matrix.M31 - matrix.M13) * num2;
				result.Z = (matrix.M12 - matrix.M21) * num2;
			}
			else if (matrix.M11 >= matrix.M22 && matrix.M11 >= matrix.M33)
			{
				float num3 = MathF.Sqrt(1f + matrix.M11 - matrix.M22 - matrix.M33);
				float num4 = 0.5f / num3;
				result.X = 0.5f * num3;
				result.Y = (matrix.M12 + matrix.M21) * num4;
				result.Z = (matrix.M13 + matrix.M31) * num4;
				result.W = (matrix.M23 - matrix.M32) * num4;
			}
			else if (matrix.M22 > matrix.M33)
			{
				float num5 = MathF.Sqrt(1f + matrix.M22 - matrix.M11 - matrix.M33);
				float num6 = 0.5f / num5;
				result.X = (matrix.M21 + matrix.M12) * num6;
				result.Y = 0.5f * num5;
				result.Z = (matrix.M32 + matrix.M23) * num6;
				result.W = (matrix.M31 - matrix.M13) * num6;
			}
			else
			{
				float num7 = MathF.Sqrt(1f + matrix.M33 - matrix.M11 - matrix.M22);
				float num8 = 0.5f / num7;
				result.X = (matrix.M31 + matrix.M13) * num8;
				result.Y = (matrix.M32 + matrix.M23) * num8;
				result.Z = 0.5f * num7;
				result.W = (matrix.M12 - matrix.M21) * num8;
			}
			return result;
		}

		public static float Dot(Quaternion quaternion1, Quaternion quaternion2)
		{
			return quaternion1.X * quaternion2.X + quaternion1.Y * quaternion2.Y + quaternion1.Z * quaternion2.Z + quaternion1.W * quaternion2.W;
		}

		public static Quaternion Slerp(Quaternion quaternion1, Quaternion quaternion2, float amount)
		{
			float num = quaternion1.X * quaternion2.X + quaternion1.Y * quaternion2.Y + quaternion1.Z * quaternion2.Z + quaternion1.W * quaternion2.W;
			bool flag = false;
			if (num < 0f)
			{
				flag = true;
				num = 0f - num;
			}
			float num2;
			float num3;
			if (num > 0.999999f)
			{
				num2 = 1f - amount;
				num3 = (flag ? (0f - amount) : amount);
			}
			else
			{
				float num4 = MathF.Acos(num);
				float num5 = 1f / MathF.Sin(num4);
				num2 = MathF.Sin((1f - amount) * num4) * num5;
				num3 = (flag ? ((0f - MathF.Sin(amount * num4)) * num5) : (MathF.Sin(amount * num4) * num5));
			}
			Quaternion result = default(Quaternion);
			result.X = num2 * quaternion1.X + num3 * quaternion2.X;
			result.Y = num2 * quaternion1.Y + num3 * quaternion2.Y;
			result.Z = num2 * quaternion1.Z + num3 * quaternion2.Z;
			result.W = num2 * quaternion1.W + num3 * quaternion2.W;
			return result;
		}

		public static Quaternion Lerp(Quaternion quaternion1, Quaternion quaternion2, float amount)
		{
			float num = 1f - amount;
			Quaternion result = default(Quaternion);
			if (quaternion1.X * quaternion2.X + quaternion1.Y * quaternion2.Y + quaternion1.Z * quaternion2.Z + quaternion1.W * quaternion2.W >= 0f)
			{
				result.X = num * quaternion1.X + amount * quaternion2.X;
				result.Y = num * quaternion1.Y + amount * quaternion2.Y;
				result.Z = num * quaternion1.Z + amount * quaternion2.Z;
				result.W = num * quaternion1.W + amount * quaternion2.W;
			}
			else
			{
				result.X = num * quaternion1.X - amount * quaternion2.X;
				result.Y = num * quaternion1.Y - amount * quaternion2.Y;
				result.Z = num * quaternion1.Z - amount * quaternion2.Z;
				result.W = num * quaternion1.W - amount * quaternion2.W;
			}
			float num2 = result.X * result.X + result.Y * result.Y + result.Z * result.Z + result.W * result.W;
			float num3 = 1f / MathF.Sqrt(num2);
			result.X *= num3;
			result.Y *= num3;
			result.Z *= num3;
			result.W *= num3;
			return result;
		}

		public static Quaternion Concatenate(Quaternion value1, Quaternion value2)
		{
			float x = value2.X;
			float y = value2.Y;
			float z = value2.Z;
			float w = value2.W;
			float x2 = value1.X;
			float y2 = value1.Y;
			float z2 = value1.Z;
			float w2 = value1.W;
			float num = y * z2 - z * y2;
			float num2 = z * x2 - x * z2;
			float num3 = x * y2 - y * x2;
			float num4 = x * x2 + y * y2 + z * z2;
			Quaternion result = default(Quaternion);
			result.X = x * w2 + x2 * w + num;
			result.Y = y * w2 + y2 * w + num2;
			result.Z = z * w2 + z2 * w + num3;
			result.W = w * w2 - num4;
			return result;
		}

		public static Quaternion Negate(Quaternion value)
		{
			Quaternion result = default(Quaternion);
			result.X = 0f - value.X;
			result.Y = 0f - value.Y;
			result.Z = 0f - value.Z;
			result.W = 0f - value.W;
			return result;
		}

		public static Quaternion Add(Quaternion value1, Quaternion value2)
		{
			Quaternion result = default(Quaternion);
			result.X = value1.X + value2.X;
			result.Y = value1.Y + value2.Y;
			result.Z = value1.Z + value2.Z;
			result.W = value1.W + value2.W;
			return result;
		}

		public static Quaternion Subtract(Quaternion value1, Quaternion value2)
		{
			Quaternion result = default(Quaternion);
			result.X = value1.X - value2.X;
			result.Y = value1.Y - value2.Y;
			result.Z = value1.Z - value2.Z;
			result.W = value1.W - value2.W;
			return result;
		}

		public static Quaternion Multiply(Quaternion value1, Quaternion value2)
		{
			float x = value1.X;
			float y = value1.Y;
			float z = value1.Z;
			float w = value1.W;
			float x2 = value2.X;
			float y2 = value2.Y;
			float z2 = value2.Z;
			float w2 = value2.W;
			float num = y * z2 - z * y2;
			float num2 = z * x2 - x * z2;
			float num3 = x * y2 - y * x2;
			float num4 = x * x2 + y * y2 + z * z2;
			Quaternion result = default(Quaternion);
			result.X = x * w2 + x2 * w + num;
			result.Y = y * w2 + y2 * w + num2;
			result.Z = z * w2 + z2 * w + num3;
			result.W = w * w2 - num4;
			return result;
		}

		public static Quaternion Multiply(Quaternion value1, float value2)
		{
			Quaternion result = default(Quaternion);
			result.X = value1.X * value2;
			result.Y = value1.Y * value2;
			result.Z = value1.Z * value2;
			result.W = value1.W * value2;
			return result;
		}

		public static Quaternion Divide(Quaternion value1, Quaternion value2)
		{
			float x = value1.X;
			float y = value1.Y;
			float z = value1.Z;
			float w = value1.W;
			float num = value2.X * value2.X + value2.Y * value2.Y + value2.Z * value2.Z + value2.W * value2.W;
			float num2 = 1f / num;
			float num3 = (0f - value2.X) * num2;
			float num4 = (0f - value2.Y) * num2;
			float num5 = (0f - value2.Z) * num2;
			float num6 = value2.W * num2;
			float num7 = y * num5 - z * num4;
			float num8 = z * num3 - x * num5;
			float num9 = x * num4 - y * num3;
			float num10 = x * num3 + y * num4 + z * num5;
			Quaternion result = default(Quaternion);
			result.X = x * num6 + num3 * w + num7;
			result.Y = y * num6 + num4 * w + num8;
			result.Z = z * num6 + num5 * w + num9;
			result.W = w * num6 - num10;
			return result;
		}

		public static Quaternion operator -(Quaternion value)
		{
			Quaternion result = default(Quaternion);
			result.X = 0f - value.X;
			result.Y = 0f - value.Y;
			result.Z = 0f - value.Z;
			result.W = 0f - value.W;
			return result;
		}

		public static Quaternion operator +(Quaternion value1, Quaternion value2)
		{
			Quaternion result = default(Quaternion);
			result.X = value1.X + value2.X;
			result.Y = value1.Y + value2.Y;
			result.Z = value1.Z + value2.Z;
			result.W = value1.W + value2.W;
			return result;
		}

		public static Quaternion operator -(Quaternion value1, Quaternion value2)
		{
			Quaternion result = default(Quaternion);
			result.X = value1.X - value2.X;
			result.Y = value1.Y - value2.Y;
			result.Z = value1.Z - value2.Z;
			result.W = value1.W - value2.W;
			return result;
		}

		public static Quaternion operator *(Quaternion value1, Quaternion value2)
		{
			float x = value1.X;
			float y = value1.Y;
			float z = value1.Z;
			float w = value1.W;
			float x2 = value2.X;
			float y2 = value2.Y;
			float z2 = value2.Z;
			float w2 = value2.W;
			float num = y * z2 - z * y2;
			float num2 = z * x2 - x * z2;
			float num3 = x * y2 - y * x2;
			float num4 = x * x2 + y * y2 + z * z2;
			Quaternion result = default(Quaternion);
			result.X = x * w2 + x2 * w + num;
			result.Y = y * w2 + y2 * w + num2;
			result.Z = z * w2 + z2 * w + num3;
			result.W = w * w2 - num4;
			return result;
		}

		public static Quaternion operator *(Quaternion value1, float value2)
		{
			Quaternion result = default(Quaternion);
			result.X = value1.X * value2;
			result.Y = value1.Y * value2;
			result.Z = value1.Z * value2;
			result.W = value1.W * value2;
			return result;
		}

		public static Quaternion operator /(Quaternion value1, Quaternion value2)
		{
			float x = value1.X;
			float y = value1.Y;
			float z = value1.Z;
			float w = value1.W;
			float num = value2.X * value2.X + value2.Y * value2.Y + value2.Z * value2.Z + value2.W * value2.W;
			float num2 = 1f / num;
			float num3 = (0f - value2.X) * num2;
			float num4 = (0f - value2.Y) * num2;
			float num5 = (0f - value2.Z) * num2;
			float num6 = value2.W * num2;
			float num7 = y * num5 - z * num4;
			float num8 = z * num3 - x * num5;
			float num9 = x * num4 - y * num3;
			float num10 = x * num3 + y * num4 + z * num5;
			Quaternion result = default(Quaternion);
			result.X = x * num6 + num3 * w + num7;
			result.Y = y * num6 + num4 * w + num8;
			result.Z = z * num6 + num5 * w + num9;
			result.W = w * num6 - num10;
			return result;
		}

		public static bool operator ==(Quaternion value1, Quaternion value2)
		{
			if (value1.X == value2.X && value1.Y == value2.Y && value1.Z == value2.Z)
			{
				return value1.W == value2.W;
			}
			return false;
		}

		public static bool operator !=(Quaternion value1, Quaternion value2)
		{
			if (value1.X == value2.X && value1.Y == value2.Y && value1.Z == value2.Z)
			{
				return value1.W != value2.W;
			}
			return true;
		}

		public bool Equals(Quaternion other)
		{
			if (X == other.X && Y == other.Y && Z == other.Z)
			{
				return W == other.W;
			}
			return false;
		}

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

		public override string ToString()
		{
			CultureInfo currentCulture = CultureInfo.CurrentCulture;
			return string.Format(currentCulture, "{{X:{0} Y:{1} Z:{2} W:{3}}}", X.ToString(currentCulture), Y.ToString(currentCulture), Z.ToString(currentCulture), W.ToString(currentCulture));
		}

		public override int GetHashCode()
		{
			return X.GetHashCode() + Y.GetHashCode() + Z.GetHashCode() + W.GetHashCode();
		}
	}
	public struct Vector2 : IEquatable<Vector2>, IFormattable
	{
		public float X;

		public float Y;

		public static Vector2 Zero => default(Vector2);

		public static Vector2 One => new Vector2(1f, 1f);

		public static Vector2 UnitX => new Vector2(1f, 0f);

		public static Vector2 UnitY => new Vector2(0f, 1f);

		public override int GetHashCode()
		{
			return HashHelpers.Combine(X.GetHashCode(), Y.GetHashCode());
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public override bool Equals(object obj)
		{
			if (!(obj is Vector2))
			{
				return false;
			}
			return Equals((Vector2)obj);
		}

		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('<');
			stringBuilder.Append(X.ToString(format, formatProvider));
			stringBuilder.Append(numberGroupSeparator);
			stringBuilder.Append(' ');
			stringBuilder.Append(Y.ToString(format, formatProvider));
			stringBuilder.Append('>');
			return stringBuilder.ToString();
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public float Length()
		{
			if (Vector.IsHardwareAccelerated)
			{
				return MathF.Sqrt(Dot(this, this));
			}
			return MathF.Sqrt(X * X + Y * Y);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public float LengthSquared()
		{
			if (Vector.IsHardwareAccelerated)
			{
				return Dot(this, this);
			}
			return X * X + Y * Y;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static float Distance(Vector2 value1, Vector2 value2)
		{
			if (Vector.IsHardwareAccelerated)
			{
				Vector2 vector = value1 - value2;
				return MathF.Sqrt(Dot(vector, vector));
			}
			float num = value1.X - value2.X;
			float num2 = value1.Y - value2.Y;
			return MathF.Sqrt(num * num + num2 * num2);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static float DistanceSquared(Vector2 value1, Vector2 value2)
		{
			if (Vector.IsHardwareAccelerated)
			{
				Vector2 vector = value1 - value2;
				return Dot(vector, vector);
			}
			float num = value1.X - value2.X;
			float num2 = value1.Y - value2.Y;
			return num * num + num2 * num2;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static Vector2 Normalize(Vector2 value)
		{
			if (Vector.IsHardwareAccelerated)
			{
				float num = value.Length();
				return value / num;
			}
			float num2 = value.X * value.X + value.Y * value.Y;
			float num3 = 1f / MathF.Sqrt(num2);
			return new Vector2(value.X * num3, value.Y * num3);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static Vector2 Reflect(Vector2 vector, Vector2 normal)
		{
			if (Vector.IsHardwareAccelerated)
			{
				float num = Dot(vector, normal);
				return vector - 2f * num * normal;
			}
			float num2 = vector.X * normal.X + vector.Y * normal.Y;
			return new Vector2(vector.X - 2f * num2 * normal.X, vector.Y - 2f * num2 * normal.Y);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static Vector2 Clamp(Vector2 value1, Vector2 min, Vector2 max)
		{
			float x = value1.X;
			x = ((x > max.X) ? max.X : x);
			x = ((x < min.X) ? min.X : x);
			float y = value1.Y;
			y = ((y > max.Y) ? max.Y : y);
			y = ((y < min.Y) ? min.Y : y);
			return new Vector2(x, y);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static Vector2 Lerp(Vector2 value1, Vector2 value2, float amount)
		{
			return new Vector2(value1.X + (value2.X - value1.X) * amount, value1.Y + (value2.Y - value1.Y) * amount);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static Vector2 Transform(Vector2 position, Matrix3x2 matrix)
		{
			return new Vector2(position.X * matrix.M11 + position.Y * matrix.M21 + matrix.M31, position.X * matrix.M12 + position.Y * matrix.M22 + matrix.M32);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static Vector2 Transform(Vector2 position, Matrix4x4 matrix)
		{
			return new Vector2(position.X * matrix.M11 + position.Y * matrix.M21 + matrix.M41, position.X * matrix.M12 + position.Y * matrix.M22 + matrix.M42);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static Vector2 TransformNormal(Vector2 normal, Matrix3x2 matrix)
		{
			return new Vector2(normal.X * matrix.M11 + normal.Y * matrix.M21, normal.X * matrix.M12 + normal.Y * matrix.M22);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static Vector2 TransformNormal(Vector2 normal, Matrix4x4 matrix)
		{
			return new Vector2(normal.X * matrix.M11 + normal.Y * matrix.M21, normal.X * matrix.M12 + normal.Y * matrix.M22);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static Vector2 Transform(Vector2 value, Quaternion rotation)
		{
			float num = rotation.X + rotation.X;
			float num2 = rotation.Y + rotation.Y;
			float num3 = rotation.Z + rotation.Z;
			float num4 = rotation.W * num3;
			float num5 = rotation.X * num;
			float num6 = rotation.X * num2;
			float num7 = rotation.Y * num2;
			float num8 = rotation.Z * num3;
			return new Vector2(value.X * (1f - num7 - num8) + value.Y * (num6 - num4), value.X * (num6 + num4) + value.Y * (1f - num5 - num8));
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static Vector2 Add(Vector2 left, Vector2 right)
		{
			return left + right;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static Vector2 Subtract(Vector2 left, Vector2 right)
		{
			return left - right;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static Vector2 Multiply(Vector2 left, Vector2 right)
		{
			return left * right;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static Vector2 Multiply(Vector2 left, float right)
		{
			return left * right;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static Vector2 Multiply(float left, Vector2 right)
		{
			return left * right;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static Vector2 Divide(Vector2 left, Vector2 right)
		{
			return left / right;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static Vector2 Divide(Vector2 left, float divisor)
		{
			return left / divisor;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static Vector2 Negate(Vector2 value)
		{
			return -value;
		}

		[System.Runtime.CompilerServices.Intrinsic]
		public Vector2(float value)
			: this(value, value)
		{
		}

		[System.Runtime.CompilerServices.Intrinsic]
		public Vector2(float x, float y)
		{
			X = x;
			Y = y;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public void CopyTo(float[] array)
		{
			CopyTo(array, 0);
		}

		public void CopyTo(float[] array, int index)
		{
			if (array == null)
			{
				throw new NullReferenceException("The method was called with a null array argument.");
			}
			if (index < 0 || index >= array.Length)
			{
				throw new ArgumentOutOfRangeException("index", SR.Format("Index was out of bounds:", index));
			}
			if (array.Length - index < 2)
			{
				throw new ArgumentException(SR.Format("Number of elements in source vector is greater than the destination array", index));
			}
			array[index] = X;
			array[index + 1] = Y;
		}

		[System.Runtime.CompilerServices.Intrinsic]
		public bool Equals(Vector2 other)
		{
			if (X == other.X)
			{
				return Y == other.Y;
			}
			return false;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.CompilerServices.Intrinsic]
		public static float Dot(Vector2 value1, Vector2 value2)
		{
			return value1.X * value2.X + value1.Y * value2.Y;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.CompilerServices.Intrinsic]
		public static Vector2 Min(Vector2 value1, Vector2 value2)
		{
			return new Vector2((value1.X < value2.X) ? value1.X : value2.X, (value1.Y < value2.Y) ? value1.Y : value2.Y);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.CompilerServices.Intrinsic]
		public static Vector2 Max(Vector2 value1, Vector2 value2)
		{
			return new Vector2((value1.X > value2.X) ? value1.X : value2.X, (value1.Y > value2.Y) ? value1.Y : value2.Y);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.CompilerServices.Intrinsic]
		public static Vector2 Abs(Vector2 value)
		{
			return new Vector2(MathF.Abs(value.X), MathF.Abs(value.Y));
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.CompilerServices.Intrinsic]
		public static Vector2 SquareRoot(Vector2 value)
		{
			return new Vector2(MathF.Sqrt(value.X), MathF.Sqrt(value.Y));
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.CompilerServices.Intrinsic]
		public static Vector2 operator +(Vector2 left, Vector2 right)
		{
			return new Vector2(left.X + right.X, left.Y + right.Y);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.CompilerServices.Intrinsic]
		public static Vector2 operator -(Vector2 left, Vector2 right)
		{
			return new Vector2(left.X - right.X, left.Y - right.Y);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.CompilerServices.Intrinsic]
		public static Vector2 operator *(Vector2 left, Vector2 right)
		{
			return new Vector2(left.X * right.X, left.Y * right.Y);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.CompilerServices.Intrinsic]
		public static Vector2 operator *(float left, Vector2 right)
		{
			return new Vector2(left, left) * right;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.CompilerServices.Intrinsic]
		public static Vector2 operator *(Vector2 left, float right)
		{
			return left * new Vector2(right, right);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.CompilerServices.Intrinsic]
		public static Vector2 operator /(Vector2 left, Vector2 right)
		{
			return new Vector2(left.X / right.X, left.Y / right.Y);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static Vector2 operator /(Vector2 value1, float value2)
		{
			return value1 / new Vector2(value2);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static Vector2 operator -(Vector2 value)
		{
			return Zero - value;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static bool operator ==(Vector2 left, Vector2 right)
		{
			return left.Equals(right);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static bool operator !=(Vector2 left, Vector2 right)
		{
			return !(left == right);
		}
	}
	public struct Vector3 : IEquatable<Vector3>, IFormattable
	{
		public float X;

		public float Y;

		public float Z;

		public static Vector3 Zero => default(Vector3);

		public static Vector3 One => new Vector3(1f, 1f, 1f);

		public static Vector3 UnitX => new Vector3(1f, 0f, 0f);

		public static Vector3 UnitY => new Vector3(0f, 1f, 0f);

		public static Vector3 UnitZ => new Vector3(0f, 0f, 1f);

		public override int GetHashCode()
		{
			return HashHelpers.Combine(HashHelpers.Combine(X.GetHashCode(), Y.GetHashCode()), Z.GetHashCode());
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public override bool Equals(object obj)
		{
			if (!(obj is Vector3))
			{
				return false;
			}
			return Equals((Vector3)obj);
		}

		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('<');
			stringBuilder.Append(((IFormattable)X).ToString(format, formatProvider));
			stringBuilder.Append(numberGroupSeparator);
			stringBuilder.Append(' ');
			stringBuilder.Append(((IFormattable)Y).ToString(format, formatProvider));
			stringBuilder.Append(numberGroupSeparator);
			stringBuilder.Append(' ');
			stringBuilder.Append(((IFormattable)Z).ToString(format, formatProvider));
			stringBuilder.Append('>');
			return stringBuilder.ToString();
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public float Length()
		{
			if (Vector.IsHardwareAccelerated)
			{
				return MathF.Sqrt(Dot(this, this));
			}
			return MathF.Sqrt(X * X + Y * Y + Z * Z);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public float LengthSquared()
		{
			if (Vector.IsHardwareAccelerated)
			{
				return Dot(this, this);
			}
			return X * X + Y * Y + Z * Z;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static float Distance(Vector3 value1, Vector3 value2)
		{
			if (Vector.IsHardwareAccelerated)
			{
				Vector3 vector = value1 - value2;
				return MathF.Sqrt(Dot(vector, vector));
			}
			float num = value1.X - value2.X;
			float num2 = value1.Y - value2.Y;
			float num3 = value1.Z - value2.Z;
			return MathF.Sqrt(num * num + num2 * num2 + num3 * num3);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static float DistanceSquared(Vector3 value1, Vector3 value2)
		{
			if (Vector.IsHardwareAccelerated)
			{
				Vector3 vector = value1 - value2;
				return Dot(vector, vector);
			}
			float num = value1.X - value2.X;
			float num2 = value1.Y - value2.Y;
			float num3 = value1.Z - value2.Z;
			return num * num + num2 * num2 + num3 * num3;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static Vector3 Normalize(Vector3 value)
		{
			if (Vector.IsHardwareAccelerated)
			{
				float num = value.Length();
				return value / num;
			}
			float num2 = MathF.Sqrt(value.X * value.X + value.Y * value.Y + value.Z * value.Z);
			return new Vector3(value.X / num2, value.Y / num2, value.Z / num2);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static Vector3 Cross(Vector3 vector1, Vector3 vector2)
		{
			return new Vector3(vector1.Y * vector2.Z - vector1.Z * vector2.Y, vector1.Z * vector2.X - vector1.X * vector2.Z, vector1.X * vector2.Y - vector1.Y * vector2.X);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static Vector3 Reflect(Vector3 vector, Vector3 normal)
		{
			if (Vector.IsHardwareAccelerated)
			{
				float num = Dot(vector, normal);
				Vector3 vector2 = normal * num * 2f;
				return vector - vector2;
			}
			float num2 = vector.X * normal.X + vector.Y * normal.Y + vector.Z * normal.Z;
			float num3 = normal.X * num2 * 2f;
			float num4 = normal.Y * num2 * 2f;
			float num5 = normal.Z * num2 * 2f;
			return new Vector3(vector.X - num3, vector.Y - num4, vector.Z - num5);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static Vector3 Clamp(Vector3 value1, Vector3 min, Vector3 max)
		{
			float x = value1.X;
			x = ((x > max.X) ? max.X : x);
			x = ((x < min.X) ? min.X : x);
			float y = value1.Y;
			y = ((y > max.Y) ? max.Y : y);
			y = ((y < min.Y) ? min.Y : y);
			float z = value1.Z;
			z = ((z > max.Z) ? max.Z : z);
			z = ((z < min.Z) ? min.Z : z);
			return new Vector3(x, y, z);
		}

		[MethodImpl(MethodImplOption

BepInExPack/mono/Managed/System.Numerics.Vectors.dll

Decompiled a month ago
using System;
using System.Diagnostics;
using System.Numerics;
using System.Reflection;
using System.Runtime.CompilerServices;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyDefaultAlias("System.Numerics.Vectors")]
[assembly: AssemblyCompany("Microsoft Corporation")]
[assembly: AssemblyCopyright("© Microsoft Corporation. All rights reserved.")]
[assembly: AssemblyDescription("System.Numerics.Vectors")]
[assembly: AssemblyFileVersion("4.700.19.46205")]
[assembly: AssemblyInformationalVersion("4.7.0+a5b5f2e1e369972c8ff1e2183979fab6099f52ef")]
[assembly: AssemblyProduct("Microsoft® .NET Framework")]
[assembly: AssemblyTitle("System.Numerics.Vectors")]
[assembly: CLSCompliant(true)]
[assembly: AssemblyVersion("4.1.5.0")]
[assembly: TypeForwardedTo(typeof(Matrix3x2))]
[assembly: TypeForwardedTo(typeof(Matrix4x4))]
[assembly: TypeForwardedTo(typeof(Plane))]
[assembly: TypeForwardedTo(typeof(Quaternion))]
[assembly: TypeForwardedTo(typeof(Vector))]
[assembly: TypeForwardedTo(typeof(Vector<>))]
[assembly: TypeForwardedTo(typeof(Vector2))]
[assembly: TypeForwardedTo(typeof(Vector3))]
[assembly: TypeForwardedTo(typeof(Vector4))]

BepInExPack/mono/Managed/System.Reflection.Emit.dll

Decompiled a month ago
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("System.Reflection.Emit")]
[assembly: AssemblyDescription("System.Reflection.Emit")]
[assembly: AssemblyDefaultAlias("System.Reflection.Emit")]
[assembly: AssemblyCompany("Mono development team")]
[assembly: AssemblyProduct("Mono Common Language Infrastructure")]
[assembly: AssemblyCopyright("(c) Various Mono authors")]
[assembly: AssemblyInformationalVersion("4.0.0.0")]
[assembly: AssemblyFileVersion("4.0.0.0")]
[assembly: AssemblyVersion("4.0.1.0")]
[assembly: TypeForwardedTo(typeof(AssemblyBuilder))]
[assembly: TypeForwardedTo(typeof(AssemblyBuilderAccess))]
[assembly: TypeForwardedTo(typeof(ConstructorBuilder))]
[assembly: TypeForwardedTo(typeof(EnumBuilder))]
[assembly: TypeForwardedTo(typeof(EventBuilder))]
[assembly: TypeForwardedTo(typeof(FieldBuilder))]
[assembly: TypeForwardedTo(typeof(GenericTypeParameterBuilder))]
[assembly: TypeForwardedTo(typeof(MethodBuilder))]
[assembly: TypeForwardedTo(typeof(ModuleBuilder))]
[assembly: TypeForwardedTo(typeof(PropertyBuilder))]
[assembly: TypeForwardedTo(typeof(TypeBuilder))]

BepInExPack/mono/Managed/System.Reflection.Emit.ILGeneration.dll

Decompiled a month ago
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("System.Reflection.Emit.ILGeneration")]
[assembly: AssemblyDescription("System.Reflection.Emit.ILGeneration")]
[assembly: AssemblyDefaultAlias("System.Reflection.Emit.ILGeneration")]
[assembly: AssemblyCompany("Mono development team")]
[assembly: AssemblyProduct("Mono Common Language Infrastructure")]
[assembly: AssemblyCopyright("(c) Various Mono authors")]
[assembly: AssemblyInformationalVersion("4.0.0.0")]
[assembly: AssemblyFileVersion("4.0.0.0")]
[assembly: AssemblyVersion("4.0.1.0")]
[assembly: TypeForwardedTo(typeof(CustomAttributeBuilder))]
[assembly: TypeForwardedTo(typeof(ILGenerator))]
[assembly: TypeForwardedTo(typeof(Label))]
[assembly: TypeForwardedTo(typeof(LocalBuilder))]
[assembly: TypeForwardedTo(typeof(ParameterBuilder))]
[assembly: TypeForwardedTo(typeof(SignatureHelper))]

BepInExPack/mono/Managed/System.Reflection.Emit.Lightweight.dll

Decompiled a month ago
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("System.Reflection.Emit.Lightweight")]
[assembly: AssemblyDescription("System.Reflection.Emit.Lightweight")]
[assembly: AssemblyDefaultAlias("System.Reflection.Emit.Lightweight")]
[assembly: AssemblyCompany("Mono development team")]
[assembly: AssemblyProduct("Mono Common Language Infrastructure")]
[assembly: AssemblyCopyright("(c) Various Mono authors")]
[assembly: AssemblyInformationalVersion("4.0.0.0")]
[assembly: AssemblyFileVersion("4.0.0.0")]
[assembly: AssemblyVersion("4.0.1.0")]
[assembly: TypeForwardedTo(typeof(DynamicMethod))]

BepInExPack/mono/Managed/System.Runtime.CompilerServices.Unsafe.dll

Decompiled a month ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;

[assembly: CLSCompliant(false)]
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyFileVersion("5.0.20.51904")]
[assembly: AssemblyInformationalVersion("5.0.0")]
[assembly: AssemblyTitle("System.Runtime.CompilerServices.Unsafe")]
[assembly: AssemblyDescription("System.Runtime.CompilerServices.Unsafe")]
[assembly: AssemblyMetadata(".NETFrameworkAssembly", "")]
[assembly: AssemblyMetadata("Serviceable", "True")]
[assembly: AssemblyCopyright("© Microsoft Corporation.  All rights reserved.")]
[assembly: AssemblyCompany("Microsoft Corporation")]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyProduct("Microsoft® .NET Framework")]
[assembly: AssemblyVersion("5.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)]
		public static ref T Unbox<T>(object box)
		{
			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)]
		[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)]
		[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)]
		[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)]
		[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
	{
	}
}

BepInExPack/mono/Managed/System.Runtime.Serialization.dll

Decompiled a month ago
using System;
using System.CodeDom;
using System.CodeDom.Compiler;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Configuration;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Resources;
using System.Runtime;
using System.Runtime.CompilerServices;
using System.Runtime.Diagnostics;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Configuration;
using System.Runtime.Serialization.Diagnostics;
using System.Runtime.Serialization.Diagnostics.Application;
using System.Runtime.Serialization.Formatters;
using System.Runtime.Serialization.Json;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;
using System.Xml.XPath;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("System.Runtime.Serialization.dll")]
[assembly: AssemblyDescription("System.Runtime.Serialization.dll")]
[assembly: AssemblyDefaultAlias("System.Runtime.Serialization.dll")]
[assembly: AssemblyCompany("Mono development team")]
[assembly: AssemblyProduct("Mono Common Language Infrastructure")]
[assembly: AssemblyCopyright("(c) Various Mono authors")]
[assembly: SatelliteContractVersion("4.0.0.0")]
[assembly: AssemblyInformationalVersion("4.6.57.0")]
[assembly: AssemblyFileVersion("4.6.57.0")]
[assembly: NeutralResourcesLanguage("en-US")]
[assembly: CLSCompliant(true)]
[assembly: AssemblyDelaySign(true)]
[assembly: AssemblyKeyFile("../ecma.pub")]
[assembly: AllowPartiallyTrustedCallers]
[assembly: ComCompatibleVersion(1, 0, 3300, 0)]
[assembly: SecurityCritical(SecurityCriticalScope.Explicit)]
[assembly: ComVisible(false)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("4.0.0.0")]
[module: UnverifiableCode]
internal static class SR
{
	internal static string GetString(string name, params object[] args)
	{
		return GetString(CultureInfo.InvariantCulture, name, args);
	}

	internal static string GetString(CultureInfo culture, string name, params object[] args)
	{
		return string.Format(culture, name, args);
	}

	internal static string GetString(string name)
	{
		return name;
	}

	internal static string GetString(CultureInfo culture, string name)
	{
		return name;
	}

	internal static string Format(string resourceFormat, params object[] args)
	{
		if (args != null)
		{
			return string.Format(CultureInfo.InvariantCulture, resourceFormat, args);
		}
		return resourceFormat;
	}

	internal static string Format(string resourceFormat, object p1)
	{
		return string.Format(CultureInfo.InvariantCulture, resourceFormat, p1);
	}

	internal static string Format(string resourceFormat, object p1, object p2)
	{
		return string.Format(CultureInfo.InvariantCulture, resourceFormat, p1, p2);
	}

	internal static string Format(CultureInfo ci, string resourceFormat, object p1, object p2)
	{
		return string.Format(ci, resourceFormat, p1, p2);
	}

	internal static string Format(string resourceFormat, object p1, object p2, object p3)
	{
		return string.Format(CultureInfo.InvariantCulture, resourceFormat, p1, p2, p3);
	}

	internal static string GetResourceString(string str)
	{
		return str;
	}
}
namespace System
{
	internal static class LocalAppContextSwitches
	{
		public static readonly bool DoNotUseTimeZoneInfo;

		public static readonly bool DoNotUseEcmaScriptV6EscapeControlCharacter;
	}
	internal static class NotImplemented
	{
		internal static Exception ByDesign => new NotImplementedException();

		internal static Exception ByDesignWithMessage(string message)
		{
			return new NotImplementedException(message);
		}
	}
}
namespace System.Xml
{
	internal abstract class ArrayHelper<TArgument, TArray>
	{
		public TArray[] ReadArray(XmlDictionaryReader reader, TArgument localName, TArgument namespaceUri, int maxArrayLength)
		{
			TArray[][] array = null;
			TArray[] array2 = null;
			int num = 0;
			int num2 = 0;
			if (reader.TryGetArrayLength(out var count))
			{
				if (count > maxArrayLength)
				{
					XmlExceptionHelper.ThrowMaxArrayLengthOrMaxItemsQuotaExceeded(reader, maxArrayLength);
				}
				if (count > 65535)
				{
					count = 65535;
				}
			}
			else
			{
				count = 32;
			}
			while (true)
			{
				array2 = new TArray[count];
				int i;
				int num3;
				for (i = 0; i < array2.Length; i += num3)
				{
					num3 = ReadArray(reader, localName, namespaceUri, array2, i, array2.Length - i);
					if (num3 == 0)
					{
						break;
					}
				}
				if (num2 > maxArrayLength - i)
				{
					XmlExceptionHelper.ThrowMaxArrayLengthOrMaxItemsQuotaExceeded(reader, maxArrayLength);
				}
				num2 += i;
				if (i < array2.Length || reader.NodeType == XmlNodeType.EndElement)
				{
					break;
				}
				if (array == null)
				{
					array = new TArray[32][];
				}
				array[num++] = array2;
				count *= 2;
			}
			if (num2 != array2.Length || num > 0)
			{
				TArray[] array3 = new TArray[num2];
				int num4 = 0;
				for (int j = 0; j < num; j++)
				{
					Array.Copy(array[j], 0, array3, num4, array[j].Length);
					num4 += array[j].Length;
				}
				Array.Copy(array2, 0, array3, num4, num2 - num4);
				array2 = array3;
			}
			return array2;
		}

		public void WriteArray(XmlDictionaryWriter writer, string prefix, TArgument localName, TArgument namespaceUri, XmlDictionaryReader reader)
		{
			int count = ((!reader.TryGetArrayLength(out count)) ? 256 : Math.Min(count, 256));
			TArray[] array = new TArray[count];
			while (true)
			{
				int num = ReadArray(reader, localName, namespaceUri, array, 0, array.Length);
				if (num != 0)
				{
					WriteArray(writer, prefix, localName, namespaceUri, array, 0, num);
					continue;
				}
				break;
			}
		}

		protected abstract int ReadArray(XmlDictionaryReader reader, TArgument localName, TArgument namespaceUri, TArray[] array, int offset, int count);

		protected abstract void WriteArray(XmlDictionaryWriter writer, string prefix, TArgument localName, TArgument namespaceUri, TArray[] array, int offset, int count);
	}
	internal class BooleanArrayHelperWithString : ArrayHelper<string, bool>
	{
		public static readonly BooleanArrayHelperWithString Instance = new BooleanArrayHelperWithString();

		protected override int ReadArray(XmlDictionaryReader reader, string localName, string namespaceUri, bool[] array, int offset, int count)
		{
			return reader.ReadArray(localName, namespaceUri, array, offset, count);
		}

		protected override void WriteArray(XmlDictionaryWriter writer, string prefix, string localName, string namespaceUri, bool[] array, int offset, int count)
		{
			writer.WriteArray(prefix, localName, namespaceUri, array, offset, count);
		}
	}
	internal class BooleanArrayHelperWithDictionaryString : ArrayHelper<XmlDictionaryString, bool>
	{
		public static readonly BooleanArrayHelperWithDictionaryString Instance = new BooleanArrayHelperWithDictionaryString();

		protected override int ReadArray(XmlDictionaryReader reader, XmlDictionaryString localName, XmlDictionaryString namespaceUri, bool[] array, int offset, int count)
		{
			return reader.ReadArray(localName, namespaceUri, array, offset, count);
		}

		protected override void WriteArray(XmlDictionaryWriter writer, string prefix, XmlDictionaryString localName, XmlDictionaryString namespaceUri, bool[] array, int offset, int count)
		{
			writer.WriteArray(prefix, localName, namespaceUri, array, offset, count);
		}
	}
	internal class Int16ArrayHelperWithString : ArrayHelper<string, short>
	{
		public static readonly Int16ArrayHelperWithString Instance = new Int16ArrayHelperWithString();

		protected override int ReadArray(XmlDictionaryReader reader, string localName, string namespaceUri, short[] array, int offset, int count)
		{
			return reader.ReadArray(localName, namespaceUri, array, offset, count);
		}

		protected override void WriteArray(XmlDictionaryWriter writer, string prefix, string localName, string namespaceUri, short[] array, int offset, int count)
		{
			writer.WriteArray(prefix, localName, namespaceUri, array, offset, count);
		}
	}
	internal class Int16ArrayHelperWithDictionaryString : ArrayHelper<XmlDictionaryString, short>
	{
		public static readonly Int16ArrayHelperWithDictionaryString Instance = new Int16ArrayHelperWithDictionaryString();

		protected override int ReadArray(XmlDictionaryReader reader, XmlDictionaryString localName, XmlDictionaryString namespaceUri, short[] array, int offset, int count)
		{
			return reader.ReadArray(localName, namespaceUri, array, offset, count);
		}

		protected override void WriteArray(XmlDictionaryWriter writer, string prefix, XmlDictionaryString localName, XmlDictionaryString namespaceUri, short[] array, int offset, int count)
		{
			writer.WriteArray(prefix, localName, namespaceUri, array, offset, count);
		}
	}
	internal class Int32ArrayHelperWithString : ArrayHelper<string, int>
	{
		public static readonly Int32ArrayHelperWithString Instance = new Int32ArrayHelperWithString();

		protected override int ReadArray(XmlDictionaryReader reader, string localName, string namespaceUri, int[] array, int offset, int count)
		{
			return reader.ReadArray(localName, namespaceUri, array, offset, count);
		}

		protected override void WriteArray(XmlDictionaryWriter writer, string prefix, string localName, string namespaceUri, int[] array, int offset, int count)
		{
			writer.WriteArray(prefix, localName, namespaceUri, array, offset, count);
		}
	}
	internal class Int32ArrayHelperWithDictionaryString : ArrayHelper<XmlDictionaryString, int>
	{
		public static readonly Int32ArrayHelperWithDictionaryString Instance = new Int32ArrayHelperWithDictionaryString();

		protected override int ReadArray(XmlDictionaryReader reader, XmlDictionaryString localName, XmlDictionaryString namespaceUri, int[] array, int offset, int count)
		{
			return reader.ReadArray(localName, namespaceUri, array, offset, count);
		}

		protected override void WriteArray(XmlDictionaryWriter writer, string prefix, XmlDictionaryString localName, XmlDictionaryString namespaceUri, int[] array, int offset, int count)
		{
			writer.WriteArray(prefix, localName, namespaceUri, array, offset, count);
		}
	}
	internal class Int64ArrayHelperWithString : ArrayHelper<string, long>
	{
		public static readonly Int64ArrayHelperWithString Instance = new Int64ArrayHelperWithString();

		protected override int ReadArray(XmlDictionaryReader reader, string localName, string namespaceUri, long[] array, int offset, int count)
		{
			return reader.ReadArray(localName, namespaceUri, array, offset, count);
		}

		protected override void WriteArray(XmlDictionaryWriter writer, string prefix, string localName, string namespaceUri, long[] array, int offset, int count)
		{
			writer.WriteArray(prefix, localName, namespaceUri, array, offset, count);
		}
	}
	internal class Int64ArrayHelperWithDictionaryString : ArrayHelper<XmlDictionaryString, long>
	{
		public static readonly Int64ArrayHelperWithDictionaryString Instance = new Int64ArrayHelperWithDictionaryString();

		protected override int ReadArray(XmlDictionaryReader reader, XmlDictionaryString localName, XmlDictionaryString namespaceUri, long[] array, int offset, int count)
		{
			return reader.ReadArray(localName, namespaceUri, array, offset, count);
		}

		protected override void WriteArray(XmlDictionaryWriter writer, string prefix, XmlDictionaryString localName, XmlDictionaryString namespaceUri, long[] array, int offset, int count)
		{
			writer.WriteArray(prefix, localName, namespaceUri, array, offset, count);
		}
	}
	internal class SingleArrayHelperWithString : ArrayHelper<string, float>
	{
		public static readonly SingleArrayHelperWithString Instance = new SingleArrayHelperWithString();

		protected override int ReadArray(XmlDictionaryReader reader, string localName, string namespaceUri, float[] array, int offset, int count)
		{
			return reader.ReadArray(localName, namespaceUri, array, offset, count);
		}

		protected override void WriteArray(XmlDictionaryWriter writer, string prefix, string localName, string namespaceUri, float[] array, int offset, int count)
		{
			writer.WriteArray(prefix, localName, namespaceUri, array, offset, count);
		}
	}
	internal class SingleArrayHelperWithDictionaryString : ArrayHelper<XmlDictionaryString, float>
	{
		public static readonly SingleArrayHelperWithDictionaryString Instance = new SingleArrayHelperWithDictionaryString();

		protected override int ReadArray(XmlDictionaryReader reader, XmlDictionaryString localName, XmlDictionaryString namespaceUri, float[] array, int offset, int count)
		{
			return reader.ReadArray(localName, namespaceUri, array, offset, count);
		}

		protected override void WriteArray(XmlDictionaryWriter writer, string prefix, XmlDictionaryString localName, XmlDictionaryString namespaceUri, float[] array, int offset, int count)
		{
			writer.WriteArray(prefix, localName, namespaceUri, array, offset, count);
		}
	}
	internal class DoubleArrayHelperWithString : ArrayHelper<string, double>
	{
		public static readonly DoubleArrayHelperWithString Instance = new DoubleArrayHelperWithString();

		protected override int ReadArray(XmlDictionaryReader reader, string localName, string namespaceUri, double[] array, int offset, int count)
		{
			return reader.ReadArray(localName, namespaceUri, array, offset, count);
		}

		protected override void WriteArray(XmlDictionaryWriter writer, string prefix, string localName, string namespaceUri, double[] array, int offset, int count)
		{
			writer.WriteArray(prefix, localName, namespaceUri, array, offset, count);
		}
	}
	internal class DoubleArrayHelperWithDictionaryString : ArrayHelper<XmlDictionaryString, double>
	{
		public static readonly DoubleArrayHelperWithDictionaryString Instance = new DoubleArrayHelperWithDictionaryString();

		protected override int ReadArray(XmlDictionaryReader reader, XmlDictionaryString localName, XmlDictionaryString namespaceUri, double[] array, int offset, int count)
		{
			return reader.ReadArray(localName, namespaceUri, array, offset, count);
		}

		protected override void WriteArray(XmlDictionaryWriter writer, string prefix, XmlDictionaryString localName, XmlDictionaryString namespaceUri, double[] array, int offset, int count)
		{
			writer.WriteArray(prefix, localName, namespaceUri, array, offset, count);
		}
	}
	internal class DecimalArrayHelperWithString : ArrayHelper<string, decimal>
	{
		public static readonly DecimalArrayHelperWithString Instance = new DecimalArrayHelperWithString();

		protected override int ReadArray(XmlDictionaryReader reader, string localName, string namespaceUri, decimal[] array, int offset, int count)
		{
			return reader.ReadArray(localName, namespaceUri, array, offset, count);
		}

		protected override void WriteArray(XmlDictionaryWriter writer, string prefix, string localName, string namespaceUri, decimal[] array, int offset, int count)
		{
			writer.WriteArray(prefix, localName, namespaceUri, array, offset, count);
		}
	}
	internal class DecimalArrayHelperWithDictionaryString : ArrayHelper<XmlDictionaryString, decimal>
	{
		public static readonly DecimalArrayHelperWithDictionaryString Instance = new DecimalArrayHelperWithDictionaryString();

		protected override int ReadArray(XmlDictionaryReader reader, XmlDictionaryString localName, XmlDictionaryString namespaceUri, decimal[] array, int offset, int count)
		{
			return reader.ReadArray(localName, namespaceUri, array, offset, count);
		}

		protected override void WriteArray(XmlDictionaryWriter writer, string prefix, XmlDictionaryString localName, XmlDictionaryString namespaceUri, decimal[] array, int offset, int count)
		{
			writer.WriteArray(prefix, localName, namespaceUri, array, offset, count);
		}
	}
	internal class DateTimeArrayHelperWithString : ArrayHelper<string, DateTime>
	{
		public static readonly DateTimeArrayHelperWithString Instance = new DateTimeArrayHelperWithString();

		protected override int ReadArray(XmlDictionaryReader reader, string localName, string namespaceUri, DateTime[] array, int offset, int count)
		{
			return reader.ReadArray(localName, namespaceUri, array, offset, count);
		}

		protected override void WriteArray(XmlDictionaryWriter writer, string prefix, string localName, string namespaceUri, DateTime[] array, int offset, int count)
		{
			writer.WriteArray(prefix, localName, namespaceUri, array, offset, count);
		}
	}
	internal class DateTimeArrayHelperWithDictionaryString : ArrayHelper<XmlDictionaryString, DateTime>
	{
		public static readonly DateTimeArrayHelperWithDictionaryString Instance = new DateTimeArrayHelperWithDictionaryString();

		protected override int ReadArray(XmlDictionaryReader reader, XmlDictionaryString localName, XmlDictionaryString namespaceUri, DateTime[] array, int offset, int count)
		{
			return reader.ReadArray(localName, namespaceUri, array, offset, count);
		}

		protected override void WriteArray(XmlDictionaryWriter writer, string prefix, XmlDictionaryString localName, XmlDictionaryString namespaceUri, DateTime[] array, int offset, int count)
		{
			writer.WriteArray(prefix, localName, namespaceUri, array, offset, count);
		}
	}
	internal class GuidArrayHelperWithString : ArrayHelper<string, Guid>
	{
		public static readonly GuidArrayHelperWithString Instance = new GuidArrayHelperWithString();

		protected override int ReadArray(XmlDictionaryReader reader, string localName, string namespaceUri, Guid[] array, int offset, int count)
		{
			return reader.ReadArray(localName, namespaceUri, array, offset, count);
		}

		protected override void WriteArray(XmlDictionaryWriter writer, string prefix, string localName, string namespaceUri, Guid[] array, int offset, int count)
		{
			writer.WriteArray(prefix, localName, namespaceUri, array, offset, count);
		}
	}
	internal class GuidArrayHelperWithDictionaryString : ArrayHelper<XmlDictionaryString, Guid>
	{
		public static readonly GuidArrayHelperWithDictionaryString Instance = new GuidArrayHelperWithDictionaryString();

		protected override int ReadArray(XmlDictionaryReader reader, XmlDictionaryString localName, XmlDictionaryString namespaceUri, Guid[] array, int offset, int count)
		{
			return reader.ReadArray(localName, namespaceUri, array, offset, count);
		}

		protected override void WriteArray(XmlDictionaryWriter writer, string prefix, XmlDictionaryString localName, XmlDictionaryString namespaceUri, Guid[] array, int offset, int count)
		{
			writer.WriteArray(prefix, localName, namespaceUri, array, offset, count);
		}
	}
	internal class TimeSpanArrayHelperWithString : ArrayHelper<string, TimeSpan>
	{
		public static readonly TimeSpanArrayHelperWithString Instance = new TimeSpanArrayHelperWithString();

		protected override int ReadArray(XmlDictionaryReader reader, string localName, string namespaceUri, TimeSpan[] array, int offset, int count)
		{
			return reader.ReadArray(localName, namespaceUri, array, offset, count);
		}

		protected override void WriteArray(XmlDictionaryWriter writer, string prefix, string localName, string namespaceUri, TimeSpan[] array, int offset, int count)
		{
			writer.WriteArray(prefix, localName, namespaceUri, array, offset, count);
		}
	}
	internal class TimeSpanArrayHelperWithDictionaryString : ArrayHelper<XmlDictionaryString, TimeSpan>
	{
		public static readonly TimeSpanArrayHelperWithDictionaryString Instance = new TimeSpanArrayHelperWithDictionaryString();

		protected override int ReadArray(XmlDictionaryReader reader, XmlDictionaryString localName, XmlDictionaryString namespaceUri, TimeSpan[] array, int offset, int count)
		{
			return reader.ReadArray(localName, namespaceUri, array, offset, count);
		}

		protected override void WriteArray(XmlDictionaryWriter writer, string prefix, XmlDictionaryString localName, XmlDictionaryString namespaceUri, TimeSpan[] array, int offset, int count)
		{
			writer.WriteArray(prefix, localName, namespaceUri, array, offset, count);
		}
	}
	internal class EncodingStreamWrapper : Stream
	{
		private enum SupportedEncoding
		{
			UTF8,
			UTF16LE,
			UTF16BE,
			None
		}

		private static readonly UTF8Encoding SafeUTF8 = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false, throwOnInvalidBytes: false);

		private static readonly UnicodeEncoding SafeUTF16 = new UnicodeEncoding(bigEndian: false, byteOrderMark: false, throwOnInvalidBytes: false);

		private static readonly UnicodeEncoding SafeBEUTF16 = new UnicodeEncoding(bigEndian: true, byteOrderMark: false, throwOnInvalidBytes: false);

		private static readonly UTF8Encoding ValidatingUTF8 = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false, throwOnInvalidBytes: true);

		private static readonly UnicodeEncoding ValidatingUTF16 = new UnicodeEncoding(bigEndian: false, byteOrderMark: false, throwOnInvalidBytes: true);

		private static readonly UnicodeEncoding ValidatingBEUTF16 = new UnicodeEncoding(bigEndian: true, byteOrderMark: false, throwOnInvalidBytes: true);

		private const int BufferLength = 128;

		private static readonly byte[] encodingAttr = new byte[8] { 101, 110, 99, 111, 100, 105, 110, 103 };

		private static readonly byte[] encodingUTF8 = new byte[5] { 117, 116, 102, 45, 56 };

		private static readonly byte[] encodingUnicode = new byte[6] { 117, 116, 102, 45, 49, 54 };

		private static readonly byte[] encodingUnicodeLE = new byte[8] { 117, 116, 102, 45, 49, 54, 108, 101 };

		private static readonly byte[] encodingUnicodeBE = new byte[8] { 117, 116, 102, 45, 49, 54, 98, 101 };

		private SupportedEncoding encodingCode;

		private Encoding encoding;

		private Encoder enc;

		private Decoder dec;

		private bool isReading;

		private Stream stream;

		private char[] chars;

		private byte[] bytes;

		private int byteOffset;

		private int byteCount;

		private byte[] byteBuffer = new byte[1];

		public override bool CanRead
		{
			get
			{
				if (!isReading)
				{
					return false;
				}
				return stream.CanRead;
			}
		}

		public override bool CanSeek => false;

		public override bool CanWrite
		{
			get
			{
				if (isReading)
				{
					return false;
				}
				return stream.CanWrite;
			}
		}

		public override long Position
		{
			get
			{
				throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException());
			}
			set
			{
				throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException());
			}
		}

		public override bool CanTimeout => stream.CanTimeout;

		public override long Length => stream.Length;

		public override int ReadTimeout
		{
			get
			{
				return stream.ReadTimeout;
			}
			set
			{
				stream.ReadTimeout = value;
			}
		}

		public override int WriteTimeout
		{
			get
			{
				return stream.WriteTimeout;
			}
			set
			{
				stream.WriteTimeout = value;
			}
		}

		public EncodingStreamWrapper(Stream stream, Encoding encoding)
		{
			try
			{
				isReading = true;
				this.stream = new BufferedStream(stream);
				SupportedEncoding supportedEncoding = GetSupportedEncoding(encoding);
				SupportedEncoding supportedEncoding2 = ReadBOMEncoding(encoding == null);
				if (supportedEncoding != SupportedEncoding.None && supportedEncoding != supportedEncoding2)
				{
					ThrowExpectedEncodingMismatch(supportedEncoding, supportedEncoding2);
				}
				if (supportedEncoding2 == SupportedEncoding.UTF8)
				{
					FillBuffer(2);
					if (bytes[byteOffset + 1] == 63 && bytes[byteOffset] == 60)
					{
						FillBuffer(128);
						CheckUTF8DeclarationEncoding(bytes, byteOffset, byteCount, supportedEncoding2, supportedEncoding);
					}
					return;
				}
				EnsureBuffers();
				FillBuffer(254);
				SetReadDocumentEncoding(supportedEncoding2);
				CleanupCharBreak();
				int charCount = this.encoding.GetChars(bytes, byteOffset, byteCount, chars, 0);
				byteOffset = 0;
				byteCount = ValidatingUTF8.GetBytes(chars, 0, charCount, bytes, 0);
				if (bytes[1] == 63 && bytes[0] == 60)
				{
					CheckUTF8DeclarationEncoding(bytes, 0, byteCount, supportedEncoding2, supportedEncoding);
				}
				else if (supportedEncoding == SupportedEncoding.None)
				{
					throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(System.Runtime.Serialization.SR.GetString("An XML declaration with an encoding is required for all non-UTF8 documents.")));
				}
			}
			catch (DecoderFallbackException innerException)
			{
				throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(System.Runtime.Serialization.SR.GetString("Invalid byte encoding."), innerException));
			}
		}

		private void SetReadDocumentEncoding(SupportedEncoding e)
		{
			EnsureBuffers();
			encodingCode = e;
			encoding = GetEncoding(e);
		}

		private static Encoding GetEncoding(SupportedEncoding e)
		{
			return e switch
			{
				SupportedEncoding.UTF8 => ValidatingUTF8, 
				SupportedEncoding.UTF16LE => ValidatingUTF16, 
				SupportedEncoding.UTF16BE => ValidatingBEUTF16, 
				_ => throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(System.Runtime.Serialization.SR.GetString("XML encoding not supported."))), 
			};
		}

		private static Encoding GetSafeEncoding(SupportedEncoding e)
		{
			return e switch
			{
				SupportedEncoding.UTF8 => SafeUTF8, 
				SupportedEncoding.UTF16LE => SafeUTF16, 
				SupportedEncoding.UTF16BE => SafeBEUTF16, 
				_ => throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(System.Runtime.Serialization.SR.GetString("XML encoding not supported."))), 
			};
		}

		private static string GetEncodingName(SupportedEncoding enc)
		{
			return enc switch
			{
				SupportedEncoding.UTF8 => "utf-8", 
				SupportedEncoding.UTF16LE => "utf-16LE", 
				SupportedEncoding.UTF16BE => "utf-16BE", 
				_ => throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(System.Runtime.Serialization.SR.GetString("XML encoding not supported."))), 
			};
		}

		private static SupportedEncoding GetSupportedEncoding(Encoding encoding)
		{
			if (encoding == null)
			{
				return SupportedEncoding.None;
			}
			if (encoding.WebName == ValidatingUTF8.WebName)
			{
				return SupportedEncoding.UTF8;
			}
			if (encoding.WebName == ValidatingUTF16.WebName)
			{
				return SupportedEncoding.UTF16LE;
			}
			if (encoding.WebName == ValidatingBEUTF16.WebName)
			{
				return SupportedEncoding.UTF16BE;
			}
			throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(System.Runtime.Serialization.SR.GetString("XML encoding not supported.")));
		}

		public EncodingStreamWrapper(Stream stream, Encoding encoding, bool emitBOM)
		{
			isReading = false;
			this.encoding = encoding;
			this.stream = new BufferedStream(stream);
			encodingCode = GetSupportedEncoding(encoding);
			if (encodingCode == SupportedEncoding.UTF8)
			{
				return;
			}
			EnsureBuffers();
			dec = ValidatingUTF8.GetDecoder();
			enc = this.encoding.GetEncoder();
			if (emitBOM)
			{
				byte[] preamble = this.encoding.GetPreamble();
				if (preamble.Length != 0)
				{
					this.stream.Write(preamble, 0, preamble.Length);
				}
			}
		}

		private SupportedEncoding ReadBOMEncoding(bool notOutOfBand)
		{
			int num = stream.ReadByte();
			int num2 = stream.ReadByte();
			int num3 = stream.ReadByte();
			int num4 = stream.ReadByte();
			if (num4 == -1)
			{
				throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(System.Runtime.Serialization.SR.GetString("Unexpected end of file.")));
			}
			int preserve;
			SupportedEncoding result = ReadBOMEncoding((byte)num, (byte)num2, (byte)num3, (byte)num4, notOutOfBand, out preserve);
			EnsureByteBuffer();
			switch (preserve)
			{
			case 1:
				bytes[0] = (byte)num4;
				break;
			case 2:
				bytes[0] = (byte)num3;
				bytes[1] = (byte)num4;
				break;
			case 4:
				bytes[0] = (byte)num;
				bytes[1] = (byte)num2;
				bytes[2] = (byte)num3;
				bytes[3] = (byte)num4;
				break;
			}
			byteCount = preserve;
			return result;
		}

		private static SupportedEncoding ReadBOMEncoding(byte b1, byte b2, byte b3, byte b4, bool notOutOfBand, out int preserve)
		{
			SupportedEncoding result = SupportedEncoding.UTF8;
			preserve = 0;
			if (b1 == 60 && b2 != 0)
			{
				result = SupportedEncoding.UTF8;
				preserve = 4;
			}
			else if (b1 == byte.MaxValue && b2 == 254)
			{
				result = SupportedEncoding.UTF16LE;
				preserve = 2;
			}
			else if (b1 == 254 && b2 == byte.MaxValue)
			{
				result = SupportedEncoding.UTF16BE;
				preserve = 2;
			}
			else if (b1 == 0 && b2 == 60)
			{
				result = SupportedEncoding.UTF16BE;
				if (notOutOfBand && (b3 != 0 || b4 != 63))
				{
					throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(System.Runtime.Serialization.SR.GetString("An XML declaration is required for all non-UTF8 documents.")));
				}
				preserve = 4;
			}
			else if (b1 == 60 && b2 == 0)
			{
				result = SupportedEncoding.UTF16LE;
				if (notOutOfBand && (b3 != 63 || b4 != 0))
				{
					throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(System.Runtime.Serialization.SR.GetString("An XML declaration is required for all non-UTF8 documents.")));
				}
				preserve = 4;
			}
			else if (b1 == 239 && b2 == 187)
			{
				if (notOutOfBand && b3 != 191)
				{
					throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(System.Runtime.Serialization.SR.GetString("Unrecognized Byte Order Mark.")));
				}
				preserve = 1;
			}
			else
			{
				preserve = 4;
			}
			return result;
		}

		private void FillBuffer(int count)
		{
			count -= byteCount;
			while (count > 0)
			{
				int num = stream.Read(bytes, byteOffset + byteCount, count);
				if (num != 0)
				{
					byteCount += num;
					count -= num;
					continue;
				}
				break;
			}
		}

		private void EnsureBuffers()
		{
			EnsureByteBuffer();
			if (chars == null)
			{
				chars = new char[128];
			}
		}

		private void EnsureByteBuffer()
		{
			if (bytes == null)
			{
				bytes = new byte[512];
				byteOffset = 0;
				byteCount = 0;
			}
		}

		private static void CheckUTF8DeclarationEncoding(byte[] buffer, int offset, int count, SupportedEncoding e, SupportedEncoding expectedEnc)
		{
			byte b = 0;
			int num = -1;
			int num2 = offset + Math.Min(count, 128);
			int num3 = 0;
			int num4 = 0;
			for (num3 = offset + 2; num3 < num2; num3++)
			{
				if (b != 0)
				{
					if (buffer[num3] == b)
					{
						b = 0;
					}
				}
				else if (buffer[num3] == 39 || buffer[num3] == 34)
				{
					b = buffer[num3];
				}
				else if (buffer[num3] == 61)
				{
					if (num4 == 1)
					{
						num = num3;
						break;
					}
					num4++;
				}
				else if (buffer[num3] == 63)
				{
					break;
				}
			}
			if (num == -1)
			{
				if (e != 0 && expectedEnc == SupportedEncoding.None)
				{
					throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(System.Runtime.Serialization.SR.GetString("An XML declaration with an encoding is required for all non-UTF8 documents.")));
				}
				return;
			}
			if (num < 28)
			{
				throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(System.Runtime.Serialization.SR.GetString("Malformed XML declaration.")));
			}
			num3 = num - 1;
			while (IsWhitespace(buffer[num3]))
			{
				num3--;
			}
			if (!Compare(encodingAttr, buffer, num3 - encodingAttr.Length + 1))
			{
				if (e == SupportedEncoding.UTF8 || expectedEnc != SupportedEncoding.None)
				{
					return;
				}
				throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(System.Runtime.Serialization.SR.GetString("An XML declaration with an encoding is required for all non-UTF8 documents.")));
			}
			for (num3 = num + 1; num3 < num2 && IsWhitespace(buffer[num3]); num3++)
			{
			}
			if (buffer[num3] != 39 && buffer[num3] != 34)
			{
				throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(System.Runtime.Serialization.SR.GetString("Malformed XML declaration.")));
			}
			b = buffer[num3];
			int num5 = num3++;
			for (; buffer[num3] != b && num3 < num2; num3++)
			{
			}
			if (buffer[num3] != b)
			{
				throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(System.Runtime.Serialization.SR.GetString("Malformed XML declaration.")));
			}
			int num6 = num5 + 1;
			int num7 = num3 - num6;
			SupportedEncoding supportedEncoding = e;
			if (num7 == encodingUTF8.Length && CompareCaseInsensitive(encodingUTF8, buffer, num6))
			{
				supportedEncoding = SupportedEncoding.UTF8;
			}
			else if (num7 == encodingUnicodeLE.Length && CompareCaseInsensitive(encodingUnicodeLE, buffer, num6))
			{
				supportedEncoding = SupportedEncoding.UTF16LE;
			}
			else if (num7 == encodingUnicodeBE.Length && CompareCaseInsensitive(encodingUnicodeBE, buffer, num6))
			{
				supportedEncoding = SupportedEncoding.UTF16BE;
			}
			else if (num7 == encodingUnicode.Length && CompareCaseInsensitive(encodingUnicode, buffer, num6))
			{
				if (e == SupportedEncoding.UTF8)
				{
					ThrowEncodingMismatch(SafeUTF8.GetString(buffer, num6, num7), SafeUTF8.GetString(encodingUTF8, 0, encodingUTF8.Length));
				}
			}
			else
			{
				ThrowEncodingMismatch(SafeUTF8.GetString(buffer, num6, num7), e);
			}
			if (e != supportedEncoding)
			{
				ThrowEncodingMismatch(SafeUTF8.GetString(buffer, num6, num7), e);
			}
		}

		private static bool CompareCaseInsensitive(byte[] key, byte[] buffer, int offset)
		{
			for (int i = 0; i < key.Length; i++)
			{
				if (key[i] != buffer[offset + i] && key[i] != char.ToLower((char)buffer[offset + i], CultureInfo.InvariantCulture))
				{
					return false;
				}
			}
			return true;
		}

		private static bool Compare(byte[] key, byte[] buffer, int offset)
		{
			for (int i = 0; i < key.Length; i++)
			{
				if (key[i] != buffer[offset + i])
				{
					return false;
				}
			}
			return true;
		}

		private static bool IsWhitespace(byte ch)
		{
			if (ch != 32 && ch != 10 && ch != 9)
			{
				return ch == 13;
			}
			return true;
		}

		internal static ArraySegment<byte> ProcessBuffer(byte[] buffer, int offset, int count, Encoding encoding)
		{
			if (count < 4)
			{
				throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(System.Runtime.Serialization.SR.GetString("Unexpected end of file.")));
			}
			try
			{
				SupportedEncoding supportedEncoding = GetSupportedEncoding(encoding);
				int preserve;
				SupportedEncoding supportedEncoding2 = ReadBOMEncoding(buffer[offset], buffer[offset + 1], buffer[offset + 2], buffer[offset + 3], encoding == null, out preserve);
				if (supportedEncoding != SupportedEncoding.None && supportedEncoding != supportedEncoding2)
				{
					ThrowExpectedEncodingMismatch(supportedEncoding, supportedEncoding2);
				}
				offset += 4 - preserve;
				count -= 4 - preserve;
				if (supportedEncoding2 == SupportedEncoding.UTF8)
				{
					if (buffer[offset + 1] != 63 || buffer[offset] != 60)
					{
						return new ArraySegment<byte>(buffer, offset, count);
					}
					CheckUTF8DeclarationEncoding(buffer, offset, count, supportedEncoding2, supportedEncoding);
					return new ArraySegment<byte>(buffer, offset, count);
				}
				Encoding safeEncoding = GetSafeEncoding(supportedEncoding2);
				int num = Math.Min(count, 256);
				char[] array = new char[safeEncoding.GetMaxCharCount(num)];
				int charCount = safeEncoding.GetChars(buffer, offset, num, array, 0);
				byte[] array2 = new byte[ValidatingUTF8.GetMaxByteCount(charCount)];
				int count2 = ValidatingUTF8.GetBytes(array, 0, charCount, array2, 0);
				if (array2[1] == 63 && array2[0] == 60)
				{
					CheckUTF8DeclarationEncoding(array2, 0, count2, supportedEncoding2, supportedEncoding);
				}
				else if (supportedEncoding == SupportedEncoding.None)
				{
					throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(System.Runtime.Serialization.SR.GetString("An XML declaration with an encoding is required for all non-UTF8 documents.")));
				}
				return new ArraySegment<byte>(ValidatingUTF8.GetBytes(GetEncoding(supportedEncoding2).GetChars(buffer, offset, count)));
			}
			catch (DecoderFallbackException innerException)
			{
				throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(System.Runtime.Serialization.SR.GetString("Invalid byte encoding."), innerException));
			}
		}

		private static void ThrowExpectedEncodingMismatch(SupportedEncoding expEnc, SupportedEncoding actualEnc)
		{
			throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(System.Runtime.Serialization.SR.GetString("The expected encoding '{0}' does not match the actual encoding '{1}'.", GetEncodingName(expEnc), GetEncodingName(actualEnc))));
		}

		private static void ThrowEncodingMismatch(string declEnc, SupportedEncoding enc)
		{
			ThrowEncodingMismatch(declEnc, GetEncodingName(enc));
		}

		private static void ThrowEncodingMismatch(string declEnc, string docEnc)
		{
			throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(System.Runtime.Serialization.SR.GetString("The encoding in the declaration '{0}' does not match the encoding of the document '{1}'.", declEnc, docEnc)));
		}

		public override void Close()
		{
			Flush();
			base.Close();
			stream.Close();
		}

		public override void Flush()
		{
			stream.Flush();
		}

		public override int ReadByte()
		{
			if (byteCount == 0 && encodingCode == SupportedEncoding.UTF8)
			{
				return stream.ReadByte();
			}
			if (Read(byteBuffer, 0, 1) == 0)
			{
				return -1;
			}
			return byteBuffer[0];
		}

		public override int Read(byte[] buffer, int offset, int count)
		{
			try
			{
				if (byteCount == 0)
				{
					if (encodingCode == SupportedEncoding.UTF8)
					{
						return stream.Read(buffer, offset, count);
					}
					byteOffset = 0;
					byteCount = stream.Read(bytes, byteCount, (chars.Length - 1) * 2);
					if (byteCount == 0)
					{
						return 0;
					}
					CleanupCharBreak();
					int charCount = encoding.GetChars(bytes, 0, byteCount, chars, 0);
					byteCount = Encoding.UTF8.GetBytes(chars, 0, charCount, bytes, 0);
				}
				if (byteCount < count)
				{
					count = byteCount;
				}
				Buffer.BlockCopy(bytes, byteOffset, buffer, offset, count);
				byteOffset += count;
				byteCount -= count;
				return count;
			}
			catch (DecoderFallbackException innerException)
			{
				throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(System.Runtime.Serialization.SR.GetString("Invalid byte encoding."), innerException));
			}
		}

		private void CleanupCharBreak()
		{
			int num = byteOffset + byteCount;
			if (byteCount % 2 != 0)
			{
				int num2 = stream.ReadByte();
				if (num2 < 0)
				{
					throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(System.Runtime.Serialization.SR.GetString("Unexpected end of file.")));
				}
				bytes[num++] = (byte)num2;
				byteCount++;
			}
			int num3 = ((encodingCode != SupportedEncoding.UTF16LE) ? (bytes[num - 1] + (bytes[num - 2] << 8)) : (bytes[num - 2] + (bytes[num - 1] << 8)));
			if ((num3 & 0xDC00) != 56320 && num3 >= 55296 && num3 <= 56319)
			{
				int num4 = stream.ReadByte();
				int num5 = stream.ReadByte();
				if (num5 < 0)
				{
					throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(System.Runtime.Serialization.SR.GetString("Unexpected end of file.")));
				}
				bytes[num++] = (byte)num4;
				bytes[num++] = (byte)num5;
				byteCount += 2;
			}
		}

		public override long Seek(long offset, SeekOrigin origin)
		{
			throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException());
		}

		public override void WriteByte(byte b)
		{
			if (encodingCode == SupportedEncoding.UTF8)
			{
				stream.WriteByte(b);
				return;
			}
			byteBuffer[0] = b;
			Write(byteBuffer, 0, 1);
		}

		public override void Write(byte[] buffer, int offset, int count)
		{
			if (encodingCode == SupportedEncoding.UTF8)
			{
				stream.Write(buffer, offset, count);
				return;
			}
			while (count > 0)
			{
				int num = ((chars.Length < count) ? chars.Length : count);
				int charCount = dec.GetChars(buffer, offset, num, chars, 0, flush: false);
				byteCount = enc.GetBytes(chars, 0, charCount, bytes, 0, flush: false);
				stream.Write(bytes, 0, byteCount);
				offset += num;
				count -= num;
			}
		}

		public override void SetLength(long value)
		{
			throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException());
		}
	}
	public interface IFragmentCapableXmlDictionaryWriter
	{
		bool CanFragment { get; }

		void StartFragment(Stream stream, bool generateSelfContainedTextFragment);

		void EndFragment();

		void WriteFragment(byte[] buffer, int offset, int count);
	}
	public interface IStreamProvider
	{
		Stream GetStream();

		void ReleaseStream(Stream stream);
	}
	public interface IXmlDictionary
	{
		bool TryLookup(string value, out XmlDictionaryString result);

		bool TryLookup(int key, out XmlDictionaryString result);

		bool TryLookup(XmlDictionaryString value, out XmlDictionaryString result);
	}
	internal enum PrefixHandleType
	{
		Empty,
		A,
		B,
		C,
		D,
		E,
		F,
		G,
		H,
		I,
		J,
		K,
		L,
		M,
		N,
		O,
		P,
		Q,
		R,
		S,
		T,
		U,
		V,
		W,
		X,
		Y,
		Z,
		Buffer,
		Max
	}
	internal class PrefixHandle
	{
		private XmlBufferReader bufferReader;

		private PrefixHandleType type;

		private int offset;

		private int length;

		private static string[] prefixStrings = new string[27]
		{
			"", "a", "b", "c", "d", "e", "f", "g", "h", "i",
			"j", "k", "l", "m", "n", "o", "p", "q", "r", "s",
			"t", "u", "v", "w", "x", "y", "z"
		};

		private static byte[] prefixBuffer = new byte[26]
		{
			97, 98, 99, 100, 101, 102, 103, 104, 105, 106,
			107, 108, 109, 110, 111, 112, 113, 114, 115, 116,
			117, 118, 119, 120, 121, 122
		};

		public bool IsEmpty => type == PrefixHandleType.Empty;

		public bool IsXmlns
		{
			get
			{
				if (type != PrefixHandleType.Buffer)
				{
					return false;
				}
				if (length != 5)
				{
					return false;
				}
				byte[] buffer = bufferReader.Buffer;
				int num = offset;
				if (buffer[num] == 120 && buffer[num + 1] == 109 && buffer[num + 2] == 108 && buffer[num + 3] == 110)
				{
					return buffer[num + 4] == 115;
				}
				return false;
			}
		}

		public bool IsXml
		{
			get
			{
				if (type != PrefixHandleType.Buffer)
				{
					return false;
				}
				if (length != 3)
				{
					return false;
				}
				byte[] buffer = bufferReader.Buffer;
				int num = offset;
				if (buffer[num] == 120 && buffer[num + 1] == 109)
				{
					return buffer[num + 2] == 108;
				}
				return false;
			}
		}

		public PrefixHandle(XmlBufferReader bufferReader)
		{
			this.bufferReader = bufferReader;
		}

		public void SetValue(PrefixHandleType type)
		{
			this.type = type;
		}

		public void SetValue(PrefixHandle prefix)
		{
			type = prefix.type;
			offset = prefix.offset;
			length = prefix.length;
		}

		public void SetValue(int offset, int length)
		{
			switch (length)
			{
			case 0:
				SetValue(PrefixHandleType.Empty);
				return;
			case 1:
			{
				byte @byte = bufferReader.GetByte(offset);
				if (@byte >= 97 && @byte <= 122)
				{
					SetValue(GetAlphaPrefix(@byte - 97));
					return;
				}
				break;
			}
			}
			type = PrefixHandleType.Buffer;
			this.offset = offset;
			this.length = length;
		}

		public bool TryGetShortPrefix(out PrefixHandleType type)
		{
			type = this.type;
			return type != PrefixHandleType.Buffer;
		}

		public static string GetString(PrefixHandleType type)
		{
			return prefixStrings[(int)type];
		}

		public static PrefixHandleType GetAlphaPrefix(int index)
		{
			return (PrefixHandleType)(1 + index);
		}

		public static byte[] GetString(PrefixHandleType type, out int offset, out int length)
		{
			if (type == PrefixHandleType.Empty)
			{
				offset = 0;
				length = 0;
			}
			else
			{
				length = 1;
				offset = (int)(type - 1);
			}
			return prefixBuffer;
		}

		public string GetString(XmlNameTable nameTable)
		{
			PrefixHandleType prefixHandleType = type;
			if (prefixHandleType != PrefixHandleType.Buffer)
			{
				return GetString(prefixHandleType);
			}
			return bufferReader.GetString(offset, length, nameTable);
		}

		public string GetString()
		{
			PrefixHandleType prefixHandleType = type;
			if (prefixHandleType != PrefixHandleType.Buffer)
			{
				return GetString(prefixHandleType);
			}
			return bufferReader.GetString(offset, length);
		}

		public byte[] GetString(out int offset, out int length)
		{
			PrefixHandleType prefixHandleType = type;
			if (prefixHandleType != PrefixHandleType.Buffer)
			{
				return GetString(prefixHandleType, out offset, out length);
			}
			offset = this.offset;
			length = this.length;
			return bufferReader.Buffer;
		}

		public int CompareTo(PrefixHandle that)
		{
			return GetString().CompareTo(that.GetString());
		}

		private bool Equals2(PrefixHandle prefix2)
		{
			PrefixHandleType prefixHandleType = type;
			PrefixHandleType prefixHandleType2 = prefix2.type;
			if (prefixHandleType != prefixHandleType2)
			{
				return false;
			}
			if (prefixHandleType != PrefixHandleType.Buffer)
			{
				return true;
			}
			if (bufferReader == prefix2.bufferReader)
			{
				return bufferReader.Equals2(offset, length, prefix2.offset, prefix2.length);
			}
			return bufferReader.Equals2(offset, length, prefix2.bufferReader, prefix2.offset, prefix2.length);
		}

		private bool Equals2(string prefix2)
		{
			PrefixHandleType prefixHandleType = type;
			if (prefixHandleType != PrefixHandleType.Buffer)
			{
				return GetString(prefixHandleType) == prefix2;
			}
			return bufferReader.Equals2(offset, length, prefix2);
		}

		private bool Equals2(XmlDictionaryString prefix2)
		{
			return Equals2(prefix2.Value);
		}

		public static bool operator ==(PrefixHandle prefix1, string prefix2)
		{
			return prefix1.Equals2(prefix2);
		}

		public static bool operator !=(PrefixHandle prefix1, string prefix2)
		{
			return !prefix1.Equals2(prefix2);
		}

		public static bool operator ==(PrefixHandle prefix1, XmlDictionaryString prefix2)
		{
			return prefix1.Equals2(prefix2);
		}

		public static bool operator !=(PrefixHandle prefix1, XmlDictionaryString prefix2)
		{
			return !prefix1.Equals2(prefix2);
		}

		public static bool operator ==(PrefixHandle prefix1, PrefixHandle prefix2)
		{
			return prefix1.Equals2(prefix2);
		}

		public static bool operator !=(PrefixHandle prefix1, PrefixHandle prefix2)
		{
			return !prefix1.Equals2(prefix2);
		}

		public override bool Equals(object obj)
		{
			if (!(obj is PrefixHandle prefixHandle))
			{
				return false;
			}
			return this == prefixHandle;
		}

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

		public override int GetHashCode()
		{
			return GetString().GetHashCode();
		}
	}
	internal enum StringHandleConstStringType
	{
		Type,
		Root,
		Item
	}
	internal class StringHandle
	{
		private enum StringHandleType
		{
			Dictionary,
			UTF8,
			EscapedUTF8,
			ConstString
		}

		private XmlBufferReader bufferReader;

		private StringHandleType type;

		private int key;

		private int offset;

		private int length;

		private static string[] constStrings = new string[3] { "type", "root", "item" };

		public bool IsEmpty
		{
			get
			{
				if (type == StringHandleType.UTF8)
				{
					return length == 0;
				}
				return Equals2(string.Empty);
			}
		}

		public bool IsXmlns
		{
			get
			{
				if (type == StringHandleType.UTF8)
				{
					if (length != 5)
					{
						return false;
					}
					byte[] buffer = bufferReader.Buffer;
					int num = offset;
					if (buffer[num] == 120 && buffer[num + 1] == 109 && buffer[num + 2] == 108 && buffer[num + 3] == 110)
					{
						return buffer[num + 4] == 115;
					}
					return false;
				}
				return Equals2("xmlns");
			}
		}

		public StringHandle(XmlBufferReader bufferReader)
		{
			this.bufferReader = bufferReader;
			SetValue(0, 0);
		}

		public void SetValue(int offset, int length)
		{
			type = StringHandleType.UTF8;
			this.offset = offset;
			this.length = length;
		}

		public void SetConstantValue(StringHandleConstStringType constStringType)
		{
			type = StringHandleType.ConstString;
			key = (int)constStringType;
		}

		public void SetValue(int offset, int length, bool escaped)
		{
			type = ((!escaped) ? StringHandleType.UTF8 : StringHandleType.EscapedUTF8);
			this.offset = offset;
			this.length = length;
		}

		public void SetValue(int key)
		{
			type = StringHandleType.Dictionary;
			this.key = key;
		}

		public void SetValue(StringHandle value)
		{
			type = value.type;
			key = value.key;
			offset = value.offset;
			length = value.length;
		}

		public void ToPrefixHandle(PrefixHandle prefix)
		{
			prefix.SetValue(offset, length);
		}

		public string GetString(XmlNameTable nameTable)
		{
			return type switch
			{
				StringHandleType.UTF8 => bufferReader.GetString(offset, length, nameTable), 
				StringHandleType.Dictionary => nameTable.Add(bufferReader.GetDictionaryString(key).Value), 
				StringHandleType.ConstString => nameTable.Add(constStrings[key]), 
				_ => bufferReader.GetEscapedString(offset, length, nameTable), 
			};
		}

		public string GetString()
		{
			return type switch
			{
				StringHandleType.UTF8 => bufferReader.GetString(offset, length), 
				StringHandleType.Dictionary => bufferReader.GetDictionaryString(key).Value, 
				StringHandleType.ConstString => constStrings[key], 
				_ => bufferReader.GetEscapedString(offset, length), 
			};
		}

		public byte[] GetString(out int offset, out int length)
		{
			switch (type)
			{
			case StringHandleType.UTF8:
				offset = this.offset;
				length = this.length;
				return bufferReader.Buffer;
			case StringHandleType.Dictionary:
			{
				byte[] array3 = bufferReader.GetDictionaryString(key).ToUTF8();
				offset = 0;
				length = array3.Length;
				return array3;
			}
			case StringHandleType.ConstString:
			{
				byte[] array2 = XmlConverter.ToBytes(constStrings[key]);
				offset = 0;
				length = array2.Length;
				return array2;
			}
			default:
			{
				byte[] array = XmlConverter.ToBytes(bufferReader.GetEscapedString(this.offset, this.length));
				offset = 0;
				length = array.Length;
				return array;
			}
			}
		}

		public bool TryGetDictionaryString(out XmlDictionaryString value)
		{
			if (type == StringHandleType.Dictionary)
			{
				value = bufferReader.GetDictionaryString(key);
				return true;
			}
			if (IsEmpty)
			{
				value = XmlDictionaryString.Empty;
				return true;
			}
			value = null;
			return false;
		}

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

		private bool Equals2(int key2, XmlBufferReader bufferReader2)
		{
			return type switch
			{
				StringHandleType.Dictionary => bufferReader.Equals2(key, key2, bufferReader2), 
				StringHandleType.UTF8 => bufferReader.Equals2(offset, length, bufferReader2.GetDictionaryString(key2).Value), 
				_ => GetString() == bufferReader.GetDictionaryString(key2).Value, 
			};
		}

		private bool Equals2(XmlDictionaryString xmlString2)
		{
			return type switch
			{
				StringHandleType.Dictionary => bufferReader.Equals2(key, xmlString2), 
				StringHandleType.UTF8 => bufferReader.Equals2(offset, length, xmlString2.ToUTF8()), 
				_ => GetString() == xmlString2.Value, 
			};
		}

		private bool Equals2(string s2)
		{
			return type switch
			{
				StringHandleType.Dictionary => bufferReader.GetDictionaryString(key).Value == s2, 
				StringHandleType.UTF8 => bufferReader.Equals2(offset, length, s2), 
				_ => GetString() == s2, 
			};
		}

		private bool Equals2(int offset2, int length2, XmlBufferReader bufferReader2)
		{
			return type switch
			{
				StringHandleType.Dictionary => bufferReader2.Equals2(offset2, length2, bufferReader.GetDictionaryString(key).Value), 
				StringHandleType.UTF8 => bufferReader.Equals2(offset, length, bufferReader2, offset2, length2), 
				_ => GetString() == bufferReader.GetString(offset2, length2), 
			};
		}

		private bool Equals2(StringHandle s2)
		{
			return s2.type switch
			{
				StringHandleType.Dictionary => Equals2(s2.key, s2.bufferReader), 
				StringHandleType.UTF8 => Equals2(s2.offset, s2.length, s2.bufferReader), 
				_ => Equals2(s2.GetString()), 
			};
		}

		public static bool operator ==(StringHandle s1, XmlDictionaryString xmlString2)
		{
			return s1.Equals2(xmlString2);
		}

		public static bool operator !=(StringHandle s1, XmlDictionaryString xmlString2)
		{
			return !s1.Equals2(xmlString2);
		}

		public static bool operator ==(StringHandle s1, string s2)
		{
			return s1.Equals2(s2);
		}

		public static bool operator !=(StringHandle s1, string s2)
		{
			return !s1.Equals2(s2);
		}

		public static bool operator ==(StringHandle s1, StringHandle s2)
		{
			return s1.Equals2(s2);
		}

		public static bool operator !=(StringHandle s1, StringHandle s2)
		{
			return !s1.Equals2(s2);
		}

		public int CompareTo(StringHandle that)
		{
			if (type == StringHandleType.UTF8 && that.type == StringHandleType.UTF8)
			{
				return bufferReader.Compare(offset, length, that.offset, that.length);
			}
			return string.Compare(GetString(), that.GetString(), StringComparison.Ordinal);
		}

		public override bool Equals(object obj)
		{
			if (!(obj is StringHandle stringHandle))
			{
				return false;
			}
			return this == stringHandle;
		}

		public override int GetHashCode()
		{
			return GetString().GetHashCode();
		}
	}
	public class UniqueId
	{
		private long idLow;

		private long idHigh;

		[SecurityCritical]
		private string s;

		private const int guidLength = 16;

		private const int uuidLength = 45;

		private static short[] char2val = new short[256]
		{
			256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
			256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
			256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
			256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
			256, 256, 256, 256, 256, 256, 256, 256, 0, 16,
			32, 48, 64, 80, 96, 112, 128, 144, 256, 256,
			256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
			256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
			256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
			256, 256, 256, 256, 256, 256, 256, 160, 176, 192,
			208, 224, 240, 256, 256, 256, 256, 256, 256, 256,
			256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
			256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
			256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
			256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
			256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
			256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
			256, 256, 256, 256, 256, 256, 0, 1, 2, 3,
			4, 5, 6, 7, 8, 9, 256, 256, 256, 256,
			256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
			256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
			256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
			256, 256, 256, 256, 256, 10, 11, 12, 13, 14,
			15, 256, 256, 256, 256, 256, 256, 256, 256, 256,
			256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
			256, 256, 256, 256, 256, 256
		};

		private const string val2char = "0123456789abcdef";

		public int CharArrayLength
		{
			[SecuritySafeCritical]
			get
			{
				if (s != null)
				{
					return s.Length;
				}
				return 45;
			}
		}

		public bool IsGuid => (idLow | idHigh) != 0;

		public UniqueId()
			: this(Guid.NewGuid())
		{
		}

		public UniqueId(Guid guid)
			: this(guid.ToByteArray())
		{
		}

		public UniqueId(byte[] guid)
			: this(guid, 0)
		{
		}

		[SecuritySafeCritical]
		public unsafe UniqueId(byte[] guid, int offset)
		{
			if (guid == null)
			{
				throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("guid"));
			}
			if (offset < 0)
			{
				throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("offset", System.Runtime.Serialization.SR.GetString("The value of this argument must be non-negative.")));
			}
			if (offset > guid.Length)
			{
				throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("offset", System.Runtime.Serialization.SR.GetString("The specified offset exceeds the buffer size ({0} bytes).", guid.Length)));
			}
			if (16 > guid.Length - offset)
			{
				throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(System.Runtime.Serialization.SR.GetString("Array too small.  Length of available data must be at least {0}.", 16), "guid"));
			}
			fixed (byte* ptr = &guid[offset])
			{
				idLow = UnsafeGetInt64(ptr);
				idHigh = UnsafeGetInt64(ptr + 8);
			}
		}

		[SecuritySafeCritical]
		public unsafe UniqueId(string value)
		{
			if (value == null)
			{
				throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("value");
			}
			if (value.Length == 0)
			{
				throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new FormatException(System.Runtime.Serialization.SR.GetString("UniqueId cannot be zero length.")));
			}
			fixed (char* chars = value)
			{
				UnsafeParse(chars, value.Length);
			}
			s = value;
		}

		[SecuritySafeCritical]
		public unsafe UniqueId(char[] chars, int offset, int count)
		{
			if (chars == null)
			{
				throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("chars"));
			}
			if (offset < 0)
			{
				throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("offset", System.Runtime.Serialization.SR.GetString("The value of this argument must be non-negative.")));
			}
			if (offset > chars.Length)
			{
				throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("offset", System.Runtime.Serialization.SR.GetString("The specified offset exceeds the buffer size ({0} bytes).", chars.Length)));
			}
			if (count < 0)
			{
				throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("count", System.Runtime.Serialization.SR.GetString("The value of this argument must be non-negative.")));
			}
			if (count > chars.Length - offset)
			{
				throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("count", System.Runtime.Serialization.SR.GetString("The specified size exceeds the remaining buffer space ({0} bytes).", chars.Length - offset)));
			}
			if (count == 0)
			{
				throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new FormatException(System.Runtime.Serialization.SR.GetString("UniqueId cannot be zero length.")));
			}
			fixed (char* chars2 = &chars[offset])
			{
				UnsafeParse(chars2, count);
			}
			if (!IsGuid)
			{
				s = new string(chars, offset, count);
			}
		}

		[SecurityCritical]
		private unsafe int UnsafeDecode(short* char2val, char ch1, char ch2)
		{
			if ((ch1 | ch2) >= 128)
			{
				return 256;
			}
			return char2val[(int)ch1] | char2val[128 + ch2];
		}

		[SecurityCritical]
		private unsafe void UnsafeEncode(char* val2char, byte b, char* pch)
		{
			*pch = val2char[b >> 4];
			pch[1] = val2char[b & 0xF];
		}

		[SecurityCritical]
		private unsafe void UnsafeParse(char* chars, int charCount)
		{
			if (charCount != 45 || *chars != 'u' || chars[1] != 'r' || chars[2] != 'n' || chars[3] != ':' || chars[4] != 'u' || chars[5] != 'u' || chars[6] != 'i' || chars[7] != 'd' || chars[8] != ':' || chars[17] != '-' || chars[22] != '-' || chars[27] != '-' || chars[32] != '-')
			{
				return;
			}
			byte* ptr = stackalloc byte[16];
			int num = 0;
			fixed (short* ptr2 = char2val)
			{
				short* ptr3 = ptr2;
				num = UnsafeDecode(ptr3, chars[15], chars[16]);
				*ptr = (byte)num;
				int num2 = 0 | num;
				num = UnsafeDecode(ptr3, chars[13], chars[14]);
				ptr[1] = (byte)num;
				int num3 = num2 | num;
				num = UnsafeDecode(ptr3, chars[11], chars[12]);
				ptr[2] = (byte)num;
				int num4 = num3 | num;
				num = UnsafeDecode(ptr3, chars[9], chars[10]);
				ptr[3] = (byte)num;
				int num5 = num4 | num;
				num = UnsafeDecode(ptr3, chars[20], chars[21]);
				ptr[4] = (byte)num;
				int num6 = num5 | num;
				num = UnsafeDecode(ptr3, chars[18], chars[19]);
				ptr[5] = (byte)num;
				int num7 = num6 | num;
				num = UnsafeDecode(ptr3, chars[25], chars[26]);
				ptr[6] = (byte)num;
				int num8 = num7 | num;
				num = UnsafeDecode(ptr3, chars[23], chars[24]);
				ptr[7] = (byte)num;
				int num9 = num8 | num;
				num = UnsafeDecode(ptr3, chars[28], chars[29]);
				ptr[8] = (byte)num;
				int num10 = num9 | num;
				num = UnsafeDecode(ptr3, chars[30], chars[31]);
				ptr[9] = (byte)num;
				int num11 = num10 | num;
				num = UnsafeDecode(ptr3, chars[33], chars[34]);
				ptr[10] = (byte)num;
				int num12 = num11 | num;
				num = UnsafeDecode(ptr3, chars[35], chars[36]);
				ptr[11] = (byte)num;
				int num13 = num12 | num;
				num = UnsafeDecode(ptr3, chars[37], chars[38]);
				ptr[12] = (byte)num;
				int num14 = num13 | num;
				num = UnsafeDecode(ptr3, chars[39], chars[40]);
				ptr[13] = (byte)num;
				int num15 = num14 | num;
				num = UnsafeDecode(ptr3, chars[41], chars[42]);
				ptr[14] = (byte)num;
				int num16 = num15 | num;
				num = UnsafeDecode(ptr3, chars[43], chars[44]);
				ptr[15] = (byte)num;
				if ((num16 | num) >= 256)
				{
					return;
				}
				idLow = UnsafeGetInt64(ptr);
				idHigh = UnsafeGetInt64(ptr + 8);
			}
		}

		[SecuritySafeCritical]
		public unsafe int ToCharArray(char[] chars, int offset)
		{
			int charArrayLength = CharArrayLength;
			if (chars == null)
			{
				throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("chars"));
			}
			if (offset < 0)
			{
				throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("offset", System.Runtime.Serialization.SR.GetString("The value of this argument must be non-negative.")));
			}
			if (offset > chars.Length)
			{
				throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("offset", System.Runtime.Serialization.SR.GetString("The specified offset exceeds the buffer size ({0} bytes).", chars.Length)));
			}
			if (charArrayLength > chars.Length - offset)
			{
				throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("chars", System.Runtime.Serialization.SR.GetString("Array too small.  Must be able to hold at least {0}.", charArrayLength)));
			}
			if (s != null)
			{
				s.CopyTo(0, chars, offset, charArrayLength);
			}
			else
			{
				byte* ptr = stackalloc byte[16];
				UnsafeSetInt64(idLow, ptr);
				UnsafeSetInt64(idHigh, ptr + 8);
				fixed (char* ptr2 = &chars[offset])
				{
					*ptr2 = 'u';
					ptr2[1] = 'r';
					ptr2[2] = 'n';
					ptr2[3] = ':';
					ptr2[4] = 'u';
					ptr2[5] = 'u';
					ptr2[6] = 'i';
					ptr2[7] = 'd';
					ptr2[8] = ':';
					ptr2[17] = '-';
					ptr2[22] = '-';
					ptr2[27] = '-';
					ptr2[32] = '-';
					fixed (char* ptr3 = "0123456789abcdef")
					{
						char* ptr4 = ptr3;
						UnsafeEncode(ptr4, *ptr, ptr2 + 15);
						UnsafeEncode(ptr4, ptr[1], ptr2 + 13);
						UnsafeEncode(ptr4, ptr[2], ptr2 + 11);
						UnsafeEncode(ptr4, ptr[3], ptr2 + 9);
						UnsafeEncode(ptr4, ptr[4], ptr2 + 20);
						UnsafeEncode(ptr4, ptr[5], ptr2 + 18);
						UnsafeEncode(ptr4, ptr[6], ptr2 + 25);
						UnsafeEncode(ptr4, ptr[7], ptr2 + 23);
						UnsafeEncode(ptr4, ptr[8], ptr2 + 28);
						UnsafeEncode(ptr4, ptr[9], ptr2 + 30);
						UnsafeEncode(ptr4, ptr[10], ptr2 + 33);
						UnsafeEncode(ptr4, ptr[11], ptr2 + 35);
						UnsafeEncode(ptr4, ptr[12], ptr2 + 37);
						UnsafeEncode(ptr4, ptr[13], ptr2 + 39);
						UnsafeEncode(ptr4, ptr[14], ptr2 + 41);
						UnsafeEncode(ptr4, ptr[15], ptr2 + 43);
					}
				}
			}
			return charArrayLength;
		}

		public bool TryGetGuid(out Guid guid)
		{
			byte[] array = new byte[16];
			if (!TryGetGuid(array, 0))
			{
				guid = Guid.Empty;
				return false;
			}
			guid = new Guid(array);
			return true;
		}

		[SecuritySafeCritical]
		public unsafe bool TryGetGuid(byte[] buffer, int offset)
		{
			if (!IsGuid)
			{
				return false;
			}
			if (buffer == null)
			{
				throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("buffer"));
			}
			if (offset < 0)
			{
				throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("offset", System.Runtime.Serialization.SR.GetString("The value of this argument must be non-negative.")));
			}
			if (offset > buffer.Length)
			{
				throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("offset", System.Runtime.Serialization.SR.GetString("The specified offset exceeds the buffer size ({0} bytes).", buffer.Length)));
			}
			if (16 > buffer.Length - offset)
			{
				throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("buffer", System.Runtime.Serialization.SR.GetString("Array too small.  Must be able to hold at least {0}.", 16)));
			}
			fixed (byte* ptr = &buffer[offset])
			{
				UnsafeSetInt64(idLow, ptr);
				UnsafeSetInt64(idHigh, ptr + 8);
			}
			return true;
		}

		[SecuritySafeCritical]
		public override string ToString()
		{
			if (s == null)
			{
				int charArrayLength = CharArrayLength;
				char[] array = new char[charArrayLength];
				ToCharArray(array, 0);
				s = new string(array, 0, charArrayLength);
			}
			return s;
		}

		public static bool operator ==(UniqueId id1, UniqueId id2)
		{
			if ((object)id1 == null && (object)id2 == null)
			{
				return true;
			}
			if ((object)id1 == null || (object)id2 == null)
			{
				return false;
			}
			if (id1.IsGuid && id2.IsGuid)
			{
				if (id1.idLow == id2.idLow)
				{
					return id1.idHigh == id2.idHigh;
				}
				return false;
			}
			return id1.ToString() == id2.ToString();
		}

		public static bool operator !=(UniqueId id1, UniqueId id2)
		{
			return !(id1 == id2);
		}

		public override bool Equals(object obj)
		{
			return this == obj as UniqueId;
		}

		public override int GetHashCode()
		{
			if (IsGuid)
			{
				long num = idLow ^ idHigh;
				return (int)(num >> 32) ^ (int)num;
			}
			return ToString().GetHashCode();
		}

		[SecurityCritical]
		private unsafe long UnsafeGetInt64(byte* pb)
		{
			int num = UnsafeGetInt32(pb);
			return ((long)UnsafeGetInt32(pb + 4) << 32) | (uint)num;
		}

		[SecurityCritical]
		private unsafe int UnsafeGetInt32(byte* pb)
		{
			return (((((pb[3] << 8) | pb[2]) << 8) | pb[1]) << 8) | *pb;
		}

		[SecurityCritical]
		private unsafe void UnsafeSetInt64(long value, byte* pb)
		{
			UnsafeSetInt32((int)value, pb);
			UnsafeSetInt32((int)(value >> 32), pb + 4);
		}

		[SecurityCritical]
		private unsafe void UnsafeSetInt32(int value, byte* pb)
		{
			*pb = (byte)value;
			value >>= 8;
			pb[1] = (byte)value;
			value >>= 8;
			pb[2] = (byte)value;
			value >>= 8;
			pb[3] = (byte)value;
		}
	}
	internal enum ValueHandleConstStringType
	{
		String,
		Number,
		Array,
		Object,
		Boolean,
		Null
	}
	internal static class ValueHandleLength
	{
		public const int Int8 = 1;

		public const int Int16 = 2;

		public const int Int32 = 4;

		public const int Int64 = 8;

		public const int UInt64 = 8;

		public const int Single = 4;

		public const int Double = 8;

		public const int Decimal = 16;

		public const int DateTime = 8;

		public const int TimeSpan = 8;

		public const int Guid = 16;

		public const int UniqueId = 16;
	}
	internal enum ValueHandleType
	{
		Empty,
		True,
		False,
		Zero,
		One,
		Int8,
		Int16,
		Int32,
		Int64,
		UInt64,
		Single,
		Double,
		Decimal,
		DateTime,
		TimeSpan,
		Guid,
		UniqueId,
		UTF8,
		EscapedUTF8,
		Base64,
		Dictionary,
		List,
		Char,
		Unicode,
		QName,
		ConstString
	}
	internal class ValueHandle
	{
		private XmlBufferReader bufferReader;

		private ValueHandleType type;

		private int offset;

		private int length;

		private static Base64Encoding base64Encoding;

		private static string[] constStrings = new string[6] { "string", "number", "array", "object", "boolean", "null" };

		private static Base64Encoding Base64Encoding
		{
			get
			{
				if (base64Encoding == null)
				{
					base64Encoding = new Base64Encoding();
				}
				return base64Encoding;
			}
		}

		public ValueHandle(XmlBufferReader bufferReader)
		{
			this.bufferReader = bufferReader;
			type = ValueHandleType.Empty;
		}

		public void SetConstantValue(ValueHandleConstStringType constStringType)
		{
			type = ValueHandleType.ConstString;
			offset = (int)constStringType;
		}

		public void SetValue(ValueHandleType type)
		{
			this.type = type;
		}

		public void SetDictionaryValue(int key)
		{
			SetValue(ValueHandleType.Dictionary, key, 0);
		}

		public void SetCharValue(int ch)
		{
			SetValue(ValueHandleType.Char, ch, 0);
		}

		public void SetQNameValue(int prefix, int key)
		{
			SetValue(ValueHandleType.QName, key, prefix);
		}

		public void SetValue(ValueHandleType type, int offset, int length)
		{
			this.type = type;
			this.offset = offset;
			this.length = length;
		}

		public bool IsWhitespace()
		{
			switch (type)
			{
			case ValueHandleType.UTF8:
				return bufferReader.IsWhitespaceUTF8(offset, length);
			case ValueHandleType.Dictionary:
				return bufferReader.IsWhitespaceKey(offset);
			case ValueHandleType.Char:
			{
				int @char = GetChar();
				if (@char > 65535)
				{
					return false;
				}
				return XmlConverter.IsWhitespace((char)@char);
			}
			case ValueHandleType.EscapedUTF8:
				return bufferReader.IsWhitespaceUTF8(offset, length);
			case ValueHandleType.Unicode:
				return bufferReader.IsWhitespaceUnicode(offset, length);
			case ValueHandleType.True:
			case ValueHandleType.False:
			case ValueHandleType.Zero:
			case ValueHandleType.One:
				return false;
			case ValueHandleType.ConstString:
				return constStrings[offset].Length == 0;
			default:
				return length == 0;
			}
		}

		public Type ToType()
		{
			switch (type)
			{
			case ValueHandleType.True:
			case ValueHandleType.False:
				return typeof(bool);
			case ValueHandleType.Zero:
			case ValueHandleType.One:
			case ValueHandleType.Int8:
			case ValueHandleType.Int16:
			case ValueHandleType.Int32:
				return typeof(int);
			case ValueHandleType.Int64:
				return typeof(long);
			case ValueHandleType.UInt64:
				return typeof(ulong);
			case ValueHandleType.Single:
				return typeof(float);
			case ValueHandleType.Double:
				return typeof(double);
			case ValueHandleType.Decimal:
				return typeof(decimal);
			case ValueHandleType.DateTime:
				return typeof(DateTime);
			case ValueHandleType.Empty:
			case ValueHandleType.UTF8:
			case ValueHandleType.EscapedUTF8:
			case ValueHandleType.Dictionary:
			case ValueHandleType.Char:
			case ValueHandleType.Unicode:
			case ValueHandleType.QName:
			case ValueHandleType.ConstString:
				return typeof(string);
			case ValueHandleType.Base64:
				return typeof(byte[]);
			case ValueHandleType.List:
				return typeof(object[]);
			case ValueHandleType.UniqueId:
				return typeof(UniqueId);
			case ValueHandleType.Guid:
				return typeof(Guid);
			case ValueHandleType.TimeSpan:
				return typeof(TimeSpan);
			default:
				throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException());
			}
		}

		public bool ToBoolean()
		{
			switch (type)
			{
			case ValueHandleType.False:
				return false;
			case ValueHandleType.True:
				return true;
			case ValueHandleType.UTF8:
				return XmlConverter.ToBoolean(bufferReader.Buffer, offset, length);
			case ValueHandleType.Int8:
				switch (GetInt8())
				{
				case 0:
					return false;
				case 1:
					return true;
				}
				break;
			}
			return XmlConverter.ToBoolean(GetString());
		}

		public int ToInt()
		{
			ValueHandleType valueHandleType = type;
			switch (valueHandleType)
			{
			case ValueHandleType.Zero:
				return 0;
			case ValueHandleType.One:
				return 1;
			case ValueHandleType.Int8:
				return GetInt8();
			case ValueHandleType.Int16:
				return GetInt16();
			case ValueHandleType.Int32:
				return GetInt32();
			case ValueHandleType.Int64:
			{
				long @int = GetInt64();
				if (@int >= int.MinValue && @int <= int.MaxValue)
				{
					return (int)@int;
				}
				break;
			}
			}
			if (valueHandleType == ValueHandleType.UInt64)
			{
				ulong uInt = GetUInt64();
				if (uInt <= int.MaxValue)
				{
					return (int)uInt;
				}
			}
			if (valueHandleType == ValueHandleType.UTF8)
			{
				return XmlConverter.ToInt32(bufferReader.Buffer, offset, length);
			}
			return XmlConverter.ToInt32(GetString());
		}

		public long ToLong()
		{
			ValueHandleType valueHandleType = type;
			switch (valueHandleType)
			{
			case ValueHandleType.Zero:
				return 0L;
			case ValueHandleType.One:
				return 1L;
			case ValueHandleType.Int8:
				return GetInt8();
			case ValueHandleType.Int16:
				return GetInt16();
			case ValueHandleType.Int32:
				return GetInt32();
			case ValueHandleType.Int64:
				return GetInt64();
			case ValueHandleType.UInt64:
			{
				ulong uInt = GetUInt64();
				if (uInt <= long.MaxValue)
				{
					return (long)uInt;
				}
				break;
			}
			}
			if (valueHandleType == ValueHandleType.UTF8)
			{
				return XmlConverter.ToInt64(bufferReader.Buffer, offset, length);
			}
			return XmlConverter.ToInt64(GetString());
		}

		public ulong ToULong()
		{
			ValueHandleType valueHandleType = type;
			switch (valueHandleType)
			{
			case ValueHandleType.Zero:
				return 0uL;
			case ValueHandleType.One:
				return 1uL;
			case ValueHandleType.Int8:
			case ValueHandleType.Int16:
			case ValueHandleType.Int32:
			case ValueHandleType.Int64:
			{
				long num = ToLong();
				if (num >= 0)
				{
					return (ulong)num;
				}
				break;
			}
			}
			return valueHandleType switch
			{
				ValueHandleType.UInt64 => GetUInt64(), 
				ValueHandleType.UTF8 => XmlConverter.ToUInt64(bufferReader.Buffer, offset, length), 
				_ => XmlConverter.ToUInt64(GetString()), 
			};
		}

		public float ToSingle()
		{
			ValueHandleType valueHandleType = type;
			switch (valueHandleType)
			{
			case ValueHandleType.Single:
				return GetSingle();
			case ValueHandleType.Double:
			{
				double @double = GetDouble();
				if ((@double >= -3.4028234663852886E+38 && @double <= 3.4028234663852886E+38) || double.IsInfinity(@double) || double.IsNaN(@double))
				{
					return (float)@double;
				}
				break;
			}
			}
			return valueHandleType switch
			{
				ValueHandleType.Zero => 0f, 
				ValueHandleType.One => 1f, 
				ValueHandleType.Int8 => GetInt8(), 
				ValueHandleType.Int16 => GetInt16(), 
				ValueHandleType.UTF8 => XmlConverter.ToSingle(bufferReader.Buffer, offset, length), 
				_ => XmlConverter.ToSingle(GetString()), 
			};
		}

		public double ToDouble()
		{
			return type switch
			{
				ValueHandleType.Double => GetDouble(), 
				ValueHandleType.Single => GetSingle(), 
				ValueHandleType.Zero => 0.0, 
				ValueHandleType.One => 1.0, 
				ValueHandleType.Int8 => GetInt8(), 
				ValueHandleType.Int16 => GetInt16(), 
				ValueHandleType.Int32 => GetInt32(), 
				ValueHandleType.UTF8 => XmlConverter.ToDouble(bufferReader.Buffer, offset, length), 
				_ => XmlConverter.ToDouble(GetString()), 
			};
		}

		public decimal ToDecimal()
		{
			ValueHandleType valueHandleType = type;
			switch (valueHandleType)
			{
			case ValueHandleType.Decimal:
				return GetDecimal();
			case ValueHandleType.Zero:
				return 0m;
			case ValueHandleType.One:
				return 1m;
			case ValueHandleType.Int8:
			case ValueHandleType.Int16:
			case ValueHandleType.Int32:
			case ValueHandleType.Int64:
				return ToLong();
			default:
				return valueHandleType switch
				{
					ValueHandleType.UInt64 => GetUInt64(), 
					ValueHandleType.UTF8 => XmlConverter.ToDecimal(bufferReader.Buffer, offset, length), 
					_ => XmlConverter.ToDecimal(GetString()), 
				};
			}
		}

		public DateTime ToDateTime()
		{
			if (type == ValueHandleType.DateTime)
			{
				return XmlConverter.ToDateTime(GetInt64());
			}
			if (type == ValueHandleType.UTF8)
			{
				return XmlConverter.ToDateTime(bufferReader.Buffer, offset, length);
			}
			return XmlConverter.ToDateTime(GetString());
		}

		public UniqueId ToUniqueId()
		{
			if (type == ValueHandleType.UniqueId)
			{
				return GetUniqueId();
			}
			if (type == ValueHandleType.UTF8)
			{
				return XmlConverter.ToUniqueId(bufferReader.Buffer, offset, length);
			}
			return XmlConverter.ToUniqueId(GetString());
		}

		public TimeSpan ToTimeSpan()
		{
			if (type == ValueHandleType.TimeSpan)
			{
				return new TimeSpan(GetInt64());
			}
			if (type == ValueHandleType.UTF8)
			{
				return XmlConverter.ToTimeSpan(bufferReader.Buffer, offset, length);
			}
			return XmlConverter.ToTimeSpan(GetString());
		}

		public Guid ToGuid()
		{
			if (type == ValueHandleType.Guid)
			{
				return GetGuid();
			}
			if (type == ValueHandleType.UTF8)
			{
				return XmlConverter.ToGuid(bufferReader.Buffer, offset, length);
			}
			return XmlConverter.ToGuid(GetString());
		}

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

		public byte[] ToByteArray()
		{
			if (type == ValueHandleType.Base64)
			{
				byte[] array = new byte[length];
				GetBase64(array, 0, length);
				return array;
			}
			if (type == ValueHandleType.UTF8 && length % 4 == 0)
			{
				try
				{
					int num = length / 4 * 3;
					if (length > 0 && bufferReader.Buffer[offset + length - 1] == 61)
					{
						num--;
						if (bufferReader.Buffer[offset + length - 2] == 61)
						{
							num--;
						}
					}
					byte[] array2 = new byte[num];
					int bytes = Base64Encoding.GetBytes(bufferReader.Buffer, offset, length, array2, 0);
					if (bytes != array2.Length)
					{
						byte[] array3 = new byte[bytes];
						Buffer.BlockCopy(array2, 0, array3, 0, bytes);
						array2 = array3;
					}
					return array2;
				}
				catch (FormatException)
				{
				}
			}
			try
			{
				return Base64Encoding.GetBytes(XmlConverter.StripWhitespace(GetString()));
			}
			catch (FormatException ex2)
			{
				throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(ex2.Message, ex2.InnerException));
			}
		}

		public string GetString()
		{
			ValueHandleType valueHandleType = type;
			if (valueHandleType == ValueHandleType.UTF8)
			{
				return GetCharsText();
			}
			switch (valueHandleType)
			{
			case ValueHandleType.False:
				return "false";
			case ValueHandleType.True:
				return "true";
			case ValueHandleType.Zero:
				return "0";
			case ValueHandleType.One:
				return "1";
			case ValueHandleType.Int8:
			case ValueHandleType.Int16:
			case ValueHandleType.Int32:
				return XmlConverter.ToString(ToInt());
			case ValueHandleType.Int64:
				return XmlConverter.ToString(GetInt64());
			case ValueHandleType.UInt64:
				return XmlConverter.ToString(GetUInt64());
			case ValueHandleType.Single:
				return XmlConverter.ToString(GetSingle());
			case ValueHandleType.Double:
				return XmlConverter.ToString(GetDouble());
			case ValueHandleType.Decimal:
				return XmlConverter.ToString(GetDecimal());
			case ValueHandleType.DateTime:
				return XmlConverter.ToString(ToDateTime());
			case ValueHandleType.Empty:
				return string.Empty;
			case ValueHandleType.UTF8:
				return GetCharsText();
			case ValueHandleType.Unicode:
				return GetUnicodeCharsText();
			case ValueHandleType.EscapedUTF8:
				return GetEscapedCharsText();
			case ValueHandleType.Char:
				return GetCharText();
			case ValueHandleType.Dictionary:
				return GetDictionaryString().Value;
			case ValueHandleType.Base64:
				return Base64Encoding.GetString(ToByteArray());
			case ValueHandleType.List:
				return XmlConverter.ToString(ToList());
			case ValueHandleType.UniqueId:
				return XmlConverter.ToString(ToUniqueId());
			case ValueHandleType.Guid:
				return XmlConverter.ToString(ToGuid());
			case ValueHandleType.TimeSpan:
				return XmlConverter.ToString(ToTimeSpan());
			case ValueHandleType.QName:
				return GetQNameDictionaryText();
			case ValueHandleType.ConstString:
				return constStrings[offset];
			default:
				throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException());
			}
		}

		public bool Equals2(string str, bool checkLower)
		{
			if (type != ValueHandleType.UTF8)
			{
				return GetString() == str;
			}
			if (length != str.Length)
			{
				return false;
			}
			byte[] buffer = bufferReader.Buffer;
			for (int i = 0; i < length; i++)
			{
				byte b = buffer[i + offset];
				if (b != str[i] && (!checkLower || char.ToLowerInvariant((char)b) != str[i]))
				{
					return false;
				}
			}
			return true;
		}

		public void Sign(XmlSigningNodeWriter writer)
		{
			switch (type)
			{
			case ValueHandleType.Int8:
			case ValueHandleType.Int16:
			case ValueHandleType.Int32:
				writer.WriteInt32Text(ToInt());
				break;
			case ValueHandleType.Int64:
				writer.WriteInt64Text(GetInt64());
				break;
			case ValueHandleType.UInt64:
				writer.WriteUInt64Text(GetUInt64());
				break;
			case ValueHandleType.Single:
				writer.WriteFloatText(GetSingle());
				break;
			case ValueHandleType.Double:
				writer.WriteDoubleText(GetDouble());
				break;
			case ValueHandleType.Decimal:
				writer.WriteDecimalText(GetDecimal());
				break;
			case ValueHandleType.DateTime:
				writer.WriteDateTimeText(ToDateTime());
				break;
			case ValueHandleType.UTF8:
				writer.WriteEscapedText(bufferReader.Buffer, offset, length);
				break;
			case ValueHandleType.Base64:
				writer.WriteBase64Text(bufferReader.Buffer, 0, bufferReader.Buffer, offset, length);
				break;
			case ValueHandleType.UniqueId:
				writer.WriteUniqueIdText(ToUniqueId());
				break;
			case ValueHandleType.Guid:
				writer.WriteGuidText(ToGuid());
				break;
			case ValueHandleType.TimeSpan:
				writer.WriteTimeSpanText(ToTimeSpan());
				break;
			default:
				writer.WriteEscapedText(GetString());
				break;
			case ValueHandleType.Empty:
				break;
			}
		}

		public object[] ToList()
		{
			return bufferReader.GetList(offset, length);
		}

		public object ToObject()
		{
			switch (type)
			{
			case ValueHandleType.True:
			case ValueHandleType.False:
				return ToBoolean();
			case ValueHandleType.Zero:
			case ValueHandleType.One:
			case ValueHandleType.Int8:
			case ValueHandleType.Int16:
			case ValueHandleType.Int32:
				return ToInt();
			case ValueHandleType.Int64:
				return ToLong();
			case ValueHandleType.UInt64:
				return GetUInt64();
			case ValueHandleType.Single:
				return ToSingle();
			case ValueHandleType.Double:
				return ToDouble();
			case ValueHandleType.Decimal:
				return ToDecimal();
			case ValueHandleType.DateTime:
				return ToDateTime();
			case ValueHandleType.Empty:
			case ValueHandleType.UTF8:
			case ValueHandleType.EscapedUTF8:
			case ValueHandleType.Dictionary:
			case ValueHandleType.Char:
			case ValueHandleType.Unicode:
			case ValueHandleType.ConstString:
				return ToString();
			case ValueHandleType.Base64:
				return ToByteArray();
			case ValueHandleType.List:
				return ToList();
			case ValueHandleType.UniqueId:
				return ToUniqueId();
			case ValueHandleType.Guid:
				return ToGuid();
			case ValueHandleType.TimeSpan:
				return ToTimeSpan();
			default:
				throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException());
			}
		}

		public bool TryReadBase64(byte[] buffer, int offset, int count, out int actual)
		{
			if (type == ValueHandleType.Base64)
			{
				actual = Math.Min(length, count);
				GetBase64(buffer, offset, actual);
				this.offset += actual;
				length -= actual;
				return true;
			}
			if (type == ValueHandleType.UTF8 && count >= 3 && length % 4 == 0)
			{
				try
				{
					int num = Math.Min(count / 3 * 4, length);
					actual = Base64Encoding.GetBytes(bufferReader.Buffer, this.offset, num, buffer, offset);
					this.offset += num;
					length -= num;
					return true;
				}
				catch (FormatException)
				{
				}
			}
			actual = 0;
			return false;
		}

		public bool TryReadChars(char[] chars, int offset, int count, out int actual)
		{
			if (type == ValueHandleType.Unicode)
			{
				return TryReadUnicodeChars(chars, offset, count, out actual);
			}
			if (type != ValueHandleType.UTF8)
			{
				actual = 0;
				return false;
			}
			int num = offset;
			int num2 = count;
			byte[] buffer = bufferReader.Buffer;
			int num3 = this.offset;
			int num4 = length;
			bool flag = false;
			while (true)
			{
				if (num2 > 0 && num4 > 0)
				{
					byte b = buffer[num3];
					if (b < 128)
					{
						chars[num] = (char)b;
						num3++;
						num4--;
						num++;
						num2--;
						continue;
					}
				}
				if (num2 == 0 || num4 == 0 || flag)
				{
					break;
				}
				UTF8Encoding uTF8Encoding = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false, throwOnInvalidBytes: true);
				int chars2;
				int num5;
				try
				{
					if (num2 >= uTF8Encoding.GetMaxCharCount(num4) || num2 >= uTF8Encoding.GetCharCount(buffer, num3, num4))
					{
						chars2 = uTF8Encoding.GetChars(buffer, num3, num4, chars, num);
						num5 = num4;
					}
					else
					{
						Decoder decoder = uTF8Encoding.GetDecoder();
						num5 = Math.Min(num2, num4);
						chars2 = decoder.GetChars(buffer, num3, num5, chars, num);
						while (chars2 == 0)
						{
							if (num5 >= 3 && num2 < 2)
							{
								flag = true;
								break;
							}
							chars2 = decoder.GetChars(buffer, num3 + num5, 1, chars, num);
							num5++;
						}
						num5 = uTF8Encoding.GetByteCount(chars, num, chars2);
					}
				}
				catch (FormatException exception)
				{
					throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateEncodingException(buffer, num3, num4, exception));
				}
				num3 += num5;
				num4 -= num5;
				num += chars2;
				num2 -= chars2;
			}
			this.offset = num3;
			length = num4;
			actual = count - num2;
			return true;
		}

		private bool TryReadUnicodeChars(char[] chars, int offset, int count, out int actual)
		{
			int num = Math.Min(count, length / 2);
			for (int i = 0; i < num; i++)
			{
				chars[offset + i] = (char)bufferReader.GetInt16(this.offset + i * 2);
			}
			this.offset += num * 2;
			length -= num * 2;
			actual = num;
			return true;
		}

		public bool TryGetDictionaryString(out XmlDictionaryString value)
		{
			if (type == ValueHandleType.Dictionary)
			{
				value = GetDictionaryString();
				return true;
			}
			value = null;
			return false;
		}

		public bool TryGetByteArrayLength(out int length)
		{
			if (type == ValueHandleType.Base64)
			{
				length = this.length;
				return true;
			}
			length = 0;
			return false;
		}

		private string GetCharsText()
		{
			if (length == 1 && bufferReader.GetByte(offset) == 49)
			{
				return "1";
			}
			return bufferReader.GetString(offset, length);
		}

		private string GetUnicodeCharsText()
		{
			return bufferReader.GetUnicodeString(offset, length);
		}

		private string GetEscapedCharsText()
		{
			return bufferReader.GetEscapedString(offset, length);
		}

		private string GetCharText()
		{
			int @char = GetChar();
			if (@char > 65535)
			{
				SurrogateChar surrogateChar = new SurrogateChar(@char);
				return new string(new char[2] { surrogateChar.HighChar, surrogateChar.LowChar }, 0, 2);
			}
			return ((char)@char).ToString();
		}

		private int GetChar()
		{
			return offset;
		}

		private int GetInt8()
		{
			return bufferReader.GetInt8(offset);
		}

		private int GetInt16()
		{
			return bufferReader.GetInt16(offset);
		}

		private int GetInt32()
		{
			return bufferReader.GetInt32(offset);
		}

		private long GetInt64()
		{
			return bufferReader.GetInt64(offset);
		}

		private ulong GetUInt64()
		{
			return bufferReader.GetUInt64(offset);
		}

		private float GetSingle()
		{
			return bufferReader.GetSingle(offset);
		}

		private double GetDouble()
		{
			return bufferReader.GetDouble(offset);
		}

		private decimal GetDecimal()
		{
			return bufferReader.GetDecimal(offset);
		}

		private UniqueId GetUniqueId()
		{
			return bufferReader.GetUniqueId(offset);
		}

		private Guid GetGuid()
		{
			return bufferReader.GetGuid(offset);
		}

		private void GetBase64(byte[] buffer, int offset, int count)
		{
			bufferReader.GetBase64(this.offset, buffer, offset, count);
		}

		private XmlDictionaryString GetDictionaryString()
		{
			return bufferReader.GetDictionaryString(offset);
		}

		private string GetQNameDictionaryText()
		{
			return PrefixHandle.GetString(PrefixHandle.GetAlphaPrefix(length)) + ":" + bufferReader.GetDictionaryString(offset);
		}
	}
	internal abstract class XmlBaseReader : XmlDictionaryReader
	{
		protected enum QNameType
		{
			Normal,
			Xmlns
		}

		protected class XmlNode
		{
			protected enum XmlNodeFlags
			{
				None = 0,
				CanGetAttribute = 1,
				CanMoveToElement = 2,
				HasValue = 4,
				AtomicValue = 8,
				SkipValue = 0x10,
				HasContent = 0x20
			}

			private XmlNodeType nodeType;

			private PrefixHandle prefix;

			private StringHandle localName;

			private ValueHandle value;

			private Namespace ns;

			private bool hasValue;

			private bool canGetAttribute;

			private bool canMoveToElement;

			private ReadState readState;

			private XmlAttributeTextNode attributeTextNode;

			private bool exitScope;

			private int depthDelta;

			private bool isAtomicValue;

			private bool skipValue;

			private QNameType qnameType;

			private bool hasContent;

			private bool isEmptyElement;

			private char quoteChar;

			public bool HasValue => hasValue;

			public ReadState ReadState => readState;

			public StringHandle LocalName => localName;

			public PrefixHandle Prefix => prefix;

			public bool CanGetAttribute => canGetAttribute;

			public bool CanMoveToElement => canMoveToElement;

			public XmlAttributeTextNode AttributeText => attributeTextNode;

			public bool SkipValue => skipValue;

			public ValueHandle Value => value;

			public int DepthDelta => depthDelta;

			public bool HasContent => hasContent;

			public XmlNodeType NodeType
			{
				get
				{
					return nodeType;
				}
				set
				{
					nodeType = value;
				}
			}

			public QNameType QNameType
			{
				get
				{
					return qnameType;
				}
				set
				{
					qnameType = value;
				}
			}

			public Namespace Namespace
			{
				get
				{
					return ns;
				}
				set
				{
					ns = value;
				}
			}

			public bool IsAtomicValue
			{
				get
				{
					return isAtomicValue;
				}
				set
				{
					isAtomicValue = value;
				}
			}

			public bool ExitScope
			{
				get
				{
					return exitScope;
				}
				set
				{
					exitScope = value;
				}
			}

			public bool IsEmptyElement
			{
				get
				{
					return isEmptyElement;
				}
				set
				{
					isEmptyElement = value;
				}
			}

			public char QuoteChar
			{
				get
				{
					return quoteChar;
				}
				set
				{
					quoteChar = value;
				}
			}

			public string ValueAsString
			{
				get
				{
					if (qnameType == QNameType.Normal)
					{
						return Value.GetString();
					}
					return Namespace.Uri.GetString();
				}
			}

			protected XmlNode(XmlNodeType nodeType, PrefixHandle prefix, StringHandle localName, ValueHandle value, XmlNodeFlags nodeFlags, ReadState readState, XmlAttributeTextNode attributeTextNode, int depthDelta)
			{
				this.nodeType = nodeType;
				this.prefix = prefix;
				this.localName = localName;
				this.value = value;
				ns = NamespaceManager.EmptyNamespace;
				hasValue = (nodeFlags & XmlNodeFlags.HasValue) != 0;
				canGetAttribute = (nodeFlags & XmlNodeFlags.CanGetAttribute) != 0;
				canMoveToElement = (nodeFlags & XmlNodeFlags.CanMoveToElement) != 0;
				isAtomicValue = (nodeFlags & XmlNodeFlags.AtomicValue) != 0;
				skipValue = (nodeFlags & XmlNodeFlags.SkipValue) != 0;
				hasContent = (nodeFlags & XmlNodeFlags.HasContent) != 0;
				this.readState = readState;
				this.attributeTextNode = attributeTextNode;
				exitScope = nodeType == XmlNodeType.EndElement;
				this.depthDelta = depthDelta;
				isEmptyElement = false;
				quoteChar = '"';
				qnameType = QNameType.Normal;
			}

			public bool IsLocalName(string localName)
			{
				if (qnameType == QNameType.Normal)
				{
					return LocalName == localName;
				}
				return Namespace.Prefix == localName;
			}

			public bool IsLocalName(XmlDictionaryString localName)
			{
				if (qnameType == QNameType.Normal)
				{
					return LocalName == localName;
				}
				return Namespace.Prefix == localName;
			}

			public bool IsNamespaceUri(string ns)
			{
				if (qnameType == QNameType.Normal)
				{
					return Namespace.IsUri(ns);
				}
				return ns == "http://www.w3.org/2000/xmlns/";
			}

			public bool IsNamespaceUri(XmlDictionaryString ns)
			{
				if (qnameType == QNameType.Normal)
				{
					return Namespace.IsUri(ns);
				}
				return ns.Value == "http://www.w3.org/2000/xmlns/";
			}

			public bool IsLocalNameAndNamespaceUri(string localName, string ns)
			{
				if (qnameType == QNameType.Normal)
				{
					if (LocalName == localName)
					{
						return Namespace.IsUri(ns);
					}
					return false;
				}
				if (Namespace.Prefix == localName)
				{
					return ns == "http://www.w3.org/2000/xmlns/";
				}
				return false;
			}

			public bool IsLocalNameAndNamespaceUri(XmlDictionaryString localName, XmlDictionaryString ns)
			{
				if (qnameType == QNameType.Normal)
				{
					if (LocalName == localName)
					{
						return Namespace.IsUri(ns);
					}
					return false;
				}
				if (Namespace.Prefix == localName)
				{
					return ns.Value == "http://www.w3.org/2000/xmlns/";
				}
				return false;
			}

			public bool IsPrefixAndLocalName(string prefix, string localName)
			{
				if (qnameType == QNameType.Normal)
				{
					if (Prefix == prefix)
					{
						return LocalName == localName;
					}
					return false;
				}
				if (prefix == "xmlns")
				{
					return Namespace.Prefix == localName;
				}
				return false;
			}

			public bool TryGetLocalNameAsDictionaryString(out XmlDictionaryString localName)
			{
				if (qnameType == QNameType.Normal)
				{
					return LocalName.TryGetDictionaryString(out localName);
				}
				localName = null;
				return false;
			}

			public bool TryGetNamespaceUriAsDictionaryString(out XmlDictionaryString ns)
			{
				if (qnameType == QNameType.Normal)
				{
					return Namespace.Uri.TryGetDictionaryString(out ns);
				}
				ns = null;
				return false;
			}

			public bool TryGetValueAsDictionaryString(out XmlDictionaryString value)
			{
				if (qnameType == QNameType.Normal)
				{
					return Value.TryGetDictionaryString(out value);
				}
				value = null;
				return false;
			}
		}

		protected class XmlElementNode : XmlNode
		{
			private XmlEndElementNode endElementNode;

			private int bufferOffset;

			public int NameOffset;

			public int NameLength;

			public XmlEndElementNode EndElement => endElementNode;

			public int BufferOffset
			{
				get
				{
					return bufferOffset;
				}
				set
				{
					bufferOffset = value;
				}
			}

			public XmlElementNode(XmlBufferReader bufferReader)
				: this(new PrefixHandle(bufferReader), new StringHandle(bufferReader), new ValueHandle(bufferReader))
			{
			}

			private XmlElementNode(PrefixHandle prefix, StringHandle localName, ValueHandle value)
				: base(XmlNodeType.Element, prefix, localName, value, (XmlNodeFlags)33, ReadState.Interactive, null, -1)
			{
				endElementNode = new XmlEndElementNode(prefix, localName, value);
			}
		}

		protected class XmlAttributeNode : XmlNode
		{
			public XmlAttributeNode(XmlBufferReader bufferReader)
				: this(new PrefixHandle(bufferReader), new StringHandle(bufferReader), new ValueHandle(bufferReader))
			{
			}

			private XmlAttributeNode(PrefixHandle prefix, StringHandle localName, ValueHandle value)
				: base(XmlNodeType.Attribute, prefix, localName, value, (XmlNodeFlags)15, ReadState.Interactive, new XmlAttributeTextNode(prefix, localName, value), 0)
			{
			}
		}

		protected class XmlEndElementNode : XmlNode
		{
			public XmlEndElementNode(PrefixHandle prefix, StringHandle localName, ValueHandle value)
				: base(XmlNodeType.EndElement, prefix, localName, value, XmlNodeFlags.HasContent, ReadState.Interactive, null, -1)
			{
			}
		}

		protected class XmlTextNode : XmlNode
		{
			protected XmlTextNode(XmlNodeType nodeType, PrefixHandle prefix, StringHandle localName, ValueHandle value, XmlNodeFlags nodeFlags, ReadState readState, XmlAttributeTextNode attributeTextNode, int depthDelta)
				: base(nodeType, prefix, localName, value, nodeFlags, readState, attributeTextNode, depthDelta)
			{
			}
		}

		protected class XmlAtomicTextNode : XmlTextNode
		{
			public XmlAtomicTextNode(XmlBufferReader bufferReader)
				: base(XmlNodeType.Text, new PrefixHandle(bufferReader), new StringHandle(bufferReader), new ValueHandle(bufferReader), (XmlNodeFlags)60, ReadState.Interactive, null, 0)
			{
			}
		}

		protected class XmlComplexTextNode : XmlTextNode
		{
			public XmlComplexTextNode(XmlBufferReader bufferReader)
				: base(XmlNodeType.Text, new PrefixHandle(bufferReader), new StringHandle(bufferReader), new ValueHandle(bufferReader), (XmlNodeFlags)36, ReadState.Interactive, null, 0)
			{
			}
		}

		protected class XmlWhitespaceTextNode : XmlTextNode
		{
			public XmlWhitespaceTextNode(XmlBufferReader bufferReader)
				: base(XmlNodeType.Whitespace, new PrefixHandle(bufferReader), new StringHandle(bufferReader), new ValueHandle(bufferReader), XmlNodeFlags.HasValue, ReadState.Interactive, null, 0)
			{
			}
		}

		protected class XmlCDataNode : XmlTextNode
		{
			public XmlCDataNode(XmlBufferReader bufferReader)
				: base(XmlNodeType.CDATA, new PrefixHandle(bufferReader), new StringHandle(bufferReader), new ValueHandle(bufferReader), (XmlNodeFlags)36, ReadState.Interactive, null, 0)
			{
			}
		}

		protected class XmlAttributeTextNode : XmlTextNode
		{
			public XmlAttributeTextNode(PrefixHandle prefix, StringHandle localName, ValueHandle value)
				: base(XmlNodeType.Text, prefix, localName, value, (XmlNodeFlags)47, ReadState.Interactive, null, 1)
			{
			}
		}

		protected class XmlInitialNode : XmlNode
		{
			public XmlInitialNode(XmlBufferReader bufferReader)
				: base(XmlNodeType.None, new PrefixHandle(bufferReader), new StringHandle(bufferReader), new ValueHandle(bufferReader), XmlNodeFlags.None, ReadState.Initial, null, 0)
			{
			}
		}

		protected class XmlDeclarationNode : XmlNode
		{
			public XmlDeclarationNode(XmlBufferReader bufferReader)
				: base(XmlNodeType.XmlDeclaration, new PrefixHandle(bufferReader), new StringHandle(bufferReader), new ValueHandle(bufferReader), XmlNodeFlags.CanGetAttribute, ReadState.Interactive, null, 0)
			{
			}
		}

		protected class XmlCommentNode : XmlNode
		{
			public XmlCommentNode(XmlBufferReader bufferReader)
				: base(XmlNodeType.Comment, new PrefixHandle(bufferReader), new StringHandle(bufferReader), new ValueHandle(bufferReader), XmlNodeFlags.HasValue, ReadState.Interactive, null, 0)
			{
			}
		}

		protected class XmlEndOfFileNode : XmlNode
		{
			public XmlEndOfFileNode(XmlBufferReader bufferReader)
				: base(XmlNodeType.None, new PrefixHandle(bufferReader), new StringHandle(bufferReader), new ValueHandle(bufferReader), XmlNodeFlags.None, ReadState.EndOfFile, null, 0)
			{
			}
		}

		protected class XmlClosedNode : XmlNode
		{
			public XmlClosedNode(XmlBufferReader bufferReader)
				: base(XmlNodeType.None, new PrefixHandle(bufferReader), new StringHandle(bufferReader), new ValueHandle(bufferReader), XmlNodeFlags.None, ReadState.Closed, null, 0)
			{
			}
		}

		private class AttributeSorter : IComparer
		{
			private object[] indeces;

			private XmlAttributeNode[] attributeNodes;

			private int attributeCount;

			private int attributeIndex1;

			private int attributeIndex2;

			public bool Sort(XmlAttributeNode[] attributeNodes, int attributeCount)
			{
				attributeIndex1 = -1;
				attributeIndex2 = -1;
				this.attributeNodes = attributeNodes;
				this.attributeCount = attributeCount;
				bool result = Sort();
				this.attributeNodes = null;
				this.attributeCount = 0;
				return result;
			}

			public void GetIndeces(out int attributeIndex1, out int attributeIndex2)
			{
				attributeIndex1 = this.attributeIndex1;
				attributeIndex2 = this.attributeIndex2;
			}

			public void Close()
			{
				if (indeces != null && indeces.Length > 32)
				{
					indeces = null;
				}
			}

			private bool Sort()
			{
				if (indeces != null && indeces.Length == attributeCount && IsSorted())
				{
					return true;
				}
				object[] array = new object[attributeCount];
				for (int i = 0; i < array.Length; i++)
				{
					array[i] = i;
				}
				indeces = array;
				Array.Sort(indeces, 0, attributeCount, this);
				return IsSorted();
			}

			private bool IsSorted()
			{
				for (int i = 0; i < indeces.Length - 1; i++)
				{
					if (Compare(indeces[i], indeces[i + 1]) >= 0)
					{
						attributeIndex1 = (int)indeces[i];
						attributeIndex2 = (int)indeces[i + 1];
						return false;
					}
				}
				return true;
			}

			public int Compare(object obj1, object obj2)
			{
				int num = (int)obj1;
				int num2 = (int)obj2;
				XmlAttributeNode xmlAttributeNode = attributeNodes[num];
				XmlAttributeNode xmlAttributeNode2 = attributeNodes[num2];
				int num3 = CompareQNameType(xmlAttributeNode.QNameType, xmlAttributeNode2.QNameType);
				if (num3 == 0)
				{
					if (xmlAttributeNode.QNameType == QNameType.Normal)
					{
						num3 = xmlAttributeNode.LocalName.CompareTo(xmlAttributeNode2.LocalName);
						if (num3 == 0)
						{
							num3 = xmlAttributeNode.Namespace.Uri.CompareTo(xmlAttributeNode2.Namespace.Uri);
						}
					}
					else
					{
						num3 = xmlAttributeNode.Namespace.Prefix.CompareTo(xmlAttributeNode2.Namespace.Prefix);
					}
				}
				return num3;
			}

			public int CompareQNameType(QNameType type1, QNameType type2)
			{
				return type1 - type2;
			}
		}

		private class NamespaceManager
		{
			private class XmlAttribute
			{
				private XmlSpace space;

				private string lang;

				private int depth;

				public int Depth
				{
					get
					{
						return depth;
					}
					set
					{
						depth = value;
					}
				}

				public string XmlLang
				{
					get
					{
						return lang;

BepInExPack/mono/Managed/System.Text.Encodings.Web.dll

Decompiled a month ago
using System;
using System.Buffers;
using System.Buffers.Binary;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text.Internal;
using System.Text.Unicode;
using System.Threading;
using FxResources.System.Text.Encodings.Web;
using Microsoft.CodeAnalysis;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = "")]
[assembly: CLSCompliant(true)]
[assembly: AssemblyDefaultAlias("System.Text.Encodings.Web")]
[assembly: NeutralResourcesLanguage("en-US")]
[assembly: AssemblyMetadata(".NETFrameworkAssembly", "")]
[assembly: AssemblyMetadata("Serviceable", "True")]
[assembly: AssemblyMetadata("PreferInbox", "True")]
[assembly: AssemblyCompany("Microsoft Corporation")]
[assembly: AssemblyCopyright("© Microsoft Corporation. All rights reserved.")]
[assembly: AssemblyDescription("System.Text.Encodings.Web")]
[assembly: AssemblyFileVersion("5.0.421.11614")]
[assembly: AssemblyInformationalVersion("5.0.4+f27d33729518f5aa478aa818b7b4f54a4d50bef1")]
[assembly: AssemblyProduct("Microsoft® .NET")]
[assembly: AssemblyTitle("System.Text.Encodings.Web")]
[assembly: AssemblyMetadata("RepositoryUrl", "git://github.com/dotnet/runtime")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("5.0.0.1")]
[module: UnverifiableCode]
[module: System.Runtime.CompilerServices.NullablePublicOnly(false)]
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
	{
	}
	[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.Text.Encodings.Web
{
	internal static class SR
	{
	}
}
namespace System
{
	internal static class HexConverter
	{
		public enum Casing : uint
		{
			Upper = 0u,
			Lower = 8224u
		}

		public static ReadOnlySpan<byte> CharToHexLookup => new byte[256]
		{
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 0, 1,
			2, 3, 4, 5, 6, 7, 8, 9, 255, 255,
			255, 255, 255, 255, 255, 10, 11, 12, 13, 14,
			15, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 10, 11, 12,
			13, 14, 15, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255
		};

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static void ToBytesBuffer(byte value, Span<byte> buffer, int startingIndex = 0, Casing casing = Casing.Upper)
		{
			uint num = (uint)(((value & 0xF0) << 4) + (value & 0xF) - 35209);
			uint num2 = ((((0 - num) & 0x7070) >> 4) + num + 47545) | (uint)casing;
			buffer[startingIndex + 1] = (byte)num2;
			buffer[startingIndex] = (byte)(num2 >> 8);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static void ToCharsBuffer(byte value, Span<char> buffer, int startingIndex = 0, Casing casing = Casing.Upper)
		{
			uint num = (uint)(((value & 0xF0) << 4) + (value & 0xF) - 35209);
			uint num2 = ((((0 - num) & 0x7070) >> 4) + num + 47545) | (uint)casing;
			buffer[startingIndex + 1] = (char)(num2 & 0xFFu);
			buffer[startingIndex] = (char)(num2 >> 8);
		}

		public static void EncodeToUtf16(ReadOnlySpan<byte> bytes, Span<char> chars, Casing casing = Casing.Upper)
		{
			for (int i = 0; i < bytes.Length; i++)
			{
				ToCharsBuffer(bytes[i], chars, i * 2, casing);
			}
		}

		public static string ToString(ReadOnlySpan<byte> bytes, Casing casing = Casing.Upper)
		{
			Span<char> span = default(Span<char>);
			if (bytes.Length > 16)
			{
				char[] array = new char[bytes.Length * 2];
				span = array.AsSpan();
			}
			else
			{
				span = stackalloc char[bytes.Length * 2];
			}
			int num = 0;
			ReadOnlySpan<byte> readOnlySpan = bytes;
			for (int i = 0; i < readOnlySpan.Length; i++)
			{
				byte value = readOnlySpan[i];
				ToCharsBuffer(value, span, num, casing);
				num += 2;
			}
			return span.ToString();
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static char ToCharUpper(int value)
		{
			value &= 0xF;
			value += 48;
			if (value > 57)
			{
				value += 7;
			}
			return (char)value;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static char ToCharLower(int value)
		{
			value &= 0xF;
			value += 48;
			if (value > 57)
			{
				value += 39;
			}
			return (char)value;
		}

		public static bool TryDecodeFromUtf16(ReadOnlySpan<char> chars, Span<byte> bytes)
		{
			int charsProcessed;
			return TryDecodeFromUtf16(chars, bytes, out charsProcessed);
		}

		public static bool TryDecodeFromUtf16(ReadOnlySpan<char> chars, Span<byte> bytes, out int charsProcessed)
		{
			int num = 0;
			int num2 = 0;
			int num3 = 0;
			int num4 = 0;
			while (num2 < bytes.Length)
			{
				num3 = FromChar(chars[num + 1]);
				num4 = FromChar(chars[num]);
				if ((num3 | num4) == 255)
				{
					break;
				}
				bytes[num2++] = (byte)((num4 << 4) | num3);
				num += 2;
			}
			if (num3 == 255)
			{
				num++;
			}
			charsProcessed = num;
			return (num3 | num4) != 255;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static int FromChar(int c)
		{
			if (c < CharToHexLookup.Length)
			{
				return CharToHexLookup[c];
			}
			return 255;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static int FromUpperChar(int c)
		{
			if (c <= 71)
			{
				return CharToHexLookup[c];
			}
			return 255;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static int FromLowerChar(int c)
		{
			switch (c)
			{
			case 48:
			case 49:
			case 50:
			case 51:
			case 52:
			case 53:
			case 54:
			case 55:
			case 56:
			case 57:
				return c - 48;
			case 97:
			case 98:
			case 99:
			case 100:
			case 101:
			case 102:
				return c - 97 + 10;
			default:
				return 255;
			}
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static bool IsHexChar(int c)
		{
			return FromChar(c) != 255;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static bool IsHexUpperChar(int c)
		{
			if ((uint)(c - 48) > 9u)
			{
				return (uint)(c - 65) <= 5u;
			}
			return true;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static bool IsHexLowerChar(int c)
		{
			if ((uint)(c - 48) > 9u)
			{
				return (uint)(c - 97) <= 5u;
			}
			return true;
		}
	}
	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 TextEncoderDoesNotImplementMaxOutputCharsPerInputChar => GetResourceString("TextEncoderDoesNotImplementMaxOutputCharsPerInputChar");

		private static bool UsingResourceKeys()
		{
			return s_usingResourceKeys;
		}

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

		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.Text
{
	internal static class UnicodeDebug
	{
		[Conditional("DEBUG")]
		internal static void AssertIsHighSurrogateCodePoint(uint codePoint)
		{
			System.Text.UnicodeUtility.IsHighSurrogateCodePoint(codePoint);
		}

		[Conditional("DEBUG")]
		internal static void AssertIsLowSurrogateCodePoint(uint codePoint)
		{
			System.Text.UnicodeUtility.IsLowSurrogateCodePoint(codePoint);
		}

		[Conditional("DEBUG")]
		internal static void AssertIsValidCodePoint(uint codePoint)
		{
			System.Text.UnicodeUtility.IsValidCodePoint(codePoint);
		}

		[Conditional("DEBUG")]
		internal static void AssertIsValidScalar(uint scalarValue)
		{
			System.Text.UnicodeUtility.IsValidUnicodeScalar(scalarValue);
		}

		[Conditional("DEBUG")]
		internal static void AssertIsValidSupplementaryPlaneScalar(uint scalarValue)
		{
			if (System.Text.UnicodeUtility.IsValidUnicodeScalar(scalarValue))
			{
				System.Text.UnicodeUtility.IsBmpCodePoint(scalarValue);
			}
		}

		private static string ToHexString(uint codePoint)
		{
			return FormattableString.Invariant($"U+{codePoint:X4}");
		}
	}
	internal static class UnicodeUtility
	{
		public const uint ReplacementChar = 65533u;

		public static int GetPlane(uint codePoint)
		{
			return (int)(codePoint >> 16);
		}

		public static uint GetScalarFromUtf16SurrogatePair(uint highSurrogateCodePoint, uint lowSurrogateCodePoint)
		{
			return (highSurrogateCodePoint << 10) + lowSurrogateCodePoint - 56613888;
		}

		public static int GetUtf16SequenceLength(uint value)
		{
			value -= 65536;
			value += 33554432;
			value >>= 24;
			return (int)value;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static void GetUtf16SurrogatesFromSupplementaryPlaneScalar(uint value, out char highSurrogateCodePoint, out char lowSurrogateCodePoint)
		{
			highSurrogateCodePoint = (char)(value + 56557568 >> 10);
			lowSurrogateCodePoint = (char)((value & 0x3FF) + 56320);
		}

		public static int GetUtf8SequenceLength(uint value)
		{
			int num = (int)(value - 2048) >> 31;
			value ^= 0xF800u;
			value -= 63616;
			value += 67108864;
			value >>= 24;
			return (int)value + num * 2;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static bool IsAsciiCodePoint(uint value)
		{
			return value <= 127;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static bool IsBmpCodePoint(uint value)
		{
			return value <= 65535;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static bool IsHighSurrogateCodePoint(uint value)
		{
			return IsInRangeInclusive(value, 55296u, 56319u);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static bool IsInRangeInclusive(uint value, uint lowerBound, uint upperBound)
		{
			return value - lowerBound <= upperBound - lowerBound;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static bool IsLowSurrogateCodePoint(uint value)
		{
			return IsInRangeInclusive(value, 56320u, 57343u);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static bool IsSurrogateCodePoint(uint value)
		{
			return IsInRangeInclusive(value, 55296u, 57343u);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static bool IsValidCodePoint(uint codePoint)
		{
			return codePoint <= 1114111;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static bool IsValidUnicodeScalar(uint value)
		{
			return ((value - 1114112) ^ 0xD800) >= 4293855232u;
		}
	}
	internal ref struct ValueStringBuilder
	{
		private char[] _arrayToReturnToPool;

		private Span<char> _chars;

		private int _pos;

		public int Length
		{
			get
			{
				return _pos;
			}
			set
			{
				_pos = value;
			}
		}

		public int Capacity => _chars.Length;

		public ref char this[int index] => ref _chars[index];

		public Span<char> RawChars => _chars;

		public ValueStringBuilder(Span<char> initialBuffer)
		{
			_arrayToReturnToPool = null;
			_chars = initialBuffer;
			_pos = 0;
		}

		public ValueStringBuilder(int initialCapacity)
		{
			_arrayToReturnToPool = ArrayPool<char>.Shared.Rent(initialCapacity);
			_chars = _arrayToReturnToPool;
			_pos = 0;
		}

		public void EnsureCapacity(int capacity)
		{
			if (capacity > _chars.Length)
			{
				Grow(capacity - _pos);
			}
		}

		public ref char GetPinnableReference()
		{
			return ref MemoryMarshal.GetReference(_chars);
		}

		public ref char GetPinnableReference(bool terminate)
		{
			if (terminate)
			{
				EnsureCapacity(Length + 1);
				_chars[Length] = '\0';
			}
			return ref MemoryMarshal.GetReference(_chars);
		}

		public override string ToString()
		{
			string result = _chars.Slice(0, _pos).ToString();
			Dispose();
			return result;
		}

		public ReadOnlySpan<char> AsSpan(bool terminate)
		{
			if (terminate)
			{
				EnsureCapacity(Length + 1);
				_chars[Length] = '\0';
			}
			return _chars.Slice(0, _pos);
		}

		public ReadOnlySpan<char> AsSpan()
		{
			return _chars.Slice(0, _pos);
		}

		public ReadOnlySpan<char> AsSpan(int start)
		{
			return _chars.Slice(start, _pos - start);
		}

		public ReadOnlySpan<char> AsSpan(int start, int length)
		{
			return _chars.Slice(start, length);
		}

		public bool TryCopyTo(Span<char> destination, out int charsWritten)
		{
			if (_chars.Slice(0, _pos).TryCopyTo(destination))
			{
				charsWritten = _pos;
				Dispose();
				return true;
			}
			charsWritten = 0;
			Dispose();
			return false;
		}

		public void Insert(int index, char value, int count)
		{
			if (_pos > _chars.Length - count)
			{
				Grow(count);
			}
			int length = _pos - index;
			_chars.Slice(index, length).CopyTo(_chars.Slice(index + count));
			_chars.Slice(index, count).Fill(value);
			_pos += count;
		}

		public void Insert(int index, string s)
		{
			if (s != null)
			{
				int length = s.Length;
				if (_pos > _chars.Length - length)
				{
					Grow(length);
				}
				int length2 = _pos - index;
				_chars.Slice(index, length2).CopyTo(_chars.Slice(index + length));
				s.AsSpan().CopyTo(_chars.Slice(index));
				_pos += length;
			}
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public void Append(char c)
		{
			int pos = _pos;
			if ((uint)pos < (uint)_chars.Length)
			{
				_chars[pos] = c;
				_pos = pos + 1;
			}
			else
			{
				GrowAndAppend(c);
			}
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public void Append(string s)
		{
			if (s != null)
			{
				int pos = _pos;
				if (s.Length == 1 && (uint)pos < (uint)_chars.Length)
				{
					_chars[pos] = s[0];
					_pos = pos + 1;
				}
				else
				{
					AppendSlow(s);
				}
			}
		}

		private void AppendSlow(string s)
		{
			int pos = _pos;
			if (pos > _chars.Length - s.Length)
			{
				Grow(s.Length);
			}
			s.AsSpan().CopyTo(_chars.Slice(pos));
			_pos += s.Length;
		}

		public void Append(char c, int count)
		{
			if (_pos > _chars.Length - count)
			{
				Grow(count);
			}
			Span<char> span = _chars.Slice(_pos, count);
			for (int i = 0; i < span.Length; i++)
			{
				span[i] = c;
			}
			_pos += count;
		}

		public unsafe void Append(char* value, int length)
		{
			int pos = _pos;
			if (pos > _chars.Length - length)
			{
				Grow(length);
			}
			Span<char> span = _chars.Slice(_pos, length);
			for (int i = 0; i < span.Length; i++)
			{
				span[i] = *(value++);
			}
			_pos += length;
		}

		public void Append(ReadOnlySpan<char> value)
		{
			int pos = _pos;
			if (pos > _chars.Length - value.Length)
			{
				Grow(value.Length);
			}
			value.CopyTo(_chars.Slice(_pos));
			_pos += value.Length;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public Span<char> AppendSpan(int length)
		{
			int pos = _pos;
			if (pos > _chars.Length - length)
			{
				Grow(length);
			}
			_pos = pos + length;
			return _chars.Slice(pos, length);
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private void GrowAndAppend(char c)
		{
			Grow(1);
			Append(c);
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private void Grow(int additionalCapacityBeyondPos)
		{
			char[] array = ArrayPool<char>.Shared.Rent(Math.Max(_pos + additionalCapacityBeyondPos, _chars.Length * 2));
			_chars.Slice(0, _pos).CopyTo(array);
			char[] arrayToReturnToPool = _arrayToReturnToPool;
			_chars = (_arrayToReturnToPool = array);
			if (arrayToReturnToPool != null)
			{
				ArrayPool<char>.Shared.Return(arrayToReturnToPool);
			}
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public void Dispose()
		{
			char[] arrayToReturnToPool = _arrayToReturnToPool;
			this = default(System.Text.ValueStringBuilder);
			if (arrayToReturnToPool != null)
			{
				ArrayPool<char>.Shared.Return(arrayToReturnToPool);
			}
		}
	}
}
namespace System.Text.Unicode
{
	internal static class UnicodeHelpers
	{
		internal const int UNICODE_LAST_CODEPOINT = 1114111;

		private static readonly uint[] _definedCharacterBitmapBigEndian = (BitConverter.IsLittleEndian ? null : CreateDefinedCharacterBitmapMachineEndian());

		private static ReadOnlySpan<byte> DefinedCharsBitmapSpan => new byte[8192]
		{
			0, 0, 0, 0, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 127, 0, 0, 0, 0,
			254, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 252, 240, 215, 255, 255, 251, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 254, 255, 255, 255,
			127, 254, 255, 255, 255, 255, 255, 231, 254, 255,
			255, 255, 255, 255, 255, 0, 255, 255, 255, 135,
			31, 0, 255, 255, 255, 223, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 191, 255, 255, 255, 255,
			255, 255, 255, 231, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 3, 0, 255, 255,
			255, 255, 255, 255, 255, 231, 255, 255, 255, 255,
			255, 63, 255, 127, 255, 255, 255, 79, 255, 7,
			0, 0, 0, 0, 0, 0, 255, 255, 223, 255,
			255, 0, 248, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 239, 159, 249, 255, 255, 253,
			197, 243, 159, 121, 128, 176, 207, 255, 255, 127,
			238, 135, 249, 255, 255, 253, 109, 211, 135, 57,
			2, 94, 192, 255, 127, 0, 238, 191, 251, 255,
			255, 253, 237, 243, 191, 59, 1, 0, 207, 255,
			3, 254, 238, 159, 249, 255, 255, 253, 237, 243,
			159, 57, 224, 176, 207, 255, 255, 0, 236, 199,
			61, 214, 24, 199, 255, 195, 199, 61, 129, 0,
			192, 255, 255, 7, 255, 223, 253, 255, 255, 253,
			255, 227, 223, 61, 96, 7, 207, 255, 128, 255,
			255, 223, 253, 255, 255, 253, 239, 243, 223, 61,
			96, 64, 207, 255, 6, 0, 255, 223, 253, 255,
			255, 255, 255, 255, 223, 253, 240, 255, 207, 255,
			255, 255, 238, 255, 127, 252, 255, 255, 251, 47,
			127, 132, 95, 255, 192, 255, 28, 0, 254, 255,
			255, 255, 255, 255, 255, 135, 255, 255, 255, 15,
			0, 0, 0, 0, 214, 247, 255, 255, 175, 255,
			255, 63, 95, 63, 255, 243, 0, 0, 0, 0,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 254,
			255, 255, 255, 31, 254, 255, 255, 255, 255, 254,
			255, 255, 255, 223, 255, 223, 255, 7, 0, 0,
			0, 0, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 191, 32, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 61, 127, 61, 255, 255,
			255, 255, 255, 61, 255, 255, 255, 255, 61, 127,
			61, 255, 127, 255, 255, 255, 255, 255, 255, 255,
			61, 255, 255, 255, 255, 255, 255, 255, 255, 231,
			255, 255, 255, 31, 255, 255, 255, 3, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 63, 63,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			254, 255, 255, 31, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 1, 255, 223, 31, 0,
			255, 255, 127, 0, 255, 255, 15, 0, 255, 223,
			13, 0, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 63, 255, 3, 255, 3, 255, 127,
			255, 3, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 1, 255, 255, 255, 255, 255, 7,
			255, 255, 255, 255, 255, 255, 255, 255, 63, 0,
			255, 255, 255, 127, 255, 15, 255, 15, 241, 255,
			255, 255, 255, 63, 31, 0, 255, 255, 255, 255,
			255, 15, 255, 255, 255, 3, 255, 199, 255, 255,
			255, 255, 255, 255, 255, 207, 255, 255, 255, 255,
			255, 255, 255, 127, 255, 255, 255, 159, 255, 3,
			255, 3, 255, 63, 255, 255, 1, 0, 0, 0,
			0, 0, 0, 0, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 15, 255, 255, 255, 255, 255, 31,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 15, 240, 255, 255, 255, 255,
			255, 255, 255, 248, 255, 227, 255, 255, 255, 255,
			255, 255, 255, 1, 255, 255, 255, 255, 255, 231,
			255, 0, 255, 255, 255, 255, 255, 7, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 251,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 63, 63, 255, 255, 255, 255,
			63, 63, 255, 170, 255, 255, 255, 63, 255, 255,
			255, 255, 255, 255, 223, 255, 223, 255, 207, 239,
			255, 255, 220, 127, 0, 248, 255, 255, 255, 124,
			255, 255, 255, 255, 255, 127, 223, 255, 243, 255,
			255, 127, 255, 31, 255, 255, 255, 255, 0, 0,
			255, 255, 255, 255, 1, 0, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 15, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 127, 0, 0, 0,
			255, 7, 0, 0, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			207, 255, 255, 255, 191, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 127, 255, 255, 255, 255, 255, 127,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 15, 254,
			255, 255, 255, 255, 191, 32, 255, 255, 255, 255,
			255, 255, 255, 128, 1, 128, 255, 255, 127, 0,
			127, 127, 127, 127, 127, 127, 127, 127, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 7, 0, 0, 0, 0, 0, 255, 255,
			255, 251, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 15, 0, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			63, 0, 0, 0, 255, 15, 254, 255, 255, 255,
			255, 255, 255, 255, 254, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 127, 254, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 224, 255,
			255, 255, 255, 255, 254, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 127, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 15, 0, 255, 255,
			255, 255, 255, 127, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 31,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 31, 255, 255, 255, 255,
			255, 255, 127, 0, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 15, 0, 0,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 0, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 252, 7,
			0, 0, 0, 0, 224, 255, 255, 255, 255, 255,
			255, 31, 255, 3, 255, 255, 255, 255, 255, 255,
			255, 0, 255, 255, 255, 255, 255, 255, 255, 255,
			63, 192, 255, 3, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 15, 128,
			255, 255, 255, 31, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 191, 255, 195, 255, 255, 255, 127,
			255, 255, 255, 255, 255, 255, 127, 0, 255, 63,
			255, 243, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 7, 0, 0, 248, 255, 255,
			127, 0, 126, 126, 126, 0, 127, 127, 255, 255,
			255, 255, 255, 255, 255, 15, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 63, 255, 3, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			15, 0, 255, 255, 127, 248, 255, 255, 255, 255,
			255, 15, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 63, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 3, 0, 0,
			0, 0, 127, 0, 248, 224, 255, 255, 127, 95,
			219, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 3, 0, 248, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 0, 0, 255, 255, 255, 255,
			255, 255, 255, 255, 252, 255, 255, 255, 255, 255,
			255, 0, 0, 0, 0, 0, 255, 63, 255, 255,
			255, 3, 255, 255, 255, 255, 255, 255, 247, 255,
			127, 15, 223, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 31,
			254, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 127, 252, 252, 252, 28, 127, 127,
			0, 62
		};

		private static uint[] CreateDefinedCharacterBitmapMachineEndian()
		{
			ReadOnlySpan<byte> source = DefinedCharsBitmapSpan;
			uint[] array = new uint[source.Length / 4];
			for (int i = 0; i < array.Length; i++)
			{
				array[i] = BinaryPrimitives.ReadUInt32LittleEndian(source);
				source = source.Slice(4);
			}
			return array;
		}

		public static OperationStatus DecodeScalarValueFromUtf8(ReadOnlySpan<byte> source, out uint result, out int bytesConsumed)
		{
			int num = 0;
			uint num2;
			if ((uint)num < (uint)source.Length)
			{
				num2 = source[num];
				if (System.Text.UnicodeUtility.IsAsciiCodePoint(num2))
				{
					goto IL_0021;
				}
				if (System.Text.UnicodeUtility.IsInRangeInclusive(num2, 194u, 244u))
				{
					num2 = num2 - 194 << 6;
					num++;
					if ((uint)num >= (uint)source.Length)
					{
						goto IL_0150;
					}
					int num3 = (sbyte)source[num];
					if (num3 < -64)
					{
						num2 += (uint)num3;
						num2 += 128;
						num2 += 128;
						if (num2 < 2048)
						{
							goto IL_0021;
						}
						if (System.Text.UnicodeUtility.IsInRangeInclusive(num2, 2080u, 3343u) && !System.Text.UnicodeUtility.IsInRangeInclusive(num2, 2912u, 2943u) && !System.Text.UnicodeUtility.IsInRangeInclusive(num2, 3072u, 3087u))
						{
							num++;
							if ((uint)num >= (uint)source.Length)
							{
								goto IL_0150;
							}
							num3 = (sbyte)source[num];
							if (num3 < -64)
							{
								num2 <<= 6;
								num2 += (uint)num3;
								num2 += 128;
								num2 -= 131072;
								if (num2 > 65535)
								{
									num++;
									if ((uint)num >= (uint)source.Length)
									{
										goto IL_0150;
									}
									num3 = (sbyte)source[num];
									if (num3 >= -64)
									{
										goto IL_0144;
									}
									num2 <<= 6;
									num2 += (uint)num3;
									num2 += 128;
									num2 -= 4194304;
								}
								goto IL_0021;
							}
						}
					}
				}
				else
				{
					num = 1;
				}
				goto IL_0144;
			}
			goto IL_0150;
			IL_0021:
			bytesConsumed = num + 1;
			result = num2;
			return OperationStatus.Done;
			IL_0144:
			bytesConsumed = num;
			result = 65533u;
			return OperationStatus.InvalidData;
			IL_0150:
			bytesConsumed = num;
			result = 65533u;
			return OperationStatus.NeedMoreData;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		internal static ReadOnlySpan<uint> GetDefinedCharacterBitmap()
		{
			if (BitConverter.IsLittleEndian)
			{
				return MemoryMarshal.Cast<byte, uint>(DefinedCharsBitmapSpan);
			}
			return _definedCharacterBitmapBigEndian;
		}

		internal static void GetUtf16SurrogatePairFromAstralScalarValue(int scalar, out char highSurrogate, out char lowSurrogate)
		{
			int num = scalar & 0xFFFF;
			int num2 = scalar >> 16;
			int num3 = num2 - 1;
			highSurrogate = (char)(0xD800u | (uint)(num3 << 6) | (uint)(num >> 10));
			lowSurrogate = (char)(0xDC00u | ((uint)num & 0x3FFu));
		}

		internal static int GetUtf8RepresentationForScalarValue(uint scalar)
		{
			if (scalar <= 127)
			{
				return (byte)scalar;
			}
			if (scalar <= 2047)
			{
				byte b = (byte)(0xC0u | (scalar >> 6));
				byte b2 = (byte)(0x80u | (scalar & 0x3Fu));
				return (b2 << 8) | b;
			}
			if (scalar <= 65535)
			{
				byte b3 = (byte)(0xE0u | (scalar >> 12));
				byte b4 = (byte)(0x80u | ((scalar >> 6) & 0x3Fu));
				byte b5 = (byte)(0x80u | (scalar & 0x3Fu));
				return (((b5 << 8) | b4) << 8) | b3;
			}
			byte b6 = (byte)(0xF0u | (scalar >> 18));
			byte b7 = (byte)(0x80u | ((scalar >> 12) & 0x3Fu));
			byte b8 = (byte)(0x80u | ((scalar >> 6) & 0x3Fu));
			byte b9 = (byte)(0x80u | (scalar & 0x3Fu));
			return (((((b9 << 8) | b8) << 8) | b7) << 8) | b6;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		internal static bool IsSupplementaryCodePoint(int scalar)
		{
			return (scalar & -65536) != 0;
		}
	}
	public sealed class UnicodeRange
	{
		public int FirstCodePoint { get; private set; }

		public int Length { get; private set; }

		public UnicodeRange(int firstCodePoint, int length)
		{
			if (firstCodePoint < 0 || firstCodePoint > 65535)
			{
				throw new ArgumentOutOfRangeException("firstCodePoint");
			}
			if (length < 0 || (long)firstCodePoint + (long)length > 65536)
			{
				throw new ArgumentOutOfRangeException("length");
			}
			FirstCodePoint = firstCodePoint;
			Length = length;
		}

		public static UnicodeRange Create(char firstCharacter, char lastCharacter)
		{
			if (lastCharacter < firstCharacter)
			{
				throw new ArgumentOutOfRangeException("lastCharacter");
			}
			return new UnicodeRange(firstCharacter, 1 + (lastCharacter - firstCharacter));
		}
	}
	public static class UnicodeRanges
	{
		private static UnicodeRange _none;

		private static UnicodeRange _all;

		private static UnicodeRange _u0000;

		private static UnicodeRange _u0080;

		private static UnicodeRange _u0100;

		private static UnicodeRange _u0180;

		private static UnicodeRange _u0250;

		private static UnicodeRange _u02B0;

		private static UnicodeRange _u0300;

		private static UnicodeRange _u0370;

		private static UnicodeRange _u0400;

		private static UnicodeRange _u0500;

		private static UnicodeRange _u0530;

		private static UnicodeRange _u0590;

		private static UnicodeRange _u0600;

		private static UnicodeRange _u0700;

		private static UnicodeRange _u0750;

		private static UnicodeRange _u0780;

		private static UnicodeRange _u07C0;

		private static UnicodeRange _u0800;

		private static UnicodeRange _u0840;

		private static UnicodeRange _u0860;

		private static UnicodeRange _u08A0;

		private static UnicodeRange _u0900;

		private static UnicodeRange _u0980;

		private static UnicodeRange _u0A00;

		private static UnicodeRange _u0A80;

		private static UnicodeRange _u0B00;

		private static UnicodeRange _u0B80;

		private static UnicodeRange _u0C00;

		private static UnicodeRange _u0C80;

		private static UnicodeRange _u0D00;

		private static UnicodeRange _u0D80;

		private static UnicodeRange _u0E00;

		private static UnicodeRange _u0E80;

		private static UnicodeRange _u0F00;

		private static UnicodeRange _u1000;

		private static UnicodeRange _u10A0;

		private static UnicodeRange _u1100;

		private static UnicodeRange _u1200;

		private static UnicodeRange _u1380;

		private static UnicodeRange _u13A0;

		private static UnicodeRange _u1400;

		private static UnicodeRange _u1680;

		private static UnicodeRange _u16A0;

		private static UnicodeRange _u1700;

		private static UnicodeRange _u1720;

		private static UnicodeRange _u1740;

		private static UnicodeRange _u1760;

		private static UnicodeRange _u1780;

		private static UnicodeRange _u1800;

		private static UnicodeRange _u18B0;

		private static UnicodeRange _u1900;

		private static UnicodeRange _u1950;

		private static UnicodeRange _u1980;

		private static UnicodeRange _u19E0;

		private static UnicodeRange _u1A00;

		private static UnicodeRange _u1A20;

		private static UnicodeRange _u1AB0;

		private static UnicodeRange _u1B00;

		private static UnicodeRange _u1B80;

		private static UnicodeRange _u1BC0;

		private static UnicodeRange _u1C00;

		private static UnicodeRange _u1C50;

		private static UnicodeRange _u1C80;

		private static UnicodeRange _u1C90;

		private static UnicodeRange _u1CC0;

		private static UnicodeRange _u1CD0;

		private static UnicodeRange _u1D00;

		private static UnicodeRange _u1D80;

		private static UnicodeRange _u1DC0;

		private static UnicodeRange _u1E00;

		private static UnicodeRange _u1F00;

		private static UnicodeRange _u2000;

		private static UnicodeRange _u2070;

		private static UnicodeRange _u20A0;

		private static UnicodeRange _u20D0;

		private static UnicodeRange _u2100;

		private static UnicodeRange _u2150;

		private static UnicodeRange _u2190;

		private static UnicodeRange _u2200;

		private static UnicodeRange _u2300;

		private static UnicodeRange _u2400;

		private static UnicodeRange _u2440;

		private static UnicodeRange _u2460;

		private static UnicodeRange _u2500;

		private static UnicodeRange _u2580;

		private static UnicodeRange _u25A0;

		private static UnicodeRange _u2600;

		private static UnicodeRange _u2700;

		private static UnicodeRange _u27C0;

		private static UnicodeRange _u27F0;

		private static UnicodeRange _u2800;

		private static UnicodeRange _u2900;

		private static UnicodeRange _u2980;

		private static UnicodeRange _u2A00;

		private static UnicodeRange _u2B00;

		private static UnicodeRange _u2C00;

		private static UnicodeRange _u2C60;

		private static UnicodeRange _u2C80;

		private static UnicodeRange _u2D00;

		private static UnicodeRange _u2D30;

		private static UnicodeRange _u2D80;

		private static UnicodeRange _u2DE0;

		private static UnicodeRange _u2E00;

		private static UnicodeRange _u2E80;

		private static UnicodeRange _u2F00;

		private static UnicodeRange _u2FF0;

		private static UnicodeRange _u3000;

		private static UnicodeRange _u3040;

		private static UnicodeRange _u30A0;

		private static UnicodeRange _u3100;

		private static UnicodeRange _u3130;

		private static UnicodeRange _u3190;

		private static UnicodeRange _u31A0;

		private static UnicodeRange _u31C0;

		private static UnicodeRange _u31F0;

		private static UnicodeRange _u3200;

		private static UnicodeRange _u3300;

		private static UnicodeRange _u3400;

		private static UnicodeRange _u4DC0;

		private static UnicodeRange _u4E00;

		private static UnicodeRange _uA000;

		private static UnicodeRange _uA490;

		private static UnicodeRange _uA4D0;

		private static UnicodeRange _uA500;

		private static UnicodeRange _uA640;

		private static UnicodeRange _uA6A0;

		private static UnicodeRange _uA700;

		private static UnicodeRange _uA720;

		private static UnicodeRange _uA800;

		private static UnicodeRange _uA830;

		private static UnicodeRange _uA840;

		private static UnicodeRange _uA880;

		private static UnicodeRange _uA8E0;

		private static UnicodeRange _uA900;

		private static UnicodeRange _uA930;

		private static UnicodeRange _uA960;

		private static UnicodeRange _uA980;

		private static UnicodeRange _uA9E0;

		private static UnicodeRange _uAA00;

		private static UnicodeRange _uAA60;

		private static UnicodeRange _uAA80;

		private static UnicodeRange _uAAE0;

		private static UnicodeRange _uAB00;

		private static UnicodeRange _uAB30;

		private static UnicodeRange _uAB70;

		private static UnicodeRange _uABC0;

		private static UnicodeRange _uAC00;

		private static UnicodeRange _uD7B0;

		private static UnicodeRange _uF900;

		private static UnicodeRange _uFB00;

		private static UnicodeRange _uFB50;

		private static UnicodeRange _uFE00;

		private static UnicodeRange _uFE10;

		private static UnicodeRange _uFE20;

		private static UnicodeRange _uFE30;

		private static UnicodeRange _uFE50;

		private static UnicodeRange _uFE70;

		private static UnicodeRange _uFF00;

		private static UnicodeRange _uFFF0;

		public static UnicodeRange None => _none ?? CreateEmptyRange(ref _none);

		public static UnicodeRange All => _all ?? CreateRange(ref _all, '\0', '\uffff');

		public static UnicodeRange BasicLatin => _u0000 ?? CreateRange(ref _u0000, '\0', '\u007f');

		public static UnicodeRange Latin1Supplement => _u0080 ?? CreateRange(ref _u0080, '\u0080', 'ÿ');

		public static UnicodeRange LatinExtendedA => _u0100 ?? CreateRange(ref _u0100, 'Ā', 'ſ');

		public static UnicodeRange LatinExtendedB => _u0180 ?? CreateRange(ref _u0180, 'ƀ', 'ɏ');

		public static UnicodeRange IpaExtensions => _u0250 ?? CreateRange(ref _u0250, 'ɐ', 'ʯ');

		public static UnicodeRange SpacingModifierLetters => _u02B0 ?? CreateRange(ref _u02B0, 'ʰ', '\u02ff');

		public static UnicodeRange CombiningDiacriticalMarks => _u0300 ?? CreateRange(ref _u0300, '\u0300', '\u036f');

		public static UnicodeRange GreekandCoptic => _u0370 ?? CreateRange(ref _u0370, 'Ͱ', 'Ͽ');

		public static UnicodeRange Cyrillic => _u0400 ?? CreateRange(ref _u0400, 'Ѐ', 'ӿ');

		public static UnicodeRange CyrillicSupplement => _u0500 ?? CreateRange(ref _u0500, 'Ԁ', 'ԯ');

		public static UnicodeRange Armenian => _u0530 ?? CreateRange(ref _u0530, '\u0530', '֏');

		public static UnicodeRange Hebrew => _u0590 ?? CreateRange(ref _u0590, '\u0590', '\u05ff');

		public static UnicodeRange Arabic => _u0600 ?? CreateRange(ref _u0600, '\u0600', 'ۿ');

		public static UnicodeRange Syriac => _u0700 ?? CreateRange(ref _u0700, '܀', 'ݏ');

		public static UnicodeRange ArabicSupplement => _u0750 ?? CreateRange(ref _u0750, 'ݐ', 'ݿ');

		public static UnicodeRange Thaana => _u0780 ?? CreateRange(ref _u0780, 'ހ', '\u07bf');

		public static UnicodeRange NKo => _u07C0 ?? CreateRange(ref _u07C0, '߀', '߿');

		public static UnicodeRange Samaritan => _u0800 ?? CreateRange(ref _u0800, 'ࠀ', '\u083f');

		public static UnicodeRange Mandaic => _u0840 ?? CreateRange(ref _u0840, 'ࡀ', '\u085f');

		public static UnicodeRange SyriacSupplement => _u0860 ?? CreateRange(ref _u0860, 'ࡠ', '\u086f');

		public static UnicodeRange ArabicExtendedA => _u08A0 ?? CreateRange(ref _u08A0, 'ࢠ', '\u08ff');

		public static UnicodeRange Devanagari => _u0900 ?? CreateRange(ref _u0900, '\u0900', 'ॿ');

		public static UnicodeRange Bengali => _u0980 ?? CreateRange(ref _u0980, 'ঀ', '\u09ff');

		public static UnicodeRange Gurmukhi => _u0A00 ?? CreateRange(ref _u0A00, '\u0a00', '\u0a7f');

		public static UnicodeRange Gujarati => _u0A80 ?? CreateRange(ref _u0A80, '\u0a80', '\u0aff');

		public static UnicodeRange Oriya => _u0B00 ?? CreateRange(ref _u0B00, '\u0b00', '\u0b7f');

		public static UnicodeRange Tamil => _u0B80 ?? CreateRange(ref _u0B80, '\u0b80', '\u0bff');

		public static UnicodeRange Telugu => _u0C00 ?? CreateRange(ref _u0C00, '\u0c00', '౿');

		public static UnicodeRange Kannada => _u0C80 ?? CreateRange(ref _u0C80, 'ಀ', '\u0cff');

		public static UnicodeRange Malayalam => _u0D00 ?? CreateRange(ref _u0D00, '\u0d00', 'ൿ');

		public static UnicodeRange Sinhala => _u0D80 ?? CreateRange(ref _u0D80, '\u0d80', '\u0dff');

		public static UnicodeRange Thai => _u0E00 ?? CreateRange(ref _u0E00, '\u0e00', '\u0e7f');

		public static UnicodeRange Lao => _u0E80 ?? CreateRange(ref _u0E80, '\u0e80', '\u0eff');

		public static UnicodeRange Tibetan => _u0F00 ?? CreateRange(ref _u0F00, 'ༀ', '\u0fff');

		public static UnicodeRange Myanmar => _u1000 ?? CreateRange(ref _u1000, 'က', '႟');

		public static UnicodeRange Georgian => _u10A0 ?? CreateRange(ref _u10A0, 'Ⴀ', 'ჿ');

		public static UnicodeRange HangulJamo => _u1100 ?? CreateRange(ref _u1100, 'ᄀ', 'ᇿ');

		public static UnicodeRange Ethiopic => _u1200 ?? CreateRange(ref _u1200, 'ሀ', '\u137f');

		public static UnicodeRange EthiopicSupplement => _u1380 ?? CreateRange(ref _u1380, 'ᎀ', '\u139f');

		public static UnicodeRange Cherokee => _u13A0 ?? CreateRange(ref _u13A0, 'Ꭰ', '\u13ff');

		public static UnicodeRange UnifiedCanadianAboriginalSyllabics => _u1400 ?? CreateRange(ref _u1400, '᐀', 'ᙿ');

		public static UnicodeRange Ogham => _u1680 ?? CreateRange(ref _u1680, '\u1680', '\u169f');

		public static UnicodeRange Runic => _u16A0 ?? CreateRange(ref _u16A0, 'ᚠ', '\u16ff');

		public static UnicodeRange Tagalog => _u1700 ?? CreateRange(ref _u1700, 'ᜀ', '\u171f');

		public static UnicodeRange Hanunoo => _u1720 ?? CreateRange(ref _u1720, 'ᜠ', '\u173f');

		public static UnicodeRange Buhid => _u1740 ?? CreateRange(ref _u1740, 'ᝀ', '\u175f');

		public static UnicodeRange Tagbanwa => _u1760 ?? CreateRange(ref _u1760, 'ᝠ', '\u177f');

		public static UnicodeRange Khmer => _u1780 ?? CreateRange(ref _u1780, 'ក', '\u17ff');

		public static UnicodeRange Mongolian => _u1800 ?? CreateRange(ref _u1800, '᠀', '\u18af');

		public static UnicodeRange UnifiedCanadianAboriginalSyllabicsExtended => _u18B0 ?? CreateRange(ref _u18B0, 'ᢰ', '\u18ff');

		public static UnicodeRange Limbu => _u1900 ?? CreateRange(ref _u1900, 'ᤀ', '᥏');

		public static UnicodeRange TaiLe => _u1950 ?? CreateRange(ref _u1950, 'ᥐ', '\u197f');

		public static UnicodeRange NewTaiLue => _u1980 ?? CreateRange(ref _u1980, 'ᦀ', '᧟');

		public static UnicodeRange KhmerSymbols => _u19E0 ?? CreateRange(ref _u19E0, '᧠', '᧿');

		public static UnicodeRange Buginese => _u1A00 ?? CreateRange(ref _u1A00, 'ᨀ', '᨟');

		public static UnicodeRange TaiTham => _u1A20 ?? CreateRange(ref _u1A20, 'ᨠ', '\u1aaf');

		public static UnicodeRange CombiningDiacriticalMarksExtended => _u1AB0 ?? CreateRange(ref _u1AB0, '\u1ab0', '\u1aff');

		public static UnicodeRange Balinese => _u1B00 ?? CreateRange(ref _u1B00, '\u1b00', '\u1b7f');

		public static UnicodeRange Sundanese => _u1B80 ?? CreateRange(ref _u1B80, '\u1b80', 'ᮿ');

		public static UnicodeRange Batak => _u1BC0 ?? CreateRange(ref _u1BC0, 'ᯀ', '᯿');

		public static UnicodeRange Lepcha => _u1C00 ?? CreateRange(ref _u1C00, 'ᰀ', 'ᱏ');

		public static UnicodeRange OlChiki => _u1C50 ?? CreateRange(ref _u1C50, '᱐', '᱿');

		public static UnicodeRange CyrillicExtendedC => _u1C80 ?? CreateRange(ref _u1C80, 'ᲀ', '\u1c8f');

		public static UnicodeRange GeorgianExtended => _u1C90 ?? CreateRange(ref _u1C90, 'Ა', 'Ჿ');

		public static UnicodeRange SundaneseSupplement => _u1CC0 ?? CreateRange(ref _u1CC0, '᳀', '\u1ccf');

		public static UnicodeRange VedicExtensions => _u1CD0 ?? CreateRange(ref _u1CD0, '\u1cd0', '\u1cff');

		public static UnicodeRange PhoneticExtensions => _u1D00 ?? CreateRange(ref _u1D00, 'ᴀ', 'ᵿ');

		public static UnicodeRange PhoneticExtensionsSupplement => _u1D80 ?? CreateRange(ref _u1D80, 'ᶀ', 'ᶿ');

		public static UnicodeRange CombiningDiacriticalMarksSupplement => _u1DC0 ?? CreateRange(ref _u1DC0, '\u1dc0', '\u1dff');

		public static UnicodeRange LatinExtendedAdditional => _u1E00 ?? CreateRange(ref _u1E00, 'Ḁ', 'ỿ');

		public static UnicodeRange GreekExtended => _u1F00 ?? CreateRange(ref _u1F00, 'ἀ', '\u1fff');

		public static UnicodeRange GeneralPunctuation => _u2000 ?? CreateRange(ref _u2000, '\u2000', '\u206f');

		public static UnicodeRange SuperscriptsandSubscripts => _u2070 ?? CreateRange(ref _u2070, '⁰', '\u209f');

		public static UnicodeRange CurrencySymbols => _u20A0 ?? CreateRange(ref _u20A0, '₠', '\u20cf');

		public static UnicodeRange CombiningDiacriticalMarksforSymbols => _u20D0 ?? CreateRange(ref _u20D0, '\u20d0', '\u20ff');

		public static UnicodeRange LetterlikeSymbols => _u2100 ?? CreateRange(ref _u2100, '℀', '⅏');

		public static UnicodeRange NumberForms => _u2150 ?? CreateRange(ref _u2150, '⅐', '\u218f');

		public static UnicodeRange Arrows => _u2190 ?? CreateRange(ref _u2190, '←', '⇿');

		public static UnicodeRange MathematicalOperators => _u2200 ?? CreateRange(ref _u2200, '∀', '⋿');

		public static UnicodeRange MiscellaneousTechnical => _u2300 ?? CreateRange(ref _u2300, '⌀', '⏿');

		public static UnicodeRange ControlPictures => _u2400 ?? CreateRange(ref _u2400, '␀', '\u243f');

		public static UnicodeRange OpticalCharacterRecognition => _u2440 ?? CreateRange(ref _u2440, '⑀', '\u245f');

		public static UnicodeRange EnclosedAlphanumerics => _u2460 ?? CreateRange(ref _u2460, '①', '⓿');

		public static UnicodeRange BoxDrawing => _u2500 ?? CreateRange(ref _u2500, '─', '╿');

		public static UnicodeRange BlockElements => _u2580 ?? CreateRange(ref _u2580, '▀', '▟');

		public static UnicodeRange GeometricShapes => _u25A0 ?? CreateRange(ref _u25A0, '■', '◿');

		public static UnicodeRange MiscellaneousSymbols => _u2600 ?? CreateRange(ref _u2600, '☀', '⛿');

		public static UnicodeRange Dingbats => _u2700 ?? CreateRange(ref _u2700, '✀', '➿');

		public static UnicodeRange MiscellaneousMathematicalSymbolsA => _u27C0 ?? CreateRange(ref _u27C0, '⟀', '⟯');

		public static UnicodeRange SupplementalArrowsA => _u27F0 ?? CreateRange(ref _u27F0, '⟰', '⟿');

		public static UnicodeRange BraillePatterns => _u2800 ?? CreateRange(ref _u2800, '⠀', '⣿');

		public static UnicodeRange SupplementalArrowsB => _u2900 ?? CreateRange(ref _u2900, '⤀', '⥿');

		public static UnicodeRange MiscellaneousMathematicalSymbolsB => _u2980 ?? CreateRange(ref _u2980, '⦀', '⧿');

		public static UnicodeRange SupplementalMathematicalOperators => _u2A00 ?? CreateRange(ref _u2A00, '⨀', '⫿');

		public static UnicodeRange MiscellaneousSymbolsandArrows => _u2B00 ?? CreateRange(ref _u2B00, '⬀', '⯿');

		public static UnicodeRange Glagolitic => _u2C00 ?? CreateRange(ref _u2C00, 'Ⰰ', '\u2c5f');

		public static UnicodeRange LatinExtendedC => _u2C60 ?? CreateRange(ref _u2C60, 'Ⱡ', 'Ɀ');

		public static UnicodeRange Coptic => _u2C80 ?? CreateRange(ref _u2C80, 'Ⲁ', '⳿');

		public static UnicodeRange GeorgianSupplement => _u2D00 ?? CreateRange(ref _u2D00, 'ⴀ', '\u2d2f');

		public static UnicodeRange Tifinagh => _u2D30 ?? CreateRange(ref _u2D30, 'ⴰ', '\u2d7f');

		public static UnicodeRange EthiopicExtended => _u2D80 ?? CreateRange(ref _u2D80, 'ⶀ', '\u2ddf');

		public static UnicodeRange CyrillicExtendedA => _u2DE0 ?? CreateRange(ref _u2DE0, '\u2de0', '\u2dff');

		public static UnicodeRange SupplementalPunctuation => _u2E00 ?? CreateRange(ref _u2E00, '⸀', '\u2e7f');

		public static UnicodeRange CjkRadicalsSupplement => _u2E80 ?? CreateRange(ref _u2E80, '⺀', '\u2eff');

		public static UnicodeRange KangxiRadicals => _u2F00 ?? CreateRange(ref _u2F00, '⼀', '\u2fdf');

		public static UnicodeRange IdeographicDescriptionCharacters => _u2FF0 ?? CreateRange(ref _u2FF0, '⿰', '\u2fff');

		public static UnicodeRange CjkSymbolsandPunctuation => _u3000 ?? CreateRange(ref _u3000, '\u3000', '〿');

		public static UnicodeRange Hiragana => _u3040 ?? CreateRange(ref _u3040, '\u3040', 'ゟ');

		public static UnicodeRange Katakana => _u30A0 ?? CreateRange(ref _u30A0, '゠', 'ヿ');

		public static UnicodeRange Bopomofo => _u3100 ?? CreateRange(ref _u3100, '\u3100', 'ㄯ');

		public static UnicodeRange HangulCompatibilityJamo => _u3130 ?? CreateRange(ref _u3130, '\u3130', '\u318f');

		public static UnicodeRange Kanbun => _u3190 ?? CreateRange(ref _u3190, '㆐', '㆟');

		public static UnicodeRange BopomofoExtended => _u31A0 ?? CreateRange(ref _u31A0, 'ㆠ', 'ㆿ');

		public static UnicodeRange CjkStrokes => _u31C0 ?? CreateRange(ref _u31C0, '㇀', '\u31ef');

		public static UnicodeRange KatakanaPhoneticExtensions => _u31F0 ?? CreateRange(ref _u31F0, 'ㇰ', 'ㇿ');

		public static UnicodeRange EnclosedCjkLettersandMonths => _u3200 ?? CreateRange(ref _u3200, '㈀', '㋿');

		public static UnicodeRange CjkCompatibility => _u3300 ?? CreateRange(ref _u3300, '㌀', '㏿');

		public static UnicodeRange CjkUnifiedIdeographsExtensionA => _u3400 ?? CreateRange(ref _u3400, '㐀', '䶿');

		public static UnicodeRange YijingHexagramSymbols => _u4DC0 ?? CreateRange(ref _u4DC0, '䷀', '䷿');

		public static UnicodeRange CjkUnifiedIdeographs => _u4E00 ?? CreateRange(ref _u4E00, '一', '\u9fff');

		public static UnicodeRange YiSyllables => _uA000 ?? CreateRange(ref _uA000, 'ꀀ', '\ua48f');

		public static UnicodeRange YiRadicals => _uA490 ?? CreateRange(ref _uA490, '꒐', '\ua4cf');

		public static UnicodeRange Lisu => _uA4D0 ?? CreateRange(ref _uA4D0, 'ꓐ', '꓿');

		public static UnicodeRange Vai => _uA500 ?? CreateRange(ref _uA500, 'ꔀ', '\ua63f');

		public static UnicodeRange CyrillicExtendedB => _uA640 ?? CreateRange(ref _uA640, 'Ꙁ', '\ua69f');

		public static UnicodeRange Bamum => _uA6A0 ?? CreateRange(ref _uA6A0, 'ꚠ', '\ua6ff');

		public static UnicodeRange ModifierToneLetters => _uA700 ?? CreateRange(ref _uA700, '\ua700', 'ꜟ');

		public static UnicodeRange LatinExtendedD => _uA720 ?? CreateRange(ref _uA720, '\ua720', 'ꟿ');

		public static UnicodeRange SylotiNagri => _uA800 ?? CreateRange(ref _uA800, 'ꠀ', '\ua82f');

		public static UnicodeRange CommonIndicNumberForms => _uA830 ?? CreateRange(ref _uA830, '꠰', '\ua83f');

		public static UnicodeRange Phagspa => _uA840 ?? CreateRange(ref _uA840, 'ꡀ', '\ua87f');

		public static UnicodeRange Saurashtra => _uA880 ?? CreateRange(ref _uA880, '\ua880', '\ua8df');

		public static UnicodeRange DevanagariExtended => _uA8E0 ?? CreateRange(ref _uA8E0, '\ua8e0', '\ua8ff');

		public static UnicodeRange KayahLi => _uA900 ?? CreateRange(ref _uA900, '꤀', '꤯');

		public static UnicodeRange Rejang => _uA930 ?? CreateRange(ref _uA930, 'ꤰ', '꥟');

		public static UnicodeRange HangulJamoExtendedA => _uA960 ?? CreateRange(ref _uA960, 'ꥠ', '\ua97f');

		public static UnicodeRange Javanese => _uA980 ?? CreateRange(ref _uA980, '\ua980', '꧟');

		public static UnicodeRange MyanmarExtendedB => _uA9E0 ?? CreateRange(ref _uA9E0, 'ꧠ', '\ua9ff');

		public static UnicodeRange Cham => _uAA00 ?? CreateRange(ref _uAA00, 'ꨀ', '꩟');

		public static UnicodeRange MyanmarExtendedA => _uAA60 ?? CreateRange(ref _uAA60, 'ꩠ', 'ꩿ');

		public static UnicodeRange TaiViet => _uAA80 ?? CreateRange(ref _uAA80, 'ꪀ', '꫟');

		public static UnicodeRange MeeteiMayekExtensions => _uAAE0 ?? CreateRange(ref _uAAE0, 'ꫠ', '\uaaff');

		public static UnicodeRange EthiopicExtendedA => _uAB00 ?? CreateRange(ref _uAB00, '\uab00', '\uab2f');

		public static UnicodeRange LatinExtendedE => _uAB30 ?? CreateRange(ref _uAB30, 'ꬰ', '\uab6f');

		public static UnicodeRange CherokeeSupplement => _uAB70 ?? CreateRange(ref _uAB70, 'ꭰ', 'ꮿ');

		public static UnicodeRange MeeteiMayek => _uABC0 ?? CreateRange(ref _uABC0, 'ꯀ', '\uabff');

		public static UnicodeRange HangulSyllables => _uAC00 ?? CreateRange(ref _uAC00, '가', '\ud7af');

		public static UnicodeRange HangulJamoExtendedB => _uD7B0 ?? CreateRange(ref _uD7B0, 'ힰ', '\ud7ff');

		public static UnicodeRange CjkCompatibilityIdeographs => _uF900 ?? CreateRange(ref _uF900, '豈', '\ufaff');

		public static UnicodeRange AlphabeticPresentationForms => _uFB00 ?? CreateRange(ref _uFB00, 'ff', 'ﭏ');

		public static UnicodeRange ArabicPresentationFormsA => _uFB50 ?? CreateRange(ref _uFB50, 'ﭐ', '\ufdff');

		public static UnicodeRange VariationSelectors => _uFE00 ?? CreateRange(ref _uFE00, '\ufe00', '\ufe0f');

		public static UnicodeRange VerticalForms => _uFE10 ?? CreateRange(ref _uFE10, '︐', '\ufe1f');

		public static UnicodeRange CombiningHalfMarks => _uFE20 ?? CreateRange(ref _uFE20, '\ufe20', '\ufe2f');

		public static UnicodeRange CjkCompatibilityForms => _uFE30 ?? CreateRange(ref _uFE30, '︰', '\ufe4f');

		public static UnicodeRange SmallFormVariants => _uFE50 ?? CreateRange(ref _uFE50, '﹐', '\ufe6f');

		public static UnicodeRange ArabicPresentationFormsB => _uFE70 ?? CreateRange(ref _uFE70, 'ﹰ', '\ufeff');

		public static UnicodeRange HalfwidthandFullwidthForms => _uFF00 ?? CreateRange(ref _uFF00, '\uff00', '\uffef');

		public static UnicodeRange Specials => _uFFF0 ?? CreateRange(ref _uFFF0, '\ufff0', '\uffff');

		[MethodImpl(MethodImplOptions.NoInlining)]
		private static UnicodeRange CreateEmptyRange([NotNull] ref UnicodeRange range)
		{
			Volatile.Write(ref range, new UnicodeRange(0, 0));
			return range;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private static UnicodeRange CreateRange([NotNull] ref UnicodeRange range, char first, char last)
		{
			Volatile.Write(ref range, UnicodeRange.Create(first, last));
			return range;
		}
	}
}
namespace System.Text.Internal
{
	internal readonly struct AllowedCharactersBitmap
	{
		private const int ALLOWED_CHARS_BITMAP_LENGTH = 2048;

		private readonly uint[] _allowedCharacters;

		public static AllowedCharactersBitmap CreateNew()
		{
			return new AllowedCharactersBitmap(new uint[2048]);
		}

		private AllowedCharactersBitmap(uint[] allowedCharacters)
		{
			if (allowedCharacters == null)
			{
				throw new ArgumentNullException("allowedCharacters");
			}
			_allowedCharacters = allowedCharacters;
		}

		public void AllowCharacter(char character)
		{
			int num = (int)character >> 5;
			int num2 = character & 0x1F;
			_allowedCharacters[num] |= (uint)(1 << num2);
		}

		public void ForbidCharacter(char character)
		{
			int num = (int)character >> 5;
			int num2 = character & 0x1F;
			_allowedCharacters[num] &= (uint)(~(1 << num2));
		}

		public void ForbidUndefinedCharacters()
		{
			ReadOnlySpan<uint> definedCharacterBitmap = UnicodeHelpers.GetDefinedCharacterBitmap();
			for (int i = 0; i < _allowedCharacters.Length; i++)
			{
				_allowedCharacters[i] &= definedCharacterBitmap[i];
			}
		}

		public void Clear()
		{
			Array.Clear(_allowedCharacters, 0, _allowedCharacters.Length);
		}

		public AllowedCharactersBitmap Clone()
		{
			return new AllowedCharactersBitmap((uint[])_allowedCharacters.Clone());
		}

		public bool IsCharacterAllowed(char character)
		{
			return IsUnicodeScalarAllowed(character);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public bool IsUnicodeScalarAllowed(int unicodeScalar)
		{
			int num = unicodeScalar >> 5;
			int num2 = unicodeScalar & 0x1F;
			return (_allowedCharacters[num] & (uint)(1 << num2)) != 0;
		}

		public unsafe int FindFirstCharacterToEncode(char* text, int textLength)
		{
			int num = 0;
			while (true)
			{
				if (num <= textLength - 8)
				{
					if (!IsCharacterAllowed(text[num]) || !IsCharacterAllowed(text[++num]) || !IsCharacterAllowed(text[++num]) || !IsCharacterAllowed(text[++num]) || !IsCharacterAllowed(text[++num]) || !IsCharacterAllowed(text[++num]) || !IsCharacterAllowed(text[++num]) || !IsCharacterAllowed(text[++num]))
					{
						break;
					}
					num++;
					continue;
				}
				while (true)
				{
					if (num <= textLength - 4)
					{
						if (!IsCharacterAllowed(text[num]) || !IsCharacterAllowed(text[++num]) || !IsCharacterAllowed(text[++num]) || !IsCharacterAllowed(text[++num]))
						{
							break;
						}
						num++;
						continue;
					}
					while (true)
					{
						if (num < textLength)
						{
							if (!IsCharacterAllowed(text[num]))
							{
								break;
							}
							num++;
							continue;
						}
						num = -1;
						break;
					}
					break;
				}
				break;
			}
			return num;
		}
	}
}
namespace System.Text.Encodings.Web
{
	internal sealed class DefaultJavaScriptEncoder : JavaScriptEncoder
	{
		private readonly AllowedCharactersBitmap _allowedCharacters;

		private readonly int[] _asciiNeedsEscaping = new int[128];

		private static readonly char[] s_b = new char[2] { '\\', 'b' };

		private static readonly char[] s_t = new char[2] { '\\', 't' };

		private static readonly char[] s_n = new char[2] { '\\', 'n' };

		private static readonly char[] s_f = new char[2] { '\\', 'f' };

		private static readonly char[] s_r = new char[2] { '\\', 'r' };

		private static readonly char[] s_back = new char[2] { '\\', '\\' };

		public override int MaxOutputCharactersPerInputCharacter => 12;

		public DefaultJavaScriptEncoder(TextEncoderSettings filter)
		{
			if (filter == null)
			{
				throw new ArgumentNullException("filter");
			}
			_allowedCharacters = filter.GetAllowedCharacters();
			_allowedCharacters.ForbidUndefinedCharacters();
			DefaultHtmlEncoder.ForbidHtmlCharacters(_allowedCharacters);
			_allowedCharacters.ForbidCharacter('\\');
			_allowedCharacters.ForbidCharacter('`');
			for (int i = 0; i < _asciiNeedsEscaping.Length; i++)
			{
				_asciiNeedsEscaping[i] = (WillEncode(i) ? 1 : (-1));
			}
		}

		public DefaultJavaScriptEncoder(params UnicodeRange[] allowedRanges)
			: this(new TextEncoderSettings(allowedRanges))
		{
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public override bool WillEncode(int unicodeScalar)
		{
			if (UnicodeHelpers.IsSupplementaryCodePoint(unicodeScalar))
			{
				return true;
			}
			return !_allowedCharacters.IsUnicodeScalarAllowed(unicodeScalar);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public unsafe override int FindFirstCharacterToEncode(char* text, int textLength)
		{
			if (text == null)
			{
				throw new ArgumentNullException("text");
			}
			return _allowedCharacters.FindFirstCharacterToEncode(text, textLength);
		}

		public unsafe override int FindFirstCharacterToEncodeUtf8(ReadOnlySpan<byte> utf8Text)
		{
			fixed (byte* ptr = utf8Text)
			{
				int num = 0;
				while (true)
				{
					if (num < utf8Text.Length)
					{
						if (System.Text.UnicodeUtility.IsAsciiCodePoint(ptr[num]))
						{
							if (DoesAsciiNeedEncoding(ptr[num]) == 1)
							{
								break;
							}
							num++;
						}
						else
						{
							if (UnicodeHelpers.DecodeScalarValueFromUtf8(utf8Text.Slice(num), out var result, out var bytesConsumed) != 0 || WillEncode((int)result))
							{
								break;
							}
							num += bytesConsumed;
						}
						continue;
					}
					num = -1;
					break;
				}
				return num;
			}
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		private int DoesAsciiNeedEncoding(byte value)
		{
			return _asciiNeedsEscaping[value];
		}

		public unsafe override bool TryEncodeUnicodeScalar(int unicodeScalar, char* buffer, int bufferLength, out int numberOfCharactersWritten)
		{
			if (buffer == null)
			{
				throw new ArgumentNullException("buffer");
			}
			if (!WillEncode(unicodeScalar))
			{
				return TextEncoder.TryWriteScalarAsChar(unicodeScalar, buffer, bufferLength, out numberOfCharactersWritten);
			}
			char[] source;
			switch (unicodeScalar)
			{
			case 8:
				source = s_b;
				break;
			case 9:
				source = s_t;
				break;
			case 10:
				source = s_n;
				break;
			case 12:
				source = s_f;
				break;
			case 13:
				source = s_r;
				break;
			case 92:
				source = s_back;
				break;
			default:
				return JavaScriptEncoderHelper.TryWriteEncodedScalarAsNumericEntity(unicodeScalar, buffer, bufferLength, out numberOfCharactersWritten);
			}
			return TextEncoder.TryCopyCharacters(source, buffer, bufferLength, out numberOfCharactersWritten);
		}
	}
	internal sealed class DefaultJavaScriptEncoderBasicLatin : JavaScriptEncoder
	{
		internal static readonly DefaultJavaScriptEncoderBasicLatin s_singleton = new DefaultJavaScriptEncoderBasicLatin();

		private static readonly char[] s_b = new char[2] { '\\', 'b' };

		private static readonly char[] s_t = new char[2] { '\\', 't' };

		private static readonly char[] s_n = new char[2] { '\\', 'n' };

		private static readonly char[] s_f = new char[2] { '\\', 'f' };

		private static readonly char[] s_r = new char[2] { '\\', 'r' };

		private static readonly char[] s_back = new char[2] { '\\', '\\' };

		public const int LastAsciiCharacter = 127;

		public override int MaxOutputCharactersPerInputCharacter => 12;

		private static ReadOnlySpan<byte> AllowList => new byte[256]
		{
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 1, 1, 0, 1, 1, 1, 0, 0,
			1, 1, 1, 0, 1, 1, 1, 1, 1, 1,
			1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
			0, 1, 0, 1, 1, 1, 1, 1, 1, 1,
			1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
			1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
			1, 1, 0, 1, 1, 1, 0, 1, 1, 1,
			1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
			1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
			1, 1, 1, 1, 1, 1, 1, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0
		};

		private DefaultJavaScriptEncoderBasicLatin()
		{
			TextEncoderSettings textEncoderSettings = new TextEncoderSettings(UnicodeRanges.BasicLatin);
			AllowedCharactersBitmap allowedCharacters = textEncoderSettings.GetAllowedCharacters();
			allowedCharacters.ForbidUndefinedCharacters();
			DefaultHtmlEncoder.ForbidHtmlCharacters(allowedCharacters);
			allowedCharacters.ForbidCharacter('\\');
			allowedCharacters.ForbidCharacter('`');
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public override bool WillEncode(int unicodeScalar)
		{
			if (UnicodeHelpers.IsSupplementaryCodePoint(unicodeScalar))
			{
				return true;
			}
			return NeedsEscaping((char)unicodeScalar);
		}

		public unsafe override int FindFirstCharacterToEncode(char* text, int textLength)
		{
			if (text == null)
			{
				throw new ArgumentNullException("text");
			}
			if (textLength == 0)
			{
				goto IL_0048;
			}
			int num = 0;
			short* ptr = (short*)text;
			short* ptr2 = ptr + (uint)textLength;
			ReadOnlySpan<byte> allowList = AllowList;
			while (true)
			{
				char c = (char)(*ptr);
				if (c > '\u007f' || allowList[c] == 0)
				{
					break;
				}
				ptr++;
				num++;
				if (ptr < ptr2)
				{
					continue;
				}
				goto IL_0048;
			}
			goto IL_004a;
			IL_004a:
			return num;
			IL_0048:
			num = -1;
			goto IL_004a;
		}

		public unsafe override int FindFirstCharacterToEncodeUtf8(ReadOnlySpan<byte> utf8Text)
		{
			fixed (byte* ptr = utf8Text)
			{
				uint length = (uint)u

BepInExPack/mono/Managed/System.Text.Json.dll

Decompiled a month ago
using System;
using System.Buffers;
using System.Buffers.Text;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Numerics;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text.Encodings.Web;
using System.Text.Json.Serialization;
using System.Text.Json.Serialization.Converters;
using System.Threading;
using System.Threading.Tasks;
using FxResources.System.Text.Json;
using Microsoft.CodeAnalysis;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = "")]
[assembly: CLSCompliant(true)]
[assembly: AssemblyDefaultAlias("System.Text.Json")]
[assembly: NeutralResourcesLanguage("en-US")]
[assembly: AssemblyMetadata(".NETFrameworkAssembly", "")]
[assembly: AssemblyMetadata("Serviceable", "True")]
[assembly: AssemblyMetadata("PreferInbox", "True")]
[assembly: AssemblyCompany("Microsoft Corporation")]
[assembly: AssemblyCopyright("© Microsoft Corporation. All rights reserved.")]
[assembly: AssemblyDescription("System.Text.Json")]
[assembly: AssemblyFileVersion("5.0.521.16609")]
[assembly: AssemblyInformationalVersion("5.0.5+2f740adc1457e8a28c1c072993b66f515977eb51")]
[assembly: AssemblyProduct("Microsoft® .NET")]
[assembly: AssemblyTitle("System.Text.Json")]
[assembly: AssemblyMetadata("RepositoryUrl", "git://github.com/dotnet/runtime")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("5.0.0.0")]
[module: UnverifiableCode]
[module: System.Runtime.CompilerServices.NullablePublicOnly(false)]
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
	{
	}
	[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.Text.Json
{
	internal static class SR
	{
	}
}
namespace System
{
	internal static class HexConverter
	{
		public enum Casing : uint
		{
			Upper = 0u,
			Lower = 8224u
		}

		public static ReadOnlySpan<byte> CharToHexLookup => new byte[256]
		{
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 0, 1,
			2, 3, 4, 5, 6, 7, 8, 9, 255, 255,
			255, 255, 255, 255, 255, 10, 11, 12, 13, 14,
			15, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 10, 11, 12,
			13, 14, 15, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
			255, 255, 255, 255, 255, 255
		};

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static void ToBytesBuffer(byte value, Span<byte> buffer, int startingIndex = 0, Casing casing = Casing.Upper)
		{
			uint num = (uint)(((value & 0xF0) << 4) + (value & 0xF) - 35209);
			uint num2 = ((((0 - num) & 0x7070) >> 4) + num + 47545) | (uint)casing;
			buffer[startingIndex + 1] = (byte)num2;
			buffer[startingIndex] = (byte)(num2 >> 8);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static void ToCharsBuffer(byte value, Span<char> buffer, int startingIndex = 0, Casing casing = Casing.Upper)
		{
			uint num = (uint)(((value & 0xF0) << 4) + (value & 0xF) - 35209);
			uint num2 = ((((0 - num) & 0x7070) >> 4) + num + 47545) | (uint)casing;
			buffer[startingIndex + 1] = (char)(num2 & 0xFFu);
			buffer[startingIndex] = (char)(num2 >> 8);
		}

		public static void EncodeToUtf16(ReadOnlySpan<byte> bytes, Span<char> chars, Casing casing = Casing.Upper)
		{
			for (int i = 0; i < bytes.Length; i++)
			{
				ToCharsBuffer(bytes[i], chars, i * 2, casing);
			}
		}

		public static string ToString(ReadOnlySpan<byte> bytes, Casing casing = Casing.Upper)
		{
			Span<char> span = default(Span<char>);
			if (bytes.Length > 16)
			{
				char[] array = new char[bytes.Length * 2];
				span = array.AsSpan();
			}
			else
			{
				span = stackalloc char[bytes.Length * 2];
			}
			int num = 0;
			ReadOnlySpan<byte> readOnlySpan = bytes;
			for (int i = 0; i < readOnlySpan.Length; i++)
			{
				byte value = readOnlySpan[i];
				ToCharsBuffer(value, span, num, casing);
				num += 2;
			}
			return span.ToString();
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static char ToCharUpper(int value)
		{
			value &= 0xF;
			value += 48;
			if (value > 57)
			{
				value += 7;
			}
			return (char)value;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static char ToCharLower(int value)
		{
			value &= 0xF;
			value += 48;
			if (value > 57)
			{
				value += 39;
			}
			return (char)value;
		}

		public static bool TryDecodeFromUtf16(ReadOnlySpan<char> chars, Span<byte> bytes)
		{
			int charsProcessed;
			return TryDecodeFromUtf16(chars, bytes, out charsProcessed);
		}

		public static bool TryDecodeFromUtf16(ReadOnlySpan<char> chars, Span<byte> bytes, out int charsProcessed)
		{
			int num = 0;
			int num2 = 0;
			int num3 = 0;
			int num4 = 0;
			while (num2 < bytes.Length)
			{
				num3 = FromChar(chars[num + 1]);
				num4 = FromChar(chars[num]);
				if ((num3 | num4) == 255)
				{
					break;
				}
				bytes[num2++] = (byte)((num4 << 4) | num3);
				num += 2;
			}
			if (num3 == 255)
			{
				num++;
			}
			charsProcessed = num;
			return (num3 | num4) != 255;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static int FromChar(int c)
		{
			if (c < CharToHexLookup.Length)
			{
				return CharToHexLookup[c];
			}
			return 255;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static int FromUpperChar(int c)
		{
			if (c <= 71)
			{
				return CharToHexLookup[c];
			}
			return 255;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static int FromLowerChar(int c)
		{
			switch (c)
			{
			case 48:
			case 49:
			case 50:
			case 51:
			case 52:
			case 53:
			case 54:
			case 55:
			case 56:
			case 57:
				return c - 48;
			case 97:
			case 98:
			case 99:
			case 100:
			case 101:
			case 102:
				return c - 97 + 10;
			default:
				return 255;
			}
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static bool IsHexChar(int c)
		{
			return FromChar(c) != 255;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static bool IsHexUpperChar(int c)
		{
			if ((uint)(c - 48) > 9u)
			{
				return (uint)(c - 65) <= 5u;
			}
			return true;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static bool IsHexLowerChar(int c)
		{
			if ((uint)(c - 48) > 9u)
			{
				return (uint)(c - 97) <= 5u;
			}
			return true;
		}
	}
	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 ArrayDepthTooLarge => GetResourceString("ArrayDepthTooLarge");

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

		private static bool UsingResourceKeys()
		{
			return s_usingResourceKeys;
		}

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

		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.Collections.Generic
{
	internal sealed class ReferenceEqualityComparer : IEqualityComparer<object>, IEqualityComparer
	{
		public static ReferenceEqualityComparer Instance { get; } = new ReferenceEqualityComparer();


		private ReferenceEqualityComparer()
		{
		}

		public new bool Equals(object x, object y)
		{
			return x == y;
		}

		public int GetHashCode(object obj)
		{
			return RuntimeHelpers.GetHashCode(obj);
		}
	}
	internal static class StackExtensions
	{
		public static bool TryPeek<T>(this Stack<T> stack, [MaybeNullWhen(false)] out T result)
		{
			if (stack.Count > 0)
			{
				result = stack.Peek();
				return true;
			}
			result = default(T);
			return false;
		}

		public static bool TryPop<T>(this Stack<T> stack, [MaybeNullWhen(false)] out T result)
		{
			if (stack.Count > 0)
			{
				result = stack.Pop();
				return true;
			}
			result = default(T);
			return false;
		}
	}
}
namespace System.Diagnostics.CodeAnalysis
{
	[AttributeUsage(AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Field, AllowMultiple = true, Inherited = false)]
	internal sealed class DynamicDependencyAttribute : Attribute
	{
		public string MemberSignature { get; }

		public DynamicallyAccessedMemberTypes MemberTypes { get; }

		public Type Type { get; }

		public string TypeName { get; }

		public string AssemblyName { get; }

		public string Condition { get; set; }

		public DynamicDependencyAttribute(string memberSignature)
		{
			MemberSignature = memberSignature;
		}

		public DynamicDependencyAttribute(string memberSignature, Type type)
		{
			MemberSignature = memberSignature;
			Type = type;
		}

		public DynamicDependencyAttribute(string memberSignature, string typeName, string assemblyName)
		{
			MemberSignature = memberSignature;
			TypeName = typeName;
			AssemblyName = assemblyName;
		}

		public DynamicDependencyAttribute(DynamicallyAccessedMemberTypes memberTypes, Type type)
		{
			MemberTypes = memberTypes;
			Type = type;
		}

		public DynamicDependencyAttribute(DynamicallyAccessedMemberTypes memberTypes, string typeName, string assemblyName)
		{
			MemberTypes = memberTypes;
			TypeName = typeName;
			AssemblyName = assemblyName;
		}
	}
	[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, Inherited = false)]
	internal sealed class DynamicallyAccessedMembersAttribute : Attribute
	{
		public DynamicallyAccessedMemberTypes MemberTypes { get; }

		public DynamicallyAccessedMembersAttribute(DynamicallyAccessedMemberTypes memberTypes)
		{
			MemberTypes = memberTypes;
		}
	}
	[Flags]
	internal enum DynamicallyAccessedMemberTypes
	{
		None = 0,
		PublicParameterlessConstructor = 1,
		PublicConstructors = 3,
		NonPublicConstructors = 4,
		PublicMethods = 8,
		NonPublicMethods = 0x10,
		PublicFields = 0x20,
		NonPublicFields = 0x40,
		PublicNestedTypes = 0x80,
		NonPublicNestedTypes = 0x100,
		PublicProperties = 0x200,
		NonPublicProperties = 0x400,
		PublicEvents = 0x800,
		NonPublicEvents = 0x1000,
		All = -1
	}
	[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.Buffers
{
	internal sealed class ArrayBufferWriter<T> : IBufferWriter<T>
	{
		private T[] _buffer;

		private int _index;

		private const int DefaultInitialBufferSize = 256;

		public ReadOnlyMemory<T> WrittenMemory => _buffer.AsMemory(0, _index);

		public ReadOnlySpan<T> WrittenSpan => _buffer.AsSpan(0, _index);

		public int WrittenCount => _index;

		public int Capacity => _buffer.Length;

		public int FreeCapacity => _buffer.Length - _index;

		public ArrayBufferWriter()
		{
			_buffer = Array.Empty<T>();
			_index = 0;
		}

		public ArrayBufferWriter(int initialCapacity)
		{
			if (initialCapacity <= 0)
			{
				throw new ArgumentException(null, "initialCapacity");
			}
			_buffer = new T[initialCapacity];
			_index = 0;
		}

		public void Clear()
		{
			_buffer.AsSpan(0, _index).Clear();
			_index = 0;
		}

		public void Advance(int count)
		{
			if (count < 0)
			{
				throw new ArgumentException(null, "count");
			}
			if (_index > _buffer.Length - count)
			{
				ThrowInvalidOperationException_AdvancedTooFar(_buffer.Length);
			}
			_index += count;
		}

		public Memory<T> GetMemory(int sizeHint = 0)
		{
			CheckAndResizeBuffer(sizeHint);
			return _buffer.AsMemory(_index);
		}

		public Span<T> GetSpan(int sizeHint = 0)
		{
			CheckAndResizeBuffer(sizeHint);
			return _buffer.AsSpan(_index);
		}

		private void CheckAndResizeBuffer(int sizeHint)
		{
			if (sizeHint < 0)
			{
				throw new ArgumentException("sizeHint");
			}
			if (sizeHint == 0)
			{
				sizeHint = 1;
			}
			if (sizeHint <= FreeCapacity)
			{
				return;
			}
			int num = _buffer.Length;
			int num2 = Math.Max(sizeHint, num);
			if (num == 0)
			{
				num2 = Math.Max(num2, 256);
			}
			int num3 = num + num2;
			if ((uint)num3 > 2147483647u)
			{
				num3 = num + sizeHint;
				if ((uint)num3 > 2147483647u)
				{
					ThrowOutOfMemoryException((uint)num3);
				}
			}
			Array.Resize(ref _buffer, num3);
		}

		private static void ThrowInvalidOperationException_AdvancedTooFar(int capacity)
		{
			throw new InvalidOperationException(System.SR.Format(System.SR.BufferWriterAdvancedTooFar, capacity));
		}

		private static void ThrowOutOfMemoryException(uint capacity)
		{
			throw new OutOfMemoryException(System.SR.Format(System.SR.BufferMaximumSizeExceeded, capacity));
		}
	}
}
namespace System.Buffers.Text
{
	internal enum SequenceValidity
	{
		Empty,
		WellFormed,
		Incomplete,
		Invalid
	}
}
namespace System.Text.Json
{
	internal sealed class PooledByteBufferWriter : IBufferWriter<byte>, IDisposable
	{
		private byte[] _rentedBuffer;

		private int _index;

		private const int MinimumBufferSize = 256;

		public ReadOnlyMemory<byte> WrittenMemory => _rentedBuffer.AsMemory(0, _index);

		public int WrittenCount => _index;

		public int Capacity => _rentedBuffer.Length;

		public int FreeCapacity => _rentedBuffer.Length - _index;

		public PooledByteBufferWriter(int initialCapacity)
		{
			_rentedBuffer = ArrayPool<byte>.Shared.Rent(initialCapacity);
			_index = 0;
		}

		public void Clear()
		{
			ClearHelper();
		}

		private void ClearHelper()
		{
			_rentedBuffer.AsSpan(0, _index).Clear();
			_index = 0;
		}

		public void Dispose()
		{
			if (_rentedBuffer != null)
			{
				ClearHelper();
				ArrayPool<byte>.Shared.Return(_rentedBuffer);
				_rentedBuffer = null;
			}
		}

		public void Advance(int count)
		{
			_index += count;
		}

		public Memory<byte> GetMemory(int sizeHint = 0)
		{
			CheckAndResizeBuffer(sizeHint);
			return _rentedBuffer.AsMemory(_index);
		}

		public Span<byte> GetSpan(int sizeHint = 0)
		{
			CheckAndResizeBuffer(sizeHint);
			return _rentedBuffer.AsSpan(_index);
		}

		internal Task WriteToStreamAsync(Stream destination, CancellationToken cancellationToken)
		{
			return destination.WriteAsync(_rentedBuffer, 0, _index, cancellationToken);
		}

		private void CheckAndResizeBuffer(int sizeHint)
		{
			if (sizeHint == 0)
			{
				sizeHint = 256;
			}
			int num = _rentedBuffer.Length - _index;
			if (sizeHint <= num)
			{
				return;
			}
			int num2 = _rentedBuffer.Length;
			int num3 = Math.Max(sizeHint, num2);
			int num4 = num2 + num3;
			if ((uint)num4 > 2147483647u)
			{
				num4 = num2 + sizeHint;
				if ((uint)num4 > 2147483647u)
				{
					ThrowHelper.ThrowOutOfMemoryException_BufferMaximumSizeExceeded((uint)num4);
				}
			}
			byte[] rentedBuffer = _rentedBuffer;
			_rentedBuffer = ArrayPool<byte>.Shared.Rent(num4);
			Span<byte> span = rentedBuffer.AsSpan(0, _index);
			span.CopyTo(_rentedBuffer);
			span.Clear();
			ArrayPool<byte>.Shared.Return(rentedBuffer);
		}
	}
	internal static class ThrowHelper
	{
		public const string ExceptionSourceValueToRethrowAsJsonException = "System.Text.Json.Rethrowable";

		[MethodImpl(MethodImplOptions.NoInlining)]
		[DoesNotReturn]
		public static void ThrowOutOfMemoryException_BufferMaximumSizeExceeded(uint capacity)
		{
			throw new OutOfMemoryException(System.SR.Format(System.SR.BufferMaximumSizeExceeded, capacity));
		}

		public static ArgumentOutOfRangeException GetArgumentOutOfRangeException_MaxDepthMustBePositive(string parameterName)
		{
			return GetArgumentOutOfRangeException(parameterName, System.SR.MaxDepthMustBePositive);
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private static ArgumentOutOfRangeException GetArgumentOutOfRangeException(string parameterName, string message)
		{
			return new ArgumentOutOfRangeException(parameterName, message);
		}

		public static ArgumentOutOfRangeException GetArgumentOutOfRangeException_CommentEnumMustBeInRange(string parameterName)
		{
			return GetArgumentOutOfRangeException(parameterName, System.SR.CommentHandlingMustBeValid);
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private static ArgumentException GetArgumentException(string message)
		{
			return new ArgumentException(message);
		}

		[DoesNotReturn]
		public static void ThrowArgumentException(string message)
		{
			throw GetArgumentException(message);
		}

		public static InvalidOperationException GetInvalidOperationException_CallFlushFirst(int _buffered)
		{
			return GetInvalidOperationException(System.SR.Format(System.SR.CallFlushToAvoidDataLoss, _buffered));
		}

		[DoesNotReturn]
		public static void ThrowArgumentException_PropertyNameTooLarge(int tokenLength)
		{
			throw GetArgumentException(System.SR.Format(System.SR.PropertyNameTooLarge, tokenLength));
		}

		[DoesNotReturn]
		public static void ThrowArgumentException_ValueTooLarge(int tokenLength)
		{
			throw GetArgumentException(System.SR.Format(System.SR.ValueTooLarge, tokenLength));
		}

		[DoesNotReturn]
		public static void ThrowArgumentException_ValueNotSupported()
		{
			throw GetArgumentException(System.SR.SpecialNumberValuesNotSupported);
		}

		[DoesNotReturn]
		public static void ThrowInvalidOperationException_NeedLargerSpan()
		{
			throw GetInvalidOperationException(System.SR.FailedToGetLargerSpan);
		}

		[DoesNotReturn]
		public static void ThrowArgumentException(ReadOnlySpan<byte> propertyName, ReadOnlySpan<byte> value)
		{
			if (propertyName.Length > 166666666)
			{
				ThrowArgumentException(System.SR.Format(System.SR.PropertyNameTooLarge, propertyName.Length));
			}
			else
			{
				ThrowArgumentException(System.SR.Format(System.SR.ValueTooLarge, value.Length));
			}
		}

		[DoesNotReturn]
		public static void ThrowArgumentException(ReadOnlySpan<byte> propertyName, ReadOnlySpan<char> value)
		{
			if (propertyName.Length > 166666666)
			{
				ThrowArgumentException(System.SR.Format(System.SR.PropertyNameTooLarge, propertyName.Length));
			}
			else
			{
				ThrowArgumentException(System.SR.Format(System.SR.ValueTooLarge, value.Length));
			}
		}

		[DoesNotReturn]
		public static void ThrowArgumentException(ReadOnlySpan<char> propertyName, ReadOnlySpan<byte> value)
		{
			if (propertyName.Length > 166666666)
			{
				ThrowArgumentException(System.SR.Format(System.SR.PropertyNameTooLarge, propertyName.Length));
			}
			else
			{
				ThrowArgumentException(System.SR.Format(System.SR.ValueTooLarge, value.Length));
			}
		}

		[DoesNotReturn]
		public static void ThrowArgumentException(ReadOnlySpan<char> propertyName, ReadOnlySpan<char> value)
		{
			if (propertyName.Length > 166666666)
			{
				ThrowArgumentException(System.SR.Format(System.SR.PropertyNameTooLarge, propertyName.Length));
			}
			else
			{
				ThrowArgumentException(System.SR.Format(System.SR.ValueTooLarge, value.Length));
			}
		}

		[DoesNotReturn]
		public static void ThrowInvalidOperationOrArgumentException(ReadOnlySpan<byte> propertyName, int currentDepth)
		{
			currentDepth &= 0x7FFFFFFF;
			if (currentDepth >= 1000)
			{
				ThrowInvalidOperationException(System.SR.Format(System.SR.DepthTooLarge, currentDepth, 1000));
			}
			else
			{
				ThrowArgumentException(System.SR.Format(System.SR.PropertyNameTooLarge, propertyName.Length));
			}
		}

		[DoesNotReturn]
		public static void ThrowInvalidOperationException(int currentDepth)
		{
			currentDepth &= 0x7FFFFFFF;
			ThrowInvalidOperationException(System.SR.Format(System.SR.DepthTooLarge, currentDepth, 1000));
		}

		[DoesNotReturn]
		public static void ThrowInvalidOperationException(string message)
		{
			throw GetInvalidOperationException(message);
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private static InvalidOperationException GetInvalidOperationException(string message)
		{
			InvalidOperationException ex = new InvalidOperationException(message);
			ex.Source = "System.Text.Json.Rethrowable";
			return ex;
		}

		[DoesNotReturn]
		public static void ThrowInvalidOperationException_DepthNonZeroOrEmptyJson(int currentDepth)
		{
			throw GetInvalidOperationException(currentDepth);
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private static InvalidOperationException GetInvalidOperationException(int currentDepth)
		{
			currentDepth &= 0x7FFFFFFF;
			if (currentDepth != 0)
			{
				return GetInvalidOperationException(System.SR.Format(System.SR.ZeroDepthAtEnd, currentDepth));
			}
			return GetInvalidOperationException(System.SR.EmptyJsonIsInvalid);
		}

		[DoesNotReturn]
		public static void ThrowInvalidOperationOrArgumentException(ReadOnlySpan<char> propertyName, int currentDepth)
		{
			currentDepth &= 0x7FFFFFFF;
			if (currentDepth >= 1000)
			{
				ThrowInvalidOperationException(System.SR.Format(System.SR.DepthTooLarge, currentDepth, 1000));
			}
			else
			{
				ThrowArgumentException(System.SR.Format(System.SR.PropertyNameTooLarge, propertyName.Length));
			}
		}

		public static InvalidOperationException GetInvalidOperationException_ExpectedNumber(JsonTokenType tokenType)
		{
			return GetInvalidOperationException("number", tokenType);
		}

		public static InvalidOperationException GetInvalidOperationException_ExpectedBoolean(JsonTokenType tokenType)
		{
			return GetInvalidOperationException("boolean", tokenType);
		}

		public static InvalidOperationException GetInvalidOperationException_ExpectedString(JsonTokenType tokenType)
		{
			return GetInvalidOperationException("string", tokenType);
		}

		public static InvalidOperationException GetInvalidOperationException_ExpectedStringComparison(JsonTokenType tokenType)
		{
			return GetInvalidOperationException(tokenType);
		}

		public static InvalidOperationException GetInvalidOperationException_ExpectedComment(JsonTokenType tokenType)
		{
			return GetInvalidOperationException("comment", tokenType);
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public static InvalidOperationException GetInvalidOperationException_CannotSkipOnPartial()
		{
			return GetInvalidOperationException(System.SR.CannotSkip);
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private static InvalidOperationException GetInvalidOperationException(string message, JsonTokenType tokenType)
		{
			return GetInvalidOperationException(System.SR.Format(System.SR.InvalidCast, tokenType, message));
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private static InvalidOperationException GetInvalidOperationException(JsonTokenType tokenType)
		{
			return GetInvalidOperationException(System.SR.Format(System.SR.InvalidComparison, tokenType));
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		internal static InvalidOperationException GetJsonElementWrongTypeException(JsonTokenType expectedType, JsonTokenType actualType)
		{
			return GetJsonElementWrongTypeException(expectedType.ToValueKind(), actualType.ToValueKind());
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		internal static InvalidOperationException GetJsonElementWrongTypeException(string expectedTypeName, JsonTokenType actualType)
		{
			return GetJsonElementWrongTypeException(expectedTypeName, actualType.ToValueKind());
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		internal static InvalidOperationException GetJsonElementWrongTypeException(JsonValueKind expectedType, JsonValueKind actualType)
		{
			return GetInvalidOperationException(System.SR.Format(System.SR.JsonElementHasWrongType, expectedType, actualType));
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		internal static InvalidOperationException GetJsonElementWrongTypeException(string expectedTypeName, JsonValueKind actualType)
		{
			return GetInvalidOperationException(System.SR.Format(System.SR.JsonElementHasWrongType, expectedTypeName, actualType));
		}

		[DoesNotReturn]
		public static void ThrowJsonReaderException(ref Utf8JsonReader json, ExceptionResource resource, byte nextByte = 0, ReadOnlySpan<byte> bytes = default(ReadOnlySpan<byte>))
		{
			throw GetJsonReaderException(ref json, resource, nextByte, bytes);
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public static JsonException GetJsonReaderException(ref Utf8JsonReader json, ExceptionResource resource, byte nextByte, ReadOnlySpan<byte> bytes)
		{
			string resourceString = GetResourceString(ref json, resource, nextByte, JsonHelpers.Utf8GetString(bytes));
			long lineNumber = json.CurrentState._lineNumber;
			long bytePositionInLine = json.CurrentState._bytePositionInLine;
			resourceString += $" LineNumber: {lineNumber} | BytePositionInLine: {bytePositionInLine}.";
			return new JsonReaderException(resourceString, lineNumber, bytePositionInLine);
		}

		private static bool IsPrintable(byte value)
		{
			if (value >= 32)
			{
				return value < 127;
			}
			return false;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		internal static string GetPrintableString(byte value)
		{
			if (!IsPrintable(value))
			{
				return $"0x{value:X2}";
			}
			char c = (char)value;
			return c.ToString();
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private static string GetResourceString(ref Utf8JsonReader json, ExceptionResource resource, byte nextByte, string characters)
		{
			string printableString = GetPrintableString(nextByte);
			string result = "";
			switch (resource)
			{
			case ExceptionResource.ArrayDepthTooLarge:
				result = System.SR.Format(System.SR.ArrayDepthTooLarge, json.CurrentState.Options.MaxDepth);
				break;
			case ExceptionResource.MismatchedObjectArray:
				result = System.SR.Format(System.SR.MismatchedObjectArray, printableString);
				break;
			case ExceptionResource.TrailingCommaNotAllowedBeforeArrayEnd:
				result = System.SR.TrailingCommaNotAllowedBeforeArrayEnd;
				break;
			case ExceptionResource.TrailingCommaNotAllowedBeforeObjectEnd:
				result = System.SR.TrailingCommaNotAllowedBeforeObjectEnd;
				break;
			case ExceptionResource.EndOfStringNotFound:
				result = System.SR.EndOfStringNotFound;
				break;
			case ExceptionResource.RequiredDigitNotFoundAfterSign:
				result = System.SR.Format(System.SR.RequiredDigitNotFoundAfterSign, printableString);
				break;
			case ExceptionResource.RequiredDigitNotFoundAfterDecimal:
				result = System.SR.Format(System.SR.RequiredDigitNotFoundAfterDecimal, printableString);
				break;
			case ExceptionResource.RequiredDigitNotFoundEndOfData:
				result = System.SR.RequiredDigitNotFoundEndOfData;
				break;
			case ExceptionResource.ExpectedEndAfterSingleJson:
				result = System.SR.Format(System.SR.ExpectedEndAfterSingleJson, printableString);
				break;
			case ExceptionResource.ExpectedEndOfDigitNotFound:
				result = System.SR.Format(System.SR.ExpectedEndOfDigitNotFound, printableString);
				break;
			case ExceptionResource.ExpectedNextDigitEValueNotFound:
				result = System.SR.Format(System.SR.ExpectedNextDigitEValueNotFound, printableString);
				break;
			case ExceptionResource.ExpectedSeparatorAfterPropertyNameNotFound:
				result = System.SR.Format(System.SR.ExpectedSeparatorAfterPropertyNameNotFound, printableString);
				break;
			case ExceptionResource.ExpectedStartOfPropertyNotFound:
				result = System.SR.Format(System.SR.ExpectedStartOfPropertyNotFound, printableString);
				break;
			case ExceptionResource.ExpectedStartOfPropertyOrValueNotFound:
				result = System.SR.ExpectedStartOfPropertyOrValueNotFound;
				break;
			case ExceptionResource.ExpectedStartOfPropertyOrValueAfterComment:
				result = System.SR.Format(System.SR.ExpectedStartOfPropertyOrValueAfterComment, printableString);
				break;
			case ExceptionResource.ExpectedStartOfValueNotFound:
				result = System.SR.Format(System.SR.ExpectedStartOfValueNotFound, printableString);
				break;
			case ExceptionResource.ExpectedValueAfterPropertyNameNotFound:
				result = System.SR.ExpectedValueAfterPropertyNameNotFound;
				break;
			case ExceptionResource.FoundInvalidCharacter:
				result = System.SR.Format(System.SR.FoundInvalidCharacter, printableString);
				break;
			case ExceptionResource.InvalidEndOfJsonNonPrimitive:
				result = System.SR.Format(System.SR.InvalidEndOfJsonNonPrimitive, json.TokenType);
				break;
			case ExceptionResource.ObjectDepthTooLarge:
				result = System.SR.Format(System.SR.ObjectDepthTooLarge, json.CurrentState.Options.MaxDepth);
				break;
			case ExceptionResource.ExpectedFalse:
				result = System.SR.Format(System.SR.ExpectedFalse, characters);
				break;
			case ExceptionResource.ExpectedNull:
				result = System.SR.Format(System.SR.ExpectedNull, characters);
				break;
			case ExceptionResource.ExpectedTrue:
				result = System.SR.Format(System.SR.ExpectedTrue, characters);
				break;
			case ExceptionResource.InvalidCharacterWithinString:
				result = System.SR.Format(System.SR.InvalidCharacterWithinString, printableString);
				break;
			case ExceptionResource.InvalidCharacterAfterEscapeWithinString:
				result = System.SR.Format(System.SR.InvalidCharacterAfterEscapeWithinString, printableString);
				break;
			case ExceptionResource.InvalidHexCharacterWithinString:
				result = System.SR.Format(System.SR.InvalidHexCharacterWithinString, printableString);
				break;
			case ExceptionResource.EndOfCommentNotFound:
				result = System.SR.EndOfCommentNotFound;
				break;
			case ExceptionResource.ZeroDepthAtEnd:
				result = System.SR.Format(System.SR.ZeroDepthAtEnd);
				break;
			case ExceptionResource.ExpectedJsonTokens:
				result = System.SR.ExpectedJsonTokens;
				break;
			case ExceptionResource.NotEnoughData:
				result = System.SR.NotEnoughData;
				break;
			case ExceptionResource.ExpectedOneCompleteToken:
				result = System.SR.ExpectedOneCompleteToken;
				break;
			case ExceptionResource.InvalidCharacterAtStartOfComment:
				result = System.SR.Format(System.SR.InvalidCharacterAtStartOfComment, printableString);
				break;
			case ExceptionResource.UnexpectedEndOfDataWhileReadingComment:
				result = System.SR.Format(System.SR.UnexpectedEndOfDataWhileReadingComment);
				break;
			case ExceptionResource.UnexpectedEndOfLineSeparator:
				result = System.SR.Format(System.SR.UnexpectedEndOfLineSeparator);
				break;
			case ExceptionResource.InvalidLeadingZeroInNumber:
				result = System.SR.Format(System.SR.InvalidLeadingZeroInNumber, printableString);
				break;
			}
			return result;
		}

		[DoesNotReturn]
		public static void ThrowInvalidOperationException(ExceptionResource resource, int currentDepth, byte token, JsonTokenType tokenType)
		{
			throw GetInvalidOperationException(resource, currentDepth, token, tokenType);
		}

		[DoesNotReturn]
		public static void ThrowArgumentException_InvalidCommentValue()
		{
			throw new ArgumentException(System.SR.CannotWriteCommentWithEmbeddedDelimiter);
		}

		[DoesNotReturn]
		public static void ThrowArgumentException_InvalidUTF8(ReadOnlySpan<byte> value)
		{
			StringBuilder stringBuilder = new StringBuilder();
			int num = Math.Min(value.Length, 10);
			for (int i = 0; i < num; i++)
			{
				byte b = value[i];
				if (IsPrintable(b))
				{
					stringBuilder.Append((char)b);
				}
				else
				{
					stringBuilder.Append($"0x{b:X2}");
				}
			}
			if (num < value.Length)
			{
				stringBuilder.Append("...");
			}
			throw new ArgumentException(System.SR.Format(System.SR.CannotEncodeInvalidUTF8, stringBuilder));
		}

		[DoesNotReturn]
		public static void ThrowArgumentException_InvalidUTF16(int charAsInt)
		{
			throw new ArgumentException(System.SR.Format(System.SR.CannotEncodeInvalidUTF16, $"0x{charAsInt:X2}"));
		}

		[DoesNotReturn]
		public static void ThrowInvalidOperationException_ReadInvalidUTF16(int charAsInt)
		{
			throw GetInvalidOperationException(System.SR.Format(System.SR.CannotReadInvalidUTF16, $"0x{charAsInt:X2}"));
		}

		[DoesNotReturn]
		public static void ThrowInvalidOperationException_ReadInvalidUTF16()
		{
			throw GetInvalidOperationException(System.SR.CannotReadIncompleteUTF16);
		}

		public static InvalidOperationException GetInvalidOperationException_ReadInvalidUTF8(DecoderFallbackException innerException)
		{
			return GetInvalidOperationException(System.SR.CannotTranscodeInvalidUtf8, innerException);
		}

		public static ArgumentException GetArgumentException_ReadInvalidUTF16(EncoderFallbackException innerException)
		{
			return new ArgumentException(System.SR.CannotTranscodeInvalidUtf16, innerException);
		}

		public static InvalidOperationException GetInvalidOperationException(string message, Exception innerException)
		{
			InvalidOperationException ex = new InvalidOperationException(message, innerException);
			ex.Source = "System.Text.Json.Rethrowable";
			return ex;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public static InvalidOperationException GetInvalidOperationException(ExceptionResource resource, int currentDepth, byte token, JsonTokenType tokenType)
		{
			string resourceString = GetResourceString(resource, currentDepth, token, tokenType);
			InvalidOperationException invalidOperationException = GetInvalidOperationException(resourceString);
			invalidOperationException.Source = "System.Text.Json.Rethrowable";
			return invalidOperationException;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private static string GetResourceString(ExceptionResource resource, int currentDepth, byte token, JsonTokenType tokenType)
		{
			string result = "";
			switch (resource)
			{
			case ExceptionResource.MismatchedObjectArray:
				result = ((tokenType == JsonTokenType.PropertyName) ? System.SR.Format(System.SR.CannotWriteEndAfterProperty, (char)token) : System.SR.Format(System.SR.MismatchedObjectArray, (char)token));
				break;
			case ExceptionResource.DepthTooLarge:
				result = System.SR.Format(System.SR.DepthTooLarge, currentDepth & 0x7FFFFFFF, 1000);
				break;
			case ExceptionResource.CannotStartObjectArrayWithoutProperty:
				result = System.SR.Format(System.SR.CannotStartObjectArrayWithoutProperty, tokenType);
				break;
			case ExceptionResource.CannotStartObjectArrayAfterPrimitiveOrClose:
				result = System.SR.Format(System.SR.CannotStartObjectArrayAfterPrimitiveOrClose, tokenType);
				break;
			case ExceptionResource.CannotWriteValueWithinObject:
				result = System.SR.Format(System.SR.CannotWriteValueWithinObject, tokenType);
				break;
			case ExceptionResource.CannotWritePropertyWithinArray:
				result = ((tokenType == JsonTokenType.PropertyName) ? System.SR.Format(System.SR.CannotWritePropertyAfterProperty) : System.SR.Format(System.SR.CannotWritePropertyWithinArray, tokenType));
				break;
			case ExceptionResource.CannotWriteValueAfterPrimitiveOrClose:
				result = System.SR.Format(System.SR.CannotWriteValueAfterPrimitiveOrClose, tokenType);
				break;
			}
			return result;
		}

		public static FormatException GetFormatException()
		{
			FormatException ex = new FormatException();
			ex.Source = "System.Text.Json.Rethrowable";
			return ex;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public static FormatException GetFormatException(NumericType numericType)
		{
			string message = "";
			switch (numericType)
			{
			case NumericType.Byte:
				message = System.SR.FormatByte;
				break;
			case NumericType.SByte:
				message = System.SR.FormatSByte;
				break;
			case NumericType.Int16:
				message = System.SR.FormatInt16;
				break;
			case NumericType.Int32:
				message = System.SR.FormatInt32;
				break;
			case NumericType.Int64:
				message = System.SR.FormatInt64;
				break;
			case NumericType.UInt16:
				message = System.SR.FormatUInt16;
				break;
			case NumericType.UInt32:
				message = System.SR.FormatUInt32;
				break;
			case NumericType.UInt64:
				message = System.SR.FormatUInt64;
				break;
			case NumericType.Single:
				message = System.SR.FormatSingle;
				break;
			case NumericType.Double:
				message = System.SR.FormatDouble;
				break;
			case NumericType.Decimal:
				message = System.SR.FormatDecimal;
				break;
			}
			FormatException ex = new FormatException(message);
			ex.Source = "System.Text.Json.Rethrowable";
			return ex;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public static FormatException GetFormatException(DataType dateType)
		{
			string message = "";
			switch (dateType)
			{
			case DataType.Boolean:
				message = System.SR.FormatBoolean;
				break;
			case DataType.DateTime:
				message = System.SR.FormatDateTime;
				break;
			case DataType.DateTimeOffset:
				message = System.SR.FormatDateTimeOffset;
				break;
			case DataType.Base64String:
				message = System.SR.CannotDecodeInvalidBase64;
				break;
			case DataType.Guid:
				message = System.SR.FormatGuid;
				break;
			}
			FormatException ex = new FormatException(message);
			ex.Source = "System.Text.Json.Rethrowable";
			return ex;
		}

		public static InvalidOperationException GetInvalidOperationException_ExpectedChar(JsonTokenType tokenType)
		{
			return GetInvalidOperationException("char", tokenType);
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[DoesNotReturn]
		public static void ThrowArgumentException_DeserializeWrongType(Type type, object value)
		{
			throw new ArgumentException(System.SR.Format(System.SR.DeserializeWrongType, type, value.GetType()));
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[DoesNotReturn]
		public static void ThrowNotSupportedException_SerializationNotSupported(Type propertyType)
		{
			throw new NotSupportedException(System.SR.Format(System.SR.SerializationNotSupportedType, propertyType));
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[DoesNotReturn]
		public static void ThrowNotSupportedException_ConstructorMaxOf64Parameters(ConstructorInfo constructorInfo, Type type)
		{
			throw new NotSupportedException(System.SR.Format(System.SR.ConstructorMaxOf64Parameters, constructorInfo, type));
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[DoesNotReturn]
		public static void ThrowNotSupportedException_DictionaryKeyTypeNotSupported(Type keyType)
		{
			throw new NotSupportedException(System.SR.Format(System.SR.DictionaryKeyTypeNotSupported, keyType));
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[DoesNotReturn]
		public static void ThrowJsonException_DeserializeUnableToConvertValue(Type propertyType)
		{
			JsonException ex = new JsonException(System.SR.Format(System.SR.DeserializeUnableToConvertValue, propertyType));
			ex.AppendPathInformation = true;
			throw ex;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[DoesNotReturn]
		public static void ThrowInvalidCastException_DeserializeUnableToAssignValue(Type typeOfValue, Type declaredType)
		{
			throw new InvalidCastException(System.SR.Format(System.SR.DeserializeUnableToAssignValue, typeOfValue, declaredType));
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[DoesNotReturn]
		public static void ThrowInvalidOperationException_DeserializeUnableToAssignNull(Type declaredType)
		{
			throw new InvalidOperationException(System.SR.Format(System.SR.DeserializeUnableToAssignNull, declaredType));
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[DoesNotReturn]
		public static void ThrowJsonException_SerializationConverterRead(JsonConverter converter)
		{
			JsonException ex = new JsonException(System.SR.Format(System.SR.SerializationConverterRead, converter));
			ex.AppendPathInformation = true;
			throw ex;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[DoesNotReturn]
		public static void ThrowJsonException_SerializationConverterWrite(JsonConverter converter)
		{
			JsonException ex = new JsonException(System.SR.Format(System.SR.SerializationConverterWrite, converter));
			ex.AppendPathInformation = true;
			throw ex;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[DoesNotReturn]
		public static void ThrowJsonException_SerializerCycleDetected(int maxDepth)
		{
			throw new JsonException(System.SR.Format(System.SR.SerializerCycleDetected, maxDepth));
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[DoesNotReturn]
		public static void ThrowJsonException(string message = null)
		{
			JsonException ex;
			if (string.IsNullOrEmpty(message))
			{
				ex = new JsonException();
			}
			else
			{
				ex = new JsonException(message);
				ex.AppendPathInformation = true;
			}
			throw ex;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[DoesNotReturn]
		public static void ThrowInvalidOperationException_CannotSerializeInvalidType(Type type, Type parentClassType, MemberInfo memberInfo)
		{
			if (parentClassType == null)
			{
				throw new InvalidOperationException(System.SR.Format(System.SR.CannotSerializeInvalidType, type));
			}
			throw new InvalidOperationException(System.SR.Format(System.SR.CannotSerializeInvalidMember, type, memberInfo.Name, parentClassType));
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[DoesNotReturn]
		public static void ThrowInvalidOperationException_SerializationConverterNotCompatible(Type converterType, Type type)
		{
			throw new InvalidOperationException(System.SR.Format(System.SR.SerializationConverterNotCompatible, converterType, type));
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[DoesNotReturn]
		public static void ThrowInvalidOperationException_SerializationConverterOnAttributeInvalid(Type classType, MemberInfo memberInfo)
		{
			string text = classType.ToString();
			if (memberInfo != null)
			{
				text = text + "." + memberInfo.Name;
			}
			throw new InvalidOperationException(System.SR.Format(System.SR.SerializationConverterOnAttributeInvalid, text));
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[DoesNotReturn]
		public static void ThrowInvalidOperationException_SerializationConverterOnAttributeNotCompatible(Type classTypeAttributeIsOn, MemberInfo memberInfo, Type typeToConvert)
		{
			string text = classTypeAttributeIsOn.ToString();
			if (memberInfo != null)
			{
				text = text + "." + memberInfo.Name;
			}
			throw new InvalidOperationException(System.SR.Format(System.SR.SerializationConverterOnAttributeNotCompatible, text, typeToConvert));
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[DoesNotReturn]
		public static void ThrowInvalidOperationException_SerializerOptionsImmutable()
		{
			throw new InvalidOperationException(System.SR.SerializerOptionsImmutable);
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[DoesNotReturn]
		public static void ThrowInvalidOperationException_SerializerPropertyNameConflict(Type type, JsonPropertyInfo jsonPropertyInfo)
		{
			throw new InvalidOperationException(System.SR.Format(System.SR.SerializerPropertyNameConflict, type, jsonPropertyInfo.MemberInfo?.Name));
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[DoesNotReturn]
		public static void ThrowInvalidOperationException_SerializerPropertyNameNull(Type parentType, JsonPropertyInfo jsonPropertyInfo)
		{
			throw new InvalidOperationException(System.SR.Format(System.SR.SerializerPropertyNameNull, parentType, jsonPropertyInfo.MemberInfo?.Name));
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[DoesNotReturn]
		public static void ThrowInvalidOperationException_NamingPolicyReturnNull(JsonNamingPolicy namingPolicy)
		{
			throw new InvalidOperationException(System.SR.Format(System.SR.NamingPolicyReturnNull, namingPolicy));
		}

		[DoesNotReturn]
		public static void ThrowInvalidOperationException_SerializerConverterFactoryReturnsNull(Type converterType)
		{
			throw new InvalidOperationException(System.SR.Format(System.SR.SerializerConverterFactoryReturnsNull, converterType));
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[DoesNotReturn]
		public static void ThrowInvalidOperationException_MultiplePropertiesBindToConstructorParameters(Type parentType, string parameterName, string firstMatchName, string secondMatchName, ConstructorInfo constructorInfo)
		{
			throw new InvalidOperationException(System.SR.Format(System.SR.MultipleMembersBindWithConstructorParameter, firstMatchName, secondMatchName, parentType, parameterName, constructorInfo));
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[DoesNotReturn]
		public static void ThrowInvalidOperationException_ConstructorParameterIncompleteBinding(ConstructorInfo constructorInfo, Type parentType)
		{
			throw new InvalidOperationException(System.SR.Format(System.SR.ConstructorParamIncompleteBinding, constructorInfo, parentType));
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[DoesNotReturn]
		public static void ThrowInvalidOperationException_ExtensionDataCannotBindToCtorParam(MemberInfo memberInfo, Type classType, ConstructorInfo constructorInfo)
		{
			throw new InvalidOperationException(System.SR.Format(System.SR.ExtensionDataCannotBindToCtorParam, memberInfo, classType, constructorInfo));
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[DoesNotReturn]
		public static void ThrowInvalidOperationException_JsonIncludeOnNonPublicInvalid(MemberInfo memberInfo, Type parentType)
		{
			throw new InvalidOperationException(System.SR.Format(System.SR.JsonIncludeOnNonPublicInvalid, memberInfo.Name, parentType));
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[DoesNotReturn]
		public static void ThrowInvalidOperationException_IgnoreConditionOnValueTypeInvalid(JsonPropertyInfo jsonPropertyInfo)
		{
			MemberInfo memberInfo = jsonPropertyInfo.MemberInfo;
			throw new InvalidOperationException(System.SR.Format(System.SR.IgnoreConditionOnValueTypeInvalid, memberInfo.Name, memberInfo.DeclaringType));
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[DoesNotReturn]
		public static void ThrowInvalidOperationException_NumberHandlingOnPropertyInvalid(JsonPropertyInfo jsonPropertyInfo)
		{
			MemberInfo memberInfo = jsonPropertyInfo.MemberInfo;
			if (!jsonPropertyInfo.ConverterBase.IsInternalConverter)
			{
				throw new InvalidOperationException(System.SR.Format(System.SR.NumberHandlingConverterMustBeBuiltIn, jsonPropertyInfo.ConverterBase.GetType(), jsonPropertyInfo.IsForClassInfo ? jsonPropertyInfo.DeclaredPropertyType : memberInfo.DeclaringType));
			}
			throw new InvalidOperationException(System.SR.Format(System.SR.NumberHandlingOnPropertyTypeMustBeNumberOrCollection, memberInfo.Name, memberInfo.DeclaringType));
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[DoesNotReturn]
		public static void ThrowInvalidOperationException_ConverterCanConvertNullableRedundant(Type runtimePropertyType, JsonConverter jsonConverter)
		{
			throw new InvalidOperationException(System.SR.Format(System.SR.ConverterCanConvertNullableRedundant, jsonConverter.GetType(), jsonConverter.TypeToConvert, runtimePropertyType));
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[DoesNotReturn]
		public static void ThrowNotSupportedException_ObjectWithParameterizedCtorRefMetadataNotHonored(ReadOnlySpan<byte> propertyName, ref Utf8JsonReader reader, ref ReadStack state)
		{
			state.Current.JsonPropertyName = propertyName.ToArray();
			NotSupportedException ex = new NotSupportedException(System.SR.Format(System.SR.ObjectWithParameterizedCtorRefMetadataNotHonored, state.Current.JsonClassInfo.Type));
			ThrowNotSupportedException(in state, in reader, ex);
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[DoesNotReturn]
		public static void ReThrowWithPath(in ReadStack state, JsonReaderException ex)
		{
			string text = state.JsonPath();
			string message = ex.Message;
			int num = message.LastIndexOf(" LineNumber: ", StringComparison.InvariantCulture);
			message = ((num < 0) ? (message + " Path: " + text + ".") : (message.Substring(0, num) + " Path: " + text + " |" + message.Substring(num)));
			throw new JsonException(message, text, ex.LineNumber, ex.BytePositionInLine, ex);
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[DoesNotReturn]
		public static void ReThrowWithPath(in ReadStack state, in Utf8JsonReader reader, Exception ex)
		{
			JsonException ex2 = new JsonException(null, ex);
			AddJsonExceptionInformation(in state, in reader, ex2);
			throw ex2;
		}

		public static void AddJsonExceptionInformation(in ReadStack state, in Utf8JsonReader reader, JsonException ex)
		{
			long lineNumber = reader.CurrentState._lineNumber;
			ex.LineNumber = lineNumber;
			long bytePositionInLine = reader.CurrentState._bytePositionInLine;
			ex.BytePositionInLine = bytePositionInLine;
			string arg = (ex.Path = state.JsonPath());
			string text2 = ex._message;
			if (string.IsNullOrEmpty(text2))
			{
				Type type = state.Current.JsonPropertyInfo?.RuntimePropertyType;
				if (type == null)
				{
					type = state.Current.JsonClassInfo?.Type;
				}
				text2 = System.SR.Format(System.SR.DeserializeUnableToConvertValue, type);
				ex.AppendPathInformation = true;
			}
			if (ex.AppendPathInformation)
			{
				text2 += $" Path: {arg} | LineNumber: {lineNumber} | BytePositionInLine: {bytePositionInLine}.";
				ex.SetMessage(text2);
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[DoesNotReturn]
		public static void ReThrowWithPath(in WriteStack state, Exception ex)
		{
			JsonException ex2 = new JsonException(null, ex);
			AddJsonExceptionInformation(in state, ex2);
			throw ex2;
		}

		public static void AddJsonExceptionInformation(in WriteStack state, JsonException ex)
		{
			string text2 = (ex.Path = state.PropertyPath());
			string text3 = ex._message;
			if (string.IsNullOrEmpty(text3))
			{
				text3 = System.SR.Format(System.SR.SerializeUnableToSerialize);
				ex.AppendPathInformation = true;
			}
			if (ex.AppendPathInformation)
			{
				text3 = text3 + " Path: " + text2 + ".";
				ex.SetMessage(text3);
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[DoesNotReturn]
		public static void ThrowInvalidOperationException_SerializationDuplicateAttribute(Type attribute, Type classType, MemberInfo memberInfo)
		{
			string text = classType.ToString();
			if (memberInfo != null)
			{
				text = text + "." + memberInfo.Name;
			}
			throw new InvalidOperationException(System.SR.Format(System.SR.SerializationDuplicateAttribute, attribute, text));
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[DoesNotReturn]
		public static void ThrowInvalidOperationException_SerializationDuplicateTypeAttribute(Type classType, Type attribute)
		{
			throw new InvalidOperationException(System.SR.Format(System.SR.SerializationDuplicateTypeAttribute, classType, attribute));
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[DoesNotReturn]
		public static void ThrowInvalidOperationException_SerializationDuplicateTypeAttribute<TAttribute>(Type classType)
		{
			throw new InvalidOperationException(System.SR.Format(System.SR.SerializationDuplicateTypeAttribute, classType, typeof(Attribute)));
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[DoesNotReturn]
		public static void ThrowInvalidOperationException_SerializationDataExtensionPropertyInvalid(Type type, JsonPropertyInfo jsonPropertyInfo)
		{
			throw new InvalidOperationException(System.SR.Format(System.SR.SerializationDataExtensionPropertyInvalid, type, jsonPropertyInfo.MemberInfo?.Name));
		}

		[DoesNotReturn]
		public static void ThrowNotSupportedException(in ReadStack state, in Utf8JsonReader reader, NotSupportedException ex)
		{
			string text = ex.Message;
			Type type = state.Current.JsonPropertyInfo?.RuntimePropertyType;
			if (type == null)
			{
				type = state.Current.JsonClassInfo.Type;
			}
			if (!text.Contains(type.ToString()))
			{
				if (text.Length > 0)
				{
					text += " ";
				}
				text += System.SR.Format(System.SR.SerializationNotSupportedParentType, type);
			}
			long lineNumber = reader.CurrentState._lineNumber;
			long bytePositionInLine = reader.CurrentState._bytePositionInLine;
			text += $" Path: {state.JsonPath()} | LineNumber: {lineNumber} | BytePositionInLine: {bytePositionInLine}.";
			throw new NotSupportedException(text, ex);
		}

		[DoesNotReturn]
		public static void ThrowNotSupportedException(in WriteStack state, NotSupportedException ex)
		{
			string text = ex.Message;
			Type type = state.Current.DeclaredJsonPropertyInfo?.RuntimePropertyType;
			if (type == null)
			{
				type = state.Current.JsonClassInfo.Type;
			}
			if (!text.Contains(type.ToString()))
			{
				if (text.Length > 0)
				{
					text += " ";
				}
				text += System.SR.Format(System.SR.SerializationNotSupportedParentType, type);
			}
			text = text + " Path: " + state.PropertyPath() + ".";
			throw new NotSupportedException(text, ex);
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[DoesNotReturn]
		public static void ThrowNotSupportedException_DeserializeNoConstructor(Type type, ref Utf8JsonReader reader, ref ReadStack state)
		{
			string message = ((!type.IsInterface) ? System.SR.Format(System.SR.DeserializeNoConstructor, "JsonConstructorAttribute", type) : System.SR.Format(System.SR.DeserializePolymorphicInterface, type));
			ThrowNotSupportedException(in state, in reader, new NotSupportedException(message));
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[DoesNotReturn]
		public static void ThrowNotSupportedException_CannotPopulateCollection(Type type, ref Utf8JsonReader reader, ref ReadStack state)
		{
			ThrowNotSupportedException(in state, in reader, new NotSupportedException(System.SR.Format(System.SR.CannotPopulateCollection, type)));
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[DoesNotReturn]
		public static void ThrowJsonException_MetadataValuesInvalidToken(JsonTokenType tokenType)
		{
			ThrowJsonException(System.SR.Format(System.SR.MetadataInvalidTokenAfterValues, tokenType));
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[DoesNotReturn]
		public static void ThrowJsonException_MetadataReferenceNotFound(string id)
		{
			ThrowJsonException(System.SR.Format(System.SR.MetadataReferenceNotFound, id));
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[DoesNotReturn]
		public static void ThrowJsonException_MetadataValueWasNotString(JsonTokenType tokenType)
		{
			ThrowJsonException(System.SR.Format(System.SR.MetadataValueWasNotString, tokenType));
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[DoesNotReturn]
		public static void ThrowJsonException_MetadataValueWasNotString(JsonValueKind valueKind)
		{
			ThrowJsonException(System.SR.Format(System.SR.MetadataValueWasNotString, valueKind));
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[DoesNotReturn]
		public static void ThrowJsonException_MetadataReferenceObjectCannotContainOtherProperties(ReadOnlySpan<byte> propertyName, ref ReadStack state)
		{
			state.Current.JsonPropertyName = propertyName.ToArray();
			ThrowJsonException_MetadataReferenceObjectCannotContainOtherProperties();
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[DoesNotReturn]
		public static void ThrowJsonException_MetadataReferenceObjectCannotContainOtherProperties()
		{
			ThrowJsonException(System.SR.MetadataReferenceCannotContainOtherProperties);
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[DoesNotReturn]
		public static void ThrowJsonException_MetadataIdIsNotFirstProperty(ReadOnlySpan<byte> propertyName, ref ReadStack state)
		{
			state.Current.JsonPropertyName = propertyName.ToArray();
			ThrowJsonException(System.SR.MetadataIdIsNotFirstProperty);
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[DoesNotReturn]
		public static void ThrowJsonException_MetadataMissingIdBeforeValues(ref ReadStack state, ReadOnlySpan<byte> propertyName)
		{
			state.Current.JsonPropertyName = propertyName.ToArray();
			ThrowJsonException(System.SR.MetadataPreservedArrayPropertyNotFound);
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[DoesNotReturn]
		public static void ThrowJsonException_MetadataInvalidPropertyWithLeadingDollarSign(ReadOnlySpan<byte> propertyName, ref ReadStack state, in Utf8JsonReader reader)
		{
			if (state.Current.IsProcessingDictionary())
			{
				state.Current.JsonPropertyNameAsString = reader.GetString();
			}
			else
			{
				state.Current.JsonPropertyName = propertyName.ToArray();
			}
			ThrowJsonException(System.SR.MetadataInvalidPropertyWithLeadingDollarSign);
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[DoesNotReturn]
		public static void ThrowJsonException_MetadataDuplicateIdFound(string id)
		{
			ThrowJsonException(System.SR.Format(System.SR.MetadataDuplicateIdFound, id));
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[DoesNotReturn]
		public static void ThrowJsonException_MetadataInvalidReferenceToValueType(Type propertyType)
		{
			ThrowJsonException(System.SR.Format(System.SR.MetadataInvalidReferenceToValueType, propertyType));
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[DoesNotReturn]
		public static void ThrowJsonException_MetadataPreservedArrayInvalidProperty(ref ReadStack state, Type propertyType, in Utf8JsonReader reader)
		{
			ref ReadStackFrame current = ref state.Current;
			byte[] jsonPropertyName;
			if (!reader.HasValueSequence)
			{
				jsonPropertyName = reader.ValueSpan.ToArray();
			}
			else
			{
				ReadOnlySequence<byte> sequence = reader.ValueSequence;
				jsonPropertyName = BuffersExtensions.ToArray(in sequence);
			}
			current.JsonPropertyName = jsonPropertyName;
			string @string = reader.GetString();
			ThrowJsonException(System.SR.Format(System.SR.MetadataPreservedArrayFailed, System.SR.Format(System.SR.MetadataPreservedArrayInvalidProperty, @string), System.SR.Format(System.SR.DeserializeUnableToConvertValue, propertyType)));
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[DoesNotReturn]
		public static void ThrowJsonException_MetadataPreservedArrayValuesNotFound(ref ReadStack state, Type propertyType)
		{
			state.Current.JsonPropertyName = null;
			ThrowJsonException(System.SR.Format(System.SR.MetadataPreservedArrayFailed, System.SR.MetadataPreservedArrayPropertyNotFound, System.SR.Format(System.SR.DeserializeUnableToConvertValue, propertyType)));
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[DoesNotReturn]
		public static void ThrowJsonException_MetadataCannotParsePreservedObjectIntoImmutable(Type propertyType)
		{
			ThrowJsonException(System.SR.Format(System.SR.MetadataCannotParsePreservedObjectToImmutable, propertyType));
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[DoesNotReturn]
		public static void ThrowInvalidOperationException_MetadataReferenceOfTypeCannotBeAssignedToType(string referenceId, Type currentType, Type typeToConvert)
		{
			throw new InvalidOperationException(System.SR.Format(System.SR.MetadataReferenceOfTypeCannotBeAssignedToType, referenceId, currentType, typeToConvert));
		}

		[DoesNotReturn]
		internal static void ThrowUnexpectedMetadataException(ReadOnlySpan<byte> propertyName, ref Utf8JsonReader reader, ref ReadStack state)
		{
			if (state.Current.JsonClassInfo.PropertyInfoForClassInfo.ConverterBase.ConstructorIsParameterized)
			{
				ThrowNotSupportedException_ObjectWithParameterizedCtorRefMetadataNotHonored(propertyName, ref reader, ref state);
			}
			switch (JsonSerializer.GetMetadataPropertyName(propertyName))
			{
			case MetadataPropertyName.Id:
				ThrowJsonException_MetadataIdIsNotFirstProperty(propertyName, ref state);
				break;
			case MetadataPropertyName.Ref:
				ThrowJsonException_MetadataReferenceObjectCannotContainOtherProperties(propertyName, ref state);
				break;
			default:
				ThrowJsonException_MetadataInvalidPropertyWithLeadingDollarSign(propertyName, ref state, in reader);
				break;
			}
		}
	}
	internal struct BitStack
	{
		private const int AllocationFreeMaxDepth = 64;

		private const int DefaultInitialArraySize = 2;

		private int[] _array;

		private ulong _allocationFreeContainer;

		private int _currentDepth;

		public int CurrentDepth => _currentDepth;

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public void PushTrue()
		{
			if (_currentDepth < 64)
			{
				_allocationFreeContainer = (_allocationFreeContainer << 1) | 1;
			}
			else
			{
				PushToArray(value: true);
			}
			_currentDepth++;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public void PushFalse()
		{
			if (_currentDepth < 64)
			{
				_allocationFreeContainer <<= 1;
			}
			else
			{
				PushToArray(value: false);
			}
			_currentDepth++;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private void PushToArray(bool value)
		{
			if (_array == null)
			{
				_array = new int[2];
			}
			int number = _currentDepth - 64;
			int remainder;
			int num = Div32Rem(number, out remainder);
			if (num >= _array.Length)
			{
				DoubleArray(num);
			}
			int num2 = _array[num];
			num2 = ((!value) ? (num2 & ~(1 << remainder)) : (num2 | (1 << remainder)));
			_array[num] = num2;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public bool Pop()
		{
			_currentDepth--;
			bool flag = false;
			if (_currentDepth < 64)
			{
				_allocationFreeContainer >>= 1;
				return (_allocationFreeContainer & 1) != 0;
			}
			if (_currentDepth == 64)
			{
				return (_allocationFreeContainer & 1) != 0;
			}
			return PopFromArray();
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private bool PopFromArray()
		{
			int number = _currentDepth - 64 - 1;
			int remainder;
			int num = Div32Rem(number, out remainder);
			return (_array[num] & (1 << remainder)) != 0;
		}

		private void DoubleArray(int minSize)
		{
			int newSize = Math.Max(minSize + 1, _array.Length * 2);
			Array.Resize(ref _array, newSize);
		}

		public void SetFirstBit()
		{
			_currentDepth++;
			_allocationFreeContainer = 1uL;
		}

		public void ResetFirstBit()
		{
			_currentDepth++;
			_allocationFreeContainer = 0uL;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		private static int Div32Rem(int number, out int remainder)
		{
			uint result = (uint)number / 32u;
			remainder = number & 0x1F;
			return (int)result;
		}
	}
	public sealed class JsonDocument : IDisposable
	{
		internal readonly struct DbRow
		{
			internal const int Size = 12;

			private readonly int _location;

			private readonly int _sizeOrLengthUnion;

			private readonly int _numberOfRowsAndTypeUnion;

			internal const int UnknownSize = -1;

			internal int Location => _location;

			internal int SizeOrLength => _sizeOrLengthUnion & 0x7FFFFFFF;

			internal bool IsUnknownSize => _sizeOrLengthUnion == -1;

			internal bool HasComplexChildren => _sizeOrLengthUnion < 0;

			internal int NumberOfRows => _numberOfRowsAndTypeUnion & 0xFFFFFFF;

			internal JsonTokenType TokenType => (JsonTokenType)((uint)_numberOfRowsAndTypeUnion >> 28);

			internal bool IsSimpleValue => (int)TokenType >= 5;

			internal DbRow(JsonTokenType jsonTokenType, int location, int sizeOrLength)
			{
				_location = location;
				_sizeOrLengthUnion = sizeOrLength;
				_numberOfRowsAndTypeUnion = (int)((uint)jsonTokenType << 28);
			}
		}

		private struct MetadataDb : IDisposable
		{
			private const int SizeOrLengthOffset = 4;

			private const int NumberOfRowsOffset = 8;

			private byte[] _data;

			internal int Length { get; private set; }

			internal MetadataDb(byte[] completeDb)
			{
				_data = completeDb;
				Length = completeDb.Length;
			}

			internal MetadataDb(int payloadLength)
			{
				int num = 12 + payloadLength;
				if (num > 1048576 && num <= 4194304)
				{
					num = 1048576;
				}
				_data = ArrayPool<byte>.Shared.Rent(num);
				Length = 0;
			}

			internal MetadataDb(MetadataDb source, bool useArrayPools)
			{
				Length = source.Length;
				if (useArrayPools)
				{
					_data = ArrayPool<byte>.Shared.Rent(Length);
					source._data.AsSpan(0, Length).CopyTo(_data);
				}
				else
				{
					_data = source._data.AsSpan(0, Length).ToArray();
				}
			}

			public void Dispose()
			{
				byte[] array = Interlocked.Exchange(ref _data, null);
				if (array != null)
				{
					ArrayPool<byte>.Shared.Return(array);
					Length = 0;
				}
			}

			internal void TrimExcess()
			{
				if (Length <= _data.Length / 2)
				{
					byte[] array = ArrayPool<byte>.Shared.Rent(Length);
					byte[] array2 = array;
					if (array.Length < _data.Length)
					{
						Buffer.BlockCopy(_data, 0, array, 0, Length);
						array2 = _data;
						_data = array;
					}
					ArrayPool<byte>.Shared.Return(array2);
				}
			}

			internal void Append(JsonTokenType tokenType, int startLocation, int length)
			{
				if (Length >= _data.Length - 12)
				{
					Enlarge();
				}
				DbRow value = new DbRow(tokenType, startLocation, length);
				MemoryMarshal.Write(_data.AsSpan(Length), ref value);
				Length += 12;
			}

			private void Enlarge()
			{
				byte[] data = _data;
				_data = ArrayPool<byte>.Shared.Rent(data.Length * 2);
				Buffer.BlockCopy(data, 0, _data, 0, data.Length);
				ArrayPool<byte>.Shared.Return(data);
			}

			[Conditional("DEBUG")]
			private void AssertValidIndex(int index)
			{
			}

			internal void SetLength(int index, int length)
			{
				Span<byte> destination = _data.AsSpan(index + 4);
				MemoryMarshal.Write(destination, ref length);
			}

			internal void SetNumberOfRows(int index, int numberOfRows)
			{
				Span<byte> span = _data.AsSpan(index + 8);
				int num = MemoryMarshal.Read<int>(span);
				int value = (num & -268435456) | numberOfRows;
				MemoryMarshal.Write(span, ref value);
			}

			internal void SetHasComplexChildren(int index)
			{
				Span<byte> span = _data.AsSpan(index + 4);
				int num = MemoryMarshal.Read<int>(span);
				int value = num | int.MinValue;
				MemoryMarshal.Write(span, ref value);
			}

			internal int FindIndexOfFirstUnsetSizeOrLength(JsonTokenType lookupType)
			{
				return FindOpenElement(lookupType);
			}

			private int FindOpenElement(JsonTokenType lookupType)
			{
				Span<byte> span = _data.AsSpan(0, Length);
				for (int num = Length - 12; num >= 0; num -= 12)
				{
					DbRow dbRow = MemoryMarshal.Read<DbRow>(span.Slice(num));
					if (dbRow.IsUnknownSize && dbRow.TokenType == lookupType)
					{
						return num;
					}
				}
				return -1;
			}

			internal DbRow Get(int index)
			{
				return MemoryMarshal.Read<DbRow>(_data.AsSpan(index));
			}

			internal JsonTokenType GetJsonTokenType(int index)
			{
				uint num = MemoryMarshal.Read<uint>(_data.AsSpan(index + 8));
				return (JsonTokenType)(num >> 28);
			}

			internal MetadataDb CopySegment(int startIndex, int endIndex)
			{
				DbRow dbRow = Get(startIndex);
				int num = endIndex - startIndex;
				byte[] array = new byte[num];
				_data.AsSpan(startIndex, num).CopyTo(array);
				Span<int> span = MemoryMarshal.Cast<byte, int>(array);
				int num2 = span[0];
				if (dbRow.TokenType == JsonTokenType.String)
				{
					num2--;
				}
				for (int num3 = (num - 12) / 4; num3 >= 0; num3 -= 3)
				{
					span[num3] -= num2;
				}
				return new MetadataDb(array);
			}
		}

		private struct StackRow
		{
			internal const int Size = 8;

			internal int SizeOrLength;

			internal int NumberOfRows;

			internal StackRow(int sizeOrLength = 0, int numberOfRows = -1)
			{
				SizeOrLength = sizeOrLength;
				NumberOfRows = numberOfRows;
			}
		}

		private struct StackRowStack : IDisposable
		{
			private byte[] _rentedBuffer;

			private int _topOfStack;

			internal StackRowStack(int initialSize)
			{
				_rentedBuffer = ArrayPool<byte>.Shared.Rent(initialSize);
				_topOfStack = _rentedBuffer.Length;
			}

			public void Dispose()
			{
				byte[] rentedBuffer = _rentedBuffer;
				_rentedBuffer = null;
				_topOfStack = 0;
				if (rentedBuffer != null)
				{
					ArrayPool<byte>.Shared.Return(rentedBuffer);
				}
			}

			internal void Push(StackRow row)
			{
				if (_topOfStack < 8)
				{
					Enlarge();
				}
				_topOfStack -= 8;
				MemoryMarshal.Write(_rentedBuffer.AsSpan(_topOfStack), ref row);
			}

			internal StackRow Pop()
			{
				StackRow result = MemoryMarshal.Read<StackRow>(_rentedBuffer.AsSpan(_topOfStack));
				_topOfStack += 8;
				return result;
			}

			private void Enlarge()
			{
				byte[] rentedBuffer = _rentedBuffer;
				_rentedBuffer = ArrayPool<byte>.Shared.Rent(rentedBuffer.Length * 2);
				Buffer.BlockCopy(rentedBuffer, _topOfStack, _rentedBuffer, _rentedBuffer.Length - rentedBuffer.Length + _topOfStack, rentedBuffer.Length - _topOfStack);
				_topOfStack += _rentedBuffer.Length - rentedBuffer.Length;
				ArrayPool<byte>.Shared.Return(rentedBuffer);
			}
		}

		private ReadOnlyMemory<byte> _utf8Json;

		private MetadataDb _parsedData;

		private byte[] _extraRentedBytes;

		private (int, string) _lastIndexAndString = (-1, null);

		private const int UnseekableStreamInitialRentSize = 4096;

		internal bool IsDisposable { get; }

		public JsonElement RootElement => new JsonElement(this, 0);

		private JsonDocument(ReadOnlyMemory<byte> utf8Json, MetadataDb parsedData, byte[] extraRentedBytes, bool isDisposable = true)
		{
			_utf8Json = utf8Json;
			_parsedData = parsedData;
			_extraRentedBytes = extraRentedBytes;
			IsDisposable = isDisposable;
		}

		public void Dispose()
		{
			int length = _utf8Json.Length;
			if (length != 0 && IsDisposable)
			{
				_parsedData.Dispose();
				_utf8Json = ReadOnlyMemory<byte>.Empty;
				byte[] array = Interlocked.Exchange(ref _extraRentedBytes, null);
				if (array != null)
				{
					array.AsSpan(0, length).Clear();
					ArrayPool<byte>.Shared.Return(array);
				}
			}
		}

		public void WriteTo(Utf8JsonWriter writer)
		{
			if (writer == null)
			{
				throw new ArgumentNullException("writer");
			}
			RootElement.WriteTo(writer);
		}

		internal JsonTokenType GetJsonTokenType(int index)
		{
			CheckNotDisposed();
			return _parsedData.GetJsonTokenType(index);
		}

		internal int GetArrayLength(int index)
		{
			CheckNotDisposed();
			DbRow dbRow = _parsedData.Get(index);
			CheckExpectedType(JsonTokenType.StartArray, dbRow.TokenType);
			return dbRow.SizeOrLength;
		}

		internal JsonElement GetArrayIndexElement(int currentIndex, int arrayIndex)
		{
			CheckNotDisposed();
			DbRow dbRow = _parsedData.Get(currentIndex);
			CheckExpectedType(JsonTokenType.StartArray, dbRow.TokenType);
			int sizeOrLength = dbRow.SizeOrLength;
			if ((uint)arrayIndex >= (uint)sizeOrLength)
			{
				throw new IndexOutOfRangeException();
			}
			if (!dbRow.HasComplexChildren)
			{
				return new JsonElement(this, currentIndex + (arrayIndex + 1) * 12);
			}
			int num = 0;
			for (int i = currentIndex + 12; i < _parsedData.Length; i += 12)
			{
				if (arrayIndex == num)
				{
					return new JsonElement(this, i);
				}
				dbRow = _parsedData.Get(i);
				if (!dbRow.IsSimpleValue)
				{
					i += 12 * dbRow.NumberOfRows;
				}
				num++;
			}
			throw new IndexOutOfRangeException();
		}

		internal int GetEndIndex(int index, bool includeEndElement)
		{
			CheckNotDisposed();
			DbRow dbRow = _parsedData.Get(index);
			if (dbRow.IsSimpleValue)
			{
				return index + 12;
			}
			int num = index + 12 * dbRow.NumberOfRows;
			if (includeEndElement)
			{
				num += 12;
			}
			return num;
		}

		private ReadOnlyMemory<byte> GetRawValue(int index, bool includeQuotes)
		{
			CheckNotDisposed();
			DbRow dbRow = _parsedData.Get(index);
			if (dbRow.IsSimpleValue)
			{
				if (includeQuotes && dbRow.TokenType == JsonTokenType.String)
				{
					return _utf8Json.Slice(dbRow.Location - 1, dbRow.SizeOrLength + 2);
				}
				return _utf8Json.Slice(dbRow.Location, dbRow.SizeOrLength);
			}
			int endIndex = GetEndIndex(index, includeEndElement: false);
			int location = dbRow.Location;
			dbRow = _parsedData.Get(endIndex);
			return _utf8Json.Slice(location, dbRow.Location - location + dbRow.SizeOrLength);
		}

		private ReadOnlyMemory<byte> GetPropertyRawValue(int valueIndex)
		{
			CheckNotDisposed();
			int num = _parsedData.Get(valueIndex - 12).Location - 1;
			DbRow dbRow = _parsedData.Get(valueIndex);
			int num2;
			if (dbRow.IsSimpleValue)
			{
				num2 = dbRow.Location + dbRow.SizeOrLength;
				if (dbRow.TokenType == JsonTokenType.String)
				{
					num2++;
				}
				return _utf8Json.Slice(num, num2 - num);
			}
			int endIndex = GetEndIndex(valueIndex, includeEndElement: false);
			dbRow = _parsedData.Get(endIndex);
			num2 = dbRow.Location + dbRow.SizeOrLength;
			return _utf8Json.Slice(num, num2 - num);
		}

		internal string GetString(int index, JsonTokenType expectedType)
		{
			CheckNotDisposed();
			int num;
			string result;
			(num, result) = _lastIndexAndString;
			if (num == index)
			{
				return result;
			}
			DbRow dbRow = _parsedData.Get(index);
			JsonTokenType tokenType = dbRow.TokenType;
			if (tokenType == JsonTokenType.Null)
			{
				return null;
			}
			CheckExpectedType(expectedType, tokenType);
			ReadOnlySpan<byte> readOnlySpan = _utf8Json.Span.Slice(dbRow.Location, dbRow.SizeOrLength);
			if (dbRow.HasComplexChildren)
			{
				int idx = readOnlySpan.IndexOf<byte>(92);
				result = JsonReaderHelper.GetUnescapedString(readOnlySpan, idx);
			}
			else
			{
				result = JsonReaderHelper.TranscodeHelper(readOnlySpan);
			}
			_lastIndexAndString = (index, result);
			return result;
		}

		internal bool TextEquals(int index, ReadOnlySpan<char> otherText, bool isPropertyName)
		{
			CheckNotDisposed();
			int num = (isPropertyName ? (index - 12) : index);
			var (num2, text) = _lastIndexAndString;
			if (num2 == num)
			{
				return otherText.SequenceEqual(text.AsSpan());
			}
			byte[] array = null;
			int num3 = checked(otherText.Length * 3);
			Span<byte> span = ((num3 > 256) ? ((Span<byte>)(array = ArrayPool<byte>.Shared.Rent(num3))) : stackalloc byte[256]);
			Span<byte> utf8Destination = span;
			ReadOnlySpan<byte> utf16Source = MemoryMarshal.AsBytes(otherText);
			int bytesConsumed;
			int bytesWritten;
			OperationStatus operationStatus = JsonWriterHelper.ToUtf8(utf16Source, utf8Destination, out bytesConsumed, out bytesWritten);
			bool result = operationStatus <= OperationStatus.DestinationTooSmall && TextEquals(index, utf8Destination.Slice(0, bytesWritten), isPropertyName, shouldUnescape: true);
			if (array != null)
			{
				utf8Destination.Slice(0, bytesWritten).Clear();
				ArrayPool<byte>.Shared.Return(array);
			}
			return result;
		}

		internal bool TextEquals(int index, ReadOnlySpan<byte> otherUtf8Text, bool isPropertyName, bool shouldUnescape)
		{
			CheckNotDisposed();
			int index2 = (isPropertyName ? (index - 12) : index);
			DbRow dbRow = _parsedData.Get(index2);
			CheckExpectedType(isPropertyName ? JsonTokenType.PropertyName : JsonTokenType.String, dbRow.TokenType);
			ReadOnlySpan<byte> span = _utf8Json.Span.Slice(dbRow.Location, dbRow.SizeOrLength);
			if (otherUtf8Text.Length > span.Length || (!shouldUnescape && otherUtf8Text.Length != span.Length))
			{
				return false;
			}
			if (dbRow.HasComplexChildren && shouldUnescape)
			{
				if (otherUtf8Text.Length < span.Length / 6)
				{
					return false;
				}
				int num = span.IndexOf<byte>(92);
				if (!otherUtf8Text.StartsWith(span.Slice(0, num)))
				{
					return false;
				}
				return JsonReaderHelper.UnescapeAndCompare(span.Slice(num), otherUtf8Text.Slice(num));
			}
			return span.SequenceEqual(otherUtf8Text);
		}

		internal string GetNameOfPropertyValue(int index)
		{
			return GetString(index - 12, JsonTokenType.PropertyName);
		}

		internal bool TryGetValue(int index, [NotNullWhen(true)] out byte[] value)
		{
			CheckNotDisposed();
			DbRow dbRow = _parsedData.Get(index);
			CheckExpectedType(JsonTokenType.String, dbRow.TokenType);
			ReadOnlySpan<byte> readOnlySpan = _utf8Json.Span.Slice(dbRow.Location, dbRow.SizeOrLength);
			if (dbRow.HasComplexChildren)
			{
				int idx = readOnlySpan.IndexOf<byte>(92);
				return JsonReaderHelper.TryGetUnescapedBase64Bytes(readOnlySpan, idx, out value);
			}
			return JsonReaderHelper.TryDecodeBase64(readOnlySpan, out value);
		}

		internal bool TryGetValue(int index, out sbyte value)
		{
			CheckNotDisposed();
			DbRow dbRow = _parsedData.Get(index);
			CheckExpectedType(JsonTokenType.Number, dbRow.TokenType);
			ReadOnlySpan<byte> source = _utf8Json.Span.Slice(dbRow.Location, dbRow.SizeOrLength);
			if (Utf8Parser.TryParse(source, out sbyte value2, out int bytesConsumed, '\0') && bytesConsumed == source.Length)
			{
				value = value2;
				return true;
			}
			value = 0;
			return false;
		}

		internal bool TryGetValue(int index, out byte value)
		{
			CheckNotDisposed();
			DbRow dbRow = _parsedData.Get(index);
			CheckExpectedType(JsonTokenType.Number, dbRow.TokenType);
			ReadOnlySpan<byte> source = _utf8Json.Span.Slice(dbRow.Location, dbRow.SizeOrLength);
			if (Utf8Parser.TryParse(source, out byte value2, out int bytesConsumed, '\0') && bytesConsumed == source.Length)
			{
				value = value2;
				return true;
			}
			value = 0;
			return false;
		}

		internal bool TryGetValue(int index, out short value)
		{
			CheckNotDisposed();
			DbRow dbRow = _parsedData.Get(index);
			CheckExpectedType(JsonTokenType.Number, dbRow.TokenType);
			ReadOnlySpan<byte> source = _utf8Json.Span.Slice(dbRow.Location, dbRow.SizeOrLength);
			if (Utf8Parser.TryParse(source, out short value2, out int bytesConsumed, '\0') && bytesConsumed == source.Length)
			{
				value = value2;
				return true;
			}
			value = 0;
			return false;
		}

		internal bool TryGetValue(int index, out ushort value)
		{
			CheckNotDisposed();
			DbRow dbRow = _parsedData.Get(index);
			CheckExpectedType(JsonTokenType.Number, dbRow.TokenType);
			ReadOnlySpan<byte> source = _utf8Json.Span.Slice(dbRow.Location, dbRow.SizeOrLength);
			if (Utf8Parser.TryParse(source, out ushort value2, out int bytesConsumed, '\0') && bytesConsumed == source.Length)
			{
				value = value2;
				return true;
			}
			value = 0;
			return false;
		}

		internal bool TryGetValue(int index, out int value)
		{
			CheckNotDisposed();
			DbRow dbRow = _parsedData.Get(index);
			CheckExpectedType(JsonTokenType.Number, dbRow.TokenType);
			ReadOnlySpan<byte> source = _utf8Json.Span.Slice(dbRow.Location, dbRow.SizeOrLength);
			if (Utf8Parser.TryParse(source, out int value2, out int bytesConsumed, '\0') && bytesConsumed == source.Length)
			{
				value = value2;
				return true;
			}
			value = 0;
			return false;
		}

		internal bool TryGetValue(int index, out uint value)
		{
			CheckNotDisposed();
			DbRow dbRow = _parsedData.Get(index);
			CheckExpectedType(JsonTokenType.Number, dbRow.TokenType);
			ReadOnlySpan<byte> source = _utf8Json.Span.Slice(dbRow.Location, dbRow.SizeOrLength);
			if (Utf8Parser.TryParse(source, out uint value2, out int bytesConsumed, '\0') && bytesConsumed == source.Length)
			{
				value = value2;
				return true;
			}
			value = 0u;
			return false;
		}

		internal bool TryGetValue(int index, out long value)
		{
			CheckNotDisposed();
			DbRow dbRow = _parsedData.Get(index);
			CheckExpectedType(JsonTokenType.Number, dbRow.TokenType);
			ReadOnlySpan<byte> source = _utf8Json.Span.Slice(dbRow.Location, dbRow.SizeOrLength);
			if (Utf8Parser.TryParse(source, out long value2, out int bytesConsumed, '\0') && bytesConsumed == source.Length)
			{
				value = value2;
				return true;
			}
			value = 0L;
			return false;
		}

		internal bool TryGetValue(int index, out ulong value)
		{
			CheckNotDisposed();
			DbRow dbRow = _parsedData.Get(index);
			CheckExpectedType(JsonTokenType.Number, dbRow.TokenType);
			ReadOnlySpan<byte> source = _utf8Json.Span.Slice(dbRow.Location, dbRow.SizeOr

BepInExPack/mono/Managed/System.Threading.Tasks.Extensions.dll

Decompiled a month ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using System.Threading.Tasks.Sources;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyDefaultAlias("System.Threading.Tasks.Extensions")]
[assembly: AssemblyCompany("Microsoft Corporation")]
[assembly: AssemblyCopyright("© Microsoft Corporation. All rights reserved.")]
[assembly: AssemblyDescription("System.Threading.Tasks.Extensions")]
[assembly: AssemblyFileVersion("4.700.19.46205")]
[assembly: AssemblyInformationalVersion("4.7.0+a5b5f2e1e369972c8ff1e2183979fab6099f52ef")]
[assembly: AssemblyProduct("Microsoft® .NET Framework")]
[assembly: AssemblyTitle("System.Threading.Tasks.Extensions")]
[assembly: CLSCompliant(true)]
[assembly: AssemblyVersion("4.2.1.0")]
[assembly: TypeForwardedTo(typeof(AsyncMethodBuilderAttribute))]
[assembly: TypeForwardedTo(typeof(AsyncValueTaskMethodBuilder))]
[assembly: TypeForwardedTo(typeof(AsyncValueTaskMethodBuilder<>))]
[assembly: TypeForwardedTo(typeof(ConfiguredValueTaskAwaitable))]
[assembly: TypeForwardedTo(typeof(ConfiguredValueTaskAwaitable<>))]
[assembly: TypeForwardedTo(typeof(ValueTaskAwaiter))]
[assembly: TypeForwardedTo(typeof(ValueTaskAwaiter<>))]
[assembly: TypeForwardedTo(typeof(IValueTaskSource))]
[assembly: TypeForwardedTo(typeof(IValueTaskSource<>))]
[assembly: TypeForwardedTo(typeof(ValueTaskSourceOnCompletedFlags))]
[assembly: TypeForwardedTo(typeof(ValueTaskSourceStatus))]
[assembly: TypeForwardedTo(typeof(ValueTask))]
[assembly: TypeForwardedTo(typeof(ValueTask<>))]

BepInExPack/mono/Managed/System.Xml.dll

Decompiled a month ago
using System;
using System.CodeDom;
using System.CodeDom.Compiler;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Configuration;
using System.Diagnostics;
using System.Diagnostics.SymbolStore;
using System.Globalization;
using System.IO;
using System.Net;
using System.Net.Cache;
using System.Reflection;
using System.Reflection.Emit;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.ConstrainedExecution;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Security;
using System.Security.Permissions;
using System.Security.Policy;
using System.Security.Principal;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;
using System.Xml.Serialization.Advanced;
using System.Xml.Serialization.Configuration;
using System.Xml.Utils;
using System.Xml.XPath;
using System.Xml.XmlConfiguration;
using System.Xml.Xsl;
using System.Xml.Xsl.IlGen;
using System.Xml.Xsl.Qil;
using System.Xml.Xsl.Runtime;
using System.Xml.Xsl.XPath;
using System.Xml.Xsl.Xslt;
using System.Xml.Xsl.XsltOld;
using System.Xml.Xsl.XsltOld.Debugger;
using MS.Internal.Xml.Cache;
using MS.Internal.Xml.XPath;
using Microsoft.CSharp;
using Microsoft.VisualBasic;
using Microsoft.Win32;

[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: InternalsVisibleTo("System.Data.SqlXml, PublicKey=00000000000000000400000000000000")]
[assembly: InternalsVisibleTo("System.Xml.Linq, PublicKey=00000000000000000400000000000000")]
[assembly: InternalsVisibleTo("System.ServiceModel.Friend, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")]
[assembly: AssemblyTitle("System.Xml.dll")]
[assembly: AssemblyDescription("System.Xml.dll")]
[assembly: AssemblyDefaultAlias("System.Xml.dll")]
[assembly: AssemblyCompany("Mono development team")]
[assembly: AssemblyProduct("Mono Common Language Infrastructure")]
[assembly: AssemblyCopyright("(c) Various Mono authors")]
[assembly: SatelliteContractVersion("4.0.0.0")]
[assembly: AssemblyInformationalVersion("4.6.57.0")]
[assembly: NeutralResourcesLanguage("en-US")]
[assembly: ComVisible(false)]
[assembly: CLSCompliant(true)]
[assembly: AssemblyDelaySign(true)]
[assembly: AssemblyKeyFile("../ecma.pub")]
[assembly: AllowPartiallyTrustedCallers]
[assembly: InternalsVisibleTo("System.Xml.Linq, PublicKey=00000000000000000400000000000000", AllInternalsVisible = false)]
[assembly: AssemblyFileVersion("4.6.57.0")]
[assembly: CompilationRelaxations(CompilationRelaxations.NoStringInterning)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("4.0.0.0")]
[module: UnverifiableCode]
internal static class AssemblyRef
{
	internal const string SystemConfiguration = "System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	internal const string System = "System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";

	public const string EcmaPublicKey = "b77a5c561934e089";

	public const string FrameworkPublicKeyFull = "00000000000000000400000000000000";

	public const string FrameworkPublicKeyFull2 = "00000000000000000400000000000000";

	public const string MicrosoftPublicKey = "b03f5f7f11d50a3a";

	public const string MicrosoftJScript = "Microsoft.JScript, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string MicrosoftVSDesigner = "Microsoft.VSDesigner, Version=0.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string SystemData = "System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string SystemDesign = "System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string SystemDrawing = "System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string SystemWeb = "System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string SystemWebExtensions = "System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";

	public const string SystemWindowsForms = "System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";
}
internal static class Consts
{
	public const string MonoCorlibVersion = "1A5E0066-58DC-428A-B21C-0AD6CDAE2789";

	public const string MonoVersion = "6.13.0.0";

	public const string MonoCompany = "Mono development team";

	public const string MonoProduct = "Mono Common Language Infrastructure";

	public const string MonoCopyright = "(c) Various Mono authors";

	public const string FxVersion = "4.0.0.0";

	public const string FxFileVersion = "4.6.57.0";

	public const string EnvironmentVersion = "4.0.30319.42000";

	public const string VsVersion = "0.0.0.0";

	public const string VsFileVersion = "11.0.0.0";

	private const string PublicKeyToken = "b77a5c561934e089";

	public const string AssemblyI18N = "I18N, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756";

	public const string AssemblyMicrosoft_JScript = "Microsoft.JScript, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblyMicrosoft_VisualStudio = "Microsoft.VisualStudio, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblyMicrosoft_VisualStudio_Web = "Microsoft.VisualStudio.Web, Version=0.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblyMicrosoft_VSDesigner = "Microsoft.VSDesigner, Version=0.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblyMono_Http = "Mono.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756";

	public const string AssemblyMono_Posix = "Mono.Posix, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756";

	public const string AssemblyMono_Security = "Mono.Security, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756";

	public const string AssemblyMono_Messaging_RabbitMQ = "Mono.Messaging.RabbitMQ, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756";

	public const string AssemblyCorlib = "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string AssemblySystem = "System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string AssemblySystem_Data = "System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string AssemblySystem_Design = "System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_DirectoryServices = "System.DirectoryServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_Drawing = "System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_Drawing_Design = "System.Drawing.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_Messaging = "System.Messaging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_Security = "System.Security, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_ServiceProcess = "System.ServiceProcess, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_Web = "System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_Windows_Forms = "System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string AssemblySystem_2_0 = "System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string AssemblySystemCore_3_5 = "System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string AssemblySystem_Core = "System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string WindowsBase_3_0 = "WindowsBase, Version=3.0.0.0, PublicKeyToken=31bf3856ad364e35";

	public const string AssemblyWindowsBase = "WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";

	public const string AssemblyPresentationCore_3_5 = "PresentationCore, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";

	public const string AssemblyPresentationCore_4_0 = "PresentationCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";

	public const string AssemblyPresentationFramework_3_5 = "PresentationFramework, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";

	public const string AssemblySystemServiceModel_3_0 = "System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";
}
internal static class SR
{
	public const string Xml_UserException = "{0}";

	public const string Xml_DefaultException = "An XML error has occurred.";

	public const string Xml_InvalidOperation = "Operation is not valid due to the current state of the object.";

	public const string Xml_ErrorFilePosition = "An error occurred at {0}, ({1}, {2}).";

	public const string Xml_StackOverflow = "Stack overflow.";

	public const string Xslt_NoStylesheetLoaded = "No stylesheet was loaded.";

	public const string Xslt_NotCompiledStylesheet = "Type '{0}' is not a compiled stylesheet class.";

	public const string Xslt_IncompatibleCompiledStylesheetVersion = "Executing a stylesheet that was compiled using a later version of the framework is not supported. Stylesheet Version: {0}. Current Framework Version: {1}.";

	public const string Xml_AsyncIsRunningException = "An asynchronous operation is already in progress.";

	public const string Xml_ReaderAsyncNotSetException = "Set XmlReaderSettings.Async to true if you want to use Async Methods.";

	public const string Xml_UnclosedQuote = "There is an unclosed literal string.";

	public const string Xml_UnexpectedEOF = "Unexpected end of file while parsing {0} has occurred.";

	public const string Xml_UnexpectedEOF1 = "Unexpected end of file has occurred.";

	public const string Xml_UnexpectedEOFInElementContent = "Unexpected end of file has occurred. The following elements are not closed: {0}";

	public const string Xml_BadStartNameChar = "Name cannot begin with the '{0}' character, hexadecimal value {1}.";

	public const string Xml_BadNameChar = "The '{0}' character, hexadecimal value {1}, cannot be included in a name.";

	public const string Xml_BadDecimalEntity = "Invalid syntax for a decimal numeric entity reference.";

	public const string Xml_BadHexEntity = "Invalid syntax for a hexadecimal numeric entity reference.";

	public const string Xml_MissingByteOrderMark = "There is no Unicode byte order mark. Cannot switch to Unicode.";

	public const string Xml_UnknownEncoding = "System does not support '{0}' encoding.";

	public const string Xml_InternalError = "An internal error has occurred.";

	public const string Xml_InvalidCharInThisEncoding = "Invalid character in the given encoding.";

	public const string Xml_ErrorPosition = "Line {0}, position {1}.";

	public const string Xml_MessageWithErrorPosition = "{0} Line {1}, position {2}.";

	public const string Xml_UnexpectedTokenEx = "'{0}' is an unexpected token. The expected token is '{1}'.";

	public const string Xml_UnexpectedTokens2 = "'{0}' is an unexpected token. The expected token is '{1}' or '{2}'.";

	public const string Xml_ExpectingWhiteSpace = "'{0}' is an unexpected token. Expecting whitespace.";

	public const string Xml_TagMismatchEx = "The '{0}' start tag on line {1} position {2} does not match the end tag of '{3}'.";

	public const string Xml_UnexpectedEndTag = "Unexpected end tag.";

	public const string Xml_UnknownNs = "'{0}' is an undeclared prefix.";

	public const string Xml_BadAttributeChar = "'{0}', hexadecimal value {1}, is an invalid attribute character.";

	public const string Xml_ExpectExternalOrClose = "Expecting external ID, '[' or '>'.";

	public const string Xml_MissingRoot = "Root element is missing.";

	public const string Xml_MultipleRoots = "There are multiple root elements.";

	public const string Xml_InvalidRootData = "Data at the root level is invalid.";

	public const string Xml_XmlDeclNotFirst = "Unexpected XML declaration. The XML declaration must be the first node in the document, and no whitespace characters are allowed to appear before it.";

	public const string Xml_InvalidXmlDecl = "Syntax for an XML declaration is invalid.";

	public const string Xml_InvalidNodeType = "'{0}' is an invalid XmlNodeType.";

	public const string Xml_InvalidPIName = "'{0}' is an invalid name for processing instructions.";

	public const string Xml_InvalidXmlSpace = "'{0}' is an invalid xml:space value.";

	public const string Xml_InvalidVersionNumber = "Version number '{0}' is invalid.";

	public const string Xml_DupAttributeName = "'{0}' is a duplicate attribute name.";

	public const string Xml_BadDTDLocation = "Unexpected DTD declaration.";

	public const string Xml_ElementNotFound = "Element '{0}' was not found.";

	public const string Xml_ElementNotFoundNs = "Element '{0}' with namespace name '{1}' was not found.";

	public const string Xml_PartialContentNodeTypeNotSupportedEx = "XmlNodeType {0} is not supported for partial content parsing.";

	public const string Xml_MultipleDTDsProvided = "Cannot have multiple DTDs.";

	public const string Xml_CanNotBindToReservedNamespace = "Cannot bind to the reserved namespace.";

	public const string Xml_InvalidCharacter = "'{0}', hexadecimal value {1}, is an invalid character.";

	public const string Xml_InvalidBinHexValue = "'{0}' is not a valid BinHex text sequence.";

	public const string Xml_InvalidBinHexValueOddCount = "'{0}' is not a valid BinHex text sequence. The sequence must contain an even number of characters.";

	public const string Xml_InvalidTextDecl = "Invalid text declaration.";

	public const string Xml_InvalidBase64Value = "'{0}' is not a valid Base64 text sequence.";

	public const string Xml_UndeclaredEntity = "Reference to undeclared entity '{0}'.";

	public const string Xml_RecursiveParEntity = "Parameter entity '{0}' references itself.";

	public const string Xml_RecursiveGenEntity = "General entity '{0}' references itself.";

	public const string Xml_ExternalEntityInAttValue = "External entity '{0}' reference cannot appear in the attribute value.";

	public const string Xml_UnparsedEntityRef = "Reference to unparsed entity '{0}'.";

	public const string Xml_NotSameNametable = "Not the same name table.";

	public const string Xml_NametableMismatch = "XmlReaderSettings.XmlNameTable must be the same name table as in XmlParserContext.NameTable or XmlParserContext.NamespaceManager.NameTable, or it must be null.";

	public const string Xml_BadNamespaceDecl = "Invalid namespace declaration.";

	public const string Xml_ErrorParsingEntityName = "An error occurred while parsing EntityName.";

	public const string Xml_InvalidNmToken = "Invalid NmToken value '{0}'.";

	public const string Xml_EntityRefNesting = "Entity replacement text must nest properly within markup declarations.";

	public const string Xml_CannotResolveEntity = "Cannot resolve entity reference '{0}'.";

	public const string Xml_CannotResolveEntityDtdIgnored = "Cannot resolve entity reference '{0}' because the DTD has been ignored. To enable DTD processing set the DtdProcessing property on XmlReaderSettings to Parse and pass the settings into XmlReader.Create method.";

	public const string Xml_CannotResolveExternalSubset = "Cannot resolve external DTD subset - public ID = '{0}', system ID = '{1}'.";

	public const string Xml_CannotResolveUrl = "Cannot resolve '{0}'.";

	public const string Xml_CDATAEndInText = "']]>' is not allowed in character data.";

	public const string Xml_ExternalEntityInStandAloneDocument = "Standalone document declaration must have a value of 'no' because an external entity '{0}' is referenced.";

	public const string Xml_DtdAfterRootElement = "DTD must be defined before the document root element.";

	public const string Xml_ReadOnlyProperty = "The '{0}' property is read only and cannot be set.";

	public const string Xml_DtdIsProhibited = "DTD is prohibited in this XML document.";

	public const string Xml_DtdIsProhibitedEx = "For security reasons DTD is prohibited in this XML document. To enable DTD processing set the DtdProcessing property on XmlReaderSettings to Parse and pass the settings into XmlReader.Create method.";

	public const string Xml_ReadSubtreeNotOnElement = "ReadSubtree() can be called only if the reader is on an element node.";

	public const string Xml_DtdNotAllowedInFragment = "DTD is not allowed in XML fragments.";

	public const string Xml_CannotStartDocumentOnFragment = "WriteStartDocument cannot be called on writers created with ConformanceLevel.Fragment.";

	public const string Xml_ErrorOpeningExternalDtd = "An error has occurred while opening external DTD '{0}': {1}";

	public const string Xml_ErrorOpeningExternalEntity = "An error has occurred while opening external entity '{0}': {1}";

	public const string Xml_ReadBinaryContentNotSupported = "{0} method is not supported on this XmlReader. Use CanReadBinaryContent property to find out if a reader implements it.";

	public const string Xml_ReadValueChunkNotSupported = "ReadValueChunk method is not supported on this XmlReader. Use CanReadValueChunk property to find out if an XmlReader implements it.";

	public const string Xml_InvalidReadContentAs = "The {0} method is not supported on node type {1}. If you want to read typed content of an element, use the ReadElementContentAs method.";

	public const string Xml_InvalidReadElementContentAs = "The {0} method is not supported on node type {1}.";

	public const string Xml_MixedReadElementContentAs = "ReadElementContentAs() methods cannot be called on an element that has child elements.";

	public const string Xml_MixingReadValueChunkWithBinary = "ReadValueChunk calls cannot be mixed with ReadContentAsBase64 or ReadContentAsBinHex.";

	public const string Xml_MixingBinaryContentMethods = "ReadContentAsBase64 and ReadContentAsBinHex method calls cannot be mixed with calls to ReadElementContentAsBase64 and ReadElementContentAsBinHex.";

	public const string Xml_MixingV1StreamingWithV2Binary = "ReadContentAsBase64 and ReadContentAsBinHex method calls cannot be mixed with calls to ReadChars, ReadBase64, and ReadBinHex.";

	public const string Xml_InvalidReadValueChunk = "The ReadValueAsChunk method is not supported on node type {0}.";

	public const string Xml_ReadContentAsFormatException = "Content cannot be converted to the type {0}.";

	public const string Xml_DoubleBaseUri = "BaseUri must be specified either as an argument of XmlReader.Create or on the XmlParserContext. If it is specified on both, it must be the same base URI.";

	public const string Xml_NotEnoughSpaceForSurrogatePair = "The buffer is not large enough to fit a surrogate pair. Please provide a buffer of size at least 2 characters.";

	public const string Xml_EmptyUrl = "The URL cannot be empty.";

	public const string Xml_UnexpectedNodeInSimpleContent = "Unexpected node type {0}. {1} method can only be called on elements with simple or empty content.";

	public const string Xml_InvalidWhitespaceCharacter = "The Whitespace or SignificantWhitespace node can contain only XML whitespace characters. '{0}' is not an XML white space character.";

	public const string Xml_IncompatibleConformanceLevel = "Cannot change conformance checking to {0}. Make sure the ConformanceLevel in XmlReaderSettings is set to Auto for wrapping scenarios.";

	public const string Xml_LimitExceeded = "The input document has exceeded a limit set by {0}.";

	public const string Xml_ClosedOrErrorReader = "The XmlReader is closed or in error state.";

	public const string Xml_CharEntityOverflow = "Invalid value of a character entity reference.";

	public const string Xml_BadNameCharWithPos = "The '{0}' character, hexadecimal value {1}, at position {2} within the name, cannot be included in a name.";

	public const string Xml_XmlnsBelongsToReservedNs = "The 'xmlns' attribute is bound to the reserved namespace 'http://www.w3.org/2000/xmlns/'.";

	public const string Xml_UndeclaredParEntity = "Reference to undeclared parameter entity '{0}'.";

	public const string Xml_InvalidXmlDocument = "Invalid XML document. {0}";

	public const string Xml_NoDTDPresent = "No DTD found.";

	public const string Xml_MultipleValidaitonTypes = "Unsupported combination of validation types.";

	public const string Xml_NoValidation = "No validation occurred.";

	public const string Xml_WhitespaceHandling = "Expected WhitespaceHandling.None, or WhitespaceHandling.All, or WhitespaceHandling.Significant.";

	public const string Xml_InvalidResetStateCall = "Cannot call ResetState when parsing an XML fragment.";

	public const string Xml_EntityHandling = "Expected EntityHandling.ExpandEntities or EntityHandling.ExpandCharEntities.";

	public const string Xml_AttlistDuplEnumValue = "'{0}' is a duplicate enumeration value.";

	public const string Xml_AttlistDuplNotationValue = "'{0}' is a duplicate notation value.";

	public const string Xml_EncodingSwitchAfterResetState = "'{0}' is an invalid value for the 'encoding' attribute. The encoding cannot be switched after a call to ResetState.";

	public const string Xml_UnexpectedNodeType = "Unexpected XmlNodeType: '{0}'.";

	public const string Xml_InvalidConditionalSection = "A conditional section is not allowed in an internal subset.";

	public const string Xml_UnexpectedCDataEnd = "']]>' is not expected.";

	public const string Xml_UnclosedConditionalSection = "There is an unclosed conditional section.";

	public const string Xml_ExpectDtdMarkup = "Expected DTD markup was not found.";

	public const string Xml_IncompleteDtdContent = "Incomplete DTD content.";

	public const string Xml_EnumerationRequired = "Enumeration data type required.";

	public const string Xml_InvalidContentModel = "Invalid content model.";

	public const string Xml_FragmentId = "Fragment identifier '{0}' cannot be part of the system identifier '{1}'.";

	public const string Xml_ExpectPcData = "Expecting 'PCDATA'.";

	public const string Xml_ExpectNoWhitespace = "Whitespace not allowed before '?', '*', or '+'.";

	public const string Xml_ExpectOp = "Expecting '?', '*', or '+'.";

	public const string Xml_InvalidAttributeType = "'{0}' is an invalid attribute type.";

	public const string Xml_InvalidAttributeType1 = "Invalid attribute type.";

	public const string Xml_ExpectAttType = "Expecting an attribute type.";

	public const string Xml_ColonInLocalName = "'{0}' is an unqualified name and cannot contain the character ':'.";

	public const string Xml_InvalidParEntityRef = "A parameter entity reference is not allowed in internal markup.";

	public const string Xml_ExpectSubOrClose = "Expecting an internal subset or the end of the DOCTYPE declaration.";

	public const string Xml_ExpectExternalOrPublicId = "Expecting a system identifier or a public identifier.";

	public const string Xml_ExpectExternalIdOrEntityValue = "Expecting an external identifier or an entity value.";

	public const string Xml_ExpectIgnoreOrInclude = "Conditional sections must specify the keyword 'IGNORE' or 'INCLUDE'.";

	public const string Xml_UnsupportedClass = "Object type is not supported.";

	public const string Xml_NullResolver = "Resolving of external URIs was prohibited.";

	public const string Xml_RelativeUriNotSupported = "Relative URIs are not supported.";

	public const string Xml_WriterAsyncNotSetException = "Set XmlWriterSettings.Async to true if you want to use Async Methods.";

	public const string Xml_PrefixForEmptyNs = "Cannot use a prefix with an empty namespace.";

	public const string Xml_InvalidCommentChars = "An XML comment cannot contain '--', and '-' cannot be the last character.";

	public const string Xml_UndefNamespace = "The '{0}' namespace is not defined.";

	public const string Xml_EmptyName = "The empty string '' is not a valid name.";

	public const string Xml_EmptyLocalName = "The empty string '' is not a valid local name.";

	public const string Xml_InvalidNameCharsDetail = "Invalid name character in '{0}'. The '{1}' character, hexadecimal value {2}, cannot be included in a name.";

	public const string Xml_NoStartTag = "There was no XML start tag open.";

	public const string Xml_ClosedOrError = "The Writer is closed or in error state.";

	public const string Xml_WrongToken = "Token {0} in state {1} would result in an invalid XML document.";

	public const string Xml_XmlPrefix = "Prefix \"xml\" is reserved for use by XML and can be mapped only to namespace name \"http://www.w3.org/XML/1998/namespace\".";

	public const string Xml_XmlnsPrefix = "Prefix \"xmlns\" is reserved for use by XML.";

	public const string Xml_NamespaceDeclXmlXmlns = "Prefix '{0}' cannot be mapped to namespace name reserved for \"xml\" or \"xmlns\".";

	public const string Xml_NonWhitespace = "Only whitespace characters should be used.";

	public const string Xml_DupXmlDecl = "Cannot write XML declaration. WriteStartDocument method has already written it.";

	public const string Xml_CannotWriteXmlDecl = "Cannot write XML declaration. XML declaration can be only at the beginning of the document.";

	public const string Xml_NoRoot = "Document does not have a root element.";

	public const string Xml_InvalidPosition = "The current position on the Reader is neither an element nor an attribute.";

	public const string Xml_IncompleteEntity = "Incomplete entity contents.";

	public const string Xml_InvalidSurrogateHighChar = "Invalid high surrogate character (0x{0}). A high surrogate character must have a value from range (0xD800 - 0xDBFF).";

	public const string Xml_InvalidSurrogateMissingLowChar = "The surrogate pair is invalid. Missing a low surrogate character.";

	public const string Xml_InvalidSurrogatePairWithArgs = "The surrogate pair (0x{0}, 0x{1}) is invalid. A high surrogate character (0xD800 - 0xDBFF) must always be paired with a low surrogate character (0xDC00 - 0xDFFF).";

	public const string Xml_RedefinePrefix = "The prefix '{0}' cannot be redefined from '{1}' to '{2}' within the same start element tag.";

	public const string Xml_DtdAlreadyWritten = "The DTD has already been written out.";

	public const string Xml_InvalidCharsInIndent = "XmlWriterSettings.{0} can contain only valid XML text content characters when XmlWriterSettings.CheckCharacters is true. {1}";

	public const string Xml_IndentCharsNotWhitespace = "XmlWriterSettings.{0} can contain only valid XML whitespace characters when XmlWriterSettings.CheckCharacters and XmlWriterSettings.NewLineOnAttributes are true.";

	public const string Xml_ConformanceLevelFragment = "Make sure that the ConformanceLevel setting is set to ConformanceLevel.Fragment or ConformanceLevel.Auto if you want to write an XML fragment. ";

	public const string Xml_InvalidQuote = "Invalid XML attribute quote character. Valid attribute quote characters are ' and \".";

	public const string Xml_UndefPrefix = "An undefined prefix is in use.";

	public const string Xml_NoNamespaces = "Cannot set the namespace if Namespaces is 'false'.";

	public const string Xml_InvalidCDataChars = "Cannot have ']]>' inside an XML CDATA block.";

	public const string Xml_NotTheFirst = "WriteStartDocument needs to be the first call.";

	public const string Xml_InvalidPiChars = "Cannot have '?>' inside an XML processing instruction.";

	public const string Xml_InvalidNameChars = "Invalid name character in '{0}'.";

	public const string Xml_Closed = "The Writer is closed.";

	public const string Xml_InvalidPrefix = "Prefixes beginning with \"xml\" (regardless of whether the characters are uppercase, lowercase, or some combination thereof) are reserved for use by XML.";

	public const string Xml_InvalidIndentation = "Indentation value must be greater than 0.";

	public const string Xml_NotInWriteState = "NotInWriteState.";

	public const string Xml_SurrogatePairSplit = "The second character surrogate pair is not in the input buffer to be written.";

	public const string Xml_NoMultipleRoots = "Document cannot have multiple document elements.";

	public const string XmlBadName = "A node of type '{0}' cannot have the name '{1}'.";

	public const string XmlNoNameAllowed = "A node of type '{0}' cannot have a name.";

	public const string XmlConvert_BadUri = "The string was not recognized as a valid Uri.";

	public const string XmlConvert_BadFormat = "The string '{0}' is not a valid {1} value.";

	public const string XmlConvert_Overflow = "Value '{0}' was either too large or too small for {1}.";

	public const string XmlConvert_TypeBadMapping = "Xml type '{0}' does not support Clr type '{1}'.";

	public const string XmlConvert_TypeBadMapping2 = "Xml type '{0}' does not support a conversion from Clr type '{1}' to Clr type '{2}'.";

	public const string XmlConvert_TypeListBadMapping = "Xml type 'List of {0}' does not support Clr type '{1}'.";

	public const string XmlConvert_TypeListBadMapping2 = "Xml type 'List of {0}' does not support a conversion from Clr type '{1}' to Clr type '{2}'.";

	public const string XmlConvert_TypeToString = "Xml type '{0}' cannot convert from Clr type '{1}' unless the destination type is String or XmlAtomicValue.";

	public const string XmlConvert_TypeFromString = "Xml type '{0}' cannot convert to Clr type '{1}' unless the source value is a String or an XmlAtomicValue.";

	public const string XmlConvert_TypeNoPrefix = "The QName '{0}' cannot be represented as a String.  A prefix for namespace '{1}' cannot be found.";

	public const string XmlConvert_TypeNoNamespace = "The String '{0}' cannot be represented as an XmlQualifiedName.  A namespace for prefix '{1}' cannot be found.";

	public const string XmlConvert_NotOneCharString = "String must be exactly one character long.";

	public const string Sch_ParEntityRefNesting = "The parameter entity replacement text must nest properly within markup declarations.";

	public const string Sch_NotTokenString = "line-feed (#xA) or tab (#x9) characters, leading or trailing spaces and sequences of one or more spaces (#x20) are not allowed in 'xs:token'.";

	public const string Sch_InvalidDateTimeOption = "The '{0}' value for the 'dateTimeOption' parameter is not an allowed value for the 'XmlDateTimeSerializationMode' enumeration.";

	public const string Sch_StandAloneNormalization = "StandAlone is 'yes' and the value of the attribute '{0}' contains a definition in an external document that changes on normalization.";

	public const string Sch_UnSpecifiedDefaultAttributeInExternalStandalone = "Markup for unspecified default attribute '{0}' is external and standalone='yes'.";

	public const string Sch_DefaultException = "A schema error occurred.";

	public const string Sch_DupElementDecl = "The '{0}' element has already been declared.";

	public const string Sch_IdAttrDeclared = "The attribute of type ID is already declared on the '{0}' element.";

	public const string Sch_RootMatchDocType = "Root element name must match the DocType name.";

	public const string Sch_DupId = "'{0}' is already used as an ID.";

	public const string Sch_UndeclaredElement = "The '{0}' element is not declared.";

	public const string Sch_UndeclaredAttribute = "The '{0}' attribute is not declared.";

	public const string Sch_UndeclaredNotation = "The '{0}' notation is not declared.";

	public const string Sch_UndeclaredId = "Reference to undeclared ID is '{0}'.";

	public const string Sch_SchemaRootExpected = "Expected schema root. Make sure the root element is <schema> and the namespace is 'http://www.w3.org/2001/XMLSchema' for an XSD schema or 'urn:schemas-microsoft-com:xml-data' for an XDR schema.";

	public const string Sch_XSDSchemaRootExpected = "The root element of a W3C XML Schema should be <schema> and its namespace should be 'http://www.w3.org/2001/XMLSchema'.";

	public const string Sch_UnsupportedAttribute = "The '{0}' attribute is not supported in this context.";

	public const string Sch_UnsupportedElement = "The '{0}' element is not supported in this context.";

	public const string Sch_MissAttribute = "The '{0}' attribute is either invalid or missing.";

	public const string Sch_AnnotationLocation = "The 'annotation' element cannot appear at this location.";

	public const string Sch_DataTypeTextOnly = "Content must be \"textOnly\" when using DataType on an ElementType.";

	public const string Sch_UnknownModel = "The model attribute must have a value of open or closed, not '{0}'.";

	public const string Sch_UnknownOrder = "The order attribute must have a value of 'seq', 'one', or 'many', not '{0}'.";

	public const string Sch_UnknownContent = "The content attribute must have a value of 'textOnly', 'eltOnly', 'mixed', or 'empty', not '{0}'.";

	public const string Sch_UnknownRequired = "The required attribute must have a value of yes or no.";

	public const string Sch_UnknownDtType = "Reference to an unknown data type, '{0}'.";

	public const string Sch_MixedMany = "The order must be many when content is mixed.";

	public const string Sch_GroupDisabled = "The group is not allowed when ElementType has empty or textOnly content.";

	public const string Sch_MissDtvalue = "The DataType value cannot be empty.";

	public const string Sch_MissDtvaluesAttribute = "The dt:values attribute is missing.";

	public const string Sch_DupDtType = "Data type has already been declared.";

	public const string Sch_DupAttribute = "The '{0}' attribute has already been declared for this ElementType.";

	public const string Sch_RequireEnumeration = "Data type should be enumeration when the values attribute is present.";

	public const string Sch_DefaultIdValue = "An attribute or element of type xs:ID or derived from xs:ID, should not have a value constraint.";

	public const string Sch_ElementNotAllowed = "Element is not allowed when the content is empty or textOnly.";

	public const string Sch_ElementMissing = "There is a missing element.";

	public const string Sch_ManyMaxOccurs = "When the order is many, the maxOccurs attribute must have a value of '*'.";

	public const string Sch_MaxOccursInvalid = "The maxOccurs attribute must have a value of 1 or *.";

	public const string Sch_MinOccursInvalid = "The minOccurs attribute must have a value of 0 or 1.";

	public const string Sch_DtMaxLengthInvalid = "The value '{0}' is invalid for dt:maxLength.";

	public const string Sch_DtMinLengthInvalid = "The value '{0}' is invalid for dt:minLength.";

	public const string Sch_DupDtMaxLength = "The value of maxLength has already been declared.";

	public const string Sch_DupDtMinLength = "The value of minLength has already been declared.";

	public const string Sch_DtMinMaxLength = "The maxLength value must be equal to or greater than the minLength value.";

	public const string Sch_DupElement = "The '{0}' element already exists in the content model.";

	public const string Sch_DupGroupParticle = "The content model can only have one of the following; 'all', 'choice', or 'sequence'.";

	public const string Sch_InvalidValue = "The value '{0}' is invalid according to its data type.";

	public const string Sch_InvalidValueDetailed = "The value '{0}' is invalid according to its schema type '{1}' - {2}";

	public const string Sch_InvalidValueDetailedAttribute = "The attribute '{0}' has an invalid value '{1}' according to its schema type '{2}' - {3}";

	public const string Sch_MissRequiredAttribute = "The required attribute '{0}' is missing.";

	public const string Sch_FixedAttributeValue = "The value of the '{0}' attribute does not equal its fixed value.";

	public const string Sch_FixedElementValue = "The value of the '{0}' element does not equal its fixed value.";

	public const string Sch_AttributeValueDataTypeDetailed = "The '{0}' attribute is invalid - The value '{1}' is invalid according to its datatype '{2}' - {3}";

	public const string Sch_AttributeDefaultDataType = "The default value of '{0}' attribute is invalid according to its datatype.";

	public const string Sch_IncludeLocation = "The 'include' element cannot appear at this location.";

	public const string Sch_ImportLocation = "The 'import' element cannot appear at this location.";

	public const string Sch_RedefineLocation = "The 'redefine' element cannot appear at this location.";

	public const string Sch_InvalidBlockDefaultValue = "The values 'list' and 'union' are invalid for the blockDefault attribute.";

	public const string Sch_InvalidFinalDefaultValue = "The value 'substitution' is invalid for the finalDefault attribute.";

	public const string Sch_InvalidElementBlockValue = "The values 'list' and 'union' are invalid for the block attribute on element.";

	public const string Sch_InvalidElementFinalValue = "The values 'substitution', 'list', and 'union' are invalid for the final attribute on element.";

	public const string Sch_InvalidSimpleTypeFinalValue = "The values 'substitution' and 'extension' are invalid for the final attribute on simpleType.";

	public const string Sch_InvalidComplexTypeBlockValue = "The values 'substitution', 'list', and 'union' are invalid for the block attribute on complexType.";

	public const string Sch_InvalidComplexTypeFinalValue = "The values 'substitution', 'list', and 'union' are invalid for the final attribute on complexType.";

	public const string Sch_DupIdentityConstraint = "The identity constraint '{0}' has already been declared.";

	public const string Sch_DupGlobalElement = "The global element '{0}' has already been declared.";

	public const string Sch_DupGlobalAttribute = "The global attribute '{0}' has already been declared.";

	public const string Sch_DupSimpleType = "The simpleType '{0}' has already been declared.";

	public const string Sch_DupComplexType = "The complexType '{0}' has already been declared.";

	public const string Sch_DupGroup = "The group '{0}' has already been declared.";

	public const string Sch_DupAttributeGroup = "The attributeGroup '{0}' has already been declared.";

	public const string Sch_DupNotation = "The notation '{0}' has already been declared.";

	public const string Sch_DefaultFixedAttributes = "The fixed and default attributes cannot both be present.";

	public const string Sch_FixedInRef = "The fixed value constraint on the '{0}' attribute reference must match the fixed value constraint on the declaration.";

	public const string Sch_FixedDefaultInRef = "The default value constraint cannot be present on the '{0}' attribute reference if the fixed value constraint is present on the declaration.";

	public const string Sch_DupXsdElement = "'{0}' is a duplicate XSD element.";

	public const string Sch_ForbiddenAttribute = "The '{0}' attribute cannot be present.";

	public const string Sch_AttributeIgnored = "The '{0}' attribute is ignored, because the value of 'prohibited' for attribute use only prevents inheritance of an identically named attribute from the base type definition.";

	public const string Sch_ElementRef = "When the ref attribute is present, the type attribute and complexType, simpleType, key, keyref, and unique elements cannot be present.";

	public const string Sch_TypeMutualExclusive = "The type attribute cannot be present with either simpleType or complexType.";

	public const string Sch_ElementNameRef = "For element declaration, either the name or the ref attribute must be present.";

	public const string Sch_AttributeNameRef = "For attribute '{0}', either the name or the ref attribute must be present, but not both.";

	public const string Sch_TextNotAllowed = "The following text is not allowed in this context: '{0}'.";

	public const string Sch_UndeclaredType = "Type '{0}' is not declared.";

	public const string Sch_UndeclaredSimpleType = "Type '{0}' is not declared, or is not a simple type.";

	public const string Sch_UndeclaredEquivClass = "Substitution group refers to '{0}', an undeclared element.";

	public const string Sch_AttListPresence = "An attribute of type ID must have a declared default of either #IMPLIED or #REQUIRED.";

	public const string Sch_NotationValue = "'{0}' is not in the notation list.";

	public const string Sch_EnumerationValue = "'{0}' is not in the enumeration list.";

	public const string Sch_EmptyAttributeValue = "The attribute value cannot be empty.";

	public const string Sch_InvalidLanguageId = "'{0}' is an invalid language identifier.";

	public const string Sch_XmlSpace = "Invalid xml:space syntax.";

	public const string Sch_InvalidXsdAttributeValue = "'{1}' is an invalid value for the '{0}' attribute.";

	public const string Sch_InvalidXsdAttributeDatatypeValue = "The value for the '{0}' attribute is invalid - {1}";

	public const string Sch_ElementValueDataTypeDetailed = "The '{0}' element is invalid - The value '{1}' is invalid according to its datatype '{2}' - {3}";

	public const string Sch_InvalidElementDefaultValue = "The default value '{0}' of element '{1}' is invalid according to the type specified by xsi:type.";

	public const string Sch_NonDeterministic = "Multiple definition of element '{0}' causes the content model to become ambiguous. A content model must be formed such that during validation of an element information item sequence, the particle contained directly, indirectly or implicitly therein with which to attempt to validate each item in the sequence in turn can be uniquely determined without examining the content or attributes of that item, and without any information about the items in the remainder of the sequence.";

	public const string Sch_NonDeterministicAnyEx = "Wildcard '{0}' allows element '{1}', and causes the content model to become ambiguous. A content model must be formed such that during validation of an element information item sequence, the particle contained directly, indirectly or implicitly therein with which to attempt to validate each item in the sequence in turn can be uniquely determined without examining the content or attributes of that item, and without any information about the items in the remainder of the sequence.";

	public const string Sch_NonDeterministicAnyAny = "Wildcards '{0}' and '{1}' have not empty intersection, and causes the content model to become ambiguous. A content model must be formed such that during validation of an element information item sequence, the particle contained directly, indirectly or implicitly therein with which to attempt to validate each item in the sequence in turn can be uniquely determined without examining the content or attributes of that item, and without any information about the items in the remainder of the sequence.";

	public const string Sch_StandAlone = "The standalone document declaration must have a value of 'no'.";

	public const string Sch_XmlNsAttribute = "The value 'xmlns' cannot be used as the name of an attribute declaration.";

	public const string Sch_AllElement = "Element '{0}' cannot appear more than once if content model type is \"all\".";

	public const string Sch_MismatchTargetNamespaceInclude = "The targetNamespace '{0}' of included/redefined schema should be the same as the targetNamespace '{1}' of the including schema.";

	public const string Sch_MismatchTargetNamespaceImport = "The namespace attribute '{0}' of an import should be the same value as the targetNamespace '{1}' of the imported schema.";

	public const string Sch_MismatchTargetNamespaceEx = "The targetNamespace parameter '{0}' should be the same value as the targetNamespace '{1}' of the schema.";

	public const string Sch_XsiTypeNotFound = "This is an invalid xsi:type '{0}'.";

	public const string Sch_XsiTypeAbstract = "The xsi:type '{0}' cannot be abstract.";

	public const string Sch_ListFromNonatomic = "A list data type must be derived from an atomic or union data type.";

	public const string Sch_UnionFromUnion = "It is an error if a union type has a member with variety union and this member cannot be substituted with its own members. This may be due to the fact that the union member is a restriction of a union with facets.";

	public const string Sch_DupLengthFacet = "This is a duplicate Length constraining facet.";

	public const string Sch_DupMinLengthFacet = "This is a duplicate MinLength constraining facet.";

	public const string Sch_DupMaxLengthFacet = "This is a duplicate MaxLength constraining facet.";

	public const string Sch_DupWhiteSpaceFacet = "This is a duplicate WhiteSpace constraining facet.";

	public const string Sch_DupMaxInclusiveFacet = "This is a duplicate MaxInclusive constraining facet.";

	public const string Sch_DupMaxExclusiveFacet = "This is a duplicate MaxExclusive constraining facet.";

	public const string Sch_DupMinInclusiveFacet = "This is a duplicate MinInclusive constraining facet.";

	public const string Sch_DupMinExclusiveFacet = "This is a duplicate MinExclusive constraining facet.";

	public const string Sch_DupTotalDigitsFacet = "This is a duplicate TotalDigits constraining facet.";

	public const string Sch_DupFractionDigitsFacet = "This is a duplicate FractionDigits constraining facet.";

	public const string Sch_LengthFacetProhibited = "The length constraining facet is prohibited for '{0}'.";

	public const string Sch_MinLengthFacetProhibited = "The MinLength constraining facet is prohibited for '{0}'.";

	public const string Sch_MaxLengthFacetProhibited = "The MaxLength constraining facet is prohibited for '{0}'.";

	public const string Sch_PatternFacetProhibited = "The Pattern constraining facet is prohibited for '{0}'.";

	public const string Sch_EnumerationFacetProhibited = "The Enumeration constraining facet is prohibited for '{0}'.";

	public const string Sch_WhiteSpaceFacetProhibited = "The WhiteSpace constraining facet is prohibited for '{0}'.";

	public const string Sch_MaxInclusiveFacetProhibited = "The MaxInclusive constraining facet is prohibited for '{0}'.";

	public const string Sch_MaxExclusiveFacetProhibited = "The MaxExclusive constraining facet is prohibited for '{0}'.";

	public const string Sch_MinInclusiveFacetProhibited = "The MinInclusive constraining facet is prohibited for '{0}'.";

	public const string Sch_MinExclusiveFacetProhibited = "The MinExclusive constraining facet is prohibited for '{0}'.";

	public const string Sch_TotalDigitsFacetProhibited = "The TotalDigits constraining facet is prohibited for '{0}'.";

	public const string Sch_FractionDigitsFacetProhibited = "The FractionDigits constraining facet is prohibited for '{0}'.";

	public const string Sch_LengthFacetInvalid = "The Length constraining facet is invalid - {0}";

	public const string Sch_MinLengthFacetInvalid = "The MinLength constraining facet is invalid - {0}";

	public const string Sch_MaxLengthFacetInvalid = "The MaxLength constraining facet is invalid - {0}";

	public const string Sch_MaxInclusiveFacetInvalid = "The MaxInclusive constraining facet is invalid - {0}";

	public const string Sch_MaxExclusiveFacetInvalid = "The MaxExclusive constraining facet is invalid - {0}";

	public const string Sch_MinInclusiveFacetInvalid = "The MinInclusive constraining facet is invalid - {0}";

	public const string Sch_MinExclusiveFacetInvalid = "The MinExclusive constraining facet is invalid - {0}";

	public const string Sch_TotalDigitsFacetInvalid = "The TotalDigits constraining facet is invalid - {0}";

	public const string Sch_FractionDigitsFacetInvalid = "The FractionDigits constraining facet is invalid - {0}";

	public const string Sch_PatternFacetInvalid = "The Pattern constraining facet is invalid - {0}";

	public const string Sch_EnumerationFacetInvalid = "The Enumeration constraining facet is invalid - {0}";

	public const string Sch_InvalidWhiteSpace = "The whitespace character, '{0}', is invalid.";

	public const string Sch_UnknownFacet = "This is an unknown facet.";

	public const string Sch_LengthAndMinMax = "It is an error for both length and minLength or maxLength to be present.";

	public const string Sch_MinLengthGtMaxLength = "MinLength is greater than MaxLength.";

	public const string Sch_FractionDigitsGtTotalDigits = "FractionDigits is greater than TotalDigits.";

	public const string Sch_LengthConstraintFailed = "The actual length is not equal to the specified length.";

	public const string Sch_MinLengthConstraintFailed = "The actual length is less than the MinLength value.";

	public const string Sch_MaxLengthConstraintFailed = "The actual length is greater than the MaxLength value.";

	public const string Sch_PatternConstraintFailed = "The Pattern constraint failed.";

	public const string Sch_EnumerationConstraintFailed = "The Enumeration constraint failed.";

	public const string Sch_MaxInclusiveConstraintFailed = "The MaxInclusive constraint failed.";

	public const string Sch_MaxExclusiveConstraintFailed = "The MaxExclusive constraint failed.";

	public const string Sch_MinInclusiveConstraintFailed = "The MinInclusive constraint failed.";

	public const string Sch_MinExclusiveConstraintFailed = "The MinExclusive constraint failed.";

	public const string Sch_TotalDigitsConstraintFailed = "The TotalDigits constraint failed.";

	public const string Sch_FractionDigitsConstraintFailed = "The FractionDigits constraint failed.";

	public const string Sch_UnionFailedEx = "The value '{0}' is not valid according to any of the memberTypes of the union.";

	public const string Sch_NotationRequired = "NOTATION cannot be used directly in a schema; only data types derived from NOTATION by specifying an enumeration value can be used in a schema. All enumeration facet values must match the name of a notation declared in the current schema.";

	public const string Sch_DupNotationAttribute = "No element type can have more than one NOTATION attribute specified.";

	public const string Sch_MissingPublicSystemAttribute = "NOTATION must have either the Public or System attribute present.";

	public const string Sch_NotationAttributeOnEmptyElement = "An attribute of type NOTATION must not be declared on an element declared EMPTY.";

	public const string Sch_RefNotInScope = "The Keyref '{0}' cannot find the referred key or unique in scope.";

	public const string Sch_UndeclaredIdentityConstraint = "The '{0}' identity constraint is not declared.";

	public const string Sch_RefInvalidIdentityConstraint = "Reference to an invalid identity constraint, '{0}'.";

	public const string Sch_RefInvalidCardin = "Keyref '{0}' has different cardinality as the referred key or unique element.";

	public const string Sch_ReftoKeyref = "The '{0}' Keyref can refer to key or unique only.";

	public const string Sch_EmptyXPath = "The XPath for selector or field cannot be empty.";

	public const string Sch_UnresolvedPrefix = "The prefix '{0}' in XPath cannot be resolved.";

	public const string Sch_UnresolvedKeyref = "The key sequence '{0}' in '{1}' Keyref fails to refer to some key.";

	public const string Sch_ICXpathError = "'{0}' is an invalid XPath for selector or field.";

	public const string Sch_SelectorAttr = "'{0}' is an invalid XPath for selector. Selector cannot have an XPath selection with an attribute node.";

	public const string Sch_FieldSimpleTypeExpected = "The field '{0}' is expecting an element or attribute with simple type or simple content.";

	public const string Sch_FieldSingleValueExpected = "The field '{0}' is expecting at the most one value.";

	public const string Sch_MissingKey = "The identity constraint '{0}' validation has failed. Either a key is missing or the existing key has an empty node.";

	public const string Sch_DuplicateKey = "There is a duplicate key sequence '{0}' for the '{1}' key or unique identity constraint.";

	public const string Sch_TargetNamespaceXsi = "The target namespace of an attribute declaration, whether local or global, must not match http://www.w3.org/2001/XMLSchema-instance.";

	public const string Sch_UndeclaredEntity = "Reference to an undeclared entity, '{0}'.";

	public const string Sch_UnparsedEntityRef = "Reference to an unparsed entity, '{0}'.";

	public const string Sch_MaxOccursInvalidXsd = "The value for the 'maxOccurs' attribute must be xsd:nonNegativeInteger or 'unbounded'.";

	public const string Sch_MinOccursInvalidXsd = "The value for the 'minOccurs' attribute must be xsd:nonNegativeInteger.";

	public const string Sch_MaxInclusiveExclusive = "'maxInclusive' and 'maxExclusive' cannot both be specified for the same data type.";

	public const string Sch_MinInclusiveExclusive = "'minInclusive' and 'minExclusive' cannot both be specified for the same data type.";

	public const string Sch_MinInclusiveGtMaxInclusive = "The value specified for 'minInclusive' cannot be greater than the value specified for 'maxInclusive' for the same data type.";

	public const string Sch_MinExclusiveGtMaxExclusive = "The value specified for 'minExclusive' cannot be greater than the value specified for 'maxExclusive' for the same data type.";

	public const string Sch_MinInclusiveGtMaxExclusive = "The value specified for 'minInclusive' cannot be greater than the value specified for 'maxExclusive' for the same data type.";

	public const string Sch_MinExclusiveGtMaxInclusive = "The value specified for 'minExclusive' cannot be greater than the value specified for 'maxInclusive' for the same data type.";

	public const string Sch_SimpleTypeRestriction = "'simpleType' should be the first child of restriction.";

	public const string Sch_InvalidFacetPosition = "Facet should go before 'attribute', 'attributeGroup', or 'anyAttribute'.";

	public const string Sch_AttributeMutuallyExclusive = "'{0}' and content model are mutually exclusive.";

	public const string Sch_AnyAttributeLastChild = "'anyAttribute' must be the last child.";

	public const string Sch_ComplexTypeContentModel = "The content model of a complex type must consist of 'annotation' (if present); followed by zero or one of the following: 'simpleContent', 'complexContent', 'group', 'choice', 'sequence', or 'all'; followed by zero or more 'attribute' or 'attributeGroup'; followed by zero or one 'anyAttribute'.";

	public const string Sch_ComplexContentContentModel = "Complex content restriction or extension should consist of zero or one of 'group', 'choice', 'sequence', or 'all'; followed by zero or more 'attribute' or 'attributeGroup'; followed by zero or one 'anyAttribute'.";

	public const string Sch_NotNormalizedString = "Carriage return (#xD), line feed (#xA), and tab (#x9) characters are not allowed in xs:normalizedString.";

	public const string Sch_FractionDigitsNotOnDecimal = "FractionDigits should be equal to 0 on types other then decimal.";

	public const string Sch_ContentInNill = "Element '{0}' must have no character or element children.";

	public const string Sch_NoElementSchemaFound = "Could not find schema information for the element '{0}'.";

	public const string Sch_NoAttributeSchemaFound = "Could not find schema information for the attribute '{0}'.";

	public const string Sch_InvalidNamespace = "The Namespace '{0}' is an invalid URI.";

	public const string Sch_InvalidTargetNamespaceAttribute = "The targetNamespace attribute cannot have empty string as its value.";

	public const string Sch_InvalidNamespaceAttribute = "The namespace attribute cannot have empty string as its value.";

	public const string Sch_InvalidSchemaLocation = "The SchemaLocation '{0}' is an invalid URI.";

	public const string Sch_ImportTargetNamespace = "Namespace attribute of an import must not match the real value of the enclosing targetNamespace of the <schema>.";

	public const string Sch_ImportTargetNamespaceNull = "The enclosing <schema> must have a targetNamespace, if the Namespace attribute is absent on the import element.";

	public const string Sch_GroupDoubleRedefine = "Double redefine for group.";

	public const string Sch_ComponentRedefineNotFound = "Cannot find a {0} with name '{1}' to redefine.";

	public const string Sch_GroupRedefineNotFound = "No group to redefine.";

	public const string Sch_AttrGroupDoubleRedefine = "Double redefine for attribute group.";

	public const string Sch_AttrGroupRedefineNotFound = "No attribute group to redefine.";

	public const string Sch_ComplexTypeDoubleRedefine = "Double redefine for complex type.";

	public const string Sch_ComplexTypeRedefineNotFound = "No complex type to redefine.";

	public const string Sch_SimpleToComplexTypeRedefine = "Cannot redefine a simple type as complex type.";

	public const string Sch_SimpleTypeDoubleRedefine = "Double redefine for simple type.";

	public const string Sch_ComplexToSimpleTypeRedefine = "Cannot redefine a complex type as simple type.";

	public const string Sch_SimpleTypeRedefineNotFound = "No simple type to redefine.";

	public const string Sch_MinMaxGroupRedefine = "When group is redefined, the real value of both minOccurs and maxOccurs attribute must be 1 (or absent).";

	public const string Sch_MultipleGroupSelfRef = "Multiple self-reference within a group is redefined.";

	public const string Sch_MultipleAttrGroupSelfRef = "Multiple self-reference within an attribute group is redefined.";

	public const string Sch_InvalidTypeRedefine = "If type is being redefined, the base type has to be self-referenced.";

	public const string Sch_InvalidElementRef = "If ref is present, all of <complexType>, <simpleType>, <key>, <keyref>, <unique>, nillable, default, fixed, form, block, and type must be absent.";

	public const string Sch_MinGtMax = "minOccurs value cannot be greater than maxOccurs value.";

	public const string Sch_DupSelector = "Selector cannot appear twice in one identity constraint.";

	public const string Sch_IdConstraintNoSelector = "Selector must be present.";

	public const string Sch_IdConstraintNoFields = "At least one field must be present.";

	public const string Sch_IdConstraintNoRefer = "The referring attribute must be present.";

	public const string Sch_SelectorBeforeFields = "Cannot define fields before selector.";

	public const string Sch_NoSimpleTypeContent = "SimpleType content is missing.";

	public const string Sch_SimpleTypeRestRefBase = "SimpleType restriction should have either the base attribute or a simpleType child, but not both.";

	public const string Sch_SimpleTypeRestRefBaseNone = "SimpleType restriction should have either the base attribute or a simpleType child to indicate the base type for the derivation.";

	public const string Sch_SimpleTypeListRefBase = "SimpleType list should have either the itemType attribute or a simpleType child, but not both.";

	public const string Sch_SimpleTypeListRefBaseNone = "SimpleType list should have either the itemType attribute or a simpleType child to indicate the itemType of the list. ";

	public const string Sch_SimpleTypeUnionNoBase = "Either the memberTypes attribute must be non-empty or there must be at least one simpleType child.";

	public const string Sch_NoRestOrExtQName = "'restriction' or 'extension' child is required for complexType '{0}' in namespace '{1}', because it has a simpleContent or complexContent child.";

	public const string Sch_NoRestOrExt = "'restriction' or 'extension' child is required for complexType with simpleContent or complexContent child.";

	public const string Sch_NoGroupParticle = "'sequence', 'choice', or 'all' child is required.";

	public const string Sch_InvalidAllMin = "'all' must have 'minOccurs' value of 0 or 1.";

	public const string Sch_InvalidAllMax = "'all' must have {max occurs}=1.";

	public const string Sch_InvalidFacet = "The 'value' attribute must be present in facet.";

	public const string Sch_AbstractElement = "The element '{0}' is abstract or its type is abstract.";

	public const string Sch_XsiTypeBlockedEx = "The xsi:type attribute value '{0}' is not valid for the element '{1}', either because it is not a type validly derived from the type in the schema, or because it has xsi:type derivation blocked.";

	public const string Sch_InvalidXsiNill = "If the 'nillable' attribute is false in the schema, the 'xsi:nil' attribute must not be present in the instance.";

	public const string Sch_SubstitutionNotAllowed = "Element '{0}' cannot substitute in place of head element '{1}' because it has block='substitution'.";

	public const string Sch_SubstitutionBlocked = "Member element {0}'s type cannot be derived by restriction or extension from head element {1}'s type, because it has block='restriction' or 'extension'.";

	public const string Sch_InvalidElementInEmptyEx = "The element '{0}' cannot contain child element '{1}' because the parent element's content model is empty.";

	public const string Sch_InvalidElementInTextOnlyEx = "The element '{0}' cannot contain child element '{1}' because the parent element's content model is text only.";

	public const string Sch_InvalidTextInElement = "The element {0} cannot contain text.";

	public const string Sch_InvalidElementContent = "The element {0} has invalid child element {1}.";

	public const string Sch_InvalidElementContentComplex = "The element {0} has invalid child element {1} - {2}";

	public const string Sch_IncompleteContent = "The element {0} has incomplete content.";

	public const string Sch_IncompleteContentComplex = "The element {0} has incomplete content - {2}";

	public const string Sch_InvalidTextInElementExpecting = "The element {0} cannot contain text. List of possible elements expected: {1}.";

	public const string Sch_InvalidElementContentExpecting = "The element {0} has invalid child element {1}. List of possible elements expected: {2}.";

	public const string Sch_InvalidElementContentExpectingComplex = "The element {0} has invalid child element {1}. List of possible elements expected: {2}. {3}";

	public const string Sch_IncompleteContentExpecting = "The element {0} has incomplete content. List of possible elements expected: {1}.";

	public const string Sch_IncompleteContentExpectingComplex = "The element {0} has incomplete content. List of possible elements expected: {1}. {2}";

	public const string Sch_InvalidElementSubstitution = "The element {0} cannot substitute for a local element {1} expected in that position.";

	public const string Sch_ElementNameAndNamespace = "'{0}' in namespace '{1}'";

	public const string Sch_ElementName = "'{0}'";

	public const string Sch_ContinuationString = "{0}as well as ";

	public const string Sch_AnyElementNS = "any element in namespace '{0}'";

	public const string Sch_AnyElement = "any element";

	public const string Sch_InvalidTextInEmpty = "The element cannot contain text. Content model is empty.";

	public const string Sch_InvalidWhitespaceInEmpty = "The element cannot contain whitespace. Content model is empty.";

	public const string Sch_InvalidPIComment = "The element cannot contain comment or processing instruction. Content model is empty.";

	public const string Sch_InvalidAttributeRef = "If ref is present, all of 'simpleType', 'form', 'type', and 'use' must be absent.";

	public const string Sch_OptionalDefaultAttribute = "The 'use' attribute must be optional (or absent) if the default attribute is present.";

	public const string Sch_AttributeCircularRef = "Circular attribute reference.";

	public const string Sch_IdentityConstraintCircularRef = "Circular identity constraint reference.";

	public const string Sch_SubstitutionCircularRef = "Circular substitution group affiliation.";

	public const string Sch_InvalidAnyAttribute = "Invalid namespace in 'anyAttribute'.";

	public const string Sch_DupIdAttribute = "Duplicate ID attribute.";

	public const string Sch_InvalidAllElementMax = "The {max occurs} of all the particles in the {particles} of an all group must be 0 or 1.";

	public const string Sch_InvalidAny = "Invalid namespace in 'any'.";

	public const string Sch_InvalidAnyDetailed = "The value of the namespace attribute of the element or attribute wildcard is invalid - {0}";

	public const string Sch_InvalidExamplar = "Cannot be nominated as the {substitution group affiliation} of any other declaration.";

	public const string Sch_NoExamplar = "Reference to undeclared substitution group affiliation.";

	public const string Sch_InvalidSubstitutionMember = "'{0}' cannot be a member of substitution group with head element '{1}'.";

	public const string Sch_RedefineNoSchema = "'SchemaLocation' must successfully resolve if <redefine> contains any child other than <annotation>.";

	public const string Sch_ProhibitedAttribute = "The '{0}' attribute is not allowed.";

	public const string Sch_TypeCircularRef = "Circular type reference.";

	public const string Sch_TwoIdAttrUses = "Two distinct members of the attribute uses must not have type definitions which are both xs:ID or are derived from xs:ID.";

	public const string Sch_AttrUseAndWildId = "It is an error if there is a member of the attribute uses of a type definition with type xs:ID or derived from xs:ID and another attribute with type xs:ID matches an attribute wildcard.";

	public const string Sch_MoreThanOneWildId = "It is an error if more than one attribute whose type is xs:ID or is derived from xs:ID, matches an attribute wildcard on an element.";

	public const string Sch_BaseFinalExtension = "The base type is the final extension.";

	public const string Sch_NotSimpleContent = "The content type of the base type must be a simple type definition or it must be mixed, and simpleType child must be present.";

	public const string Sch_NotComplexContent = "The content type of the base type must not be a simple type definition.";

	public const string Sch_BaseFinalRestriction = "The base type is final restriction.";

	public const string Sch_BaseFinalList = "The base type is the final list.";

	public const string Sch_BaseFinalUnion = "The base type is the final union.";

	public const string Sch_UndefBaseRestriction = "Undefined complexType '{0}' is used as a base for complex type restriction.";

	public const string Sch_UndefBaseExtension = "Undefined complexType '{0}' is used as a base for complex type extension.";

	public const string Sch_DifContentType = "The derived type and the base type must have the same content type.";

	public const string Sch_InvalidContentRestriction = "Invalid content type derivation by restriction.";

	public const string Sch_InvalidContentRestrictionDetailed = "Invalid content type derivation by restriction. {0}";

	public const string Sch_InvalidBaseToEmpty = "If the derived content type is Empty, then the base content type should also be Empty or Mixed with Emptiable particle according to rule 5.3 of Schema Component Constraint: Derivation Valid (Restriction, Complex).";

	public const string Sch_InvalidBaseToMixed = "If the derived content type is Mixed, then the base content type should also be Mixed according to rule 5.4 of Schema Component Constraint: Derivation Valid (Restriction, Complex).";

	public const string Sch_DupAttributeUse = "The attribute '{0}' already exists.";

	public const string Sch_InvalidParticleRestriction = "Invalid particle derivation by restriction.";

	public const string Sch_InvalidParticleRestrictionDetailed = "Invalid particle derivation by restriction - '{0}'.";

	public const string Sch_ForbiddenDerivedParticleForAll = "'Choice' or 'any' is forbidden as derived particle when the base particle is 'all'.";

	public const string Sch_ForbiddenDerivedParticleForElem = "Only 'element' is valid as derived particle when the base particle is 'element'.";

	public const string Sch_ForbiddenDerivedParticleForChoice = "'All' or 'any' is forbidden as derived particle when the base particle is 'choice'.";

	public const string Sch_ForbiddenDerivedParticleForSeq = "'All', 'any', and 'choice' are forbidden as derived particles when the base particle is 'sequence'.";

	public const string Sch_ElementFromElement = "Derived element '{0}' is not a valid restriction of base element '{1}' according to Elt:Elt -- NameAndTypeOK.";

	public const string Sch_ElementFromAnyRule1 = "The namespace of element '{0}'is not valid with respect to the wildcard's namespace constraint in the base, Elt:Any -- NSCompat Rule 1.";

	public const string Sch_ElementFromAnyRule2 = "The occurrence range of element '{0}'is not a valid restriction of the wildcard's occurrence range in the base, Elt:Any -- NSCompat Rule2.";

	public const string Sch_AnyFromAnyRule1 = "The derived wildcard's occurrence range is not a valid restriction of the base wildcard's occurrence range, Any:Any -- NSSubset Rule 1.";

	public const string Sch_AnyFromAnyRule2 = "The derived wildcard's namespace constraint must be an intensional subset of the base wildcard's namespace constraint, Any:Any -- NSSubset Rule2.";

	public const string Sch_AnyFromAnyRule3 = "The derived wildcard's 'processContents' must be identical to or stronger than the base wildcard's 'processContents', where 'strict' is stronger than 'lax' and 'lax' is stronger than 'skip', Any:Any -- NSSubset Rule 3.";

	public const string Sch_GroupBaseFromAny1 = "Every member of the derived group particle must be a valid restriction of the base wildcard, NSRecurseCheckCardinality Rule 1.";

	public const string Sch_GroupBaseFromAny2 = "The derived particle's occurrence range at ({0}, {1}) is not a valid restriction of the base wildcard's occurrence range at ({2}, {3}), NSRecurseCheckCardinality Rule 2.";

	public const string Sch_ElementFromGroupBase1 = "The derived element {0} at ({1}, {2}) is not a valid restriction of the base sequence particle at ({3}, {4}) according to Elt:All/Choice/Sequence -- RecurseAsIfGroup.";

	public const string Sch_ElementFromGroupBase2 = "The derived element {0} at ({1}, {2}) is not a valid restriction of the base choice particle at ({3}, {4}) according to Elt:All/Choice/Sequence -- RecurseAsIfGroup.";

	public const string Sch_ElementFromGroupBase3 = "The derived element {0} at ({1}, {2}) is not a valid restriction of the base all particle at ({3}, {4}) according to Elt:All/Choice/Sequence -- RecurseAsIfGroup.";

	public const string Sch_GroupBaseRestRangeInvalid = "The derived particle's range is not a valid restriction of the base particle's range according to All:All,Sequence:Sequence -- Recurse Rule 1 or Choice:Choice -- RecurseLax.";

	public const string Sch_GroupBaseRestNoMap = "The derived particle cannot have more members than the base particle - All:All,Sequence:Sequence -- Recurse Rule 2 / Choice:Choice -- RecurseLax.";

	public const string Sch_GroupBaseRestNotEmptiable = "All particles in the {particles} of the base particle which are not mapped to by any particle in the {particles} of the derived particle should be emptiable - All:All,Sequence:Sequence -- Recurse Rule 2 / Choice:Choice -- RecurseLax.";

	public const string Sch_SeqFromAll = "The derived sequence particle at ({0}, {1}) is not a valid restriction of the base all particle at ({2}, {3}) according to Sequence:All -- RecurseUnordered.";

	public const string Sch_SeqFromChoice = "The derived sequence particle at ({0}, {1}) is not a valid restriction of the base choice particle at ({2}, {3}) according to Sequence:Choice -- MapAndSum.";

	public const string Sch_UndefGroupRef = "Reference to undeclared model group '{0}'.";

	public const string Sch_GroupCircularRef = "Circular group reference.";

	public const string Sch_AllRefNotRoot = "The group ref to 'all' is not the root particle, or it is being used as an extension.";

	public const string Sch_AllRefMinMax = "The group ref to 'all' must have {min occurs}= 0 or 1 and {max occurs}=1.";

	public const string Sch_NotAllAlone = "'all' is not the only particle in a group, or is being used as an extension.";

	public const string Sch_AttributeGroupCircularRef = "Circular attribute group reference.";

	public const string Sch_UndefAttributeGroupRef = "Reference to undeclared attribute group '{0}'.";

	public const string Sch_InvalidAttributeExtension = "Invalid attribute extension.";

	public const string Sch_InvalidAnyAttributeRestriction = "The base any attribute must be a superset of the derived 'anyAttribute'.";

	public const string Sch_AttributeRestrictionProhibited = "Invalid attribute restriction. Attribute restriction is prohibited in base type.";

	public const string Sch_AttributeRestrictionInvalid = "Invalid attribute restriction. Derived attribute's type is not a valid restriction of the base attribute's type.";

	public const string Sch_AttributeFixedInvalid = "Invalid attribute restriction. Derived attribute's fixed value must be the same as the base attribute's fixed value. ";

	public const string Sch_AttributeUseInvalid = "Derived attribute's use has to be required if base attribute's use is required.";

	public const string Sch_AttributeRestrictionInvalidFromWildcard = "The {base type definition} must have an {attribute wildcard} and the {target namespace} of the R's {attribute declaration} must be valid with respect to that wildcard.";

	public const string Sch_NoDerivedAttribute = "The base attribute '{0}' whose use = 'required' does not have a corresponding derived attribute while redefining attribute group '{1}'.";

	public const string Sch_UnexpressibleAnyAttribute = "The 'anyAttribute' is not expressible.";

	public const string Sch_RefInvalidAttribute = "Reference to invalid attribute '{0}'.";

	public const string Sch_ElementCircularRef = "Circular element reference.";

	public const string Sch_RefInvalidElement = "Reference to invalid element '{0}'.";

	public const string Sch_ElementCannotHaveValue = "Element's type does not allow fixed or default value constraint.";

	public const string Sch_ElementInMixedWithFixed = "Although the '{0}' element's content type is mixed, it cannot have element children, because it has a fixed value constraint in the schema.";

	public const string Sch_ElementTypeCollision = "Elements with the same name and in the same scope must have the same type.";

	public const string Sch_InvalidIncludeLocation = "Cannot resolve the 'schemaLocation' attribute.";

	public const string Sch_CannotLoadSchema = "Cannot load the schema for the namespace '{0}' - {1}";

	public const string Sch_CannotLoadSchemaLocation = "Cannot load the schema from the location '{0}' - {1}";

	public const string Sch_LengthGtBaseLength = "It is an error if 'length' is among the members of {facets} of {base type definition} and {value} is greater than the {value} of the parent 'length'.";

	public const string Sch_MinLengthGtBaseMinLength = "It is an error if 'minLength' is among the members of {facets} of {base type definition} and {value} is less than the {value} of the parent 'minLength'.";

	public const string Sch_MaxLengthGtBaseMaxLength = "It is an error if 'maxLength' is among the members of {facets} of {base type definition} and {value} is greater than the {value} of the parent 'maxLength'.";

	public const string Sch_MaxMinLengthBaseLength = "It is an error for both 'length' and either 'minLength' or 'maxLength' to be members of {facets}, unless they are specified in different derivation steps. In which case the following must be true: the {value} of 'minLength' <= the {value} of 'length' <= the {value} of 'maxLength'.";

	public const string Sch_MaxInclusiveMismatch = "It is an error if the derived 'maxInclusive' facet value is greater than the parent 'maxInclusive' facet value.";

	public const string Sch_MaxExclusiveMismatch = "It is an error if the derived 'maxExclusive' facet value is greater than the parent 'maxExclusive' facet value.";

	public const string Sch_MinInclusiveMismatch = "It is an error if the derived 'minInclusive' facet value is less than the parent 'minInclusive' facet value.";

	public const string Sch_MinExclusiveMismatch = "It is an error if the derived 'minExclusive' facet value is less than the parent 'minExclusive' facet value.";

	public const string Sch_MinExlIncMismatch = "It is an error if the derived 'minExclusive' facet value is less than or equal to the parent 'minInclusive' facet value.";

	public const string Sch_MinExlMaxExlMismatch = "It is an error if the derived 'minExclusive' facet value is greater than or equal to the parent 'maxExclusive' facet value.";

	public const string Sch_MinIncMaxExlMismatch = "It is an error if the derived 'minInclusive' facet value is greater than or equal to the parent 'maxExclusive' facet value.";

	public const string Sch_MinIncExlMismatch = "It is an error if the derived 'minInclusive' facet value is less than or equal to the parent 'minExclusive' facet value.";

	public const string Sch_MaxIncExlMismatch = "It is an error if the derived 'maxInclusive' facet value is greater than or equal to the parent 'maxExclusive' facet value.";

	public const string Sch_MaxExlIncMismatch = "It is an error if the derived 'maxExclusive' facet value is greater than or equal to the parent 'maxInclusive' facet value.";

	public const string Sch_TotalDigitsMismatch = "It is an error if the derived 'totalDigits' facet value is greater than the parent 'totalDigits' facet value.";

	public const string Sch_FacetBaseFixed = "Values that are declared as {fixed} in a base type can not be changed in a derived type.";

	public const string Sch_WhiteSpaceRestriction1 = "It is an error if 'whiteSpace' is among the members of {facets} of {base type definition}, {value} is 'replace' or 'preserve', and the {value} of the parent 'whiteSpace' is 'collapse'.";

	public const string Sch_WhiteSpaceRestriction2 = "It is an error if 'whiteSpace' is among the members of {facets} of {base type definition}, {value} is 'preserve', and the {value} of the parent 'whiteSpace' is 'replace'.";

	public const string Sch_XsiNilAndFixed = "There must be no fixed value when an attribute is 'xsi:nil' and has a value of 'true'.";

	public const string Sch_MixSchemaTypes = "Different schema types cannot be mixed.";

	public const string Sch_XSDSchemaOnly = "'XmlSchemaSet' can load only W3C XML Schemas.";

	public const string Sch_InvalidPublicAttribute = "Public attribute '{0}' is an invalid URI.";

	public const string Sch_InvalidSystemAttribute = "System attribute '{0}' is an invalid URI.";

	public const string Sch_TypeAfterConstraints = "'simpleType' or 'complexType' cannot follow 'unique', 'key' or 'keyref'.";

	public const string Sch_XsiNilAndType = "There can be no type value when attribute is 'xsi:nil' and has value 'true'.";

	public const string Sch_DupSimpleTypeChild = "'simpleType' should have only one child 'union', 'list', or 'restriction'.";

	public const string Sch_InvalidIdAttribute = "Invalid 'id' attribute value: {0}";

	public const string Sch_InvalidNameAttributeEx = "Invalid 'name' attribute value '{0}': '{1}'.";

	public const string Sch_InvalidAttribute = "Invalid '{0}' attribute: '{1}'.";

	public const string Sch_EmptyChoice = "Empty choice cannot be satisfied if 'minOccurs' is not equal to 0.";

	public const string Sch_DerivedNotFromBase = "The data type of the simple content is not a valid restriction of the base complex type.";

	public const string Sch_NeedSimpleTypeChild = "Simple content restriction must have a simple type child if the content type of the base type is not a simple type definition.";

	public const string Sch_InvalidCollection = "The schema items collection cannot contain an object of type 'XmlSchemaInclude', 'XmlSchemaImport', or 'XmlSchemaRedefine'.";

	public const string Sch_UnrefNS = "Namespace '{0}' is not available to be referenced in this schema.";

	public const string Sch_InvalidSimpleTypeRestriction = "Restriction of 'anySimpleType' is not allowed.";

	public const string Sch_MultipleRedefine = "Multiple redefines of the same schema will be ignored.";

	public const string Sch_NullValue = "Value cannot be null.";

	public const string Sch_ComplexContentModel = "Content model validation resulted in a large number of states, possibly due to large occurrence ranges. Therefore, content model may not be validated accurately.";

	public const string Sch_SchemaNotPreprocessed = "All schemas in the set should be successfully preprocessed prior to compilation.";

	public const string Sch_SchemaNotRemoved = "The schema could not be removed because other schemas in the set have dependencies on this schema or its imports.";

	public const string Sch_ComponentAlreadySeenForNS = "An element or attribute information item has already been validated from the '{0}' namespace. It is an error if 'xsi:schemaLocation', 'xsi:noNamespaceSchemaLocation', or an inline schema occurs for that namespace.";

	public const string Sch_DefaultAttributeNotApplied = "Default attribute '{0}' for element '{1}' could not be applied as the attribute namespace is not mapped to a prefix in the instance document.";

	public const string Sch_NotXsiAttribute = "The attribute '{0}' does not match one of the four allowed attributes in the 'xsi' namespace.";

	public const string Sch_SchemaDoesNotExist = "Schema does not exist in the set.";

	public const string XmlDocument_ValidateInvalidNodeType = "Validate method can be called only on nodes of type Document, DocumentFragment, Element, or Attribute.";

	public const string XmlDocument_NodeNotFromDocument = "Cannot validate '{0}' because its owner document is not the current document. ";

	public const string XmlDocument_NoNodeSchemaInfo = "Schema information could not be found for the node passed into Validate. The node may be invalid in its current position. Navigate to the ancestor that has schema information, then call Validate again.";

	public const string XmlDocument_NoSchemaInfo = "The XmlSchemaSet on the document is either null or has no schemas in it. Provide schema information before calling Validate.";

	public const string Sch_InvalidStartTransition = "It is invalid to call the '{0}' method in the current state of the validator. The '{1}' method must be called before proceeding with validation.";

	public const string Sch_InvalidStateTransition = "The transition from the '{0}' method to the '{1}' method is not allowed.";

	public const string Sch_InvalidEndValidation = "The 'EndValidation' method cannot not be called when all the elements have not been validated. 'ValidateEndElement' calls corresponding to 'ValidateElement' calls might be missing.";

	public const string Sch_InvalidEndElementCall = "It is invalid to call the 'ValidateEndElement' overload that takes in a 'typedValue' after 'ValidateText' or 'ValidateWhitespace' methods have been called.";

	public const string Sch_InvalidEndElementCallTyped = "It is invalid to call the 'ValidateEndElement' overload that takes in a 'typedValue' for elements with complex content.";

	public const string Sch_InvalidEndElementMultiple = "The call to the '{0}' method does not match a corresponding call to 'ValidateElement' method.";

	public const string Sch_DuplicateAttribute = "The '{0}' attribute has already been validated and is a duplicate attribute.";

	public const string Sch_InvalidPartialValidationType = "The partial validation type has to be 'XmlSchemaElement', 'XmlSchemaAttribute', or 'XmlSchemaType'.";

	public const string Sch_SchemaElementNameMismatch = "The element name '{0}' does not match the name '{1}' of the 'XmlSchemaElement' set as a partial validation type. ";

	public const string Sch_SchemaAttributeNameMismatch = "The attribute name '{0}' does not match the name '{1}' of the 'XmlSchemaAttribute' set as a partial validation type. ";

	public const string Sch_ValidateAttributeInvalidCall = "If the partial validation type is 'XmlSchemaElement' or 'XmlSchemaType', the 'ValidateAttribute' method cannot be called.";

	public const string Sch_ValidateElementInvalidCall = "If the partial validation type is 'XmlSchemaAttribute', the 'ValidateElement' method cannot be called.";

	public const string Sch_EnumNotStarted = "Enumeration has not started. Call MoveNext.";

	public const string Sch_EnumFinished = "Enumeration has already finished.";

	public const string SchInf_schema = "The supplied xml instance is a schema or contains an inline schema. This class cannot infer a schema for a schema.";

	public const string SchInf_entity = "Inference cannot handle entity references. Pass in an 'XmlReader' that expands entities.";

	public const string SchInf_simplecontent = "Expected simple content. Schema was not created using this tool.";

	public const string SchInf_extension = "Expected 'Extension' within 'SimpleContent'. Schema was not created using this tool.";

	public const string SchInf_particle = "Particle cannot exist along with 'ContentModel'.";

	public const string SchInf_ct = "Complex type expected to exist with at least one 'Element' at this point.";

	public const string SchInf_seq = "sequence expected to contain elements only. Schema was not created using this tool.";

	public const string SchInf_noseq = "The supplied schema contains particles other than Sequence and Choice. Only schemas generated by this tool are supported.";

	public const string SchInf_noct = "Expected ComplexType. Schema was not generated using this tool.";

	public const string SchInf_UnknownParticle = "Expected Element. Schema was not generated using this tool.";

	public const string SchInf_schematype = "Inference can only handle simple built-in types for 'SchemaType'.";

	public const string SchInf_NoElement = "There is no element to infer schema.";

	public const string Xp_UnclosedString = "This is an unclosed string.";

	public const string Xp_ExprExpected = "'{0}' is an invalid expression.";

	public const string Xp_InvalidArgumentType = "The argument to function '{0}' in '{1}' cannot be converted to a node-set.";

	public const string Xp_InvalidNumArgs = "Function '{0}' in '{1}' has an invalid number of arguments.";

	public const string Xp_InvalidName = "'{0}' has an invalid qualified name.";

	public const string Xp_InvalidToken = "'{0}' has an invalid token.";

	public const string Xp_NodeSetExpected = "Expression must evaluate to a node-set.";

	public const string Xp_NotSupported = "The XPath query '{0}' is not supported.";

	public const string Xp_InvalidPattern = "'{0}' is an invalid XSLT pattern.";

	public const string Xp_InvalidKeyPattern = "'{0}' is an invalid key pattern. It either contains a variable reference or 'key()' function.";

	public const string Xp_BadQueryObject = "This is an invalid object. Only objects returned from Compile() can be passed as input.";

	public const string Xp_UndefinedXsltContext = "XsltContext is needed for this query because of an unknown function.";

	public const string Xp_NoContext = "Namespace Manager or XsltContext needed. This query has a prefix, variable, or user-defined function.";

	public const string Xp_UndefVar = "The variable '{0}' is undefined.";

	public const string Xp_UndefFunc = "The function '{0}()' is undefined.";

	public const string Xp_FunctionFailed = "Function '{0}()' has failed.";

	public const string Xp_CurrentNotAllowed = "The 'current()' function cannot be used in a pattern.";

	public const string Xp_QueryTooComplex = "The xpath query is too complex.";

	public const string Xdom_DualDocumentTypeNode = "This document already has a 'DocumentType' node.";

	public const string Xdom_DualDocumentElementNode = "This document already has a 'DocumentElement' node.";

	public const string Xdom_DualDeclarationNode = "This document already has an 'XmlDeclaration' node.";

	public const string Xdom_Import = "Cannot import nodes of type '{0}'.";

	public const string Xdom_Import_NullNode = "Cannot import a null node.";

	public const string Xdom_NoRootEle = "The document does not have a root element.";

	public const string Xdom_Attr_Name = "The attribute local name cannot be empty.";

	public const string Xdom_AttrCol_Object = "An 'Attributes' collection can only contain 'Attribute' objects.";

	public const string Xdom_AttrCol_Insert = "The reference node must be a child of the current node.";

	public const string Xdom_NamedNode_Context = "The named node is from a different document context.";

	public const string Xdom_Version = "Wrong XML version information. The XML must match production \"VersionNum ::= '1.' [0-9]+\".";

	public const string Xdom_standalone = "Wrong value for the XML declaration standalone attribute of '{0}'.";

	public const string Xdom_Ent_Innertext = "The 'InnerText' of an 'Entity' node is read-only and cannot be set.";

	public const string Xdom_EntRef_SetVal = "'EntityReference' nodes have no support for setting value.";

	public const string Xdom_WS_Char = "The string for whitespace contains an invalid character.";

	public const string Xdom_Node_SetVal = "Cannot set a value on node type '{0}'.";

	public const string Xdom_Empty_LocalName = "The local name for elements or attributes cannot be null or an empty string.";

	public const string Xdom_Set_InnerXml = "Cannot set the 'InnerXml' for the current node because it is either read-only or cannot have children.";

	public const string Xdom_Attr_InUse = "The 'Attribute' node cannot be inserted because it is already an attribute of another element.";

	public const string Xdom_Enum_ElementList = "The element list has changed. The enumeration operation failed to continue.";

	public const string Xdom_Invalid_NT_String = "'{0}' does not represent any 'XmlNodeType'.";

	public const string Xdom_InvalidCharacter_EntityReference = "Cannot create an 'EntityReference' node with a name starting with '#'.";

	public const string Xdom_IndexOutOfRange = "The index being passed in is out of range.";

	public const string Xdom_Document_Innertext = "The 'InnerText' of a 'Document' node is read-only and cannot be set.";

	public const string Xpn_BadPosition = "Operation is not valid due to the current position of the navigator.";

	public const string Xpn_MissingParent = "The current position of the navigator is missing a valid parent.";

	public const string Xpn_NoContent = "No content generated as the result of the operation.";

	public const string Xdom_Load_NoDocument = "The document to be loaded could not be found.";

	public const string Xdom_Load_NoReader = "There is no reader from which to load the document.";

	public const string Xdom_Node_Null_Doc = "Cannot create a node without an owner document.";

	public const string Xdom_Node_Insert_Child = "Cannot insert a node or any ancestor of that node as a child of itself.";

	public const string Xdom_Node_Insert_Contain = "The current node cannot contain other nodes.";

	public const string Xdom_Node_Insert_Path = "The reference node is not a child of this node.";

	public const string Xdom_Node_Insert_Context = "The node to be inserted is from a different document context.";

	public const string Xdom_Node_Insert_Location = "Cannot insert the node in the specified location.";

	public const string Xdom_Node_Insert_TypeConflict = "The specified node cannot be inserted as the valid child of this node, because the specified node is the wrong type.";

	public const string Xdom_Node_Remove_Contain = "The current node cannot contain other nodes, so the node to be removed is not its child.";

	public const string Xdom_Node_Remove_Child = "The node to be removed is not a child of this node.";

	public const string Xdom_Node_Modify_ReadOnly = "This node is read-only. It cannot be modified.";

	public const string Xdom_TextNode_SplitText = "The 'Text' node is not connected in the DOM live tree. No 'SplitText' operation could be performed.";

	public const string Xdom_Attr_Reserved_XmlNS = "The namespace declaration attribute has an incorrect 'namespaceURI': '{0}'.";

	public const string Xdom_Node_Cloning = "'Entity' and 'Notation' nodes cannot be cloned.";

	public const string Xnr_ResolveEntity = "The node is not an expandable 'EntityReference' node.";

	public const string XPathDocument_MissingSchemas = "An XmlSchemaSet must be provided to validate the document.";

	public const string XPathDocument_NotEnoughSchemaInfo = "Element should have prior schema information to call this method.";

	public const string XPathDocument_ValidateInvalidNodeType = "Validate and CheckValidity are only allowed on Root or Element nodes.";

	public const string XPathDocument_SchemaSetNotAllowed = "An XmlSchemaSet is only allowed as a parameter on the Root node.";

	public const string XmlBin_MissingEndCDATA = "CDATA end token is missing.";

	public const string XmlBin_InvalidQNameID = "Invalid QName ID.";

	public const string XmlBinary_UnexpectedToken = "Unexpected BinaryXml token.";

	public const string XmlBinary_InvalidSqlDecimal = "Unable to parse data as SQL_DECIMAL.";

	public const string XmlBinary_InvalidSignature = "Invalid BinaryXml signature.";

	public const string XmlBinary_InvalidProtocolVersion = "Invalid BinaryXml protocol version.";

	public const string XmlBinary_UnsupportedCodePage = "Unsupported BinaryXml codepage.";

	public const string XmlBinary_InvalidStandalone = "Invalid BinaryXml standalone token.";

	public const string XmlBinary_NoParserContext = "BinaryXml Parser does not support initialization with XmlParserContext.";

	public const string XmlBinary_ListsOfValuesNotSupported = "Lists of BinaryXml value tokens not supported.";

	public const string XmlBinary_CastNotSupported = "Token '{0}' does not support a conversion to Clr type '{1}'.";

	public const string XmlBinary_NoRemapPrefix = "Prefix '{0}' is already assigned to namespace '{1}' and cannot be reassigned to '{2}' on this tag.";

	public const string XmlBinary_AttrWithNsNoPrefix = "Attribute '{0}' has namespace '{1}' but no prefix.";

	public const string XmlBinary_ValueTooBig = "The value is too big to fit into an Int32. The arithmetic operation resulted in an overflow.";

	public const string SqlTypes_ArithOverflow = "Arithmetic Overflow.";

	public const string XmlMissingType = "Invalid serialization assembly: Required type {0} cannot be found in the generated assembly '{1}'.";

	public const string XmlSerializerUnsupportedType = "{0} is an unsupported type. Please use [XmlIgnore] attribute to exclude members of this type from serialization graph.";

	public const string XmlSerializerUnsupportedMember = "Cannot serialize member '{0}' of type '{1}', see inner exception for more details.";

	public const string XmlUnsupportedTypeKind = "The type {0} may not be serialized.";

	public const string XmlUnsupportedSoapTypeKind = "The type {0} may not be serialized with SOAP-encoded messages. Set the Use for your message to Literal.";

	public const string XmlUnsupportedIDictionary = "The type {0} is not supported because it implements IDictionary.";

	public const string XmlUnsupportedIDictionaryDetails = "Cannot serialize member {0} of type {1}, because it implements IDictionary.";

	public const string XmlDuplicateTypeName = "A type with the name {0} has already been added in namespace {1}.";

	public const string XmlSerializableNameMissing1 = "Schema Id is missing. The schema returned from {0}.GetSchema() must have an Id.";

	public const string XmlConstructorInaccessible = "{0} cannot be serialized because it does not have a parameterless constructor.";

	public const string XmlTypeInaccessible = "{0} is inaccessible due to its protection level. Only public types can be processed.";

	public const string XmlTypeStatic = "{0} cannot be serialized. Static types cannot be used as parameters or return types.";

	public const string XmlNoDefaultAccessors = "You must implement a default accessor on {0} because it inherits from ICollection.";

	public const string XmlNoAddMethod = "To be XML serializable, types which inherit from {2} must have an implementation of Add({1}) at all levels of their inheritance hierarchy. {0} does not implement Add({1}).";

	public const string XmlReadOnlyPropertyError = "Cannot deserialize type '{0}' because it contains property '{1}' which has no public setter.";

	public const string XmlAttributeSetAgain = "'{0}.{1}' already has attributes.";

	public const string XmlIllegalWildcard = "Cannot use wildcards at the top level of a schema.";

	public const string XmlIllegalArrayElement = "An element declared at the top level of a schema cannot have maxOccurs > 1. Provide a wrapper element for '{0}' by using XmlArray or XmlArrayItem instead of XmlElementAttribute, or by using the Wrapped parameter style.";

	public const string XmlIllegalForm = "There was an error exporting '{0}': elements declared at the top level of a schema cannot be unqualified.";

	public const string XmlBareTextMember = "There was an error exporting '{0}': bare members cannot contain text content.";

	public const string XmlBareAttributeMember = "There was an error exporting '{0}': bare members cannot be attributes.";

	public const string XmlReflectionError = "There was an error reflecting '{0}'.";

	public const string XmlTypeReflectionError = "There was an error reflecting type '{0}'.";

	public const string XmlPropertyReflectionError = "There was an error reflecting property '{0}'.";

	public const string XmlFieldReflectionError = "There was an error reflecting field '{0}'.";

	public const string XmlInvalidDataTypeUsage = "'{0}' is an invalid value for the {1} property. The property may only be specified for primitive types.";

	public const string XmlInvalidXsdDataType = "Value '{0}' cannot be used for the {1} property. The datatype '{2}' is missing.";

	public const string XmlDataTypeMismatch = "'{0}' is an invalid value for the {1} property. {0} cannot be converted to {2}.";

	public const string XmlIllegalTypeContext = "{0} cannot be used as: 'xml {1}'.";

	public const string XmlUdeclaredXsdType = "The type, {0}, is undeclared.";

	public const string XmlInvalidConstantAttribute = "Only XmlEnum may be used on enumerated constants.";

	public const string XmlIllegalAttributesArrayAttribute = "XmlAttribute and XmlAnyAttribute cannot be used in conjunction with XmlElement, XmlText, XmlAnyElement, XmlArray, or XmlArrayItem.";

	public const string XmlIllegalElementsArrayAttribute = "XmlElement, XmlText, and XmlAnyElement cannot be used in conjunction with XmlAttribute, XmlAnyAttribute, XmlArray, or XmlArrayItem.";

	public const string XmlIllegalArrayArrayAttribute = "XmlArray and XmlArrayItem cannot be used in conjunction with XmlAttribute, XmlAnyAttribute, XmlElement, XmlText, or XmlAnyElement.";

	public const string XmlIllegalAttribute = "For non-array types, you may use the following attributes: XmlAttribute, XmlText, XmlElement, or XmlAnyElement.";

	public const string XmlIllegalType = "The type for {0} may not be specified for primitive types.";

	public const string XmlIllegalAttrOrText = "Cannot serialize member '{0}' of type {1}. XmlAttribute/XmlText cannot be used to encode complex types.";

	public const string XmlIllegalSoapAttribute = "Cannot serialize member '{0}' of type {1}. SoapAttribute cannot be used to encode complex types.";

	public const string XmlIllegalAttrOrTextInterface = "Cannot serialize member '{0}' of type {1}. XmlAttribute/XmlText cannot be used to encode types implementing {2}.";

	public const string XmlIllegalAttributeFlagsArray = "XmlAttribute cannot be used to encode array of {1}, because it is marked with FlagsAttribute.";

	public const string XmlIllegalAnyElement = "Cannot serialize member of type {0}: XmlAnyElement can only be used with classes of type XmlNode or a type deriving from XmlNode.";

	public const string XmlInvalidIsNullable = "IsNullable may not be 'true' for value type {0}.  Please consider using Nullable<{0}> instead.";

	public const string XmlInvalidNotNullable = "IsNullable may not be set to 'false' for a Nullable<{0}> type. Consider using '{0}' type or removing the IsNullable property from the {1} attribute.";

	public const string XmlInvalidFormUnqualified = "The Form property may not be 'Unqualified' when an explicit Namespace property is present.";

	public const string XmlDuplicateNamespace = "The namespace, {0}, is a duplicate.";

	public const string XmlElementHasNoName = "This element has no name. Please review schema type '{0}' from namespace '{1}'.";

	public const string XmlAttributeHasNoName = "This attribute has no name.";

	public const string XmlElementImportedTwice = "The element, {0}, from namespace, {1}, was imported in two different contexts: ({2}, {3}).";

	public const string XmlHiddenMember = "Member {0}.{1} of type {2} hides base class member {3}.{4} of type {5}. Use XmlElementAttribute or XmlAttributeAttribute to specify a new name.";

	public const string XmlInvalidXmlOverride = "Member '{0}.{1}' hides inherited member '{2}.{3}', but has different custom attributes.";

	public const string XmlMembersDeriveError = "These members may not be derived.";

	public const string XmlTypeUsedTwice = "The type '{0}' from namespace '{1}' was used in two different ways.";

	public const string XmlMissingGroup = "Group {0} is missing.";

	public const string XmlMissingAttributeGroup = "The attribute group {0} is missing.";

	public const string XmlMissingDataType = "The datatype '{0}' is missing.";

	public const string XmlInvalidEncoding = "Referenced type '{0}' is only valid for encoded SOAP.";

	public const string XmlMissingElement = "The element '{0}' is missing.";

	public const string XmlMissingAttribute = "The attribute {0} is missing.";

	public const string XmlMissingMethodEnum = "The method for enum {0} is missing.";

	public const string XmlNoAttributeHere = "Cannot write a node of type XmlAttribute as an element value. Use XmlAnyAttributeAttribute with an array of XmlNode or XmlAttribute to write the node as an at