diff --git a/extracommands/ChainCommandEngine.cs b/extracommands/ChainCommandEngine.cs index 6404e1a..3b1c14a 100644 --- a/extracommands/ChainCommandEngine.cs +++ b/extracommands/ChainCommandEngine.cs @@ -12,9 +12,7 @@ using RobocraftX; namespace ExtraCommands.Basics { - [CustomCommand("Chain", "Run two commands, one after the other")] - [CustomCommand("ChainNoFail", "Run two commands, one after the other even if the first one is invalid")] - [CustomCommand("ChainQuiet", "Run two commands, one after the other quietly")] + [CustomCommand] class ChainCommandEngine : CustomCommandEngine { public ChainCommandEngine(UnityContext ctxHolder, EnginesRoot enginesRoot, World physW, Action reloadGame, MultiplayerInitParameters mpParams) : base(ctxHolder, enginesRoot, physW, reloadGame, mpParams) @@ -23,9 +21,9 @@ namespace ExtraCommands.Basics public override void Ready() { - uREPL.RuntimeCommands.Register("Chain", ChainCommand, "Run two commands, one after the other"); - uREPL.RuntimeCommands.Register("ChainNoFail", ChainNoFailCommand, "Run two commands, one after the other even if the first one is invalid"); - uREPL.RuntimeCommands.Register("ChainQuiet", ChainQuietCommand, "Run two commands, one after the other quietly"); + CustomCommandUtility.Register("Chain", ChainCommand, "Run two commands, one after the other"); + CustomCommandUtility.Register("ChainNoFail", ChainNoFailCommand, "Run two commands, one after the other even if the first one is invalid"); + CustomCommandUtility.Register("ChainQuiet", ChainQuietCommand, "Run two commands, one after the other quietly"); } private void ChainCommand(string command1, string command2) @@ -90,9 +88,9 @@ namespace ExtraCommands.Basics public override void Dispose() { - uREPL.RuntimeCommands.Unregister("Chain"); - uREPL.RuntimeCommands.Unregister("ChainNoFail"); - uREPL.RuntimeCommands.Unregister("ChainQuiet"); + CustomCommandUtility.Unregister("Chain"); + CustomCommandUtility.Unregister("ChainNoFail"); + CustomCommandUtility.Unregister("ChainQuiet"); } } } diff --git a/extracommands/CommandLineCompositionRootSaveCommandPatch.cs b/extracommands/CommandLineCompositionRootSaveCommandPatch.cs index 01ebf1a..0e964ad 100644 --- a/extracommands/CommandLineCompositionRootSaveCommandPatch.cs +++ b/extracommands/CommandLineCompositionRootSaveCommandPatch.cs @@ -16,7 +16,6 @@ namespace ExtraCommands { static void Postfix(UnityContext contextHolder, EnginesRoot enginesRoot, World physicsWorld, Action reloadGame, MultiplayerInitParameters multiplayerParameters) { - int commandCount = 0; int engineCount = 0; MethodInfo commandHelp = Harmony.AccessTools.Method(Harmony.AccessTools.TypeByName("RobocraftX.GUI.CommandLine.CommandLineUtility"), "SaveCommandHelp", new Type[] { typeof(string), typeof(string) }); foreach (Type t in typeof(CustomCommandEngine).Assembly.GetTypes()) @@ -36,22 +35,19 @@ namespace ExtraCommands enginesRoot.AddEngine(inst); engineCount++; } - // add to Gamecraft help command - commandHelp.Invoke(null, new string[] { attr.Name, attr.Description }); - commandCount++; } } } - enginesRoot.AddEngine(new UnregisterCommandEngine(contextHolder, enginesRoot, physicsWorld, reloadGame, multiplayerParameters)); - Debug.Log($"Added {commandCount} custom commands in {engineCount} engines"); + // enginesRoot.AddEngine(new UnregisterCommandEngine(contextHolder, enginesRoot, physicsWorld, reloadGame, multiplayerParameters)); + Debug.Log($"Added {engineCount} custom command engines"); } static MethodBase TargetMethod(HarmonyInstance instance) { - return _ComposeMethodInfo(CommandLineCompositionRoot.Compose); + return _ComposeMethodInfo(CommandLineCompositionRoot.Compose>); } - private static MethodInfo _ComposeMethodInfo(Action a) + private static MethodInfo _ComposeMethodInfo(Action, EnginesRoot, World, Action, MultiplayerInitParameters> a) { return a.Method; } diff --git a/extracommands/CustomCommandAttribute.cs b/extracommands/CustomCommandAttribute.cs index ecf1a74..30af547 100644 --- a/extracommands/CustomCommandAttribute.cs +++ b/extracommands/CustomCommandAttribute.cs @@ -7,11 +7,9 @@ namespace ExtraCommands { public string Name { get; protected set; } - public string Description { get; protected set; } - public CustomCommandAttribute(string name, string description = "") + public CustomCommandAttribute(string name = "") { this.Name = name; - this.Description = description; } } } diff --git a/extracommands/CustomCommandEngine.cs b/extracommands/CustomCommandEngine.cs index ddd1042..8963275 100644 --- a/extracommands/CustomCommandEngine.cs +++ b/extracommands/CustomCommandEngine.cs @@ -33,7 +33,7 @@ namespace ExtraCommands virtual public void Dispose() { } - // NOTE: Ready() should call uREPL.RuntimeCommands.Register to add the command to the command line + // NOTE: Ready() should call CustomCommandUtility.Register to add the command to the command line virtual public void Ready() { } } } diff --git a/extracommands/CustomCommandUtility.cs b/extracommands/CustomCommandUtility.cs new file mode 100644 index 0000000..2a8ac87 --- /dev/null +++ b/extracommands/CustomCommandUtility.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using uREPL; +using RobocraftX.CommandLine.Custom; + +namespace ExtraCommands +{ + static class CustomCommandUtility + { + public static void Register(string name, Action action, string desc) + { + RuntimeCommands.Register(name, action, desc); + ConsoleCommands.Register(name, action, desc); + } + + public static void Register(string name, Action action, string desc) + { + RuntimeCommands.Register(name, action, desc); + } + + public static void Register(string name, Action action, string desc) + { + RuntimeCommands.Register(name, action, desc); + ConsoleCommands.Register(name, action, desc); + } + + public static void Register(string name, Action action, string desc) + { + RuntimeCommands.Register(name, action, desc); + ConsoleCommands.Register(name, action, desc); + } + + public static void Register(string name, Action action, string desc) + { + RuntimeCommands.Register(name, action, desc); + ConsoleCommands.Register(name, action, desc); + } + + public static void Register(string name, Action action, string desc) + { + RuntimeCommands.Register(name, action, desc); + ConsoleCommands.Register(name, action, desc); + } + + public static void Unregister(string name) + { + RuntimeCommands.Unregister(name); + ConsoleCommands.Unregister(name); + } + } +} diff --git a/extracommands/ExitCommandEngine.cs b/extracommands/ExitCommandEngine.cs index 5647e91..e2caa2b 100644 --- a/extracommands/ExitCommandEngine.cs +++ b/extracommands/ExitCommandEngine.cs @@ -12,7 +12,7 @@ using RobocraftX; namespace ExtraCommands.Basics { - [CustomCommand("Exit", "Forcefully close Gamecraft")] + [CustomCommand("Exit")] class ExitCommandEngine : CustomCommandEngine { public ExitCommandEngine(UnityContext ctxHolder, EnginesRoot enginesRoot, World physW, Action reloadGame, MultiplayerInitParameters mpParams) : base(ctxHolder, enginesRoot, physW, reloadGame, mpParams) @@ -21,7 +21,7 @@ namespace ExtraCommands.Basics public override void Ready() { - uREPL.RuntimeCommands.Register("Exit", ExitCommand, "Forcefully close Gamecraft"); + CustomCommandUtility.Register("Exit", ExitCommand, "Forcefully close Gamecraft"); } private void ExitCommand() @@ -31,7 +31,7 @@ namespace ExtraCommands.Basics public override void Dispose() { - uREPL.RuntimeCommands.Unregister("Exit"); + CustomCommandUtility.Unregister("Exit"); } } } diff --git a/extracommands/ExtraCommands.csproj b/extracommands/ExtraCommands.csproj index db17a5c..7b34e8f 100644 --- a/extracommands/ExtraCommands.csproj +++ b/extracommands/ExtraCommands.csproj @@ -1,7 +1,7 @@  - net45 + net461 @@ -12,6 +12,9 @@ ..\ref\CommandLine.dll + + ..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Gamecraft\Gamecraft_Data\Managed\Facepunch.Steamworks.Win64.dll + ..\ref\FullGame.dll diff --git a/extracommands/MoveBlocksCommandEngine.cs b/extracommands/MoveBlocksCommandEngine.cs index 851ff41..d69452d 100644 --- a/extracommands/MoveBlocksCommandEngine.cs +++ b/extracommands/MoveBlocksCommandEngine.cs @@ -23,7 +23,7 @@ namespace ExtraCommands.Building public override void Ready() { - uREPL.RuntimeCommands.Register("MoveBlocks", MoveBlocksCommand, "Move blocks from their original position"); + CustomCommandUtility.Register("MoveBlocks", MoveBlocksCommand, "Move blocks from their original position"); } private void MoveBlocksCommand(float x, float y, float z) @@ -45,7 +45,7 @@ namespace ExtraCommands.Building public override void Dispose() { - uREPL.RuntimeCommands.Unregister("MoveBlocks"); + CustomCommandUtility.Unregister("MoveBlocks"); } } } diff --git a/extracommands/SetFOVCommandEngine.cs b/extracommands/SetFOVCommandEngine.cs index f72cb0e..b4f7b45 100644 --- a/extracommands/SetFOVCommandEngine.cs +++ b/extracommands/SetFOVCommandEngine.cs @@ -12,7 +12,7 @@ using RobocraftX; namespace ExtraCommands.Basics { - [CustomCommand("SetFieldOfView", "Set the camera's field of view")] + [CustomCommand("SetFieldOfView")] class SetFOVCommandEngine : CustomCommandEngine { public SetFOVCommandEngine(UnityContext ctxHolder, EnginesRoot enginesRoot, World physW, Action reloadGame, MultiplayerInitParameters mpParams) : base(ctxHolder, enginesRoot, physW, reloadGame, mpParams) @@ -21,7 +21,7 @@ namespace ExtraCommands.Basics public override void Ready() { - uREPL.RuntimeCommands.Register("SetFieldOfView", SetFieldOfViewCommand, "Set the camera's field of view"); + CustomCommandUtility.Register("SetFieldOfView", SetFieldOfViewCommand, "Set the camera's field of view"); } private void SetFieldOfViewCommand(float newFoV) @@ -31,7 +31,7 @@ namespace ExtraCommands.Basics public override void Dispose() { - uREPL.RuntimeCommands.Unregister("SetFieldOfView"); + CustomCommandUtility.Unregister("SetFieldOfView"); } } } diff --git a/extracommands/SetTargetFramerateCommandEngine.cs b/extracommands/SetTargetFramerateCommandEngine.cs index 4d863e8..378d404 100644 --- a/extracommands/SetTargetFramerateCommandEngine.cs +++ b/extracommands/SetTargetFramerateCommandEngine.cs @@ -12,7 +12,7 @@ using RobocraftX; namespace ExtraCommands.Basics { - [CustomCommand("SetTargetFPS", "Set Gamecraft's target FPS")] + [CustomCommand("SetTargetFPS")] class SetTargetFramerateCommandEngine : CustomCommandEngine { public SetTargetFramerateCommandEngine(UnityContext ctxHolder, EnginesRoot enginesRoot, World physW, Action reloadGame, MultiplayerInitParameters mpParams) : base(ctxHolder, enginesRoot, physW, reloadGame, mpParams) @@ -21,7 +21,7 @@ namespace ExtraCommands.Basics public override void Ready() { - uREPL.RuntimeCommands.Register("SetTargetFPS", SetFramerateCommand, "Set Gamecraft's target FPS"); + CustomCommandUtility.Register("SetTargetFPS", SetFramerateCommand, "Set Gamecraft's target FPS"); } private void SetFramerateCommand(int newFoV) @@ -31,7 +31,7 @@ namespace ExtraCommands.Basics public override void Dispose() { - uREPL.RuntimeCommands.Unregister("SetTargetFPS"); + CustomCommandUtility.Unregister("SetTargetFPS"); } } } diff --git a/extracommands/TeleportWaypointCommandEngine.cs b/extracommands/TeleportWaypointCommandEngine.cs index b55763a..329a177 100644 --- a/extracommands/TeleportWaypointCommandEngine.cs +++ b/extracommands/TeleportWaypointCommandEngine.cs @@ -12,8 +12,7 @@ using RobocraftX; namespace ExtraCommands.Waypoints { - [CustomCommand("CreateWaypoint", "Create a waypoint in your current location")] - [CustomCommand("TeleportPlayerWaypoint", "Teleport to a waypoint")] + [CustomCommand] class TeleportWaypointCommandEngine : CustomCommandEngine { private Dictionary _waypoints = new Dictionary(); @@ -23,8 +22,8 @@ namespace ExtraCommands.Waypoints public override void Ready() { - uREPL.RuntimeCommands.Register("CreateWaypoint", CreateWaypointCommand, "Create a waypoint in your current location"); - uREPL.RuntimeCommands.Register("TeleportPlayerWaypoint", TeleportToWaypointCommand, "Teleport to a waypoint"); + CustomCommandUtility.Register("CreateWaypoint", CreateWaypointCommand, "Create a waypoint in your current location"); + CustomCommandUtility.Register("TeleportPlayerWaypoint", TeleportToWaypointCommand, "Teleport to a waypoint"); } private void CreateWaypointCommand(object name) @@ -47,8 +46,8 @@ namespace ExtraCommands.Waypoints public override void Dispose() { - uREPL.RuntimeCommands.Unregister("CreateWaypoint"); - uREPL.RuntimeCommands.Unregister("TeleportPlayerWaypoint"); + CustomCommandUtility.Unregister("CreateWaypoint"); + CustomCommandUtility.Unregister("TeleportPlayerWaypoint"); } } } diff --git a/extracommands/WaitCommandEngine.cs b/extracommands/WaitCommandEngine.cs index 328f56b..2dd1899 100644 --- a/extracommands/WaitCommandEngine.cs +++ b/extracommands/WaitCommandEngine.cs @@ -12,7 +12,7 @@ using RobocraftX; namespace ExtraCommands.Basics { - [CustomCommand("Wait", "Delay execution for a length of time (ms)")] + [CustomCommand("Wait")] class WaitCommandEngine : CustomCommandEngine { public WaitCommandEngine(UnityContext ctxHolder, EnginesRoot enginesRoot, World physW, Action reloadGame, MultiplayerInitParameters mpParams) : base(ctxHolder, enginesRoot, physW, reloadGame, mpParams) @@ -21,7 +21,7 @@ namespace ExtraCommands.Basics public override void Ready() { - uREPL.RuntimeCommands.Register("Wait", WaitCommand, "Delay execution for a length of time (ms)"); + CustomCommandUtility.Register("Wait", WaitCommand, "Delay execution for a length of time (ms)"); } private void WaitCommand(int ms) @@ -31,7 +31,7 @@ namespace ExtraCommands.Basics public override void Dispose() { - uREPL.RuntimeCommands.Unregister("Wait"); + CustomCommandUtility.Unregister("Wait"); } } }