Пример #1
0
        /// <summary>
        ///     Handles an element which describes how a value
        ///     should be read from the cache file.
        /// </summary>
        /// <param name="reader">The XmlReader that read the element.</param>
        /// <param name="elementName">The element's name.</param>
        /// <param name="visitor">The IPluginVisitor to call to.</param>
        private static void HandleValueElement(XmlReader reader, string elementName, IPluginVisitor visitor)
        {
            string name        = "Unknown";
            uint   offset      = 0;
            var    xmlLineInfo = reader as IXmlLineInfo;

            if (xmlLineInfo == null)
            {
                return;
            }
            var    pluginLine = (uint)xmlLineInfo.LineNumber;
            bool   visible    = true;
            string tooltip    = "";

            if (reader.MoveToAttribute("name"))
            {
                name = reader.Value;
            }
            if (reader.MoveToAttribute("offset"))
            {
                offset = ParseUInt(reader.Value);
            }
            if (reader.MoveToAttribute("visible"))
            {
                visible = ParseBool(reader.Value);
            }
            if (reader.MoveToAttribute("tooltip"))
            {
                tooltip = reader.Value;
            }

            reader.MoveToElement();
            switch (elementName.ToLower())             // FIXME: Using ToLower() here violates XML standards
            {
            case "uint8":
                visitor.VisitUInt8(name, offset, visible, pluginLine, tooltip);
                break;

            case "int8":
                visitor.VisitInt8(name, offset, visible, pluginLine, tooltip);
                break;

            case "uint16":
                visitor.VisitUInt16(name, offset, visible, pluginLine, tooltip);
                break;

            case "int16":
                visitor.VisitInt16(name, offset, visible, pluginLine, tooltip);
                break;

            case "uint32":
                visitor.VisitUInt32(name, offset, visible, pluginLine, tooltip);
                break;

            case "int32":
                visitor.VisitInt32(name, offset, visible, pluginLine, tooltip);
                break;

            case "uint64":
                visitor.VisitUInt64(name, offset, visible, pluginLine, tooltip);
                break;

            case "int64":
                visitor.VisitInt64(name, offset, visible, pluginLine, tooltip);
                break;

            case "float32":
            case "float":
                visitor.VisitFloat32(name, offset, visible, pluginLine, tooltip);
                break;

            case "undefined":
                visitor.VisitUndefined(name, offset, visible, pluginLine, tooltip);
                break;

            case "point2":
                visitor.VisitPoint2(name, offset, visible, pluginLine, tooltip);
                break;

            case "point3":
                visitor.VisitPoint3(name, offset, visible, pluginLine, tooltip);
                break;

            case "vector2":
                visitor.VisitVector2(name, offset, visible, pluginLine, tooltip);
                break;

            case "vector3":
                visitor.VisitVector3(name, offset, visible, pluginLine, tooltip);
                break;

            case "vector4":
            case "quaternion":
                visitor.VisitVector4(name, offset, visible, pluginLine, tooltip);
                break;

            case "degree":
                visitor.VisitDegree(name, offset, visible, pluginLine, tooltip);
                break;

            case "degree2":
                visitor.VisitDegree2(name, offset, visible, pluginLine, tooltip);
                break;

            case "degree3":
                visitor.VisitDegree3(name, offset, visible, pluginLine, tooltip);
                break;

            case "plane2":
                visitor.VisitPlane2(name, offset, visible, pluginLine, tooltip);
                break;

            case "plane3":
                visitor.VisitPlane3(name, offset, visible, pluginLine, tooltip);
                break;

            case "rect16":
                visitor.VisitRect16(name, offset, visible, pluginLine, tooltip);
                break;

            case "quat16":
                visitor.VisitQuat16(name, offset, visible, pluginLine, tooltip);
                break;

            case "point16":
                visitor.VisitPoint16(name, offset, visible, pluginLine, tooltip);
                break;

            case "stringid":
                visitor.VisitStringID(name, offset, visible, pluginLine, tooltip);
                break;

            case "tagref":
                ReadTagRef(reader, name, offset, visible, visitor, pluginLine, tooltip);
                break;

            case "ascii":
                ReadAscii(reader, name, offset, visible, visitor, pluginLine, tooltip);
                break;

            case "utf16":
                ReadUtf16(reader, name, offset, visible, visitor, pluginLine, tooltip);
                break;

            case "flags8":
            case "bitfield8":
                if (visitor.EnterFlags8(name, offset, visible, pluginLine, tooltip))
                {
                    ReadBits(reader, visitor);
                }
                else
                {
                    reader.Skip();
                }
                break;

            case "flags16":
            case "bitfield16":
                if (visitor.EnterFlags16(name, offset, visible, pluginLine, tooltip))
                {
                    ReadBits(reader, visitor);
                }
                else
                {
                    reader.Skip();
                }
                break;

            case "flags32":
            case "bitfield32":
                if (visitor.EnterFlags32(name, offset, visible, pluginLine, tooltip))
                {
                    ReadBits(reader, visitor);
                }
                else
                {
                    reader.Skip();
                }
                break;

            case "flags64":
            case "bitfield64":
                if (visitor.EnterFlags64(name, offset, visible, pluginLine, tooltip))
                {
                    ReadBits(reader, visitor);
                }
                else
                {
                    reader.Skip();
                }
                break;

            case "enum8":
                if (visitor.EnterEnum8(name, offset, visible, pluginLine, tooltip))
                {
                    ReadOptions(reader, visitor);
                }
                else
                {
                    reader.Skip();
                }
                break;

            case "enum16":
                if (visitor.EnterEnum16(name, offset, visible, pluginLine, tooltip))
                {
                    ReadOptions(reader, visitor);
                }
                else
                {
                    reader.Skip();
                }
                break;

            case "enum32":
                if (visitor.EnterEnum32(name, offset, visible, pluginLine, tooltip))
                {
                    ReadOptions(reader, visitor);
                }
                else
                {
                    reader.Skip();
                }
                break;

            case "color":
            case "color32":
                visitor.VisitColorInt(name, offset, visible, ReadColorAlpha(reader), pluginLine, tooltip);
                break;

            case "colorf":
                visitor.VisitColorF(name, offset, visible, ReadColorAlpha(reader), pluginLine, tooltip);
                break;

            case "dataref":
                ReadDataRef(reader, name, offset, visible, visitor, pluginLine, tooltip);
                break;

            case "reflexive":
            case "tagblock":
                ReadTagBlock(reader, name, offset, visible, visitor, pluginLine, tooltip);
                break;

            case "raw":
                ReadRaw(reader, name, offset, visible, visitor, pluginLine, tooltip);
                break;

            case "shader":
                ReadShader(reader, name, offset, visible, visitor, pluginLine, tooltip);
                break;

            case "uniclist":
                ReadUnicList(reader, name, offset, visible, visitor, pluginLine, tooltip);
                break;

            case "range16":
                visitor.VisitRangeInt16(name, offset, visible, pluginLine, tooltip);
                break;

            case "rangef":
                visitor.VisitRangeFloat32(name, offset, visible, pluginLine, tooltip);
                break;

            case "ranged":
                visitor.VisitRangeDegree(name, offset, visible, pluginLine, tooltip);
                break;

            case "datum":
                visitor.VisitDatum(name, offset, visible, pluginLine, tooltip);
                break;

            default:
                throw new ArgumentException("Unknown element \"" + elementName + "\"." + PositionInfo(reader));
            }
        }
Пример #2
0
        /// <summary>
        ///     Handles an element which describes how a value
        ///     should be read from the cache file.
        /// </summary>
        /// <param name="reader">The XmlReader that read the element.</param>
        /// <param name="elementName">The element's name.</param>
        /// <param name="visitor">The IPluginVisitor to call to.</param>
        private void HandleValueElement(XmlReader reader, string elementName, IPluginVisitor visitor)
        {
            string name       = "Unknown";
            uint   offset     = 0;
            var    pluginLine = (uint)(reader as IXmlLineInfo).LineNumber;
            bool   visible    = true;
            string tooltip    = "";

            if (reader.MoveToAttribute("name"))
            {
                name = reader.Value;
            }
            if (reader.MoveToAttribute("offset"))
            {
                offset = ParseUInt(reader.Value);
            }
            if (reader.MoveToAttribute("visible"))
            {
                visible = ParseBool(reader.Value);
            }
            if (reader.MoveToAttribute("tooltip"))
            {
                visible = ParseBool(reader.Value);
            }

            reader.MoveToElement();
            switch (elementName.ToLower())
            {
            case "uint8":
            case "byte":
                visitor.VisitUInt8(name, offset, visible, pluginLine, tooltip);
                break;

            case "sbyte":
            case "int8":
                visitor.VisitInt8(name, offset, visible, pluginLine, tooltip);
                break;

            case "ushort":
            case "uint16":
                visitor.VisitUInt16(name, offset, visible, pluginLine, tooltip);
                break;

            case "short":
            case "int16":
                visitor.VisitInt16(name, offset, visible, pluginLine, tooltip);
                break;

            case "dword":
            case "uint":
            case "uint32":
            case "long":
            case "true":
                visitor.VisitUInt32(name, offset, visible, pluginLine, tooltip);
                break;

            case "int":
            case "int32":
                visitor.VisitInt32(name, offset, visible, pluginLine, tooltip);
                break;

            case "int64":
                visitor.VisitInt64(name, offset, visible, pluginLine, tooltip);
                break;

            case "uint64":
                visitor.VisitUInt64(name, offset, visible, pluginLine, tooltip);
                break;

            case "undefined":
            case "unknown":
                visitor.VisitUndefined(name, offset, visible, pluginLine, tooltip);
                break;

            case "float":
            case "float32":
            case "degree":
                visitor.VisitFloat32(name, offset, visible, pluginLine, tooltip);
                break;

            case "point2":
                visitor.VisitPoint2(name, offset, visible, pluginLine, tooltip);
                break;

            case "point3":
                visitor.VisitPoint3(name, offset, visible, pluginLine, tooltip);
                break;

            case "vector2":
                visitor.VisitVector2(name, offset, visible, pluginLine, tooltip);
                break;

            case "vector3":
                visitor.VisitVector3(name, offset, visible, pluginLine, tooltip);
                break;

            case "vector4":
            case "quaternion":
                visitor.VisitVector4(name, offset, visible, pluginLine, tooltip);
                break;

            case "degree2":
                visitor.VisitDegree2(name, offset, visible, pluginLine, tooltip);
                break;

            case "degree3":
                visitor.VisitDegree3(name, offset, visible, pluginLine, tooltip);
                break;

            case "plane2":
                visitor.VisitPlane2(name, offset, visible, pluginLine, tooltip);
                break;

            case "plane3":
                visitor.VisitPlane3(name, offset, visible, pluginLine, tooltip);
                break;

            case "rect16":
                visitor.VisitRect16(name, offset, visible, pluginLine, tooltip);
                break;

            case "quat16":
                visitor.VisitQuat16(name, offset, visible, pluginLine, tooltip);
                break;

            case "point16":
                visitor.VisitPoint16(name, offset, visible, pluginLine, tooltip);
                break;

            case "stringid":
                visitor.VisitStringID(name, offset, visible, pluginLine, tooltip);
                break;

            case "tag":
            case "tagid":
            case "tagref":
            case "ident":
                ReadTagRef(reader, name, offset, visible, visitor, pluginLine, tooltip);
                break;

            case "string":
            case "ascii":
                ReadAscii(reader, name, offset, visible, visitor, pluginLine, tooltip);
                break;

            case "string32":
                visitor.VisitAscii(name, offset, visible, 32, pluginLine, tooltip);
                break;

            case "string64":
                visitor.VisitAscii(name, offset, visible, 64, pluginLine, tooltip);
                break;

            case "string256":
                visitor.VisitAscii(name, offset, visible, 256, pluginLine, tooltip);
                break;

            case "unicode":
            case "utf16":
                ReadUtf16(reader, name, offset, visible, visitor, pluginLine, tooltip);
                break;

            case "unicode32":
                visitor.VisitUtf16(name, offset, visible, 32, pluginLine, tooltip);
                break;

            case "unicode64":
                visitor.VisitUtf16(name, offset, visible, 64, pluginLine, tooltip);
                break;

            case "unicode256":
                visitor.VisitUtf16(name, offset, visible, 256, pluginLine, tooltip);
                break;

            case "flags8":
            case "bitfield8":
            case "bitmask8":
                if (visitor.EnterFlags8(name, offset, visible, pluginLine, tooltip))
                {
                    ReadBits(reader, visitor);
                }
                break;

            case "flags16":
            case "bitmask16":
            case "bitfield16":
                if (visitor.EnterFlags16(name, offset, visible, pluginLine, tooltip))
                {
                    ReadBits(reader, visitor);
                }
                break;

            case "flags32":
            case "bitmask32":
            case "bitfield32":
                if (visitor.EnterFlags32(name, offset, visible, pluginLine, tooltip))
                {
                    ReadBits(reader, visitor);
                }
                break;

            case "flags64":
            case "bitmask64":
            case "bitfield64":
                if (visitor.EnterFlags64(name, offset, visible, pluginLine, tooltip))
                {
                    ReadBits(reader, visitor);
                }
                break;

            case "enum8":
                if (visitor.EnterEnum8(name, offset, visible, pluginLine, tooltip))
                {
                    ReadOptions(reader, visitor);
                }
                break;

            case "enum16":
                if (visitor.EnterEnum16(name, offset, visible, pluginLine, tooltip))
                {
                    ReadOptions(reader, visitor);
                }
                break;

            case "enum32":
                if (visitor.EnterEnum32(name, offset, visible, pluginLine, tooltip))
                {
                    ReadOptions(reader, visitor);
                }
                break;

            case "tagdata":
            case "dataref":
                ReadDataRef(reader, name, offset, visible, visitor, pluginLine, tooltip);
                break;

            case "struct":
            case "reflexive":
            case "reflexives":
            case "tagblock":
                ReadTagBlock(reader, name, offset, visible, visitor, pluginLine, tooltip);
                break;

            case "bytearray":
            case "raw":
                ReadRaw(reader, name, offset, visible, visitor, pluginLine, tooltip);
                break;

            case "shader":
                ReadShader(reader, name, offset, visible, visitor, pluginLine, tooltip);
                break;

            case "uniclist":
                ReadUnicList(reader, name, offset, visible, visitor, pluginLine, tooltip);
                break;

            case "color32":
                visitor.VisitColorInt(name, offset, visible, ReadColorAlpha(reader), pluginLine, tooltip);
                break;

            case "colorf":
                visitor.VisitColorF(name, offset, visible, ReadColorAlpha(reader), pluginLine, tooltip);
                break;

            case "id":
                // Group ID, part of a tag reference
                break;

            case "unused":
            case "unusued":
            case "ununused":
                // Do nothing, I really don't understand the point of this
                break;

            case "datum":
                visitor.VisitDatum(name, offset, visible, pluginLine, tooltip);
                break;

            case "range16":
                visitor.VisitRangeInt16(name, offset, visible, pluginLine, tooltip);
                break;

            case "rangef":
                visitor.VisitRangeFloat32(name, offset, visible, pluginLine, tooltip);
                break;

            case "ranged":
                visitor.VisitRangeDegree(name, offset, visible, pluginLine, tooltip);
                break;


            default:
                throw new ArgumentException("Unknown element \"" + elementName + "\"." + PositionInfo(reader));
            }
        }