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;
|
2020-02-14 22:14:24 +01:00
|
|
|
|
|
2020-07-30 22:27:14 +02:00
|
|
|
|
namespace QSB.Utility
|
2020-02-15 20:48:02 +01:00
|
|
|
|
{
|
2020-12-02 21:23:01 +00:00
|
|
|
|
public static class DebugLog
|
|
|
|
|
{
|
|
|
|
|
public static void ToConsole(string message, MessageType type = MessageType.Message)
|
|
|
|
|
{
|
|
|
|
|
// 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
|
|
|
|
|
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 });
|
|
|
|
|
}
|
2020-07-28 00:13:43 +01:00
|
|
|
|
|
2020-12-02 21:23:01 +00:00
|
|
|
|
public static void ToHud(string message)
|
|
|
|
|
{
|
|
|
|
|
if (Locator.GetPlayerBody() == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var data = new NotificationData(NotificationTarget.Player, message.ToUpper());
|
|
|
|
|
NotificationManager.SharedInstance.PostNotification(data);
|
|
|
|
|
}
|
2020-02-15 20:48:02 +01:00
|
|
|
|
|
2020-12-02 21:23:01 +00:00
|
|
|
|
public static void ToAll(string message, MessageType type = MessageType.Message)
|
|
|
|
|
{
|
|
|
|
|
ToConsole(message, type);
|
|
|
|
|
ToHud(message);
|
|
|
|
|
}
|
2020-08-10 18:17:54 +02:00
|
|
|
|
|
2020-12-02 21:23:01 +00:00
|
|
|
|
public static void DebugWrite(string message, MessageType type = MessageType.Message)
|
|
|
|
|
{
|
|
|
|
|
if (QSB.DebugMode)
|
|
|
|
|
{
|
|
|
|
|
ToConsole(message, type);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-08-22 20:21:13 +01:00
|
|
|
|
|
2020-12-02 21:23:01 +00:00
|
|
|
|
private static string GetCallingType(StackTrace frame)
|
|
|
|
|
{
|
|
|
|
|
var stackFrame = frame.GetFrames().First(x => x.GetMethod().DeclaringType.Name != "DebugLog");
|
|
|
|
|
return stackFrame.GetMethod().DeclaringType.Name;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-02-14 22:14:24 +01:00
|
|
|
|
}
|