Skip to content

Commit

Permalink
update runtime submodule. apply feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
TheDutchDev committed Dec 26, 2024
1 parent 9e8e7b5 commit b1eb8bd
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 80 deletions.
32 changes: 12 additions & 20 deletions api/AltV.Net.Async/Elements/Entities/AsyncPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,18 @@ public long DiscordId
}
}
}

public List<StreamedEntityDistance> StreamedEntityDistances => GetStreamedEntities();

public List<StreamedEntityDistance> StreamedEntities
{
get
{
lock (Player)
{
if (!AsyncContext.CheckIfExistsOrCachedNullable(Player)) return default;
return Player.StreamedEntities;
}
}
}

public ushort Health
{
Expand Down Expand Up @@ -944,24 +954,6 @@ public WeaponData[] GetWeapons()
}
}

public uint GetStreamedEntitiesCount()
{
lock (Player)
{
if (!AsyncContext.CheckIfExistsNullable(Player)) return default;
return Player.GetStreamedEntitiesCount();
}
}

public List<StreamedEntityDistance> GetStreamedEntities()
{
lock (Player)
{
if (!AsyncContext.CheckIfExistsNullable(Player)) return default;
return Player.GetStreamedEntities();
}
}

public void ClearBloodDamage()
{
lock (Player)
Expand Down
2 changes: 1 addition & 1 deletion api/AltV.Net.CApi/Libraries/ClientLibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3717,7 +3717,7 @@ private IntPtr GetUnmanagedPtr<T>(IDictionary<ulong, IntPtr> funcTable, ulong ha
public ClientLibrary(Dictionary<ulong, IntPtr> 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]<nint, nint, void>) GetUnmanagedPtr<Audio_AddOutputDelegate>(funcTable, 9914412815391408844UL, Audio_AddOutputFallback);
Audio_GetBaseObject = (delegate* unmanaged[Cdecl]<nint, nint>) GetUnmanagedPtr<Audio_GetBaseObjectDelegate>(funcTable, 6330360502401226894UL, Audio_GetBaseObjectFallback);
Audio_GetCurrentTime = (delegate* unmanaged[Cdecl]<nint, double>) GetUnmanagedPtr<Audio_GetCurrentTimeDelegate>(funcTable, 2944324482134975819UL, Audio_GetCurrentTimeFallback);
Expand Down
12 changes: 6 additions & 6 deletions api/AltV.Net.CApi/Libraries/ServerLibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public unsafe interface IServerLibrary
public delegate* unmanaged[Cdecl]<nint, byte> Player_GetSendNames { get; }
public delegate* unmanaged[Cdecl]<nint, int*, nint> Player_GetSocialClubName { get; }
public delegate* unmanaged[Cdecl]<nint, ulong> Player_GetSocialID { get; }
public delegate* unmanaged[Cdecl]<nint, nint*, ushort[], byte[], uint, void> Player_GetStreamedEntities { get; }
public delegate* unmanaged[Cdecl]<nint, nint*, byte[], ushort[], uint, void> Player_GetStreamedEntities { get; }
public delegate* unmanaged[Cdecl]<nint, uint> Player_GetStreamedEntitiesCount { get; }
public delegate* unmanaged[Cdecl]<nint, uint, ushort> Player_GetWeaponAmmo { get; }
public delegate* unmanaged[Cdecl]<nint, ulong> Player_GetWeaponCount { get; }
Expand Down Expand Up @@ -686,7 +686,7 @@ public unsafe class ServerLibrary : IServerLibrary
public delegate* unmanaged[Cdecl]<nint, byte> Player_GetSendNames { get; }
public delegate* unmanaged[Cdecl]<nint, int*, nint> Player_GetSocialClubName { get; }
public delegate* unmanaged[Cdecl]<nint, ulong> Player_GetSocialID { get; }
public delegate* unmanaged[Cdecl]<nint, nint*, ushort[], byte[], uint, void> Player_GetStreamedEntities { get; }
public delegate* unmanaged[Cdecl]<nint, nint*, byte[], ushort[], uint, void> Player_GetStreamedEntities { get; }
public delegate* unmanaged[Cdecl]<nint, uint> Player_GetStreamedEntitiesCount { get; }
public delegate* unmanaged[Cdecl]<nint, uint, ushort> Player_GetWeaponAmmo { get; }
public delegate* unmanaged[Cdecl]<nint, ulong> Player_GetWeaponCount { get; }
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -1925,7 +1925,7 @@ private IntPtr GetUnmanagedPtr<T>(IDictionary<ulong, IntPtr> funcTable, ulong ha
public ServerLibrary(Dictionary<ulong, IntPtr> 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]<nint, nint, void>) GetUnmanagedPtr<BaseObject_DeleteSyncedMetaDataDelegate>(funcTable, 8228424877092269355UL, BaseObject_DeleteSyncedMetaDataFallback);
BaseObject_SetMultipleSyncedMetaData = (delegate* unmanaged[Cdecl]<nint, nint[], nint[], ulong, void>) GetUnmanagedPtr<BaseObject_SetMultipleSyncedMetaDataDelegate>(funcTable, 1390762125822890831UL, BaseObject_SetMultipleSyncedMetaDataFallback);
BaseObject_SetSyncedMetaData = (delegate* unmanaged[Cdecl]<nint, nint, nint, void>) GetUnmanagedPtr<BaseObject_SetSyncedMetaDataDelegate>(funcTable, 8002999088966424231UL, BaseObject_SetSyncedMetaDataFallback);
Expand Down Expand Up @@ -2121,7 +2121,7 @@ public ServerLibrary(Dictionary<ulong, IntPtr> funcTable)
Player_GetSendNames = (delegate* unmanaged[Cdecl]<nint, byte>) GetUnmanagedPtr<Player_GetSendNamesDelegate>(funcTable, 7490273379384857895UL, Player_GetSendNamesFallback);
Player_GetSocialClubName = (delegate* unmanaged[Cdecl]<nint, int*, nint>) GetUnmanagedPtr<Player_GetSocialClubNameDelegate>(funcTable, 17452312619664438538UL, Player_GetSocialClubNameFallback);
Player_GetSocialID = (delegate* unmanaged[Cdecl]<nint, ulong>) GetUnmanagedPtr<Player_GetSocialIDDelegate>(funcTable, 17807664466527734655UL, Player_GetSocialIDFallback);
Player_GetStreamedEntities = (delegate* unmanaged[Cdecl]<nint, nint*, ushort[], byte[], uint, void>) GetUnmanagedPtr<Player_GetStreamedEntitiesDelegate>(funcTable, 16539572063395996721UL, Player_GetStreamedEntitiesFallback);
Player_GetStreamedEntities = (delegate* unmanaged[Cdecl]<nint, nint*, byte[], ushort[], uint, void>) GetUnmanagedPtr<Player_GetStreamedEntitiesDelegate>(funcTable, 17370306352290181349UL, Player_GetStreamedEntitiesFallback);
Player_GetStreamedEntitiesCount = (delegate* unmanaged[Cdecl]<nint, uint>) GetUnmanagedPtr<Player_GetStreamedEntitiesCountDelegate>(funcTable, 13915984405046061551UL, Player_GetStreamedEntitiesCountFallback);
Player_GetWeaponAmmo = (delegate* unmanaged[Cdecl]<nint, uint, ushort>) GetUnmanagedPtr<Player_GetWeaponAmmoDelegate>(funcTable, 2928381910125083497UL, Player_GetWeaponAmmoFallback);
Player_GetWeaponCount = (delegate* unmanaged[Cdecl]<nint, ulong>) GetUnmanagedPtr<Player_GetWeaponCountDelegate>(funcTable, 17600594564491002166UL, Player_GetWeaponCountFallback);
Expand Down
2 changes: 1 addition & 1 deletion api/AltV.Net.CApi/Libraries/SharedLibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1669,7 +1669,7 @@ private IntPtr GetUnmanagedPtr<T>(IDictionary<ulong, IntPtr> funcTable, ulong ha
public SharedLibrary(Dictionary<ulong, IntPtr> 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]<nint, uint>) GetUnmanagedPtr<Audio_GetIDDelegate>(funcTable, 4464042055475980737UL, Audio_GetIDFallback);
AudioAttachedOutput_GetID = (delegate* unmanaged[Cdecl]<nint, uint>) GetUnmanagedPtr<AudioAttachedOutput_GetIDDelegate>(funcTable, 17725794901805112189UL, AudioAttachedOutput_GetIDFallback);
AudioFilter_GetID = (delegate* unmanaged[Cdecl]<nint, uint>) GetUnmanagedPtr<AudioFilter_GetIDDelegate>(funcTable, 8824535635529306325UL, AudioFilter_GetIDFallback);
Expand Down
14 changes: 1 addition & 13 deletions api/AltV.Net/Elements/Entities/IPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public interface IPlayer : ISharedPlayer, IEntity

long DiscordId { get; }

List<StreamedEntityDistance> StreamedEntityDistances { get; }
List<StreamedEntityDistance> StreamedEntities { get; }

/// <summary>
/// Gets and Sets the players health
Expand Down Expand Up @@ -254,18 +254,6 @@ void SetDateTime(int day, int month, int year, int hour,
/// <returns></returns>
WeaponData[] GetWeapons();

/// <summary>
/// Returns the amount of streamed entities
/// </summary>
/// <returns></returns>
uint GetStreamedEntitiesCount();

/// <summary>
/// Returns a list of streamed entities
/// </summary>
/// <returns></returns>
List<StreamedEntityDistance> GetStreamedEntities();

/// <summary>
/// Clears the blood damage of the player
/// </summary>
Expand Down
68 changes: 30 additions & 38 deletions api/AltV.Net/Elements/Entities/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,36 @@ public long DiscordId
}
}

public List<StreamedEntityDistance> StreamedEntityDistances => GetStreamedEntities();
public List<StreamedEntityDistance> 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<StreamedEntityDistance>((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
{
Expand Down Expand Up @@ -1245,43 +1274,6 @@ public WeaponData[] GetWeapons()
}
}

public uint GetStreamedEntitiesCount()
{
unsafe
{
CheckIfEntityExists();
return Core.Library.Server.Player_GetStreamedEntitiesCount(PlayerNativePointer);
}
}

public List<StreamedEntityDistance> 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<StreamedEntityDistance>((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
Expand Down
2 changes: 1 addition & 1 deletion runtime

0 comments on commit b1eb8bd

Please sign in to comment.