Tools for building games mainly focused on changing block properties. And noclip.
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.

110 lines
3.4KB

  1. using System;
  2. using System.Collections;
  3. using TechbloxModdingAPI;
  4. using TechbloxModdingAPI.Engines;
  5. using TechbloxModdingAPI.Utility;
  6. using RobocraftX.Character;
  7. using RobocraftX.Common;
  8. using RobocraftX.Common.Input;
  9. using RobocraftX.UECS;
  10. using Svelto.ECS;
  11. using Svelto.Tasks.ExtraLean;
  12. using Unity.Entities;
  13. using Unity.Physics;
  14. using Yield = Svelto.Tasks.Yield;
  15. namespace BuildingTools
  16. {
  17. public class NoClipCommand : IApiEngine
  18. {
  19. private readonly CollisionFilter _collisionFilter = new CollisionFilter
  20. { //AddCollidersToRigidBodyEngineUECS._simCubeNoCollisionFilter
  21. BelongsTo = 0,
  22. CollidesWith = 239532
  23. };
  24. private EntityManager _entityManager;
  25. private CollisionFilter _oldFilter;
  26. private bool _enabled;
  27. private void Enable()
  28. {
  29. if (_entityManager == default) _entityManager = FullGameFields._physicsWorld.EntityManager;
  30. Logging.CommandLog("Enabling noclip");
  31. _oldFilter = ChangeCollider(_collisionFilter);
  32. OnUpdate().RunOn(TechbloxModdingAPI.Tasks.Scheduler.extraLeanRunner);
  33. _enabled = true;
  34. Logging.CommandLog("Noclip enabled");
  35. }
  36. private void Disable()
  37. {
  38. Logging.CommandLog("Disabling noclip");
  39. ChangeCollider(_oldFilter);
  40. _enabled = false;
  41. Logging.CommandLog("Noclip disabled");
  42. }
  43. public void Toggle()
  44. {
  45. if (!_enabled) Enable();
  46. else Disable();
  47. }
  48. private IEnumerator OnUpdate()
  49. { //ScreenshotTakerCompositionRoot
  50. while (_enabled)
  51. {
  52. EnsureFlying();
  53. ChangeCollider(_collisionFilter);
  54. if (!entitiesDB.Exists<LocalInputEntityStruct>(0U, CommonExclusiveGroups.GameStateGroup))
  55. {
  56. yield break;
  57. }
  58. yield return Yield.It;
  59. }
  60. }
  61. private CollisionFilter ChangeCollider(CollisionFilter newFilter)
  62. {
  63. foreach (var group in CharacterExclusiveGroups.AllCharacters)
  64. {
  65. if (!entitiesDB.Exists<UECSPhysicsEntityStruct>(new EGID(Player.LocalPlayer.Id, group)))
  66. continue;
  67. ref var uecsEntity =
  68. ref entitiesDB.QueryEntity<UECSPhysicsEntityStruct>(new EGID(Player.LocalPlayer.Id, group));
  69. var collider = _entityManager.GetComponentData<PhysicsCollider>(uecsEntity.uecsEntity);
  70. unsafe
  71. {
  72. var coll = (CompoundCollider*) collider.Value.GetUnsafePtr();
  73. var filter = coll->Filter;
  74. coll->Filter = newFilter;
  75. return filter;
  76. }
  77. }
  78. throw new InvalidOperationException("No character physics found!");
  79. }
  80. private void EnsureFlying()
  81. {
  82. /*foreach (var ((coll, count), _) in entitiesDB.QueryEntities<CharacterMovementEntityStruct>(CharacterExclusiveGroups.AllCharacters))
  83. for (int i = 0; i < count; i++)
  84. coll[i].moveState = MovementState.Flying;*/
  85. }
  86. public void Ready()
  87. {
  88. }
  89. public EntitiesDB entitiesDB { get; set; }
  90. public void Dispose()
  91. {
  92. }
  93. public string Name { get; } = "BuildingToolsNoClipEngine";
  94. public bool isRemovable { get; } = true;
  95. }
  96. }