public Stream Decompress(Stream stream) { using (var reader = new FileReader(stream, true)) { byte type = reader.ReadByte(); if (type == 0x10) { uint decomp_size = reader.ReadUInt32(); var sub = new SubStream(stream, 0); return(new MemoryStream(LZ77_WII.Decompress10(sub.ToArray(), (int)decomp_size))); } else if (type == 0x11) { uint decomp_size = reader.ReadUInt32(); var sub = new SubStream(stream, 16); return(new MemoryStream(LZ77_WII.Decompress11(sub.ToArray(), (int)decomp_size))); } else { return(new MemoryStream()); } } }
public void Content() { MemoryStream stream = new MemoryStream(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }); SubStream subStream = new SubStream(stream, 5); byte[] result = subStream.ToArray(); Assert.Equal(new byte[] { 6, 7, 8, 9, 10 }, result); }
public static SarcData UnpackRamN(Stream src) { Dictionary <string, Stream> res = new Dictionary <string, Stream>(); BinaryDataReader br = new BinaryDataReader(src, Encoding.UTF8, true); br.ByteOrder = ByteOrder.LittleEndian; br.BaseStream.Position = 6; if (br.ReadUInt16() == 0xFFFE) { br.ByteOrder = ByteOrder.BigEndian; } br.BaseStream.Position = 0; if (br.ReadString(4) != "SARC") { throw new Exception("Wrong magic"); } br.ReadUInt16(); // Chunk length br.ReadUInt16(); // BOM br.ReadUInt32(); // File size UInt32 startingOff = br.ReadUInt32(); br.ReadUInt32(); // Unknown; SFAT sfat = new SFAT(); sfat.parse(br, (int)br.BaseStream.Position); SFNT sfnt = new SFNT(); sfnt.parse(br, (int)br.BaseStream.Position, sfat, (int)startingOff); bool HashOnly = false; if (sfat.nodeCount > 0) { if (sfat.nodes[0].fileBool != 1) { HashOnly = true; } } for (int m = 0; m < sfat.nodeCount; m++) { br.Seek(sfat.nodes[m].nodeOffset + startingOff, 0); uint size = 0; if (m == 0) { size = sfat.nodes[m].EON; } else { size = sfat.nodes[m].EON - sfat.nodes[m].nodeOffset; } var temp = new SubStream(br.BaseStream, br.Position, size); if (sfat.nodes[m].fileBool == 1) { res.Add(sfnt.fileNames[m], temp); } else { res.Add(sfat.nodes[m].hash.ToString("X8") + GuessFileExtension(temp.ToArray()), temp); } } return(new SarcData() { endianness = br.ByteOrder, HashOnly = HashOnly, Files = res }); }