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;
|
2019-12-16 00:35:59 +00:00
|
|
|
|
|
2020-05-03 19:31:09 +00:00
|
|
|
|
using HarmonyLib;
|
2020-06-03 23:42:13 +00:00
|
|
|
|
using RobocraftX.CR.MainGame;
|
2019-12-14 18:52:24 +00:00
|
|
|
|
using Svelto.ECS;
|
2020-06-03 23:42:13 +00:00
|
|
|
|
using Unity.Entities;
|
2019-12-14 18:52:24 +00:00
|
|
|
|
|
|
|
|
|
using GamecraftModdingAPI.Utility;
|
|
|
|
|
|
|
|
|
|
namespace GamecraftModdingAPI.Events
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Patch of RobocraftX.FullGameCompositionRoot.ActivateGame()
|
|
|
|
|
/// </summary>
|
2020-08-03 02:39:26 +00:00
|
|
|
|
[Obsolete]
|
2020-02-18 18:59:02 +00:00
|
|
|
|
[HarmonyPatch]
|
|
|
|
|
class GameActivatedComposePatch
|
2019-12-14 18:52:24 +00:00
|
|
|
|
{
|
2020-02-18 18:59:02 +00:00
|
|
|
|
public static bool IsGameSwitching = false;
|
|
|
|
|
|
|
|
|
|
public static bool IsGameReloading = false;
|
|
|
|
|
|
2020-06-03 23:42:13 +00:00
|
|
|
|
public static void Postfix(ref object contextHolder, ref EnginesRoot enginesRoot, World physicsWorld)
|
2019-12-14 18:52:24 +00:00
|
|
|
|
{
|
2019-12-16 00:35:59 +00:00
|
|
|
|
// register custom game engines
|
2020-02-18 18:59:02 +00:00
|
|
|
|
GameEngineManager.RegisterEngines(enginesRoot);
|
2020-05-22 01:00:33 +00:00
|
|
|
|
// initialize AsyncUtils
|
|
|
|
|
AsyncUtils.Setup(enginesRoot);
|
2020-06-03 23:42:13 +00:00
|
|
|
|
// A new EnginesRoot is always created when ActivateGame is called
|
2019-12-14 18:52:24 +00:00
|
|
|
|
// so all event emitters and handlers must be re-registered.
|
2020-02-18 18:59:02 +00:00
|
|
|
|
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();
|
2020-02-18 18:59:02 +00:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|