TechbloxModdingAPI/GamecraftModdingAPI/Events/GameActivatedComposePatch.cs

59 lines
1.8 KiB
C#
Raw Normal View History

2019-12-14 18:52:24 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
2020-02-08 21:05:16 +00:00
using System.Reflection;
2019-12-14 18:52:24 +00:00
using System.Text;
using System.Threading.Tasks;
2020-05-03 19:31:09 +00:00
using HarmonyLib;
2019-12-14 18:52:24 +00:00
using RobocraftX;
using Svelto.ECS;
using GamecraftModdingAPI.Utility;
2020-02-08 21:05:16 +00:00
using RobocraftX.CR.MainGame;
2019-12-14 18:52:24 +00:00
namespace GamecraftModdingAPI.Events
{
/// <summary>
/// Patch of RobocraftX.FullGameCompositionRoot.ActivateGame()
/// </summary>
[HarmonyPatch]
class GameActivatedComposePatch
2019-12-14 18:52:24 +00:00
{
public static bool IsGameSwitching = false;
public static bool IsGameReloading = false;
2020-02-23 22:02:11 +00:00
public static void Postfix(ref object contextHolder, ref EnginesRoot enginesRoot)
2019-12-14 18:52:24 +00:00
{
// register custom game engines
GameEngineManager.RegisterEngines(enginesRoot);
// initialize AsyncUtils
AsyncUtils.Setup(enginesRoot);
2019-12-14 18:52:24 +00:00
// A new EnginesRoot is always created when ActivateGame is called
// so all event emitters and handlers must be re-registered.
EventManager.RegisterEngines(enginesRoot);
2019-12-14 18:52:24 +00:00
Logging.Log("Dispatching Game Activated event");
2019-12-15 07:20:20 +00:00
EventManager.GetEventEmitter("GamecraftModdingAPIGameActivatedEventEmitter").Emit();
if (IsGameSwitching)
{
IsGameSwitching = false;
Logging.Log("Dispatching Game Switched To event");
EventManager.GetEventEmitter("GamecraftModdingAPIGameSwitchedToEventEmitter").Emit();
}
if (IsGameReloading)
{
IsGameReloading = false;
Logging.Log("Dispatching Game Reloaded event");
EventManager.GetEventEmitter("GamecraftModdingAPIGameReloadedEventEmitter").Emit();
}
2019-12-14 18:52:24 +00:00
}
2020-02-08 21:05:16 +00:00
public static MethodBase TargetMethod()
{
return typeof(MainGameCompositionRoot).GetMethods().First(m => m.Name == "Compose")
.MakeGenericMethod(typeof(object));
}
2019-12-14 18:52:24 +00:00
}
}