Skip to content

Fix bug on macOS#273

Open
sptndc wants to merge 3 commits into
BepInEx:masterfrom
sptndc:patch-1
Open

Fix bug on macOS#273
sptndc wants to merge 3 commits into
BepInEx:masterfrom
sptndc:patch-1

Conversation

@sptndc

@sptndc sptndc commented Jun 24, 2026

Copy link
Copy Markdown

This PR originates from #272 due to an accidental force-pushed incident.

sptndc added 3 commits June 24, 2026 15:53
This fixes an issue where `GameAssembly.dylib` was
not loaded for IL2CPP games on macOS.
Additionally, remove unnecessary `if` statements.
@ds5678 ds5678 closed this Jul 8, 2026
@ds5678 ds5678 reopened this 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);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Annotate these with [SupportedOSPlatform("osx")]

}

internal static void AddTypeToLookup<T>(IntPtr typePointer) where T : class => AddTypeToLookup(typeof(T), typePointer);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

internal static long CreateClassToken(IntPtr classPointer)
{
long newToken = Interlocked.Decrement(ref s_LastInjectedToken);
var newToken = Interlocked.Decrement(ref s_LastInjectedToken);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var newToken = Interlocked.Decrement(ref s_LastInjectedToken);
long newToken = Interlocked.Decrement(ref s_LastInjectedToken);

GenericMethodGetMethodHook_Unity6.ApplyHook();
else
GenericMethodGetMethodHook.ApplyHook();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

internal static void Setup()
{
if (InjectedAssembly == null) CreateInjectedAssembly();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

Comment on lines +238 to +239

var methodInfo = UnityVersionHandler.Wrap((Il2CppMethodInfo*)methodInfoPointer);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should be documented with a verifiable source and marked as [SupportedOSPlatform("osx")]

Comment on lines +13 to +16
{
ptr = XrefScannerLowLevel.JumpTargets(ptr).FirstOrDefault();
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be long instead of int?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants