using System.Collections.Generic; using System.Linq; using Global.Shared.API; using HarmonyLib; using Sandbox.Game.Entities; using VRage.Game.Entity; using VRageMath; namespace Global.Shared.Patches { [HarmonyPatch(typeof(MyGamePruningStructure))] public class MyGamePruningStructurePatch { private static readonly List _gridQueryStorage = new List(); private static readonly List _queryStorage = new List(); // [HarmonyPatch("GetTopMostEntitiesInBox")] // [HarmonyPrefix] public static bool GetTopMostEntitiesInBox( ref BoundingBoxD box, List result, MyEntityQueryType qtype = MyEntityQueryType.Both) { GetTopMostBox(ref box, result, qtype); return false; } public static void GetTopMostBox(ref BoundingBoxD box, List result, MyEntityQueryType qType) { _queryStorage.Clear(); _gridQueryStorage.Clear(); var gridSearch = GridFlag.None; if (qType.HasDynamic()) gridSearch |= GridFlag.DynamicGrid; if (qType.HasStatic()) gridSearch |= GridFlag.StaticGrid; if (gridSearch != GridFlag.None) GlobalAPI.LocateGrids(_gridQueryStorage, box, gridSearch); result.AddRange(_gridQueryStorage.Select(e => e.CubeGrid)); if (qType.HasDynamic()) GlobalAPI.LocateCharacters(_queryStorage, box, PlayerFlag.Character); result.AddRange(_queryStorage.Select(l => l.Entity.Entity)); } // [HarmonyPatch("GetAllTopMostStaticEntitiesInBox")] // [HarmonyPrefix] public static bool GetAllTopMostStaticEntitiesInBox( ref BoundingBoxD box, List result, MyEntityQueryType qtype = MyEntityQueryType.Both) { GetTopMostBox(ref box, result, qtype); return false; } } }