53 lines
1.8 KiB
C#
Raw Normal View History

2020-08-21 14:04:13 +01:00
using OWML.Common;
2020-09-16 17:51:58 +01:00
using OWML.Logging;
using System.Diagnostics;
using System.Linq;
namespace QSB.Utility
2020-02-15 20:48:02 +01:00
{
2020-08-20 14:10:37 +01:00
public static class DebugLog
2020-02-15 20:48:02 +01:00
{
public static void ToConsole(string message, MessageType type = MessageType.Message)
{
2020-11-20 19:50:31 +00:00
// make custom method name in owml log.
// i wrote the owml code for this so this is fine?? shut up i dont want to change owml
2020-09-16 17:51:58 +01:00
var console = (ModSocketOutput)QSB.Helper.Console;
var method = console.GetType()
.GetMethods(System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance)
.Last(x => x.Name == "WriteLine");
var callingType = GetCallingType(new StackTrace());
method.Invoke(console, new object[] { type, message, callingType });
}
public static void ToHud(string message)
2020-02-15 20:48:02 +01:00
{
if (Locator.GetPlayerBody() == null)
{
return;
}
2020-08-24 16:01:33 +01:00
var data = new NotificationData(NotificationTarget.Player, message.ToUpper());
2020-07-28 15:59:24 +02:00
NotificationManager.SharedInstance.PostNotification(data);
}
2020-02-15 20:48:02 +01:00
public static void ToAll(string message, MessageType type = MessageType.Message)
2020-03-04 21:46:16 +01:00
{
ToConsole(message, type);
ToHud(message);
2020-03-04 21:46:16 +01:00
}
2020-08-10 18:17:54 +02:00
2020-08-22 20:21:13 +01:00
public static void DebugWrite(string message, MessageType type = MessageType.Message)
{
if (QSB.DebugMode)
{
ToConsole(message, type);
}
}
2020-09-22 21:00:56 +01:00
private static string GetCallingType(StackTrace frame)
2020-09-16 17:51:58 +01:00
{
2020-09-22 21:00:56 +01:00
var stackFrame = frame.GetFrames().First(x => x.GetMethod().DeclaringType.Name != "DebugLog");
return stackFrame.GetMethod().DeclaringType.Name;
2020-09-16 17:51:58 +01:00
}
}
}