Skip to content

Commit 23eb58a

Browse files
macos solution?
1 parent f0c61de commit 23eb58a

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

gm_dotnet_managed/GmodNET/GameConsoleWriter.cs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,22 @@ public GameConsoleWriter(ILua lua)
4040
}
4141
else if (OperatingSystem.IsMacOS())
4242
{
43-
Msg = Msg_Tier0_MacOS;
43+
unsafe
44+
{
45+
IntPtr lib_handle = NativeLibrary.Load(Directory.GetCurrentDirectory() + "/GarrysMod_Signed.app/Contents/MacOS/libtier0.dylib");
46+
delegate* unmanaged[Cdecl]<byte*, void> msg_func = (delegate* unmanaged[Cdecl]<byte*, void>)NativeLibrary.GetExport(lib_handle, "Msg");
47+
48+
Msg = (message) =>
49+
{
50+
byte[] string_array = Encoding.UTF8.GetBytes(message);
51+
fixed (byte* ptr = &string_array[0])
52+
{
53+
msg_func(ptr);
54+
}
55+
};
56+
}
4457
}
45-
else Msg = (string msg) => { throw new PlatformNotSupportedException(); };
58+
else Msg = (string msg) => throw new PlatformNotSupportedException();
4659
}
4760

4861
#pragma warning disable CA2101 // workaround for https://github.com/dotnet/roslyn-analyzers/issues/5009
@@ -53,9 +66,6 @@ public GameConsoleWriter(ILua lua)
5366
[DllImport("tier0_client", EntryPoint = "Msg", CallingConvention = CallingConvention.Cdecl)]
5467
private static extern void Msg_Tier0_Client([MarshalAs(UnmanagedType.LPUTF8Str)] string msg);
5568

56-
[DllImport("GarrysMod_Signed/Contents/MacOS/libtier0.dylib", EntryPoint = "Msg", CallingConvention = CallingConvention.Cdecl)]
57-
private static extern void Msg_Tier0_MacOS([MarshalAs(UnmanagedType.LPUTF8Str)] string msg);
58-
5969
#pragma warning restore CA2101
6070

6171
private delegate void MsgFunc(string str);

0 commit comments

Comments
 (0)