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.

46 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. [HarmonyPatch]
  14. class CommandLineCompositionRootUnregisterCommandPatch
  15. {
  16. static void Prefix()
  17. {
  18. MethodInfo commandRemoveHelp = Harmony.AccessTools.Method(Harmony.AccessTools.TypeByName("RobocraftX.GUI.CommandLine.CommandLineUtility"), "SaveCommandHelp", new Type[] { typeof(string) });
  19. foreach (Type t in typeof(CustomCommandEngine).Assembly.GetTypes())
  20. {
  21. CustomCommandAttribute[] attributes = (CustomCommandAttribute[])t.GetCustomAttributes(typeof(CustomCommandAttribute), false);
  22. foreach (CustomCommandAttribute attr in attributes)
  23. {
  24. if (attr != null && t.IsSubclassOf(typeof(CustomCommandEngine)))
  25. {
  26. // remove Gamecraft help command
  27. commandRemoveHelp.Invoke(null, new string[] { attr.Name });
  28. }
  29. }
  30. }
  31. }
  32. [HarmonyTargetMethod]
  33. static MethodBase HTargetMethod(HarmonyInstance instance)
  34. {
  35. return _OnContextDestroyedMethodInfo((new CommandLineCompositionRoot()).OnContextDestroyed);
  36. }
  37. private static MethodInfo _OnContextDestroyedMethodInfo(Action a)
  38. {
  39. return a.Method;
  40. }
  41. }
  42. }