mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-23 12:33:06 +00:00
Fix gen3 once-saved saves
The uninitialized half of the save was tripping everything up. The getIsG3SAV now checks both save partitions for validity. The constructor now checks both save partitions to see if the 0th block is present when determining the active save file. Closes #304 , thanks @Ninjistix
This commit is contained in:
parent
10fbcfcd74
commit
54980483b4
2 changed files with 31 additions and 20 deletions
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
/// <summary>Determines the type of 3rd gen Box RS</summary>
|
||||
/// <param name="data">Save data of which to determine the type</param>
|
||||
|
|
Loading…
Reference in a new issue