Skip to content

Commit

Permalink
add latest events
Browse files Browse the repository at this point in the history
  • Loading branch information
Doxoh committed Sep 23, 2023
1 parent 24a03ad commit 8218298
Show file tree
Hide file tree
Showing 15 changed files with 347 additions and 22 deletions.
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 @@ -536,6 +536,7 @@ public unsafe interface IClientLibrary
public delegate* unmanaged[Cdecl]<nint, float> Player_GetMicLevel { get; }
public delegate* unmanaged[Cdecl]<nint, float> Player_GetNonSpatialVolume { get; }
public delegate* unmanaged[Cdecl]<nint, float> Player_GetSpatialVolume { get; }
public delegate* unmanaged[Cdecl]<nint, int*, nint> Player_GetTaskData { get; }
public delegate* unmanaged[Cdecl]<nint, byte> Player_IsTalking { get; }
public delegate* unmanaged[Cdecl]<nint, void> Player_RemoveFilter { get; }
public delegate* unmanaged[Cdecl]<nint, float, void> Player_SetNonSpatialVolume { get; }
Expand Down Expand Up @@ -881,7 +882,7 @@ public unsafe interface IClientLibrary

public unsafe class ClientLibrary : IClientLibrary
{
public readonly uint Methods = 1715;
public readonly uint Methods = 1716;
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 @@ -1408,6 +1409,7 @@ public unsafe class ClientLibrary : IClientLibrary
public delegate* unmanaged[Cdecl]<nint, float> Player_GetMicLevel { get; }
public delegate* unmanaged[Cdecl]<nint, float> Player_GetNonSpatialVolume { get; }
public delegate* unmanaged[Cdecl]<nint, float> Player_GetSpatialVolume { get; }
public delegate* unmanaged[Cdecl]<nint, int*, nint> Player_GetTaskData { get; }
public delegate* unmanaged[Cdecl]<nint, byte> Player_IsTalking { get; }
public delegate* unmanaged[Cdecl]<nint, void> Player_RemoveFilter { get; }
public delegate* unmanaged[Cdecl]<nint, float, void> Player_SetNonSpatialVolume { get; }
Expand Down Expand Up @@ -2801,6 +2803,8 @@ public unsafe class ClientLibrary : IClientLibrary
private static float Player_GetNonSpatialVolumeFallback(nint _player) => throw new Exceptions.OutdatedSdkException("Player_GetNonSpatialVolume", "Player_GetNonSpatialVolume SDK method is outdated. Please update your module nuget");
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate float Player_GetSpatialVolumeDelegate(nint _player);
private static float Player_GetSpatialVolumeFallback(nint _player) => throw new Exceptions.OutdatedSdkException("Player_GetSpatialVolume", "Player_GetSpatialVolume SDK method is outdated. Please update your module nuget");
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate nint Player_GetTaskDataDelegate(nint _player, int* _size);
private static nint Player_GetTaskDataFallback(nint _player, int* _size) => throw new Exceptions.OutdatedSdkException("Player_GetTaskData", "Player_GetTaskData SDK method is outdated. Please update your module nuget");
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate byte Player_IsTalkingDelegate(nint _player);
private static byte Player_IsTalkingFallback(nint _player) => throw new Exceptions.OutdatedSdkException("Player_IsTalking", "Player_IsTalking SDK method is outdated. Please update your module nuget");
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate void Player_RemoveFilterDelegate(nint _player);
Expand Down Expand Up @@ -3492,7 +3496,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 != 10494575567167650847UL) Outdated = true;
else if (capiHash == IntPtr.Zero || *(ulong*)capiHash != 3088291357268716232UL) 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 @@ -4019,6 +4023,7 @@ public ClientLibrary(Dictionary<ulong, IntPtr> funcTable)
Player_GetMicLevel = (delegate* unmanaged[Cdecl]<nint, float>) GetUnmanagedPtr<Player_GetMicLevelDelegate>(funcTable, 15449156962697427469UL, Player_GetMicLevelFallback);
Player_GetNonSpatialVolume = (delegate* unmanaged[Cdecl]<nint, float>) GetUnmanagedPtr<Player_GetNonSpatialVolumeDelegate>(funcTable, 3333598534924196965UL, Player_GetNonSpatialVolumeFallback);
Player_GetSpatialVolume = (delegate* unmanaged[Cdecl]<nint, float>) GetUnmanagedPtr<Player_GetSpatialVolumeDelegate>(funcTable, 1924883508304421034UL, Player_GetSpatialVolumeFallback);
Player_GetTaskData = (delegate* unmanaged[Cdecl]<nint, int*, nint>) GetUnmanagedPtr<Player_GetTaskDataDelegate>(funcTable, 15465454396501521389UL, Player_GetTaskDataFallback);
Player_IsTalking = (delegate* unmanaged[Cdecl]<nint, byte>) GetUnmanagedPtr<Player_IsTalkingDelegate>(funcTable, 2228995248668686637UL, Player_IsTalkingFallback);
Player_RemoveFilter = (delegate* unmanaged[Cdecl]<nint, void>) GetUnmanagedPtr<Player_RemoveFilterDelegate>(funcTable, 14799984366573861130UL, Player_RemoveFilterFallback);
Player_SetNonSpatialVolume = (delegate* unmanaged[Cdecl]<nint, float, void>) GetUnmanagedPtr<Player_SetNonSpatialVolumeDelegate>(funcTable, 13836779891982146248UL, Player_SetNonSpatialVolumeFallback);
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 @@ -468,7 +468,7 @@ public unsafe interface IServerLibrary

public unsafe class ServerLibrary : IServerLibrary
{
public readonly uint Methods = 1715;
public readonly uint Methods = 1716;
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 @@ -1840,7 +1840,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 != 10494575567167650847UL) Outdated = true;
else if (capiHash == IntPtr.Zero || *(ulong*)capiHash != 3088291357268716232UL) 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
4 changes: 2 additions & 2 deletions api/AltV.Net.CApi/Libraries/SharedLibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ public unsafe interface ISharedLibrary

public unsafe class SharedLibrary : ISharedLibrary
{
public readonly uint Methods = 1715;
public readonly uint Methods = 1716;
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 @@ -1592,7 +1592,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 != 10494575567167650847UL) Outdated = true;
else if (capiHash == IntPtr.Zero || *(ulong*)capiHash != 3088291357268716232UL) 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
40 changes: 37 additions & 3 deletions api/AltV.Net.CApi/Native/AltV.Resource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,15 @@ internal delegate void CheckpointDelegate(IntPtr checkpointPointer, IntPtr entit
BaseObjectType baseObjectType,
byte state);

internal delegate void PlayerConnectDelegate(IntPtr playerPointer, ushort playerId, string reason);
internal delegate void PlayerConnectDelegate(IntPtr playerPointer, string reason);

internal delegate void PlayerConnectDeniedDelegate(PlayerConnectDeniedReason reason, string name, string ip,
ulong passwordHash, byte isDebug, string branch, uint majorVersion, string cdnUrl, long discordId);

internal delegate void ResourceEventDelegate(IntPtr resourcePointer);

internal delegate void PlayerDamageDelegate(IntPtr playerPointer, IntPtr attackerEntityPointer,
BaseObjectType attackerBaseObjectType,
ushort attackerEntityId, uint weapon, ushort healthDamage, ushort armourDamage);
BaseObjectType attackerBaseObjectType, uint weapon, ushort healthDamage, ushort armourDamage);

internal delegate void PlayerDeathDelegate(IntPtr playerPointer, IntPtr killerEntityPointer,
BaseObjectType killerBaseObjectType, uint weapon);
Expand Down Expand Up @@ -125,6 +124,21 @@ internal delegate void VehicleHornDelegate(IntPtr eventPointer, IntPtr targetPoi

internal delegate void GivePedScriptedTaskDelegate(IntPtr eventPointer, IntPtr source, IntPtr target, uint taskType);


internal delegate void PedDamageDelegate(IntPtr pedPointer, IntPtr attackerEntityPointer,
BaseObjectType attackerBaseObjectType, uint weapon, ushort healthDamage, ushort armourDamage);

internal delegate void PedDeathDelegate(IntPtr pedPointer, IntPtr killerEntityPointer,
BaseObjectType killerBaseObjectType, uint weapon);

internal delegate void PedHealDelegate(IntPtr pedPointer, ushort oldHealth, ushort newHealth,
ushort oldArmour, ushort newArmour);

internal delegate void PlayerStartTalkingDelegate(IntPtr playerPointer);

internal delegate void PlayerStopTalkingDelegate(IntPtr playerPointer);


[DllImport(DllName, CallingConvention = NativeCallingConvention)]
internal static extern void CSharpResourceImpl_SetMainDelegate(IntPtr resource,
MainDelegate @delegate);
Expand Down Expand Up @@ -324,6 +338,26 @@ internal static extern void CSharpResourceImpl_SetUpdateSyncedSceneDelegate(IntP
[DllImport(DllName, CallingConvention = NativeCallingConvention)]
internal static extern void CSharpResourceImpl_SetGivePedScriptedTaskDelegate(IntPtr resource,
GivePedScriptedTaskDelegate @delegate);

[DllImport(DllName, CallingConvention = NativeCallingConvention)]
internal static extern void CSharpResourceImpl_SetPedDamageDelegate(IntPtr resource,
PedDamageDelegate @delegate);

[DllImport(DllName, CallingConvention = NativeCallingConvention)]
internal static extern void CSharpResourceImpl_SetPedDeathDelegate(IntPtr resource,
PedDeathDelegate @delegate);

[DllImport(DllName, CallingConvention = NativeCallingConvention)]
internal static extern void CSharpResourceImpl_SetPedHealDelegate(IntPtr resource,
PedHealDelegate @delegate);

[DllImport(DllName, CallingConvention = NativeCallingConvention)]
internal static extern void CSharpResourceImpl_SetPlayerStartTalkingDelegate(IntPtr resource,
PlayerStartTalkingDelegate @delegate);

[DllImport(DllName, CallingConvention = NativeCallingConvention)]
internal static extern void CSharpResourceImpl_SetPlayerStopTalkingDelegate(IntPtr resource,
PlayerStopTalkingDelegate @delegate);
}
}
}
14 changes: 14 additions & 0 deletions api/AltV.Net.Client/Elements/Entities/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,20 @@ public IAudioFilter GetFilter()
}
}

public string TaskData
{
get
{
unsafe
{
CheckIfEntityExistsOrCached();
var size = 0;
return Core.PtrToStringUtf8AndFree(
Core.Library.Client.Player_GetTaskData(PlayerNativePointer, &size), size);
}
}
}

public IVehicle? Vehicle
{
get
Expand Down
2 changes: 2 additions & 0 deletions api/AltV.Net.Client/Elements/Interfaces/IPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@ public interface IPlayer : ISharedPlayer, IEntity
void AddFilter(IAudioFilter filter);
void RemoveFilter();
IAudioFilter GetFilter();

string TaskData { get; }
}
}
2 changes: 1 addition & 1 deletion api/AltV.Net.Mock/MockAltV.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public IPlayer ConnectPlayer(string playerName, string reason, Action<IPlayer> i
var player = Alt.Core.PoolManager.Player.Create(core, ptr, entityId);
//player.Name = playerName;
intercept?.Invoke(player);
Alt.CoreImpl.OnPlayerConnect(ptr, player.Id, reason);
Alt.CoreImpl.OnPlayerConnect(ptr, reason);
return player;
}
}
Expand Down
2 changes: 1 addition & 1 deletion api/AltV.Net.Mock/MockPlayer.Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static void Damage(this IPlayer player, IEntity attacker, uint weapon, by
player.Armor -= armourDamage;

Alt.CoreImpl.OnPlayerDamage(player.NativePointer, attacker?.NativePointer ?? IntPtr.Zero,
attacker?.Type ?? BaseObjectType.Undefined, attacker?.Id ?? 0, weapon, healthDamage, armourDamage);
attacker?.Type ?? BaseObjectType.Undefined, weapon, healthDamage, armourDamage);
}

public static void Death(this IPlayer player, IEntity killer, uint weapon)
Expand Down
6 changes: 6 additions & 0 deletions api/AltV.Net.Shared/Events/EventType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public enum EventType : byte
PLAYER_CHANGE_VEHICLE_SEAT,
PLAYER_WEAPON_CHANGE,
PLAYER_REQUEST_CONTROL,
PLAYER_START_TALKING,
PLAYER_STOP_TALKING,

VEHICLE_ATTACH,
VEHICLE_DETACH,
Expand Down Expand Up @@ -101,6 +103,10 @@ public enum EventType : byte

VOICE_CONNECTION_EVENT,

PED_DAMAGE,
PED_DEATH,
PED_HEAL,

ALL,
SIZE
}
Expand Down
30 changes: 30 additions & 0 deletions api/AltV.Net/Alt.Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -345,5 +345,35 @@ public static event GivePedScriptedTaskDelegate OnGivePedScriptedTask
add => CoreImpl.GivePedScriptedTaskHandler.Add(value);
remove => CoreImpl.GivePedScriptedTaskHandler.Remove(value);
}

public static event PedDamageDelegate OnPedDamage
{
add => CoreImpl.PedDamageEventHandler.Add(value);
remove => CoreImpl.PedDamageEventHandler.Remove(value);
}

public static event PedDeadDelegate OnPedDead
{
add => CoreImpl.PedDeadEventHandler.Add(value);
remove => CoreImpl.PedDeadEventHandler.Remove(value);
}

public static event PedHealDelegate OnPedHeal
{
add => CoreImpl.PedHealEventHandler.Add(value);
remove => CoreImpl.PedHealEventHandler.Remove(value);
}

public static event PlayerStartTalkingDelegate OnPlayerStartTalking
{
add => CoreImpl.PlayerStartTalkingHandler.Add(value);
remove => CoreImpl.PlayerStartTalkingHandler.Remove(value);
}

public static event PlayerStopTalkingDelegate OnPlayerStopTalking
{
add => CoreImpl.PlayerStopTalkingHandler.Add(value);
remove => CoreImpl.PlayerStopTalkingHandler.Remove(value);
}
}
}
21 changes: 21 additions & 0 deletions api/AltV.Net/CSharpResourceImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,27 @@ internal void SetDelegates(AltNative.Resource.MainDelegate onStart)
handles.AddFirst(GCHandle.Alloc(onGivePedScriptedTaskDelegate));
AltNative.Resource.CSharpResourceImpl_SetGivePedScriptedTaskDelegate(NativePointer, onGivePedScriptedTaskDelegate);


AltNative.Resource.PedDamageDelegate onPedDamage = ModuleWrapper.OnPedDamage;
handles.AddFirst(GCHandle.Alloc(onPedDamage));
AltNative.Resource.CSharpResourceImpl_SetPedDamageDelegate(NativePointer, onPedDamage);

AltNative.Resource.PedDeathDelegate onPedDeath = ModuleWrapper.OnPedDeath;
handles.AddFirst(GCHandle.Alloc(onPedDeath));
AltNative.Resource.CSharpResourceImpl_SetPedDeathDelegate(NativePointer, onPedDeath);

AltNative.Resource.PedHealDelegate onPedHeal = ModuleWrapper.OnPedHeal;
handles.AddFirst(GCHandle.Alloc(onPedHeal));
AltNative.Resource.CSharpResourceImpl_SetPedHealDelegate(NativePointer, onPedHeal);

AltNative.Resource.PlayerStartTalkingDelegate onPlayerStartTalking = ModuleWrapper.OnPlayerStartTalking;
handles.AddFirst(GCHandle.Alloc(onPlayerStartTalking));
AltNative.Resource.CSharpResourceImpl_SetPlayerStartTalkingDelegate(NativePointer, onPlayerStartTalking);

AltNative.Resource.PlayerStopTalkingDelegate onPlayerStopTalking = ModuleWrapper.OnPlayerStopTalking;
handles.AddFirst(GCHandle.Alloc(onPlayerStopTalking));
AltNative.Resource.CSharpResourceImpl_SetPlayerStopTalkingDelegate(NativePointer, onPlayerStopTalking);

}

public void Dispose()
Expand Down
Loading

0 comments on commit 8218298

Please sign in to comment.