Exemple #1
0
        public void RefreshListBox(bool firstLoad)
        {
            PacketList.Items.Clear();
            foreach (ArcheAgePacket packet in m_Packets)
            {
                ListBoxItem item = new ListBoxItem();
                if (packet.type.Equals("[C]"))
                {
                    item.Foreground = Brushes.Green;
                }
                else
                {
                    item.Foreground = Brushes.Red;
                }

                if (ExtremeDirectionChecking)
                {
                    using (BinaryReader reader = new BinaryReader(new MemoryStream(packet.data)))
                    {
                        if ((reader.ReadInt16() - 0x100) >= 0)
                        {
                            packet.direction = "[GP]";
                        }
                    }
                }

                item.Content = packet.type + " " + packet.direction;
                if (firstLoad)
                {
                    PacketTypeWay way    = m_CurrentFamily.getWayByPort(packet.port).getTypeWay(packet.type.Equals("[C]") ? PacketType.CLIENT : PacketType.SERVER);
                    short         opcode = BitConverter.ToInt16(packet.data, (packet.direction.Equals("[GP]") ? 2 : 0));

                    Packet p = null;
                    if (packet.PacketLevel != null)
                    {
                        item.Content += "";
                    }
                    if (way != null)
                    {
                        p = way.packets.FirstOrDefault(f => f.opcode.ToString("X2") == opcode.ToString("X2") && f.level == packet.PacketLevel); //we dont want have problems with 0x0C or 0x12
                    }
                    if (p == null)
                    {
                        item.Content += " Undefined Packet";
                    }
                    else
                    {
                        item.Content    += " " + p.name;
                        packet.name      = p.name;
                        packet.isDefined = true;
                    }

                    item.Content += " Length: " + (packet.data.Length - 2);
                    if (p != null && p.parts != null)
                    {
                        packet.parts = p.parts;
                    }
                    if (p != null && p.arrays != null)
                    {
                        packet.arrays = p.arrays;
                    }
                }
                else
                {
                    item.Content += " " + packet.name;
                    item.Content += " Length: " + (packet.data.Length - 2);
                }
                PacketList.Items.Add(item);
            }

            PacketsDefined.Content = "Распознных: " + m_Packets.Count;
        }
Exemple #2
0
        private void MetroWindow_Closing_1(object sender, System.ComponentModel.CancelEventArgs e)
        {
            if (m_Packets == null || m_Packets.Count == 0)
            {
                return;
            }
            //Saving Changes
            PacketFamily family = new PacketFamily();

            family.ways = new List <PacketWay>();
            //Filter Ways
            if (m_Packets != null)
            {
                foreach (ArcheAgePacket p1 in m_Packets)
                {
                    PacketWay found = family.getWayByPort(p1.port);
                    if (found == null)
                    {
                        PacketWay m_Way = new PacketWay();
                        m_Way.Port     = p1.port;
                        m_Way.typeways = new List <PacketTypeWay>();
                        PacketTypeWay client = new PacketTypeWay();
                        client.packets = new List <Packet>();
                        client.type    = PacketType.CLIENT;
                        PacketTypeWay server = new PacketTypeWay();
                        server.packets = new List <Packet>();
                        server.type    = PacketType.SERVER;
                        m_Way.typeways.Add(client);
                        m_Way.typeways.Add(server);

                        family.ways.Add(m_Way);
                    }
                }
            }
            //Ways Filtered
            //Add Packets
            List <ArcheAgePacket> m_Filtered = new List <ArcheAgePacket>();

            foreach (ArcheAgePacket packet in m_Packets)
            {
                if (packet.name == null || packet.name.Contains("Undefined Packet"))
                {
                    continue;
                }
                if (m_Filtered.Where(n => n.name == packet.name).ToArray().Length > 0)
                {
                    continue;
                }

                m_Filtered.Add(packet);
            }

            foreach (PacketWay way in family.ways)
            {
                PacketWay m_CurrentWay = family.getWayByPort((short)way.Port);
                foreach (ArcheAgePacket packet in m_Filtered)
                {
                    if (way.Port == packet.port)
                    {
                        PacketType type = packet.type.Equals("[C]") ? PacketType.CLIENT : PacketType.SERVER;
                        Packet     mSer = new Packet();
                        if (packet.PacketLevel != null)
                        {
                            mSer.level = packet.PacketLevel;
                        }
                        mSer.parts  = packet.parts;
                        mSer.arrays = packet.arrays;
                        mSer.id     = "0x" + BitConverter.ToInt16(packet.data, (packet.direction.Equals("[GP]") ? 2 : 0)).ToString("X2");
                        mSer.name   = packet.name;
                        List <Packet> packets = way.typeways.Where(n => n.type == type).ToArray()[0].packets;
                        packets.Add(mSer);
                    }
                }
            }

            XmlSerializer serializer = new XmlSerializer(typeof(PacketFamily));

            var settings = new XmlWriterSettings()
            {
                CheckCharacters = false,
                CloseOutput     = false,
                Encoding        = new UTF8Encoding(false),
                Indent          = true,
                IndentChars     = "\t",
                NewLineChars    = "\n",
            };

            using (var fs = new FileStream(System.IO.Path.Combine("PacketFamily.xml"), FileMode.Create, FileAccess.Write))
                using (XmlWriter writer = XmlWriter.Create(fs, settings))
                {
                    writer.WriteComment(" This File Represents Current Defined Packets ");
                    writer.WriteComment(" Allowed Only : Int16, Int32, Single, Byte[], DynamicString, FixedString, Byte, Boolean, Double - Types ");
                    writer.WriteComment(" Byte[] Syntax: Byte[]:ArrayLength Example: Byte[]:10 ");
                    writer.WriteComment(" If you're Using Arrays, Delete Type Mandatory! ");
                    writer.WriteComment(" Created By Raphail ");

                    serializer.Serialize(writer, family);
                }
        }
Exemple #3
0
        private void MetroWindow_Closing_1(object sender, System.ComponentModel.CancelEventArgs e)
        {
            if (m_Packets == null || m_Packets.Count == 0)
                return;
            //Saving Changes
            PacketFamily family = new PacketFamily();
            family.ways = new List<PacketWay>();
            //Filter Ways
            if(m_Packets != null)
            foreach (ArcheAgePacket p1 in m_Packets)
            {
                PacketWay found = family.getWayByPort(p1.port);
                if (found == null)
                {
                    PacketWay m_Way = new PacketWay();
                    m_Way.Port = p1.port;
                    m_Way.typeways = new List<PacketTypeWay>();
                    PacketTypeWay client = new PacketTypeWay();
                    client.packets = new List<Packet>();
                    client.type = PacketType.CLIENT;
                    PacketTypeWay server = new PacketTypeWay();
                    server.packets = new List<Packet>();
                    server.type = PacketType.SERVER;
                    m_Way.typeways.Add(client);
                    m_Way.typeways.Add(server);

                    family.ways.Add(m_Way);
                }
            }
            //Ways Filtered
            //Add Packets
            List<ArcheAgePacket> m_Filtered = new List<ArcheAgePacket>();
            foreach (ArcheAgePacket packet in m_Packets)
            {
                if (packet.name == null || packet.name.Contains("Undefined Packet"))
                    continue;
                if (m_Filtered.Where(n => n.name == packet.name).ToArray().Length > 0)
                    continue;

                m_Filtered.Add(packet);
            }

            foreach (PacketWay way in family.ways)
            {
                PacketWay m_CurrentWay = family.getWayByPort((short)way.Port);
                foreach (ArcheAgePacket packet in m_Filtered)
                {
                    if (way.Port == packet.port)
                    {
                        PacketType type = packet.type.Equals("[C]") ? PacketType.CLIENT : PacketType.SERVER;
                        Packet mSer = new Packet();
                        if (packet.PacketLevel != null)
                            mSer.level = packet.PacketLevel;
                        mSer.parts = packet.parts;
                        mSer.arrays = packet.arrays;
                        mSer.id = "0x" + BitConverter.ToInt16(packet.data, (packet.direction.Equals("[GP]") ? 2 : 0)).ToString("X2");
                        mSer.name = packet.name;
                        List<Packet> packets = way.typeways.Where(n => n.type == type).ToArray()[0].packets;
                        packets.Add(mSer);
                    }
                }
            }

            XmlSerializer serializer = new XmlSerializer(typeof(PacketFamily));

            var settings = new XmlWriterSettings()
            {
                CheckCharacters = false,
                CloseOutput = false,
                Encoding = new UTF8Encoding(false),
                Indent = true,
                IndentChars = "\t",
                NewLineChars = "\n",
            };

            using(var fs = new FileStream(System.IO.Path.Combine("PacketFamily.xml"), FileMode.Create, FileAccess.Write))
            using (XmlWriter writer = XmlWriter.Create(fs, settings))
            {
                writer.WriteComment(" This File Represents Current Defined Packets ");
                writer.WriteComment(" Allowed Only : Int16, Int32, Single, Byte[], DynamicString, FixedString, Byte, Boolean, Double - Types ");
                writer.WriteComment(" Byte[] Syntax: Byte[]:ArrayLength Example: Byte[]:10 ");
                writer.WriteComment(" If you're Using Arrays, Delete Type Mandatory! ");
                writer.WriteComment(" Created By Raphail ");

                serializer.Serialize(writer, family);
            }
        }