Decompiled source of DetourContext Dispose Fix v1.0.3

patchers/Hamunii.DetourContext.Dispose_Fix.dll

Decompiled 7 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Mono.Cecil;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using MonoMod.RuntimeDetour;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Hamunii.DetourContext.Dispose_Fix")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.3.0")]
[assembly: AssemblyInformationalVersion("1.0.3+d2f7200abd14384aa282646a5cc4e9892bd4926f")]
[assembly: AssemblyProduct("DetourContext.Dispose_Fix")]
[assembly: AssemblyTitle("Hamunii.DetourContext.Dispose_Fix")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.3.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

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

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

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace DetourContext_Dispose_Fix
{
	internal class Patcher
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static Manipulator <0>__Fix_DetourContext_Dispose;
		}

		internal static ManualLogSource Logger = Logger.CreateLogSource("Hamunii.DetourContext.Dispose_Fix");

		private static ILHook disposeHook = null;

		public static IEnumerable<string> TargetDLLs { get; } = new string[0];


		public static void Initialize()
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Expected O, but got Unknown
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Expected O, but got Unknown
			MethodInfo methodInfo = AccessTools.DeclaredMethod(typeof(DetourContext), "Dispose", (Type[])null, (Type[])null);
			object obj = <>O.<0>__Fix_DetourContext_Dispose;
			if (obj == null)
			{
				Manipulator val = Fix_DetourContext_Dispose;
				<>O.<0>__Fix_DetourContext_Dispose = val;
				obj = (object)val;
			}
			disposeHook = new ILHook((MethodBase)methodInfo, (Manipulator)obj);
		}

		private static void Fix_DetourContext_Dispose(ILContext il)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			ILCursor val = new ILCursor(il);
			ILLabel val2 = default(ILLabel);
			if (!val.TryGotoNext(new Func<Instruction, bool>[4]
			{
				(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0),
				(Instruction x) => ILPatternMatchingExt.MatchLdfld<DetourContext>(x, "IsDisposed"),
				(Instruction x) => ILPatternMatchingExt.MatchBrtrue(x, ref val2),
				(Instruction x) => ILPatternMatchingExt.MatchRet(x)
			}))
			{
				Logger.LogInfo((object)"Nothing to patch.");
				return;
			}
			val.Index += 2;
			val.Next.OpCode = OpCodes.Brfalse_S;
		}

		public static void Patch(AssemblyDefinition _)
		{
		}
	}
}