Example #1
0
        public static MethodInfo UpdateWrapper(MethodBase original, ILGenerator il)
        {
            PatchProcessor    patchProcessor      = RimThreadedHarmony.harmony.CreateProcessor(original);
            PatchInfo         patchInfo           = HarmonySharedState.GetPatchInfo(patchProcessor.original) ?? new PatchInfo();
            bool              debug               = patchInfo.Debugging || Harmony.DEBUG;
            List <MethodInfo> sortedPatchMethods  = PatchFunctions.GetSortedPatchMethods(original, patchInfo.prefixes, debug);
            List <MethodInfo> sortedPatchMethods2 = PatchFunctions.GetSortedPatchMethods(original, patchInfo.postfixes, debug);
            List <MethodInfo> sortedPatchMethods3 = PatchFunctions.GetSortedPatchMethods(original, patchInfo.transpilers, debug);
            List <MethodInfo> sortedPatchMethods4 = PatchFunctions.GetSortedPatchMethods(original, patchInfo.finalizers, debug);
            Dictionary <int, CodeInstruction> finalInstructions;
            MethodPatcher methodPatcher = new MethodPatcher(original, null, sortedPatchMethods, sortedPatchMethods2, sortedPatchMethods3, sortedPatchMethods4, debug);

            methodPatcher.il = il;
            MethodInfo methodInfo = methodPatcher.CreateReplacement(out finalInstructions);

            if (methodInfo == null)
            {
                throw new MissingMethodException("Cannot create replacement for " + original.FullDescription());
            }
            try
            {
                Memory.DetourMethodAndPersist(original, methodInfo);
            } finally
            {
            }
            return(methodInfo);
        }
Example #2
0
 public static MethodBase GetOriginalFromHarmonyReplacement(long replacementAddr)
 {
     return(HarmonySharedState.WithState(() =>
     {
         return HarmonySharedState.originals
         .FirstOrDefault(kv => kv.Key.GetNativeStart().ToInt64() == replacementAddr).Value;
     }));
 }