BepInEx / HarmonyX

Harmony built on top of MonoMod.RuntimeDetours with additional features
MIT License
329 stars 42 forks source link

fix double execution of TargetMethods #78

Closed Neutron3529 closed 1 year ago

Neutron3529 commented 1 year ago

fix #76.

This is a bugfix from https://github.com/pardeike/Harmony/commit/7ab508c95e336619d0b77eb0918d74ac10fbcc2c, which fixes a bug where Harmony calls TargetMethods() always twice.

Unit test:

using System;
using HarmonyLib;
using System.Reflection;
namespace Test {
    internal class Program {
        static void Main(string[] args) {
            var harmony=new Harmony("fine");
            harmony.PatchAll();
        }
    }
    [HarmonyPatch]
    class Test {
        static IEnumerable<MethodBase> TargetMethods() {
            Console.WriteLine("Hello World!");
            yield break;
        }
    }
}

this simple program currently generate 2 hello worlds, add another harmony.PatchAll(); would generate 4 hello worlds in total. After this patch, only one is generate per PatchAll.

@js6pak It seems @ghorsington has been inactive for half year, do you know what happened? And, could you please merge this PR for both HarmonyX and BepInEx?

ManlyMarco commented 1 year ago

Looks like upstream Harmony repo needs to be merged since there's a bunch of changes since the last merge.

For now I cherry picked the commit directly into https://github.com/BepInEx/HarmonyX/commit/4e71dc4f483a8432b001b34e0d2ba7faf47d59b1 so I'll close this PR.