diff --git a/PKHeX.Core/Saves/MemeCrypto/MemeCrypto.cs b/PKHeX.Core/Saves/MemeCrypto/MemeCrypto.cs index 94e60f244..8dbe36707 100644 --- a/PKHeX.Core/Saves/MemeCrypto/MemeCrypto.cs +++ b/PKHeX.Core/Saves/MemeCrypto/MemeCrypto.cs @@ -7,7 +7,7 @@ namespace PKHeX.Core /// MemeCrypto V1 - The Original Series /// /// - /// A variant of encryption and obfuscation, used in . + /// A variant of encryption and obfuscation used in . ///
The save file stores a dedicated block to contain a hash of the savedata, computed when the block is zeroed.
///
This signing logic is reused for other authentication; refer to .
///
The save file first computes a SHA256 Hash over the block checksum region. diff --git a/PKHeX.Core/Saves/MemeCrypto/SwishCrypto.cs b/PKHeX.Core/Saves/MemeCrypto/SwishCrypto.cs index dd5c37011..d6125aa11 100644 --- a/PKHeX.Core/Saves/MemeCrypto/SwishCrypto.cs +++ b/PKHeX.Core/Saves/MemeCrypto/SwishCrypto.cs @@ -111,9 +111,12 @@ public static byte[] GetDecryptedRawData(byte[] data) return temp; } + private const int BlockDataRatioEstimate1 = 777; // bytes per block, on average (generous) + private const int BlockDataRatioEstimate2 = 555; // bytes per block, on average (stingy) + private static IReadOnlyList ReadBlocks(byte[] data) { - var result = new List(); + var result = new List(data.Length / BlockDataRatioEstimate2); int offset = 0; while (offset < data.Length - SIZE_HASH) { @@ -144,9 +147,9 @@ public static byte[] Encrypt(IReadOnlyList blocks) /// Tries to encrypt the save data. /// /// Raw save data without the final xorpad layer. - public static byte[] GetDecryptedRawData(IEnumerable blocks) + public static byte[] GetDecryptedRawData(IReadOnlyList blocks) { - using var ms = new MemoryStream(); + using var ms = new MemoryStream(blocks.Count * BlockDataRatioEstimate1); using var bw = new BinaryWriter(ms); foreach (var block in blocks) block.WriteBlock(bw);