mirror of
https://github.com/kwsch/PKHeX
synced 2024-09-20 22:32:00 +00:00
Inline checksum logic for gen3, simplify else case
This commit is contained in:
parent
c09fb9a0ec
commit
6239f59b9d
4 changed files with 7 additions and 19 deletions
|
@ -201,6 +201,8 @@ namespace PKHeX.Core
|
|||
base.RefreshChecksum();
|
||||
}
|
||||
|
||||
protected override ushort CalculateChecksum() => PokeCrypto.GetCHK3(Data);
|
||||
|
||||
public PK4 ConvertToPK4()
|
||||
{
|
||||
PK4 pk4 = new PK4 // Convert away!
|
||||
|
|
|
@ -39,21 +39,7 @@ namespace PKHeX.Core
|
|||
|
||||
protected byte[] GetData(int Offset, int Length) => Data.Slice(Offset, Length);
|
||||
|
||||
protected virtual ushort CalculateChecksum()
|
||||
{
|
||||
ushort chk = 0;
|
||||
switch (Format)
|
||||
{
|
||||
case 3:
|
||||
for (int i = 32; i < SIZE_STORED; i += 2)
|
||||
chk += BitConverter.ToUInt16(Data, i);
|
||||
return chk;
|
||||
default: // 4+
|
||||
for (int i = 8; i < SIZE_STORED; i += 2)
|
||||
chk += BitConverter.ToUInt16(Data, i);
|
||||
return chk;
|
||||
}
|
||||
}
|
||||
protected virtual ushort CalculateChecksum() => PokeCrypto.GetCHK(Data, SIZE_STORED);
|
||||
|
||||
protected abstract byte[] Encrypt();
|
||||
public abstract int Format { get; }
|
||||
|
|
|
@ -78,7 +78,7 @@ namespace PKHeX.Core
|
|||
case PokeCrypto.SIZE_6PARTY: // collision with PGT, same size.
|
||||
if (BitConverter.ToUInt16(data, 0x4) != 0) // Bad Sanity?
|
||||
return -1;
|
||||
if (BitConverter.ToUInt32(data, 0x06) == PokeCrypto.GetCHK(data))
|
||||
if (BitConverter.ToUInt32(data, 0x06) == PokeCrypto.GetCHK(data, PokeCrypto.SIZE_6STORED))
|
||||
return 6;
|
||||
if (BitConverter.ToUInt16(data, 0x58) != 0) // Encrypted?
|
||||
{
|
||||
|
|
|
@ -313,12 +313,12 @@ namespace PKHeX.Core
|
|||
/// Gets the checksum of a 232 byte array.
|
||||
/// </summary>
|
||||
/// <param name="data">Decrypted Pokémon data.</param>
|
||||
public static ushort GetCHK(byte[] data)
|
||||
/// <param name="partyStart">Offset at which the Stored data ends and the Party data starts.</param>
|
||||
public static ushort GetCHK(byte[] data, int partyStart)
|
||||
{
|
||||
ushort chk = 0;
|
||||
for (int i = 8; i < SIZE_6STORED; i += 2)
|
||||
for (int i = 8; i < partyStart; i += 2)
|
||||
chk += BitConverter.ToUInt16(data, i);
|
||||
|
||||
return chk;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue