コード例 #1
0
ファイル: NbtTree.cs プロジェクト: wledfor2/Substrate
        private TagNode ReadIntArray()
        {
            byte[] lenBytes = new byte[4];
            _stream.Read(lenBytes, 0, 4);

            if (BitConverter.IsLittleEndian)
            {
                Array.Reverse(lenBytes);
            }

            int length = BitConverter.ToInt32(lenBytes, 0);

            if (length < 0)
            {
                throw new NBTException(NBTException.MSG_READ_NEG);
            }

            int[]  data   = new int[length];
            byte[] buffer = new byte[4];
            for (int i = 0; i < length; i++)
            {
                _stream.Read(buffer, 0, 4);
                if (BitConverter.IsLittleEndian)
                {
                    Array.Reverse(buffer);
                }
                data[i] = BitConverter.ToInt32(buffer, 0);
            }

            TagNodeIntArray val = new TagNodeIntArray(data);

            return(val);
        }
コード例 #2
0
        private static void SerializeIntArray(TagNodeIntArray tag, StringBuilder str, int level)
        {
            if (tag.Length == 0)
            {
                str.Append("[ ]");
                return;
            }

            str.Append("[ ");

            bool first = true;

            for (int i = 0; i < tag.Length; i++)
            {
                if (!first)
                {
                    str.Append(", ");
                }

                str.Append(tag.Data[i]);
                first = false;
            }

            str.Append(" ]");
        }
コード例 #3
0
        private void WriteIntArray(TagNodeIntArray val)
        {
            var lenBytes = BitConverter.GetBytes(val.Length);

            if (BitConverter.IsLittleEndian)
            {
                Array.Reverse(lenBytes);
            }

            _stream.Write(lenBytes, 0, 4);

            var data = new byte[val.Length * 4];

            for (var i = 0; i < val.Length; i++)
            {
                var buffer = BitConverter.GetBytes(val.Data[i]);
                if (BitConverter.IsLittleEndian)
                {
                    Array.Reverse(buffer);
                }
                Array.Copy(buffer, 0, data, i * 4, 4);
            }

            _stream.Write(data, 0, data.Length);
        }
コード例 #4
0
        private bool VerifyIntArray(TagNode tag, SchemaNodeIntArray schema)
        {
            TagNodeIntArray atag = tag as TagNodeIntArray;

            if (atag == null)
            {
                if (!OnInvalidTagType(new TagEventArgs(schema, tag)))
                {
                    return(false);
                }
            }
            if (schema.Length > 0 && atag.Length != schema.Length)
            {
                if (!OnInvalidTagValue(new TagEventArgs(schema, tag)))
                {
                    return(false);
                }
            }

            return(true);
        }
コード例 #5
0
ファイル: SchemaNodeIntArray.cs プロジェクト: DinoV/Substrate
        public override bool Verify(NbtVerifier verifier, TagNode tag)
        {
            TagNodeIntArray atag = tag as TagNodeIntArray;

            if (atag == null)
            {
                if (!verifier.OnInvalidTagType(new TagEventArgs(this, tag)))
                {
                    return(false);
                }
            }
            if (Length > 0 && atag.Length != Length)
            {
                if (!verifier.OnInvalidTagValue(new TagEventArgs(this, tag)))
                {
                    return(false);
                }
            }

            return(true);
        }
コード例 #6
0
 public TagIntArrayDataNode(TagNodeIntArray tag)
     : base(tag)
 {
 }
コード例 #7
0
        internal static void AddTagToNode(TreeNode node, int descriptionIndex, TagType type)
        {
            TagNode tag = GetTagNode(node);
            if (tag == null)
                return;

            if (tag.GetTagType() != TagType.TAG_COMPOUND &&
                tag.GetTagType() != TagType.TAG_LIST)
                return;

            if (tag.GetTagType() == TagType.TAG_LIST &&
                tag.ToTagList().ValueType != type &&
                tag.ToTagList().Count > 0)
                return;

            TagNode newNode = null;
            switch (type)
            {
                case TagType.TAG_BYTE:
                    newNode = new TagNodeByte();
                    break;
                case TagType.TAG_SHORT:
                    newNode = new TagNodeShort();
                    break;
                case TagType.TAG_INT:
                    newNode = new TagNodeInt();
                    break;
                case TagType.TAG_LONG:
                    newNode = new TagNodeLong();
                    break;
                case TagType.TAG_FLOAT:
                    newNode = new TagNodeFloat();
                    break;
                case TagType.TAG_DOUBLE:
                    newNode = new TagNodeDouble();
                    break;
                case TagType.TAG_BYTE_ARRAY:
                    newNode = new TagNodeByteArray();
                    break;
                case TagType.TAG_STRING:
                    newNode = new TagNodeString();
                    break;
                case TagType.TAG_LIST:
                    newNode = new TagNodeList(TagType.TAG_BYTE);
                    break;
                case TagType.TAG_COMPOUND:
                    newNode = new TagNodeCompound();
                    break;
                case TagType.TAG_INT_ARRAY:
                    newNode = new TagNodeIntArray();
                    break;
            }

            if (tag is TagNodeCompound)
            {
                TagNodeCompound ctag = tag as TagNodeCompound;

                EditValue form = new EditValue("");
                foreach (string key in ctag.Keys)
                {
                    form.InvalidNames.Add(key);
                }

                if (form.ShowDialog() != DialogResult.OK)
                    return;

                ctag.Add(form.NodeName, newNode);

                TreeNode tnode = NodeFromTag(newNode, descriptionIndex, form.NodeName);
                node.Nodes.Add(tnode);

                tnode.TreeView.SelectedNode = tnode;
                tnode.Expand();
            }
            else if (tag is TagNodeList)
            {
                var ltag = tag as TagNodeList;
                if (ltag.ValueType != type)
                    ltag.ChangeValueType(type);

                ltag.Add(newNode);

                TreeNode tnode = NodeFromTag(newNode, descriptionIndex);
                node.Nodes.Add(tnode);
                tnode.TreeView.SelectedNode = tnode;

                tnode.Expand();
            }

            node.Text = GetNodeText(node);

            TreeNode baseNode = BaseNode(node);
            if (baseNode != null)
            {
                (baseNode.Tag as DataNode).Modified = true;
            }
        }
コード例 #8
0
        private static void SerializeIntArray(TagNodeIntArray tag, StringBuilder str, int level)
        {
            if (tag.Length == 0) {
                str.Append("[ ]");
                return;
            }

            str.Append("[ ");

            bool first = true;
            for (int i = 0; i < tag.Length; i++) {
                if (!first) {
                    str.Append(", ");
                }

                str.Append(tag.Data[i]);
                first = false;
            }

            str.Append(" ]");
        }