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.

57 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. // A new EnginesRoot is always created when ActivateGame is called
  27. // so all event emitters and handlers must be re-registered.
  28. EventManager.RegisterEngines(enginesRoot);
  29. Logging.Log("Dispatching Game Activated event");
  30. EventManager.GetEventEmitter("GamecraftModdingAPIGameActivatedEventEmitter").Emit();
  31. if (IsGameSwitching)
  32. {
  33. IsGameSwitching = false;
  34. Logging.Log("Dispatching Game Switched To event");
  35. EventManager.GetEventEmitter("GamecraftModdingAPIGameSwitchedToEventEmitter").Emit();
  36. }
  37. if (IsGameReloading)
  38. {
  39. IsGameReloading = false;
  40. Logging.Log("Dispatching Game Reloaded event");
  41. EventManager.GetEventEmitter("GamecraftModdingAPIGameReloadedEventEmitter").Emit();
  42. }
  43. }
  44. public static MethodBase TargetMethod()
  45. {
  46. return typeof(MainGameCompositionRoot).GetMethods().First(m => m.Name == "Compose")
  47. .MakeGenericMethod(typeof(object));
  48. }
  49. }
  50. }