Exemple #1
0
        /// <summary>
        /// Gets and returns the display name(s) of the data object using the supplied map file.
        /// </summary>
        /// <returns>An array of string elements.</returns>
        /// <param name="map">The map file.</param>
        public string[] GetDisplayNames(MapFile map)
        {
            //Prepare
            List <string> names = new List <string>();
            string        name  = node.Name;

            //Check
            if (IsTagBlock && value is TagBlock tagBlock)
            {
                //Check Label
                if (!string.IsNullOrEmpty(node.Label))
                {
                    //Check Count
                    if (tagBlock.Count > 0)
                    {
                        //Get Node
                        IfpNode[] labelNodes = node.Nodes[node.Label];

                        //Loop
                        if (labelNodes.Length > 0)
                        {
                            using (BinaryReader reader = new BinaryReader(dataStream))
                                for (int i = 0; i < tagBlock.Count; i++)
                                {
                                    //Hacky
                                    IfpNode hack = labelNodes[0];

                                    //Set name...
                                    name = GetNodeDisplayName(hack.Type, dataStream, tagBlock.Offset + (uint)(i * node.Length), map);

                                    //Check
                                    if (!string.IsNullOrEmpty(name))
                                    {
                                        names.Add(name);
                                    }
                                    else
                                    {
                                        names.Add(node.Name);
                                    }
                                }
                        }
                    }
                }
                else
                {
                    //Add names...
                    for (int i = 0; i < tagBlock.Count; i++)
                    {
                        names.Add(name);
                    }
                }
            }

            //Add element name once if no names are retrieved
            if (names.Count == 0)
            {
                names.Add(name);
            }

            //Return
            return(names.ToArray());
        }
Exemple #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DataObject"/> class using the supplied ifp node and data stream.
 /// </summary>
 /// <param name="node">The object's ifp node.</param>
 /// <param name="dataStream">The tag's data stream.</param>
 public DataObject(IfpNode node, VirtualStream dataStream)
 {
     //Set
     this.node       = node ?? throw new ArgumentNullException(nameof(node));
     this.dataStream = dataStream ?? throw new ArgumentNullException(nameof(dataStream));
 }
Exemple #3
0
        public IfpTagBlock(IfpNode ifpNode)
        {
            int size;

            if (ifpNode.HeaderSize > ifpNode.TagBlockSize)
            {
                size = ifpNode.HeaderSize;
            }
            else
            {
                size = ifpNode.TagBlockSize;
            }

            AnalyzeFieldSet(ifpNode.Nodes, size);

            int offset = 0, previousOffset = 0;

            if (ifpNode.Alignment > 0)
            {
                alignment = ifpNode.Alignment;
            }

            bool skipId = false;

            foreach (var node in ifpNode.Nodes)
            {
                Field field = null;
                if (node.FieldOffset >= offset)
                {
                    offset = node.FieldOffset;
                }
                else if (node.FieldOffset > 0)
                {
                    continue;
                }

                if (node.Type == IfpNodeType.Tag)
                {
                    int nodeIndex = ifpNode.Nodes.IndexOf(node);
                    if (ifpNode.Nodes.Count > nodeIndex && ifpNode.Nodes[nodeIndex + 1].Type == IfpNodeType.TagId)
                    {
                        skipId = true;
                        continue;
                    }
                }
                else if (node.Type == IfpNodeType.TagId && skipId)
                {
                    skipId = false;
                    field  = new TagReferenceField(node.Name);
                }
                else
                {
                    switch (node.Type)
                    {
                    case IfpNodeType.TagBlock:
                        field = new IfpBlockField(node);
                        break;

                    case IfpNodeType.UnusedArray:
                        field = new PadField(node.Name, node.Length);
                        break;

                    case IfpNodeType.Byte:
                    case IfpNodeType.SignedByte:
                        field = new CharIntegerField(node.Name);
                        break;

                    case IfpNodeType.Short:
                    case IfpNodeType.UnsignedShort:
                        field = new ShortIntegerField(node.Name);
                        break;

                    case IfpNodeType.Int:
                    case IfpNodeType.UnsignedInt:
                        field = new LongIntegerField(node.Name);
                        break;

                    case IfpNodeType.Single:
                        field = new RealField(node.Name);
                        break;

                    case IfpNodeType.Enumerator8:
                        field = new CharEnumField(node.Name);
                        break;

                    case IfpNodeType.Enumerator16:
                        field = new EnumField(node.Name);
                        break;

                    case IfpNodeType.Enumerator32:
                        field = new LongEnumField(node.Name);
                        break;

                    case IfpNodeType.Bitfield8:
                        field = new ByteFlagsField(node.Name);
                        break;

                    case IfpNodeType.Bitfield16:
                        field = new WordFlagsField(node.Name);
                        break;

                    case IfpNodeType.Bitfield32:
                        field = new LongFlagsField(node.Name);
                        break;

                    case IfpNodeType.String32:
                        field = new StringField(node.Name);
                        break;

                    case IfpNodeType.String64:
                        break;

                    case IfpNodeType.Unicode128:
                        break;

                    case IfpNodeType.Unicode256:
                        break;

                    case IfpNodeType.Tag:
                        field = new TagField(node.Name);
                        break;

                    case IfpNodeType.TagId:
                        field = new TagIndexField(node.Name);
                        break;

                    case IfpNodeType.StringId:
                        field = new StringIdField(node.Name);
                        break;
                    }
                }

                if (field != null)
                {
                    if (node.Type == IfpNodeType.Enumerator8 || node.Type == IfpNodeType.Enumerator16 || node.Type == IfpNodeType.Enumerator32 ||
                        node.Type == IfpNodeType.Bitfield8 || node.Type == IfpNodeType.Bitfield16 || node.Type == IfpNodeType.Bitfield32)
                    {
                        var optionField = (OptionField)field;
                        foreach (var optionNode in node.Nodes)
                        {
                            optionField.Options.Add(new Option(optionNode.Name, optionNode.Value));
                        }
                    }

                    if (previousOffset <= offset)
                    {
                        int length = offset - previousOffset;
                        if (length > 0)
                        {
                            Fields.Add(new PadField("ifp padding", length));
                        }

                        offset        += field.Size;
                        previousOffset = offset;
                        Fields.Add(field);
                    }
                }
            }

            if (offset < size)
            {
                Fields.Add(new PadField("ifp padding", size - offset));
            }

            if (!string.IsNullOrEmpty(ifpNode.Label))
            {
                var labelFields = Fields.Where(f => f.Name.Equals(ifpNode.Label, StringComparison.OrdinalIgnoreCase));
                foreach (var labelField in labelFields)
                {
                    this.labelFields.Add(labelField);
                }
            }
        }
Exemple #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DataObject"/> class using the supplied parent object, ifp node and data stream.
 /// </summary>
 /// <param name="parent">The object's parent.</param>
 /// <param name="node">The object's ifp node.</param>
 /// <param name="dataStream">The tag's data stream.</param>
 public DataObject(DataObject parent, IfpNode node, VirtualStream dataStream) : this(node, dataStream)
 {
     //Set
     this.parent = parent ?? throw new ArgumentNullException(nameof(parent));
     parent.children.Add(this);
 }
Exemple #5
0
 public IfpBlockField(IfpNode structIfpNode) : base(structIfpNode.Name, ushort.MaxValue)
 {
     node = structIfpNode;
 }