public static void WriteSurrenderReason(this PacketWriter writer, SurrenderReason data)
 {
     writer.WriteByte((byte)data);
 }
Beispiel #2
0
        public override void WriteBody(PacketWriter writer)
        {
            int packetCount = Packets.Count;

            if (packetCount > 255)
            {
                throw new IOException("Too many packets inside batch packet!");
            }
            writer.WriteByte((byte)packetCount);
            byte packetLastId    = 0;
            int  packetLastNetId = 0;

            for (int i = 0; i < packetCount; i++)
            {
                var    packet               = Packets[i];
                var    packetData           = packet.GetBytes();
                var    newPacketId          = packetData[0];
                byte[] newPacketNetIdBuffer = new byte[4];
                Buffer.BlockCopy(packetData, 1, newPacketNetIdBuffer, 0, 4);
                if (!BitConverter.IsLittleEndian)
                {
                    Array.Reverse(newPacketNetIdBuffer);
                }
                int newPacketNetId = BitConverter.ToInt32(newPacketNetIdBuffer, 0);


                if (packetData.Length < 5)
                {
                    throw new IOException("Packet too small for batch < 5!");
                }
                if (i == 0)
                {
                    if (packetData.Length > 255)
                    {
                        throw new IOException("First packet too big for batch > 255!");
                    }
                    writer.WriteByte((byte)packetData.Length);
                    writer.WriteBytes(packetData);
                }
                else
                {
                    if (packetData.Length > 260)
                    {
                        throw new IOException("Non-first packet too big for batch > 260!");
                    }

                    bool hasId    = true;
                    bool hasNetId = true;
                    bool hasSize  = true;

                    int  packetSize = packetData.Length - 5;
                    byte bitfield   = 0;
                    if (newPacketId == packetLastId)
                    {
                        hasId     = false;
                        bitfield |= 1;
                    }
                    else
                    {
                        hasId = true;
                    }

                    int packetNetIdDiff = newPacketNetId - packetLastNetId;
                    if (packetNetIdDiff <= SByte.MaxValue && packetNetIdDiff >= SByte.MinValue)
                    {
                        hasNetId  = false;
                        bitfield |= 2;
                    }
                    else
                    {
                        hasNetId = true;
                    }


                    if (packetSize < 63)
                    {
                        hasSize   = false;
                        bitfield |= (byte)((byte)packetSize << 2);
                    }
                    else
                    {
                        hasSize   = true;
                        bitfield |= (63 << 2);
                    }

                    writer.WriteByte(bitfield);
                    if (hasId)
                    {
                        writer.WriteByte(newPacketId);
                    }
                    if (hasNetId)
                    {
                        writer.WriteInt32(newPacketNetId);
                    }
                    else
                    {
                        writer.WriteSByte((SByte)packetNetIdDiff);
                    }
                    if (hasSize)
                    {
                        writer.WriteByte((byte)packetSize);
                    }
                    byte[] remainData = new byte[packetSize];
                    Buffer.BlockCopy(packetData, 5, remainData, 0, packetSize);
                    writer.WriteBytes(remainData);
                }
                packetLastId    = newPacketId;
                packetLastNetId = newPacketNetId;
            }
        }
Beispiel #3
0
 public override void WriteHeader(PacketWriter writer)
 {
     writer.WriteByte(0xFF);
 }
 public static void WriteSpectatorChunkType(this PacketWriter writer, SpectatorChunkType data)
 {
     writer.WriteByte((byte)data);
 }
 public static void WriteHitResult(this PacketWriter writer, HitResult data)
 {
     writer.WriteByte((byte)data);
 }
 public static void WriteParticleAttachType(this PacketWriter writer, ParticleAttachType data)
 {
     writer.WriteByte((byte)data);
 }
 public static void WriteHealthBarType(this PacketWriter writer, HealthBarType data)
 {
     writer.WriteByte((byte)data);
 }
 public static void WriteDrawPathMode(this PacketWriter writer, DrawPathMode data)
 {
     writer.WriteByte((byte)data);
 }
 public static void WriteContextualEmoteFlags(this PacketWriter writer, ContextualEmoteFlags data)
 {
     writer.WriteByte((byte)data);
 }
 public static void WriteRespawnPointEvent(this PacketWriter writer, RespawnPointEvent data)
 {
     writer.WriteByte((byte)data);
 }
 public static void WriteLookAtType(this PacketWriter writer, LookAtType data)
 {
     writer.WriteByte((byte)data);
 }
 public static void WriteRespawnPointCommand(this PacketWriter writer, RespawnPointCommand data)
 {
     writer.WriteByte((byte)data);
 }
 public static void WriteUIHighlightCommand(this PacketWriter writer, UIHighlightCommand data)
 {
     writer.WriteByte((byte)data);
 }
 public static void WriteUIElement(this PacketWriter writer, UIElement data)
 {
     writer.WriteByte((byte)data);
 }
 public static void WriteQuestType(this PacketWriter writer, QuestType data)
 {
     writer.WriteByte((byte)data);
 }
 public static void WriteAudioVOComponentEvent(this PacketWriter writer, AudioVOComponentEvent data)
 {
     writer.WriteByte((byte)data);
 }
 public static void WriteFlexID(this PacketWriter writer, ParticleFlexID data)
 {
     writer.WriteByte((byte)data);
 }
 public static void WriteVisibilityTeam(this PacketWriter writer, VisibilityTeam data)
 {
     writer.WriteByte((byte)data);
 }
 public static void WriteTipCommand(this PacketWriter writer, TipCommand data)
 {
     writer.WriteByte((byte)data);
 }
 public static void WriteScoreEvent(this PacketWriter writer, ScoreEvent data)
 {
     writer.WriteByte((byte)data);
 }
 public static void WriteTargetingType(this PacketWriter writer, TargetingType data)
 {
     writer.WriteByte((byte)data);
 }
 public static void WriteScoreCategory(this PacketWriter writer, ScoreCategory data)
 {
     writer.WriteByte((byte)data);
 }
 public static void WriteOrderType(this PacketWriter writer, OrderType data)
 {
     writer.WriteByte((byte)data);
 }
 public static void WriteCapturePointUpdateCommand(this PacketWriter writer, CapturePointUpdateCommand data)
 {
     writer.WriteByte((byte)data);
 }
 public static void WriteEventSourceType(this PacketWriter writer, EventSourceType data)
 {
     writer.WriteByte((byte)data);
 }
 public static void WriteNetNodeID(this PacketWriter writer, NetNodeID nodeID)
 {
     writer.WriteByte((byte)nodeID);
 }
Beispiel #27
0
        public BatchPacket(PacketReader reader, ChannelID channel)
        {
            int  count     = reader.ReadByte();
            long totalSize = reader.Stream.Length - 2;

            if (totalSize < 1 || count == 0)
            {
                return;
            }


            byte packetSize = reader.ReadByte();

            if (packetSize < 5)
            {
                throw new IOException("Too small packet in batch!");
            }
            byte packetLastID    = reader.ReadByte();
            int  packetLastNetID = reader.ReadInt32();

            byte[] packetData = reader.ReadBytes(packetSize - 5);
            using (var stream = new MemoryStream())
            {
                using (var packetWriter = new PacketWriter(stream, true))
                {
                    packetWriter.WriteByte(packetLastID);
                    packetWriter.WriteInt32(packetLastNetID);
                    packetWriter.WriteBytes(packetData);
                }
                stream.Seek(0, SeekOrigin.Begin);
                using (var packetReader = new PacketReader(stream, true))
                {
                    var packet = reader.ReadPacket(channel);
                    Packets.Add(packet);
                }
            }

            for (int i = 1; i < count; i++)
            {
                byte bitfield = reader.ReadByte();
                if ((bitfield & 1) == 0) //if this is true re-use old packetID
                {
                    packetLastID = reader.ReadByte();
                }
                if ((bitfield & 2) != 0)
                {
                    packetLastNetID += reader.ReadSByte();
                }
                else
                {
                    packetLastNetID = reader.ReadInt32();
                }
                packetSize = (byte)(bitfield >> 2);
                if (packetSize == 63)
                {
                    packetSize = reader.ReadByte();
                }
                packetData = reader.ReadBytes(packetSize);

                using (var stream = new MemoryStream())
                {
                    using (var packetWriter = new PacketWriter(stream, true))
                    {
                        packetWriter.WriteByte(packetLastID);
                        packetWriter.WriteInt32(packetLastNetID);
                        packetWriter.WriteBytes(packetData);
                    }
                    stream.Seek(0, SeekOrigin.Begin);
                    using (var packetReader = new PacketReader(stream, true))
                    {
                        var packet = reader.ReadPacket(channel);
                        Packets.Add(packet);
                    }
                }
            }
        }
 public static void WriteQuestEvent(this PacketWriter writer, QuestEvent data)
 {
     writer.WriteByte((byte)data);
 }
Beispiel #29
0
 public override void WriteHeader(PacketWriter writer)
 {
     writer.WriteByte((byte)ID);
 }
 public static void WriteAudioVOEventType(this PacketWriter writer, AudioVOEventType data)
 {
     writer.WriteByte((byte)data);
 }