diff --git a/PKHeX/Saves/SAV3.cs b/PKHeX/Saves/SAV3.cs index be6411dfd..835377a4e 100644 --- a/PKHeX/Saves/SAV3.cs +++ b/PKHeX/Saves/SAV3.cs @@ -47,7 +47,6 @@ namespace PKHeX if (Version == GameVersion.Invalid) return; - int[] BlockOrder1 = new int[14]; for (int i = 0; i < 14; i++) BlockOrder1[i] = BitConverter.ToInt16(Data, i*0x1000 + 0xFF4); @@ -60,6 +59,11 @@ namespace PKHeX BlockOrder2[i] = BitConverter.ToInt16(Data, 0xE000 + i*0x1000 + 0xFF4); int zeroBlock2 = Array.IndexOf(BlockOrder2, 0); + if (zeroBlock2 < 0) + ActiveSAV = 0; + else if (zeroBlock1 < 0) + ActiveSAV = 1; + else ActiveSAV = BitConverter.ToUInt32(Data, zeroBlock1*0x1000 + 0xFFC) > BitConverter.ToUInt32(Data, zeroBlock2*0x1000 + 0xEFFC) ? 0 diff --git a/PKHeX/Saves/SaveUtil.cs b/PKHeX/Saves/SaveUtil.cs index 100b4d04a..0ddebec7f 100644 --- a/PKHeX/Saves/SaveUtil.cs +++ b/PKHeX/Saves/SaveUtil.cs @@ -213,27 +213,34 @@ namespace PKHeX if (data.Length != SIZE_G3RAW && data.Length != SIZE_G3RAWHALF) return GameVersion.Invalid; - int[] BlockOrder = new int[14]; - for (int i = 0; i < 14; i++) - BlockOrder[i] = BitConverter.ToInt16(data, i * 0x1000 + 0xFF4); - - if (BlockOrder.Any(i => i > 0xD || i < 0)) - return GameVersion.Invalid; - - // Detect RS/E/FRLG - // Section 0 stores Game Code @ 0x00AC; 0 for RS, 1 for FRLG, else for Emerald - - int Block0 = Array.IndexOf(BlockOrder, 0); - uint GameCode = BitConverter.ToUInt32(data, Block0 * 0x1000 + 0xAC); - if (GameCode == uint.MaxValue) - return GameVersion.Unknown; // what a hack - - switch (GameCode) + // check the save file(s) + int count = data.Length/SIZE_G3RAWHALF; + for (int s = 0; s < count; s++) { - case 0: return GameVersion.RS; - case 1: return GameVersion.FRLG; - default: return GameVersion.E; + int ofs = 0xE000*s; + int[] BlockOrder = new int[14]; + for (int i = 0; i < 14; i++) + BlockOrder[i] = BitConverter.ToInt16(data, i * 0x1000 + 0xFF4 + ofs); + + if (BlockOrder.Any(i => i > 0xD || i < 0)) + continue; + + // Detect RS/E/FRLG + // Section 0 stores Game Code @ 0x00AC; 0 for RS, 1 for FRLG, else for Emerald + + int Block0 = Array.IndexOf(BlockOrder, 0); + uint GameCode = BitConverter.ToUInt32(data, Block0 * 0x1000 + 0xAC + ofs); + if (GameCode == uint.MaxValue) + return GameVersion.Unknown; // what a hack + + switch (GameCode) + { + case 0: return GameVersion.RS; + case 1: return GameVersion.FRLG; + default: return GameVersion.E; + } } + return GameVersion.Invalid; } /// Determines the type of 3rd gen Box RS /// Save data of which to determine the type