mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-08-23 05:44:17 -05:00
Add loading encrypted pkm files
Also fix 220 byte pkm file loading
This commit is contained in:
17
Misc/PKM.cs
17
Misc/PKM.cs
@@ -64,7 +64,7 @@ internal static byte[] shuffleArray(byte[] data, uint sv)
|
||||
|
||||
// Fill the Battle Stats back
|
||||
if (data.Length > 136)
|
||||
Array.Copy(data, 136, sdata, 136, 100);
|
||||
Array.Copy(data, 136, sdata, 136, data.Length - 136);
|
||||
|
||||
return sdata;
|
||||
}
|
||||
@@ -120,6 +120,21 @@ internal static byte[] encryptArray(byte[] pkm)
|
||||
// Done
|
||||
return ekm;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks to see if the PKM file is encrypted; if so, decrypts.
|
||||
/// </summary>
|
||||
/// <param name="pkm">Input byte array</param>
|
||||
internal static void checkEncrypted(ref byte[] pkm)
|
||||
{
|
||||
if (pkm.Length != PK4.SIZE_STORED && pkm.Length != PK4.SIZE_PARTY && pkm.Length != PK5.SIZE_PARTY)
|
||||
return; // bad
|
||||
|
||||
ushort chk = 0;
|
||||
for (int i = 8; i < PK4.SIZE_STORED; i += 2) // Loop through the entire PKM
|
||||
chk += BitConverter.ToUInt16(pkm, i);
|
||||
pkm = chk != BitConverter.ToUInt16(pkm, 0x06) ? decryptArray(pkm) : pkm;
|
||||
}
|
||||
|
||||
/// <summary>Calculates the CRC16-CCITT checksum over an input byte array.</summary>
|
||||
/// <param name="chunk">Input byte array</param>
|
||||
|
||||
@@ -617,8 +617,9 @@ private void openFile(byte[] input, string path, string ext)
|
||||
#region PK3/PK4/PK5 Conversion
|
||||
else if (new[] { PK3.SIZE_PARTY, PK3.SIZE_STORED, PK4.SIZE_PARTY, PK4.SIZE_STORED, PK5.SIZE_PARTY }.Contains(input.Length))
|
||||
{
|
||||
PKM.checkEncrypted(ref input);
|
||||
if (!PKX.verifychk(input)) Util.Error("Invalid File (Checksum Error)");
|
||||
try // to convert g5pkm
|
||||
try // to convert pk6
|
||||
{
|
||||
populateFields(Converter.ConvertPKMtoPK6(input));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user