|
- using HarmonyLib;
- using Svelto.DataStructures;
- using Svelto.ECS;
-
- namespace CLre.API.Engines
- {
- public abstract class GameObsoleteEnginePreBuild : ICLreEngine
- {
- public GameObsoleteEnginePreBuild()
- {
- MainLevel_BuildDeprecatedEngines_Patch.beforeBuildEngines.Add(this);
- }
-
- public abstract void Ready();
- public abstract IEntitiesDB entitiesDB { get; set; }
- public abstract IEntityFactory entityFactory { get; set; }
- }
-
- public abstract class GameObsoleteEnginePostBuild : ICLreEngine
- {
- public GameObsoleteEnginePostBuild()
- {
- MainLevel_BuildDeprecatedEngines_Patch.afterBuildEngines.Add(this);
- }
-
- public abstract void Ready();
- public abstract IEntitiesDB entitiesDB { get; set; }
- public abstract IEntityFactory entityFactory { get; set; }
- }
-
- [HarmonyPatch(typeof(GameFramework.MainLevel), "BuildDeprecatedEngines")]
- class MainLevel_BuildDeprecatedEngines_Patch
- {
- internal static FasterList<GameObsoleteEnginePreBuild> beforeBuildEngines = new FasterList<GameObsoleteEnginePreBuild>();
-
- internal static FasterList<GameObsoleteEnginePostBuild> afterBuildEngines = new FasterList<GameObsoleteEnginePostBuild>();
-
- [HarmonyPrefix]
- public static void BeforeMethodCall(GameFramework.MainLevel __instance)
- {
- IEntityFactory factory = AccessTools.Field(typeof(GameFramework.MainLevel), "_entityFactory").GetValue(__instance) as IEntityFactory;
- foreach (ICLreEngine e in beforeBuildEngines)
- {
- e.entityFactory = factory;
- __instance.AddEngine(e);
- }
- }
-
- [HarmonyPostfix]
- public static void AfterMethodCall(GameFramework.MainLevel __instance)
- {
- IEntityFactory factory = AccessTools.Field(typeof(GameFramework.MainLevel), "_entityFactory").GetValue(__instance) as IEntityFactory;
- foreach (ICLreEngine e in afterBuildEngines)
- {
- e.entityFactory = factory;
- __instance.AddEngine(e);
- }
- }
- }
- }
|