/// <summary> /// Loads the data for the given entry /// </summary> public byte[] LoadEntry(Entry entry) { lock (Reader) { Reader.BaseStream.Position = entry.Offset; switch (entry.Flags[0] & 0x0F) { case 0: return(Reader.ReadBytes((int)entry.CompressedSize)); case 1: return(ZLIB.Decompress(Reader.ReadBytes((int)entry.CompressedSize), -15)); case 2: return(ZStandard.Decompress(Reader.ReadBytes((int)entry.CompressedSize))); default: throw new Exception("Invalid Entry Compression"); } } }
/// <summary> /// Loads entries from a binary file /// </summary> /// <param name="fileName">File to load from</param> public void LoadBinary(string fileName) { try { using (var fileReader = new BinaryReader(File.OpenRead(fileName))) { var magic = fileReader.ReadUInt64(); var compression = fileReader.ReadUInt64(); var compressedSize = fileReader.ReadInt64(); var decompressedSize = fileReader.ReadInt64(); byte[] buffer = null; switch (compression) { case 0: buffer = fileReader.ReadBytes((int)compressedSize); break; case 1: buffer = ZLIB.Decompress(fileReader.ReadBytes((int)compressedSize)); break; case 2: buffer = ZStandard.Decompress(fileReader.ReadBytes((int)compressedSize)); break; case 3: buffer = LZ4.Decompress(fileReader.ReadBytes((int)compressedSize), (int)decompressedSize); break; default: throw new Exception("Invalid cache compression"); } using (var reader = new BinaryReader(new MemoryStream(buffer))) { var count = (int)reader.ReadUInt64(); switch (magic) { // 32Bit Cache case 0x3130454843414354: { for (int i = 0; i < count; i++) { Entries[reader.ReadUInt32()] = reader.ReadNullTerminatedString(); } break; } // 64Bit Cache case 0x3230454843414354: { for (int i = 0; i < count; i++) { Entries[reader.ReadUInt64()] = reader.ReadNullTerminatedString(); } break; } } } } } #if DEBUG catch (Exception e) { Console.WriteLine("Failed to load {0}: {1}", fileName, e); } #else catch { } #endif }