/// <summary> /// Reads a Stream header and returns a decompressed Refpack body. /// </summary> public Stream Decompress() { byte BodyType = ReadByte(); uint DecompressedSize = ReadUInt32(); if (BodyType == 0) { return(new MemoryStream(ReadBytes((int)DecompressedSize))); } else { uint CompressedSize = ReadUInt32(); //This is *always* in little endian, regardless of the rest //of the stream, probably to avoid switching, because its //value is the same as the above field. SwitchEndianNess(new LittleEndianBitConverter()); uint StreamSize = ReadUInt32(); Decompresser Dec = new Decompresser(); byte[] DecompressedData = Dec.Decompress(ReadBytes((int)CompressedSize)); SwitchEndianNess(new BigEndianBitConverter()); return(new MemoryStream(DecompressedData)); } }
private void Create(BinaryReader Reader) { byte BodyType = m_Reader.ReadByte(); if (BodyType != 0x01 && BodyType != 0x03) { throw (new Exception("Tuning.cs: Unknown Persist BodyType!")); } uint DecompressedSize = m_Reader.ReadUInt32(); uint CompressedSize = m_Reader.ReadUInt32(); //This is ALSO decompressed size... uint StreamBodySize = m_Reader.ReadUInt32(); //Note: wiki.niotso.org says this is actually one byte Compressor and four bytes CompressionParameters. ushort CompressionID = m_Reader.ReadUInt16(); if (CompressionID != 0xFB10) { throw (new Exception("Tuning.cs: Unknown CompressionID!")); } byte[] Dummy = m_Reader.ReadBytes(3); //Why are there 11 bytes of decompressed size at the start of a COMPRESSION format? #wtfmaxis uint DecompressedSize2 = (uint)((Dummy[0] << 0x10) | (Dummy[1] << 0x08) | +Dummy[2]); Decompresser Dec = new Decompresser(); Dec.CompressedSize = CompressedSize; Dec.DecompressedSize = DecompressedSize; var decompressedData = Dec.Decompress(m_Reader.ReadBytes((int)CompressedSize)); if (decompressedData == null) { throw (new Exception("Tuning.cs: Decompression failed!")); } m_Reader = new BinaryReader(new MemoryStream(decompressedData)); EntryCount = m_Reader.ReadUInt32(); for (int i = 0; i < EntryCount; i++) { TuningEntry Entry = new TuningEntry(); Entry.EntryName = DecodeString(m_Reader); Entry.KeyValueCount = m_Reader.ReadUInt32(); Entry.KeyValues = new ConcurrentDictionary <string, string>(); for (int j = 0; j < Entry.KeyValueCount; j++) { string Key = DecodeString(m_Reader); string Val = DecodeString(m_Reader); Entry.KeyValues.TryAdd(Key, Val); } Entries.Add(Entry); } }
private void Create(BinaryReader Reader) { byte BodyType = m_Reader.ReadByte(); if (BodyType != 0x01 && BodyType != 0x03) { throw (new Exception("Tuning.cs: Unknown Persist BodyType!")); } uint DecompressedSize = m_Reader.ReadUInt32(); uint CompressedSize = m_Reader.ReadUInt32(); uint StreamBodySize = m_Reader.ReadUInt32(); //same as compressed size for all current examples //Note: wiki.niotso.org says this is actually one byte Compressor and four bytes CompressionParameters. ushort CompressionID = m_Reader.ReadUInt16(); if (CompressionID != 0xFB10) { throw (new Exception("Tuning.cs: Unknown CompressionID!")); } byte[] Dummy = m_Reader.ReadBytes(3); uint DecompressedSize2 = (uint)((Dummy[0] << 0x10) | (Dummy[1] << 0x08) | +Dummy[2]); var Dec = new Decompresser(); Dec.CompressedSize = CompressedSize; Dec.DecompressedSize = DecompressedSize; var decompressedData = Dec.Decompress(m_Reader.ReadBytes((int)CompressedSize)); if (decompressedData == null) { throw (new Exception("Tuning.cs: Decompression failed!")); } m_Reader = new BinaryReader(new MemoryStream(decompressedData)); EntryCount = m_Reader.ReadUInt32(); for (int i = 0; i < EntryCount; i++) { var Entry = new TuningEntry(); Entry.EntryName = DecodeString(m_Reader); Entry.KeyValueCount = m_Reader.ReadUInt32(); Entry.KeyValues = new Dictionary <string, string>(); for (int j = 0; j < Entry.KeyValueCount; j++) { string Key = DecodeString(m_Reader); string Val = DecodeString(m_Reader); Entry.KeyValues.Add(Key, Val); } EntriesByName.Add(Entry.EntryName.ToLowerInvariant(), Entry); } }
public void InstallFile(string location) { Log.Info ("Installing file {0} to {1}", location, this.InstallPath); Decompresser decomp = new Decompresser(location, this.InstallPath); decomp.Run(); if (decomp.DeleteFile) { Log.Info("Deleting archive {0}", location); File.Delete(location); } }
/// <summary> /// Reads a Stream header and returns a decompressed Refpack body. /// </summary> public Stream Decompress() { try { byte BodyType = ReadByte(); uint DecompressedSize = ReadUInt32(); if (BodyType == 0) { return(new MemoryStream(ReadBytes((int)DecompressedSize))); } else { uint CompressedSize = ReadUInt32(); //This is *always* in little endian, regardless of the rest //of the stream, probably to avoid switching, because its //value is the same as the above field. SwitchEndianNess(new LittleEndianBitConverter()); uint StreamSize = ReadUInt32(); //For some reason, reading the RefPak header inside the decompresser causes it to crash. //So read it here instead. ReadBytes(5); Decompresser Dec = new Decompresser(); Dec.DecompressedSize = DecompressedSize; //CompressedSize includes the size of itself (4 bytes) and the RefPak header (5 bytes). byte[] DecompressedData = Dec.Decompress(ReadBytes((int)CompressedSize - 9)); SwitchEndianNess(new BigEndianBitConverter()); return(new MemoryStream(DecompressedData)); } } catch (Exception E) { throw new Exception(E.ToString()); } }