protected override void _Read(BinaryReader reader) { uint identifier = reader.ReadUInt32(); reader.BaseStream.Seek(-4, SeekOrigin.Current); if (!TEXN.IsValid(identifier)) { return; } while (reader.BaseStream.CanRead) { if (reader.BaseStream.Position >= reader.BaseStream.Length - 16) { break; } uint token = reader.ReadUInt32(); if (token == 0) { continue; } reader.BaseStream.Seek(-4, SeekOrigin.Current); TEXN texture = new TEXN(reader); if (TextureDatabase.Automatic) { TextureDatabase.AddTexture(texture); } Textures.Add(texture); } }
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(); } }