From 0dc45c00ec0db94423c4c620f74f58db356445e5 Mon Sep 17 00:00:00 2001 From: Kurt Date: Sat, 27 Apr 2019 17:19:54 -0700 Subject: [PATCH] Check block index before calculating Missing/Duplicate blocks (???) result in -1, so skip them. https://projectpokemon.org/home/forums/topic/52437-cant-export-unmodified-sav-file/ replace linq with manual allocation --- PKHeX.Core/Saves/SAV3.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/PKHeX.Core/Saves/SAV3.cs b/PKHeX.Core/Saves/SAV3.cs index ea36826f7..965a17224 100644 --- a/PKHeX.Core/Saves/SAV3.cs +++ b/PKHeX.Core/Saves/SAV3.cs @@ -239,7 +239,9 @@ namespace PKHeX.Core } SetChecksums(); - return Data.Take(Data.Length - SIZE_RESERVED).ToArray(); + var result = new byte[Data.Length - SIZE_RESERVED]; + Buffer.BlockCopy(Data, 0, result, 0, result.Length); + return result; } private readonly int ActiveSAV; @@ -283,7 +285,10 @@ namespace PKHeX.Core for (int i = 0; i < BLOCK_COUNT; i++) { int ofs = ABO + (i * SIZE_BLOCK); - int len = chunkLength[BlockOrder[i]]; + var index = BlockOrder[i]; + if (index == -1) + continue; + int len = chunkLength[index]; ushort chk = Checksums.CRC32(Data, ofs, len); BitConverter.GetBytes(chk).CopyTo(Data, ofs + 0xFF6); }