A stable modding interface between Techblox and mods https://mod.exmods.org/
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.

62 lines
1.7KB

  1. using System.Reflection;
  2. using HarmonyLib;
  3. using RobocraftX.Common;
  4. using RobocraftX.UECS;
  5. using Svelto.ECS;
  6. using Unity.Entities;
  7. using GamecraftModdingAPI.Engines;
  8. using GamecraftModdingAPI.Utility;
  9. namespace GamecraftModdingAPI.Blocks
  10. {
  11. public class ScalingEngine : IApiEngine
  12. {
  13. private static IReactOnAddAndRemove<UECSPhysicsEntityCreationStruct> physicsEngine;
  14. public void Ready()
  15. {
  16. }
  17. public EntitiesDB entitiesDB { get; set; }
  18. public void Dispose()
  19. {
  20. }
  21. public string Name { get; } = "GamecraftModdingAPIScalingEngine";
  22. public bool isRemovable { get; } = false;
  23. private static EntityManager _entityManager; //Unity entity manager
  24. public void UpdateCollision(EGID egid)
  25. {
  26. //Assuming the block exists
  27. var entity = entitiesDB.QueryEntity<UECSPhysicsEntityStruct>(egid).uecsEntity;
  28. var pes = new UECSPhysicsEntityCreationStruct();
  29. physicsEngine.Add(ref pes, egid); //Create new UECS entity
  30. _entityManager.DestroyEntity(entity);
  31. }
  32. internal void Setup(EntityManager entityManager)
  33. {
  34. _entityManager = entityManager;
  35. }
  36. [HarmonyPatch]
  37. public class PhysicsEnginePatch
  38. {
  39. static void Postfix(IReactOnAddAndRemove<UECSPhysicsEntityCreationStruct> __instance)
  40. {
  41. physicsEngine = __instance;
  42. Logging.MetaDebugLog("Physics engine injected.");
  43. }
  44. static MethodBase TargetMethod(Harmony instance)
  45. {
  46. return AccessTools.Method("RobocraftX.StateSync.HandleUECSPhysicEntitiesWithPrefabCreationEngine" +
  47. ":Ready");
  48. }
  49. }
  50. }
  51. }