From d30e1f6bb36edbc07e45ea18f82d07ad3efd8e2d Mon Sep 17 00:00:00 2001 From: "Nick I. A" <109136581+xEntenKoeniqx@users.noreply.github.com> Date: Sun, 14 Aug 2022 23:35:36 +0200 Subject: [PATCH] Added mouth animation when speaking --- RageCoop.Client/Networking/Receive.cs | 4 +++ RageCoop.Client/Networking/Send.cs | 2 +- .../Sync/Entities/Ped/SyncedPed.Animations.cs | 31 +++++++++++++++---- .../Sync/Entities/Ped/SyncedPed.cs | 18 +++++++++++ RageCoop.Core/Packets/Voice.cs | 3 ++ 5 files changed, 51 insertions(+), 7 deletions(-) diff --git a/RageCoop.Client/Networking/Receive.cs b/RageCoop.Client/Networking/Receive.cs index 76c729b..05053ed 100644 --- a/RageCoop.Client/Networking/Receive.cs +++ b/RageCoop.Client/Networking/Receive.cs @@ -272,6 +272,10 @@ namespace RageCoop.Client Main.QueueAction(() => { + SyncedPed player = EntityPool.GetPedByID(packet.ID); + player.IsSpeaking = true; + player.LastSpeakingTime = Main.Ticked; + Sync.Voice.AddVoiceData(packet.Buffer, packet.Recorded); }); } diff --git a/RageCoop.Client/Networking/Send.cs b/RageCoop.Client/Networking/Send.cs index 7fb5e77..4f27adc 100644 --- a/RageCoop.Client/Networking/Send.cs +++ b/RageCoop.Client/Networking/Send.cs @@ -201,7 +201,7 @@ namespace RageCoop.Client } public static void SendVoiceMessage(byte[] buffer, int recorded) { - SendSync(new Packets.Voice() { Buffer = buffer, Recorded = recorded }, ConnectionChannel.Voice, NetDeliveryMethod.ReliableOrdered); + SendSync(new Packets.Voice() { ID = Main.LocalPlayerID, Buffer = buffer, Recorded = recorded }, ConnectionChannel.Voice, NetDeliveryMethod.ReliableOrdered); } } } diff --git a/RageCoop.Client/Sync/Entities/Ped/SyncedPed.Animations.cs b/RageCoop.Client/Sync/Entities/Ped/SyncedPed.Animations.cs index 1b65bca..4e4552b 100644 --- a/RageCoop.Client/Sync/Entities/Ped/SyncedPed.Animations.cs +++ b/RageCoop.Client/Sync/Entities/Ped/SyncedPed.Animations.cs @@ -1,15 +1,34 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using GTA; +using GTA; using GTA.Native; -using System.Threading.Tasks; namespace RageCoop.Client { public partial class SyncedPed { + private void DisplaySpeaking(bool speaking) + { + if (MainPed == null || !MainPed.Exists() || !MainPed.IsHuman) + return; + + if (speaking) + { + Function.Call(Hash.PLAY_FACIAL_ANIM, MainPed.Handle, "mic_chatter", "mp_facial"); + return; + } + + switch (MainPed.Gender) + { + case Gender.Male: + Function.Call(Hash.PLAY_FACIAL_ANIM, MainPed.Handle, "mood_normal_1", "facials@gen_male@variations@normal"); + break; + case Gender.Female: + Function.Call(Hash.PLAY_FACIAL_ANIM, MainPed.Handle, "mood_normal_1", "facials@gen_female@variations@normal"); + break; + default: + Function.Call(Hash.PLAY_FACIAL_ANIM, MainPed.Handle, "mood_normal_1", "facials@mime@variations@normal"); + break; + } + } private void DisplayInCover() { diff --git a/RageCoop.Client/Sync/Entities/Ped/SyncedPed.cs b/RageCoop.Client/Sync/Entities/Ped/SyncedPed.cs index 65c700d..c36b2b6 100644 --- a/RageCoop.Client/Sync/Entities/Ped/SyncedPed.cs +++ b/RageCoop.Client/Sync/Entities/Ped/SyncedPed.cs @@ -7,6 +7,7 @@ using System; using System.Collections.Generic; using System.Drawing; using System.Linq; +using System.Windows.Forms; namespace RageCoop.Client { @@ -80,6 +81,8 @@ namespace RageCoop.Client internal float Heading { get; set; } + internal ulong LastSpeakingTime { get; set; } = 0; + internal bool IsSpeaking { get; set; } = false; #region -- VARIABLES -- public byte Speed { get; set; } @@ -214,6 +217,21 @@ namespace RageCoop.Client DisplayOnFoot(); } + if (IsSpeaking) + { + if (Main.Ticked - LastSpeakingTime < 10) + { + DisplaySpeaking(true); + } + else + { + DisplaySpeaking(false); + + IsSpeaking = false; + LastSpeakingTime = 0; + } + } + LastUpdated=Main.Ticked; } diff --git a/RageCoop.Core/Packets/Voice.cs b/RageCoop.Core/Packets/Voice.cs index a2e82d9..a5504b7 100644 --- a/RageCoop.Core/Packets/Voice.cs +++ b/RageCoop.Core/Packets/Voice.cs @@ -6,12 +6,14 @@ namespace RageCoop.Core { internal class Voice : Packet { + public int ID { get; set; } public byte[] Buffer { get; set; } public int Recorded { get; set; } public override PacketType Type => PacketType.Voice; public override byte[] Serialize() { var data = new List(); + data.AddInt(ID); data.AddArray(Buffer); data.AddInt(Recorded); return data.ToArray(); @@ -19,6 +21,7 @@ namespace RageCoop.Core public override void Deserialize(byte[] array) { var reader = new BitReader(array); + ID = reader.ReadInt32(); Buffer = reader.ReadByteArray(); Recorded = reader.ReadInt32(); }