Skip to content

Feature: Support osx-arm64#1090

Draft
BennyDioxide wants to merge 2 commits into
LavaGang:alpha-developmentfrom
BennyDioxide:feat/apple-silicon
Draft

Feature: Support osx-arm64#1090
BennyDioxide wants to merge 2 commits into
LavaGang:alpha-developmentfrom
BennyDioxide:feat/apple-silicon

Conversation

@BennyDioxide

Copy link
Copy Markdown

The build target itself is relatively easy, since it's just the work of building external binaries. But since HarmonyX finally supports Apple Silicon with the release of the version v2.15.0, We gotta wait for the huge amount of work of bumping versions.

Up to now, the binaries can have been built, just that MelonLoader can't hook into any game successfully.

Compiled from:
Dobby: latest@5dfc854
plthook: master@24c69df
@HerpDerpinstine HerpDerpinstine added Improvement New feature or request Work-in-Progress This issue or pull request is being worked on currently labels Feb 8, 2026
@HerpDerpinstine HerpDerpinstine added this to the 0.7.3 milestone Feb 25, 2026
@VeryNormalMan

Copy link
Copy Markdown

Hello There.
I Have Managed To Fix The Hooking, But I Am Met With This Error:

[04:55:23.742] [ERROR] [MelonLoader.Bootstrap] System.Reflection.CustomAttributeFormatException: Could not find a field with name CharSet
  at (wrapper managed-to-native) System.MonoCustomAttrs.GetCustomAttributesInternal(System.Reflection.ICustomAttributeProvider,System.Type,bool)
  at System.MonoCustomAttrs.GetCustomAttributesBase (System.Reflection.ICustomAttributeProvider obj, System.Type attributeType, System.Boolean inheritedOnly) [0x00013] in <2f16246080b843678677cb63fc90f43c>:0 
  at System.MonoCustomAttrs.GetCustomAttributes (System.Reflection.ICustomAttributeProvider obj, System.Type attributeType, System.Boolean inherit) [0x00037] in <2f16246080b843678677cb63fc90f43c>:0 
  at System.RuntimeType.GetCustomAttributes (System.Type attributeType, System.Boolean inherit) [0x00038] in <2f16246080b843678677cb63fc90f43c>:0 
  at MelonLoader.NativeLibrary`1[T]..ctor (System.IntPtr ptr) [0x000ee] in [REDACTED]/MelonLoader/MelonLoader/Utils/NativeLibrary.cs:143 
  at MelonLoader.InternalUtils.BootstrapInterop.Initialize (System.IntPtr bootstrapHandle) [0x00000] in [REDACTED]/MelonLoader/MelonLoader/InternalUtils/BootstrapInterop.cs:95 

@VeryNormalMan

Copy link
Copy Markdown
diff --git a/MelonLoader/Utils/NativeLibrary.cs b/MelonLoader/Utils/NativeLibrary.cs
--- a/MelonLoader/Utils/NativeLibrary.cs
+++ b/MelonLoader/Utils/NativeLibrary.cs
@@ -115,5 +115,15 @@
         public readonly T Instance;
 
+	private static bool HasUnmanagedFunctionPointer(Type type)
+	{
+	    foreach (var cad in CustomAttributeData.GetCustomAttributes(type))
+	    {
+		if (cad.Constructor.DeclaringType == typeof(UnmanagedFunctionPointerAttribute))
+		    return true;
+	    }
+	    return false;
+	}
+
         public NativeLibrary(IntPtr ptr) : base(ptr)
         {
             if (ptr == IntPtr.Zero)
@@ -131,7 +141,7 @@
                     continue;
 
                 var fieldType = fieldInfo.FieldType;
-                if (fieldType.GetCustomAttributes(typeof(UnmanagedFunctionPointerAttribute), false).Length == 0)
+                if (!HasUnmanagedFunctionPointer(fieldType))
                     continue;
 
                 fieldInfo.SetValue(Instance, GetExport(fieldType, fieldInfo.Name));
@@ -140,7 +150,7 @@
             foreach (var propertyInfo in specifiedType.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
             {
                 var fieldType = propertyInfo.PropertyType;
-                if (fieldType.GetCustomAttributes(typeof(UnmanagedFunctionPointerAttribute), false).Length == 0)
+                if (!HasUnmanagedFunctionPointer(fieldType))
                     continue;
 
                 propertyInfo.SetValue(Instance, GetExport(fieldType, propertyInfo.Name), null);

I tried this but it still doesn't work:

Could not load UnmanagedFunctionPointerAttribute due to Could not find a field with name CharSet assembly:<unknown assembly> type:<unknown type> member:(null)
Could not load UnmanagedFunctionPointerAttribute due to Could not find a field with name CharSet assembly:<unknown assembly> type:<unknown type> member:(null)
Could not load UnmanagedFunctionPointerAttribute due to Could not find a field with name CharSet assembly:<unknown assembly> type:<unknown type> member:(null)
[07:11:14.687] [ERROR] [MelonLoader.Bootstrap] Failed to invoke the managed init function
[GAME](26786,0x1f74fd8c0) malloc: *** error for object 0x1423d5000: pointer being freed was not allocated
[GAME](26786,0x1f74fd8c0) malloc: *** set a breakpoint in malloc_error_break to debug
[07:11:14.691] [UNITY] Obtained 38 stack frames.
[07:11:14.691] [UNITY] #0  0x0000018b6b85e8 in __pthread_kill
[07:11:14.691] [UNITY] #1  0x0000018b5fa790 in abort
[07:11:14.691] [UNITY] #2  0x0000018b4f3a40 in malloc_vreport
[07:11:14.691] [UNITY] #3  0x0000018b4f728c in malloc_report
[07:11:14.691] [UNITY] #4  0x0000018b4fc648 in ___BUG_IN_CLIENT_OF_LIBMALLOC_POINTER_BEING_FREED_WAS_NOT_ALLOCATED
[07:11:14.691] [UNITY] #5  0x00000105ef6f10 in GetLoaderConfig
[07:11:14.692] [UNITY] #6  0x000001057e78b4 in GetLoaderConfig
[07:11:14.692] [UNITY] #7  0x000001057e74a4 in GetLoaderConfig
[07:11:14.692] [UNITY] #8  0x000001057e5b94 in GetLoaderConfig
[07:11:14.692] [UNITY] #9  0x000001057e4d98 in GetLoaderConfig
[07:11:14.692] [UNITY] #10 0x00000105ef14f4 in GetLoaderConfig
[07:11:14.692] [UNITY] #11 0x00000108b64f80 in (Unknown)
[07:11:14.692] [UNITY] #12 0x00000108b8d95c in (Unknown)
[07:11:14.692] [UNITY] #13 0x000001096d9f44 in (Unknown)
[07:11:14.692] [UNITY] #14 0x000001096da40c in (Unknown)
[07:11:14.692] [UNITY] #15 0x000001096dcee4 in unity_operator_delete_dealloc
[07:11:14.692] [UNITY] #16 0x0000018b7a564c in __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__
[07:11:14.692] [UNITY] #17 0x0000018b831abc in ___CFXRegistrationPost_block_invoke
[07:11:14.692] [UNITY] #18 0x0000018b831a00 in _CFXRegistrationPost
[07:11:14.692] [UNITY] #19 0x0000018b774170 in _CFXNotificationPost
[07:11:14.692] [UNITY] #20 0x0000018cfa84a4 in -[NSNotificationCenter postNotificationName:object:userInfo:]
[07:11:14.692] [UNITY] #21 0x0000018fbe35e8 in -[NSApplication _postDidFinishNotification]
[07:11:14.692] [UNITY] #22 0x0000018fbe3380 in -[NSApplication _sendFinishLaunchingNotification]
[07:11:14.692] [UNITY] #23 0x0000018fbe19c4 in -[NSApplication(NSAppleEventHandling) _handleAEOpenEvent:]
[07:11:14.692] [UNITY] #24 0x0000018fbe15d8 in -[NSApplication(NSAppleEventHandling) _handleCoreEvent:withReplyEvent:]
[07:11:14.693] [UNITY] #25 0x0000018cfd0fbc in -[NSAppleEventManager dispatchRawAppleEvent:withRawReply:handlerRefCon:]
[07:11:14.693] [UNITY] #26 0x0000018cfd0db4 in _NSAppleEventManagerGenericHandler
[07:11:14.693] [UNITY] #27 0x000001939d9f34 in _AppleEventsCheckInAppWithBlock
[07:11:14.693] [UNITY] #28 0x000001939d988c in _AppleEventsCheckInAppWithBlock
[07:11:14.693] [UNITY] #29 0x000001939d2fb8 in aeProcessAppleEvent
[07:11:14.693] [UNITY] #30 0x000001984dd344 in AEProcessAppleEvent
[07:11:14.693] [UNITY] #31 0x0000018fbdb348 in _DPSNextEvent
[07:11:14.693] [UNITY] #32 0x0000019077069c in -[NSApplication(NSEventRouting) _nextEventMatchingEventMask:untilDate:inMode:dequeue:]
[07:11:14.693] [UNITY] #33 0x000001907703a8 in -[NSApplication(NSEventRouting) nextEventMatchingMask:untilDate:inMode:dequeue:]
[07:11:14.693] [UNITY] #34 0x0000018fbce13c in -[NSApplication run]
[07:11:14.693] [UNITY] #35 0x0000018fba67b0 in NSApplicationMain
[07:11:14.693] [UNITY] #36 0x000001096db4c4 in PlayerMain(int, char const**)
[07:11:14.693] [UNITY] #37 0x0000018b337da4 in start

@VeryNormalMan

Copy link
Copy Markdown

@BennyDioxide any ideas? im not very knowledgeable on this topic. ill drop my modifications if it helps

@VeryNormalMan

Copy link
Copy Markdown

MelonLoader-04-50-46.patch
compiled lib not here cuz it might have file paths, sry. run clang -Wall -Wextra -Wpedantic -Wno-cast-align -O3 -c plthook_osx.c -o osx-arm64/plthook.o && ar rcs osx-arm64/libplthook.a osx-arm64/plthook.o
plz fix the charset thingy :3

@VeryNormalMan

Copy link
Copy Markdown

it looks like the crash is same as #1145 so ig they have the same root cause

@VeryNormalMan

Copy link
Copy Markdown

i just tried it under rosetta with the latest stable and alpha and it did the same thing. so it just isn't compatible with this game on macos maybe unity version too new?

@VeryNormalMan

Copy link
Copy Markdown

it looks like the game is .net 9 but melonloader is loading .net 3.5 stuff, why?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Improvement New feature or request Work-in-Progress This issue or pull request is being worked on currently

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants