From 42f34ec555b3578782744fce825a850b6bd19eb4 Mon Sep 17 00:00:00 2001 From: TauAkiou Date: Thu, 10 Mar 2022 09:57:25 -0500 Subject: [PATCH] Console works again (though the console is very likely to change in the future) --- AUCapture-GTK/AUCapture-GTK.csproj | 4 + .../ConsoleTypes/NlogGTKConsoleTarget.cs | 8 - AUCapture-GTK/ConsoleTypes/NormalConsole.cs | 29 -- AUCapture-GTK/GtkSettings.cs | 35 ++ AUCapture-GTK/IPC/DBus/IPCAdapterDBus.cs | 14 +- .../{PangoText => Logging}/ColoredString.cs | 0 .../ConsoleInterface.cs | 0 .../{ConsoleTypes => Logging}/FormConsole.cs | 12 +- AUCapture-GTK/Logging/NlogGTKConsoleTarget.cs | 120 +++++++ .../TextColor.cs => Logging/PangoColor.cs} | 2 +- AUCapture-GTK/MainGTKWindow.cs | 305 ++++-------------- AUCapture-GTK/Program.cs | 11 +- AUCapture-GTK/Settings.cs | 64 ---- 13 files changed, 251 insertions(+), 353 deletions(-) delete mode 100644 AUCapture-GTK/ConsoleTypes/NlogGTKConsoleTarget.cs delete mode 100644 AUCapture-GTK/ConsoleTypes/NormalConsole.cs create mode 100644 AUCapture-GTK/GtkSettings.cs rename AUCapture-GTK/{PangoText => Logging}/ColoredString.cs (100%) rename AUCapture-GTK/{ConsoleTypes => Logging}/ConsoleInterface.cs (100%) rename AUCapture-GTK/{ConsoleTypes => Logging}/FormConsole.cs (88%) create mode 100644 AUCapture-GTK/Logging/NlogGTKConsoleTarget.cs rename AUCapture-GTK/{PangoText/TextColor.cs => Logging/PangoColor.cs} (99%) delete mode 100644 AUCapture-GTK/Settings.cs diff --git a/AUCapture-GTK/AUCapture-GTK.csproj b/AUCapture-GTK/AUCapture-GTK.csproj index 51806643..48bd7d32 100644 --- a/AUCapture-GTK/AUCapture-GTK.csproj +++ b/AUCapture-GTK/AUCapture-GTK.csproj @@ -49,4 +49,8 @@ + + + + diff --git a/AUCapture-GTK/ConsoleTypes/NlogGTKConsoleTarget.cs b/AUCapture-GTK/ConsoleTypes/NlogGTKConsoleTarget.cs deleted file mode 100644 index 580c23ec..00000000 --- a/AUCapture-GTK/ConsoleTypes/NlogGTKConsoleTarget.cs +++ /dev/null @@ -1,8 +0,0 @@ -using NLog.Targets; - -namespace AUCapture_GTK.ConsoleTypes; - -public class NlogGTKConsoleTarget : Target -{ - -} \ No newline at end of file diff --git a/AUCapture-GTK/ConsoleTypes/NormalConsole.cs b/AUCapture-GTK/ConsoleTypes/NormalConsole.cs deleted file mode 100644 index 1d8d03d6..00000000 --- a/AUCapture-GTK/ConsoleTypes/NormalConsole.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System; -using System.Drawing; -using AmongUsCapture.TextColorLibrary; - -namespace AmongUsCapture_GTK.ConsoleTypes -{ - public class NormalConsole : ConsoleInterface - { - public void WriteColoredText(string ColoredText) - { - Console.WriteLine(TextColor.StripColor(ColoredText)); - } - - public void WriteLine(string str) - { - Console.WriteLine(str); - } - - public void WriteModuleTextColored(string ModuleName, Color moduleColor, string text) - { - Console.WriteLine($"[{ModuleName}]: {text}"); - } - - public void WriteTextFormatted(string text, bool acceptNewLines = true) - { - Console.WriteLine(text); - } - } -} diff --git a/AUCapture-GTK/GtkSettings.cs b/AUCapture-GTK/GtkSettings.cs new file mode 100644 index 00000000..43bbf2d4 --- /dev/null +++ b/AUCapture-GTK/GtkSettings.cs @@ -0,0 +1,35 @@ +using System; +using System.IO; +using Config.Net; +using Gtk; + +namespace AmongUsCapture_GTK +{ + public static class GtkSettings + { + public static string StorageLocation = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "AmongUsCapture"); + + public static ConsoleInterface conInterface; + + public static void WriteLineToConsole(string time, string module, string severity, string message) + { + if (conInterface != null) + { + + } + } + + //Global persistent settings that are saved to a json file. Limited Types + public static IGtkPersistentSettings PersistentSettings = new ConfigurationBuilder().UseJsonFile(Path.Join(StorageLocation, "GtkSettings.json")).Build(); + } + + + public interface IGtkPersistentSettings + { + //Types allowed: bool, double, int, long, string, TimeSpan, DateTime, Uri, Guid + //DateTime is always converted to UTC + bool skipHandlerInstall { get; set; } + + } + +} \ No newline at end of file diff --git a/AUCapture-GTK/IPC/DBus/IPCAdapterDBus.cs b/AUCapture-GTK/IPC/DBus/IPCAdapterDBus.cs index 18dbf8b1..41ccf21e 100644 --- a/AUCapture-GTK/IPC/DBus/IPCAdapterDBus.cs +++ b/AUCapture-GTK/IPC/DBus/IPCAdapterDBus.cs @@ -39,14 +39,14 @@ public override URIStartResult HandleURIStart(string[] args) var wasURIStart = args.Length > 0 && args[0].StartsWith(UriScheme + "://"); var result = URIStartResult.CONTINUE; - if (!File.Exists(Path.Join(Settings.StorageLocation, ".amonguscapture.pid"))) + if (!File.Exists(Path.Join(AmongUsCapture.Settings.StorageLocation, ".amonguscapture.pid"))) { _isHostInstance = true; } else { // Open our PID file. - using (var pidfile = File.OpenText(Path.Join(Settings.StorageLocation, ".amonguscapture.pid"))) + using (var pidfile = File.OpenText(Path.Join(AmongUsCapture.Settings.StorageLocation, ".amonguscapture.pid"))) { var pid = pidfile.ReadLine(); if (pid != null) @@ -76,7 +76,7 @@ public override URIStartResult HandleURIStart(string[] args) { // Process doesn't exist. Clear the file. Console.WriteLine($"Found stale PID file containing {pid}."); - File.Delete(Path.Join(Settings.StorageLocation, ".amonguscapture.pid")); + File.Delete(Path.Join(AmongUsCapture.Settings.StorageLocation, ".amonguscapture.pid")); _isHostInstance = true; } } @@ -86,7 +86,7 @@ public override URIStartResult HandleURIStart(string[] args) if (_isHostInstance) { - using (var pidwriter = File.CreateText(Path.Join(Settings.StorageLocation, ".amonguscapture.pid"))) + using (var pidwriter = File.CreateText(Path.Join(AmongUsCapture.Settings.StorageLocation, ".amonguscapture.pid"))) { pidwriter.Write(myProcessId); } @@ -281,13 +281,13 @@ public override async Task Cancel() private Task CleanPid() { // Make sure the pidfile is cleaned up if we have one. - var pidfile = Path.Join(Settings.StorageLocation, ".amonguscapture.pid"); + var pidfile = Path.Join(AmongUsCapture.Settings.StorageLocation, ".amonguscapture.pid"); if (File.Exists(pidfile)) { int pid; bool fileread; - using (var pidread = File.OpenText(Path.Join(Settings.StorageLocation, ".amonguscapture.pid"))) + using (var pidread = File.OpenText(Path.Join(AmongUsCapture.Settings.StorageLocation, ".amonguscapture.pid"))) { fileread = Int32.TryParse(pidread.ReadLine(), out pid); } @@ -310,7 +310,7 @@ private Task CleanPid() private void RespondToDbus(string signalresponse) { - Settings.conInterface.WriteModuleTextColored("DBus", Color.Silver, + GtkSettings.conInterface.WriteModuleTextColored("DBus", Color.Silver, $"Received DBus Method Call: \"{signalresponse}\""); var token = StartToken.FromString(signalresponse); diff --git a/AUCapture-GTK/PangoText/ColoredString.cs b/AUCapture-GTK/Logging/ColoredString.cs similarity index 100% rename from AUCapture-GTK/PangoText/ColoredString.cs rename to AUCapture-GTK/Logging/ColoredString.cs diff --git a/AUCapture-GTK/ConsoleTypes/ConsoleInterface.cs b/AUCapture-GTK/Logging/ConsoleInterface.cs similarity index 100% rename from AUCapture-GTK/ConsoleTypes/ConsoleInterface.cs rename to AUCapture-GTK/Logging/ConsoleInterface.cs diff --git a/AUCapture-GTK/ConsoleTypes/FormConsole.cs b/AUCapture-GTK/Logging/FormConsole.cs similarity index 88% rename from AUCapture-GTK/ConsoleTypes/FormConsole.cs rename to AUCapture-GTK/Logging/FormConsole.cs index d402a81e..391e4beb 100644 --- a/AUCapture-GTK/ConsoleTypes/FormConsole.cs +++ b/AUCapture-GTK/Logging/FormConsole.cs @@ -14,7 +14,12 @@ public class FormConsole : ConsoleInterface public MainGTKWindow form; private static object locker = new Object(); - public FormConsole(MainGTKWindow mainWindow) + private Dictionary ModuleColor = new Dictionary() + { + { "GameMemReader", Color.Purple } + }; + + public FormConsole(MainGTKWindow mainWindow) { form = mainWindow; string directoryuri = null; @@ -51,8 +56,7 @@ public void WriteModuleTextColored(string ModuleName, Color moduleColor, string form.WriteConsoleLineFormatted(ModuleName, moduleColor, text); WriteToLog($"[{ModuleName}]: {text}"); } - - + public void WriteToLog(string textToLog) { WriteLogLine(DateTime.UtcNow, textToLog); @@ -60,7 +64,7 @@ public void WriteToLog(string textToLog) private string StripColor(string text) { - return TextColor.StripColor(text); + return PangoColor.StripColor(text); } private void WriteLogLine(DateTime time, string textToLog) diff --git a/AUCapture-GTK/Logging/NlogGTKConsoleTarget.cs b/AUCapture-GTK/Logging/NlogGTKConsoleTarget.cs new file mode 100644 index 00000000..0d48c7d1 --- /dev/null +++ b/AUCapture-GTK/Logging/NlogGTKConsoleTarget.cs @@ -0,0 +1,120 @@ +using System.Drawing; +using AmongUsCapture; +using AmongUsCapture_GTK; +using Castle.Components.DictionaryAdapter; +using Discord.Commands; +using GLib; +using Gtk; +using NLog; +using Target = NLog.Targets.Target; +using NLog.Targets; +using NLog.Config; + +namespace AUCapture_GTK.ConsoleTypes; + +[Target("AUGTKConsole")] +public sealed class NlogGTKConsoleTarget : TargetWithContext +{ + [RequiredParameter] + public MainGTKWindow MainWindow { get; set; } + + protected override void Write(LogEventInfo logEvent) + { + string logMessage = this.RenderLogEvent(this.Layout, logEvent); + + IDictionary logProperties = this.GetAllProperties(logEvent); + + writeMessageToGTKWindow(logMessage, logProperties); + } + + private void writeMessageToGTKWindow(string message, IDictionary logProperties) + { + MainWindow.AppendNewLineToConsole(message); + } + + + private Color GetColorForLogLevel(LogLevel level) + { + // COME ON, NLOG. YOU COULDN'T HAVE PROVIDED A LIST OF THESE OR SOMETHING? + switch (level.Ordinal) + { + case 0: // + return Color.Black; + case 1: + return Color.Blue; + case 2: + return Color.Gray; + case 3: + return Color.YellowGreen; + case 4: + return Color.Red; + case 5: + return Color.Red; + default: + return Color.White; + } + } + + private Color PlayerColorToColorOBJ(PlayerColor pColor) { + var OutputCode = Color.White; + switch (pColor) { + case PlayerColor.Red: + OutputCode = Color.Red; + break; + case PlayerColor.Blue: + OutputCode = Color.RoyalBlue; + break; + case PlayerColor.Green: + OutputCode = Color.Green; + break; + case PlayerColor.Pink: + OutputCode = Color.Magenta; + break; + case PlayerColor.Orange: + OutputCode = Color.Orange; + break; + case PlayerColor.Yellow: + OutputCode = Color.Yellow; + break; + case PlayerColor.Black: + OutputCode = Color.Gray; + break; + case PlayerColor.White: + OutputCode = Color.White; + break; + case PlayerColor.Purple: + OutputCode = Color.MediumPurple; + break; + case PlayerColor.Brown: + OutputCode = Color.SaddleBrown; + break; + case PlayerColor.Cyan: + OutputCode = Color.Cyan; + break; + case PlayerColor.Lime: + OutputCode = Color.Lime; + break; + case PlayerColor.Maroon: + OutputCode = Color.Maroon; + break; + case PlayerColor.Rose: + OutputCode = Color.MistyRose; + break; + case PlayerColor.Banana: + OutputCode = Color.LightGoldenrodYellow; + break; + case PlayerColor.Gray: + OutputCode = Color.Gray; + break; + case PlayerColor.Tan: + OutputCode = Color.Tan; + break; + case PlayerColor.Sunset: + OutputCode = Color.LightSalmon; + break; + } + + return OutputCode; + } + +} \ No newline at end of file diff --git a/AUCapture-GTK/PangoText/TextColor.cs b/AUCapture-GTK/Logging/PangoColor.cs similarity index 99% rename from AUCapture-GTK/PangoText/TextColor.cs rename to AUCapture-GTK/Logging/PangoColor.cs index 76095704..7d39a8f1 100644 --- a/AUCapture-GTK/PangoText/TextColor.cs +++ b/AUCapture-GTK/Logging/PangoColor.cs @@ -6,7 +6,7 @@ namespace AmongUsCapture.TextColorLibrary { - public static class TextColor + public static class PangoColor { private static char colorIndicator = '§'; //Represent color codes as §FFFFFF (6 Letters, Hex decode) diff --git a/AUCapture-GTK/MainGTKWindow.cs b/AUCapture-GTK/MainGTKWindow.cs index fb38e2c7..af8a5c1a 100644 --- a/AUCapture-GTK/MainGTKWindow.cs +++ b/AUCapture-GTK/MainGTKWindow.cs @@ -18,12 +18,13 @@ using AmongUsCapture_GTK.IPC; using AUCapture_GTK.IPC; using AmongUsCapture; -using Castle.Core.Internal; +using AUCapture_GTK.ConsoleTypes; using NLog; using NLog.Config; using NLog.Targets; using Process = System.Diagnostics.Process; using Target = Gtk.Target; +using Microsoft.Win32; // We need registry shit from this. namespace AmongUsCapture_GTK { @@ -58,14 +59,13 @@ private void SetupLogger() Header = $"Capture version: {v.FileMajorPart}.{v.FileMinorPart}.{v.FileBuildPart}.{v.FilePrivatePart}\n", Footer = $"\nCapture version: {v.FileMajorPart}.{v.FileMinorPart}.{v.FileBuildPart}.{v.FilePrivatePart}" }; - var logconsole = new MethodCallTarget("logconsole") + var logconsole = new NlogGTKConsoleTarget() { - ClassName = typeof(MainGTKWindow).AssemblyQualifiedName, - MethodName = "WriteLineToConsole" - }; - logconsole.Parameters.Add(new MethodCallParameter("${level}")); - logconsole.Parameters.Add(new MethodCallParameter("${message}")); + MainWindow = this, + + Layout = "${date:format=yyyy-MM-dd HH\\:mm\\:ss} - ${logger:shortName=true} | [${level:uppercase=true}]: ${message}", + }; LoggingConfig.AddRule(LogLevel.Debug, LogLevel.Fatal, logfile); LoggingConfig.AddRule(LogLevel.Debug, LogLevel.Fatal, logconsole); @@ -74,29 +74,6 @@ private void SetupLogger() NLog.LogManager.Configuration = LoggingConfig; } - private Color Rainbow(float progress) - { - var div = Math.Abs(progress % 1) * 6; - var ascending = (int) (div % 1 * 255); - var descending = 255 - ascending; - - switch ((int) div) - { - case 0: - return Color.FromArgb(255, 255, ascending, 0); - case 1: - return Color.FromArgb(255, descending, 255, 0); - case 2: - return Color.FromArgb(255, 0, 255, ascending); - case 3: - return Color.FromArgb(255, 0, descending, 255); - case 4: - return Color.FromArgb(255, ascending, 0, 255); - default: // case 5: - return Color.FromArgb(255, 255, 0, descending); - } - } - public MainGTKWindow(ClientSocket sock) : base("Among Us Capture - GTK") { //builder.Autoconnect(this); @@ -111,7 +88,7 @@ public MainGTKWindow(ClientSocket sock) : base("Among Us Capture - GTK") GameMemReader.getInstance().ChatMessageAdded += _eventChatMessageAdded; // Load URL - _urlHostEntryField.Text = Settings.PersistentSettings.host; + _urlHostEntryField.Text = AmongUsCapture.Settings.PersistentSettings.host; // Connect on Enter //this.AcceptButton = ConnectButton; @@ -124,7 +101,7 @@ public MainGTKWindow(ClientSocket sock) : base("Among Us Capture - GTK") "applications"); var xdg_file = System.IO.Path.Join(xdg_path, "aucapture-opener.desktop"); - var skippingHandler = Settings.PersistentSettings.skipHandlerInstall; + var skippingHandler = GtkSettings.PersistentSettings.skipHandlerInstall; if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { @@ -191,7 +168,7 @@ private void _eventGameIsUnverified(object o, ValidatorEventArgs e) }); - Settings.conInterface.WriteModuleTextColored("Notification", Color.Red, + GtkSettings.conInterface.WriteModuleTextColored("Notification", Color.Red, $"We have detected an unverified version of Among Us. Things may not work properly."); } @@ -212,18 +189,22 @@ private void _primaryWindowInstallLinkWindow_Dialog(object o, EventArgs e) { false, String.Empty); - if(!File.Exists(xdg_file) && !Settings.PersistentSettings.skipHandlerInstall) + if(!File.Exists(xdg_file) && !GtkSettings.PersistentSettings.skipHandlerInstall) { info += - "Would you like to enable support for AutoMuteUs one-click connection?" + - "This will allow you to use the links provided by AutoMuteUs to connect the capture to the bot automatically.\n\n" + + "Would you like to enable capture bot URI support?" + + "This will allow you to use the links provided by the AutoMuteUs bot to connect the capture automatically.\n\n" + "The following operations will be performed:\n\n" + + #if _WINDOWS + $"- 'aucapture:' links will be handled by this application, located at: {System.Reflection.Assembly.GetExecutingAssembly().CodeBase}" + + #else $"- The following .desktop file will be installed: {xdg_file}\n\n" + "- The following command will be run to link the 'aucapture:' URI to the program:\n\n \'xdg-mime default aucapture-opener.desktop x-scheme-handler/aucapture\'" + + #endif "\n\nIf you decline, Discord connection links will not be functional." + "\n\nYou can install or manage One-Click support by using the \"One-Click Connection Management\" link in the File menu."; - InstallLinkDialogBox.Text = info; + InstallLinkDialogBox.Text = info; InstallLinkDialogBox.Title = "Enable One-Click Connection?"; InstallLinkDialogBox.AddButton("Cancel", ResponseType.Reject); InstallLinkDialogBox.AddButton("Install", ResponseType.Accept); @@ -233,7 +214,7 @@ private void _primaryWindowInstallLinkWindow_Dialog(object o, EventArgs e) { if (responseArgs.ResponseId == ResponseType.Reject) { // Make sure we have the setting to ignore the dialog box set. - Settings.PersistentSettings.skipHandlerInstall = true; + GtkSettings.PersistentSettings.skipHandlerInstall = true; } if (responseArgs.ResponseId == ResponseType.Accept) @@ -244,18 +225,25 @@ private void _primaryWindowInstallLinkWindow_Dialog(object o, EventArgs e) { } else { - info += "This menu manages the One-Click Connection link system.\n\n"; + info += "This menu manages the aucapture link handler.\n\n"; - info += "One-Click Connection Status: "; - if (File.Exists(xdg_file)) info += "Enabled\n\n"; - else info += "Disabled\n\n"; - - info += $"Runner (.desktop) Installation Path: "; - if (File.Exists(xdg_file)) info += xdg_file; - else info += "Not Found"; - InstallLinkDialogBox.Text += info; - InstallLinkDialogBox.Title = "Manage One-Click Connection"; + #if _WINDOWS + info += "Capture Handler Status: "; + // Complete Windows handling here. + + #else + info += "Capture Handler Status: "; + if (File.Exists(xdg_file)) info += "Enabled\n\n"; + else info += "Disabled\n\n"; + + info += $"Runner (.desktop) Installation Path: "; + if (File.Exists(xdg_file)) info += xdg_file; + else info += "Not Found"; + #endif + + InstallLinkDialogBox.Text += info; + InstallLinkDialogBox.Title = "Manage AUCapture URI Handler"; InstallLinkDialogBox.AddButton("Cancel", ResponseType.Close); InstallLinkDialogBox.AddButton("Uninstall", ResponseType.Reject); InstallLinkDialogBox.AddButton("Reinstall", ResponseType.Accept); @@ -391,19 +379,10 @@ private void OnLoad(object sender, EventArgs e) { //TestFillConsole(1000); } - - private string getRainbowText(string nonRainbow, int shift = 0) - { - var OutputString = ""; - for (var i = 0; i < nonRainbow.Length; i++) - OutputString += Rainbow((float) ((i + shift) % nonRainbow.Length) / nonRainbow.Length).ToTextColor() + - nonRainbow[i]; - return OutputString; - } - + private void _eventChatMessageAdded(object sender, ChatMessageEventArgs e) { - Settings.conInterface.WriteModuleTextColored("CHAT", Color.DarkKhaki, + GtkSettings.conInterface.WriteModuleTextColored("CHAT", Color.DarkKhaki, $"{PlayerColorToColorOBJ(e.Color).ToTextColorPango(e.Sender)}{e.Message}"); } @@ -413,7 +392,7 @@ private void UserForm_PlayerChanged(object sender, PlayerChangedEventArgs e) deadMessageQueue.Enqueue( $"{PlayerColorToColorOBJ(e.Color).ToTextColorPango(e.Name)}: {e.Action}"); else - Settings.conInterface.WriteModuleTextColored("PlayerChange", Color.DarkKhaki, + GtkSettings.conInterface.WriteModuleTextColored("PlayerChange", Color.DarkKhaki, $"{PlayerColorToColorOBJ(e.Color).ToTextColorPango(e.Name)}: {e.Action}"); //Program.conInterface.WriteModuleTextColored("GameMemReader", Color.Green, e.Name + ": " + e.Action); } @@ -423,7 +402,7 @@ private void _eventGameStateChanged(object sender, GameStateChangedEventArgs e) while (deadMessageQueue.Count > 0) //Lets print out the state changes now that gamestate has changed. { var text = deadMessageQueue.Dequeue(); - Settings.conInterface.WriteModuleTextColored("PlayerChange", Color.DarkKhaki, text); + GtkSettings.conInterface.WriteModuleTextColored("PlayerChange", Color.DarkKhaki, text); } Idle.Add(delegate @@ -431,10 +410,10 @@ private void _eventGameStateChanged(object sender, GameStateChangedEventArgs e) _currentStateLabel.Text = e.NewState.ToString(); return false; }); - Settings.conInterface.WriteModuleTextColored("GameMemReader", Color.Lime, $"State changed to {Color.Cyan.ToTextColorPango(e.NewState.ToString())}"); + GtkSettings.conInterface.WriteModuleTextColored("GameMemReader", Color.Lime, $"State changed to {Color.Cyan.ToTextColorPango(e.NewState.ToString())}"); //Program.conInterface.WriteModuleTextColored("GameMemReader", Color.Green, "State changed to " + e.NewState); } - + private void _connectCodeSubmitButton_Click(object sender, EventArgs e) { @@ -501,19 +480,6 @@ private void _consoleTextView_BufferChanged(object sender, EventArgs e) } - private void TestFillConsole(int entries) //Helper test method to see if filling console works. - { - for (var i = 0; i < entries; i++) - { - var nonString = "Wow! Look at this pretty text!"; - Settings.conInterface.WriteModuleTextColored("Rainbow", Rainbow((float) i / entries), - getRainbowText(nonString, i)); - } - - ; - //this.WriteColoredText(getRainbowText("This is a Pre-Release from Carbon's branch.")); - } - public void WriteConsoleLineFormatted(string moduleName, Color moduleColor, string message) { //Outputs a message like this: [{ModuleName}]: {Message} @@ -525,7 +491,7 @@ public void WriteColoredText(string ColoredText) { lock (locker) { - foreach (var part in TextColor.toParts(ColoredText)) + foreach (var part in PangoColor.toParts(ColoredText)) AppendColoredTextToConsole(part.text, part.textColor); AppendColoredTextToConsole("", Color.White, true); } @@ -547,8 +513,8 @@ public void AppendColoredTextToConsole(string line, Color color, bool addNewLine }); } } - - public void WriteLineToConsole(string level, string line) + + public void AppendNewLineToConsole(string line) { if (!(_consoleTextView is null)) { @@ -556,13 +522,13 @@ public void WriteLineToConsole(string level, string line) { Idle.Add(delegate { + // Let the actual nlog interface handle adding text to the console. var iter = _consoleTextView.Buffer.EndIter; - _consoleTextView.Buffer.Insert(ref iter,$" [{level}] {line} \n"); + _consoleTextView.Buffer.Insert(ref iter,$"{line}\n"); _consoleTextView.Buffer.PlaceCursor(iter); return false; }); } - //autoscroll(); } } @@ -613,159 +579,6 @@ private Color PlayerColorToColorOBJ(PlayerColor pColor) return OutputCode; } - private string PlayerColorToColorCode(PlayerColor pColor) - { - //Red = 0, - //Blue = 1, - //Green = 2, - //Pink = 3, - //Orange = 4, - //Yellow = 5, - //Black = 6, - //White = 7, - //Purple = 8, - //Brown = 9, - //Cyan = 10, - //Lime = 11 - var OutputCode = ""; - switch (pColor) - { - case PlayerColor.Red: - OutputCode = "§c"; - break; - case PlayerColor.Blue: - OutputCode = "§1"; - break; - case PlayerColor.Green: - OutputCode = "§2"; - break; - case PlayerColor.Pink: - OutputCode = "§d"; - break; - case PlayerColor.Orange: - OutputCode = "§o"; - break; - case PlayerColor.Yellow: - OutputCode = "§e"; - break; - case PlayerColor.Black: - OutputCode = "§0"; - break; - case PlayerColor.White: - OutputCode = "§f"; - break; - case PlayerColor.Purple: - OutputCode = "§5"; - break; - case PlayerColor.Brown: - OutputCode = "§n"; - break; - case PlayerColor.Cyan: - OutputCode = "§b"; - break; - case PlayerColor.Lime: - OutputCode = "§a"; - break; - } - - return OutputCode; - } - - public void WriteLineFormatted(string str, bool acceptnewlines = true) - { - if (!(_consoleTextView is null)) - { - Idle.Add(delegate - { - lock (locker) - { - if (!string.IsNullOrEmpty(str)) - { - if (!acceptnewlines) str = str.Replace('\n', ' '); - var parts = str.Split(new[] {'§'}); - if (parts[0].Length > 0) AppendColoredTextToConsole(parts[0], Color.White); - for (var i = 1; i < parts.Length; i++) - { - var charColor = Color.White; - if (parts[i].Length > 0) - { - switch (parts[i][0]) - { - case '0': - charColor = Color.Gray; - break; //Should be Black but Black is non-readable on a black background - case '1': - charColor = Color.RoyalBlue; - break; - case '2': - charColor = Color.Green; - break; - case '3': - charColor = Color.DarkCyan; - break; - case '4': - charColor = Color.DarkRed; - break; - case '5': - charColor = Color.MediumPurple; - break; - case '6': - charColor = Color.DarkKhaki; - break; - case '7': - charColor = Color.Gray; - break; - case '8': - charColor = Color.DarkGray; - break; - case '9': - charColor = Color.LightBlue; - break; - case 'a': - charColor = Color.Lime; - break; - case 'b': - charColor = Color.Cyan; - break; - case 'c': - charColor = Color.Red; - break; - case 'd': - charColor = Color.Magenta; - break; - case 'e': - charColor = Color.Yellow; - break; - case 'f': - charColor = Color.White; - break; - case 'o': - charColor = Color.Orange; - break; - case 'n': - charColor = Color.SaddleBrown; - break; - case 'r': - charColor = Color.Gray; - break; - } - - if (parts[i].Length > 1) - AppendColoredTextToConsole(parts[i].Substring(1, parts[i].Length - 1), - charColor); - } - } - } - - AppendColoredTextToConsole("", Color.White, true); - return false; - } - - //autoscroll(); - }); - } - } - public void ShowCrackedBox() { /* var result = @@ -791,6 +604,30 @@ private Color GetRgbColorFromFloat(RGBA gtkcolor) (byte)(gtkcolor.Blue * 255)); } + + private Color Rainbow(float progress) + { + var div = Math.Abs(progress % 1) * 6; + var ascending = (int) (div % 1 * 255); + var descending = 255 - ascending; + + switch ((int) div) + { + case 0: + return Color.FromArgb(255, 255, ascending, 0); + case 1: + return Color.FromArgb(255, descending, 255, 0); + case 2: + return Color.FromArgb(255, 0, 255, ascending); + case 3: + return Color.FromArgb(255, 0, descending, 255); + case 4: + return Color.FromArgb(255, ascending, 0, 255); + default: // case 5: + return Color.FromArgb(255, 255, 0, descending); + } + } + } } \ No newline at end of file diff --git a/AUCapture-GTK/Program.cs b/AUCapture-GTK/Program.cs index 0f3f6742..a373f004 100644 --- a/AUCapture-GTK/Program.cs +++ b/AUCapture-GTK/Program.cs @@ -36,13 +36,13 @@ internal static class Program [STAThread] private static void Main(string[] args) { - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && Settings.PersistentSettings.debugConsole) + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && AmongUsCapture.Settings.PersistentSettings.debugConsole) AllocConsole(); // needs to be the first call in the program to prevent weird bugs - if (!Directory.Exists(Settings.StorageLocation)) + if (!Directory.Exists(AmongUsCapture.Settings.StorageLocation)) { // Create Settings directory if it doesn't exist, as we need to stick our pidfile there. - Directory.CreateDirectory(Settings.StorageLocation); + Directory.CreateDirectory(AmongUsCapture.Settings.StorageLocation); } URIStartResult uriRes = URIStartResult.CLOSE; @@ -67,7 +67,7 @@ private static void Main(string[] args) var thread = new Thread(OpenGUI); if(RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) thread.SetApartmentState(ApartmentState.STA); thread.Start(); - while (Settings.conInterface is null) Thread.Sleep(250); + while (GtkSettings.conInterface is null) Thread.Sleep(250); Task.Factory.StartNew(() => socket.Init()) .Wait(); // run socket in background. Important to wait for init to have actually finished before continuing Task.Factory.StartNew(() => IPCAdapter.getInstance().RegisterMinion()).Wait(); @@ -94,8 +94,7 @@ private static void OpenGUI() Application.Init(); window = new MainGTKWindow(socket); appstate.AddWindow(window); - Settings.form = window; - Settings.conInterface = new FormConsole(window); + GtkSettings.conInterface = new FormConsole(window); window.DeleteEvent += (object o, DeleteEventArgs e) => { diff --git a/AUCapture-GTK/Settings.cs b/AUCapture-GTK/Settings.cs deleted file mode 100644 index eb0069ae..00000000 --- a/AUCapture-GTK/Settings.cs +++ /dev/null @@ -1,64 +0,0 @@ -using System; -using System.IO; -using Config.Net; -using Gtk; - -namespace AmongUsCapture_GTK -{ - public static class Settings - { - public static string StorageLocation = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "AmongUsCapture"); - - public static ConsoleInterface conInterface; - - public static Application app; - - public static MainGTKWindow form; - - //Global persistent settings that are saved to a json file. Limited Types - public static IPersistentSettings PersistentSettings = new ConfigurationBuilder().UseJsonFile(Path.Join(StorageLocation, "Settings.json")).Build(); - public static IGameOffsets GameOffsets = new ConfigurationBuilder().UseJsonFile(Path.Join(StorageLocation, "GameOffsets.json")).Build(); - } - - - public interface IPersistentSettings - { - //Types allowed: bool, double, int, long, string, TimeSpan, DateTime, Uri, Guid - //DateTime is always converted to UTC - [Option(Alias = "Host", DefaultValue = "http://localhost:8123")] - string host { get; set; } - - [Option(Alias = "DebugConsole", DefaultValue = false)] - bool debugConsole { get; set; } - - [Option(Alias = "SkipHandlerInstall", DefaultValue = false)] - bool skipHandlerInstall { get; set; } - } - - public interface IGameOffsets - { - //Types allowed: bool, double, int, long, string, TimeSpan, DateTime, Uri, Guid - //DateTime is always converted to UTC - - [Option(Alias = "GameHash", DefaultValue = "5ab7b3419ed29af0728e66ae8f1a207aedd6456280128060fedf74621b287be6")] - string GameHash { get; set; } - - [Option(Alias = "Offsets.Client", DefaultValue = 0x193C154)] - int AmongUsClientOffset { get; set; } - - [Option(Alias = "Offsets.GameData", DefaultValue = 0x193C054)] - int GameDataOffset { get; set; } - - [Option(Alias = "Offsets.MeetingHud", DefaultValue = 0x193BA9C)] - int MeetingHudOffset { get; set; } - - [Option(Alias = "Offsets.GameStartManager", DefaultValue = 0x1858970)] - int GameStartManagerOffset { get; set; } - - [Option(Alias = "Offsets.HudManager", DefaultValue = 0x1849100)] - int HudManagerOffset { get; set; } - - [Option(Alias = "Offsets.ServerManager", DefaultValue = 0x184C230)] - int ServerManagerOffset { get; set; } - } -} \ No newline at end of file