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.

60 lines
2.1KB

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