Add radio station sync.

This commit is contained in:
Sardelka 2022-06-03 13:11:17 +08:00
parent 291ba5691b
commit 88a51cc154
6 changed files with 33 additions and 5 deletions

View File

@ -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<VehicleSeat, SyncedPed>();
v.LockStatus=packet.LockStatus;
v.RadioStation=packet.RadioStation;
v.Flags=packet.Flag;
foreach (KeyValuePair<int, int> 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)

View File

@ -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)

View File

@ -55,7 +55,7 @@ namespace RageCoop.Client
private ulong _vehicleStopTime { get; set; }
private byte[] _lastVehicleColors = new byte[] { 0, 0 };
private Dictionary<int, int> _lastVehicleMods = new Dictionary<int, int>();
private byte _lastRadioIndex=255;
#endregion
#region -- CRITICAL STUFF --
@ -90,6 +90,7 @@ namespace RageCoop.Client
/// </summary>
public Dictionary<VehicleSeat, SyncedPed> 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);
}

View File

@ -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)

View File

@ -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<int>(Hash.GET_PLAYER_RADIO_STATION_INDEX);
}
public static void SetPlayerRadioIndex(int index)
{
Function.Call(Hash.SET_RADIO_TO_STATION_INDEX, index);
}
}
}

View File

@ -41,6 +41,7 @@ namespace RageCoop.Core
/// </summary>
public Dictionary<int, int> 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();