Skip to content

Instantly share code, notes, and snippets.

@Traderain
Last active June 20, 2017 16:53
Show Gist options
  • Save Traderain/08df5788e9cc870ab07d26bbb9f61a7a to your computer and use it in GitHub Desktop.
Save Traderain/08df5788e9cc870ab07d26bbb9f61a7a to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WolvenKit.W3Strings;
namespace TestStuff
{
class Program
{
[STAThread]
static void Main(string[] args)
{
Console.Title = "Metadata.store reader!";
using (var of = new OpenFileDialog())
{
of.Filter = "Witcher 3 Metadata files | metadata.store";
if (of.ShowDialog() == DialogResult.OK)
{
var ms = new Metadata_Store(of.FileName);
}
}
Console.ReadKey();
}
}
public class Metadata_Store
{
public byte[] Magic = {0x03, 0x56, 0x54, 0x4D}; // ".VTM"
public Int32 Version = 6;
public Int32 BiggestFileSizeCompressed;
public Int32 BiggestFileSize;
public Int32 StringTableSize;
public List<string> FileStringTable;
public Int32 FileCount;
public List<FileRecord> FileRecords;
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("-----------------------------------");
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;
}
}
//TODO: Constructor with List<Bundle>();
public void Write(string path)
{
}
}
public class FileRecord
{
public Int32 FilePathLength;
//4 null bytes
public Int32 FileSIzeCompressed;
public Int32 FileSize;
public Int32 FileIndex;
public Int32 CompressionType;
//8 null bytes
public Int32 LastIndex;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment