BepInEx / HarmonyX

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

System.Reflection.Emit.ILGeneration is not supported on this platform when using Transpilers. #116

Open MarshMello0 opened 6 days ago

MarshMello0 commented 6 days ago

Using the latest release of HarmonyX, it keeps throwing not supported on this platform when using Transpilers. They work fine in BepInEx 6.0.0-pre.1. but the version of Harmony BepInEx uses is 2.10.1. I wanted to try also use this same version but its missing HarmonyPatchCategory so I couldn't compile my mod loader.

I remember in the past for .NET Standard (Unity) games we needed to add a version of mscorlib.dll that was not stripped down to remove runtime code generation. However I thought after Harmony started using MonoMod, this was no longer the case? Anyways putting that old patch in didn't solve the problem, so I assume this is something new.

Looking at BepInEx's assemblies it loads there was some differences between mine.

I need to add

- System.Reflection.Emit.ILGeneration.dll
- System.Reflection.Emit.Lightweight.dll

To load HarmonyX, otherwise I get this error message from Doorstop

`System.TypeInitializationException: The type initializer for 'HarmonyLib.Harmony' threw an exception. ---> System.TypeInitializationException: The type initializer for '<Module>' threw an exception. ---> System.TypeInitializationException: The type initializer for '<Module>' threw an exception. ---> System.TypeInitializationException: The type initializer for 'MonoMod.Logs.DebugLog' threw an exception. ---> System.TypeInitializationException: The type initializer for 'MonoMod.Switches' threw an exception. ---> System.TypeInitializationException: The type initializer for 'MonoMod.Utils.Extensions' threw an exception. ---> System.IO.FileNotFoundException: Could not load file or assembly 'System.Reflection.Emit.Lightweight, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies.`

Has anyone used the version 2.13.0 and got Transpilers to work?

MarshMello0 commented 6 days ago

This was my simple test which I used to confirm that they where not working in my Mod Loader. But working on the BepIn 6.0.0-pre1 which uses HarmonyX 2.10.1 instead of 2.13.0 The game its for is VTOL VR

    [HarmonyPatch(typeof(AirportManager), nameof(AirportManager.RequestLanding2))]
    public static class TranspilerTest
    {
        [HarmonyTranspiler]
        static IEnumerable<CodeInstruction> StringReplacer(IEnumerable<CodeInstruction> instructions)
        {
            Debug.Log("Start of Harmony Transpiler");
            var codes = new List<CodeInstruction>(instructions);

            foreach (var codeInstruction in codes)
            {
                if (codeInstruction.opcode != OpCodes.Ldstr)
                    continue;

                var oldText = codeInstruction.operand as string;
                Debug.Log($"Replacing '{oldText}'");
                codeInstruction.operand = "haha I've changed the text on this string";
            }
            Debug.Log("end of Harmony Transpiler");
            return codes.AsEnumerable();
        }
    }
ManlyMarco commented 6 days ago

What unity version does the game use? Did you hit this issue in any other games (ideally not VR only)?

MarshMello0 commented 6 days ago

VTOL VR is using Unity 2020.3.48f1

Did you hit this issue in any other games (ideally not VR only)?

I've just managed to reproduce it with Muck, it is using Unity 2019.4.19f1 and I see a netstandard.dll in its managed folder

I downloaded the latest release of doorstop and created a simple DLL which tries the similar patch.

Here is a zip of my test that also threw a System.Reflection.Emit.ILGeneration is not supported on this platform. but instead in the doorstop log (this is using the verbose one) MuckTranspilers.zip