using 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.14.0")] [assembly: AssemblyInformationalVersion("0.7.14+0d55abe3fd0d330206803b376c57bc7135c48257")] [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.14.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] [CompilerGenerated] internal sealed class <>z__ReadOnlyArray : IEnumerable, ICollection, IList, IEnumerable, IReadOnlyCollection, IReadOnlyList, ICollection, IList { 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.Count => _items.Length; T IReadOnlyList.this[int index] => _items[index]; int ICollection.Count => _items.Length; bool ICollection.IsReadOnly => true; T IList.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 IEnumerable.GetEnumerator() { return ((IEnumerable)_items).GetEnumerator(); } void ICollection.Add(T item) { throw new NotSupportedException(); } void ICollection.Clear() { throw new NotSupportedException(); } bool ICollection.Contains(T item) { return ((ICollection)_items).Contains(item); } void ICollection.CopyTo(T[] array, int arrayIndex) { ((ICollection)_items).CopyTo(array, arrayIndex); } bool ICollection.Remove(T item) { throw new NotSupportedException(); } int IList.IndexOf(T item) { return ((IList)_items).IndexOf(item); } void IList.Insert(int index, T item) { throw new NotSupportedException(); } void IList.RemoveAt(int index) { throw new NotSupportedException(); } } [CompilerGenerated] internal sealed class <>z__ReadOnlySingleElementList : IEnumerable, ICollection, IList, IEnumerable, IReadOnlyCollection, IReadOnlyList, ICollection, IList { private sealed class Enumerator : IDisposable, IEnumerator, IEnumerator { object IEnumerator.Current => _item; T IEnumerator.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.Count => 1; T IReadOnlyList.this[int index] { get { if (index != 0) { throw new IndexOutOfRangeException(); } return _item; } } int ICollection.Count => 1; bool ICollection.IsReadOnly => true; T IList.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.Default.Equals(_item, (T)value); } int IList.IndexOf(object value) { if (!EqualityComparer.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 IEnumerable.GetEnumerator() { return new Enumerator(_item); } void ICollection.Add(T item) { throw new NotSupportedException(); } void ICollection.Clear() { throw new NotSupportedException(); } bool ICollection.Contains(T item) { return EqualityComparer.Default.Equals(_item, item); } void ICollection.CopyTo(T[] array, int arrayIndex) { array[arrayIndex] = _item; } bool ICollection.Remove(T item) { throw new NotSupportedException(); } int IList.IndexOf(T item) { if (!EqualityComparer.Default.Equals(_item, item)) { return -1; } return 0; } void IList.Insert(int index, T item) { throw new NotSupportedException(); } void IList.RemoveAt(int index) { throw new NotSupportedException(); } } 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 <1>__GetHookTargetInfo; public static Func <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(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[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(x, "MoveNext"), (Instruction x) => ILPatternMatchingExt.MatchBrtrue(x, ref val4) }); if (!val.IsValid) { MonoDetourLogger.Log(persistentManager, (LogChannel)16, val.FailureMessage); return; } MethodReference val3 = default(MethodReference); val = w.MatchRelaxed(new Predicate[2] { (Instruction x) => ILPatternMatchingExt.MatchCallvirt(x, ref val3), (Instruction x) => ILPatternMatchingExt.MatchStloc(x, locInstruction) && w.SetInstructionTo(ref loopStartOnLocSet, x) }); if (!val.IsValid) { MonoDetourLogger.Log(persistentManager, (LogChannel)16, val.FailureMessage); return; } VariableDefinition val2 = w.DeclareVariable(typeof(HookTargetInfo)); w.InsertBefore(w.First, (IEnumerable)new <>z__ReadOnlyArray((Instruction[])(object)new Instruction[4] { w.Create(OpCodes.Ldarg_0), w.Create(OpCodes.Ldfld, "il"), w.CreateCall((Delegate)new Func(GetHookTargetInfo)), w.Create(OpCodes.Stloc, val2) })); w.InsertBranchOverIfTrue(loopStartOnLocSet.Next, loopEnd, (IEnumerable)new <>z__ReadOnlyArray((Instruction[])(object)new Instruction[3] { w.Create(OpCodes.Ldloc, locInstruction), w.Create(OpCodes.Ldloc, val2), w.CreateCall((Delegate)new Func(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> <1>__MapInstructions; public static Func, List> <2>__CreateInstructionsList; public static Func, Dictionary> <3>__CreateOldToNewDictionary; public static Action, List, Dictionary> <4>__MapInstruction; public static Action, Dictionary> <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(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(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(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(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)); VariableDefinition val5 = val.DeclareVariable(typeof(List)); VariableDefinition val6 = val.DeclareVariable(typeof(Dictionary)); val.InsertBefore(val.First, (IEnumerable)new <>z__ReadOnlyArray((Instruction[])(object)new Instruction[10] { val.Create(OpCodes.Ldarg_0), val.Create(OpCodes.Ldarg_1), val.CreateCall((Delegate)new Func>(MapInstructions)), val.Create(OpCodes.Stloc, val4), val.Create(OpCodes.Ldloc, val4), val.CreateCall((Delegate)new Func, List>(CreateInstructionsList)), val.Create(OpCodes.Stloc, val5), val.Create(OpCodes.Ldloc, val4), val.CreateCall((Delegate)new Func, Dictionary>(CreateOldToNewDictionary)), val.Create(OpCodes.Stloc, val6) })); val.InsertBeforeCurrent((IEnumerable)new <>z__ReadOnlyArray((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, List, Dictionary>(MapInstruction)) })); val.InsertBeforeStealLabels(val.Last, (IEnumerable)new <>z__ReadOnlyArray((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, Dictionary>(UpdateOriginalInstructions)) })); HarmonyXInterop.anyFailed = false; } private static Dictionary MapInstructions(ILManipulator manipulator, MethodBody body) { ReadOnlyCollection originalInstructions = HookTargetRecords.GetOriginalInstructions(body.Method); HashSet hashSet = new HashSet(); foreach (Instruction item in originalInstructions) { hashSet.Add(item); } HashSet hashSet2 = hashSet; IEnumerable codeInstructions = manipulator.codeInstructions; Dictionary dictionary = new Dictionary(codeInstructions.Count()); foreach (RawInstruction item2 in codeInstructions) { dictionary.Add(item2.Instruction, (item2.CILInstruction, hashSet2.Contains(item2.CILInstruction))); } return dictionary; } private static List CreateInstructionsList(Dictionary harmonyToCecil) { return new List(harmonyToCecil.Count); } private static Dictionary CreateOldToNewDictionary(Dictionary harmonyToCecil) { return new Dictionary(harmonyToCecil.Count); } private static void MapInstruction(MethodBody body, CodeInstruction cur, Dictionary harmonyToCecil, List newOriginalInstructions, Dictionary oldToNew) { if (!harmonyToCecil.TryGetValue(cur, out (Instruction, bool) value)) { return; } Collection 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 newOriginalInstructions, Dictionary oldToNew) { MethodDefinition method = body.Method; HookTargetInfo hookTargetInfo = HookTargetRecords.GetHookTargetInfo(body.Method); HookTargetRecords.SwapOriginalInstructionsCollection(method, hookTargetInfo, new ReadOnlyCollection(newOriginalInstructions)); List 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 <2>__GetRetVar; public static Action <3>__RunOriginalParamInit; public static Func <4>__RunOriginalParamBranchLogic; public static Action <5>__ReturnLogic; public static <>A{00000001}, ILEmitter> <6>__AddStlocToLabelList; public static <>A{00000001}, Label> <7>__AddToLabelList; public static <>A{00000001}, 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(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(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_0713: Unknown result type (might be due to invalid IL or missing references) //IL_0726: Unknown result type (might be due to invalid IL or missing references) //IL_0782: Unknown result type (might be due to invalid IL or missing references) //IL_07b1: Unknown result type (might be due to invalid IL or missing references) //IL_07c4: Unknown result type (might be due to invalid IL or missing references) //IL_07d7: Unknown result type (might be due to invalid IL or missing references) //IL_07f5: Unknown result type (might be due to invalid IL or missing references) //IL_085a: Unknown result type (might be due to invalid IL or missing references) //IL_086d: Unknown result type (might be due to invalid IL or missing references) //IL_0880: Unknown result type (might be due to invalid IL or missing references) //IL_089e: Unknown result type (might be due to invalid IL or missing references) //IL_08fd: Unknown result type (might be due to invalid IL or missing references) //IL_0910: 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 declareVar_ResultVar = null; Instruction init_runOriginal = null; Instruction start_RunOriginalParamLogic = null; Instruction end_RunOriginalParamLogic = null; Instruction end_RetLogic = null; Instruction ilEmitterField = null; int loc_runOriginal = -1; 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[12] { (Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0), (Instruction x) => ILPatternMatchingExt.MatchLdfld(x, ref val24), (Instruction x) => ILPatternMatchingExt.MatchLdsfld(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(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[11] { (Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0), (Instruction x) => ILPatternMatchingExt.MatchLdfld(x, ref val18), (Instruction x) => ILPatternMatchingExt.MatchLdsfld(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(x, "DeclareVariable") && w.SetInstructionTo(ref declareVar_ResultVar, x) }); if (!val.IsValid) { MonoDetourLogger.Log(patchManager, (LogChannel)16, val.FailureMessage); return; } } FieldReference val13 = default(FieldReference); MethodReference val12 = default(MethodReference); FieldReference val11 = default(FieldReference); MethodReference val10 = default(MethodReference); val = w.MatchRelaxed(new Predicate[9] { (Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0), (Instruction x) => ILPatternMatchingExt.MatchLdfld(x, ref val13), (Instruction x) => ILPatternMatchingExt.MatchLdsfld(x, typeof(OpCodes), "Ldc_I4_1"), (Instruction x) => ILPatternMatchingExt.MatchCallvirt(x, ref val12), (Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0), (Instruction x) => ILPatternMatchingExt.MatchLdfld(x, ref val11), (Instruction x) => ILPatternMatchingExt.MatchLdsfld(x, typeof(OpCodes), "Stloc"), (Instruction x) => ILPatternMatchingExt.MatchLdloc(x, ref loc_runOriginal), (Instruction x) => ILPatternMatchingExt.MatchCallvirt(x, ref val10) && w.SetInstructionTo(ref init_runOriginal, x) }); if (!val.IsValid) { MonoDetourLogger.Log(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[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(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[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(patchManager, (LogChannel)16, val.FailureMessage); return; } w.InsertBranchOver(ldarg0_ResultVar, declareVar_ResultVar); w.InsertBeforeStealLabels(declareVar_ResultVar.Next, (IEnumerable)new <>z__ReadOnlyArray((Instruction[])(object)new Instruction[3] { w.Create(OpCodes.Ldarg_0), w.Create(OpCodes.Ldfld, ilEmitterField.Operand), w.CreateCall((Delegate)new Func(GetRetVar)) })); w.InsertAfter(declareVar_ResultVar, (IEnumerable)new <>z__ReadOnlySingleElementList(w.Create(OpCodes.Pop))); w.InsertAfter(init_runOriginal, (IEnumerable)new <>z__ReadOnlyArray((Instruction[])(object)new Instruction[5] { w.Create(OpCodes.Ldarg_0), w.Create(OpCodes.Ldarg_0), w.Create(OpCodes.Ldfld, ilEmitterField.Operand), w.Create(OpCodes.Ldloc, loc_runOriginal), w.CreateCall((Delegate)new Action(RunOriginalParamInit)) })); w.InsertBranchOverIfTrue(start_RunOriginalParamLogic, end_RunOriginalParamLogic, (IEnumerable)new <>z__ReadOnlyArray((Instruction[])(object)new Instruction[5] { w.Create(OpCodes.Ldarg_0), w.Create(OpCodes.Ldarg_0), w.Create(OpCodes.Ldfld, ilEmitterField.Operand), w.Create(OpCodes.Ldloc, loc_runOriginal), w.CreateCall((Delegate)new Func(RunOriginalParamBranchLogic)) })); w.InsertAfter(end_RetLogic, (IEnumerable)new <>z__ReadOnlyArray((Instruction[])(object)new Instruction[3] { w.Create(OpCodes.Ldarg_0), w.Create(OpCodes.Ldfld, ilEmitterField.Operand), w.CreateCall((Delegate)new Action(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_0805: Unknown result type (might be due to invalid IL or missing references) //IL_0819: Unknown result type (might be due to invalid IL or missing references) //IL_082c: Unknown result type (might be due to invalid IL or missing references) //IL_0890: Unknown result type (might be due to invalid IL or missing references) //IL_08a4: Unknown result type (might be due to invalid IL or missing references) //IL_0908: Unknown result type (might be due to invalid IL or missing references) //IL_091c: Unknown result type (might be due to invalid IL or missing references) //IL_0985: Unknown result type (might be due to invalid IL or missing references) //IL_0999: Unknown result type (might be due to invalid IL or missing references) //IL_09ac: 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[12] { (Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0), (Instruction x) => ILPatternMatchingExt.MatchLdfld(x, ref val24), (Instruction x) => ILPatternMatchingExt.MatchLdsfld(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(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[11] { (Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0), (Instruction x) => ILPatternMatchingExt.MatchLdfld(x, ref val18), (Instruction x) => ILPatternMatchingExt.MatchLdsfld(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(x, "DeclareVariable") && w.SetInstructionTo(ref declareVar_ResultVar, x) }); if (!val.IsValid) { MonoDetourLogger.Log(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[8] { (Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0), (Instruction x) => ILPatternMatchingExt.MatchLdfld(x, ref val13), (Instruction x) => ILPatternMatchingExt.MatchLdsfld(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(x, "DeclareVariable") && w.SetInstructionTo(ref declareVar_RunOriginalParam, x) }); if (!val.IsValid) { MonoDetourLogger.Log(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[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(x, "Emit") && w.SetInstructionTo(ref emitStloc, x) }); if (!val.IsValid) { MonoDetourLogger.Log(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[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(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[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(patchManager, (LogChannel)16, "4: " + val.FailureMessage); return; } w.InsertBranchOver(ldarg0_ResultVar, declareVar_ResultVar); w.InsertBeforeStealLabels(declareVar_ResultVar.Next, (IEnumerable)new <>z__ReadOnlyArray((Instruction[])(object)new Instruction[3] { w.Create(OpCodes.Ldarg_0), w.Create(OpCodes.Ldfld, ilEmitterField.Operand), w.CreateCall((Delegate)new Func(GetRetVar)) })); w.InsertAfter(declareVar_ResultVar, (IEnumerable)new <>z__ReadOnlySingleElementList(w.Create(OpCodes.Pop))); VariableDefinition val2 = w.DeclareVariable(typeof(List