private void AddFixup(ulong id, Fixup fixup)
 {
     FixupIDs.Add(id);
     foreach (ulong required_ids in fixup.RequiredIDs)
     {
         if (!Fixes.TryGetValue(required_ids, out HashSet <Fixup> set))
         {
             set = new HashSet <Fixup>();
             Fixes[required_ids] = set;
         }
         set.Add(fixup);
     }
 }
        internal void FixupMembers(ClassMap map, object obfixup, bool isValueList)
        {
            Fixup       fixup   = (Fixup)obfixup;
            ICollection members = map.ElementMembers;

            string[] ids = fixup.Ids;
            foreach (XmlTypeMapMember member in members)
            {
                if (ids[member.Index] != null)
                {
                    SetMemberValue(member, fixup.Source, GetTarget(ids[member.Index]), isValueList);
                }
            }
        }
Example #3
0
        void ProcessFixups(ProjectState state, IO.XmlStream s)
        {
            foreach (XmlNode n in s.Cursor.ChildNodes)
            {
                if (n.Name != "fixup")
                {
                    continue;
                }

                s.SaveCursor(n);
                var fu = new Fixup(state, s);
                s.RestoreCursor();
                string name_str = fu.ToString();

                try { Fixups.Add(name_str, fu); }
                catch (ArgumentException) { Debug.LogFile.WriteLine(kDuplicateErrorStr, "fix-up definition", name_str); }
            }
        }
Example #4
0
        private static Fixup ConvertFixupDefinition(
            FixupDefinition def, Dictionary<object, object> objectMap)
        {
            Fixup fixup = new Fixup();
            fixup.StartIndex = def.DataOffset;
            switch (def.Location)
            {
                case FixupLocation.LowByte:
                    fixup.LocationType = FixupLocationType.LowByte;
                    break;
                case FixupLocation.Offset:
                case FixupLocation.LoaderResolvedOffset:
                    fixup.LocationType = FixupLocationType.Offset;
                    break;
                case FixupLocation.Base:
                    fixup.LocationType = FixupLocationType.Base;
                    break;
                case FixupLocation.Pointer:
                    fixup.LocationType = FixupLocationType.Pointer;
                    break;
                default:
                    throw new InvalidDataException("The fixup location is not supported.");
            }
            fixup.Mode = def.Mode;

            IAddressReferent referent;
            if (def.Target.Referent is UInt16)
            {
                referent = new PhysicalAddress((UInt16)def.Target.Referent, 0);
            }
            else
            {
                referent = (IAddressReferent)objectMap[def.Target.Referent];
            }
            fixup.Target = new SymbolicTarget
            {
                Referent = (IAddressReferent)referent,
                Displacement = def.Target.Displacement
            };
            //f.Frame = null;
            return fixup;
        }
        protected void FixupsToMemoryStream()
        {
            uint base_address = OwnerState.Definition.MemoryInfo.BaseAddress;

            Head.FixupCount = OwnerState.Importer.Fixups.Count;
            if (Head.FixupCount > 0)
            {
                Fixup f = new Fixup();
                Head.FixupAddress = base_address + MemoryStream.PositionUnsigned;
                foreach (Import.Fixup fu in OwnerState.Importer.Fixups.Values)
                {
                    AddLocationFixup(fu.Name, MemoryStream, true);
                    MemoryStream.Write((int)0);
                }
                foreach (Import.Fixup fu in OwnerState.Importer.Fixups.Values)
                {
                    f.Reset(fu);
                    f.Write(MemoryStream);
                }

                AlignMemoryStream(Compiler.kDefaultAlignment);
            }
        }
 public object[] Read25_getHometownResponse() {
     Reader.MoveToContent();
     object[] p = new object[3];
     Reader.MoveToContent();
     int whileIterations33 = 0;
     int readerCount33 = ReaderCount;
     while (Reader.NodeType == System.Xml.XmlNodeType.Element) {
         string root = Reader.GetAttribute("root", "http://schemas.xmlsoap.org/soap/encoding/");
         if (root == null || System.Xml.XmlConvert.ToBoolean(root)) break;
         ReadReferencedElement();
         Reader.MoveToContent();
         CheckReaderCount(ref whileIterations33, ref readerCount33);
     }
     bool isEmptyWrapper = Reader.IsEmptyElement;
     Reader.ReadStartElement();
     Fixup fixup = new Fixup(p, new System.Xml.Serialization.XmlSerializationFixupCallback(this.fixup_Read25_getHometownResponse), 3);
     AddFixup(fixup);
     IsReturnValue = true;
     bool[] paramsRead = new bool[3];
     Reader.MoveToContent();
     int whileIterations34 = 0;
     int readerCount34 = ReaderCount;
     while (Reader.NodeType != System.Xml.XmlNodeType.EndElement && Reader.NodeType != System.Xml.XmlNodeType.None) {
         if (Reader.NodeType == System.Xml.XmlNodeType.Element) {
             if (!paramsRead[0] && (IsReturnValue || ((object) Reader.LocalName == (object)id27_country && (object) Reader.NamespaceURI == (object)id2_Item))) {
                 object rre = ReadReferencingElement(id3_string, id4_Item, out fixup.Ids[0]);
                 try {
                     p[0] = (global::System.String)rre;
                 }
                 catch (System.InvalidCastException) {
                     throw CreateInvalidCastException(typeof(global::System.String), rre, null);
                 }
                 Referenced(p[0]);
                 IsReturnValue = false;
                 paramsRead[0] = true;
             }
             else if (!paramsRead[1] && ((object) Reader.LocalName == (object)id28_state && (object) Reader.NamespaceURI == (object)id2_Item)) {
                 object rre = ReadReferencingElement(id3_string, id4_Item, out fixup.Ids[1]);
                 try {
                     p[1] = (global::System.String)rre;
                 }
                 catch (System.InvalidCastException) {
                     throw CreateInvalidCastException(typeof(global::System.String), rre, null);
                 }
                 Referenced(p[1]);
                 paramsRead[1] = true;
             }
             else if (!paramsRead[2] && ((object) Reader.LocalName == (object)id29_hometown && (object) Reader.NamespaceURI == (object)id2_Item)) {
                 object rre = ReadReferencingElement(id3_string, id4_Item, out fixup.Ids[2]);
                 try {
                     p[2] = (global::System.String)rre;
                 }
                 catch (System.InvalidCastException) {
                     throw CreateInvalidCastException(typeof(global::System.String), rre, null);
                 }
                 Referenced(p[2]);
                 paramsRead[2] = true;
             }
             else {
                 UnknownNode((object)p);
             }
         }
         else {
             UnknownNode((object)p);
         }
         Reader.MoveToContent();
         CheckReaderCount(ref whileIterations34, ref readerCount34);
     }
     if (!isEmptyWrapper) ReadEndElement();
     ReadReferencedElements();
     return p;
 }
        void ReadMembers(ClassMap map, object ob, bool isValueList, bool readBySoapOrder)
        {
            // Reads attributes
            ReadAttributeMembers(map, ob, isValueList);

            if (!isValueList)
            {
                Reader.MoveToElement();
                if (Reader.IsEmptyElement)
                {
                    SetListMembersDefaults(map, ob, isValueList);
                    return;
                }

                Reader.ReadStartElement();
            }

            // Reads elements

            bool[] readFlag = new bool[(map.ElementMembers != null) ? map.ElementMembers.Count : 0];

            bool hasAnyReturnMember = (isValueList && _format == SerializationFormat.Encoded && map.ReturnMember != null);

            Reader.MoveToContent();

            int[]    indexes          = null;
            object[] flatLists        = null;
            object[] flatListsChoices = null;
            Fixup    fixup            = null;
            int      ind = -1;
            int      maxInd;

            if (readBySoapOrder)
            {
                if (map.ElementMembers != null)
                {
                    maxInd = map.ElementMembers.Count;
                }
                else
                {
                    maxInd = -1;
                }
            }
            else
            {
                maxInd = int.MaxValue;
            }

            if (map.FlatLists != null)
            {
                indexes   = new int[map.FlatLists.Count];
                flatLists = new object[map.FlatLists.Count];
                foreach (XmlTypeMapMemberExpandable mem in map.FlatLists)
                {
                    if (IsReadOnly(mem, mem.TypeData, ob, isValueList))
                    {
                        flatLists [mem.FlatArrayIndex] = mem.GetValue(ob);
                    }
                    else if (mem.TypeData.Type.IsArray)
                    {
                        flatLists [mem.FlatArrayIndex] = InitializeList(mem.TypeData);
                    }
                    else
                    {
                        object list = mem.GetValue(ob);
                        if (list == null)
                        {
                            list = InitializeList(mem.TypeData);
                            SetMemberValue(mem, ob, list, isValueList);
                        }
                        flatLists [mem.FlatArrayIndex] = list;
                    }

                    if (mem.ChoiceMember != null)
                    {
                        if (flatListsChoices == null)
                        {
                            flatListsChoices = new object [map.FlatLists.Count];
                        }
                        flatListsChoices [mem.FlatArrayIndex] = InitializeList(mem.ChoiceTypeData);
                    }
                }
            }

            if (_format == SerializationFormat.Encoded && map.ElementMembers != null)
            {
                FixupCallbackInfo info = new FixupCallbackInfo(this, map, isValueList);
                fixup = new Fixup(ob, new XmlSerializationFixupCallback(info.FixupMembers), map.ElementMembers.Count);
                AddFixup(fixup);
            }

            XmlTypeMapMember previousMember = null;

            while (Reader.NodeType != System.Xml.XmlNodeType.EndElement && (ind < maxInd - 1))
            {
                if (Reader.NodeType == System.Xml.XmlNodeType.Element)
                {
                    XmlTypeMapElementInfo info;

                    if (readBySoapOrder)
                    {
                        info = map.GetElement(Reader.LocalName, Reader.NamespaceURI, ind);
                    }
                    else if (hasAnyReturnMember)
                    {
                        info = (XmlTypeMapElementInfo)((XmlTypeMapMemberElement)map.ReturnMember).ElementInfo[0];
                        hasAnyReturnMember = false;
                    }
                    else
                    {
                        if (map.IsOrderDependentMap)
                        {
                            info = map.GetElement(Reader.LocalName, Reader.NamespaceURI, ind);
                        }
                        else
                        {
                            info = map.GetElement(Reader.LocalName, Reader.NamespaceURI);
                        }
                    }

                    if (info != null && !readFlag[info.Member.Index])
                    {
                        if (info.Member != previousMember)
                        {
                            ind = info.ExplicitOrder + 1;
                            // If the member is a flat list don't increase the index, since the next element may
                            // be another item of the list. This is a fix for Xamarin bug #9193.
                            if (info.Member is XmlTypeMapMemberFlatList)
                            {
                                ind--;
                            }
                            previousMember = info.Member;
                        }

                        if (info.Member.GetType() == typeof(XmlTypeMapMemberList))
                        {
                            if (_format == SerializationFormat.Encoded && info.MultiReferenceType)
                            {
                                object list = ReadReferencingElement(out fixup.Ids[info.Member.Index]);
                                if (fixup.Ids[info.Member.Index] == null)                                       // Already read
                                {
                                    if (IsReadOnly(info.Member, info.TypeData, ob, isValueList))
                                    {
                                        throw CreateReadOnlyCollectionException(info.TypeData.FullTypeName);
                                    }
                                    else
                                    {
                                        SetMemberValue(info.Member, ob, list, isValueList);
                                    }
                                }
                                else if (!info.MappedType.TypeData.Type.IsArray)
                                {
                                    if (IsReadOnly(info.Member, info.TypeData, ob, isValueList))
                                    {
                                        list = GetMemberValue(info.Member, ob, isValueList);
                                    }
                                    else
                                    {
                                        list = CreateList(info.MappedType.TypeData.Type);
                                        SetMemberValue(info.Member, ob, list, isValueList);
                                    }
                                    AddFixup(new CollectionFixup(list, new XmlSerializationCollectionFixupCallback(FillList), fixup.Ids[info.Member.Index]));
                                    fixup.Ids[info.Member.Index] = null;                                        // The member already has the value, no further fix needed.
                                }
                            }
                            else
                            {
                                if (IsReadOnly(info.Member, info.TypeData, ob, isValueList))
                                {
                                    ReadListElement(info.MappedType, info.IsNullable, GetMemberValue(info.Member, ob, isValueList), false);
                                }
                                else if (info.MappedType.TypeData.Type.IsArray)
                                {
                                    object list = ReadListElement(info.MappedType, info.IsNullable, null, true);
                                    if (list != null || info.IsNullable)
                                    {
                                        SetMemberValue(info.Member, ob, list, isValueList);
                                    }
                                }
                                else
                                {
                                    // If the member already has a list, reuse that list. No need to create a new one.
                                    object list = GetMemberValue(info.Member, ob, isValueList);
                                    if (list == null)
                                    {
                                        list = CreateList(info.MappedType.TypeData.Type);
                                        SetMemberValue(info.Member, ob, list, isValueList);
                                    }
                                    ReadListElement(info.MappedType, info.IsNullable, list, true);
                                }
                            }
                            readFlag[info.Member.Index] = true;
                        }
                        else if (info.Member.GetType() == typeof(XmlTypeMapMemberFlatList))
                        {
                            XmlTypeMapMemberFlatList mem = (XmlTypeMapMemberFlatList)info.Member;
                            AddListValue(mem.TypeData, ref flatLists[mem.FlatArrayIndex], indexes[mem.FlatArrayIndex]++, ReadObjectElement(info), !IsReadOnly(info.Member, info.TypeData, ob, isValueList));
                            if (mem.ChoiceMember != null)
                            {
                                AddListValue(mem.ChoiceTypeData, ref flatListsChoices [mem.FlatArrayIndex], indexes[mem.FlatArrayIndex] - 1, info.ChoiceValue, true);
                            }
                        }
                        else if (info.Member.GetType() == typeof(XmlTypeMapMemberAnyElement))
                        {
                            XmlTypeMapMemberAnyElement mem = (XmlTypeMapMemberAnyElement)info.Member;
                            if (mem.TypeData.IsListType)
                            {
                                AddListValue(mem.TypeData, ref flatLists[mem.FlatArrayIndex], indexes[mem.FlatArrayIndex]++, ReadXmlNode(mem.TypeData.ListItemTypeData, false), true);
                            }
                            else
                            {
                                SetMemberValue(mem, ob, ReadXmlNode(mem.TypeData, false), isValueList);
                            }
                        }
                        else if (info.Member.GetType() == typeof(XmlTypeMapMemberElement))
                        {
                            object val;
                            readFlag[info.Member.Index] = true;
                            if (_format == SerializationFormat.Encoded)
                            {
                                if (info.Member.TypeData.SchemaType != SchemaTypes.Primitive)
                                {
                                    val = ReadReferencingElement(out fixup.Ids[info.Member.Index]);
                                }
                                else
                                {
                                    val = ReadReferencingElement(info.Member.TypeData.XmlType, System.Xml.Schema.XmlSchema.Namespace, out fixup.Ids[info.Member.Index]);
                                }

                                if (info.MultiReferenceType)
                                {
                                    if (fixup.Ids[info.Member.Index] == null)                                           // already read
                                    {
                                        SetMemberValue(info.Member, ob, val, isValueList);
                                    }
                                }
                                else if (val != null)
                                {
                                    SetMemberValue(info.Member, ob, val, isValueList);
                                }
                            }
                            else
                            {
                                SetMemberValue(info.Member, ob, ReadObjectElement(info), isValueList);
                                if (info.ChoiceValue != null)
                                {
                                    XmlTypeMapMemberElement imem = (XmlTypeMapMemberElement)info.Member;
                                    imem.SetChoice(ob, info.ChoiceValue);
                                }
                            }
                        }
                        else
                        {
                            throw new InvalidOperationException("Unknown member type");
                        }
                    }
                    else if (map.DefaultAnyElementMember != null)
                    {
                        XmlTypeMapMemberAnyElement mem = map.DefaultAnyElementMember;
                        if (mem.TypeData.IsListType)
                        {
                            AddListValue(mem.TypeData, ref flatLists[mem.FlatArrayIndex], indexes[mem.FlatArrayIndex]++, ReadXmlNode(mem.TypeData.ListItemTypeData, false), true);
                        }
                        else
                        {
                            SetMemberValue(mem, ob, ReadXmlNode(mem.TypeData, false), isValueList);
                        }
                    }
                    else
                    {
                        ProcessUnknownElement(ob);
                    }
                }
                else if ((Reader.NodeType == System.Xml.XmlNodeType.Text || Reader.NodeType == System.Xml.XmlNodeType.CDATA) && map.XmlTextCollector != null)
                {
                    if (map.XmlTextCollector is XmlTypeMapMemberExpandable)
                    {
                        XmlTypeMapMemberExpandable mem   = (XmlTypeMapMemberExpandable)map.XmlTextCollector;
                        XmlTypeMapMemberFlatList   flatl = mem as XmlTypeMapMemberFlatList;
                        TypeData itype = (flatl == null) ? mem.TypeData.ListItemTypeData : flatl.ListMap.FindTextElement().TypeData;

                        object val = (itype.Type == typeof(string)) ? (object)Reader.ReadString() : (object)ReadXmlNode(itype, false);
                        AddListValue(mem.TypeData, ref flatLists[mem.FlatArrayIndex], indexes[mem.FlatArrayIndex]++, val, true);
                    }
                    else
                    {
                        XmlTypeMapMemberElement mem  = (XmlTypeMapMemberElement)map.XmlTextCollector;
                        XmlTypeMapElementInfo   info = (XmlTypeMapElementInfo)mem.ElementInfo [0];
                        if (info.TypeData.Type == typeof(string))
                        {
                            SetMemberValue(mem, ob, ReadString((string)GetMemberValue(mem, ob, isValueList)), isValueList);
                        }
                        else
                        {
                            SetMemberValue(mem, ob, GetValueFromXmlString(Reader.ReadString(), info.TypeData, info.MappedType), isValueList);
                        }
                    }
                }
                else
                {
                    UnknownNode(ob);
                }
                Reader.MoveToContent();
            }

            if (flatLists != null)
            {
                foreach (XmlTypeMapMemberExpandable mem in map.FlatLists)
                {
                    Object list = flatLists[mem.FlatArrayIndex];
                    if (mem.TypeData.Type.IsArray)
                    {
                        list = ShrinkArray((Array)list, indexes[mem.FlatArrayIndex], mem.TypeData.Type.GetElementType(), true);
                    }
                    if (!IsReadOnly(mem, mem.TypeData, ob, isValueList) && mem.TypeData.Type.IsArray)
                    {
                        SetMemberValue(mem, ob, list, isValueList);
                    }
                }
            }

            if (flatListsChoices != null)
            {
                foreach (XmlTypeMapMemberExpandable mem in map.FlatLists)
                {
                    Object list = flatListsChoices[mem.FlatArrayIndex];
                    if (list == null)
                    {
                        continue;
                    }
                    list = ShrinkArray((Array)list, indexes[mem.FlatArrayIndex], mem.ChoiceTypeData.Type.GetElementType(), true);
                    XmlTypeMapMember.SetValue(ob, mem.ChoiceMember, list);
                }
            }
            SetListMembersDefaults(map, ob, isValueList);
        }
Example #8
0
        private void Load(Stream stream)
        {
            BinaryReader reader       = new BinaryReader(stream, Encoding.ASCII);
            long         basePosition = reader.BaseStream.Position;

            string signature = Encoding.ASCII.GetString(reader.ReadBytes(4));

            if (signature != "IDSV")
            {
                throw new InvalidDataException("File signature does not match 'IDSV'.");
            }

            Version = reader.ReadInt32();

            if (Version != 4)
            {
                throw new InvalidDataException(string.Format("File version {0} does not match 4.", Version));
            }

            Checksum = reader.ReadInt32();
            Lods     = reader.ReadInt32();

            VertexCounts = new ImmutableArray <int>(MaxNumberOfLods);
            for (int i = 0; i < MaxNumberOfLods; ++i)
            {
                VertexCounts = VertexCounts.SetValue(reader.ReadInt32(), i);
            }

            Fixup[] fixups            = new Fixup[reader.ReadInt32()];
            long    fixupOffset       = reader.ReadInt32();
            long    vertexDataOffset  = reader.ReadInt32();
            long    tangentDataOffset = reader.ReadInt32();

            reader.BaseStream.Position = basePosition + fixupOffset;

            for (int i = 0; i < fixups.Length; ++i)
            {
                fixups[i].Lod            = reader.ReadInt32();
                fixups[i].SourceVertexID = reader.ReadInt32();
                fixups[i].VertexCount    = reader.ReadInt32();
            }

            long vertexCount = (tangentDataOffset - vertexDataOffset) / 48;

            ImmutableArray <BoneWeight>[] boneWeights = new ImmutableArray <BoneWeight> [vertexCount];
            Vector3f[] positions          = new Vector3f[vertexCount];
            Vector3f[] normals            = new Vector3f[vertexCount];
            Vector2f[] textureCoordinates = new Vector2f[vertexCount];
            Vector4f[] tangents           = new Vector4f[vertexCount];

            reader.BaseStream.Position = basePosition + vertexDataOffset;
            for (int v = 0; v < vertexCount; ++v)
            {
                float boneWeight0 = reader.ReadSingle();
                float boneWeight1 = reader.ReadSingle();
                float boneWeight2 = reader.ReadSingle();
                byte  bone0       = reader.ReadByte();
                byte  bone1       = reader.ReadByte();
                byte  bone2       = reader.ReadByte();

                byte boneCount = reader.ReadByte();

                switch (boneCount)
                {
                case 0:
                    boneWeights[v] = new ImmutableArray <BoneWeight>(0);
                    break;

                case 1:
                    boneWeights[v] = new ImmutableArray <BoneWeight>(new BoneWeight[] {
                        new BoneWeight(boneWeight0, bone0)
                    });
                    break;

                case 2:
                    boneWeights[v] = new ImmutableArray <BoneWeight>(new BoneWeight[] {
                        new BoneWeight(boneWeight0, bone0),
                        new BoneWeight(boneWeight1, bone1)
                    });
                    break;

                case 3:
                    boneWeights[v] = new ImmutableArray <BoneWeight>(new BoneWeight[] {
                        new BoneWeight(boneWeight0, bone0),
                        new BoneWeight(boneWeight1, bone1),
                        new BoneWeight(boneWeight2, bone2)
                    });
                    break;
                }

                positions[v]          = new Vector3f(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
                normals[v]            = new Vector3f(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
                textureCoordinates[v] = new Vector2f(reader.ReadSingle(), reader.ReadSingle());
            }

            reader.BaseStream.Position = basePosition + tangentDataOffset;
            for (int v = 0; v < vertexCount; ++v)
            {
                tangents[v] = new Vector4f(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
            }

            Vertex[] vertices = new Vertex[vertexCount];

            for (int v = 0; v < vertices.Length; ++v)
            {
                vertices[v] = new Vertex(boneWeights[v], positions[v], normals[v], textureCoordinates[v], tangents[v]);
            }

            Vertices = new ImmutableArray <Vertex>(vertices);
        }
Example #9
0
		/// <summary>
		/// Process a XML file containing CheApe definitions
		/// </summary>
		/// <param name="state"></param>
		/// <param name="s"></param>
		private void ProcessFile(ProjectState state, BlamLib.IO.XmlStream s)
		{
			int complexity = 1 + 
				PreprocessXmlNodeComplexity();

			BlamVersion def_engine = BlamVersion.Unknown;
			s.ReadAttribute("game", ref def_engine);
			if (def_engine != state.Definition.Engine)
			{
				Debug.Assert.If(false, "CheApe definition '{0}' is for {1}. Expected a {2} definition.", s.FileName, def_engine, state.Definition.Engine);
			}
			else
			{
				string name_str;
				foreach (XmlNode n in s.Cursor.ChildNodes)
				{
					switch (n.Name)
					{
						#region Enums
						case "enums":
							s.SaveCursor(n);
							foreach (XmlNode n2 in s.Cursor.ChildNodes)
							{
								if (n2.Name != "Enum") continue;

								s.SaveCursor(n2);
								StringList list = new StringList(state, s);
								s.RestoreCursor();
								name_str = list.ToString();

								try { Enums.Add(name_str, list); }
								catch (ArgumentException) { Debug.LogFile.WriteLine(kDuplicateErrorStr, "enum definition", name_str); }
							}
							s.RestoreCursor();
							break;
						#endregion

						#region Flags
						case "flags":
							s.SaveCursor(n);
							foreach (XmlNode n2 in s.Cursor.ChildNodes)
							{
								if (n2.Name != "Flag") continue;

								s.SaveCursor(n2);
								StringList list = new StringList(state, s);
								s.RestoreCursor();
								name_str = list.ToString();

								try { Flags.Add(name_str, list); }
								catch (ArgumentException) { Debug.LogFile.WriteLine(kDuplicateErrorStr, "flag definition", name_str); }
							}
							s.RestoreCursor();
							break;
						#endregion

						#region Tag References
						case "references":
							s.SaveCursor(n);
							foreach (XmlNode n2 in s.Cursor.ChildNodes)
							{
								if (n2.Name != "Reference") continue;

								s.SaveCursor(n2);
								TagReference tagref = new TagReference(state, s);
								s.RestoreCursor();
								name_str = tagref.ToString();

								try { References.Add(name_str, tagref); }
								catch (ArgumentException) { Debug.LogFile.WriteLine(kDuplicateErrorStr, "tag reference definition", name_str); }
							}
							s.RestoreCursor();
							break;
						#endregion

						#region Tag Data
						case "data":
							s.SaveCursor(n);
							foreach (XmlNode n2 in s.Cursor.ChildNodes)
							{
								if (n2.Name != "TagData") continue;

								s.SaveCursor(n2);
								TagData tagdata = new TagData(state, s);
								s.RestoreCursor();
								name_str = tagdata.ToString();

								try { Data.Add(name_str, tagdata); }
								catch (ArgumentException) { Debug.LogFile.WriteLine(kDuplicateErrorStr, "tag data definition", name_str); }
							}
							s.RestoreCursor();
							break;
						#endregion

						#region Script Functions
						case "scriptFunctions":
							if (state.scriptingInterface == null) break;

							s.SaveCursor(n);
							foreach (XmlNode n2 in s.Cursor.ChildNodes)
							{
								if (n2.Name != "function") continue;

								s.SaveCursor(n2);
								ScriptFunction sc = new ScriptFunction(state, s);
								s.RestoreCursor();
								name_str = sc.ToString();

								if (state.scriptingInterface.Functions.Contains(name_str))
								{
									Debug.LogFile.WriteLine("Engine already contains a {0} named '{1}', skipping...", "script function", name_str);
									continue;
								}

								try { ScriptFunctions.Add(name_str, sc); }
								catch (ArgumentException) { Debug.LogFile.WriteLine(kDuplicateErrorStr, "script function definition", name_str); }
							}
							s.RestoreCursor();
							break;
						#endregion

						#region Script Globals
						case "scriptGlobals":
							if (state.scriptingInterface == null) break;

							s.SaveCursor(n);
							foreach (XmlNode n2 in s.Cursor.ChildNodes)
							{
								if (n2.Name != "global") continue;

								s.SaveCursor(n2);
								ScriptGlobal sc = new ScriptGlobal(state, s);
								s.RestoreCursor();
								name_str = sc.ToString();

								if (state.scriptingInterface.Globals.Contains(name_str))
								{
									Debug.LogFile.WriteLine("Engine already contains a {0} named '{1}', ignoring...", "script global", name_str);
									continue;
								}

								try { ScriptGlobals.Add(name_str, sc); }
								catch (ArgumentException) { Debug.LogFile.WriteLine(kDuplicateErrorStr, "script global definition", name_str); }
							}
							s.RestoreCursor();
							break;
						#endregion

						#region Fix-ups
						case "fixups":
							s.SaveCursor(n);
							foreach (XmlNode n2 in s.Cursor.ChildNodes)
							{
								if (n2.Name != "fixup") continue;

								s.SaveCursor(n2);
								Fixup fu = new Fixup(state, s);
								s.RestoreCursor();
								name_str = fu.ToString();

								try { Fixups.Add(name_str, fu); }
								catch (ArgumentException) { Debug.LogFile.WriteLine(kDuplicateErrorStr, "fix-up definition", name_str); }
							}
							s.RestoreCursor();
							break;
						#endregion

						default:
							ProcessDefinition(n, state, s);
							break;
					}
				}
			}
		}
        object ReadArray(string typeName, string typeNs) {
            SoapArrayInfo arrayInfo;
            Type fallbackElementType = null;
            if (soap12) {
                string itemType = r.GetAttribute(itemTypeID, soap12NsID);
                string arraySize = r.GetAttribute(arraySizeID, soap12NsID);
                Type arrayType = (Type)types[new XmlQualifiedName(typeName, typeNs)];
                // no indication that this is an array?
                if (itemType == null && arraySize == null && (arrayType == null || !arrayType.IsArray))
                    return null;

                arrayInfo = ParseSoap12ArrayType(itemType, arraySize);
                if (arrayType != null)
                    fallbackElementType = TypeScope.GetArrayElementType(arrayType, null);
            }
            else {
                string arrayType = r.GetAttribute(arrayTypeID, soapNsID);
                if (arrayType == null) 
                    return null;

                arrayInfo = ParseArrayType(arrayType);
            }

            if (arrayInfo.dimensions != 1) throw new InvalidOperationException(Res.GetString(Res.XmlInvalidArrayDimentions, CurrentTag()));

            // NOTE: don't use the array size that is specified since an evil client might pass
            // a number larger than the actual number of items in an attempt to harm the server.

            XmlQualifiedName qname;
            bool isPrimitive;
            Type elementType = null;
            XmlQualifiedName urTypeName = new XmlQualifiedName(urTypeID, schemaNsID);
            if (arrayInfo.qname.Length > 0) {
                qname = ToXmlQualifiedName(arrayInfo.qname, false);
                elementType = (Type)types[qname];
            }
            else
                qname = urTypeName;
            
            // try again if the best we could come up with was object
            if (soap12 && elementType == typeof(object))
                elementType = null;
            
            if (elementType == null) {
                if (!soap12) {
                    elementType = GetPrimitiveType(qname, true);
                    isPrimitive = true;
                }
                else {
                    // try it as a primitive
                    if (qname != urTypeName)
                        elementType = GetPrimitiveType(qname, false);
                    if (elementType != null) {
                        isPrimitive = true;
                    }
                    else {
                        // still nothing: go with fallback type or object
                        if (fallbackElementType == null) {
                            elementType = typeof(object);
                            isPrimitive = false;
                        }
                        else {
                            elementType = fallbackElementType;
                            XmlQualifiedName newQname = (XmlQualifiedName)typesReverse[elementType];
                            if (newQname == null) {
                                newQname = XmlSerializationWriter.GetPrimitiveTypeNameInternal(elementType);
                                isPrimitive = true;
                            }
                            else
                                isPrimitive = elementType.IsPrimitive;
                            if (newQname != null) qname = newQname;
                        }
                    }
                }
            }
            else
                isPrimitive = elementType.IsPrimitive;

            if (!soap12 && arrayInfo.jaggedDimensions > 0) {
                for (int i = 0; i < arrayInfo.jaggedDimensions; i++)
                    elementType = elementType.MakeArrayType();
            }

            if (r.IsEmptyElement) {
                r.Skip();
                return Array.CreateInstance(elementType, 0);
            }

            r.ReadStartElement();
            r.MoveToContent();

            int arrayLength = 0;
            Array array = null;

            if (elementType.IsValueType) {
                if (!isPrimitive && !elementType.IsEnum) {
                    throw new NotSupportedException(Res.GetString(Res.XmlRpcArrayOfValueTypes, elementType.FullName));
                }
                // 

                int whileIterations = 0;
                int readerCount = ReaderCount;
                while (r.NodeType != XmlNodeType.EndElement) {
                    array = EnsureArrayIndex(array, arrayLength, elementType);
                    array.SetValue(ReadReferencedElement(qname.Name, qname.Namespace), arrayLength);
                    arrayLength++;
                    r.MoveToContent();
                    CheckReaderCount(ref whileIterations, ref readerCount);
                }
                array = ShrinkArray(array, arrayLength, elementType, false);
            }
            else {
                string type;
                string typens;
                string[] ids = null;
                int idsLength = 0;

                int whileIterations = 0;
                int readerCount = ReaderCount;
                while (r.NodeType != XmlNodeType.EndElement) {
                    array = EnsureArrayIndex(array, arrayLength, elementType);
                    ids = (string[])EnsureArrayIndex(ids, idsLength, typeof(string));
                    // 
                    if (r.NamespaceURI.Length != 0){
                        type = r.LocalName;
                        if ((object)r.NamespaceURI == (object)soapNsID)
                            typens = XmlSchema.Namespace;
                        else
                            typens = r.NamespaceURI;
                    }
                    else {
                        type = qname.Name;
                        typens = qname.Namespace;                        
                    }
                    array.SetValue(ReadReferencingElement(type, typens, out ids[idsLength]), arrayLength);
                    arrayLength++;
                    idsLength++;
                    // 
                    r.MoveToContent();
                    CheckReaderCount(ref whileIterations, ref readerCount);
                }

                // special case for soap 1.2: try to get a better fit than object[] when no metadata is known
                // this applies in the doc/enc/bare case
                if (soap12 && elementType == typeof(object)) {
                    Type itemType = null;
                    for (int i = 0; i < arrayLength; i++) {
                        object currItem = array.GetValue(i);
                        if (currItem != null) {
                            Type currItemType = currItem.GetType();
                            if (currItemType.IsValueType) {
                                itemType = null;
                                break;
                            }
                            if (itemType == null || currItemType.IsAssignableFrom(itemType)) {
                                itemType = currItemType;
                            }
                            else if (!itemType.IsAssignableFrom(currItemType)) {
                                itemType = null;
                                break;
                            }
                        }
                    }
                    if (itemType != null)
                        elementType = itemType;
                }
                ids = (string[])ShrinkArray(ids, idsLength, typeof(string), false);
                array = ShrinkArray(array, arrayLength, elementType, false);
                Fixup fixupArray = new Fixup(array, new XmlSerializationFixupCallback(this.FixupArrayRefs), ids);
                AddFixup(fixupArray);
            }

            // 

            ReadEndElement();
            return array;
        }
 protected void AddFixup(Fixup fixup)
 {
     fixups = EnsureArrayList(fixups);
     fixups.Add(fixup);
 }
 public object[] Read19_getSongResultResponse() {
     Reader.MoveToContent();
     object[] p = new object[1];
     Reader.MoveToContent();
     int whileIterations24 = 0;
     int readerCount24 = ReaderCount;
     while (Reader.NodeType == System.Xml.XmlNodeType.Element) {
         string root = Reader.GetAttribute("root", "http://schemas.xmlsoap.org/soap/encoding/");
         if (root == null || System.Xml.XmlConvert.ToBoolean(root)) break;
         ReadReferencedElement();
         Reader.MoveToContent();
         CheckReaderCount(ref whileIterations24, ref readerCount24);
     }
     bool isEmptyWrapper = Reader.IsEmptyElement;
     Reader.ReadStartElement();
     Fixup fixup = new Fixup(p, new System.Xml.Serialization.XmlSerializationFixupCallback(this.fixup_Read19_getSongResultResponse), 1);
     AddFixup(fixup);
     IsReturnValue = true;
     bool[] paramsRead = new bool[1];
     Reader.MoveToContent();
     int whileIterations25 = 0;
     int readerCount25 = ReaderCount;
     while (Reader.NodeType != System.Xml.XmlNodeType.EndElement && Reader.NodeType != System.Xml.XmlNodeType.None) {
         if (Reader.NodeType == System.Xml.XmlNodeType.Element) {
             if (!paramsRead[0] && (IsReturnValue || ((object) Reader.LocalName == (object)id20_songResult && (object) Reader.NamespaceURI == (object)id2_Item))) {
                 object rre = ReadReferencingElement(id19_LyricsResult, id17_urnLyricWiki, out fixup.Ids[0]);
                 try {
                     p[0] = (global::MusicLand.com.wikia.lyrics.LyricsResult)rre;
                 }
                 catch (System.InvalidCastException) {
                     throw CreateInvalidCastException(typeof(global::MusicLand.com.wikia.lyrics.LyricsResult), rre, null);
                 }
                 Referenced(p[0]);
                 IsReturnValue = false;
                 paramsRead[0] = true;
             }
             else {
                 UnknownNode((object)p);
             }
         }
         else {
             UnknownNode((object)p);
         }
         Reader.MoveToContent();
         CheckReaderCount(ref whileIterations25, ref readerCount25);
     }
     if (!isEmptyWrapper) ReadEndElement();
     ReadReferencedElements();
     return p;
 }
		void ReadMembers (ClassMap map, object ob, bool isValueList, bool readByOrder)
		{
			// Reads attributes
			ReadAttributeMembers (map, ob, isValueList);

			if (!isValueList)
			{
				Reader.MoveToElement();
				if (Reader.IsEmptyElement) { 
					SetListMembersDefaults (map, ob, isValueList);
					return;
				}

				Reader.ReadStartElement();
			}

			// Reads elements

			bool[] readFlag = new bool[(map.ElementMembers != null) ? map.ElementMembers.Count : 0];

			bool hasAnyReturnMember = (isValueList && _format == SerializationFormat.Encoded && map.ReturnMember != null);
			
			Reader.MoveToContent();

			int[] indexes = null;
			object[] flatLists = null;
			object[] flatListsChoices = null;
			Fixup fixup = null;
			int ind = 0;
			int maxInd;

			if (readByOrder) {
				if (map.ElementMembers != null) maxInd = map.ElementMembers.Count;
				else maxInd = 0;
			}
			else
				maxInd = int.MaxValue;

			if (map.FlatLists != null) 
			{
				indexes = new int[map.FlatLists.Count];
				flatLists = new object[map.FlatLists.Count];
				foreach (XmlTypeMapMemberExpandable mem in map.FlatLists) {
					if (IsReadOnly (mem, mem.TypeData, ob, isValueList))
						flatLists [mem.FlatArrayIndex] = mem.GetValue (ob);
					else if (mem.TypeData.Type.IsArray) {
						flatLists [mem.FlatArrayIndex] = InitializeList (mem.TypeData);
					}
					else {
						object list = mem.GetValue (ob);
						if (list == null) {
							list = InitializeList (mem.TypeData);
							SetMemberValue (mem, ob, list, isValueList);
						}
						flatLists [mem.FlatArrayIndex] = list;
					}
						
					if (mem.ChoiceMember != null) {
						if (flatListsChoices == null)
							flatListsChoices = new object [map.FlatLists.Count];
						flatListsChoices [mem.FlatArrayIndex] = InitializeList (mem.ChoiceTypeData);
					}
				}
			}
			
			if (_format == SerializationFormat.Encoded && map.ElementMembers != null)
			{
				FixupCallbackInfo info = new FixupCallbackInfo (this, map, isValueList);
				fixup = new Fixup(ob, new XmlSerializationFixupCallback(info.FixupMembers), map.ElementMembers.Count);
				AddFixup (fixup);
			}

			while (Reader.NodeType != System.Xml.XmlNodeType.EndElement && (ind < maxInd)) 
			{
				if (Reader.NodeType == System.Xml.XmlNodeType.Element) 
				{
					XmlTypeMapElementInfo info;
					
					if (readByOrder) {
						info = map.GetElement (ind++);
					}
					else if (hasAnyReturnMember) {
						info = (XmlTypeMapElementInfo) ((XmlTypeMapMemberElement)map.ReturnMember).ElementInfo[0];
						hasAnyReturnMember = false;
					}
					else
						info = map.GetElement (Reader.LocalName, Reader.NamespaceURI);
						
					if (info != null && !readFlag[info.Member.Index] )
					{
						if (info.Member.GetType() == typeof (XmlTypeMapMemberList))
						{
							if (_format == SerializationFormat.Encoded && info.MultiReferenceType)
							{
								object list = ReadReferencingElement (out fixup.Ids[info.Member.Index]);
								if (fixup.Ids[info.Member.Index] == null)	// Already read
								{
									if (IsReadOnly (info.Member, info.TypeData, ob, isValueList)) throw CreateReadOnlyCollectionException (info.TypeData.FullTypeName);
									else SetMemberValue (info.Member, ob, list, isValueList);
								}
								else if (!info.MappedType.TypeData.Type.IsArray)
								{
									if (IsReadOnly (info.Member, info.TypeData, ob, isValueList)) 
										list = GetMemberValue (info.Member, ob, isValueList);
									else { 
										list = CreateList (info.MappedType.TypeData.Type);
										SetMemberValue (info.Member, ob, list, isValueList);
									}
									AddFixup (new CollectionFixup (list, new XmlSerializationCollectionFixupCallback (FillList), fixup.Ids[info.Member.Index]));
									fixup.Ids[info.Member.Index] = null;	// The member already has the value, no further fix needed.
								}
							}
							else
							{
								if (IsReadOnly (info.Member, info.TypeData, ob, isValueList)) {
									ReadListElement (info.MappedType, info.IsNullable, GetMemberValue (info.Member, ob, isValueList), false);
								} else if (info.MappedType.TypeData.Type.IsArray) {
									object list = ReadListElement (info.MappedType, info.IsNullable, null, true);
									if (list != null || info.IsNullable)
										SetMemberValue (info.Member, ob, list, isValueList);
								} else {
									// If the member already has a list, reuse that list. No need to create a new one. 
									object list = GetMemberValue (info.Member, ob, isValueList);
									if (list == null) {
										list = CreateList (info.MappedType.TypeData.Type);
										SetMemberValue (info.Member, ob, list, isValueList);
									}
									ReadListElement (info.MappedType, info.IsNullable, list, true);
								}
							}
							readFlag[info.Member.Index] = true;
						}
						else if (info.Member.GetType() == typeof (XmlTypeMapMemberFlatList))
						{
							XmlTypeMapMemberFlatList mem = (XmlTypeMapMemberFlatList)info.Member;
							AddListValue (mem.TypeData, ref flatLists[mem.FlatArrayIndex], indexes[mem.FlatArrayIndex]++, ReadObjectElement (info), !IsReadOnly (info.Member, info.TypeData, ob, isValueList));
							if (mem.ChoiceMember != null) {
								AddListValue (mem.ChoiceTypeData, ref flatListsChoices [mem.FlatArrayIndex], indexes[mem.FlatArrayIndex]-1, info.ChoiceValue, true);
							}
						}
						else if (info.Member.GetType() == typeof (XmlTypeMapMemberAnyElement))
						{
							XmlTypeMapMemberAnyElement mem = (XmlTypeMapMemberAnyElement)info.Member;
							if (mem.TypeData.IsListType) AddListValue (mem.TypeData, ref flatLists[mem.FlatArrayIndex], indexes[mem.FlatArrayIndex]++, ReadXmlNode (mem.TypeData.ListItemTypeData, false), true);
							else SetMemberValue (mem, ob, ReadXmlNode (mem.TypeData, false), isValueList);
						}
						else if (info.Member.GetType() == typeof(XmlTypeMapMemberElement))
						{
							object val;
							readFlag[info.Member.Index] = true;
							if (_format == SerializationFormat.Encoded)
							{
								if (info.Member.TypeData.SchemaType != SchemaTypes.Primitive)
									val = ReadReferencingElement (out fixup.Ids[info.Member.Index]);
								else
									val = ReadReferencingElement (info.Member.TypeData.XmlType, System.Xml.Schema.XmlSchema.Namespace, out fixup.Ids[info.Member.Index]);
									
								if (info.MultiReferenceType) {
									if (fixup.Ids[info.Member.Index] == null)	// already read
										SetMemberValue (info.Member, ob, val, isValueList);
								}
								else if (val != null)
									SetMemberValue (info.Member, ob, val, isValueList);
							}
							else {
								SetMemberValue (info.Member, ob, ReadObjectElement (info), isValueList);
								if (info.ChoiceValue != null) {
									XmlTypeMapMemberElement imem = (XmlTypeMapMemberElement) info.Member;
									imem.SetChoice (ob, info.ChoiceValue);
								}
							}
						}
						else
							throw new InvalidOperationException ("Unknown member type");
					}
					else if (map.DefaultAnyElementMember != null)
					{
						XmlTypeMapMemberAnyElement mem = map.DefaultAnyElementMember;
						if (mem.TypeData.IsListType) AddListValue (mem.TypeData, ref flatLists[mem.FlatArrayIndex], indexes[mem.FlatArrayIndex]++, ReadXmlNode (mem.TypeData.ListItemTypeData, false), true);
						else SetMemberValue (mem, ob, ReadXmlNode (mem.TypeData, false), isValueList);
					}
					else 
						ProcessUnknownElement(ob);
				}
				else if ((Reader.NodeType == System.Xml.XmlNodeType.Text || Reader.NodeType == System.Xml.XmlNodeType.CDATA) && map.XmlTextCollector != null)
				{
					if (map.XmlTextCollector is XmlTypeMapMemberExpandable)
					{
						XmlTypeMapMemberExpandable mem = (XmlTypeMapMemberExpandable)map.XmlTextCollector;
						XmlTypeMapMemberFlatList flatl = mem as XmlTypeMapMemberFlatList;
						TypeData itype = (flatl == null) ? mem.TypeData.ListItemTypeData : flatl.ListMap.FindTextElement().TypeData;

						object val = (itype.Type == typeof (string)) ? (object) Reader.ReadString() : (object) ReadXmlNode (itype, false);
						AddListValue (mem.TypeData, ref flatLists[mem.FlatArrayIndex], indexes[mem.FlatArrayIndex]++, val, true);
					}
					else
					{
						XmlTypeMapMemberElement mem = (XmlTypeMapMemberElement) map.XmlTextCollector;
						XmlTypeMapElementInfo info = (XmlTypeMapElementInfo) mem.ElementInfo [0];
						if (info.TypeData.Type == typeof (string))
							SetMemberValue (mem, ob, ReadString ((string) GetMemberValue (mem, ob, isValueList)), isValueList);
						else
							SetMemberValue (mem, ob, GetValueFromXmlString (Reader.ReadString(), info.TypeData, info.MappedType), isValueList);
					}
				}
				else 
					UnknownNode(ob);

				Reader.MoveToContent();
			}

			if (flatLists != null)
			{
				foreach (XmlTypeMapMemberExpandable mem in map.FlatLists)
				{
					Object list = flatLists[mem.FlatArrayIndex];
					if (mem.TypeData.Type.IsArray)
						list = ShrinkArray ((Array)list, indexes[mem.FlatArrayIndex], mem.TypeData.Type.GetElementType(), true);
					if (!IsReadOnly (mem, mem.TypeData, ob, isValueList) && mem.TypeData.Type.IsArray)
						SetMemberValue (mem, ob, list, isValueList);
				}
			}

			if (flatListsChoices != null)
			{
				foreach (XmlTypeMapMemberExpandable mem in map.FlatLists)
				{
					Object list = flatListsChoices[mem.FlatArrayIndex];
					if (list == null) continue;
					list = ShrinkArray ((Array)list, indexes[mem.FlatArrayIndex], mem.ChoiceTypeData.Type.GetElementType(), true);
					XmlTypeMapMember.SetValue (ob, mem.ChoiceMember, list);
				}
			}
			SetListMembersDefaults (map, ob, isValueList);
		}
 protected void AddFixup(Fixup fixup)
 {
     if (this.fixups == null)
     {
         this.fixups = new ArrayList();
     }
     this.fixups.Add(fixup);
 }
Example #15
0
        /// <summary>
        /// Process a XML file containing CheApe definitions
        /// </summary>
        /// <param name="state"></param>
        /// <param name="s"></param>
        private void ProcessFile(ProjectState state, BlamLib.IO.XmlStream s)
        {
            int complexity = 1 +
                             PreprocessXmlNodeComplexity();

            BlamVersion def_engine = BlamVersion.Unknown;

            s.ReadAttribute("game", ref def_engine);
            if (def_engine != state.Definition.Engine)
            {
                Debug.Assert.If(false, "CheApe definition '{0}' is for {1}. Expected a {2} definition.", s.FileName, def_engine, state.Definition.Engine);
            }
            else
            {
                string name_str;
                foreach (XmlNode n in s.Cursor.ChildNodes)
                {
                    switch (n.Name)
                    {
                        #region Enums
                    case "enums":
                        s.SaveCursor(n);
                        foreach (XmlNode n2 in s.Cursor.ChildNodes)
                        {
                            if (n2.Name != "Enum")
                            {
                                continue;
                            }

                            s.SaveCursor(n2);
                            StringList list = new StringList(state, s);
                            s.RestoreCursor();
                            name_str = list.ToString();

                            try { Enums.Add(name_str, list); }
                            catch (ArgumentException) { Debug.LogFile.WriteLine(kDuplicateErrorStr, "enum definition", name_str); }
                        }
                        s.RestoreCursor();
                        break;
                        #endregion

                        #region Flags
                    case "flags":
                        s.SaveCursor(n);
                        foreach (XmlNode n2 in s.Cursor.ChildNodes)
                        {
                            if (n2.Name != "Flag")
                            {
                                continue;
                            }

                            s.SaveCursor(n2);
                            StringList list = new StringList(state, s);
                            s.RestoreCursor();
                            name_str = list.ToString();

                            try { Flags.Add(name_str, list); }
                            catch (ArgumentException) { Debug.LogFile.WriteLine(kDuplicateErrorStr, "flag definition", name_str); }
                        }
                        s.RestoreCursor();
                        break;
                        #endregion

                        #region Tag References
                    case "references":
                        s.SaveCursor(n);
                        foreach (XmlNode n2 in s.Cursor.ChildNodes)
                        {
                            if (n2.Name != "Reference")
                            {
                                continue;
                            }

                            s.SaveCursor(n2);
                            TagReference tagref = new TagReference(state, s);
                            s.RestoreCursor();
                            name_str = tagref.ToString();

                            try { References.Add(name_str, tagref); }
                            catch (ArgumentException) { Debug.LogFile.WriteLine(kDuplicateErrorStr, "tag reference definition", name_str); }
                        }
                        s.RestoreCursor();
                        break;
                        #endregion

                        #region Tag Data
                    case "data":
                        s.SaveCursor(n);
                        foreach (XmlNode n2 in s.Cursor.ChildNodes)
                        {
                            if (n2.Name != "TagData")
                            {
                                continue;
                            }

                            s.SaveCursor(n2);
                            TagData tagdata = new TagData(state, s);
                            s.RestoreCursor();
                            name_str = tagdata.ToString();

                            try { Data.Add(name_str, tagdata); }
                            catch (ArgumentException) { Debug.LogFile.WriteLine(kDuplicateErrorStr, "tag data definition", name_str); }
                        }
                        s.RestoreCursor();
                        break;
                        #endregion

                        #region Script Functions
                    case "scriptFunctions":
                        if (state.scriptingInterface == null)
                        {
                            break;
                        }

                        s.SaveCursor(n);
                        foreach (XmlNode n2 in s.Cursor.ChildNodes)
                        {
                            if (n2.Name != "function")
                            {
                                continue;
                            }

                            s.SaveCursor(n2);
                            ScriptFunction sc = new ScriptFunction(state, s);
                            s.RestoreCursor();
                            name_str = sc.ToString();

                            if (state.scriptingInterface.Functions.Contains(name_str))
                            {
                                Debug.LogFile.WriteLine("Engine already contains a {0} named '{1}', skipping...", "script function", name_str);
                                continue;
                            }

                            try { ScriptFunctions.Add(name_str, sc); }
                            catch (ArgumentException) { Debug.LogFile.WriteLine(kDuplicateErrorStr, "script function definition", name_str); }
                        }
                        s.RestoreCursor();
                        break;
                        #endregion

                        #region Script Globals
                    case "scriptGlobals":
                        if (state.scriptingInterface == null)
                        {
                            break;
                        }

                        s.SaveCursor(n);
                        foreach (XmlNode n2 in s.Cursor.ChildNodes)
                        {
                            if (n2.Name != "global")
                            {
                                continue;
                            }

                            s.SaveCursor(n2);
                            ScriptGlobal sc = new ScriptGlobal(state, s);
                            s.RestoreCursor();
                            name_str = sc.ToString();

                            if (state.scriptingInterface.Globals.Contains(name_str))
                            {
                                Debug.LogFile.WriteLine("Engine already contains a {0} named '{1}', ignoring...", "script global", name_str);
                                continue;
                            }

                            try { ScriptGlobals.Add(name_str, sc); }
                            catch (ArgumentException) { Debug.LogFile.WriteLine(kDuplicateErrorStr, "script global definition", name_str); }
                        }
                        s.RestoreCursor();
                        break;
                        #endregion

                        #region Fix-ups
                    case "fixups":
                        s.SaveCursor(n);
                        foreach (XmlNode n2 in s.Cursor.ChildNodes)
                        {
                            if (n2.Name != "fixup")
                            {
                                continue;
                            }

                            s.SaveCursor(n2);
                            Fixup fu = new Fixup(state, s);
                            s.RestoreCursor();
                            name_str = fu.ToString();

                            try { Fixups.Add(name_str, fu); }
                            catch (ArgumentException) { Debug.LogFile.WriteLine(kDuplicateErrorStr, "fix-up definition", name_str); }
                        }
                        s.RestoreCursor();
                        break;
                        #endregion

                    default:
                        ProcessDefinition(n, state, s);
                        break;
                    }
                }
            }
        }
        private bool IsFloatingPointEmulatorFixup(Fixup fixup)
        {
            ExternalSymbol symbol = fixup.Target.Referent as ExternalSymbol;
            if (symbol == null)
                return false;

            switch (symbol.Name)
            {
                case "FIARQQ":
                case "FICRQQ":
                case "FIDRQQ":
                case "FIERQQ":
                case "FISRQQ":
                case "FIWRQQ":
                case "FJARQQ":
                case "FJCRQQ":
                case "FJSRQQ":
                    return true;
                default:
                    return false;
            }
        }
		void ReadMembers (ClassMap map, object ob, bool isValueList, bool readByOrder)
		{
			// Set the default values of the members
			if (map.MembersWithDefault != null)
			{
				ArrayList members = map.MembersWithDefault;
				for (int n=0; n<members.Count; n++) {
					XmlTypeMapMember mem = (XmlTypeMapMember) members[n];
					SetMemberValueFromAttr (mem, ob, mem.DefaultValue, isValueList);
				}
			}
			
			// Reads attributes

			XmlTypeMapMember anyAttrMember = map.DefaultAnyAttributeMember;
			int anyAttributeIndex = 0;
			object anyAttributeArray = null;

			while (Reader.MoveToNextAttribute())
			{
				XmlTypeMapMemberAttribute member = map.GetAttribute (Reader.LocalName, Reader.NamespaceURI);

				if (member != null) 
				{
					SetMemberValue (member, ob, GetValueFromXmlString (Reader.Value, member.TypeData, member.MappedType), isValueList);
				}
				else if (IsXmlnsAttribute(Reader.Name)) 
				{
					// If the map has NamespaceDeclarations,
					// then store this xmlns to the given member.
					// If the instance doesn't exist, then create.
					if (map.NamespaceDeclarations != null) {
						XmlSerializerNamespaces nss = this.GetMemberValue (map.NamespaceDeclarations, ob, isValueList) as XmlSerializerNamespaces;
						if (nss == null) {
							nss = new XmlSerializerNamespaces ();
							SetMemberValue (map.NamespaceDeclarations, ob, nss, isValueList);
						}
						if (Reader.Prefix == "xmlns")
							nss.Add (Reader.LocalName, Reader.Value);
						else
							nss.Add ("", Reader.Value);
					}
				}	
				else if (anyAttrMember != null) 
				{
					XmlAttribute attr = (XmlAttribute) Document.ReadNode(Reader);
					ParseWsdlArrayType (attr);
					AddListValue (anyAttrMember.TypeData, ref anyAttributeArray, anyAttributeIndex++, attr, true);
				}
				else
					ProcessUnknownAttribute(ob);
			}

			if (anyAttrMember != null)
			{
				anyAttributeArray = ShrinkArray ((Array)anyAttributeArray, anyAttributeIndex, anyAttrMember.TypeData.Type.GetElementType(), true);
				SetMemberValue (anyAttrMember, ob, anyAttributeArray, isValueList);
			}
			
			if (!isValueList)
			{
				Reader.MoveToElement();
				if (Reader.IsEmptyElement) 
					return;

				Reader.ReadStartElement();
			}

			// Reads elements

			bool[] readFlag = new bool[(map.ElementMembers != null) ? map.ElementMembers.Count : 0];

			bool hasAnyReturnMember = (isValueList && _format == SerializationFormat.Encoded && map.ReturnMember != null 
										&& map.ReturnMember.TypeData.Type == typeof(object));
			
			Reader.MoveToContent();

			int[] indexes = null;
			object[] flatLists = null;
			Fixup fixup = null;
			int ind = 0;
			int maxInd;

			if (readByOrder) {
				if (map.ElementMembers != null) maxInd = map.ElementMembers.Count;
				else maxInd = 0;
			}
			else
				maxInd = int.MaxValue;

			if (map.FlatLists != null) 
			{
				indexes = new int[map.FlatLists.Count];
				flatLists = new object[map.FlatLists.Count];
				foreach (XmlTypeMapMemberExpandable mem in map.FlatLists)
					if (IsReadOnly (mem, ob, isValueList)) flatLists[mem.FlatArrayIndex] = mem.GetValue (ob);
			}
			
			if (_format == SerializationFormat.Encoded && map.ElementMembers != null)
			{
				FixupCallbackInfo info = new FixupCallbackInfo (this, map, isValueList);
				fixup = new Fixup(ob, new XmlSerializationFixupCallback(info.FixupMembers), map.ElementMembers.Count);
				AddFixup (fixup);
			}

			while (Reader.NodeType != System.Xml.XmlNodeType.EndElement && (ind < maxInd)) 
			{
				if (Reader.NodeType == System.Xml.XmlNodeType.Element) 
				{
					XmlTypeMapElementInfo info;
					
					if (readByOrder) {
						info = map.GetElement (ind++);
					}
					else if (hasAnyReturnMember) {
						info = (XmlTypeMapElementInfo) ((XmlTypeMapMemberElement)map.ReturnMember).ElementInfo[0];
						hasAnyReturnMember = false;
					}
					else
						info = map.GetElement (Reader.LocalName, Reader.NamespaceURI);
						
					if (info != null && !readFlag[info.Member.Index] )
					{
						if (info.Member.GetType() == typeof (XmlTypeMapMemberList))
						{
							if (_format == SerializationFormat.Encoded && info.MultiReferenceType)
							{
								object list = ReadReferencingElement (out fixup.Ids[info.Member.Index]);
								if (fixup.Ids[info.Member.Index] == null)	// Already read
								{
									if (IsReadOnly (info.Member, ob, isValueList)) throw CreateReadOnlyCollectionException (info.TypeData.FullTypeName);
									else SetMemberValue (info.Member, ob, list, isValueList);
								}
								else if (!info.MappedType.TypeData.Type.IsArray)
								{
									if (IsReadOnly (info.Member, ob, isValueList)) 
										list = GetMemberValue (info.Member, ob, isValueList);
									else { 
										list = CreateList (info.MappedType.TypeData.Type);
										SetMemberValue (info.Member, ob, list, isValueList);
									}
									AddFixup (new CollectionFixup (list, new XmlSerializationCollectionFixupCallback (FillList), fixup.Ids[info.Member.Index]));
									fixup.Ids[info.Member.Index] = null;	// The member already has the value, no further fix needed.
								}
							}
							else
							{
								if (IsReadOnly (info.Member, ob, isValueList)) ReadListElement (info.MappedType, info.IsNullable, GetMemberValue (info.Member, ob, isValueList), false);
								else SetMemberValue (info.Member, ob, ReadListElement (info.MappedType, info.IsNullable, null, true), isValueList);
							}
							readFlag[info.Member.Index] = true;
						}
						else if (info.Member.GetType() == typeof (XmlTypeMapMemberFlatList))
						{
							XmlTypeMapMemberFlatList mem = (XmlTypeMapMemberFlatList)info.Member;
							AddListValue (mem.TypeData, ref flatLists[mem.FlatArrayIndex], indexes[mem.FlatArrayIndex]++, ReadObjectElement (info), !IsReadOnly (info.Member, ob, isValueList));
						}
						else if (info.Member.GetType() == typeof (XmlTypeMapMemberAnyElement))
						{
							XmlTypeMapMemberAnyElement mem = (XmlTypeMapMemberAnyElement)info.Member;
							if (mem.TypeData.IsListType) AddListValue (mem.TypeData, ref flatLists[mem.FlatArrayIndex], indexes[mem.FlatArrayIndex]++, ReadXmlNode (mem.TypeData.ListItemTypeData, false), true);
							else SetMemberValue (mem, ob, ReadXmlNode (mem.TypeData, false), isValueList);
						}
						else if (info.Member.GetType() == typeof(XmlTypeMapMemberElement))
						{
							object val;
							readFlag[info.Member.Index] = true;
							if (_format == SerializationFormat.Encoded)
							{
								val = ReadReferencingElement (out fixup.Ids[info.Member.Index]);
								if (info.MultiReferenceType) {
									if (fixup.Ids[info.Member.Index] == null)	// already read
										SetMemberValue (info.Member, ob, val, isValueList);
								}
								else if (val != null)
									SetMemberValue (info.Member, ob, val, isValueList);
							}
							else 
								SetMemberValue (info.Member, ob, ReadObjectElement (info), isValueList);
						}
						else
							throw new InvalidOperationException ("Unknown member type");
					}
					else if (map.DefaultAnyElementMember != null)
					{
						XmlTypeMapMemberAnyElement mem = map.DefaultAnyElementMember;
						if (mem.TypeData.IsListType) AddListValue (mem.TypeData, ref flatLists[mem.FlatArrayIndex], indexes[mem.FlatArrayIndex]++, ReadXmlNode (mem.TypeData.ListItemTypeData, false), true);
						else SetMemberValue (mem, ob, ReadXmlNode (mem.TypeData, false), isValueList);
					}
					else 
						ProcessUnknownElement(ob);
				}
				else if (Reader.NodeType == System.Xml.XmlNodeType.Text && map.XmlTextCollector != null)
				{
					if (map.XmlTextCollector is XmlTypeMapMemberExpandable)
					{
						XmlTypeMapMemberExpandable mem = (XmlTypeMapMemberExpandable)map.XmlTextCollector;
						XmlTypeMapMemberFlatList flatl = mem as XmlTypeMapMemberFlatList;
						TypeData itype = (flatl == null) ? mem.TypeData.ListItemTypeData : flatl.ListMap.FindTextElement().TypeData;

						object val = (itype.Type == typeof (string)) ? (object) Reader.ReadString() : (object) ReadXmlNode (itype, false);
						AddListValue (mem.TypeData, ref flatLists[mem.FlatArrayIndex], indexes[mem.FlatArrayIndex]++, val, true);
					}
					else
					{
						XmlTypeMapMemberElement mem = (XmlTypeMapMemberElement) map.XmlTextCollector;
						XmlTypeMapElementInfo info = (XmlTypeMapElementInfo) mem.ElementInfo [0];
						if (info.TypeData.Type == typeof (string))
							SetMemberValue (mem, ob, ReadString ((string) GetMemberValue (mem, ob, isValueList)), isValueList);
						else
							SetMemberValue (mem, ob, GetValueFromXmlString (Reader.ReadString(), info.TypeData, info.MappedType), isValueList);
					}
				}
				else 
					UnknownNode(ob);

				Reader.Read();
				Reader.MoveToContent();
			}

			if (flatLists != null)
			{
				foreach (XmlTypeMapMemberExpandable mem in map.FlatLists)
				{
					Object list = flatLists[mem.FlatArrayIndex];
					if (mem.TypeData.Type.IsArray)
						list = ShrinkArray ((Array)list, indexes[mem.FlatArrayIndex], mem.TypeData.Type.GetElementType(), true);
					if (!IsReadOnly (mem, ob, isValueList))
						SetMemberValue (mem, ob, list, isValueList);
				}
			}		
		}
 private object ReadArray(string typeName, string typeNs)
 {
     SoapArrayInfo info;
     Type arrayElementType = null;
     XmlQualifiedName name;
     bool isPrimitive;
     if (this.soap12)
     {
         string attribute = this.r.GetAttribute(this.itemTypeID, this.soap12NsID);
         string arraySize = this.r.GetAttribute(this.arraySizeID, this.soap12NsID);
         Type type2 = (Type) this.types[new XmlQualifiedName(typeName, typeNs)];
         if (((attribute == null) && (arraySize == null)) && ((type2 == null) || !type2.IsArray))
         {
             return null;
         }
         info = this.ParseSoap12ArrayType(attribute, arraySize);
         if (type2 != null)
         {
             arrayElementType = TypeScope.GetArrayElementType(type2, null);
         }
     }
     else
     {
         string str3 = this.r.GetAttribute(this.arrayTypeID, this.soapNsID);
         if (str3 == null)
         {
             return null;
         }
         info = this.ParseArrayType(str3);
     }
     if (info.dimensions != 1)
     {
         throw new InvalidOperationException(Res.GetString("XmlInvalidArrayDimentions", new object[] { this.CurrentTag() }));
     }
     Type primitiveType = null;
     XmlQualifiedName name2 = new XmlQualifiedName(this.urTypeID, this.schemaNsID);
     if (info.qname.Length > 0)
     {
         name = this.ToXmlQualifiedName(info.qname, false);
         primitiveType = (Type) this.types[name];
     }
     else
     {
         name = name2;
     }
     if (this.soap12 && (primitiveType == typeof(object)))
     {
         primitiveType = null;
     }
     if (primitiveType == null)
     {
         if (!this.soap12)
         {
             primitiveType = this.GetPrimitiveType(name, true);
             isPrimitive = true;
         }
         else
         {
             if (name != name2)
             {
                 primitiveType = this.GetPrimitiveType(name, false);
             }
             if (primitiveType != null)
             {
                 isPrimitive = true;
             }
             else if (arrayElementType == null)
             {
                 primitiveType = typeof(object);
                 isPrimitive = false;
             }
             else
             {
                 primitiveType = arrayElementType;
                 XmlQualifiedName primitiveTypeNameInternal = (XmlQualifiedName) this.typesReverse[primitiveType];
                 if (primitiveTypeNameInternal == null)
                 {
                     primitiveTypeNameInternal = XmlSerializationWriter.GetPrimitiveTypeNameInternal(primitiveType);
                     isPrimitive = true;
                 }
                 else
                 {
                     isPrimitive = primitiveType.IsPrimitive;
                 }
                 if (primitiveTypeNameInternal != null)
                 {
                     name = primitiveTypeNameInternal;
                 }
             }
         }
     }
     else
     {
         isPrimitive = primitiveType.IsPrimitive;
     }
     if (!this.soap12 && (info.jaggedDimensions > 0))
     {
         for (int i = 0; i < info.jaggedDimensions; i++)
         {
             primitiveType = primitiveType.MakeArrayType();
         }
     }
     if (this.r.IsEmptyElement)
     {
         this.r.Skip();
         return Array.CreateInstance(primitiveType, 0);
     }
     this.r.ReadStartElement();
     this.r.MoveToContent();
     int index = 0;
     Array a = null;
     if (primitiveType.IsValueType)
     {
         if (!isPrimitive && !primitiveType.IsEnum)
         {
             throw new NotSupportedException(Res.GetString("XmlRpcArrayOfValueTypes", new object[] { primitiveType.FullName }));
         }
         int whileIterations = 0;
         int readerCount = this.ReaderCount;
         while (this.r.NodeType != XmlNodeType.EndElement)
         {
             a = this.EnsureArrayIndex(a, index, primitiveType);
             a.SetValue(this.ReadReferencedElement(name.Name, name.Namespace), index);
             index++;
             this.r.MoveToContent();
             this.CheckReaderCount(ref whileIterations, ref readerCount);
         }
         a = this.ShrinkArray(a, index, primitiveType, false);
     }
     else
     {
         string[] strArray = null;
         int num5 = 0;
         int num6 = 0;
         int num7 = this.ReaderCount;
         while (this.r.NodeType != XmlNodeType.EndElement)
         {
             string localName;
             string namespaceURI;
             a = this.EnsureArrayIndex(a, index, primitiveType);
             strArray = (string[]) this.EnsureArrayIndex(strArray, num5, typeof(string));
             if (this.r.NamespaceURI.Length != 0)
             {
                 localName = this.r.LocalName;
                 if (this.r.NamespaceURI == this.soapNsID)
                 {
                     namespaceURI = "http://www.w3.org/2001/XMLSchema";
                 }
                 else
                 {
                     namespaceURI = this.r.NamespaceURI;
                 }
             }
             else
             {
                 localName = name.Name;
                 namespaceURI = name.Namespace;
             }
             a.SetValue(this.ReadReferencingElement(localName, namespaceURI, out strArray[num5]), index);
             index++;
             num5++;
             this.r.MoveToContent();
             this.CheckReaderCount(ref num6, ref num7);
         }
         if (this.soap12 && (primitiveType == typeof(object)))
         {
             Type c = null;
             for (int j = 0; j < index; j++)
             {
                 object obj2 = a.GetValue(j);
                 if (obj2 != null)
                 {
                     Type type = obj2.GetType();
                     if (type.IsValueType)
                     {
                         c = null;
                         break;
                     }
                     if ((c == null) || type.IsAssignableFrom(c))
                     {
                         c = type;
                     }
                     else if (!c.IsAssignableFrom(type))
                     {
                         c = null;
                         break;
                     }
                 }
             }
             if (c != null)
             {
                 primitiveType = c;
             }
         }
         strArray = (string[]) this.ShrinkArray(strArray, num5, typeof(string), false);
         a = this.ShrinkArray(a, index, primitiveType, false);
         Fixup fixup = new Fixup(a, new XmlSerializationFixupCallback(this.FixupArrayRefs), strArray);
         this.AddFixup(fixup);
     }
     this.ReadEndElement();
     return a;
 }
Example #19
0
		protected void FixupsToMemoryStream()
		{
			uint base_address = OwnerState.Definition.MemoryInfo.BaseAddress;

			Head.FixupCount = OwnerState.Importer.Fixups.Count;
			if (Head.FixupCount > 0)
			{
				Fixup f = new Fixup();
				Head.FixupAddress = base_address + MemoryStream.PositionUnsigned;
				foreach (Import.Fixup fu in OwnerState.Importer.Fixups.Values)
				{
					AddLocationFixup(fu.Name, MemoryStream, true);
					MemoryStream.Write((int)0);
				}
				foreach (Import.Fixup fu in OwnerState.Importer.Fixups.Values)
				{
					f.Reset(fu);
					f.Write(MemoryStream);
				}

				AlignMemoryStream(Compiler.kDefaultAlignment);
			}
		}
 public object[] Read29_postAlbumResponse() {
     Reader.MoveToContent();
     object[] p = new object[5];
     p[0] = new global::System.Boolean();
     p[3] = new global::System.Int32();
     Reader.MoveToContent();
     int whileIterations39 = 0;
     int readerCount39 = ReaderCount;
     while (Reader.NodeType == System.Xml.XmlNodeType.Element) {
         string root = Reader.GetAttribute("root", "http://schemas.xmlsoap.org/soap/encoding/");
         if (root == null || System.Xml.XmlConvert.ToBoolean(root)) break;
         ReadReferencedElement();
         Reader.MoveToContent();
         CheckReaderCount(ref whileIterations39, ref readerCount39);
     }
     bool isEmptyWrapper = Reader.IsEmptyElement;
     Reader.ReadStartElement();
     Fixup fixup = new Fixup(p, new System.Xml.Serialization.XmlSerializationFixupCallback(this.fixup_Read29_postAlbumResponse), 5);
     AddFixup(fixup);
     IsReturnValue = true;
     bool[] paramsRead = new bool[5];
     Reader.MoveToContent();
     int whileIterations40 = 0;
     int readerCount40 = ReaderCount;
     while (Reader.NodeType != System.Xml.XmlNodeType.EndElement && Reader.NodeType != System.Xml.XmlNodeType.None) {
         if (Reader.NodeType == System.Xml.XmlNodeType.Element) {
             if (!paramsRead[0] && (IsReturnValue || ((object) Reader.LocalName == (object)id10_dataUsed && (object) Reader.NamespaceURI == (object)id2_Item))) {
                 object rre = ReadReferencingElement(id11_boolean, id4_Item, out fixup.Ids[0]);
                 if (rre != null) {
                     try {
                         p[0] = (global::System.Boolean)rre;
                     }
                     catch (System.InvalidCastException) {
                         throw CreateInvalidCastException(typeof(global::System.Boolean), rre, null);
                     }
                     Referenced(p[0]);
                 }
                 IsReturnValue = false;
                 paramsRead[0] = true;
             }
             else if (!paramsRead[1] && ((object) Reader.LocalName == (object)id1_artist && (object) Reader.NamespaceURI == (object)id2_Item)) {
                 object rre = ReadReferencingElement(id3_string, id4_Item, out fixup.Ids[1]);
                 try {
                     p[1] = (global::System.String)rre;
                 }
                 catch (System.InvalidCastException) {
                     throw CreateInvalidCastException(typeof(global::System.String), rre, null);
                 }
                 Referenced(p[1]);
                 paramsRead[1] = true;
             }
             else if (!paramsRead[2] && ((object) Reader.LocalName == (object)id23_album && (object) Reader.NamespaceURI == (object)id2_Item)) {
                 object rre = ReadReferencingElement(id3_string, id4_Item, out fixup.Ids[2]);
                 try {
                     p[2] = (global::System.String)rre;
                 }
                 catch (System.InvalidCastException) {
                     throw CreateInvalidCastException(typeof(global::System.String), rre, null);
                 }
                 Referenced(p[2]);
                 paramsRead[2] = true;
             }
             else if (!paramsRead[3] && ((object) Reader.LocalName == (object)id24_year && (object) Reader.NamespaceURI == (object)id2_Item)) {
                 object rre = ReadReferencingElement(id25_int, id4_Item, out fixup.Ids[3]);
                 if (rre != null) {
                     try {
                         p[3] = (global::System.Int32)rre;
                     }
                     catch (System.InvalidCastException) {
                         throw CreateInvalidCastException(typeof(global::System.Int32), rre, null);
                     }
                     Referenced(p[3]);
                 }
                 paramsRead[3] = true;
             }
             else if (!paramsRead[4] && ((object) Reader.LocalName == (object)id12_message && (object) Reader.NamespaceURI == (object)id2_Item)) {
                 object rre = ReadReferencingElement(id3_string, id4_Item, out fixup.Ids[4]);
                 try {
                     p[4] = (global::System.String)rre;
                 }
                 catch (System.InvalidCastException) {
                     throw CreateInvalidCastException(typeof(global::System.String), rre, null);
                 }
                 Referenced(p[4]);
                 paramsRead[4] = true;
             }
             else {
                 UnknownNode((object)p);
             }
         }
         else {
             UnknownNode((object)p);
         }
         Reader.MoveToContent();
         CheckReaderCount(ref whileIterations40, ref readerCount40);
     }
     if (!isEmptyWrapper) ReadEndElement();
     ReadReferencedElements();
     return p;
 }
Example #21
0
        protected static void UpdateLength(RdpPacket packet, string Identifier)
        {
            Fixup fixup = RDPClient.m_Fixup[Identifier];

            RDPClient.m_Fixup.Remove(Identifier);
            long position = packet.Position;

            if (fixup.Length != -1)
            {
                long num2 = packet.Position - fixup.Offset;
                if (num2 != fixup.Length)
                {
                    throw new Exception("DER Tag length invalid");
                }
            }
            else
            {
                long   num3  = packet.Position - (fixup.Offset + 1L);
                byte[] bytes = BitConverter.GetBytes(num3);
                packet.Position = fixup.Offset;
                if (num3 > 0xffffffL)
                {
                    packet.WriteByte(0x84);
                    packet.InsertByte(bytes[3]);
                    position += 1L;
                    packet.InsertByte(bytes[2]);
                    position += 1L;
                    packet.InsertByte(bytes[1]);
                    position += 1L;
                    packet.InsertByte(bytes[0]);
                    position += 1L;
                }
                else if (num3 > 0xffffL)
                {
                    packet.WriteByte(0x83);
                    packet.InsertByte(bytes[2]);
                    position += 1L;
                    packet.InsertByte(bytes[1]);
                    position += 1L;
                    packet.InsertByte(bytes[0]);
                    position += 1L;
                }
                else if (num3 > 0xffL)
                {
                    packet.WriteByte(130);
                    packet.InsertByte(bytes[1]);
                    position += 1L;
                    packet.InsertByte(bytes[0]);
                    position += 1L;
                }
                else if (num3 > 0x7fL)
                {
                    packet.WriteByte(0x81);
                    packet.InsertByte(bytes[0]);
                    position += 1L;
                }
                else
                {
                    packet.WriteByte(bytes[0]);
                }
                packet.Position = position;
            }
        }
 object Read4_LyricsResult() {
     global::MusicLand.com.wikia.lyrics.LyricsResult o;
     o = new global::MusicLand.com.wikia.lyrics.LyricsResult();
     Fixup fixup = new Fixup(o, new System.Xml.Serialization.XmlSerializationFixupCallback(this.fixup_Read4_LyricsResult), 4);
     AddFixup(fixup);
     bool[] paramsRead = new bool[4];
     while (Reader.MoveToNextAttribute()) {
         if (!IsXmlnsAttribute(Reader.Name)) {
             UnknownNode((object)o);
         }
     }
     Reader.MoveToElement();
     if (Reader.IsEmptyElement) { Reader.Skip(); return o; }
     Reader.ReadStartElement();
     Reader.MoveToContent();
     int whileIterations2 = 0;
     int readerCount2 = ReaderCount;
     while (Reader.NodeType != System.Xml.XmlNodeType.EndElement && Reader.NodeType != System.Xml.XmlNodeType.None) {
         if (Reader.NodeType == System.Xml.XmlNodeType.Element) {
             if (!paramsRead[0] && ((object) Reader.LocalName == (object)id1_artist && (object) Reader.NamespaceURI == (object)id2_Item)) {
                 object rre = ReadReferencingElement(id3_string, id4_Item, out fixup.Ids[0]);
                 try {
                     o.@artist = (global::System.String)rre;
                 }
                 catch (System.InvalidCastException) {
                     throw CreateInvalidCastException(typeof(global::System.String), rre, null);
                 }
                 Referenced(o.@artist);
                 paramsRead[0] = true;
             }
             else if (!paramsRead[1] && ((object) Reader.LocalName == (object)id5_song && (object) Reader.NamespaceURI == (object)id2_Item)) {
                 object rre = ReadReferencingElement(id3_string, id4_Item, out fixup.Ids[1]);
                 try {
                     o.@song = (global::System.String)rre;
                 }
                 catch (System.InvalidCastException) {
                     throw CreateInvalidCastException(typeof(global::System.String), rre, null);
                 }
                 Referenced(o.@song);
                 paramsRead[1] = true;
             }
             else if (!paramsRead[2] && ((object) Reader.LocalName == (object)id8_lyrics && (object) Reader.NamespaceURI == (object)id2_Item)) {
                 object rre = ReadReferencingElement(id3_string, id4_Item, out fixup.Ids[2]);
                 try {
                     o.@lyrics = (global::System.String)rre;
                 }
                 catch (System.InvalidCastException) {
                     throw CreateInvalidCastException(typeof(global::System.String), rre, null);
                 }
                 Referenced(o.@lyrics);
                 paramsRead[2] = true;
             }
             else if (!paramsRead[3] && ((object) Reader.LocalName == (object)id9_url && (object) Reader.NamespaceURI == (object)id2_Item)) {
                 object rre = ReadReferencingElement(id3_string, id4_Item, out fixup.Ids[3]);
                 try {
                     o.@url = (global::System.String)rre;
                 }
                 catch (System.InvalidCastException) {
                     throw CreateInvalidCastException(typeof(global::System.String), rre, null);
                 }
                 Referenced(o.@url);
                 paramsRead[3] = true;
             }
             else {
                 UnknownNode((object)o);
             }
         }
         else {
             UnknownNode((object)o);
         }
         Reader.MoveToContent();
         CheckReaderCount(ref whileIterations2, ref readerCount2);
     }
     ReadEndElement();
     return o;
 }
Example #23
0
File: Vvd.cs Project: Frassle/Ibasa
        private void Load(Stream stream)
        {
            BinaryReader reader = new BinaryReader(stream, Encoding.ASCII);
            long basePosition = reader.BaseStream.Position;

            string signature = Encoding.ASCII.GetString(reader.ReadBytes(4));

            if (signature != "IDSV")
                throw new InvalidDataException("File signature does not match 'IDSV'.");

            Version = reader.ReadInt32();

            if (Version != 4)
                throw new InvalidDataException(string.Format("File version {0} does not match 4.", Version));

            Checksum = reader.ReadInt32();
            Lods = reader.ReadInt32();

            VertexCounts = new ImmutableArray<int>(MaxNumberOfLods);
            for (int i = 0; i < MaxNumberOfLods; ++i)
            {
                VertexCounts = VertexCounts.SetValue(reader.ReadInt32(), i);
            }

            Fixup[] fixups = new Fixup[reader.ReadInt32()];
            long fixupOffset = reader.ReadInt32();
            long vertexDataOffset = reader.ReadInt32();
            long tangentDataOffset = reader.ReadInt32();
            
            reader.BaseStream.Position = basePosition + fixupOffset;

            for (int i = 0; i < fixups.Length; ++i)
            {
                fixups[i].Lod = reader.ReadInt32();
                fixups[i].SourceVertexID = reader.ReadInt32();
                fixups[i].VertexCount = reader.ReadInt32();
            }

            long vertexCount = (tangentDataOffset - vertexDataOffset) / 48;

            ImmutableArray<BoneWeight>[] boneWeights = new ImmutableArray<BoneWeight>[vertexCount];
            Vector3f[] positions = new Vector3f[vertexCount];
            Vector3f[] normals = new Vector3f[vertexCount];
            Vector2f[] textureCoordinates = new Vector2f[vertexCount];
            Vector4f[] tangents = new Vector4f[vertexCount];

            reader.BaseStream.Position = basePosition + vertexDataOffset;
            for (int v = 0; v < vertexCount; ++v)
            {
                float boneWeight0 = reader.ReadSingle();
                float boneWeight1 = reader.ReadSingle();
                float boneWeight2 = reader.ReadSingle();
                byte bone0 = reader.ReadByte();
                byte bone1 = reader.ReadByte();
                byte bone2 = reader.ReadByte();

                byte boneCount = reader.ReadByte();

                switch (boneCount)
                {
                    case 0:
                        boneWeights[v] = new ImmutableArray<BoneWeight>(0);
                        break;
                    case 1:
                        boneWeights[v] = new ImmutableArray<BoneWeight>(new BoneWeight[] {
                            new BoneWeight(boneWeight0, bone0) });
                        break;
                    case 2:
                        boneWeights[v] = new ImmutableArray<BoneWeight>(new BoneWeight[] {
                            new BoneWeight(boneWeight0, bone0),
                            new BoneWeight(boneWeight1, bone1)});
                        break;
                    case 3:
                        boneWeights[v] = new ImmutableArray<BoneWeight>(new BoneWeight[] {
                            new BoneWeight(boneWeight0, bone0),
                            new BoneWeight(boneWeight1, bone1),
                            new BoneWeight(boneWeight2, bone2)});
                        break;
                }

                positions[v] = new Vector3f(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
                normals[v] = new Vector3f(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
                textureCoordinates[v] = new Vector2f(reader.ReadSingle(), reader.ReadSingle());
            }
            
            reader.BaseStream.Position = basePosition + tangentDataOffset;
            for (int v = 0; v < vertexCount; ++v)
            {
                tangents[v] = new Vector4f(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
            }

            Vertex[] vertices = new Vertex[vertexCount];

            for(int v=0;v<vertices.Length;++v)
            {
                vertices[v] = new Vertex(boneWeights[v], positions[v], normals[v], textureCoordinates[v], tangents[v]);
            }

            Vertices = new ImmutableArray<Vertex>(vertices);
        }
 public object[] Read7_checkSongExistsResponse() {
     Reader.MoveToContent();
     object[] p = new object[1];
     p[0] = new global::System.Boolean();
     Reader.MoveToContent();
     int whileIterations6 = 0;
     int readerCount6 = ReaderCount;
     while (Reader.NodeType == System.Xml.XmlNodeType.Element) {
         string root = Reader.GetAttribute("root", "http://schemas.xmlsoap.org/soap/encoding/");
         if (root == null || System.Xml.XmlConvert.ToBoolean(root)) break;
         ReadReferencedElement();
         Reader.MoveToContent();
         CheckReaderCount(ref whileIterations6, ref readerCount6);
     }
     bool isEmptyWrapper = Reader.IsEmptyElement;
     Reader.ReadStartElement();
     Fixup fixup = new Fixup(p, new System.Xml.Serialization.XmlSerializationFixupCallback(this.fixup_Read7_checkSongExistsResponse), 1);
     AddFixup(fixup);
     IsReturnValue = true;
     bool[] paramsRead = new bool[1];
     Reader.MoveToContent();
     int whileIterations7 = 0;
     int readerCount7 = ReaderCount;
     while (Reader.NodeType != System.Xml.XmlNodeType.EndElement && Reader.NodeType != System.Xml.XmlNodeType.None) {
         if (Reader.NodeType == System.Xml.XmlNodeType.Element) {
             if (!paramsRead[0] && (IsReturnValue || ((object) Reader.LocalName == (object)id13_return && (object) Reader.NamespaceURI == (object)id2_Item))) {
                 object rre = ReadReferencingElement(id11_boolean, id4_Item, out fixup.Ids[0]);
                 if (rre != null) {
                     try {
                         p[0] = (global::System.Boolean)rre;
                     }
                     catch (System.InvalidCastException) {
                         throw CreateInvalidCastException(typeof(global::System.Boolean), rre, null);
                     }
                     Referenced(p[0]);
                 }
                 IsReturnValue = false;
                 paramsRead[0] = true;
             }
             else {
                 UnknownNode((object)p);
             }
         }
         else {
             UnknownNode((object)p);
         }
         Reader.MoveToContent();
         CheckReaderCount(ref whileIterations7, ref readerCount7);
     }
     if (!isEmptyWrapper) ReadEndElement();
     ReadReferencedElements();
     return p;
 }
 /// <include file='doc\XmlSerializationReader.uex' path='docs/doc[@for="XmlSerializationReader.AddFixup"]/*' />
 protected void AddFixup(Fixup fixup) {
     if (fixups == null) fixups = new ArrayList();
     fixups.Add(fixup);
 }
Example #26
0
        object ReadArray() {
            string arrayType = r.GetAttribute(arrayTypeID, soapNsID);
            if (arrayType == null) return null;

            SoapArrayInfo arrayInfo = ParseArrayType(arrayType);

            if (arrayInfo.dimensions != 1) throw new InvalidOperationException(Res.GetString(Res.XmlInvalidArrayDimentions, CurrentTag()));

            //NOTE: don't use the array size that is specified since an evil client might pass
            // a number larger than the actual number of items in an attempt to harm the server. 

            XmlQualifiedName qname = ToXmlQualifiedName(arrayInfo.qname);
            
            bool isPrimitive;
            Type elementType = (Type)types[qname];
            if (elementType == null) {
                elementType = GetPrimitiveType(qname);
                isPrimitive = true;
            }
            else {
                isPrimitive = elementType.IsPrimitive;
            }

            if (arrayInfo.jaggedDimensions > 0) {
                // Unfortunately there's no way to create an array type given its
                // element type without actually creating the array.
                int[] dummyLengths = new int[arrayInfo.jaggedDimensions];
                Array dummyArray = Array.CreateInstance(elementType, dummyLengths);
                elementType = dummyArray.GetType();
            }

            r.ReadStartElement();
            r.MoveToContent();

            int arrayLength = 0;
            Array array = null;

            if (elementType.IsValueType) {
                if (!isPrimitive && !elementType.IsEnum) {
                    throw new NotSupportedException(Res.GetString(Res.XmlRpcArrayOfValueTypes, elementType.FullName));
                }
                while (r.NodeType != XmlNodeType.EndElement) {
                    array = EnsureArrayIndex(array, arrayLength, elementType);
                    array.SetValue(ReadReferencedElement(qname.Name, qname.Namespace), arrayLength);
                    arrayLength++;
                    r.MoveToContent();
                }
                array = ShrinkArray(array, arrayLength, elementType, false);
    
            }
            else {
                string type;
                string typens;
                string[] ids = null;
                int idsLength = 0;

                while (r.NodeType != XmlNodeType.EndElement) {
                    array = EnsureArrayIndex(array, arrayLength, elementType);
                    ids = (string[])EnsureArrayIndex(ids, idsLength, typeof(string));
                    if (r.NamespaceURI.Length != 0){
                        type = r.LocalName;
                        if ((object)r.NamespaceURI == (object)soapNsID)
                            typens = XmlSchema.Namespace;
                        else
                            typens = r.NamespaceURI;
                    }
                    else {
                        type = qname.Name;
                        typens = qname.Namespace;                        
                    }
                    array.SetValue(ReadReferencingElement(type, typens, out ids[idsLength]), arrayLength);
                    arrayLength++;
                    idsLength++;
                    // CONSIDER, erikc, sparse arrays, perhaps?
                    r.MoveToContent();
                }
                ids = (string[])ShrinkArray(ids, idsLength, typeof(string), false);
                array = ShrinkArray(array, arrayLength, elementType, false);
                Fixup fixupArray = new Fixup(array, new XmlSerializationFixupCallback(this.FixupArrayRefs), ids);
                AddFixup(fixupArray);
            }


            ReadEndElement();
            return array;
        }
Example #27
0
		protected void AddFixup (Fixup fixup)
		{
			fixups = EnsureArrayList (fixups);
			fixups.Add (fixup);
		}
Example #28
0
        void ReadMembers(ClassMap map, object ob, bool isValueList, bool readByOrder)
        {
            // Set the default values of the members
            if (map.MembersWithDefault != null)
            {
                ArrayList members = map.MembersWithDefault;
                for (int n = 0; n < members.Count; n++)
                {
                    XmlTypeMapMember mem = (XmlTypeMapMember)members[n];
                    SetMemberValueFromAttr(mem, ob, mem.DefaultValue, isValueList);
                }
            }

            // Reads attributes

            XmlTypeMapMember anyAttrMember = map.DefaultAnyAttributeMember;
            int    anyAttributeIndex       = 0;
            object anyAttributeArray       = null;

            while (Reader.MoveToNextAttribute())
            {
                XmlTypeMapMemberAttribute member = map.GetAttribute(Reader.LocalName, Reader.NamespaceURI);

                if (member != null)
                {
                    SetMemberValue(member, ob, GetValueFromXmlString(Reader.Value, member.TypeData, member.MappedType), isValueList);
                }
                else if (IsXmlnsAttribute(Reader.Name))
                {
                    // If the map has NamespaceDeclarations,
                    // then store this xmlns to the given member.
                    // If the instance doesn't exist, then create.
                    if (map.NamespaceDeclarations != null)
                    {
                        XmlSerializerNamespaces nss = this.GetMemberValue(map.NamespaceDeclarations, ob, isValueList) as XmlSerializerNamespaces;
                        if (nss == null)
                        {
                            nss = new XmlSerializerNamespaces();
                            SetMemberValue(map.NamespaceDeclarations, ob, nss, isValueList);
                        }
                        if (Reader.Prefix == "xmlns")
                        {
                            nss.Add(Reader.LocalName, Reader.Value);
                        }
                        else
                        {
                            nss.Add("", Reader.Value);
                        }
                    }
                }
                else if (anyAttrMember != null)
                {
                    XmlAttribute attr = (XmlAttribute)Document.ReadNode(Reader);
                    ParseWsdlArrayType(attr);
                    AddListValue(anyAttrMember.TypeData, ref anyAttributeArray, anyAttributeIndex++, attr, true);
                }
                else
                {
                    ProcessUnknownAttribute(ob);
                }
            }

            if (anyAttrMember != null)
            {
                anyAttributeArray = ShrinkArray((Array)anyAttributeArray, anyAttributeIndex, anyAttrMember.TypeData.Type.GetElementType(), true);
                SetMemberValue(anyAttrMember, ob, anyAttributeArray, isValueList);
            }

            if (!isValueList)
            {
                Reader.MoveToElement();
                if (Reader.IsEmptyElement)
                {
                    SetListMembersDefaults(map, ob, isValueList);
                    return;
                }

                Reader.ReadStartElement();
            }

            // Reads elements

            bool[] readFlag = new bool[(map.ElementMembers != null) ? map.ElementMembers.Count : 0];

            bool hasAnyReturnMember = (isValueList && _format == SerializationFormat.Encoded && map.ReturnMember != null);

            Reader.MoveToContent();

            int[]    indexes          = null;
            object[] flatLists        = null;
            object[] flatListsChoices = null;
            Fixup    fixup            = null;
            int      ind = 0;
            int      maxInd;

            if (readByOrder)
            {
                if (map.ElementMembers != null)
                {
                    maxInd = map.ElementMembers.Count;
                }
                else
                {
                    maxInd = 0;
                }
            }
            else
            {
                maxInd = int.MaxValue;
            }

            if (map.FlatLists != null)
            {
                indexes   = new int[map.FlatLists.Count];
                flatLists = new object[map.FlatLists.Count];
                foreach (XmlTypeMapMemberExpandable mem in map.FlatLists)
                {
                    if (IsReadOnly(mem, mem.TypeData, ob, isValueList))
                    {
                        flatLists[mem.FlatArrayIndex] = mem.GetValue(ob);
                    }
                    else if (mem.TypeData.Type.IsArray)
                    {
                        flatLists[mem.FlatArrayIndex] = InitializeList(mem.TypeData);
                    }
                    else
                    {
                        object list = mem.GetValue(ob);
                        if (list == null)
                        {
                            list = InitializeList(mem.TypeData);
                            SetMemberValue(mem, ob, list, isValueList);
                        }
                        flatLists[mem.FlatArrayIndex] = list;
                    }

                    if (mem.ChoiceMember != null)
                    {
                        if (flatListsChoices == null)
                        {
                            flatListsChoices = new object[map.FlatLists.Count];
                        }
                        flatListsChoices[mem.FlatArrayIndex] = InitializeList(mem.ChoiceTypeData);
                    }
                }
            }

            if (_format == SerializationFormat.Encoded && map.ElementMembers != null)
            {
                FixupCallbackInfo info = new FixupCallbackInfo(this, map, isValueList);
                fixup = new Fixup(ob, new XmlSerializationFixupCallback(info.FixupMembers), map.ElementMembers.Count);
                AddFixup(fixup);
            }

            while (Reader.NodeType != System.Xml.XmlNodeType.EndElement && (ind < maxInd))
            {
                if (Reader.NodeType == System.Xml.XmlNodeType.Element)
                {
                    XmlTypeMapElementInfo info;

                    if (readByOrder)
                    {
                        info = map.GetElement(ind++);
                    }
                    else if (hasAnyReturnMember)
                    {
                        info = (XmlTypeMapElementInfo)((XmlTypeMapMemberElement)map.ReturnMember).ElementInfo[0];
                        hasAnyReturnMember = false;
                    }
                    else
                    {
                        info = map.GetElement(Reader.LocalName, Reader.NamespaceURI);
                    }

                    if (info != null && !readFlag[info.Member.Index])
                    {
                        if (info.Member.GetType() == typeof(XmlTypeMapMemberList))
                        {
                            if (_format == SerializationFormat.Encoded && info.MultiReferenceType)
                            {
                                object list = ReadReferencingElement(out fixup.Ids[info.Member.Index]);
                                if (fixup.Ids[info.Member.Index] == null)       // Already read
                                {
                                    if (IsReadOnly(info.Member, info.TypeData, ob, isValueList))
                                    {
                                        throw CreateReadOnlyCollectionException(info.TypeData.FullTypeName);
                                    }
                                    else
                                    {
                                        SetMemberValue(info.Member, ob, list, isValueList);
                                    }
                                }
                                else if (!info.MappedType.TypeData.Type.IsArray)
                                {
                                    if (IsReadOnly(info.Member, info.TypeData, ob, isValueList))
                                    {
                                        list = GetMemberValue(info.Member, ob, isValueList);
                                    }
                                    else
                                    {
                                        list = CreateList(info.MappedType.TypeData.Type);
                                        SetMemberValue(info.Member, ob, list, isValueList);
                                    }
                                    AddFixup(new CollectionFixup(list, new XmlSerializationCollectionFixupCallback(FillList), fixup.Ids[info.Member.Index]));
                                    fixup.Ids[info.Member.Index] = null;        // The member already has the value, no further fix needed.
                                }
                            }
                            else
                            {
                                if (IsReadOnly(info.Member, info.TypeData, ob, isValueList))
                                {
                                    ReadListElement(info.MappedType, info.IsNullable, GetMemberValue(info.Member, ob, isValueList), false);
                                }
                                else if (info.MappedType.TypeData.Type.IsArray)
                                {
                                    object list = ReadListElement(info.MappedType, info.IsNullable, null, true);
                                    if (list != null || info.IsNullable)
                                    {
                                        SetMemberValue(info.Member, ob, list, isValueList);
                                    }
                                }
                                else
                                {
                                    // If the member already has a list, reuse that list. No need to create a new one.
                                    object list = GetMemberValue(info.Member, ob, isValueList);
                                    if (list == null)
                                    {
                                        list = CreateList(info.MappedType.TypeData.Type);
                                        SetMemberValue(info.Member, ob, list, isValueList);
                                    }
                                    ReadListElement(info.MappedType, info.IsNullable, list, true);
                                }
                            }
                            readFlag[info.Member.Index] = true;
                        }
                        else if (info.Member.GetType() == typeof(XmlTypeMapMemberFlatList))
                        {
                            XmlTypeMapMemberFlatList mem = (XmlTypeMapMemberFlatList)info.Member;
                            AddListValue(mem.TypeData, ref flatLists[mem.FlatArrayIndex], indexes[mem.FlatArrayIndex]++, ReadObjectElement(info), !IsReadOnly(info.Member, info.TypeData, ob, isValueList));
                            if (mem.ChoiceMember != null)
                            {
                                AddListValue(mem.ChoiceTypeData, ref flatListsChoices[mem.FlatArrayIndex], indexes[mem.FlatArrayIndex] - 1, info.ChoiceValue, true);
                            }
                        }
                        else if (info.Member.GetType() == typeof(XmlTypeMapMemberAnyElement))
                        {
                            XmlTypeMapMemberAnyElement mem = (XmlTypeMapMemberAnyElement)info.Member;
                            if (mem.TypeData.IsListType)
                            {
                                AddListValue(mem.TypeData, ref flatLists[mem.FlatArrayIndex], indexes[mem.FlatArrayIndex]++, ReadXmlNode(mem.TypeData.ListItemTypeData, false), true);
                            }
                            else
                            {
                                SetMemberValue(mem, ob, ReadXmlNode(mem.TypeData, false), isValueList);
                            }
                        }
                        else if (info.Member.GetType() == typeof(XmlTypeMapMemberElement))
                        {
                            object val;
                            readFlag[info.Member.Index] = true;
                            if (_format == SerializationFormat.Encoded)
                            {
                                if (info.Member.TypeData.SchemaType != SchemaTypes.Primitive)
                                {
                                    val = ReadReferencingElement(out fixup.Ids[info.Member.Index]);
                                }
                                else
                                {
                                    val = ReadReferencingElement(info.Member.TypeData.XmlType, System.Xml.Schema.XmlSchema.Namespace, out fixup.Ids[info.Member.Index]);
                                }

                                if (info.MultiReferenceType)
                                {
                                    if (fixup.Ids[info.Member.Index] == null)   // already read
                                    {
                                        SetMemberValue(info.Member, ob, val, isValueList);
                                    }
                                }
                                else if (val != null)
                                {
                                    SetMemberValue(info.Member, ob, val, isValueList);
                                }
                            }
                            else
                            {
                                SetMemberValue(info.Member, ob, ReadObjectElement(info), isValueList);
                                if (info.ChoiceValue != null)
                                {
                                    XmlTypeMapMemberElement imem = (XmlTypeMapMemberElement)info.Member;
                                    imem.SetChoice(ob, info.ChoiceValue);
                                }
                            }
                        }
                        else
                        {
                            throw new InvalidOperationException("Unknown member type");
                        }
                    }
                    else if (map.DefaultAnyElementMember != null)
                    {
                        XmlTypeMapMemberAnyElement mem = map.DefaultAnyElementMember;
                        if (mem.TypeData.IsListType)
                        {
                            AddListValue(mem.TypeData, ref flatLists[mem.FlatArrayIndex], indexes[mem.FlatArrayIndex]++, ReadXmlNode(mem.TypeData.ListItemTypeData, false), true);
                        }
                        else
                        {
                            SetMemberValue(mem, ob, ReadXmlNode(mem.TypeData, false), isValueList);
                        }
                    }
                    else
                    {
                        ProcessUnknownElement(ob);
                    }
                }
                else if ((Reader.NodeType == System.Xml.XmlNodeType.Text || Reader.NodeType == System.Xml.XmlNodeType.CDATA) && map.XmlTextCollector != null)
                {
                    if (map.XmlTextCollector is XmlTypeMapMemberExpandable)
                    {
                        XmlTypeMapMemberExpandable mem   = (XmlTypeMapMemberExpandable)map.XmlTextCollector;
                        XmlTypeMapMemberFlatList   flatl = mem as XmlTypeMapMemberFlatList;
                        TypeData itype = (flatl == null) ? mem.TypeData.ListItemTypeData : flatl.ListMap.FindTextElement().TypeData;

                        object val = (itype.Type == typeof(string)) ? (object)Reader.ReadString() : (object)ReadXmlNode(itype, false);
                        AddListValue(mem.TypeData, ref flatLists[mem.FlatArrayIndex], indexes[mem.FlatArrayIndex]++, val, true);
                    }
                    else
                    {
                        XmlTypeMapMemberElement mem  = (XmlTypeMapMemberElement)map.XmlTextCollector;
                        XmlTypeMapElementInfo   info = (XmlTypeMapElementInfo)mem.ElementInfo[0];
                        if (info.TypeData.Type == typeof(string))
                        {
                            SetMemberValue(mem, ob, ReadString((string)GetMemberValue(mem, ob, isValueList)), isValueList);
                        }
                        else
                        {
                            SetMemberValue(mem, ob, GetValueFromXmlString(Reader.ReadString(), info.TypeData, info.MappedType), isValueList);
                        }
                    }
                }
                else
                {
                    UnknownNode(ob);
                }

                Reader.MoveToContent();
            }

            if (flatLists != null)
            {
                foreach (XmlTypeMapMemberExpandable mem in map.FlatLists)
                {
                    Object list = flatLists[mem.FlatArrayIndex];
                    if (mem.TypeData.Type.IsArray)
                    {
                        list = ShrinkArray((Array)list, indexes[mem.FlatArrayIndex], mem.TypeData.Type.GetElementType(), true);
                    }
                    if (!IsReadOnly(mem, mem.TypeData, ob, isValueList) && mem.TypeData.Type.IsArray)
                    {
                        SetMemberValue(mem, ob, list, isValueList);
                    }
                }
            }

            if (flatListsChoices != null)
            {
                foreach (XmlTypeMapMemberExpandable mem in map.FlatLists)
                {
                    Object list = flatListsChoices[mem.FlatArrayIndex];
                    if (list == null)
                    {
                        continue;
                    }
                    list = ShrinkArray((Array)list, indexes[mem.FlatArrayIndex], mem.ChoiceTypeData.Type.GetElementType(), true);
                    XmlTypeMapMember.SetValue(ob, mem.ChoiceMember, list);
                }
            }
            SetListMembersDefaults(map, ob, isValueList);
        }