コード例 #1
0
        public static PssgFile ReadPssg(Stream fileStream, PssgFileType fileType)
        {
            PssgFile file = new PssgFile(fileType);

            using (PssgBinaryReader reader = new PssgBinaryReader(EndianBitConverter.Big, fileStream, true))
            {
                reader.ReadPSSGString(4); // "PSSG"
                int size = reader.ReadInt32();

                // Load all the pssg node/attribute names
                PssgSchema.ClearSchemaIds();
                PssgSchema.LoadFromPssg(reader);
                long positionAfterInfo = reader.BaseStream.Position;

                file.RootNode = new PssgNode(reader, file, null, true);
                if (reader.BaseStream.Position < reader.BaseStream.Length)
                {
                    reader.BaseStream.Position = positionAfterInfo;
                    file.RootNode = new PssgNode(reader, file, null, false);
                    if (reader.BaseStream.Position < 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 the original version of the pssg file.");
                    }
                }
            }

            return(file);
        }
コード例 #2
0
        public static Attribute AddAttribute(string nodeName, string attributeName, Type attrType)
        {
            Node node = PssgSchema.AddNode(nodeName);

            if (attrType != null)
            {
                bool add = true;
                for (int i = 0; i < node.Attributes.Count; i++)
                {
                    if (node.Attributes[i].Name == attributeName)
                    {
                        add = false;
                        // Allow overwrite if current data type is null
                        PssgSchema.SetAttributeDataTypeIfNull(node.Attributes[i], attrType);
                        return(node.Attributes[i]);
                    }
                }

                if (add)
                {
                    PssgSchema.Attribute attr = new Attribute(attributeName, attrType);
                    node.Attributes.Add(attr);
                    return(attr);
                }
            }

            return(null);
        }
コード例 #3
0
        public void WritePssg(Stream fileStream)
        {
            using (PssgBinaryWriter writer = new PssgBinaryWriter(EndianBitConverter.Big, fileStream, true))
            {
                writer.Write(Encoding.ASCII.GetBytes("PSSG"));
                writer.Write(0); // Length, filled in later

                if (RootNode != null)
                {
                    // make all ids -1
                    PssgSchema.ClearSchemaIds();

                    // Get the counts, and update ids of the nodes/attributes used in this file
                    GetNodeAttributeNameCount(this, out var nodeNameCount, out var attributeNameCount);
                    writer.Write(attributeNameCount);
                    writer.Write(nodeNameCount);

                    // Update ids again to make sequential and save ones used in this file
                    PssgSchema.SaveToPssg(writer);

                    RootNode.UpdateSize();
                    RootNode.Write(writer);
                }

                writer.BaseStream.Position = 4;
                writer.Write((int)writer.BaseStream.Length - 8);
            }
コード例 #4
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);
        }
コード例 #5
0
        internal static Node AddNode(Node node)
        {
            if (!entries.ContainsKey(node.Name))
            {
                entries.Add(node.Name, node);
                return(node);
            }
            else
            {
                PssgSchema.SetNodeDataTypeIfNull(entries[node.Name], node.DataType);

                foreach (Attribute attrEntry in node.Attributes)
                {
                    bool add = true;
                    for (int i = 0; i < entries[node.Name].Attributes.Count; i++)
                    {
                        if (entries[node.Name].Attributes[i].Name == attrEntry.Name)
                        {
                            add = false;
                            PssgSchema.SetAttributeDataTypeIfNull(entries[node.Name].Attributes[i], attrEntry.DataType);
                            break;
                        }
                    }

                    if (add)
                    {
                        entries[node.Name].Attributes.Add(attrEntry);
                    }
                }

                return(entries[node.Name]);
            }
        }
コード例 #6
0
 public PssgAttribute(PssgSchema.Attribute attributeInfo, object data, PssgFile file, PssgNode ParentNode)
 {
     this.AttributeInfo = attributeInfo;
     this.data = data;
     this.file = file;
     this.ParentNode = ParentNode;
 }
コード例 #7
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();
 }
コード例 #8
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);
        }
コード例 #9
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);
        }
コード例 #10
0
        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);
        }
コード例 #11
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);
        }
コード例 #12
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));
        }
コード例 #13
0
        public static Attribute AddAttribute(string nodeName, string attributeName)
        {
            Node node = PssgSchema.AddNode(nodeName);

            for (int i = 0; i < node.Attributes.Count; i++)
            {
                if (node.Attributes[i].Name == attributeName)
                {
                    return(node.Attributes[i]);
                }
            }

            PssgSchema.Attribute attr = new Attribute(attributeName);
            node.Attributes.Add(attr);
            return(attr);
        }
コード例 #14
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);
        }
コード例 #15
0
ファイル: PssgNode.cs プロジェクト: ptasev/Ego-Engine-Modding
        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);
        }
コード例 #16
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);
        }
コード例 #17
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);
        }
コード例 #18
0
        public static void LoadFromPssg(PssgBinaryReader reader)
        {
            int       attributeInfoCount = reader.ReadInt32();
            int       nodeInfoCount      = reader.ReadInt32();
            Node      node;
            Attribute attribute;

            for (int i = 0; i < nodeInfoCount; i++)
            {
                int nId = reader.ReadInt32();
                node    = new Node(reader.ReadPSSGString());
                node.Id = nId;

                if (entries.ContainsKey(node.Name))
                {
                    entries[node.Name].Id = node.Id;
                }
                else
                {
                    PssgSchema.AddNode(node);
                }

                int subAttributeInfoCount = reader.ReadInt32();
                for (int j = 0; j < subAttributeInfoCount; j++)
                {
                    int id = reader.ReadInt32();
                    attribute    = new Attribute(reader.ReadPSSGString());
                    attribute.Id = id;

                    Attribute attr = PssgSchema.GetAttribute(node.Name, attribute.Name);
                    if (attr == null)
                    {
                        PssgSchema.AddAttribute(node.Name, attribute);
                    }
                    else
                    {
                        attr.Id = attribute.Id;
                    }
                }
            }
        }
コード例 #19
0
        public void WritePssg(Stream fileStream, bool close)
        {
            PssgBinaryWriter writer = new PssgBinaryWriter(new BigEndianBitConverter(), fileStream);

            try
            {
                writer.Write(Encoding.ASCII.GetBytes("PSSG"));
                writer.Write(0); // Length, filled in later

                if (RootNode != null)
                {
                    int nodeNameCount      = 0;
                    int attributeNameCount = 0;
                    PssgSchema.ClearSchemaIds(); // make all ids -1
                    RootNode.UpdateId(ref nodeNameCount, ref attributeNameCount);
                    writer.Write(attributeNameCount);
                    writer.Write(nodeNameCount);
                    PssgSchema.SaveToPssg(writer); // Update Ids again, to make sequential

                    RootNode.UpdateSize();
                    RootNode.Write(writer);
                }
                writer.BaseStream.Position = 4;
                writer.Write((int)writer.BaseStream.Length - 8);

                if (close)
                {
                    writer.Close();
                }
            }
            catch (Exception ex)
            {
                if (writer != null)
                {
                    writer.Close();
                }
                throw ex;
            }
        }
コード例 #20
0
        public static void AddAttribute(string nodeName, Attribute attribute)
        {
            Node node = PssgSchema.AddNode(nodeName);

            bool add = true;

            for (int i = 0; i < node.Attributes.Count; i++)
            {
                if (node.Attributes[i].Name == attribute.Name)
                {
                    add = false;
                    // Allow overwrite if current data type is null
                    PssgSchema.SetAttributeDataTypeIfNull(node.Attributes[i], attribute.DataType);
                    break;
                }
            }

            if (add)
            {
                node.Attributes.Add(attribute);
            }
        }
コード例 #21
0
        public static Attribute AddAttribute(string nodeName, string attributeName)
        {
            Node node = PssgSchema.AddNode(nodeName);

            bool add = true;

            for (int i = 0; i < node.Attributes.Count; i++)
            {
                if (node.Attributes[i].Name == attributeName)
                {
                    add = false;
                    return(node.Attributes[i]);
                }
            }

            if (add)
            {
                PssgSchema.Attribute attr = new Attribute(attributeName);
                node.Attributes.Add(attr);
                return(attr);
            }

            return(null);
        }
コード例 #22
0
 public static void SetAttributeDataTypeIfNull(PssgSchema.Attribute attribute, Type attrType)
 {
     if (attribute.DataType == typeof(System.Exception))
     {
         attribute.DataType = attrType;
     }
 }
コード例 #23
0
 public void Rename(string nodeName)
 {
     this.NodeInfo = PssgSchema.RenameNode(this, nodeName);
 }
コード例 #24
0
 public static void SetNodeDataTypeIfNull(PssgSchema.Node node, Type dataType)
 {
     if (node.DataType == typeof(System.Exception))
     {
         node.DataType = dataType;
     }
 }
コード例 #25
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);
        }
コード例 #26
0
        public static void LoadSchema(Stream stream)
        {
            entries.Clear();

            PssgSchema.AddAttribute("FETEXTLAYOUT", "height", typeof(Single));
            PssgSchema.AddAttribute("FETEXTLAYOUT", "depth", typeof(Single));
            PssgSchema.AddAttribute("FETEXTLAYOUT", "tracking", typeof(Single));

            PssgSchema.AddAttribute("NEGLYPHMETRICS", "advanceWidth", typeof(Single));
            PssgSchema.AddAttribute("NEGLYPHMETRICS", "horizontalBearing", typeof(Single));
            PssgSchema.AddAttribute("NEGLYPHMETRICS", "verticalBearing", typeof(Single));
            PssgSchema.AddAttribute("NEGLYPHMETRICS", "physicalWidth", typeof(Single));
            PssgSchema.AddAttribute("NEGLYPHMETRICS", "physicalHeight", typeof(Single));

            PssgSchema.AddAttribute("FEATLASINFODATA", "u0", typeof(Single));
            PssgSchema.AddAttribute("FEATLASINFODATA", "v0", typeof(Single));
            PssgSchema.AddAttribute("FEATLASINFODATA", "u1", typeof(Single));
            PssgSchema.AddAttribute("FEATLASINFODATA", "v1", typeof(Single));

            if (stream.Length == 0)
            {
                return;
            }

            using (stream)
            {
                XDocument xDoc = XDocument.Load(stream);

                foreach (XNode xN in xDoc.Descendants("node"))
                {
                    if (xN is XElement)
                    {
                        XElement elemNode = (XElement)xN;
                        string   nodeName = elemNode.Attribute("name").Value;
                        Node     node     = PssgSchema.AddNode(nodeName);
                        Type     nodeType = Type.GetType(elemNode.Attribute("dataType").Value, false);
                        if (nodeType != null)
                        {
                            node.DataType = nodeType;
                        }
                        node.ElementsPerRow = Convert.ToInt32(elemNode.Attribute("elementsPerRow").Value);
                        string linkAttributeName = elemNode.Attribute("linkAttributeName").Value;
                        if (!string.IsNullOrEmpty(linkAttributeName))
                        {
                            node.LinkAttributeName = linkAttributeName;
                        }

                        foreach (XNode subNode in elemNode.Descendants("attribute"))
                        {
                            if (xN is XElement)
                            {
                                string attrName = ((XElement)subNode).Attribute("name").Value;
                                Type   attrType = Type.GetType(((XElement)subNode).Attribute("dataType").Value, false);
                                if (attrType != null)
                                {
                                    bool add = true;
                                    for (int i = 0; i < node.Attributes.Count; i++)
                                    {
                                        if (node.Attributes[i].Name == attrName)
                                        {
                                            add = false;
                                            node.Attributes[i].DataType = attrType;
                                            break;
                                        }
                                    }

                                    if (add)
                                    {
                                        node.Attributes.Add(new Attribute(attrName, attrType));
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }