From d11391925030ac5e86792fd619ca30db24824085 Mon Sep 17 00:00:00 2001 From: D1GQ Date: Thu, 2 Apr 2026 20:41:23 -0500 Subject: [PATCH] Add support to dump command on android --- src/BAUPlugin.cs | 6 +-- src/Commands/DumpCommand.cs | 91 +++++++++++++++++++++++------------ src/Data/BetterDataManager.cs | 32 +++++++----- src/Helpers/Logger.cs | 4 +- 4 files changed, 87 insertions(+), 46 deletions(-) diff --git a/src/BAUPlugin.cs b/src/BAUPlugin.cs index 006db2e..2ac3ee3 100644 --- a/src/BAUPlugin.cs +++ b/src/BAUPlugin.cs @@ -160,10 +160,10 @@ internal class BAUPlugin : BasePlugin InstanceAttribute.RegisterAll(); OutfitData.Initialize(); - if (File.Exists(Path.Combine(BetterDataManager.Folders.fileFolderPath, "better-log.txt"))) - File.WriteAllText(Path.Combine(BetterDataManager.Folders.fileFolderPath, "better-previous-log.txt"), File.ReadAllText(Path.Combine(BetterDataManager.Folders.fileFolderPath, "better-log.txt"))); + if (File.Exists(BetterDataManager.Files.logFilePath)) + File.WriteAllText(BetterDataManager.Files.previousLogFilePath, File.ReadAllText(BetterDataManager.Files.logFilePath)); - File.WriteAllText(Path.Combine(BetterDataManager.Folders.fileFolderPath, "better-log.txt"), ""); + File.WriteAllText(BetterDataManager.Files.logFilePath, ""); Logger_.Log("Better Among Us successfully loaded!"); string SupportedVersions = string.Join(" ", ModInfo.SupportedAmongUsVersions); diff --git a/src/Commands/DumpCommand.cs b/src/Commands/DumpCommand.cs index 47daaa4..5fe0d3c 100644 --- a/src/Commands/DumpCommand.cs +++ b/src/Commands/DumpCommand.cs @@ -9,8 +9,6 @@ internal sealed class DumpCommand : BaseCommand { internal override string Name => "dump"; internal override string Description => "Dump the entire log to the user's desktop"; - internal override bool ShowCommand() => - !ModInfo.Starlight; internal override bool CanRunCommand(out string reason) { @@ -23,10 +21,8 @@ internal sealed class DumpCommand : BaseCommand return base.CanRunCommand(out reason); } - internal override void Run() + private static string DecryptLog(string log) { - string logFilePath = Path.Combine(BetterDataManager.Folders.fileFolderPath, "better-log.txt"); - string log = File.ReadAllText(logFilePath); string newLog = string.Empty; string[] logArray = log.Split([Environment.NewLine], StringSplitOptions.None); foreach (string text in logArray) @@ -40,29 +36,64 @@ internal sealed class DumpCommand : BaseCommand newLog += text + "\n"; } } - - string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); - string logFolderPath = Path.Combine(desktopPath, "BetterLogs"); - if (!Directory.Exists(logFolderPath)) - { - Directory.CreateDirectory(logFolderPath); - } - string logFileName = "log-" + BAUPlugin.GetVersionText().Replace(' ', '-').ToLower() + "-" + DateTime.Now.ToString("yyyy.MM.dd-HH.mm.ss") + ".log"; - string newLogFilePath = Path.Combine(logFolderPath, logFileName); - File.WriteAllText(newLogFilePath, newLog); - System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo() - { - FileName = logFolderPath, - UseShellExecute = true, - Verb = "open" - }); - System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo() - { - FileName = newLogFilePath, - UseShellExecute = true, - Verb = "open" - }); - - CommandResultText($"Dump logs at '{newLogFilePath}'"); + return newLog; } -} + + internal override void Run() + { + string logFilePath = BetterDataManager.Files.logFilePath; + if (!File.Exists(logFilePath)) + { + CommandErrorText("Log file not found!"); + return; + } + + if (!ModInfo.Starlight) + { + string log = File.ReadAllText(logFilePath); + string newLog = DecryptLog(log); + + string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); + string logFolderPath = Path.Combine(desktopPath, "BetterLogDumps"); + if (!Directory.Exists(logFolderPath)) + { + Directory.CreateDirectory(logFolderPath); + } + string logFileName = "log-" + BAUPlugin.GetVersionText().Replace(' ', '-').ToLower() + "-" + DateTime.Now.ToString("yyyy.MM.dd-HH.mm.ss") + ".log"; + string newLogFilePath = Path.Combine(logFolderPath, logFileName); + File.WriteAllText(newLogFilePath, newLog); + System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo() + { + FileName = logFolderPath, + UseShellExecute = true, + Verb = "open" + }); + System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo() + { + FileName = newLogFilePath, + UseShellExecute = true, + Verb = "open" + }); + + CommandResultText($"Dump logs at '{newLogFilePath}'"); + } + else + { + string dataPath = BetterDataManager.Folders.fileFolderPath; + string logFolderPath = Path.Combine(dataPath, "BetterLogDumps"); + if (!Directory.Exists(logFolderPath)) + { + Directory.CreateDirectory(logFolderPath); + } + + string androidLogContent = File.ReadAllText(logFilePath); + string androidNewLog = DecryptLog(androidLogContent); + + string androidLogFileName = "log-" + BAUPlugin.GetVersionText().Replace(' ', '-').ToLower() + "-" + DateTime.Now.ToString("yyyy.MM.dd-HH.mm.ss") + ".log"; + string androidNewLogFilePath = Path.Combine(logFolderPath, androidLogFileName); + File.WriteAllText(androidNewLogFilePath, androidNewLog); + + CommandResultText($"Dump logs at '{androidNewLogFilePath}'"); + } + } +} \ No newline at end of file diff --git a/src/Data/BetterDataManager.cs b/src/Data/BetterDataManager.cs index 4db562c..770272b 100644 --- a/src/Data/BetterDataManager.cs +++ b/src/Data/BetterDataManager.cs @@ -18,27 +18,27 @@ internal static class BetterDataManager /// /// Root directory for BetterAmongUs data. /// - internal static string fileFolderPath = Path.Combine(GetPathToAmongUs(), $"Better_Data"); + internal static readonly string fileFolderPath = Path.Combine(GetPathToAmongUs(), $"Better_Data"); /// /// Root directory for BetterAmongUs data. /// - internal static string starLightDataFolderPath = Environment.GetEnvironmentVariable("STAR_DATA_PATH") ?? string.Empty; + internal static readonly string starLightDataFolderPath = Environment.GetEnvironmentVariable("STAR_DATA_PATH") ?? string.Empty; /// /// Directory for save information files. /// - internal static string saveInfoFolderPath = Path.Combine(fileFolderPath, $"SaveInfo"); + internal static readonly string saveInfoFolderPath = Path.Combine(fileFolderPath, $"SaveInfo"); /// /// Directory for settings files. /// - internal static string settingsFolderPath = Path.Combine(fileFolderPath, $"Settings"); + internal static readonly string settingsFolderPath = Path.Combine(fileFolderPath, $"Settings"); /// /// Directory for game replay files. /// - internal static string replaysFolderPath = Path.Combine(fileFolderPath, $"Replays"); + internal static readonly string replaysFolderPath = Path.Combine(fileFolderPath, $"Replays"); } /// @@ -56,20 +56,30 @@ internal static class BetterDataManager /// internal static BetterGameSettingsFile BetterGameSettingsFile = new(); + /// + /// The log file path. + /// + internal static readonly string logFilePath = Path.Combine(Folders.fileFolderPath, "better-log.txt"); + + /// + /// The previous log file path. + /// + internal static readonly string previousLogFilePath = Path.Combine(Folders.fileFolderPath, "better-previous-log.txt"); + /// /// Legacy data file path (BetterData.json). /// - internal static string dataFilePath_Legacy = Path.Combine(GetPathToAmongUsData(), "BetterData.json"); + internal static readonly string dataFilePath_Legacy = Path.Combine(GetPathToAmongUsData(), "BetterData.json"); /// /// Current data file path (BetterDataV2.json). /// - internal static string dataFilePath = Path.Combine(GetPathToAmongUsData(), "BetterDataV2.json"); + internal static readonly string dataFilePath = Path.Combine(GetPathToAmongUsData(), "BetterDataV2.json"); /// /// Legacy settings file path. /// - internal static string settingsFilePath_Legacy = Path.Combine(Folders.settingsFolderPath, "Settings.dat"); + internal static readonly string settingsFilePath_Legacy = Path.Combine(Folders.settingsFolderPath, "Settings.dat"); /// /// Current compressed settings file path. @@ -79,17 +89,17 @@ internal static class BetterDataManager /// /// File containing banned player identifiers. /// - internal static string banPlayerListFilePath = Path.Combine(Folders.saveInfoFolderPath, "BanPlayerList.txt"); + internal static readonly string banPlayerListFilePath = Path.Combine(Folders.saveInfoFolderPath, "BanPlayerList.txt"); /// /// File containing banned player names. /// - internal static string banNameListFilePath = Path.Combine(Folders.saveInfoFolderPath, "BanNameList.txt"); + internal static readonly string banNameListFilePath = Path.Combine(Folders.saveInfoFolderPath, "BanNameList.txt"); /// /// File containing banned words/patterns. /// - internal static string banWordListFilePath = Path.Combine(Folders.saveInfoFolderPath, "BanWordList.txt"); + internal static readonly string banWordListFilePath = Path.Combine(Folders.saveInfoFolderPath, "BanWordList.txt"); } /// diff --git a/src/Helpers/Logger.cs b/src/Helpers/Logger.cs index 1ff6455..f776a29 100644 --- a/src/Helpers/Logger.cs +++ b/src/Helpers/Logger.cs @@ -28,7 +28,7 @@ internal static class Logger_ return; string mark = $"{DateTime.Now:HH:mm} [BetterLog][{tag}]"; - string logFilePath = Path.Combine(BetterDataManager.Folders.fileFolderPath, "better-log.txt"); + string logFilePath = BetterDataManager.Files.logFilePath; string newLine = $"{mark}: {Utils.RemoveHtmlText(info)}"; File.AppendAllText(logFilePath, newLine + Environment.NewLine); BAUPlugin.Logger.LogInfo($"[{tag}] {info}"); @@ -185,7 +185,7 @@ internal static class Logger_ return; string mark = $"{DateTime.Now:HH:mm} [BetterLog][PrivateLog][{tag}]"; - string logFilePath = Path.Combine(BetterDataManager.Folders.fileFolderPath, "better-log.txt"); + string logFilePath = BetterDataManager.Files.logFilePath; string newLine = $"{mark}: " + Encryptor.Encrypt($"{info}"); File.AppendAllText(logFilePath, newLine + Environment.NewLine); }