/// <summary> /// Reads a Metadata_Store from a metadata.store file. /// </summary> /// <param name="filepath"></param> private void Read(string filepath) { Console.WriteLine("Reading: " + filepath); using (var br = new BinaryReader(new FileStream(filepath, FileMode.Open))) { if (br.ReadUInt32() != VTM) { throw new InvalidDataException("Wrong Magic when reading the metadata.store file!"); } Version = br.ReadInt32(); MaxFileSizeInBundle = br.ReadUInt32(); MaxFileSIzeInMemory = br.ReadUInt32(); var StringTableSize = br.ReadVLQInt32(); //Read the string table /* * empty line => "" * <everything> * empty line => "" * parts so stuff like * bundles\\buffers.bundle is here split * by the \\ for the non bundles this is * basically if you would * do a virtual tree inside the bundles * one more empty line at the end=> "" */ FileStringTable = br.ReadBytes(StringTableSize).ToList(); //Read the file infos fileInfoList = new TDynArray <UFileInfo>(); fileInfoList.Deserialize(br); using (var ms = new MemoryStream(FileStringTable.ToArray())) { using (var brr = new BinaryReader(ms)) { foreach (var inf in fileInfoList) { brr.BaseStream.Seek(inf.StringTableNameOffset, SeekOrigin.Begin); inf.path = ReadCR2WString(brr); } } } //Read the file entry infos fileEntryInfoList = new TDynArray <UFileEntryInfo>(); fileEntryInfoList.Deserialize(br); //Read the Bundle Infos bundleInfoList = new TDynArray <UBundleInfo>(); bundleInfoList.Deserialize(br); //Read the buffers var buffercount = br.ReadVLQInt32(); if (buffercount > 0) { for (int i = 0; i < buffercount; i++) { Buffers.Add(br.ReadInt32()); } } //Read dir initialization infos dirInitInfoList = new TDynArray <UDirInitInfo>(); dirInitInfoList.Deserialize(br); //File initialization infos fileInitInfoList = new TDynArray <UFileInitInfo>(); fileInitInfoList.Deserialize(br); //Hashes hashes = new TDynArray <UHash>(); hashes.Deserialize(br); if (br.BaseStream.Position == br.BaseStream.Length) { Console.WriteLine("Succesfully read everything!"); } else { Console.WriteLine($"Reader is at {br.BaseStream.Position} bytes. The length of the file is { br.BaseStream.Length} bytes.\n{ br.BaseStream.Length-br.BaseStream.Position} bytes wasn't read."); } } }
public Metadata_Store(string filepath) { Console.WriteLine("Reading: " + filepath); using (var br = new BinaryReader(new FileStream(filepath, FileMode.Open))) { if (!br.ReadBytes(4).SequenceEqual(Magic)) { throw new InvalidDataException("Wrong Magic when reading the metadata.store file!"); } Version = br.ReadInt32(); Console.WriteLine("Version: " + Version); BiggestFileSizeCompressed = br.ReadInt32(); Console.WriteLine("BiggestFileSizeCompressed: " + BiggestFileSizeCompressed); BiggestFileSize = br.ReadInt32(); Console.WriteLine("BiggestFileSize: " + BiggestFileSize); StringTableSize = br.ReadBit6().value; Console.WriteLine("String table size: " + StringTableSize); FileStringTable = new string(br.ReadChars(StringTableSize)).Split('\0').ToList(); Console.WriteLine("\n-----------------------------------\nFile string table:"); Console.WriteLine(FileStringTable.Aggregate("", (c, n) => c += "\n" + n)); Console.WriteLine("-----------------------------------"); fileInfoList = new TDynArray <UFileInfo>(); fileInfoList.Deserialize(br); fileEntryInfoList = new TDynArray <UFileEntryInfo>(); fileEntryInfoList.Deserialize(br); bundleInfoList = new TDynArray <UBundleInfo>(); bundleInfoList.Deserialize(br); unknownType01List = new TDynArray <UnknownType01>(); unknownType01List.Deserialize(br); unknownType02List = new TDynArray <UnknownType02>(); unknownType02List.Deserialize(br); dirInitInfoList = new TDynArray <UDirInitInfo>(); dirInitInfoList.Deserialize(br); unknownType03List = new TDynArray <UnknownType03>(); unknownType03List.Deserialize(br); //FileCount = br.ReadInt32() - 1; //Console.WriteLine("FileCount: " + FileCount); //br.BaseStream.Seek(0x17, SeekOrigin.Current); //FileRecords = new List<FileRecord>(); //for (var i = 0; i < FileCount; i++) //{ // FileRecords.Add(new FileRecord // { // FilePathLength = br.ReadInt32(), // FileSIzeCompressed = br.ReadInt32(), // FileSize = br.ReadInt32(), // FileIndex = br.ReadInt32(), // CompressionType = br.ReadInt32(), // LastIndex = br.ReadInt32() // }); //} var a = br.BaseStream.Position; } }