Skip to content

Commit

Permalink
feat(client): add debug infos
Browse files Browse the repository at this point in the history
  • Loading branch information
Doxoh committed Jan 7, 2024
1 parent 9f02fd1 commit fbc5090
Show file tree
Hide file tree
Showing 8 changed files with 167 additions and 15 deletions.
8 changes: 1 addition & 7 deletions api/AltV.Net.CApi.Generator/TypeRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,19 +112,15 @@ public static class TypeRegistry
{ "rgba_t", "Rgba" },
{ "rgba_t&", "Rgba*" },
{ "std::vector<uint32_t>", "UIntArray*" },

{ "alt::Quaternion", "Quaternion" },
{ "alt::Quaternion&", "Quaternion*" },

{ "position_t&", "Vector3*" },
{ "position_t", "Vector3" },
{ "alt::Position", "Vector3" },
{ "rotation_t&", "Rotation*" },
{ "rotation_t", "Rotation" },
{ "alt::Rotation", "Rotation" },

{ "vehicleBadgePosition_t[]", "VehicleBadgePosition[]" },

{ "cloth_t&", "Cloth*" },
{ "cloth_t", "Cloth" },
{ "dlccloth_t&", "DlcCloth*" },
Expand Down Expand Up @@ -170,9 +166,7 @@ public static class TypeRegistry
{ "const alt::MValueList&", "MValue*" }, //no c# representation for MValue list memory layout yet
{ "alt::MValueDict&", "MValue*" }, //no c# representation for MValue dictionary memory layout yet
{ "alt::ICheckpoint*", "nint" },
{
"alt::MValueFunction&", "MValue*"
}, //no c# representation for MValue function memory layout yet, this is only in commented code and not required
{ "alt::MValueFunction&", "MValue*" }, //no c# representation for MValue function memory layout yet, this is only in commented code and not required
{ "alt::CEvent::Type", "ushort" },
{ "alt::CEvent*", "nint" },
{ "alt::CCancellableEvent*", "nint" },
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 @@ -273,6 +273,7 @@ public unsafe interface IClientLibrary
public delegate* unmanaged[Cdecl]<nint, nint> CustomTexture_GetBaseObject { get; }
public delegate* unmanaged[Cdecl]<nint, uint> CustomTexture_GetID { get; }
public delegate* unmanaged[Cdecl]<nint, uint> Entity_GetScriptID { get; }
public delegate* unmanaged[Cdecl]<nint, nint*, void> Entity_GetSyncInfo { get; }
public delegate* unmanaged[Cdecl]<nint, ClientEvents.AnyResourceErrorModuleDelegate, void> Event_SetAnyResourceErrorDelegate { get; }
public delegate* unmanaged[Cdecl]<nint, ClientEvents.AnyResourceStartModuleDelegate, void> Event_SetAnyResourceStartDelegate { get; }
public delegate* unmanaged[Cdecl]<nint, ClientEvents.AnyResourceStopModuleDelegate, void> Event_SetAnyResourceStopDelegate { get; }
Expand Down Expand Up @@ -900,7 +901,7 @@ public unsafe interface IClientLibrary

public unsafe class ClientLibrary : IClientLibrary
{
public readonly uint Methods = 1767;
public readonly uint Methods = 1769;
public delegate* unmanaged[Cdecl]<nint, nint, void> Audio_AddOutput { get; }
public delegate* unmanaged[Cdecl]<nint, nint> Audio_GetBaseObject { get; }
public delegate* unmanaged[Cdecl]<nint, double> Audio_GetCurrentTime { get; }
Expand Down Expand Up @@ -1163,6 +1164,7 @@ public unsafe class ClientLibrary : IClientLibrary
public delegate* unmanaged[Cdecl]<nint, nint> CustomTexture_GetBaseObject { get; }
public delegate* unmanaged[Cdecl]<nint, uint> CustomTexture_GetID { get; }
public delegate* unmanaged[Cdecl]<nint, uint> Entity_GetScriptID { get; }
public delegate* unmanaged[Cdecl]<nint, nint*, void> Entity_GetSyncInfo { get; }
public delegate* unmanaged[Cdecl]<nint, ClientEvents.AnyResourceErrorModuleDelegate, void> Event_SetAnyResourceErrorDelegate { get; }
public delegate* unmanaged[Cdecl]<nint, ClientEvents.AnyResourceStartModuleDelegate, void> Event_SetAnyResourceStartDelegate { get; }
public delegate* unmanaged[Cdecl]<nint, ClientEvents.AnyResourceStopModuleDelegate, void> Event_SetAnyResourceStopDelegate { get; }
Expand Down Expand Up @@ -2310,6 +2312,8 @@ public unsafe class ClientLibrary : IClientLibrary
private static uint CustomTexture_GetIDFallback(nint _costumTexture) => throw new Exceptions.OutdatedSdkException("CustomTexture_GetID", "CustomTexture_GetID SDK method is outdated. Please update your module nuget");
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate uint Entity_GetScriptIDDelegate(nint _entity);
private static uint Entity_GetScriptIDFallback(nint _entity) => throw new Exceptions.OutdatedSdkException("Entity_GetScriptID", "Entity_GetScriptID SDK method is outdated. Please update your module nuget");
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate void Entity_GetSyncInfoDelegate(nint _entity, nint* _syncInfo);
private static void Entity_GetSyncInfoFallback(nint _entity, nint* _syncInfo) => throw new Exceptions.OutdatedSdkException("Entity_GetSyncInfo", "Entity_GetSyncInfo SDK method is outdated. Please update your module nuget");
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate void Event_SetAnyResourceErrorDelegateDelegate(nint _resource, ClientEvents.AnyResourceErrorModuleDelegate _delegate);
private static void Event_SetAnyResourceErrorDelegateFallback(nint _resource, ClientEvents.AnyResourceErrorModuleDelegate _delegate) => throw new Exceptions.OutdatedSdkException("Event_SetAnyResourceErrorDelegate", "Event_SetAnyResourceErrorDelegate SDK method is outdated. Please update your module nuget");
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate void Event_SetAnyResourceStartDelegateDelegate(nint _resource, ClientEvents.AnyResourceStartModuleDelegate _delegate);
Expand Down Expand Up @@ -3565,7 +3569,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 != 16106728582837015091UL) Outdated = true;
else if (capiHash == IntPtr.Zero || *(ulong*)capiHash != 12612033657027659340UL) 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 Expand Up @@ -3828,6 +3832,7 @@ public ClientLibrary(Dictionary<ulong, IntPtr> funcTable)
CustomTexture_GetBaseObject = (delegate* unmanaged[Cdecl]<nint, nint>) GetUnmanagedPtr<CustomTexture_GetBaseObjectDelegate>(funcTable, 4168880360490742954UL, CustomTexture_GetBaseObjectFallback);
CustomTexture_GetID = (delegate* unmanaged[Cdecl]<nint, uint>) GetUnmanagedPtr<CustomTexture_GetIDDelegate>(funcTable, 12755828446518747613UL, CustomTexture_GetIDFallback);
Entity_GetScriptID = (delegate* unmanaged[Cdecl]<nint, uint>) GetUnmanagedPtr<Entity_GetScriptIDDelegate>(funcTable, 11915813456855488252UL, Entity_GetScriptIDFallback);
Entity_GetSyncInfo = (delegate* unmanaged[Cdecl]<nint, nint*, void>) GetUnmanagedPtr<Entity_GetSyncInfoDelegate>(funcTable, 18237250479106097113UL, Entity_GetSyncInfoFallback);
Event_SetAnyResourceErrorDelegate = (delegate* unmanaged[Cdecl]<nint, ClientEvents.AnyResourceErrorModuleDelegate, void>) GetUnmanagedPtr<Event_SetAnyResourceErrorDelegateDelegate>(funcTable, 14079997901958077241UL, Event_SetAnyResourceErrorDelegateFallback);
Event_SetAnyResourceStartDelegate = (delegate* unmanaged[Cdecl]<nint, ClientEvents.AnyResourceStartModuleDelegate, void>) GetUnmanagedPtr<Event_SetAnyResourceStartDelegateDelegate>(funcTable, 18259284189737259993UL, Event_SetAnyResourceStartDelegateFallback);
Event_SetAnyResourceStopDelegate = (delegate* unmanaged[Cdecl]<nint, ClientEvents.AnyResourceStopModuleDelegate, void>) GetUnmanagedPtr<Event_SetAnyResourceStopDelegateDelegate>(funcTable, 13707820718504089625UL, Event_SetAnyResourceStopDelegateFallback);
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 @@ -485,7 +485,7 @@ public unsafe interface IServerLibrary

public unsafe class ServerLibrary : IServerLibrary
{
public readonly uint Methods = 1767;
public readonly uint Methods = 1769;
public delegate* unmanaged[Cdecl]<nint, nint, void> BaseObject_DeleteSyncedMetaData { get; }
public delegate* unmanaged[Cdecl]<nint, nint[], nint[], ulong, void> BaseObject_SetMultipleSyncedMetaData { get; }
public delegate* unmanaged[Cdecl]<nint, nint, nint, void> BaseObject_SetSyncedMetaData { get; }
Expand Down Expand Up @@ -1905,7 +1905,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 != 16106728582837015091UL) Outdated = true;
else if (capiHash == IntPtr.Zero || *(ulong*)capiHash != 12612033657027659340UL) 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
9 changes: 7 additions & 2 deletions api/AltV.Net.CApi/Libraries/SharedLibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ public unsafe interface ISharedLibrary
public delegate* unmanaged[Cdecl]<nint, void> FreeResourceArray { get; }
public delegate* unmanaged[Cdecl]<nint, void> FreeString { get; }
public delegate* unmanaged[Cdecl]<nint, uint, void> FreeStringArray { get; }
public delegate* unmanaged[Cdecl]<nint, void> FreeSyncInfo { get; }
public delegate* unmanaged[Cdecl]<nint, void> FreeTextLabelArray { get; }
public delegate* unmanaged[Cdecl]<nint, void> FreeUInt32Array { get; }
public delegate* unmanaged[Cdecl]<nint, void> FreeUInt8Array { get; }
Expand Down Expand Up @@ -425,7 +426,7 @@ public unsafe interface ISharedLibrary

public unsafe class SharedLibrary : ISharedLibrary
{
public readonly uint Methods = 1767;
public readonly uint Methods = 1769;
public delegate* unmanaged[Cdecl]<nint, uint> Audio_GetID { get; }
public delegate* unmanaged[Cdecl]<nint, uint> AudioAttachedOutput_GetID { get; }
public delegate* unmanaged[Cdecl]<nint, uint> AudioFilter_GetID { get; }
Expand Down Expand Up @@ -662,6 +663,7 @@ public unsafe class SharedLibrary : ISharedLibrary
public delegate* unmanaged[Cdecl]<nint, void> FreeResourceArray { get; }
public delegate* unmanaged[Cdecl]<nint, void> FreeString { get; }
public delegate* unmanaged[Cdecl]<nint, uint, void> FreeStringArray { get; }
public delegate* unmanaged[Cdecl]<nint, void> FreeSyncInfo { get; }
public delegate* unmanaged[Cdecl]<nint, void> FreeTextLabelArray { get; }
public delegate* unmanaged[Cdecl]<nint, void> FreeUInt32Array { get; }
public delegate* unmanaged[Cdecl]<nint, void> FreeUInt8Array { get; }
Expand Down Expand Up @@ -1308,6 +1310,8 @@ public unsafe class SharedLibrary : ISharedLibrary
private static void FreeStringFallback(nint _string) => throw new Exceptions.OutdatedSdkException("FreeString", "FreeString SDK method is outdated. Please update your module nuget");
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate void FreeStringArrayDelegate(nint _stringArray, uint _size);
private static void FreeStringArrayFallback(nint _stringArray, uint _size) => throw new Exceptions.OutdatedSdkException("FreeStringArray", "FreeStringArray SDK method is outdated. Please update your module nuget");
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate void FreeSyncInfoDelegate(nint _syncInfo);
private static void FreeSyncInfoFallback(nint _syncInfo) => throw new Exceptions.OutdatedSdkException("FreeSyncInfo", "FreeSyncInfo SDK method is outdated. Please update your module nuget");
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate void FreeTextLabelArrayDelegate(nint _textLabelArray);
private static void FreeTextLabelArrayFallback(nint _textLabelArray) => throw new Exceptions.OutdatedSdkException("FreeTextLabelArray", "FreeTextLabelArray SDK method is outdated. Please update your module nuget");
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate void FreeUInt32ArrayDelegate(nint _uInt32Array);
Expand Down Expand Up @@ -1665,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 != 16106728582837015091UL) Outdated = true;
else if (capiHash == IntPtr.Zero || *(ulong*)capiHash != 12612033657027659340UL) 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 Expand Up @@ -1902,6 +1906,7 @@ public SharedLibrary(Dictionary<ulong, IntPtr> funcTable)
FreeResourceArray = (delegate* unmanaged[Cdecl]<nint, void>) GetUnmanagedPtr<FreeResourceArrayDelegate>(funcTable, 7782187912558785270UL, FreeResourceArrayFallback);
FreeString = (delegate* unmanaged[Cdecl]<nint, void>) GetUnmanagedPtr<FreeStringDelegate>(funcTable, 10646355260907021718UL, FreeStringFallback);
FreeStringArray = (delegate* unmanaged[Cdecl]<nint, uint, void>) GetUnmanagedPtr<FreeStringArrayDelegate>(funcTable, 9817201133426969670UL, FreeStringArrayFallback);
FreeSyncInfo = (delegate* unmanaged[Cdecl]<nint, void>) GetUnmanagedPtr<FreeSyncInfoDelegate>(funcTable, 756563802353195975UL, FreeSyncInfoFallback);
FreeTextLabelArray = (delegate* unmanaged[Cdecl]<nint, void>) GetUnmanagedPtr<FreeTextLabelArrayDelegate>(funcTable, 247876811202044668UL, FreeTextLabelArrayFallback);
FreeUInt32Array = (delegate* unmanaged[Cdecl]<nint, void>) GetUnmanagedPtr<FreeUInt32ArrayDelegate>(funcTable, 2025110884526748511UL, FreeUInt32ArrayFallback);
FreeUInt8Array = (delegate* unmanaged[Cdecl]<nint, void>) GetUnmanagedPtr<FreeUInt8ArrayDelegate>(funcTable, 15676846424137302955UL, FreeUInt8ArrayFallback);
Expand Down
125 changes: 125 additions & 0 deletions api/AltV.Net.Client/Elements/Data/SyncInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
using System.Runtime.InteropServices;
using AltV.Net.Data;

namespace AltV.Net.Client.Elements.Data;


[StructLayout(LayoutKind.Sequential)]
internal struct SyncInfoInternal
{
public byte Active;
public uint ReceivedTick;
public uint FullyReceivedTick;
public uint SendTick;
public uint AckedSendTick;
public ushort PropertyCount;
public byte ComponentCount;
public IntPtr PropertiesUpdateTick;
public IntPtr ComponentPropertyIndex;

public uint[] GetPropertiesUpdateTick()
{
if (PropertyCount == 0)
{
return Array.Empty<uint>();
}

var value = ComponentPropertyIndex;
var values = new uint[PropertyCount];
var buffer = new byte[4];

for (var i = 0; i < values.Length; i++)
{
values[i] = UIntArray.ReadUInt32(buffer, value);
value += UIntArray.UInt32Size;
}

return values;
}

public uint[] GetComponentPropertyIndex()
{
if (ComponentCount == 0)
{
return Array.Empty<uint>();
}

var value = ComponentPropertyIndex;
var values = new uint[ComponentCount];
var buffer = new byte[4];

for (var i = 0; i < values.Length; i++)
{
values[i] = UIntArray.ReadUInt32(buffer, value);
value += UIntArray.UInt32Size;
}

return values;
}

public SyncInfo ToPublic()
{
return new SyncInfo(
Active,
ReceivedTick,
FullyReceivedTick,
SendTick,
AckedSendTick,
PropertyCount,
ComponentCount,
GetPropertiesUpdateTick(),
GetComponentPropertyIndex());
}
}

[StructLayout(LayoutKind.Sequential)]
public struct SyncInfo : IEquatable<SyncInfo>
{
public byte Active;
public uint ReceivedTick;
public uint FullyReceivedTick;
public uint SendTick;
public uint AckedSendTick;
public ushort PropertyCount;
public byte ComponentCount;
public uint[] PropertiesUpdateTick;
public uint[] ComponentPropertyIndex;

public SyncInfo(byte active, uint receivedTick, uint fullyReceivedTick, uint sendTick, uint ackedSendTick, ushort propertyCount, byte componentCount, uint[] propertiesUpdateTick, uint[] componentPropertyIndex)
{
Active = active;
ReceivedTick = receivedTick;
FullyReceivedTick = fullyReceivedTick;
SendTick = sendTick;
AckedSendTick = ackedSendTick;
PropertyCount = propertyCount;
ComponentCount = componentCount;
PropertiesUpdateTick = propertiesUpdateTick;
ComponentPropertyIndex = componentPropertyIndex;
}

public bool Equals(SyncInfo other)
{
return Active == other.Active && ReceivedTick == other.ReceivedTick && FullyReceivedTick == other.FullyReceivedTick && SendTick == other.SendTick && AckedSendTick == other.AckedSendTick && PropertyCount == other.PropertyCount && ComponentCount == other.ComponentCount && PropertiesUpdateTick.Equals(other.PropertiesUpdateTick) && ComponentPropertyIndex.Equals(other.ComponentPropertyIndex);
}

public override bool Equals(object obj)
{
return obj is SyncInfo other && Equals(other);
}

public override int GetHashCode()
{
var hashCode = new HashCode();
hashCode.Add(Active);
hashCode.Add(ReceivedTick);
hashCode.Add(FullyReceivedTick);
hashCode.Add(SendTick);
hashCode.Add(AckedSendTick);
hashCode.Add(PropertyCount);
hashCode.Add(ComponentCount);
hashCode.Add(PropertiesUpdateTick);
hashCode.Add(ComponentPropertyIndex);
return hashCode.ToHashCode();
}
}
21 changes: 21 additions & 0 deletions api/AltV.Net.Client/Elements/Entities/Entity.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using AltV.Net.Client.Elements.Data;
using AltV.Net.Client.Elements.Interfaces;
using AltV.Net.Data;
using AltV.Net.Elements.Args;
Expand Down Expand Up @@ -67,6 +68,26 @@ public uint ScriptId
}
}

public SyncInfo SyncInfo
{
get
{
unsafe
{
CheckIfEntityExistsOrCached();

var syncInfoPtr = IntPtr.Zero;
Core.Library.Client.Entity_GetSyncInfo(EntityNativePointer, &syncInfoPtr);

var syncInfo = Marshal.PtrToStructure<SyncInfoInternal>(syncInfoPtr).ToPublic();

Core.Library.Shared.FreeSyncInfo(syncInfoPtr);

return syncInfo;
}
}
}

public bool Spawned => ScriptId != 0;

public Position Position
Expand Down
Loading

0 comments on commit fbc5090

Please sign in to comment.