Exemple #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);
        }
        public PssgAttribute(PssgAttribute attrToCopy)
        {
            this.file = attrToCopy.file;
            this.ParentNode = attrToCopy.ParentNode;

            this.AttributeInfo = attrToCopy.AttributeInfo;
            this.size = attrToCopy.size;
            this.data = attrToCopy.data;
        }
        public PssgAttribute(PssgAttribute attrToCopy)
        {
            this.file       = attrToCopy.file;
            this.ParentNode = attrToCopy.ParentNode;

            this.AttributeInfo = attrToCopy.AttributeInfo;
            this.size          = attrToCopy.size;
            this.data          = attrToCopy.data;
        }
        private Type GetValueType()
        {
            PssgSchema.Node sNode = this.NodeInfo;// PssgSchema.GetNode(this.Name);
            if (sNode == null)
            {
                return(typeof(byte[]));
            }

            if (!string.IsNullOrEmpty(sNode.LinkAttributeName))
            {
                PssgNode node;
                string   linkAttrName;
                if (sNode.LinkAttributeName[0] == '^')
                {
                    if (this.ParentNode == null)
                    {
                        throw new InvalidOperationException("Node without parent cannot reference a parent's attribute.");
                    }
                    node         = this.ParentNode;
                    linkAttrName = sNode.LinkAttributeName.Substring(1);
                }
                else
                {
                    node         = this;
                    linkAttrName = sNode.LinkAttributeName;
                }

                if (node.HasAttribute(linkAttrName))
                {
                    PssgAttribute attr = node.Attributes[linkAttrName];
                    if (attr.Value is string)
                    {
                        string format = (string)attr.Value;
                        if (format.Contains("float"))
                        {
                            return(typeof(Single[]));
                        }
                        else if (format.Contains("ushort"))
                        {
                            return(typeof(UInt16[]));
                        }
                    }
                }
            }

            return(sNode.DataType);
        }
Exemple #5
0
        public List <PssgNode> FindNodes(string nodeName, string attributeName = null, string attributeValue = null)
        {
            List <PssgNode> ret = new List <PssgNode>();

            if (this.Name == nodeName)
            {
                if (attributeName != null && attributeValue != null)
                {
                    PssgAttribute attr = this.GetAttribute(attributeName);
                    if (attr != null && attr.ToString() == attributeValue)
                    {
                        ret.Add(this);
                    }
                }
                else if (attributeName != null)
                {
                    if (this.HasAttribute(attributeName) == true)
                    {
                        ret.Add(this);
                    }
                }
                else if (attributeValue != null)
                {
                    foreach (PssgAttribute pair in Attributes)
                    {
                        if (pair.ToString() == attributeValue)
                        {
                            ret.Add(this);
                            break;
                        }
                    }
                }
                else
                {
                    ret.Add(this);
                }
            }
            if (ChildNodes != null)
            {
                foreach (PssgNode subNode in ChildNodes)
                {
                    ret.AddRange(subNode.FindNodes(nodeName, attributeName, attributeValue));
                }
            }
            return(ret);
        }
Exemple #6
0
        public PssgAttribute AddAttribute(string attributeName, object data)
        {
            if (this.Attributes == null)
            {
                this.Attributes = new PssgAttributeCollection();
            }
            else if (this.HasAttribute(attributeName))
            {
                this.GetAttribute(attributeName).Value = data;
                return(this.GetAttribute(attributeName));
            }

            PssgAttribute newAttr = new PssgAttribute(PssgSchema.AddAttribute(this.Name, attributeName, data.GetType()), data, this.File, this);

            this.Attributes.Add(newAttr);

            return(newAttr);
        }
Exemple #7
0
        private Type GetValueType()
        {
            PssgSchema.Node sNode = this.NodeInfo;// PssgSchema.GetNode(this.Name);
            if (sNode == null)
            {
                return(typeof(byte[]));
            }

            if (!string.IsNullOrEmpty(sNode.LinkAttributeName))
            {
                PssgAttributeCollection attrs;
                string linkAttrName;
                if (sNode.LinkAttributeName[0] == '^')
                {
                    attrs        = this.ParentNode.Attributes;
                    linkAttrName = sNode.LinkAttributeName.Substring(1);
                }
                else
                {
                    attrs        = this.Attributes;
                    linkAttrName = sNode.LinkAttributeName;
                }

                PssgAttribute attr = attrs[linkAttrName];
                if (attr != null && attr.Value is string)
                {
                    string format = (string)attr.Value;
                    if (format.Contains("float"))
                    {
                        return(typeof(Single[]));
                    }
                    else if (format.Contains("ushort"))
                    {
                        return(typeof(UInt16[]));
                    }
                }
            }

            return(sNode.DataType);
        }
Exemple #8
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);
                }
            }
        }
Exemple #9
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);
        }
        private void termpToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // Dirt 2 to Grid
            foreach (PssgNode mpjn in pssg.FindNodes("MATRIXPALETTEJOINTNODE"))
            {
                PssgAttribute jointId = new PssgAttribute(null, null, null, null);
                foreach (PssgNode mpjri in mpjn.FindNodes("MATRIXPALETTEJOINTRENDERINSTANCE"))
                {
                    mpjri.Rename("MATRIXPALETTERENDERINSTANCE");
                    jointId = mpjri.GetAttribute("jointID");
                    mpjri.RemoveAttribute(jointId.Name);
                }
                mpjn.AddAttribute(jointId.Name, jointId.Value);
            }

            foreach (PssgNode mpn in pssg.FindNodes("MATRIXPALETTENODE"))
            {
                PssgAttribute jointCount = new PssgAttribute(null, null, null, null);
                UInt32 jointCountNum = 0;
                List<PssgNode> mpriNodes = mpn.FindNodes("MATRIXPALETTERENDERINSTANCE");
                foreach (PssgNode mpri in mpriNodes)
                {
                    mpri.Rename("RENDERSTREAMINSTANCE");
                    jointCountNum += (UInt32)mpri.GetAttribute("jointCount").Value;
                    mpri.RemoveAttribute("jointCount");
                    foreach (PssgNode mpsj in mpri.FindNodes("MATRIXPALETTESKINJOINT"))
                    {
                        pssg.MoveNode(mpsj, mpn);
                    }
                }
                mpn.AddAttribute("jointCount", jointCountNum);
            }

            // Stuff below may not be needed
            foreach (PssgNode rds in pssg.FindNodes("RENDERDATASOURCE"))
            {
                rds[3].GetAttribute("subStream").Value = 3u;
                rds[3].GetAttribute("dataBlock").Value = rds[4].GetAttribute("dataBlock").Value;
                PssgNode dBlock1 = pssg.FindNodes("DATABLOCK", "id", rds[2].GetAttribute("dataBlock").ToString().Substring(1))[0];
                PssgNode dBlock2 = pssg.FindNodes("DATABLOCK", "id", rds[4].GetAttribute("dataBlock").ToString().Substring(1))[0];

                dBlock1[0].GetAttribute("stride").Value = 16u;
                dBlock1[1].GetAttribute("stride").Value = 16u;

                dBlock1[2].GetAttribute("offset").Value = dBlock2[0].GetAttribute("stride").Value;
                dBlock2[0].GetAttribute("stride").Value = (UInt32)dBlock2[0].GetAttribute("stride").Value + 12u;
                dBlock2[1].GetAttribute("stride").Value = (UInt32)dBlock2[1].GetAttribute("stride").Value + 12u;
                dBlock2[2].GetAttribute("stride").Value = (UInt32)dBlock2[2].GetAttribute("stride").Value + 12u;
                dBlock1[2].GetAttribute("stride").Value = dBlock2[0].GetAttribute("stride").Value;

                pssg.MoveNode(dBlock1[2], dBlock2);
            }

            clearVars(false);
            setupEditor(MainTabs.Auto);
        }
Exemple #11
0
        public PssgAttribute AddAttribute(string attributeName, object data)
        {
            if (this.Attributes == null)
            {
                this.Attributes = new PssgAttributeCollection();
            }
            else if (this.HasAttribute(attributeName))
            {
                this.GetAttribute(attributeName).Value = data;
                return this.GetAttribute(attributeName);
            }

            PssgAttribute newAttr = new PssgAttribute(PssgSchema.AddAttribute(this.Name, attributeName, data.GetType()), data, this.File, this);
            this.Attributes.Add(newAttr);

            return newAttr;
        }
Exemple #12
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);
        }
Exemple #13
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++;
                }
            }
        }
Exemple #14
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);
        }