Exemple #1
0
 /// <summary>
 /// Extracts the specified entry to a file.
 /// </summary>
 /// <param name="entry">An archive entry.</param>
 /// <param name="path">The path to extract the file to.</param>
 public void ExtractToFile(ArchiveEntry entry, string path)
 {
     using (Stream source = OpenEntry(entry), destination = File.Create(path))
     {
         PTStream.CopyTo(source, destination);
     }
 }
Exemple #2
0
        public override Stream OpenEntry(ArchiveEntry entry)
        {
            // If this archive does not contain any global indexes, then just return the data as is.
            if (!hasGlobalIndexes)
            {
                return(base.OpenEntry(entry));
            }

            long oldPosition = archiveData.Position;

            MemoryStream data = new MemoryStream();

            // Write out the GBIX header
            data.WriteByte((byte)'G');
            data.WriteByte((byte)'B');
            data.WriteByte((byte)'I');
            data.WriteByte((byte)'X');
            PTStream.WriteInt32(data, 8);

            archiveData.Position = 0xC + (entry.Index * tableEntryLength) + globalIndexOffset;
            PTStream.WriteUInt32(data, PTStream.ReadUInt32(archiveData));

            data.Position += 4;

            // Now copy over the file data
            archiveData.Position = entry.Offset;
            PTStream.CopyPartTo(archiveData, data, entry.Length);

            archiveData.Position = oldPosition;
            data.Position        = 0;

            return(data);
        }
Exemple #3
0
        public override Stream OpenEntry(ArchiveEntry entry)
        {
            // Some Billy Hatcher textures have an oddity where the texture length is 16 more than what it
            // actually should be. This seems to only effect the last texture of a GVM, and only some of them
            // are affected. In that case, we will "fix" the GVRs in question.
            bool needToFix = (entry.Index == entries.Count - 1 && this.needToFix);

            // If this archive does not contain any global indicies, then just return the data as is.
            if (!hasGlobalIndexes && !needToFix)
            {
                return(base.OpenEntry(entry));
            }

            long oldPosition = archiveData.Position;

            MemoryStream data = new MemoryStream();

            // Write out the GBIX header, if this archive contains global indexes
            if (hasGlobalIndexes)
            {
                data.WriteByte((byte)'G');
                data.WriteByte((byte)'B');
                data.WriteByte((byte)'I');
                data.WriteByte((byte)'X');
                PTStream.WriteInt32(data, 8);

                archiveData.Position = 0xC + (entry.Index * tableEntryLength) + globalIndexOffset;
                PTStream.WriteInt32BE(data, PTStream.ReadInt32BE(archiveData));

                data.Position += 4;
            }

            // Now copy over the file data
            archiveData.Position = entry.Offset;
            PTStream.CopyPartTo(archiveData, data, entry.Length);

            // Fix the texture lengths for the textures that need to be "fixed"
            if (needToFix)
            {
                if (hasGlobalIndexes)
                {
                    data.Position = 0x14;
                }
                else
                {
                    data.Position = 0x4;
                }

                uint actualLength = PTStream.ReadUInt32(data);
                data.Position -= 4;
                PTStream.WriteUInt32(data, actualLength - 16);
            }

            archiveData.Position = oldPosition;
            data.Position        = 0;

            return(data);
        }
        public override Stream OpenEntry(ArchiveEntry entry)
        {
            archiveData.Seek(entry.Offset, SeekOrigin.Begin);
            var memoryStream = new MemoryStream();

            _prsCompression.Decompress(archiveData, memoryStream);
            memoryStream.Seek(0, SeekOrigin.Begin);
            return(memoryStream);
        }
Exemple #5
0
        /// <summary>
        /// Opens the specified entry in the archive.
        /// </summary>
        /// <param name="entry">An archive entry.</param>
        /// <returns>The stream that represents the contents of the entry.</returns>
        public virtual Stream OpenEntry(ArchiveEntry entry)
        {
            if (entry == null || entry.ArchiveReader != this)
            {
                throw new ArgumentException("entry");
            }

            return(new StreamView(archiveData, entry.Offset, entry.Length));
        }
Exemple #6
0
        public override Stream OpenEntry(ArchiveEntry entry)
        {
            // If this archive does not contain any global indexes, then just return the data as is.
            if (!hasGlobalIndexes)
            {
                return base.OpenEntry(entry);
            }

            long oldPosition = archiveData.Position;

            MemoryStream data = new MemoryStream();

            // Write out the GBIX header
            data.WriteByte((byte)'G');
            data.WriteByte((byte)'B');
            data.WriteByte((byte)'I');
            data.WriteByte((byte)'X');
            PTStream.WriteInt32(data, 8);

            archiveData.Position = 0xC + (entry.Index * tableEntryLength) + globalIndexOffset;
            PTStream.WriteUInt32(data, PTStream.ReadUInt32(archiveData));

            data.Position += 4;

            // Now copy over the file data
            archiveData.Position = entry.Offset;
            PTStream.CopyPartTo(archiveData, data, entry.Length);

            archiveData.Position = oldPosition;
            data.Position = 0;

            return data;
        }
Exemple #7
0
 /// <summary>
 /// Adds the specified entry to the ArchiveEntryCollection associated with this archive.
 /// </summary>
 /// <param name="entry">An archive entry.</param>
 protected void AddEntry(ArchiveEntry entry)
 {
     entries.Add(entry);
 }
Exemple #8
0
 /// <summary>
 /// Adds an item to the ArchiveEntryCollection.
 /// </summary>
 /// <param name="item"></param>
 internal void Add(ArchiveEntry item)
 {
     entries.Add(item);
     entries[entries.Count - 1].Index = entries.Count - 1;
 }
Exemple #9
0
 /// <summary>
 /// Adds an item to the ArchiveEntryCollection.
 /// </summary>
 /// <param name="item"></param>
 internal void Add(ArchiveEntry item)
 {
     entries.Add(item);
     entries[entries.Count - 1].Index = entries.Count - 1;
 }
Exemple #10
0
        public override Stream OpenEntry(ArchiveEntry entry)
        {
            // Some Billy Hatcher textures have an oddity where the texture length is 16 more than what it
            // actually should be. This seems to only effect the last texture of a GVM, and only some of them
            // are affected. In that case, we will "fix" the GVRs in question.
            bool needToFix = (entry.Index == entries.Count - 1 && this.needToFix);

            // If this archive does not contain any global indicies, then just return the data as is.
            if (!hasGlobalIndexes && !needToFix)
            {
                return base.OpenEntry(entry);
            }

            long oldPosition = archiveData.Position;

            MemoryStream data = new MemoryStream();

            // Write out the GBIX header, if this archive contains global indexes
            if (hasGlobalIndexes)
            {
                data.WriteByte((byte)'G');
                data.WriteByte((byte)'B');
                data.WriteByte((byte)'I');
                data.WriteByte((byte)'X');
                PTStream.WriteInt32(data, 8);

                archiveData.Position = 0xC + (entry.Index * tableEntryLength) + globalIndexOffset;
                PTStream.WriteInt32BE(data, PTStream.ReadInt32BE(archiveData));

                data.Position += 4;
            }

            // Now copy over the file data
            archiveData.Position = entry.Offset;
            PTStream.CopyPartTo(archiveData, data, entry.Length);

            // Fix the texture lengths for the textures that need to be "fixed"
            if (needToFix)
            {
                if (hasGlobalIndexes)
                {
                    data.Position = 0x14;
                }
                else
                {
                    data.Position = 0x4;
                }

                uint actualLength = PTStream.ReadUInt32(data);
                data.Position -= 4;
                PTStream.WriteUInt32(data, actualLength - 16);
            }

            archiveData.Position = oldPosition;
            data.Position = 0;

            return data;
        }
Exemple #11
0
 /// <summary>
 /// Adds the specified entry to the ArchiveEntryCollection associated with this archive.
 /// </summary>
 /// <param name="entry">An archive entry.</param>
 protected void AddEntry(ArchiveEntry entry)
 {
     entries.Add(entry);
 }
Exemple #12
0
        /// <summary>
        /// Opens the specified entry in the archive.
        /// </summary>
        /// <param name="entry">An archive entry.</param>
        /// <returns>The stream that represents the contents of the entry.</returns>
        public virtual Stream OpenEntry(ArchiveEntry entry)
        {
            if (entry == null || entry.ArchiveReader != this)
            {
                throw new ArgumentException("entry");
            }

            return new StreamView(archiveData, entry.Offset, entry.Length);
        }
Exemple #13
0
 /// <summary>
 /// Extracts the specified entry to a file.
 /// </summary>
 /// <param name="entry">An archive entry.</param>
 /// <param name="path">The path to extract the file to.</param>
 public void ExtractToFile(ArchiveEntry entry, string path)
 {
     using (Stream source = OpenEntry(entry), destination = File.Create(path))
     {
         PTStream.CopyTo(source, destination);
     }
 }