public static byte[] LazyCompress(byte[] data) { FileOutput f = new FileOutput(); f.Endian = Endianness.Little; f.writeString("Yaz0"); byte w1 = (byte)(data.Length & 0xFF); byte w2 = (byte)((data.Length >> 8) & 0xFF); byte w3 = (byte)((data.Length >> 16) & 0xFF); byte w4 = (byte)(data.Length >> 24); f.writeInt((w1 << 24) | (w2 << 16) | (w3 << 8) | w4); f.writeHex("0000000000000000"); int pos = 0, posInChunk = 0; while (pos < data.Length) { posInChunk = 0; f.writeByte(0xFF); while (pos + posInChunk < data.Length && posInChunk < 8) { f.writeByte(data[pos + posInChunk]); posInChunk++; } pos += posInChunk; } return(f.getBytes()); }
public byte[] Rebuild() { FileOutput f = new FileOutput(); f.Endian = endian; f.writeString("SARC"); f.writeShort(0x14); f.Endian = endian; f.writeShort(65279); byte[] sfat = RebuildSFATArchive(); f.writeInt(sfat.Length + 0x14); f.writeInt(sfatStartOffset + 0x14); f.writeInt(0x1000000); f.writeBytes(sfat); return(f.getBytes()); }
private byte[] RebuildSFATArchive() { FileOutput f = new FileOutput(); f.Endian = endian; f.writeString("SFAT"); f.writeShort(0xC); f.writeShort(files.Count); f.writeInt(0x65); int stringPos = 0; int dataPos = 0; bool isString = true; foreach (string filename in files.Keys) { if (filename.Contains("0x")) { isString = false; f.writeInt((int)Convert.ToInt32(filename, 16)); f.writeInt(0); } else { f.writeInt((int)GetHash(filename.ToArray(), filename.Length, 0x65)); f.writeInt(stringPos + 0x1000000); stringPos += GetSizeInChunks(filename.Length + 1, 4) / 4; } f.writeInt(dataPos); f.writeInt(dataPos + files[filename].Length); dataPos += files[filename].Length % padding == 0 ? files[filename].Length : files[filename].Length + (padding - files[filename].Length % padding); } f.writeHex("53464E5400080000"); if (isString) { foreach (string filename in files.Keys) { f.writeString(filename); f.writeByte(0); while (f.pos() % 4 != 0) { f.writeByte(0); } } } if (padding == -1 || padding < f.pos()) { while ((f.pos() + 0x14) % 0x100 != 0) { f.writeByte(0); } } else { f.writeBytes(new byte[padding - (f.pos() + 0x14)]); } sfatStartOffset = f.pos(); int cur = 0; foreach (string filename in files.Keys) { f.writeIntAt(f.pos() - sfatStartOffset, 0x14 + (cur * 0x10)); f.writeBytes(files[filename]); f.writeIntAt(f.pos() - sfatStartOffset, 0x18 + (cur * 0x10)); while ((f.pos() + 0x14) % padding != 0) { f.writeByte(0); } cur++; } return(f.getBytes()); }