diff --git a/Debug-Console/Debug-Console.cs b/Debug-Console/Debug-Console.cs new file mode 100644 index 0000000..9566701 --- /dev/null +++ b/Debug-Console/Debug-Console.cs @@ -0,0 +1,28 @@ +string Version = "0.1-alpha"; +Console.Title = "LumKitty's Debug console v" + Version; +Console.WriteLine("LumKitty's Debug console v"+Version+" - https://github.com/LumKitty - https://twitch.tv/LumKitty"); +String LineInput; +while (true) +{ + LineInput = Console.ReadLine(); + if (LineInput != null) + { + if (LineInput.Length >= 4) + { + switch (LineInput.Substring(0,4)) + { + case "LOG:": + Console.ForegroundColor = ConsoleColor.Yellow; + break; + case "ERR:": + Console.ForegroundColor = ConsoleColor.Red; + break; + case "TRG:": + Console.ForegroundColor = ConsoleColor.Cyan; + break; + } + } + Console.WriteLine(LineInput); + Console.ForegroundColor = ConsoleColor.White; + } +} diff --git a/Debug-Console/Debug-Console.csproj b/Debug-Console/Debug-Console.csproj new file mode 100644 index 0000000..7ad7387 --- /dev/null +++ b/Debug-Console/Debug-Console.csproj @@ -0,0 +1,15 @@ + + + + Exe + net8.0 + Debug_Console + enable + enable + true + true + win-x64 + x64 + + + diff --git a/Debug-Plugin/Debug-Plugin.cs b/Debug-Plugin/Debug-Plugin.cs new file mode 100644 index 0000000..9588a28 --- /dev/null +++ b/Debug-Plugin/Debug-Plugin.cs @@ -0,0 +1,215 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Globalization; +using System.IO; +using System.Linq; +using System.Net; +using System.Net.Http; +using System.Net.NetworkInformation; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using System.Xml.Linq; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using UnityEngine; +using UnityEngine.XR; +using static UnityEngine.Networking.UnityWebRequest; + +namespace Debug_Plugin +{ + public class Debug_Plugin : MonoBehaviour, VNyanInterface.IButtonClickedHandler, VNyanInterface.ITriggerHandler + { + private string ErrorFile = ""; + string TriggersFile = VNyanInterface.VNyanInterface.VNyanSettings.getProfilePath() + "Lum-Debug-Triggers.txt"; + private string LogFile = ""; + private string Version = "0.1-alpha"; + private string ConsolePath = ""; + private StreamWriter DebugStreamWriter = null; + private Process DebugProcess = null; + dynamic SettingsJSON; + List MonitorTriggers; + private void Log(string message) + { + if (LogFile.ToString().Length > 0) + { + System.IO.File.AppendAllText(LogFile, message + "\r\n"); + } + if (DebugStreamWriter != null) + { + DebugStreamWriter.WriteLine(message); + } + } + + private void LoadPluginSettings() + { + // Get settings in dictionary + Dictionary settings = VNyanInterface.VNyanInterface.VNyanSettings.loadSettings("Lum-Debug.cfg"); + if (settings != null) + { + string temp_ErrorFile; + string temp_LogFile; + settings.TryGetValue("ErrorFile", out temp_ErrorFile); + settings.TryGetValue("LogFile", out temp_LogFile); + if (temp_ErrorFile != null) + { + ErrorFile = temp_ErrorFile; + } + else + { + ErrorFile = System.IO.Path.GetTempPath() + "\\Lum_DBG_Error.txt"; + } + if (temp_LogFile != null) + { + LogFile = temp_LogFile; + } + else + { + LogFile = System.IO.Path.GetTempPath() + "\\Lum_DBG_Log.txt"; + } + } + /*if (File.Exists(TriggersFile)) + { + String[] Triggers = File.ReadLines(TriggersFile).ToString().Split('\n'); + foreach (string Trigger in Triggers) { + MonitorTriggers.Add(Trigger.ToString()); + } + }*/ + + } + private void OnApplicationQuit() + { + // Save settings + SavePluginSettings(); + } + private void SavePluginSettings() + { + Dictionary settings = new Dictionary(); + settings["ErrorFile"] = ErrorFile; + settings["LogFile"] = LogFile; + // settings["SomeValue2"] = someValue2.ToString(CultureInfo.InvariantCulture); // Make sure to use InvariantCulture to avoid decimal delimeter errors + + VNyanInterface.VNyanInterface.VNyanSettings.saveSettings("Lum-Debug.cfg", settings); + //File.WriteAllText(JsonFile, SettingsJSON.ToString()); + } + + void ErrorHandler(Exception e) + { + System.IO.File.WriteAllText(ErrorFile, e.ToString()); + CallVNyan("_lum_miu_error", 0, 0, 0, e.ToString(), "", ""); + } + void CallVNyan(string TriggerName, int int1, int int2, int int3, string Text1, string Text2, string Text3) + { + if (TriggerName.Length > 0) + { + Log("Calling " + TriggerName + " with " + int1.ToString() + ", " + int2.ToString() + ", " + int3.ToString() + ", " + Text1 + ", " + Text2 + ", " + Text3); + VNyanInterface.VNyanInterface.VNyanTrigger.callTrigger(TriggerName, int1, int2, int3, Text1, Text2, Text3); + } + else + { + Log("Invalid trigger name"); + } + } + public void Awake() + { + try + { + VNyanInterface.VNyanInterface.VNyanTrigger.registerTriggerListener(this); + VNyanInterface.VNyanInterface.VNyanUI.registerPluginButton("LumKitty's Debug Tool", this); + LoadPluginSettings(); + System.IO.File.WriteAllText(LogFile, "Started v"+Version+"\r\n"); + string CommandLine = Environment.CommandLine; + if (CommandLine[0] == '"') + { + int n = CommandLine.IndexOf('"', 1); + CommandLine = CommandLine.Substring(1, n - 1); + } else + { + CommandLine = CommandLine.Substring(0,CommandLine.IndexOf(" ")); + } + Log("VNyan path: " + CommandLine); + ConsolePath = Path.GetDirectoryName(CommandLine) + "\\Items\\Assemblies\\Debug-Console.exe"; + if (File.Exists(ConsolePath)) + { + Log("Debug Console found at: " + ConsolePath); + } else + { + Log("Debug Console not found should be at: " + ConsolePath); + } + } + catch (Exception e) + { + ErrorHandler(e); + } + } + public void triggerCalled(string name, int int1, int int2, int int3, string text1, string text2, string text3) + { + try + { + if (name.Length > 10) + { + if (name.Substring(0, 9) == "_lum_dbg_") + { + //Log("Detected trigger: " + name + " with " + int1.ToString() + ", " + SessionID.ToString() + ", " + PlatformID.ToString() + ", " + text1 + ", " + text2 + ", " + Callback); + switch (name.Substring(8)) + { + case "_log": + Log("LOG: " + int1.ToString() + ", " + int2.ToString() + ", " + int3.ToString() + "|" + text1 + "|" + text2 + "|" + text3); + break; + case "_err": + Log("ERR: " + int1.ToString() + ", " + int2.ToString() + ", " + int3.ToString() + "|" + text1 + "|" + text2 + "|" + text3); + break; + // Log("Detected: " + name + " with " + int1.ToString() + ", " + int2.ToString() + ", " + int3.ToString() + ", " + text1 + ", " + text2 + ", " + text3); + } + } + } + /*if (MonitorTriggers.Contains(name)) { + Log("TRG: " +name+"|"+ int1.ToString() + ", " + int2.ToString() + ", " + int3.ToString() + "|" + text1 + "|" + text2 + "|" + text3); + }*/ + } + catch (Exception e) + { + ErrorHandler(e); + } + } + async Task RunDebugProcess() + { + using (DebugProcess = new Process()) + { + DebugProcess.StartInfo.FileName = ConsolePath; + DebugProcess.StartInfo.UseShellExecute = false; + DebugProcess.StartInfo.RedirectStandardInput = true; + DebugProcess.StartInfo.WindowStyle = ProcessWindowStyle.Normal; + DebugProcess.StartInfo.CreateNoWindow = false; + DebugProcess.EnableRaisingEvents = true; + DebugProcess.Start(); + DebugStreamWriter = DebugProcess.StandardInput; + DebugStreamWriter.WriteLine("Connected to plugin v"+Version); + DebugStreamWriter.WriteLine("Checking for triggers: " + MonitorTriggers.ToString()); + DebugProcess.WaitForExit(); + DebugStreamWriter.Close(); + DebugStreamWriter.Dispose(); + DebugStreamWriter = null; + DebugProcess.Dispose(); + DebugProcess = null; + Log("Monitoring process terminated"); + } + } + + public void pluginButtonClicked() + { + if (DebugProcess == null) + { + Log("The button was pressed!"); + Task.Run(() => RunDebugProcess()); + + } else + { + Log("The button was pressed again!"); + } + } + } +} \ No newline at end of file diff --git a/Debug-Plugin/Debug-Plugin.csproj b/Debug-Plugin/Debug-Plugin.csproj new file mode 100644 index 0000000..4a6eaf7 --- /dev/null +++ b/Debug-Plugin/Debug-Plugin.csproj @@ -0,0 +1,23 @@ + + + + netstandard2.0 + Debug_Plugin + + + + + + + + + + + C:\Program Files\Unity\Hub\Editor\2020.3.40f1\Editor\Data\Managed\UnityEngine.dll + + + ..\..\..\Twitch\Software\VNyan\VNyan_Data\Managed\VNyanInterface.dll + + + + diff --git a/Test-Plugin/Program.cs b/Test-Plugin/Program.cs new file mode 100644 index 0000000..f484f8d --- /dev/null +++ b/Test-Plugin/Program.cs @@ -0,0 +1,22 @@ +// See https://aka.ms/new-console-template for more information +using System.Diagnostics; + + +StreamWriter DebugStreamWriter = null; +string ConsolePath = "D:\\Twitch\\Software\\VNyan\\Items\\Assemblies\\Debug-Console.exe"; +using (Process DebugProcess = new Process()) +{ + DebugProcess.StartInfo.FileName = ConsolePath; + DebugProcess.StartInfo.UseShellExecute = false; + DebugProcess.StartInfo.RedirectStandardInput = true; + DebugProcess.StartInfo.WindowStyle = ProcessWindowStyle.Normal; + DebugProcess.StartInfo.CreateNoWindow = false; + Console.WriteLine("Starting Process"); + DebugProcess.Start(); + + DebugStreamWriter = DebugProcess.StandardInput; + + string text = "lemon"; + DebugStreamWriter.WriteLine(text); + text = Console.ReadLine(); +} \ No newline at end of file diff --git a/Test-Plugin/Test-Plugin.csproj b/Test-Plugin/Test-Plugin.csproj new file mode 100644 index 0000000..21947b8 --- /dev/null +++ b/Test-Plugin/Test-Plugin.csproj @@ -0,0 +1,11 @@ + + + + Exe + net8.0 + Test_Plugin + enable + enable + + + diff --git a/VNyan-Debug.sln b/VNyan-Debug.sln new file mode 100644 index 0000000..ae0bb8e --- /dev/null +++ b/VNyan-Debug.sln @@ -0,0 +1,48 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.12.35707.178 d17.12 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Debug-Plugin", "Debug-Plugin\Debug-Plugin.csproj", "{10E13F85-9E2E-4333-A996-A917787B0963}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Debug-Console", "Debug-Console\Debug-Console.csproj", "{851A4C34-27C6-4C4B-8A60-FFCBD7A15D80}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test-Plugin", "Test-Plugin\Test-Plugin.csproj", "{34DA4F60-F0C4-4AC5-AE60-C5623BA6E46C}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 + Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {10E13F85-9E2E-4333-A996-A917787B0963}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {10E13F85-9E2E-4333-A996-A917787B0963}.Debug|Any CPU.Build.0 = Debug|Any CPU + {10E13F85-9E2E-4333-A996-A917787B0963}.Debug|x64.ActiveCfg = Debug|Any CPU + {10E13F85-9E2E-4333-A996-A917787B0963}.Debug|x64.Build.0 = Debug|Any CPU + {10E13F85-9E2E-4333-A996-A917787B0963}.Release|Any CPU.ActiveCfg = Release|Any CPU + {10E13F85-9E2E-4333-A996-A917787B0963}.Release|Any CPU.Build.0 = Release|Any CPU + {10E13F85-9E2E-4333-A996-A917787B0963}.Release|x64.ActiveCfg = Release|Any CPU + {10E13F85-9E2E-4333-A996-A917787B0963}.Release|x64.Build.0 = Release|Any CPU + {851A4C34-27C6-4C4B-8A60-FFCBD7A15D80}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {851A4C34-27C6-4C4B-8A60-FFCBD7A15D80}.Debug|Any CPU.Build.0 = Debug|Any CPU + {851A4C34-27C6-4C4B-8A60-FFCBD7A15D80}.Debug|x64.ActiveCfg = Release|x64 + {851A4C34-27C6-4C4B-8A60-FFCBD7A15D80}.Debug|x64.Build.0 = Release|x64 + {851A4C34-27C6-4C4B-8A60-FFCBD7A15D80}.Release|Any CPU.ActiveCfg = Release|Any CPU + {851A4C34-27C6-4C4B-8A60-FFCBD7A15D80}.Release|Any CPU.Build.0 = Release|Any CPU + {851A4C34-27C6-4C4B-8A60-FFCBD7A15D80}.Release|x64.ActiveCfg = Release|x64 + {851A4C34-27C6-4C4B-8A60-FFCBD7A15D80}.Release|x64.Build.0 = Release|x64 + {34DA4F60-F0C4-4AC5-AE60-C5623BA6E46C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {34DA4F60-F0C4-4AC5-AE60-C5623BA6E46C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {34DA4F60-F0C4-4AC5-AE60-C5623BA6E46C}.Debug|x64.ActiveCfg = Debug|Any CPU + {34DA4F60-F0C4-4AC5-AE60-C5623BA6E46C}.Debug|x64.Build.0 = Debug|Any CPU + {34DA4F60-F0C4-4AC5-AE60-C5623BA6E46C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {34DA4F60-F0C4-4AC5-AE60-C5623BA6E46C}.Release|Any CPU.Build.0 = Release|Any CPU + {34DA4F60-F0C4-4AC5-AE60-C5623BA6E46C}.Release|x64.ActiveCfg = Release|Any CPU + {34DA4F60-F0C4-4AC5-AE60-C5623BA6E46C}.Release|x64.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal