using Game.DataLoader; using HarmonyLib; using Svelto.DataStructures; using Svelto.ECS; namespace CLre_server.API.Engines { public abstract class ServerEnginePreBuild : ICLreEngine { public ServerEnginePreBuild() { MainGameServer_BuildDeprecatedEngines_Patch.beforeBuildEngines.Add(this); } public abstract void Ready(); public IEntitiesDB entitiesDB { get; set; } public IEntityFactory entityFactory { get; set; } public IDataDB dataDB { get; set; } } public abstract class ServerEnginePostBuild : ICLreEngine { public ServerEnginePostBuild() { MainGameServer_BuildDeprecatedEngines_Patch.afterBuildEngines.Add(this); } public abstract void Ready(); public IEntitiesDB entitiesDB { get; set; } public IEntityFactory entityFactory { get; set; } public IDataDB dataDB { get; set; } } [HarmonyPatch(typeof(GameServer.GameFramework.MainGameServer), "BuildDeprecatedEngines")] class MainGameServer_BuildDeprecatedEngines_Patch { internal static FasterList beforeBuildEngines = new FasterList(); internal static FasterList afterBuildEngines = new FasterList(); private delegate IEngine MainGameServer_AddEngine(IEngine engine); [HarmonyPrefix] public static void BeforeMethodCall(GameServer.GameFramework.MainGameServer __instance, IEntityFactory ____entityFactory) { var addEngine = Utility.Reflection.MethodAsDelegate(typeof(GameServer.GameFramework.MainGameServer), "AddEngine", //parameters: new [] {typeof(int), typeof(string)}, instance: __instance); foreach (ICLreEngine e in beforeBuildEngines) { e.entityFactory = ____entityFactory; addEngine(e); } } [HarmonyPostfix] public static void AfterMethodCall(GameServer.GameFramework.MainGameServer __instance, IEntityFactory ____entityFactory) { var addEngine = Utility.Reflection.MethodAsDelegate(typeof(GameServer.GameFramework.MainGameServer), "AddEngine", //parameters: new [] {typeof(int), typeof(string)}, instance: __instance); foreach (ICLreEngine e in afterBuildEngines) { e.entityFactory = ____entityFactory; addEngine(e); } } } }