From 3771a382e61772c6add8882029e66868bf850b29 Mon Sep 17 00:00:00 2001 From: MajorMoth <61519600+MajorMoth@users.noreply.github.com> Date: Sat, 18 Jul 2026 09:47:05 +0200 Subject: [PATCH] dump prototypes command --- .../DumpPrototypes/DumpPrototypesCommand.cs | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 Content.Client/_DEN/DumpPrototypes/DumpPrototypesCommand.cs diff --git a/Content.Client/_DEN/DumpPrototypes/DumpPrototypesCommand.cs b/Content.Client/_DEN/DumpPrototypes/DumpPrototypesCommand.cs new file mode 100644 index 0000000000..1594605f6b --- /dev/null +++ b/Content.Client/_DEN/DumpPrototypes/DumpPrototypesCommand.cs @@ -0,0 +1,71 @@ +using System.IO; +using System.Linq; +using System.Text; +using Content.Shared.Administration; +using Content.Shared.Maps; +using Robust.Client.UserInterface; +using Robust.Shared.Console; +using Robust.Shared.Prototypes; + +namespace Content.Client._DEN.DumpPrototypesCommand; + +[AnyCommand] +public sealed class DumpPrototypesCommand : IConsoleCommand +{ + [Dependency] private readonly IPrototypeManager _prototypeManager = default!; + [Dependency] private readonly IFileDialogManager _dialogManager = default!; + [Dependency] private readonly ILogManager _logManager = default!; + + public string Command => "dumpprototypes"; + public string Description => Loc.GetString("Dumps all currently loaded entity and tile prototypes into a file."); + public string Help => ""; // doesn't need it, no arguments + + public async void Execute(IConsoleShell shell, string argStr, string[] args) + { + var file = await _dialogManager.SaveFile(new FileDialogFilters(new FileDialogFilters.Group("txt"))); // Content.Client fails the type check when I try to use json + + var sawmill = _logManager.GetSawmill(Command); + + // while we wait for the dialog, we can do this in the background. + + var entities = _prototypeManager.EnumeratePrototypes(); + var tiles = _prototypeManager.EnumeratePrototypes(); + + var dump = new StringBuilder(); + + dump.AppendLine("=== Entities ==="); + + foreach (var entity in entities) + { + dump.AppendLine(entity.ID); + } + + dump.AppendLine("=== Tiles ==="); + + foreach (var tile in tiles) + { + dump.AppendLine(tile.ID); + } + + if (file == null) + { + sawmill.Error($"Error when dumping prototypes: Could not create file."); + return; + } + + try + { + await using var writer = new StreamWriter(file.Value.fileStream); + writer.Write(dump.ToString()); + + } + catch (Exception exc) + { + sawmill.Error($"Error when dumping prototypes: {exc.Message}\n{exc.StackTrace}"); + } + finally + { + await file.Value.fileStream.DisposeAsync(); + } + } +} \ No newline at end of file