Inheritance: MiscUtil.IO.EndianBinaryReader
Example #1
0
        public PssgFile(System.IO.Stream fileStream)
        {
            using (PssgBinaryReader reader = new PssgBinaryReader(new BigEndianBitConverter(), fileStream))
            {
                magic = reader.ReadPSSGString(4);
                if (magic != "PSSG")
                {
                    throw new Exception("This is not a PSSG file!");
                }
                int size = reader.ReadInt32();
                int attributeInfoCount = reader.ReadInt32();
                int nodeInfoCount = reader.ReadInt32();

                attributeInfo = new PssgAttributeInfo[attributeInfoCount];
                nodeInfo = new PssgNodeInfo[nodeInfoCount];

                for (int i = 0; i < nodeInfoCount; i++)
                {
                    nodeInfo[i] = new PssgNodeInfo(reader, this);
                }
                long positionAfterInfo = reader.BaseStream.Position;

                rootNode = new PssgNode(reader, this, null, true);
                if (reader.BaseStream.Position < reader.BaseStream.Length)
                {
                    reader.BaseStream.Position = positionAfterInfo;
                    rootNode = new PssgNode(reader, this, 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.");
                    }
                }
            }
        }
Example #2
0
 public PssgAttributeInfo(PssgBinaryReader reader)
 {
     id = reader.ReadInt32();
     name = reader.ReadPSSGString();
 }
Example #3
0
        public PssgNodeInfo(PssgBinaryReader reader, PssgFile file)
        {
            attributeInfo = new SortedDictionary<int, PssgAttributeInfo>();

            id = reader.ReadInt32();
            name = reader.ReadPSSGString();
            int attributeInfoCount = reader.ReadInt32();
            PssgAttributeInfo ai;
            for (int i = 0; i < attributeInfoCount; i++)
            {
                ai = new PssgAttributeInfo(reader);
                try
                {
                    attributeInfo.Add(ai.id, ai);
                }
                catch (ArgumentException ex)
                {
                    if (MessageBox.Show("The attribute of id " + ai.id + ", named " + ai.name + ", already exists, and will not be saved. Continue?",
                        "PSSG Editor", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                        continue;
                    else
                        throw new Exception("The attribute of id " + ai.id + ", named " + ai.name + ", already exists.");
                }

                file.attributeInfo[ai.id - 1] = ai;
            }
        }
Example #4
0
        public PssgAttribute(PssgBinaryReader reader, PssgFile file, PssgNode node)
        {
            this.file = file;
            ParentNode = node;

            id = reader.ReadInt32();
            size = reader.ReadInt32();
            if (size == 4)
            {
                data = reader.ReadBytes(size);
                return;
            }
            else if (size > 4)
            {
                int strlen = reader.ReadInt32();
                if (size - 4 == strlen)
                {
                    data = reader.ReadPSSGString(strlen);
                    return;
                }
                else
                {
                    reader.Seek(-4, System.IO.SeekOrigin.Current);
                }
            }
            data = reader.ReadBytes(size);
        }
Example #5
0
        public PssgNode(PssgBinaryReader reader, PssgFile file, PssgNode node, bool useDataNodeCheck)
        {
            this.file = file;
            ParentNode = node;

            id = reader.ReadInt32();
            size = reader.ReadInt32();
            long end = reader.BaseStream.Position + size;

            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
            attributes = new Dictionary<string, PssgAttribute>();
            PssgAttribute attr;
            while (reader.BaseStream.Position < attributeEnd)
            {
                attr = new PssgAttribute(reader, file, this);
                attributes.Add(attr.Name, attr);
            }

            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 > file.nodeInfo.Length || tempID < 0)
                    {
                        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)
            {
                data = reader.ReadBytes((int)(end - reader.BaseStream.Position));
            }
            else
            {
                // Each node at least 12 bytes (id + size + arg size)
                subNodes = new PssgNode[(end - reader.BaseStream.Position) / 12];
                int nodeCount = 0;
                while (reader.BaseStream.Position < end)
                {
                    subNodes[nodeCount] = new PssgNode(reader, file, this, useDataNodeCheck);
                    nodeCount++;
                }
                Array.Resize(ref subNodes, nodeCount);
            }

            file.nodeInfo[id - 1].isDataNode = isDataNode;
        }