コード例 #1
0
        protected override void _Read(BinaryReader reader)
        {
            byte[] gzipSignature = reader.ReadBytes(2);
            reader.BaseStream.Seek(-2, SeekOrigin.Current);

            Compress = false;
            MemoryStream streamOut = null;

            if (GZ.IsValid(gzipSignature))
            {
                streamOut = new MemoryStream();
                GZipStream streamGZip = new GZipStream(reader.BaseStream, CompressionMode.Decompress);
                streamGZip.CopyTo(streamOut);
                reader = new BinaryReader(streamOut);
                reader.BaseStream.Seek(0, SeekOrigin.Begin);
                Compress = true;
            }

            Signature = reader.ReadUInt32();
            if (!IsValid(Signature))
            {
                throw new InvalidFileSignatureException();
            }

            IPACOffset = reader.ReadUInt32();
            Unknown1   = reader.ReadUInt32();
            Unknown2   = reader.ReadUInt32();
            IPAC       = new IPAC(reader);

            if (Compress)
            {
                reader.Close();
            }
        }
コード例 #2
0
ファイル: PKF.cs プロジェクト: psyouloveme/ShenmueDKSharp
 /// <summary>
 /// Unpacks all files into the given folder or, when empty, in an folder next to the PKF file.
 /// </summary>
 public void Unpack(string folder = "")
 {
     if (String.IsNullOrEmpty(folder))
     {
         folder = Path.GetDirectoryName(FilePath) + "\\_" + FileName + "_";
     }
     if (!Directory.Exists(folder))
     {
         Directory.CreateDirectory(folder);
     }
     for (int i = 0; i < Entries.Count; i++)
     {
         PKFEntry entry = (PKFEntry)Entries[i];
         using (FileStream stream = new FileStream(String.Format(folder + "\\file_{0}.{1}", i, entry.TokenString), FileMode.Create))
         {
             stream.Write(entry.Buffer, 0, entry.Buffer.Length);
         }
     }
     if (IPAC != null)
     {
         IPAC.Unpack(folder);
     }
 }
コード例 #3
0
ファイル: PKF.cs プロジェクト: psyouloveme/ShenmueDKSharp
        protected override void _Read(BinaryReader reader)
        {
            byte[] gzipSignature = reader.ReadBytes(2);
            reader.BaseStream.Seek(-2, SeekOrigin.Current);

            Compress = false;
            MemoryStream streamOut = null;

            if (GZ.IsValid(gzipSignature))
            {
                streamOut = new MemoryStream();
                GZipStream streamGZip = new GZipStream(reader.BaseStream, CompressionMode.Decompress);
                streamGZip.CopyTo(streamOut);
                reader = new BinaryReader(streamOut);
                reader.BaseStream.Seek(0, SeekOrigin.Begin);
                Compress = true;
            }

            //Read header
            Identifier = reader.ReadUInt32();
            if (!IsValid(Identifier))
            {
                throw new InvalidFileSignatureException();
            }

            ContentSize = reader.ReadUInt32();
            Unknown     = reader.ReadUInt32();
            FileCount   = reader.ReadUInt32();

            //Check for DUMY
            if (reader.ReadUInt32() == PKFEntry.DUMY_Entry.Token)
            {
                //Skip DUMY
                int dummySize = reader.ReadInt32();
                reader.BaseStream.Seek(dummySize - 8, SeekOrigin.Current);
            }
            else
            {
                reader.BaseStream.Seek(-4, SeekOrigin.Current);
            }

            //Read files
            for (int i = 0; i < FileCount; i++)
            {
                if (reader.BaseStream.Position == reader.BaseStream.Length)
                {
                    break;
                }

                //Test read token to filter out broken PKF files
                uint token = reader.ReadUInt32();
                if (token == 0)
                {
                    continue;
                }
                reader.BaseStream.Seek(-4, SeekOrigin.Current);

                PKFEntry entry = new PKFEntry();
                entry.Read(reader);
                entry.Index = (uint)i;
                Entries.Add(entry);

                if (TextureDatabase.Automatic)
                {
                    if (entry.TokenString.ToUpper() == "TEXN")
                    {
                        using (MemoryStream stream = new MemoryStream(entry.Buffer))
                        {
                            TextureDatabase.AddTexture(new TEXN(stream));
                        }
                    }
                }
            }

            reader.BaseStream.Seek(ContentSize, SeekOrigin.Begin);
            if (reader.BaseStream.CanRead && reader.BaseStream.Position + 8 < reader.BaseStream.Length)
            {
                try
                {
                    IPAC = new IPAC(reader);
                }
                catch (Exception e)
                {
                }
            }

            if (Compress)
            {
                reader.Close();
            }
        }