From dc83cd5be9ad524c4d44f9fc1b69a3d15456e15e Mon Sep 17 00:00:00 2001 From: Sardelka Date: Sun, 14 Aug 2022 19:06:51 +0800 Subject: [PATCH] Ped sync improvements --- RageCoop.Client/Networking/Receive.cs | 12 +- RageCoop.Client/RageCoop.Client.csproj | 3 +- .../Sync/Entities/Ped/SyncedPed.Animations.cs | 142 ++++++++++++++++++ .../Sync/Entities/{ => Ped}/SyncedPed.cs | 58 +++---- RageCoop.Client/Util/PedExtensions.cs | 13 +- RageCoop.Core/Packets/Packets.cs | 3 + 6 files changed, 185 insertions(+), 46 deletions(-) create mode 100644 RageCoop.Client/Sync/Entities/Ped/SyncedPed.Animations.cs rename RageCoop.Client/Sync/Entities/{ => Ped}/SyncedPed.cs (93%) diff --git a/RageCoop.Client/Networking/Receive.cs b/RageCoop.Client/Networking/Receive.cs index c8fe10a..76c729b 100644 --- a/RageCoop.Client/Networking/Receive.cs +++ b/RageCoop.Client/Networking/Receive.cs @@ -330,17 +330,7 @@ namespace RageCoop.Client c.Rotation = packet.Rotation; c.Velocity = packet.Velocity; c.Speed = packet.Speed; - c.IsAiming = flags.HasPedFlag(PedDataFlags.IsAiming); - c.IsReloading = flags.HasPedFlag(PedDataFlags.IsReloading); - c.IsJumping = flags.HasPedFlag(PedDataFlags.IsJumping); - c.IsRagdoll = flags.HasPedFlag(PedDataFlags.IsRagdoll); - c.IsOnFire = flags.HasPedFlag(PedDataFlags.IsOnFire); - c.IsInParachuteFreeFall = flags.HasPedFlag(PedDataFlags.IsInParachuteFreeFall); - c.IsParachuteOpen = flags.HasPedFlag(PedDataFlags.IsParachuteOpen); - c.IsOnLadder = flags.HasPedFlag(PedDataFlags.IsOnLadder); - c.IsVaulting = flags.HasPedFlag(PedDataFlags.IsVaulting); - c.IsInCover = flags.HasPedFlag(PedDataFlags.IsInCover); - c.IsInStealthMode = flags.HasPedFlag(PedDataFlags.IsInStealthMode); + c.Flags=packet.Flags; c.Heading=packet.Heading; c.Position = packet.Position; if (c.IsRagdoll) diff --git a/RageCoop.Client/RageCoop.Client.csproj b/RageCoop.Client/RageCoop.Client.csproj index 2868f8a..2fe843f 100644 --- a/RageCoop.Client/RageCoop.Client.csproj +++ b/RageCoop.Client/RageCoop.Client.csproj @@ -50,8 +50,9 @@ + - + diff --git a/RageCoop.Client/Sync/Entities/Ped/SyncedPed.Animations.cs b/RageCoop.Client/Sync/Entities/Ped/SyncedPed.Animations.cs new file mode 100644 index 0000000..1b65bca --- /dev/null +++ b/RageCoop.Client/Sync/Entities/Ped/SyncedPed.Animations.cs @@ -0,0 +1,142 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using GTA; +using GTA.Native; +using System.Threading.Tasks; + +namespace RageCoop.Client +{ + public partial class SyncedPed + { + + private void DisplayInCover() + { + var ourAnim = GetCoverAnim(); + var animDict = GetCoverIdleAnimDict(); + + if (ourAnim != null && animDict != null) + { + var flag = AnimationFlags.Loop; + if (!Function.Call(Hash.IS_ENTITY_PLAYING_ANIM, MainPed, animDict, ourAnim, 3)) + { + MainPed.Task.ClearAll(); + Function.Call(Hash.TASK_PLAY_ANIM, MainPed, LoadAnim(animDict), ourAnim, 8f, 10f, -1, flag, -8f, 1, 1, 1); + } + } + } + + internal string GetCoverAnim() + { + if (IsInCover) + { + if (IsBlindFiring) + { + if (IsInCover) + return IsInCoverFacingLeft ? "blindfire_low_l_aim_med" : "blindfire_low_r_aim_med"; + return IsInCoverFacingLeft ? "blindfire_hi_l_aim_med" : "blindfire_hi_r_aim_med"; + } + + return IsInCoverFacingLeft ? "idle_l_corner" : "idle_r_corner"; + } + return null; + } + + internal string GetCoverIdleAnimDict() + { + if (!IsInCover) return ""; + var altitude = IsInLowCover ? "low" : "high"; + + var hands = GetWeaponHandsHeld(CurrentWeaponHash); + if (IsBlindFiring) + { + if (hands == 1) return "cover@weapon@1h"; + if (hands == 2 || hands == 5) return "cover@weapon@2h"; + } + + if (hands == 1) return "cover@idles@1h@" + altitude + "@_a"; + if (hands == 2 || hands == 5) return "cover@idles@2h@" + altitude + "@_a"; + if (hands == 3 || hands == 4 || hands == 0) return "cover@idles@unarmed@" + altitude + "@_a"; + return ""; + } + + internal int GetWeaponHandsHeld(uint weapon) + { + switch (weapon) + { + case unchecked((uint)WeaponHash.Unarmed): + return 0; + + case unchecked((uint)WeaponHash.RPG): + case unchecked((uint)WeaponHash.HomingLauncher): + case unchecked((uint)WeaponHash.Firework): + return 5; + + case unchecked((uint)WeaponHash.Minigun): + return 5; + + case unchecked((uint)WeaponHash.GolfClub): + case unchecked((uint)WeaponHash.PoolCue): + case unchecked((uint)WeaponHash.Bat): + return 4; + + case unchecked((uint)WeaponHash.Knife): + case unchecked((uint)WeaponHash.Nightstick): + case unchecked((uint)WeaponHash.Hammer): + case unchecked((uint)WeaponHash.Crowbar): + case unchecked((uint)WeaponHash.Wrench): + case unchecked((uint)WeaponHash.BattleAxe): + case unchecked((uint)WeaponHash.Dagger): + case unchecked((uint)WeaponHash.Hatchet): + case unchecked((uint)WeaponHash.KnuckleDuster): + case unchecked((uint)-581044007): + case unchecked((uint)-102323637): + case unchecked((uint)-538741184): + return 3; + + case unchecked((uint)-1357824103): + case unchecked((uint)-1074790547): + case unchecked((uint)2132975508): + case unchecked((uint)-2084633992): + case unchecked((uint)-952879014): + case unchecked((uint)100416529): + case unchecked((uint)WeaponHash.Gusenberg): + case unchecked((uint)WeaponHash.MG): + case unchecked((uint)WeaponHash.CombatMG): + case unchecked((uint)WeaponHash.CombatPDW): + case unchecked((uint)WeaponHash.AssaultSMG): + case unchecked((uint)WeaponHash.SMG): + case unchecked((uint)WeaponHash.HeavySniper): + case unchecked((uint)WeaponHash.PumpShotgun): + case unchecked((uint)WeaponHash.HeavyShotgun): + case unchecked((uint)WeaponHash.Musket): + case unchecked((uint)WeaponHash.AssaultShotgun): + case unchecked((uint)WeaponHash.BullpupShotgun): + case unchecked((uint)WeaponHash.SawnOffShotgun): + case unchecked((uint)WeaponHash.SweeperShotgun): + case unchecked((uint)WeaponHash.CompactRifle): + return 2; + } + + return 1; + } + + private string LoadAnim(string anim) + { + ulong startTime = Util.GetTickCount64(); + + while (!Function.Call(Hash.HAS_ANIM_DICT_LOADED, anim)) + { + Script.Yield(); + Function.Call(Hash.REQUEST_ANIM_DICT, anim); + if (Util.GetTickCount64() - startTime >= 1000) + { + break; + } + } + + return anim; + } + } +} diff --git a/RageCoop.Client/Sync/Entities/SyncedPed.cs b/RageCoop.Client/Sync/Entities/Ped/SyncedPed.cs similarity index 93% rename from RageCoop.Client/Sync/Entities/SyncedPed.cs rename to RageCoop.Client/Sync/Entities/Ped/SyncedPed.cs index 4313fbd..65c700d 100644 --- a/RageCoop.Client/Sync/Entities/SyncedPed.cs +++ b/RageCoop.Client/Sync/Entities/Ped/SyncedPed.cs @@ -13,7 +13,7 @@ namespace RageCoop.Client /// /// ? /// - public class SyncedPed : SyncedEntity + public partial class SyncedPed : SyncedEntity { #region CONSTRUCTORS @@ -64,7 +64,6 @@ namespace RageCoop.Client public bool IsPlayer { get => OwnerID == ID && ID != 0; } public Ped MainPed { get; internal set; } internal int Health { get; set; } - internal bool IsInStealthMode { get; set; } internal Vector3 HeadPosition { get; set; } internal Vector3 RightFootPosition { get; set; } @@ -85,17 +84,23 @@ namespace RageCoop.Client #region -- VARIABLES -- public byte Speed { get; set; } private bool _lastIsJumping = false; - internal bool IsJumping { get; set; } - internal bool IsOnLadder { get; set; } - internal bool IsVaulting { get; set; } - internal bool IsInParachuteFreeFall { get; set; } - internal bool IsParachuteOpen { get; set; } + internal PedDataFlags Flags; + + internal bool IsAiming => Flags.HasPedFlag(PedDataFlags.IsAiming); + internal bool IsReloading => Flags.HasPedFlag(PedDataFlags.IsReloading); + internal bool IsJumping => Flags.HasPedFlag(PedDataFlags.IsJumping); + internal bool IsRagdoll => Flags.HasPedFlag(PedDataFlags.IsRagdoll); + internal bool IsOnFire => Flags.HasPedFlag(PedDataFlags.IsOnFire); + internal bool IsInParachuteFreeFall => Flags.HasPedFlag(PedDataFlags.IsInParachuteFreeFall); + internal bool IsParachuteOpen => Flags.HasPedFlag(PedDataFlags.IsParachuteOpen); + internal bool IsOnLadder => Flags.HasPedFlag(PedDataFlags.IsOnLadder); + internal bool IsVaulting => Flags.HasPedFlag(PedDataFlags.IsVaulting); + internal bool IsInCover => Flags.HasPedFlag(PedDataFlags.IsInCover); + internal bool IsInLowCover => Flags.HasPedFlag(PedDataFlags.IsInLowCover); + internal bool IsInCoverFacingLeft => Flags.HasPedFlag(PedDataFlags.IsInCoverFacingLeft); + internal bool IsBlindFiring => Flags.HasPedFlag(PedDataFlags.IsBlindFiring); + internal bool IsInStealthMode => Flags.HasPedFlag(PedDataFlags.IsInStealthMode); internal Prop ParachuteProp { get; set; } = null; - internal bool IsRagdoll { get; set; } - internal bool IsOnFire { get; set; } - internal bool IsAiming { get; set; } - internal bool IsReloading { get; set; } - internal bool IsInCover { get; set; } internal uint CurrentWeaponHash { get; set; } private Dictionary _lastWeaponComponents = null; internal Dictionary WeaponComponents { get; set; } = null; @@ -286,6 +291,10 @@ namespace RageCoop.Client MainPed.SetConfigFlag((int)PedConfigFlags.CPED_CONFIG_FLAG_DisableHurt, true); MainPed.SetConfigFlag((int)PedConfigFlags.CPED_CONFIG_FLAG_DisableExplosionReactions, true); MainPed.SetConfigFlag((int)PedConfigFlags.CPED_CONFIG_FLAG_AvoidTearGas, false); + MainPed.SetConfigFlag((int)PedConfigFlags.CPED_CONFIG_FLAG_IgnoreBeingOnFire, true); + MainPed.SetConfigFlag((int)PedConfigFlags.CPED_CONFIG_FLAG_DisableEvasiveDives, true); + MainPed.SetConfigFlag((int)PedConfigFlags.CPED_CONFIG_FLAG_DisablePanicInVehicle, true); + MainPed.SetConfigFlag((int)PedConfigFlags.CPED_CONFIG_FLAG_BlockNonTemporaryEvents, true); MainPed.SetConfigFlag((int)PedConfigFlags.CPED_CONFIG_FLAG_DisableShockingEvents, true); MainPed.SetConfigFlag((int)PedConfigFlags.CPED_CONFIG_FLAG_DisableHurt, true); @@ -318,6 +327,8 @@ namespace RageCoop.Client private void DisplayOnFoot() { + + MainPed.Task.ClearAll(); CheckCurrentWeapon(); if (IsInParachuteFreeFall) { @@ -418,7 +429,7 @@ namespace RageCoop.Client SmoothTransition(); return; } - if (!IsOnLadder && MainPed.IsTaskActive(TaskType.CTaskGoToAndClimbLadder)) + else if (MainPed.IsTaskActive(TaskType.CTaskGoToAndClimbLadder)) { MainPed.Task.ClearAllImmediately(); _currentAnimation[1] = ""; @@ -474,12 +485,6 @@ namespace RageCoop.Client _lastRagdoll = true; _lastRagdollTime=Main.Ticked; } - /* - if((Main.Ticked-_lastRagdollTime>30)&&((Position.DistanceTo(MainPed.Position)>2)||MainPed.Velocity.Length()<3f)) - { - MainPed.ApplyForce((Position-MainPed.Position)*0.2f, (RotationVelocity-MainPed.RotationVelocity)*0.1f); - - }*/ return; } else @@ -712,22 +717,9 @@ namespace RageCoop.Client } } - private string LoadAnim(string anim) - { - ulong startTime = Util.GetTickCount64(); - while (!Function.Call(Hash.HAS_ANIM_DICT_LOADED, anim)) - { - Script.Yield(); - Function.Call(Hash.REQUEST_ANIM_DICT, anim); - if (Util.GetTickCount64() - startTime >= 1000) - { - break; - } - } - return anim; - } + #endregion private void DisplayInVehicle() { diff --git a/RageCoop.Client/Util/PedExtensions.cs b/RageCoop.Client/Util/PedExtensions.cs index 1254f79..b560a48 100644 --- a/RageCoop.Client/Util/PedExtensions.cs +++ b/RageCoop.Client/Util/PedExtensions.cs @@ -140,7 +140,18 @@ namespace RageCoop.Client if (ped.IsInCover || ped.IsGoingIntoCover) { - flags |=PedDataFlags.IsInCover; + flags |= PedDataFlags.IsInCover; + if (ped.IsInCoverFacingLeft) + { + flags |=PedDataFlags.IsInCover; + } + if (!Function.Call(Hash.IS_PED_IN_HIGH_COVER, ped)){ + flags|=PedDataFlags.IsInLowCover; + } + if (ped.IsTaskActive(TaskType.CTaskAimGunBlindFire)) + { + flags|=PedDataFlags.IsBlindFiring; + } } if (Function.Call(Hash.GET_PED_STEALTH_MOVEMENT, ped)) diff --git a/RageCoop.Core/Packets/Packets.cs b/RageCoop.Core/Packets/Packets.cs index c819c45..fa38686 100644 --- a/RageCoop.Core/Packets/Packets.cs +++ b/RageCoop.Core/Packets/Packets.cs @@ -95,6 +95,9 @@ namespace RageCoop.Core IsOnLadder = 1 << 8, IsVaulting = 1 << 9, IsInCover = 1 << 10, + IsInLowCover = 1 << 11, + IsInCoverFacingLeft = 1 << 12, + IsBlindFiring = 1 << 13, IsFullSync = 1<<15 , }