private void ReadSectionMixedMarshallingRelocations(Section section) { if (section.Header.numMixedMarshallingData == 0) { return; } InputStream.Seek(section.Header.mixedMarshallingDataOffset, SeekOrigin.Begin); if (section.Header.compression == 4) { using (var reader = new BinaryReader(InputStream, Encoding.Default, true)) { UInt32 compressedSize = reader.ReadUInt32(); byte[] compressed = reader.ReadBytes((int)compressedSize); var uncompressed = Granny2Compressor.Decompress4( compressed, (int)(section.Header.numMixedMarshallingData * 16)); using (var ms = new MemoryStream(uncompressed)) { ReadSectionMixedMarshallingRelocationsInternal(section, ms); } } } else { ReadSectionMixedMarshallingRelocationsInternal(section, InputStream); } }
private void UncompressStream() { #if DEBUG_GR2_SERIALIZATION System.Console.WriteLine(String.Format(" ===== Repacking sections ===== ")); #endif uint totalSize = 0; foreach (var section in Sections) { totalSize += section.Header.uncompressedSize; } // Copy the whole file, as we'll update its contents because of relocations and marshalling fixups byte[] uncompressedStream = new byte[totalSize]; this.Stream = new MemoryStream(uncompressedStream); this.Reader = new BinaryReader(this.Stream); for (int i = 0; i < Sections.Count; i++) { var section = Sections[i]; var hdr = section.Header; byte[] sectionContents = new byte[hdr.compressedSize]; InputStream.Position = hdr.offsetInFile; InputStream.Read(sectionContents, 0, (int)hdr.compressedSize); var originalOffset = hdr.offsetInFile; hdr.offsetInFile = (uint)Stream.Position; if (section.Header.compression == 0) { Stream.Write(sectionContents, 0, sectionContents.Length); } else if (section.Header.uncompressedSize > 0) { if (hdr.compression == 4) { var uncompressed = Granny2Compressor.Decompress4( sectionContents, (int)hdr.uncompressedSize); Stream.Write(uncompressed, 0, uncompressed.Length); } else { var uncompressed = Granny2Compressor.Decompress( (int)hdr.compression, sectionContents, (int)hdr.uncompressedSize, (int)hdr.first16bit, (int)hdr.first8bit, (int)hdr.uncompressedSize); Stream.Write(uncompressed, 0, uncompressed.Length); } } #if DEBUG_GR2_SERIALIZATION System.Console.WriteLine(String.Format(" {0}: {1:X8} ({2}) --> {3:X8} ({4})", i, originalOffset, hdr.compressedSize, hdr.offsetInFile, hdr.uncompressedSize)); #endif } }