示例#1
0
        public PssgNode(XElement elem, PssgFile file, PssgNode node)
        {
            this.File       = file;
            this.ParentNode = node;
            this.NodeInfo   = PssgSchema.AddNode(elem.Name.LocalName);// PssgSchema.GetNode(elem.Name.LocalName);

            this.Attributes = new PssgAttributeCollection();
            PssgAttribute attr;

            foreach (XAttribute xAttr in elem.Attributes())
            {
                attr = new PssgAttribute(xAttr, file, this);
                this.Attributes.Add(attr);
            }

            // Add data, and sub nodes code here
            if (elem.FirstNode != null && elem.FirstNode is XText)
            {
                this.data       = this.FromString(elem.Value);
                this.ChildNodes = new PssgNodeCollection();
            }
            else
            {
                this.data       = new byte[0];
                this.ChildNodes = new PssgNodeCollection(elem.Elements().Count());
                int nodeCount = 0;
                foreach (XElement subElem in elem.Elements())
                {
                    this.ChildNodes.Add(new PssgNode(subElem, file, this));
                    ++nodeCount;
                }
            }
            PssgSchema.SetNodeDataTypeIfNull(this.NodeInfo, this.ValueType);
        }
示例#2
0
 public PssgAttribute(PssgSchema.Attribute attributeInfo, object data, PssgFile file, PssgNode ParentNode)
 {
     this.AttributeInfo = attributeInfo;
     this.data = data;
     this.file = file;
     this.ParentNode = ParentNode;
 }
示例#3
0
 public PssgNode(string name, PssgFile file, PssgNode node)
 {
     this.File       = file;
     this.ParentNode = node;
     this.NodeInfo   = PssgSchema.AddNode(name);
     this.Attributes = new PssgAttributeCollection();
     this.data       = new byte[0];
     this.ChildNodes = new PssgNodeCollection();
 }
示例#4
0
        public PssgAttribute(XAttribute xAttr, PssgFile file, PssgNode node)
        {
            this.file = file;
            this.ParentNode = node;

            //this.id = PssgSchema.GetAttributeId(ParentNode.Name, xAttr.Name.LocalName);
            this.AttributeInfo = PssgSchema.AddAttribute(this.ParentNode.Name, xAttr.Name.LocalName);// PssgSchema.GetAttribute(this.ParentNode.Name, xAttr.Name.LocalName);
            this.data = this.FromString(xAttr.Value);
            PssgSchema.SetAttributeDataTypeIfNull(this.AttributeInfo, this.ValueType);
        }
        public static PssgSchema.Node RenameNode(PssgNode pssgNode, string nodeName)
        {
            PssgSchema.Node node = PssgSchema.AddNode(nodeName);

            foreach (PssgAttribute attr in pssgNode.Attributes)
            {
                PssgSchema.AddAttribute(node.Name, attr.AttributeInfo.Name, attr.AttributeInfo.DataType);
            }

            return(node);
        }
示例#6
0
        public PssgAttribute(PssgBinaryReader reader, PssgFile file, PssgNode node)
        {
            this.file = file;
            this.ParentNode = node;

            int id = reader.ReadInt32();
            this.AttributeInfo = PssgSchema.GetAttribute(id);
            this.size = reader.ReadInt32();
            this.data = reader.ReadAttributeValue(this.AttributeInfo.DataType, size);
            this.AttributeInfo = PssgSchema.AddAttribute(this.ParentNode.Name, this.Name, this.ValueType);
        }
示例#7
0
 public void RemoveChild(PssgNode childNode)
 {
     if (this.ChildNodes.Remove(childNode))
     {
         childNode.ParentNode = null;
     }
     else
     {
         throw new InvalidOperationException("Failed to remove child node.");
     }
 }
        public PssgAttribute(XAttribute xAttr, PssgFile file, PssgNode node)
        {
            this.file       = file;
            this.ParentNode = node;

            //this.id = PssgSchema.GetAttributeId(ParentNode.Name, xAttr.Name.LocalName);
            string attrName = xAttr.Name.LocalName.StartsWith("___") ? xAttr.Name.LocalName.Substring(3) : xAttr.Name.LocalName;

            this.AttributeInfo = PssgSchema.AddAttribute(this.ParentNode.Name, attrName);// PssgSchema.GetAttribute(this.ParentNode.Name, xAttr.Name.LocalName);
            this.data          = this.FromString(xAttr.Value);
            PssgSchema.SetAttributeDataTypeIfNull(this.AttributeInfo, this.ValueType);
        }
        public PssgAttribute(PssgBinaryReader reader, PssgFile file, PssgNode node)
        {
            this.file       = file;
            this.ParentNode = node;

            int id = reader.ReadInt32();

            this.AttributeInfo = PssgSchema.GetAttribute(id);
            this.size          = reader.ReadInt32();
            this.data          = reader.ReadAttributeValue(this.AttributeInfo.DataType, size);
            this.AttributeInfo = PssgSchema.AddAttribute(this.ParentNode.Name, this.Name, this.ValueType);
        }
示例#10
0
        public PssgNode SetChild(PssgNode childNode, PssgNode newChildNode)
        {
            newChildNode.File       = this.File;
            newChildNode.ParentNode = this;
            PssgNode node = this.ChildNodes.Set(childNode, newChildNode);

            if (node != null)
            {
                node.NodeInfo = PssgSchema.AddNode(node);
            }
            return(node);
        }
示例#11
0
        //public static void CreatePssgInfo(out PssgNodeInfo[] nodeInfo, out PssgAttributeInfo[] attributeInfo)
        //{
        //    nodeInfo = new PssgNodeInfo[entries.Count];
        //    List<PssgAttributeInfo> attrInfo = new List<PssgAttributeInfo>();

        //    int i = 0, j = 0;
        //    foreach (KeyValuePair<string, Node> node in entries)
        //    {
        //        nodeInfo[i] = new PssgNodeInfo(i + 1, node.Key);

        //        foreach (Attribute attr in node.Value.Attributes)
        //        {
        //            attr.Id = ++j;
        //            PssgAttributeInfo aInfo = new PssgAttributeInfo(attr.Id, attr.Name);
        //            attrInfo.Add(aInfo);
        //            nodeInfo[i].attributeInfo.Add(attr.Id, aInfo);
        //        }

        //        node.Value.Id = ++i;
        //    }

        //    attributeInfo = attrInfo.ToArray();
        //}

        public static PssgSchema.Node AddNode(PssgNode node)
        {
            Node sNode = new Node(node.Name);

            sNode.DataType = node.ValueType;

            foreach (PssgAttribute attr in node.Attributes)
            {
                Attribute sAttr = new Attribute(attr.Name, attr.ValueType);
                sNode.Attributes.Add(sAttr);
            }

            return(PssgSchema.AddNode(sNode));
        }
示例#12
0
        public PssgNode AppendChild(PssgNode childNode)
        {
            if (this.IsDataNode == true)
            {
                return(null);
            }

            if (this.ChildNodes == null)
            {
                this.ChildNodes = new PssgNodeCollection();
            }

            childNode.File       = this.File;
            childNode.ParentNode = this;
            this.ChildNodes.Add(childNode);
            childNode.NodeInfo = PssgSchema.AddNode(childNode);

            return(childNode);
        }
示例#13
0
        public PssgNode AppendChild(PssgNode childNode)
        {
            if (this.IsDataNode == true)
            {
                throw new InvalidOperationException("Cannot append a child node to a data node");
            }

            if (this.ChildNodes == null)
            {
                this.ChildNodes = new PssgNodeCollection();
            }

            childNode.File       = this.File;
            childNode.ParentNode = this;
            this.ChildNodes.Add(childNode);
            childNode.NodeInfo = PssgSchema.AddNode(childNode);

            return(childNode);
        }
示例#14
0
        public PssgNode AppendChild(PssgNode childNode)
        {
            if (this.IsDataNode == true)
            {
                MessageBox.Show("Adding sub nodes to a node with data is not allowed!", "PSSG Editor", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return(null);
            }

            if (this.ChildNodes == null)
            {
                this.ChildNodes = new PssgNodeCollection();
            }

            childNode.File       = this.File;
            childNode.ParentNode = this;
            this.ChildNodes.Add(childNode);
            childNode.NodeInfo = PssgSchema.AddNode(childNode);

            return(childNode);
        }
示例#15
0
        public PssgNode(PssgNode nodeToCopy)
        {
            this.File       = nodeToCopy.File;
            this.ParentNode = nodeToCopy.ParentNode;

            this.NodeInfo      = nodeToCopy.NodeInfo;
            this.size          = nodeToCopy.size;
            this.attributeSize = nodeToCopy.attributeSize;
            this.Attributes    = new PssgAttributeCollection();
            PssgAttribute attr;

            foreach (PssgAttribute attrToCopy in nodeToCopy.Attributes)
            {
                attr            = new PssgAttribute(attrToCopy);
                attr.ParentNode = this;
                this.Attributes.Add(attr);
            }


            if (nodeToCopy.IsDataNode)
            {
                this.data       = nodeToCopy.data;
                this.ChildNodes = new PssgNodeCollection();
            }
            else
            {
                this.data = new byte[0];
                // Each node at least 12 bytes (id + size + arg size)
                this.ChildNodes = new PssgNodeCollection(nodeToCopy.ChildNodes.Count);
                foreach (PssgNode subNodeToCopy in nodeToCopy.ChildNodes)
                {
                    PssgNode node = new PssgNode(subNodeToCopy);
                    node.ParentNode = this;
                    this.ChildNodes.Add(node);
                }
            }
        }
示例#16
0
        public PssgNode AppendChild(PssgNode childNode)
        {
            if (this.IsDataNode == true)
            {
                MessageBox.Show("Adding sub nodes to a node with data is not allowed!", "PSSG Editor", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return null;
            }

            if (this.ChildNodes == null)
            {
                this.ChildNodes = new PssgNodeCollection();
            }

            childNode.File = this.File;
            childNode.ParentNode = this;
            this.ChildNodes.Add(childNode);
            childNode.NodeInfo = PssgSchema.AddNode(childNode);

            return childNode;
        }
示例#17
0
        public void Write(PssgNode node)
        {
            node.Attributes["height"].Value = header.height;
            node.Attributes["width"].Value  = header.width;
            if (node.HasAttribute("numberMipMapLevels") == true)
            {
                if ((int)header.mipMapCount - 1 >= 0)
                {
                    node.Attributes["numberMipMapLevels"].Value = header.mipMapCount - 1;
                }
                else
                {
                    node.Attributes["numberMipMapLevels"].Value = 0u;
                }
            }
            if (header.ddspf.rGBBitCount == 32)
            {
                node.Attributes["texelFormat"].Value = "ui8x4";
            }
            else if (header.ddspf.rGBBitCount == 8)
            {
                node.Attributes["texelFormat"].Value = "u8";
            }
            else
            {
                node.Attributes["texelFormat"].Value = Encoding.UTF8.GetString(BitConverter.GetBytes(header.ddspf.fourCC)).ToLower();
            }
            List <PssgNode> textureImageBlocks = node.FindNodes("TEXTUREIMAGEBLOCK");

            if (bdata2 != null && bdata2.Count > 0)
            {
                for (int i = 0; i < textureImageBlocks.Count; i++)
                {
                    switch (textureImageBlocks[i].Attributes["typename"].ToString())
                    {
                    case "Raw":
                        if (bdata2.ContainsKey(0) == true)
                        {
                            textureImageBlocks[i].FindNodes("TEXTUREIMAGEBLOCKDATA")[0].Value = bdata2[0];
                            textureImageBlocks[i].Attributes["size"].Value = (UInt32)bdata2[0].Length;
                        }
                        else
                        {
                            throw new Exception("Loading cubemap failed because not all blocks were found. (Write)");
                        }
                        break;

                    case "RawNegativeX":
                        if (bdata2.ContainsKey(1) == true)
                        {
                            textureImageBlocks[i].FindNodes("TEXTUREIMAGEBLOCKDATA")[0].Value = bdata2[1];
                            textureImageBlocks[i].Attributes["size"].Value = (UInt32)bdata2[1].Length;
                        }
                        else
                        {
                            throw new Exception("Loading cubemap failed because not all blocks were found. (Write)");
                        }
                        break;

                    case "RawPositiveY":
                        if (bdata2.ContainsKey(2) == true)
                        {
                            textureImageBlocks[i].FindNodes("TEXTUREIMAGEBLOCKDATA")[0].Value = bdata2[2];
                            textureImageBlocks[i].Attributes["size"].Value = (UInt32)bdata2[2].Length;
                        }
                        else
                        {
                            throw new Exception("Loading cubemap failed because not all blocks were found. (Write)");
                        }
                        break;

                    case "RawNegativeY":
                        if (bdata2.ContainsKey(3) == true)
                        {
                            textureImageBlocks[i].FindNodes("TEXTUREIMAGEBLOCKDATA")[0].Value = bdata2[3];
                            textureImageBlocks[i].Attributes["size"].Value = (UInt32)bdata2[3].Length;
                        }
                        else
                        {
                            throw new Exception("Loading cubemap failed because not all blocks were found. (Write)");
                        }
                        break;

                    case "RawPositiveZ":
                        if (bdata2.ContainsKey(4) == true)
                        {
                            textureImageBlocks[i].FindNodes("TEXTUREIMAGEBLOCKDATA")[0].Value = bdata2[4];
                            textureImageBlocks[i].Attributes["size"].Value = (UInt32)bdata2[4].Length;
                        }
                        else
                        {
                            throw new Exception("Loading cubemap failed because not all blocks were found. (Write)");
                        }
                        break;

                    case "RawNegativeZ":
                        if (bdata2.ContainsKey(5) == true)
                        {
                            textureImageBlocks[i].FindNodes("TEXTUREIMAGEBLOCKDATA")[0].Value = bdata2[5];
                            textureImageBlocks[i].Attributes["size"].Value = (UInt32)bdata2[5].Length;
                        }
                        else
                        {
                            throw new Exception("Loading cubemap failed because not all blocks were found. (Write)");
                        }
                        break;
                    }
                }
            }
            else
            {
                if ((uint)node.Attributes["imageBlockCount"].Value > 1)
                {
                    throw new Exception("Loading cubemap failed because not all blocks were found. (Write)");
                }
                textureImageBlocks[0].FindNodes("TEXTUREIMAGEBLOCKDATA")[0].Value = bdata;
                textureImageBlocks[0].Attributes["size"].Value = (UInt32)bdata.Length;
            }
        }
示例#18
0
        //public static void CreatePssgInfo(out PssgNodeInfo[] nodeInfo, out PssgAttributeInfo[] attributeInfo)
        //{
        //    nodeInfo = new PssgNodeInfo[entries.Count];
        //    List<PssgAttributeInfo> attrInfo = new List<PssgAttributeInfo>();
        //    int i = 0, j = 0;
        //    foreach (KeyValuePair<string, Node> node in entries)
        //    {
        //        nodeInfo[i] = new PssgNodeInfo(i + 1, node.Key);
        //        foreach (Attribute attr in node.Value.Attributes)
        //        {
        //            attr.Id = ++j;
        //            PssgAttributeInfo aInfo = new PssgAttributeInfo(attr.Id, attr.Name);
        //            attrInfo.Add(aInfo);
        //            nodeInfo[i].attributeInfo.Add(attr.Id, aInfo);
        //        }
        //        node.Value.Id = ++i;
        //    }
        //    attributeInfo = attrInfo.ToArray();
        //}
        public static PssgSchema.Node AddNode(PssgNode node)
        {
            Node sNode = new Node(node.Name);
            sNode.DataType = node.ValueType;

            foreach (PssgAttribute attr in node.Attributes)
            {
                Attribute sAttr = new Attribute(attr.Name, attr.ValueType);
                sNode.Attributes.Add(sAttr);
            }

            PssgSchema.AddNode(sNode);
            return sNode;
        }
示例#19
0
        public static PssgSchema.Node RenameNode(PssgNode pssgNode, string nodeName)
        {
            PssgSchema.Node node = PssgSchema.AddNode(nodeName);

            foreach (PssgAttribute attr in pssgNode.Attributes)
            {
                PssgSchema.AddAttribute(node.Name, attr.AttributeInfo.Name, attr.AttributeInfo.DataType);
            }

            return node;
        }
示例#20
0
        public PssgNode(XElement elem, PssgFile file, PssgNode node)
        {
            this.File = file;
            this.ParentNode = node;
            this.NodeInfo = PssgSchema.AddNode(elem.Name.LocalName);// PssgSchema.GetNode(elem.Name.LocalName);

            this.Attributes = new PssgAttributeCollection();
            PssgAttribute attr;
            foreach (XAttribute xAttr in elem.Attributes())
            {
                attr = new PssgAttribute(xAttr, file, this);
                this.Attributes.Add(attr);
            }

            // Add data, and sub nodes code here
            if (elem.FirstNode != null && elem.FirstNode is XText)
            {
                this.data = this.FromString(elem.Value);
                this.ChildNodes = new PssgNodeCollection();
            }
            else
            {
                this.data = new byte[0];
                this.ChildNodes = new PssgNodeCollection(elem.Elements().Count());
                int nodeCount = 0;
                foreach (XElement subElem in elem.Elements())
                {
                    this.ChildNodes.Add(new PssgNode(subElem, file, this));
                    ++nodeCount;
                }
            }
            PssgSchema.SetNodeDataTypeIfNull(this.NodeInfo, this.ValueType);
        }
示例#21
0
 public PssgFile(PssgFileType fileType)
 {
     this.FileType = fileType;
     this.RootNode = new PssgNode("PSSGDATABASE", this, null);
 }
示例#22
0
 private void CubeMapCreatePreview(PssgNode node, int targetCount)
 {
     // Make Preview
     try
     {
         cubeMapImageLabel.Text = "";
         int height = 0; int width = 0;
         cubeMapPictureBox.Dock = DockStyle.Fill;
         height = cubeMapPictureBox.Height;
         width = cubeMapPictureBox.Width;
         FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_DDS;
         System.Drawing.Bitmap image = null;
         if (targetCount > 5)
         {
             targetCount = 0;
             cubeMapPictureBox.Tag = 0;
         }
         else
         {
             cubeMapPictureBox.Tag = targetCount;
         }
         DdsFile dds = new DdsFile(node, false);
         dds.Write(File.Open(Application.StartupPath + "\\temp.dds", FileMode.Create), targetCount);
         image = FreeImage.LoadBitmap(Application.StartupPath + "\\temp.dds", FREE_IMAGE_LOAD_FLAGS.DEFAULT, ref format);
         if (cubeMapPictureBox.Image != null)
         {
             cubeMapPictureBox.Image.Dispose();
             cubeMapPictureBox.Image = null;
         }
         /*foreach (CNode sub in node.subNodes) {
             if (targetCount == 0 && sub.attributes["typename"].ToString() == "Raw") {
                 CubeMapWriteDDS(Application.StartupPath + "\\temp" + "Raw" + ".dds", node, targetCount);
                 image = FreeImage.LoadBitmap(Application.StartupPath + "\\temp" + "Raw" + ".dds", FREE_IMAGE_LOAD_FLAGS.DEFAULT, ref format);
             } else if (targetCount == 1 && sub.attributes["typename"].ToString() == "RawNegativeX") {
                 CubeMapWriteDDS(Application.StartupPath + "\\temp" + "RawNegativeX" + ".dds", node, targetCount);
                 image = FreeImage.LoadBitmap(Application.StartupPath + "\\temp" + "RawNegativeX" + ".dds", FREE_IMAGE_LOAD_FLAGS.DEFAULT, ref format);
             } else if (targetCount == 2 && sub.attributes["typename"].ToString() == "RawPositiveY") {
                 CubeMapWriteDDS(Application.StartupPath + "\\temp" + "RawPositiveY" + ".dds", node, targetCount);
                 image = FreeImage.LoadBitmap(Application.StartupPath + "\\temp" + "RawPositiveY" + ".dds", FREE_IMAGE_LOAD_FLAGS.DEFAULT, ref format);
             } else if (targetCount == 3 && sub.attributes["typename"].ToString() == "RawNegativeY") {
                 CubeMapWriteDDS(Application.StartupPath + "\\temp" + "RawNegativeY" + ".dds", node, targetCount);
                 image = FreeImage.LoadBitmap(Application.StartupPath + "\\temp" + "RawNegativeY" + ".dds", FREE_IMAGE_LOAD_FLAGS.DEFAULT, ref format);
             } else if (targetCount == 4 && sub.attributes["typename"].ToString() == "RawPositiveZ") {
                 CubeMapWriteDDS(Application.StartupPath + "\\temp" + "RawPositiveZ" + ".dds", node, targetCount);
                 image = FreeImage.LoadBitmap(Application.StartupPath + "\\temp" + "RawPositiveZ" + ".dds", FREE_IMAGE_LOAD_FLAGS.DEFAULT, ref format);
             } else if (targetCount == 5 && sub.attributes["typename"].ToString() == "RawNegativeZ") {
                 CubeMapWriteDDS(Application.StartupPath + "\\temp" + "RawNegativeZ" + ".dds", node, targetCount);
                 image = FreeImage.LoadBitmap(Application.StartupPath + "\\temp" + "RawNegativeZ" + ".dds", FREE_IMAGE_LOAD_FLAGS.DEFAULT, ref format);
             }
         }*/
         if (image.Height <= height && image.Width <= width)
         {
             cubeMapPictureBox.Dock = DockStyle.None;
             cubeMapPictureBox.Width = image.Width;
             cubeMapPictureBox.Height = image.Height;
         }
         cubeMapPictureBox.Image = image;
     }
     catch
     {
         if (cubeMapPictureBox.Image != null)
         {
             cubeMapPictureBox.Image.Dispose();
             cubeMapPictureBox.Image = null;
         }
         cubeMapImageLabel.Text = "Could not create preview!";
         //MessageBox.Show("Could not create preview!", "No Preview", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
     }
 }
示例#23
0
 public PssgNode(string name, PssgFile file, PssgNode node)
 {
     this.File = file;
     this.ParentNode = node;
     this.NodeInfo = PssgSchema.AddNode(name);
     this.Attributes = new PssgAttributeCollection();
     this.data = new byte[0];
     this.ChildNodes = new PssgNodeCollection();
 }
示例#24
0
 public void MoveNode(PssgNode source, PssgNode target)
 {
     source.ParentNode.RemoveChild(source);
     target.AppendChild(source);
 }
示例#25
0
 public void Write(PssgNode node)
 {
     node.Attributes["height"].Value = header.height;
     node.Attributes["width"].Value = header.width;
     if (node.HasAttribute("numberMipMapLevels") == true)
     {
         if ((int)header.mipMapCount - 1 >= 0)
         {
             node.Attributes["numberMipMapLevels"].Value = header.mipMapCount - 1;
         }
         else
         {
             node.Attributes["numberMipMapLevels"].Value = 0u;
         }
     }
     if (header.ddspf.rGBBitCount == 32)
     {
         node.Attributes["texelFormat"].Value = "ui8x4";
     }
     else if (header.ddspf.rGBBitCount == 8)
     {
         node.Attributes["texelFormat"].Value = "u8";
     }
     else
     {
         node.Attributes["texelFormat"].Value = Encoding.UTF8.GetString(BitConverter.GetBytes(header.ddspf.fourCC)).ToLower();
     }
     List<PssgNode> textureImageBlocks = node.FindNodes("TEXTUREIMAGEBLOCK");
     if (bdata2 != null && bdata2.Count > 0)
     {
         for (int i = 0; i < textureImageBlocks.Count; i++)
         {
             switch (textureImageBlocks[i].Attributes["typename"].ToString())
             {
                 case "Raw":
                     if (bdata2.ContainsKey(0) == true)
                     {
                         textureImageBlocks[i].FindNodes("TEXTUREIMAGEBLOCKDATA")[0].Value = bdata2[0];
                         textureImageBlocks[i].Attributes["size"].Value = (UInt32)bdata2[0].Length;
                     }
                     else
                     {
                         throw new Exception("Loading cubemap failed because not all blocks were found. (Write)");
                     }
                     break;
                 case "RawNegativeX":
                     if (bdata2.ContainsKey(1) == true)
                     {
                         textureImageBlocks[i].FindNodes("TEXTUREIMAGEBLOCKDATA")[0].Value = bdata2[1];
                         textureImageBlocks[i].Attributes["size"].Value = (UInt32)bdata2[1].Length;
                     }
                     else
                     {
                         throw new Exception("Loading cubemap failed because not all blocks were found. (Write)");
                     }
                     break;
                 case "RawPositiveY":
                     if (bdata2.ContainsKey(2) == true)
                     {
                         textureImageBlocks[i].FindNodes("TEXTUREIMAGEBLOCKDATA")[0].Value = bdata2[2];
                         textureImageBlocks[i].Attributes["size"].Value = (UInt32)bdata2[2].Length;
                     }
                     else
                     {
                         throw new Exception("Loading cubemap failed because not all blocks were found. (Write)");
                     }
                     break;
                 case "RawNegativeY":
                     if (bdata2.ContainsKey(3) == true)
                     {
                         textureImageBlocks[i].FindNodes("TEXTUREIMAGEBLOCKDATA")[0].Value = bdata2[3];
                         textureImageBlocks[i].Attributes["size"].Value = (UInt32)bdata2[3].Length;
                     }
                     else
                     {
                         throw new Exception("Loading cubemap failed because not all blocks were found. (Write)");
                     }
                     break;
                 case "RawPositiveZ":
                     if (bdata2.ContainsKey(4) == true)
                     {
                         textureImageBlocks[i].FindNodes("TEXTUREIMAGEBLOCKDATA")[0].Value = bdata2[4];
                         textureImageBlocks[i].Attributes["size"].Value = (UInt32)bdata2[4].Length;
                     }
                     else
                     {
                         throw new Exception("Loading cubemap failed because not all blocks were found. (Write)");
                     }
                     break;
                 case "RawNegativeZ":
                     if (bdata2.ContainsKey(5) == true)
                     {
                         textureImageBlocks[i].FindNodes("TEXTUREIMAGEBLOCKDATA")[0].Value = bdata2[5];
                         textureImageBlocks[i].Attributes["size"].Value = (UInt32)bdata2[5].Length;
                     }
                     else
                     {
                         throw new Exception("Loading cubemap failed because not all blocks were found. (Write)");
                     }
                     break;
             }
         }
     }
     else
     {
         if ((uint)node.Attributes["imageBlockCount"].Value > 1)
         {
             throw new Exception("Loading cubemap failed because not all blocks were found. (Write)");
         }
         textureImageBlocks[0].FindNodes("TEXTUREIMAGEBLOCKDATA")[0].Value = bdata;
         textureImageBlocks[0].Attributes["size"].Value = (UInt32)bdata.Length;
     }
 }
示例#26
0
 public DdsFile(PssgNode node, bool cubePreview)
 {
     magic = 0x20534444;
     header.size = 124;
     header.flags |= DdsHeader.Flags.DDSD_CAPS | DdsHeader.Flags.DDSD_HEIGHT | DdsHeader.Flags.DDSD_WIDTH | DdsHeader.Flags.DDSD_PIXELFORMAT;
     header.height = (uint)(node.Attributes["height"].Value);
     header.width = (uint)(node.Attributes["width"].Value);
     switch ((string)node.Attributes["texelFormat"].Value)
     {
             // gimp doesn't like pitch, so we'll go with linear size
         case "dxt1":
             header.flags |= DdsHeader.Flags.DDSD_LINEARSIZE;
             header.pitchOrLinearSize = ((uint)node.Attributes["height"].Value * (uint)node.Attributes["width"].Value) / 2;
             header.ddspf.flags |= DdsPixelFormat.Flags.DDPF_FOURCC;
             header.ddspf.fourCC = BitConverter.ToUInt32(Encoding.UTF8.GetBytes(((string)node.Attributes["texelFormat"].Value).ToUpper()), 0);
             break;
         case "dxt1_srgb":
             header.flags |= DdsHeader.Flags.DDSD_LINEARSIZE;
             header.pitchOrLinearSize = ((uint)node.Attributes["height"].Value * (uint)node.Attributes["width"].Value) / 2;
             header.ddspf.flags |= DdsPixelFormat.Flags.DDPF_FOURCC;
             header.ddspf.fourCC = BitConverter.ToUInt32(Encoding.UTF8.GetBytes("DXT1"), 0);
             break;
         case "dxt2":
         case "dxt3":
         case "dxt4":
         case "dxt5":
             header.flags |= DdsHeader.Flags.DDSD_LINEARSIZE;
             header.pitchOrLinearSize = ((uint)node.Attributes["height"].Value * (uint)node.Attributes["width"].Value);
             header.ddspf.flags |= DdsPixelFormat.Flags.DDPF_FOURCC;
             header.ddspf.fourCC = BitConverter.ToUInt32(Encoding.UTF8.GetBytes(((string)node.Attributes["texelFormat"].Value).ToUpper()), 0);
             break;
         case "dxt5_srgb":
             header.flags |= DdsHeader.Flags.DDSD_LINEARSIZE;
             header.pitchOrLinearSize = ((uint)node.Attributes["height"].Value * (uint)node.Attributes["width"].Value);
             header.ddspf.flags |= DdsPixelFormat.Flags.DDPF_FOURCC;
             header.ddspf.fourCC = BitConverter.ToUInt32(Encoding.UTF8.GetBytes("DXT5"), 0);
             break;
         case "ui8x4":
             header.flags |= DdsHeader.Flags.DDSD_LINEARSIZE;
             header.pitchOrLinearSize = ((uint)node.Attributes["height"].Value * (uint)node.Attributes["width"].Value); // is this right?
             header.ddspf.flags |= DdsPixelFormat.Flags.DDPF_ALPHAPIXELS | DdsPixelFormat.Flags.DDPF_RGB;
             header.ddspf.fourCC = 0;
             header.ddspf.rGBBitCount = 32;
             header.ddspf.rBitMask = 0xFF0000;
             header.ddspf.gBitMask = 0xFF00;
             header.ddspf.bBitMask = 0xFF;
             header.ddspf.aBitMask = 0xFF000000;
             break;
         case "u8":
             header.flags |= DdsHeader.Flags.DDSD_LINEARSIZE;
             header.pitchOrLinearSize = ((uint)node.Attributes["height"].Value * (uint)node.Attributes["width"].Value); // is this right?
             // Interchanging the commented values will both work, not sure which is better
             header.ddspf.flags |= DdsPixelFormat.Flags.DDPF_LUMINANCE;
             //header.ddspf.flags |= DDS_PIXELFORMAT.Flags.DDPF_ALPHA;
             header.ddspf.fourCC = 0;
             header.ddspf.rGBBitCount = 8;
             header.ddspf.rBitMask = 0xFF;
             //header.ddspf.aBitMask = 0xFF;
             break;
     }
     if (node.HasAttribute("automipmap") == true && node.HasAttribute("numberMipMapLevels") == true)
     {
         if ((uint)node.Attributes["automipmap"].Value == 0 && (uint)node.Attributes["numberMipMapLevels"].Value > 0)
         {
             header.flags |= DdsHeader.Flags.DDSD_MIPMAPCOUNT;
             header.mipMapCount = (uint)((uint)node.Attributes["numberMipMapLevels"].Value + 1);
             header.caps |= DdsHeader.Caps.DDSCAPS_MIPMAP | DdsHeader.Caps.DDSCAPS_COMPLEX;
         }
     }
     header.reserved1 = new uint[11];
     header.ddspf.size = 32;
     header.caps |= DdsHeader.Caps.DDSCAPS_TEXTURE;
     List<PssgNode> textureImageBlocks = node.FindNodes("TEXTUREIMAGEBLOCK");
     if ((uint)node.Attributes["imageBlockCount"].Value > 1)
     {
         bdata2 = new Dictionary<int, byte[]>();
         for (int i = 0; i < textureImageBlocks.Count; i++)
         {
             switch (textureImageBlocks[i].Attributes["typename"].ToString())
             {
                 case "Raw":
                     header.caps2 |= DdsHeader.Caps2.DDSCAPS2_CUBEMAP_POSITIVEX;
                     bdata2.Add(0, (byte[])textureImageBlocks[i].FindNodes("TEXTUREIMAGEBLOCKDATA")[0].Value);
                     break;
                 case "RawNegativeX":
                     header.caps2 |= DdsHeader.Caps2.DDSCAPS2_CUBEMAP_NEGATIVEX;
                     bdata2.Add(1, (byte[])textureImageBlocks[i].FindNodes("TEXTUREIMAGEBLOCKDATA")[0].Value);
                     break;
                 case "RawPositiveY":
                     header.caps2 |= DdsHeader.Caps2.DDSCAPS2_CUBEMAP_POSITIVEY;
                     bdata2.Add(2, (byte[])textureImageBlocks[i].FindNodes("TEXTUREIMAGEBLOCKDATA")[0].Value);
                     break;
                 case "RawNegativeY":
                     header.caps2 |= DdsHeader.Caps2.DDSCAPS2_CUBEMAP_NEGATIVEY;
                     bdata2.Add(3, (byte[])textureImageBlocks[i].FindNodes("TEXTUREIMAGEBLOCKDATA")[0].Value);
                     break;
                 case "RawPositiveZ":
                     header.caps2 |= DdsHeader.Caps2.DDSCAPS2_CUBEMAP_POSITIVEZ;
                     bdata2.Add(4, (byte[])textureImageBlocks[i].FindNodes("TEXTUREIMAGEBLOCKDATA")[0].Value);
                     break;
                 case "RawNegativeZ":
                     header.caps2 |= DdsHeader.Caps2.DDSCAPS2_CUBEMAP_NEGATIVEZ;
                     bdata2.Add(5, (byte[])textureImageBlocks[i].FindNodes("TEXTUREIMAGEBLOCKDATA")[0].Value);
                     break;
             }
         }
         if (cubePreview == true)
         {
             header.caps2 = 0;
         }
         else if (bdata2.Count == (uint)node.Attributes["imageBlockCount"].Value)
         {
             header.caps2 |= DdsHeader.Caps2.DDSCAPS2_CUBEMAP;
             header.flags = header.flags ^ DdsHeader.Flags.DDSD_LINEARSIZE;
             header.pitchOrLinearSize = 0;
             header.caps |= DdsHeader.Caps.DDSCAPS_COMPLEX;
         }
         else
         {
             throw new Exception("Loading cubemap failed because not all blocks were found. (Read)");
         }
     }
     else
     {
         bdata = (byte[])textureImageBlocks[0].FindNodes("TEXTUREIMAGEBLOCKDATA")[0].Value;
     }
 }
示例#27
0
 public PssgNode SetChild(PssgNode childNode, PssgNode newChildNode)
 {
     newChildNode.File = this.File;
     newChildNode.ParentNode = this;
     PssgNode node = this.ChildNodes.Set(childNode, newChildNode);
     if (node != null) node.NodeInfo = PssgSchema.AddNode(node);
     return node;
 }
示例#28
0
 public void RemoveChild(PssgNode childNode)
 {
     this.ChildNodes.Remove(childNode);
     childNode.ParentNode = null;
     childNode.File = null;
 }
示例#29
0
 private void createPreview(PssgNode node)
 {
     // Make Preview
     try
     {
         textureImageLabel.Text = "";
         int height = 0; int width = 0;
         texturePictureBox.Dock = DockStyle.Fill;
         height = texturePictureBox.Height;
         width = texturePictureBox.Width;
         DdsFile dds = new DdsFile(node, false);
         dds.Write(File.Open(Application.StartupPath + "\\temp.dds", FileMode.Create, FileAccess.ReadWrite, FileShare.Read), -1);
         // Dispose of Old Images
         if (texturePictureBox.Image != null)
         {
             texturePictureBox.Image.Dispose();
             texturePictureBox.Image = null;
         }
         // Setup New Image
         FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_DDS;
         System.Drawing.Bitmap image = FreeImage.LoadBitmap(Application.StartupPath + "\\temp.dds", FREE_IMAGE_LOAD_FLAGS.DEFAULT, ref format);
         if (image.Height <= height && image.Width <= width)
         {
             texturePictureBox.Dock = DockStyle.None;
             texturePictureBox.Width = image.Width;
             texturePictureBox.Height = image.Height;
         }
         texturePictureBox.Image = image;
     }
     catch (Exception ex)
     {
         if (texturePictureBox.Image != null)
         {
             texturePictureBox.Image.Dispose();
             texturePictureBox.Image = null;
         }
         textureImageLabel.Text = "Could not create preview! Export/Import may still work in certain circumstances." + Environment.NewLine + Environment.NewLine + ex.Message;
         //MessageBox.Show("Could not create preview! Export/Import may still work in certain circumstances." + Environment.NewLine + Environment.NewLine
         //	+ ex.Message, "No Preview", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
     }
 }
示例#30
0
 private void createView(PssgNode node)
 {
     // Determine if we need a DataGridView or a RichTextBox based on data to be displayed
     dataGridView.Rows.Clear();
     dataGridView.TopLeftHeaderCell.Value = node.Name;
     int i = 0;
     foreach (PssgAttribute pair in node.Attributes)
     {
         dataGridView.Rows.Add(pair.Value);
         dataGridView.Rows[i].HeaderCell.Value = pair.Name;
         dataGridView.Rows[i].Cells[0].ValueType = pair.ValueType;
         dataGridView.Rows[i].Tag = pair;
         i++;
     }
     dataGridView.Tag = node;
     dataGridView.BringToFront();
     if (node.IsDataNode)
     {
         richTextBox1.Text = node.ToString();//EndianBitConverter.ToString(node.data);
         richTextBox1.Visible = true;
         if (node.Attributes.Count == 0)
         {
             richTextBox1.Dock = DockStyle.Fill;
             richTextBox1.BringToFront();
         }
         else
         {
             richTextBox1.Dock = DockStyle.Bottom;
             richTextBox1.Size = new System.Drawing.Size(richTextBox1.Size.Width, 214);
             dataGridView.BringToFront();
         }
     }
     else
     {
         richTextBox1.Visible = false;
     }
 }
 public TreeNode CreateTreeViewNode(PssgNode node)
 {
     TreeNode treeNode = new TreeNode();
     treeNode.Text = node.Name;
     treeNode.Tag = node;
     if (node.ChildNodes != null)
     {
         foreach (PssgNode subNode in node.ChildNodes)
         {
             treeNode.Nodes.Add(CreateTreeViewNode(subNode));
         }
     }
     node.TreeNode = treeNode;
     return treeNode;
 }
示例#32
0
        private void importNodeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();
            dialog.Filter = "Xml files|*.xml|All files|*.*";
            dialog.Title = "Select a xml file";
            dialog.FileName = "node.xml";
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    PssgNode node = ((PssgNode)treeView.SelectedNode.Tag);
                    using (FileStream fileStream = File.Open(dialog.FileName, FileMode.Open, FileAccess.Read, FileShare.Read))
                    {
                        XDocument xDoc = XDocument.Load(fileStream);

                        PssgNode newNode = new PssgNode((XElement)((XElement)xDoc.FirstNode).FirstNode, pssg, node.ParentNode);
                        if (node.ParentNode != null)
                        {
                            node = node.ParentNode.SetChild(node, newNode);
                        }
                        else
                        {
                            node.File.RootNode = newNode;
                        }
                    }

                    clearVars(false);
                    setupEditor(MainTabs.All);
                    treeView.SelectedNode = node.TreeNode;
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Could not import the node!" + Environment.NewLine + Environment.NewLine +
                        ex.Message, "Import Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
 public void MoveNode(PssgNode source, PssgNode target)
 {
     source.ParentNode.RemoveChild(source);
     target.AppendChild(source);
 }
示例#34
0
        public PssgNode(PssgNode nodeToCopy)
        {
            this.File = nodeToCopy.File;
            this.ParentNode = nodeToCopy.ParentNode;

            this.NodeInfo = nodeToCopy.NodeInfo;
            this.size = nodeToCopy.size;
            this.attributeSize = nodeToCopy.attributeSize;
            this.Attributes = new PssgAttributeCollection();
            PssgAttribute attr;
            foreach (PssgAttribute attrToCopy in nodeToCopy.Attributes)
            {
                attr = new PssgAttribute(attrToCopy);
                this.Attributes.Add(attr);
            }

            if (nodeToCopy.IsDataNode)
            {
                this.data = nodeToCopy.data;
                this.ChildNodes = new PssgNodeCollection();
            }
            else
            {
                this.data = new byte[0];
                // Each node at least 12 bytes (id + size + arg size)
                this.ChildNodes = new PssgNodeCollection(nodeToCopy.ChildNodes.Count);
                int nodeCount = 0;
                foreach (PssgNode subNodeToCopy in nodeToCopy.ChildNodes)
                {
                    this.ChildNodes.Add(new PssgNode(subNodeToCopy));
                    nodeCount++;
                }
            }
        }
        public static DdsFile ToDdsFile(this PssgNode node, bool cubePreview)
        {
            DdsFile dds = new DdsFile();

            dds.header.height = (uint)(node.Attributes["height"].Value);
            dds.header.width  = (uint)(node.Attributes["width"].Value);
            switch ((string)node.Attributes["texelFormat"].Value)
            {
            // gimp doesn't like pitch, so we'll go with linear size
            case "dxt1":
                dds.header.flags            |= DdsHeader.Flags.DDSD_LINEARSIZE;
                dds.header.pitchOrLinearSize = ((uint)node.Attributes["height"].Value * (uint)node.Attributes["width"].Value) / 2;
                dds.header.ddspf.flags      |= DdsPixelFormat.Flags.DDPF_FOURCC;
                dds.header.ddspf.fourCC      = BitConverter.ToUInt32(Encoding.UTF8.GetBytes(((string)node.Attributes["texelFormat"].Value).ToUpper()), 0);
                break;

            case "dxt1_srgb":
                dds.header.flags            |= DdsHeader.Flags.DDSD_LINEARSIZE;
                dds.header.pitchOrLinearSize = ((uint)node.Attributes["height"].Value * (uint)node.Attributes["width"].Value) / 2;
                dds.header.ddspf.flags      |= DdsPixelFormat.Flags.DDPF_FOURCC;
                dds.header.ddspf.fourCC      = BitConverter.ToUInt32(Encoding.UTF8.GetBytes("DX10"), 0);
                dds.header10.dxgiFormat      = DXGI_Format.DXGI_FORMAT_BC1_UNORM_SRGB;
                break;

            case "dxt2":
            case "dxt3":
            case "dxt4":
            case "dxt5":
                dds.header.flags            |= DdsHeader.Flags.DDSD_LINEARSIZE;
                dds.header.pitchOrLinearSize = ((uint)node.Attributes["height"].Value * (uint)node.Attributes["width"].Value);
                dds.header.ddspf.flags      |= DdsPixelFormat.Flags.DDPF_FOURCC;
                dds.header.ddspf.fourCC      = BitConverter.ToUInt32(Encoding.UTF8.GetBytes(((string)node.Attributes["texelFormat"].Value).ToUpper()), 0);
                break;

            case "dxt3_srgb":
                dds.header.flags            |= DdsHeader.Flags.DDSD_LINEARSIZE;
                dds.header.pitchOrLinearSize = ((uint)node.Attributes["height"].Value * (uint)node.Attributes["width"].Value);
                dds.header.ddspf.flags      |= DdsPixelFormat.Flags.DDPF_FOURCC;
                dds.header.ddspf.fourCC      = BitConverter.ToUInt32(Encoding.UTF8.GetBytes("DX10"), 0);
                dds.header10.dxgiFormat      = DXGI_Format.DXGI_FORMAT_BC2_UNORM_SRGB;
                break;

            case "dxt5_srgb":
                dds.header.flags            |= DdsHeader.Flags.DDSD_LINEARSIZE;
                dds.header.pitchOrLinearSize = ((uint)node.Attributes["height"].Value * (uint)node.Attributes["width"].Value);
                dds.header.ddspf.flags      |= DdsPixelFormat.Flags.DDPF_FOURCC;
                dds.header.ddspf.fourCC      = BitConverter.ToUInt32(Encoding.UTF8.GetBytes("DX10"), 0);
                dds.header10.dxgiFormat      = DXGI_Format.DXGI_FORMAT_BC3_UNORM_SRGB;
                break;

            case "BC7":
                dds.header.flags            |= DdsHeader.Flags.DDSD_LINEARSIZE;
                dds.header.pitchOrLinearSize = ((uint)node.Attributes["height"].Value * (uint)node.Attributes["width"].Value);
                dds.header.ddspf.flags      |= DdsPixelFormat.Flags.DDPF_FOURCC;
                dds.header.ddspf.fourCC      = BitConverter.ToUInt32(Encoding.UTF8.GetBytes("DX10"), 0);
                dds.header10.dxgiFormat      = DXGI_Format.DXGI_FORMAT_BC7_UNORM;
                break;

            case "BC7_srgb":
                dds.header.flags            |= DdsHeader.Flags.DDSD_LINEARSIZE;
                dds.header.pitchOrLinearSize = ((uint)node.Attributes["height"].Value * (uint)node.Attributes["width"].Value);
                dds.header.ddspf.flags      |= DdsPixelFormat.Flags.DDPF_FOURCC;
                dds.header.ddspf.fourCC      = BitConverter.ToUInt32(Encoding.UTF8.GetBytes("DX10"), 0);
                dds.header10.dxgiFormat      = DXGI_Format.DXGI_FORMAT_BC7_UNORM_SRGB;
                break;

            case "ui8x4":
            case "u8x4":
                dds.header.flags            |= DdsHeader.Flags.DDSD_PITCH;
                dds.header.pitchOrLinearSize = ((uint)node.Attributes["height"].Value * (uint)node.Attributes["width"].Value);     // is this right?
                dds.header.ddspf.flags      |= DdsPixelFormat.Flags.DDPF_ALPHAPIXELS | DdsPixelFormat.Flags.DDPF_RGB;
                dds.header.ddspf.fourCC      = 0;
                dds.header.ddspf.rGBBitCount = 32;
                dds.header.ddspf.rBitMask    = 0xFF0000;
                dds.header.ddspf.gBitMask    = 0xFF00;
                dds.header.ddspf.bBitMask    = 0xFF;
                dds.header.ddspf.aBitMask    = 0xFF000000;
                break;

            case "u8":
                dds.header.flags            |= DdsHeader.Flags.DDSD_PITCH;
                dds.header.pitchOrLinearSize = ((uint)node.Attributes["height"].Value * (uint)node.Attributes["width"].Value);     // is this right?
                // Interchanging the commented values will both work, not sure which is better
                dds.header.ddspf.flags |= DdsPixelFormat.Flags.DDPF_LUMINANCE;
                //header.ddspf.flags |= DDS_PIXELFORMAT.Flags.DDPF_ALPHA;
                dds.header.ddspf.fourCC      = 0;
                dds.header.ddspf.rGBBitCount = 8;
                dds.header.ddspf.rBitMask    = 0xFF;
                //header.ddspf.aBitMask = 0xFF;
                break;

            default:
                throw new NotSupportedException("Texel format not supported.");
            }

            // Mip Maps
            if (node.HasAttribute("automipmap") == true && node.HasAttribute("numberMipMapLevels") == true)
            {
                if ((uint)node.Attributes["automipmap"].Value == 0 && (uint)node.Attributes["numberMipMapLevels"].Value > 0)
                {
                    dds.header.flags      |= DdsHeader.Flags.DDSD_MIPMAPCOUNT;
                    dds.header.mipMapCount = (uint)((uint)node.Attributes["numberMipMapLevels"].Value + 1);
                    dds.header.caps       |= DdsHeader.Caps.DDSCAPS_MIPMAP | DdsHeader.Caps.DDSCAPS_COMPLEX;
                }
            }

            // Byte Data
            List <PssgNode> textureImageBlocks = node.FindNodes("TEXTUREIMAGEBLOCK");

            if ((uint)node.Attributes["imageBlockCount"].Value > 1)
            {
                dds.bdata2 = new Dictionary <int, byte[]>();
                for (int i = 0; i < textureImageBlocks.Count; i++)
                {
                    switch (textureImageBlocks[i].Attributes["typename"].ToString())
                    {
                    case "Raw":
                        dds.header.caps2 |= DdsHeader.Caps2.DDSCAPS2_CUBEMAP_POSITIVEX;
                        dds.bdata2.Add(0, (byte[])textureImageBlocks[i].FindNodes("TEXTUREIMAGEBLOCKDATA")[0].Value);
                        break;

                    case "RawNegativeX":
                        dds.header.caps2 |= DdsHeader.Caps2.DDSCAPS2_CUBEMAP_NEGATIVEX;
                        dds.bdata2.Add(1, (byte[])textureImageBlocks[i].FindNodes("TEXTUREIMAGEBLOCKDATA")[0].Value);
                        break;

                    case "RawPositiveY":
                        dds.header.caps2 |= DdsHeader.Caps2.DDSCAPS2_CUBEMAP_POSITIVEY;
                        dds.bdata2.Add(2, (byte[])textureImageBlocks[i].FindNodes("TEXTUREIMAGEBLOCKDATA")[0].Value);
                        break;

                    case "RawNegativeY":
                        dds.header.caps2 |= DdsHeader.Caps2.DDSCAPS2_CUBEMAP_NEGATIVEY;
                        dds.bdata2.Add(3, (byte[])textureImageBlocks[i].FindNodes("TEXTUREIMAGEBLOCKDATA")[0].Value);
                        break;

                    case "RawPositiveZ":
                        dds.header.caps2 |= DdsHeader.Caps2.DDSCAPS2_CUBEMAP_POSITIVEZ;
                        dds.bdata2.Add(4, (byte[])textureImageBlocks[i].FindNodes("TEXTUREIMAGEBLOCKDATA")[0].Value);
                        break;

                    case "RawNegativeZ":
                        dds.header.caps2 |= DdsHeader.Caps2.DDSCAPS2_CUBEMAP_NEGATIVEZ;
                        dds.bdata2.Add(5, (byte[])textureImageBlocks[i].FindNodes("TEXTUREIMAGEBLOCKDATA")[0].Value);
                        break;
                    }
                }
                if (cubePreview == true)
                {
                    dds.header.caps2 = 0;
                }
                else if (dds.bdata2.Count == (uint)node.Attributes["imageBlockCount"].Value)
                {
                    dds.header.caps2            |= DdsHeader.Caps2.DDSCAPS2_CUBEMAP;
                    dds.header.flags             = dds.header.flags ^ DdsHeader.Flags.DDSD_LINEARSIZE;
                    dds.header.pitchOrLinearSize = 0;
                    dds.header.caps |= DdsHeader.Caps.DDSCAPS_COMPLEX;
                }
                else
                {
                    throw new Exception("Loading cubemap failed because not all blocks were found. (Read)");
                }
            }
            else
            {
                dds.bdata = (byte[])textureImageBlocks[0].FindNodes("TEXTUREIMAGEBLOCKDATA")[0].Value;
            }

            return(dds);
        }
示例#36
0
        public PssgNode(PssgBinaryReader reader, PssgFile file, PssgNode node, bool useDataNodeCheck)
        {
            this.File       = file;
            this.ParentNode = node;

            int id = reader.ReadInt32();

            this.NodeInfo = PssgSchema.GetNode(id);
            this.size     = reader.ReadInt32();
            long end = reader.BaseStream.Position + size;

            this.attributeSize = reader.ReadInt32();
            long attributeEnd = reader.BaseStream.Position + attributeSize;

            if (attributeEnd > reader.BaseStream.Length || end > reader.BaseStream.Length)
            {
                throw new Exception("This file is improperly saved and not supported by this version of the PSSG editor." + Environment.NewLine + Environment.NewLine +
                                    "Get an older version of the program if you wish to take out its contents, but, put it back together using this program and a non-modded version of the pssg file.");
            }
            // Each attr is at least 8 bytes (id + size), so take a conservative guess
            this.Attributes = new PssgAttributeCollection();
            PssgAttribute attr;

            while (reader.BaseStream.Position < attributeEnd)
            {
                attr = new PssgAttribute(reader, file, this);
                this.Attributes.Add(attr);
            }

            bool isDataNode = false;

            switch (Name)
            {
            case "BOUNDINGBOX":
            case "DATA":
            case "DATABLOCKDATA":
            case "DATABLOCKBUFFERED":
            case "INDEXSOURCEDATA":
            case "INVERSEBINDMATRIX":
            case "MODIFIERNETWORKINSTANCEUNIQUEMODIFIERINPUT":
            case "NeAnimPacketData_B1":
            case "NeAnimPacketData_B4":
            case "RENDERINTERFACEBOUNDBUFFERED":
            case "SHADERINPUT":
            case "TEXTUREIMAGEBLOCKDATA":
            case "TRANSFORM":
                isDataNode = true;
                break;
            }
            if (isDataNode == false && useDataNodeCheck == true)
            {
                long currentPos = reader.BaseStream.Position;
                // Check if it has subnodes
                while (reader.BaseStream.Position < end)
                {
                    int tempID = reader.ReadInt32();
                    if (tempID < 0)//tempID > file.nodeInfo.Length ||
                    {
                        isDataNode = true;
                        break;
                    }
                    else
                    {
                        int tempSize = reader.ReadInt32();
                        if ((reader.BaseStream.Position + tempSize > end) || (tempSize == 0 && tempID == 0) || tempSize < 0)
                        {
                            isDataNode = true;
                            break;
                        }
                        else if (reader.BaseStream.Position + tempSize == end)
                        {
                            break;
                        }
                        else
                        {
                            reader.BaseStream.Position += tempSize;
                        }
                    }
                }
                reader.BaseStream.Position = currentPos;
            }

            if (isDataNode)
            {
                this.data       = reader.ReadNodeValue(GetValueType(), (int)(end - reader.BaseStream.Position));
                this.ChildNodes = new PssgNodeCollection();
                //data = reader.ReadBytes((int)(end - reader.BaseStream.Position));
            }
            else
            {
                this.data = new byte[0];
                // Each node at least 12 bytes (id + size + arg size)
                this.ChildNodes = new PssgNodeCollection((int)(end - reader.BaseStream.Position) / 12);
                int nodeCount = 0;
                while (reader.BaseStream.Position < end)
                {
                    this.ChildNodes.Add(new PssgNode(reader, file, this, useDataNodeCheck));
                    nodeCount++;
                }
            }
            PssgSchema.SetNodeDataTypeIfNull(this.NodeInfo, this.ValueType);
        }
        public static void ToPssgNode(this DdsFile dds, PssgNode node)
        {
            node.Attributes["height"].Value = dds.header.height;
            node.Attributes["width"].Value  = dds.header.width;
            if (node.HasAttribute("numberMipMapLevels") == true)
            {
                if ((int)dds.header.mipMapCount - 1 >= 0)
                {
                    node.Attributes["numberMipMapLevels"].Value = dds.header.mipMapCount - 1;
                }
                else
                {
                    node.Attributes["numberMipMapLevels"].Value = 0u;
                }
            }
            if (dds.header.ddspf.rGBBitCount == 32)
            {
                node.Attributes["texelFormat"].Value = "ui8x4";
            }
            else if (dds.header.ddspf.rGBBitCount == 8)
            {
                node.Attributes["texelFormat"].Value = "u8";
            }
            else if (dds.header.ddspf.fourCC == 808540228) //DX10
            {
                if (dds.header10.dxgiFormat == DXGI_Format.DXGI_FORMAT_BC7_TYPELESS ||
                    dds.header10.dxgiFormat == DXGI_Format.DXGI_FORMAT_BC7_UNORM)
                {
                    node.Attributes["texelFormat"].Value = "BC7";
                }
                else if (dds.header10.dxgiFormat == DXGI_Format.DXGI_FORMAT_BC7_UNORM_SRGB)
                {
                    node.Attributes["texelFormat"].Value = "BC7_srgb";
                }
                else if (dds.header10.dxgiFormat == DXGI_Format.DXGI_FORMAT_BC1_TYPELESS ||
                         dds.header10.dxgiFormat == DXGI_Format.DXGI_FORMAT_BC1_UNORM)
                {
                    node.Attributes["texelFormat"].Value = "dxt1";
                }
                else if (dds.header10.dxgiFormat == DXGI_Format.DXGI_FORMAT_BC1_UNORM_SRGB)
                {
                    node.Attributes["texelFormat"].Value = "dxt1_srgb";
                }
                else if (dds.header10.dxgiFormat == DXGI_Format.DXGI_FORMAT_BC2_TYPELESS ||
                         dds.header10.dxgiFormat == DXGI_Format.DXGI_FORMAT_BC2_UNORM)
                {
                    node.Attributes["texelFormat"].Value = "dxt3";
                }
                else if (dds.header10.dxgiFormat == DXGI_Format.DXGI_FORMAT_BC2_UNORM_SRGB)
                {
                    node.Attributes["texelFormat"].Value = "dxt3_srgb";
                }
                else if (dds.header10.dxgiFormat == DXGI_Format.DXGI_FORMAT_BC3_TYPELESS ||
                         dds.header10.dxgiFormat == DXGI_Format.DXGI_FORMAT_BC3_UNORM)
                {
                    node.Attributes["texelFormat"].Value = "dxt5";
                }
                else if (dds.header10.dxgiFormat == DXGI_Format.DXGI_FORMAT_BC3_UNORM_SRGB)
                {
                    node.Attributes["texelFormat"].Value = "dxt5_srgb";
                }
                else
                {
                    throw new FormatException("The dds has an invalid or unsupported format type!");
                }
            }
            else
            {
                node.Attributes["texelFormat"].Value = Encoding.UTF8.GetString(BitConverter.GetBytes(dds.header.ddspf.fourCC)).ToLower();
            }
            List <PssgNode> textureImageBlocks = node.FindNodes("TEXTUREIMAGEBLOCK");

            if (dds.bdata2 != null && dds.bdata2.Count > 0)
            {
                for (int i = 0; i < textureImageBlocks.Count; i++)
                {
                    switch (textureImageBlocks[i].Attributes["typename"].ToString())
                    {
                    case "Raw":
                        if (dds.bdata2.ContainsKey(0) == true)
                        {
                            textureImageBlocks[i].FindNodes("TEXTUREIMAGEBLOCKDATA")[0].Value = dds.bdata2[0];
                            textureImageBlocks[i].Attributes["size"].Value = (UInt32)dds.bdata2[0].Length;
                        }
                        else
                        {
                            throw new Exception("Loading cubemap failed because not all blocks were found. (Write)");
                        }
                        break;

                    case "RawNegativeX":
                        if (dds.bdata2.ContainsKey(1) == true)
                        {
                            textureImageBlocks[i].FindNodes("TEXTUREIMAGEBLOCKDATA")[0].Value = dds.bdata2[1];
                            textureImageBlocks[i].Attributes["size"].Value = (UInt32)dds.bdata2[1].Length;
                        }
                        else
                        {
                            throw new Exception("Loading cubemap failed because not all blocks were found. (Write)");
                        }
                        break;

                    case "RawPositiveY":
                        if (dds.bdata2.ContainsKey(2) == true)
                        {
                            textureImageBlocks[i].FindNodes("TEXTUREIMAGEBLOCKDATA")[0].Value = dds.bdata2[2];
                            textureImageBlocks[i].Attributes["size"].Value = (UInt32)dds.bdata2[2].Length;
                        }
                        else
                        {
                            throw new Exception("Loading cubemap failed because not all blocks were found. (Write)");
                        }
                        break;

                    case "RawNegativeY":
                        if (dds.bdata2.ContainsKey(3) == true)
                        {
                            textureImageBlocks[i].FindNodes("TEXTUREIMAGEBLOCKDATA")[0].Value = dds.bdata2[3];
                            textureImageBlocks[i].Attributes["size"].Value = (UInt32)dds.bdata2[3].Length;
                        }
                        else
                        {
                            throw new Exception("Loading cubemap failed because not all blocks were found. (Write)");
                        }
                        break;

                    case "RawPositiveZ":
                        if (dds.bdata2.ContainsKey(4) == true)
                        {
                            textureImageBlocks[i].FindNodes("TEXTUREIMAGEBLOCKDATA")[0].Value = dds.bdata2[4];
                            textureImageBlocks[i].Attributes["size"].Value = (UInt32)dds.bdata2[4].Length;
                        }
                        else
                        {
                            throw new Exception("Loading cubemap failed because not all blocks were found. (Write)");
                        }
                        break;

                    case "RawNegativeZ":
                        if (dds.bdata2.ContainsKey(5) == true)
                        {
                            textureImageBlocks[i].FindNodes("TEXTUREIMAGEBLOCKDATA")[0].Value = dds.bdata2[5];
                            textureImageBlocks[i].Attributes["size"].Value = (UInt32)dds.bdata2[5].Length;
                        }
                        else
                        {
                            throw new Exception("Loading cubemap failed because not all blocks were found. (Write)");
                        }
                        break;
                    }
                }
            }
            else
            {
                if ((uint)node.Attributes["imageBlockCount"].Value > 1)
                {
                    throw new Exception("Loading cubemap failed because not all blocks were found. (Write)");
                }
                textureImageBlocks[0].FindNodes("TEXTUREIMAGEBLOCKDATA")[0].Value = dds.bdata;
                textureImageBlocks[0].Attributes["size"].Value = (UInt32)dds.bdata.Length;
            }
        }
示例#38
0
        private void tag()
        {
            PssgNode node;
            if (pssg.RootNode == null)
            {
                node = new PssgNode("PSSGDATABASE", pssg, null);
                pssg.RootNode = node;
                setupEditor(MainTabs.All);
            }
            else
            {
                node = pssg.RootNode;
            }

            PssgAttribute attribute = node.AddAttribute("creatorApplication", "EgoPSSGEditor 10.2");
        }
示例#39
0
        private void addTextureToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (textureTreeView.SelectedNode == null)
            {
                MessageBox.Show("Select a texture to copy first!", "Select a Texture", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            AddTexture ATForm = new AddTexture(idTextBox.Text + "_2");
            if (ATForm.ShowDialog() == DialogResult.OK)
            {
                // Copy and Edit Name
                PssgNode nodeToCopy = (PssgNode)textureTreeView.SelectedNode.Tag;
                PssgNode newTexture = new PssgNode(nodeToCopy);
                newTexture.Attributes["id"].Value = ATForm.TName;
                // Add to Library
                if (nodeToCopy.ParentNode != null)
                {
                    nodeToCopy.ParentNode.AppendChild(newTexture);
                }
                else
                {
                    nodeToCopy.AppendChild(newTexture);
                }
                // Populate treeViews
                clearVars(false);
                setupEditor(MainTabs.Textures);
                textureTreeView.SelectedNode = textureTreeView.Nodes[textureTreeView.Nodes.Count - 1];
            }
        }
 public PssgAttribute(PssgSchema.Attribute attributeInfo, object data, PssgFile file, PssgNode ParentNode)
 {
     this.AttributeInfo = attributeInfo;
     this.data          = data;
     this.file          = file;
     this.ParentNode    = ParentNode;
 }
示例#41
0
 private void allTvAddNode()
 {
     PssgNode parentNode = pssg.RootNode == null ? null : ((PssgNode)treeView.SelectedNode.Tag);
     using (AddBox aBox = new AddBox(pssg, 0))
     {
         if (aBox.ShowDialog() == DialogResult.OK)
         {
             PssgNode newNode;
             if (pssg.RootNode == null)
             {
                 newNode = new PssgNode(aBox.NodeName, pssg, null);
                 pssg.RootNode = newNode;
             }
             else
             {
                 newNode = parentNode.AppendChild(aBox.NodeName);
             }
             if (newNode == null)
             {
                 return;
             }
             TreeNode newTreeNode = pssg.CreateTreeViewNode(newNode);
             if (parentNode == null)
                 treeView.Nodes.Add(newTreeNode);
             else
                 treeView.SelectedNode.Nodes.Add(newTreeNode);
             treeView.SelectedNode = newTreeNode;
         }
     }
 }
示例#42
0
 public void RemoveChild(PssgNode childNode)
 {
     this.ChildNodes.Remove(childNode);
     childNode.ParentNode = null;
     childNode.File       = null;
 }
示例#43
0
        public PssgNode(PssgBinaryReader reader, PssgFile file, PssgNode node, bool useDataNodeCheck)
        {
            this.File = file;
            this.ParentNode = node;

            int id = reader.ReadInt32();
            this.NodeInfo = PssgSchema.GetNode(id);
            this.size = reader.ReadInt32();
            long end = reader.BaseStream.Position + size;

            this.attributeSize = reader.ReadInt32();
            long attributeEnd = reader.BaseStream.Position + attributeSize;
            if (attributeEnd > reader.BaseStream.Length || end > reader.BaseStream.Length)
            {
                throw new Exception("This file is improperly saved and not supported by this version of the PSSG editor." + Environment.NewLine + Environment.NewLine +
                            "Get an older version of the program if you wish to take out its contents, but, put it back together using this program and a non-modded version of the pssg file.");
            }
            // Each attr is at least 8 bytes (id + size), so take a conservative guess
            this.Attributes = new PssgAttributeCollection();
            PssgAttribute attr;
            while (reader.BaseStream.Position < attributeEnd)
            {
                attr = new PssgAttribute(reader, file, this);
                this.Attributes.Add(attr);
            }

            bool isDataNode = false;
            switch (Name)
            {
                case "BOUNDINGBOX":
                case "DATA":
                case "DATABLOCKDATA":
                case "DATABLOCKBUFFERED":
                case "INDEXSOURCEDATA":
                case "INVERSEBINDMATRIX":
                case "MODIFIERNETWORKINSTANCEUNIQUEMODIFIERINPUT":
                case "NeAnimPacketData_B1":
                case "NeAnimPacketData_B4":
                case "RENDERINTERFACEBOUNDBUFFERED":
                case "SHADERINPUT":
                case "TEXTUREIMAGEBLOCKDATA":
                case "TRANSFORM":
                    isDataNode = true;
                    break;
            }
            if (isDataNode == false && useDataNodeCheck == true)
            {
                long currentPos = reader.BaseStream.Position;
                // Check if it has subnodes
                while (reader.BaseStream.Position < end)
                {
                    int tempID = reader.ReadInt32();
                    if (tempID < 0)//tempID > file.nodeInfo.Length ||
                    {
                        isDataNode = true;
                        break;
                    }
                    else
                    {
                        int tempSize = reader.ReadInt32();
                        if ((reader.BaseStream.Position + tempSize > end) || (tempSize == 0 && tempID == 0) || tempSize < 0)
                        {
                            isDataNode = true;
                            break;
                        }
                        else if (reader.BaseStream.Position + tempSize == end)
                        {
                            break;
                        }
                        else
                        {
                            reader.BaseStream.Position += tempSize;
                        }
                    }
                }
                reader.BaseStream.Position = currentPos;
            }

            if (isDataNode)
            {
                this.data = reader.ReadNodeValue(GetValueType(), (int)(end - reader.BaseStream.Position));
                this.ChildNodes = new PssgNodeCollection();
                //data = reader.ReadBytes((int)(end - reader.BaseStream.Position));
            }
            else
            {
                this.data = new byte[0];
                // Each node at least 12 bytes (id + size + arg size)
                this.ChildNodes = new PssgNodeCollection((int)(end - reader.BaseStream.Position) / 12);
                int nodeCount = 0;
                while (reader.BaseStream.Position < end)
                {
                    this.ChildNodes.Add(new PssgNode(reader, file, this, useDataNodeCheck));
                    nodeCount++;
                }
            }
            PssgSchema.SetNodeDataTypeIfNull(this.NodeInfo, this.ValueType);
        }