Skip to content

Commit

Permalink
Change NetworkObject to Object
Browse files Browse the repository at this point in the history
  • Loading branch information
Doxoh committed Jul 21, 2023
1 parent 7f94c4a commit c491044
Show file tree
Hide file tree
Showing 42 changed files with 356 additions and 375 deletions.
15 changes: 0 additions & 15 deletions api/AltV.Net.Async/AltAsync.NetworkObject.cs

This file was deleted.

15 changes: 15 additions & 0 deletions api/AltV.Net.Async/AltAsync.Object.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System.Threading.Tasks;
using AltV.Net.Data;
using AltV.Net.Elements.Entities;

namespace AltV.Net.Async
{
public partial class AltAsync
{
public static Task<IObject> CreateObject(uint model, Position position, Rotation rotation, byte alpha = 255, byte textureVariation = 0, ushort lodDistance = 100) =>
AltVAsync.Schedule(() => Alt.CreateObject(model, position, rotation, alpha, textureVariation, lodDistance));

public static Task<IObject> CreateObject(string model, Position position, Rotation rotation, byte alpha = 255, byte textureVariation = 0, ushort lodDistance = 100) =>
AltVAsync.Schedule(() => Alt.CreateObject(Alt.Hash(model), position, rotation, alpha, textureVariation, lodDistance));
}
}
4 changes: 2 additions & 2 deletions api/AltV.Net.Async/AsyncResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@ public override IBaseObjectFactory<IMarker> GetMarkerFactory()
return forceAsync ? new AsyncMarkerFactory() : base.GetMarkerFactory();
}

public override IEntityFactory<INetworkObject> GetNetworkObjectFactory()
public override IEntityFactory<IObject> GetObjectFactory()
{
return forceAsync ? new AsyncNetworkObjectFactory() : base.GetNetworkObjectFactory();
return forceAsync ? new AsyncObjectFactory() : base.GetObjectFactory();
}

public override IBaseObjectFactory<IConnectionInfo> GetConnectionInfoFactory()
Expand Down
105 changes: 0 additions & 105 deletions api/AltV.Net.Async/Elements/Entities/AsyncNetworkObject.cs

This file was deleted.

106 changes: 106 additions & 0 deletions api/AltV.Net.Async/Elements/Entities/AsyncObject.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
using System;
using AltV.Net.Data;
using AltV.Net.Elements.Entities;
using Object = AltV.Net.Elements.Entities.Object;

namespace AltV.Net.Async.Elements.Entities;

public class AsyncObject : AsyncEntity, IObject, IAsyncConvertible<IObject>
{
protected readonly IObject Object;
public IntPtr ObjectNativePointer => Object.ObjectNativePointer;

public AsyncObject(IObject @object, IAsyncContext asyncContext) : base(@object, asyncContext)
{
Object = @object;
}

public AsyncObject(ICore core, IntPtr nativePointer, uint id) : this(new Object(core, nativePointer, id),
null)
{
}

public byte Alpha
{
get
{
lock (Object)
{
if (!AsyncContext.CheckIfExistsOrCachedNullable(Object)) return default;
return Object.Alpha;
}
}
set
{
lock (Object)
{
if (!AsyncContext.CheckIfExistsNullable(Object)) return;
Object.Alpha = value;
}
}
}

public ushort LodDistance
{
get
{
lock (Object)
{
if (!AsyncContext.CheckIfExistsOrCachedNullable(Object)) return default;
return Object.LodDistance;
}
}
set
{
lock (Object)
{
if (!AsyncContext.CheckIfExistsNullable(Object)) return;
Object.LodDistance = value;
}
}
}

public void PlaceOnGroundProperly()
{
lock (Object)
{
if (!AsyncContext.CheckIfExistsNullable(Object)) return;
Object.PlaceOnGroundProperly();
}
}

public void ActivatePhysics()
{
lock (Object)
{
if (!AsyncContext.CheckIfExistsNullable(Object)) return;
Object.ActivatePhysics();
}
}

public byte TextureVariation
{
get
{
lock (Object)
{
if (!AsyncContext.CheckIfExistsOrCachedNullable(Object)) return default;
return Object.TextureVariation;
}
}
set
{
lock (Object)
{
if (!AsyncContext.CheckIfExistsNullable(Object)) return;
Object.TextureVariation = value;
}
}
}

[Obsolete("Use new async API instead")]
public IObject ToAsync(IAsyncContext asyncContext)
{
return this;
}
}
14 changes: 0 additions & 14 deletions api/AltV.Net.Async/Elements/Factories/AsyncNetworkObjectFactory.cs

This file was deleted.

14 changes: 14 additions & 0 deletions api/AltV.Net.Async/Elements/Factories/AsyncObjectFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using AltV.Net.Async.Elements.Entities;
using AltV.Net.Elements.Entities;

namespace AltV.Net.Async.Elements.Factories
{
public class AsyncObjectFactory : IEntityFactory<IObject>
{
public IObject Create(ICore core, IntPtr baseObjectPointer, uint id)
{
return new AsyncObject(core, baseObjectPointer, id);
}
}
}
6 changes: 3 additions & 3 deletions api/AltV.Net.CApi.Generator/TypeRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static class TypeRegistry
{ "alt::IVirtualEntityGroup**", "nint" },
{ "alt::IVehicle*", "nint" },
{ "alt::IAudioFilter*", "nint" },
{ "alt::INetworkObject*", "nint" },
{ "alt::IObject*", "nint" },
{ "alt::ITextLabel*", "nint" },
{ "alt::IVehicle**", "nint" },
{ "alt::IHandlingData*", "nint" },
Expand Down Expand Up @@ -185,8 +185,8 @@ public static class TypeRegistry
{ "alt::ICheckpoint*[]", "nint[]" },
{ "alt::ICheckpoint**", "nint" },
{ "alt::IWebView*[]", "nint[]" },
{ "alt::INetworkObject*[]", "nint[]" },
{ "alt::INetworkObject**", "nint" },
{ "alt::IObject*[]", "nint[]" },
{ "alt::IObject**", "nint" },
{ "alt::IColShape**", "nint" },
{ "alt::IAudio*[]", "nint[]" },
{ "alt::IMarker*[]", "nint[]" },
Expand Down
2 changes: 1 addition & 1 deletion api/AltV.Net.CApi/Enums/BaseObjectType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ public enum BaseObjectType : byte
Player,
Vehicle,
Ped,
NetworkObject,
Object,
Blip,
Webview,
VoiceChannel,
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 @@ -3440,7 +3440,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 != 12483615785659756931UL) Outdated = true;
else if (capiHash == IntPtr.Zero || *(ulong*)capiHash != 8496771753167776193UL) 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
Loading

0 comments on commit c491044

Please sign in to comment.