IL2CPPLogSource.cs 816 B

12345678910111213141516171819202122232425262728
  1. using System;
  2. using System.Runtime.InteropServices;
  3. using BepInEx.Logging;
  4. namespace BepInEx.IL2CPP.Logging
  5. {
  6. public class IL2CPPLogSource : ILogSource
  7. {
  8. public string SourceName { get; } = "IL2CPP";
  9. public event EventHandler<LogEventArgs> LogEvent;
  10. [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
  11. private delegate void IL2CPPLogCallbackDelegate([In][MarshalAs(UnmanagedType.LPStr)] string message);
  12. private void IL2CPPLogCallback(string message)
  13. {
  14. LogEvent?.Invoke(this, new LogEventArgs(message.Trim(), LogLevel.Message, this));
  15. }
  16. public IL2CPPLogSource()
  17. {
  18. var loggerPointer = Marshal.GetFunctionPointerForDelegate(new IL2CPPLogCallbackDelegate(IL2CPPLogCallback));
  19. UnhollowerBaseLib.IL2CPP.il2cpp_register_log_callback(loggerPointer);
  20. }
  21. public void Dispose() { }
  22. }
  23. }