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.

79 lines
2.2KB

  1. using System.Reflection;
  2. using HarmonyLib;
  3. using RobocraftX;
  4. using RobocraftX.CR.MainGame;
  5. using RobocraftX.FrontEnd;
  6. using RobocraftX.StateSync;
  7. using Svelto.ECS;
  8. using Svelto.ECS.Schedulers;
  9. using TechbloxModdingAPI.Commands;
  10. using TechbloxModdingAPI.Utility;
  11. namespace TechbloxModdingAPI.Engines
  12. {
  13. [HarmonyPatch]
  14. static class GameLoadedTimeStoppedEnginePatch
  15. {
  16. public static EntitiesSubmissionScheduler Scheduler { get; private set; }
  17. public static void Postfix(StateSyncRegistrationHelper stateSyncReg)
  18. {
  19. // register all game engines, including deterministic
  20. GameEngineManager.RegisterEngines(stateSyncReg);
  21. Scheduler = stateSyncReg.enginesRoot.scheduler;
  22. // register command engines
  23. /*CommandLineCompositionRoot.Compose(contextHolder, stateSyncReg.enginesRoot, reloadGame, multiplayerParameters,
  24. stateSyncReg); - uREPL C# compilation not supported anymore */
  25. CommandManager.RegisterEngines(stateSyncReg.enginesRoot);
  26. }
  27. public static MethodBase TargetMethod()
  28. {
  29. return AccessTools.Method(typeof(MainGameCompositionRoot), "DeterministicTimeStoppedCompose").MakeGenericMethod(typeof(object));
  30. }
  31. }
  32. [HarmonyPatch]
  33. static class GameLoadedTimeRunningEnginePatch
  34. {
  35. public static EntitiesSubmissionScheduler Scheduler { get; private set; }
  36. public static void Postfix(StateSyncRegistrationHelper stateSyncReg)
  37. {
  38. GameLoadedTimeStoppedEnginePatch.Postfix(stateSyncReg);
  39. }
  40. public static MethodBase TargetMethod()
  41. {
  42. return AccessTools.Method(typeof(MainGameCompositionRoot), "DeterministicTimeRunningCompose").MakeGenericMethod(typeof(object));
  43. }
  44. }
  45. [HarmonyPatch]
  46. class MenuLoadedEnginePatch
  47. {
  48. public static void Postfix(EnginesRoot enginesRoot)
  49. {
  50. // register menu engines
  51. MenuEngineManager.RegisterEngines(enginesRoot);
  52. }
  53. public static MethodBase TargetMethod()
  54. {
  55. return AccessTools.Method(typeof(FrontEndCompositionRoot), "Compose").MakeGenericMethod(typeof(object));
  56. }
  57. }
  58. [HarmonyPatch]
  59. class FullGameCreatedEnginePatch
  60. {
  61. public static void Postfix(FullGameCompositionRoot __instance)
  62. {
  63. FullGameFields.Init(__instance);
  64. }
  65. public static MethodBase TargetMethod()
  66. {
  67. return AccessTools.DeclaredConstructor(typeof(FullGameCompositionRoot));
  68. }
  69. }
  70. }