Decompiled source of HarmonyXTranspilerFix v1.4.0

BepInEx/patchers/HarmonyXTranspilerFix/HarmonyXTranspilerFix.dll

Decompiled 6 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
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.Versioning;
using System.Security;
using System.Security.Permissions;
using HarmonyLib;
using HarmonyLib.Internal.Patching;
using HarmonyLib.Internal.Util;
using HarmonyLib.Public.Patching;
using Microsoft.CodeAnalysis;
using Mono.Cecil;
using Mono.Cecil.Cil;
using MonoMod.RuntimeDetour;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("0Harmony")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("HarmonyXTranspilerFix")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.0.0.0")]
[assembly: AssemblyInformationalVersion("0.0.0+2289a098188c5676c52c8825b9cb451d36131588")]
[assembly: AssemblyProduct("HarmonyXTranspilerFix")]
[assembly: AssemblyTitle("HarmonyXTranspilerFix")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
[CompilerGenerated]
internal sealed class <>z__ReadOnlyArray<T> : IEnumerable, ICollection, IList, IEnumerable<T>, IReadOnlyCollection<T>, IReadOnlyList<T>, ICollection<T>, IList<T>
{
	int ICollection.Count => _items.Length;

	bool ICollection.IsSynchronized => false;

	object ICollection.SyncRoot => this;

	object IList.this[int index]
	{
		get
		{
			return _items[index];
		}
		set
		{
			throw new NotSupportedException();
		}
	}

	bool IList.IsFixedSize => true;

	bool IList.IsReadOnly => true;

	int IReadOnlyCollection<T>.Count => _items.Length;

	T IReadOnlyList<T>.this[int index] => _items[index];

	int ICollection<T>.Count => _items.Length;

	bool ICollection<T>.IsReadOnly => true;

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

	public <>z__ReadOnlyArray(T[] items)
	{
		_items = items;
	}

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

	void ICollection.CopyTo(Array array, int index)
	{
		((ICollection)_items).CopyTo(array, index);
	}

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

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

	bool IList.Contains(object value)
	{
		return ((IList)_items).Contains(value);
	}

	int IList.IndexOf(object value)
	{
		return ((IList)_items).IndexOf(value);
	}

	void IList.Insert(int index, object value)
	{
		throw new NotSupportedException();
	}

	void IList.Remove(object value)
	{
		throw new NotSupportedException();
	}

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

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

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

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

	bool ICollection<T>.Contains(T item)
	{
		return ((ICollection<T>)_items).Contains(item);
	}

	void ICollection<T>.CopyTo(T[] array, int arrayIndex)
	{
		((ICollection<T>)_items).CopyTo(array, arrayIndex);
	}

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

	int IList<T>.IndexOf(T item)
	{
		return ((IList<T>)_items).IndexOf(item);
	}

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

	void IList<T>.RemoveAt(int index)
	{
		throw new NotSupportedException();
	}
}
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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]
	[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]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace HarmonyXTranspilerFix
{
	public class HarmonyXTranspilerFixPatcher
	{
		public static IEnumerable<string> TargetDLLs { get; } = Array.Empty<string>();

		public static void Finish()
		{
			try
			{
				Harmony.CreateAndPatchAll(typeof(HarmonyXTranspilerFixPatcher).Assembly, "HarmonyXTranspilerFixPatcher");
			}
			catch (Exception ex)
			{
				Console.WriteLine(ex.ToString());
			}
		}

		public static void Patch(AssemblyDefinition _)
		{
		}
	}
}
namespace HarmonyXTranspilerFix.Patches
{
	[HarmonyPatch(typeof(HarmonyManipulator))]
	internal static class Patch_HarmonyManipulator
	{
		public static readonly MethodInfo PrepareMethod = typeof(Patch_HarmonyManipulator).GetMethod("PrepareException", AccessTools.all);

		public static readonly MethodInfo ThrowMethod = typeof(ExceptionDispatchInfo).GetMethod("Throw", Type.EmptyTypes);

		private static readonly MethodInfo s_InternalPreserveStackTrace = typeof(Exception).GetMethod("InternalPreserveStackTrace", BindingFlags.Instance | BindingFlags.NonPublic);

		[HarmonyPatch("WriteFinalizers")]
		[HarmonyTranspiler]
		public static IEnumerable<CodeInstruction> PreserveFinalizerExceptionStack(IEnumerable<CodeInstruction> instructions)
		{
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Expected O, but got Unknown
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Expected O, but got Unknown
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Expected O, but got Unknown
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Expected O, but got Unknown
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Expected O, but got Unknown
			//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c9: Expected O, but got Unknown
			//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Expected O, but got Unknown
			//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f3: Expected O, but got Unknown
			//IL_0200: Unknown result type (might be due to invalid IL or missing references)
			//IL_0206: Expected O, but got Unknown
			//IL_0213: Unknown result type (might be due to invalid IL or missing references)
			//IL_0219: Expected O, but got Unknown
			//IL_0221: Unknown result type (might be due to invalid IL or missing references)
			//IL_0227: Expected O, but got Unknown
			//IL_0234: Unknown result type (might be due to invalid IL or missing references)
			//IL_023a: Expected O, but got Unknown
			//IL_029b: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a1: Expected O, but got Unknown
			//IL_02b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b6: Expected O, but got Unknown
			//IL_02ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f3: Expected O, but got Unknown
			//IL_0302: Unknown result type (might be due to invalid IL or missing references)
			//IL_0308: Expected O, but got Unknown
			//IL_0317: Unknown result type (might be due to invalid IL or missing references)
			//IL_031d: Expected O, but got Unknown
			//IL_032c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0332: Expected O, but got Unknown
			//IL_0372: Unknown result type (might be due to invalid IL or missing references)
			//IL_037c: Expected O, but got Unknown
			//IL_0388: Unknown result type (might be due to invalid IL or missing references)
			//IL_0392: Expected O, but got Unknown
			//IL_03ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b3: Expected O, but got Unknown
			//IL_03c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c6: Expected O, but got Unknown
			//IL_03d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d9: Expected O, but got Unknown
			//IL_03e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ec: Expected O, but got Unknown
			//IL_03f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ff: Expected O, but got Unknown
			MethodInfo emitOpCode = AccessTools.Method(typeof(ILEmitter), "Emit", new Type[1] { typeof(OpCode) }, (Type[])null);
			MethodInfo emitOpCodeMethod = AccessTools.Method(typeof(ILEmitter), "Emit", new Type[2]
			{
				typeof(OpCode),
				typeof(MethodInfo)
			}, (Type[])null);
			FieldInfo callField = AccessTools.Field(typeof(OpCodes), "Call");
			FieldInfo throwField = AccessTools.Field(typeof(OpCodes), "Throw");
			FieldInfo rethrowField = AccessTools.Field(typeof(OpCodes), "Rethrow");
			FieldInfo ldlocField = AccessTools.Field(typeof(OpCodes), "Ldloc");
			FieldInfo prepareField = AccessTools.Field(typeof(Patch_HarmonyManipulator), "PrepareMethod");
			FieldInfo fieldInfo = AccessTools.Field(typeof(Patch_HarmonyManipulator), "ThrowMethod");
			FieldInfo exceptionVarField = AccessTools.Field(typeof(HarmonyManipulator), "ExceptionVar");
			FieldInfo variablesField = AccessTools.Field(typeof(HarmonyManipulator), "variables");
			FieldInfo ilField = AccessTools.Field(typeof(HarmonyManipulator), "il");
			CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null);
			CodeMatch[] array = (CodeMatch[])(object)new CodeMatch[6]
			{
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => CodeInstructionExtensions.LoadsField(i, ldlocField, false)), (string)null),
				new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null),
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => CodeInstructionExtensions.LoadsField(i, variablesField, false)), (string)null),
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => CodeInstructionExtensions.LoadsField(i, exceptionVarField, false)), (string)null),
				new CodeMatch((OpCode?)OpCodes.Callvirt, (object)null, (string)null),
				new CodeMatch((OpCode?)OpCodes.Callvirt, (object)null, (string)null)
			};
			CodeInstruction[] emitDispatchThrow = (CodeInstruction[])(object)new CodeInstruction[5]
			{
				new CodeInstruction(OpCodes.Ldarg_0, (object)null),
				new CodeInstruction(OpCodes.Ldfld, (object)ilField),
				new CodeInstruction(OpCodes.Ldsfld, (object)callField),
				new CodeInstruction(OpCodes.Ldsfld, (object)fieldInfo),
				new CodeInstruction(OpCodes.Callvirt, (object)emitOpCodeMethod)
			};
			val.MatchForward(false, array);
			if (val.IsInvalid)
			{
				return instructions;
			}
			CodeInstruction[] collection = val.Instructions(array.Length).Select(delegate(CodeInstruction instruction)
			{
				CodeInstruction val2 = instruction.Clone();
				val2.labels.Clear();
				val2.blocks.Clear();
				return val2;
			}).ToArray();
			CodeMatch[] array2 = (CodeMatch[])(object)new CodeMatch[2]
			{
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => CodeInstructionExtensions.LoadsField(i, throwField, false)), (string)null),
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => CodeInstructionExtensions.Calls(i, emitOpCode)), (string)null)
			};
			val.Start().MatchForward(false, array2).Repeat((Action<CodeMatcher>)delegate(CodeMatcher m)
			{
				//IL_0024: Unknown result type (might be due to invalid IL or missing references)
				//IL_002a: Expected O, but got Unknown
				m.SetAndAdvance(OpCodes.Ldsfld, (object)callField).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1]
				{
					new CodeInstruction(OpCodes.Ldsfld, (object)prepareField)
				}).SetAndAdvance(OpCodes.Callvirt, (object)emitOpCodeMethod)
					.InsertAndAdvance(emitDispatchThrow);
			}, (Action<string>)null);
			CodeMatch[] array3 = (CodeMatch[])(object)new CodeMatch[4]
			{
				new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null),
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => CodeInstructionExtensions.LoadsField(i, ilField, false)), (string)null),
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => CodeInstructionExtensions.LoadsField(i, rethrowField, false)), (string)null),
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => CodeInstructionExtensions.Calls(i, emitOpCode)), (string)null)
			};
			val.Start().MatchForward(false, array3);
			if (val.IsInvalid)
			{
				return instructions;
			}
			List<Label> collection2 = val.Labels.ToList();
			val.RemoveInstructions(array3.Length);
			List<CodeInstruction> list = new List<CodeInstruction>
			{
				new CodeInstruction(OpCodes.Ldarg_0, (object)null),
				new CodeInstruction(OpCodes.Ldfld, (object)ilField)
			};
			list.AddRange(collection);
			list.AddRange(new <>z__ReadOnlyArray<CodeInstruction>((CodeInstruction[])(object)new CodeInstruction[5]
			{
				new CodeInstruction(OpCodes.Ldarg_0, (object)null),
				new CodeInstruction(OpCodes.Ldfld, (object)ilField),
				new CodeInstruction(OpCodes.Ldsfld, (object)callField),
				new CodeInstruction(OpCodes.Ldsfld, (object)prepareField),
				new CodeInstruction(OpCodes.Callvirt, (object)emitOpCodeMethod)
			}));
			list.AddRange(emitDispatchThrow);
			list[0].labels.AddRange(collection2);
			val.Insert((IEnumerable<CodeInstruction>)list);
			return val.InstructionEnumeration();
		}

		public static ExceptionDispatchInfo PrepareException(Exception exception)
		{
			s_InternalPreserveStackTrace.Invoke(exception, null);
			return ExceptionDispatchInfo.Capture(exception);
		}
	}
	[HarmonyPatch(typeof(ILManipulator))]
	internal static class Patch_ILManipulator
	{
		[HarmonyPatch("WriteTo")]
		[HarmonyTranspiler]
		[HarmonyPriority(100)]
		public static IEnumerable<CodeInstruction> FixILManipulatorBreaksMethod(IEnumerable<CodeInstruction> instructions)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected O, but got Unknown
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Expected O, but got Unknown
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Expected O, but got Unknown
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Expected O, but got Unknown
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: 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_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Expected O, but got Unknown
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Expected O, but got Unknown
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Expected O, but got Unknown
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Expected O, but got Unknown
			//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c9: Expected O, but got Unknown
			//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Expected O, but got Unknown
			//IL_0215: Unknown result type (might be due to invalid IL or missing references)
			//IL_021b: Expected O, but got Unknown
			//IL_023e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0244: Expected O, but got Unknown
			//IL_0267: Unknown result type (might be due to invalid IL or missing references)
			//IL_026d: Expected O, but got Unknown
			//IL_0290: Unknown result type (might be due to invalid IL or missing references)
			//IL_0296: Expected O, but got Unknown
			//IL_02b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bf: Expected O, but got Unknown
			//IL_02e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e8: Expected O, but got Unknown
			//IL_030b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0311: Expected O, but got Unknown
			//IL_0334: Unknown result type (might be due to invalid IL or missing references)
			//IL_033a: Expected O, but got Unknown
			//IL_035d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0363: Expected O, but got Unknown
			//IL_0386: Unknown result type (might be due to invalid IL or missing references)
			//IL_038c: Expected O, but got Unknown
			CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null);
			Label? label = default(Label?);
			CodeMatch[] array = (CodeMatch[])(object)new CodeMatch[22]
			{
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => CodeInstructionExtensions.IsLdloc(i, (LocalBuilder)null)), (string)null),
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => CodeInstructionExtensions.LoadsField(i, typeof(CodeInstruction).GetField("opcode"), false)), (string)null),
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => CodeInstructionExtensions.LoadsField(i, typeof(OpCodes).GetField("Leave"), false)), (string)null),
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => CodeInstructionExtensions.Calls(i, typeof(OpCode).GetMethod("op_Equality"))), (string)null),
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => CodeInstructionExtensions.Branches(i, ref label)), (string)null),
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => CodeInstructionExtensions.IsLdloc(i, (LocalBuilder)null)), (string)null),
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => CodeInstructionExtensions.LoadsField(i, typeof(CodeInstruction).GetField("opcode"), false)), (string)null),
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => CodeInstructionExtensions.LoadsField(i, typeof(OpCodes).GetField("Leave_S"), false)), (string)null),
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => CodeInstructionExtensions.Calls(i, typeof(OpCode).GetMethod("op_Equality"))), (string)null),
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => CodeInstructionExtensions.Branches(i, ref label)), (string)null),
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => CodeInstructionExtensions.IsLdloc(i, (LocalBuilder)null)), (string)null),
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => CodeInstructionExtensions.LoadsField(i, typeof(CodeInstruction).GetField("blocks"), false)), (string)null),
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => CodeInstructionExtensions.Calls(i, typeof(List<ExceptionBlock>).GetMethod("get_Count"))), (string)null),
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => CodeInstructionExtensions.LoadsConstant(i, 0L)), (string)null),
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => CodeInstructionExtensions.Branches(i, ref label)), (string)null),
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => CodeInstructionExtensions.IsLdloc(i, (LocalBuilder)null)), (string)null),
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => CodeInstructionExtensions.Branches(i, ref label)), (string)null),
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => CodeInstructionExtensions.IsLdloc(i, (LocalBuilder)null)), (string)null),
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => CodeInstructionExtensions.LoadsField(i, typeof(CodeInstruction).GetField("blocks"), false)), (string)null),
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => CodeInstructionExtensions.Calls(i, typeof(List<ExceptionBlock>).GetMethod("get_Count"))), (string)null),
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => CodeInstructionExtensions.LoadsConstant(i, 0L)), (string)null),
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => CodeInstructionExtensions.Branches(i, ref label)), (string)null)
			};
			val.MatchForward(false, array);
			if (val.IsInvalid)
			{
				return instructions;
			}
			val.RemoveInstructions(array.Length);
			return val.InstructionEnumeration();
		}
	}
	[HarmonyPatch(typeof(ManagedMethodPatcher))]
	internal static class Patch_ManagedMethodPatcher
	{
		[HarmonyPatch("DetourTo")]
		[HarmonyTranspiler]
		public static IEnumerable<CodeInstruction> UndoPatchCorrectly(IEnumerable<CodeInstruction> instructions)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Expected O, but got Unknown
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Expected O, but got Unknown
			CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null);
			FieldInfo setIsApplied = AccessTools.Field(typeof(ILHookExtensions), "SetIsApplied");
			List<ExceptionBlock> blocks = val.SearchForward((Func<CodeInstruction, bool>)((CodeInstruction c) => CodeInstructionExtensions.LoadsField(c, setIsApplied, false))).Set(OpCodes.Nop, (object)null).Advance(1)
				.RemoveInstructions(4)
				.Blocks;
			val.Blocks = new List<ExceptionBlock>();
			val.Insert((CodeInstruction[])(object)new CodeInstruction[3]
			{
				new CodeInstruction(OpCodes.Ldarg_0, (object)null),
				CodeInstruction.LoadField(typeof(ManagedMethodPatcher), "ilHook", false),
				CodeInstruction.Call<ILHook>((Expression<Action<ILHook>>)((ILHook _) => _.Undo()))
			}).Blocks = blocks;
			return val.InstructionEnumeration();
		}
	}
	[HarmonyPatch(typeof(PatchClassProcessor))]
	internal static class Patch_PatchClassProcessor
	{
		[HarmonyPatch("GetBulkMethods")]
		[HarmonyTranspiler]
		public static IEnumerable<CodeInstruction> FixTargetMethodsCalledTwice(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Expected O, but got Unknown
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Expected O, but got Unknown
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Expected O, but got Unknown
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Expected O, but got Unknown
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Expected O, but got Unknown
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Expected O, but got Unknown
			CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null);
			MethodInfo method = typeof(PatchClassProcessor).GetMethods(BindingFlags.Instance | BindingFlags.NonPublic).First((MethodInfo m) => m.Name == "RunMethod" && m.GetGenericArguments().Length == 2).MakeGenericMethod(typeof(HarmonyTargetMethods), typeof(IEnumerable<MethodBase>));
			val.SearchForward((Func<CodeInstruction, bool>)((CodeInstruction c) => CodeInstructionExtensions.Calls(c, method))).Advance(-4).RemoveInstructions(4)
				.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1]
				{
					new CodeInstruction(OpCodes.Ldnull, (object)null)
				});
			val.SearchForward((Func<CodeInstruction, bool>)((CodeInstruction c) => c.operand is MethodInfo methodInfo && methodInfo.Name == "ToList")).Advance(1).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[5]
			{
				new CodeInstruction(OpCodes.Stloc_1, (object)null),
				new CodeInstruction(OpCodes.Ldarg_0, (object)null),
				new CodeInstruction(OpCodes.Ldloc_1, (object)null),
				CodeInstruction.Call((Expression<Action>)(() => ValidateTargetMethods(null, null))),
				new CodeInstruction(OpCodes.Ldloc_1, (object)null)
			});
			return val.InstructionEnumeration();
		}

		private static void ValidateTargetMethods(PatchClassProcessor classProcessor, List<MethodBase>? targetMethods)
		{
			string text = null;
			if (targetMethods == null)
			{
				text = "null";
			}
			else if (targetMethods.Any((MethodBase m) => (object)m == null))
			{
				text = "some element was null";
			}
			if (text != null)
			{
				if (classProcessor.auxilaryMethods.TryGetValue(typeof(HarmonyTargetMethods), out var value))
				{
					throw new Exception("Method " + GeneralExtensions.FullDescription((MethodBase)value) + " returned an unexpected result: " + text);
				}
				throw new Exception("Some method returned an unexpected result: " + text);
			}
		}
	}
	[HarmonyPatch(typeof(SymbolExtensions))]
	internal static class Patch_SymbolExtensions
	{
		[HarmonyPatch("GetMethodInfo", new Type[] { typeof(LambdaExpression) })]
		[HarmonyPrefix]
		public static bool MadeAbleToGetMethodWithoutParameters(LambdaExpression expression, out MethodInfo? __result)
		{
			if (expression.Body is UnaryExpression { Operand: MethodCallExpression { Object: ConstantExpression { Value: MethodInfo value } } })
			{
				__result = value;
				return false;
			}
			__result = null;
			return true;
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}