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.

62 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. [Obsolete]
  18. [HarmonyPatch]
  19. class GameActivatedComposePatch
  20. {
  21. public static bool IsGameSwitching = false;
  22. public static bool IsGameReloading = false;
  23. public static void Postfix(ref object contextHolder, ref EnginesRoot enginesRoot, World physicsWorld)
  24. {
  25. // register custom game engines
  26. GameEngineManager.RegisterEngines(enginesRoot);
  27. // initialize AsyncUtils
  28. AsyncUtils.Setup(enginesRoot);
  29. // initialize Block
  30. Block.Setup(physicsWorld);
  31. // A new EnginesRoot is always created when ActivateGame is called
  32. // so all event emitters and handlers must be re-registered.
  33. EventManager.RegisterEngines(enginesRoot);
  34. Logging.Log("Dispatching Game Activated event");
  35. EventManager.GetEventEmitter("GamecraftModdingAPIGameActivatedEventEmitter").Emit();
  36. if (IsGameSwitching)
  37. {
  38. IsGameSwitching = false;
  39. Logging.Log("Dispatching Game Switched To event");
  40. EventManager.GetEventEmitter("GamecraftModdingAPIGameSwitchedToEventEmitter").Emit();
  41. }
  42. if (IsGameReloading)
  43. {
  44. IsGameReloading = false;
  45. Logging.Log("Dispatching Game Reloaded event");
  46. EventManager.GetEventEmitter("GamecraftModdingAPIGameReloadedEventEmitter").Emit();
  47. }
  48. }
  49. public static MethodBase TargetMethod()
  50. {
  51. return typeof(MainGameCompositionRoot).GetMethods().First(m => m.Name == "Compose")
  52. .MakeGenericMethod(typeof(object));
  53. }
  54. }
  55. }