Files
RobustToolbox/Robust.Shared/Console/Commands/DumpEventTablesCommand.cs
T
Leon FriedrichandGitHub 2eb740cea8 Try prevent eventbus loops (#5166)
* Add test

* Try prevent event bus linked list loops

* Eh, add an upper limit anyways
2024-06-15 12:20:48 +10:00

57 lines
1.8 KiB
C#

using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
namespace Robust.Shared.Console.Commands;
internal sealed class DumpEventTablesCommand : LocalizedCommands
{
[Dependency] private readonly EntityManager _entities = default!;
[Dependency] private readonly IComponentFactory _componentFactory = default!;
public override string Command => "dump_event_tables";
public override void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (args.Length < 1)
{
shell.WriteError(Loc.GetString("cmd-dump_event_tables-missing-arg-entity"));
return;
}
if (!NetEntity.TryParse(args[0], out var entityNet) ||
!_entities.TryGetEntity(entityNet, out var entity) ||
!_entities.EntityExists(entity))
{
shell.WriteError(Loc.GetString("cmd-dump_event_tables-error-entity"));
return;
}
var eventBus = (EntityEventBus)_entities.EventBus;
var table = eventBus._entEventTables[entity.Value];
foreach (var (evType, comps) in table.EventIndices)
{
shell.WriteLine($"{evType}:");
var idx = comps.Start;
while (idx != -1)
{
ref var entry = ref table.ComponentLists[idx];
idx = entry.Next;
var reg = _componentFactory.IdxToType(entry.Component);
shell.WriteLine($" {reg.Name}");
}
}
}
public override CompletionResult GetCompletion(IConsoleShell shell, string[] args)
{
if (args.Length == 1)
return CompletionResult.FromHint(Loc.GetString("cmd-dump_event_tables-arg-entity"));
return CompletionResult.Empty;
}
}