A stable modding interface between Techblox and mods https://mod.exmods.org/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

105 lines
6.7KB

  1. using System;
  2. using System.Reflection;
  3. using HarmonyLib;
  4. using Svelto.Context;
  5. using Svelto.ECS;
  6. using RobocraftX.CR.MainGame;
  7. using RobocraftX.Multiplayer;
  8. using RobocraftX.StateSync;
  9. namespace GamecraftModdingAPI.Commands
  10. {
  11. /// <summary>
  12. /// Patch of RobocraftX.CR.MainGame.MainGameCompositionRoot.DeterministicCompose<T>()
  13. /// Initializes existing and custom commands
  14. /// </summary>
  15. [HarmonyPatch]
  16. static class CommandPatch
  17. {
  18. public static void Postfix(Action reloadGame, MultiplayerInitParameters multiplayerParameters,
  19. StateSyncRegistrationHelper stateSyncReg)
  20. {
  21. /*CommandLineCompositionRoot.Compose(contextHolder, stateSyncReg.enginesRoot, reloadGame, multiplayerParameters,
  22. stateSyncReg); - uREPL C# compilation not supported anymore */
  23. var enginesRoot = stateSyncReg.enginesRoot;
  24. var entityFunctions = enginesRoot.GenerateEntityFunctions();
  25. var entityFactory = enginesRoot.GenerateEntityFactory();
  26. var entitySerializer = enginesRoot.GenerateEntitySerializer();
  27. enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
  28. AccessTools.TypeByName("RobocraftX.GUI.CommandLine.ExecuteSetGravityCommandEngine")));
  29. enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
  30. AccessTools.TypeByName("RobocraftX.GUI.CommandLine.ExecuteSetPhysicsPrecisionCommandEngine")));
  31. enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
  32. AccessTools.TypeByName("RobocraftX.GUI.CommandLine.ExecuteSetPhysicsFrequencyCommandEngine")));
  33. enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
  34. AccessTools.TypeByName(
  35. "RobocraftX.GUI.CommandLine.ExecuteClearAllPartsCommandEngine"),
  36. entityFunctions));
  37. enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
  38. AccessTools.TypeByName("RobocraftX.GUI.CommandLine.ExecuteHelpCommandEngine")));
  39. enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
  40. AccessTools.TypeByName(
  41. "RobocraftX.GUI.CommandLine.ExecuteSetLinearRestingThresholdCommandEngine")));
  42. enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
  43. AccessTools.TypeByName(
  44. "RobocraftX.GUI.CommandLine.ExecuteSetAngularRestingThresholdCommandEngine")));
  45. enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
  46. AccessTools.TypeByName("RobocraftX.GUI.CommandLine.ExecuteEnableVisualProfilerCommandEngine")));
  47. enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
  48. AccessTools.TypeByName("RobocraftX.GUI.CommandLine.ExecuteSetNetworkJitterFramesEngine")));
  49. enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
  50. AccessTools.TypeByName("RobocraftX.GUI.CommandLine.ExecuteSetSendConnectedEntitiesCommandEngine")));
  51. enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
  52. AccessTools.TypeByName("RobocraftX.GUI.CommandLine.ExecuteSetMaxSimFramesEngine")));
  53. enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
  54. AccessTools.TypeByName("RobocraftX.GUI.CommandLine.SetDebugDisplayExtraInfoCommandEngine")));
  55. enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
  56. AccessTools.TypeByName("RobocraftX.GUI.CommandLine.SetNetSyncBandwidthLimitCommandEngine")));
  57. enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
  58. AccessTools.TypeByName("RobocraftX.GUI.CommandLine.ThrowExceptionCommandEngine")));
  59. enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
  60. AccessTools.TypeByName("RobocraftX.GUI.CommandLine.SetPriorityCommandEngine")));
  61. enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
  62. AccessTools.TypeByName("RobocraftX.GUI.CommandLine.TeleportCharacterCommandEngine"),
  63. entityFactory));
  64. enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
  65. AccessTools.TypeByName("RobocraftX.GUI.CommandLine.ChangeTextBlockTextCommandEngine")));
  66. enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
  67. AccessTools.TypeByName("RobocraftX.GUI.CommandLine.SetCharacterRunSpeedCommandEngine")));
  68. enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
  69. AccessTools.TypeByName("RobocraftX.GUI.CommandLine.SetCameraZoomDistanceCommandEngine")));
  70. enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
  71. AccessTools.TypeByName("RobocraftX.GUI.CommandLine.EditLightingSettingsCommandEngine")));
  72. enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
  73. AccessTools.TypeByName("RobocraftX.GUI.CommandLine.EditSkySettingsCommandEngine")));
  74. enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
  75. AccessTools.TypeByName("RobocraftX.GUI.CommandLine.EditFogSettingsCommandEngine")));
  76. enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
  77. AccessTools.TypeByName("RobocraftX.GUI.CommandLine.TeleportCharacterImplementationEngine"),
  78. entityFunctions));
  79. enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
  80. AccessTools.TypeByName("RobocraftX.GUI.CommandLine.ExecuteConnectToServerCommandEngine"),
  81. entityFunctions, entitySerializer, reloadGame, multiplayerParameters));
  82. enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
  83. AccessTools.TypeByName("RobocraftX.GUI.CommandLine.SetInputBroadcastCommandEngine")));
  84. enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
  85. AccessTools.TypeByName("RobocraftX.GUI.CommandLine.ExecuteSetJointInertiaTensorCommandEngine")));
  86. enginesRoot.AddEngine(
  87. (IEngine) Activator.CreateInstance(
  88. AccessTools.TypeByName("RobocraftX.GUI.CommandLine.ChangeTeamCommandEngine")));
  89. enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
  90. AccessTools.TypeByName("RobocraftX.GUI.CommandLine.DamageCharacterCommandEngine"), entityFactory));
  91. enginesRoot.AddEngine((IEngine) Activator.CreateInstance(
  92. AccessTools.TypeByName("RobocraftX.GUI.CommandLine.DisableCharacterDamageCommandEngine")));
  93. CommandManager.RegisterEngines(enginesRoot);
  94. }
  95. public static MethodInfo TargetMethod()
  96. {
  97. return AccessTools.Method(typeof(MainGameCompositionRoot), "DeterministicCompose")
  98. .MakeGenericMethod(typeof(UnityContext<MainGameCompositionRoot>));
  99. }
  100. }
  101. }