167 lines
3.8 KiB
C#
Raw Normal View History

2022-01-01 03:07:18 +01:00
using System;
using System.Collections.Generic;
using System.Text;
using Lidgren.Network;
using Newtonsoft.Json;
using GTA.Math;
2022-05-22 15:55:26 +08:00
namespace RageCoop.Core
2022-01-01 03:07:18 +01:00
{
2022-07-01 14:39:43 +08:00
internal enum PacketType:byte
2022-05-22 15:55:26 +08:00
{
Handshake=0,
PlayerConnect=1,
PlayerDisconnect=2,
PlayerInfoUpdate=3,
2022-06-24 10:33:36 +08:00
PublicKeyRequest=4,
PublicKeyResponse=5,
2022-07-01 12:22:31 +08:00
Request=6,
Response=7,
2022-07-29 21:15:23 +08:00
PingPong = 8,
2022-08-08 17:03:41 +08:00
HandshakeSuccess = 9,
2022-07-29 21:15:23 +08:00
ChatMessage =10,
2022-07-01 12:22:31 +08:00
FileTransferChunk=11,
FileTransferRequest=12,
FileTransferResponse = 13,
FileTransferComplete =14,
AllResourcesSent=15,
2022-07-01 12:22:31 +08:00
CustomEvent = 16,
2022-07-05 11:18:26 +08:00
CustomEventQueued = 17,
2022-08-06 11:40:38 +08:00
ConnectionRequest=18,
2022-08-08 17:03:41 +08:00
ConnectionEstablished = 19,
2022-05-22 15:55:26 +08:00
#region Sync
#region INTERVAL
VehicleSync = 20,
PedSync = 22,
ProjectileSync=24,
2022-05-22 15:55:26 +08:00
#endregion
#region EVENT
PedKilled=30,
BulletShot=31,
EnteringVehicle=32,
LeaveVehicle = 33,
EnteredVehicle=34,
OwnerChanged=35,
VehicleBulletShot = 36,
NozzleTransform=37,
2022-05-22 15:55:26 +08:00
#endregion
#endregion
2022-06-24 10:33:36 +08:00
Unknown=255
2022-05-22 15:55:26 +08:00
}
2022-07-01 14:39:43 +08:00
internal static class PacketExtensions
2022-01-01 03:07:18 +01:00
{
2022-07-01 14:39:43 +08:00
internal static bool IsSyncEvent(this PacketType p)
2022-05-22 15:55:26 +08:00
{
return (30<=(byte)p)&&((byte)p<=40);
}
2022-01-01 03:07:18 +01:00
}
2022-07-01 14:39:43 +08:00
internal enum ConnectionChannel
2022-01-01 03:07:18 +01:00
{
Default = 0,
Chat = 5,
Native = 6,
2022-04-02 18:11:30 +02:00
Mod = 7,
File = 8,
2022-05-22 15:55:26 +08:00
Event = 9,
2022-07-01 12:22:31 +08:00
RequestResponse=10,
PingPong = 11,
VehicleSync =20,
PedSync=21,
ProjectileSync = 22,
SyncEvents =30,
2022-01-01 03:07:18 +01:00
}
2022-05-22 15:55:26 +08:00
[Flags]
2022-07-01 14:39:43 +08:00
internal enum PedDataFlags:ushort
2022-01-01 03:07:18 +01:00
{
2022-05-22 15:55:26 +08:00
None=0,
2022-01-01 03:07:18 +01:00
IsAiming = 1 << 0,
2022-06-22 14:18:20 +08:00
IsInStealthMode = 1 << 1,
2022-01-01 03:07:18 +01:00
IsReloading = 1 << 2,
IsJumping = 1 << 3,
IsRagdoll = 1 << 4,
IsOnFire = 1 << 5,
IsInParachuteFreeFall = 1 << 6,
2022-01-01 04:16:24 +01:00
IsParachuteOpen = 1 << 7,
IsOnLadder = 1 << 8,
2022-05-22 15:55:26 +08:00
IsVaulting = 1 << 9,
IsInCover = 1 << 10,
IsInVehicle = 1 << 11,
IsFullSync = 1<<12 ,
2022-01-01 03:07:18 +01:00
}
#region ===== VEHICLE DATA =====
2022-07-01 14:39:43 +08:00
internal enum VehicleDataFlags:ushort
2022-01-01 03:07:18 +01:00
{
2022-06-22 14:18:20 +08:00
None=0,
2022-01-01 03:07:18 +01:00
IsEngineRunning = 1 << 0,
AreLightsOn = 1 << 1,
2022-01-01 17:24:55 +01:00
AreBrakeLightsOn = 1 << 2,
AreHighBeamsOn = 1 << 3,
IsSirenActive = 1 << 4,
IsDead = 1 << 5,
IsHornActive = 1 << 6,
IsTransformed = 1 << 7,
RoofOpened = 1 << 8,
OnTurretSeat = 1 << 9,
2022-05-22 15:55:26 +08:00
IsAircraft = 1 << 10,
IsDeluxoHovering=1 << 11,
2022-06-19 13:36:23 +08:00
HasRoof=1 << 12,
IsFullSync = 1<<13,
2022-07-17 20:12:25 +08:00
IsOnFire = 1<<14,
Repaired = 1<<15,
2022-01-01 03:07:18 +01:00
}
2022-06-22 14:18:20 +08:00
2022-07-01 14:39:43 +08:00
internal enum PlayerConfigFlags : byte
2022-06-22 14:18:20 +08:00
{
None = 0,
ShowBlip= 1 << 0,
ShowNameTag= 1 << 1
}
2022-07-01 14:39:43 +08:00
internal struct VehicleDamageModel
2022-01-01 03:07:18 +01:00
{
public byte BrokenDoors { get; set; }
2022-05-22 15:55:26 +08:00
public byte OpenedDoors { get; set; }
public byte BrokenWindows { get; set; }
2022-04-14 02:08:13 +02:00
public short BurstedTires { get; set; }
public byte LeftHeadLightBroken { get; set; }
public byte RightHeadLightBroken { get; set; }
2022-01-01 03:07:18 +01:00
}
#endregion
2022-08-06 10:43:24 +08:00
internal interface IPacket
2022-01-01 03:07:18 +01:00
{
2022-08-06 10:43:24 +08:00
PacketType Type { get; }
byte[] Serialize();
void Deserialize(byte[] data);
2022-01-01 03:07:18 +01:00
}
2022-07-01 14:39:43 +08:00
internal abstract class Packet : IPacket
2022-01-01 03:07:18 +01:00
{
2022-08-06 10:43:24 +08:00
public abstract PacketType Type { get; }
2022-08-06 11:40:38 +08:00
public virtual byte[] Serialize()
{
return new byte[0];
}
public virtual void Deserialize(byte[] array) { }
2022-08-06 10:43:24 +08:00
public void Pack(NetOutgoingMessage message)
2022-01-01 03:07:18 +01:00
{
2022-08-06 10:43:24 +08:00
var d=Serialize();
message.Write((byte)Type);
message.Write(d.Length);
message.Write(d);
2022-01-01 03:07:18 +01:00
}
}
}