public static void ReadBytes(Client client, byte[] buffer, int length) { MemoryStream stream = new MemoryStream(buffer); BinaryReader reader = new BinaryReader(stream); while (reader.BaseStream.Position != length) { byte packetId = reader.ReadByte(); if (packets.ContainsKey(packetId)) { try { PacketBase packet = (PacketBase)Activator.CreateInstance(packets[packetId]); packet.SetReader(reader, stream); packet.Read(client); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } } else { Console.WriteLine("No packet with id: " + packetId); } } }