Exemple #1
0
            public void Read(FileReader reader, PTCL ptcl)
            {
                uint Position = (uint)reader.Position; //Offsets are relative to this

                reader.ByteOrder = Syroot.BinaryData.ByteOrder.LittleEndian;
                Signature        = reader.ReadString(4, Encoding.ASCII);

                if (Signature == "EFTB")
                {
                    reader.ByteOrder = Syroot.BinaryData.ByteOrder.BigEndian;

                    reader.Seek(48, SeekOrigin.Begin);
                }
                else if (Signature == "VFXB")
                {
                    uint padding = reader.ReadUInt32();
                    GraphicsAPIVersion = reader.ReadUInt16();
                    VFXVersion         = reader.ReadUInt16();
                    ByteOrderMark      = reader.ReadUInt16();
                    Alignment          = reader.ReadByte();
                    TargetOffset       = reader.ReadByte();
                    uint HeaderSize = reader.ReadUInt32();
                    Flag        = reader.ReadUInt16();
                    BlockOffset = reader.ReadUInt16();
                    uint padding2 = reader.ReadUInt32();
                    uint FileSize = reader.ReadUInt32();
                    reader.Seek(Position + BlockOffset, SeekOrigin.Begin);
                }
                else
                {
                    throw new Exception("Unknown ptcl format. Signature not valid " + Signature);
                }


                while (reader.Position < reader.BaseStream.Length)
                {
                    SectionBase sectionBase = new SectionBase();
                    sectionBase.Read(reader, this);
                    Sections.Add(sectionBase);
                    ptcl.Nodes.Add(sectionBase);

                    if (sectionBase.NextSectionOffset == NullOffset)
                    {
                        break;
                    }
                }

                MapTextureIDs(ptcl);

                reader.Dispose();
                reader.Close();
            }
Exemple #2
0
            private void ReadSectionData(SectionBase section, Header ptclHeader, FileReader reader)
            {
                if (section.BinaryDataOffset != NullOffset)
                {
                    using (reader.TemporarySeek(section.BinaryDataOffset + section.Position, SeekOrigin.Begin))
                    {
                        BinaryDataBytes = reader.ReadBytes((int)section.SectionSize);
                    }
                }

                switch (section.Signature)
                {
                case "TEXR":
                    section.Text = "Texture Info";
                    BinaryData   = new TEXR();

                    if (SubSectionCount > 0)
                    {
                        //Set the data block first!
                        reader.Seek(SubSectionOffset + section.Position, SeekOrigin.Begin);
                        var dataBlockSection = new SectionBase();
                        dataBlockSection.Read(reader, ptclHeader, "GX2B");

                        if (dataBlockSection.BinaryDataOffset != NullOffset)
                        {
                            reader.Seek(dataBlockSection.BinaryDataOffset + dataBlockSection.Position, SeekOrigin.Begin);
                            ((TEXR)BinaryData).data = reader.ReadBytes((int)dataBlockSection.SectionSize);
                        }
                    }

                    reader.Seek(BinaryDataOffset + section.Position, SeekOrigin.Begin);
                    ((TEXR)BinaryData).Read(reader, ptclHeader);

                    break;

                case "SHDB":
                    reader.Seek(BinaryDataOffset + section.Position, SeekOrigin.Begin);
                    section.Text = "GTX Shader";
                    reader.ReadBytes((int)section.SectionSize);
                    break;

                case "EMTR":
                    reader.Seek(BinaryDataOffset + 16 + section.Position, SeekOrigin.Begin);
                    Text = reader.ReadString(BinaryStringFormat.ZeroTerminated);

                    reader.Seek(BinaryDataOffset + 16 + 64 + section.Position, SeekOrigin.Begin);
                    BinaryData = new Emitter();
                    ((Emitter)BinaryData).Read(reader, ptclHeader);
                    break;

                case "ESTA":
                    section.Text = "Emitter Sets";
                    break;

                case "ESET":
                    byte[] Padding = reader.ReadBytes(16);
                    section.Text = reader.ReadString(BinaryStringFormat.ZeroTerminated);
                    break;

                case "GRTF":
                    if (section.BinaryDataOffset != NullOffset)
                    {
                        reader.Seek(section.BinaryDataOffset + section.Position, SeekOrigin.Begin);
                        BinaryData = new BNTX();
                        ((BNTX)BinaryData).FileName = "textures.bntx";
                        ((BNTX)BinaryData).Load(new MemoryStream(reader.ReadBytes((int)section.SectionSize)));
                        ((BNTX)BinaryData).IFileInfo.InArchive = true;
                        Nodes.Add(((BNTX)BinaryData));
                    }
                    break;

                case "PRMA":
                    break;

                case "ESFT":
                    reader.Seek(28, SeekOrigin.Current);
                    int StringSize = reader.ReadInt32();
                    section.Text = reader.ReadString(StringSize, Encoding.ASCII);
                    break;

                case "GRSN":
                    section.Text = "Shaders";

                    if (section.BinaryDataOffset != NullOffset)
                    {
                        reader.Seek(section.BinaryDataOffset + section.Position, SeekOrigin.Begin);
                        BinaryData = reader.ReadBytes((int)section.SectionSize);
                    }
                    break;

                case "GRSC":
                    section.Text = "Shaders 2";
                    if (section.BinaryDataOffset != NullOffset)
                    {
                        reader.Seek(section.BinaryDataOffset + section.Position, SeekOrigin.Begin);
                        BinaryData = reader.ReadBytes((int)section.SectionSize);
                    }
                    break;

                case "G3PR":
                    if (section.BinaryDataOffset != NullOffset)
                    {
                        reader.Seek(section.BinaryDataOffset + section.Position, SeekOrigin.Begin);
                        BinaryData = new BFRES();
                        ((BFRES)BinaryData).FileName = "model.bfres";
                        ((BFRES)BinaryData).Load(new MemoryStream(reader.ReadBytes((int)section.SectionSize)));
                        ((BFRES)BinaryData).IFileInfo           = new IFileInfo();
                        ((BFRES)BinaryData).IFileInfo.InArchive = true;
                        Nodes.Add(((BFRES)BinaryData));
                    }
                    break;

                case "GTNT":
                    if (section.BinaryDataOffset != NullOffset)
                    {
                        foreach (var node in Parent.Nodes)
                        {
                            if (node is BNTX)
                            {
                                BNTX bntx = (BNTX)node;

                                reader.Seek(section.BinaryDataOffset + section.Position, SeekOrigin.Begin);
                                for (int i = 0; i < bntx.Textures.Count; i++)
                                {
                                    var texDescriptor = new TextureDescriptor();
                                    Nodes.Add(texDescriptor);
                                    texDescriptor.Read(reader, bntx);
                                }
                            }
                        }
                    }
                    break;
                }
            }
Exemple #3
0
            public void Read(FileReader reader, Header ptclHeader, string MagicCheck = "")
            {
                Position = (uint)reader.Position;

                if (MagicCheck != "")
                {
                    Signature = reader.ReadSignature(4, MagicCheck);
                }
                else
                {
                    Signature = reader.ReadString(4, Encoding.ASCII);
                }

                SectionSize       = reader.ReadUInt32();
                SubSectionOffset  = reader.ReadUInt32();
                NextSectionOffset = reader.ReadUInt32();
                Unkown            = reader.ReadUInt32();
                BinaryDataOffset  = reader.ReadUInt32();
                Unkown3           = reader.ReadUInt32();

                if (ptclHeader.Signature == "EFTB")
                {
                    SubSectionCount = reader.ReadUInt16();
                    ushort unk = reader.ReadUInt16();
                }
                else
                {
                    SubSectionCount = reader.ReadUInt32();
                }

                Text = Signature;

                ReadSectionData(this, ptclHeader, reader);

                if (SubSectionOffset != NullOffset)
                {
                    uint tempCount = 0;

                    //Some sections will point to sub sections but have no count? (GRSN to GRSC)
                    //This will work decently for now
                    if (SubSectionCount == 0)
                    {
                        tempCount = 1;
                    }

                    reader.Seek(Position + SubSectionOffset, SeekOrigin.Begin);
                    for (int i = 0; i < SubSectionCount + tempCount; i++)
                    {
                        var ChildSection = new SectionBase();
                        Nodes.Add(ChildSection);

                        ChildSection.Read(reader, ptclHeader);
                        ChildSections.Add(ChildSection);

                        if (ChildSection.NextSectionOffset == NullOffset)
                        {
                            break;
                        }
                    }
                }

                reader.Seek(Position, SeekOrigin.Begin);

                if (ChildSections.Count != 0)
                {
                    data = reader.ReadBytes((int)SubSectionOffset);
                }
                else if (NextSectionOffset != NullOffset)
                {
                    data = reader.ReadBytes((int)NextSectionOffset);
                }
                else
                {
                    data = reader.ReadBytes((int)SectionSize);
                }

                if (NextSectionOffset != NullOffset)
                {
                    reader.Seek(Position + NextSectionOffset, SeekOrigin.Begin);
                }
            }