mirror of
https://github.com/kwsch/PKHeX
synced 2025-02-17 05:48:44 +00:00
Fix Gen3 checksum calc
Also when checking the active save, check the block0 for both save files since it is always updated.
This commit is contained in:
parent
2365e974cb
commit
9b3d6e5177
2 changed files with 33 additions and 11 deletions
|
@ -46,12 +46,33 @@ namespace PKHeX
|
|||
else Version = SaveUtil.getIsG3SAV(Data);
|
||||
if (Version == GameVersion.Invalid)
|
||||
return;
|
||||
|
||||
BlockOrder = new int[14];
|
||||
BlockOfs = new int[14];
|
||||
ActiveSAV = SaveUtil.SIZE_G3RAWHALF == data.Length || BitConverter.ToUInt32(Data, 0xFFC) > BitConverter.ToUInt32(Data, 0xEFFC) ? 0 : 1;
|
||||
|
||||
|
||||
int[] BlockOrder1 = new int[14];
|
||||
for (int i = 0; i < 14; i++)
|
||||
BlockOrder[i] = BitConverter.ToInt16(Data, ABO + i*0x1000 + 0xFF4);
|
||||
BlockOrder1[i] = BitConverter.ToInt16(Data, i*0x1000 + 0xFF4);
|
||||
int zeroBlock1 = Array.IndexOf(BlockOrder1, 0);
|
||||
|
||||
if (data.Length > SaveUtil.SIZE_G3RAWHALF)
|
||||
{
|
||||
int[] BlockOrder2 = new int[14];
|
||||
for (int i = 0; i < 14; i++)
|
||||
BlockOrder2[i] = BitConverter.ToInt16(Data, 0xE000 + i*0x1000 + 0xFF4);
|
||||
int zeroBlock2 = Array.IndexOf(BlockOrder2, 0);
|
||||
|
||||
ActiveSAV = BitConverter.ToUInt32(Data, zeroBlock1*0x1000 + 0xFFC) >
|
||||
BitConverter.ToUInt32(Data, zeroBlock2*0x1000 + 0xEFFC)
|
||||
? 0
|
||||
: 1;
|
||||
BlockOrder = ActiveSAV == 0 ? BlockOrder1 : BlockOrder2;
|
||||
}
|
||||
else
|
||||
{
|
||||
ActiveSAV = 0;
|
||||
BlockOrder = BlockOrder1;
|
||||
}
|
||||
|
||||
BlockOfs = new int[14];
|
||||
for (int i = 0; i < 14; i++)
|
||||
BlockOfs[i] = Array.IndexOf(BlockOrder, i)*0x1000 + ABO;
|
||||
|
||||
|
@ -86,7 +107,7 @@ namespace PKHeX
|
|||
OFS_PouchBalls = BlockOfs[1] + 0x0430;
|
||||
OFS_PouchTMHM = BlockOfs[1] + 0x0464;
|
||||
OFS_PouchBerry = BlockOfs[1] + 0x054C;
|
||||
Personal = PersonalTable.FR; // todo split FR & LG
|
||||
Personal = PersonalTable.FR;
|
||||
break;
|
||||
case GameVersion.E:
|
||||
LegalKeyItems = Legal.Pouch_Key_E;
|
||||
|
@ -161,7 +182,7 @@ namespace PKHeX
|
|||
{
|
||||
byte[] chunk = Data.Skip(ABO + i*0x1000).Take(chunkLength[BlockOrder[i]]).ToArray();
|
||||
ushort chk = SaveUtil.check32(chunk);
|
||||
BitConverter.GetBytes(chk).CopyTo(Data, ABO + i + 0xFF4);
|
||||
BitConverter.GetBytes(chk).CopyTo(Data, ABO + i*0x1000 + 0xFF6);
|
||||
}
|
||||
}
|
||||
public override bool ChecksumsValid
|
||||
|
@ -172,7 +193,7 @@ namespace PKHeX
|
|||
{
|
||||
byte[] chunk = Data.Skip(ABO + i * 0x1000).Take(chunkLength[BlockOrder[i]]).ToArray();
|
||||
ushort chk = SaveUtil.check32(chunk);
|
||||
if (chk != BitConverter.ToUInt16(Data, ABO + i*0xFF4))
|
||||
if (chk != BitConverter.ToUInt16(Data, ABO + i*0x1000 + 0xFF6))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -187,8 +208,9 @@ namespace PKHeX
|
|||
{
|
||||
byte[] chunk = Data.Skip(ABO + i * 0x1000).Take(chunkLength[BlockOrder[i]]).ToArray();
|
||||
ushort chk = SaveUtil.check32(chunk);
|
||||
if (chk != BitConverter.ToUInt16(Data, ABO + i * 0xFF4))
|
||||
r += $"Block {BlockOrder[i]} @ {i*0x1000} (len {chunkLength[BlockOrder[i]]}) invalid." + Environment.NewLine;
|
||||
ushort old = BitConverter.ToUInt16(Data, ABO + i*0x1000 + 0xFF6);
|
||||
if (chk != old)
|
||||
r += $"Block {BlockOrder[i].ToString("00")} @ {(i*0x1000).ToString("X5")} invalid." + Environment.NewLine;
|
||||
}
|
||||
return r.Length == 0 ? "Checksums valid." : r.TrimEnd();
|
||||
}
|
||||
|
|
|
@ -224,7 +224,7 @@ namespace PKHeX
|
|||
uint val = 0;
|
||||
for (int i = 0; i < data.Length; i += 4)
|
||||
val += BitConverter.ToUInt32(data, i);
|
||||
return (ushort)(val + val >> 16);
|
||||
return (ushort)((val & 0xFFFF) + (val >> 16));
|
||||
}
|
||||
|
||||
public static int getDexFormIndexXY(int species, int formct)
|
||||
|
|
Loading…
Add table
Reference in a new issue