Fix commands not being disposed properly and disabled MoveBlocks
This commit is contained in:
parent
064f719f82
commit
9071fccf76
4 changed files with 18 additions and 20 deletions
|
@ -16,6 +16,8 @@ namespace ExtraCommands
|
|||
{
|
||||
static void Postfix(UnityContext<FullGameCompositionRoot> 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())
|
||||
{
|
||||
|
@ -32,16 +34,19 @@ namespace ExtraCommands
|
|||
.Invoke(new object[] { contextHolder, enginesRoot, physicsWorld, reloadGame, multiplayerParameters });
|
||||
// add to engineRoot
|
||||
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");
|
||||
}
|
||||
|
||||
[HarmonyTargetMethod]
|
||||
static MethodBase HTargetMethod(HarmonyInstance instance)
|
||||
static MethodBase TargetMethod(HarmonyInstance instance)
|
||||
{
|
||||
return _ComposeMethodInfo(CommandLineCompositionRoot.Compose<CommandLineContext>);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<TargetFramework>net45</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -72,7 +72,6 @@
|
|||
<Reference Include="uREPL">
|
||||
<HintPath>..\ref\uREPL.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Build, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -14,7 +14,7 @@ using RobocraftX;
|
|||
|
||||
namespace ExtraCommands.Building
|
||||
{
|
||||
[CustomCommand("MoveBlocks", "Move blocks from their original position")]
|
||||
//[CustomCommand("MoveBlocks", "Move blocks from their original position")]
|
||||
class MoveBlocksCommandEngine : CustomCommandEngine
|
||||
{
|
||||
public MoveBlocksCommandEngine(UnityContext<FullGameCompositionRoot> ctxHolder, EnginesRoot enginesRoot, World physW, Action reloadGame, MultiplayerInitParameters mpParams) : base(ctxHolder, enginesRoot, physW, reloadGame, mpParams)
|
||||
|
|
|
@ -11,12 +11,15 @@ using Svelto.Context;
|
|||
|
||||
namespace ExtraCommands
|
||||
{
|
||||
[HarmonyPatch]
|
||||
class CommandLineCompositionRootUnregisterCommandPatch
|
||||
class UnregisterCommandEngine : CustomCommandEngine
|
||||
{
|
||||
static void Prefix()
|
||||
public UnregisterCommandEngine(UnityContext<FullGameCompositionRoot> ctxHolder, EnginesRoot enginesRoot, World physW, Action reloadGame, MultiplayerInitParameters mpParams) : base(ctxHolder, enginesRoot, physW, reloadGame, mpParams)
|
||||
{
|
||||
MethodInfo commandRemoveHelp = Harmony.AccessTools.Method(Harmony.AccessTools.TypeByName("RobocraftX.GUI.CommandLine.CommandLineUtility"), "SaveCommandHelp", new Type[] { typeof(string) });
|
||||
}
|
||||
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);
|
||||
|
@ -26,20 +29,11 @@ namespace ExtraCommands
|
|||
{
|
||||
// remove Gamecraft help command
|
||||
commandRemoveHelp.Invoke(null, new string[] { attr.Name });
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyTargetMethod]
|
||||
static MethodBase HTargetMethod(HarmonyInstance instance)
|
||||
{
|
||||
return _OnContextDestroyedMethodInfo((new CommandLineCompositionRoot()).OnContextDestroyed);
|
||||
}
|
||||
|
||||
private static MethodInfo _OnContextDestroyedMethodInfo(Action a)
|
||||
{
|
||||
return a.Method;
|
||||
Debug.Log($"Removed {count} custom commands");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue