Skip to content

Patching ref parameter with IL2Cpp results in invalid IL #93

@wund3rcr4zy

Description

@wund3rcr4zy

Patch:

        [HarmonyPatch]
        public class SpeakHook
        {
            [HarmonyTargetMethod]
            static MethodBase TargetMethod()
            {
                MethodInfo target = AccessTools.Method(typeof(SpeechController), nameof(SpeechController.Speak),
                    [
                        typeof(Il2CppSystem.Collections.Generic.List<redacted extends Il2CppSystem.Object>).MakeByRefType(),
                        ... other types
                    ]);
                return target;
            }

            [HarmonyPostfix]
            public static void Postfix()
            {
                ByTheBookPlugin.Logger.LogInfo($"Speak triggered!!");
            }
        }

The MethodBase is correctly found by the TargetMethod function when I logged out the information.

Error:

[Error  :Il2CppInterop] During invoking native->managed trampoline
Exception: System.InvalidProgramException: Common Language Runtime detected an invalid program.
   at DMD<SpeechController::Speak>(SpeechController this, List`1& speechOptions, <other params redacted>)
   at (il2cpp -> managed) Speak(IntPtr , IntPtr* , IntPtr , IntPtr , IntPtr , IntPtr , Il2CppMethodInfo* )

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions