This repository has been archived by the owner on Nov 5, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
VRCToolsLogger.cs
85 lines (73 loc) · 2.5 KB
/
VRCToolsLogger.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
using System;
using System.IO;
using System.Runtime.InteropServices;
using UnityEngine;
namespace VRCTools
{
public abstract class VRCToolsLogger
{
[DllImport("kernel32.dll")]
internal static extern int AllocConsole();
[DllImport("kernel32.dll")]
public static extern IntPtr GetConsoleWindow();
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetForegroundWindow(IntPtr hWnd);
private static bool errorOccured = false;
public static void Init(bool showConsole)
{
if (showConsole)
{
AllocConsole();
Console.Title = "VRCTools by Slaynash";
Console.SetOut(new StreamWriter(Console.OpenStandardOutput())
{
AutoFlush = true
});
Console.SetIn(new StreamReader(Console.OpenStandardInput()));
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
Console.WriteLine("VRCTools by Slaynash");
}
}
private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
Error(((Exception)e.ExceptionObject).Message);
}
public static void Info(string str)
{
String tmp = " [VRCTools] " + str;
Debug.Log(tmp);
Console.WriteLine("[Info] " + tmp);
}
public static void Warn(string str)
{
String tmp = " [VRCTools] " + str;
Debug.LogWarning(tmp);
Console.WriteLine("[Warn] " + tmp);
}
public static void Update()
{
if (Input.GetKey(KeyCode.LeftControl) && Input.GetKeyDown(KeyCode.K))
{
errorOccured = false;
}
}
public static int OnGUI(int padding)
{
if (errorOccured)
{
GUI.color = Color.red;
GUI.Label(new Rect(0, Screen.height - padding, Screen.width, 20), "VRCTools: An error has occured (Press CTRL+K to hide/show)");
return 20;
}
return 0;
}
public static void Error(string str)
{
String tmp = " [VRCTools] " + str;
Debug.LogError(tmp);
Console.WriteLine("[Error] " + tmp);
errorOccured = true;
}
}
}