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.

59 lines
1.8KB

  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;
  9. using Svelto.ECS;
  10. using GamecraftModdingAPI.Utility;
  11. using RobocraftX.CR.MainGame;
  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)
  23. {
  24. // register custom game engines
  25. GameEngineManager.RegisterEngines(enginesRoot);
  26. // initialize AsyncUtils
  27. AsyncUtils.Setup(enginesRoot);
  28. // A new EnginesRoot is always created when ActivateGame is called
  29. // so all event emitters and handlers must be re-registered.
  30. EventManager.RegisterEngines(enginesRoot);
  31. Logging.Log("Dispatching Game Activated event");
  32. EventManager.GetEventEmitter("GamecraftModdingAPIGameActivatedEventEmitter").Emit();
  33. if (IsGameSwitching)
  34. {
  35. IsGameSwitching = false;
  36. Logging.Log("Dispatching Game Switched To event");
  37. EventManager.GetEventEmitter("GamecraftModdingAPIGameSwitchedToEventEmitter").Emit();
  38. }
  39. if (IsGameReloading)
  40. {
  41. IsGameReloading = false;
  42. Logging.Log("Dispatching Game Reloaded event");
  43. EventManager.GetEventEmitter("GamecraftModdingAPIGameReloadedEventEmitter").Emit();
  44. }
  45. }
  46. public static MethodBase TargetMethod()
  47. {
  48. return typeof(MainGameCompositionRoot).GetMethods().First(m => m.Name == "Compose")
  49. .MakeGenericMethod(typeof(object));
  50. }
  51. }
  52. }