Skip to content

Commit

Permalink
one big refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Doxoh committed Apr 14, 2023
1 parent 423b822 commit dd42ed1
Show file tree
Hide file tree
Showing 71 changed files with 977 additions and 1,049 deletions.
2 changes: 1 addition & 1 deletion api/AltV.Net.Async/AltAsync.Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public static async Task<IVehicle> GetVehicleAsync(this IPlayer player)
{
player.CheckIfEntityExists();
var vehiclePtr = Alt.Core.Library.Shared.Player_GetVehicle(player.PlayerNativePointer);
return Alt.Core.VehiclePool.Get(vehiclePtr);
return Alt.Core.PoolManager.Vehicle.Get(vehiclePtr);
}
});
}
Expand Down
12 changes: 0 additions & 12 deletions api/AltV.Net.Async/AsyncBaseBaseObjectPool.cs

This file was deleted.

12 changes: 12 additions & 0 deletions api/AltV.Net.Async/AsyncBaseObjectPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,18 @@ public bool Remove(IntPtr entityPointer)
return true;
}

public TBaseObject GetOrCreate(ICore core, IntPtr entityPointer, uint entityId)
{
if (entityPointer == IntPtr.Zero)
{
return default;
}

if (entities.TryGetValue(entityPointer, out var entity)) return entity;

return Create(core, entityPointer, entityId);
}

public TBaseObject Get(IntPtr entityPointer)
{
return entities.TryGetValue(entityPointer, out var entity) ? entity : default;
Expand Down
12 changes: 2 additions & 10 deletions api/AltV.Net.Async/AsyncCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,16 +147,8 @@ internal readonly AsyncEventHandler<PlayerChangeVehicleSeatAsyncDelegate>
internal readonly AsyncEventHandler<PlayerSpawnAsyncDelegate> PlayerSpawnAsyncEventHandler =
new(EventType.PLAYER_SPAWN);

public AsyncCore(IntPtr nativePointer, IntPtr resourcePointer, AssemblyLoadContext assemblyLoadContext, ILibrary library, IBaseBaseObjectPool baseBaseObjectPool,
IBaseEntityPool baseEntityPool,
IEntityPool<IPlayer> playerPool,
IEntityPool<IVehicle> vehiclePool,
IEntityPool<IPed> pedPool,
IBaseObjectPool<IBlip> blipPool,
IBaseObjectPool<ICheckpoint> checkpointPool,
IBaseObjectPool<IVoiceChannel> voiceChannelPool,
IBaseObjectPool<IColShape> colShapePool,
INativeResourcePool nativeResourcePool) : base(nativePointer, resourcePointer, assemblyLoadContext, library, baseBaseObjectPool, baseEntityPool, playerPool, vehiclePool, pedPool, blipPool, checkpointPool, voiceChannelPool, colShapePool, nativeResourcePool)
public AsyncCore(IntPtr nativePointer, IntPtr resourcePointer, AssemblyLoadContext assemblyLoadContext, ILibrary library, IPoolManager poolManager,
INativeResourcePool nativeResourcePool) : base(nativePointer, resourcePointer, assemblyLoadContext, library, poolManager, nativeResourcePool)
{
AltAsync.Setup(this);
}
Expand Down
18 changes: 2 additions & 16 deletions api/AltV.Net.Async/AsyncResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,6 @@ public override void OnTick()
altVAsync.TickDelegate();
}

public override IBaseEntityPool GetBaseEntityPool(IEntityPool<IPlayer> playerPool,
IEntityPool<IVehicle> vehiclePool, IEntityPool<IPed> pedPool)
{
return new AsyncBaseBaseObjectPool(playerPool, vehiclePool, pedPool);
}

public override IEntityPool<IPlayer> GetPlayerPool(IEntityFactory<IPlayer> playerFactory)
{
return new AsyncPlayerPool(playerFactory, forceAsync);
Expand Down Expand Up @@ -90,18 +84,10 @@ public override IBaseObjectPool<IMarker> GetMarkerPool(IBaseObjectFactory<IMarke
return new AsyncMarkerPool(factory, forceAsync);
}

public override Core GetCore(IntPtr nativePointer, IntPtr resourcePointer, AssemblyLoadContext assemblyLoadContext, ILibrary library, IBaseBaseObjectPool baseBaseObjectPool,
IBaseEntityPool baseEntityPool,
IEntityPool<IPlayer> playerPool,
IEntityPool<IVehicle> vehiclePool,
IEntityPool<IPed> pedPool,
IBaseObjectPool<IBlip> blipPool,
IBaseObjectPool<ICheckpoint> checkpointPool,
IBaseObjectPool<IVoiceChannel> voiceChannelPool,
IBaseObjectPool<IColShape> colShapePool,
public override Core GetCore(IntPtr nativePointer, IntPtr resourcePointer, AssemblyLoadContext assemblyLoadContext, ILibrary library, IPoolManager poolManager,
INativeResourcePool nativeResourcePool)
{
return new AsyncCore(nativePointer, resourcePointer, assemblyLoadContext, library, baseBaseObjectPool, baseEntityPool, playerPool, vehiclePool, pedPool, blipPool, checkpointPool, voiceChannelPool, colShapePool, nativeResourcePool);
return new AsyncCore(nativePointer, resourcePointer, assemblyLoadContext, library, poolManager, nativeResourcePool);
}

public override IBaseObjectFactory<IBlip> GetBlipFactory()
Expand Down
2 changes: 1 addition & 1 deletion api/AltV.Net.Async/Elements/Entities/AsyncPed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public AsyncPed(ICore core, IntPtr nativePointer, uint id) : this(new Ped(core,
public AsyncPed(ICore core, uint model, Position position, Rotation rotation) : this(
core, core.CreateVehicleEntity(out var id, model, position, rotation), id)
{
Alt.Core.PedPool.Add(this);
core.PoolManager.Ped.Add(this);
}

[Obsolete("Use new async API instead")]
Expand Down
2 changes: 1 addition & 1 deletion api/AltV.Net.Async/Elements/Entities/AsyncVehicle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ public AsyncVehicle(ICore core, IntPtr nativePointer, uint id) : this(new Vehicl
public AsyncVehicle(ICore core, uint model, Position position, Rotation rotation) : this(
core, core.CreateVehicleEntity(out var id, model, position, rotation), id)
{
Alt.Core.VehiclePool.Add(this);
core.PoolManager.Vehicle.Add(this);
}

public byte GetMod(byte category)
Expand Down
2 changes: 1 addition & 1 deletion api/AltV.Net.Async/Elements/Entities/VehicleBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ public async Task<IVehicle> Build()
});
enumerator.Dispose();
Dispose();
return Alt.Core.VehiclePool.Create(Alt.Core, vehiclePtr, vehicleId);
return Alt.Core.PoolManager.Vehicle.Create(Alt.Core, vehiclePtr, vehicleId);
}

// Call Dispose when you don't wanna continue building the vehicle anymore to cleanup memory
Expand Down
9 changes: 7 additions & 2 deletions api/AltV.Net.CApi/Libraries/ClientLibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public unsafe interface IClientLibrary
public delegate* unmanaged[Cdecl]<nint, nint, nint, float, uint, byte, uint*, nint> Core_CreateAudio { get; }
public delegate* unmanaged[Cdecl]<nint, byte, Vector3, Vector3, float, float, Rgba, nint, uint*, nint> Core_CreateCheckpoint { get; }
public delegate* unmanaged[Cdecl]<nint, nint, uint*, nint> Core_CreateHttpClient { get; }
public delegate* unmanaged[Cdecl]<nint, byte, Vector3, Rgba, nint, uint*, nint> Core_CreateMarker { get; }
public delegate* unmanaged[Cdecl]<nint, uint, Vector3, Vector3, byte, byte, nint, ushort*, nint> Core_CreateObject { get; }
public delegate* unmanaged[Cdecl]<nint, nint, nint, uint*, nint> Core_CreateRmlDocument { get; }
public delegate* unmanaged[Cdecl]<nint, nint, nint, uint*, nint> Core_CreateWebsocketClient { get; }
Expand Down Expand Up @@ -745,7 +746,7 @@ public unsafe interface IClientLibrary

public unsafe class ClientLibrary : IClientLibrary
{
public readonly uint Methods = 1432;
public readonly uint Methods = 1433;
public delegate* unmanaged[Cdecl]<nint, nint, void> Audio_AddOutput_Entity { get; }
public delegate* unmanaged[Cdecl]<nint, uint, void> Audio_AddOutput_ScriptId { get; }
public delegate* unmanaged[Cdecl]<nint, nint> Audio_GetBaseObject { get; }
Expand Down Expand Up @@ -786,6 +787,7 @@ public unsafe class ClientLibrary : IClientLibrary
public delegate* unmanaged[Cdecl]<nint, nint, nint, float, uint, byte, uint*, nint> Core_CreateAudio { get; }
public delegate* unmanaged[Cdecl]<nint, byte, Vector3, Vector3, float, float, Rgba, nint, uint*, nint> Core_CreateCheckpoint { get; }
public delegate* unmanaged[Cdecl]<nint, nint, uint*, nint> Core_CreateHttpClient { get; }
public delegate* unmanaged[Cdecl]<nint, byte, Vector3, Rgba, nint, uint*, nint> Core_CreateMarker { get; }
public delegate* unmanaged[Cdecl]<nint, uint, Vector3, Vector3, byte, byte, nint, ushort*, nint> Core_CreateObject { get; }
public delegate* unmanaged[Cdecl]<nint, nint, nint, uint*, nint> Core_CreateRmlDocument { get; }
public delegate* unmanaged[Cdecl]<nint, nint, nint, uint*, nint> Core_CreateWebsocketClient { get; }
Expand Down Expand Up @@ -1557,6 +1559,8 @@ public unsafe class ClientLibrary : IClientLibrary
private static nint Core_CreateCheckpointFallback(nint _server, byte _type, Vector3 _pos, Vector3 _nextPos, float _radius, float _height, Rgba _color, nint _resource, uint* _id) => throw new Exceptions.OutdatedSdkException("Core_CreateCheckpoint", "Core_CreateCheckpoint SDK method is outdated. Please update your module nuget");
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate nint Core_CreateHttpClientDelegate(nint _core, nint _resource, uint* _id);
private static nint Core_CreateHttpClientFallback(nint _core, nint _resource, uint* _id) => throw new Exceptions.OutdatedSdkException("Core_CreateHttpClient", "Core_CreateHttpClient SDK method is outdated. Please update your module nuget");
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate nint Core_CreateMarkerDelegate(nint _core, byte _type, Vector3 _pos, Rgba _color, nint _resource, uint* _id);
private static nint Core_CreateMarkerFallback(nint _core, byte _type, Vector3 _pos, Rgba _color, nint _resource, uint* _id) => throw new Exceptions.OutdatedSdkException("Core_CreateMarker", "Core_CreateMarker SDK method is outdated. Please update your module nuget");
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate nint Core_CreateObjectDelegate(nint _core, uint _modelHash, Vector3 _position, Vector3 _rot, byte _noOffset, byte _dynamic, nint _resource, ushort* _id);
private static nint Core_CreateObjectFallback(nint _core, uint _modelHash, Vector3 _position, Vector3 _rot, byte _noOffset, byte _dynamic, nint _resource, ushort* _id) => throw new Exceptions.OutdatedSdkException("Core_CreateObject", "Core_CreateObject SDK method is outdated. Please update your module nuget");
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate nint Core_CreateRmlDocumentDelegate(nint _core, nint _resource, nint _url, uint* _id);
Expand Down Expand Up @@ -2948,7 +2952,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 != 1529280386609474865UL) Outdated = true;
else if (capiHash == IntPtr.Zero || *(ulong*)capiHash != 2679354782642095290UL) Outdated = true;
Audio_AddOutput_Entity = (delegate* unmanaged[Cdecl]<nint, nint, void>) GetUnmanagedPtr<Audio_AddOutput_EntityDelegate>(funcTable, 9879036518735269522UL, Audio_AddOutput_EntityFallback);
Audio_AddOutput_ScriptId = (delegate* unmanaged[Cdecl]<nint, uint, void>) GetUnmanagedPtr<Audio_AddOutput_ScriptIdDelegate>(funcTable, 14116998947805478300UL, Audio_AddOutput_ScriptIdFallback);
Audio_GetBaseObject = (delegate* unmanaged[Cdecl]<nint, nint>) GetUnmanagedPtr<Audio_GetBaseObjectDelegate>(funcTable, 6330360502401226894UL, Audio_GetBaseObjectFallback);
Expand Down Expand Up @@ -2989,6 +2993,7 @@ public ClientLibrary(Dictionary<ulong, IntPtr> funcTable)
Core_CreateAudio = (delegate* unmanaged[Cdecl]<nint, nint, nint, float, uint, byte, uint*, nint>) GetUnmanagedPtr<Core_CreateAudioDelegate>(funcTable, 7736168136360038277UL, Core_CreateAudioFallback);
Core_CreateCheckpoint = (delegate* unmanaged[Cdecl]<nint, byte, Vector3, Vector3, float, float, Rgba, nint, uint*, nint>) GetUnmanagedPtr<Core_CreateCheckpointDelegate>(funcTable, 16485029339771645828UL, Core_CreateCheckpointFallback);
Core_CreateHttpClient = (delegate* unmanaged[Cdecl]<nint, nint, uint*, nint>) GetUnmanagedPtr<Core_CreateHttpClientDelegate>(funcTable, 18346481764601280220UL, Core_CreateHttpClientFallback);
Core_CreateMarker = (delegate* unmanaged[Cdecl]<nint, byte, Vector3, Rgba, nint, uint*, nint>) GetUnmanagedPtr<Core_CreateMarkerDelegate>(funcTable, 4215745029296794033UL, Core_CreateMarkerFallback);
Core_CreateObject = (delegate* unmanaged[Cdecl]<nint, uint, Vector3, Vector3, byte, byte, nint, ushort*, nint>) GetUnmanagedPtr<Core_CreateObjectDelegate>(funcTable, 12959857024542892545UL, Core_CreateObjectFallback);
Core_CreateRmlDocument = (delegate* unmanaged[Cdecl]<nint, nint, nint, uint*, nint>) GetUnmanagedPtr<Core_CreateRmlDocumentDelegate>(funcTable, 6616548211992387591UL, Core_CreateRmlDocumentFallback);
Core_CreateWebsocketClient = (delegate* unmanaged[Cdecl]<nint, nint, nint, uint*, nint>) GetUnmanagedPtr<Core_CreateWebsocketClientDelegate>(funcTable, 10887342887795907175UL, Core_CreateWebsocketClientFallback);
Expand Down
4 changes: 2 additions & 2 deletions api/AltV.Net.CApi/Libraries/ServerLibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ public unsafe interface IServerLibrary

public unsafe class ServerLibrary : IServerLibrary
{
public readonly uint Methods = 1432;
public readonly uint Methods = 1433;
public delegate* unmanaged[Cdecl]<nint, BaseObjectType*, nint> Blip_AttachedTo { get; }
public delegate* unmanaged[Cdecl]<nint, byte> Blip_IsAttached { get; }
public delegate* unmanaged[Cdecl]<nint, byte> ColShape_GetColShapeType { get; }
Expand Down Expand Up @@ -1544,7 +1544,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 != 1529280386609474865UL) Outdated = true;
else if (capiHash == IntPtr.Zero || *(ulong*)capiHash != 2679354782642095290UL) Outdated = true;
Blip_AttachedTo = (delegate* unmanaged[Cdecl]<nint, BaseObjectType*, nint>) GetUnmanagedPtr<Blip_AttachedToDelegate>(funcTable, 15602966080933483258UL, Blip_AttachedToFallback);
Blip_IsAttached = (delegate* unmanaged[Cdecl]<nint, byte>) GetUnmanagedPtr<Blip_IsAttachedDelegate>(funcTable, 7870458832410754161UL, Blip_IsAttachedFallback);
ColShape_GetColShapeType = (delegate* unmanaged[Cdecl]<nint, byte>) GetUnmanagedPtr<ColShape_GetColShapeTypeDelegate>(funcTable, 18034368716132758796UL, ColShape_GetColShapeTypeFallback);
Expand Down
Loading

0 comments on commit dd42ed1

Please sign in to comment.