TechbloxModdingAPI/TechbloxModdingAPI/Engines/EnginePatches.cs

78 lines
2.2 KiB
C#

using System.Reflection;
using HarmonyLib;
using RobocraftX;
using RobocraftX.CR.MainGame;
using RobocraftX.FrontEnd;
using RobocraftX.StateSync;
using Svelto.ECS;
using Svelto.ECS.Schedulers;
using TechbloxModdingAPI.Commands;
using TechbloxModdingAPI.Utility;
namespace TechbloxModdingAPI.Engines
{
[HarmonyPatch]
static class GameLoadedTimeStoppedEnginePatch
{
public static EntitiesSubmissionScheduler Scheduler { get; private set; }
public static void Postfix(StateSyncRegistrationHelper stateSyncReg)
{
// register all game engines, including deterministic
GameEngineManager.RegisterEngines(stateSyncReg);
Scheduler = stateSyncReg.enginesRoot.scheduler;
// register command engines
/*CommandLineCompositionRoot.Compose(contextHolder, stateSyncReg.enginesRoot, reloadGame, multiplayerParameters,
stateSyncReg); - uREPL C# compilation not supported anymore */
CommandManager.RegisterEngines(stateSyncReg.enginesRoot);
}
public static MethodBase TargetMethod()
{
return AccessTools.Method(typeof(MainGameCompositionRoot), "DeterministicTimeStoppedCompose").MakeGenericMethod(typeof(object));
}
}
[HarmonyPatch]
static class GameLoadedTimeRunningEnginePatch
{
public static EntitiesSubmissionScheduler Scheduler { get; private set; }
public static void Postfix(StateSyncRegistrationHelper stateSyncReg)
{
GameLoadedTimeStoppedEnginePatch.Postfix(stateSyncReg);
}
public static MethodBase TargetMethod()
{
return AccessTools.Method(typeof(MainGameCompositionRoot), "DeterministicTimeRunningCompose").MakeGenericMethod(typeof(object));
}
}
[HarmonyPatch]
class MenuLoadedEnginePatch
{
public static void Postfix(EnginesRoot enginesRoot)
{
// register menu engines
MenuEngineManager.RegisterEngines(enginesRoot);
}
public static MethodBase TargetMethod()
{
return AccessTools.Method(typeof(FrontEndCompositionRoot), "Compose").MakeGenericMethod(typeof(object));
}
}
[HarmonyPatch]
class FullGameCreatedEnginePatch
{
public static void Postfix(FullGameCompositionRoot __instance)
{
FullGameFields.Init(__instance);
}
public static MethodBase TargetMethod()
{
return AccessTools.DeclaredConstructor(typeof(FullGameCompositionRoot));
}
}
}