Created
August 3, 2017 07:46
-
-
Save Traderain/6ef6eeb572427bc555f6680b861bf24e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ShaderCache | |
{ | |
public byte[] IdString = { (byte)'R', (byte)'D', (byte)'H', (byte)'S' }; | |
public uint Version; | |
public Int64 FileTableOffset1; | |
public Int64 FileTableOffset2; | |
public Int64 Unk1; | |
public List<Tuple<byte[],Int32>> Files = new List<Tuple<byte[], int>>(); | |
public ShaderCache(string filename) | |
{ | |
this.Read(new BinaryReader(new FileStream(filename, FileMode.Open))); | |
} | |
public void Read(BinaryReader br) | |
{ | |
br.BaseStream.Seek(-32, SeekOrigin.End); | |
FileTableOffset2 = br.ReadInt64(); | |
Unk1 = br.ReadInt64(); | |
FileTableOffset1 = br.ReadInt64(); | |
if (!br.ReadBytes(4).SequenceEqual(IdString)) | |
throw new Exception("Invalid file!"); | |
this.Version = br.ReadUInt32(); | |
var len = 0; | |
br.BaseStream.Seek(FileTableOffset1, SeekOrigin.Begin); | |
len = br.ReadInt32(); | |
do | |
{ | |
var info = br.ReadBytes(len); | |
var hash = br.ReadInt32(); | |
br.BaseStream.Seek(0x30, SeekOrigin.Current); | |
Files.Add(new Tuple<byte[], int>(info,hash)); | |
len = br.ReadInt32(); | |
} while ((len + 0x30 + 4 + br.BaseStream.Position) < br.BaseStream.Length); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment