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.

GameActivatedComposePatch.cs 1.8KB

4 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. }