예제 #1
0
파일: ppHeader.cs 프로젝트: ezdiy/GDImport
        public List <IWriteFile> ReadHeader(FileStream stream, ppFormat format, byte[] SMFigTable)
        {
            List <IWriteFile> subfiles = null;

            stream.Position = 0;
            BinaryReader binaryReader = new BinaryReader(stream);

            DecryptHeaderBytes(binaryReader.ReadBytes(1), SMFigTable);              // first byte
            int numFiles = BitConverter.ToInt32(DecryptHeaderBytes(binaryReader.ReadBytes(4), SMFigTable), 0);

            byte[] buf = DecryptHeaderBytes(binaryReader.ReadBytes(numFiles * 268), SMFigTable);

            subfiles = new List <IWriteFile>(numFiles);
            for (int i = 0; i < numFiles; i++)
            {
                int       offset  = i * 268;
                ppSubfile subfile = new ppSubfile(stream.Name);
                subfile.ppFormat = format;
                subfile.Name     = Utility.EncodingShiftJIS.GetString(buf, offset, 260).TrimEnd(new char[] { '\0' });
                subfile.size     = BitConverter.ToUInt32(buf, offset + 260);
                subfile.offset   = BitConverter.ToUInt32(buf, offset + 264);
                subfiles.Add(subfile);
            }

            return(subfiles);
        }
예제 #2
0
        public override List <IWriteFile> ReadHeader(string path, ppFormat format)
        {
            List <IWriteFile> subfiles = null;

            using (BinaryReader reader = new BinaryReader(File.OpenRead(path)))
            {
                byte[] versionHeader = reader.ReadBytes(8);
                int    version       = BitConverter.ToInt32(ppHeader_SMRetail.DecryptHeaderBytes(reader.ReadBytes(4)), 0);

                ppHeader_SMRetail.DecryptHeaderBytes(reader.ReadBytes(1));                  // first byte
                int    numFiles = BitConverter.ToInt32(ppHeader_SMRetail.DecryptHeaderBytes(reader.ReadBytes(4)), 0);
                byte[] buf      = ppHeader_SMRetail.DecryptHeaderBytes(reader.ReadBytes(numFiles * 288));

                subfiles = new List <IWriteFile>(numFiles);
                for (int i = 0; i < numFiles; i++)
                {
                    int       offset  = i * 288;
                    ppSubfile subfile = new ppSubfile(path);
                    subfile.ppFormat = format;
                    subfile.Name     = Utility.EncodingShiftJIS.GetString(buf, offset, 260).TrimEnd(new char[] { '\0' });
                    subfile.size     = BitConverter.ToUInt32(buf, offset + 260);
                    subfile.offset   = BitConverter.ToUInt32(buf, offset + 264);

                    Metadata metadata = new Metadata();
                    metadata.LastBytes = new byte[20];
                    System.Array.Copy(buf, offset + 268, metadata.LastBytes, 0, 20);
                    subfile.Metadata = metadata;

                    subfiles.Add(subfile);
                }
            }
            return(subfiles);
        }
예제 #3
0
 public ppParser(string path, ppFormat format)
 {
     this.Format = format;
     this.FilePath = path;
     using (FileStream stream = File.OpenRead(path))
     {
         this.Subfiles = format.ppHeader.ReadHeader(stream, format);
     }
 }
예제 #4
0
 public ppParser(string path, ppFormat format)
 {
     this.Format   = format;
     this.FilePath = path;
     using (FileStream stream = File.OpenRead(path))
     {
         this.Subfiles = format.ppHeader.ReadHeader(stream, format);
     }
 }
예제 #5
0
        public static ppParser OpenPP([DefaultVar] string path)
        {
            ppFormat format = ppFormat.GetFormat(path);

            if (format == null)
            {
                throw new Exception("Couldn't auto-detect the ppFormat");
            }
            return(new ppParser(path, format));
        }
예제 #6
0
 public ppParser(string path, ppFormat format)
 {
     this.Format   = format;
     this.FilePath = path;
     if (File.Exists(path))
     {
         this.Subfiles = format.ppHeader.ReadHeader(path, format);
     }
     else
     {
         this.Subfiles = new List <IWriteFile>();
     }
 }
예제 #7
0
 public ppParser(string path, ppFormat format)
 {
     this.Format = format;
     this.FilePath = path;
     if (File.Exists(path))
     {
         this.Subfiles = format.ppHeader.ReadHeader(path, format);
     }
     else
     {
         this.Subfiles = new List<IWriteFile>();
     }
 }
예제 #8
0
        public static ppFormat GetFormat(string path)
        {
            ppHeader header = null;

            for (int i = 0; i < ppHeader.Array.Length; i++)
            {
                try
                {
                    if ((header = ppHeader.Array[i].TryHeader(path)) != null)
                    {
                        break;
                    }
                }
                catch
                {
                }
            }

            ppFormat resultFormat = null;

            if (header != null)
            {
                if (header.ppFormats.Length == 1)
                {
                    resultFormat = header.ppFormats[0];
                }
                else
                {
                    List <IWriteFile> subfiles = header.ReadHeader(path, null);
                    for (int i = 0; i < subfiles.Count; i++)
                    {
                        if ((resultFormat = TryFile((ppSubfile)subfiles[i], header.ppFormats)) != null)
                        {
                            break;
                        }
                    }
                }

                if (resultFormat == null)
                {
                    resultFormat = header.ppFormats[0];
                    Report.ReportLog("Couldn't auto-detect the ppFormat for " + path + ". Using " + resultFormat.Name + " instead");
                }
            }

            return(resultFormat);
        }
예제 #9
0
 public static object OpenPP([DefaultVar] string path)
 {
     using (FileStream stream = File.OpenRead(path))
     {
         ppHeader header;
         ppFormat format = ppFormat.GetFormat(stream, out header);
         if (format == null)
         {
             if (header == null)
             {
                 throw new Exception("Couldn't auto-detect the ppFormat");
             }
             return(header);
         }
         return(new ppParser(stream, format));
     }
 }
예제 #10
0
파일: ppHeader.cs 프로젝트: ezdiy/GDImport
        public override List <IWriteFile> ReadHeader(FileStream stream, ppFormat format)
        {
            List <IWriteFile> subfiles = null;

            stream.Position = 0;
            BinaryReader reader = new BinaryReader(stream);

            byte[] versionHeader = reader.ReadBytes(8);
            Version = BitConverter.ToInt32(ppHeader_SMRetail.DecryptHeaderBytes(reader.ReadBytes(4)), 0);

            ppHeader_SMRetail.DecryptHeaderBytes(reader.ReadBytes(1));              // first byte
            int numFiles = BitConverter.ToInt32(ppHeader_SMRetail.DecryptHeaderBytes(reader.ReadBytes(4)), 0);

            byte[] buf = ppHeader_SMRetail.DecryptHeaderBytes(reader.ReadBytes(numFiles * 288));

            subfiles = new List <IWriteFile>(numFiles);
            for (int i = 0; i < numFiles; i++)
            {
                int       offset  = i * 288;
                ppSubfile subfile = new ppSubfile(stream.Name);
                subfile.ppFormat = format;
                int length = 260;
                for (int j = 0; j < length; j++)
                {
                    if (buf[offset + j] == 0x00)
                    {
                        length = j;
                        break;
                    }
                }
                subfile.Name   = Utility.EncodingShiftJIS.GetString(buf, offset, length);
                subfile.size   = BitConverter.ToUInt32(buf, offset + 260);
                subfile.offset = BitConverter.ToUInt32(buf, offset + 264);

                Metadata metadata = new Metadata();
                metadata.LastBytes = new byte[20];
                System.Array.Copy(buf, offset + 268, metadata.LastBytes, 0, 20);
                subfile.Metadata = metadata;

                subfiles.Add(subfile);
            }

            return(subfiles);
        }
예제 #11
0
파일: ppFormat.cs 프로젝트: ezdiy/GDImport
        public static ppFormat GetFormat(FileStream stream, out ppHeader header)
        {
            header = null;
            for (int i = 0; i < ppHeader.Array.Length; i++)
            {
                try
                {
                    if ((header = ppHeader.Array[i].TryHeader(stream)) != null)
                    {
                        break;
                    }
                }
                catch
                {
                }
            }

            ppFormat resultFormat = null;

            if (header != null)
            {
                if (header.ppFormats.Length == 1)
                {
                    resultFormat = header.ppFormats[0];
                }
                else
                {
                    List <IWriteFile> subfiles = header.ReadHeader(stream, null);
                    for (int i = 0; i < subfiles.Count; i++)
                    {
                        if ((resultFormat = TryFile(stream, (ppSubfile)subfiles[i], header.ppFormats)) != null)
                        {
                            break;
                        }
                    }
                }
            }

            return(resultFormat);
        }
예제 #12
0
파일: ppHeader.cs 프로젝트: ezdiy/GDImport
        public override List <IWriteFile> ReadHeader(FileStream stream, ppFormat format)
        {
            List <IWriteFile> subfiles = null;

            stream.Position = 0;
            BinaryReader binaryReader = new BinaryReader(stream);

            int numFiles = binaryReader.ReadInt32();

            subfiles = new List <IWriteFile>(numFiles);
            binaryReader.ReadInt32();              // total size

            // get filenames
            for (int i = 0; i < numFiles; i++)
            {
                byte[] nameBuf = binaryReader.ReadBytes(0x20);
                for (int j = 0; j < nameBuf.Length; j++)
                {
                    nameBuf[j] = (byte)(~nameBuf[j] + 1);
                }

                ppSubfile subfile = new ppSubfile(stream.Name);
                subfile.ppFormat = format;
                subfile.Name     = Utility.EncodingShiftJIS.GetString(nameBuf).TrimEnd(new char[] { '\0' });
                subfiles.Add(subfile);
            }

            // get filesizes
            uint offset = HeaderSize(numFiles);              // start of first file data

            for (int i = 0; i < numFiles; i++)
            {
                ppSubfile subfile = (ppSubfile)subfiles[i];
                subfile.offset = offset;
                subfile.size   = binaryReader.ReadUInt32();
                offset        += subfile.size;
            }

            return(subfiles);
        }
예제 #13
0
        public List<IWriteFile> ReadHeader(FileStream stream, ppFormat format, byte[] SMFigTable)
        {
            List<IWriteFile> subfiles = null;
            stream.Position = 0;
            BinaryReader binaryReader = new BinaryReader(stream);

            DecryptHeaderBytes(binaryReader.ReadBytes(1), SMFigTable);  // first byte
            int numFiles = BitConverter.ToInt32(DecryptHeaderBytes(binaryReader.ReadBytes(4), SMFigTable), 0);
            byte[] buf = DecryptHeaderBytes(binaryReader.ReadBytes(numFiles * 268), SMFigTable);

            subfiles = new List<IWriteFile>(numFiles);
            for (int i = 0; i < numFiles; i++)
            {
                int offset = i * 268;
                ppSubfile subfile = new ppSubfile(stream.Name);
                subfile.ppFormat = format;
                subfile.Name = Utility.EncodingShiftJIS.GetString(buf, offset, 260).TrimEnd(new char[] { '\0' });
                subfile.size = BitConverter.ToUInt32(buf, offset + 260);
                subfile.offset = BitConverter.ToUInt32(buf, offset + 264);
                subfiles.Add(subfile);
            }

            return subfiles;
        }
예제 #14
0
        public override List<IWriteFile> ReadHeader(FileStream stream, ppFormat format)
        {
            List<IWriteFile> subfiles = null;
            stream.Position = 0;
            BinaryReader binaryReader = new BinaryReader(stream);

            int numFiles = binaryReader.ReadInt32();

            subfiles = new List<IWriteFile>(numFiles);
            binaryReader.ReadInt32();  // total size

            // get filenames
            for (int i = 0; i < numFiles; i++)
            {
                byte[] nameBuf = binaryReader.ReadBytes(0x20);
                for (int j = 0; j < nameBuf.Length; j++)
                {
                    nameBuf[j] = (byte)(~nameBuf[j] + 1);
                }

                ppSubfile subfile = new ppSubfile(stream.Name);
                subfile.ppFormat = format;
                subfile.Name = Utility.EncodingShiftJIS.GetString(nameBuf).TrimEnd(new char[] { '\0' });
                subfiles.Add(subfile);
            }

            // get filesizes
            uint offset = HeaderSize(numFiles);  // start of first file data
            for (int i = 0; i < numFiles; i++)
            {
                ppSubfile subfile = (ppSubfile)subfiles[i];
                subfile.offset = offset;
                subfile.size = binaryReader.ReadUInt32();
                offset += subfile.size;
            }

            return subfiles;
        }
예제 #15
0
 public override List <IWriteFile> ReadHeader(string path, ppFormat format)
 {
     return(ReadHeader(path, format, InitTableFigure()));
 }
예제 #16
0
 public ppParser(string path, ppFormat format)
 {
     this.Format   = format;
     this.FilePath = path;
     this.Subfiles = format.ppHeader.ReadHeader(path, format);
 }
예제 #17
0
 public ppParser(string path, ppFormat format)
 {
     this.Format = format;
     this.FilePath = path;
     this.Subfiles = format.ppHeader.ReadHeader(path, format);
 }
예제 #18
0
 public override List<IWriteFile> ReadHeader(FileStream stream, ppFormat format)
 {
     return ReadHeader(stream, format, null);
 }
예제 #19
0
파일: ppHeader.cs 프로젝트: ezdiy/GDImport
 public abstract List <IWriteFile> ReadHeader(FileStream stream, ppFormat format);
예제 #20
0
 public abstract List <IWriteFile> ReadHeader(string path, ppFormat format);
예제 #21
0
 public ppParser(FileStream stream, ppFormat format)
 {
     this.Format   = format;
     this.FilePath = stream.Name;
     this.Subfiles = format.ppHeader.ReadHeader(stream, format);
 }
예제 #22
0
파일: ppHeader.cs 프로젝트: ezdiy/GDImport
 public override List <IWriteFile> ReadHeader(FileStream stream, ppFormat format)
 {
     return(ReadHeader(stream, format, InitTableFigure()));
 }
예제 #23
0
 public override List<IWriteFile> ReadHeader(FileStream stream, ppFormat format)
 {
     return ReadHeader(stream, format, InitTableFigure());
 }
예제 #24
0
        private static ppFormat TryFile(ppSubfile subfile, ppFormat[] formats)
        {
            Func<ppSubfile, bool> tryFunc = null;

            string ext = Path.GetExtension(subfile.Name).ToLower();
            if (ext == ".xx")
            {
                tryFunc = new Func<ppSubfile, bool>(TryFileXX);
            }
            else if (ext == ".xa")
            {
                tryFunc = new Func<ppSubfile, bool>(TryFileXA);
            }
            else if (ext == ".bmp")
            {
                tryFunc = new Func<ppSubfile, bool>(TryFileBMP);
            }
            else if (ext == ".tga")
            {
                tryFunc = new Func<ppSubfile, bool>(TryFileTGA);
            }
            else if (ext == ".ema")
            {
                tryFunc = new Func<ppSubfile, bool>(TryFileEMA);
            }
            else if (Utility.ImageSupported(ext))
            {
                tryFunc = new Func<ppSubfile, bool>(TryFileImage);
            }
            else if (ext == ".lst")
            {
                tryFunc = new Func<ppSubfile, bool>(TryFileLst);
            }
            else if (ext == ".wav" || ext == ".ogg")
            {
                tryFunc = new Func<ppSubfile, bool>(TryFileSound);
            }

            if (tryFunc != null)
            {
                for (int i = 0; i < formats.Length; i++)
                {
                    subfile.ppFormat = formats[i];
                    if (tryFunc(subfile))
                    {
                        return subfile.ppFormat;
                    }
                }
            }

            return null;
        }
예제 #25
0
 public abstract List<IWriteFile> ReadHeader(FileStream stream, ppFormat format);
예제 #26
0
 public override List<IWriteFile> ReadHeader(string path, ppFormat format)
 {
     return ReadHeader(path, format, InitTableFigure());
 }
예제 #27
0
        public override List<IWriteFile> ReadHeader(FileStream stream, ppFormat format)
        {
            List<IWriteFile> subfiles = null;
            stream.Position = 0;
            BinaryReader reader = new BinaryReader(stream);

            byte[] versionHeader = reader.ReadBytes(8);
            Version = BitConverter.ToInt32(ppHeader_SMRetail.DecryptHeaderBytes(reader.ReadBytes(4)), 0);

            ppHeader_SMRetail.DecryptHeaderBytes(reader.ReadBytes(1));  // first byte
            int numFiles = BitConverter.ToInt32(ppHeader_SMRetail.DecryptHeaderBytes(reader.ReadBytes(4)), 0);
            byte[] buf = ppHeader_SMRetail.DecryptHeaderBytes(reader.ReadBytes(numFiles * 288));

            subfiles = new List<IWriteFile>(numFiles);
            for (int i = 0; i < numFiles; i++)
            {
                int offset = i * 288;
                ppSubfile subfile = new ppSubfile(stream.Name);
                subfile.ppFormat = format;
                int length = 260;
                for (int j = 0; j < length; j++)
                {
                    if (buf[offset + j] == 0x00)
                    {
                        length = j;
                        break;
                    }
                }
                subfile.Name = Utility.EncodingShiftJIS.GetString(buf, offset, length);
                subfile.size = BitConverter.ToUInt32(buf, offset + 260);
                subfile.offset = BitConverter.ToUInt32(buf, offset + 264);

                Metadata metadata = new Metadata();
                metadata.LastBytes = new byte[20];
                System.Array.Copy(buf, offset + 268, metadata.LastBytes, 0, 20);
                subfile.Metadata = metadata;

                subfiles.Add(subfile);
            }

            return subfiles;
        }
예제 #28
0
 public abstract List<IWriteFile> ReadHeader(string path, ppFormat format);
예제 #29
0
 public override List <IWriteFile> ReadHeader(string path, ppFormat format)
 {
     return(ReadHeader(path, format, null));
 }
예제 #30
0
 public override List<IWriteFile> ReadHeader(string path, ppFormat format)
 {
     return ReadHeader(path, format, null);
 }
예제 #31
0
        private static ppFormat TryFile(Stream stream, ppSubfile subfile, ppFormat[] formats)
        {
            Func<Stream, ppSubfile, bool> tryFunc = null;

            string ext = Path.GetExtension(subfile.Name).ToLower();
            if (ext == ".xx")
            {
                tryFunc = new Func<Stream, ppSubfile, bool>(TryFileXX);
            }
            else if (ext == ".xa")
            {
                tryFunc = new Func<Stream, ppSubfile, bool>(TryFileXA);
            }
            else if (ext == ".svi")
            {
                tryFunc = new Func<Stream, ppSubfile, bool>(TryFileSVI);
            }
            else if (ext == ".sviex")
            {
                tryFunc = new Func<Stream, ppSubfile, bool>(TryFileSVIEX);
            }
            else if (ext == ".bmp")
            {
                tryFunc = new Func<Stream, ppSubfile, bool>(TryFileBMP);
            }
            else if (ext == ".tga")
            {
                tryFunc = new Func<Stream, ppSubfile, bool>(TryFileTGA);
            }
            else if (ext == ".ema")
            {
                tryFunc = new Func<Stream, ppSubfile, bool>(TryFileEMA);
            }
            else if (Utility.ImageSupported(ext))
            {
                tryFunc = new Func<Stream, ppSubfile, bool>(TryFileImage);
            }
            else if (ext == ".lst")
            {
                tryFunc = new Func<Stream, ppSubfile, bool>(TryFileLst);
            }
            else if (ext == ".wav" || ext == ".ogg")
            {
                tryFunc = new Func<Stream, ppSubfile, bool>(TryFileSound);
            }

            if (tryFunc != null)
            {
                for (int i = 0; i < formats.Length; i++)
                {
                    subfile.ppFormat = formats[i];
                    stream.Position = subfile.offset;
                    if (tryFunc(subfile.ppFormat.ReadStream(new PartialStream(stream, subfile.size)), subfile))
                    {
                        return subfile.ppFormat;
                    }
                }
            }

            return null;
        }
예제 #32
0
        public override List<IWriteFile> ReadHeader(string path, ppFormat format)
        {
            List<IWriteFile> subfiles = null;
            using (BinaryReader reader = new BinaryReader(File.OpenRead(path)))
            {
                byte[] versionHeader = reader.ReadBytes(8);
                int version = BitConverter.ToInt32(ppHeader_SMRetail.DecryptHeaderBytes(reader.ReadBytes(4)), 0);

                ppHeader_SMRetail.DecryptHeaderBytes(reader.ReadBytes(1));  // first byte
                int numFiles = BitConverter.ToInt32(ppHeader_SMRetail.DecryptHeaderBytes(reader.ReadBytes(4)), 0);
                byte[] buf = ppHeader_SMRetail.DecryptHeaderBytes(reader.ReadBytes(numFiles * 288));

                subfiles = new List<IWriteFile>(numFiles);
                for (int i = 0; i < numFiles; i++)
                {
                    int offset = i * 288;
                    ppSubfile subfile = new ppSubfile(path);
                    subfile.ppFormat = format;
                    subfile.Name = Utility.EncodingShiftJIS.GetString(buf, offset, 260).TrimEnd(new char[] { '\0' });
                    subfile.size = BitConverter.ToInt32(buf, offset + 260);
                    subfile.offset = BitConverter.ToInt32(buf, offset + 264);

                    Metadata metadata = new Metadata();
                    metadata.LastBytes = new byte[20];
                    System.Array.Copy(buf, offset + 268, metadata.LastBytes, 0, 20);
                    subfile.Metadata = metadata;

                    subfiles.Add(subfile);
                }
            }
            return subfiles;
        }
예제 #33
0
 public ppParser(FileStream stream, ppFormat format)
 {
     this.Format = format;
     this.FilePath = stream.Name;
     this.Subfiles = format.ppHeader.ReadHeader(stream, format);
 }
예제 #34
0
파일: ppHeader.cs 프로젝트: ezdiy/GDImport
 public override List <IWriteFile> ReadHeader(FileStream stream, ppFormat format)
 {
     return(ReadHeader(stream, format, null));
 }