Fixes, move command patch out of the test class
Removed some command line engines that shouldn't be registered Fixed registering custom commands - registering it with the existing ones
This commit is contained in:
parent
6a2459b3e7
commit
eb7a09ed22
2 changed files with 85 additions and 126 deletions
|
@ -1,38 +1,105 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
using HarmonyLib;
|
||||
using Svelto.Context;
|
||||
using Svelto.ECS;
|
||||
using RobocraftX;
|
||||
|
||||
using GamecraftModdingAPI.Utility;
|
||||
using RobocraftX.CR.MainGame;
|
||||
using RobocraftX.Multiplayer;
|
||||
using RobocraftX.StateSync;
|
||||
|
||||
namespace GamecraftModdingAPI.Commands
|
||||
{
|
||||
/// <summary>
|
||||
/// Patch of RobocraftX.GUI.CommandLine.CommandLineCompositionRoot.Compose<T>()
|
||||
/// Patch of RobocraftX.CR.MainGame.MainGameCompositionRoot.DeterministicCompose<T>()
|
||||
/// Initializes existing and custom commands
|
||||
/// </summary>
|
||||
// TODO: fix
|
||||
[HarmonyPatch]
|
||||
//[HarmonyPatch(typeof(RobocraftX.GUI.CommandLine.CommandLineCompositionRoot))]
|
||||
//[HarmonyPatch("Compose")]
|
||||
//[HarmonyPatch("Compose", new Type[] { typeof(UnityContext<FullGameCompositionRoot>), typeof(EnginesRoot), typeof(World), typeof(Action), typeof(MultiplayerInitParameters), typeof(StateSyncRegistrationHelper)})]
|
||||
static class CommandPatch
|
||||
{
|
||||
public static void Postfix(EnginesRoot enginesRoot)
|
||||
public static void Postfix(Action reloadGame, MultiplayerInitParameters multiplayerParameters,
|
||||
StateSyncRegistrationHelper stateSyncReg)
|
||||
{
|
||||
// When a game is loaded, register the command engines
|
||||
/*CommandLineCompositionRoot.Compose(contextHolder, stateSyncReg.enginesRoot, reloadGame, multiplayerParameters,
|
||||
stateSyncReg); - uREPL C# compilation not supported anymore */
|
||||
var enginesRoot = stateSyncReg.enginesRoot;
|
||||
var entityFunctions = enginesRoot.GenerateEntityFunctions();
|
||||
var entityFactory = enginesRoot.GenerateEntityFactory();
|
||||
var entitySerializer = enginesRoot.GenerateEntitySerializer();
|
||||
enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
|
||||
AccessTools.TypeByName("RobocraftX.GUI.CommandLine.ExecuteSetGravityCommandEngine")));
|
||||
enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
|
||||
AccessTools.TypeByName("RobocraftX.GUI.CommandLine.ExecuteSetPhysicsPrecisionCommandEngine")));
|
||||
enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
|
||||
AccessTools.TypeByName("RobocraftX.GUI.CommandLine.ExecuteSetPhysicsFrequencyCommandEngine")));
|
||||
enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
|
||||
AccessTools.TypeByName(
|
||||
"RobocraftX.GUI.CommandLine.ExecuteClearAllPartsCommandEngine"),
|
||||
entityFunctions));
|
||||
enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
|
||||
AccessTools.TypeByName("RobocraftX.GUI.CommandLine.ExecuteHelpCommandEngine")));
|
||||
enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
|
||||
AccessTools.TypeByName(
|
||||
"RobocraftX.GUI.CommandLine.ExecuteSetLinearRestingThresholdCommandEngine")));
|
||||
enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
|
||||
AccessTools.TypeByName(
|
||||
"RobocraftX.GUI.CommandLine.ExecuteSetAngularRestingThresholdCommandEngine")));
|
||||
enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
|
||||
AccessTools.TypeByName("RobocraftX.GUI.CommandLine.ExecuteEnableVisualProfilerCommandEngine")));
|
||||
enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
|
||||
AccessTools.TypeByName("RobocraftX.GUI.CommandLine.ExecuteSetNetworkJitterFramesEngine")));
|
||||
enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
|
||||
AccessTools.TypeByName("RobocraftX.GUI.CommandLine.ExecuteSetSendConnectedEntitiesCommandEngine")));
|
||||
enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
|
||||
AccessTools.TypeByName("RobocraftX.GUI.CommandLine.ExecuteSetMaxSimFramesEngine")));
|
||||
enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
|
||||
AccessTools.TypeByName("RobocraftX.GUI.CommandLine.SetDebugDisplayExtraInfoCommandEngine")));
|
||||
enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
|
||||
AccessTools.TypeByName("RobocraftX.GUI.CommandLine.SetNetSyncBandwidthLimitCommandEngine")));
|
||||
enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
|
||||
AccessTools.TypeByName("RobocraftX.GUI.CommandLine.ThrowExceptionCommandEngine")));
|
||||
enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
|
||||
AccessTools.TypeByName("RobocraftX.GUI.CommandLine.SetPriorityCommandEngine")));
|
||||
enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
|
||||
AccessTools.TypeByName("RobocraftX.GUI.CommandLine.TeleportCharacterCommandEngine"),
|
||||
entityFactory));
|
||||
enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
|
||||
AccessTools.TypeByName("RobocraftX.GUI.CommandLine.ChangeTextBlockTextCommandEngine")));
|
||||
enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
|
||||
AccessTools.TypeByName("RobocraftX.GUI.CommandLine.SetCharacterRunSpeedCommandEngine")));
|
||||
enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
|
||||
AccessTools.TypeByName("RobocraftX.GUI.CommandLine.SetCameraZoomDistanceCommandEngine")));
|
||||
enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
|
||||
AccessTools.TypeByName("RobocraftX.GUI.CommandLine.EditLightingSettingsCommandEngine")));
|
||||
enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
|
||||
AccessTools.TypeByName("RobocraftX.GUI.CommandLine.EditSkySettingsCommandEngine")));
|
||||
enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
|
||||
AccessTools.TypeByName("RobocraftX.GUI.CommandLine.EditFogSettingsCommandEngine")));
|
||||
enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
|
||||
AccessTools.TypeByName("RobocraftX.GUI.CommandLine.TeleportCharacterImplementationEngine"),
|
||||
entityFunctions));
|
||||
enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
|
||||
AccessTools.TypeByName("RobocraftX.GUI.CommandLine.ExecuteConnectToServerCommandEngine"),
|
||||
entityFunctions, entitySerializer, reloadGame, multiplayerParameters));
|
||||
enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
|
||||
AccessTools.TypeByName("RobocraftX.GUI.CommandLine.SetInputBroadcastCommandEngine")));
|
||||
enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
|
||||
AccessTools.TypeByName("RobocraftX.GUI.CommandLine.ExecuteSetJointInertiaTensorCommandEngine")));
|
||||
enginesRoot.AddEngine(
|
||||
(IEngine) Activator.CreateInstance(
|
||||
AccessTools.TypeByName("RobocraftX.GUI.CommandLine.ChangeTeamCommandEngine")));
|
||||
enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
|
||||
AccessTools.TypeByName("RobocraftX.GUI.CommandLine.DamageCharacterCommandEngine"), entityFactory));
|
||||
enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
|
||||
AccessTools.TypeByName("RobocraftX.GUI.CommandLine.DisableCharacterDamageCommandEngine")));
|
||||
|
||||
CommandManager.RegisterEngines(enginesRoot);
|
||||
}
|
||||
|
||||
public static MethodBase TargetMethod(Harmony instance)
|
||||
public static MethodInfo TargetMethod()
|
||||
{
|
||||
return typeof(RobocraftX.GUI.CommandLine.CommandLineCompositionRoot).GetMethod("Compose").MakeGenericMethod(typeof(object));
|
||||
//return func.Method;
|
||||
return AccessTools.Method(typeof(MainGameCompositionRoot), "DeterministicCompose")
|
||||
.MakeGenericMethod(typeof(UnityContext<MainGameCompositionRoot>));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -500,114 +500,6 @@ namespace GamecraftModdingAPI.Tests
|
|||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch]
|
||||
public static class MainGamePatch
|
||||
{
|
||||
public static void Postfix(Transform mainGameTransform)
|
||||
{
|
||||
//CommandLineCompositionRoot.Init(mainGameTransform).RunOn(Scheduler.extraLeanRunner); - uREPL C# compilation not supported anymore
|
||||
}
|
||||
|
||||
public static MethodInfo TargetMethod()
|
||||
{
|
||||
return AccessTools.Method(typeof(MainGameCompositionRoot), "Init");
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch]
|
||||
public static class MainGamePatch2
|
||||
{
|
||||
public static void Postfix(UnityContext<MainGameCompositionRoot> contextHolder,
|
||||
Action reloadGame, MultiplayerInitParameters multiplayerParameters,
|
||||
StateSyncRegistrationHelper stateSyncReg)
|
||||
{
|
||||
/*CommandLineCompositionRoot.Compose(contextHolder, stateSyncReg.enginesRoot, reloadGame, multiplayerParameters,
|
||||
stateSyncReg); - uREPL C# compilation not supported anymore */
|
||||
var enginesRoot = stateSyncReg.enginesRoot;
|
||||
var entityFunctions = enginesRoot.GenerateEntityFunctions();
|
||||
var entityFactory = enginesRoot.GenerateEntityFactory();
|
||||
var entitySerializer = enginesRoot.GenerateEntitySerializer();
|
||||
enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
|
||||
AccessTools.TypeByName("RobocraftX.GUI.CommandLine.ExecuteSetGravityCommandEngine")));
|
||||
enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
|
||||
AccessTools.TypeByName("RobocraftX.GUI.CommandLine.ExecuteSetPhysicsPrecisionCommandEngine")));
|
||||
enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
|
||||
AccessTools.TypeByName("RobocraftX.GUI.CommandLine.ExecuteSetPhysicsFrequencyCommandEngine")));
|
||||
enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
|
||||
AccessTools.TypeByName(
|
||||
"RobocraftX.GUI.CommandLine.ExecuteClearAllPartsCommandEngine"),
|
||||
entityFunctions));
|
||||
enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
|
||||
AccessTools.TypeByName("RobocraftX.GUI.CommandLine.ExecuteHelpCommandEngine")));
|
||||
enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
|
||||
AccessTools.TypeByName(
|
||||
"RobocraftX.GUI.CommandLine.ExecuteSetLinearRestingThresholdCommandEngine")));
|
||||
enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
|
||||
AccessTools.TypeByName(
|
||||
"RobocraftX.GUI.CommandLine.ExecuteSetAngularRestingThresholdCommandEngine")));
|
||||
enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
|
||||
AccessTools.TypeByName("RobocraftX.GUI.CommandLine.ExecuteEnableVisualProfilerCommandEngine")));
|
||||
enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
|
||||
AccessTools.TypeByName("RobocraftX.GUI.CommandLine.ExecuteSetNetworkJitterFramesEngine")));
|
||||
enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
|
||||
AccessTools.TypeByName("RobocraftX.GUI.CommandLine.ExecuteSetSendConnectedEntitiesCommandEngine")));
|
||||
enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
|
||||
AccessTools.TypeByName("RobocraftX.GUI.CommandLine.ExecuteSetMaxSimFramesEngine")));
|
||||
enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
|
||||
AccessTools.TypeByName("RobocraftX.GUI.CommandLine.SetDebugDisplayExtraInfoCommandEngine")));
|
||||
enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
|
||||
AccessTools.TypeByName("RobocraftX.GUI.CommandLine.SetNetSyncBandwidthLimitCommandEngine")));
|
||||
enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
|
||||
AccessTools.TypeByName("RobocraftX.GUI.CommandLine.ThrowExceptionCommandEngine")));
|
||||
enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
|
||||
AccessTools.TypeByName("RobocraftX.GUI.CommandLine.SetPriorityCommandEngine")));
|
||||
enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
|
||||
AccessTools.TypeByName("RobocraftX.GUI.CommandLine.TeleportCharacterCommandEngine"),
|
||||
entityFactory));
|
||||
enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
|
||||
AccessTools.TypeByName("RobocraftX.GUI.CommandLine.ChangeTextBlockTextCommandEngine")));
|
||||
enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
|
||||
AccessTools.TypeByName("RobocraftX.GUI.CommandLine.SetCharacterRunSpeedCommandEngine")));
|
||||
enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
|
||||
AccessTools.TypeByName("RobocraftX.GUI.CommandLine.SetCameraZoomDistanceCommandEngine")));
|
||||
enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
|
||||
AccessTools.TypeByName("RobocraftX.GUI.CommandLine.EditLightingSettingsCommandEngine")));
|
||||
enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
|
||||
AccessTools.TypeByName("RobocraftX.GUI.CommandLine.EditSkySettingsCommandEngine")));
|
||||
enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
|
||||
AccessTools.TypeByName("RobocraftX.GUI.CommandLine.EditFogSettingsCommandEngine")));
|
||||
enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
|
||||
AccessTools.TypeByName("RobocraftX.GUI.CommandLine.TeleportCharacterImplementationEngine"),
|
||||
entityFunctions));
|
||||
enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
|
||||
AccessTools.TypeByName("RobocraftX.GUI.CommandLine.ExecuteConnectToServerCommandEngine"),
|
||||
entityFunctions, entitySerializer, reloadGame, multiplayerParameters));
|
||||
enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
|
||||
AccessTools.TypeByName("RobocraftX.GUI.CommandLine.SetInputBroadcastCommandEngine")));
|
||||
enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
|
||||
AccessTools.TypeByName("RobocraftX.GUI.CommandLine.ExecuteSetJointInertiaTensorCommandEngine")));
|
||||
enginesRoot.AddEngine(
|
||||
(IEngine) Activator.CreateInstance(
|
||||
AccessTools.TypeByName("RobocraftX.GUI.CommandLine.CommandLineInputEngine")));
|
||||
stateSyncReg.AddDeterministicEngine(
|
||||
(IDeterministicEngine) Activator.CreateInstance(
|
||||
AccessTools.TypeByName("RobocraftX.GUI.CommandLine.ExecuteCommandEngine")));
|
||||
enginesRoot.AddEngine(
|
||||
(IEngine) Activator.CreateInstance(
|
||||
AccessTools.TypeByName("RobocraftX.GUI.CommandLine.ChangeTeamCommandEngine")));
|
||||
enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
|
||||
AccessTools.TypeByName("RobocraftX.GUI.CommandLine.DamageCharacterCommandEngine"), entityFactory));
|
||||
enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
|
||||
AccessTools.TypeByName("RobocraftX.GUI.CommandLine.DisableCharacterDamageCommandEngine")));
|
||||
}
|
||||
|
||||
public static MethodInfo TargetMethod()
|
||||
{
|
||||
return AccessTools.Method(typeof(MainGameCompositionRoot), "DeterministicCompose")
|
||||
.MakeGenericMethod(typeof(UnityContext<MainGameCompositionRoot>));
|
||||
}
|
||||
}
|
||||
|
||||
[CustomBlock("customCatalog.json", "Assets/Prefabs/Cube.prefab", "strAluminiumCube", SortIndex = 12)]
|
||||
public class TestBlock : CustomBlock
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue