Example #1
0
        /// <summary>
        /// Reads a .bundle file.
        /// </summary>
        private void Read(string filename)
        {
            FileName = filename;
            Name     = filename.Split('\\').Last();

            using (var br = new BinaryReader(new FileStream(FileName, FileMode.Open, FileAccess.Read)))
            {
                //read bundleheader
                Header = new BundleHeader();
                Header.Read(br);
                if (!IDString.SequenceEqual(Header.IDString))
                {
                    throw new InvalidBundleException("Bundle header mismatch.");
                }

                //Read Table of Contents
                br.BaseStream.Seek(0x20, SeekOrigin.Begin);
                while (br.BaseStream.Position < Header.TocRealSize + 0x20)
                {
                    var item = new BundleItem
                    {
                        Bundle = this
                    };

                    var strname = Encoding.Default.GetString(br.ReadBytes(0x100));

                    item.DepotPath  = strname.Substring(0, strname.IndexOf('\0'));
                    item.Hash       = br.ReadBytes(16);
                    item.Empty      = br.ReadUInt32();
                    item.Size       = br.ReadUInt32();
                    item.ZSize      = br.ReadUInt32();
                    item.PageOffset = br.ReadUInt32();

                    var date = br.ReadUInt32();
                    var y    = date >> 20;
                    var m    = date >> 15 & 0x1F;
                    var d    = date >> 10 & 0x1F;

                    var time = br.ReadUInt32();
                    var h    = time >> 22;
                    var n    = time >> 16 & 0x3F;
                    var s    = time >> 10 & 0x3F;

                    item.DateString = string.Format(" {0}/{1}/{2} {3}:{4}:{5}", d, m, y, h, n, s);

                    item.Zero        = br.ReadBytes(16); //00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 (always, in every archive)
                    item.CRC         = br.ReadUInt32();
                    item.Compression = br.ReadUInt32();

                    Items.Add(item);
                }


                br.Close();
            }
        }