Some mods may be broken due to the recent Alloyed Collective update.
Decompiled source of MonoDetour BepInEx 5 v0.7.7
patchers/0.com.github.MonoDetour.BepInEx.5.dll
Decompiled 6 days agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx.Logging; using Microsoft.CodeAnalysis; using Mono.Cecil; using MonoDetour.Interop.HarmonyX; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = ".NET Standard 2.0")] [assembly: AssemblyCompany("Hamunii")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("0.7.7.0")] [assembly: AssemblyInformationalVersion("0.7.7+d7c5fcdc39fb24ad6b0d68e7f1ff487bf6cbc1e7")] [assembly: AssemblyProduct("MonoDetour.BepInEx.5")] [assembly: AssemblyTitle("MonoDetour.BepInEx.5")] [assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/MonoDetour/MonoDetour")] [assembly: AssemblyVersion("0.7.7.0")] [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 MonoDetour.Logging { internal static class Patcher { [CompilerGenerated] private static class <>O { public static LogReceiver <0>__LogHandler; } internal static ManualLogSource Log = Logger.CreateLogSource("MonoDetour"); public static IEnumerable<string> TargetDLLs { get; } = Array.Empty<string>(); public static void Initialize() { //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_001b: Expected O, but got Unknown object obj = <>O.<0>__LogHandler; if (obj == null) { LogReceiver val = LogHandler; <>O.<0>__LogHandler = val; obj = (object)val; } MonoDetourLogger.OnLog += (LogReceiver)obj; HarmonyXInterop.Initialize(); } private static void LogHandler(LogChannel channel, string message) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Invalid comparison between Unknown and I4 //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Invalid comparison between Unknown and I4 //IL_0004: 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_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Invalid comparison between Unknown and I4 //IL_0019: 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: Invalid comparison between Unknown and I4 //IL_0039: 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_0040: 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) LogLevel val; if ((int)channel <= 4) { if ((int)channel != 0) { if ((int)channel != 4) { goto IL_0029; } val = (LogLevel)32; } else { val = (LogLevel)0; } } else if ((int)channel != 8) { if ((int)channel != 16) { goto IL_0029; } val = (LogLevel)2; } else { val = (LogLevel)4; } LogLevel val2 = val; Log.Log(val2, (object)message); return; IL_0029: throw new ArgumentOutOfRangeException("channel", "A log can only have a single known channel."); } public static void Patch(AssemblyDefinition _) { } } }
patchers/com.github.MonoDetour.Interop.HarmonyX.dll
Decompiled 6 days agousing System; using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; 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 Mono.Collections.Generic; using MonoDetour.Cil; using MonoDetour.DetourTypes.Manipulation; using MonoDetour.Interop.MonoModUtils; using MonoDetour.Logging; using MonoMod.Cil; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: InternalsVisibleTo("MonoDetour.UnitTests")] [assembly: IgnoresAccessChecksTo("0Harmony")] [assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = ".NET Standard 2.0")] [assembly: AssemblyCompany("Hamunii")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("0.7.7.0")] [assembly: AssemblyInformationalVersion("0.7.7+d7c5fcdc39fb24ad6b0d68e7f1ff487bf6cbc1e7")] [assembly: AssemblyProduct("MonoDetour.Interop.HarmonyX")] [assembly: AssemblyTitle("MonoDetour.Interop.HarmonyX")] [assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/MonoDetour/MonoDetour")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("0.7.7.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace MonoDetour.Interop.HarmonyX { internal static class EnforcePersistentInstructions { [CompilerGenerated] private static class <>O { public static Manipulator <0>__ILHook_HarmonyManipulator_MakeReturnLabel; public static Func<ILEmitter, HookTargetInfo> <1>__GetHookTargetInfo; public static Func<Instruction, HookTargetInfo, bool> <2>__IsPersistent; } internal static readonly MonoDetourManager persistentManager = new MonoDetourManager("com.github.MonoDetour.Interop.HarmonyX"); internal static void Init() { //IL_0042: 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_004d: Expected O, but got Unknown MethodInfo method = typeof(HarmonyManipulator).GetMethod("MakeReturnLabel", BindingFlags.Instance | BindingFlags.NonPublic); if ((object)method == null) { MonoDetourLogger.Log((IMonoDetourLogSource)(object)persistentManager, (LogChannel)16, "HarmonyManipulator.MakeReturnLabel doesn't exist!"); return; } MonoDetourManager obj = persistentManager; object obj2 = <>O.<0>__ILHook_HarmonyManipulator_MakeReturnLabel; if (obj2 == null) { Manipulator val = ILHook_HarmonyManipulator_MakeReturnLabel; <>O.<0>__ILHook_HarmonyManipulator_MakeReturnLabel = val; obj2 = (object)val; } obj.ILHook((MethodBase)method, (Manipulator)obj2, (MonoDetourConfig)null, true); } private static void ILHook_HarmonyManipulator_MakeReturnLabel(ILManipulationInfo info) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Expected O, but got Unknown //IL_01b5: Unknown result type (might be due to invalid IL or missing references) //IL_01c8: Unknown result type (might be due to invalid IL or missing references) //IL_0209: Unknown result type (might be due to invalid IL or missing references) //IL_0245: 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) HarmonyXInterop.anyFailed = true; ILWeaver w = new ILWeaver(info); Instruction loopStartOnLocSet = null; Instruction loopEnd = null; int locInstruction = 0; int num2 = default(int); FieldReference val6 = default(FieldReference); MethodReference val5 = default(MethodReference); int num = default(int); ILLabel val4 = default(ILLabel); ILWeaverResult val = w.MatchRelaxed(new Predicate<Instruction>[7] { (Instruction x) => ILPatternMatchingExt.MatchLdloc(x, ref num2), (Instruction x) => ILPatternMatchingExt.MatchLdfld(x, ref val6), (Instruction x) => ILPatternMatchingExt.MatchLdloc(x, ref locInstruction), (Instruction x) => ILPatternMatchingExt.MatchCallvirt(x, ref val5) && w.SetInstructionTo(ref loopEnd, x), (Instruction x) => ILPatternMatchingExt.MatchLdloc(x, ref num), (Instruction x) => ILPatternMatchingExt.MatchCallvirt<IEnumerator>(x, "MoveNext"), (Instruction x) => ILPatternMatchingExt.MatchBrtrue(x, ref val4) }); if (!val.IsValid) { MonoDetourLogger.Log((IMonoDetourLogSource)(object)persistentManager, (LogChannel)16, val.FailureMessage); return; } MethodReference val3 = default(MethodReference); val = w.MatchRelaxed(new Predicate<Instruction>[2] { (Instruction x) => ILPatternMatchingExt.MatchCallvirt(x, ref val3), (Instruction x) => ILPatternMatchingExt.MatchStloc(x, locInstruction) && w.SetInstructionTo(ref loopStartOnLocSet, x) }); if (!val.IsValid) { MonoDetourLogger.Log((IMonoDetourLogSource)(object)persistentManager, (LogChannel)16, val.FailureMessage); return; } VariableDefinition val2 = w.DeclareVariable(typeof(HookTargetInfo)); w.InsertBefore(w.First, (IEnumerable<Instruction>)new <>z__ReadOnlyArray<Instruction>((Instruction[])(object)new Instruction[4] { w.Create(OpCodes.Ldarg_0), w.Create<HarmonyManipulator>(OpCodes.Ldfld, "il"), w.CreateCall((Delegate)new Func<ILEmitter, HookTargetInfo>(GetHookTargetInfo)), w.Create(OpCodes.Stloc, val2) })); w.InsertBranchOverIfTrue(loopStartOnLocSet.Next, loopEnd, (IEnumerable<Instruction>)new <>z__ReadOnlyArray<Instruction>((Instruction[])(object)new Instruction[3] { w.Create(OpCodes.Ldloc, locInstruction), w.Create(OpCodes.Ldloc, val2), w.CreateCall((Delegate)new Func<Instruction, HookTargetInfo, bool>(IsPersistent)) })); HarmonyXInterop.anyFailed = false; } private static HookTargetInfo GetHookTargetInfo(ILEmitter il) { return HookTargetRecords.GetHookTargetInfo(il.IL.Body.Method); } private static bool IsPersistent(Instruction instruction, HookTargetInfo info) { return info.IsPersistentInstruction(instruction); } } public static class HarmonyXInterop { internal const string ManagerName = "com.github.MonoDetour.Interop.HarmonyX"; private static bool initialized; internal static bool anyFailed; public static void Initialize() { try { InternalInitialize(); } catch (Exception arg) { MonoDetourLogger.Log((LogChannel)16, $"HarmonyX interop exploded while trying to initialize: {arg}"); Dispose(); } } private static void InternalInitialize() { if (initialized) { return; } initialized = true; TrackInstructions.Init(); if (anyFailed) { MonoDetourLogger.Log((LogChannel)16, "HarmonyX interop module has completely failed to initialize."); return; } EnforcePersistentInstructions.Init(); if (anyFailed) { MonoDetourLogger.Log((LogChannel)16, "HarmonyX interop module has partly failed to initialize."); return; } TrackPatches.Init(); if (anyFailed) { MonoDetourLogger.Log((LogChannel)16, "HarmonyX interop module has partly failed to initialize."); } } internal static void Dispose() { TrackInstructions.instructionManager.DisposeHooks(); EnforcePersistentInstructions.persistentManager.DisposeHooks(); TrackPatches.patchManager.DisposeHooks(); initialized = false; } } internal static class TrackInstructions { [CompilerGenerated] private static class <>O { public static Manipulator <0>__ILHook_ILManipulator_WriteTo; public static Func<ILManipulator, MethodBody, Dictionary<CodeInstruction, (Instruction, bool)>> <1>__MapInstructions; public static Func<Dictionary<CodeInstruction, (Instruction, bool)>, List<Instruction>> <2>__CreateInstructionsList; public static Func<Dictionary<CodeInstruction, (Instruction, bool)>, Dictionary<Instruction, Instruction>> <3>__CreateOldToNewDictionary; public static Action<MethodBody, CodeInstruction, Dictionary<CodeInstruction, (Instruction, bool)>, List<Instruction>, Dictionary<Instruction, Instruction>> <4>__MapInstruction; public static Action<MethodBody, List<Instruction>, Dictionary<Instruction, Instruction>> <5>__UpdateOriginalInstructions; } internal static readonly MonoDetourManager instructionManager = new MonoDetourManager("com.github.MonoDetour.Interop.HarmonyX"); internal static void Init() { //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_004b: Expected O, but got Unknown MethodInfo method = typeof(ILManipulator).GetMethod("WriteTo"); if ((object)method == null) { MonoDetourLogger.Log((IMonoDetourLogSource)(object)instructionManager, (LogChannel)16, "ILManipulator.WriteTo doesn't exist!"); return; } MonoDetourManager obj = instructionManager; object obj2 = <>O.<0>__ILHook_ILManipulator_WriteTo; if (obj2 == null) { Manipulator val = ILHook_ILManipulator_WriteTo; <>O.<0>__ILHook_ILManipulator_WriteTo = val; obj2 = (object)val; } obj.ILHook((MethodBase)method, (Manipulator)obj2, (MonoDetourConfig)null, true); } private static void ILHook_ILManipulator_WriteTo(ILManipulationInfo info) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Expected O, but got Unknown //IL_0116: 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_0156: Unknown result type (might be due to invalid IL or missing references) //IL_0166: Unknown result type (might be due to invalid IL or missing references) //IL_019a: Unknown result type (might be due to invalid IL or missing references) //IL_01aa: 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_0201: 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_021f: Unknown result type (might be due to invalid IL or missing references) //IL_022f: Unknown result type (might be due to invalid IL or missing references) //IL_023f: Unknown result type (might be due to invalid IL or missing references) //IL_028b: 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_02a9: Unknown result type (might be due to invalid IL or missing references) HarmonyXInterop.anyFailed = true; ILWeaver val = new ILWeaver(info); if (!val.Body.HasExceptionHandlers) { MonoDetourLogger.Log((IMonoDetourLogSource)(object)instructionManager, (LogChannel)16, "ILManipulator.WriteTo has no Exception handlers!"); return; } ILLabel val2 = default(ILLabel); if (!ILPatternMatchingExt.MatchBr(val.Body.ExceptionHandlers[0].TryStart, ref val2)) { MonoDetourLogger.Log((IMonoDetourLogSource)(object)instructionManager, (LogChannel)16, "ILManipulator.WriteTo first try block's first instruction is not br!"); return; } Instruction val3 = InteropILLabel.InteropGetTarget(val2); val.CurrentTo(val3); int num = default(int); if (!ILPatternMatchingExt.MatchLdloc(val3, ref num)) { MonoDetourLogger.Log((IMonoDetourLogSource)(object)instructionManager, (LogChannel)16, "ILManipulator.WriteTo first try block's first instruction's branch target is not Ldloc! " + $"Instead it is: '{val3}'"); return; } int num2 = ((((VariableReference)val.Body.Variables[num]).VariableType != val.Context.Import(typeof(CodeInstruction))) ? (num + 1) : num); VariableDefinition val4 = val.DeclareVariable(typeof(Dictionary<CodeInstruction, (Instruction, bool)>)); VariableDefinition val5 = val.DeclareVariable(typeof(List<Instruction>)); VariableDefinition val6 = val.DeclareVariable(typeof(Dictionary<Instruction, Instruction>)); val.InsertBefore(val.First, (IEnumerable<Instruction>)new <>z__ReadOnlyArray<Instruction>((Instruction[])(object)new Instruction[10] { val.Create(OpCodes.Ldarg_0), val.Create(OpCodes.Ldarg_1), val.CreateCall((Delegate)new Func<ILManipulator, MethodBody, Dictionary<CodeInstruction, (Instruction, bool)>>(MapInstructions)), val.Create(OpCodes.Stloc, val4), val.Create(OpCodes.Ldloc, val4), val.CreateCall((Delegate)new Func<Dictionary<CodeInstruction, (Instruction, bool)>, List<Instruction>>(CreateInstructionsList)), val.Create(OpCodes.Stloc, val5), val.Create(OpCodes.Ldloc, val4), val.CreateCall((Delegate)new Func<Dictionary<CodeInstruction, (Instruction, bool)>, Dictionary<Instruction, Instruction>>(CreateOldToNewDictionary)), val.Create(OpCodes.Stloc, val6) })); val.InsertBeforeCurrent((IEnumerable<Instruction>)new <>z__ReadOnlyArray<Instruction>((Instruction[])(object)new Instruction[6] { val.Create(OpCodes.Ldarg_1), val.Create(OpCodes.Ldloc, num2), val.Create(OpCodes.Ldloc, val4), val.Create(OpCodes.Ldloc, val5), val.Create(OpCodes.Ldloc, val6), val.CreateCall((Delegate)new Action<MethodBody, CodeInstruction, Dictionary<CodeInstruction, (Instruction, bool)>, List<Instruction>, Dictionary<Instruction, Instruction>>(MapInstruction)) })); val.InsertBeforeStealLabels(val.Last, (IEnumerable<Instruction>)new <>z__ReadOnlyArray<Instruction>((Instruction[])(object)new Instruction[4] { val.Create(OpCodes.Ldarg_1), val.Create(OpCodes.Ldloc, val5), val.Create(OpCodes.Ldloc, val6), val.CreateCall((Delegate)new Action<MethodBody, List<Instruction>, Dictionary<Instruction, Instruction>>(UpdateOriginalInstructions)) })); HarmonyXInterop.anyFailed = false; } private static Dictionary<CodeInstruction, (Instruction, bool)> MapInstructions(ILManipulator manipulator, MethodBody body) { ReadOnlyCollection<Instruction> originalInstructions = HookTargetRecords.GetOriginalInstructions(body.Method); HashSet<Instruction> hashSet = new HashSet<Instruction>(); foreach (Instruction item in originalInstructions) { hashSet.Add(item); } HashSet<Instruction> hashSet2 = hashSet; IEnumerable<RawInstruction> codeInstructions = manipulator.codeInstructions; Dictionary<CodeInstruction, (Instruction, bool)> dictionary = new Dictionary<CodeInstruction, (Instruction, bool)>(codeInstructions.Count()); foreach (RawInstruction item2 in codeInstructions) { dictionary.Add(item2.Instruction, (item2.CILInstruction, hashSet2.Contains(item2.CILInstruction))); } return dictionary; } private static List<Instruction> CreateInstructionsList(Dictionary<CodeInstruction, (Instruction, bool)> harmonyToCecil) { return new List<Instruction>(harmonyToCecil.Count); } private static Dictionary<Instruction, Instruction> CreateOldToNewDictionary(Dictionary<CodeInstruction, (Instruction, bool)> harmonyToCecil) { return new Dictionary<Instruction, Instruction>(harmonyToCecil.Count); } private static void MapInstruction(MethodBody body, CodeInstruction cur, Dictionary<CodeInstruction, (Instruction, bool)> harmonyToCecil, List<Instruction> newOriginalInstructions, Dictionary<Instruction, Instruction> oldToNew) { if (!harmonyToCecil.TryGetValue(cur, out (Instruction, bool) value)) { return; } Collection<Instruction> instructions = body.Instructions; Instruction val = instructions[instructions.Count - 1]; if (!oldToNew.ContainsKey(value.Item1)) { oldToNew.Add(value.Item1, val); if (value.Item2) { newOriginalInstructions.Add(val); } } } private static void UpdateOriginalInstructions(MethodBody body, List<Instruction> newOriginalInstructions, Dictionary<Instruction, Instruction> oldToNew) { MethodDefinition method = body.Method; HookTargetRecords.SwapOriginalInstructionsCollection(method, new ReadOnlyCollection<Instruction>(newOriginalInstructions)); HookTargetInfo hookTargetInfo = HookTargetRecords.GetHookTargetInfo(body.Method); List<Instruction> firstPostfixInstructions = hookTargetInfo.PostfixInfo.FirstPostfixInstructions; for (int i = 0; i < firstPostfixInstructions.Count; i++) { Instruction key = firstPostfixInstructions[i]; if (oldToNew.TryGetValue(key, out Instruction value)) { firstPostfixInstructions[i] = value; } } Instruction[] array = hookTargetInfo.PersistentInstructions.ToArray(); hookTargetInfo.PersistentInstructions.Clear(); Instruction[] array2 = array; foreach (Instruction key2 in array2) { if (oldToNew.TryGetValue(key2, out Instruction value2)) { hookTargetInfo.MarkPersistentInstruction(value2); } } } } internal static class TrackPatches { [CompilerGenerated] private static class <>O { public static Manipulator <0>__ILHook_HarmonyManipulator_WritePrefixes; public static Manipulator <1>__ILHook_HarmonyManipulator_WritePostfixes; public static Func<ILEmitter, VariableDefinition?> <2>__GetRetVar; public static Func<ILEmitter, VariableDefinition?> <3>__GetRunOriginalParamVar; public static Func<ILEmitter, bool> <4>__RunOriginalParamLogic; public static Action<ILEmitter> <5>__ReturnLogic; public static <>A{00000001}<List<Label>, ILEmitter> <6>__AddStlocToLabelList; public static <>A{00000001}<List<Label>, Label> <7>__AddToLabelList; public static <>A{00000001}<List<Label>, ILEmitter> <8>__LabelsToMonoDetourPostfixes; } internal static readonly MonoDetourManager patchManager = new MonoDetourManager("com.github.MonoDetour.Interop.HarmonyX"); internal static void Init() { //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) //IL_0079: Expected O, but got Unknown //IL_00a9: 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_00b4: Expected O, but got Unknown MethodInfo method = typeof(HarmonyManipulator).GetMethod("WritePrefixes", BindingFlags.Instance | BindingFlags.NonPublic); if ((object)method == null) { MonoDetourLogger.Log((IMonoDetourLogSource)(object)patchManager, (LogChannel)16, "HarmonyManipulator.WritePrefixes doesn't exist!"); return; } MethodInfo method2 = typeof(HarmonyManipulator).GetMethod("WritePostfixes", BindingFlags.Instance | BindingFlags.NonPublic); if ((object)method2 == null) { MonoDetourLogger.Log((IMonoDetourLogSource)(object)patchManager, (LogChannel)16, "HarmonyManipulator.WritePostfixes doesn't exist!"); return; } MonoDetourManager obj = patchManager; object obj2 = <>O.<0>__ILHook_HarmonyManipulator_WritePrefixes; if (obj2 == null) { Manipulator val = ILHook_HarmonyManipulator_WritePrefixes; <>O.<0>__ILHook_HarmonyManipulator_WritePrefixes = val; obj2 = (object)val; } obj.ILHook((MethodBase)method, (Manipulator)obj2, (MonoDetourConfig)null, true); if (HarmonyXInterop.anyFailed) { patchManager.Dispose(); return; } MonoDetourManager obj3 = patchManager; object obj4 = <>O.<1>__ILHook_HarmonyManipulator_WritePostfixes; if (obj4 == null) { Manipulator val2 = ILHook_HarmonyManipulator_WritePostfixes; <>O.<1>__ILHook_HarmonyManipulator_WritePostfixes = val2; obj4 = (object)val2; } obj3.ILHook((MethodBase)method2, (Manipulator)obj4, (MonoDetourConfig)null, true); if (HarmonyXInterop.anyFailed) { patchManager.Dispose(); } } private static void ILHook_HarmonyManipulator_WritePrefixes(ILManipulationInfo info) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Expected O, but got Unknown //IL_06f0: Unknown result type (might be due to invalid IL or missing references) //IL_0703: Unknown result type (might be due to invalid IL or missing references) //IL_075f: Unknown result type (might be due to invalid IL or missing references) //IL_07ab: Unknown result type (might be due to invalid IL or missing references) //IL_07be: Unknown result type (might be due to invalid IL or missing references) //IL_081a: Unknown result type (might be due to invalid IL or missing references) //IL_084f: Unknown result type (might be due to invalid IL or missing references) //IL_0862: Unknown result type (might be due to invalid IL or missing references) //IL_08c6: Unknown result type (might be due to invalid IL or missing references) //IL_08d9: Unknown result type (might be due to invalid IL or missing references) HarmonyXInterop.anyFailed = true; ILWeaver w = new ILWeaver(info); Instruction ldarg0_ResultVar = null; Instruction ldarg0_RunOriginalParam = null; Instruction declareVar_ResultVar = null; Instruction declareVar_RunOriginalParam = null; Instruction start_RunOriginalParamLogic = null; Instruction end_RunOriginalParamLogic = null; Instruction end_RetLogic = null; Instruction ilEmitterField = null; FieldReference val24 = default(FieldReference); int num7 = default(int); IMetadataTokenProvider val23 = default(IMetadataTokenProvider); MethodReference val22 = default(MethodReference); MethodReference val21 = default(MethodReference); ILLabel val20 = default(ILLabel); FieldReference val19 = default(FieldReference); int num6 = default(int); ILWeaverResult val = w.MatchRelaxed(new Predicate<Instruction>[12] { (Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0), (Instruction x) => ILPatternMatchingExt.MatchLdfld(x, ref val24), (Instruction x) => ILPatternMatchingExt.MatchLdsfld<HarmonyManipulator>(x, "ResultVar"), (Instruction x) => ILPatternMatchingExt.MatchLdloc(x, ref num7), (Instruction x) => ILPatternMatchingExt.MatchLdtoken(x, ref val23), (Instruction x) => ILPatternMatchingExt.MatchCall(x, ref val22), (Instruction x) => ILPatternMatchingExt.MatchCall(x, ref val21), (Instruction x) => ILPatternMatchingExt.MatchBrtrue(x, ref val20), (Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0) && w.SetInstructionTo(ref ldarg0_ResultVar, x), (Instruction x) => ILPatternMatchingExt.MatchLdfld(x, ref val19) && w.SetInstructionTo(ref ilEmitterField, x), (Instruction x) => ILPatternMatchingExt.MatchLdloc(x, ref num6), (Instruction x) => ILPatternMatchingExt.MatchCallvirt<ILEmitter>(x, "DeclareVariable") && w.SetInstructionTo(ref declareVar_ResultVar, x) }); if (!val.IsValid) { FieldReference val18 = default(FieldReference); int num5 = default(int); IMetadataTokenProvider val17 = default(IMetadataTokenProvider); MethodReference val16 = default(MethodReference); ILLabel val15 = default(ILLabel); FieldReference val14 = default(FieldReference); int num4 = default(int); val = w.MatchRelaxed(new Predicate<Instruction>[11] { (Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0), (Instruction x) => ILPatternMatchingExt.MatchLdfld(x, ref val18), (Instruction x) => ILPatternMatchingExt.MatchLdsfld<HarmonyManipulator>(x, "ResultVar"), (Instruction x) => ILPatternMatchingExt.MatchLdloc(x, ref num5), (Instruction x) => ILPatternMatchingExt.MatchLdtoken(x, ref val17), (Instruction x) => ILPatternMatchingExt.MatchCall(x, ref val16), (Instruction x) => ILPatternMatchingExt.MatchBeq(x, ref val15), (Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0) && w.SetInstructionTo(ref ldarg0_ResultVar, x), (Instruction x) => ILPatternMatchingExt.MatchLdfld(x, ref val14) && w.SetInstructionTo(ref ilEmitterField, x), (Instruction x) => ILPatternMatchingExt.MatchLdloc(x, ref num4), (Instruction x) => ILPatternMatchingExt.MatchCallvirt<ILEmitter>(x, "DeclareVariable") && w.SetInstructionTo(ref declareVar_ResultVar, x) }); if (!val.IsValid) { MonoDetourLogger.Log((IMonoDetourLogSource)(object)patchManager, (LogChannel)16, val.FailureMessage); return; } } FieldReference val13 = default(FieldReference); FieldReference val12 = default(FieldReference); IMetadataTokenProvider val11 = default(IMetadataTokenProvider); MethodReference val10 = default(MethodReference); val = w.MatchRelaxed(new Predicate<Instruction>[8] { (Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0), (Instruction x) => ILPatternMatchingExt.MatchLdfld(x, ref val13), (Instruction x) => ILPatternMatchingExt.MatchLdsfld<HarmonyManipulator>(x, "RunOriginalParam"), (Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0) && w.SetInstructionTo(ref ldarg0_RunOriginalParam, x), (Instruction x) => ILPatternMatchingExt.MatchLdfld(x, ref val12), (Instruction x) => ILPatternMatchingExt.MatchLdtoken(x, ref val11), (Instruction x) => ILPatternMatchingExt.MatchCall(x, ref val10), (Instruction x) => ILPatternMatchingExt.MatchCallvirt<ILEmitter>(x, "DeclareVariable") && w.SetInstructionTo(ref declareVar_RunOriginalParam, x) }); if (!val.IsValid) { MonoDetourLogger.Log((IMonoDetourLogSource)(object)patchManager, (LogChannel)16, val.FailureMessage); return; } FieldReference val9 = default(FieldReference); int num3 = default(int); MethodReference val8 = default(MethodReference); FieldReference val7 = default(FieldReference); int num2 = default(int); MethodReference val6 = default(MethodReference); val = w.MatchRelaxed(new Predicate<Instruction>[10] { (Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0) && w.SetInstructionTo(ref start_RunOriginalParamLogic, x), (Instruction x) => ILPatternMatchingExt.MatchLdfld(x, ref val9), (Instruction x) => ILPatternMatchingExt.MatchLdsfld(x, typeof(OpCodes), "Ldloc"), (Instruction x) => ILPatternMatchingExt.MatchLdloc(x, ref num3), (Instruction x) => ILPatternMatchingExt.MatchCallvirt(x, ref val8), (Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0), (Instruction x) => ILPatternMatchingExt.MatchLdfld(x, ref val7), (Instruction x) => ILPatternMatchingExt.MatchLdsfld(x, typeof(OpCodes), "Brfalse"), (Instruction x) => ILPatternMatchingExt.MatchLdloc(x, ref num2), (Instruction x) => ILPatternMatchingExt.MatchCallvirt(x, ref val6) && w.SetInstructionTo(ref end_RunOriginalParamLogic, x) }); if (!val.IsValid) { MonoDetourLogger.Log((IMonoDetourLogSource)(object)patchManager, (LogChannel)16, val.FailureMessage); return; } FieldReference val5 = default(FieldReference); FieldReference val4 = default(FieldReference); int num = default(int); MethodReference val3 = default(MethodReference); ILLabel val2 = default(ILLabel); val = w.MatchRelaxed(new Predicate<Instruction>[7] { (Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0), (Instruction x) => ILPatternMatchingExt.MatchLdfld(x, ref val5), (Instruction x) => ILPatternMatchingExt.MatchLdsfld(x, ref val4), (Instruction x) => ILPatternMatchingExt.MatchLdloc(x, ref num), (Instruction x) => ILPatternMatchingExt.MatchCallvirt(x, ref val3) && w.SetInstructionTo(ref end_RetLogic, x), (Instruction x) => ILPatternMatchingExt.MatchLdcI4(x, 1), (Instruction x) => ILPatternMatchingExt.MatchRet(x) || ILPatternMatchingExt.MatchBr(x, ref val2) }); if (!val.IsValid) { MonoDetourLogger.Log((IMonoDetourLogSource)(object)patchManager, (LogChannel)16, val.FailureMessage); return; } w.InsertBranchOver(ldarg0_ResultVar, declareVar_ResultVar); w.InsertBeforeStealLabels(declareVar_ResultVar.Next, (IEnumerable<Instruction>)new <>z__ReadOnlyArray<Instruction>((Instruction[])(object)new Instruction[3] { w.Create(OpCodes.Ldarg_0), w.Create(OpCodes.Ldfld, ilEmitterField.Operand), w.CreateCall((Delegate)new Func<ILEmitter, VariableDefinition>(GetRetVar)) })); w.InsertAfter(declareVar_ResultVar, (IEnumerable<Instruction>)new <>z__ReadOnlySingleElementList<Instruction>(w.Create(OpCodes.Pop))); w.InsertBranchOver(ldarg0_RunOriginalParam, declareVar_RunOriginalParam); w.InsertBeforeStealLabels(declareVar_RunOriginalParam.Next, (IEnumerable<Instruction>)new <>z__ReadOnlyArray<Instruction>((Instruction[])(object)new Instruction[3] { w.Create(OpCodes.Ldarg_0), w.Create(OpCodes.Ldfld, ilEmitterField.Operand), w.CreateCall((Delegate)new Func<ILEmitter, VariableDefinition>(GetRunOriginalParamVar)) })); w.InsertAfter(declareVar_RunOriginalParam, (IEnumerable<Instruction>)new <>z__ReadOnlySingleElementList<Instruction>(w.Create(OpCodes.Pop))); w.InsertBranchOverIfTrue(start_RunOriginalParamLogic, end_RunOriginalParamLogic, (IEnumerable<Instruction>)new <>z__ReadOnlyArray<Instruction>((Instruction[])(object)new Instruction[3] { w.Create(OpCodes.Ldarg_0), w.Create(OpCodes.Ldfld, ilEmitterField.Operand), w.CreateCall((Delegate)new Func<ILEmitter, bool>(RunOriginalParamLogic)) })); w.InsertAfter(end_RetLogic, (IEnumerable<Instruction>)new <>z__ReadOnlyArray<Instruction>((Instruction[])(object)new Instruction[3] { w.Create(OpCodes.Ldarg_0), w.Create(OpCodes.Ldfld, ilEmitterField.Operand), w.CreateCall((Delegate)new Action<ILEmitter>(ReturnLogic)) })); HarmonyXInterop.anyFailed = false; } private static void ILHook_HarmonyManipulator_WritePostfixes(ILManipulationInfo info) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Expected O, but got Unknown //IL_0751: Unknown result type (might be due to invalid IL or missing references) //IL_0764: Unknown result type (might be due to invalid IL or missing references) //IL_07c0: Unknown result type (might be due to invalid IL or missing references) //IL_080c: Unknown result type (might be due to invalid IL or missing references) //IL_081f: Unknown result type (might be due to invalid IL or missing references) //IL_087b: Unknown result type (might be due to invalid IL or missing references) //IL_08c0: Unknown result type (might be due to invalid IL or missing references) //IL_08d4: Unknown result type (might be due to invalid IL or missing references) //IL_08e7: Unknown result type (might be due to invalid IL or missing references) //IL_094b: Unknown result type (might be due to invalid IL or missing references) //IL_095f: Unknown result type (might be due to invalid IL or missing references) //IL_09c3: Unknown result type (might be due to invalid IL or missing references) //IL_09d7: Unknown result type (might be due to invalid IL or missing references) //IL_0a40: Unknown result type (might be due to invalid IL or missing references) //IL_0a54: Unknown result type (might be due to invalid IL or missing references) //IL_0a67: Unknown result type (might be due to invalid IL or missing references) HarmonyXInterop.anyFailed = true; ILWeaver w = new ILWeaver(info); Instruction ldarg0_ResultVar = null; Instruction ldarg0_RunOriginalParam = null; Instruction declareVar_ResultVar = null; Instruction declareVar_RunOriginalParam = null; Instruction emitStloc = null; Instruction startLabel_1 = null; Instruction startLabel_2 = null; Instruction ilEmitterField = null; FieldReference val24 = default(FieldReference); int num9 = default(int); IMetadataTokenProvider val23 = default(IMetadataTokenProvider); MethodReference val22 = default(MethodReference); MethodReference val21 = default(MethodReference); ILLabel val20 = default(ILLabel); FieldReference val19 = default(FieldReference); int num8 = default(int); ILWeaverResult val = w.MatchRelaxed(new Predicate<Instruction>[12] { (Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0), (Instruction x) => ILPatternMatchingExt.MatchLdfld(x, ref val24), (Instruction x) => ILPatternMatchingExt.MatchLdsfld<HarmonyManipulator>(x, "ResultVar"), (Instruction x) => ILPatternMatchingExt.MatchLdloc(x, ref num9), (Instruction x) => ILPatternMatchingExt.MatchLdtoken(x, ref val23), (Instruction x) => ILPatternMatchingExt.MatchCall(x, ref val22), (Instruction x) => ILPatternMatchingExt.MatchCall(x, ref val21), (Instruction x) => ILPatternMatchingExt.MatchBrtrue(x, ref val20), (Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0) && w.SetInstructionTo(ref ldarg0_ResultVar, x), (Instruction x) => ILPatternMatchingExt.MatchLdfld(x, ref val19) && w.SetInstructionTo(ref ilEmitterField, x), (Instruction x) => ILPatternMatchingExt.MatchLdloc(x, ref num8), (Instruction x) => ILPatternMatchingExt.MatchCallvirt<ILEmitter>(x, "DeclareVariable") && w.SetInstructionTo(ref declareVar_ResultVar, x) }); if (!val.IsValid) { FieldReference val18 = default(FieldReference); int num7 = default(int); IMetadataTokenProvider val17 = default(IMetadataTokenProvider); MethodReference val16 = default(MethodReference); ILLabel val15 = default(ILLabel); FieldReference val14 = default(FieldReference); int num6 = default(int); val = w.MatchRelaxed(new Predicate<Instruction>[11] { (Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0), (Instruction x) => ILPatternMatchingExt.MatchLdfld(x, ref val18), (Instruction x) => ILPatternMatchingExt.MatchLdsfld<HarmonyManipulator>(x, "ResultVar"), (Instruction x) => ILPatternMatchingExt.MatchLdloc(x, ref num7), (Instruction x) => ILPatternMatchingExt.MatchLdtoken(x, ref val17), (Instruction x) => ILPatternMatchingExt.MatchCall(x, ref val16), (Instruction x) => ILPatternMatchingExt.MatchBeq(x, ref val15), (Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0) && w.SetInstructionTo(ref ldarg0_ResultVar, x), (Instruction x) => ILPatternMatchingExt.MatchLdfld(x, ref val14) && w.SetInstructionTo(ref ilEmitterField, x), (Instruction x) => ILPatternMatchingExt.MatchLdloc(x, ref num6), (Instruction x) => ILPatternMatchingExt.MatchCallvirt<ILEmitter>(x, "DeclareVariable") && w.SetInstructionTo(ref declareVar_ResultVar, x) }); if (!val.IsValid) { MonoDetourLogger.Log((IMonoDetourLogSource)(object)patchManager, (LogChannel)16, val.FailureMessage); return; } } FieldReference val13 = default(FieldReference); FieldReference val12 = default(FieldReference); IMetadataTokenProvider val11 = default(IMetadataTokenProvider); MethodReference val10 = default(MethodReference); val = w.MatchRelaxed(new Predicate<Instruction>[8] { (Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0), (Instruction x) => ILPatternMatchingExt.MatchLdfld(x, ref val13), (Instruction x) => ILPatternMatchingExt.MatchLdsfld<HarmonyManipulator>(x, "RunOriginalParam"), (Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0) && w.SetInstructionTo(ref ldarg0_RunOriginalParam, x), (Instruction x) => ILPatternMatchingExt.MatchLdfld(x, ref val12), (Instruction x) => ILPatternMatchingExt.MatchLdtoken(x, ref val11), (Instruction x) => ILPatternMatchingExt.MatchCall(x, ref val10), (Instruction x) => ILPatternMatchingExt.MatchCallvirt<ILEmitter>(x, "DeclareVariable") && w.SetInstructionTo(ref declareVar_RunOriginalParam, x) }); if (!val.IsValid) { MonoDetourLogger.Log((IMonoDetourLogSource)(object)patchManager, (LogChannel)16, val.FailureMessage); return; } int num5 = default(int); ILLabel val9 = default(ILLabel); FieldReference val8 = default(FieldReference); int num4 = default(int); val = w.MatchRelaxed(new Predicate<Instruction>[7] { (Instruction x) => ILPatternMatchingExt.MatchAnd(x) || ILPatternMatchingExt.MatchLdloc(x, ref num5), (Instruction x) => ILPatternMatchingExt.MatchBrfalse(x, ref val9), (Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0), (Instruction x) => ILPatternMatchingExt.MatchLdfld(x, ref val8), (Instruction x) => ILPatternMatchingExt.MatchLdsfld(x, typeof(OpCodes), "Stloc"), (Instruction x) => ILPatternMatchingExt.MatchLdloc(x, ref num4), (Instruction x) => ILPatternMatchingExt.MatchCallvirt<ILEmitter>(x, "Emit") && w.SetInstructionTo(ref emitStloc, x) }); if (!val.IsValid) { MonoDetourLogger.Log((IMonoDetourLogSource)(object)patchManager, (LogChannel)16, val.FailureMessage); return; } int num3 = default(int); FieldReference val7 = default(FieldReference); MethodReference val6 = default(MethodReference); int num2 = default(int); val = w.MatchRelaxed(new Predicate<Instruction>[5] { (Instruction x) => ILPatternMatchingExt.MatchStloc(x, ref num3), (Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0), (Instruction x) => ILPatternMatchingExt.MatchLdfld(x, ref val7), (Instruction x) => ILPatternMatchingExt.MatchCallvirt(x, ref val6), (Instruction x) => ILPatternMatchingExt.MatchStloc(x, ref num2) && w.SetInstructionTo(ref startLabel_1, x) }); if (!val.IsValid) { MonoDetourLogger.Log((IMonoDetourLogSource)(object)patchManager, (LogChannel)16, "3: " + val.FailureMessage); return; } MethodReference val5 = default(MethodReference); FieldReference val4 = default(FieldReference); MethodReference val3 = default(MethodReference); int num = default(int); val = w.MatchRelaxed(new Predicate<Instruction>[6] { (Instruction x) => ILPatternMatchingExt.MatchLdloc(x, 0), (Instruction x) => ILPatternMatchingExt.MatchCallvirt(x, ref val5), (Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0), (Instruction x) => ILPatternMatchingExt.MatchLdfld(x, ref val4), (Instruction x) => ILPatternMatchingExt.MatchCallvirt(x, ref val3), (Instruction x) => ILPatternMatchingExt.MatchStloc(x, ref num) && w.SetInstructionTo(ref startLabel_2, x) }); if (!val.IsValid) { MonoDetourLogger.Log((IMonoDetourLogSource)(object)patchManager, (LogChannel)16, "4: " + val.FailureMessage); return; } w.InsertBranchOver(ldarg0_ResultVar, declareVar_ResultVar); w.InsertBeforeStealLabels(declareVar_ResultVar.Next, (IEnumerable<Instruction>)new <>z__ReadOnlyArray<Instruction>((Instruction[])(object)new Instruction[3] { w.Create(OpCodes.Ldarg_0), w.Create(OpCodes.Ldfld, ilEmitterField.Operand), w.CreateCall((Delegate)new Func<ILEmitter, VariableDefinition>(GetRetVar)) })); w.InsertAfter(declareVar_ResultVar, (IEnumerable<Instruction>)new <>z__ReadOnlySingleElementList<Instruction>(w.Create(OpCodes.Pop))); w.InsertBranchOver(ldarg0_RunOriginalParam, declareVar_RunOriginalParam); w.InsertBeforeStealLabels(declareVar_RunOriginalParam.Next, (IEnumerable<Instruction>)new <>z__ReadOnlyArray<Instruction>((Instruction[])(object)new Instruction[3] { w.Create(OpCodes.Ldarg_0), w.Create(OpCodes.Ldfld, ilEmitterField.Operand), w.CreateCall((Delegate)new Func<ILEmitter, VariableDefinition>(GetRunOriginalParamVar)) })); w.InsertAfter(declareVar_RunOriginalParam, (IEnumerable<Instruction>)new <>z__ReadOnlySingleElementList<Instruction>(w.Create(OpCodes.Pop))); VariableDefinition val2 = w.DeclareVariable(typeof(List<Label>)); w.InsertAfter(emitStloc, (IEnumerable<Instruction>)new <>z__ReadOnlyArray<Instruction>((Instruction[])(object)new Instruction[4] { w.Create(OpCodes.Ldloca, val2), w.Create(OpCodes.Ldarg_0), w.Create(OpCodes.Ldfld, ilEmitterField.Operand), w.CreateCall((Delegate)new <>A{00000001}<List<Label>, ILEmitter>(AddStlocToLabelList)) })); w.InsertAfter(startLabel_1, (IEnumerable<Instruction>)new <>z__ReadOnlyArray<Instruction>((Instruction[])(object)new Instruction[3] { w.Create(OpCodes.Ldloca, val2), w.Create(OpCodes.Ldloc, startLabel_1.Operand), w.CreateCall((Delegate)new <>A{00000001}<List<Label>, Label>(AddToLabelList)) })); w.InsertAfter(startLabel_2, (IEnumerable<Instruction>)new <>z__ReadOnlyArray<Instruction>((Instruction[])(object)new Instruction[3] { w.Create(OpCodes.Ldloca, val2), w.Create(OpCodes.Ldloc, startLabel_2.Operand), w.CreateCall((Delegate)new <>A{00000001}<List<Label>, Label>(AddToLabelList)) })); w.InsertBeforeStealLabels(w.Last, (IEnumerable<Instruction>)new <>z__ReadOnlyArray<Instruction>((Instruction[])(object)new Instruction[4] { w.Create(OpCodes.Ldloca, val2), w.Create(OpCodes.Ldarg_0), w.Create(OpCodes.Ldfld, ilEmitterField.Operand), w.CreateCall((Delegate)new <>A{00000001}<List<Label>, ILEmitter>(LabelsToMonoDetourPostfixes)) })); HarmonyXInterop.anyFailed = false; } private static void AddStlocToLabelList(ref List<Label>? labels, ILEmitter il) { if (labels == null) { labels = new List<Label>(); } Collection<Instruction> instructions = il.IL.Body.Instructions; Label item = il.DeclareLabelFor(instructions[instructions.Count - 2]); labels.Add(item); } private static void AddToLabelList(ref List<Label>? labels, Label label) { if (labels == null) { labels = new List<Label>(); } labels.Add(label); } private static void LabelsToMonoDetourPostfixes(ref List<Label>? labels, ILEmitter il) { if (labels == null) { return; } foreach (Label label in labels) { HookTargetInfo hookTargetInfo = HookTargetRecords.GetHookTargetInfo(il.IL.Body.Method); hookTargetInfo.PostfixInfo.FirstPostfixInstructions.Add(label.instruction); } } private static VariableDefinition? GetRetVar(ILEmitter ilEmitter) { MethodDefinition method = ilEmitter.IL.Body.Method; HookTargetInfo hookTargetInfo = HookTargetRecords.GetHookTargetInfo(method); return hookTargetInfo.ReturnValue; } private static VariableDefinition? GetRunOriginalParamVar(ILEmitter ilEmitter) { MethodDefinition method = ilEmitter.IL.Body.Method; HookTargetInfo hookTargetInfo = HookTargetRecords.GetHookTargetInfo(method); return hookTargetInfo.PrefixInfo.ControlFlow; } private static bool RunOriginalParamLogic(ILEmitter il) { MethodDefinition method = il.IL.Body.Method; HookTargetInfo hookTargetInfo = HookTargetRecords.GetHookTargetInfo(method); if (hookTargetInfo.PrefixInfo.ControlFlowImplemented) { return true; } hookTargetInfo.PrefixInfo.SetControlFlowImplemented(); return false; } private static void ReturnLogic(ILEmitter il) { //IL_005f: Unknown result type (might be due to invalid IL or missing references) MethodDefinition method = il.IL.Body.Method; HookTargetInfo hookTargetInfo = HookTargetRecords.GetHookTargetInfo(method); if (hookTargetInfo.PostfixInfo.FirstPostfixInstructions.FirstOrDefault() == null) { return; } foreach (Instruction firstPostfixInstruction in hookTargetInfo.PostfixInfo.FirstPostfixInstructions) { if (il.IL.Body.Instructions.Contains(firstPostfixInstruction)) { il.Emit(OpCodes.Br, il.DeclareLabelFor(firstPostfixInstruction)); return; } } MonoDetourLogger.Log((IMonoDetourLogSource)(object)patchManager, (LogChannel)8, "While applying HarmonyX Prefixes: No postfix labels found despite postfixes being applied on the method. " + $"Postfixes might not run on method '{il.IL.Body.Method}'. "); } } } namespace System.Runtime.CompilerServices { [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] internal sealed class IgnoresAccessChecksToAttribute : Attribute { public IgnoresAccessChecksToAttribute(string assemblyName) { } } } [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(); } } [CompilerGenerated] internal sealed class <>z__ReadOnlySingleElementList<T> : IEnumerable, ICollection, IList, IEnumerable<T>, IReadOnlyCollection<T>, IReadOnlyList<T>, ICollection<T>, IList<T> { private sealed class Enumerator : IDisposable, IEnumerator, IEnumerator<T> { object IEnumerator.Current => _item; T IEnumerator<T>.Current => _item; public Enumerator(T item) { _item = item; } bool IEnumerator.MoveNext() { if (!_moveNextCalled) { return _moveNextCalled = true; } return false; } void IEnumerator.Reset() { _moveNextCalled = false; } void IDisposable.Dispose() { } } int ICollection.Count => 1; bool ICollection.IsSynchronized => false; object ICollection.SyncRoot => this; object IList.this[int index] { get { if (index != 0) { throw new IndexOutOfRangeException(); } return _item; } set { throw new NotSupportedException(); } } bool IList.IsFixedSize => true; bool IList.IsReadOnly => true; int IReadOnlyCollection<T>.Count => 1; T IReadOnlyList<T>.this[int index] { get { if (index != 0) { throw new IndexOutOfRangeException(); } return _item; } } int ICollection<T>.Count => 1; bool ICollection<T>.IsReadOnly => true; T IList<T>.this[int index] { get { if (index != 0) { throw new IndexOutOfRangeException(); } return _item; } set { throw new NotSupportedException(); } } public <>z__ReadOnlySingleElementList(T item) { _item = item; } IEnumerator IEnumerable.GetEnumerator() { return new Enumerator(_item); } void ICollection.CopyTo(Array array, int index) { array.SetValue(_item, index); } int IList.Add(object value) { throw new NotSupportedException(); } void IList.Clear() { throw new NotSupportedException(); } bool IList.Contains(object value) { return EqualityComparer<T>.Default.Equals(_item, (T)value); } int IList.IndexOf(object value) { if (!EqualityComparer<T>.Default.Equals(_item, (T)value)) { return -1; } return 0; } 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 new Enumerator(_item); } void ICollection<T>.Add(T item) { throw new NotSupportedException(); } void ICollection<T>.Clear() { throw new NotSupportedException(); } bool ICollection<T>.Contains(T item) { return EqualityComparer<T>.Default.Equals(_item, item); } void ICollection<T>.CopyTo(T[] array, int arrayIndex) { array[arrayIndex] = _item; } bool ICollection<T>.Remove(T item) { throw new NotSupportedException(); } int IList<T>.IndexOf(T item) { if (!EqualityComparer<T>.Default.Equals(_item, item)) { return -1; } return 0; } void IList<T>.Insert(int index, T item) { throw new NotSupportedException(); } void IList<T>.RemoveAt(int index) { throw new NotSupportedException(); } }