Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transpiler patching an Enumerator's MoveNext method "blocks" Postfix patches on Enumerators created inside that method #55

Open
benediktwerner opened this issue Nov 18, 2022 · 0 comments

Comments

@benediktwerner
Copy link

benediktwerner commented Nov 18, 2022

Example code to be patched:

class C {
    IEnumerator FirstEnumerator() {
        yield return SecondEnumerator();
    }

    static IEnumerator SecondEnumerator() {
        yield break;
    }
}

Example plugin:

[BepInPlugin("test", "test", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
    static ManualLogSource L;

    private void Awake()
    {
        L = Logger;
        Harmony.CreateAndPatchAll(typeof(Plugin));
    }

    [HarmonyTranspiler]
    [HarmonyPatch(typeof(C), nameof(C.FirstEnumerator), MethodType.Enumerator)]
    public static IEnumerable<CodeInstruction> Test1(IEnumerable<CodeInstruction> instructions)
    {
        return instructions;
    }

    [HarmonyPostfix]
    [HarmonyPatch(typeof(C), nameof(C.SecondEnumerator))]
    public static void Test2()
    {
        L.LogDebug("postfix");
    }
}

When FirstEnumerator is executed, postfix is never logged. Removing the Test1 patch fixes it. This only seems to happen when the Test1 patch is applied before the Test2 patch and only on Enumerators as far as I can tell.

Version info:

[Message:   BepInEx] BepInEx 5.4.21.0 - Stacklands (04.05.2022 01:33:52)
[Info   :   BepInEx] Running under Unity v2020.3.6.3378102
[Info   :   BepInEx] CLR runtime version: 4.0.30319.17020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant