private byte[] ReadData() { var dataLength = _header.CompressedLength >= 0 ? _header.CompressedLength : _header.DecompressedLength; var data = _stream.SetPosition(_dataOffset).ReadBytes(dataLength); _originalRawData = data.ToArray(); if (_header.CompressedLength > -2) { for (var i = 0; i < Math.Min(dataLength, 0x100); i += 0x10) { EgsEncryption.DecryptChunk(_key, data, i, PASS_COUNT); } } if (_header.CompressedLength > -1) { using var compressedStream = new MemoryStream(data); using var deflate = new DeflateStream(compressedStream.SetPosition(2), CompressionMode.Decompress); var decompressedData = new byte[_header.DecompressedLength]; deflate.Read(decompressedData, 0, decompressedData.Length); data = decompressedData; } _originalData = data.ToArray(); return(data); }
public byte[] DecompressRemasteredData(byte[] data, RemasteredEntry entry) { var paddedData = data; if (data.Length % 16 != 0) { paddedData = new byte[data.Length + 16 - (data.Length % 16)]; } Array.Copy(data, 0, paddedData, 0, data.Length); if (entry.CompressedLength >= -1) { for (var i = 0; i < Math.Min(paddedData.Length, 0x100); i += 0x10) { EgsEncryption.DecryptChunk(_key, paddedData, i, PassCount); } } if (entry.CompressedLength >= 0) { using var compressedStream = new MemoryStream(paddedData); using var deflate = new DeflateStream(compressedStream.SetPosition(2), CompressionMode.Decompress); var decompressedData = new byte[entry.DecompressedLength]; deflate.Read(decompressedData, 0, decompressedData.Length); return(decompressedData); } return(paddedData); }
public byte[] DecompressData(byte[] data) { if (_header.CompressedLength >= -1) { for (var i = 0; i < Math.Min(data.Length, 0x100); i += 0x10) { EgsEncryption.DecryptChunk(_key, data, i, PassCount); } } if (_header.CompressedLength >= 0) { using var compressedStream = new MemoryStream(data); using var deflate = new DeflateStream(compressedStream.SetPosition(2), CompressionMode.Decompress); var decompressedData = new byte[_header.DecompressedLength]; deflate.Read(decompressedData, 0, decompressedData.Length); return(decompressedData); } return(data); }
private byte[] ReadRemasteredAsset(string assetName) { var header = _entries[assetName]; var dataLength = header.CompressedLength >= 0 ? header.CompressedLength : header.DecompressedLength; if (dataLength % 16 != 0) { dataLength += 16 - (dataLength % 16); } var data = _stream.AlignPosition(0x10).ReadBytes(dataLength); _remasteredAssetsRawData.Add(assetName, data.ToArray()); if (header.CompressedLength > -2) { for (var i = 0; i < Math.Min(dataLength, 0x100); i += 0x10) { EgsEncryption.DecryptChunk(_key, data, i, PASS_COUNT); } } if (header.CompressedLength > -1) { using var compressedStream = new MemoryStream(data); using var deflate = new DeflateStream(compressedStream.SetPosition(2), CompressionMode.Decompress); var decompressedData = new byte[header.DecompressedLength]; deflate.Read(decompressedData, 0, decompressedData.Length); data = decompressedData; } _remasteredAssetsData.Add(assetName, data.ToArray()); return(data); }