diff --git a/api/AltV.Net/Alt.Pools.cs b/api/AltV.Net/Alt.Pools.cs new file mode 100644 index 00000000..8b17a2ce --- /dev/null +++ b/api/AltV.Net/Alt.Pools.cs @@ -0,0 +1,104 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using AltV.Net.Elements.Entities; +using AltV.Net.Elements.Pools; + +namespace AltV.Net; + +public partial class Alt +{ + public static void AddToPool(IBaseObject baseObject) => CoreImpl.PoolManager.Add(baseObject); + + public static IReadOnlyCollection GetAllPlayers() => CoreImpl.PoolManager.Player.GetAllEntities(); + + public static IReadOnlyCollection GetAllVehicles() => CoreImpl.PoolManager.Vehicle.GetAllEntities(); + + public static IReadOnlyCollection GetAllPeds() => CoreImpl.PoolManager.Ped.GetAllEntities(); + + public static IReadOnlyCollection GetAllBlips() => CoreImpl.PoolManager.Blip.GetAllObjects(); + + public static IReadOnlyCollection GetAllNetworkObjects() => CoreImpl.PoolManager.Object.GetAllEntities(); + + public static IReadOnlyCollection GetAllCheckpoints() => + CoreImpl.PoolManager.Checkpoint.GetAllObjects(); + + public static IReadOnlyCollection GetAllVoiceChannels() => + CoreImpl.PoolManager.VoiceChannel.GetAllObjects(); + + public static IReadOnlyCollection GetAllColShapes() => CoreImpl.PoolManager.ColShape.GetAllObjects(); + + public static IReadOnlyCollection GetAllMarkers() => CoreImpl.PoolManager.Marker.GetAllObjects(); + + public static IReadOnlyCollection GetAllConnectionInfos() => + CoreImpl.PoolManager.ConnectionInfo.GetAllObjects(); + + public static IReadOnlyCollection GetAllVirtualEntities() => + CoreImpl.PoolManager.VirtualEntity.GetAllObjects(); + + public static IReadOnlyCollection GetAllVirtualEntityGroups() => + CoreImpl.PoolManager.VirtualEntityGroup.GetAllObjects(); + + public static KeyValuePair[] GetPlayersArray() => CoreImpl.PoolManager.Player.GetEntitiesArray(); + + public static KeyValuePair[] GetVehiclesArray() => + CoreImpl.PoolManager.Vehicle.GetEntitiesArray(); + + public static KeyValuePair[] GetPedsArray() => CoreImpl.PoolManager.Ped.GetEntitiesArray(); + + public static KeyValuePair[] GetBlipsArray() => CoreImpl.PoolManager.Blip.GetObjectsArray(); + + public static KeyValuePair[] GetCheckpointsArray() => + CoreImpl.PoolManager.Checkpoint.GetObjectsArray(); + + public static KeyValuePair[] GetVoiceChannelsArray() => + CoreImpl.PoolManager.VoiceChannel.GetObjectsArray(); + + public static KeyValuePair[] GetColShapesArray() => + CoreImpl.PoolManager.ColShape.GetObjectsArray(); + + public static KeyValuePair[] GetConnectionInfoArray() => + CoreImpl.PoolManager.ConnectionInfo.GetObjectsArray(); + + public static void ForEachPlayers(IBaseObjectCallback baseObjectCallback) => + CoreImpl.PoolManager.Player.ForEach(baseObjectCallback); + + public static Task ForEachPlayers(IAsyncBaseObjectCallback baseObjectCallback) => + CoreImpl.PoolManager.Player.ForEach(baseObjectCallback); + + public static void ForEachVehicles(IBaseObjectCallback baseObjectCallback) => + CoreImpl.PoolManager.Vehicle.ForEach(baseObjectCallback); + + public static Task ForEachVehicles(IAsyncBaseObjectCallback baseObjectCallback) => + CoreImpl.PoolManager.Vehicle.ForEach(baseObjectCallback); + + public static void ForEachPeds(IBaseObjectCallback baseObjectCallback) => + CoreImpl.PoolManager.Ped.ForEach(baseObjectCallback); + + public static Task ForEachPeds(IAsyncBaseObjectCallback baseObjectCallback) => + CoreImpl.PoolManager.Ped.ForEach(baseObjectCallback); + + public static void ForEachBlips(IBaseObjectCallback baseObjectCallback) => + CoreImpl.PoolManager.Blip.ForEach(baseObjectCallback); + + public static Task ForEachBlips(IAsyncBaseObjectCallback baseObjectCallback) => + CoreImpl.PoolManager.Blip.ForEach(baseObjectCallback); + + public static void ForEachCheckpoints(IBaseObjectCallback baseObjectCallback) => + CoreImpl.PoolManager.Checkpoint.ForEach(baseObjectCallback); + + public static Task ForEachCheckpoints(IAsyncBaseObjectCallback baseObjectCallback) => + CoreImpl.PoolManager.Checkpoint.ForEach(baseObjectCallback); + + public static void ForEachVoiceChannels(IBaseObjectCallback baseObjectCallback) => + CoreImpl.PoolManager.VoiceChannel.ForEach(baseObjectCallback); + + public static Task ForEachVoiceChannels(IAsyncBaseObjectCallback baseObjectCallback) => + CoreImpl.PoolManager.VoiceChannel.ForEach(baseObjectCallback); + + public static void ForEachColShapes(IBaseObjectCallback baseObjectCallback) => + CoreImpl.PoolManager.ColShape.ForEach(baseObjectCallback); + + public static Task ForEachColShapes(IAsyncBaseObjectCallback baseObjectCallback) => + CoreImpl.PoolManager.ColShape.ForEach(baseObjectCallback); +} \ No newline at end of file diff --git a/api/AltV.Net/Alt.cs b/api/AltV.Net/Alt.cs index a9a2bb4c..a759d89f 100644 --- a/api/AltV.Net/Alt.cs +++ b/api/AltV.Net/Alt.cs @@ -43,87 +43,6 @@ public static void EmitUnreliableClients(IPlayer[] clients, string eventName, pa public static void Log(string message) => CoreImpl.LogInfo(message); - public static IReadOnlyCollection GetAllPlayers() => CoreImpl.PoolManager.Player.GetAllEntities(); - - public static IReadOnlyCollection GetAllVehicles() =>CoreImpl.PoolManager.Vehicle.GetAllEntities(); - - public static IReadOnlyCollection GetAllPeds() =>CoreImpl.PoolManager.Ped.GetAllEntities(); - - public static IReadOnlyCollection GetAllBlips() =>CoreImpl.PoolManager.Blip.GetAllObjects(); - - public static IReadOnlyCollection GetAllNetworkObjects() =>CoreImpl.PoolManager.Object.GetAllEntities(); - - public static IReadOnlyCollection GetAllCheckpoints() =>CoreImpl.PoolManager.Checkpoint.GetAllObjects(); - - public static IReadOnlyCollection GetAllVoiceChannels() =>CoreImpl.PoolManager.VoiceChannel.GetAllObjects(); - - public static IReadOnlyCollection GetAllColShapes() =>CoreImpl.PoolManager.ColShape.GetAllObjects(); - - public static IReadOnlyCollection GetAllMarkers() =>CoreImpl.PoolManager.Marker.GetAllObjects(); - - public static IReadOnlyCollection GetAllConnectionInfos() => CoreImpl.PoolManager.ConnectionInfo.GetAllObjects(); - - public static IReadOnlyCollection GetAllVirtualEntities() => CoreImpl.PoolManager.VirtualEntity.GetAllObjects(); - - public static IReadOnlyCollection GetAllVirtualEntityGroups() => CoreImpl.PoolManager.VirtualEntityGroup.GetAllObjects(); - - public static KeyValuePair[] GetPlayersArray() => CoreImpl.PoolManager.Player.GetEntitiesArray(); - - public static KeyValuePair[] GetVehiclesArray() => CoreImpl.PoolManager.Vehicle.GetEntitiesArray(); - - public static KeyValuePair[] GetPedsArray() => CoreImpl.PoolManager.Ped.GetEntitiesArray(); - - public static KeyValuePair[] GetBlipsArray() => CoreImpl.PoolManager.Blip.GetObjectsArray(); - - public static KeyValuePair[] GetCheckpointsArray() => CoreImpl.PoolManager.Checkpoint.GetObjectsArray(); - - public static KeyValuePair[] GetVoiceChannelsArray() => CoreImpl.PoolManager.VoiceChannel.GetObjectsArray(); - - public static KeyValuePair[] GetColShapesArray() => CoreImpl.PoolManager.ColShape.GetObjectsArray(); - public static KeyValuePair[] GetConnectionInfoArray() => CoreImpl.PoolManager.ConnectionInfo.GetObjectsArray(); - - public static void ForEachPlayers(IBaseObjectCallback baseObjectCallback) => - CoreImpl.PoolManager.Player.ForEach(baseObjectCallback); - - public static Task ForEachPlayers(IAsyncBaseObjectCallback baseObjectCallback) => - CoreImpl.PoolManager.Player.ForEach(baseObjectCallback); - - public static void ForEachVehicles(IBaseObjectCallback baseObjectCallback) => - CoreImpl.PoolManager.Vehicle.ForEach(baseObjectCallback); - - public static Task ForEachVehicles(IAsyncBaseObjectCallback baseObjectCallback) => - CoreImpl.PoolManager.Vehicle.ForEach(baseObjectCallback); - - public static void ForEachPeds(IBaseObjectCallback baseObjectCallback) => - CoreImpl.PoolManager.Ped.ForEach(baseObjectCallback); - - public static Task ForEachPeds(IAsyncBaseObjectCallback baseObjectCallback) => - CoreImpl.PoolManager.Ped.ForEach(baseObjectCallback); - - public static void ForEachBlips(IBaseObjectCallback baseObjectCallback) => - CoreImpl.PoolManager.Blip.ForEach(baseObjectCallback); - - public static Task ForEachBlips(IAsyncBaseObjectCallback baseObjectCallback) => - CoreImpl.PoolManager.Blip.ForEach(baseObjectCallback); - - public static void ForEachCheckpoints(IBaseObjectCallback baseObjectCallback) => - CoreImpl.PoolManager.Checkpoint.ForEach(baseObjectCallback); - - public static Task ForEachCheckpoints(IAsyncBaseObjectCallback baseObjectCallback) => - CoreImpl.PoolManager.Checkpoint.ForEach(baseObjectCallback); - - public static void ForEachVoiceChannels(IBaseObjectCallback baseObjectCallback) => - CoreImpl.PoolManager.VoiceChannel.ForEach(baseObjectCallback); - - public static Task ForEachVoiceChannels(IAsyncBaseObjectCallback baseObjectCallback) => - CoreImpl.PoolManager.VoiceChannel.ForEach(baseObjectCallback); - - public static void ForEachColShapes(IBaseObjectCallback baseObjectCallback) => - CoreImpl.PoolManager.ColShape.ForEach(baseObjectCallback); - - public static Task ForEachColShapes(IAsyncBaseObjectCallback baseObjectCallback) => - CoreImpl.PoolManager.ColShape.ForEach(baseObjectCallback); - public static VehicleModelInfo GetVehicleModelInfo(uint hash) => CoreImpl.GetVehicleModelInfo(hash); public static VehicleModelInfo GetVehicleModelInfo(string name) => CoreImpl.GetVehicleModelInfo(Hash(name)); public static PedModelInfo? GetPedModelInfo(uint hash) => CoreImpl.GetPedModelInfo(hash); diff --git a/api/AltV.Net/Elements/Pools/PoolManager.cs b/api/AltV.Net/Elements/Pools/PoolManager.cs index 3756f8fa..1a625e48 100644 --- a/api/AltV.Net/Elements/Pools/PoolManager.cs +++ b/api/AltV.Net/Elements/Pools/PoolManager.cs @@ -117,6 +117,75 @@ public IBaseObject Get(IntPtr entityPointer, BaseObjectType baseObjectType) }; } + public void Add(IBaseObject baseObject) + { + switch (baseObject.Type) + { + case BaseObjectType.Player: + { + Player.Add((IPlayer)baseObject); + break; + } + case BaseObjectType.Vehicle: + { + Vehicle.Add((IVehicle)baseObject); + break; + } + case BaseObjectType.Ped: + { + Ped.Add((IPed)baseObject); + break; + } + case BaseObjectType.Object: + { + Object.Add((IObject)baseObject); + break; + } + case BaseObjectType.Blip: + { + Blip.Add((IBlip)baseObject); + break; + } + case BaseObjectType.Checkpoint: + { + Checkpoint.Add((ICheckpoint)baseObject); + break; + } + case BaseObjectType.VoiceChannel: + { + VoiceChannel.Add((IVoiceChannel)baseObject); + break; + } + case BaseObjectType.ColShape: + { + ColShape.Add((IColShape)baseObject); + break; + } + case BaseObjectType.VirtualEntity: + { + VirtualEntity.Add((IVirtualEntity)baseObject); + break; + } + case BaseObjectType.VirtualEntityGroup: + { + VirtualEntityGroup.Add((IVirtualEntityGroup)baseObject); + break; + } + case BaseObjectType.Marker: + { + Marker.Add((IMarker)baseObject); + break; + } + case BaseObjectType.ConnectionInfo: + { + ConnectionInfo.Add((IConnectionInfo)baseObject); + break; + } + } + + + } + public void Dispose() { Player.Dispose(); diff --git a/api/AltV.Net/IPoolManager.cs b/api/AltV.Net/IPoolManager.cs index 60f187ae..d07034a4 100644 --- a/api/AltV.Net/IPoolManager.cs +++ b/api/AltV.Net/IPoolManager.cs @@ -26,6 +26,7 @@ public interface IPoolManager : ISharedPoolManager IBaseObject GetOrCreate(ICore core, IntPtr entityPointer, BaseObjectType baseObjectType, uint entityId); IBaseObject GetOrCreate(ICore core, IntPtr entityPointer, BaseObjectType baseObjectType); IBaseObject Get(IntPtr entityPointer, BaseObjectType baseObjectType); + void Add(IBaseObject baseObject); bool Remove(IBaseObject baseObject); bool Remove(IntPtr entityPointer, BaseObjectType baseObjectType); } diff --git a/runtime b/runtime index 8a6dcc7a..4837f367 160000 --- a/runtime +++ b/runtime @@ -1 +1 @@ -Subproject commit 8a6dcc7a02ee5b404a29616c125cab4ca404f540 +Subproject commit 4837f367eef832e7f6d73b12cc6f2e5437753974