using System.Reflection; using Gamecraft.Blocks.BlockGroups; using Gamecraft.GUI.Blueprints; using GamecraftModdingAPI.Engines; using HarmonyLib; using RobocraftX.Blocks; using Svelto.DataStructures; using Svelto.ECS; using Svelto.ECS.DataStructures; using Unity.Collections; namespace GamecraftModdingAPI.Blocks { public class BlueprintEngine : IApiEngine { private readonly MethodInfo getBlocksFromGroup = AccessTools.Method("RobocraftX.CR.MachineEditing.PlaceBlockUtility:GetBlocksSharingBlockgroup"); private readonly NativeDynamicArray selectedBlocksInGroup = new NativeDynamicArray(); private readonly NativeHashSet removedConnections = new NativeHashSet(); private static NativeEntityRemove nativeRemove; private static MachineGraphConnectionEntityFactory connectionFactory; public void Ready() { } public EntitiesDB entitiesDB { get; set; } public void Dispose() { } public Block[] GetBlocksFromGroup(EGID blockID) { var list = new FasterList(); object blockPos = null, blockRot = null; getBlocksFromGroup.Invoke(null, new[] {blockID, selectedBlocksInGroup, entitiesDB, blockPos, blockRot}); for (uint i = 0; i < selectedBlocksInGroup.Count(); i++) list.Add(new Block(selectedBlocksInGroup.Get(i))); selectedBlocksInGroup.FastClear(); return list.ToArray(); } public void RemoveBlockGroup(int id) { BlockGroupUtility.RemoveAllBlocksInBlockGroup(id, entitiesDB, removedConnections, nativeRemove, connectionFactory, default).Complete(); } public void SelectBlueprint(uint resourceID) { BlueprintUtil.SelectBlueprint(null, new BlueprintInventoryItemEntityStruct { blueprintResourceId = resourceID, }); } public string Name { get; } = "GamecraftModdingAPIBlueprintGameEngine"; public bool isRemovable { get; } [HarmonyPatch] private static class RemoveEnginePatch { public static void Prefix(IEntityFunctions entityFunctions, MachineGraphConnectionEntityFactory machineGraphConnectionEntityFactory) { nativeRemove = entityFunctions.ToNativeRemove("GCAPI" + nameof(BlueprintEngine)); connectionFactory = machineGraphConnectionEntityFactory; } public static MethodBase TargetMethod() { return AccessTools.Constructor(AccessTools.TypeByName("RobocraftX.CR.MachineEditing.RemoveBlockEngine")); } } } }