2022-09-08 12:41:56 -07:00
|
|
|
|
using GTA;
|
2022-05-30 14:32:38 +08:00
|
|
|
|
using GTA.Math;
|
2022-05-22 15:55:26 +08:00
|
|
|
|
using Lidgren.Network;
|
2022-09-08 12:41:56 -07:00
|
|
|
|
using System.Collections.Generic;
|
2022-05-22 15:55:26 +08:00
|
|
|
|
|
|
|
|
|
namespace RageCoop.Core
|
|
|
|
|
{
|
2022-07-01 14:39:43 +08:00
|
|
|
|
internal partial class Packets
|
2022-05-22 15:55:26 +08:00
|
|
|
|
{
|
2022-07-17 11:59:37 +08:00
|
|
|
|
|
|
|
|
|
public class VehicleSync : Packet
|
2022-05-22 15:55:26 +08:00
|
|
|
|
{
|
2022-09-08 12:41:56 -07:00
|
|
|
|
public override PacketType Type => PacketType.VehicleSync;
|
2022-05-22 15:55:26 +08:00
|
|
|
|
public int ID { get; set; }
|
|
|
|
|
|
|
|
|
|
public int OwnerID { get; set; }
|
|
|
|
|
|
2022-07-17 12:22:11 +08:00
|
|
|
|
public VehicleDataFlags Flags { get; set; }
|
2022-07-17 11:59:37 +08:00
|
|
|
|
|
|
|
|
|
public Vector3 Position { get; set; }
|
|
|
|
|
|
|
|
|
|
public Quaternion Quaternion { get; set; }
|
|
|
|
|
// public Vector3 Rotation { get; set; }
|
|
|
|
|
|
|
|
|
|
public Vector3 Velocity { get; set; }
|
|
|
|
|
|
|
|
|
|
public Vector3 RotationVelocity { get; set; }
|
|
|
|
|
|
|
|
|
|
public float ThrottlePower { get; set; }
|
|
|
|
|
public float BrakePower { get; set; }
|
|
|
|
|
public float SteeringAngle { get; set; }
|
|
|
|
|
public float DeluxoWingRatio { get; set; } = -1;
|
|
|
|
|
|
|
|
|
|
#region FULL-SYNC
|
2022-05-22 15:55:26 +08:00
|
|
|
|
public int ModelHash { get; set; }
|
|
|
|
|
|
|
|
|
|
public float EngineHealth { get; set; }
|
|
|
|
|
|
|
|
|
|
public byte[] Colors { get; set; }
|
|
|
|
|
|
|
|
|
|
public Dictionary<int, int> Mods { get; set; }
|
|
|
|
|
|
|
|
|
|
public VehicleDamageModel DamageModel { get; set; }
|
|
|
|
|
|
|
|
|
|
public byte LandingGear { get; set; }
|
2022-06-19 13:36:23 +08:00
|
|
|
|
public byte RoofState { get; set; }
|
2022-05-22 15:55:26 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public VehicleLockStatus LockStatus { get; set; }
|
|
|
|
|
|
2022-07-09 22:18:00 +08:00
|
|
|
|
public int Livery { get; set; } = -1;
|
|
|
|
|
|
2022-06-03 13:11:17 +08:00
|
|
|
|
public byte RadioStation { get; set; } = 255;
|
2022-06-20 10:27:45 +08:00
|
|
|
|
public string LicensePlate { get; set; }
|
2022-07-17 11:59:37 +08:00
|
|
|
|
#endregion
|
|
|
|
|
|
2022-09-08 12:37:06 -07:00
|
|
|
|
protected override void Serialize(NetOutgoingMessage m)
|
2022-05-22 15:55:26 +08:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
2022-09-08 12:37:06 -07:00
|
|
|
|
m.Write(ID);
|
|
|
|
|
m.Write(OwnerID);
|
|
|
|
|
m.Write((ushort)Flags);
|
|
|
|
|
m.Write(Position);
|
|
|
|
|
m.Write(Quaternion);
|
|
|
|
|
m.Write(Velocity);
|
|
|
|
|
m.Write(RotationVelocity);
|
|
|
|
|
m.Write(ThrottlePower);
|
|
|
|
|
m.Write(BrakePower);
|
|
|
|
|
m.Write(SteeringAngle);
|
2022-06-03 13:11:17 +08:00
|
|
|
|
|
2022-07-17 12:22:11 +08:00
|
|
|
|
if (Flags.HasVehFlag(VehicleDataFlags.IsDeluxoHovering))
|
2022-06-20 10:27:45 +08:00
|
|
|
|
{
|
2022-09-08 12:37:06 -07:00
|
|
|
|
m.Write(DeluxoWingRatio);
|
2022-06-20 10:27:45 +08:00
|
|
|
|
}
|
2022-05-22 15:55:26 +08:00
|
|
|
|
|
2022-07-17 12:22:11 +08:00
|
|
|
|
if (Flags.HasVehFlag(VehicleDataFlags.IsFullSync))
|
2022-05-22 15:55:26 +08:00
|
|
|
|
{
|
2022-09-08 12:37:06 -07:00
|
|
|
|
m.Write(ModelHash);
|
|
|
|
|
m.Write(EngineHealth);
|
2022-05-22 15:55:26 +08:00
|
|
|
|
|
2022-07-17 11:59:37 +08:00
|
|
|
|
// Check
|
2022-07-17 12:22:11 +08:00
|
|
|
|
if (Flags.HasVehFlag(VehicleDataFlags.IsAircraft))
|
2022-05-22 15:55:26 +08:00
|
|
|
|
{
|
2022-07-17 11:59:37 +08:00
|
|
|
|
// Write the vehicle landing gear
|
2022-09-08 12:37:06 -07:00
|
|
|
|
m.Write(LandingGear);
|
2022-07-17 11:59:37 +08:00
|
|
|
|
}
|
2022-07-17 12:22:11 +08:00
|
|
|
|
if (Flags.HasVehFlag(VehicleDataFlags.HasRoof))
|
2022-07-17 11:59:37 +08:00
|
|
|
|
{
|
2022-09-08 12:37:06 -07:00
|
|
|
|
m.Write(RoofState);
|
2022-07-17 11:59:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Write vehicle colors
|
2022-09-08 12:37:06 -07:00
|
|
|
|
m.Write(Colors[0]);
|
|
|
|
|
m.Write(Colors[1]);
|
2022-07-17 11:59:37 +08:00
|
|
|
|
|
|
|
|
|
// Write vehicle mods
|
|
|
|
|
// Write the count of mods
|
2022-09-08 12:37:06 -07:00
|
|
|
|
m.Write((short)Mods.Count);
|
2022-07-17 11:59:37 +08:00
|
|
|
|
// Loop the dictionary and add the values
|
|
|
|
|
foreach (KeyValuePair<int, int> mod in Mods)
|
|
|
|
|
{
|
|
|
|
|
// Write the mod value
|
2022-09-08 12:37:06 -07:00
|
|
|
|
m.Write(mod.Key);
|
|
|
|
|
m.Write(mod.Value);
|
2022-07-17 11:59:37 +08:00
|
|
|
|
}
|
2022-05-22 15:55:26 +08:00
|
|
|
|
|
2022-07-17 11:59:37 +08:00
|
|
|
|
if (!DamageModel.Equals(default(VehicleDamageModel)))
|
|
|
|
|
{
|
|
|
|
|
// Write boolean = true
|
2022-09-08 12:37:06 -07:00
|
|
|
|
m.Write(true);
|
2022-07-17 11:59:37 +08:00
|
|
|
|
// Write vehicle damage model
|
2022-09-08 12:37:06 -07:00
|
|
|
|
m.Write(DamageModel.BrokenDoors);
|
|
|
|
|
m.Write(DamageModel.OpenedDoors);
|
|
|
|
|
m.Write(DamageModel.BrokenWindows);
|
|
|
|
|
m.Write(DamageModel.BurstedTires);
|
|
|
|
|
m.Write(DamageModel.LeftHeadLightBroken);
|
|
|
|
|
m.Write(DamageModel.RightHeadLightBroken);
|
2022-07-17 11:59:37 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Write boolean = false
|
2022-09-08 12:37:06 -07:00
|
|
|
|
m.Write(false);
|
2022-07-17 11:59:37 +08:00
|
|
|
|
}
|
2022-05-22 15:55:26 +08:00
|
|
|
|
|
2022-07-17 11:59:37 +08:00
|
|
|
|
// Write LockStatus
|
2022-09-08 12:37:06 -07:00
|
|
|
|
m.Write((byte)LockStatus);
|
2022-05-22 15:55:26 +08:00
|
|
|
|
|
2022-07-17 11:59:37 +08:00
|
|
|
|
// Write RadioStation
|
2022-09-08 12:37:06 -07:00
|
|
|
|
m.Write(RadioStation);
|
2022-05-22 15:55:26 +08:00
|
|
|
|
|
2022-07-17 11:59:37 +08:00
|
|
|
|
// Write LicensePlate
|
2022-09-08 12:37:06 -07:00
|
|
|
|
m.Write(LicensePlate);
|
2022-05-22 15:55:26 +08:00
|
|
|
|
|
2022-09-08 12:41:56 -07:00
|
|
|
|
m.Write((byte)(Livery + 1));
|
2022-05-31 09:14:30 +08:00
|
|
|
|
}
|
2022-05-22 15:55:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-09-08 12:37:06 -07:00
|
|
|
|
public override void Deserialize(NetIncomingMessage m)
|
2022-05-22 15:55:26 +08:00
|
|
|
|
{
|
|
|
|
|
#region NetIncomingMessageToPacket
|
|
|
|
|
|
2022-09-08 12:37:06 -07:00
|
|
|
|
ID = m.ReadInt32();
|
|
|
|
|
OwnerID = m.ReadInt32();
|
2022-09-08 12:41:56 -07:00
|
|
|
|
Flags = (VehicleDataFlags)m.ReadUInt16();
|
2022-09-08 12:37:06 -07:00
|
|
|
|
Position = m.ReadVector3();
|
2022-09-08 12:41:56 -07:00
|
|
|
|
Quaternion = m.ReadQuaternion();
|
|
|
|
|
Velocity = m.ReadVector3();
|
|
|
|
|
RotationVelocity = m.ReadVector3();
|
|
|
|
|
ThrottlePower = m.ReadFloat();
|
|
|
|
|
BrakePower = m.ReadFloat();
|
2022-09-08 12:37:06 -07:00
|
|
|
|
SteeringAngle = m.ReadFloat();
|
2022-05-22 15:55:26 +08:00
|
|
|
|
|
2022-06-03 13:11:17 +08:00
|
|
|
|
|
2022-07-17 12:22:11 +08:00
|
|
|
|
if (Flags.HasVehFlag(VehicleDataFlags.IsDeluxoHovering))
|
2022-07-17 11:59:37 +08:00
|
|
|
|
{
|
2022-09-08 12:37:06 -07:00
|
|
|
|
DeluxoWingRatio = m.ReadFloat();
|
2022-07-17 11:59:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-07-17 12:22:11 +08:00
|
|
|
|
if (Flags.HasVehFlag(VehicleDataFlags.IsFullSync))
|
2022-05-31 09:14:30 +08:00
|
|
|
|
{
|
2022-07-17 11:59:37 +08:00
|
|
|
|
// Read vehicle model hash
|
2022-09-08 12:37:06 -07:00
|
|
|
|
ModelHash = m.ReadInt32();
|
2022-07-17 11:59:37 +08:00
|
|
|
|
|
|
|
|
|
// Read vehicle engine health
|
2022-09-08 12:37:06 -07:00
|
|
|
|
EngineHealth = m.ReadFloat();
|
2022-07-17 11:59:37 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Check
|
2022-07-17 12:22:11 +08:00
|
|
|
|
if (Flags.HasVehFlag(VehicleDataFlags.IsAircraft))
|
2022-07-17 11:59:37 +08:00
|
|
|
|
{
|
|
|
|
|
// Read vehicle landing gear
|
2022-09-08 12:37:06 -07:00
|
|
|
|
LandingGear = m.ReadByte();
|
2022-07-17 11:59:37 +08:00
|
|
|
|
}
|
2022-07-17 12:22:11 +08:00
|
|
|
|
if (Flags.HasVehFlag(VehicleDataFlags.HasRoof))
|
2022-07-17 11:59:37 +08:00
|
|
|
|
{
|
2022-09-08 12:41:56 -07:00
|
|
|
|
RoofState = m.ReadByte();
|
2022-07-17 11:59:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Read vehicle colors
|
2022-09-08 12:37:06 -07:00
|
|
|
|
byte vehColor1 = m.ReadByte();
|
|
|
|
|
byte vehColor2 = m.ReadByte();
|
2022-07-17 11:59:37 +08:00
|
|
|
|
Colors = new byte[] { vehColor1, vehColor2 };
|
|
|
|
|
|
|
|
|
|
// Read vehicle mods
|
|
|
|
|
// Create new Dictionary
|
|
|
|
|
Mods = new Dictionary<int, int>();
|
|
|
|
|
// Read count of mods
|
2022-09-08 12:37:06 -07:00
|
|
|
|
short vehModCount = m.ReadInt16();
|
2022-07-17 11:59:37 +08:00
|
|
|
|
// Loop
|
|
|
|
|
for (int i = 0; i < vehModCount; i++)
|
|
|
|
|
{
|
|
|
|
|
// Read the mod value
|
2022-09-08 12:37:06 -07:00
|
|
|
|
Mods.Add(m.ReadInt32(), m.ReadInt32());
|
2022-07-17 11:59:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-09-08 12:37:06 -07:00
|
|
|
|
if (m.ReadBoolean())
|
2022-07-17 11:59:37 +08:00
|
|
|
|
{
|
|
|
|
|
// Read vehicle damage model
|
|
|
|
|
DamageModel = new VehicleDamageModel()
|
|
|
|
|
{
|
2022-09-08 12:37:06 -07:00
|
|
|
|
BrokenDoors = m.ReadByte(),
|
2022-09-08 12:41:56 -07:00
|
|
|
|
OpenedDoors = m.ReadByte(),
|
2022-09-08 12:37:06 -07:00
|
|
|
|
BrokenWindows = m.ReadByte(),
|
|
|
|
|
BurstedTires = m.ReadInt16(),
|
|
|
|
|
LeftHeadLightBroken = m.ReadByte(),
|
|
|
|
|
RightHeadLightBroken = m.ReadByte()
|
2022-07-17 11:59:37 +08:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Read LockStatus
|
2022-09-08 12:41:56 -07:00
|
|
|
|
LockStatus = (VehicleLockStatus)m.ReadByte();
|
2022-07-17 11:59:37 +08:00
|
|
|
|
|
|
|
|
|
// Read RadioStation
|
2022-09-08 12:41:56 -07:00
|
|
|
|
RadioStation = m.ReadByte();
|
2022-07-17 11:59:37 +08:00
|
|
|
|
|
2022-09-08 12:41:56 -07:00
|
|
|
|
LicensePlate = m.ReadString();
|
2022-07-17 11:59:37 +08:00
|
|
|
|
|
2022-09-08 12:41:56 -07:00
|
|
|
|
Livery = m.ReadByte() - 1;
|
2022-05-31 09:14:30 +08:00
|
|
|
|
}
|
2022-05-22 15:55:26 +08:00
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|