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.

61 lines
1.9KB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Reflection;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using HarmonyLib;
  8. using RobocraftX.CR.MainGame;
  9. using Svelto.ECS;
  10. using Unity.Entities;
  11. using GamecraftModdingAPI.Utility;
  12. namespace GamecraftModdingAPI.Events
  13. {
  14. /// <summary>
  15. /// Patch of RobocraftX.FullGameCompositionRoot.ActivateGame()
  16. /// </summary>
  17. [HarmonyPatch]
  18. class GameActivatedComposePatch
  19. {
  20. public static bool IsGameSwitching = false;
  21. public static bool IsGameReloading = false;
  22. public static void Postfix(ref object contextHolder, ref EnginesRoot enginesRoot, World physicsWorld)
  23. {
  24. // register custom game engines
  25. GameEngineManager.RegisterEngines(enginesRoot);
  26. // initialize AsyncUtils
  27. AsyncUtils.Setup(enginesRoot);
  28. // initialize Block
  29. Block.Setup(physicsWorld);
  30. // A new EnginesRoot is always created when ActivateGame is called
  31. // so all event emitters and handlers must be re-registered.
  32. EventManager.RegisterEngines(enginesRoot);
  33. Logging.Log("Dispatching Game Activated event");
  34. EventManager.GetEventEmitter("GamecraftModdingAPIGameActivatedEventEmitter").Emit();
  35. if (IsGameSwitching)
  36. {
  37. IsGameSwitching = false;
  38. Logging.Log("Dispatching Game Switched To event");
  39. EventManager.GetEventEmitter("GamecraftModdingAPIGameSwitchedToEventEmitter").Emit();
  40. }
  41. if (IsGameReloading)
  42. {
  43. IsGameReloading = false;
  44. Logging.Log("Dispatching Game Reloaded event");
  45. EventManager.GetEventEmitter("GamecraftModdingAPIGameReloadedEventEmitter").Emit();
  46. }
  47. }
  48. public static MethodBase TargetMethod()
  49. {
  50. return typeof(MainGameCompositionRoot).GetMethods().First(m => m.Name == "Compose")
  51. .MakeGenericMethod(typeof(object));
  52. }
  53. }
  54. }