RAGECOOP-V/Client/Packets.cs

856 lines
22 KiB
C#
Raw Normal View History

2021-07-07 13:36:25 +02:00
using System;
using System.IO;
using System.Collections.Generic;
using Lidgren.Network;
using ProtoBuf;
using GTA.Math;
namespace CoopClient
{
#region CLIENT-ONLY
2021-08-14 21:49:23 +02:00
static class VectorExtensions
2021-07-07 13:36:25 +02:00
{
2021-08-13 15:20:26 +02:00
public static Vector3 ToVector(this Quaternion vec)
{
return new Vector3()
{
X = vec.X,
Y = vec.Y,
Z = vec.Z
};
}
public static Quaternion ToQuaternion(this Vector3 vec, float vW = 0.0f)
{
return new Quaternion()
{
X = vec.X,
Y = vec.Y,
Z = vec.Z,
W = vW
};
}
2021-07-07 13:36:25 +02:00
public static LVector3 ToLVector(this Vector3 vec)
{
return new LVector3()
{
X = vec.X,
Y = vec.Y,
2021-08-13 15:20:26 +02:00
Z = vec.Z
2021-07-07 13:36:25 +02:00
};
}
public static LQuaternion ToLQuaternion(this Quaternion vec)
{
return new LQuaternion()
{
X = vec.X,
Y = vec.Y,
Z = vec.Z,
W = vec.W
};
}
2021-07-07 13:36:25 +02:00
}
#endregion
[ProtoContract]
2021-08-14 21:49:23 +02:00
struct LVector3
2021-07-07 13:36:25 +02:00
{
#region CLIENT-ONLY
public Vector3 ToVector()
{
return new Vector3(X, Y, Z);
}
#endregion
public LVector3(float X, float Y, float Z)
{
this.X = X;
this.Y = Y;
this.Z = Z;
}
[ProtoMember(1)]
public float X { get; set; }
[ProtoMember(2)]
public float Y { get; set; }
[ProtoMember(3)]
public float Z { get; set; }
}
[ProtoContract]
2021-08-14 21:49:23 +02:00
struct LQuaternion
{
#region CLIENT-ONLY
public Quaternion ToQuaternion()
{
return new Quaternion(X, Y, Z, W);
}
#endregion
public LQuaternion(float X, float Y, float Z, float W)
{
this.X = X;
this.Y = Y;
this.Z = Z;
this.W = W;
}
[ProtoMember(1)]
public float X { get; set; }
[ProtoMember(2)]
public float Y { get; set; }
[ProtoMember(3)]
public float Z { get; set; }
[ProtoMember(4)]
public float W { get; set; }
}
2021-08-14 21:49:23 +02:00
enum PacketTypes
2021-07-07 13:36:25 +02:00
{
HandshakePacket,
PlayerConnectPacket,
PlayerDisconnectPacket,
FullSyncPlayerPacket,
FullSyncPlayerVehPacket,
2021-07-07 13:36:25 +02:00
LightSyncPlayerPacket,
LightSyncPlayerVehPacket,
FullSyncNpcPacket,
FullSyncNpcVehPacket,
2021-08-20 17:28:13 +02:00
ChatMessagePacket,
NativeCallPacket
2021-07-07 13:36:25 +02:00
}
[Flags]
2021-08-14 21:49:23 +02:00
enum PedDataFlags
2021-07-07 13:36:25 +02:00
{
LastSyncWasFull = 1 << 0,
IsAiming = 1 << 1,
IsShooting = 1 << 2,
IsReloading = 1 << 3,
IsJumping = 1 << 4,
IsRagdoll = 1 << 5,
IsOnFire = 1 << 6,
IsInVehicle = 1 << 7
2021-07-07 13:36:25 +02:00
}
#region ===== VEHICLE DATA =====
2021-07-10 23:41:28 +02:00
[Flags]
2021-08-14 21:49:23 +02:00
enum VehicleDataFlags
2021-07-10 23:41:28 +02:00
{
LastSyncWasFull = 1 << 0,
IsInVehicle = 1 << 1,
IsEngineRunning = 1 << 2,
AreLightsOn = 1 << 3,
2021-07-13 12:00:37 +02:00
AreHighBeamsOn = 1 << 4,
IsInBurnout = 1 << 5,
IsSirenActive = 1 << 6,
IsDead = 1 << 7
2021-07-10 23:41:28 +02:00
}
[ProtoContract]
public struct VehicleDoors
{
#region CLIENT-ONLY
public VehicleDoors(float angleRatio = 0f, bool broken = false, bool open = false, bool fullyOpen = false)
{
AngleRatio = angleRatio;
Broken = broken;
Open = open;
FullyOpen = fullyOpen;
}
#endregion
[ProtoMember(1)]
public float AngleRatio { get; set; }
[ProtoMember(2)]
public bool Broken { get; set; }
[ProtoMember(3)]
public bool Open { get; set; }
[ProtoMember(4)]
public bool FullyOpen { get; set; }
}
#endregion
2021-07-07 13:36:25 +02:00
public interface IPacket
{
void PacketToNetOutGoingMessage(NetOutgoingMessage message);
void NetIncomingMessageToPacket(NetIncomingMessage message);
}
public abstract class Packet : IPacket
{
public abstract void PacketToNetOutGoingMessage(NetOutgoingMessage message);
public abstract void NetIncomingMessageToPacket(NetIncomingMessage message);
}
#region -- PLAYER --
2021-07-07 13:36:25 +02:00
[ProtoContract]
2021-08-14 21:49:23 +02:00
class HandshakePacket : Packet
2021-07-07 13:36:25 +02:00
{
[ProtoMember(1)]
2021-08-16 14:03:05 +02:00
public long ID { get; set; }
2021-07-07 13:36:25 +02:00
[ProtoMember(2)]
public string SocialClubName { get; set; }
[ProtoMember(3)]
public string Username { get; set; }
[ProtoMember(4)]
public string ModVersion { get; set; }
[ProtoMember(5)]
public bool NpcsAllowed { get; set; }
public override void PacketToNetOutGoingMessage(NetOutgoingMessage message)
{
message.Write((byte)PacketTypes.HandshakePacket);
2021-07-07 18:05:08 +02:00
byte[] result = CoopSerializer.Serialize(this);
2021-07-07 13:36:25 +02:00
message.Write(result.Length);
message.Write(result);
}
public override void NetIncomingMessageToPacket(NetIncomingMessage message)
{
int len = message.ReadInt32();
2021-07-07 18:05:08 +02:00
HandshakePacket data = CoopSerializer.Deserialize<HandshakePacket>(message.ReadBytes(len));
2021-07-07 13:36:25 +02:00
ID = data.ID;
SocialClubName = data.SocialClubName;
Username = data.Username;
ModVersion = data.ModVersion;
NpcsAllowed = data.NpcsAllowed;
}
}
[ProtoContract]
2021-08-14 21:49:23 +02:00
class PlayerConnectPacket : Packet
2021-07-07 13:36:25 +02:00
{
[ProtoMember(1)]
2021-08-16 14:03:05 +02:00
public long Player { get; set; }
2021-07-07 13:36:25 +02:00
[ProtoMember(2)]
public string SocialClubName { get; set; }
[ProtoMember(3)]
public string Username { get; set; }
public override void PacketToNetOutGoingMessage(NetOutgoingMessage message)
{
message.Write((byte)PacketTypes.PlayerConnectPacket);
2021-07-07 18:05:08 +02:00
byte[] result = CoopSerializer.Serialize(this);
2021-07-07 13:36:25 +02:00
message.Write(result.Length);
message.Write(result);
}
public override void NetIncomingMessageToPacket(NetIncomingMessage message)
{
int len = message.ReadInt32();
2021-07-07 18:05:08 +02:00
PlayerConnectPacket data = CoopSerializer.Deserialize<PlayerConnectPacket>(message.ReadBytes(len));
2021-07-07 13:36:25 +02:00
Player = data.Player;
SocialClubName = data.SocialClubName;
Username = data.Username;
}
}
[ProtoContract]
2021-08-14 21:49:23 +02:00
class PlayerDisconnectPacket : Packet
2021-07-07 13:36:25 +02:00
{
[ProtoMember(1)]
2021-08-16 14:03:05 +02:00
public long Player { get; set; }
2021-07-07 13:36:25 +02:00
public override void PacketToNetOutGoingMessage(NetOutgoingMessage message)
{
message.Write((byte)PacketTypes.PlayerDisconnectPacket);
2021-07-07 18:05:08 +02:00
byte[] result = CoopSerializer.Serialize(this);
2021-07-07 13:36:25 +02:00
message.Write(result.Length);
message.Write(result);
}
public override void NetIncomingMessageToPacket(NetIncomingMessage message)
{
int len = message.ReadInt32();
2021-07-07 18:05:08 +02:00
PlayerDisconnectPacket data = CoopSerializer.Deserialize<PlayerDisconnectPacket>(message.ReadBytes(len));
2021-07-07 13:36:25 +02:00
Player = data.Player;
}
}
[ProtoContract]
struct PlayerPacket
2021-07-07 13:36:25 +02:00
{
[ProtoMember(1)]
2021-08-16 14:03:05 +02:00
public long Player { get; set; }
2021-07-07 13:36:25 +02:00
[ProtoMember(2)]
public int Health { get; set; }
2021-07-07 13:36:25 +02:00
[ProtoMember(3)]
public LVector3 Position { get; set; }
2021-07-07 13:36:25 +02:00
[ProtoMember(4)]
public float Latency { get; set; }
}
2021-07-07 13:36:25 +02:00
[ProtoContract]
class FullSyncPlayerPacket : Packet
{
[ProtoMember(1)]
public PlayerPacket Extra { get; set; }
2021-07-07 13:36:25 +02:00
[ProtoMember(2)]
public int ModelHash { get; set; }
[ProtoMember(3)]
public Dictionary<int, int> Props { get; set; }
[ProtoMember(4)]
2021-07-07 13:36:25 +02:00
public LVector3 Rotation { get; set; }
[ProtoMember(5)]
2021-07-07 13:36:25 +02:00
public LVector3 Velocity { get; set; }
[ProtoMember(6)]
2021-07-07 13:36:25 +02:00
public byte Speed { get; set; }
[ProtoMember(7)]
2021-07-07 13:36:25 +02:00
public LVector3 AimCoords { get; set; }
[ProtoMember(8)]
2021-07-07 13:36:25 +02:00
public int CurrentWeaponHash { get; set; }
[ProtoMember(9)]
2021-07-07 13:36:25 +02:00
public byte? Flag { get; set; } = 0;
public override void PacketToNetOutGoingMessage(NetOutgoingMessage message)
{
message.Write((byte)PacketTypes.FullSyncPlayerPacket);
2021-07-07 18:05:08 +02:00
byte[] result = CoopSerializer.Serialize(this);
2021-07-07 13:36:25 +02:00
message.Write(result.Length);
message.Write(result);
}
public override void NetIncomingMessageToPacket(NetIncomingMessage message)
{
int len = message.ReadInt32();
2021-07-07 18:05:08 +02:00
FullSyncPlayerPacket data = CoopSerializer.Deserialize<FullSyncPlayerPacket>(message.ReadBytes(len));
2021-07-07 13:36:25 +02:00
Extra = data.Extra;
2021-07-07 13:36:25 +02:00
ModelHash = data.ModelHash;
Props = data.Props;
Rotation = data.Rotation;
Velocity = data.Velocity;
Speed = data.Speed;
AimCoords = data.AimCoords;
CurrentWeaponHash = data.CurrentWeaponHash;
Flag = data.Flag;
}
}
[ProtoContract]
2021-08-14 21:49:23 +02:00
class FullSyncPlayerVehPacket : Packet
2021-07-07 13:36:25 +02:00
{
[ProtoMember(1)]
public PlayerPacket Extra { get; set; }
2021-07-07 13:36:25 +02:00
[ProtoMember(2)]
public int ModelHash { get; set; }
[ProtoMember(3)]
public Dictionary<int, int> Props { get; set; }
[ProtoMember(4)]
public int VehModelHash { get; set; }
2021-07-07 13:36:25 +02:00
[ProtoMember(5)]
public int VehSeatIndex { get; set; }
2021-07-07 13:36:25 +02:00
[ProtoMember(6)]
public LVector3 VehPosition { get; set; }
2021-07-07 13:36:25 +02:00
[ProtoMember(7)]
public LQuaternion VehRotation { get; set; }
2021-07-07 13:36:25 +02:00
[ProtoMember(8)]
2021-08-16 16:51:33 +02:00
public float VehEngineHealth { get; set; }
2021-07-07 13:36:25 +02:00
[ProtoMember(9)]
2021-08-16 16:51:33 +02:00
public LVector3 VehVelocity { get; set; }
[ProtoMember(10)]
2021-08-16 16:51:33 +02:00
public float VehSpeed { get; set; }
[ProtoMember(11)]
2021-08-16 16:51:33 +02:00
public float VehSteeringAngle { get; set; }
2021-08-13 15:52:30 +02:00
[ProtoMember(12)]
2021-08-16 16:51:33 +02:00
public int[] VehColors { get; set; }
[ProtoMember(13)]
2021-08-22 13:59:15 +02:00
public Dictionary<int, int> VehMods { get; set; }
2021-08-16 16:51:33 +02:00
[ProtoMember(14)]
2021-08-22 13:59:15 +02:00
public VehicleDoors[] VehDoors { get; set; }
[ProtoMember(15)]
2021-07-07 13:36:25 +02:00
public byte? Flag { get; set; } = 0;
public override void PacketToNetOutGoingMessage(NetOutgoingMessage message)
{
message.Write((byte)PacketTypes.FullSyncPlayerVehPacket);
2021-07-07 13:36:25 +02:00
2021-07-07 18:05:08 +02:00
byte[] result = CoopSerializer.Serialize(this);
2021-07-07 13:36:25 +02:00
message.Write(result.Length);
message.Write(result);
}
public override void NetIncomingMessageToPacket(NetIncomingMessage message)
{
int len = message.ReadInt32();
FullSyncPlayerVehPacket data = CoopSerializer.Deserialize<FullSyncPlayerVehPacket>(message.ReadBytes(len));
2021-07-07 13:36:25 +02:00
Extra = data.Extra;
2021-07-07 13:36:25 +02:00
ModelHash = data.ModelHash;
Props = data.Props;
VehModelHash = data.VehModelHash;
VehSeatIndex = data.VehSeatIndex;
VehPosition = data.VehPosition;
VehRotation = data.VehRotation;
2021-08-16 16:51:33 +02:00
VehEngineHealth = data.VehEngineHealth;
VehVelocity = data.VehVelocity;
VehSpeed = data.VehSpeed;
2021-07-13 16:30:33 +02:00
VehSteeringAngle = data.VehSteeringAngle;
VehColors = data.VehColors;
2021-08-22 13:59:15 +02:00
VehMods = data.VehMods;
VehDoors = data.VehDoors;
2021-07-07 13:36:25 +02:00
Flag = data.Flag;
}
}
[ProtoContract]
2021-08-14 21:49:23 +02:00
class LightSyncPlayerPacket : Packet
2021-07-07 13:36:25 +02:00
{
[ProtoMember(1)]
public PlayerPacket Extra { get; set; }
2021-07-07 13:36:25 +02:00
[ProtoMember(2)]
public LVector3 Rotation { get; set; }
[ProtoMember(3)]
2021-07-07 13:36:25 +02:00
public LVector3 Velocity { get; set; }
[ProtoMember(4)]
2021-07-07 13:36:25 +02:00
public byte Speed { get; set; }
[ProtoMember(5)]
2021-07-07 13:36:25 +02:00
public LVector3 AimCoords { get; set; }
[ProtoMember(6)]
2021-07-07 13:36:25 +02:00
public int CurrentWeaponHash { get; set; }
[ProtoMember(7)]
2021-07-07 13:36:25 +02:00
public byte? Flag { get; set; } = 0;
public override void PacketToNetOutGoingMessage(NetOutgoingMessage message)
{
message.Write((byte)PacketTypes.LightSyncPlayerPacket);
2021-07-07 18:05:08 +02:00
byte[] result = CoopSerializer.Serialize(this);
2021-07-07 13:36:25 +02:00
message.Write(result.Length);
message.Write(result);
}
public override void NetIncomingMessageToPacket(NetIncomingMessage message)
{
int len = message.ReadInt32();
2021-07-07 18:05:08 +02:00
LightSyncPlayerPacket data = CoopSerializer.Deserialize<LightSyncPlayerPacket>(message.ReadBytes(len));
2021-07-07 13:36:25 +02:00
Extra = data.Extra;
2021-07-07 13:36:25 +02:00
Rotation = data.Rotation;
Velocity = data.Velocity;
Speed = data.Speed;
AimCoords = data.AimCoords;
CurrentWeaponHash = data.CurrentWeaponHash;
Flag = data.Flag;
}
}
[ProtoContract]
2021-08-14 21:49:23 +02:00
class LightSyncPlayerVehPacket : Packet
{
[ProtoMember(1)]
public PlayerPacket Extra { get; set; }
[ProtoMember(4)]
public int VehModelHash { get; set; }
[ProtoMember(5)]
public int VehSeatIndex { get; set; }
[ProtoMember(6)]
public LVector3 VehPosition { get; set; }
[ProtoMember(7)]
public LQuaternion VehRotation { get; set; }
[ProtoMember(8)]
2021-07-11 00:51:46 +02:00
public LVector3 VehVelocity { get; set; }
2021-07-10 10:52:43 +02:00
[ProtoMember(9)]
2021-07-11 00:51:46 +02:00
public float VehSpeed { get; set; }
2021-07-10 22:01:36 +02:00
[ProtoMember(10)]
2021-07-13 16:30:33 +02:00
public float VehSteeringAngle { get; set; }
2021-07-11 00:51:46 +02:00
[ProtoMember(11)]
public byte? Flag { get; set; } = 0;
public override void PacketToNetOutGoingMessage(NetOutgoingMessage message)
{
message.Write((byte)PacketTypes.LightSyncPlayerVehPacket);
byte[] result = CoopSerializer.Serialize(this);
message.Write(result.Length);
message.Write(result);
}
public override void NetIncomingMessageToPacket(NetIncomingMessage message)
{
int len = message.ReadInt32();
LightSyncPlayerVehPacket data = CoopSerializer.Deserialize<LightSyncPlayerVehPacket>(message.ReadBytes(len));
Extra = data.Extra;
VehModelHash = data.VehModelHash;
VehSeatIndex = data.VehSeatIndex;
VehPosition = data.VehPosition;
VehRotation = data.VehRotation;
2021-07-11 00:51:46 +02:00
VehVelocity = data.VehVelocity;
2021-07-10 10:52:43 +02:00
VehSpeed = data.VehSpeed;
2021-07-13 16:30:33 +02:00
VehSteeringAngle = data.VehSteeringAngle;
Flag = data.Flag;
}
}
2021-07-07 13:36:25 +02:00
[ProtoContract]
2021-08-14 21:49:23 +02:00
class ChatMessagePacket : Packet
2021-07-07 13:36:25 +02:00
{
[ProtoMember(1)]
public string Username { get; set; }
[ProtoMember(2)]
public string Message { get; set; }
public override void PacketToNetOutGoingMessage(NetOutgoingMessage message)
{
message.Write((byte)PacketTypes.ChatMessagePacket);
2021-07-07 18:05:08 +02:00
byte[] result = CoopSerializer.Serialize(this);
2021-07-07 13:36:25 +02:00
message.Write(result.Length);
message.Write(result);
}
public override void NetIncomingMessageToPacket(NetIncomingMessage message)
{
int len = message.ReadInt32();
2021-07-07 18:05:08 +02:00
ChatMessagePacket data = CoopSerializer.Deserialize<ChatMessagePacket>(message.ReadBytes(len));
2021-07-07 13:36:25 +02:00
Username = data.Username;
Message = data.Message;
}
}
2021-08-20 17:28:13 +02:00
#region ===== NATIVECALL =====
[ProtoContract]
class NativeCallPacket : Packet
{
[ProtoMember(1)]
public ulong Hash { get; set; }
[ProtoMember(2)]
public List<NativeArgument> Args { get; set; }
public override void PacketToNetOutGoingMessage(NetOutgoingMessage message)
{
message.Write((byte)PacketTypes.NativeCallPacket);
byte[] result = CoopSerializer.Serialize(this);
message.Write(result.Length);
message.Write(result);
}
public override void NetIncomingMessageToPacket(NetIncomingMessage message)
{
int len = message.ReadInt32();
NativeCallPacket data = CoopSerializer.Deserialize<NativeCallPacket>(message.ReadBytes(len));
Hash = data.Hash;
Args = data.Args;
}
}
[ProtoContract]
[ProtoInclude(1, typeof(IntArgument))]
[ProtoInclude(2, typeof(BoolArgument))]
[ProtoInclude(3, typeof(FloatArgument))]
2021-08-21 16:52:17 +02:00
[ProtoInclude(4, typeof(StringArgument))]
[ProtoInclude(5, typeof(LVector3Argument))]
2021-08-20 17:28:13 +02:00
class NativeArgument { }
[ProtoContract]
class IntArgument : NativeArgument
{
[ProtoMember(1)]
public int Data { get; set; }
}
[ProtoContract]
class BoolArgument : NativeArgument
{
[ProtoMember(1)]
public bool Data { get; set; }
}
[ProtoContract]
class FloatArgument : NativeArgument
{
[ProtoMember(1)]
public float Data { get; set; }
}
2021-08-21 16:52:17 +02:00
[ProtoContract]
class StringArgument : NativeArgument
{
[ProtoMember(1)]
public string Data { get; set; }
}
2021-08-20 17:28:13 +02:00
[ProtoContract]
class LVector3Argument : NativeArgument
{
[ProtoMember(1)]
public LVector3 Data { get; set; }
}
#endregion // ===== NATIVECALL =====
#endregion
#region -- NPC --
[ProtoContract]
2021-08-14 21:49:23 +02:00
class FullSyncNpcPacket : Packet
{
[ProtoMember(1)]
2021-08-16 14:03:05 +02:00
public long ID { get; set; }
[ProtoMember(2)]
public int ModelHash { get; set; }
[ProtoMember(3)]
public Dictionary<int, int> Props { get; set; }
[ProtoMember(4)]
public int Health { get; set; }
[ProtoMember(5)]
public LVector3 Position { get; set; }
[ProtoMember(6)]
public LVector3 Rotation { get; set; }
[ProtoMember(7)]
public LVector3 Velocity { get; set; }
[ProtoMember(8)]
public byte Speed { get; set; }
[ProtoMember(9)]
public LVector3 AimCoords { get; set; }
[ProtoMember(10)]
public int CurrentWeaponHash { get; set; }
[ProtoMember(11)]
public byte? Flag { get; set; } = 0;
public override void PacketToNetOutGoingMessage(NetOutgoingMessage message)
{
message.Write((byte)PacketTypes.FullSyncNpcPacket);
byte[] result = CoopSerializer.Serialize(this);
message.Write(result.Length);
message.Write(result);
}
public override void NetIncomingMessageToPacket(NetIncomingMessage message)
{
int len = message.ReadInt32();
FullSyncNpcPacket data = CoopSerializer.Deserialize<FullSyncNpcPacket>(message.ReadBytes(len));
ID = data.ID;
ModelHash = data.ModelHash;
Props = data.Props;
Health = data.Health;
Position = data.Position;
Rotation = data.Rotation;
Velocity = data.Velocity;
Speed = data.Speed;
AimCoords = data.AimCoords;
CurrentWeaponHash = data.CurrentWeaponHash;
Flag = data.Flag;
}
}
[ProtoContract]
2021-08-14 21:49:23 +02:00
class FullSyncNpcVehPacket : Packet
{
[ProtoMember(1)]
2021-08-16 14:03:05 +02:00
public long ID { get; set; }
[ProtoMember(2)]
public int ModelHash { get; set; }
[ProtoMember(3)]
public Dictionary<int, int> Props { get; set; }
[ProtoMember(4)]
public int Health { get; set; }
[ProtoMember(5)]
public LVector3 Position { get; set; }
[ProtoMember(6)]
public int VehModelHash { get; set; }
[ProtoMember(7)]
public int VehSeatIndex { get; set; }
[ProtoMember(8)]
public LVector3 VehPosition { get; set; }
[ProtoMember(9)]
public LQuaternion VehRotation { get; set; }
[ProtoMember(10)]
2021-08-16 16:51:33 +02:00
public float VehEngineHealth { get; set; }
[ProtoMember(11)]
2021-08-16 16:51:33 +02:00
public LVector3 VehVelocity { get; set; }
[ProtoMember(12)]
2021-08-16 16:51:33 +02:00
public float VehSpeed { get; set; }
[ProtoMember(13)]
2021-08-16 16:51:33 +02:00
public float VehSteeringAngle { get; set; }
2021-08-13 15:52:30 +02:00
[ProtoMember(14)]
2021-08-16 16:51:33 +02:00
public int[] VehColors { get; set; }
[ProtoMember(15)]
2021-08-22 13:59:15 +02:00
public Dictionary<int, int> VehMods { get; set; }
2021-08-16 16:51:33 +02:00
[ProtoMember(16)]
2021-08-22 13:59:15 +02:00
public VehicleDoors[] VehDoors { get; set; }
[ProtoMember(17)]
public byte? Flag { get; set; } = 0;
public override void PacketToNetOutGoingMessage(NetOutgoingMessage message)
{
message.Write((byte)PacketTypes.FullSyncNpcVehPacket);
byte[] result = CoopSerializer.Serialize(this);
message.Write(result.Length);
message.Write(result);
}
public override void NetIncomingMessageToPacket(NetIncomingMessage message)
{
int len = message.ReadInt32();
FullSyncNpcVehPacket data = CoopSerializer.Deserialize<FullSyncNpcVehPacket>(message.ReadBytes(len));
ID = data.ID;
ModelHash = data.ModelHash;
Props = data.Props;
Health = data.Health;
Position = data.Position;
VehModelHash = data.VehModelHash;
VehSeatIndex = data.VehSeatIndex;
VehPosition = data.VehPosition;
VehRotation = data.VehRotation;
2021-08-16 16:51:33 +02:00
VehEngineHealth = data.VehEngineHealth;
VehVelocity = data.VehVelocity;
VehSpeed = data.VehSpeed;
2021-07-13 16:30:33 +02:00
VehSteeringAngle = data.VehSteeringAngle;
VehColors = data.VehColors;
2021-08-22 13:59:15 +02:00
VehMods = data.VehMods;
VehDoors = data.VehDoors;
Flag = data.Flag;
}
}
#endregion
2021-07-07 18:05:08 +02:00
class CoopSerializer
{
public static T Deserialize<T>(byte[] data) where T : new()
{
try
{
using (MemoryStream stream = new MemoryStream(data))
{
return Serializer.Deserialize<T>(stream);
}
}
catch
{
throw new Exception(string.Format("The deserialization of the packet {0} failed!", typeof(T).Name));
}
}
public static byte[] Serialize<T>(T packet)
{
using (MemoryStream stream = new MemoryStream())
{
Serializer.Serialize(stream, packet);
return stream.ToArray();
}
}
}
2021-07-07 13:36:25 +02:00
}