diff --git a/api/AltV.Net.Async/AltAsync.cs b/api/AltV.Net.Async/AltAsync.cs index d4f56d2d2..0a1762f07 100644 --- a/api/AltV.Net.Async/AltAsync.cs +++ b/api/AltV.Net.Async/AltAsync.cs @@ -244,6 +244,114 @@ public static event PlayerSpawnAsyncDelegate OnPlayerSpawn remove => Core.PlayerSpawnAsyncEventHandler.Remove(value); } + public static event RequestSyncedSceneAsyncEventDelegate OnRequestSyncedScene + { + add => Core.RequestSyncedSceneAsyncEventHandler.Add(value); + remove => Core.RequestSyncedSceneAsyncEventHandler.Remove(value); + } + + public static event StartSyncedSceneAsyncEventDelegate OnStartSyncedScene + { + add => Core.StartSyncedSceneAsyncEventHandler.Add(value); + remove => Core.StartSyncedSceneAsyncEventHandler.Remove(value); + } + + public static event StopSyncedSceneAsyncEventDelegate OnStopSyncedScene + { + add => Core.StopSyncedSceneAsyncEventHandler.Add(value); + remove => Core.StopSyncedSceneAsyncEventHandler.Remove(value); + } + + public static event UpdateSyncedSceneAsyncEventDelegate OnUpdateSyncedScene + { + add => Core.UpdateSyncedSceneAsyncEventHandler.Add(value); + remove => Core.UpdateSyncedSceneAsyncEventHandler.Remove(value); + } + + public static event ClientRequestObjectAsyncEventDelegate OnClientRequestObject + { + add => Core.ClientRequestObjectAsyncEventHandler.Add(value); + remove => Core.ClientRequestObjectAsyncEventHandler.Remove(value); + } + + public static event ClientDeleteObjectAsyncEventDelegate OnClientDeleteObject + { + add => Core.ClientDeleteObjectAsyncEventHandler.Add(value); + remove => Core.ClientDeleteObjectAsyncEventHandler.Remove(value); + } + + public static event GivePedScriptedTaskAsyncDelegate OnGivePedScriptedTask + { + add => Core.GivePedScriptedTaskAsyncEventHandler.Add(value); + remove => Core.GivePedScriptedTaskAsyncEventHandler.Remove(value); + } + + public static event PedDamageAsyncDelegate OnPedDamage + { + add => Core.PedDamageAsyncEventHandler.Add(value); + remove => Core.PedDamageAsyncEventHandler.Remove(value); + } + + public static event PedDeadAsyncDelegate OnPedDead + { + add => Core.PedDeadAsyncEventHandler.Add(value); + remove => Core.PedDeadAsyncEventHandler.Remove(value); + } + + public static event PedHealAsyncDelegate OnPedHeal + { + add => Core.PedHealAsyncEventHandler.Add(value); + remove => Core.PedHealAsyncEventHandler.Remove(value); + } + + public static event PlayerStartTalkingAsyncDelegate OnPlayerStartTalking + { + add => Core.PlayerStartTalkingAsyncEventHandler.Add(value); + remove => Core.PlayerStartTalkingAsyncEventHandler.Remove(value); + } + + public static event PlayerStopTalkingAsyncDelegate OnPlayerStopTalking + { + add => Core.PlayerStopTalkingAsyncEventHandler.Add(value); + remove => Core.PlayerStopTalkingAsyncEventHandler.Remove(value); + } + + public static event ScriptRpcAsyncDelegate OnScriptRpc + { + add => Core.ScriptRpcAsyncEventHandler.Add(value); + remove => Core.ScriptRpcAsyncEventHandler.Remove(value); + } + + public static event ScriptRpcAnswerAsyncDelegate OnScriptRpcAnswer + { + add => Core.ScriptRpcAnswerAsyncEventHandler.Add(value); + remove => Core.ScriptRpcAnswerAsyncEventHandler.Remove(value); + } + + public static event PlayerConnectDeniedAsyncDelegate OnPlayerConnectDenied + { + add => Core.PlayerConnectDeniedAsyncEventHandler.Add(value); + remove => Core.PlayerConnectDeniedAsyncEventHandler.Remove(value); + } + + public static event ResourceEventAsyncDelegate OnResourceStart + { + add => Core.ResourceStartAsyncEventHandler.Add(value); + remove => Core.ResourceStartAsyncEventHandler.Remove(value); + } + + public static event ResourceEventAsyncDelegate OnResourceStop + { + add => Core.ResourceStopAsyncEventHandler.Add(value); + remove => Core.ResourceStopAsyncEventHandler.Remove(value); + } + + public static event ResourceEventAsyncDelegate OnResourceError + { + add => Core.ResourceErrorAsyncEventHandler.Add(value); + remove => Core.ResourceErrorAsyncEventHandler.Remove(value); + } + public static async void Log(string message) { var messagePtr = AltNative.StringUtils.StringToHGlobalUtf8(message); diff --git a/api/AltV.Net.Async/AsyncCore.cs b/api/AltV.Net.Async/AsyncCore.cs index c088d203a..92c5fcece 100644 --- a/api/AltV.Net.Async/AsyncCore.cs +++ b/api/AltV.Net.Async/AsyncCore.cs @@ -1,8 +1,6 @@ using System; using System.Collections.Generic; -using System.Diagnostics; using System.Linq; -using System.Runtime.CompilerServices; using System.Runtime.Loader; using System.Threading; using System.Threading.Tasks; @@ -11,9 +9,8 @@ using AltV.Net.Data; using AltV.Net.Elements.Entities; using AltV.Net.Elements.Args; -using AltV.Net.Events; +using AltV.Net.Shared.Elements.Entities; using AltV.Net.Shared.Events; -using AltV.Net.Types; namespace AltV.Net.Async { @@ -41,6 +38,18 @@ public override IEnumerable GetRegisteredServerEvents() internal readonly AsyncEventHandler PlayerConnectAsyncEventHandler = new(EventType.PLAYER_CONNECT); + internal readonly AsyncEventHandler PlayerConnectDeniedAsyncEventHandler = + new(EventType.PLAYER_CONNECT_DENIED); + + internal readonly AsyncEventHandler ResourceStartAsyncEventHandler = + new(EventType.RESOURCE_START); + + internal readonly AsyncEventHandler ResourceStopAsyncEventHandler = + new(EventType.RESOURCE_STOP); + + internal readonly AsyncEventHandler ResourceErrorAsyncEventHandler = + new(EventType.RESOURCE_ERROR); + internal readonly AsyncEventHandler PlayerDamageAsyncEventHandler = new(EventType.PLAYER_DAMAGE); @@ -171,6 +180,29 @@ internal readonly AsyncEventHandler internal readonly AsyncEventHandler GivePedScriptedTaskAsyncEventHandler = new(EventType.GIVE_PED_SCRIPTED_TASK); + internal readonly AsyncEventHandler PedDamageAsyncEventHandler = + new(EventType.PED_DAMAGE); + + internal readonly AsyncEventHandler PedDeadAsyncEventHandler = + new(EventType.PED_DEATH); + + internal readonly AsyncEventHandler PedHealAsyncEventHandler = + new(EventType.PED_HEAL); + + internal readonly AsyncEventHandler PlayerStartTalkingAsyncEventHandler = + new(EventType.PLAYER_START_TALKING); + + internal readonly AsyncEventHandler PlayerStopTalkingAsyncEventHandler = + new(EventType.PLAYER_STOP_TALKING); + + internal readonly AsyncEventHandler ScriptRpcAsyncEventHandler = + new(EventType.SCRIPT_RPC_EVENT); + + internal readonly AsyncEventHandler ScriptRpcAnswerAsyncEventHandler = + new(EventType.SCRIPT_RPC_ANSWER_EVENT); + + + public AsyncCore(IntPtr nativePointer, IntPtr resourcePointer, AssemblyLoadContext assemblyLoadContext, ILibrary library, IPoolManager poolManager, INativeResourcePool nativeResourcePool) : base(nativePointer, resourcePointer, assemblyLoadContext, library, poolManager, nativeResourcePool) { @@ -836,6 +868,130 @@ public override void OnGivePedScriptedTaskEvent(IntPtr eventPointer, IPlayer sou }); } + public override void OnPlayerConnectDeniedEvent(PlayerConnectDeniedReason reason, string name, string ip, ulong passwordHash, + bool isDebug, string branch, uint majorVersion, string cdnUrl, long discordId) + { + base.OnPlayerConnectDeniedEvent(reason, name, ip, passwordHash, isDebug, branch, majorVersion, cdnUrl, discordId); + + if (!PlayerConnectDeniedAsyncEventHandler.HasEvents()) return; + Task.Run(async () => + { + await PlayerConnectDeniedAsyncEventHandler.CallAsync(@delegate => @delegate(reason, name, ip, passwordHash, isDebug, branch, majorVersion, cdnUrl, discordId)); + }); + } + + public override void OnResourceStartEvent(INativeResource resource) + { + base.OnResourceStartEvent(resource); + + if (!ResourceStartAsyncEventHandler.HasEvents()) return; + Task.Run(async () => + { + await ResourceStartAsyncEventHandler.CallAsync(@delegate => @delegate(resource)); + }); + } + + public override void OnResourceStopEvent(INativeResource resource) + { + base.OnResourceStopEvent(resource); + + if (!ResourceStopAsyncEventHandler.HasEvents()) return; + Task.Run(async () => + { + await ResourceStopAsyncEventHandler.CallAsync(@delegate => @delegate(resource)); + }); + } + + public override void OnResourceErrorEvent(INativeResource resource) + { + base.OnResourceErrorEvent(resource); + + if (!ResourceErrorAsyncEventHandler.HasEvents()) return; + Task.Run(async () => + { + await ResourceErrorAsyncEventHandler.CallAsync(@delegate => @delegate(resource)); + }); + } + + public override void OnPedDamageEvent(IPed ped, IEntity attacker, uint weapon, ushort healthDamage, ushort armourDamage) + { + base.OnPedDamageEvent(ped, attacker, weapon, healthDamage, armourDamage); + + if (!PedDamageAsyncEventHandler.HasEvents()) return; + Task.Run(async () => + { + await PedDamageAsyncEventHandler.CallAsync(@delegate => @delegate(ped, attacker, weapon, healthDamage, armourDamage)); + }); + } + + public override void OnPedDeathEvent(IPed ped, IEntity killer, uint weapon) + { + base.OnPedDeathEvent(ped, killer, weapon); + + if (!PedDeadAsyncEventHandler.HasEvents()) return; + Task.Run(async () => + { + await PedDeadAsyncEventHandler.CallAsync(@delegate => @delegate(ped, killer, weapon)); + }); + } + + public override void OnPedHealEvent(IPed ped, ushort oldHealth, ushort newHealth, ushort oldArmour, ushort newArmour) + { + base.OnPedHealEvent(ped, oldHealth, newHealth, oldArmour, newArmour); + + if (!PedHealAsyncEventHandler.HasEvents()) return; + Task.Run(async () => + { + await PedHealAsyncEventHandler.CallAsync(@delegate => @delegate(ped, oldHealth, newHealth, oldArmour, newArmour)); + }); + } + + public override void OnPlayerStartTalkingEvent(IPlayer player) + { + base.OnPlayerStartTalkingEvent(player); + + if (!PlayerStartTalkingAsyncEventHandler.HasEvents()) return; + Task.Run(async () => + { + await PlayerStartTalkingAsyncEventHandler.CallAsync(@delegate => @delegate(player)); + }); + } + + public override void OnPlayerStopTalkingEvent(IPlayer player) + { + base.OnPlayerStopTalkingEvent(player); + + if (!PlayerStopTalkingAsyncEventHandler.HasEvents()) return; + Task.Run(async () => + { + await PlayerStopTalkingAsyncEventHandler.CallAsync(@delegate => @delegate(player)); + }); + } + + public override void OnScriptRPCEvent(IntPtr eventpointer, IPlayer target, string name, IntPtr[] args, ushort answerId) + { + base.OnScriptRPCEvent(eventpointer, target, name, args, answerId); + + if (!ScriptRpcAsyncEventHandler.HasEvents()) return; + Task.Run(async () => + { + var mValues = MValueConst.CreateFrom(this, args); + var clientScriptRPCEvent = new ScriptRpcEvent(this, eventpointer); + await ScriptRpcAsyncEventHandler.CallAsync(@delegate => @delegate(clientScriptRPCEvent, target, name, mValues.Select(x => x.ToObject()).ToArray(), answerId)); + }); + } + + public override void OnScriptAnswerRPCEvent(IPlayer target, ushort answerid, IntPtr mValue, string answererror) + { + base.OnScriptAnswerRPCEvent(target, answerid, mValue, answererror); + + if (!ScriptRpcAnswerAsyncEventHandler.HasEvents()) return; + Task.Run(async () => + { + await ScriptRpcAnswerAsyncEventHandler.CallAsync(@delegate => @delegate(target, answerid, mValue, answererror)); + }); + } + public new Function OnClient(string eventName, Function function) { if (function == null) diff --git a/api/AltV.Net.Async/Events/Events.cs b/api/AltV.Net.Async/Events/Events.cs index c78fec2cc..8a2765639 100644 --- a/api/AltV.Net.Async/Events/Events.cs +++ b/api/AltV.Net.Async/Events/Events.cs @@ -2,6 +2,7 @@ using System.Threading.Tasks; using AltV.Net.Data; using AltV.Net.Elements.Entities; +using AltV.Net.Shared.Elements.Entities; using AltV.Net.Types; namespace AltV.Net.Async.Events @@ -12,6 +13,11 @@ namespace AltV.Net.Async.Events public delegate Task PlayerConnectAsyncDelegate(IPlayer player, string reason); + public delegate Task PlayerConnectDeniedAsyncDelegate(PlayerConnectDeniedReason reason, string name, string ip, + ulong passwordHash, bool isDebug, string branch, uint majorVersion, string cdnUrl, long discordId); + + public delegate Task ResourceEventAsyncDelegate(INativeResource resource); + public delegate Task PlayerDamageAsyncDelegate(IPlayer player, IEntity attacker, ushort oldHealth, ushort oldArmor, ushort oldMaxHealth, ushort oldMaxArmor, uint weapon, ushort healthDamage, ushort armourDamage); @@ -98,4 +104,16 @@ public delegate Task WeaponDamageAsyncDelegate(IPlayer player, IEntity target, u public delegate Task ClientDeleteObjectAsyncEventDelegate(IPlayer target); public delegate Task GivePedScriptedTaskAsyncDelegate(IPlayer source, IPed target, uint taskType); + + public delegate Task PedDamageAsyncDelegate(IPed ped, IEntity attacker, uint weapon, ushort healthDamage, ushort armourDamage); + + public delegate Task PedDeadAsyncDelegate(IPed ped, IEntity killer, uint weapon); + + public delegate Task PedHealAsyncDelegate(IPed ped, ushort oldHealth, ushort newHealth, ushort oldArmour, + ushort newArmour); + public delegate Task PlayerStartTalkingAsyncDelegate(IPlayer Player); + public delegate Task PlayerStopTalkingAsyncDelegate(IPlayer Player); + + public delegate Task ScriptRpcAsyncDelegate(IScriptRPCEvent scriptRpcEvent, IPlayer target, string name, object[] args, ushort answerId); + public delegate Task ScriptRpcAnswerAsyncDelegate(IPlayer target, ushort answerId, object answer, string answerError); } \ No newline at end of file diff --git a/api/AltV.Net/Core.Events.cs b/api/AltV.Net/Core.Events.cs index 833a646dd..d2895cd0c 100644 --- a/api/AltV.Net/Core.Events.cs +++ b/api/AltV.Net/Core.Events.cs @@ -254,15 +254,15 @@ public virtual void OnPlayerConnectEvent(IPlayer player, string reason) } } - public void onPlayerConnectDenied(PlayerConnectDeniedReason reason, string name, string ip, ulong passwordHash, + public void OnPlayerConnectDenied(PlayerConnectDeniedReason reason, string name, string ip, ulong passwordHash, bool isDebug, string branch, uint majorVersion, string cdnUrl, long discordId) { - onPlayerConnectDeniedEvent(reason, name, ip, passwordHash, isDebug, branch, majorVersion, cdnUrl, + OnPlayerConnectDeniedEvent(reason, name, ip, passwordHash, isDebug, branch, majorVersion, cdnUrl, discordId); } - public virtual void onPlayerConnectDeniedEvent(PlayerConnectDeniedReason reason, string name, string ip, + public virtual void OnPlayerConnectDeniedEvent(PlayerConnectDeniedReason reason, string name, string ip, ulong passwordHash, bool isDebug, string branch, uint majorVersion, string cdnUrl, long discordId) { foreach (var @delegate in PlayerConnectDeniedEventHandler.GetEvents()) @@ -273,11 +273,11 @@ public virtual void onPlayerConnectDeniedEvent(PlayerConnectDeniedReason reason, } catch (TargetInvocationException exception) { - Alt.Log("exception at event:" + "onPlayerConnectDeniedEvent" + ":" + exception.InnerException); + Alt.Log("exception at event:" + "OnPlayerConnectDeniedEvent" + ":" + exception.InnerException); } catch (Exception exception) { - Alt.Log("exception at event:" + "onPlayerConnectDeniedEvent" + ":" + exception); + Alt.Log("exception at event:" + "OnPlayerConnectDeniedEvent" + ":" + exception); } } } diff --git a/api/AltV.Net/ModuleWrapper.cs b/api/AltV.Net/ModuleWrapper.cs index 9c247ba3b..f75f35841 100644 --- a/api/AltV.Net/ModuleWrapper.cs +++ b/api/AltV.Net/ModuleWrapper.cs @@ -420,7 +420,7 @@ public static void OnPlayerDimensionChange(IntPtr player, int oldDimension, int public static void OnPlayerConnectDenied(PlayerConnectDeniedReason reason, string name, string ip, ulong passwordHash, byte isDebug, string branch, uint majorVersion, string cdnUrl, long discordId) { - _core.onPlayerConnectDenied(reason, name, ip, passwordHash, isDebug == 1, branch, majorVersion, cdnUrl, + _core.OnPlayerConnectDenied(reason, name, ip, passwordHash, isDebug == 1, branch, majorVersion, cdnUrl, discordId); }