Fix bug on macOS#273
Open
sptndc wants to merge 3 commits into
Open
Conversation
This fixes an issue where `GameAssembly.dylib` was not loaded for IL2CPP games on macOS.
Additionally, remove unnecessary `if` statements.
ds5678
requested changes
Jul 8, 2026
Comment on lines
+120
to
+141
| [StructLayout(LayoutKind.Sequential)] | ||
| private struct DlInfo | ||
| { | ||
| public IntPtr dli_fname; | ||
| public IntPtr dli_fbase; | ||
| public IntPtr dli_sname; | ||
| public IntPtr dli_saddr; | ||
| } | ||
|
|
||
| [DllImport("libSystem.dylib", EntryPoint = "dlopen", CallingConvention = CallingConvention.Cdecl, | ||
| CharSet = CharSet.Ansi)] | ||
| private static extern IntPtr dlopen(string filename, int flags); | ||
|
|
||
| [DllImport("libSystem.dylib", EntryPoint = "dlerror", CallingConvention = CallingConvention.Cdecl)] | ||
| private static extern IntPtr dlerror(); | ||
|
|
||
| [DllImport("libSystem.dylib", EntryPoint = "dlsym", CallingConvention = CallingConvention.Cdecl, | ||
| CharSet = CharSet.Ansi)] | ||
| private static extern IntPtr dlsym(IntPtr handle, string symbol); | ||
|
|
||
| [DllImport("libSystem.dylib", EntryPoint = "dladdr", CallingConvention = CallingConvention.Cdecl)] | ||
| private static extern int dladdr(IntPtr addr, out DlInfo info); |
Collaborator
There was a problem hiding this comment.
Annotate these with [SupportedOSPlatform("osx")]
| } | ||
|
|
||
| internal static void AddTypeToLookup<T>(IntPtr typePointer) where T : class => AddTypeToLookup(typeof(T), typePointer); | ||
|
|
| internal static long CreateClassToken(IntPtr classPointer) | ||
| { | ||
| long newToken = Interlocked.Decrement(ref s_LastInjectedToken); | ||
| var newToken = Interlocked.Decrement(ref s_LastInjectedToken); |
Collaborator
There was a problem hiding this comment.
Suggested change
| var newToken = Interlocked.Decrement(ref s_LastInjectedToken); | |
| long newToken = Interlocked.Decrement(ref s_LastInjectedToken); |
| GenericMethodGetMethodHook_Unity6.ApplyHook(); | ||
| else | ||
| GenericMethodGetMethodHook.ApplyHook(); | ||
|
|
| internal static void Setup() | ||
| { | ||
| if (InjectedAssembly == null) CreateInjectedAssembly(); | ||
|
|
Comment on lines
+238
to
+239
|
|
||
| var methodInfo = UnityVersionHandler.Wrap((Il2CppMethodInfo*)methodInfoPointer); |
Collaborator
There was a problem hiding this comment.
Suggested change
| var methodInfo = UnityVersionHandler.Wrap((Il2CppMethodInfo*)methodInfoPointer); | |
| INativeMethodInfoStruct methodInfo = UnityVersionHandler.Wrap((Il2CppMethodInfo*)methodInfoPointer); |
Comment on lines
+295
to
+297
| throw new NotSupportedException( | ||
| "Failed to use signature for Class::Init and a substitute cannot be found, please create an " + | ||
| "issue and report your unity version & game"); |
Collaborator
There was a problem hiding this comment.
Please don't make formatting changes. It makes it harder to review your pull request
Comment on lines
+317
to
+366
| [StructLayout(LayoutKind.Sequential)] | ||
| private struct DlInfo | ||
| { | ||
| public IntPtr dli_fname; | ||
| public IntPtr dli_fbase; | ||
| public IntPtr dli_sname; | ||
| public IntPtr dli_saddr; | ||
| } | ||
|
|
||
| [StructLayout(LayoutKind.Sequential)] | ||
| private struct MachHeader64 | ||
| { | ||
| public uint magic; | ||
| public int cputype; | ||
| public int cpusubtype; | ||
| public uint filetype; | ||
| public uint ncmds; | ||
| public uint sizeofcmds; | ||
| public uint flags; | ||
| public uint reserved; | ||
| } | ||
|
|
||
| [StructLayout(LayoutKind.Sequential)] | ||
| private struct LoadCommand | ||
| { | ||
| public uint cmd; | ||
| public uint cmdsize; | ||
| } | ||
|
|
||
| [StructLayout(LayoutKind.Sequential)] | ||
| private struct SegmentCommand64 | ||
| { | ||
| public uint cmd; | ||
| public uint cmdsize; | ||
|
|
||
| [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)] | ||
| public string segname; | ||
|
|
||
| public ulong vmaddr; | ||
| public ulong vmsize; | ||
| public ulong fileoff; | ||
| public ulong filesize; | ||
| public int maxprot; | ||
| public int initprot; | ||
| public uint nsects; | ||
| public uint flags; | ||
| } | ||
|
|
||
| [DllImport("libSystem.dylib", EntryPoint = "dladdr", CallingConvention = CallingConvention.Cdecl)] | ||
| private static extern int dladdr(IntPtr addr, out DlInfo info); |
Collaborator
There was a problem hiding this comment.
These should be documented with a verifiable source and marked as [SupportedOSPlatform("osx")]
Comment on lines
+13
to
+16
| { | ||
| ptr = XrefScannerLowLevel.JumpTargets(ptr).FirstOrDefault(); | ||
| } | ||
|
|
Collaborator
There was a problem hiding this comment.
Please remove these formatting changes
|
|
||
| internal static IntPtr Il2CppHandle = NativeLibrary.Load("GameAssembly", typeof(InjectorHelpers).Assembly, null); | ||
| internal static IntPtr Il2CppModuleBaseAddress => GetIl2CppModuleBaseAddress(); | ||
| internal static int Il2CppModuleMemorySize => GetIl2CppModuleMemorySize(); |
Collaborator
There was a problem hiding this comment.
Should this be long instead of int?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR originates from #272 due to an accidental force-pushed incident.