diff --git a/api/AltV.Net.CApi/Libraries/ClientLibrary.cs b/api/AltV.Net.CApi/Libraries/ClientLibrary.cs index 4998f5341..072d181ca 100644 --- a/api/AltV.Net.CApi/Libraries/ClientLibrary.cs +++ b/api/AltV.Net.CApi/Libraries/ClientLibrary.cs @@ -536,6 +536,7 @@ public unsafe interface IClientLibrary public delegate* unmanaged[Cdecl] Player_GetMicLevel { get; } public delegate* unmanaged[Cdecl] Player_GetNonSpatialVolume { get; } public delegate* unmanaged[Cdecl] Player_GetSpatialVolume { get; } + public delegate* unmanaged[Cdecl] Player_GetTaskData { get; } public delegate* unmanaged[Cdecl] Player_IsTalking { get; } public delegate* unmanaged[Cdecl] Player_RemoveFilter { get; } public delegate* unmanaged[Cdecl] Player_SetNonSpatialVolume { get; } @@ -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] Audio_AddOutput { get; } public delegate* unmanaged[Cdecl] Audio_GetBaseObject { get; } public delegate* unmanaged[Cdecl] Audio_GetCurrentTime { get; } @@ -1408,6 +1409,7 @@ public unsafe class ClientLibrary : IClientLibrary public delegate* unmanaged[Cdecl] Player_GetMicLevel { get; } public delegate* unmanaged[Cdecl] Player_GetNonSpatialVolume { get; } public delegate* unmanaged[Cdecl] Player_GetSpatialVolume { get; } + public delegate* unmanaged[Cdecl] Player_GetTaskData { get; } public delegate* unmanaged[Cdecl] Player_IsTalking { get; } public delegate* unmanaged[Cdecl] Player_RemoveFilter { get; } public delegate* unmanaged[Cdecl] Player_SetNonSpatialVolume { get; } @@ -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); @@ -3492,7 +3496,7 @@ private IntPtr GetUnmanagedPtr(IDictionary funcTable, ulong ha public ClientLibrary(Dictionary 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]) GetUnmanagedPtr(funcTable, 9914412815391408844UL, Audio_AddOutputFallback); Audio_GetBaseObject = (delegate* unmanaged[Cdecl]) GetUnmanagedPtr(funcTable, 6330360502401226894UL, Audio_GetBaseObjectFallback); Audio_GetCurrentTime = (delegate* unmanaged[Cdecl]) GetUnmanagedPtr(funcTable, 2944324482134975819UL, Audio_GetCurrentTimeFallback); @@ -4019,6 +4023,7 @@ public ClientLibrary(Dictionary funcTable) Player_GetMicLevel = (delegate* unmanaged[Cdecl]) GetUnmanagedPtr(funcTable, 15449156962697427469UL, Player_GetMicLevelFallback); Player_GetNonSpatialVolume = (delegate* unmanaged[Cdecl]) GetUnmanagedPtr(funcTable, 3333598534924196965UL, Player_GetNonSpatialVolumeFallback); Player_GetSpatialVolume = (delegate* unmanaged[Cdecl]) GetUnmanagedPtr(funcTable, 1924883508304421034UL, Player_GetSpatialVolumeFallback); + Player_GetTaskData = (delegate* unmanaged[Cdecl]) GetUnmanagedPtr(funcTable, 15465454396501521389UL, Player_GetTaskDataFallback); Player_IsTalking = (delegate* unmanaged[Cdecl]) GetUnmanagedPtr(funcTable, 2228995248668686637UL, Player_IsTalkingFallback); Player_RemoveFilter = (delegate* unmanaged[Cdecl]) GetUnmanagedPtr(funcTable, 14799984366573861130UL, Player_RemoveFilterFallback); Player_SetNonSpatialVolume = (delegate* unmanaged[Cdecl]) GetUnmanagedPtr(funcTable, 13836779891982146248UL, Player_SetNonSpatialVolumeFallback); diff --git a/api/AltV.Net.CApi/Libraries/ServerLibrary.cs b/api/AltV.Net.CApi/Libraries/ServerLibrary.cs index 5d46689c1..91d667545 100644 --- a/api/AltV.Net.CApi/Libraries/ServerLibrary.cs +++ b/api/AltV.Net.CApi/Libraries/ServerLibrary.cs @@ -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] BaseObject_DeleteSyncedMetaData { get; } public delegate* unmanaged[Cdecl] BaseObject_SetMultipleSyncedMetaData { get; } public delegate* unmanaged[Cdecl] BaseObject_SetSyncedMetaData { get; } @@ -1840,7 +1840,7 @@ private IntPtr GetUnmanagedPtr(IDictionary funcTable, ulong ha public ServerLibrary(Dictionary 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]) GetUnmanagedPtr(funcTable, 8228424877092269355UL, BaseObject_DeleteSyncedMetaDataFallback); BaseObject_SetMultipleSyncedMetaData = (delegate* unmanaged[Cdecl]) GetUnmanagedPtr(funcTable, 1390762125822890831UL, BaseObject_SetMultipleSyncedMetaDataFallback); BaseObject_SetSyncedMetaData = (delegate* unmanaged[Cdecl]) GetUnmanagedPtr(funcTable, 8002999088966424231UL, BaseObject_SetSyncedMetaDataFallback); diff --git a/api/AltV.Net.CApi/Libraries/SharedLibrary.cs b/api/AltV.Net.CApi/Libraries/SharedLibrary.cs index 2cc203d30..3e5353dcb 100644 --- a/api/AltV.Net.CApi/Libraries/SharedLibrary.cs +++ b/api/AltV.Net.CApi/Libraries/SharedLibrary.cs @@ -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] Audio_GetID { get; } public delegate* unmanaged[Cdecl] AudioAttachedOutput_GetID { get; } public delegate* unmanaged[Cdecl] AudioFilter_GetID { get; } @@ -1592,7 +1592,7 @@ private IntPtr GetUnmanagedPtr(IDictionary funcTable, ulong ha public SharedLibrary(Dictionary 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]) GetUnmanagedPtr(funcTable, 4464042055475980737UL, Audio_GetIDFallback); AudioAttachedOutput_GetID = (delegate* unmanaged[Cdecl]) GetUnmanagedPtr(funcTable, 17725794901805112189UL, AudioAttachedOutput_GetIDFallback); AudioFilter_GetID = (delegate* unmanaged[Cdecl]) GetUnmanagedPtr(funcTable, 8824535635529306325UL, AudioFilter_GetIDFallback); diff --git a/api/AltV.Net.CApi/Native/AltV.Resource.cs b/api/AltV.Net.CApi/Native/AltV.Resource.cs index 590dc7c49..a34419461 100644 --- a/api/AltV.Net.CApi/Native/AltV.Resource.cs +++ b/api/AltV.Net.CApi/Native/AltV.Resource.cs @@ -24,7 +24,7 @@ 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); @@ -32,8 +32,7 @@ internal delegate void PlayerConnectDeniedDelegate(PlayerConnectDeniedReason rea 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); @@ -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); @@ -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); } } } \ No newline at end of file diff --git a/api/AltV.Net.Client/Elements/Entities/Player.cs b/api/AltV.Net.Client/Elements/Entities/Player.cs index f19841a69..36173b5da 100644 --- a/api/AltV.Net.Client/Elements/Entities/Player.cs +++ b/api/AltV.Net.Client/Elements/Entities/Player.cs @@ -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 diff --git a/api/AltV.Net.Client/Elements/Interfaces/IPlayer.cs b/api/AltV.Net.Client/Elements/Interfaces/IPlayer.cs index 56656f267..eab170e52 100644 --- a/api/AltV.Net.Client/Elements/Interfaces/IPlayer.cs +++ b/api/AltV.Net.Client/Elements/Interfaces/IPlayer.cs @@ -15,5 +15,7 @@ public interface IPlayer : ISharedPlayer, IEntity void AddFilter(IAudioFilter filter); void RemoveFilter(); IAudioFilter GetFilter(); + + string TaskData { get; } } } \ No newline at end of file diff --git a/api/AltV.Net.Mock/MockAltV.cs b/api/AltV.Net.Mock/MockAltV.cs index 16799a848..6fc154615 100644 --- a/api/AltV.Net.Mock/MockAltV.cs +++ b/api/AltV.Net.Mock/MockAltV.cs @@ -69,7 +69,7 @@ public IPlayer ConnectPlayer(string playerName, string reason, Action 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; } } diff --git a/api/AltV.Net.Mock/MockPlayer.Events.cs b/api/AltV.Net.Mock/MockPlayer.Events.cs index 3031cb89c..d37dc9410 100644 --- a/api/AltV.Net.Mock/MockPlayer.Events.cs +++ b/api/AltV.Net.Mock/MockPlayer.Events.cs @@ -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) diff --git a/api/AltV.Net.Shared/Events/EventType.cs b/api/AltV.Net.Shared/Events/EventType.cs index fd6fb0690..78b5ddec3 100644 --- a/api/AltV.Net.Shared/Events/EventType.cs +++ b/api/AltV.Net.Shared/Events/EventType.cs @@ -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, @@ -101,6 +103,10 @@ public enum EventType : byte VOICE_CONNECTION_EVENT, + PED_DAMAGE, + PED_DEATH, + PED_HEAL, + ALL, SIZE } diff --git a/api/AltV.Net/Alt.Events.cs b/api/AltV.Net/Alt.Events.cs index 17169376f..3824bb770 100644 --- a/api/AltV.Net/Alt.Events.cs +++ b/api/AltV.Net/Alt.Events.cs @@ -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); + } } } \ No newline at end of file diff --git a/api/AltV.Net/CSharpResourceImpl.cs b/api/AltV.Net/CSharpResourceImpl.cs index 7be369e03..9650c0c63 100644 --- a/api/AltV.Net/CSharpResourceImpl.cs +++ b/api/AltV.Net/CSharpResourceImpl.cs @@ -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() diff --git a/api/AltV.Net/Core.Events.cs b/api/AltV.Net/Core.Events.cs index 818b55b59..f8971167a 100644 --- a/api/AltV.Net/Core.Events.cs +++ b/api/AltV.Net/Core.Events.cs @@ -157,6 +157,21 @@ public partial class Core internal readonly IEventHandler GivePedScriptedTaskHandler = new HashSetEventHandler(EventType.GIVE_PED_SCRIPTED_TASK); + internal readonly IEventHandler PedDamageEventHandler = + new HashSetEventHandler(EventType.PED_DAMAGE); + + internal readonly IEventHandler PedDeadEventHandler = + new HashSetEventHandler(EventType.PED_DEATH); + + internal readonly IEventHandler PedHealEventHandler = + new HashSetEventHandler(EventType.PED_HEAL); + + internal readonly IEventHandler PlayerStartTalkingHandler = + new HashSetEventHandler(EventType.PLAYER_START_TALKING); + + internal readonly IEventHandler PlayerStopTalkingHandler = + new HashSetEventHandler(EventType.PLAYER_STOP_TALKING); + public void OnCheckpoint(IntPtr checkpointPointer, IntPtr entityPointer, BaseObjectType baseObjectType, bool state) { @@ -199,12 +214,12 @@ public virtual void OnCheckPointEvent(ICheckpoint checkpoint, IWorldObject entit } } - public void OnPlayerConnect(IntPtr playerPointer, uint playerId, string reason) + public void OnPlayerConnect(IntPtr playerPointer, string reason) { var player = PoolManager.Player.Get(playerPointer); if (player == null) { - Console.WriteLine("OnPlayerConnect Invalid player " + playerPointer + " " + playerId + " " + + Console.WriteLine("OnPlayerConnect Invalid player " + playerPointer + " " + reason); return; } @@ -338,14 +353,13 @@ public virtual void OnResourceErrorEvent(INativeResource resource) } public void OnPlayerDamage(IntPtr playerPointer, IntPtr attackerEntityPointer, - BaseObjectType attackerBaseObjectType, - uint attackerEntityId, uint weapon, ushort healthDamage, ushort armourDamage) + BaseObjectType attackerBaseObjectType, uint weapon, ushort healthDamage, ushort armourDamage) { var player = PoolManager.Player.Get(playerPointer); if (player == null) { Console.WriteLine("OnPlayerDamage Invalid player " + playerPointer + " " + attackerEntityPointer + " " + - attackerBaseObjectType + " " + attackerEntityId + " " + weapon + " " + healthDamage + + attackerBaseObjectType + " " + weapon + " " + healthDamage + " " + armourDamage); return; } @@ -2432,5 +2446,171 @@ public virtual void OnGivePedScriptedTaskEvent(IntPtr eventPointer, IPlayer sour } } } + + public void OnPedDamage(IntPtr pedpointer, IntPtr attackerentitypointer, BaseObjectType attackerbaseobjecttype, uint weapon, ushort healthdamage, ushort armourdamage) + { + var ped = PoolManager.Ped.Get(pedpointer); + if (ped == null) + { + Console.WriteLine("OnPedDamage Invalid player " + pedpointer + " " + attackerentitypointer + " " + + attackerbaseobjecttype + " " + weapon + " " + healthdamage + + " " + armourdamage); + return; + } + + var attacker = (IEntity)PoolManager.Get(attackerentitypointer, attackerbaseobjecttype); + + OnPedDamageEvent(ped, attacker, weapon, healthdamage, armourdamage); + } + + public virtual void OnPedDamageEvent(IPed ped, IEntity attacker, uint weapon, ushort healthDamage, + ushort armourDamage) + { + foreach (var @delegate in PedDamageEventHandler.GetEvents()) + { + try + { + @delegate(ped, attacker, weapon, healthDamage, armourDamage); + } + catch (TargetInvocationException exception) + { + Alt.Log("exception at event:" + "OnPedDamageEvent" + ":" + exception.InnerException); + } + catch (Exception exception) + { + Alt.Log("exception at event:" + "OnPedDamageEvent" + ":" + exception); + } + } + } + + public void OnPedDeath(IntPtr pedpointer, IntPtr killerentitypointer, BaseObjectType killerbaseobjecttype, uint weapon) + { + var ped = PoolManager.Ped.Get(pedpointer); + if (ped == null) + { + Console.WriteLine("OnPedDeath Invalid ped " + pedpointer + " " + killerentitypointer + " " + + killerbaseobjecttype + " " + weapon); + return; + } + + var killer = (IEntity)PoolManager.Get(killerentitypointer, killerbaseobjecttype); + + OnPedDeathEvent(ped, killer, weapon); + } + + public virtual void OnPedDeathEvent(IPed ped, IEntity killer, uint weapon) + { + foreach (var @delegate in PedDeadEventHandler.GetEvents()) + { + try + { + @delegate(ped, killer, weapon); + } + catch (TargetInvocationException exception) + { + Alt.Log("exception at event:" + "OnPedDeathEvent" + ":" + exception.InnerException); + } + catch (Exception exception) + { + Alt.Log("exception at event:" + "OnPedDeathEvent" + ":" + exception); + } + } + } + + public void OnPedHeal(IntPtr pedpointer, ushort oldHealth, ushort newHealth, ushort oldArmour, + ushort newArmour) + { + var ped = PoolManager.Ped.Get(pedpointer); + if (ped == null) + { + Console.WriteLine("OnPedHeal Invalid ped " + pedpointer + " " + oldHealth + " " + + newHealth + " " + oldArmour + " " + newArmour); + return; + } + + OnPedHealEvent(ped, oldHealth, newHealth, oldArmour, newArmour); + } + + public virtual void OnPedHealEvent(IPed ped, ushort oldHealth, ushort newHealth, ushort oldArmour, + ushort newArmour) + { + foreach (var @delegate in PedHealEventHandler.GetEvents()) + { + try + { + @delegate(ped, oldHealth, newHealth, oldArmour, newArmour); + } + catch (TargetInvocationException exception) + { + Alt.Log("exception at event:" + "OnPedHealEvent" + ":" + exception.InnerException); + } + catch (Exception exception) + { + Alt.Log("exception at event:" + "OnPedHealEvent" + ":" + exception); + } + } + } + + public void OnPlayerStartTalking(IntPtr playerpointer) + { + var player = PoolManager.Player.Get(playerpointer); + if (player == null) + { + Console.WriteLine("OnPlayerStartTalking Invalid player " + playerpointer); + return; + } + + OnPlayerStartTalkingEvent(player); + } + + private void OnPlayerStartTalkingEvent(IPlayer player) + { + foreach (var @delegate in PlayerStartTalkingHandler.GetEvents()) + { + try + { + @delegate(player); + } + catch (TargetInvocationException exception) + { + Alt.Log("exception at event:" + "OnPlayerStartTalkingEvent" + ":" + exception.InnerException); + } + catch (Exception exception) + { + Alt.Log("exception at event:" + "OnPlayerStartTalkingEvent" + ":" + exception); + } + } + } + + public void OnPlayerStopTalking(IntPtr playerpointer) + { + var player = PoolManager.Player.Get(playerpointer); + if (player == null) + { + Console.WriteLine("OnPlayerStopTalking Invalid player " + playerpointer); + return; + } + + OnPlayerStopTalkingEvent(player); + } + + private void OnPlayerStopTalkingEvent(IPlayer player) + { + foreach (var @delegate in PlayerStopTalkingHandler.GetEvents()) + { + try + { + @delegate(player); + } + catch (TargetInvocationException exception) + { + Alt.Log("exception at event:" + "OnPlayerStopTalkingEvent" + ":" + exception.InnerException); + } + catch (Exception exception) + { + Alt.Log("exception at event:" + "OnPlayerStopTalkingEvent" + ":" + exception); + } + } + } } } \ No newline at end of file diff --git a/api/AltV.Net/Events/Events.cs b/api/AltV.Net/Events/Events.cs index f07c5e3ce..fa0d0fc14 100644 --- a/api/AltV.Net/Events/Events.cs +++ b/api/AltV.Net/Events/Events.cs @@ -107,4 +107,13 @@ public delegate WeaponDamageResponse WeaponDamageDelegate(IPlayer player, IEntit public delegate bool ClientDeleteObjectDelegate(IPlayer target); public delegate bool GivePedScriptedTaskDelegate(IPlayer source, IPed target, uint taskType); + + public delegate void PedDamageDelegate(IPed ped, IEntity attacker, uint weapon, ushort healthDamage, ushort armourDamage); + + public delegate void PedDeadDelegate(IPed ped, IEntity killer, uint weapon); + + public delegate void PedHealDelegate(IPed ped, ushort oldHealth, ushort newHealth, ushort oldArmour, + ushort newArmour); + public delegate bool PlayerStartTalkingDelegate(IPlayer Player); + public delegate bool PlayerStopTalkingDelegate(IPlayer Player); } \ No newline at end of file diff --git a/api/AltV.Net/ModuleWrapper.cs b/api/AltV.Net/ModuleWrapper.cs index 270f5d3e8..1dfa4e3df 100644 --- a/api/AltV.Net/ModuleWrapper.cs +++ b/api/AltV.Net/ModuleWrapper.cs @@ -205,9 +205,9 @@ public static void OnCheckpoint(IntPtr checkpointPointer, IntPtr entityPointer, _core.OnCheckpoint(checkpointPointer, entityPointer, baseObjectType, state == 1); } - public static void OnPlayerConnect(IntPtr playerPointer, ushort playerId, string reason) + public static void OnPlayerConnect(IntPtr playerPointer, string reason) { - _core.OnPlayerConnect(playerPointer, playerId, reason); + _core.OnPlayerConnect(playerPointer, reason); } public static void OnResourceStart(IntPtr resourcePointer) @@ -226,10 +226,9 @@ public static void OnResourceError(IntPtr resourcePointer) } public static void OnPlayerDamage(IntPtr playerPointer, IntPtr attackerEntityPointer, - BaseObjectType attackerBaseObjectType, - ushort attackerEntityId, uint weapon, ushort healthDamage, ushort armourDamage) + BaseObjectType attackerBaseObjectType, uint weapon, ushort healthDamage, ushort armourDamage) { - _core.OnPlayerDamage(playerPointer, attackerEntityPointer, attackerBaseObjectType, attackerEntityId, + _core.OnPlayerDamage(playerPointer, attackerEntityPointer, attackerBaseObjectType, weapon, healthDamage, armourDamage); } @@ -488,5 +487,30 @@ public static void OnGivePedScriptedTask(IntPtr eventPointer, IntPtr source, Int { _core.OnGivePedScriptedTask(eventPointer, source, target, taskType); } + + public static void OnPedDamage(IntPtr pedpointer, IntPtr attackerentitypointer, BaseObjectType attackerbaseobjecttype, uint weapon, ushort healthdamage, ushort armourdamage) + { + _core.OnPedDamage(pedpointer, attackerentitypointer, attackerbaseobjecttype, weapon, healthdamage, armourdamage); + } + + public static void OnPedDeath(IntPtr pedpointer, IntPtr killerentitypointer, BaseObjectType killerbaseobjecttype, uint weapon) + { + _core.OnPedDeath(pedpointer, killerentitypointer, killerbaseobjecttype, weapon); + } + + public static void OnPedHeal(IntPtr pedpointer, ushort oldhealth, ushort newhealth, ushort oldarmour, ushort newarmour) + { + _core.OnPedHeal(pedpointer, oldhealth, newhealth, oldarmour, newarmour); + } + + public static void OnPlayerStartTalking(IntPtr playerpointer) + { + _core.OnPlayerStartTalking(playerpointer); + } + + public static void OnPlayerStopTalking(IntPtr playerpointer) + { + _core.OnPlayerStopTalking(playerpointer); + } } } diff --git a/runtime b/runtime index 460ad8735..9667ff523 160000 --- a/runtime +++ b/runtime @@ -1 +1 @@ -Subproject commit 460ad87357f4467c17599c8c6aefa3dc39416371 +Subproject commit 9667ff523ad8f2be2141b180a941098f9c173314