浏览代码

Fix commands not being disposed properly and disabled MoveBlocks

tags/v0.0.2
NGnius 4 年前
父节点
当前提交
9071fccf76
共有 4 个文件被更改,包括 18 次插入20 次删除
  1. +7
    -2
      extracommands/CommandLineCompositionRootSaveCommandPatch.cs
  2. +1
    -2
      extracommands/ExtraCommands.csproj
  3. +1
    -1
      extracommands/MoveBlocksCommandEngine.cs
  4. +9
    -15
      extracommands/UnregisterCommandEngine.cs

+ 7
- 2
extracommands/CommandLineCompositionRootSaveCommandPatch.cs 查看文件

@@ -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
- 2
extracommands/ExtraCommands.csproj 查看文件

@@ -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>

+ 1
- 1
extracommands/MoveBlocksCommandEngine.cs 查看文件

@@ -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)


extracommands/CommandLineCompositionRootUnregisterCommandPatch.cs → extracommands/UnregisterCommandEngine.cs 查看文件

@@ -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");
}
}
}

正在加载...
取消
保存