Example #1
0
        /*
         * Reads pack header from the given reader.
         */
        public static PFHeader ReadHeader(BinaryReader reader)
        {
            PFHeader header;
            string   packIdentifier = new string (reader.ReadChars(4));

            header = new PFHeader(packIdentifier);
            int packType = reader.ReadInt32();

            header.PrecedenceByte = (byte)packType;
            // header.Type = (PackType)packType;
            header.Version = reader.ReadInt32();
            int replacedPackFilenameLength = reader.ReadInt32();

            reader.BaseStream.Seek(0x10L, SeekOrigin.Begin);
            header.FileCount = reader.ReadUInt32();
            UInt32 indexSize = reader.ReadUInt32();

            header.DataStart = header.Length + indexSize;

            if (header.PackIdentifier == "PFH4")
            {
                header.Unknown = reader.ReadUInt32();
            }

            // go to correct position
            reader.BaseStream.Seek(header.Length, SeekOrigin.Begin);
            for (int i = 0; i < header.Version; i++)
            {
                header.ReplacedPackFileNames.Add(IOFunctions.ReadZeroTerminatedAscii(reader));
            }
            header.DataStart += replacedPackFilenameLength;
            return(header);
        }
Example #2
0
        /*
         * Decode pack file at the given path.
         */
        public PackFile Open(string packFullPath)
        {
            PackFile file;
            long     sizes = 0;

            using (var reader = new BinaryReader(new FileStream(packFullPath, FileMode.Open), Encoding.ASCII))
            {
                PFHeader header = ReadHeader(reader);
                file = new PackFile(packFullPath, header);
                OnHeaderLoaded(header);

                long offset = file.Header.DataStart;
                for (int i = 0; i < file.Header.FileCount; i++)
                {
                    uint size = reader.ReadUInt32();
                    sizes += size;
                    if (file.Header.HasAdditionalInfo)
                    {
                        header.AdditionalInfo = reader.ReadInt64();
                    }
                    string packedFileName = IOFunctions.ReadZeroTerminatedAscii(reader);
                    // this is easier because we can use the Path methods
                    // under both Windows and Unix
                    packedFileName = packedFileName.Replace('\\', Path.DirectorySeparatorChar);

                    PackedFile packed = new PackedFile(file.Filepath, packedFileName, offset, size);
                    file.Add(packed);
                    offset += size;
                    this.OnPackedFileLoaded(packed);
                }
            }
            this.OnFinishedLoading(file);
            file.IsModified = false;
            return(file);
        }