Exemplo n.º 1
0
        public static NSBTP_File Read(string Filename)
        {
            EndianBinaryReader er = new EndianBinaryReader(File.OpenRead(Filename), Endianness.LittleEndian);
            NSBTP_File ns = new NSBTP_File();
            ns.Header.ID = er.ReadString(Encoding.ASCII, 4);
            if (ns.Header.ID == "BTP0")
            {
                ns.Header.Magic = er.ReadBytes(4);
                ns.Header.file_size = er.ReadInt32();
                ns.Header.header_size = er.ReadInt16();
                ns.Header.nSection = er.ReadInt16();
                ns.Header.Section_Offset = new Int32[ns.Header.nSection];
                for (int i = 0; i < ns.Header.nSection; i++)
                {
                    ns.Header.Section_Offset[i] = er.ReadInt32();
                }
                ns.PAT0.ID = er.ReadString(Encoding.ASCII, 4);
                if (ns.PAT0.ID == "PAT0")
                {
                    ns.PAT0.Size = er.ReadInt32();
                    //3D Info Structure
                    ns.PAT0.dummy = er.ReadByte();
                    ns.PAT0.num_objs = er.ReadByte();
                    ns.PAT0.section_size = er.ReadInt16();
                    ns.PAT0.unknownBlock.header_size = er.ReadInt16();
                    ns.PAT0.unknownBlock.section_size = er.ReadInt16();
                    ns.PAT0.unknownBlock.constant = er.ReadInt32();
                    ns.PAT0.unknownBlock.unknown1 = new short[ns.PAT0.num_objs];
                    ns.PAT0.unknownBlock.unknown2 = new short[ns.PAT0.num_objs];
                    for (int i = 0; i < ns.PAT0.num_objs; i++)
                    {
                        ns.PAT0.unknownBlock.unknown1[i] = er.ReadInt16();
                        ns.PAT0.unknownBlock.unknown2[i] = er.ReadInt16();
                    }

                    ns.PAT0.infoBlock.header_size = er.ReadInt16();
                    ns.PAT0.infoBlock.data_size = er.ReadInt16();
                    ns.PAT0.infoBlock.Data = new NSBTP_File.pat0.Info.info[ns.PAT0.num_objs];
                    for (int i = 0; i < ns.PAT0.num_objs; i++)
                    {
                        ns.PAT0.infoBlock.Data[i].MPToffset = er.ReadInt32();
                    }
                    ns.PAT0.names = new string[ns.PAT0.num_objs];
                    for (int i = 0; i < ns.PAT0.num_objs; i++)
                    {
                        ns.PAT0.names[i] = er.ReadString(Encoding.ASCII, 16).Replace("\0", "");
                    }

                    ns.MPT.ID = er.ReadString(Encoding.ASCII, 4);
                    if (ns.MPT.ID == "M" + (char)0x00 + "PT")
                    {
                        ns.MPT.NoFrames = er.ReadInt16();
                        ns.MPT.NoTex = er.ReadByte();
                        ns.MPT.NoPal = er.ReadByte();
                        ns.MPT.Texoffset = er.ReadInt16();
                        ns.MPT.Paloffset = er.ReadInt16();
                        //3D Info Structure
                        ns.MPT.dummy = er.ReadByte();
                        ns.MPT.num_objs = er.ReadByte();
                        ns.MPT.section_size = er.ReadInt16();
                        ns.MPT.unknownBlock.header_size = er.ReadInt16();
                        ns.MPT.unknownBlock.section_size = er.ReadInt16();
                        ns.MPT.unknownBlock.constant = er.ReadInt32();
                        ns.MPT.unknownBlock.unknown1 = new short[ns.MPT.num_objs];
                        ns.MPT.unknownBlock.unknown2 = new short[ns.MPT.num_objs];
                        for (int i = 0; i < ns.MPT.num_objs; i++)
                        {
                            ns.MPT.unknownBlock.unknown1[i] = er.ReadInt16();
                            ns.MPT.unknownBlock.unknown2[i] = er.ReadInt16();
                        }

                        ns.MPT.infoBlock.header_size = er.ReadInt16();
                        ns.MPT.infoBlock.data_size = er.ReadInt16();
                        ns.MPT.infoBlock.Data = new NSBTP_File.M_PT.Info.info[ns.MPT.num_objs];
                        ns.AnimData = new NSBTP_File.animData[ns.MPT.num_objs];
                        for (int i = 0; i < ns.MPT.num_objs; i++)
                        {
                            ns.MPT.infoBlock.Data[i].KeyFrames = er.ReadInt32();
                            ns.MPT.infoBlock.Data[i].Unknown1 = er.ReadInt16();
                            ns.MPT.infoBlock.Data[i].Offset = er.ReadInt16();
                            ns.AnimData[i].KeyFrames = new NSBTP_File.animData.keyFrame[ns.MPT.infoBlock.Data[i].KeyFrames];
                            for (int j = 0; j < ns.MPT.infoBlock.Data[i].KeyFrames; j++)
                            {
                                long curpos = er.BaseStream.Position;
                                er.BaseStream.Position = ns.Header.Section_Offset[0] + ns.PAT0.section_size + ns.MPT.infoBlock.Data[i].Offset + j*4 + 8;
                                ns.AnimData[i].KeyFrames[j].Start = er.ReadInt16();
                                ns.AnimData[i].KeyFrames[j].texId = er.ReadByte();
                                ns.AnimData[i].KeyFrames[j].palId = er.ReadByte();
                                er.BaseStream.Position = ns.Header.Section_Offset[0] + ns.PAT0.section_size + ns.MPT.Texoffset + ns.AnimData[i].KeyFrames[j].texId * 16 + 8;
                                ns.AnimData[i].KeyFrames[j].texName = LibNDSFormats.Utils.ReadNSBMDString(er);
                                er.BaseStream.Position = ns.Header.Section_Offset[0] + ns.PAT0.section_size + ns.MPT.Paloffset + ns.AnimData[i].KeyFrames[j].palId * 16 + 8;
                                ns.AnimData[i].KeyFrames[j].palName = LibNDSFormats.Utils.ReadNSBMDString(er);
                                er.BaseStream.Position = curpos;
                            }
                        }
                        ns.MPT.names = new string[ns.MPT.num_objs];
                        for (int i = 0; i < ns.MPT.num_objs; i++)
                        {
                            ns.MPT.names[i] = LibNDSFormats.Utils.ReadNSBMDString(er);
                        }
                    }
                    else
                    {
                        MessageBox.Show("NSBTP Error");
                        er.Close();
                        return ns;
                    }
                }
                else
                {
                    MessageBox.Show("NSBTP Error");
                    er.Close();
                    return ns;
                }
            }
            else
            {
                MessageBox.Show("NSBTP Error");
                er.Close();
                return ns;
            }
            er.Close();
            return ns;
        }
Exemplo n.º 2
0
        public static NSBTP_File Read(string Filename)
        {
            EndianBinaryReader er = new EndianBinaryReader(File.OpenRead(Filename), Endianness.LittleEndian);
            NSBTP_File         ns = new NSBTP_File();

            ns.Header.ID = er.ReadString(Encoding.ASCII, 4);
            if (ns.Header.ID == "BTP0")
            {
                ns.Header.Magic          = er.ReadBytes(4);
                ns.Header.file_size      = er.ReadInt32();
                ns.Header.header_size    = er.ReadInt16();
                ns.Header.nSection       = er.ReadInt16();
                ns.Header.Section_Offset = new Int32[ns.Header.nSection];
                for (int i = 0; i < ns.Header.nSection; i++)
                {
                    ns.Header.Section_Offset[i] = er.ReadInt32();
                }
                ns.PAT0.ID = er.ReadString(Encoding.ASCII, 4);
                if (ns.PAT0.ID == "PAT0")
                {
                    ns.PAT0.Size = er.ReadInt32();
                    //3D Info Structure
                    ns.PAT0.dummy                     = er.ReadByte();
                    ns.PAT0.num_objs                  = er.ReadByte();
                    ns.PAT0.section_size              = er.ReadInt16();
                    ns.PAT0.unknownBlock.header_size  = er.ReadInt16();
                    ns.PAT0.unknownBlock.section_size = er.ReadInt16();
                    ns.PAT0.unknownBlock.constant     = er.ReadInt32();
                    ns.PAT0.unknownBlock.unknown1     = new short[ns.PAT0.num_objs];
                    ns.PAT0.unknownBlock.unknown2     = new short[ns.PAT0.num_objs];
                    for (int i = 0; i < ns.PAT0.num_objs; i++)
                    {
                        ns.PAT0.unknownBlock.unknown1[i] = er.ReadInt16();
                        ns.PAT0.unknownBlock.unknown2[i] = er.ReadInt16();
                    }

                    ns.PAT0.infoBlock.header_size = er.ReadInt16();
                    ns.PAT0.infoBlock.data_size   = er.ReadInt16();
                    ns.PAT0.infoBlock.Data        = new NSBTP_File.pat0.Info.info[ns.PAT0.num_objs];
                    for (int i = 0; i < ns.PAT0.num_objs; i++)
                    {
                        ns.PAT0.infoBlock.Data[i].MPToffset = er.ReadInt32();
                    }
                    ns.PAT0.names = new string[ns.PAT0.num_objs];
                    for (int i = 0; i < ns.PAT0.num_objs; i++)
                    {
                        ns.PAT0.names[i] = er.ReadString(Encoding.ASCII, 16).Replace("\0", "");
                    }

                    ns.MPT.ID = er.ReadString(Encoding.ASCII, 4);
                    if (ns.MPT.ID == "M" + (char)0x00 + "PT")
                    {
                        ns.MPT.NoFrames  = er.ReadInt16();
                        ns.MPT.NoTex     = er.ReadByte();
                        ns.MPT.NoPal     = er.ReadByte();
                        ns.MPT.Texoffset = er.ReadInt16();
                        ns.MPT.Paloffset = er.ReadInt16();
                        //3D Info Structure
                        ns.MPT.dummy                     = er.ReadByte();
                        ns.MPT.num_objs                  = er.ReadByte();
                        ns.MPT.section_size              = er.ReadInt16();
                        ns.MPT.unknownBlock.header_size  = er.ReadInt16();
                        ns.MPT.unknownBlock.section_size = er.ReadInt16();
                        ns.MPT.unknownBlock.constant     = er.ReadInt32();
                        ns.MPT.unknownBlock.unknown1     = new short[ns.MPT.num_objs];
                        ns.MPT.unknownBlock.unknown2     = new short[ns.MPT.num_objs];
                        for (int i = 0; i < ns.MPT.num_objs; i++)
                        {
                            ns.MPT.unknownBlock.unknown1[i] = er.ReadInt16();
                            ns.MPT.unknownBlock.unknown2[i] = er.ReadInt16();
                        }

                        ns.MPT.infoBlock.header_size = er.ReadInt16();
                        ns.MPT.infoBlock.data_size   = er.ReadInt16();
                        ns.MPT.infoBlock.Data        = new NSBTP_File.M_PT.Info.info[ns.MPT.num_objs];
                        ns.AnimData = new NSBTP_File.animData[ns.MPT.num_objs];
                        for (int i = 0; i < ns.MPT.num_objs; i++)
                        {
                            ns.MPT.infoBlock.Data[i].KeyFrames = er.ReadInt32();
                            ns.MPT.infoBlock.Data[i].Unknown1  = er.ReadInt16();
                            ns.MPT.infoBlock.Data[i].Offset    = er.ReadInt16();
                            ns.AnimData[i].KeyFrames           = new NSBTP_File.animData.keyFrame[ns.MPT.infoBlock.Data[i].KeyFrames];
                            for (int j = 0; j < ns.MPT.infoBlock.Data[i].KeyFrames; j++)
                            {
                                long curpos = er.BaseStream.Position;
                                er.BaseStream.Position              = ns.Header.Section_Offset[0] + ns.PAT0.section_size + ns.MPT.infoBlock.Data[i].Offset + j * 4 + 8;
                                ns.AnimData[i].KeyFrames[j].Start   = er.ReadInt16();
                                ns.AnimData[i].KeyFrames[j].texId   = er.ReadByte();
                                ns.AnimData[i].KeyFrames[j].palId   = er.ReadByte();
                                er.BaseStream.Position              = ns.Header.Section_Offset[0] + ns.PAT0.section_size + ns.MPT.Texoffset + ns.AnimData[i].KeyFrames[j].texId * 16 + 8;
                                ns.AnimData[i].KeyFrames[j].texName = LibNDSFormats.Utils.ReadNSBMDString(er);
                                er.BaseStream.Position              = ns.Header.Section_Offset[0] + ns.PAT0.section_size + ns.MPT.Paloffset + ns.AnimData[i].KeyFrames[j].palId * 16 + 8;
                                ns.AnimData[i].KeyFrames[j].palName = LibNDSFormats.Utils.ReadNSBMDString(er);
                                er.BaseStream.Position              = curpos;
                            }
                        }
                        ns.MPT.names = new string[ns.MPT.num_objs];
                        for (int i = 0; i < ns.MPT.num_objs; i++)
                        {
                            ns.MPT.names[i] = LibNDSFormats.Utils.ReadNSBMDString(er);
                        }
                    }
                    else
                    {
                        MessageBox.Show("NSBTP Error");
                        er.Close();
                        return(ns);
                    }
                }
                else
                {
                    MessageBox.Show("NSBTP Error");
                    er.Close();
                    return(ns);
                }
            }
            else
            {
                MessageBox.Show("NSBTP Error");
                er.Close();
                return(ns);
            }
            er.Close();
            return(ns);
        }