2020-06-03 23:42:13 +00:00
|
|
|
|
using System.Reflection;
|
|
|
|
|
|
|
|
|
|
using HarmonyLib;
|
|
|
|
|
using RobocraftX.Common;
|
|
|
|
|
using RobocraftX.UECS;
|
|
|
|
|
using Svelto.ECS;
|
|
|
|
|
using Unity.Entities;
|
|
|
|
|
|
|
|
|
|
using GamecraftModdingAPI.Engines;
|
|
|
|
|
using GamecraftModdingAPI.Utility;
|
|
|
|
|
|
|
|
|
|
namespace GamecraftModdingAPI.Blocks
|
|
|
|
|
{
|
|
|
|
|
public class ScalingEngine : IApiEngine
|
|
|
|
|
{
|
|
|
|
|
private static IReactOnAddAndRemove<UECSPhysicsEntityCreationStruct> physicsEngine;
|
|
|
|
|
|
|
|
|
|
public void Ready()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public EntitiesDB entitiesDB { get; set; }
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Name { get; } = "GamecraftModdingAPIScalingEngine";
|
|
|
|
|
public bool isRemovable { get; } = false;
|
|
|
|
|
|
2020-10-01 23:54:59 +00:00
|
|
|
|
private EntityManager _entityManager; //Unity entity manager
|
2020-06-03 23:42:13 +00:00
|
|
|
|
|
|
|
|
|
public void UpdateCollision(EGID egid)
|
|
|
|
|
{
|
2020-10-01 23:54:59 +00:00
|
|
|
|
if (_entityManager == default)
|
|
|
|
|
_entityManager = FullGameFields._physicsWorld.EntityManager;
|
2020-06-03 23:42:13 +00:00
|
|
|
|
//Assuming the block exists
|
|
|
|
|
var entity = entitiesDB.QueryEntity<UECSPhysicsEntityStruct>(egid).uecsEntity;
|
|
|
|
|
var pes = new UECSPhysicsEntityCreationStruct();
|
|
|
|
|
physicsEngine.Add(ref pes, egid); //Create new UECS entity
|
|
|
|
|
_entityManager.DestroyEntity(entity);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HarmonyPatch]
|
|
|
|
|
public class PhysicsEnginePatch
|
|
|
|
|
{
|
|
|
|
|
static void Postfix(IReactOnAddAndRemove<UECSPhysicsEntityCreationStruct> __instance)
|
|
|
|
|
{
|
|
|
|
|
physicsEngine = __instance;
|
|
|
|
|
Logging.MetaDebugLog("Physics engine injected.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static MethodBase TargetMethod(Harmony instance)
|
|
|
|
|
{
|
|
|
|
|
return AccessTools.Method("RobocraftX.StateSync.HandleUECSPhysicEntitiesWithPrefabCreationEngine" +
|
|
|
|
|
":Ready");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|