예제 #1
0
        public PatchProcessor Patch(MethodBase original, HarmonyMethod prefix, HarmonyMethod postfix, HarmonyMethod transpiler = null)
        {
            var processor = new PatchProcessor(this, original, prefix, postfix, transpiler);

            processor.Patch();
            return(processor);
        }
예제 #2
0
        /// <summary>Creates patches by manually specifying the methods</summary>
        /// <param name="original">The original method</param>
        /// <param name="prefix">An optional prefix method wrapped in a HarmonyMethod object</param>
        /// <param name="postfix">An optional postfix method wrapped in a HarmonyMethod object</param>
        /// <param name="transpiler">An optional transpiler method wrapped in a HarmonyMethod object</param>
        /// <returns>The dynamic method that was created to patch the original method</returns>
        ///
        public DynamicMethod Patch(MethodBase original, HarmonyMethod prefix = null, HarmonyMethod postfix = null, HarmonyMethod transpiler = null)
        {
            var processor = new PatchProcessor(this, new List <MethodBase> {
                original
            }, prefix, postfix, transpiler);

            return(processor.Patch().FirstOrDefault());
        }
예제 #3
0
        public void PatchVoid(MethodBase original, HarmonyMethod prefix, HarmonyMethod postfix, HarmonyMethod transpiler)
        {
            var processor = new PatchProcessor(this, new List <MethodBase> {
                original
            }, prefix, postfix, transpiler);

            processor.Patch();
        }
예제 #4
0
        static void ApplyPatch(string owner, MethodBase target, HarmonyMethod prefix = null, HarmonyMethod postfix = null, HarmonyMethod transpiler = null)
        {
            var instance  = HarmonyInstance.Create(owner);
            var processor = new Harmony.PatchProcessor(instance, new List <MethodBase> {
                target
            }, prefix: prefix, postfix: postfix, transpiler: transpiler);

            processor.Patch();
        }
예제 #5
0
 /// <summary>Searches an assembly for Harmony annotations and uses them to create patches</summary>
 /// <param name="assembly">The assembly</param>
 ///
 public void PatchAll(Assembly assembly)
 {
     assembly.GetTypes().Do(type =>
     {
         var parentMethodInfos = type.GetHarmonyMethods();
         if (parentMethodInfos != null && parentMethodInfos.Count() > 0)
         {
             var info      = HarmonyMethod.Merge(parentMethodInfos);
             var processor = new PatchProcessor(this, type, info);
             processor.Patch();
         }
     });
 }
        public DynamicMethod Patch(MethodBase original, HarmonyMethod prefix = null, HarmonyMethod postfix = null, HarmonyMethod transpiler = null)
        {
            if ((original.DeclaringType.Assembly.GetCustomAttributes(typeof(HarmonyShield), false).Count() > 0) ||
                (original.DeclaringType.GetCustomAttributes(typeof(HarmonyShield), false).Count() > 0) ||
                (original.GetCustomAttributes(typeof(HarmonyShield), false).Count() > 0))
            {
                return(null);
            }
            var processor = new PatchProcessor(this, new List <MethodBase> {
                original
            }, prefix, postfix, transpiler);

            return(processor.Patch().FirstOrDefault());
        }
예제 #7
0
        public void TestMultiple()
        {
            var targetMethods = new List <MethodBase>()
            {
                AccessTools.Method(typeof(PatchProcessorClass1), nameof(PatchProcessorClass1.TestA)),
                AccessTools.Method(typeof(PatchProcessorClass1), nameof(PatchProcessorClass1.TestB))
            };
            var postfix   = new HarmonyMethod(typeof(PatchProcessorPatchClass1), nameof(PatchProcessorPatchClass1.Postfix));
            var harmony   = HarmonyInstance.Create("test");
            var processor = new Harmony.PatchProcessor(harmony, targetMethods, postfix: postfix);

            processor.Patch();
            Assert.AreEqual("Patched", PatchProcessorClass1.TestA(), "Test A");
            Assert.AreEqual("Patched", PatchProcessorClass1.TestB(), "Test B");
        }
 public void PatchAll(Assembly assembly)
 {
     if (assembly.GetCustomAttributes(typeof(HarmonyShield), false).Count() > 0)
     {
         return;
     }
     assembly.GetTypes().Do(type =>
     {
         var parentMethodInfos = type.GetHarmonyMethods();
         if (parentMethodInfos != null && parentMethodInfos.Count() > 0)
         {
             var info      = HarmonyMethod.Merge(parentMethodInfos);
             var processor = new PatchProcessor(this, type, info);
             processor.Patch();
         }
     });
 }
예제 #9
0
        public PatchInfoData Patch(MethodBase original, HarmonyMethod prefix, HarmonyMethod postfix, HarmonyMethod transpiler, PatchFlags flags)
        {
            var processor = new PatchProcessor(this, original, prefix, postfix, transpiler);

            return(processor.Patch(flags));
        }
예제 #10
0
        public void Patch(MethodBase original, HarmonyMethod prefix, HarmonyMethod postfix, HarmonyMethod infix = null)
        {
            var processor = new PatchProcessor(this, original, prefix, postfix, infix);

            processor.Patch();
        }