From b1eb8bdc10412101c5147833166c542d36a805dc 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.CApi/Libraries/ClientLibrary.cs | 2 +- api/AltV.Net.CApi/Libraries/ServerLibrary.cs | 12 ++-- api/AltV.Net.CApi/Libraries/SharedLibrary.cs | 2 +- api/AltV.Net/Elements/Entities/IPlayer.cs | 14 +--- api/AltV.Net/Elements/Entities/Player.cs | 68 ++++++++----------- runtime | 2 +- 7 files changed, 52 insertions(+), 80 deletions(-) diff --git a/api/AltV.Net.Async/Elements/Entities/AsyncPlayer.cs b/api/AltV.Net.Async/Elements/Entities/AsyncPlayer.cs index 360167e5..24680146 100644 --- a/api/AltV.Net.Async/Elements/Entities/AsyncPlayer.cs +++ b/api/AltV.Net.Async/Elements/Entities/AsyncPlayer.cs @@ -124,8 +124,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 { @@ -944,24 +954,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.CApi/Libraries/ClientLibrary.cs b/api/AltV.Net.CApi/Libraries/ClientLibrary.cs index 2862f16d..c40ba5fb 100644 --- a/api/AltV.Net.CApi/Libraries/ClientLibrary.cs +++ b/api/AltV.Net.CApi/Libraries/ClientLibrary.cs @@ -3717,7 +3717,7 @@ private IntPtr GetUnmanagedPtr(IDictionary funcTable, ulong ha public ClientLibrary(Dictionary funcTable) { if (!funcTable.TryGetValue(0, out var capiHash)) Outdated = true; - else if (capiHash == IntPtr.Zero || *(ulong*)capiHash != 13612278072387064778UL) Outdated = true; + else if (capiHash == IntPtr.Zero || *(ulong*)capiHash != 16672804929878796074UL) Outdated = true; Audio_AddOutput = (delegate* unmanaged[Cdecl]) GetUnmanagedPtr(funcTable, 9914412815391408844UL, Audio_AddOutputFallback); Audio_GetBaseObject = (delegate* unmanaged[Cdecl]) GetUnmanagedPtr(funcTable, 6330360502401226894UL, Audio_GetBaseObjectFallback); Audio_GetCurrentTime = (delegate* unmanaged[Cdecl]) GetUnmanagedPtr(funcTable, 2944324482134975819UL, Audio_GetCurrentTimeFallback); diff --git a/api/AltV.Net.CApi/Libraries/ServerLibrary.cs b/api/AltV.Net.CApi/Libraries/ServerLibrary.cs index e5ac37c3..3b220137 100644 --- a/api/AltV.Net.CApi/Libraries/ServerLibrary.cs +++ b/api/AltV.Net.CApi/Libraries/ServerLibrary.cs @@ -206,7 +206,7 @@ public unsafe interface IServerLibrary public delegate* unmanaged[Cdecl] Player_GetSendNames { get; } public delegate* unmanaged[Cdecl] Player_GetSocialClubName { get; } public delegate* unmanaged[Cdecl] Player_GetSocialID { get; } - public delegate* unmanaged[Cdecl] Player_GetStreamedEntities { get; } + public delegate* unmanaged[Cdecl] Player_GetStreamedEntities { get; } public delegate* unmanaged[Cdecl] Player_GetStreamedEntitiesCount { get; } public delegate* unmanaged[Cdecl] Player_GetWeaponAmmo { get; } public delegate* unmanaged[Cdecl] Player_GetWeaponCount { get; } @@ -686,7 +686,7 @@ public unsafe class ServerLibrary : IServerLibrary public delegate* unmanaged[Cdecl] Player_GetSendNames { get; } public delegate* unmanaged[Cdecl] Player_GetSocialClubName { get; } public delegate* unmanaged[Cdecl] Player_GetSocialID { get; } - public delegate* unmanaged[Cdecl] Player_GetStreamedEntities { get; } + public delegate* unmanaged[Cdecl] Player_GetStreamedEntities { get; } public delegate* unmanaged[Cdecl] Player_GetStreamedEntitiesCount { get; } public delegate* unmanaged[Cdecl] Player_GetWeaponAmmo { get; } public delegate* unmanaged[Cdecl] Player_GetWeaponCount { get; } @@ -1356,8 +1356,8 @@ public unsafe class ServerLibrary : IServerLibrary private static nint Player_GetSocialClubNameFallback(nint _player, int* _size) => throw new Exceptions.OutdatedSdkException("Player_GetSocialClubName", "Player_GetSocialClubName SDK method is outdated. Please update your module nuget"); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate ulong Player_GetSocialIDDelegate(nint _player); private static ulong Player_GetSocialIDFallback(nint _player) => throw new Exceptions.OutdatedSdkException("Player_GetSocialID", "Player_GetSocialID SDK method is outdated. Please update your module nuget"); - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate void Player_GetStreamedEntitiesDelegate(nint _player, nint* _entities, ushort[] distances, byte[] types, uint _size); - private static void Player_GetStreamedEntitiesFallback(nint _player, nint* _entities, ushort[] distances, byte[] types, uint _size) => throw new Exceptions.OutdatedSdkException("Player_GetStreamedEntities", "Player_GetStreamedEntities SDK method is outdated. Please update your module nuget"); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate void Player_GetStreamedEntitiesDelegate(nint _player, nint* _entities, byte[] types, ushort[] distances, uint _size); + private static void Player_GetStreamedEntitiesFallback(nint _player, nint* _entities, byte[] types, ushort[] distances, uint _size) => throw new Exceptions.OutdatedSdkException("Player_GetStreamedEntities", "Player_GetStreamedEntities SDK method is outdated. Please update your module nuget"); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate uint Player_GetStreamedEntitiesCountDelegate(nint _player); private static uint Player_GetStreamedEntitiesCountFallback(nint _player) => throw new Exceptions.OutdatedSdkException("Player_GetStreamedEntitiesCount", "Player_GetStreamedEntitiesCount SDK method is outdated. Please update your module nuget"); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate ushort Player_GetWeaponAmmoDelegate(nint _player, uint _weaponHash); @@ -1925,7 +1925,7 @@ private IntPtr GetUnmanagedPtr(IDictionary funcTable, ulong ha public ServerLibrary(Dictionary funcTable) { if (!funcTable.TryGetValue(0, out var capiHash)) Outdated = true; - else if (capiHash == IntPtr.Zero || *(ulong*)capiHash != 13612278072387064778UL) Outdated = true; + else if (capiHash == IntPtr.Zero || *(ulong*)capiHash != 16672804929878796074UL) Outdated = true; BaseObject_DeleteSyncedMetaData = (delegate* unmanaged[Cdecl]) GetUnmanagedPtr(funcTable, 8228424877092269355UL, BaseObject_DeleteSyncedMetaDataFallback); BaseObject_SetMultipleSyncedMetaData = (delegate* unmanaged[Cdecl]) GetUnmanagedPtr(funcTable, 1390762125822890831UL, BaseObject_SetMultipleSyncedMetaDataFallback); BaseObject_SetSyncedMetaData = (delegate* unmanaged[Cdecl]) GetUnmanagedPtr(funcTable, 8002999088966424231UL, BaseObject_SetSyncedMetaDataFallback); @@ -2121,7 +2121,7 @@ public ServerLibrary(Dictionary funcTable) Player_GetSendNames = (delegate* unmanaged[Cdecl]) GetUnmanagedPtr(funcTable, 7490273379384857895UL, Player_GetSendNamesFallback); Player_GetSocialClubName = (delegate* unmanaged[Cdecl]) GetUnmanagedPtr(funcTable, 17452312619664438538UL, Player_GetSocialClubNameFallback); Player_GetSocialID = (delegate* unmanaged[Cdecl]) GetUnmanagedPtr(funcTable, 17807664466527734655UL, Player_GetSocialIDFallback); - Player_GetStreamedEntities = (delegate* unmanaged[Cdecl]) GetUnmanagedPtr(funcTable, 16539572063395996721UL, Player_GetStreamedEntitiesFallback); + Player_GetStreamedEntities = (delegate* unmanaged[Cdecl]) GetUnmanagedPtr(funcTable, 17370306352290181349UL, Player_GetStreamedEntitiesFallback); Player_GetStreamedEntitiesCount = (delegate* unmanaged[Cdecl]) GetUnmanagedPtr(funcTable, 13915984405046061551UL, Player_GetStreamedEntitiesCountFallback); Player_GetWeaponAmmo = (delegate* unmanaged[Cdecl]) GetUnmanagedPtr(funcTable, 2928381910125083497UL, Player_GetWeaponAmmoFallback); Player_GetWeaponCount = (delegate* unmanaged[Cdecl]) GetUnmanagedPtr(funcTable, 17600594564491002166UL, Player_GetWeaponCountFallback); diff --git a/api/AltV.Net.CApi/Libraries/SharedLibrary.cs b/api/AltV.Net.CApi/Libraries/SharedLibrary.cs index 359162c6..b5049921 100644 --- a/api/AltV.Net.CApi/Libraries/SharedLibrary.cs +++ b/api/AltV.Net.CApi/Libraries/SharedLibrary.cs @@ -1669,7 +1669,7 @@ private IntPtr GetUnmanagedPtr(IDictionary funcTable, ulong ha public SharedLibrary(Dictionary funcTable) { if (!funcTable.TryGetValue(0, out var capiHash)) Outdated = true; - else if (capiHash == IntPtr.Zero || *(ulong*)capiHash != 13612278072387064778UL) Outdated = true; + else if (capiHash == IntPtr.Zero || *(ulong*)capiHash != 16672804929878796074UL) Outdated = true; Audio_GetID = (delegate* unmanaged[Cdecl]) GetUnmanagedPtr(funcTable, 4464042055475980737UL, Audio_GetIDFallback); AudioAttachedOutput_GetID = (delegate* unmanaged[Cdecl]) GetUnmanagedPtr(funcTable, 17725794901805112189UL, AudioAttachedOutput_GetIDFallback); AudioFilter_GetID = (delegate* unmanaged[Cdecl]) GetUnmanagedPtr(funcTable, 8824535635529306325UL, AudioFilter_GetIDFallback); diff --git a/api/AltV.Net/Elements/Entities/IPlayer.cs b/api/AltV.Net/Elements/Entities/IPlayer.cs index cc3feff3..56543574 100644 --- a/api/AltV.Net/Elements/Entities/IPlayer.cs +++ b/api/AltV.Net/Elements/Entities/IPlayer.cs @@ -41,7 +41,7 @@ public interface IPlayer : ISharedPlayer, IEntity long DiscordId { get; } - List StreamedEntityDistances { get; } + List StreamedEntities { get; } /// /// Gets and Sets the players health @@ -254,18 +254,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 f3beb39a..c399f151 100644 --- a/api/AltV.Net/Elements/Entities/Player.cs +++ b/api/AltV.Net/Elements/Entities/Player.cs @@ -565,7 +565,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 { @@ -1245,43 +1274,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 diff --git a/runtime b/runtime index 514d1e52..0083c6de 160000 --- a/runtime +++ b/runtime @@ -1 +1 @@ -Subproject commit 514d1e52715d75e08702b0b6a3e997a50e5b1543 +Subproject commit 0083c6de4598dd8edc26412f06237002523dbb97