|
- using System;
- using System.Reflection;
- using Harmony;
- using UnityEngine;
- using Unity.Entities;
- using RobocraftX;
- using RobocraftX.GUI.CommandLine;
- using RobocraftX.Multiplayer;
- using Svelto.ECS;
- using Svelto.Context;
-
- namespace ExtraCommands
- {
- class UnregisterCommandEngine : CustomCommandEngine
- {
- public UnregisterCommandEngine(UnityContext<FullGameCompositionRoot> ctxHolder, EnginesRoot enginesRoot, World physW, Action reloadGame, MultiplayerInitParameters mpParams) : base(ctxHolder, enginesRoot, physW, reloadGame, mpParams)
- {
- }
- public override void Dispose()
- {
- int count = 0;
- MethodInfo commandRemoveHelp = Harmony.AccessTools.Method(Harmony.AccessTools.TypeByName("RobocraftX.GUI.CommandLine.CommandLineUtility"), "UnregisterCommandHelp", new Type[] { typeof(string) });
- foreach (Type t in typeof(CustomCommandEngine).Assembly.GetTypes())
- {
- CustomCommandAttribute[] attributes = (CustomCommandAttribute[])t.GetCustomAttributes(typeof(CustomCommandAttribute), false);
- foreach (CustomCommandAttribute attr in attributes)
- {
- if (attr != null && t.IsSubclassOf(typeof(CustomCommandEngine)))
- {
- // remove Gamecraft help command
- commandRemoveHelp.Invoke(null, new string[] { attr.Name });
- count++;
- }
- }
- }
- Debug.Log($"Removed {count} custom commands");
- }
- }
- }
|