forked from RocketMod/Rocket.Unturned
-
Notifications
You must be signed in to change notification settings - Fork 0
/
UnturnedConsole.cs
64 lines (56 loc) · 1.68 KB
/
UnturnedConsole.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
using System;
using System.IO;
using System.Threading;
using UnityEngine;
using Rocket.Core.Logging;
using SDG.Unturned;
namespace Rocket.Unturned
{
public class UnturnedConsole : MonoBehaviour
{
FileStream fileStream = null;
private void Awake()
{
try
{
fileStream = new FileStream(String.Format(Environment.ConsoleFile, Steam.InstanceName), FileMode.Create,FileAccess.Write,FileShare.ReadWrite);
StreamWriter streamWriter = new StreamWriter(fileStream, System.Text.Encoding.ASCII)
{
AutoFlush = true
};
System.Console.SetOut(streamWriter);
readingThread = new Thread(new ThreadStart(DoRead));
readingThread.Start();
}
catch (Exception ex)
{
Logger.Log("Error: " + ex.ToString());
}
}
private void Destroy() {
if (fileStream != null)
{
fileStream.Close();
fileStream.Dispose();
}
}
private static Thread readingThread;
private static void DoRead()
{
string x;
do
{
try
{
x = System.Console.ReadLine();
if (x != null && Steam.ConsoleInput != null && Steam.ConsoleInput.onInputText != null && x.Trim().Length != 0) Steam.ConsoleInput.onInputText(x);
}
catch (Exception ex)
{
Logger.LogException(ex);
}
}
while (true);
}
}
}