예제 #1
0
        private static MapElement ReadElement(BinaryReader reader, MapElement parent, string[] lookupTable)
        {
            MapElement element = new MapElement();

            element.Name   = lookupTable[reader.ReadInt16()];
            element.Parent = parent;
            int attributes = reader.ReadByte();

            for (int i = 0; i < attributes; i++)
            {
                string key   = lookupTable[reader.ReadInt16()];
                byte   type  = reader.ReadByte();
                object value = null;
                if (type == 0)
                {
                    value = reader.ReadBoolean();
                }
                else if (type == 1)
                {
                    value = (int)reader.ReadByte();
                }
                else if (type == 2)
                {
                    value = (int)reader.ReadInt16();
                }
                else if (type == 3)
                {
                    value = reader.ReadInt32();
                }
                else if (type == 4)
                {
                    value = reader.ReadSingle();
                }
                else if (type == 5)
                {
                    value = lookupTable[reader.ReadInt16()];
                }
                else if (type == 6)
                {
                    value = reader.ReadString();
                }
                else if (type == 7)
                {
                    int count = reader.ReadInt16();
                    value = RunLengthEncoding.Decode(reader.ReadBytes(count));
                }
                element.Attributes.Add(key, value);
            }

            int elements = reader.ReadInt16();

            for (int j = 0; j < elements; j++)
            {
                element.Children.Add(ReadElement(reader, element, lookupTable));
            }
            return(element);
        }
예제 #2
0
        private static BinaryPacker.Element ReadElement(BinaryReader reader)
        {
            BinaryPacker.Element element = new BinaryPacker.Element();
            element.Name = BinaryPacker.stringLookup[(int)reader.ReadInt16()];
            byte num1 = reader.ReadByte();

            if (num1 > (byte)0)
            {
                element.Attributes = new Dictionary <string, object>();
            }
            for (int index = 0; index < (int)num1; ++index)
            {
                string key  = BinaryPacker.stringLookup[(int)reader.ReadInt16()];
                byte   num2 = reader.ReadByte();
                object obj  = (object)null;
                switch (num2)
                {
                case 0:
                    obj = (object)reader.ReadBoolean();
                    break;

                case 1:
                    obj = (object)Convert.ToInt32(reader.ReadByte());
                    break;

                case 2:
                    obj = (object)Convert.ToInt32(reader.ReadInt16());
                    break;

                case 3:
                    obj = (object)reader.ReadInt32();
                    break;

                case 4:
                    obj = (object)reader.ReadSingle();
                    break;

                case 5:
                    obj = (object)BinaryPacker.stringLookup[(int)reader.ReadInt16()];
                    break;

                case 6:
                    obj = (object)reader.ReadString();
                    break;

                case 7:
                    short num3 = reader.ReadInt16();
                    obj = (object)RunLengthEncoding.Decode(reader.ReadBytes((int)num3));
                    break;
                }
                element.Attributes.Add(key, obj);
            }
            short num4 = reader.ReadInt16();

            if (num4 > (short)0)
            {
                element.Children = new List <BinaryPacker.Element>();
            }
            for (int index = 0; index < (int)num4; ++index)
            {
                element.Children.Add(BinaryPacker.ReadElement(reader));
            }
            return(element);
        }
예제 #3
0
        private static void WriteElement(Dictionary <string, short> ids, BinaryWriter writer, XmlElement element)
        {
            int children = 0;

            for (int i = element.ChildNodes.Count - 1; i >= 0; i--)
            {
                if (element.ChildNodes[i] is XmlElement)
                {
                    children++;
                }
            }

            int attributes = 0;

            for (int i = element.Attributes.Count - 1; i >= 0; i--)
            {
                if (!IgnoreAttributes.Contains(element.Attributes[i].Name))
                {
                    attributes++;
                }
            }

            if (element.InnerText.Length > 0 && children == 0)
            {
                attributes++;
            }

            writer.Write(ids[element.Name]);
            writer.Write((byte)attributes);

            int count = element.Attributes.Count;

            for (int i = 0; i < count; i++)
            {
                XmlAttribute attribute = element.Attributes[i];

                if (IgnoreAttributes.Contains(attribute.Name))
                {
                    continue;
                }

                ParseValue(attribute.Value, out byte type, out object result);
                writer.Write(ids[attribute.Name]);
                writer.Write(type);

                switch (type)
                {
                case 0: writer.Write((bool)result); break;

                case 1: writer.Write((byte)result); break;

                case 2: writer.Write((short)result); break;

                case 3: writer.Write((int)result); break;

                case 4: writer.Write((float)result); break;

                case 5: writer.Write(ids[(string)result]); break;
                }
            }

            if (element.InnerText.Length > 0 && children == 0)
            {
                writer.Write(ids[InnerTextAttributeName]);
                if (element.Name == "solids" || element.Name == "bg")
                {
                    byte[] encoded = RunLengthEncoding.Encode(element.InnerText);
                    writer.Write((byte)7);
                    writer.Write((short)encoded.Length);
                    writer.Write(encoded);
                }
                else
                {
                    writer.Write((byte)6);
                    writer.Write(element.InnerText);
                }
            }

            writer.Write((short)children);
            children = element.ChildNodes.Count;
            for (int i = 0; i < children; i++)
            {
                XmlElement node = element.ChildNodes[i] as XmlElement;
                if (node != null)
                {
                    WriteElement(ids, writer, node);
                }
            }
        }