using System;
using System.Collections.Generic;
using System.Text;
using Lidgren.Network;
using Newtonsoft.Json;
using GTA.Math;
namespace CoopClient
{
///
///
///
public struct LVector3
{
#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;
}
///
///
///
public float X { get; set; }
///
///
///
public float Y { get; set; }
///
///
///
public float Z { get; set; }
}
///
///
///
public 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;
}
///
///
///
public float X { get; set; }
///
///
///
public float Y { get; set; }
///
///
///
public float Z { get; set; }
///
///
///
public float W { get; set; }
}
enum PacketTypes
{
Handshake,
PlayerConnect,
PlayerDisconnect,
FullSyncPlayer,
FullSyncPlayerVeh,
LightSyncPlayer,
LightSyncPlayerVeh,
SuperLightSync,
FullSyncNpc,
FullSyncNpcVeh,
ChatMessage,
NativeCall,
NativeResponse,
Mod,
CleanUpWorld
}
enum ConnectionChannel
{
Default = 0,
PlayerLight = 1,
PlayerFull = 2,
PlayerSuperLight = 3,
NPCFull = 4,
Chat = 5,
Native = 6,
Mod = 7
}
[Flags]
enum PedDataFlags
{
IsAiming = 1 << 0,
IsShooting = 1 << 1,
IsReloading = 1 << 2,
IsJumping = 1 << 3,
IsRagdoll = 1 << 4,
IsOnFire = 1 << 5,
IsInParachuteFreeFall = 1 << 6,
IsParachuteOpen = 1 << 7,
IsOnLadder = 1 << 8,
IsVaulting = 1 << 9
}
#region ===== VEHICLE DATA =====
[Flags]
enum VehicleDataFlags
{
IsEngineRunning = 1 << 0,
AreLightsOn = 1 << 1,
AreBrakeLightsOn = 1 << 2,
AreHighBeamsOn = 1 << 3,
IsSirenActive = 1 << 4,
IsDead = 1 << 5,
IsHornActive = 1 << 6,
IsTransformed = 1 << 7,
RoofOpened = 1 << 8,
OnTurretSeat = 1 << 9,
IsPlane = 1 << 10
}
///
/// ?
///
struct VehicleDamageModel
{
public byte BrokenWindows { get; set; }
public byte BrokenDoors { get; set; }
public ushort BurstedTires { get; set; }
public ushort PuncturedTires { get; set; }
}
#endregion
interface IPacket
{
void PacketToNetOutGoingMessage(NetOutgoingMessage message);
void NetIncomingMessageToPacket(byte[] array);
}
abstract class Packet : IPacket
{
public abstract void PacketToNetOutGoingMessage(NetOutgoingMessage message);
public abstract void NetIncomingMessageToPacket(byte[] array);
}
internal partial class Packets
{
public class Mod : Packet
{
public long NetHandle { get; set; }
public long Target { get; set; }
public string Name { get; set; }
public byte CustomPacketID { get; set; }
public byte[] Bytes { get; set; }
public override void PacketToNetOutGoingMessage(NetOutgoingMessage message)
{
#region PacketToNetOutGoingMessage
message.Write((byte)PacketTypes.Mod);
List byteArray = new List();
// Write NetHandle
byteArray.AddRange(BitConverter.GetBytes(NetHandle));
// Write Target
byteArray.AddRange(BitConverter.GetBytes(Target));
// Write Name
byte[] nameBytes = Encoding.UTF8.GetBytes(Name);
byteArray.AddRange(BitConverter.GetBytes(nameBytes.Length));
byteArray.AddRange(nameBytes);
// Write CustomPacketID
byteArray.Add(CustomPacketID);
// Write Bytes
byteArray.AddRange(BitConverter.GetBytes(Bytes.Length));
byteArray.AddRange(Bytes);
byte[] result = byteArray.ToArray();
message.Write(result.Length);
message.Write(result);
#endregion
}
public override void NetIncomingMessageToPacket(byte[] array)
{
#region NetIncomingMessageToPacket
BitReader reader = new BitReader(array);
// Read NetHandle
NetHandle = reader.ReadLong();
// Read Target
Target = reader.ReadLong();
// Read Name
int nameLength = reader.ReadInt();
Name = reader.ReadString(nameLength);
// Read CustomPacketID
CustomPacketID = reader.ReadByte();
// Read Bytes
int bytesLength = reader.ReadInt();
Bytes = reader.ReadByteArray(bytesLength);
#endregion
}
}
public class ChatMessage : Packet
{
public string Username { get; set; }
public string Message { get; set; }
public override void PacketToNetOutGoingMessage(NetOutgoingMessage message)
{
#region PacketToNetOutGoingMessage
message.Write((byte)PacketTypes.ChatMessage);
List byteArray = new List();
byte[] usernameBytes = Encoding.UTF8.GetBytes(Username);
byte[] messageBytes = Encoding.UTF8.GetBytes(Message);
// Write UsernameLength
byteArray.AddRange(BitConverter.GetBytes(usernameBytes.Length));
// Write Username
byteArray.AddRange(usernameBytes);
// Write MessageLength
byteArray.AddRange(BitConverter.GetBytes(messageBytes.Length));
// Write Message
byteArray.AddRange(messageBytes);
byte[] result = byteArray.ToArray();
message.Write(result.Length);
message.Write(result);
#endregion
}
public override void NetIncomingMessageToPacket(byte[] array)
{
#region NetIncomingMessageToPacket
BitReader reader = new BitReader(array);
// Read username
int usernameLength = reader.ReadInt();
Username = reader.ReadString(usernameLength);
// Read message
int messageLength = reader.ReadInt();
Message = reader.ReadString(messageLength);
#endregion
}
}
#region ===== NATIVECALL =====
public class NativeCall : Packet
{
public ulong Hash { get; set; }
public List