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); } }
/// <summary> /// Gets an entry's data from a Far3Entry instance. /// </summary> /// <param name="Entry">The Far3Entry instance.</param> /// <returns>The entry's data.</returns> public byte[] GetEntry(Far3Entry Entry) { lock (m_Reader) { m_Reader.BaseStream.Seek((long)Entry.DataOffset, SeekOrigin.Begin); isReadingSomething = true; if (Entry.IsCompressed == 0x01) { m_Reader.ReadBytes(9); uint Filesize = m_Reader.ReadUInt32(); ushort CompressionID = m_Reader.ReadUInt16(); if (CompressionID == 0xFB10) { byte[] Dummy = m_Reader.ReadBytes(3); uint DecompressedSize = (uint)((Dummy[0] << 0x10) | (Dummy[1] << 0x08) | +Dummy[2]); Decompresser Dec = new Decompresser(); Dec.CompressedSize = Filesize; Dec.DecompressedSize = DecompressedSize; byte[] DecompressedData = Dec.Decompress(m_Reader.ReadBytes((int)Filesize)); //m_Reader.Close(); isReadingSomething = false; return DecompressedData; } else { m_Reader.BaseStream.Seek((m_Reader.BaseStream.Position - 15), SeekOrigin.Begin); byte[] Data = m_Reader.ReadBytes((int)Entry.DecompressedFileSize); //m_Reader.Close(); isReadingSomething = false; return Data; } } else { byte[] Data = m_Reader.ReadBytes((int)Entry.DecompressedFileSize); //m_Reader.Close(); isReadingSomething = false; return Data; } } throw new FAR3Exception("FAR3Entry didn't exist in archive - FAR3Archive.GetEntry()"); }