Moar Gamecraft commands!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.5KB

  1. using System;
  2. using System.Reflection;
  3. using Harmony;
  4. using UnityEngine;
  5. using Unity.Entities;
  6. using RobocraftX;
  7. using RobocraftX.GUI.CommandLine;
  8. using RobocraftX.Multiplayer;
  9. using Svelto.ECS;
  10. using Svelto.Context;
  11. namespace ExtraCommands
  12. {
  13. class UnregisterCommandEngine : CustomCommandEngine
  14. {
  15. public UnregisterCommandEngine(UnityContext<FullGameCompositionRoot> ctxHolder, EnginesRoot enginesRoot, World physW, Action reloadGame, MultiplayerInitParameters mpParams) : base(ctxHolder, enginesRoot, physW, reloadGame, mpParams)
  16. {
  17. }
  18. public override void Dispose()
  19. {
  20. int count = 0;
  21. MethodInfo commandRemoveHelp = Harmony.AccessTools.Method(Harmony.AccessTools.TypeByName("RobocraftX.GUI.CommandLine.CommandLineUtility"), "UnregisterCommandHelp", new Type[] { typeof(string) });
  22. foreach (Type t in typeof(CustomCommandEngine).Assembly.GetTypes())
  23. {
  24. CustomCommandAttribute[] attributes = (CustomCommandAttribute[])t.GetCustomAttributes(typeof(CustomCommandAttribute), false);
  25. foreach (CustomCommandAttribute attr in attributes)
  26. {
  27. if (attr != null && t.IsSubclassOf(typeof(CustomCommandEngine)))
  28. {
  29. // remove Gamecraft help command
  30. commandRemoveHelp.Invoke(null, new string[] { attr.Name });
  31. count++;
  32. }
  33. }
  34. }
  35. Debug.Log($"Removed {count} custom commands");
  36. }
  37. }
  38. }