Skip to content

Commit 43b5423

Browse files
committed
add PLAYER_BULLET_HIT_EVENT event
1 parent ca1dbf4 commit 43b5423

File tree

10 files changed

+37
-7
lines changed

10 files changed

+37
-7
lines changed

api/AltV.Net.CApi/Events/Events.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,7 @@ public delegate void EntityHitEntityModuleDelegate(IntPtr targetPointer, BaseObj
7979

8080
public delegate void PlayerStartEnterVehicleModuleDelegate(IntPtr targetPointer, IntPtr player, byte seat);
8181
public delegate void PlayerStartLeaveVehicleModuleDelegate(IntPtr targetPointer, IntPtr player, byte seat);
82+
83+
public delegate void PlayerBulletHitModuleDelegate(uint weapon, IntPtr victimPointer, BaseObjectType victimType,
84+
Position pos);
8285
}

api/AltV.Net.CApi/Libraries/ClientLibrary.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ public unsafe interface IClientLibrary
223223
public delegate* unmanaged[Cdecl]<nint, ClientEvents.LocalMetaChangeModuleDelegate, void> Event_SetLocalMetaChangeDelegate { get; }
224224
public delegate* unmanaged[Cdecl]<nint, ClientEvents.MetaChangeModuleDelegate, void> Event_SetMetaChangeDelegate { get; }
225225
public delegate* unmanaged[Cdecl]<nint, ClientEvents.NetOwnerChangeModuleDelegate, void> Event_SetNetOwnerChangeDelegate { get; }
226+
public delegate* unmanaged[Cdecl]<nint, ClientEvents.PlayerBulletHitModuleDelegate, void> Event_SetPlayerBulletHitDelegate { get; }
226227
public delegate* unmanaged[Cdecl]<nint, ClientEvents.PlayerChangeAnimationModuleDelegate, void> Event_SetPlayerChangeAnimationDelegate { get; }
227228
public delegate* unmanaged[Cdecl]<nint, ClientEvents.PlayerChangeInteriorModuleDelegate, void> Event_SetPlayerChangeInteriorDelegate { get; }
228229
public delegate* unmanaged[Cdecl]<nint, ClientEvents.PlayerChangeVehicleSeatModuleDelegate, void> Event_SetPlayerChangeVehicleSeatDelegate { get; }
@@ -816,7 +817,7 @@ public unsafe interface IClientLibrary
816817

817818
public unsafe class ClientLibrary : IClientLibrary
818819
{
819-
public readonly uint Methods = 1537;
820+
public readonly uint Methods = 1538;
820821
public delegate* unmanaged[Cdecl]<nint, nint, void> Audio_AddOutput_Entity { get; }
821822
public delegate* unmanaged[Cdecl]<nint, uint, void> Audio_AddOutput_ScriptId { get; }
822823
public delegate* unmanaged[Cdecl]<nint, nint> Audio_GetBaseObject { get; }
@@ -1030,6 +1031,7 @@ public unsafe class ClientLibrary : IClientLibrary
10301031
public delegate* unmanaged[Cdecl]<nint, ClientEvents.LocalMetaChangeModuleDelegate, void> Event_SetLocalMetaChangeDelegate { get; }
10311032
public delegate* unmanaged[Cdecl]<nint, ClientEvents.MetaChangeModuleDelegate, void> Event_SetMetaChangeDelegate { get; }
10321033
public delegate* unmanaged[Cdecl]<nint, ClientEvents.NetOwnerChangeModuleDelegate, void> Event_SetNetOwnerChangeDelegate { get; }
1034+
public delegate* unmanaged[Cdecl]<nint, ClientEvents.PlayerBulletHitModuleDelegate, void> Event_SetPlayerBulletHitDelegate { get; }
10331035
public delegate* unmanaged[Cdecl]<nint, ClientEvents.PlayerChangeAnimationModuleDelegate, void> Event_SetPlayerChangeAnimationDelegate { get; }
10341036
public delegate* unmanaged[Cdecl]<nint, ClientEvents.PlayerChangeInteriorModuleDelegate, void> Event_SetPlayerChangeInteriorDelegate { get; }
10351037
public delegate* unmanaged[Cdecl]<nint, ClientEvents.PlayerChangeVehicleSeatModuleDelegate, void> Event_SetPlayerChangeVehicleSeatDelegate { get; }
@@ -2045,6 +2047,8 @@ public unsafe class ClientLibrary : IClientLibrary
20452047
private static void Event_SetMetaChangeDelegateFallback(nint _resource, ClientEvents.MetaChangeModuleDelegate _delegate) => throw new Exceptions.OutdatedSdkException("Event_SetMetaChangeDelegate", "Event_SetMetaChangeDelegate SDK method is outdated. Please update your module nuget");
20462048
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate void Event_SetNetOwnerChangeDelegateDelegate(nint _resource, ClientEvents.NetOwnerChangeModuleDelegate _delegate);
20472049
private static void Event_SetNetOwnerChangeDelegateFallback(nint _resource, ClientEvents.NetOwnerChangeModuleDelegate _delegate) => throw new Exceptions.OutdatedSdkException("Event_SetNetOwnerChangeDelegate", "Event_SetNetOwnerChangeDelegate SDK method is outdated. Please update your module nuget");
2050+
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate void Event_SetPlayerBulletHitDelegateDelegate(nint _resource, ClientEvents.PlayerBulletHitModuleDelegate _delegate);
2051+
private static void Event_SetPlayerBulletHitDelegateFallback(nint _resource, ClientEvents.PlayerBulletHitModuleDelegate _delegate) => throw new Exceptions.OutdatedSdkException("Event_SetPlayerBulletHitDelegate", "Event_SetPlayerBulletHitDelegate SDK method is outdated. Please update your module nuget");
20482052
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate void Event_SetPlayerChangeAnimationDelegateDelegate(nint _resource, ClientEvents.PlayerChangeAnimationModuleDelegate _delegate);
20492053
private static void Event_SetPlayerChangeAnimationDelegateFallback(nint _resource, ClientEvents.PlayerChangeAnimationModuleDelegate _delegate) => throw new Exceptions.OutdatedSdkException("Event_SetPlayerChangeAnimationDelegate", "Event_SetPlayerChangeAnimationDelegate SDK method is outdated. Please update your module nuget");
20502054
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate void Event_SetPlayerChangeInteriorDelegateDelegate(nint _resource, ClientEvents.PlayerChangeInteriorModuleDelegate _delegate);
@@ -3232,7 +3236,7 @@ private IntPtr GetUnmanagedPtr<T>(IDictionary<ulong, IntPtr> funcTable, ulong ha
32323236
public ClientLibrary(Dictionary<ulong, IntPtr> funcTable)
32333237
{
32343238
if (!funcTable.TryGetValue(0, out var capiHash)) Outdated = true;
3235-
else if (capiHash == IntPtr.Zero || *(ulong*)capiHash != 18419608128736389916UL) Outdated = true;
3239+
else if (capiHash == IntPtr.Zero || *(ulong*)capiHash != 11688032597971807811UL) Outdated = true;
32363240
Audio_AddOutput_Entity = (delegate* unmanaged[Cdecl]<nint, nint, void>) GetUnmanagedPtr<Audio_AddOutput_EntityDelegate>(funcTable, 9879036518735269522UL, Audio_AddOutput_EntityFallback);
32373241
Audio_AddOutput_ScriptId = (delegate* unmanaged[Cdecl]<nint, uint, void>) GetUnmanagedPtr<Audio_AddOutput_ScriptIdDelegate>(funcTable, 14116998947805478300UL, Audio_AddOutput_ScriptIdFallback);
32383242
Audio_GetBaseObject = (delegate* unmanaged[Cdecl]<nint, nint>) GetUnmanagedPtr<Audio_GetBaseObjectDelegate>(funcTable, 6330360502401226894UL, Audio_GetBaseObjectFallback);
@@ -3446,6 +3450,7 @@ public ClientLibrary(Dictionary<ulong, IntPtr> funcTable)
34463450
Event_SetLocalMetaChangeDelegate = (delegate* unmanaged[Cdecl]<nint, ClientEvents.LocalMetaChangeModuleDelegate, void>) GetUnmanagedPtr<Event_SetLocalMetaChangeDelegateDelegate>(funcTable, 1555813148561817401UL, Event_SetLocalMetaChangeDelegateFallback);
34473451
Event_SetMetaChangeDelegate = (delegate* unmanaged[Cdecl]<nint, ClientEvents.MetaChangeModuleDelegate, void>) GetUnmanagedPtr<Event_SetMetaChangeDelegateDelegate>(funcTable, 10052271841742065911UL, Event_SetMetaChangeDelegateFallback);
34483452
Event_SetNetOwnerChangeDelegate = (delegate* unmanaged[Cdecl]<nint, ClientEvents.NetOwnerChangeModuleDelegate, void>) GetUnmanagedPtr<Event_SetNetOwnerChangeDelegateDelegate>(funcTable, 15651483423859541657UL, Event_SetNetOwnerChangeDelegateFallback);
3453+
Event_SetPlayerBulletHitDelegate = (delegate* unmanaged[Cdecl]<nint, ClientEvents.PlayerBulletHitModuleDelegate, void>) GetUnmanagedPtr<Event_SetPlayerBulletHitDelegateDelegate>(funcTable, 17879780001793566297UL, Event_SetPlayerBulletHitDelegateFallback);
34493454
Event_SetPlayerChangeAnimationDelegate = (delegate* unmanaged[Cdecl]<nint, ClientEvents.PlayerChangeAnimationModuleDelegate, void>) GetUnmanagedPtr<Event_SetPlayerChangeAnimationDelegateDelegate>(funcTable, 1013031841840963141UL, Event_SetPlayerChangeAnimationDelegateFallback);
34503455
Event_SetPlayerChangeInteriorDelegate = (delegate* unmanaged[Cdecl]<nint, ClientEvents.PlayerChangeInteriorModuleDelegate, void>) GetUnmanagedPtr<Event_SetPlayerChangeInteriorDelegateDelegate>(funcTable, 10641081887455190199UL, Event_SetPlayerChangeInteriorDelegateFallback);
34513456
Event_SetPlayerChangeVehicleSeatDelegate = (delegate* unmanaged[Cdecl]<nint, ClientEvents.PlayerChangeVehicleSeatModuleDelegate, void>) GetUnmanagedPtr<Event_SetPlayerChangeVehicleSeatDelegateDelegate>(funcTable, 2849447755791784577UL, Event_SetPlayerChangeVehicleSeatDelegateFallback);

api/AltV.Net.CApi/Libraries/ServerLibrary.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ public unsafe interface IServerLibrary
411411

412412
public unsafe class ServerLibrary : IServerLibrary
413413
{
414-
public readonly uint Methods = 1537;
414+
public readonly uint Methods = 1538;
415415
public delegate* unmanaged[Cdecl]<nint, nint, void> BaseObject_DeleteSyncedMetaData { get; }
416416
public delegate* unmanaged[Cdecl]<nint, nint, nint, void> BaseObject_SetSyncedMetaData { get; }
417417
public delegate* unmanaged[Cdecl]<nint, BaseObjectType*, nint> Blip_AttachedTo { get; }
@@ -1612,7 +1612,7 @@ private IntPtr GetUnmanagedPtr<T>(IDictionary<ulong, IntPtr> funcTable, ulong ha
16121612
public ServerLibrary(Dictionary<ulong, IntPtr> funcTable)
16131613
{
16141614
if (!funcTable.TryGetValue(0, out var capiHash)) Outdated = true;
1615-
else if (capiHash == IntPtr.Zero || *(ulong*)capiHash != 18419608128736389916UL) Outdated = true;
1615+
else if (capiHash == IntPtr.Zero || *(ulong*)capiHash != 11688032597971807811UL) Outdated = true;
16161616
BaseObject_DeleteSyncedMetaData = (delegate* unmanaged[Cdecl]<nint, nint, void>) GetUnmanagedPtr<BaseObject_DeleteSyncedMetaDataDelegate>(funcTable, 8228424877092269355UL, BaseObject_DeleteSyncedMetaDataFallback);
16171617
BaseObject_SetSyncedMetaData = (delegate* unmanaged[Cdecl]<nint, nint, nint, void>) GetUnmanagedPtr<BaseObject_SetSyncedMetaDataDelegate>(funcTable, 8002999088966424231UL, BaseObject_SetSyncedMetaDataFallback);
16181618
Blip_AttachedTo = (delegate* unmanaged[Cdecl]<nint, BaseObjectType*, nint>) GetUnmanagedPtr<Blip_AttachedToDelegate>(funcTable, 15602966080933483258UL, Blip_AttachedToFallback);

api/AltV.Net.CApi/Libraries/SharedLibrary.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ public unsafe interface ISharedLibrary
350350

351351
public unsafe class SharedLibrary : ISharedLibrary
352352
{
353-
public readonly uint Methods = 1537;
353+
public readonly uint Methods = 1538;
354354
public delegate* unmanaged[Cdecl]<nint, uint> Audio_GetID { get; }
355355
public delegate* unmanaged[Cdecl]<nint, nint, void> BaseObject_DeleteMetaData { get; }
356356
public delegate* unmanaged[Cdecl]<nint, void> BaseObject_DestructCache { get; }
@@ -1368,7 +1368,7 @@ private IntPtr GetUnmanagedPtr<T>(IDictionary<ulong, IntPtr> funcTable, ulong ha
13681368
public SharedLibrary(Dictionary<ulong, IntPtr> funcTable)
13691369
{
13701370
if (!funcTable.TryGetValue(0, out var capiHash)) Outdated = true;
1371-
else if (capiHash == IntPtr.Zero || *(ulong*)capiHash != 18419608128736389916UL) Outdated = true;
1371+
else if (capiHash == IntPtr.Zero || *(ulong*)capiHash != 11688032597971807811UL) Outdated = true;
13721372
Audio_GetID = (delegate* unmanaged[Cdecl]<nint, uint>) GetUnmanagedPtr<Audio_GetIDDelegate>(funcTable, 4464042055475980737UL, Audio_GetIDFallback);
13731373
BaseObject_DeleteMetaData = (delegate* unmanaged[Cdecl]<nint, nint, void>) GetUnmanagedPtr<BaseObject_DeleteMetaDataDelegate>(funcTable, 8032676411671743849UL, BaseObject_DeleteMetaDataFallback);
13741374
BaseObject_DestructCache = (delegate* unmanaged[Cdecl]<nint, void>) GetUnmanagedPtr<BaseObject_DestructCacheDelegate>(funcTable, 6691163275156255752UL, BaseObject_DestructCacheFallback);

api/AltV.Net.Client/Core.Events.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ public virtual IEnumerable<string> GetRegisteredServerEvents()
148148
internal readonly IEventHandler<EntityHitEntityDelegate> EntityHitEntityEventHandler =
149149
new HashSetEventHandler<EntityHitEntityDelegate>(EventType.ENTITY_HIT_ENTITY);
150150

151+
internal readonly IEventHandler<PlayerBulletHitDelegate> PlayerBulletHitEventHandler =
152+
new HashSetEventHandler<PlayerBulletHitDelegate>(EventType.PLAYER_BULLET_HIT_EVENT);
153+
151154

152155
public void OnServerEvent(string name, IntPtr[] args)
153156
{
@@ -635,5 +638,12 @@ public void OnEntityHitEntity(IntPtr targetpointer, BaseObjectType targettype, I
635638

636639
EntityHitEntityEventHandler.GetEvents().ForEachCatching(fn => fn(target, damager, weaponhash), $"event {nameof(OnEntityHitEntity)}");
637640
}
641+
642+
public void OnPlayerBulletHit(uint weapon, IntPtr victimPointer, BaseObjectType victimType, Position pos)
643+
{
644+
var victim = (IEntity)PoolManager.Get(victimPointer, victimType);
645+
646+
PlayerBulletHitEventHandler.GetEvents().ForEachCatching(fn => fn(weapon, victim, pos), $"event {nameof(OnPlayerBulletHit)}");
647+
}
638648
}
639649
}

api/AltV.Net.Client/Events/Events.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ public delegate bool WeaponDamageDelegate(IEntity target, uint weapon, ushort da
5858
public delegate void PlayerStartLeaveVehicleDelegate(IVehicle vehicle, IPlayer player, byte seat);
5959
public delegate void EntityHitEntityDelegate(IEntity target, IEntity damager, uint weaponHash);
6060

61+
public delegate void PlayerBulletHitDelegate(uint weapon, IEntity victim, Position position);
62+
6163

6264

6365
}

api/AltV.Net.Client/ModuleWrapper.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,5 +417,10 @@ public static void OnEntityHitEntity(IntPtr targetpointer, BaseObjectType target
417417
{
418418
_core.OnEntityHitEntity(targetpointer, targettype, damagerpointer, damagertype, weaponhash);
419419
}
420+
421+
public static void OnPlayerBulletHit(uint weapon, IntPtr victimpointer, BaseObjectType victimtype, Position pos)
422+
{
423+
_core.OnPlayerBulletHit(weapon, victimpointer, victimtype, pos);
424+
}
420425
}
421426
}

api/AltV.Net.Client/Runtime/CSharpResourceImpl.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,10 @@ internal void SetDelegates()
196196
PlayerStartLeaveVehicleModuleDelegate onPlayerStartLeaveVehicle = ModuleWrapper.OnPlayerStartLeaveVehicle;
197197
handles.AddFirst(GCHandle.Alloc(onPlayerStartLeaveVehicle));
198198
core.Library.Client.Event_SetPlayerStartLeaveVehicleDelegate(this.NativePointer, onPlayerStartLeaveVehicle);
199+
200+
PlayerBulletHitModuleDelegate onPlayerBulletHit = ModuleWrapper.OnPlayerBulletHit;
201+
handles.AddFirst(GCHandle.Alloc(onPlayerBulletHit));
202+
core.Library.Client.Event_SetPlayerBulletHitDelegate(this.NativePointer, onPlayerBulletHit);
199203
}
200204
}
201205

api/AltV.Net.Shared/Events/EventType.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public enum EventType : byte
6868
PLAYER_CHANGE_INTERIOR_EVENT,
6969

7070
PLAYER_WEAPON_SHOOT_EVENT,
71+
PLAYER_BULLET_HIT_EVENT,
7172

7273
PLAYER_DIMENSION_CHANGE,
7374

runtime

0 commit comments

Comments
 (0)