mirror of
https://github.com/BepInEx/BepInEx.git
synced 2026-11-19 13:17:07 +00:00
dbc82f05b8ea34833de5b6a723eb60dd8398e0b1
* fix(macos): load plugins when the game runs as native arm64 This is the v6 port of #1402, which fixed the same failure on v5-lts. MonoMod picks DetourNativeMonoPosixPlatform on Mono, whose MakeWritable and MakeExecutable call mprotect with PROT_READ|PROT_WRITE|PROT_EXEC. macOS on Apple Silicon answers EACCES, because a process without the com.apple.security.cs.allow-unsigned-executable-memory entitlement can never hold a page that is writable and executable at once. Unity ships com.apple.security.cs.allow-jit instead, so Mono's code lives in a MAP_JIT region, which also rejects mach_vm_write with KERN_INVALID_ADDRESS. The EACCES escapes DetourRuntimeILPlatform's constructor, which runs inside DetourHelper.Runtime's initialiser after _RuntimeInit is already set, so every later read of DetourHelper.Runtime returns null and every Harmony patch dies on a NullReferenceException in DetourHelper.GetIdentifiable. On v6 the first casualty is ConsoleSetOutFix.Apply, which is not wrapped in Utility.TryDo, so the whole preloader dies before it opens LogOutput.log. The only trace is a preloader_*.log beside the executable. v6 reaches this more easily than v5 does: run_bepinex_mono.sh sets ARCHPREFERENCE="arm64,x86_64" unconditionally on Apple Silicon, so a universal game runs as native arm64 by default and no opt-in is needed to hit the bug. AppleSiliconDetourFix installs a detour platform that keeps DetourNativeARMPlatform's AArch64 encoding and routes every code write through doorstop_jit_memcpy, which toggles pthread_jit_write_protect_np around its own memcpy. The toggle cannot be done from managed code: it drops execute permission for the calling thread, and the caller is itself running JIT-compiled code. XTermFix forced DetourNativeX86Platform on every non-Windows target. On Apple Silicon that encoded x86 branches into arm64 method bodies and reinstated the failing mprotect, so it is now skipped when the new fix applies. XTermFix also cleared DetourHelper.Native back to null on the way out, which would discard the platform installed here, so it now restores what it found. doorstop_jit_memcpy landed in UnityDoorstop via NeighTools/UnityDoorstop#114 and is not in the pinned 4.5.0 release. Until DoorstopVersion is bumped, this fix reports its absence as a warning through the preloader instead of failing silently, which is what happens today. Verified on an M4 Pro against Valheim 6000.0.75f1 (Unity Mono), with a probe plugin that Harmony-patches an already-JIT-compiled method: arm64, unpatched build: preloader dies, no LogOutput.log arm64, this build: plugin loads, Harmony patch applies x86_64, this build: plugin loads, Harmony patch applies * Move AppleSiliconDetourFix to BepInEx.Preloader.Core The IL2CPP preloader needs the same class, so keep one copy where both preloaders already reference it rather than a copy per runtime. * Cut the comments back to one line each
BepInEx
Bepis Injector Extensible
BepInEx is a plugin / modding framework for Unity Mono, IL2CPP and .NET framework games (XNA, FNA, MonoGame, etc.)
(Currently only Unity Mono has stable releases)
Platform compatibility chart
| Windows | OSX | Linux | ARM | |
|---|---|---|---|---|
| Unity Mono | ✔️ | ✔️ | ✔️ | N/A |
| Unity IL2CPP | ✔️ | ❌ | ✔ | ❌ |
| .NET / XNA | ✔️ | Mono | Mono | N/A |
A more comprehensive comparison list of features and compatibility is available at https://bepis.io/unity.html
Resources
How to install (latest releases)
How to install (Bleeding Edge, BepInEx 6)
Available plugin loaders
| Name | Link to project |
|---|---|
| BSIPA | BepInEx.BSIPA.Loader |
| IPA | IPALoaderX |
| MelonLoader | BepInEx.MelonLoader.Loader |
| MonoMod | BepInEx.MonoMod.Loader |
| MuseDashModLoader | BepInEx.MDML.Loader |
| Partiality | BepInEx-Partiality-Wrapper |
| Sybaris | BepInEx.SybarisLoader.Patcher |
| UnityInjector | BepInEx.UnityInjector.Loader |
| Unity Mod Manager | Yan.UMMLoader |
| uMod | BepInEx.uMod.Loader |
Used libraries
- NeighTools/UnityDoorstop - v4.6.0
- BepInEx/HarmonyX - v2.10.2
- 0x0ade/MonoMod - v22.7.31.1
- jbevain/cecil - v0.10.4
IL2CPP libraries
- SamboyCoding/Cpp2IL - v2022.1.0
- BepInEx/Il2CppInterop - v1.5.3
- BepInEx/dotnet-runtime - v6.0.7
License
The BepInEx project is licensed under the LGPL-2.1 license.
Languages
C#
95.9%
Shell
4.1%
