BepInEx icon indicating copy to clipboard operation
BepInEx copied to clipboard

MacOS arm64 (Apple Silicon) Support - Valheim

Open allquixotic opened this issue 1 year ago • 48 comments

Describe your problem

Valheim just released on MacOS today. Source

On Apple Silicon (arm64) hardware, the game launches an arm64 binary. It is still built with Mono as evidenced by the usual Mono directories in the app bundle.

It appears that the Mac builds of BepInEx are all for Intel x64 platform.

Proposed solution

Please provide builds of BepInEx for MacOS arm64, or create a Universal Binary. If you create a UB, then all the .dylib files for BepInEx will internally have both an Intel x64 build and an Apple arm64 build in the same file.

A Universal Binary will be easier for users, as they just have to download "the Mac version" and not worry about which architecture their game is running. Some Unity games only ship Intel x64 binaries, but others run natively on arm64 on Apple Silicon.

This game is getting significant exposure at WWDC 2024 and may appear in the Keynote. Mods with BepInEx are very popular, therefore you can expect to see many, many requests for this until it is implemented.

Alternatives

No response

allquixotic avatar Jun 10 '24 11:06 allquixotic

This is probably dependent on https://github.com/NeighTools/UnityDoorstop/issues/61 .

allquixotic avatar Jun 10 '24 17:06 allquixotic

Making some progress on https://github.com/NeighTools/UnityDoorstop/issues/61 --

Not sure if there is still a problem with the plthook_osx.c in Doorstop, but if there isn't, then something is amiss with Harmony.

See my preloader log for BepInEx/core/BepInEx.Unity.Mono.Preloader.dll on bleeding edge (it doesn't work with stable BepInEx core DLLs either):

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> HarmonyLib.HarmonyException: IL Compile Error (unknown location) ---> System.NullReferenceException: Object reference not set to an instance of an object
  at MonoMod.RuntimeDetour.DetourHelper.GetIdentifiable (System.Reflection.MethodBase method) [0x00005] in <7e79d87a23084646a4f7750a6feaa4c0>:0 
  at MonoMod.RuntimeDetour.ILHook..ctor (System.Reflection.MethodBase from, MonoMod.Cil.ILContext+Manipulator manipulator, MonoMod.RuntimeDetour.ILHookConfig& config) [0x0001c] in <7e79d87a23084646a4f7750a6feaa4c0>:0 
  at MonoMod.RuntimeDetour.ILHook..ctor (System.Reflection.MethodBase from, MonoMod.Cil.ILContext+Manipulator manipulator, MonoMod.RuntimeDetour.ILHookConfig config) [0x00000] in <7e79d87a23084646a4f7750a6feaa4c0>:0 
  at HarmonyLib.Public.Patching.ManagedMethodPatcher.DetourTo (System.Reflection.MethodBase replacement) [0x0000f] in <40a82cc9705b4865b72ee4c45165e7e9>:0 
  at HarmonyLib.PatchFunctions.UpdateWrapper (System.Reflection.MethodBase original, HarmonyLib.PatchInfo patchInfo) [0x00033] in <40a82cc9705b4865b72ee4c45165e7e9>:0 
   --- End of inner exception stack trace ---
  at HarmonyLib.PatchClassProcessor.ReportException (System.Exception exception, System.Reflection.MethodBase original) [0x00045] in <40a82cc9705b4865b72ee4c45165e7e9>:0 
  at HarmonyLib.PatchClassProcessor.Patch () [0x00095] in <40a82cc9705b4865b72ee4c45165e7e9>:0 
  at HarmonyLib.Harmony.PatchAll (System.Type type) [0x00008] in <40a82cc9705b4865b72ee4c45165e7e9>:0 
  at HarmonyLib.Harmony.CreateAndPatchAll (System.Type type, System.String harmonyInstanceId) [0x0001e] in <40a82cc9705b4865b72ee4c45165e7e9>:0 
  at BepInEx.Preloader.RuntimeFixes.ConsoleSetOutFix.Apply () [0x0001f] in /home/runner/work/BepInEx/BepInEx/BepInEx.Preloader.Core/RuntimeFixes/ConsoleSetOutFix.cs:18 
  at BepInEx.Unity.Mono.Preloader.UnityPreloaderRunner.PreloaderMain () [0x00011] in /home/runner/work/BepInEx/BepInEx/Runtimes/Unity/BepInEx.Unity.Mono.Preloader/UnityPreloaderRunner.cs:64 
  at BepInEx.Unity.Mono.Preloader.UnityPreloaderRunner.PreloaderPreMain () [0x00047] in /home/runner/work/BepInEx/BepInEx/Runtimes/Unity/BepInEx.Unity.Mono.Preloader/UnityPreloaderRunner.cs:56 
  at (wrapper managed-to-native) System.Reflection.RuntimeMethodInfo.InternalInvoke(System.Reflection.RuntimeMethodInfo,object,object[],System.Exception&)
  at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0006a] in <fd2d3e9b010a4ba4b3fdc0456cd6b40b>:0 
   --- End of inner exception stack trace ---
  at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00083] in <fd2d3e9b010a4ba4b3fdc0456cd6b40b>:0 
  at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in <fd2d3e9b010a4ba4b3fdc0456cd6b40b>:0 
  at Doorstop.Entrypoint.Start () [0x00034] in /home/runner/work/BepInEx/BepInEx/Runtimes/Unity/BepInEx.Unity.Mono.Preloader/DoorstopEntrypoint.cs:28 

The fact that the preloader log gets written tells me that this line of code is getting hit: https://github.com/BepInEx/BepInEx/blob/master/Runtimes/Unity/BepInEx.Unity.Mono.Preloader/DoorstopEntrypoint.cs#L34

... which means Doorstop did its job (?) and handed off into managed land and started executing BepInEx, but then BepInEx or Harmony has some problem.

I deleted my cache/ directory and it didn't help. Not very clear on how to proceed from here.

allquixotic avatar Jun 11 '24 05:06 allquixotic

Bumping to show interest in this solution.

thadawilliams avatar Jun 11 '24 16:06 thadawilliams

Bumping another time

TonioGela avatar Aug 06 '24 22:08 TonioGela

Any progress? can I build aarch from source?

logiota avatar Aug 21 '24 21:08 logiota

We are waiting on this issue: https://github.com/MonoMod/MonoMod/issues/90 Until this is done, no further progress can be made. Nobody seems to have a combination of skill, time and interest to work on https://github.com/MonoMod/MonoMod/issues/90 . Until someone solves https://github.com/MonoMod/MonoMod/issues/90 it will not be possible to run BepInEx on Apple Silicon.

allquixotic avatar Aug 21 '24 21:08 allquixotic

Apparently the key to Arm support in BepInEx and Hamrony is MonoMod.

TianMengLucky avatar Aug 22 '24 05:08 TianMengLucky