Exemplo n.º 1
0
        public PackFile(string fileName)
        {
            FileName = fileName;
            Entries  = new Dictionary <string, PackEntry>();

            stream = File.OpenRead(fileName);
            br     = new BinaryReader(stream);

            string magic = Encoding.ASCII.GetString(br.ReadBytes(4));

            if (magic != "PACK")
            {
                throw new FormatException($"Invalid PAK file: got {magic}, expected PACK");
            }

            int dirOffset = br.ReadInt32();
            int dirSize   = br.ReadInt32();

            stream.Seek(dirOffset, SeekOrigin.Begin);
            for (var i = 0; i < dirSize / 64; i++)
            {
                string    file   = Encoding.ASCII.GetString(br.ReadBytes(56));
                int       offset = br.ReadInt32();
                int       size   = br.ReadInt32();
                PackEntry e      = new PackEntry(file, offset, size);

                Entries.Add(e.FileName, e);
            }
        }
Exemplo n.º 2
0
        public Stream GetFile(string path)
        {
            PackEntry e = Entries[path];

            stream.Seek(e.Offset, SeekOrigin.Begin);

            byte[] bytes = new byte[e.Size];
            stream.Read(bytes, 0, e.Size);
            return(new MemoryStream(bytes));
        }