Unofficial CardLife revival project, pronounced like "celery"
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
2.0KB

  1. using Game.DataLoader;
  2. using HarmonyLib;
  3. using Svelto.DataStructures;
  4. using Svelto.ECS;
  5. namespace CLre_server.API.Engines
  6. {
  7. public abstract class ServerEnginePreBuild : ICLreEngine
  8. {
  9. public ServerEnginePreBuild()
  10. {
  11. MainGameServer_BuildDeprecatedEngines_Patch.beforeBuildEngines.Add(this);
  12. }
  13. public abstract void Ready();
  14. public abstract IEntitiesDB entitiesDB { get; set; }
  15. public abstract IEntityFactory entityFactory { get; set; }
  16. public IDataDB dataDB { get; set; }
  17. }
  18. public abstract class ServerEnginePostBuild : ICLreEngine
  19. {
  20. public ServerEnginePostBuild()
  21. {
  22. MainGameServer_BuildDeprecatedEngines_Patch.afterBuildEngines.Add(this);
  23. }
  24. public abstract void Ready();
  25. public abstract IEntitiesDB entitiesDB { get; set; }
  26. public abstract IEntityFactory entityFactory { get; set; }
  27. public IDataDB dataDB { get; set; }
  28. }
  29. [HarmonyPatch(typeof(GameServer.GameFramework.MainGameServer), "BuildDeprecatedEngines")]
  30. class MainGameServer_BuildDeprecatedEngines_Patch
  31. {
  32. internal static FasterList<ICLreEngine> beforeBuildEngines = new FasterList<ICLreEngine>();
  33. internal static FasterList<ICLreEngine> afterBuildEngines = new FasterList<ICLreEngine>();
  34. [HarmonyPrefix]
  35. public static void BeforeMethodCall(GameServer.GameFramework.MainGameServer __instance, IEntityFactory ____entityFactory)
  36. {
  37. foreach (ICLreEngine e in beforeBuildEngines)
  38. {
  39. e.entityFactory = ____entityFactory;
  40. __instance.AddEngine(e);
  41. }
  42. }
  43. [HarmonyPostfix]
  44. public static void AfterMethodCall(GameServer.GameFramework.MainGameServer __instance, IEntityFactory ____entityFactory)
  45. {
  46. foreach (ICLreEngine e in afterBuildEngines)
  47. {
  48. e.entityFactory = ____entityFactory;
  49. __instance.AddEngine(e);
  50. }
  51. }
  52. }
  53. }