Constantly set the collision filter
Something is resetting it
This commit is contained in:
parent
2b0cec100e
commit
5a24074fef
1 changed files with 53 additions and 12 deletions
|
@ -1,9 +1,11 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
|
using System.Reflection;
|
||||||
using GamecraftModdingAPI;
|
using GamecraftModdingAPI;
|
||||||
using GamecraftModdingAPI.Engines;
|
using GamecraftModdingAPI.Engines;
|
||||||
using GamecraftModdingAPI.Players;
|
using GamecraftModdingAPI.Players;
|
||||||
using GamecraftModdingAPI.Utility;
|
using GamecraftModdingAPI.Utility;
|
||||||
|
using HarmonyLib;
|
||||||
using RobocraftX.Character;
|
using RobocraftX.Character;
|
||||||
using RobocraftX.Character.Camera;
|
using RobocraftX.Character.Camera;
|
||||||
using RobocraftX.Character.Factories;
|
using RobocraftX.Character.Factories;
|
||||||
|
@ -32,14 +34,14 @@ namespace BuildingTools
|
||||||
};
|
};
|
||||||
|
|
||||||
private EntityManager _entityManager;
|
private EntityManager _entityManager;
|
||||||
private CollisionFilter _oldCollider;
|
private CollisionFilter _oldFilter;
|
||||||
private bool _enabled;
|
private bool _enabled;
|
||||||
|
|
||||||
private void Enable()
|
private void Enable()
|
||||||
{
|
{
|
||||||
if (_entityManager == default) _entityManager = FullGameFields._physicsWorld.EntityManager;
|
if (_entityManager == default) _entityManager = FullGameFields._physicsWorld.EntityManager;
|
||||||
Logging.CommandLog("Enabling noclip");
|
Logging.CommandLog("Enabling noclip");
|
||||||
_oldCollider = ChangeCollider(_collisionFilter, null);
|
_oldFilter = ChangeCollider(_collisionFilter);
|
||||||
OnUpdate().RunOn(GamecraftModdingAPI.Tasks.Scheduler.extraLeanRunner);
|
OnUpdate().RunOn(GamecraftModdingAPI.Tasks.Scheduler.extraLeanRunner);
|
||||||
_enabled = true;
|
_enabled = true;
|
||||||
Logging.CommandLog("Noclip enabled");
|
Logging.CommandLog("Noclip enabled");
|
||||||
|
@ -48,7 +50,7 @@ namespace BuildingTools
|
||||||
private void Disable()
|
private void Disable()
|
||||||
{
|
{
|
||||||
Logging.CommandLog("Disabling noclip");
|
Logging.CommandLog("Disabling noclip");
|
||||||
ChangeCollider(null, _oldCollider); //Dispose old (cloned) collider
|
ChangeCollider(_oldFilter);
|
||||||
_enabled = false;
|
_enabled = false;
|
||||||
Logging.CommandLog("Noclip disabled");
|
Logging.CommandLog("Noclip disabled");
|
||||||
}
|
}
|
||||||
|
@ -65,6 +67,7 @@ namespace BuildingTools
|
||||||
while (_enabled)
|
while (_enabled)
|
||||||
{
|
{
|
||||||
EnsureFlying();
|
EnsureFlying();
|
||||||
|
ChangeCollider(_collisionFilter);
|
||||||
if (!entitiesDB.Exists<LocalInputEntityStruct>(0U, CommonExclusiveGroups.GameStateGroup))
|
if (!entitiesDB.Exists<LocalInputEntityStruct>(0U, CommonExclusiveGroups.GameStateGroup))
|
||||||
{
|
{
|
||||||
//Disable();
|
//Disable();
|
||||||
|
@ -75,7 +78,8 @@ namespace BuildingTools
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private CollisionFilter ChangeCollider(CollisionFilter? newFilter, CollisionFilter? newCollider)
|
//private BlobAssetReference<Collider> ChangeCollider(CollisionFilter? newFilter, BlobAssetReference<Collider>? newCollider)
|
||||||
|
private CollisionFilter ChangeCollider(CollisionFilter newFilter)
|
||||||
{
|
{
|
||||||
foreach (var group in CharacterExclusiveGroups.AllCharacters)
|
foreach (var group in CharacterExclusiveGroups.AllCharacters)
|
||||||
{
|
{
|
||||||
|
@ -89,31 +93,53 @@ namespace BuildingTools
|
||||||
var collider = _entityManager.GetComponentData<PhysicsCollider>(uecsEntity.uecsEntity);
|
var collider = _entityManager.GetComponentData<PhysicsCollider>(uecsEntity.uecsEntity);
|
||||||
//var collider = _entityManager.GetComponentData<CharacterEnvironmentCollision>(uecsEntity.uecsEntity);
|
//var collider = _entityManager.GetComponentData<CharacterEnvironmentCollision>(uecsEntity.uecsEntity);
|
||||||
//Console.WriteLine("Collider: " + collider.sphereCollider.Value.Filter.BelongsTo);
|
//Console.WriteLine("Collider: " + collider.sphereCollider.Value.Filter.BelongsTo);
|
||||||
unsafe
|
/*unsafe
|
||||||
{
|
{
|
||||||
Console.WriteLine("Collider ptr: " + (long) collider.ColliderPtr);
|
Console.WriteLine("Collider ptr: " + (long) collider.ColliderPtr);
|
||||||
}
|
}
|
||||||
|
|
||||||
var oldCollider = collider.Value.Value.Filter;
|
Console.WriteLine("Old filter: " + collider.Value.Value.Filter.BelongsTo);
|
||||||
|
|
||||||
|
Console.WriteLine("Collider type: " + collider.Value.Value.Type);
|
||||||
|
|
||||||
|
var oldCollider = collider.Value;
|
||||||
if (newFilter.HasValue)
|
if (newFilter.HasValue)
|
||||||
{
|
{
|
||||||
unsafe
|
unsafe
|
||||||
{
|
{
|
||||||
//var colRef = ColliderUtilityUECS.ClonePhysicsCollider(collider.ColliderPtr, newFilter.Value);
|
var colRef = ColliderUtilityUECS.ClonePhysicsCollider(collider.ColliderPtr, newFilter.Value);
|
||||||
//collider.Value = colRef;
|
collider.Value = colRef;
|
||||||
collider.Value.Value.Filter = newFilter.Value;
|
//collider.Value.Value.Filter = newFilter.Value;
|
||||||
Console.WriteLine("New collider: " + (long) collider.ColliderPtr);
|
Console.WriteLine("New filter: " + collider.Value.Value.Filter.BelongsTo);
|
||||||
|
Console.WriteLine("Should be: " + newFilter.Value.BelongsTo);
|
||||||
|
Console.WriteLine("New collider ptr: " + (long) collider.ColliderPtr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (newCollider.HasValue)
|
else if (newCollider.HasValue)
|
||||||
collider.Value.Value.Filter = newCollider.Value;
|
collider.Value = newCollider.Value;
|
||||||
|
|
||||||
//Console.WriteLine("New collider: " + collider.sphereCollider.Value.Filter.BelongsTo);
|
//Console.WriteLine("New collider: " + collider.sphereCollider.Value.Filter.BelongsTo);
|
||||||
_entityManager.SetComponentData(uecsEntity.uecsEntity, collider);
|
_entityManager.SetComponentData(uecsEntity.uecsEntity, collider);
|
||||||
Console.WriteLine("Resulting filter: " + _entityManager
|
Console.WriteLine("Resulting filter: " + _entityManager
|
||||||
.GetComponentData<PhysicsCollider>(uecsEntity.uecsEntity).Value.Value.Filter
|
.GetComponentData<PhysicsCollider>(uecsEntity.uecsEntity).Value.Value.Filter
|
||||||
.BelongsTo);
|
.BelongsTo);
|
||||||
return oldCollider;
|
unsafe
|
||||||
|
{
|
||||||
|
Console.WriteLine("Resulting collider ptr: " + (long) _entityManager
|
||||||
|
.GetComponentData<PhysicsCollider>(uecsEntity.uecsEntity).ColliderPtr);
|
||||||
|
}
|
||||||
|
|
||||||
|
return oldCollider;*/
|
||||||
|
|
||||||
|
unsafe
|
||||||
|
{
|
||||||
|
var coll = (CompoundCollider*) collider.Value.GetUnsafePtr();
|
||||||
|
var filter = coll->Filter;
|
||||||
|
coll->Filter = newFilter;
|
||||||
|
Console.WriteLine("Changed filter from " + filter.BelongsTo + " to " + newFilter.BelongsTo);
|
||||||
|
//_entityManager.SetComponentData(uecsEntity.uecsEntity, collider);
|
||||||
|
return filter;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new InvalidOperationException("No character physics found!");
|
throw new InvalidOperationException("No character physics found!");
|
||||||
|
@ -128,6 +154,7 @@ namespace BuildingTools
|
||||||
|
|
||||||
public void Ready()
|
public void Ready()
|
||||||
{
|
{
|
||||||
|
new Harmony("BuildingTools").PatchAll(Assembly.GetExecutingAssembly());
|
||||||
}
|
}
|
||||||
|
|
||||||
public EntitiesDB entitiesDB { get; set; }
|
public EntitiesDB entitiesDB { get; set; }
|
||||||
|
@ -137,5 +164,19 @@ namespace BuildingTools
|
||||||
|
|
||||||
public string Name { get; } = "BuildingToolsNoClipEngine";
|
public string Name { get; } = "BuildingToolsNoClipEngine";
|
||||||
public bool isRemovable { get; } = true;
|
public bool isRemovable { get; } = true;
|
||||||
|
|
||||||
|
[HarmonyPatch]
|
||||||
|
public static class Patch
|
||||||
|
{
|
||||||
|
public static void Prefix(CompoundCollider __instance, CollisionFilter value)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Compound collider filter changed for " + __instance.Type + " to " + value.BelongsTo);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MethodBase TargetMethod()
|
||||||
|
{
|
||||||
|
return typeof(CompoundCollider).GetProperty("Filter").SetMethod;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue