From a84334e7a403ccf80fd8773dfa0c0e03483fc86e Mon Sep 17 00:00:00 2001 From: Niels <7136117+TheDutchDev@users.noreply.github.com> Date: Mon, 23 Dec 2024 20:41:10 +0100 Subject: [PATCH] update runtime submodule. apply feedback --- .../Elements/Entities/AsyncPlayer.cs | 32 ++++----- api/AltV.Net/Elements/Entities/IPlayer.cs | 14 +--- api/AltV.Net/Elements/Entities/Player.cs | 68 ++++++++----------- 3 files changed, 43 insertions(+), 71 deletions(-) diff --git a/api/AltV.Net.Async/Elements/Entities/AsyncPlayer.cs b/api/AltV.Net.Async/Elements/Entities/AsyncPlayer.cs index d98dcd79..4a63e773 100644 --- a/api/AltV.Net.Async/Elements/Entities/AsyncPlayer.cs +++ b/api/AltV.Net.Async/Elements/Entities/AsyncPlayer.cs @@ -136,8 +136,18 @@ public long DiscordId } } } - - public List StreamedEntityDistances => GetStreamedEntities(); + + public List StreamedEntities + { + get + { + lock (Player) + { + if (!AsyncContext.CheckIfExistsOrCachedNullable(Player)) return default; + return Player.StreamedEntities; + } + } + } public ushort Health { @@ -956,24 +966,6 @@ public WeaponData[] GetWeapons() } } - public uint GetStreamedEntitiesCount() - { - lock (Player) - { - if (!AsyncContext.CheckIfExistsNullable(Player)) return default; - return Player.GetStreamedEntitiesCount(); - } - } - - public List GetStreamedEntities() - { - lock (Player) - { - if (!AsyncContext.CheckIfExistsNullable(Player)) return default; - return Player.GetStreamedEntities(); - } - } - public void ClearBloodDamage() { lock (Player) diff --git a/api/AltV.Net/Elements/Entities/IPlayer.cs b/api/AltV.Net/Elements/Entities/IPlayer.cs index c12e27ae..1f0c0772 100644 --- a/api/AltV.Net/Elements/Entities/IPlayer.cs +++ b/api/AltV.Net/Elements/Entities/IPlayer.cs @@ -43,7 +43,7 @@ public interface IPlayer : ISharedPlayer, IEntity long DiscordId { get; } - List StreamedEntityDistances { get; } + List StreamedEntities { get; } /// /// Gets and Sets the players health @@ -256,18 +256,6 @@ void SetDateTime(int day, int month, int year, int hour, /// WeaponData[] GetWeapons(); - /// - /// Returns the amount of streamed entities - /// - /// - uint GetStreamedEntitiesCount(); - - /// - /// Returns a list of streamed entities - /// - /// - List GetStreamedEntities(); - /// /// Clears the blood damage of the player /// diff --git a/api/AltV.Net/Elements/Entities/Player.cs b/api/AltV.Net/Elements/Entities/Player.cs index 643975b7..1256c644 100644 --- a/api/AltV.Net/Elements/Entities/Player.cs +++ b/api/AltV.Net/Elements/Entities/Player.cs @@ -579,7 +579,36 @@ public long DiscordId } } - public List StreamedEntityDistances => GetStreamedEntities(); + public List StreamedEntities + { + get + { + unsafe + { + CheckIfEntityExistsOrCached(); + + var entitiesCount = Core.Library.Server.Player_GetStreamedEntitiesCount(PlayerNativePointer); + + var pointers = IntPtr.Zero; + var distances = new ushort[entitiesCount]; + var types = new byte[entitiesCount]; + Core.Library.Server.Player_GetStreamedEntities(PlayerNativePointer, &pointers, types, distances, entitiesCount); + + var entityPtrArray = new IntPtr[entitiesCount]; + Marshal.Copy(pointers, entityPtrArray, 0, (int) entitiesCount); + Core.Library.Shared.FreeVoidPointerArray(pointers); + + var streamedEntities = new List((int) entitiesCount); + for (ulong i = 0; i < entitiesCount; i++) + { + var entity = (IEntity) Core.PoolManager.GetOrCreate(Core, entityPtrArray[i], (BaseObjectType) types[i]); + streamedEntities.Add(new StreamedEntityDistance(entity, distances[i])); + } + + return streamedEntities; + } + } + } public ushort Health { @@ -1259,43 +1288,6 @@ public WeaponData[] GetWeapons() } } - public uint GetStreamedEntitiesCount() - { - unsafe - { - CheckIfEntityExists(); - return Core.Library.Server.Player_GetStreamedEntitiesCount(PlayerNativePointer); - } - } - - public List GetStreamedEntities() - { - unsafe - { - CheckIfEntityExists(); - - var entitiesCount = Core.Library.Server.Player_GetStreamedEntitiesCount(PlayerNativePointer); - - var pointers = IntPtr.Zero; - var distances = new ushort[entitiesCount]; - var types = new byte[entitiesCount]; - Core.Library.Server.Player_GetStreamedEntities(PlayerNativePointer, &pointers, distances, types, entitiesCount); - - var entityPtrArray = new IntPtr[entitiesCount]; - Marshal.Copy(pointers, entityPtrArray, 0, (int) entitiesCount); - Core.Library.Shared.FreeVoidPointerArray(pointers); - - var streamedEntities = new List((int) entitiesCount); - for (ulong i = 0; i < entitiesCount; i++) - { - var entity = (IEntity) Core.PoolManager.GetOrCreate(Core, entityPtrArray[i], (BaseObjectType) types[i]); - streamedEntities.Add(new StreamedEntityDistance(entity, distances[i])); - } - - return streamedEntities; - } - } - public void Kick(string reason) { unsafe