Example #1
0
        public List <FieldHeader> ReadFieldHeaders()
        {
            var header = ReadHeader();
            var list   = new List <FieldHeader>();

            for (int i = 0; i < header.entryCount; i++)
            {
                FieldHeader fh = new FieldHeader();
                fh.name     = ReadString(0x20);
                fh.padding  = binStream.ReadBytes(FieldHeader.Size - 0x20);
                fh.children = new List <FieldHeader>();
                for (int j = i - 1; j >= 0; j--)
                {
                    if (list[j].FieldLevel == fh.FieldLevel)
                    {
                        fh.parent = list[j].parent;
                        break;
                    }
                    else if (list[j].FieldLevel < fh.FieldLevel)
                    {
                        fh.parent = list[j];
                        break;
                    }
                }
                if (fh.parent == null)
                {
                    fh.parent = root;
                }
                fh.parent.children.Add(fh);
                fh.index = i;
                list.Add(fh);
            }
            return(list);
        }
Example #2
0
        public override DataTemplate SelectTemplate(object item, DependencyObject container)
        {
            var field = FieldHeader.GetHeader(container)?.Field;

            if (field != null && field.Group == null)
            {
                return(CustomTemplate);
            }
            return(LegacyTemplate);
        }
Example #3
0
        public void Read(BinaryFileReader r, string filePath, GameFormat format)
        {
            var startPosition = r.Position;
            var endPosition   = startPosition + Header.DataSize;

            while (r.Position < endPosition)
            {
                var fieldHeader = new FieldHeader(r, format);
                if (fieldHeader.Type == "XXXX")
                {
                    if (fieldHeader.DataSize != 4)
                    {
                        throw new InvalidOperationException();
                    }
                    fieldHeader.DataSize = (int)r.ReadUInt32();
                    continue;
                }
                else if (fieldHeader.Type == "OFST" && Header.Type == "WRLD")
                {
                    r.Position = endPosition;
                    continue;
                }
                var position = r.Position;
                if (!CreateField(r, format, fieldHeader.Type, fieldHeader.DataSize))
                {
                    Log($"Unsupported ESM record type: {Header.Type}:{fieldHeader.Type}");
                    r.Position += fieldHeader.DataSize;
                    continue;
                }
                // check full read
                if (r.Position != position + fieldHeader.DataSize)
                {
                    throw new FormatException($"Failed reading {Header.Type}:{fieldHeader.Type} field data at offset {position} in {filePath} of {r.Position - position - fieldHeader.DataSize}");
                }
            }
            // check full read
            if (r.Position != endPosition)
            {
                throw new FormatException($"Failed reading {Header.Type} record data at offset {startPosition} in {filePath}");
            }
        }
Example #4
0
        /// <summary>
        /// Converts the xml documentation string into a description object.
        /// </summary>
        public static Description GetDescription(IEntity entity)
        {
            IHeader header = null;

            var method = entity as IMethod;

            if (method != null)
            {
                header = new MethodHeader(method);
            }
            var field = entity as IField;

            if (field != null)
            {
                header = new FieldHeader(field);
            }

            var property = entity as IProperty;

            if (property != null)
            {
                header = new PropertyHeader(property);
            }

            if (header == null)
            {
                header = new SimpleHeader(AmbienceService.GetCurrentAmbience().Convert(entity));
            }


            var    description      = new Description(header);
            string xmlDocumentation = entity.Documentation;

            if (string.IsNullOrEmpty(xmlDocumentation))
            {
                return(description);
            }

            try
            {
                // original pattern without escape symbols: \<see cref=\"[^\"]+\.([^\"]+)\"\ /\>
                const string seeCrefPattern = "\\<see cref=\\\"[^\\\"]+\\.([^\\\"]+)\\\"\\ /\\>";
                xmlDocumentation = Regex.Replace(xmlDocumentation, seeCrefPattern, "$1");

                XDocument xml = XDocument.Parse("<docroot>" + xmlDocumentation + "</docroot>");

                foreach (XElement element in xml.Root.Elements())
                {
                    Test[element.Name.LocalName] = element.ToString();
                }

                XElement summary = xml.Descendants("summary").FirstOrDefault();
                if (summary != null)
                {
                    description.Summary = summary.Value.Trim();
                }

                XElement[] xmlParameters = xml.Descendants("param").ToArray();
                foreach (XElement node in xmlParameters)
                {
                    string    name = node.Attribute("name").Value;
                    string    parameterDescription = node.Value;
                    Parameter parameterObject      =
                        description.Parameters.FirstOrDefault(parameter => parameter.Name == name);
                    if (parameterObject != null)
                    {
                        parameterObject.Description = parameterDescription;
                    }
                }
            }
            catch (Exception)
            {
                return(new SimpleDescription(xmlDocumentation));
            }
            return(description);
        }