diff --git a/Client/Networking/Receive.cs b/Client/Networking/Receive.cs index bda3306..cedb7a5 100644 --- a/Client/Networking/Receive.cs +++ b/Client/Networking/Receive.cs @@ -346,7 +346,7 @@ namespace RageCoop.Client c.Clothes=packet.Clothes; c.WeaponComponents=packet.WeaponComponents; c.ModelHash=packet.ModelHash; - c.LastSynced=c.LastStateSynced = Main.Ticked; + c.LastStateSynced = Main.Ticked; } private static void VehicleSync(Packets.VehicleSync packet) { @@ -390,6 +390,7 @@ namespace RageCoop.Client v.Transformed = packet.Flag.HasFlag(VehicleDataFlags.IsTransformed); v.Passengers=new Dictionary(); v.LockStatus=packet.LockStatus; + v.RadioStation=packet.RadioStation; v.Flags=packet.Flag; foreach (KeyValuePair pair in packet.Passengers) { @@ -398,7 +399,7 @@ namespace RageCoop.Client v.Passengers.Add((VehicleSeat)pair.Key, EntityPool.GetPedByID(pair.Value)); } } - v.LastStateSynced=v.LastSynced= Main.Ticked; + v.LastStateSynced= Main.Ticked; } private static void ProjectileSync(Packets.ProjectileSync packet) diff --git a/Client/Networking/Send.cs b/Client/Networking/Send.cs index 5c0771a..18129c7 100644 --- a/Client/Networking/Send.cs +++ b/Client/Networking/Send.cs @@ -109,6 +109,10 @@ namespace RageCoop.Client Passengers=veh.GetPassengers(), LockStatus=veh.LockStatus, }; + if (v.MainVehicle==Game.Player.LastVehicle) + { + packet.RadioStation=Util.GetPlayerRadioIndex(); + } Send(packet, ConnectionChannel.VehicleSync); } public static void SendProjectile(SyncedProjectile sp) diff --git a/Client/Sync/Entities/SyncedVehicle.cs b/Client/Sync/Entities/SyncedVehicle.cs index ed3cbb2..9a159cc 100644 --- a/Client/Sync/Entities/SyncedVehicle.cs +++ b/Client/Sync/Entities/SyncedVehicle.cs @@ -55,7 +55,7 @@ namespace RageCoop.Client private ulong _vehicleStopTime { get; set; } private byte[] _lastVehicleColors = new byte[] { 0, 0 }; private Dictionary _lastVehicleMods = new Dictionary(); - + private byte _lastRadioIndex=255; #endregion #region -- CRITICAL STUFF -- @@ -90,6 +90,7 @@ namespace RageCoop.Client /// public Dictionary Passengers { get; set; } public float DeluxoWingRatio { get; set; } = -1; + public byte RadioStation = 255; private long _lastPositionCalibrated { get; set; } #endregion @@ -100,10 +101,8 @@ namespace RageCoop.Client // Check if all data avalible if(!IsReady) { return; } - // Skip update if no new sync message has arrived. if (!NeedUpdate) { return; } - #endregion #region -- CHECK EXISTENCE -- if ((MainVehicle == null) || (!MainVehicle.Exists()) || (MainVehicle.Model.Hash != ModelHash)) @@ -171,6 +170,10 @@ namespace RageCoop.Client { SyncedPed c = Passengers[seat]; + if (c?.ID==Main.LocalPlayerID && (RadioStation!=_lastRadioIndex)) + { + Util.SetPlayerRadioIndex(RadioStation); + } if (c?.MainPed!=null&&(!currentPassengers.ContainsKey(i))&&(!c.MainPed.IsBeingJacked)&&(!c.MainPed.IsTaskActive(TaskType.CTaskExitVehicleSeat))) { Passengers[seat].MainPed.SetIntoVehicle(MainVehicle, seat); } diff --git a/Client/Sync/SyncEvents.cs b/Client/Sync/SyncEvents.cs index 11dc75f..6f3f6e4 100644 --- a/Client/Sync/SyncEvents.cs +++ b/Client/Sync/SyncEvents.cs @@ -148,6 +148,7 @@ namespace RageCoop.Client { v.OwnerID=p.NewOwnerID; v.ModelHash=v.MainVehicle.Model; + v.LastSynced=Main.Ticked; // So this vehicle doesn's get re-spawned } private static void HandleNozzleTransform(Packets.NozzleTransform p) diff --git a/Client/Util/Util.cs b/Client/Util/Util.cs index 654d2cc..a9817e9 100644 --- a/Client/Util/Util.cs +++ b/Client/Util/Util.cs @@ -186,5 +186,15 @@ namespace RageCoop.Client if (v==null) { EntityPool.Add(v=new SyncedVehicle(veh)); } return v; } + + public static byte GetPlayerRadioIndex() + { + return (byte)Function.Call(Hash.GET_PLAYER_RADIO_STATION_INDEX); + } + public static void SetPlayerRadioIndex(int index) + { + Function.Call(Hash.SET_RADIO_TO_STATION_INDEX, index); + } + } } diff --git a/Core/Packets/VehiclePackets.cs b/Core/Packets/VehiclePackets.cs index 566f9ba..e80dae4 100644 --- a/Core/Packets/VehiclePackets.cs +++ b/Core/Packets/VehiclePackets.cs @@ -41,6 +41,7 @@ namespace RageCoop.Core /// public Dictionary Passengers { get; set; } + public byte RadioStation { get; set; } = 255; public override void Pack(NetOutgoingMessage message) { #region PacketToNetOutGoingMessage @@ -118,6 +119,9 @@ namespace RageCoop.Core // Write LockStatus byteArray.Add((byte)LockStatus); + // Write RadioStation + byteArray.Add(RadioStation); + byte[] result = byteArray.ToArray(); message.Write(result.Length); @@ -200,6 +204,9 @@ namespace RageCoop.Core // Read LockStatus LockStatus=(VehicleLockStatus)reader.ReadByte(); + + // Read RadioStation + RadioStation=reader.ReadByte(); #endregion } } @@ -257,6 +264,7 @@ namespace RageCoop.Core byteArray.AddFloat(DeluxoWingRatio); } + byte[] result = byteArray.ToArray(); message.Write(result.Length); @@ -293,6 +301,7 @@ namespace RageCoop.Core // Read steering angle SteeringAngle = reader.ReadFloat(); + if (reader.CanRead(4)) { DeluxoWingRatio= reader.ReadFloat();