private static void ReadPackedInt(XmlReader reader, IPluginVisitor visitor) { string name = "Unknown"; if (reader.MoveToAttribute("name")) { name = reader.Value; } if (!reader.MoveToAttribute("offset")) { throw new ArgumentException("Packed int definitions must have an offset." + PositionInfo(reader)); } int offset = ParseInt(reader.Value); if (!reader.MoveToAttribute("count")) { throw new ArgumentException("Packed int definitions must have an count." + PositionInfo(reader)); } int count = ParseInt(reader.Value); bool signed = false; if (reader.MoveToAttribute("signed")) { signed = ParseBool(reader.Value); } visitor.VisitPackedInt(name, offset, count, signed); }
private void WritePlugin(MetaMap map, int size, IPluginVisitor writer) { for (int offset = 0; offset < size; offset += 4) { MetaValueGuess guess = map.GetGuess(offset); if (guess != null) { switch (guess.Type) { case MetaValueType.DataReference: if (offset <= size - 0x14) { writer.VisitDataReference("Unknown", (uint)offset, "bytes", false, 4, 0); offset += 0x10; continue; } break; case MetaValueType.TagReference: if (offset <= size - 0x10) { writer.VisitTagReference("Unknown", (uint)offset, false, true, true, 0); offset += 0xC; continue; } break; case MetaValueType.Reflexive: if (offset <= size - 0xC) { MetaMap subMap = map.GetSubMap(offset); if (subMap != null) { int subMapSize = subMap.GetBestSizeEstimate(); writer.EnterReflexive("Unknown", (uint)offset, false, (uint)subMapSize, 4, 0); WritePlugin(subMap, subMapSize, writer); writer.LeaveReflexive(); offset += 0x8; continue; } } break; } } // Just write an unknown value depending upon how much space we have left if (offset <= size - 4) { writer.VisitUndefined("Unknown", (uint)offset, false, 0); } else if (offset <= size - 2) { writer.VisitInt16("Unknown", (uint)offset, false, 0); } else { writer.VisitInt8("Unknown", (uint)offset, false, 0); } } }
private static void ReadRevisions(XmlReader reader, IPluginVisitor visitor) { reader.ReadStartElement(); while (reader.ReadToFollowing("revision")) { visitor.VisitRevision(ReadRevision(reader)); } }
private static void ReadAscii(XmlReader reader, string name, uint offset, bool visible, IPluginVisitor visitor, uint pluginLine) { int length = 0; if (reader.MoveToAttribute("length")) length = ParseInt(reader.Value); visitor.VisitAscii(name, offset, visible, length, pluginLine); }
private static void ReadBits(XmlReader reader, IPluginVisitor visitor) { XmlReader subtree = reader.ReadSubtree(); subtree.ReadStartElement(); while (subtree.ReadToNextSibling("bit")) ReadBit(subtree, visitor); visitor.LeaveFlags(); }
private static void ReadOptions(XmlReader reader, IPluginVisitor visitor) { XmlReader subtree = reader.ReadSubtree(); subtree.ReadStartElement(); while (subtree.ReadToNextSibling("option")) ReadOption(subtree, visitor); visitor.LeaveEnum(); }
private static void ReadElements(XmlReader reader, bool topLevel, IPluginVisitor visitor) { while (reader.Read()) { if (reader.NodeType != XmlNodeType.Element) continue; if (topLevel) HandleTopLevelElement(reader, visitor); else HandleElement(reader, visitor); } }
private static void HandleElement(XmlReader reader, IPluginVisitor visitor) { switch (reader.Name) { case "comment": ReadComment(reader, visitor); break; default: HandleValueElement(reader, reader.Name, visitor); break; } }
private static void ReadPackedInts(XmlReader reader, IPluginVisitor visitor) { XmlReader subtree = reader.ReadSubtree(); subtree.ReadStartElement(); while (subtree.ReadToNextSibling("int")) { ReadPackedInt(subtree, visitor); } visitor.LeavePackedInt(); }
private static void HandleTopLevelElement(XmlReader reader, IPluginVisitor visitor) { if (reader.Name == "revisions" && visitor.EnterRevisions()) { ReadRevisions(reader.ReadSubtree(), visitor); visitor.LeaveRevisions(); } else { HandleElement(reader, visitor); } }
/// <summary> /// Parses an XML plugin, calling the corresponding method in /// IPluginVisitor for each XML tag it encounters. /// </summary> /// <param name="reader">The XmlReader to read the plugin XML from.</param> /// <param name="visitor">The IPluginVisitor to call for each XML tag.</param> public static void LoadPlugin(XmlReader reader, IPluginVisitor visitor) { if (!reader.ReadToNextSibling("plugin")) throw new ArgumentException("The XML file is missing a <plugin> tag."); var baseSize = 0; if (reader.MoveToAttribute("baseSize")) baseSize = ParseInt(reader.Value); if (!visitor.EnterPlugin(baseSize)) return; ReadElements(reader, true, visitor); visitor.LeavePlugin(); }
/// <summary> /// Parses an XML plugin, calling the corresponding method in /// IPluginVisitor for each XML tag it encounters. /// </summary> /// <param name="reader">The XmlReader to read the plugin XML from.</param> /// <param name="visitor">The IPluginVisitor to call for each XML tag.</param> public static void LoadPlugin(XmlReader reader, IPluginVisitor visitor) { if (!reader.ReadToNextSibling("plugin")) throw new ArgumentException("The XML file is missing a <plugin> tag."); int baseSize = 0; if (reader.MoveToAttribute("baseSize")) baseSize = ParseInt(reader.Value); if (!visitor.EnterPlugin(baseSize)) return; ReadElements(reader, true, visitor); visitor.LeavePlugin(); }
private static void ReadComment(XmlReader reader, IPluginVisitor visitor) { string title = "Comment"; if (reader.MoveToAttribute("title")) title = reader.Value; reader.MoveToElement(); var xmlLineInfo = reader as IXmlLineInfo; if (xmlLineInfo == null) return; var pluginLine = (uint) xmlLineInfo.LineNumber; string text = reader.ReadElementContentAsString(); visitor.VisitComment(title, text, pluginLine); }
private static void ReadBit(XmlReader reader, IPluginVisitor visitor) { string name = "Unknown"; string tooltip = ""; if (reader.MoveToAttribute("name")) name = reader.Value; if (!reader.MoveToAttribute("index")) throw new ArgumentException("Bit definitions must have an index." + PositionInfo(reader)); int index = ParseInt(reader.Value); if (reader.MoveToAttribute("tooltip")) tooltip = reader.Value; visitor.VisitBit(name, index, tooltip); }
private void ReadComment(XmlReader reader, IPluginVisitor visitor) { string title = "Comment"; if (reader.MoveToAttribute("title")) { title = reader.Value; } reader.MoveToElement(); var pluginLine = (uint)(reader as IXmlLineInfo).LineNumber; string text = reader.ReadElementContentAsString(); visitor.VisitComment(title, text, pluginLine); }
private static void ReadOption(XmlReader reader, IPluginVisitor visitor) { string name = "Unknown"; int value = 0; string tooltip = ""; if (reader.MoveToAttribute("name")) name = reader.Value; if (reader.MoveToAttribute("value")) value = ParseInt(reader.Value); if (reader.MoveToAttribute("tooltip")) tooltip = reader.Value; visitor.VisitOption(name, value, tooltip); }
private void HandleTopLevelElement(XmlReader reader, string elementName, IPluginVisitor visitor) { if (elementName == "revisions") { ReadRevisions(reader.ReadSubtree()); } else if (elementName == "revision") { ReadRevision(reader); } else { HandleElement(reader, elementName, visitor); } }
/// <summary> /// Parses an XML plugin, calling the corresponding method in /// IPluginVisitor for each XML tag it encounters. /// </summary> /// <param name="reader">The XmlReader to read the plugin XML from.</param> /// <param name="visitor">The IPluginVisitor to call for each XML tag.</param> public static void LoadPlugin(XmlReader reader, IPluginVisitor visitor) { if (!reader.ReadToNextSibling("plugin")) throw new ArgumentException("The XML file is missing a <plugin> tag."); if (!reader.MoveToAttribute("baseSize")) throw new ArgumentException("The <plugin> tag is missing the baseSize attribute." + PositionInfo(reader)); int baseSize = ParseInt(reader.Value); if (visitor.EnterPlugin(baseSize)) { ReadElements(reader, true, visitor); visitor.LeavePlugin(); } }
private static void ReadOption(XmlReader reader, IPluginVisitor visitor) { string name = "Unknown"; int value = 0; if (reader.MoveToAttribute("name")) { name = reader.Value; } if (reader.MoveToAttribute("value")) { value = ParseInt(reader.Value); } visitor.VisitOption(name, value); }
/// <summary> /// Parses an XML plugin, calling the corresponding method in /// IPluginVisitor for each XML tag it encounters. /// </summary> /// <param name="reader">The XmlReader to read the plugin XML from.</param> /// <param name="visitor">The IPluginVisitor to call for each XML tag.</param> public static void LoadPlugin(XmlReader reader, IPluginVisitor visitor) { if (!reader.ReadToNextSibling("plugin")) throw new ArgumentException("The XML file is missing a <plugin> tag."); if (!reader.MoveToAttribute("headersize") && !reader.MoveToAttribute("baseSize")) throw new ArgumentException("The plugin is missing tag size information."); int baseSize = ParseInt(reader.Value); if (visitor.EnterPlugin(baseSize)) { UniversalPluginLoader loader = new UniversalPluginLoader(); loader.ReadElements(reader, true, visitor); visitor.LeavePlugin(); } }
private static void ReadBit(XmlReader reader, IPluginVisitor visitor) { string name = "Unknown"; int index = 0; if (reader.MoveToAttribute("name")) { name = reader.Value; } if (!reader.MoveToAttribute("index") && !reader.MoveToAttribute("value")) { throw new ArgumentException("Bit definitions must have an index" + PositionInfo(reader)); } index = ParseInt(reader.Value); visitor.VisitBit(name, index); }
// Fixes up the version numbers on revisions private void DumpRevisions(IPluginVisitor visitor) { if (visitor.EnterRevisions()) { // Dump ALL the revisions! int version = versionBase; foreach (var pair in revisions) { pair.Value.Version = version; version++; visitor.VisitRevision(pair.Value); } versionBase = version; visitor.LeaveRevisions(); } }
private void ReadElements(XmlReader reader, bool topLevel, IPluginVisitor visitor) { while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { string elementName = reader.Name.ToLower(); if (topLevel) { HandleTopLevelElement(reader, elementName, visitor); } else { HandleElement(reader, elementName, visitor); } } } }
private void HandleElement(XmlReader reader, string elementName, IPluginVisitor visitor) { if (revisions.Count > 0) { DumpRevisions(visitor); revisions.Clear(); } switch (elementName) { case "comment": ReadComment(reader, visitor); break; default: HandleValueElement(reader, elementName, visitor); break; } }
private static void HandleTopLevelElement(XmlReader reader, IPluginVisitor visitor) { if (reader.Name == "revisions") { if (visitor.EnterRevisions()) { ReadRevisions(reader.ReadSubtree(), visitor); visitor.LeaveRevisions(); } else { reader.Skip(); } } else { HandleElement(reader, visitor); } }
/// <summary> /// Parses an XML plugin, calling the corresponding method in /// IPluginVisitor for each XML tag it encounters. /// </summary> /// <param name="reader">The XmlReader to read the plugin XML from.</param> /// <param name="visitor">The IPluginVisitor to call for each XML tag.</param> public static void LoadPlugin(XmlReader reader, IPluginVisitor visitor) { if (!reader.ReadToNextSibling("plugin")) { throw new ArgumentException("The XML file is missing a <plugin> tag."); } int baseSize = 0; if (reader.MoveToAttribute("headersize") || reader.MoveToAttribute("baseSize")) { baseSize = ParseInt(reader.Value); } if (visitor.EnterPlugin(baseSize)) { var loader = new UniversalPluginLoader(); loader.ReadElements(reader, true, visitor); visitor.LeavePlugin(); } }
private static void ReadBits(XmlReader reader, IPluginVisitor visitor) { XmlReader subtree = reader.ReadSubtree(); subtree.ReadStartElement(); while (subtree.Read()) { if (subtree.NodeType == XmlNodeType.Element) { if (subtree.Name == "bit" || subtree.Name == "option") { ReadBit(subtree, visitor); } else { throw new ArgumentException("Unknown bit definition tag: " + subtree.Name + PositionInfo(reader)); } } } visitor.LeaveBitfield(); }
private static void ReadRaw(XmlReader reader, string name, uint offset, bool visible, IPluginVisitor visitor, uint pluginLine) { if (!reader.MoveToAttribute("size")) { throw new ArgumentException("Raw data blocks must have a size attribute." + PositionInfo(reader)); } int size = ParseInt(reader.Value); visitor.VisitRawData(name, offset, visible, size, pluginLine); }
private static void ReadAscii(XmlReader reader, string name, uint offset, bool visible, IPluginVisitor visitor, uint pluginLine) { // Both "size" and "length" are accepted here because they are the same // with ASCII strings, but "size" should be preferred because it's less ambiguous // and <utf16> only supports "size" int size = 0; if (reader.MoveToAttribute("size") || reader.MoveToAttribute("length")) { size = ParseInt(reader.Value); } visitor.VisitAscii(name, offset, visible, size, pluginLine); }
private static void ReadRange(XmlReader reader, string name, uint offset, bool visible, IPluginVisitor visitor, uint pluginLine) { double min = 0.0; double max = 0.0; double largeChange = 0.0; double smallChange = 0.0; string type = "int32"; if (reader.MoveToAttribute("min")) { min = double.Parse(reader.Value); } if (reader.MoveToAttribute("max")) { max = double.Parse(reader.Value); } if (reader.MoveToAttribute("smallStep")) { smallChange = double.Parse(reader.Value); } if (reader.MoveToAttribute("largeStep")) { largeChange = double.Parse(reader.Value); } if (reader.MoveToAttribute("type")) { type = reader.Value.ToLower(); } visitor.VisitRange(name, offset, visible, type, min, max, smallChange, largeChange, pluginLine); }
/// <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) { var name = "Unknown"; uint offset = 0; var xmlLineInfo = reader as IXmlLineInfo; if (xmlLineInfo == null) return; var pluginLine = (uint)xmlLineInfo.LineNumber; var visible = true; if (reader.MoveToAttribute("name")) name = reader.Value; if (reader.MoveToAttribute("offset")) offset = ParseUInt(reader.Value); if (reader.MoveToAttribute("visible")) visible = ParseBool(reader.Value); reader.MoveToElement(); switch (elementName.ToLower()) // FIXME: Using ToLower() here violates XML standards { case "uint8": visitor.VisitUInt8(name, offset, visible, pluginLine); break; case "int8": visitor.VisitInt8(name, offset, visible, pluginLine); break; case "uint16": visitor.VisitUInt16(name, offset, visible, pluginLine); break; case "int16": visitor.VisitInt16(name, offset, visible, pluginLine); break; case "uint32": visitor.VisitUInt32(name, offset, visible, pluginLine); break; case "int32": visitor.VisitInt32(name, offset, visible, pluginLine); break; case "float32": case "float": visitor.VisitFloat32(name, offset, visible, pluginLine); break; case "undefined": visitor.VisitUndefined(name, offset, visible, pluginLine); break; case "vector3": visitor.VisitVector3(name, offset, visible, pluginLine); break; case "degree": visitor.VisitDegree(name, offset, visible, pluginLine); break; case "stringid": visitor.VisitStringID(name, offset, visible, pluginLine); break; case "tagref": ReadTagRef(reader, name, offset, visible, visitor, pluginLine); break; case "range": ReadRange(reader, name, offset, visible, visitor, pluginLine); break; case "ascii": ReadAscii(reader, name, offset, visible, visitor, pluginLine); break; case "utf16": ReadUtf16(reader, name, offset, visible, visitor, pluginLine); break; case "bitfield8": if (visitor.EnterBitfield8(name, offset, visible, pluginLine)) ReadBits(reader, visitor); else reader.Skip(); break; case "bitfield16": if (visitor.EnterBitfield16(name, offset, visible, pluginLine)) ReadBits(reader, visitor); else reader.Skip(); break; case "bitfield32": if (visitor.EnterBitfield32(name, offset, visible, pluginLine)) ReadBits(reader, visitor); else reader.Skip(); break; case "enum8": if (visitor.EnterEnum8(name, offset, visible, pluginLine)) ReadOptions(reader, visitor); else reader.Skip(); break; case "enum16": if (visitor.EnterEnum16(name, offset, visible, pluginLine)) ReadOptions(reader, visitor); else reader.Skip(); break; case "enum32": if (visitor.EnterEnum32(name, offset, visible, pluginLine)) ReadOptions(reader, visitor); else reader.Skip(); break; //case "color8": case "colour8": //case "color16": case "colour16": case "color": case "colour": visitor.VisitColorInt(name, offset, visible, ReadColorFormat(reader), pluginLine); break; case "color24": case "colour24": visitor.VisitColorInt(name, offset, visible, "rgb", pluginLine); break; case "color32": case "colour32": visitor.VisitColorInt(name, offset, visible, "argb", pluginLine); break; case "colorf": case "colourf": visitor.VisitColorF(name, offset, visible, ReadColorFormat(reader), pluginLine); break; case "dataref": visitor.VisitDataReference(name, offset, ReadDataRef(reader), visible, pluginLine); break; case "reflexive": ReadReflexive(reader, name, offset, visible, visitor, pluginLine); break; case "raw": ReadRaw(reader, name, offset, visible, visitor, pluginLine); break; default: throw new ArgumentException("Unknown element \"" + elementName + "\"." + PositionInfo(reader)); } }
private static void ReadUtf16(XmlReader reader, string name, uint offset, bool visible, IPluginVisitor visitor, uint pluginLine) { var size = 0; if (reader.MoveToAttribute("size")) size = ParseInt(reader.Value); visitor.VisitUtf16(name, offset, visible, size, pluginLine); }
private static void ReadRevisions(XmlReader reader, IPluginVisitor visitor) { reader.ReadStartElement(); while (reader.ReadToFollowing("revision")) visitor.VisitRevision(ReadRevision(reader)); }
private static void ReadBit(XmlReader reader, IPluginVisitor visitor) { var name = "Unknown"; if (reader.MoveToAttribute("name")) name = reader.Value; if (!reader.MoveToAttribute("index")) throw new ArgumentException("Bit definitions must have an index." + PositionInfo(reader)); var index = ParseInt(reader.Value); visitor.VisitBit(name, index); }
private static void ReadAscii(XmlReader reader, string name, uint offset, bool visible, IPluginVisitor visitor, uint pluginLine) { // Both "size" and "length" are accepted here because they are the same // with ASCII strings, but "size" should be preferred because it's less ambiguous // and <utf16> only supports "size" var size = 0; if (reader.MoveToAttribute("size") || reader.MoveToAttribute("length")) size = ParseInt(reader.Value); visitor.VisitAscii(name, offset, visible, size, pluginLine); }
private static void ReadBits(XmlReader reader, IPluginVisitor visitor) { XmlReader subtree = reader.ReadSubtree(); subtree.ReadStartElement(); while (subtree.Read()) { if (subtree.NodeType == XmlNodeType.Element) { if (subtree.Name == "bit" || subtree.Name == "option") ReadBit(subtree, visitor); else throw new ArgumentException("Unknown bit definition tag: " + subtree.Name + PositionInfo(reader)); } } visitor.LeaveBitfield(); }
private void ReadReflexive(XmlReader reader, string name, uint offset, bool visible, IPluginVisitor visitor, uint pluginLine) { uint entrySize = 0; if (reader.MoveToAttribute("entrySize") || reader.MoveToAttribute("size")) { if (!string.IsNullOrWhiteSpace(reader.Value)) entrySize = ParseUInt(reader.Value); } if (visitor.EnterReflexive(name, offset, visible, entrySize, pluginLine)) { reader.MoveToElement(); XmlReader subtree = reader.ReadSubtree(); subtree.ReadStartElement(); ReadElements(subtree, false, visitor); visitor.LeaveReflexive(); } }
private static void ReadShader(XmlReader reader, string name, uint offset, bool visible, IPluginVisitor visitor, uint pluginLine) { if (!reader.MoveToAttribute("type")) { throw new ArgumentException("Shaders must have a type attribute." + PositionInfo(reader)); } ShaderType type; if (reader.Value == "pixel") { type = ShaderType.Pixel; } else if (reader.Value == "vertex") { type = ShaderType.Vertex; } else { throw new ArgumentException("Invalid shader type \"" + reader.Value + "\""); } visitor.VisitShader(name, offset, visible, type, pluginLine); }
/// <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; if (reader.MoveToAttribute("name")) name = reader.Value; if (reader.MoveToAttribute("offset")) offset = ParseUInt(reader.Value); if (reader.MoveToAttribute("visible")) visible = ParseBool(reader.Value); reader.MoveToElement(); switch (elementName.ToLower()) { case "uint8": case "byte": visitor.VisitUInt8(name, offset, visible, pluginLine); break; case "sbyte": case "int8": visitor.VisitInt8(name, offset, visible, pluginLine); break; case "ushort": case "uint16": visitor.VisitUInt16(name, offset, visible, pluginLine); break; case "short": case "int16": visitor.VisitInt16(name, offset, visible, pluginLine); break; case "dword": case "uint": case "uint32": case "long": case "true": visitor.VisitUInt32(name, offset, visible, pluginLine); break; case "int": case "int32": visitor.VisitInt32(name, offset, visible, pluginLine); break; case "undefined": case "unknown": visitor.VisitUndefined(name, offset, visible, pluginLine); break; case "float": case "float32": case "degree": visitor.VisitFloat32(name, offset, visible, pluginLine); break; case "vector3": visitor.VisitVector3(name, offset, visible, pluginLine); break; case "stringid": visitor.VisitStringID(name, offset, visible, pluginLine); break; case "tag": case "tagid": case "tagref": case "ident": ReadTagRef(reader, name, offset, visible, visitor, pluginLine); break; case "string": case "ascii": ReadAscii(reader, name, offset, visible, visitor, pluginLine); break; case "string32": visitor.VisitAscii(name, offset, visible, 32, pluginLine); break; case "string64": visitor.VisitAscii(name, offset, visible, 64, pluginLine); break; case "string256": visitor.VisitAscii(name, offset, visible, 256, pluginLine); break; case "unicode": case "utf16": ReadUtf16(reader, name, offset, visible, visitor, pluginLine); break; case "unicode32": visitor.VisitUtf16(name, offset, visible, 32, pluginLine); break; case "unicode64": visitor.VisitUtf16(name, offset, visible, 64, pluginLine); break; case "unicode256": visitor.VisitUtf16(name, offset, visible, 256, pluginLine); break; case "bitfield8": case "bitmask8": if (visitor.EnterBitfield8(name, offset, visible, pluginLine)) ReadBits(reader, visitor); break; case "bitmask16": case "bitfield16": if (visitor.EnterBitfield16(name, offset, visible, pluginLine)) ReadBits(reader, visitor); break; case "bitmask32": case "bitfield32": if (visitor.EnterBitfield32(name, offset, visible, pluginLine)) ReadBits(reader, visitor); break; case "enum8": if (visitor.EnterEnum8(name, offset, visible, pluginLine)) ReadOptions(reader, visitor); break; case "enum16": if (visitor.EnterEnum16(name, offset, visible, pluginLine)) ReadOptions(reader, visitor); break; case "enum32": if (visitor.EnterEnum32(name, offset, visible, pluginLine)) ReadOptions(reader, visitor); break; case "tagdata": case "dataref": visitor.VisitDataReference(name, offset, ReadDataRef(reader), visible, pluginLine); break; case "struct": case "reflexive": case "reflexives": ReadReflexive(reader, name, offset, visible, visitor, pluginLine); break; case "bytearray": case "raw": ReadRaw(reader, name, offset, visible, visitor, pluginLine); break; case "color8": case "color16": case "color24": case "color32": visitor.VisitColorInt(name, offset, visible, ReadColorFormat(reader), pluginLine); break; case "colorf": visitor.VisitColorF(name, offset, visible, ReadColorFormat(reader), pluginLine); break; case "id": // Class 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; default: throw new ArgumentException("Unknown element \"" + elementName + "\"." + PositionInfo(reader)); } }
private void HandleTopLevelElement(XmlReader reader, string elementName, IPluginVisitor visitor) { if (elementName == "revisions") ReadRevisions(reader.ReadSubtree()); else if (elementName == "revision") ReadRevision(reader); else HandleElement(reader, elementName, visitor); }
private static void ReadReflexive(XmlReader reader, string name, uint offset, bool visible, IPluginVisitor visitor, uint pluginLine) { if (!reader.MoveToAttribute("entrySize")) throw new ArgumentException("Reflexives must have an entrySize attribute." + PositionInfo(reader)); var entrySize = ParseUInt(reader.Value); if (visitor.EnterReflexive(name, offset, visible, entrySize, pluginLine)) { reader.MoveToElement(); var subtree = reader.ReadSubtree(); subtree.ReadStartElement(); ReadElements(subtree, false, visitor); visitor.LeaveReflexive(); } else { reader.Skip(); } }
private static void ReadBits(XmlReader reader, IPluginVisitor visitor) { var subtree = reader.ReadSubtree(); subtree.ReadStartElement(); while (subtree.ReadToNextSibling("bit")) ReadBit(subtree, visitor); visitor.LeaveBitfield(); }
private static void ReadTagRef(XmlReader reader, string name, uint offset, bool visible, IPluginVisitor visitor, uint pluginLine) { var showJumpTo = true; var withClass = true; if (reader.MoveToAttribute("showJumpTo")) showJumpTo = ParseBool(reader.Value); if (reader.MoveToAttribute("withClass")) withClass = ParseBool(reader.Value); visitor.VisitTagReference(name, offset, visible, withClass, showJumpTo, pluginLine); }
private static void ReadComment(XmlReader reader, IPluginVisitor visitor) { var title = "Comment"; if (reader.MoveToAttribute("title")) title = reader.Value; reader.MoveToElement(); var xmlLineInfo = reader as IXmlLineInfo; if (xmlLineInfo == null) return; var pluginLine = (uint)xmlLineInfo.LineNumber; var text = reader.ReadElementContentAsString(); visitor.VisitComment(title, text, pluginLine); }
private static void ReadShader(XmlReader reader, string name, uint offset, bool visible, IPluginVisitor visitor, uint pluginLine) { if (!reader.MoveToAttribute("type")) throw new ArgumentException("Shaders must have a type attribute." + PositionInfo(reader)); ShaderType type; if (reader.Value == "pixel") type = ShaderType.Pixel; else if (reader.Value == "vertex") type = ShaderType.Vertex; else throw new ArgumentException("Invalid shader type \"" + reader.Value + "\""); visitor.VisitShader(name, offset, visible, type, pluginLine); }
private static void ReadUnicList(XmlReader reader, string name, uint offset, bool visible, IPluginVisitor visitor, uint pluginLine) { if (!reader.MoveToAttribute("languages")) throw new ArgumentException("Unicode string lists must have a languages attribute." + PositionInfo(reader)); int languages = ParseInt(reader.Value); visitor.VisitUnicList(name, offset, visible, languages, pluginLine); }
private static void ReadOption(XmlReader reader, IPluginVisitor visitor) { var name = "Unknown"; var value = 0; if (reader.MoveToAttribute("name")) name = reader.Value; if (reader.MoveToAttribute("value")) value = ParseInt(reader.Value); visitor.VisitOption(name, value); }
private static void ReadTagRef(XmlReader reader, string name, uint offset, bool visible, IPluginVisitor visitor, uint pluginLine) { bool showJumpTo = true; bool withClass = true; if (reader.MoveToAttribute("showJumpTo")) { showJumpTo = ParseBool(reader.Value); } if (reader.MoveToAttribute("withClass")) { withClass = ParseBool(reader.Value); } visitor.VisitTagReference(name, offset, visible, withClass, showJumpTo, pluginLine); }
private static void ReadOptions(XmlReader reader, IPluginVisitor visitor) { var subtree = reader.ReadSubtree(); subtree.ReadStartElement(); while (subtree.ReadToNextSibling("option")) ReadOption(subtree, visitor); visitor.LeaveEnum(); }
private static void ReadUtf16(XmlReader reader, string name, uint offset, bool visible, IPluginVisitor visitor, uint pluginLine) { int size = 0; if (reader.MoveToAttribute("size")) { size = ParseInt(reader.Value); } visitor.VisitUtf16(name, offset, visible, size, pluginLine); }
private static void ReadRange(XmlReader reader, string name, uint offset, bool visible, IPluginVisitor visitor, uint pluginLine) { var min = 0.0; var max = 0.0; var largeChange = 0.0; var smallChange = 0.0; var type = "int32"; if (reader.MoveToAttribute("min")) min = double.Parse(reader.Value); if (reader.MoveToAttribute("max")) max = double.Parse(reader.Value); if (reader.MoveToAttribute("smallStep")) smallChange = double.Parse(reader.Value); if (reader.MoveToAttribute("largeStep")) largeChange = double.Parse(reader.Value); if (reader.MoveToAttribute("type")) type = reader.Value.ToLower(); visitor.VisitRange(name, offset, visible, type, min, max, smallChange, largeChange, pluginLine); }
private static void ReadReflexive(XmlReader reader, string name, uint offset, bool visible, IPluginVisitor visitor, uint pluginLine) { if (!reader.MoveToAttribute("entrySize")) { throw new ArgumentException("Reflexives must have an entrySize attribute." + PositionInfo(reader)); } uint entrySize = ParseUInt(reader.Value); int align = 4; if (reader.MoveToAttribute("align")) { align = ParseInt(reader.Value); } if (visitor.EnterReflexive(name, offset, visible, entrySize, align, pluginLine)) { reader.MoveToElement(); XmlReader subtree = reader.ReadSubtree(); subtree.ReadStartElement(); ReadElements(subtree, false, visitor); visitor.LeaveReflexive(); } else { reader.Skip(); } }
private static void ReadRaw(XmlReader reader, string name, uint offset, bool visible, IPluginVisitor visitor, uint pluginLine) { if (!reader.MoveToAttribute("size")) throw new ArgumentException("Raw data blocks must have a size attribute." + PositionInfo(reader)); var size = ParseInt(reader.Value); visitor.VisitRawData(name, offset, visible, size, pluginLine); }
private void ReadComment(XmlReader reader, IPluginVisitor visitor) { string title = "Comment"; if (reader.MoveToAttribute("title")) title = reader.Value; reader.MoveToElement(); var pluginLine = (uint) (reader as IXmlLineInfo).LineNumber; string text = reader.ReadElementContentAsString(); visitor.VisitComment(title, text, pluginLine); }
private static void ReadUnicList(XmlReader reader, string name, uint offset, bool visible, IPluginVisitor visitor, uint pluginLine) { if (!reader.MoveToAttribute("languages")) { throw new ArgumentException("Unicode string lists must have a languages attribute." + PositionInfo(reader)); } int languages = ParseInt(reader.Value); visitor.VisitUnicList(name, offset, visible, languages, pluginLine); }
private void ReadElements(XmlReader reader, bool topLevel, IPluginVisitor visitor) { while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { string elementName = reader.Name.ToLower(); if (topLevel) HandleTopLevelElement(reader, elementName, visitor); else HandleElement(reader, elementName, visitor); } } }