diff --git a/GamecraftModdingAPI/Events/DeterministicStepComposeEngineGroupsPatch.cs b/GamecraftModdingAPI/Events/DeterministicStepComposeEngineGroupsPatch.cs
new file mode 100644
index 0000000..b880257
--- /dev/null
+++ b/GamecraftModdingAPI/Events/DeterministicStepComposeEngineGroupsPatch.cs
@@ -0,0 +1,40 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Text;
+using System.Threading.Tasks;
+
+using Harmony;
+using Svelto.ECS;
+using RobocraftX.StateSync;
+
+using GamecraftModdingAPI.Utility;
+
+namespace GamecraftModdingAPI.Events
+{
+ ///
+ /// Patch of RobocraftX.StateSync.DeterministicStepCompositionRoot.ComposeEnginesGroups(...)
+ ///
+ [HarmonyPatch(typeof(DeterministicStepCompositionRoot), "ComposeEnginesGroups")]
+ //[HarmonyPatch]
+ class DeterministicStepComposeEngineGroupsPatch
+ {
+
+ public static readonly GameStateBuildEmitterEngine buildEngine = new GameStateBuildEmitterEngine();
+
+ public static readonly GameStateSimulationEmitterEngine simEngine = new GameStateSimulationEmitterEngine();
+
+ public static void Prefix(ref StateSyncRegistrationHelper stateSyncReg)
+ {
+ stateSyncReg.buildModeInitializationEngines.Add(buildEngine);
+ stateSyncReg.simulationModeInitializationEngines.Add(simEngine);
+ }
+
+ public static MethodBase NopeTargetMethod()
+ {
+ return typeof(DeterministicStepCompositionRoot).GetMethods().First(m => m.Name == "ComposeEnginesGroups")
+ .MakeGenericMethod(typeof(object));
+ }
+ }
+}
diff --git a/GamecraftModdingAPI/Events/EventType.cs b/GamecraftModdingAPI/Events/EventType.cs
index 7383da2..468e214 100644
--- a/GamecraftModdingAPI/Events/EventType.cs
+++ b/GamecraftModdingAPI/Events/EventType.cs
@@ -17,6 +17,8 @@ namespace GamecraftModdingAPI.Events
MenuSwitchedTo,
Game,
GameReloaded,
- GameSwitchedTo
+ GameSwitchedTo,
+ SimulationSwitchedTo,
+ BuildSwitchedTo
}
}
diff --git a/GamecraftModdingAPI/Events/GameStateBuildEmitterEngine.cs b/GamecraftModdingAPI/Events/GameStateBuildEmitterEngine.cs
new file mode 100644
index 0000000..c9b267e
--- /dev/null
+++ b/GamecraftModdingAPI/Events/GameStateBuildEmitterEngine.cs
@@ -0,0 +1,44 @@
+using System;
+
+using Unity.Jobs;
+using RobocraftX.StateSync;
+using Svelto.ECS;
+
+using GamecraftModdingAPI.Utility;
+
+namespace GamecraftModdingAPI.Events
+{
+ ///
+ /// Event emitter engine for switching to to build mode.
+ ///
+ public class GameStateBuildEmitterEngine : IEventEmitterEngine, IInitializeOnBuildStart
+ {
+ public string Name { get; } = "GamecraftModdingAPIGameStateBuildEventEmitter" ;
+
+ public IEntitiesDB entitiesDB { set; private get; }
+
+ public object type { get; } = EventType.BuildSwitchedTo;
+
+ public bool isRemovable { get; } = false;
+
+ public IEntityFactory Factory { set; private get; }
+
+ public void Dispose() { }
+
+ public void Emit()
+ {
+ Logging.Log("Dispatching Build Switched To event");
+ if (Factory == null) { return; }
+ Factory.BuildEntity(ApiExclusiveGroups.eventID++, ApiExclusiveGroups.eventsExclusiveGroup)
+ .Init(new ModEventEntityStruct { type = type });
+ }
+
+ public JobHandle OnInitializeBuildMode()
+ {
+ Emit();
+ return default(JobHandle);
+ }
+
+ public void Ready() { }
+ }
+}
diff --git a/GamecraftModdingAPI/Events/GameStateSimulationEmitterEngine.cs b/GamecraftModdingAPI/Events/GameStateSimulationEmitterEngine.cs
new file mode 100644
index 0000000..7427dd0
--- /dev/null
+++ b/GamecraftModdingAPI/Events/GameStateSimulationEmitterEngine.cs
@@ -0,0 +1,44 @@
+using System;
+
+using Unity.Jobs;
+using RobocraftX.StateSync;
+using Svelto.ECS;
+
+using GamecraftModdingAPI.Utility;
+
+namespace GamecraftModdingAPI.Events
+{
+ ///
+ /// Event emitter engine for switching to simulation mode.
+ ///
+ public class GameStateSimulationEmitterEngine : IEventEmitterEngine, IInitializeOnSimulationStart
+ {
+ public string Name { get; } = "GamecraftModdingAPIGameStateSimulationEventEmitter" ;
+
+ public IEntitiesDB entitiesDB { set; private get; }
+
+ public object type { get; } = EventType.SimulationSwitchedTo;
+
+ public bool isRemovable { get; } = false;
+
+ public IEntityFactory Factory { set; private get; }
+
+ public void Dispose() { }
+
+ public void Emit()
+ {
+ Logging.Log("Dispatching Simulation Switched To event");
+ if (Factory == null) { return; }
+ Factory.BuildEntity(ApiExclusiveGroups.eventID++, ApiExclusiveGroups.eventsExclusiveGroup)
+ .Init(new ModEventEntityStruct { type = type });
+ }
+
+ public JobHandle OnInitializeSimulationMode()
+ {
+ Emit();
+ return default(JobHandle);
+ }
+
+ public void Ready() { }
+ }
+}
diff --git a/GamecraftModdingAPI/Main.cs b/GamecraftModdingAPI/Main.cs
index 28b4dce..2c51872 100644
--- a/GamecraftModdingAPI/Main.cs
+++ b/GamecraftModdingAPI/Main.cs
@@ -56,6 +56,8 @@ namespace GamecraftModdingAPI
EventManager.AddEventEmitter(new SimpleEventEmitterEngine(EventType.Game, "GamecraftModdingAPIGameActivatedEventEmitter", false));
EventManager.AddEventEmitter(new SimpleEventEmitterEngine(EventType.GameReloaded, "GamecraftModdingAPIGameReloadedEventEmitter", false));
EventManager.AddEventEmitter(new SimpleEventEmitterEngine(EventType.GameSwitchedTo, "GamecraftModdingAPIGameSwitchedToEventEmitter", false));
+ EventManager.AddEventEmitter(DeterministicStepComposeEngineGroupsPatch.buildEngine);
+ EventManager.AddEventEmitter(DeterministicStepComposeEngineGroupsPatch.simEngine);
// init block implementors
Logging.MetaDebugLog($"Initializing Blocks");
Blocks.Movement.Init();
diff --git a/GamecraftModdingAPI/Tests/GamecraftModdingAPIPluginTest.cs b/GamecraftModdingAPI/Tests/GamecraftModdingAPIPluginTest.cs
index 3a47ad9..1d55602 100644
--- a/GamecraftModdingAPI/Tests/GamecraftModdingAPIPluginTest.cs
+++ b/GamecraftModdingAPI/Tests/GamecraftModdingAPIPluginTest.cs
@@ -68,6 +68,10 @@ namespace GamecraftModdingAPI.Tests
EventType.GameReloaded, "gamerel API debug"));
EventManager.AddEventHandler(new SimpleEventHandlerEngine(() => { Logging.Log("Game Switched To event!"); }, () => { },
EventType.GameSwitchedTo, "gameswitch API debug"));
+ EventManager.AddEventHandler(new SimpleEventHandlerEngine(() => { Logging.Log("Game Mode Simulation Switched To event!"); }, () => { },
+ EventType.SimulationSwitchedTo, "simulationswitch API debug"));
+ EventManager.AddEventHandler(new SimpleEventHandlerEngine(() => { Logging.Log("Game Mode Build Switched To event!"); }, () => { },
+ EventType.BuildSwitchedTo, "buildswitch API debug"));
// debug/test commands
if (Dependency.Hell("ExtraCommands"))