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.CR.MainGame;
  9. using Svelto.ECS;
  10. using Unity.Entities;
  11. using TechbloxModdingAPI.Utility;
  12. namespace TechbloxModdingAPI.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. // A new EnginesRoot is always created when ActivateGame is called
  28. // so all event emitters and handlers must be re-registered.
  29. EventManager.RegisterEngines(enginesRoot);
  30. Logging.Log("Dispatching Game Activated event");
  31. EventManager.GetEventEmitter("TechbloxModdingAPIGameActivatedEventEmitter").Emit();
  32. if (IsGameSwitching)
  33. {
  34. IsGameSwitching = false;
  35. Logging.Log("Dispatching Game Switched To event");
  36. EventManager.GetEventEmitter("TechbloxModdingAPIGameSwitchedToEventEmitter").Emit();
  37. }
  38. if (IsGameReloading)
  39. {
  40. IsGameReloading = false;
  41. Logging.Log("Dispatching Game Reloaded event");
  42. EventManager.GetEventEmitter("TechbloxModdingAPIGameReloadedEventEmitter").Emit();
  43. }
  44. }
  45. public static MethodBase TargetMethod()
  46. {
  47. return typeof(MainGameCompositionRoot).GetMethods().First(m => m.Name == "Compose")
  48. .MakeGenericMethod(typeof(object));
  49. }
  50. }
  51. }