diff --git a/Misc/PKX.cs b/Misc/PKX.cs index d568b4e25..05d96ffbd 100644 --- a/Misc/PKX.cs +++ b/Misc/PKX.cs @@ -3,7 +3,6 @@ using System.Drawing; using System.Drawing.Text; using System.Linq; -using System.Security.Cryptography; using System.Text; namespace PKHeX @@ -800,40 +799,6 @@ public SaveGame(string GameID) #endregion // SAV Manipulation - internal static int detectSAVIndex(byte[] data, out int savindex) - { - SHA256 mySHA256 = SHA256.Create(); - { - byte[] difihash1 = new byte[0x12C]; - byte[] difihash2 = new byte[0x12C]; - Array.Copy(data, 0x330, difihash1, 0, 0x12C); - Array.Copy(data, 0x200, difihash2, 0, 0x12C); - byte[] hashValue1 = mySHA256.ComputeHash(difihash1); - byte[] hashValue2 = mySHA256.ComputeHash(difihash2); - byte[] actualhash = new byte[0x20]; - Array.Copy(data, 0x16C, actualhash, 0, 0x20); - if (hashValue1.SequenceEqual(actualhash)) - { - Console.WriteLine("Active DIFI 2 - Save 1."); - savindex = 0; - } - else if (hashValue2.SequenceEqual(actualhash)) - { - Console.WriteLine("Active DIFI 1 - Save 2."); - savindex = 1; - } - else - { - Console.WriteLine("ERROR: NO ACTIVE DIFI HASH MATCH"); - savindex = 2; - } - } - if ((data[0x168] ^ 1) == savindex || savindex == 2) // success - return savindex; - Console.WriteLine("ERROR: ACTIVE BLOCK MISMATCH"); - savindex = 2; - return savindex; - } internal static ushort ccitt16(byte[] data) { ushort crc = 0xFFFF; @@ -895,216 +860,6 @@ internal static string verifyG6CHK(byte[] savefile) rv += String.Format("SAV: {0}/{1}", (count - invalid), count + Environment.NewLine); return rv; } - internal static string verifyG6SHA(byte[] savefile, bool oras) - { - string rv = ""; - int invalid1 = 0; - // Verify Hashes - #region hash table data - uint[] hashtabledata = { - 0x2020, 0x203F, 0x2000, 0x200, - 0x2040, 0x2FFF, 0x2020, 0x1000, - 0x3000, 0x3FFF, 0x2040, 0x1000, - 0x4000, 0x4FFF, 0x2060, 0x1000, - 0x5000, 0x5FFF, 0x2080, 0x1000, - 0x6000, 0x6FFF, 0x20A0, 0x1000, - 0x7000, 0x7FFF, 0x20C0, 0x1000, - 0x8000, 0x8FFF, 0x20E0, 0x1000, - 0x9000, 0x9FFF, 0x2100, 0x1000, - 0xA000, 0xAFFF, 0x2120, 0x1000, - 0xB000, 0xBFFF, 0x2140, 0x1000, - 0xC000, 0xCFFF, 0x2160, 0x1000, - 0xD000, 0xDFFF, 0x2180, 0x1000, - 0xE000, 0xEFFF, 0x21A0, 0x1000, - 0xF000, 0xFFFF, 0x21C0, 0x1000, - 0x10000, 0x10FFF, 0x21E0, 0x1000, - 0x11000, 0x11FFF, 0x2200, 0x1000, - 0x12000, 0x12FFF, 0x2220, 0x1000, - 0x13000, 0x13FFF, 0x2240, 0x1000, - 0x14000, 0x14FFF, 0x2260, 0x1000, - 0x15000, 0x15FFF, 0x2280, 0x1000, - 0x16000, 0x16FFF, 0x22A0, 0x1000, - 0x17000, 0x17FFF, 0x22C0, 0x1000, - 0x18000, 0x18FFF, 0x22E0, 0x1000, - 0x19000, 0x19FFF, 0x2300, 0x1000, - 0x1A000, 0x1AFFF, 0x2320, 0x1000, - 0x1B000, 0x1BFFF, 0x2340, 0x1000, - 0x1C000, 0x1CFFF, 0x2360, 0x1000, - 0x1D000, 0x1DFFF, 0x2380, 0x1000, - 0x1E000, 0x1EFFF, 0x23A0, 0x1000, - 0x1F000, 0x1FFFF, 0x23C0, 0x1000, - 0x20000, 0x20FFF, 0x23E0, 0x1000, - 0x21000, 0x21FFF, 0x2400, 0x1000, - 0x22000, 0x22FFF, 0x2420, 0x1000, - 0x23000, 0x23FFF, 0x2440, 0x1000, - 0x24000, 0x24FFF, 0x2460, 0x1000, - 0x25000, 0x25FFF, 0x2480, 0x1000, - 0x26000, 0x26FFF, 0x24A0, 0x1000, - 0x27000, 0x27FFF, 0x24C0, 0x1000, - 0x28000, 0x28FFF, 0x24E0, 0x1000, - 0x29000, 0x29FFF, 0x2500, 0x1000, - 0x2A000, 0x2AFFF, 0x2520, 0x1000, - 0x2B000, 0x2BFFF, 0x2540, 0x1000, - 0x2C000, 0x2CFFF, 0x2560, 0x1000, - 0x2D000, 0x2DFFF, 0x2580, 0x1000, - 0x2E000, 0x2EFFF, 0x25A0, 0x1000, - 0x2F000, 0x2FFFF, 0x25C0, 0x1000, - 0x30000, 0x30FFF, 0x25E0, 0x1000, - 0x31000, 0x31FFF, 0x2600, 0x1000, - 0x32000, 0x32FFF, 0x2620, 0x1000, - 0x33000, 0x33FFF, 0x2640, 0x1000, - 0x34000, 0x34FFF, 0x2660, 0x1000, - 0x35000, 0x35FFF, 0x2680, 0x1000, - 0x36000, 0x36FFF, 0x26A0, 0x1000, - 0x37000, 0x37FFF, 0x26C0, 0x1000, - 0x38000, 0x38FFF, 0x26E0, 0x1000, - 0x39000, 0x39FFF, 0x2700, 0x1000, - 0x3A000, 0x3AFFF, 0x2720, 0x1000, - 0x3B000, 0x3BFFF, 0x2740, 0x1000, - 0x3C000, 0x3CFFF, 0x2760, 0x1000, - 0x3D000, 0x3DFFF, 0x2780, 0x1000, - 0x3E000, 0x3EFFF, 0x27A0, 0x1000, - 0x3F000, 0x3FFFF, 0x27C0, 0x1000, - 0x40000, 0x40FFF, 0x27E0, 0x1000, - 0x41000, 0x41FFF, 0x2800, 0x1000, - 0x42000, 0x42FFF, 0x2820, 0x1000, - 0x43000, 0x43FFF, 0x2840, 0x1000, - 0x44000, 0x44FFF, 0x2860, 0x1000, - 0x45000, 0x45FFF, 0x2880, 0x1000, - 0x46000, 0x46FFF, 0x28A0, 0x1000, - 0x47000, 0x47FFF, 0x28C0, 0x1000, - 0x48000, 0x48FFF, 0x28E0, 0x1000, - 0x49000, 0x49FFF, 0x2900, 0x1000, - 0x4A000, 0x4AFFF, 0x2920, 0x1000, - 0x4B000, 0x4BFFF, 0x2940, 0x1000, - 0x4C000, 0x4CFFF, 0x2960, 0x1000, - 0x4D000, 0x4DFFF, 0x2980, 0x1000, - 0x4E000, 0x4EFFF, 0x29A0, 0x1000, - 0x4F000, 0x4FFFF, 0x29C0, 0x1000, - 0x50000, 0x50FFF, 0x29E0, 0x1000, - 0x51000, 0x51FFF, 0x2A00, 0x1000, - 0x52000, 0x52FFF, 0x2A20, 0x1000, - 0x53000, 0x53FFF, 0x2A40, 0x1000, - 0x54000, 0x54FFF, 0x2A60, 0x1000, - 0x55000, 0x55FFF, 0x2A80, 0x1000, - 0x56000, 0x56FFF, 0x2AA0, 0x1000, - 0x57000, 0x57FFF, 0x2AC0, 0x1000, - 0x58000, 0x58FFF, 0x2AE0, 0x1000, - 0x59000, 0x59FFF, 0x2B00, 0x1000, - 0x5A000, 0x5AFFF, 0x2B20, 0x1000, - 0x5B000, 0x5BFFF, 0x2B40, 0x1000, - 0x5C000, 0x5CFFF, 0x2B60, 0x1000, - 0x5D000, 0x5DFFF, 0x2B80, 0x1000, - 0x5E000, 0x5EFFF, 0x2BA0, 0x1000, - 0x5F000, 0x5FFFF, 0x2BC0, 0x1000, - 0x60000, 0x60FFF, 0x2BE0, 0x1000, - 0x61000, 0x61FFF, 0x2C00, 0x1000, - 0x62000, 0x62FFF, 0x2C20, 0x1000, - 0x63000, 0x63FFF, 0x2C40, 0x1000, - 0x64000, 0x64FFF, 0x2C60, 0x1000, - 0x65000, 0x65FFF, 0x2C80, 0x1000, - 0x66000, 0x66FFF, 0x2CA0, 0x1000, - 0x67000, 0x67FFF, 0x2CC0, 0x1000, - 0x68000, 0x68FFF, 0x2CE0, 0x1000, - 0x69000, 0x69FFF, 0x2D00, 0x1000, - 0x6A000, 0x6AFFF, 0x2D20, 0x1000, - }; - #endregion - SHA256 mySHA256 = SHA256.Create(); - - for (int i = 0; i < hashtabledata.Length / 4; i++) - { - uint start = hashtabledata[0 + 4 * i]; - uint length = hashtabledata[1 + 4 * i] - hashtabledata[0 + 4 * i]; - uint offset = hashtabledata[2 + 4 * i]; - uint blocksize = hashtabledata[3 + 4 * i]; - - byte[] zeroarray = new byte[blocksize]; - Array.Copy(savefile, start, zeroarray, 0, length + 1); - byte[] hashValue = mySHA256.ComputeHash(zeroarray); - byte[] actualhash = new byte[0x20]; - Array.Copy(savefile, offset, actualhash, 0, 0x20); - - if (hashValue.SequenceEqual(actualhash)) continue; - invalid1++; - rv += "Invalid: " + hashtabledata[2 + 4 * i].ToString("X5") + " @ " + hashtabledata[0 + 4 * i].ToString("X5") + "-" + hashtabledata[1 + 4 * i].ToString("X5") + Environment.NewLine; - } - rv += "1st SAV: " + (106 - invalid1) + "/" + 106 + Environment.NewLine; - - // Check The Second Half of Hashes - int invalid2 = 0; - for (int i = 0; i < hashtabledata.Length; i += 4) - { - hashtabledata[i + 0] += 0x7F000; - hashtabledata[i + 1] += 0x7F000; - hashtabledata[i + 2] += 0x7F000; - } - // Problem with save2 saves is that 0x3000-0x4FFF doesn't use save2 data. Probably different when hashed, but different when stored. - for (int i = 2; i < 4; i++) - { - hashtabledata[i * 4 + 0] -= 0x7F000; - hashtabledata[i * 4 + 1] -= 0x7F000; - } - - for (int i = 0; i < hashtabledata.Length / 4; i++) - { - uint start = hashtabledata[0 + 4 * i]; - uint length = hashtabledata[1 + 4 * i] - hashtabledata[0 + 4 * i]; - uint offset = hashtabledata[2 + 4 * i]; - uint blocksize = hashtabledata[3 + 4 * i]; - - byte[] zeroarray = new byte[blocksize]; - Array.Copy(savefile, start, zeroarray, 0, length + 1); - byte[] hashValue = mySHA256.ComputeHash(zeroarray); - byte[] actualhash = new byte[0x20]; - Array.Copy(savefile, offset, actualhash, 0, 0x20); - - if (hashValue.SequenceEqual(actualhash)) continue; - invalid2++; - rv += "Invalid: " + hashtabledata[2 + 4 * i].ToString("X5") + " @ " + hashtabledata[0 + 4 * i].ToString("X5") + "-" + hashtabledata[1 + 4 * i].ToString("X5") + Environment.NewLine; - } - rv += "2nd SAV: " + (106 - invalid2) + "/" + 106 + Environment.NewLine; - - if (invalid1 + invalid2 == (2 * 106)) - rv = "None of the IVFC hashes are valid." + Environment.NewLine; - - // Check the Upper Level IVFC Hashes - { - byte[] zeroarray = new byte[0x200]; - Array.Copy(savefile, 0x2000, zeroarray, 0, 0x20); - byte[] hashValue = mySHA256.ComputeHash(zeroarray); - byte[] actualhash = new byte[0x20]; - Array.Copy(savefile, 0x43C, actualhash, 0, 0x20); - if (!hashValue.SequenceEqual(actualhash)) - rv += "Invalid: " + 0x2000.ToString("X5") + " @ " + 0x43C.ToString("X3") + Environment.NewLine; - } - { - byte[] zeroarray = new byte[0x200]; - Array.Copy(savefile, 0x81000, zeroarray, 0, 0x20); - byte[] hashValue = mySHA256.ComputeHash(zeroarray); - byte[] actualhash = new byte[0x20]; - Array.Copy(savefile, 0x30C, actualhash, 0, 0x20); - if (!hashValue.SequenceEqual(actualhash)) - rv += "Invalid: " + 0x81000.ToString("X5") + " @ " + 0x30C.ToString("X3") + Environment.NewLine; - } - { - byte[] difihash1 = new byte[0x12C]; - byte[] difihash2 = new byte[0x12C]; - Array.Copy(savefile, 0x330, difihash1, 0, 0x12C); - Array.Copy(savefile, 0x200, difihash2, 0, 0x12C); - byte[] hashValue1 = mySHA256.ComputeHash(difihash1); - byte[] hashValue2 = mySHA256.ComputeHash(difihash2); - byte[] actualhash = new byte[0x20]; - Array.Copy(savefile, 0x16C, actualhash, 0, 0x20); - if (hashValue1.SequenceEqual(actualhash)) - rv += "Active DIFI partition is Save 1."; - else if (hashValue2.SequenceEqual(actualhash)) - rv += "Active DIFI partition is Save 2."; - else - rv += "ERROR: NO ACTIVE DIFI HASH MATCH"; - } - return rv; - } internal static void writeG6CHK(byte[] savefile) { // Dynamic handling of checksums regardless of save size. @@ -1140,193 +895,6 @@ internal static void writeG6CHK(byte[] savefile) Array.Copy(BitConverter.GetBytes(ccitt16(array)), 0, savefile, verificationOffset + 6 + i * 8, 2); } } - internal static byte[] writeG6SHA(byte[] savefile, bool oras, int savegame) - { - #region hash table data - uint[] hashtabledata = { - 0x2020, 0x203F, 0x2000, 0x200, - 0x2040, 0x2FFF, 0x2020, 0x1000, - 0x3000, 0x3FFF, 0x2040, 0x1000, - 0x4000, 0x4FFF, 0x2060, 0x1000, - 0x5000, 0x5FFF, 0x2080, 0x1000, - 0x6000, 0x6FFF, 0x20A0, 0x1000, - 0x7000, 0x7FFF, 0x20C0, 0x1000, - 0x8000, 0x8FFF, 0x20E0, 0x1000, - 0x9000, 0x9FFF, 0x2100, 0x1000, - 0xA000, 0xAFFF, 0x2120, 0x1000, - 0xB000, 0xBFFF, 0x2140, 0x1000, - 0xC000, 0xCFFF, 0x2160, 0x1000, - 0xD000, 0xDFFF, 0x2180, 0x1000, - 0xE000, 0xEFFF, 0x21A0, 0x1000, - 0xF000, 0xFFFF, 0x21C0, 0x1000, - 0x10000, 0x10FFF, 0x21E0, 0x1000, - 0x11000, 0x11FFF, 0x2200, 0x1000, - 0x12000, 0x12FFF, 0x2220, 0x1000, - 0x13000, 0x13FFF, 0x2240, 0x1000, - 0x14000, 0x14FFF, 0x2260, 0x1000, - 0x15000, 0x15FFF, 0x2280, 0x1000, - 0x16000, 0x16FFF, 0x22A0, 0x1000, - 0x17000, 0x17FFF, 0x22C0, 0x1000, - 0x18000, 0x18FFF, 0x22E0, 0x1000, - 0x19000, 0x19FFF, 0x2300, 0x1000, - 0x1A000, 0x1AFFF, 0x2320, 0x1000, - 0x1B000, 0x1BFFF, 0x2340, 0x1000, - 0x1C000, 0x1CFFF, 0x2360, 0x1000, - 0x1D000, 0x1DFFF, 0x2380, 0x1000, - 0x1E000, 0x1EFFF, 0x23A0, 0x1000, - 0x1F000, 0x1FFFF, 0x23C0, 0x1000, - 0x20000, 0x20FFF, 0x23E0, 0x1000, - 0x21000, 0x21FFF, 0x2400, 0x1000, - 0x22000, 0x22FFF, 0x2420, 0x1000, - 0x23000, 0x23FFF, 0x2440, 0x1000, - 0x24000, 0x24FFF, 0x2460, 0x1000, - 0x25000, 0x25FFF, 0x2480, 0x1000, - 0x26000, 0x26FFF, 0x24A0, 0x1000, - 0x27000, 0x27FFF, 0x24C0, 0x1000, - 0x28000, 0x28FFF, 0x24E0, 0x1000, - 0x29000, 0x29FFF, 0x2500, 0x1000, - 0x2A000, 0x2AFFF, 0x2520, 0x1000, - 0x2B000, 0x2BFFF, 0x2540, 0x1000, - 0x2C000, 0x2CFFF, 0x2560, 0x1000, - 0x2D000, 0x2DFFF, 0x2580, 0x1000, - 0x2E000, 0x2EFFF, 0x25A0, 0x1000, - 0x2F000, 0x2FFFF, 0x25C0, 0x1000, - 0x30000, 0x30FFF, 0x25E0, 0x1000, - 0x31000, 0x31FFF, 0x2600, 0x1000, - 0x32000, 0x32FFF, 0x2620, 0x1000, - 0x33000, 0x33FFF, 0x2640, 0x1000, - 0x34000, 0x34FFF, 0x2660, 0x1000, - 0x35000, 0x35FFF, 0x2680, 0x1000, - 0x36000, 0x36FFF, 0x26A0, 0x1000, - 0x37000, 0x37FFF, 0x26C0, 0x1000, - 0x38000, 0x38FFF, 0x26E0, 0x1000, - 0x39000, 0x39FFF, 0x2700, 0x1000, - 0x3A000, 0x3AFFF, 0x2720, 0x1000, - 0x3B000, 0x3BFFF, 0x2740, 0x1000, - 0x3C000, 0x3CFFF, 0x2760, 0x1000, - 0x3D000, 0x3DFFF, 0x2780, 0x1000, - 0x3E000, 0x3EFFF, 0x27A0, 0x1000, - 0x3F000, 0x3FFFF, 0x27C0, 0x1000, - 0x40000, 0x40FFF, 0x27E0, 0x1000, - 0x41000, 0x41FFF, 0x2800, 0x1000, - 0x42000, 0x42FFF, 0x2820, 0x1000, - 0x43000, 0x43FFF, 0x2840, 0x1000, - 0x44000, 0x44FFF, 0x2860, 0x1000, - 0x45000, 0x45FFF, 0x2880, 0x1000, - 0x46000, 0x46FFF, 0x28A0, 0x1000, - 0x47000, 0x47FFF, 0x28C0, 0x1000, - 0x48000, 0x48FFF, 0x28E0, 0x1000, - 0x49000, 0x49FFF, 0x2900, 0x1000, - 0x4A000, 0x4AFFF, 0x2920, 0x1000, - 0x4B000, 0x4BFFF, 0x2940, 0x1000, - 0x4C000, 0x4CFFF, 0x2960, 0x1000, - 0x4D000, 0x4DFFF, 0x2980, 0x1000, - 0x4E000, 0x4EFFF, 0x29A0, 0x1000, - 0x4F000, 0x4FFFF, 0x29C0, 0x1000, - 0x50000, 0x50FFF, 0x29E0, 0x1000, - 0x51000, 0x51FFF, 0x2A00, 0x1000, - 0x52000, 0x52FFF, 0x2A20, 0x1000, - 0x53000, 0x53FFF, 0x2A40, 0x1000, - 0x54000, 0x54FFF, 0x2A60, 0x1000, - 0x55000, 0x55FFF, 0x2A80, 0x1000, - 0x56000, 0x56FFF, 0x2AA0, 0x1000, - 0x57000, 0x57FFF, 0x2AC0, 0x1000, - 0x58000, 0x58FFF, 0x2AE0, 0x1000, - 0x59000, 0x59FFF, 0x2B00, 0x1000, - 0x5A000, 0x5AFFF, 0x2B20, 0x1000, - 0x5B000, 0x5BFFF, 0x2B40, 0x1000, - 0x5C000, 0x5CFFF, 0x2B60, 0x1000, - 0x5D000, 0x5DFFF, 0x2B80, 0x1000, - 0x5E000, 0x5EFFF, 0x2BA0, 0x1000, - 0x5F000, 0x5FFFF, 0x2BC0, 0x1000, - 0x60000, 0x60FFF, 0x2BE0, 0x1000, - 0x61000, 0x61FFF, 0x2C00, 0x1000, - 0x62000, 0x62FFF, 0x2C20, 0x1000, - 0x63000, 0x63FFF, 0x2C40, 0x1000, - 0x64000, 0x64FFF, 0x2C60, 0x1000, - 0x65000, 0x65FFF, 0x2C80, 0x1000, - 0x66000, 0x66FFF, 0x2CA0, 0x1000, - 0x67000, 0x67FFF, 0x2CC0, 0x1000, - 0x68000, 0x68FFF, 0x2CE0, 0x1000, - 0x69000, 0x69FFF, 0x2D00, 0x1000, - 0x6A000, 0x6AFFF, 0x2D20, 0x1000, - }; - if (savegame == 1) - { - for (int i = 0; i < hashtabledata.Length / 4; i++) - { - hashtabledata[i * 4 + 0] += 0x7F000; - hashtabledata[i * 4 + 1] += 0x7F000; - hashtabledata[i * 4 + 2] += 0x7F000; - } - - // Problem with save2 saves is that 0x3000-0x4FFF doesn't use save2 data. Probably different when hashed, but different when stored. - for (int i = 2; i < 4; i++) - { - hashtabledata[i * 4 + 0] -= 0x7F000; - hashtabledata[i * 4 + 1] -= 0x7F000; - } - } - #endregion - SHA256 mySHA256 = SHA256.Create(); - - // Hash for 0x3000 onwards - for (int i = 2; i < hashtabledata.Length / 4; i++) - { - uint start = hashtabledata[0 + 4 * i]; - uint length = hashtabledata[1 + 4 * i] - hashtabledata[0 + 4 * i]; - uint offset = hashtabledata[2 + 4 * i]; - uint blocksize = hashtabledata[3 + 4 * i]; - - byte[] zeroarray = new byte[blocksize]; - Array.Copy(savefile, start, zeroarray, 0, length + 1); - byte[] hashValue = mySHA256.ComputeHash(zeroarray); - Array.Copy(hashValue, 0, savefile, offset, 0x20); - } - // Fix 2nd Hash - { - uint start = hashtabledata[0 + 4 * 1]; - uint length = hashtabledata[1 + 4 * 1] - hashtabledata[0 + 4 * 1]; - uint offset = hashtabledata[2 + 4 * 1]; - uint blocksize = hashtabledata[3 + 4 * 1]; - - byte[] zeroarray = new byte[blocksize]; - Array.Copy(savefile, start, zeroarray, 0, length + 1); - byte[] hashValue = mySHA256.ComputeHash(zeroarray); - - Array.Copy(hashValue, 0, savefile, offset, 0x20); - } - // Fix 1st Hash - { - uint start = hashtabledata[0 + 4 * 0]; - uint length = hashtabledata[1 + 4 * 0] - hashtabledata[0 + 4 * 0]; - uint offset = hashtabledata[2 + 4 * 0]; - uint blocksize = hashtabledata[3 + 4 * 0]; - - byte[] zeroarray = new byte[blocksize]; - Array.Copy(savefile, start, zeroarray, 0, length + 1); - byte[] hashValue = mySHA256.ComputeHash(zeroarray); - - Array.Copy(hashValue, 0, savefile, offset, 0x20); - } - // Fix IVFC Hash - { - byte[] zeroarray = new byte[0x200]; - Array.Copy(savefile, 0x2000 + savegame * 0x7F000, zeroarray, 0, 0x20); - byte[] hashValue = mySHA256.ComputeHash(zeroarray); - - Array.Copy(hashValue, 0, savefile, 0x43C - savegame * 0x130, 0x20); - } - // Fix DISA Hash - { - byte[] difihash = new byte[0x12C]; - Array.Copy(savefile, 0x330 - savegame * 0x130, difihash, 0, 0x12C); - byte[] hashValue = mySHA256.ComputeHash(difihash); - - Array.Copy(hashValue, 0, savefile, 0x16C, 0x20); - } - return savefile; - } // Data Requests internal static Image getSprite(int species, int form, int gender, int item, bool isegg, bool shiny) diff --git a/PKX/f1-Main.Designer.cs b/PKX/f1-Main.Designer.cs index 7c945f28d..328f9e68a 100644 --- a/PKX/f1-Main.Designer.cs +++ b/PKX/f1-Main.Designer.cs @@ -310,11 +310,9 @@ public void InitializeComponent() this.RTB_T = new System.Windows.Forms.RichTextBox(); this.Tab_SAV = new System.Windows.Forms.TabPage(); this.L_SAVManipulation = new System.Windows.Forms.Label(); - this.B_SwitchSAV = new System.Windows.Forms.Button(); this.B_VerifyCHK = new System.Windows.Forms.Button(); this.L_IntegrityCheck = new System.Windows.Forms.Label(); this.B_ExportSAV = new System.Windows.Forms.Button(); - this.RTB_S = new System.Windows.Forms.RichTextBox(); this.B_OpenHallofFame = new System.Windows.Forms.Button(); this.B_OUTPasserby = new System.Windows.Forms.Button(); this.B_OpenPokepuffs = new System.Windows.Forms.Button(); @@ -328,9 +326,9 @@ public void InitializeComponent() this.B_OpenPokedex = new System.Windows.Forms.Button(); this.GB_SAVtools = new System.Windows.Forms.GroupBox(); this.B_OpenSuperTraining = new System.Windows.Forms.Button(); - this.L_SAVINDEX = new System.Windows.Forms.Label(); this.dragout = new System.Windows.Forms.PictureBox(); this.L_QR = new System.Windows.Forms.Label(); + this.RTB_S = new System.Windows.Forms.RichTextBox(); this.tabMain.SuspendLayout(); this.Tab_Main.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.Label_IsShiny)).BeginInit(); @@ -2593,7 +2591,7 @@ public void InitializeComponent() this.Menu_Open.Name = "Menu_Open"; this.Menu_Open.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.O))); this.Menu_Open.ShowShortcutKeys = false; - this.Menu_Open.Size = new System.Drawing.Size(114, 22); + this.Menu_Open.Size = new System.Drawing.Size(152, 22); this.Menu_Open.Text = "&Open..."; this.Menu_Open.Click += new System.EventHandler(this.mainMenuOpen); // @@ -2602,7 +2600,7 @@ public void InitializeComponent() this.Menu_Save.Name = "Menu_Save"; this.Menu_Save.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.S))); this.Menu_Save.ShowShortcutKeys = false; - this.Menu_Save.Size = new System.Drawing.Size(114, 22); + this.Menu_Save.Size = new System.Drawing.Size(152, 22); this.Menu_Save.Text = "&Save as..."; this.Menu_Save.Click += new System.EventHandler(this.mainMenuSave); // @@ -2611,7 +2609,7 @@ public void InitializeComponent() this.Menu_Exit.Name = "Menu_Exit"; this.Menu_Exit.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.E))); this.Menu_Exit.ShowShortcutKeys = false; - this.Menu_Exit.Size = new System.Drawing.Size(114, 22); + this.Menu_Exit.Size = new System.Drawing.Size(152, 22); this.Menu_Exit.Text = "&Exit"; this.Menu_Exit.Click += new System.EventHandler(this.mainMenuExit); // @@ -3671,7 +3669,6 @@ public void InitializeComponent() // // Tab_Tools // - this.Tab_Tools.Controls.Add(this.B_SaveBoxBin); this.Tab_Tools.Controls.Add(this.B_3DSSETemp); this.Tab_Tools.Controls.Add(this.B_JPEG); this.Tab_Tools.Controls.Add(this.RTB_T); @@ -3685,7 +3682,7 @@ public void InitializeComponent() // // B_SaveBoxBin // - this.B_SaveBoxBin.Location = new System.Drawing.Point(122, 20); + this.B_SaveBoxBin.Location = new System.Drawing.Point(117, 20); this.B_SaveBoxBin.Name = "B_SaveBoxBin"; this.B_SaveBoxBin.Size = new System.Drawing.Size(75, 45); this.B_SaveBoxBin.TabIndex = 8; @@ -3727,8 +3724,8 @@ public void InitializeComponent() // // Tab_SAV // + this.Tab_SAV.Controls.Add(this.B_SaveBoxBin); this.Tab_SAV.Controls.Add(this.L_SAVManipulation); - this.Tab_SAV.Controls.Add(this.B_SwitchSAV); this.Tab_SAV.Controls.Add(this.B_VerifyCHK); this.Tab_SAV.Controls.Add(this.L_IntegrityCheck); this.Tab_SAV.Controls.Add(this.B_ExportSAV); @@ -3743,29 +3740,18 @@ public void InitializeComponent() // L_SAVManipulation // this.L_SAVManipulation.AutoSize = true; - this.L_SAVManipulation.Location = new System.Drawing.Point(154, 7); + this.L_SAVManipulation.Location = new System.Drawing.Point(208, 7); this.L_SAVManipulation.Name = "L_SAVManipulation"; - this.L_SAVManipulation.Size = new System.Drawing.Size(117, 13); + this.L_SAVManipulation.Size = new System.Drawing.Size(54, 13); this.L_SAVManipulation.TabIndex = 7; - this.L_SAVManipulation.Text = "Save File Manipulation:"; - // - // B_SwitchSAV - // - this.B_SwitchSAV.Enabled = false; - this.B_SwitchSAV.Location = new System.Drawing.Point(122, 20); - this.B_SwitchSAV.Name = "B_SwitchSAV"; - this.B_SwitchSAV.Size = new System.Drawing.Size(75, 45); - this.B_SwitchSAV.TabIndex = 6; - this.B_SwitchSAV.Text = "Switch SAV"; - this.B_SwitchSAV.UseVisualStyleBackColor = true; - this.B_SwitchSAV.Click += new System.EventHandler(this.clickSwitchSAV); + this.L_SAVManipulation.Text = "Save File:"; // // B_VerifyCHK // this.B_VerifyCHK.Enabled = false; this.B_VerifyCHK.Location = new System.Drawing.Point(32, 20); this.B_VerifyCHK.Name = "B_VerifyCHK"; - this.B_VerifyCHK.Size = new System.Drawing.Size(75, 23); + this.B_VerifyCHK.Size = new System.Drawing.Size(75, 45); this.B_VerifyCHK.TabIndex = 2; this.B_VerifyCHK.Text = "Checksums"; this.B_VerifyCHK.UseVisualStyleBackColor = true; @@ -3791,17 +3777,6 @@ public void InitializeComponent() this.B_ExportSAV.UseVisualStyleBackColor = true; this.B_ExportSAV.Click += new System.EventHandler(this.clickExportSAV); // - // RTB_S - // - this.RTB_S.Font = new System.Drawing.Font("Courier New", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.RTB_S.Location = new System.Drawing.Point(1, 68); - this.RTB_S.Name = "RTB_S"; - this.RTB_S.ReadOnly = true; - this.RTB_S.Size = new System.Drawing.Size(300, 130); - this.RTB_S.TabIndex = 0; - this.RTB_S.Text = ""; - this.RTB_S.WordWrap = false; - // // B_OpenHallofFame // this.B_OpenHallofFame.Location = new System.Drawing.Point(230, 41); @@ -3944,15 +3919,6 @@ public void InitializeComponent() this.B_OpenSuperTraining.UseVisualStyleBackColor = true; this.B_OpenSuperTraining.Click += new System.EventHandler(this.B_OpenSuperTraining_Click); // - // L_SAVINDEX - // - this.L_SAVINDEX.AutoSize = true; - this.L_SAVINDEX.Location = new System.Drawing.Point(600, 5); - this.L_SAVINDEX.Name = "L_SAVINDEX"; - this.L_SAVINDEX.Size = new System.Drawing.Size(13, 13); - this.L_SAVINDEX.TabIndex = 16; - this.L_SAVINDEX.Text = "0"; - // // dragout // this.dragout.BackColor = System.Drawing.Color.Transparent; @@ -3979,6 +3945,17 @@ public void InitializeComponent() this.L_QR.Visible = false; this.L_QR.Click += new System.EventHandler(this.clickQR); // + // RTB_S + // + this.RTB_S.Font = new System.Drawing.Font("Courier New", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.RTB_S.Location = new System.Drawing.Point(1, 68); + this.RTB_S.Name = "RTB_S"; + this.RTB_S.ReadOnly = true; + this.RTB_S.Size = new System.Drawing.Size(300, 130); + this.RTB_S.TabIndex = 0; + this.RTB_S.Text = ""; + this.RTB_S.WordWrap = false; + // // Main // this.AllowDrop = true; @@ -3987,7 +3964,6 @@ public void InitializeComponent() this.ClientSize = new System.Drawing.Size(614, 362); this.Controls.Add(this.dragout); this.Controls.Add(this.L_QR); - this.Controls.Add(this.L_SAVINDEX); this.Controls.Add(this.GB_SAVtools); this.Controls.Add(this.tabBoxMulti); this.Controls.Add(this.L_Save); @@ -4340,7 +4316,6 @@ public void InitializeComponent() private System.Windows.Forms.TabPage Tab_SAV; private System.Windows.Forms.Button B_ExportSAV; private System.Windows.Forms.Button B_VerifyCHK; - private System.Windows.Forms.RichTextBox RTB_S; private System.Windows.Forms.Button B_BoxRight; private System.Windows.Forms.Button B_BoxLeft; private System.Windows.Forms.Label L_XP2; @@ -4357,9 +4332,7 @@ public void InitializeComponent() private System.Windows.Forms.RichTextBox RTB_T; private System.Windows.Forms.Button B_JPEG; private System.Windows.Forms.Label L_SAVManipulation; - private System.Windows.Forms.Button B_SwitchSAV; private System.Windows.Forms.Label L_IntegrityCheck; - private System.Windows.Forms.Label L_SAVINDEX; private System.Windows.Forms.ComboBox CB_EggLocation; private System.Windows.Forms.Label Label_CharacteristicPrefix; private System.Windows.Forms.ToolStripMenuItem Menu_Tools; @@ -4412,6 +4385,7 @@ public void InitializeComponent() private System.Windows.Forms.Button B_SaveBoxBin; private System.Windows.Forms.Label L_QR; private System.Windows.Forms.ComboBox CB_HPType; + private System.Windows.Forms.RichTextBox RTB_S; } } diff --git a/PKX/f1-Main.cs b/PKX/f1-Main.cs index e44818197..9d76fc308 100644 --- a/PKX/f1-Main.cs +++ b/PKX/f1-Main.cs @@ -4,7 +4,6 @@ using System.Drawing; using System.IO; using System.Linq; -using System.Security.Cryptography; using System.Text; using System.Threading; using System.Windows.Forms; @@ -196,7 +195,6 @@ public Main() public static byte[] ramsav; public static bool ramsavloaded; public bool savLoaded; - public int savindex; public static bool savedited; public string pathSDF; public string path3DS; @@ -485,30 +483,17 @@ private void openFile(byte[] input, string path, string ext) DialogResult sdr = Util.Prompt(MessageBoxButtons.YesNoCancel, "Press Yes to load the sav at 0x3000", "Press No for the one at 0x82000"); if (sdr == DialogResult.Cancel) return; - savindex = (sdr == DialogResult.Yes) ? 0 : 1; - B_SwitchSAV.Enabled = true; open1MB(input, path, GameType, false); } - else if (PKX.detectSAVIndex(input, out savindex) == 2) + else { DialogResult dialogResult = Util.Prompt(MessageBoxButtons.YesNo, "Hash verification failed.", "Press Yes to ignore this warning and continue loading the save file."); if (dialogResult != DialogResult.Yes) return; DialogResult sdr = Util.Prompt(MessageBoxButtons.YesNoCancel, "Press Yes to load the sav at 0x3000", "Press No for the one at 0x82000"); if (sdr == DialogResult.Cancel) - { - savindex = 0; return; // abort load - } - savindex = (sdr == DialogResult.Yes) ? 0 : 1; - B_SwitchSAV.Enabled = true; - open1MB(input, path, GameType, false); - } - else - { - B_ExportSAV.Enabled = true; - B_SwitchSAV.Enabled = true; - PKX.detectSAVIndex(input, out savindex); + open1MB(input, path, GameType, false); } } @@ -638,11 +623,9 @@ private void openMAIN(byte[] input, string path, string GameType, bool oras, boo SaveGame = new PKX.Structures.SaveGame(GameType); // Load CyberGadget - savindex = 0; savefile = input; powersave = null; B_ExportSAV.Enabled = true; - B_SwitchSAV.Enabled = false; savefile = input; openSave(oras); @@ -656,15 +639,6 @@ private void open1MB(byte[] input, string path, string GameType, bool oras) powersave = input; savefile = input.Skip(0x5400).Take(oras ? 0x76000 : 0x65600).ToArray(); - // Logic to allow unlocking of Switch SAV - // Check both IVFC Hashes - SHA256 mySHA256 = SHA256.Create(); - byte[] hashValue1 = mySHA256.ComputeHash(powersave.Skip(0x2000 + 0 * 0x7F000).Take(0x20).ToArray()); - byte[] hashValue2 = mySHA256.ComputeHash(powersave.Skip(0x2000 + 1 * 0x7F000).Take(0x20).ToArray()); - byte[] realHash1 = powersave.Skip(0x43C - 0*0x130).Take(0x20).ToArray(); - byte[] realHash2 = powersave.Skip(0x43C - 1*0x130).Take(0x20).ToArray(); - B_SwitchSAV.Enabled = (hashValue1.SequenceEqual(realHash1) && hashValue2.SequenceEqual(realHash2)); - getSAVOffsets(ref oras); // to detect if we are ORAS or not openSave(oras); @@ -735,7 +709,6 @@ private void openSave(bool oras) setBoxNames(); // Display the Box Names setPKXBoxes(); // Reload all of the PKX Windows - setSAVLabel(); // Reload the label indicating current save // Version Exclusive Editors GB_SUBE.Visible = !oras; @@ -2730,7 +2703,6 @@ private void refreshTrainerInfo() // Generic Subfunctions // private void setPokedex(byte[] pkxdata) { - if (savindex > 1) return; int species = BitConverter.ToUInt16(pkxdata, 0x8); // Species int lang = pkxdata[0xE3] - 1; if (lang > 5) lang--; // 0-6 language vals int origin = pkxdata[0xDF]; // Native / Non Native @@ -2910,11 +2882,6 @@ private void setBoxNames() } CB_BoxSelect.SelectedIndex = selectedbox; // restore selected box } - private void setSAVLabel() - { - L_SAVINDEX.Text = (savindex + 1).ToString(); - RTB_S.AppendText("Loaded Save File " + (savindex + 1) + Environment.NewLine); - } private void getSAVOffsets(ref bool oras) { // Get the save file offsets for the input game @@ -2937,8 +2904,7 @@ private void getSAVOffsets(ref bool oras) } // Enable Buttons - GB_SAVtools.Enabled = B_JPEG.Enabled = B_VerifyCHK.Enabled = B_SwitchSAV.Enabled - = enableInterface; + GB_SAVtools.Enabled = B_JPEG.Enabled = B_VerifyCHK.Enabled = enableInterface; } private void getQuickFiller(PictureBox pb, byte[] dslotdata = null) { @@ -3476,17 +3442,6 @@ private void clickOpenTempFolder(object sender, EventArgs e) } } - private void clickSwitchSAV(object sender, EventArgs e) - { - if (DialogResult.Yes != - Util.Prompt(MessageBoxButtons.YesNo, String.Format("Current Savefile is Save {0}.", (savindex + 1)), - String.Format("Would you like to switch to Save {0}?", ((savindex + 1)%2 + 1)))) - return; - - savefile = powersave.Skip(0x5400 + 0x7F000 + savindex).Take(savefile.Length).ToArray(); - openSave(SaveGame.ORAS); - } - // Drag & Drop within Box private void pbBoxSlot_MouseDown(object sender, MouseEventArgs e) { diff --git a/PKX/f1-Main.resx b/PKX/f1-Main.resx index b8594dd25..065610a47 100644 --- a/PKX/f1-Main.resx +++ b/PKX/f1-Main.resx @@ -582,9 +582,6 @@ True - - True - True @@ -594,9 +591,6 @@ True - - True - True