From 365561122d69be35951dcd0d178a71db7857f2b0 Mon Sep 17 00:00:00 2001 From: Kaphotics Date: Thu, 26 May 2016 09:21:02 -0700 Subject: [PATCH 01/49] Update README.md Update screenshot --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e5b55efbf..c7cf62815 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ The interface is translatable with resource/external text files so that differen ## Screenshots -![Main Window](http://i.snag.gy/dGdB4.jpg?raw=true) +![Main Window](http://i.imgur.com/BjPBhKm.png) ### License From 763bc525b92391bbc1088e39d78deceadbea9f49 Mon Sep 17 00:00:00 2001 From: Kaphotics Date: Fri, 27 May 2016 17:57:03 -0700 Subject: [PATCH 02/49] Fix party stat decryption now it doesn't autosize --- Misc/PKM.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/PKM.cs b/Misc/PKM.cs index 441921e2a..8dc08e37e 100644 --- a/Misc/PKM.cs +++ b/Misc/PKM.cs @@ -55,7 +55,7 @@ internal static string TrimFromFFFF(string input) }; internal static byte[] shuffleArray(byte[] data, uint sv) { - byte[] sdata = new byte[PK4.SIZE_PARTY]; + byte[] sdata = new byte[data.Length]; Array.Copy(data, sdata, 8); // Copy unshuffled bytes // Shuffle Away! From 20f3a10838b3456ccb61f97c4a796de02debd2fe Mon Sep 17 00:00:00 2001 From: Kaphotics Date: Sun, 29 May 2016 14:44:08 -0700 Subject: [PATCH 03/49] Refactor Remove unnecessary reference, Core is within Legal --- Legality/Core.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Legality/Core.cs b/Legality/Core.cs index 2f1574ceb..3be95b083 100644 --- a/Legality/Core.cs +++ b/Legality/Core.cs @@ -376,7 +376,7 @@ internal static bool getCanLearnMove(PK6 pk6, int move, int version = -1) } internal static bool getCanKnowMove(PK6 pk6, int move, int version = -1) { - if (pk6.Species == 235 && !Legal.InvalidSketch.Contains(move)) + if (pk6.Species == 235 && !InvalidSketch.Contains(move)) return true; return getValidMoves(pk6, Version: version, LVL: true, Relearn: true, Tutor: true, Machine: true).Contains(move); } From 862c2fd8231c80ec6b5033c8e8c53cf8dd000a73 Mon Sep 17 00:00:00 2001 From: Kaphotics Date: Mon, 30 May 2016 18:56:37 -0700 Subject: [PATCH 04/49] Fix trade skitty level 25->30 --- Legality/Tables.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Legality/Tables.cs b/Legality/Tables.cs index ba0b63444..afcb3c4a3 100644 --- a/Legality/Tables.cs +++ b/Legality/Tables.cs @@ -778,7 +778,7 @@ public static partial class Legal internal static readonly EncounterTrade[] TradeGift_AO = { new EncounterTrade { Species = 296, Level = 9, Ability = 2, Gender = 0, TID = 30724, Nature = Nature.Brave, IVs = new[] {-1, 31, -1, -1, -1, -1}, }, // Makuhita - new EncounterTrade { Species = 300, Level = 25, Ability = 1, Gender = 1, TID = 03239, Nature = Nature.Naughty, IVs = new[] {-1, -1, -1, 31, -1, -1}, }, // Skitty + new EncounterTrade { Species = 300, Level = 30, Ability = 1, Gender = 1, TID = 03239, Nature = Nature.Naughty, IVs = new[] {-1, -1, -1, 31, -1, -1}, }, // Skitty new EncounterTrade { Species = 222, Level = 50, Ability = 4, Gender = 1, TID = 00325, Nature = Nature.Calm, IVs = new[] {31, -1, -1, -1, -1, 31}, }, // Corsola }; #endregion From 2e4c75aca3c51bd42041f59599197e2fae6d0f31 Mon Sep 17 00:00:00 2001 From: Eskuero Date: Sun, 5 Jun 2016 19:49:20 +0100 Subject: [PATCH 05/49] Fix third gen balls on second gen starters with HA Second generation starters are legal with third generation introduced balls because you can catch their second stage on Pokemon Colosseum, but since back then Hidden Abilities didn't exist they're restricted to normal balls only. Other balls are checked already but this ones weren't flagged as illegal. --- Legality/Checks.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Legality/Checks.cs b/Legality/Checks.cs index 3b924e242..577bf5bd2 100644 --- a/Legality/Checks.cs +++ b/Legality/Checks.cs @@ -553,6 +553,8 @@ private LegalityCheck verifyBall() { if (Legal.Ban_Gen3Ball.Contains(pk6.Species)) return new LegalityCheck(Severity.Invalid, "Unobtainable capture for Gen4 Ball."); + if (pk6.AbilityNumber == 4 && 152 <= pk6.Species && pk6.Species <= 160) + return new LegalityCheck(Severity.Invalid, "Ball not possible for species with hidden ability."); return new LegalityCheck(Severity.Valid, "Obtainable capture for Gen4 Ball."); } From a0fb281ced636425e0095b70da8fc377a3be07d4 Mon Sep 17 00:00:00 2001 From: chenzw95 Date: Fri, 10 Jun 2016 15:43:39 +0800 Subject: [PATCH 06/49] Move WC6 OT memory checks from verifyHistory to verifyOTMemory --- Legality/Checks.cs | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/Legality/Checks.cs b/Legality/Checks.cs index 577bf5bd2..4aa70f9c9 100644 --- a/Legality/Checks.cs +++ b/Legality/Checks.cs @@ -576,14 +576,6 @@ private LegalityCheck verifyHistory() return new LegalityCheck(Severity.Invalid, "Event OT Affection should be zero."); if (pk6.CurrentHandler != 1) return new LegalityCheck(Severity.Invalid, "Current handler should not be Event OT."); - if (pk6.OT_Memory != MatchedWC6.OT_Memory) - return new LegalityCheck(Severity.Invalid, "Event " + (MatchedWC6.OT_Memory == 0 ? "should not have an OT Memory" : "OT Memory should be index " + MatchedWC6.OT_Memory) + "."); - if (pk6.OT_Intensity != MatchedWC6.OT_Intensity) - return new LegalityCheck(Severity.Invalid, "Event " + (MatchedWC6.OT_Intensity == 0 ? "should not have an OT Memory Intensity value" : "OT Memory Intensity should be index " + MatchedWC6.OT_Intensity) + "."); - if (pk6.OT_TextVar != MatchedWC6.OT_TextVar) - return new LegalityCheck(Severity.Invalid, "Event " + (MatchedWC6.OT_TextVar == 0 ? "should not have an OT Memory TextVar value" : "OT Memory TextVar should be index " + MatchedWC6.OT_TextVar) + "."); - if (pk6.OT_Feeling != MatchedWC6.OT_Feeling) - return new LegalityCheck(Severity.Invalid, "Event " + (MatchedWC6.OT_Feeling == 0 ? "should not have an OT Memory Feeling value" : "OT Memory Feeling should be index " + MatchedWC6.OT_Feeling) + "."); } if (!pk6.WasEvent && !(pk6.WasLink && (EncounterMatch as EncounterLink)?.OT == false) && (pk6.HT_Name.Length == 0 || pk6.Geo1_Country == 0)) // Is not Traded { @@ -691,10 +683,15 @@ private LegalityCheck verifyOTMemory() } if (EncounterType == typeof(WC6)) { - if (pk6.OT_Memory != 0) - return new LegalityCheck(Severity.Invalid, "Event Pokémon should not have an OT memory."); - - return new LegalityCheck(Severity.Valid, "OT Memory (Event) is valid."); + WC6 MatchedWC6 = EncounterMatch as WC6; + if (pk6.OT_Memory != MatchedWC6.OT_Memory) + return new LegalityCheck(Severity.Invalid, "Event " + (MatchedWC6.OT_Memory == 0 ? "should not have an OT Memory" : "OT Memory should be index " + MatchedWC6.OT_Memory) + "."); + if (pk6.OT_Intensity != MatchedWC6.OT_Intensity) + return new LegalityCheck(Severity.Invalid, "Event " + (MatchedWC6.OT_Intensity == 0 ? "should not have an OT Memory Intensity value" : "OT Memory Intensity should be index " + MatchedWC6.OT_Intensity) + "."); + if (pk6.OT_TextVar != MatchedWC6.OT_TextVar) + return new LegalityCheck(Severity.Invalid, "Event " + (MatchedWC6.OT_TextVar == 0 ? "should not have an OT Memory TextVar value" : "OT Memory TextVar should be index " + MatchedWC6.OT_TextVar) + "."); + if (pk6.OT_Feeling != MatchedWC6.OT_Feeling) + return new LegalityCheck(Severity.Invalid, "Event " + (MatchedWC6.OT_Feeling == 0 ? "should not have an OT Memory Feeling value" : "OT Memory Feeling should be index " + MatchedWC6.OT_Feeling) + "."); } switch (pk6.OT_Memory) { From 52ff97191ab707016802a30f1f0d1cb40c7769d4 Mon Sep 17 00:00:00 2001 From: chenzw95 Date: Fri, 10 Jun 2016 15:44:25 +0800 Subject: [PATCH 07/49] Clarify History vs Memory check in legality output --- Legality/Checks.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Legality/Checks.cs b/Legality/Checks.cs index 4aa70f9c9..31443de14 100644 --- a/Legality/Checks.cs +++ b/Legality/Checks.cs @@ -565,7 +565,7 @@ private LegalityCheck verifyBall() private LegalityCheck verifyHistory() { if (!Encounter.Valid) - return new LegalityCheck(Severity.Valid, "Skipped Memory check due to other check being invalid."); + return new LegalityCheck(Severity.Valid, "Skipped History check due to other check being invalid."); WC6 MatchedWC6 = EncounterMatch as WC6; if (MatchedWC6?.OT.Length > 0) // Has Event OT -- null propagation yields false if MatchedWC6=null From 1bf70d99a39be371142f22c9b1d70d838f7eedc3 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Tue, 14 Jun 2016 15:31:33 -0700 Subject: [PATCH 08/49] Preliminary Gen V Checksum Support --- Misc/SAV5.cs | 1080 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 1074 insertions(+), 6 deletions(-) diff --git a/Misc/SAV5.cs b/Misc/SAV5.cs index 7f29c58f2..ca94e4705 100644 --- a/Misc/SAV5.cs +++ b/Misc/SAV5.cs @@ -3,20 +3,27 @@ namespace PKHeX { + public class BlockInfo5 + { + public int Offset; + public int Length; + public int ChecksumOffset; + public int ChecksumMirror; + } public class SAV5 : PKM { internal const int SIZERAW = 0x80000; // 512KB - internal const int SIZE1 = 0x24000; // B/W - internal const int SIZE2 = 0x26000; // B2/W2 + internal const int SIZE_BW = 0x24000; // B/W + internal const int SIZE_B2W2 = 0x26000; // B2/W2 internal static int getIsG5SAV(byte[] data) { - ushort chk1 = BitConverter.ToUInt16(data, SIZE1 - 0x100 + 0x8C + 0xE); - ushort actual1 = ccitt16(data.Skip(SIZE1 - 0x100).Take(0x8C).ToArray()); + ushort chk1 = BitConverter.ToUInt16(data, SIZE_BW - 0x100 + 0x8C + 0xE); + ushort actual1 = ccitt16(data.Skip(SIZE_BW - 0x100).Take(0x8C).ToArray()); if (chk1 == actual1) return 0; - ushort chk2 = BitConverter.ToUInt16(data, SIZE2 - 0x100 + 0x94 + 0xE); - ushort actual2 = ccitt16(data.Skip(SIZE2 - 0x100).Take(0x94).ToArray()); + ushort chk2 = BitConverter.ToUInt16(data, SIZE_B2W2 - 0x100 + 0x94 + 0xE); + ushort actual2 = ccitt16(data.Skip(SIZE_B2W2 - 0x100).Take(0x94).ToArray()); if (chk2 == actual2) return 1; return -1; @@ -29,6 +36,9 @@ internal static int getIsG5SAV(byte[] data) public readonly bool Exportable; public readonly byte[] BAK; public string FileName, FilePath; + + private BlockInfo5[] Blocks; + public SAV5(byte[] data = null) { Data = (byte[])(data ?? new byte[SIZERAW]).Clone(); @@ -40,8 +50,1039 @@ public SAV5(byte[] data = null) if (version < 0) // Invalidate Data Data = null; + B2W2 = version == 1; + BW = version == 0; + // Different Offsets for different games. BattleBox = version == 1 ? 0x20A00 : 0x20900; + + #region Block Tables + if (BW) + { + Blocks = new[] + { + new BlockInfo5 + { + Offset = 0x00000, + Length = 0x3E0, + ChecksumOffset = 0x003E2, + ChecksumMirror = 0x23F00 /* Box Names */ + }, + new BlockInfo5 + { + Offset = 0x00400, + Length = 0xFF0, + ChecksumOffset = 0x013F2, + ChecksumMirror = 0x23F02 /* Box 1 */ + }, + new BlockInfo5 + { + Offset = 0x01400, + Length = 0xFF0, + ChecksumOffset = 0x023F2, + ChecksumMirror = 0x23F04 /* Box 2 */ + }, + new BlockInfo5 + { + Offset = 0x02400, + Length = 0xFF0, + ChecksumOffset = 0x033F2, + ChecksumMirror = 0x23F06 /* Box 3 */ + }, + new BlockInfo5 + { + Offset = 0x03400, + Length = 0xFF0, + ChecksumOffset = 0x043F2, + ChecksumMirror = 0x23F08 /* Box 4 */ + }, + new BlockInfo5 + { + Offset = 0x04400, + Length = 0xFF0, + ChecksumOffset = 0x053F2, + ChecksumMirror = 0x23F0A /* Box 5 */ + }, + new BlockInfo5 + { + Offset = 0x05400, + Length = 0xFF0, + ChecksumOffset = 0x063F2, + ChecksumMirror = 0x23F0C /* Box 6 */ + }, + new BlockInfo5 + { + Offset = 0x06400, + Length = 0xFF0, + ChecksumOffset = 0x073F2, + ChecksumMirror = 0x23F0E /* Box 7 */ + }, + new BlockInfo5 + { + Offset = 0x07400, + Length = 0xFF0, + ChecksumOffset = 0x083F2, + ChecksumMirror = 0x23F10 /* Box 8 */ + }, + new BlockInfo5 + { + Offset = 0x08400, + Length = 0xFF0, + ChecksumOffset = 0x093F2, + ChecksumMirror = 0x23F12 /* Box 9 */ + }, + new BlockInfo5 + { + Offset = 0x09400, + Length = 0xFF0, + ChecksumOffset = 0x0A3F2, + ChecksumMirror = 0x23F14 /* Box 10 */ + }, + new BlockInfo5 + { + Offset = 0x0A400, + Length = 0xFF0, + ChecksumOffset = 0x0B3F2, + ChecksumMirror = 0x23F16 /* Box 11 */ + }, + new BlockInfo5 + { + Offset = 0x0B400, + Length = 0xFF0, + ChecksumOffset = 0x0C3F2, + ChecksumMirror = 0x23F18 /* Box 12 */ + }, + new BlockInfo5 + { + Offset = 0x0C400, + Length = 0xFF0, + ChecksumOffset = 0x0D3F2, + ChecksumMirror = 0x23F1A /* Box 13 */ + }, + new BlockInfo5 + { + Offset = 0x0D400, + Length = 0xFF0, + ChecksumOffset = 0x0E3F2, + ChecksumMirror = 0x23F1C /* Box 14 */ + }, + new BlockInfo5 + { + Offset = 0x0E400, + Length = 0xFF0, + ChecksumOffset = 0x0F3F2, + ChecksumMirror = 0x23F1E /* Box 15 */ + }, + new BlockInfo5 + { + Offset = 0x0F400, + Length = 0xFF0, + ChecksumOffset = 0x103F2, + ChecksumMirror = 0x23F20 /* Box 16 */ + }, + new BlockInfo5 + { + Offset = 0x10400, + Length = 0xFF0, + ChecksumOffset = 0x113F2, + ChecksumMirror = 0x23F22 /* Box 17 */ + }, + new BlockInfo5 + { + Offset = 0x11400, + Length = 0xFF0, + ChecksumOffset = 0x123F2, + ChecksumMirror = 0x23F24 /* Box 18 */ + }, + new BlockInfo5 + { + Offset = 0x12400, + Length = 0xFF0, + ChecksumOffset = 0x133F2, + ChecksumMirror = 0x23F26 /* Box 19 */ + }, + new BlockInfo5 + { + Offset = 0x13400, + Length = 0xFF0, + ChecksumOffset = 0x143F2, + ChecksumMirror = 0x23F28 /* Box 20 */ + }, + new BlockInfo5 + { + Offset = 0x14400, + Length = 0xFF0, + ChecksumOffset = 0x153F2, + ChecksumMirror = 0x23F2A /* Box 21 */ + }, + new BlockInfo5 + { + Offset = 0x15400, + Length = 0xFF0, + ChecksumOffset = 0x163F2, + ChecksumMirror = 0x23F2C /* Box 22 */ + }, + new BlockInfo5 + { + Offset = 0x16400, + Length = 0xFF0, + ChecksumOffset = 0x173F2, + ChecksumMirror = 0x23F2E /* Box 23 */ + }, + new BlockInfo5 + { + Offset = 0x17400, + Length = 0xFF0, + ChecksumOffset = 0x183F2, + ChecksumMirror = 0x23F30 /* Box 24 */ + }, + new BlockInfo5 + { + Offset = 0x18400, + Length = 0x9C0, + ChecksumOffset = 0x18DC2, + ChecksumMirror = 0x23F32 /* Inventory */ + }, + new BlockInfo5 + { + Offset = 0x18E00, + Length = 0x534, + ChecksumOffset = 0x19336, + ChecksumMirror = 0x23F34 /* Party Pokemon */ + }, + new BlockInfo5 + { + Offset = 0x19400, + Length = 0x68, + ChecksumOffset = 0x19469, + ChecksumMirror = 0x23F36 /* Trainer Data */ + }, + new BlockInfo5 + { + Offset = 0x19500, + Length = 0x9C, + ChecksumOffset = 0x1959E, + ChecksumMirror = 0x23F38 /* ??? */ + }, + new BlockInfo5 + { + Offset = 0x19600, + Length = 0x1338, + ChecksumOffset = 0x1A93A, + ChecksumMirror = 0x23F3A /* ??? */ + }, + new BlockInfo5 + { + Offset = 0x1AA00, + Length = 0x7C4, + ChecksumOffset = 0x1B1C6, + ChecksumMirror = 0x23F3C /* ??? */ + }, + new BlockInfo5 + { + Offset = 0x1B200, + Length = 0xD54, + ChecksumOffset = 0x1BF56, + ChecksumMirror = 0x23F3E /* ??? */ + }, + new BlockInfo5 + { + Offset = 0x1C000, + Length = 0x2C, + ChecksumOffset = 0x1C02E, + ChecksumMirror = 0x23F40 /* ??? */ + }, + new BlockInfo5 + { + Offset = 0x1C100, + Length = 0x658, + ChecksumOffset = 0x1C75A, + ChecksumMirror = 0x23F42 /* ??? Gym badge data */ + }, + new BlockInfo5 + { + Offset = 0x1C800, + Length = 0xA94, + ChecksumOffset = 0x1D296, + ChecksumMirror = 0x23F44 /* ??? */ + }, + new BlockInfo5 + { + Offset = 0x1D300, + Length = 0x1AC, + ChecksumOffset = 0x1D4AE, + ChecksumMirror = 0x23F46 /* ??? */ + }, + new BlockInfo5 + { + Offset = 0x1D500, + Length = 0x3EC, + ChecksumOffset = 0x1D8EE, + ChecksumMirror = 0x23F48 /* ??? */ + }, + new BlockInfo5 + { + Offset = 0x1D900, + Length = 0x5C, + ChecksumOffset = 0x1D95E, + ChecksumMirror = 0x23F4A /* ??? */ + }, + new BlockInfo5 + { + Offset = 0x1DA00, + Length = 0x1E0, + ChecksumOffset = 0x1DBE2, + ChecksumMirror = 0x23F4C /* ??? */ + }, + new BlockInfo5 + { + Offset = 0x1DC00, + Length = 0xA8, + ChecksumOffset = 0x1DCAA, + ChecksumMirror = 0x23F4E /* ??? */ + }, + new BlockInfo5 + { + Offset = 0x1DD00, + Length = 0x460, + ChecksumOffset = 0x1E162, + ChecksumMirror = 0x23F50 /* ??? */ + }, + new BlockInfo5 + { + Offset = 0x1E200, + Length = 0x1400, + ChecksumOffset = 0x1F602, + ChecksumMirror = 0x23F52 /* ??? */ + }, + new BlockInfo5 + { + Offset = 0x1F700, + Length = 0x2A4, + ChecksumOffset = 0x1F9A6, + ChecksumMirror = 0x23F54 /* ??? */ + }, + new BlockInfo5 + { + Offset = 0x1FA00, + Length = 0x2DC, + ChecksumOffset = 0x1FCDE, + ChecksumMirror = 0x23F56 /* ??? */ + }, + new BlockInfo5 + { + Offset = 0x1FD00, + Length = 0x34C, + ChecksumOffset = 0x2004E, + ChecksumMirror = 0x23F58 /* ??? */ + }, + new BlockInfo5 + { + Offset = 0x20100, + Length = 0x3EC, + ChecksumOffset = 0x204EE, + ChecksumMirror = 0x23F5A /* ??? */ + }, + new BlockInfo5 + { + Offset = 0x20500, + Length = 0xF8, + ChecksumOffset = 0x205FA, + ChecksumMirror = 0x23F5C /* ??? */ + }, + new BlockInfo5 + { + Offset = 0x20600, + Length = 0x2FC, + ChecksumOffset = 0x208FE, + ChecksumMirror = 0x23F5E /* ??? */ + }, + new BlockInfo5 + { + Offset = 0x20900, + Length = 0x94, + ChecksumOffset = 0x20996, + ChecksumMirror = 0x23F60 /* ??? */ + }, + new BlockInfo5 + { + Offset = 0x20A00, + Length = 0x35C, + ChecksumOffset = 0x20D5E, + ChecksumMirror = 0x23F62 /* ??? */ + }, + new BlockInfo5 + { + Offset = 0x20E00, + Length = 0x1CC, + ChecksumOffset = 0x20FCE, + ChecksumMirror = 0x23F64 /* ??? */ + }, + new BlockInfo5 + { + Offset = 0x21000, + Length = 0x168, + ChecksumOffset = 0x2116A, + ChecksumMirror = 0x23F66 /* ??? */ + }, + new BlockInfo5 + { + Offset = 0x21200, + Length = 0xEC, + ChecksumOffset = 0x212EE, + ChecksumMirror = 0x23F68 /* ??? */ + }, + new BlockInfo5 + { + Offset = 0x21300, + Length = 0x1B0, + ChecksumOffset = 0x214B2, + ChecksumMirror = 0x23F6A /* ??? */ + }, + new BlockInfo5 + { + Offset = 0x21500, + Length = 0x1C, + ChecksumOffset = 0x2151E, + ChecksumMirror = 0x23F6C /* ??? */ + }, + new BlockInfo5 + { + Offset = 0x21600, + Length = 0x4D4, + ChecksumOffset = 0x21AD6, + ChecksumMirror = 0x23F6E /* ??? */ + }, + new BlockInfo5 + { + Offset = 0x21B00, + Length = 0x34, + ChecksumOffset = 0x21B36, + ChecksumMirror = 0x23F70 /* ??? */ + }, + new BlockInfo5 + { + Offset = 0x21C00, + Length = 0x3C, + ChecksumOffset = 0x21C3E, + ChecksumMirror = 0x23F72 /* ??? */ + }, + new BlockInfo5 + { + Offset = 0x21D00, + Length = 0x1AC, + ChecksumOffset = 0x21EAE, + ChecksumMirror = 0x23F74 /* ??? */ + }, + new BlockInfo5 + { + Offset = 0x21F00, + Length = 0xB90, + ChecksumOffset = 0x22A92, + ChecksumMirror = 0x23F76 /* ??? */ + }, + new BlockInfo5 + { + Offset = 0x22B00, + Length = 0x9C, + ChecksumOffset = 0x22B9E, + ChecksumMirror = 0x23F78 /* ??? */ + }, + new BlockInfo5 + { + Offset = 0x22C00, + Length = 0x850, + ChecksumOffset = 0x23452, + ChecksumMirror = 0x23F7A /* Entralink Forest pokémon data */ + }, + new BlockInfo5 + { + Offset = 0x23500, + Length = 0x28, + ChecksumOffset = 0x2352A, + ChecksumMirror = 0x23F7C /* ??? */ + }, + new BlockInfo5 + { + Offset = 0x23600, + Length = 0x284, + ChecksumOffset = 0x23886, + ChecksumMirror = 0x23F7E /* ??? */ + }, + new BlockInfo5 + { + Offset = 0x23900, + Length = 0x10, + ChecksumOffset = 0x23912, + ChecksumMirror = 0x23F80 /* ??? */ + }, + new BlockInfo5 + { + Offset = 0x23A00, + Length = 0x5C, + ChecksumOffset = 0x23A5E, + ChecksumMirror = 0x23F82 /* ??? */ + }, + new BlockInfo5 + { + Offset = 0x23B00, + Length = 0x16C, + ChecksumOffset = 0x23C6E, + ChecksumMirror = 0x23F84 /* ??? */ + }, + new BlockInfo5 + { + Offset = 0x23D00, + Length = 0x40, + ChecksumOffset = 0x23D42, + ChecksumMirror = 0x23F86 /* ??? */ + }, + new BlockInfo5 + { + Offset = 0x23E00, + Length = 0xFC, + ChecksumOffset = 0x23EFE, + ChecksumMirror = 0x23F88 /* ??? */ + }, + new BlockInfo5 + { + Offset = 0x23F00, + Length = 0x8C, + ChecksumOffset = 0x23F9A, + ChecksumMirror = 0x23F9A /* Checksums */ + } + }; + } + else if (B2W2) + { + Blocks = new[] + { + new BlockInfo5 + { + Offset = 0x00000, + Length = 0x3e0, + ChecksumOffset = 0x003E2, + ChecksumMirror = 0x25F00 /* Box Names */ + }, + new BlockInfo5 + { + Offset = 0x00400, + Length = 0xff0, + ChecksumOffset = 0x013F2, + ChecksumMirror = 0x25F02 /* Box 1 */ + }, + new BlockInfo5 + { + Offset = 0x01400, + Length = 0xff0, + ChecksumOffset = 0x023F2, + ChecksumMirror = 0x25F04 /* Box 2 */ + }, + new BlockInfo5 + { + Offset = 0x02400, + Length = 0xff0, + ChecksumOffset = 0x033F2, + ChecksumMirror = 0x25F06 /* Box 3 */ + }, + new BlockInfo5 + { + Offset = 0x03400, + Length = 0xff0, + ChecksumOffset = 0x043F2, + ChecksumMirror = 0x25F08 /* Box 4 */ + }, + new BlockInfo5 + { + Offset = 0x04400, + Length = 0xff0, + ChecksumOffset = 0x053F2, + ChecksumMirror = 0x25F0A /* Box 5 */ + }, + new BlockInfo5 + { + Offset = 0x05400, + Length = 0xff0, + ChecksumOffset = 0x063F2, + ChecksumMirror = 0x25F0C /* Box 6 */ + }, + new BlockInfo5 + { + Offset = 0x06400, + Length = 0xff0, + ChecksumOffset = 0x073F2, + ChecksumMirror = 0x25F0E /* Box 7 */ + }, + new BlockInfo5 + { + Offset = 0x07400, + Length = 0xff0, + ChecksumOffset = 0x083F2, + ChecksumMirror = 0x25F10 /* Box 8 */ + }, + new BlockInfo5 + { + Offset = 0x08400, + Length = 0xff0, + ChecksumOffset = 0x093F2, + ChecksumMirror = 0x25F12 /* Box 9 */ + }, + new BlockInfo5 + { + Offset = 0x09400, + Length = 0xff0, + ChecksumOffset = 0x0A3F2, + ChecksumMirror = 0x25F14 /* Box 10 */ + }, + new BlockInfo5 + { + Offset = 0x0A400, + Length = 0xff0, + ChecksumOffset = 0x0B3F2, + ChecksumMirror = 0x25F16 /* Box 11 */ + }, + new BlockInfo5 + { + Offset = 0x0B400, + Length = 0xff0, + ChecksumOffset = 0x0C3F2, + ChecksumMirror = 0x25F18 /* Box 12 */ + }, + new BlockInfo5 + { + Offset = 0x0C400, + Length = 0xff0, + ChecksumOffset = 0x0D3F2, + ChecksumMirror = 0x25F1A /* Box 13 */ + }, + new BlockInfo5 + { + Offset = 0x0D400, + Length = 0xff0, + ChecksumOffset = 0x0E3F2, + ChecksumMirror = 0x25F1C /* Box 14 */ + }, + new BlockInfo5 + { + Offset = 0x0E400, + Length = 0xff0, + ChecksumOffset = 0x0F3F2, + ChecksumMirror = 0x25F1E /* Box 15 */ + }, + new BlockInfo5 + { + Offset = 0x0F400, + Length = 0xff0, + ChecksumOffset = 0x103F2, + ChecksumMirror = 0x25F20 /* Box 16 */ + }, + new BlockInfo5 + { + Offset = 0x10400, + Length = 0xff0, + ChecksumOffset = 0x113F2, + ChecksumMirror = 0x25F22 /* Box 17 */ + }, + new BlockInfo5 + { + Offset = 0x11400, + Length = 0xff0, + ChecksumOffset = 0x123F2, + ChecksumMirror = 0x25F24 /* Box 18 */ + }, + new BlockInfo5 + { + Offset = 0x12400, + Length = 0xff0, + ChecksumOffset = 0x133F2, + ChecksumMirror = 0x25F26 /* Box 19 */ + }, + new BlockInfo5 + { + Offset = 0x13400, + Length = 0xff0, + ChecksumOffset = 0x143F2, + ChecksumMirror = 0x25F28 /* Box 20 */ + }, + new BlockInfo5 + { + Offset = 0x14400, + Length = 0xff0, + ChecksumOffset = 0x153F2, + ChecksumMirror = 0x25F2A /* Box 21 */ + }, + new BlockInfo5 + { + Offset = 0x15400, + Length = 0xff0, + ChecksumOffset = 0x163F2, + ChecksumMirror = 0x25F2C /* Box 22 */ + }, + new BlockInfo5 + { + Offset = 0x16400, + Length = 0xff0, + ChecksumOffset = 0x173F2, + ChecksumMirror = 0x25F2E /* Box 23 */ + }, + new BlockInfo5 + { + Offset = 0x17400, + Length = 0xff0, + ChecksumOffset = 0x183F2, + ChecksumMirror = 0x25F30 /* Box 24 */ + }, + new BlockInfo5 + { + Offset = 0x18400, + Length = 0x9ec, + ChecksumOffset = 0x18DEE, + ChecksumMirror = 0x25F32 /* Inventory */ + }, + new BlockInfo5 + { + Offset = 0x18E00, + Length = 0x534, + ChecksumOffset = 0x19336, + ChecksumMirror = 0x25F34 /* Party Pokemon */ + }, + new BlockInfo5 + { + Offset = 0x19400, + Length = 0xb0, + ChecksumOffset = 0x194B2, + ChecksumMirror = 0x25F36 /* Trainer Data */ + }, + new BlockInfo5 + { + Offset = 0x19500, + Length = 0xa8, + ChecksumOffset = 0x195AA, + ChecksumMirror = 0x25F38 /* Trainer Position */ + }, + new BlockInfo5 + { + Offset = 0x19600, + Length = 0x1338, + ChecksumOffset = 0x1A93A, + ChecksumMirror = 0x25F3A /* Unity Tower and survey stuff */ + }, + new BlockInfo5 + { + Offset = 0x1AA00, + Length = 0x7c4, + ChecksumOffset = 0x1B1C6, + ChecksumMirror = 0x25F3C /* Pal Pad Player Data (30d) */ + }, + new BlockInfo5 + { + Offset = 0x1B200, + Length = 0xd54, + ChecksumOffset = 0x1BF56, + ChecksumMirror = 0x25F3E /* Pal Pad Friend Data */ + }, + new BlockInfo5 + { + Offset = 0x1C000, + Length = 0x94, + ChecksumOffset = 0x1C096, + ChecksumMirror = 0x25F40 /* C-Gear */ + }, + new BlockInfo5 + { + Offset = 0x1C100, + Length = 0x658, + ChecksumOffset = 0x1C75A, + ChecksumMirror = 0x25F42 /* Card Signature Block & ???? */ + }, + new BlockInfo5 + { + Offset = 0x1C800, + Length = 0xa94, + ChecksumOffset = 0x1D296, + ChecksumMirror = 0x25F44 /* Mystery Gift */ + }, + new BlockInfo5 + { + Offset = 0x1D300, + Length = 0x1ac, + ChecksumOffset = 0x1D4AE, + ChecksumMirror = 0x25F46 /* Dream World Stuff (Catalog) */ + }, + new BlockInfo5 + { + Offset = 0x1D500, + Length = 0x3ec, + ChecksumOffset = 0x1D8EE, + ChecksumMirror = 0x25F48 /* Chatter */ + }, + new BlockInfo5 + { + Offset = 0x1D900, + Length = 0x5c, + ChecksumOffset = 0x1D95E, + ChecksumMirror = 0x25F4A /* Adventure data */ + }, + new BlockInfo5 + { + Offset = 0x1DA00, + Length = 0x1e0, + ChecksumOffset = 0x1DBE2, + ChecksumMirror = 0x25F4C /* Trainer Card Records */ + }, + new BlockInfo5 + { + Offset = 0x1DC00, + Length = 0xa8, + ChecksumOffset = 0x1DCAA, + ChecksumMirror = 0x25F4E /* ??? */ + }, + new BlockInfo5 + { + Offset = 0x1DD00, + Length = 0x460, + ChecksumOffset = 0x1E162, + ChecksumMirror = 0x25F50 /* (40d) */ + }, + new BlockInfo5 + { + Offset = 0x1E200, + Length = 0x1400, + ChecksumOffset = 0x1F602, + ChecksumMirror = 0x25F52 /* ??? */ + }, + new BlockInfo5 + { + Offset = 0x1F700, + Length = 0x2a4, + ChecksumOffset = 0x1F9A6, + ChecksumMirror = 0x25F54 /* Contains flags and references for downloaded data (Musical) */ + }, + new BlockInfo5 + { + Offset = 0x1FA00, + Length = 0xe0, + ChecksumOffset = 0x1FAE2, + ChecksumMirror = 0x25F56 /* Fused Reshiram/Zekrom Storage */ + }, + new BlockInfo5 + { + Offset = 0x1FB00, + Length = 0x34c, + ChecksumOffset = 0x1FE4E, + ChecksumMirror = 0x25F58 /* ??? */ + }, + new BlockInfo5 + { + Offset = 0x1FF00, + Length = 0x4e0, + ChecksumOffset = 0x203E2, + ChecksumMirror = 0x25F5A /* Const Data Block and Event Flag Block (0x35E is the split) */ + }, + new BlockInfo5 + { + Offset = 0x20400, + Length = 0xf8, + ChecksumOffset = 0x204FA, + ChecksumMirror = 0x25F5C /* ??? */ + }, + new BlockInfo5 + { + Offset = 0x20500, + Length = 0x2fc, + ChecksumOffset = 0x207FE, + ChecksumMirror = 0x25F5E /* Tournament Block */ + }, + new BlockInfo5 + { + Offset = 0x20800, + Length = 0x94, + ChecksumOffset = 0x20896, + ChecksumMirror = 0x25F60 /* ??? */ + }, + new BlockInfo5 + { + Offset = 0x20900, + Length = 0x35c, + ChecksumOffset = 0x20C5E, + ChecksumMirror = 0x25F62 /* Battle Box Block */ + }, + new BlockInfo5 + { + Offset = 0x20D00, + Length = 0x1d4, + ChecksumOffset = 0x20ED6, + ChecksumMirror = 0x25F64 /* Daycare Block (50d) */ + }, + new BlockInfo5 + { + Offset = 0x20F00, + Length = 0x1e0, + ChecksumOffset = 0x201E2, + ChecksumMirror = 0x25F66 /* Strength Boulder Status Block */ + }, + new BlockInfo5 + { + Offset = 0x21100, + Length = 0xf0, + ChecksumOffset = 0x211F2, + ChecksumMirror = 0x25F68 /* Badge Flags, Money, Trainer Sayings */ + }, + new BlockInfo5 + { + Offset = 0x21200, + Length = 0x1b4, + ChecksumOffset = 0x213B6, + ChecksumMirror = 0x25F6A /* Entralink (Level & Powers etc) */ + }, + new BlockInfo5 + { + Offset = 0x21400, + Length = 0x4dc, + ChecksumOffset = 0x218DE, + ChecksumMirror = 0x25F6C /* Pokedex */ + }, + new BlockInfo5 + { + Offset = 0x21900, + Length = 0x34, + ChecksumOffset = 0x21936, + ChecksumMirror = 0x25F6E + /* Swarm and other overworld info - 2C - swarm, 2D - repel steps, 2E repel type */ + }, + new BlockInfo5 + { + Offset = 0x21A00, + Length = 0x3c, + ChecksumOffset = 0x21A3E, + ChecksumMirror = 0x25F70 /* ??? */ + }, + new BlockInfo5 + { + Offset = 0x21B00, + Length = 0x1ac, + ChecksumOffset = 0x21CAE, + ChecksumMirror = 0x25F72 /* ??? */ + }, + new BlockInfo5 + { + Offset = 0x21D00, + Length = 0xb90, + ChecksumOffset = 0x22892, + ChecksumMirror = 0x25F74 /* ??? */ + }, + new BlockInfo5 + { + Offset = 0x22900, + Length = 0xac, + ChecksumOffset = 0x229AE, + ChecksumMirror = 0x25F76 /* Online Records */ + }, + new BlockInfo5 + { + Offset = 0x22A00, + Length = 0x850, + ChecksumOffset = 0x23252, + ChecksumMirror = 0x25F78 /* Area NPC data - encrypted (60d) */ + }, + new BlockInfo5 + { + Offset = 0x23300, + Length = 0x284, + ChecksumOffset = 0x23586, + ChecksumMirror = 0x25F7A /* ??? */ + }, + new BlockInfo5 + { + Offset = 0x23600, + Length = 0x10, + ChecksumOffset = 0x23612, + ChecksumMirror = 0x25F7C /* ??? */ + }, + new BlockInfo5 + { + Offset = 0x23700, + Length = 0xa8, + ChecksumOffset = 0x237AA, + ChecksumMirror = 0x25F7E /* ??? */ + }, + new BlockInfo5 + { + Offset = 0x23800, + Length = 0x16c, + ChecksumOffset = 0x2396E, + ChecksumMirror = 0x25F80 /* ??? */ + }, + new BlockInfo5 + { + Offset = 0x23A00, + Length = 0x80, + ChecksumOffset = 0x23A82, + ChecksumMirror = 0x25F82 /* ??? */ + }, + new BlockInfo5 + { + Offset = 0x23B00, + Length = 0xfc, + ChecksumOffset = 0x23BFE, + ChecksumMirror = 0x25F84 /* Hollow/Rival Block */ + }, + new BlockInfo5 + { + Offset = 0x23C00, + Length = 0x16a8, + ChecksumOffset = 0x252AA, + ChecksumMirror = 0x25F86 /* Join Avenue Block */ + }, + new BlockInfo5 + { + Offset = 0x25300, + Length = 0x498, + ChecksumOffset = 0x2579A, + ChecksumMirror = 0x25F88 /* Medal data */ + }, + new BlockInfo5 + { + Offset = 0x25800, + Length = 0x60, + ChecksumOffset = 0x25862, + ChecksumMirror = 0x25F8A /* Key-related data */ + }, + new BlockInfo5 + { + Offset = 0x25900, + Length = 0xfc, + ChecksumOffset = 0x259FE, + ChecksumMirror = 0x25F8C /* (70d) */ + }, + new BlockInfo5 + { + Offset = 0x25A00, + Length = 0x3e4, + ChecksumOffset = 0x25DE6, + ChecksumMirror = 0x25F8E /* ??? */ + }, + new BlockInfo5 + { + Offset = 0x25E00, + Length = 0xf0, + ChecksumOffset = 0x25EF2, + ChecksumMirror = 0x25F90 /* ??? */ + }, + new BlockInfo5 + { + Offset = 0x25F00, + Length = 0x94, + ChecksumOffset = 0x25FA2, + ChecksumMirror = 0x25FA2 /* Checksum Block (73d) */ + } + }; + } + else + { + Blocks = new BlockInfo5[] {}; + } + #endregion } private const int Box = 0x400; @@ -51,6 +1092,33 @@ public SAV5(byte[] data = null) private const int Wondercard = 0x1C800; private const int wcSeed = 0x1D290; + private bool BW; + private bool B2W2; + + private void setChecksums() + { + // Check for invalid block lengths + if (Blocks.Length < 3) // arbitrary... + { + Console.WriteLine("Not enough blocks ({0}), aborting setChecksums", Blocks.Length); + return; + } + // Apply checksums + for (int i = 0; i < Blocks.Length; i++) + { + byte[] array = Data.Skip(Blocks[i].Offset).Take(Blocks[i].Length).ToArray(); + ushort chk = ccitt16(array); + BitConverter.GetBytes(chk).CopyTo(Data, Blocks[i].ChecksumOffset); + BitConverter.GetBytes(chk).CopyTo(Data, Blocks[i].ChecksumMirror); + } + } + + public byte[] Write() + { + setChecksums(); + return Data; + } + public int PartyCount { get { return Data[Party]; } From 6378eb7f561b4dce3c5f79e0f63df717973a7884 Mon Sep 17 00:00:00 2001 From: Kaphotics Date: Sun, 19 Jun 2016 21:22:43 -0700 Subject: [PATCH 09/49] Current progress Still a few milestones left to hit before official release. --- Legality/Analysis.cs | 10 +- Legality/Checks.cs | 7 + Legality/Core.cs | 6 +- Legality/Tables.cs | 71 +- Legality/Tables4.cs | 70 + Legality/Tables5.cs | 29 + Misc/PGT.cs | 142 -- Misc/PK3.cs | 299 --- Misc/PKX.cs | 1518 ------------ Misc/QR.cs | 55 + Misc/SAV4.cs | 178 -- Misc/SAV5.cs | 204 -- Misc/Util.cs | 54 +- MysteryGifts/MysteryGift.cs | 41 + {Misc => MysteryGifts}/PGF.cs | 43 +- MysteryGifts/PGT.cs | 209 ++ {Misc => MysteryGifts}/WC6.cs | 24 +- PKHeX.csproj | 90 +- PKM/PK3.cs | 299 +++ {Misc => PKM}/PK4.cs | 328 ++- {Misc => PKM}/PK5.cs | 286 +-- {Misc => PKM}/PK6.cs | 332 +-- PKM/PKM.cs | 278 +++ PKM/PKMConverter.cs | 138 ++ Misc/PKM.cs => PKM/PKX.cs | 1147 ++++++++- PKM/ShowdownSet.cs | 281 +++ PKX/f1-Main.Designer.cs | 636 +++-- PKX/f1-Main.cs | 2081 ++++++++++------- PKX/f1-Main.resx | 613 +++-- PKX/f3-MemoryAmie.cs | 142 +- PKX/f4-RibbMedal.cs | 6 +- Properties/Resources.Designer.cs | 608 +++-- Properties/Resources.resx | 69 + Resources/img/Bag/Bag_Balls.png | Bin 0 -> 283 bytes Resources/img/Bag/Bag_Battle.png | Bin 0 -> 305 bytes Resources/img/Bag/Bag_Berries.png | Bin 0 -> 291 bytes Resources/img/Bag/Bag_Items.png | Bin 0 -> 257 bytes Resources/img/Bag/Bag_Key.png | Bin 0 -> 286 bytes Resources/img/Bag/Bag_Mail.png | Bin 0 -> 225 bytes Resources/img/Bag/Bag_Medicine.png | Bin 0 -> 216 bytes Resources/img/Bag/Bag_TMHM.png | Bin 0 -> 311 bytes Resources/img/Program/about.png | Bin 0 -> 367 bytes Resources/img/Program/bak.png | Bin 0 -> 352 bytes Resources/img/Program/data.png | Bin 0 -> 168 bytes Resources/img/Program/database.png | Bin 0 -> 134 bytes Resources/img/Program/dump.png | Bin 0 -> 203 bytes Resources/img/Program/exit.png | Bin 0 -> 288 bytes Resources/img/Program/export.png | Bin 0 -> 253 bytes Resources/img/Program/folder.png | Bin 0 -> 177 bytes Resources/img/Program/import.png | Bin 0 -> 372 bytes Resources/img/Program/language.png | Bin 0 -> 439 bytes Resources/img/Program/load.png | Bin 0 -> 206 bytes Resources/img/Program/main.png | Bin 0 -> 274 bytes Resources/img/Program/nocheck.png | Bin 0 -> 224 bytes Resources/img/Program/open.png | Bin 0 -> 180 bytes Resources/img/Program/other.png | Bin 0 -> 357 bytes Resources/img/Program/report.png | Bin 0 -> 297 bytes Resources/img/Program/savePKM.png | Bin 0 -> 334 bytes Resources/img/Program/saveSAV.png | Bin 0 -> 289 bytes Resources/img/Program/settings.png | Bin 0 -> 354 bytes Resources/img/Program/showdown.png | Bin 0 -> 289 bytes Resources/text/other/const_oras.txt | 4 + Resources/text/other/flags_oras.txt | 66 + Resources/text/other/flags_xy.txt | 19 + SAV/SAV_BerryFieldXY.cs | 18 +- SAV/SAV_BoxLayout.cs | 28 +- SAV/SAV_Database.Designer.cs | 7 +- SAV/SAV_Database.cs | 51 +- SAV/SAV_EventFlags.Designer.cs | 382 +++ SAV/SAV_EventFlags.cs | 358 +++ ...erryFieldORAS.resx => SAV_EventFlags.resx} | 0 SAV/SAV_EventFlagsORAS.Designer.cs | 1378 ----------- SAV/SAV_EventFlagsORAS.cs | 261 --- SAV/SAV_EventFlagsXY.Designer.cs | 701 ------ SAV/SAV_EventFlagsXY.cs | 230 -- SAV/SAV_EventFlagsXY.resx | 216 -- SAV/SAV_HallOfFame.cs | 5 +- SAV/SAV_Inventory.Designer.cs | 160 +- SAV/SAV_Inventory.cs | 313 ++- SAV/SAV_Inventory.resx | 191 +- SAV/SAV_OPower.cs | 40 +- ...igner.cs => SAV_PokeBlockORAS.Designer.cs} | 6 +- ...BerryFieldORAS.cs => SAV_PokeBlockORAS.cs} | 14 +- ...tFlagsORAS.resx => SAV_PokeBlockORAS.resx} | 0 SAV/SAV_PokedexORAS.cs | 38 +- SAV/SAV_PokedexXY.cs | 32 +- SAV/SAV_Pokepuff.cs | 17 +- SAV/SAV_SecretBase.cs | 78 +- SAV/SAV_SuperTrain.cs | 40 +- SAV/SAV_Trainer.cs | 6 +- SAV/SAV_Wondercard.Designer.cs | 40 +- SAV/SAV_Wondercard.cs | 364 +-- SAV/frmReport.cs | 235 +- Saves/BlockInfo.cs | 25 + Saves/Inventory.cs | 64 + Saves/SAV4.cs | 665 ++++++ Saves/SAV5.cs | 599 +++++ {Misc => Saves}/SAV6.cs | 889 +++---- Saves/SaveFile.cs | 435 ++++ Saves/SaveObjects.cs | 22 + Saves/SaveUtil.cs | 373 +++ 101 files changed, 9574 insertions(+), 9090 deletions(-) create mode 100644 Legality/Tables4.cs create mode 100644 Legality/Tables5.cs delete mode 100644 Misc/PGT.cs delete mode 100644 Misc/PK3.cs delete mode 100644 Misc/PKX.cs delete mode 100644 Misc/SAV4.cs delete mode 100644 Misc/SAV5.cs create mode 100644 MysteryGifts/MysteryGift.cs rename {Misc => MysteryGifts}/PGF.cs (89%) create mode 100644 MysteryGifts/PGT.cs rename {Misc => MysteryGifts}/WC6.cs (96%) create mode 100644 PKM/PK3.cs rename {Misc => PKM}/PK4.cs (65%) rename {Misc => PKM}/PK5.cs (71%) rename {Misc => PKM}/PK6.cs (70%) create mode 100644 PKM/PKM.cs create mode 100644 PKM/PKMConverter.cs rename Misc/PKM.cs => PKM/PKX.cs (63%) create mode 100644 PKM/ShowdownSet.cs create mode 100644 Resources/img/Bag/Bag_Balls.png create mode 100644 Resources/img/Bag/Bag_Battle.png create mode 100644 Resources/img/Bag/Bag_Berries.png create mode 100644 Resources/img/Bag/Bag_Items.png create mode 100644 Resources/img/Bag/Bag_Key.png create mode 100644 Resources/img/Bag/Bag_Mail.png create mode 100644 Resources/img/Bag/Bag_Medicine.png create mode 100644 Resources/img/Bag/Bag_TMHM.png create mode 100644 Resources/img/Program/about.png create mode 100644 Resources/img/Program/bak.png create mode 100644 Resources/img/Program/data.png create mode 100644 Resources/img/Program/database.png create mode 100644 Resources/img/Program/dump.png create mode 100644 Resources/img/Program/exit.png create mode 100644 Resources/img/Program/export.png create mode 100644 Resources/img/Program/folder.png create mode 100644 Resources/img/Program/import.png create mode 100644 Resources/img/Program/language.png create mode 100644 Resources/img/Program/load.png create mode 100644 Resources/img/Program/main.png create mode 100644 Resources/img/Program/nocheck.png create mode 100644 Resources/img/Program/open.png create mode 100644 Resources/img/Program/other.png create mode 100644 Resources/img/Program/report.png create mode 100644 Resources/img/Program/savePKM.png create mode 100644 Resources/img/Program/saveSAV.png create mode 100644 Resources/img/Program/settings.png create mode 100644 Resources/img/Program/showdown.png create mode 100644 Resources/text/other/const_oras.txt create mode 100644 Resources/text/other/flags_oras.txt create mode 100644 Resources/text/other/flags_xy.txt create mode 100644 SAV/SAV_EventFlags.Designer.cs create mode 100644 SAV/SAV_EventFlags.cs rename SAV/{SAV_BerryFieldORAS.resx => SAV_EventFlags.resx} (100%) delete mode 100644 SAV/SAV_EventFlagsORAS.Designer.cs delete mode 100644 SAV/SAV_EventFlagsORAS.cs delete mode 100644 SAV/SAV_EventFlagsXY.Designer.cs delete mode 100644 SAV/SAV_EventFlagsXY.cs delete mode 100644 SAV/SAV_EventFlagsXY.resx rename SAV/{SAV_BerryFieldORAS.Designer.cs => SAV_PokeBlockORAS.Designer.cs} (99%) rename SAV/{SAV_BerryFieldORAS.cs => SAV_PokeBlockORAS.cs} (84%) rename SAV/{SAV_EventFlagsORAS.resx => SAV_PokeBlockORAS.resx} (100%) create mode 100644 Saves/BlockInfo.cs create mode 100644 Saves/Inventory.cs create mode 100644 Saves/SAV4.cs create mode 100644 Saves/SAV5.cs rename {Misc => Saves}/SAV6.cs (56%) create mode 100644 Saves/SaveFile.cs create mode 100644 Saves/SaveObjects.cs create mode 100644 Saves/SaveUtil.cs diff --git a/Legality/Analysis.cs b/Legality/Analysis.cs index c23251823..940284439 100644 --- a/Legality/Analysis.cs +++ b/Legality/Analysis.cs @@ -21,9 +21,11 @@ public partial class LegalityAnalysis public string Report => getLegalityReport(); public string VerboseReport => getVerboseLegalityReport(); - public LegalityAnalysis(PK6 pk) + public LegalityAnalysis(PKM pk) { - pk6 = pk; + if (!(pk is PK6)) + return; + pk6 = pk as PK6; updateRelearnLegality(); updateMoveLegality(); updateChecks(); @@ -66,7 +68,7 @@ private void updateChecks() } private string getLegalityReport() { - if (!pk6.Gen6) + if (pk6 == null || !pk6.Gen6) return "Analysis only available for Pokémon that originate from X/Y & OR/AS."; var chks = Checks; @@ -91,6 +93,8 @@ private string getLegalityReport() private string getVerboseLegalityReport() { string r = getLegalityReport() + Environment.NewLine; + if (pk6 == null) + return r; r += "===" + Environment.NewLine + Environment.NewLine; int rl = r.Length; diff --git a/Legality/Checks.cs b/Legality/Checks.cs index 3b924e242..08500ec93 100644 --- a/Legality/Checks.cs +++ b/Legality/Checks.cs @@ -37,6 +37,13 @@ private LegalityCheck verifyECPID() if (pk6.PID == 0) return new LegalityCheck(Severity.Fishy, "PID is not set."); + if (EncounterType == typeof (EncounterStatic)) + { + var enc = (EncounterStatic) EncounterMatch; + if (enc.Shiny != null && (bool)enc.Shiny ^ pk6.IsShiny) + return new LegalityCheck(Severity.Invalid, "Encounter " + (enc.Shiny == true ? "must be" : "cannot be") + " shiny."); + } + string special = ""; if (pk6.Gen6) { diff --git a/Legality/Core.cs b/Legality/Core.cs index 3be95b083..8a9454ab5 100644 --- a/Legality/Core.cs +++ b/Legality/Core.cs @@ -198,8 +198,10 @@ internal static EncounterStatic getValidStaticEncounter(PK6 pk6) continue; if (e.Level != pk6.Met_Level) continue; - if (e.Shiny != null && e.Shiny != pk6.IsShiny) - continue; + + // Defer to EC/PID check + // if (e.Shiny != null && e.Shiny != pk6.IsShiny) + // continue; // Defer ball check to later // if (e.Gift && pk6.Ball != 4) // PokéBall diff --git a/Legality/Tables.cs b/Legality/Tables.cs index afcb3c4a3..c03db8fe7 100644 --- a/Legality/Tables.cs +++ b/Legality/Tables.cs @@ -1,57 +1,22 @@ -namespace PKHeX +using System.Linq; + +namespace PKHeX { public static partial class Legal { // PKHeX Valid Array Storage - #region Items - - internal static readonly int[] Items_Held = - { - 000, 001, 002, 003, 004, 005, 006, 007, 008, 009, 010, 011, 012, 013, 014, 015, 017, 018, 019, 020, 021, 022, - 023, 024, 025, 026, 027, 028, 029, 030, 031, 032, 033, 034, 035, - 036, 037, 038, 039, 040, 041, 042, 043, 044, 045, 046, 047, 048, 049, 050, 051, 052, 053, 054, 055, 056, 057, - 058, 059, 060, 061, 062, 063, 064, 065, 066, 067, 068, 069, 070, - 071, 072, 073, 074, 075, 076, 077, 078, 079, 080, 081, 082, 083, 084, 085, 086, 087, 088, 089, 090, 091, 092, - 093, 094, 099, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, - 110, 112, 116, 117, 118, 119, 134, 135, 136, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, - 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, - 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, - 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, - 210, 211, 212, 213, 214, 215, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, - 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, - 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, - 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, - 280, 281, 282, 283, 284, 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300, 301, - 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, - 315, 316, 317, 318, 319, 320, 321, 322, 323, 324, 325, 326, 327, 504, 537, 538, 539, 540, 541, 542, 543, 544, - 545, 546, 547, 548, 549, 550, 551, 552, 553, 554, 555, 556, 557, - 558, 559, 560, 561, 562, 563, 564, 565, 566, 567, 568, 569, 570, 571, 572, 573, 577, 580, 581, 582, 583, 584, - 585, 586, 587, 588, 589, 590, 591, 639, 640, 644, 645, 646, 647, - 648, 649, 650, 652, 653, 654, 655, 656, 657, 658, 659, 660, 661, 662, 663, 664, 665, 666, 667, 668, 669, 670, - 671, 672, 673, 674, 675, 676, 677, 678, 679, 680, 681, 682, 683, - 684, 685, 686, 687, 688, 699, 704, 708, 709, 710, 711, 715, - - // Appended ORAS Items (Orbs & Mega Stones) - 534, 535, - 752, 753, 754, 755, 756, 757, 758, 759, 760, 761, 762, 763, 764, 767, 768, 769, 770, - }; - internal static readonly int[] Items_Ball = { 000, 001, 002, 003, 004, 005, 006, 007, 008, 009, 010, 011, 012, 013, 014, 015, 016, 492, 493, 494, 495, 496, 497, 498, 499, 576, }; - internal static readonly int[] Items_CommonBall = {4, 3, 2, 1}; - internal static readonly int[] Items_UncommonBall = { 7, 576, 13, 492, 497, 14, 495, 493, 496, 494, 11, 498, 8, 6, 12, 15, 9, 5, 499, 10, 16 }; - - #endregion #region Games @@ -170,7 +135,7 @@ public static partial class Legal internal static readonly ushort[] Pouch_Items_XY = { - 000, 001, 002, 003, 004, 005, 006, 007, 008, 009, 010, 011, 012, 013, 014, 015, 016, 055, 056, + 001, 002, 003, 004, 005, 006, 007, 008, 009, 010, 011, 012, 013, 014, 015, 016, 055, 056, 057, 058, 059, 060, 061, 062, 063, 064, 065, 066, 067, 068, 069, 070, 071, 072, 073, 074, 075, 076, 077, 078, 079, 080, 081, 082, 083, 084, 085, 086, 087, 088, 089, 090, 091, 092, 093, 094, 099, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 112, 116, 117, 118, 119, 135, 136, @@ -188,9 +153,9 @@ public static partial class Legal 699, 704, 710, 711, 715, }; - internal static readonly ushort[] Pouch_Items_ORAS = + internal static readonly ushort[] Pouch_Items_AO = { - 000, 001, 002, 003, 004, 005, 006, 007, 008, 009, 010, 011, 012, 013, 014, 015, 016, 055, 056, + 001, 002, 003, 004, 005, 006, 007, 008, 009, 010, 011, 012, 013, 014, 015, 016, 055, 056, 057, 058, 059, 060, 061, 062, 063, 064, 068, 069, 070, 071, 072, 073, 074, 075, 076, 077, 078, 079, 080, 081, 082, 083, 084, 085, 086, 087, 088, 089, 090, 091, 092, 093, 094, 099, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 112, 116, 117, 118, 119, 135, 136, @@ -214,7 +179,7 @@ public static partial class Legal internal static readonly ushort[] Pouch_Key_XY = { - 000, 216, 431, 442, 445, 446, 447, 450, 465, 466, 471, 628, + 216, 431, 442, 445, 446, 447, 450, 465, 466, 471, 628, 629, 631, 632, 638, 641, 642, 643, 689, 695, 696, 697, 698, 700, 701, 702, 703, 705, 706, 707, 712, 713, 714, @@ -222,9 +187,9 @@ public static partial class Legal 716, 717, // For the cheaters who want useless items... }; - internal static readonly ushort[] Pouch_Key_ORAS = + internal static readonly ushort[] Pouch_Key_AO = { - 000, 216, 445, 446, 447, 465, 466, 471, 628, + 216, 445, 446, 447, 465, 466, 471, 628, 629, 631, 632, 638, 697, // Illegal @@ -242,7 +207,6 @@ public static partial class Legal internal static readonly ushort[] Pouch_TMHM_XY = { - 0, 328, 329, 330, 331, 332, 333, 334, 335, 336, 337, 338, 339, 340, 341, 342, 343, 344, 345, 346, 347, 348, 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, 362, 363, 364, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, 381, @@ -253,9 +217,8 @@ public static partial class Legal 420, 421, 422, 423, 424, }; - internal static readonly ushort[] Pouch_TMHM_ORAS = + internal static readonly ushort[] Pouch_TMHM_AO = { - 0, 328, 329, 330, 331, 332, 333, 334, 335, 336, 337, 338, 339, 340, 341, 342, 343, 344, 345, 346, 347, 348, 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, 362, 363, 364, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, 381, @@ -271,14 +234,14 @@ public static partial class Legal internal static readonly ushort[] Pouch_Medicine_XY = { - 000, 017, 018, 019, 020, 021, 022, 023, 024, 025, 026, 027, 028, 029, 030, 031, 032, 033, + 017, 018, 019, 020, 021, 022, 023, 024, 025, 026, 027, 028, 029, 030, 031, 032, 033, 034, 035, 036, 037, 038, 039, 040, 041, 042, 043, 044, 045, 046, 047, 048, 049, 050, 051, 052, 053, 054, 134, 504, 565, 566, 567, 568, 569, 570, 571, 591, 645, 708, 709, }; - internal static readonly ushort[] Pouch_Medicine_ORAS = + internal static readonly ushort[] Pouch_Medicine_AO = { - 000, 017, 018, 019, 020, 021, 022, 023, 024, 025, 026, 027, 028, 029, 030, 031, 032, 033, + 017, 018, 019, 020, 021, 022, 023, 024, 025, 026, 027, 028, 029, 030, 031, 032, 033, 034, 035, 036, 037, 038, 039, 040, 041, 042, 043, 044, 045, 046, 047, 048, 049, 050, 051, 052, 053, 054, 134, 504, 565, 566, 567, 568, 569, 570, 571, 591, 645, 708, 709, @@ -288,13 +251,15 @@ public static partial class Legal internal static readonly ushort[] Pouch_Berry_XY = { - 0, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, + 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 686, 687, 688, }; + internal static readonly ushort[] HeldItem_XY = new ushort[1].Concat(Pouch_Items_XY).Concat(Pouch_Medicine_XY).Concat(Pouch_Berry_XY).ToArray(); + internal static readonly ushort[] HeldItem_AO = new ushort[1].Concat(Pouch_Items_AO).Concat(Pouch_Medicine_AO).Concat(Pouch_Berry_XY).ToArray(); #endregion #region TMHM @@ -345,8 +310,8 @@ public static partial class Legal // Legality internal static readonly int[] Gen4EncounterTypes = { 1, 2, 4, 5, 7, 9, 10, 12, 23, 24 }; - internal static readonly int Struggle = 165; - internal static readonly int Chatter = 448; + internal const int Struggle = 165; + internal const int Chatter = 448; internal static readonly int[] InvalidSketch = {Struggle, Chatter}; internal static readonly int[] EggLocations = {60002, 30002}; internal static readonly int[] LightBall = {25, 26, 172}; diff --git a/Legality/Tables4.cs b/Legality/Tables4.cs new file mode 100644 index 000000000..1500a39ab --- /dev/null +++ b/Legality/Tables4.cs @@ -0,0 +1,70 @@ +using System.Linq; + +namespace PKHeX +{ + public static partial class Legal + { + // PKHeX Valid Array Storage + #region DP + internal static readonly ushort[] Pouch_Items_DP = { + 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 135, 136, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, 323, 324, 325, 326, 327 + }; + internal static readonly ushort[] Pouch_Key_DP = { + 428, 429, 430, 431, 432, 433, 434, 435, 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, 446, 447, 448, 449, 450, 451, 452, 453, 454, 455, 456, 457, 458, 459, 460, 461, 462, 463, 464 + }; + internal static readonly ushort[] Pouch_TMHM_DP = { + 328, 329, 330, 331, 332, 333, 334, 335, 336, 337, 338, 339, 340, 341, 342, 343, 344, 345, 346, 347, 348, 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, 362, 363, 364, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, 381, 382, 383, 384, 385, 386, 387, 388, 389, 390, 391, 392, 393, 394, 395, 396, 397, 398, 399, 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, 420, 421, 422, 423, 424, 425, 426, 427 + }; + internal static readonly ushort[] Pouch_Mail_DP = { + 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148 + }; + internal static readonly ushort[] Pouch_Medicine_DP = { + 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54 + }; + internal static readonly ushort[] Pouch_Berries_DP = { + 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212 + }; + internal static readonly ushort[] Pouch_Ball_DP = { + 1, 2, 3, 4, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 + }; + internal static readonly ushort[] Pouch_Battle_DP = { + 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67 + }; + internal static readonly ushort[] HeldItems_DP = new ushort[1].Concat(Pouch_Items_DP).Concat(Pouch_Mail_DP).Concat(Pouch_Medicine_DP).Concat(Pouch_Berries_DP).Concat(Pouch_Ball_DP).ToArray(); + #endregion + + #region Pt + internal static readonly ushort[] Pouch_Items_Pt = { + 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 135, 136, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, 323, 324, 325, 326, 327 + }; + internal static readonly ushort[] Pouch_Key_Pt = { + 428, 429, 430, 431, 432, 433, 434, 435, 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, 446, 447, 448, 449, 450, 451, 452, 453, 454, 455, 456, 457, 458, 459, 460, 461, 462, 463, 464, 465, 466, 467 + }; + internal static readonly ushort[] Pouch_TMHM_Pt = Pouch_TMHM_DP; + internal static readonly ushort[] Pouch_Mail_Pt = Pouch_Mail_DP; + internal static readonly ushort[] Pouch_Medicine_Pt = Pouch_Medicine_DP; + internal static readonly ushort[] Pouch_Berries_Pt = Pouch_Berries_DP; + internal static readonly ushort[] Pouch_Ball_Pt = Pouch_Ball_DP; + internal static readonly ushort[] Pouch_Battle_Pt = Pouch_Battle_DP; + + internal static readonly ushort[] HeldItems_Pt = new ushort[1].Concat(Pouch_Items_Pt).Concat(Pouch_Mail_Pt).Concat(Pouch_Medicine_Pt).Concat(Pouch_Berries_Pt).Concat(Pouch_Ball_Pt).ToArray(); + #endregion + + #region HGSS + internal static readonly ushort[] Pouch_Items_HGSS = Pouch_Items_Pt; + internal static readonly ushort[] Pouch_Key_HGSS = { + 434, 435, 437, 444, 445, 446, 447, 450, 456, 464, 465, 466, 468, 469, 470, 471, 472, 473, 474, 475, 476, 477, 478, 479, 480, 481, 482, 483, 484, 501, 502, 503, 504, 532, 533, 534, 535, 536 + }; + internal static readonly ushort[] Pouch_TMHM_HGSS = Pouch_TMHM_DP; + internal static readonly ushort[] Pouch_Mail_HGSS = Pouch_Mail_DP; + internal static readonly ushort[] Pouch_Medicine_HGSS = Pouch_Medicine_DP; + internal static readonly ushort[] Pouch_Berries_HGSS = Pouch_Berries_DP; + internal static readonly ushort[] Pouch_Ball_HGSS = { + 1, 2, 3, 4, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 492, 493, 494, 495, 496, 497, 498, 499, 500 + }; + internal static readonly ushort[] Pouch_Battle_HGSS = Pouch_Battle_DP; + + internal static readonly ushort[] HeldItems_HGSS = new ushort[1].Concat(Pouch_Items_HGSS).Concat(Pouch_Mail_HGSS).Concat(Pouch_Medicine_HGSS).Concat(Pouch_Berries_HGSS).Concat(Pouch_Ball_Pt).ToArray(); + #endregion + } +} diff --git a/Legality/Tables5.cs b/Legality/Tables5.cs new file mode 100644 index 000000000..d6b09e99e --- /dev/null +++ b/Legality/Tables5.cs @@ -0,0 +1,29 @@ +using System.Linq; + +namespace PKHeX +{ + public static partial class Legal + { + // PKHeX Valid Array Storage + internal static readonly ushort[] Pouch_Items_BW = { + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 116, 117, 118, 119, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, 323, 324, 325, 326, 327, 492, 493, 494, 495, 496, 497, 498, 499, 500, 537, 538, 539, 540, 541, 542, 543, 544, 545, 546, 547, 548, 549, 550, 551, 552, 553, 554, 555, 556, 557, 558, 559, 560, 561, 562, 563, 564, 571, 572, 573, 575, 576, 577, 580, 581, 582, 583, 584, 585, 586, 587, 588, 589, 590, + }; + internal static readonly ushort[] Pouch_Key_BW = { + 437, 442, 447, 450, 465, 466, 471, 504, 533, 574, 578, 579, 616, 617, 621, 623, 624, 625, 626, + }; + internal static readonly ushort[] Pouch_TMHM_BW = { + 328, 329, 330, 331, 332, 333, 334, 335, 336, 337, 338, 339, 340, 341, 342, 343, 344, 345, 346, 347, 348, 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, 362, 363, 364, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, 381, 382, 383, 384, 385, 386, 387, 388, 389, 390, 391, 392, 393, 394, 395, 396, 397, 398, 399, 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, 618, 619, 620, 420, 421, 422, 423, 424, 425 + }; + internal static readonly ushort[] Pouch_Medicine_BW = { + 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 134, 504, 565, 566, 567, 568, 569, 570, 591 + }; + internal static readonly ushort[] Pouch_Berries_BW = { + 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212 + }; + internal static readonly ushort[] HeldItems_BW = new ushort[1].Concat(Pouch_Items_BW).Concat(Pouch_Medicine_BW).Concat(Pouch_Berries_BW).ToArray(); + + internal static readonly ushort[] Pouch_Key_B2W2 = { + 437, 442, 447, 450, 453, 458, 465, 466, 471, 504, 578, 616, 617, 621, 626, 627, 628, 630, 631, 632, 633, 634, 635, 636, 637, 638, + }; + } +} diff --git a/Misc/PGT.cs b/Misc/PGT.cs deleted file mode 100644 index 79ff137bc..000000000 --- a/Misc/PGT.cs +++ /dev/null @@ -1,142 +0,0 @@ -using System; - -namespace PKHeX -{ - public class PCD - { - internal const int Size = 0x358; // 856 - - public byte[] Data; - public PCD(byte[] data = null) - { - Data = data ?? new byte[Size]; - - byte[] giftData = new byte[PGT.Size]; - Array.Copy(Data, 0, giftData, 0, PGT.Size); - Gift = new PGT(giftData); - - Information = new byte[Data.Length - PGT.Size]; - Array.Copy(Data, PGT.Size, Information, 0, Information.Length); - } - public readonly PGT Gift; - - public readonly byte[] Information; - /* Big thanks to Grovyle91's Pokémon Mystery Gift Editor, from which the structure was referenced. - * http://projectpokemon.org/forums/member.php?829-Grovyle91 - * http://projectpokemon.org/forums/showthread.php?6524 - * See also: http://tccphreak.shiny-clique.net/debugger/pcdfiles.htm - */ - } - public class PGT - { - internal static int Size = 0x104; // 260 - - public byte[] Data; - public PGT(byte[] data = null) - { - Data = data ?? new byte[Size]; - byte[] ekdata = new byte[PK4.SIZE_PARTY]; - Array.Copy(Data, 8, ekdata, 0, ekdata.Length); - // Decrypt PK4 - PK = new PK4(PKM.decryptArray(ekdata)); - - Unknown = new byte[0x10]; - Array.Copy(Data, 0xF4, Unknown, 0, 0x10); - } - - public byte CardType { get { return Data[0]; } set { Data[0] = value; } } - // Unused 0x01 - public byte Slot { get { return Data[2]; } set { Data[2] = value; } } - public byte Detail { get { return Data[3]; } set { Data[3] = value; } } - public PK4 PK; - public byte[] Unknown; - - public bool IsPokémon { get { return CardType == 1; } set { if (value) CardType = 1; } } - public bool IsEgg { get { return CardType == 2; } set { if (value) CardType = 2; } } - public bool IsManaphyEgg { get { return CardType == 7; } set { if (value) CardType = 7; } } - public bool PokémonGift => IsPokémon || IsEgg || IsManaphyEgg; - - public PK4 convertToPK4(SAV6 SAV) - { - if (!PokémonGift) - return null; - - PK4 pk4 = new PK4(PK.Data); - if (!IsPokémon && Detail == 0) - { - pk4.OT_Name = "PKHeX"; - pk4.TID = 12345; - pk4.SID = 54321; - pk4.OT_Gender = (int)(Util.rnd32()%2); - } - if (IsManaphyEgg) - { - // Since none of this data is populated, fill in default info. - pk4.Species = 490; - // Level 1 Moves - pk4.Move1 = 294; - pk4.Move2 = 145; - pk4.Move3 = 346; - pk4.FatefulEncounter = true; - pk4.Ball = 4; - pk4.Version = 10; // Diamond - pk4.Language = 2; // English - pk4.Nickname = "MANAPHY"; - pk4.Egg_Location = 1; // Ranger (will be +3000 later) - } - - // Generate IV - uint seed = Util.rnd32(); - if (pk4.PID == 1) // Create Nonshiny - { - uint pid1 = PKM.LCRNG(ref seed) >> 16; - uint pid2 = PKM.LCRNG(ref seed) >> 16; - - while ((pid1 ^ pid2 ^ pk4.TID ^ pk4.SID) < 8) - { - uint testPID = pid1 | pid2 << 16; - - // Call the ARNG to change the PID - testPID = testPID * 0x6c078965 + 1; - - pid1 = testPID & 0xFFFF; - pid2 = testPID >> 16; - } - pk4.PID = pid1 | (pid2 << 16); - } - - // Generate IVs - if (pk4.IV32 == 0) - { - uint iv1 = PKM.LCRNG(ref seed) >> 16; - uint iv2 = PKM.LCRNG(ref seed) >> 16; - pk4.IV32 = (iv1 | iv2 << 16) & 0x3FFFFFFF; - } - - // Generate Met Info - DateTime dt = DateTime.Now; - if (IsPokémon) - { - pk4.Met_Location = pk4.Egg_Location + 3000; - pk4.Egg_Location = 0; - pk4.Met_Day = dt.Day; - pk4.Met_Month = dt.Month; - pk4.Met_Year = dt.Year - 2000; - pk4.IsEgg = false; - } - else - { - pk4.Egg_Location = pk4.Egg_Location + 3000; - pk4.Egg_Day = dt.Day; - pk4.Egg_Month = dt.Month; - pk4.Egg_Year = dt.Year - 2000; - pk4.IsEgg = false; - // Met Location is modified when transferred to pk5; don't worry about it. - } - if (pk4.Species == 201) // Never will be true; Unown was never distributed. - pk4.AltForm = PKM.getUnownForm(pk4.PID); - - return pk4; - } - } -} diff --git a/Misc/PK3.cs b/Misc/PK3.cs deleted file mode 100644 index 03fa7db7b..000000000 --- a/Misc/PK3.cs +++ /dev/null @@ -1,299 +0,0 @@ -using System; -using System.Linq; - -namespace PKHeX -{ - public class PK3 // 3rd Generation PKM File - { - internal const int SIZE_PARTY = 100; - internal const int SIZE_STORED = 80; - internal const int SIZE_BLOCK = 12; - - public PK3(byte[] decryptedData = null, string ident = null) - { - Data = (byte[])(decryptedData ?? new byte[SIZE_PARTY]).Clone(); - Identifier = ident; - if (Data.Length != SIZE_PARTY) - Array.Resize(ref Data, SIZE_PARTY); - } - - // Internal Attributes set on creation - public byte[] Data; // Raw Storage - public string Identifier; // User or Form Custom Attribute - - // 0x20 Intro - public uint PID { get { return BitConverter.ToUInt32(Data, 0x00); } set { BitConverter.GetBytes(value).CopyTo(Data, 0x00); } } - public uint EID { get { return BitConverter.ToUInt32(Data, 0x04); } set { BitConverter.GetBytes(value).CopyTo(Data, 0x04); } } - public ushort TID { get { return BitConverter.ToUInt16(Data, 0x04); } set { BitConverter.GetBytes(value).CopyTo(Data, 0x04); } } - public ushort SID { get { return BitConverter.ToUInt16(Data, 0x06); } set { BitConverter.GetBytes(value).CopyTo(Data, 0x06); } } - public string Nickname { - get { return PKM.getG3Str(Data.Skip(0x08).Take(10).ToArray(), Japanese); } - set { byte[] strdata = PKM.setG3Str(value, Japanese); - if (strdata.Length > 10) - Array.Resize(ref strdata, 10); - strdata.CopyTo(Data, 0x08); } } - public int Language { get { return BitConverter.ToUInt16(Data, 0x12); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x12); } } - public string OT_Name { - get { return PKM.getG3Str(Data.Skip(0x14).Take(7).ToArray(), Japanese); } - set { byte[] strdata = PKM.setG3Str(value, Japanese); - if (strdata.Length > 7) - Array.Resize(ref strdata, 7); - strdata.CopyTo(Data, 0x14); } } - private byte Markings { get { return Data[0x1B]; } set { Data[0x1B] = value; } } - public bool Circle { get { return (Markings & (1 << 0)) == 1 << 0; } set { Markings = (byte)(Markings & ~(1 << 0) | (value ? 1 << 0 : 0)); } } - public bool Square { get { return (Markings & (1 << 1)) == 1 << 1; } set { Markings = (byte)(Markings & ~(1 << 1) | (value ? 1 << 1 : 0)); } } - public bool Triangle { get { return (Markings & (1 << 2)) == 1 << 2; } set { Markings = (byte)(Markings & ~(1 << 2) | (value ? 1 << 2 : 0)); } } - public bool Heart { get { return (Markings & (1 << 3)) == 1 << 3; } set { Markings = (byte)(Markings & ~(1 << 3) | (value ? 1 << 3 : 0)); } } - public ushort Checksum { get { return BitConverter.ToUInt16(Data, 0x1C); } set { BitConverter.GetBytes(value).CopyTo(Data, 0x1C); } } - public ushort Sanity { get { return BitConverter.ToUInt16(Data, 0x1E); } set { BitConverter.GetBytes(value).CopyTo(Data, 0x1E); } } - - #region Block A - public int Species { get { return PKM.getG4Species(BitConverter.ToUInt16(Data, 0x20)); } set { BitConverter.GetBytes((ushort)PKM.getG3Species(value)).CopyTo(Data, 0x20); } } - public ushort HeldItem { get { return BitConverter.ToUInt16(Data, 0x22); } set { BitConverter.GetBytes(value).CopyTo(Data, 0x22); } } - public uint EXP { get { return BitConverter.ToUInt32(Data, 0x24); } set { BitConverter.GetBytes(value).CopyTo(Data, 0x24); } } - private byte PPUps { get { return Data[0x28]; } set { Data[0x28] = value; } } - public int Move1_PPUps { get { return (PPUps >> 0) & 3; } set { PPUps = (byte)((PPUps & ~(3 << 0)) | value); } } - public int Move2_PPUps { get { return (PPUps >> 2) & 3; } set { PPUps = (byte)((PPUps & ~(3 << 2)) | value); } } - public int Move3_PPUps { get { return (PPUps >> 4) & 3; } set { PPUps = (byte)((PPUps & ~(3 << 4)) | value); } } - public int Move4_PPUps { get { return (PPUps >> 6) & 3; } set { PPUps = (byte)((PPUps & ~(3 << 6)) | value); } } - public int Friendship { get { return Data[0x29]; } set { Data[0x29] = (byte)value; } } - // Unused 0x2A 0x2B - #endregion - - #region Block B - public int Move1 { get { return BitConverter.ToUInt16(Data, 0x2C); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x2C); } } - public int Move2 { get { return BitConverter.ToUInt16(Data, 0x2E); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x2E); } } - public int Move3 { get { return BitConverter.ToUInt16(Data, 0x30); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x30); } } - public int Move4 { get { return BitConverter.ToUInt16(Data, 0x32); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x32); } } - public int Move1_PP { get { return Data[0x34]; } set { Data[0x34] = (byte)value; } } - public int Move2_PP { get { return Data[0x35]; } set { Data[0x35] = (byte)value; } } - public int Move3_PP { get { return Data[0x36]; } set { Data[0x36] = (byte)value; } } - public int Move4_PP { get { return Data[0x37]; } set { Data[0x37] = (byte)value; } } - #endregion - - #region Block C - public int EV_HP { get { return Data[0x38]; } set { Data[0x38] = (byte)value; } } - public int EV_ATK { get { return Data[0x39]; } set { Data[0x39] = (byte)value; } } - public int EV_DEF { get { return Data[0x3A]; } set { Data[0x3A] = (byte)value; } } - public int EV_SPE { get { return Data[0x3B]; } set { Data[0x3B] = (byte)value; } } - public int EV_SPA { get { return Data[0x3C]; } set { Data[0x3C] = (byte)value; } } - public int EV_SPD { get { return Data[0x3D]; } set { Data[0x3D] = (byte)value; } } - public int CNT_Cool { get { return Data[0x3E]; } set { Data[0x3E] = (byte)value; } } - public int CNT_Beauty { get { return Data[0x3F]; } set { Data[0x3F] = (byte)value; } } - public int CNT_Cute { get { return Data[0x40]; } set { Data[0x40] = (byte)value; } } - public int CNT_Smart { get { return Data[0x41]; } set { Data[0x41] = (byte)value; } } - public int CNT_Tough { get { return Data[0x42]; } set { Data[0x42] = (byte)value; } } - public int CNT_Sheen { get { return Data[0x43]; } set { Data[0x43] = (byte)value; } } - #endregion - - #region Block D - private byte PKRS { get { return Data[0x44]; } set { Data[0x44] = value; } } - public int PKRS_Days { get { return PKRS & 0xF; } set { PKRS = (byte)(PKRS & ~0xF | value); } } - public int PKRS_Strain { get { return PKRS >> 4; } set { PKRS = (byte)(PKRS & 0xF | value << 4); } } - public int Met_Location { get { return Data[0x45]; } set { Data[0x45] = (byte)value; } } - // Origins - private ushort Origins { get { return BitConverter.ToUInt16(Data, 0x46); } set { BitConverter.GetBytes(value).CopyTo(Data, 0x46); } } - public int Version { get { return (Origins >> 7) & 0xF; } set { Origins = (ushort)((Origins & ~0x780) | ((value & 0xF) << 7));} } - public int Pokéball { get { return (Origins >> 11) & 0xF; } set { Origins = (ushort)((Origins & ~0x7800) | ((value & 0xF) << 11)); } } - public int OT_Gender { get { return (Origins >> 15) & 1; } set { Origins = (ushort)(Origins & ~(1 << 15) | ((value & 1) << 15)); } } - - public uint IV32 { get { return BitConverter.ToUInt32(Data, 0x48); } set { BitConverter.GetBytes(value).CopyTo(Data, 0x48); } } - public int IV_HP { get { return (int)(IV32 >> 00) & 0x1F; } set { IV32 = (uint)((IV32 & ~(0x1F << 00)) | (uint)((value > 31 ? 31 : value) << 00)); } } - public int IV_ATK { get { return (int)(IV32 >> 05) & 0x1F; } set { IV32 = (uint)((IV32 & ~(0x1F << 05)) | (uint)((value > 31 ? 31 : value) << 05)); } } - public int IV_DEF { get { return (int)(IV32 >> 10) & 0x1F; } set { IV32 = (uint)((IV32 & ~(0x1F << 10)) | (uint)((value > 31 ? 31 : value) << 10)); } } - public int IV_SPE { get { return (int)(IV32 >> 15) & 0x1F; } set { IV32 = (uint)((IV32 & ~(0x1F << 15)) | (uint)((value > 31 ? 31 : value) << 15)); } } - public int IV_SPA { get { return (int)(IV32 >> 20) & 0x1F; } set { IV32 = (uint)((IV32 & ~(0x1F << 20)) | (uint)((value > 31 ? 31 : value) << 20)); } } - public int IV_SPD { get { return (int)(IV32 >> 25) & 0x1F; } set { IV32 = (uint)((IV32 & ~(0x1F << 25)) | (uint)((value > 31 ? 31 : value) << 25)); } } - public bool IsEgg { get { return ((IV32 >> 30) & 1) == 1; } set { IV32 = (uint)((IV32 & ~0x40000000) | (uint)(value ? 0x40000000 : 0)); } } - public int Ability { get { return (int)((IV32 >> 31) & 1); } set { IV32 = (IV32 & 0x7FFFFFFF) | (value == 1 ? 0x80000000 : 0); } } - - private uint RIB0 { get { return BitConverter.ToUInt32(Data, 0x4C); } set { BitConverter.GetBytes(value).CopyTo(Data, 0x4C); } } - public int Cool_Ribbons { get { return (int)(RIB0 >> 00) & 7; } set { RIB0 = (uint)((RIB0 & ~(7 << 00)) | (uint)(value & 7)); } } - public int Beauty_Ribbons{ get { return (int)(RIB0 >> 03) & 7; } set { RIB0 = (uint)((RIB0 & ~(7 << 03)) | (uint)(value & 7)); } } - public int Cute_Ribbons { get { return (int)(RIB0 >> 06) & 7; } set { RIB0 = (uint)((RIB0 & ~(7 << 06)) | (uint)(value & 7)); } } - public int Smart_Ribbons { get { return (int)(RIB0 >> 09) & 3; } set { RIB0 = (uint)((RIB0 & ~(7 << 09)) | (uint)(value & 7)); } } - public int Tough_Ribbons { get { return (int)(RIB0 >> 12) & 3; } set { RIB0 = (uint)((RIB0 & ~(7 << 12)) | (uint)(value & 7)); } } - public bool Champion { get { return (RIB0 & (1 << 15)) == 1 << 15; } set { RIB0 = (uint)(RIB0 & ~(1 << 15) | (uint)(value ? 1 << 0 : 0)); } } - public bool Winning { get { return (RIB0 & (1 << 16)) == 1 << 16; } set { RIB0 = (uint)(RIB0 & ~(1 << 16) | (uint)(value ? 1 << 0 : 0)); } } - public bool Victory { get { return (RIB0 & (1 << 17)) == 1 << 17; } set { RIB0 = (uint)(RIB0 & ~(1 << 17) | (uint)(value ? 1 << 0 : 0)); } } - public bool Artist { get { return (RIB0 & (1 << 18)) == 1 << 18; } set { RIB0 = (uint)(RIB0 & ~(1 << 18) | (uint)(value ? 1 << 0 : 0)); } } - public bool Effort { get { return (RIB0 & (1 << 19)) == 1 << 19; } set { RIB0 = (uint)(RIB0 & ~(1 << 19) | (uint)(value ? 1 << 0 : 0)); } } - public bool Special1 { get { return (RIB0 & (1 << 20)) == 1 << 20; } set { RIB0 = (uint)(RIB0 & ~(1 << 20) | (uint)(value ? 1 << 0 : 0)); } } - public bool Special2 { get { return (RIB0 & (1 << 21)) == 1 << 21; } set { RIB0 = (uint)(RIB0 & ~(1 << 21) | (uint)(value ? 1 << 0 : 0)); } } - public bool Special3 { get { return (RIB0 & (1 << 22)) == 1 << 22; } set { RIB0 = (uint)(RIB0 & ~(1 << 22) | (uint)(value ? 1 << 0 : 0)); } } - public bool Special4 { get { return (RIB0 & (1 << 23)) == 1 << 23; } set { RIB0 = (uint)(RIB0 & ~(1 << 23) | (uint)(value ? 1 << 0 : 0)); } } - public bool Special5 { get { return (RIB0 & (1 << 24)) == 1 << 24; } set { RIB0 = (uint)(RIB0 & ~(1 << 24) | (uint)(value ? 1 << 0 : 0)); } } - public bool Special6 { get { return (RIB0 & (1 << 25)) == 1 << 25; } set { RIB0 = (uint)(RIB0 & ~(1 << 25) | (uint)(value ? 1 << 0 : 0)); } } - public bool Special7 { get { return (RIB0 & (1 << 26)) == 1 << 26; } set { RIB0 = (uint)(RIB0 & ~(1 << 26) | (uint)(value ? 1 << 0 : 0)); } } - public bool Unused1 { get { return (RIB0 & (1 << 27)) == 1 << 27; } set { RIB0 = (uint)(RIB0 & ~(1 << 27) | (uint)(value ? 1 << 0 : 0)); } } - public bool Unused2 { get { return (RIB0 & (1 << 28)) == 1 << 28; } set { RIB0 = (uint)(RIB0 & ~(1 << 28) | (uint)(value ? 1 << 0 : 0)); } } - public bool Unused3 { get { return (RIB0 & (1 << 29)) == 1 << 29; } set { RIB0 = (uint)(RIB0 & ~(1 << 29) | (uint)(value ? 1 << 0 : 0)); } } - public bool Unused4 { get { return (RIB0 & (1 << 30)) == 1 << 30; } set { RIB0 = (uint)(RIB0 & ~(1 << 30) | (uint)(value ? 1 << 0 : 0)); } } - public bool Obedience { get { return (RIB0 & (1 << 31)) == 1 << 31; } set { RIB0 = (RIB0 & ~(1 << 31)) | (uint)(value ? 1 << 0 : 0); } } - #endregion - - // Simple Generated Attributes - public bool Japanese => Language == 1; - public bool Gen3 => Version >= 1 && Version <= 5 || Version == 15; - - public int[] Moves - { - get { return new[] { Move1, Move2, Move3, Move4 }; } - set - { - if (value.Length > 0) Move1 = value[0]; - if (value.Length > 1) Move2 = value[1]; - if (value.Length > 2) Move3 = value[2]; - if (value.Length > 3) Move4 = value[3]; - } - } - - // Methods - public void FixMoves() - { - if (Move4 != 0 && Move3 == 0) - { - Move3 = Move4; - Move3_PP = Move4_PP; - Move3_PPUps = Move4_PPUps; - Move4 = Move4_PP = Move4_PPUps = 0; - } - if (Move3 != 0 && Move2 == 0) - { - Move2 = Move3; - Move2_PP = Move3_PP; - Move2_PPUps = Move3_PPUps; - Move3 = Move3_PP = Move3_PPUps = 0; - } - if (Move2 != 0 && Move1 == 0) - { - Move1 = Move2; - Move1_PP = Move2_PP; - Move1_PPUps = Move2_PPUps; - Move2 = Move2_PP = Move2_PPUps = 0; - } - } - - public PK4 convertToPK4() - { - DateTime moment = DateTime.Now; - PK4 pk4 = new PK4 // Convert away! - { - PID = PID, - Species = Species, - TID = TID, - SID = SID, - EXP = IsEgg ? PKX.getEXP(5, Species) : EXP, - IsEgg = false, - Friendship = 40, - Circle = Circle, - Square = Square, - Triangle = Triangle, - Heart = Heart, - Language = Language, - EV_HP = EV_HP, - EV_ATK = EV_ATK, - EV_DEF = EV_DEF, - EV_SPA = EV_SPA, - EV_SPD = EV_SPD, - EV_SPE = EV_SPE, - CNT_Cool = CNT_Cool, - CNT_Beauty = CNT_Beauty, - CNT_Cute = CNT_Cute, - CNT_Smart = CNT_Smart, - CNT_Tough = CNT_Tough, - CNT_Sheen = CNT_Sheen, - FatefulEncounter = Obedience, - Move1 = Move1, - Move2 = Move2, - Move3 = Move3, - Move4 = Move4, - Move1_PPUps = Move1_PPUps, - Move2_PPUps = Move2_PPUps, - Move3_PPUps = Move3_PPUps, - Move4_PPUps = Move4_PPUps, - Move1_PP = PKX.getMovePP(Move1, Move1_PPUps), - Move2_PP = PKX.getMovePP(Move2, Move2_PPUps), - Move3_PP = PKX.getMovePP(Move3, Move3_PPUps), - Move4_PP = PKX.getMovePP(Move4, Move4_PPUps), - IV_HP = IV_HP, - IV_ATK = IV_ATK, - IV_DEF = IV_DEF, - IV_SPA = IV_SPA, - IV_SPD = IV_SPD, - IV_SPE = IV_SPE, - Ability = PKM.Gen3Abilities[Species][Ability], - Version = Version, - Ball = Pokéball, - PKRS_Strain = PKRS_Strain, - PKRS_Days = PKRS_Days, - OT_Gender = OT_Gender, - Met_Year = moment.Year - 2000, - Met_Month = moment.Month, - Met_Day = moment.Day, - Met_Location = 0x37, // Pal Park - RIB6_4 = Champion, - RIB6_5 = Winning, - RIB6_6 = Victory, - RIB6_7 = Artist, - RIB7_0 = Effort, - RIB7_1 = Special1, // Battle Champion Ribbon - RIB7_2 = Special2, // Regional Champion Ribbon - RIB7_3 = Special3, // National Champion Ribbon - RIB7_4 = Special4, // Country Ribbon - RIB7_5 = Special5, // National Ribbon - RIB7_6 = Special6, // Earth Ribbon - RIB7_7 = Special7, // World Ribbon - }; - - // Remaining Ribbons - pk4.RIB4_0 |= Cool_Ribbons > 0; - pk4.RIB4_1 |= Cool_Ribbons > 1; - pk4.RIB4_2 |= Cool_Ribbons > 2; - pk4.RIB4_3 |= Cool_Ribbons > 3; - pk4.RIB4_4 |= Beauty_Ribbons > 0; - pk4.RIB4_5 |= Beauty_Ribbons > 1; - pk4.RIB4_6 |= Beauty_Ribbons > 2; - pk4.RIB4_7 |= Beauty_Ribbons > 3; - pk4.RIB5_0 |= Cute_Ribbons > 0; - pk4.RIB5_1 |= Cute_Ribbons > 1; - pk4.RIB5_2 |= Cute_Ribbons > 2; - pk4.RIB5_3 |= Cute_Ribbons > 3; - pk4.RIB5_4 |= Smart_Ribbons > 0; - pk4.RIB5_5 |= Smart_Ribbons > 1; - pk4.RIB5_6 |= Smart_Ribbons > 2; - pk4.RIB5_7 |= Smart_Ribbons > 3; - pk4.RIB6_0 |= Tough_Ribbons > 0; - pk4.RIB6_1 |= Tough_Ribbons > 1; - pk4.RIB6_2 |= Tough_Ribbons > 2; - pk4.RIB6_3 |= Tough_Ribbons > 3; - - // Yay for reusing string buffers! - PKM.G4TransferTrashBytes[pk4.Language].CopyTo(pk4.Data, 0x48 + 4); - pk4.Nickname = IsEgg ? PKM.getSpeciesName(pk4.Species, pk4.Language) : Nickname; - Array.Copy(pk4.Data, 0x48, pk4.Data, 0x68, 0x10); - pk4.OT_Name = OT_Name; - - // Set Final Data - pk4.Met_Level = PKX.getLevel(pk4.Species, pk4.EXP); - pk4.Gender = PKM.getGender(pk4.Species, pk4.PID); - pk4.IsNicknamed |= pk4.Nickname != PKM.getSpeciesName(pk4.Species, pk4.Language); - - // Unown Form - if (Species == 201) - pk4.AltForm = PKM.getUnownForm(PID); - - // Remove HM moves - int[] banned = { 15, 19, 57, 70, 148, 249, 127, 291 }; - int[] newMoves = pk4.Moves; - for (int i = 0; i < 4; i++) - if (banned.Contains(newMoves[i])) - newMoves[i] = 0; - pk4.Moves = newMoves; - pk4.FixMoves(); - - pk4.RefreshChecksum(); - return pk4; - } - } -} diff --git a/Misc/PKX.cs b/Misc/PKX.cs deleted file mode 100644 index 41c00d952..000000000 --- a/Misc/PKX.cs +++ /dev/null @@ -1,1518 +0,0 @@ -using System; -using System.Drawing; -using System.Drawing.Text; -using System.Linq; - -namespace PKHeX -{ - public class PKX - { - // C# PKX Function Library - // No WinForm object related code, only to calculate information. - // May require re-referencing to main form for string array referencing. - // Relies on Util for some common operations. - - // Data - internal static uint LCRNG(uint seed) - { - const uint a = 0x41C64E6D; - const uint c = 0x00006073; - - return seed * a + c; - } - internal static uint LCRNG(ref uint seed) - { - const uint a = 0x41C64E6D; - const uint c = 0x00006073; - - return seed = seed * a + c; - } - #region ExpTable - internal static readonly uint[,] ExpTable = - { - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {8, 15, 4, 9, 6, 10}, - {27, 52, 13, 57, 21, 33}, - {64, 122, 32, 96, 51, 80}, - {125, 237, 65, 135, 100, 156}, - {216, 406, 112, 179, 172, 270}, - {343, 637, 178, 236, 274, 428}, - {512, 942, 276, 314, 409, 640}, - {729, 1326, 393, 419, 583, 911}, - {1000, 1800, 540, 560, 800, 1250}, - {1331, 2369, 745, 742, 1064, 1663}, - {1728, 3041, 967, 973, 1382, 2160}, - {2197, 3822, 1230, 1261, 1757, 2746}, - {2744, 4719, 1591, 1612, 2195, 3430}, - {3375, 5737, 1957, 2035, 2700, 4218}, - {4096, 6881, 2457, 2535, 3276, 5120}, - {4913, 8155, 3046, 3120, 3930, 6141}, - {5832, 9564, 3732, 3798, 4665, 7290}, - {6859, 11111, 4526, 4575, 5487, 8573}, - {8000, 12800, 5440, 5460, 6400, 10000}, - {9261, 14632, 6482, 6458, 7408, 11576}, - {10648, 16610, 7666, 7577, 8518, 13310}, - {12167, 18737, 9003, 8825, 9733, 15208}, - {13824, 21012, 10506, 10208, 11059, 17280}, - {15625, 23437, 12187, 11735, 12500, 19531}, - {17576, 26012, 14060, 13411, 14060, 21970}, - {19683, 28737, 16140, 15244, 15746, 24603}, - {21952, 31610, 18439, 17242, 17561, 27440}, - {24389, 34632, 20974, 19411, 19511, 30486}, - {27000, 37800, 23760, 21760, 21600, 33750}, - {29791, 41111, 26811, 24294, 23832, 37238}, - {32768, 44564, 30146, 27021, 26214, 40960}, - {35937, 48155, 33780, 29949, 28749, 44921}, - {39304, 51881, 37731, 33084, 31443, 49130}, - {42875, 55737, 42017, 36435, 34300, 53593}, - {46656, 59719, 46656, 40007, 37324, 58320}, - {50653, 63822, 50653, 43808, 40522, 63316}, - {54872, 68041, 55969, 47846, 43897, 68590}, - {59319, 72369, 60505, 52127, 47455, 74148}, - {64000, 76800, 66560, 56660, 51200, 80000}, - {68921, 81326, 71677, 61450, 55136, 86151}, - {74088, 85942, 78533, 66505, 59270, 92610}, - {79507, 90637, 84277, 71833, 63605, 99383}, - {85184, 95406, 91998, 77440, 68147, 106480}, - {91125, 100237, 98415, 83335, 72900, 113906}, - {97336, 105122, 107069, 89523, 77868, 121670}, - {103823, 110052, 114205, 96012, 83058, 129778}, - {110592, 115015, 123863, 102810, 88473, 138240}, - {117649, 120001, 131766, 109923, 94119, 147061}, - {125000, 125000, 142500, 117360, 100000, 156250}, - {132651, 131324, 151222, 125126, 106120, 165813}, - {140608, 137795, 163105, 133229, 112486, 175760}, - {148877, 144410, 172697, 141677, 119101, 186096}, - {157464, 151165, 185807, 150476, 125971, 196830}, - {166375, 158056, 196322, 159635, 133100, 207968}, - {175616, 165079, 210739, 169159, 140492, 219520}, - {185193, 172229, 222231, 179056, 148154, 231491}, - {195112, 179503, 238036, 189334, 156089, 243890}, - {205379, 186894, 250562, 199999, 164303, 256723}, - {216000, 194400, 267840, 211060, 172800, 270000}, - {226981, 202013, 281456, 222522, 181584, 283726}, - {238328, 209728, 300293, 234393, 190662, 297910}, - {250047, 217540, 315059, 246681, 200037, 312558}, - {262144, 225443, 335544, 259392, 209715, 327680}, - {274625, 233431, 351520, 272535, 219700, 343281}, - {287496, 241496, 373744, 286115, 229996, 359370}, - {300763, 249633, 390991, 300140, 240610, 375953}, - {314432, 257834, 415050, 314618, 251545, 393040}, - {328509, 267406, 433631, 329555, 262807, 410636}, - {343000, 276458, 459620, 344960, 274400, 428750}, - {357911, 286328, 479600, 360838, 286328, 447388}, - {373248, 296358, 507617, 377197, 298598, 466560}, - {389017, 305767, 529063, 394045, 311213, 486271}, - {405224, 316074, 559209, 411388, 324179, 506530}, - {421875, 326531, 582187, 429235, 337500, 527343}, - {438976, 336255, 614566, 447591, 351180, 548720}, - {456533, 346965, 639146, 466464, 365226, 570666}, - {474552, 357812, 673863, 485862, 379641, 593190}, - {493039, 367807, 700115, 505791, 394431, 616298}, - {512000, 378880, 737280, 526260, 409600, 640000}, - {531441, 390077, 765275, 547274, 425152, 664301}, - {551368, 400293, 804997, 568841, 441094, 689210}, - {571787, 411686, 834809, 590969, 457429, 714733}, - {592704, 423190, 877201, 613664, 474163, 740880}, - {614125, 433572, 908905, 636935, 491300, 767656}, - {636056, 445239, 954084, 660787, 508844, 795070}, - {658503, 457001, 987754, 685228, 526802, 823128}, - {681472, 467489, 1035837, 710266, 545177, 851840}, - {704969, 479378, 1071552, 735907, 563975, 881211}, - {729000, 491346, 1122660, 762160, 583200, 911250}, - {753571, 501878, 1160499, 789030, 602856, 941963}, - {778688, 513934, 1214753, 816525, 622950, 973360}, - {804357, 526049, 1254796, 844653, 643485, 1005446}, - {830584, 536557, 1312322, 873420, 664467, 1038230}, - {857375, 548720, 1354652, 902835, 685900, 1071718}, - {884736, 560922, 1415577, 932903, 707788, 1105920}, - {912673, 571333, 1460276, 963632, 730138, 1140841}, - {941192, 583539, 1524731, 995030, 752953, 1176490}, - {970299, 591882, 1571884, 1027103, 776239, 1212873}, - {1000000, 600000, 1640000, 1059860, 800000, 1250000}, - }; - #endregion - - internal static readonly string[][] SpeciesLang = - { - Util.getStringList("species", "ja"), // none - Util.getStringList("species", "ja"), // 1 - Util.getStringList("species", "en"), // 2 - Util.getStringList("species", "fr"), // 3 - Util.getStringList("species", "it"), // 4 - Util.getStringList("species", "de"), // 5 - Util.getStringList("species", "es"), // none - Util.getStringList("species", "es"), // 7 - Util.getStringList("species", "ko"), // 8 - }; - - internal static string getSpeciesName(int species, int lang) - { - try { return SpeciesLang[lang][species]; } - catch { return ""; } - } - internal static readonly PersonalInfo[] Personal = Legal.PersonalAO; - - // Stat Fetching - internal static int getMovePP(int move, int ppup) - { - return getBasePP(move) * (5 + ppup) / 5; - } - internal static int getBasePP(int move) - { - byte[] movepptable = - { - 00, - 35, 25, 10, 15, 20, 20, 15, 15, 15, 35, 30, 05, 10, 20, 30, 35, 35, 20, 15, 20, - 20, 25, 20, 30, 05, 10, 15, 15, 15, 25, 20, 05, 35, 15, 20, 20, 10, 15, 30, 35, - 20, 20, 30, 25, 40, 20, 15, 20, 20, 20, 30, 25, 15, 30, 25, 05, 15, 10, 05, 20, - 20, 20, 05, 35, 20, 25, 20, 20, 20, 15, 25, 15, 10, 20, 25, 10, 35, 30, 15, 10, - 40, 10, 15, 30, 15, 20, 10, 15, 10, 05, 10, 10, 25, 10, 20, 40, 30, 30, 20, 20, - 15, 10, 40, 15, 10, 30, 10, 20, 10, 40, 40, 20, 30, 30, 20, 30, 10, 10, 20, 05, - 10, 30, 20, 20, 20, 05, 15, 10, 20, 10, 15, 35, 20, 15, 10, 10, 30, 15, 40, 20, - 15, 10, 05, 10, 30, 10, 15, 20, 15, 40, 20, 10, 05, 15, 10, 10, 10, 15, 30, 30, - 10, 10, 20, 10, 01, 01, 10, 25, 10, 05, 15, 25, 15, 10, 15, 30, 05, 40, 15, 10, - 25, 10, 30, 10, 20, 10, 10, 10, 10, 10, 20, 05, 40, 05, 05, 15, 05, 10, 05, 10, - 10, 10, 10, 20, 20, 40, 15, 10, 20, 20, 25, 05, 15, 10, 05, 20, 15, 20, 25, 20, - 05, 30, 05, 10, 20, 40, 05, 20, 40, 20, 15, 35, 10, 05, 05, 05, 15, 05, 20, 05, - 05, 15, 20, 10, 05, 05, 15, 10, 15, 15, 10, 10, 10, 20, 10, 10, 10, 10, 15, 15, - 15, 10, 20, 20, 10, 20, 20, 20, 20, 20, 10, 10, 10, 20, 20, 05, 15, 10, 10, 15, - 10, 20, 05, 05, 10, 10, 20, 05, 10, 20, 10, 20, 20, 20, 05, 05, 15, 20, 10, 15, - 20, 15, 10, 10, 15, 10, 05, 05, 10, 15, 10, 05, 20, 25, 05, 40, 15, 05, 40, 15, - 20, 20, 05, 15, 20, 20, 15, 15, 05, 10, 30, 20, 30, 15, 05, 40, 15, 05, 20, 05, - 15, 25, 25, 15, 20, 15, 20, 15, 20, 10, 20, 20, 05, 05, 10, 05, 40, 10, 10, 05, - 10, 10, 15, 10, 20, 15, 30, 10, 20, 05, 10, 10, 15, 10, 10, 05, 15, 05, 10, 10, - 30, 20, 20, 10, 10, 05, 05, 10, 05, 20, 10, 20, 10, 15, 10, 20, 20, 20, 15, 15, - 10, 15, 15, 15, 10, 10, 10, 20, 10, 30, 05, 10, 15, 10, 10, 05, 20, 30, 10, 30, - 15, 15, 15, 15, 30, 10, 20, 15, 10, 10, 20, 15, 05, 05, 15, 15, 05, 10, 05, 20, - 05, 15, 20, 05, 20, 20, 20, 20, 10, 20, 10, 15, 20, 15, 10, 10, 05, 10, 05, 05, - 10, 05, 05, 10, 05, 05, 05, 15, 10, 10, 10, 10, 10, 10, 15, 20, 15, 10, 15, 10, - 15, 10, 20, 10, 15, 10, 20, 20, 20, 20, 20, 15, 15, 15, 15, 15, 15, 20, 15, 10, - 15, 15, 15, 15, 10, 10, 10, 10, 10, 15, 15, 15, 15, 05, 05, 15, 05, 10, 10, 10, - 20, 20, 20, 10, 10, 30, 15, 15, 10, 15, 25, 10, 15, 10, 10, 10, 20, 10, 10, 10, - 10, 10, 15, 15, 05, 05, 10, 10, 10, 05, 05, 10, 05, 05, 15, 10, 05, 05, 05, 10, - 10, 10, 10, 20, 25, 10, 20, 30, 25, 20, 20, 15, 20, 15, 20, 20, 10, 10, 10, 10, - 10, 20, 10, 30, 15, 10, 10, 10, 20, 20, 05, 05, 05, 20, 10, 10, 20, 15, 20, 20, - 10, 20, 30, 10, 10, 40, 40, 30, 20, 40, 20, 20, 10, 10, 10, 10, 05, 10, 10, 05, - 05 - }; - if (move < 0) move = 0; - return movepptable[move]; - } - internal static byte[] getRandomEVs() - { - byte[] evs = new byte[6]; - do { - evs[0] = (byte)Math.Min(Util.rnd32() % 300, 252); // bias two to get maybe 252 - evs[1] = (byte)Math.Min(Util.rnd32() % 300, 252); - evs[2] = (byte)Math.Min(Util.rnd32() % (510 - evs[0] - evs[1]), 252); - evs[3] = (byte)Math.Min(Util.rnd32() % (510 - evs[0] - evs[1] - evs[2]), 252); - evs[4] = (byte)Math.Min(Util.rnd32() % (510 - evs[0] - evs[1] - evs[2] - evs[3]), 252); - evs[5] = (byte)Math.Min(510 - evs[0] - evs[1] - evs[2] - evs[3] - evs[4], 252); - } while (evs.Sum(b => b) > 510); // recalculate random EVs... - Util.Shuffle(evs); - return evs; - } - internal static byte getBaseFriendship(int species) - { - return Personal[species].BaseFriendship; - } - internal static int getLevel(int species, uint exp) - { - int growth = Personal[species].EXPGrowth; - int tl = 1; // Initial Level. Iterate upwards to find the level - while (ExpTable[++tl, growth] <= exp) - if (tl == 100) return 100; - return --tl; - } - internal static bool getIsShiny(uint PID, uint TID, uint SID) - { - uint PSV = getPSV(PID); - uint TSV = getTSV(TID, SID); - return TSV == PSV; - } - internal static uint getEXP(int level, int species) - { - if (level <= 1) return 0; - if (level > 100) level = 100; - return ExpTable[level, Personal[species].EXPGrowth]; - } - internal static byte[] getAbilities(int species, int formnum) - { - return Personal[Personal[species].FormeIndex(species, formnum)].Abilities; - } - internal static int getAbilityNumber(int species, int ability, int formnum) - { - byte[] spec_abilities = Personal[Personal[species].FormeIndex(species, formnum)].Abilities; - int abilval = Array.IndexOf(spec_abilities, (byte)ability); - if (abilval >= 0) - return 1 << abilval; - return -1; - } - internal static int getGender(string s) - { - if (s == null) - return -1; - if (s == "♂" || s == "M") - return 0; - if (s == "♀" || s == "F") - return 1; - return 2; - } - - internal static string[] getCountryRegionText(int country, int region, string lang) - { - // Get Language we're fetching for - int index = Array.IndexOf(new[] { "ja", "en", "fr", "de", "it", "es", "zh", "ko"}, lang); - // Return value storage - string[] data = new string[2]; // country, region - - // Get Country Text - try - { - string[] inputCSV = Util.getStringList("countries"); - // Set up our Temporary Storage - string[] unsortedList = new string[inputCSV.Length - 1]; - int[] indexes = new int[inputCSV.Length - 1]; - - // Gather our data from the input file - for (int i = 1; i < inputCSV.Length; i++) - { - string[] countryData = inputCSV[i].Split(','); - if (countryData.Length <= 1) continue; - indexes[i - 1] = Convert.ToInt32(countryData[0]); - unsortedList[i - 1] = countryData[index + 1]; - } - - int countrynum = Array.IndexOf(indexes, country); - data[0] = unsortedList[countrynum]; - } - catch { data[0] = "Illegal"; } - - // Get Region Text - try - { - string[] inputCSV = Util.getStringList("sr_" + country.ToString("000")); - // Set up our Temporary Storage - string[] unsortedList = new string[inputCSV.Length - 1]; - int[] indexes = new int[inputCSV.Length - 1]; - - // Gather our data from the input file - for (int i = 1; i < inputCSV.Length; i++) - { - string[] countryData = inputCSV[i].Split(','); - if (countryData.Length <= 1) continue; - indexes[i - 1] = Convert.ToInt32(countryData[0]); - unsortedList[i - 1] = countryData[index + 1]; - } - - int regionnum = Array.IndexOf(indexes, region); - data[1] = unsortedList[regionnum]; - } - catch { data[1] = "Illegal"; } - return data; - } - internal static string getLocation(bool eggmet, int gameorigin, int locval) - { - if (gameorigin < 13 && gameorigin > 6 && eggmet) - { - if (locval < 2000) return Main.metHGSS_00000[locval]; - if (locval < 3000) return Main.metHGSS_02000[locval % 2000]; - return Main.metHGSS_03000[locval % 3000]; - } - if (gameorigin < 24) - { - if (locval < 30000) return Main.metBW2_00000[locval]; - if (locval < 40000) return Main.metBW2_30000[locval % 10000 - 1]; - if (locval < 60000) return Main.metBW2_40000[locval % 10000 - 1]; - return Main.metBW2_60000[locval % 10000 - 1]; - } - if (gameorigin > 23) - { - if (locval < 30000) return Main.metXY_00000[locval]; - if (locval < 40000) return Main.metXY_30000[locval % 10000 - 1]; - if (locval < 60000) return Main.metXY_40000[locval % 10000 - 1]; - return Main.metXY_60000[locval % 10000 - 1]; - } - return null; // Shouldn't happen. - } - internal static string[] getQRText(PK6 pk6) - { - string[] response = new string[3]; - // Summarize - string filename = pk6.Nickname; - if (pk6.Nickname != Main.specieslist[pk6.Species] && Main.specieslist[pk6.Species] != null) - filename += $" ({Main.specieslist[pk6.Species]})"; - response[0] = $"{filename} [{Main.abilitylist[pk6.Ability]}] lv{pk6.Stat_Level} @ {Main.itemlist[pk6.HeldItem]} -- {Main.natures[pk6.Nature]}"; - response[1] = $"{Main.movelist[pk6.Move1]} / {Main.movelist[pk6.Move2]} / {Main.movelist[pk6.Move3]} / {Main.movelist[pk6.Move4]}"; - response[2] = string.Format( - "IVs:{0}{1}{2}{3}{4}{5}" - + Environment.NewLine + Environment.NewLine + - "EVs:{6}{7}{8}{9}{10}{11}", - Environment.NewLine + pk6.IV_HP.ToString("00"), - Environment.NewLine + pk6.IV_ATK.ToString("00"), - Environment.NewLine + pk6.IV_DEF.ToString("00"), - Environment.NewLine + pk6.IV_SPA.ToString("00"), - Environment.NewLine + pk6.IV_SPD.ToString("00"), - Environment.NewLine + pk6.IV_SPE.ToString("00"), - Environment.NewLine + pk6.EV_HP, - Environment.NewLine + pk6.EV_ATK, - Environment.NewLine + pk6.EV_DEF, - Environment.NewLine + pk6.EV_SPA, - Environment.NewLine + pk6.EV_SPD, - Environment.NewLine + pk6.EV_SPE); - - return response; - } - internal static string getFileName(PK6 pk6) - { - return - $"{pk6.Species.ToString("000")}{(pk6.IsShiny ? " ★" : "")} - {pk6.Nickname} - {pk6.Checksum.ToString("X4")}{pk6.EncryptionConstant.ToString("X8")}.pk6"; - } - internal static ushort[] getStats(PK6 pk6) - { - return getStats(pk6.Species, pk6.Stat_Level, pk6.Nature, pk6.AltForm, - pk6.EV_HP, pk6.EV_ATK, pk6.EV_DEF, pk6.EV_SPA, pk6.EV_SPD, pk6.EV_SPE, - pk6.IV_HP, pk6.IV_ATK, pk6.IV_DEF, pk6.IV_SPA, pk6.IV_SPD, pk6.IV_SPE); - } - internal static ushort[] getStats(int species, int level, int nature, int form, - int HP_EV, int ATK_EV, int DEF_EV, int SPA_EV, int SPD_EV, int SPE_EV, - int HP_IV, int ATK_IV, int DEF_IV, int SPA_IV, int SPD_IV, int SPE_IV) - { - PersonalInfo p = Personal[Personal[species].FormeIndex(species, form)]; - // Calculate Stats - ushort[] stats = new ushort[6]; // Stats are stored as ushorts in the PKX structure. We'll cap them as such. - stats[0] = (ushort)(p.HP == 1 ? 1 : (HP_IV + 2 * p.HP + HP_EV / 4 + 100) * level / 100 + 10); - stats[1] = (ushort)((ATK_IV + 2 * p.ATK + ATK_EV / 4) * level / 100 + 5); - stats[2] = (ushort)((DEF_IV + 2 * p.DEF + DEF_EV / 4) * level / 100 + 5); - stats[4] = (ushort)((SPA_IV + 2 * p.SPA + SPA_EV / 4) * level / 100 + 5); - stats[5] = (ushort)((SPD_IV + 2 * p.SPD + SPD_EV / 4) * level / 100 + 5); - stats[3] = (ushort)((SPE_IV + 2 * p.SPE + SPE_EV / 4) * level / 100 + 5); - - // Account for nature - int incr = nature / 5 + 1; - int decr = nature % 5 + 1; - if (incr == decr) return stats; // if neutral return stats without mod - stats[incr] *= 11; stats[incr] /= 10; - stats[decr] *= 9; stats[decr] /= 10; - - // Return Result - return stats; - } - - - // PKX Manipulation - internal static readonly byte[][] blockPosition = - { - new byte[] {0, 0, 0, 0, 0, 0, 1, 1, 2, 3, 2, 3, 1, 1, 2, 3, 2, 3, 1, 1, 2, 3, 2, 3}, - new byte[] {1, 1, 2, 3, 2, 3, 0, 0, 0, 0, 0, 0, 2, 3, 1, 1, 3, 2, 2, 3, 1, 1, 3, 2}, - new byte[] {2, 3, 1, 1, 3, 2, 2, 3, 1, 1, 3, 2, 0, 0, 0, 0, 0, 0, 3, 2, 3, 2, 1, 1}, - new byte[] {3, 2, 3, 2, 1, 1, 3, 2, 3, 2, 1, 1, 3, 2, 3, 2, 1, 1, 0, 0, 0, 0, 0, 0}, - }; - internal static readonly byte[] blockPositionInvert = - { - 0, 1, 2, 4, 3, 5, 6, 7, 12, 18, 13, 19, 8, 10, 14, 20, 16, 22, 9, 11, 15, 21, 17, 23 - }; - internal static byte[] shuffleArray(byte[] data, uint sv) - { - byte[] sdata = new byte[data.Length]; - Array.Copy(data, sdata, 8); // Copy unshuffled bytes - - // Shuffle Away! - for (int block = 0; block < 4; block++) - Array.Copy(data, 8 + 56*blockPosition[block][sv], sdata, 8 + 56*block, 56); - - // Fill the Battle Stats back - if (data.Length > 232) - Array.Copy(data, 232, sdata, 232, 28); - - return sdata; - } - internal static byte[] decryptArray(byte[] ekx) - { - byte[] pkx = (byte[])ekx.Clone(); - - uint pv = BitConverter.ToUInt32(pkx, 0); - uint sv = (pv >> 0xD & 0x1F) % 24; - - uint seed = pv; - - // Decrypt Blocks with RNG Seed - for (int i = 8; i < 232; i += 2) - BitConverter.GetBytes((ushort)(BitConverter.ToUInt16(pkx, i) ^ LCRNG(ref seed) >> 16)).CopyTo(pkx, i); - - // Deshuffle - pkx = shuffleArray(pkx, sv); - - // Decrypt the Party Stats - seed = pv; - if (pkx.Length <= 232) return pkx; - for (int i = 232; i < 260; i += 2) - BitConverter.GetBytes((ushort)(BitConverter.ToUInt16(pkx, i) ^ LCRNG(ref seed) >> 16)).CopyTo(pkx, i); - - return pkx; - } - internal static byte[] encryptArray(byte[] pkx) - { - // Shuffle - uint pv = BitConverter.ToUInt32(pkx, 0); - uint sv = (pv >> 0xD & 0x1F) % 24; - - byte[] ekx = (byte[])pkx.Clone(); - - ekx = shuffleArray(ekx, blockPositionInvert[sv]); - - uint seed = pv; - - // Encrypt Blocks with RNG Seed - for (int i = 8; i < 232; i += 2) - BitConverter.GetBytes((ushort)(BitConverter.ToUInt16(ekx, i) ^ LCRNG(ref seed) >> 16)).CopyTo(ekx, i); - - // If no party stats, return. - if (ekx.Length <= 232) return ekx; - - // Encrypt the Party Stats - seed = pv; - for (int i = 232; i < 260; i += 2) - BitConverter.GetBytes((ushort)(BitConverter.ToUInt16(ekx, i) ^ LCRNG(ref seed) >> 16)).CopyTo(ekx, i); - - // Done - return ekx; - } - internal static ushort getCHK(byte[] data) - { - ushort chk = 0; - for (int i = 8; i < 232; i += 2) // Loop through the entire PKX - chk += BitConverter.ToUInt16(data, i); - - return chk; - } - internal static bool verifychk(byte[] input) - { - ushort checksum = 0; - if (input.Length == 100 || input.Length == 80) // Gen 3 Files - { - for (int i = 32; i < 80; i += 2) - checksum += BitConverter.ToUInt16(input, i); - - return checksum == BitConverter.ToUInt16(input, 28); - } - - if (input.Length == 236 || input.Length == 220 || input.Length == 136) // Gen 4/5 - Array.Resize(ref input, 136); - else if (input.Length == 232 || input.Length == 260) // Gen 6 - Array.Resize(ref input, 232); - else throw new ArgumentException("Wrong sized input array to verifychecksum"); - - ushort chk = 0; - for (int i = 8; i < input.Length; i += 2) - chk += BitConverter.ToUInt16(input, i); - - return chk == BitConverter.ToUInt16(input, 0x6); - } - - internal static uint getPSV(uint PID) - { - return (PID >> 16 ^ PID & 0xFFFF) >> 4; - } - internal static uint getTSV(uint TID, uint SID) - { - return (TID ^ SID) >> 4; - } - internal static uint getRandomPID(int species, int cg, int origin, int nature, int form) - { - int gt = Personal[species].Gender; - if (origin >= 24) - return Util.rnd32(); - - bool g3unown = origin <= 5 && species == 201; - while (true) // Loop until we find a suitable PID - { - uint pid = Util.rnd32(); - - // Gen 3/4: Nature derived from PID - if (origin <= 15 && pid%25 != nature) - continue; - - // Gen 3 Unown: Letter/form derived from PID - if (g3unown) - { - uint pidLetter = ((pid & 0x3000000) >> 18 | (pid & 0x30000) >> 12 | (pid & 0x300) >> 6 | pid & 0x3) % 28; - if (pidLetter != form) - continue; - } - - // Gen 3/4/5: Gender derived from PID - uint gv = pid & 0xFF; - if (gt == 255 || gt == 254 || gt == 0) // Set Gender(less) - return pid; // PID can be anything - if (cg == 1 && gv <= gt) // Female - return pid; // PID Passes - if (cg == 0 && gv > gt) // Male - return pid; // PID Passes - } - } - - // SAV Manipulation - /// Calculates the CRC16-CCITT checksum over an input byte array. - /// Input byte array - /// Checksum - internal static ushort ccitt16(byte[] data) - { - const ushort init = 0xFFFF; - const ushort poly = 0x1021; - - ushort crc = init; - foreach (byte b in data) - { - crc ^= (ushort)(b << 8); - for (int j = 0; j < 8; j++) - { - bool flag = (crc & 0x8000) > 0; - crc <<= 1; - if (flag) - crc ^= poly; - } - } - return crc; - } - /// Simple check to see if the save is valid. - /// Input binary file - /// True/False - internal static bool verifyG6SAV(byte[] savefile) - { - // Dynamic handling of checksums regardless of save size. - - int verificationOffset = savefile.Length - 0x200 + 0x10; - if (BitConverter.ToUInt32(savefile, verificationOffset) != SAV6.BEEF) - verificationOffset -= 0x200; // No savegames have more than 0x3D blocks, maybe in the future? - - int count = (savefile.Length - verificationOffset - 0x8) / 8; - verificationOffset += 4; - int[] Lengths = new int[count]; - ushort[] BlockIDs = new ushort[count]; - ushort[] Checksums = new ushort[count]; - int[] Start = new int[count]; - int CurrentPosition = 0; - for (int i = 0; i < count; i++) - { - Start[i] = CurrentPosition; - Lengths[i] = BitConverter.ToInt32(savefile, verificationOffset + 0 + 8 * i); - BlockIDs[i] = BitConverter.ToUInt16(savefile, verificationOffset + 4 + 8 * i); - Checksums[i] = BitConverter.ToUInt16(savefile, verificationOffset + 6 + 8 * i); - - CurrentPosition += Lengths[i] % 0x200 == 0 ? Lengths[i] : 0x200 - Lengths[i] % 0x200 + Lengths[i]; - - if ((BlockIDs[i] != 0) || i == 0) continue; - count = i; - break; - } - // Verify checksums - for (int i = 0; i < count; i++) - { - ushort chk = ccitt16(savefile.Skip(Start[i]).Take(Lengths[i]).ToArray()); - ushort old = BitConverter.ToUInt16(savefile, verificationOffset + 6 + i * 8); - - if (chk != old) - return false; - } - return true; - } - /// Verbose check to see if the save is valid. - /// Input binary file - /// String containing invalid blocks. - internal static string verifyG6CHK(byte[] savefile) - { - string rv = ""; - int invalid = 0; - // Dynamic handling of checksums regardless of save size. - - int verificationOffset = savefile.Length - 0x200 + 0x10; - if (BitConverter.ToUInt32(savefile, verificationOffset) != SAV6.BEEF) - verificationOffset -= 0x200; // No savegames have more than 0x3D blocks, maybe in the future? - - int count = (savefile.Length - verificationOffset - 0x8) / 8; - verificationOffset += 4; - int[] Lengths = new int[count]; - ushort[] BlockIDs = new ushort[count]; - ushort[] Checksums = new ushort[count]; - int[] Start = new int[count]; - int CurrentPosition = 0; - for (int i = 0; i < count; i++) - { - Start[i] = CurrentPosition; - Lengths[i] = BitConverter.ToInt32(savefile, verificationOffset + 0 + 8 * i); - BlockIDs[i] = BitConverter.ToUInt16(savefile, verificationOffset + 4 + 8 * i); - Checksums[i] = BitConverter.ToUInt16(savefile, verificationOffset + 6 + 8 * i); - - CurrentPosition += Lengths[i] % 0x200 == 0 ? Lengths[i] : 0x200 - Lengths[i] % 0x200 + Lengths[i]; - - if (BlockIDs[i] != 0 || i == 0) continue; - count = i; - break; - } - // Apply checksums - for (int i = 0; i < count; i++) - { - ushort chk = ccitt16(savefile.Skip(Start[i]).Take(Lengths[i]).ToArray()); - ushort old = BitConverter.ToUInt16(savefile, verificationOffset + 6 + i * 8); - - if (chk == old) continue; - - invalid++; - rv += $"Invalid: {i.ToString("X2")} @ Region {Start[i].ToString("X5") + Environment.NewLine}"; - } - // Return Outputs - rv += $"SAV: {count - invalid}/{count + Environment.NewLine}"; - return rv; - } - /// Fix checksums in the input save file. - /// Input binary file - /// Fixed save file. - internal static void writeG6CHK(byte[] savefile) - { - // Dynamic handling of checksums regardless of save size. - - int verificationOffset = savefile.Length - 0x200 + 0x10; - if (BitConverter.ToUInt32(savefile, verificationOffset) != SAV6.BEEF) - verificationOffset -= 0x200; // No savegames have more than 0x3D blocks, maybe in the future? - - int count = (savefile.Length - verificationOffset - 0x8) / 8; - verificationOffset += 4; - int[] Lengths = new int[count]; - ushort[] BlockIDs = new ushort[count]; - ushort[] Checksums = new ushort[count]; - int[] Start = new int[count]; - int CurrentPosition = 0; - for (int i = 0; i < count; i++) - { - Start[i] = CurrentPosition; - Lengths[i] = BitConverter.ToInt32(savefile, verificationOffset + 0 + 8 * i); - BlockIDs[i] = BitConverter.ToUInt16(savefile, verificationOffset + 4 + 8 * i); - Checksums[i] = BitConverter.ToUInt16(savefile, verificationOffset + 6 + 8 * i); - - CurrentPosition += Lengths[i]%0x200 == 0 ? Lengths[i] : 0x200 - Lengths[i]%0x200 + Lengths[i]; - - if (BlockIDs[i] != 0 || i == 0) continue; - count = i; - break; - } - // Apply checksums - for (int i = 0; i < count; i++) - { - byte[] array = savefile.Skip(Start[i]).Take(Lengths[i]).ToArray(); - BitConverter.GetBytes(ccitt16(array)).CopyTo(savefile, verificationOffset + 6 + i * 8); - } - } - - // Data Requests - internal static Image getSprite(int species, int form, int gender, int item, bool isegg, bool shiny) - { - if (species == 0) - return (Image)Properties.Resources.ResourceManager.GetObject("_0"); - if (new[] { 664, 665, 414, 493 }.Contains(species)) // Species who show their default sprite regardless of Form - form = 0; - - string file = "_" + species; - if (form > 0) // Alt Form Handling - file = file + "_" + form; - else if (gender == 1 && new[] { 592, 593, 521, 668 }.Contains(species)) // Frillish & Jellicent, Unfezant & Pyroar - file = file + "_" + gender; - - // Redrawing logic - Image baseImage = (Image)Properties.Resources.ResourceManager.GetObject(file); - if (baseImage == null) - { - if (species < 722) - { - baseImage = Util.LayerImage( - (Image)Properties.Resources.ResourceManager.GetObject("_" + species), - Properties.Resources.unknown, - 0, 0, .5); - } - else - baseImage = Properties.Resources.unknown; - } - if (isegg) - { - // Start with a partially transparent species by layering the species with partial opacity onto a blank image. - baseImage = Util.LayerImage((Image)Properties.Resources.ResourceManager.GetObject("_0"), baseImage, 0, 0, 0.33); - // Add the egg layer over-top with full opacity. - baseImage = Util.LayerImage(baseImage, (Image)Properties.Resources.ResourceManager.GetObject("egg"), 0, 0, 1); - } - if (shiny) - { - // Add shiny star to top left of image. - baseImage = Util.LayerImage(baseImage, Properties.Resources.rare_icon, 0, 0, 0.7); - } - if (item > 0) - { - Image itemimg = (Image)Properties.Resources.ResourceManager.GetObject("item_" + item) ?? Properties.Resources.helditem; - // Redraw - baseImage = Util.LayerImage(baseImage, itemimg, 22 + (15 - itemimg.Width) / 2, 15 + (15 - itemimg.Height), 1); - } - return baseImage; - } - internal static Image getSprite(PK6 pk6) - { - return getSprite(pk6.Species, pk6.AltForm, pk6.Gender, pk6.HeldItem, pk6.IsEgg, pk6.IsShiny); - } - internal static Image getSprite(byte[] data) - { - return new PK6(data).Sprite; - } - - // Font Related - [System.Runtime.InteropServices.DllImport("gdi32.dll")] - internal static extern IntPtr AddFontMemResourceEx(IntPtr pbFont, uint cbFont, IntPtr pdv, [System.Runtime.InteropServices.In] ref uint pcFonts); - internal static readonly PrivateFontCollection s_FontCollection = new PrivateFontCollection(); - internal static FontFamily[] FontFamilies - { - get - { - if (s_FontCollection.Families.Length == 0) setPKXFont(); - return s_FontCollection.Families; - } - } - internal static Font getPKXFont(float size) - { - return new Font(FontFamilies[0], size); - } - internal static void setPKXFont() - { - try - { - byte[] fontData = Properties.Resources.pgldings_normalregular; - IntPtr fontPtr = System.Runtime.InteropServices.Marshal.AllocCoTaskMem(fontData.Length); - System.Runtime.InteropServices.Marshal.Copy(fontData, 0, fontPtr, fontData.Length); - s_FontCollection.AddMemoryFont(fontPtr, Properties.Resources.pgldings_normalregular.Length); uint dummy = 0; - AddFontMemResourceEx(fontPtr, (uint)Properties.Resources.pgldings_normalregular.Length, IntPtr.Zero, ref dummy); - System.Runtime.InteropServices.Marshal.FreeCoTaskMem(fontPtr); - } - catch { Util.Error("Unable to add ingame font."); } - } - - // Personal.dat - internal static string[] getFormList(int species, string[] t, string[] f, string[] g) - { - // Mega List - if (Array.IndexOf(new[] - { // XY - 003, 009, 065, 094, 115, 127, 130, 142, 181, 212, 214, 229, 248, 257, 282, 303, 306, 308, 310, 354, 359, 380, 381, 445, 448, 460, - // ORAS - 015, 018, 080, 208, 254, 260, 302, 319, 323, 334, 362, 373, 376, 384, 428, 475, 531, 719, - }, species) > -1) { // ... - return new[] - { - t[000], // Normal - f[723], // Mega - };} - // MegaXY List - switch (species) - { - case 6: - case 150: - return new[] - { - t[000], // Normal - f[724], // Mega X - f[725], // Mega Y - }; - case 025: - return new[] - { - t[000], // Normal - f[729], // Rockstar - f[730], // Belle - f[731], // Pop - f[732], // PhD - f[733], // Libre - f[734], // Cosplay - }; - case 201: - return new[] - { - "A", "B", "C", "D", "E", - "F", "G", "H", "I", "J", - "K", "L", "M", "N", "O", - "P", "Q", "R", "S", "T", - "U", "V", "W", "X", "Y", - "Z", - "!", "?", - }; - case 351: - return new[] - { - t[000], // Normal - f[789], // Sunny - f[790], // Rainy - f[791], // Snowy - }; - case 382: - case 383: - return new[] - { - t[000], // Normal - f[800], // Primal - }; - case 386: - return new[] - { - t[000], // Normal - f[802], // Attack - f[803], // Defense - f[804], // Speed - }; - - case 412: - case 413: - case 414: - return new[] - { - f[412], // Plant - f[805], // Sandy - f[806], // Trash - }; - - case 421: - return new[] - { - f[421], // Overcast - f[809], // Sunshine - }; - - case 422: - case 423: - return new[] - { - f[422], // West - f[811], // East - }; - - case 479: - return new[] - { - t[000], // Normal - f[817], // Heat - f[818], // Wash - f[819], // Frost - f[820], // Fan - f[821], // Mow - }; - - case 487: - return new[] - { - f[487], // Altered - f[822], // Origin - }; - - case 492: - return new[] - { - f[492], // Land - f[823], // Sky - }; - - case 493: - return new[] - { - t[00], // Normal - t[01], // Fighting - t[02], // Flying - t[03], // Poison - t[04], // etc - t[05], - t[06], - t[07], - t[08], - t[09], - t[10], - t[11], - t[12], - t[13], - t[14], - t[15], - t[16], - t[17], - }; - - case 550: - return new[] - { - f[550], // Red - f[842], // Blue - }; - - case 555: - return new[] - { - f[555], // Standard - f[843], // Zen - }; - - case 585: - case 586: - return new[] - { - f[585], // Spring - f[844], // Summer - f[845], // Autumn - f[846], // Winter - }; - - case 641: - case 642: - case 645: - return new[] - { - f[641], // Incarnate - f[852], // Therian - }; - - case 646: - return new[] - { - t[000], // Normal - f[853], // White - f[854], // Black - }; - - case 647: - return new[] - { - f[647], // Ordinary - f[855], // Resolute - }; - - case 648: - return new[] - { - f[648], // Aria - f[856], // Pirouette - }; - - case 649: - return new[] - { - t[000], // Normal - t[010], // Douse - t[012], // Shock - t[009], // Burn - t[014], // Chill - }; - - case 664: - case 665: - case 666: - return new[] - { - f[666], // Icy Snow - f[861], // Polar - f[862], // Tundra - f[863], // Continental - f[864], // Garden - f[865], // Elegant - f[866], // Meadow - f[867], // Modern - f[868], // Marine - f[869], // Archipelago - f[870], // High-Plains - f[871], // Sandstorm - f[872], // River - f[873], // Monsoon - f[874], // Savannah - f[875], // Sun - f[876], // Ocean - f[877], // Jungle - f[878], // Fancy - f[879], // Poké Ball - }; - - case 669: - case 671: - return new[] - { - f[669], // Red - f[884], // Yellow - f[885], // Orange - f[886], // Blue - f[887], // White - }; - - case 670: - return new[] - { - f[669], // Red - f[884], // Yellow - f[885], // Orange - f[886], // Blue - f[887], // White - f[888], // Eternal - }; - - case 676: - return new[] - { - f[676], // Natural - f[893], // Heart - f[894], // Star - f[895], // Diamond - f[896], // Deputante - f[897], // Matron - f[898], // Dandy - f[899], // La Reine - f[900], // Kabuki - f[901], // Pharaoh - }; - - case 678: - return new[] - { - g[000], // Male - g[001], // Female - }; - - case 681: - return new[] - { - f[681], // Shield - f[903], // Blade - }; - - case 710: - case 711: - return new[] - { - f[904], // Small - f[710], // Average - f[905], // Large - f[906], // Super - }; - - case 716: - return new[] - { - t[000], // Normal - f[910], // Active - }; - - case 720: - return new[] - { - t[000], // Normal - f[912], // Unbound - }; - } - return new[] {""}; - } - internal static int getDexFormIndexXY(int species, int formct) - { - if (formct < 1 || species < 0) - return -1; // invalid - switch (species) - { - case 201: return 000; // 28 Unown - case 386: return 028; // 4 Deoxys - case 492: return 032; // 2 Shaymin - case 487: return 034; // 2 Giratina - case 479: return 036; // 6 Rotom - case 422: return 042; // 2 Shellos - case 423: return 044; // 2 Gastrodon - case 412: return 046; // 3 Burmy - case 413: return 049; // 3 Wormadam - case 351: return 052; // 4 Castform - case 421: return 056; // 2 Cherrim - case 585: return 058; // 4 Deerling - case 586: return 062; // 4 Sawsbuck - case 648: return 066; // 2 Meloetta - case 555: return 068; // 2 Darmanitan - case 550: return 070; // 2 Basculin - case 646: return 072; // 3 Kyurem - case 647: return 075; // 2 Keldeo - case 642: return 077; // 2 Thundurus - case 641: return 079; // 2 Tornadus - case 645: return 081; // 2 Landorus - case 666: return 083; // 20 Vivillion - case 669: return 103; // 5 Flabébé - case 670: return 108; // 6 Floette - case 671: return 114; // 5 Florges - case 710: return 119; // 4 Pumpkaboo - case 711: return 123; // 4 Gourgeist - case 681: return 127; // 2 Aegislash - case 716: return 129; // 2 Xerneas - case 003: return 131; // 2 Venusaur - case 006: return 133; // 3 Charizard - case 009: return 136; // 2 Blastoise - case 065: return 138; // 2 Alakazam - case 094: return 140; // 2 Gengar - case 115: return 142; // 2 Kangaskhan - case 127: return 144; // 2 Pinsir - case 130: return 146; // 2 Gyarados - case 142: return 148; // 2 Aerodactyl - case 150: return 150; // 3 Mewtwo - case 181: return 153; // 2 Ampharos - case 212: return 155; // 2 Scizor - case 214: return 157; // 2 Heracros - case 229: return 159; // 2 Houndoom - case 248: return 161; // 2 Tyranitar - case 257: return 163; // 2 Blaziken - case 282: return 165; // 2 Gardevoir - case 303: return 167; // 2 Mawile - case 306: return 169; // 2 Aggron - case 308: return 171; // 2 Medicham - case 310: return 173; // 2 Manetric - case 354: return 175; // 2 Banette - case 359: return 177; // 2 Absol - case 380: return 179; // 2 Latias - case 381: return 181; // 2 Latios - case 445: return 183; // 2 Garchomp - case 448: return 185; // 2 Lucario - case 460: return 187; // 2 Abomasnow - default: return -1; - } - } - internal static int getDexFormIndexORAS(int species, int formct) - { - if (formct < 1 || species < 0) - return -1; // invalid - switch (species) - { - case 025: return 189; // 7 Pikachu - case 720: return 196; // 2 Hoopa - case 015: return 198; // 2 Beedrill - case 018: return 200; // 2 Pidgeot - case 080: return 202; // 2 Slowbro - case 208: return 204; // 2 Steelix - case 254: return 206; // 2 Sceptile - case 360: return 208; // 2 Swampert - case 302: return 210; // 2 Sableye - case 319: return 212; // 2 Sharpedo - case 323: return 214; // 2 Camerupt - case 334: return 216; // 2 Altaria - case 362: return 218; // 2 Glalie - case 373: return 220; // 2 Salamence - case 376: return 222; // 2 Metagross - case 384: return 224; // 2 Rayquaza - case 428: return 226; // 2 Lopunny - case 475: return 228; // 2 Gallade - case 531: return 230; // 2 Audino - case 719: return 232; // 2 Diancie - case 382: return 234; // 2 Kyogre - case 383: return 236; // 2 Groudon - case 493: return 238; // 18 Arceus - case 649: return 256; // 5 Genesect - case 676: return 261; // 10 Furfrou - default: return getDexFormIndexXY(species, formct); - } - } - - /// Calculate the Hidden Power Type of the entered IVs. - /// Order: HP,ATK,DEF,SPEED,SPA,SPD - /// Hidden Power Type - internal static int getHPType(int[] ivs) - { - return 15 * ((ivs[0] & 1) + 2 * (ivs[1] & 1) + 4 * (ivs[2] & 1) + 8 * (ivs[3] & 1) + 16 * (ivs[4] & 1) + 32 * (ivs[5] & 1)) / 63; - } - internal static int[] setHPIVs(int type, int[] ivs) - { - for (int i = 0; i < 6; i++) - ivs[i] = (ivs[i] & 0x1E) + hpivs[type, i]; - return ivs; - } - internal static readonly int[,] hpivs = { - { 1, 1, 0, 0, 0, 0 }, // Fighting - { 0, 0, 0, 0, 0, 1 }, // Flying - { 1, 1, 0, 0, 0, 1 }, // Poison - { 1, 1, 1, 0, 0, 1 }, // Ground - { 1, 1, 0, 1, 0, 0 }, // Rock - { 1, 0, 0, 1, 0, 1 }, // Bug - { 1, 0, 1, 1, 0, 1 }, // Ghost - { 1, 1, 1, 1, 0, 1 }, // Steel - { 1, 0, 1, 0, 1, 0 }, // Fire - { 1, 0, 0, 0, 1, 1 }, // Water - { 1, 0, 1, 0, 1, 1 }, // Grass - { 1, 1, 1, 0, 1, 1 }, // Electric - { 1, 0, 1, 1, 1, 0 }, // Psychic - { 1, 0, 0, 1, 1, 1 }, // Ice - { 1, 0, 1, 1, 1, 1 }, // Dragon - { 1, 1, 1, 1, 1, 1 }, // Dark - }; - - internal static readonly string[] StatNames = { "HP", "Atk", "Def", "SpA", "SpD", "Spe" }; - public class ShowdownSet - { - // String to Values - public static readonly string[] types = Util.getStringList("types", "en"); - public static readonly string[] forms = Util.getStringList("forms", "en"); - private static readonly string[] species = Util.getStringList("species", "en"); - private static readonly string[] items = Util.getStringList("items", "en"); - private static readonly string[] natures = Util.getStringList("natures", "en"); - private static readonly string[] moves = Util.getStringList("moves", "en"); - private static readonly string[] abilities = Util.getStringList("abilities", "en"); - private static readonly string[] hptypes = types.Skip(1).ToArray(); - - // Default Set Data - public string Nickname; - public int Species; - public string Form; - public string Gender; - public int Item; - public int Ability; - public int Level; - public bool Shiny; - public int Friendship; - public int Nature; - public int[] EVs; - public int[] IVs; - public int[] Moves; - - // Parsing Utility - public ShowdownSet(string input = null) - { - if (input == null) - return; - - Nickname = null; - Species = -1; - Form = null; - Gender = null; - Item = 0; - Ability = 0; - Level = 100; - Shiny = false; - Friendship = 255; - Nature = 0; - EVs = new int[6]; - IVs = new[] { 31, 31, 31, 31, 31, 31 }; - Moves = new int[4]; - - string[] lines = input.Split(new[] { "\r\n", "\n" }, StringSplitOptions.None); - for (int i = 0; i < lines.Length; i++) lines[i] = lines[i].Replace("'", "’").Trim(); // Sanitize apostrophes - - if (lines.Length < 3) return; - - // Seek for start of set - int start = -1; - for (int i = 0; i < lines.Length; i++) - if (lines[i].Contains(" @ ")) { start = i; break; } - lines = lines.Skip(start).Take(lines.Length - start).ToArray(); - - // Abort if no text is found - if (start == -1) - { - // Try to parse the first line if it does not have any item - string ld = lines[0]; - // Gender Detection - string last3 = ld.Substring(ld.Length - 3); - if (last3 == "(M)" || last3 == "(F)") - { - Gender = last3.Substring(1, 1); - ld = ld.Substring(0, ld.Length - 3); - } - // Nickname Detection - string spec = ld; - if (spec.Contains("(")) - { - int index = spec.LastIndexOf("(", StringComparison.Ordinal); - string n1 = spec.Substring(0, index - 1); - string n2 = spec.Substring(index).Replace("(", "").Replace(")", "").Replace(" ", ""); - - bool inverted = Array.IndexOf(species, n2.Replace(" ", "")) > -1 || (Species = Array.IndexOf(species, n2.Split('-')[0])) > 0; - spec = inverted ? n2 : n1; - Nickname = inverted ? n1 : n2; - } - Species = Array.IndexOf(species, spec.Replace(" ", "")); - if ( - (Species = Array.IndexOf(species, spec)) < 0 // Not an Edge Case - && - (Species = Array.IndexOf(species, spec.Replace(" ", ""))) < 0 // Has Form - ) - { - string[] tmp = spec.Split(new[] { "-" }, StringSplitOptions.None); - if (tmp.Length < 2) return; - Species = Array.IndexOf(species, tmp[0].Replace(" ", "")); - Form = tmp[1].Replace(" ", ""); - if (tmp.Length > 2) - Form += " " + tmp[2]; - } - if (Species < -1) - return; - lines = lines.Skip(1).Take(lines.Length - 1).ToArray(); - } - int movectr = 0; - // Detect relevant data - foreach (string line in lines) - { - if (line.Length < 2) continue; - if (line.Contains("- ")) - { - string moveString = line.Substring(2); - if (moveString.Contains("Hidden Power")) - { - if (moveString.Length > 13) // Defined Hidden Power - { - string type = moveString.Remove(0, 13).Replace("[", "").Replace("]", ""); // Trim out excess data - int hpVal = Array.IndexOf(hptypes, type); // Get HP Type - if (hpVal >= 0) IVs = setHPIVs(hpVal, IVs); // Get IVs - } - moveString = "Hidden Power"; - } - Moves[movectr++] = Array.IndexOf(moves, moveString); - if (movectr == 4) - break; // End of moves - continue; - } - - string[] brokenline = line.Split(new[] { ": " }, StringSplitOptions.None); - switch (brokenline[0]) - { - case "Trait": - case "Ability": { Ability = Array.IndexOf(abilities, brokenline[1]); break; } - case "Level": { Level = Util.ToInt32(brokenline[1]); break; } - case "Shiny": { Shiny = brokenline[1] == "Yes"; break; } - case "Happiness": { Friendship = Util.ToInt32(brokenline[1]); break; } - case "EVs": - { - // Get EV list String - string[] evlist = brokenline[1].Replace("SAtk", "SpA").Replace("SDef", "SpD").Replace("Spd", "Spe").Split(new[] { " / ", " " }, StringSplitOptions.None); - for (int i = 0; i < evlist.Length / 2; i++) - EVs[Array.IndexOf(StatNames, evlist[1 + i * 2])] = (byte)Util.ToInt32(evlist[0 + 2 * i]); - break; - } - case "IVs": - { - // Get IV list String - string[] ivlist = brokenline[1].Split(new[] { " / ", " " }, StringSplitOptions.None); - for (int i = 0; i < ivlist.Length / 2; i++) - IVs[Array.IndexOf(StatNames, ivlist[1 + i * 2])] = (byte)Util.ToInt32(ivlist[0 + 2 * i]); - break; - } - default: - { - // Either Nature or Gender ItemSpecies - if (brokenline[0].Contains(" @ ")) - { - string[] ld = line.Split(new[] { " @ " }, StringSplitOptions.None); - Item = Array.IndexOf(items, ld.Last()); - // Gender Detection - string last3 = ld[0].Substring(ld[0].Length - 3); - if (last3 == "(M)" || last3 == "(F)") - { - Gender = last3.Substring(1, 1); - ld[0] = ld[0].Substring(0, ld[ld.Length - 2].Length - 3); - } - // Nickname Detection - string spec = ld[0]; - if (spec.Contains("(")) - { - int index = spec.LastIndexOf("(", StringComparison.Ordinal); - string n1 = spec.Substring(0, index - 1); - string n2 = spec.Substring(index).Replace("(", "").Replace(")", "").Replace(" ", ""); - - bool inverted = Array.IndexOf(species, n2.Replace(" ", "")) > -1 || (Species = Array.IndexOf(species, n2.Split('-')[0])) > 0; - spec = inverted ? n2 : n1; - Nickname = inverted ? n1 : n2; - } - if ( - (Species = Array.IndexOf(species, spec)) < 0 // Not an Edge Case - && - (Species = Array.IndexOf(species, spec.Replace(" ", ""))) < 0 // Has Form - ) - { - string[] tmp = spec.Split(new[] { "-" }, StringSplitOptions.None); - Species = Array.IndexOf(species, tmp[0].Replace(" ", "")); - Form = tmp[1].Replace(" ", ""); - if (tmp.Length > 2) - Form += " " + tmp[2]; - } - } - else if (brokenline[0].Contains("Nature")) - Nature = Array.IndexOf(natures, line.Split(' ')[0]); - else // Fallback - Species = Array.IndexOf(species, line.Split('(')[0]); - } break; - } - } - } - public string getText() - { - if (Species == 0 || Species > 722) - return ""; - - // First Line: Name, Nickname, Gender, Item - string result = string.Format(species[Species] != Nickname ? "{0} ({1})" : "{1}", Nickname, - species[Species] + ((Form ?? "") != "" ? "-" + Form.Replace("Mega ", "Mega-") : "")) // Species (& Form if necessary) - + Gender + (Item != 0 ? " @ " + items[Item] : "") + Environment.NewLine; - - // IVs - string[] ivstr = new string[6]; - int ivctr = 0; - int[] sIVs = { IVs[0], IVs[1], IVs[2], IVs[4], IVs[5], IVs[3] }; // Reorganize speed - for (int i = 0; i < 6; i++) - { - if (sIVs[i] == 31) continue; - ivstr[ivctr++] += $"{sIVs[i]} {StatNames[i]}"; - } - if (ivctr > 0) - result += "IVs: " + string.Join(" / ", ivstr.Take(ivctr)) + Environment.NewLine; - - // EVs - string[] evstr = new string[6]; - int[] sEVs = { EVs[0], EVs[1], EVs[2], EVs[4], EVs[5], EVs[3] }; // Reorganize speed - int evctr = 0; - for (int i = 0; i < 6; i++) - { - if (sEVs[i] == 0) continue; - evstr[evctr++] += $"{sEVs[i]} {StatNames[i]}"; - } - if (evctr > 0) - result += "EVs: " + string.Join(" / ", evstr.Take(evctr)) + Environment.NewLine; - - // Secondary Stats - result += "Ability: " + abilities[Ability] + Environment.NewLine; - result += "Level: " + Level + Environment.NewLine; - if (Shiny) - result += "Shiny: Yes" + Environment.NewLine; - - result += natures[Nature] + " Nature" + Environment.NewLine; - // Add in Moves - string[] MoveLines = new string[Moves.Length]; - int movectr = 0; - foreach (int move in Moves.Where(move => move != 0 && move < moves.Length)) - { - MoveLines[movectr] += "- " + moves[move]; - if (move == 237) - MoveLines[movectr] += $" [{hptypes[getHPType(IVs)]}]"; - movectr++; - } - result += string.Join(Environment.NewLine, MoveLines.Take(movectr)); - - return result; - } - } - internal static string getShowdownText(PK6 pk6) - { - if (pk6.Species == 0) return ""; - ShowdownSet Set = new ShowdownSet - { - Nickname = pk6.Nickname, - Species = pk6.Species, - Item = pk6.HeldItem, - Ability = pk6.Ability, - EVs = pk6.EVs, - IVs = pk6.IVs, - Moves = pk6.Moves, - Nature = pk6.Nature, - Gender = new[] { " (M)", " (F)", "" }[pk6.Gender], - Friendship = pk6.CurrentFriendship, - Level = getLevel(pk6.Species, pk6.EXP), - Shiny = pk6.IsShiny, - Form = pk6.AltForm > 0 ? getFormList(pk6.Species, ShowdownSet.types, ShowdownSet.forms, new [] {"", "F", ""})[pk6.AltForm] : "", - }; - if (Set.Form == "F") Set.Gender = ""; - return Set.getText(); - } - } -} diff --git a/Misc/QR.cs b/Misc/QR.cs index 4107d64eb..ebf8dc130 100644 --- a/Misc/QR.cs +++ b/Misc/QR.cs @@ -1,5 +1,8 @@ using System; using System.Drawing; +using System.IO; +using System.Net; +using System.Web; using System.Windows.Forms; namespace PKHeX @@ -41,5 +44,57 @@ private void PB_QR_Click(object sender, EventArgs e) try { Clipboard.SetImage(PB_QR.BackgroundImage); } catch { Util.Alert("Failed to set Image to Clipboard"); } } + + // QR Utility + internal static byte[] getQRData() + { + // Fetch data from QR code... + string address; + try { address = Clipboard.GetText(); } + catch { Util.Alert("No text (url) in clipboard."); return null; } + try { if (address.Length < 4 || address.Substring(0, 3) != "htt") { Util.Alert("Clipboard text is not a valid URL:", address); return null; } } + catch { Util.Alert("Clipboard text is not a valid URL:", address); return null; } + string webURL = "http://api.qrserver.com/v1/read-qr-code/?fileurl=" + HttpUtility.UrlEncode(address); + try + { + HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(webURL); + HttpWebResponse httpWebReponse = (HttpWebResponse)httpWebRequest.GetResponse(); + var reader = new StreamReader(httpWebReponse.GetResponseStream()); + string data = reader.ReadToEnd(); + if (data.Contains("could not find")) { Util.Alert("Reader could not find QR data in the image."); return null; } + if (data.Contains("filetype not supported")) { Util.Alert("Input URL is not valid. Double check that it is an image (jpg/png).", address); return null; } + // Quickly convert the json response to a data string + string pkstr = data.Substring(data.IndexOf("#", StringComparison.Ordinal) + 1); // Trim intro + pkstr = pkstr.Substring(0, pkstr.IndexOf("\",\"error\":null}]}]", StringComparison.Ordinal)); // Trim outro + if (pkstr.Contains("nQR-Code:")) pkstr = pkstr.Substring(0, pkstr.IndexOf("nQR-Code:", StringComparison.Ordinal)); // Remove multiple QR codes in same image + pkstr = pkstr.Replace("\\", ""); // Rectify response + + try { return Convert.FromBase64String(pkstr); } + catch { Util.Alert("QR string to Data failed.", pkstr); return null; } + } + catch { Util.Alert("Unable to connect to the internet to decode QR code."); return null; } + } + internal static Image getQRImage(byte[] data, string server) + { + string qrdata = Convert.ToBase64String(data); + string message = server + qrdata; + string webURL = "http://chart.apis.google.com/chart?chs=365x365&cht=qr&chl=" + HttpUtility.UrlEncode(message); + + try + { + HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(webURL); + HttpWebResponse httpWebReponse = (HttpWebResponse)httpWebRequest.GetResponse(); + Stream stream = httpWebReponse.GetResponseStream(); + if (stream != null) return Image.FromStream(stream); + } + catch + { + if (DialogResult.Yes != Util.Prompt(MessageBoxButtons.YesNo, "Unable to connect to the internet to receive QR code.", "Copy QR URL to Clipboard?")) + return null; + try { Clipboard.SetText(webURL); } + catch { Util.Alert("Failed to set text to Clipboard"); } + } + return null; + } } } \ No newline at end of file diff --git a/Misc/SAV4.cs b/Misc/SAV4.cs deleted file mode 100644 index d3b491e27..000000000 --- a/Misc/SAV4.cs +++ /dev/null @@ -1,178 +0,0 @@ -using System; -using System.Linq; - -namespace PKHeX -{ - public class SAV4 : PKM - { - internal const int SIZERAW = 0x80000; // 512KB - internal static int getIsG4SAV(byte[] data) - { - int version = -1; - if (BitConverter.ToUInt16(data, 0xC0FE) == ccitt16(data.Take(0xC0EC).ToArray())) - version = 0; // DP - else if (BitConverter.ToUInt16(data, 0xCF2A) == ccitt16(data.Take(0xCF18).ToArray())) - version = 1; // PT - else if (BitConverter.ToUInt16(data, 0xF626) == ccitt16(data.Take(0xF618).ToArray())) - version = 2; // HGSS - return version; - } - - // Global Settings - // Save Data Attributes - public readonly byte[] Data; - public bool Edited; - public readonly bool Exportable; - public readonly byte[] BAK; - public string FileName, FilePath; - public SAV4(byte[] data = null) - { - Data = (byte[])(data ?? new byte[SIZERAW]).Clone(); - BAK = (byte[])Data.Clone(); - Exportable = !Data.SequenceEqual(new byte[Data.Length]); - - // Get Version - int version = getIsG4SAV(Data); - getActiveBlock(version); - getSAVOffsets(version); - } - - private int generalBlock = -1; - private int storageBlock = -1; - private void getActiveBlock(int version) - { - if (version < 0) - return; - int ofs = 0; - - if (version == 0) ofs = 0xC0F0; // DP - else if (version == 1) ofs = 0xCF1C; // PT - else if (version == 2) ofs = 0xF626; // HGSS - generalBlock = BitConverter.ToUInt16(Data, ofs) >= BitConverter.ToUInt16(Data, ofs + 0x40000) ? 0 : 1; - - if (version == 0) ofs = 0x1E2D0; // DP - else if (version == 1) ofs = 0x1F100; // PT - else if (version == 2) ofs = 0x21A00; // HGSS - storageBlock = BitConverter.ToUInt16(Data, ofs) >= BitConverter.ToUInt16(Data, ofs + 0x40000) ? 0 : 1; - } - private void getSAVOffsets(int version) - { - if (version < 0) - return; - - switch (version) - { - case 0: // DP - Party = 0x98 + 0x40000 * generalBlock; - Box = 0xC104 + 0x40000 * storageBlock; - break; - case 1: // PT - Party = 0xA0 + 0x40000 * generalBlock; - Box = 0xCF34 + 0x40000 * storageBlock; - break; - case 2: // HGSS - Party = 0x98 + 0x40000 * generalBlock; - Box = 0xF704 + 0x40000 * storageBlock; - break; - } - } - - private int Box, Party = -1; - - public int PartyCount - { - get { return Data[Party - 4]; } - set { Data[Party - 4] = (byte)value; } - } - - public int BoxCount - { - get { return Data[Box - 4]; } - set { Data[Box - 4] = (byte)value; } - } - public PK4[] BoxData - { - get - { - PK4[] data = new PK4[18 * 30]; - for (int i = 0; i < data.Length; i++) - { - data[i] = getPK4Stored(Box + PK4.SIZE_STORED * i); - data[i].Identifier = $"B{(i / 30 + 1).ToString("00")}:{(i % 30 + 1).ToString("00")}"; - } - return data; - } - set - { - if (value == null) - throw new ArgumentNullException(); - if (value.Length != 18 * 30) - throw new ArgumentException("Expected 540, got " + value.Length); - - for (int i = 0; i < value.Length; i++) - setPK4Stored(value[i], Box + PK4.SIZE_STORED * i); - } - } - public PK4[] PartyData - { - get - { - PK4[] data = new PK4[PartyCount]; - for (int i = 0; i < data.Length; i++) - data[i] = getPK4Party(Party + PK4.SIZE_PARTY * i); - return data; - } - set - { - if (value == null) - throw new ArgumentNullException(); - if (value.Length == 0 || value.Length > 6) - throw new ArgumentException("Expected 1-6, got " + value.Length); - if (value[0].Species == 0) - throw new ArgumentException("Can't have an empty first slot." + value.Length); - - PK4[] newParty = value.Where(pk => pk.Species != 0).ToArray(); - - PartyCount = newParty.Length; - Array.Resize(ref newParty, 6); - - for (int i = PartyCount; i < newParty.Length; i++) - newParty[i] = new PK4(); - for (int i = 0; i < newParty.Length; i++) - setPK4Party(newParty[i], Party + PK4.SIZE_PARTY * i); - } - } - - public PK4 getPK4Party(int offset) - { - return new PK4(decryptArray(getData(offset, PK4.SIZE_PARTY))); - } - public PK4 getPK4Stored(int offset) - { - return new PK4(decryptArray(getData(offset, PK4.SIZE_STORED))); - } - public void setPK4Party(PK4 pk4, int offset) - { - if (pk4 == null) return; - - setData(pk4.EncryptedPartyData, offset); - Edited = true; - } - public void setPK4Stored(PK4 pk4, int offset) - { - if (pk4 == null) return; - - setData(pk4.EncryptedBoxData, offset); - Edited = true; - } - public byte[] getData(int Offset, int Length) - { - return Data.Skip(Offset).Take(Length).ToArray(); - } - public void setData(byte[] input, int Offset) - { - input.CopyTo(Data, Offset); - Edited = true; - } - } -} diff --git a/Misc/SAV5.cs b/Misc/SAV5.cs deleted file mode 100644 index 7f29c58f2..000000000 --- a/Misc/SAV5.cs +++ /dev/null @@ -1,204 +0,0 @@ -using System; -using System.Linq; - -namespace PKHeX -{ - public class SAV5 : PKM - { - internal const int SIZERAW = 0x80000; // 512KB - internal const int SIZE1 = 0x24000; // B/W - internal const int SIZE2 = 0x26000; // B2/W2 - - internal static int getIsG5SAV(byte[] data) - { - ushort chk1 = BitConverter.ToUInt16(data, SIZE1 - 0x100 + 0x8C + 0xE); - ushort actual1 = ccitt16(data.Skip(SIZE1 - 0x100).Take(0x8C).ToArray()); - if (chk1 == actual1) - return 0; - ushort chk2 = BitConverter.ToUInt16(data, SIZE2 - 0x100 + 0x94 + 0xE); - ushort actual2 = ccitt16(data.Skip(SIZE2 - 0x100).Take(0x94).ToArray()); - if (chk2 == actual2) - return 1; - return -1; - } - - // Global Settings - // Save Data Attributes - public readonly byte[] Data; - public bool Edited; - public readonly bool Exportable; - public readonly byte[] BAK; - public string FileName, FilePath; - public SAV5(byte[] data = null) - { - Data = (byte[])(data ?? new byte[SIZERAW]).Clone(); - BAK = (byte[])Data.Clone(); - Exportable = !Data.SequenceEqual(new byte[Data.Length]); - - // Get Version - int version = getIsG5SAV(Data); - if (version < 0) // Invalidate Data - Data = null; - - // Different Offsets for different games. - BattleBox = version == 1 ? 0x20A00 : 0x20900; - } - - private const int Box = 0x400; - private const int Party = 0x18E00; - private readonly int BattleBox; - private const int Trainer = 0x19400; - private const int Wondercard = 0x1C800; - private const int wcSeed = 0x1D290; - - public int PartyCount - { - get { return Data[Party]; } - set { Data[Party] = (byte)value; } - } - - public PK5[] BoxData - { - get - { - PK5[] data = new PK5[24 * 30]; - for (int i = 0; i < data.Length; i++) - { - data[i] = getPK5Stored(Box + i/30 * 0x10 + PK5.SIZE_STORED * i); - data[i].Identifier = $"B{(i / 30 + 1).ToString("00")}:{(i % 30 + 1).ToString("00")}"; - } - return data; - } - set - { - if (value == null) - throw new ArgumentNullException(); - if (value.Length != 24 * 30) - throw new ArgumentException("Expected 720, got " + value.Length); - - for (int i = 0; i < value.Length; i++) - setPK5Stored(value[i], Box + i/30 * 0x10 + PK5.SIZE_STORED * i); - } - } - public PK5[] PartyData - { - get - { - PK5[] data = new PK5[PartyCount]; - for (int i = 0; i < data.Length; i++) - data[i] = getPK5Party(Party + 8 + PK5.SIZE_PARTY * i); - return data; - } - set - { - if (value == null) - throw new ArgumentNullException(); - if (value.Length == 0 || value.Length > 6) - throw new ArgumentException("Expected 1-6, got " + value.Length); - if (value[0].Species == 0) - throw new ArgumentException("Can't have an empty first slot." + value.Length); - - PK5[] newParty = value.Where(pk => pk.Species != 0).ToArray(); - - PartyCount = newParty.Length; - Array.Resize(ref newParty, 6); - - for (int i = PartyCount; i < newParty.Length; i++) - newParty[i] = new PK5(); - for (int i = 0; i < newParty.Length; i++) - setPK5Party(newParty[i], Party + 8 + PK5.SIZE_PARTY * i); - } - } - public PK5[] BattleBoxData - { - get - { - PK5[] data = new PK5[6]; - for (int i = 0; i < data.Length; i++) - { - data[i] = getPK5Stored(BattleBox + PK5.SIZE_STORED * i); - if (data[i].Species == 0) - return data.Take(i).ToArray(); - } - return data; - } - } - - public class MysteryGift - { - public readonly PGF[] Cards = new PGF[12]; - public readonly bool[] UsedFlags = new bool[0x800]; - public uint Seed; - } - public MysteryGift WondercardInfo - { - get - { - uint seed = BitConverter.ToUInt32(Data, wcSeed); - MysteryGift Info = new MysteryGift { Seed = seed }; - byte[] wcData = Data.Skip(Wondercard).Take(0xA90).ToArray(); // Encrypted, Decrypt - for (int i = 0; i < wcData.Length; i += 2) - BitConverter.GetBytes((ushort)(BitConverter.ToUInt16(wcData, i) ^ LCRNG(ref seed) >> 16)).CopyTo(wcData, i); - - // 0x100 Bytes for Used Flags - for (int i = 0; i < Info.UsedFlags.Length; i++) - Info.UsedFlags[i] = (wcData[i/8] >> i%8 & 0x1) == 1; - // 12 PGFs - for (int i = 0; i < Info.Cards.Length; i++) - Info.Cards[i] = new PGF(Data.Skip(0x100 + i*PGF.Size).Take(PGF.Size).ToArray()); - - return Info; - } - set - { - MysteryGift Info = value; - byte[] wcData = new byte[0xA90]; - - // Toss back into byte[] - for (int i = 0; i < Info.UsedFlags.Length; i++) - if (Info.UsedFlags[i]) - wcData[i/8] |= (byte)(1 << (i & 7)); - for (int i = 0; i < Info.Cards.Length; i++) - Info.Cards[i].Data.CopyTo(wcData, 0x100 + i*PGF.Size); - - // Decrypted, Encrypt - uint seed = Info.Seed; - for (int i = 0; i < wcData.Length; i += 2) - BitConverter.GetBytes((ushort)(BitConverter.ToUInt16(wcData, i) ^ LCRNG(ref seed) >> 16)).CopyTo(wcData, i); - BitConverter.GetBytes(Info.Seed).CopyTo(Data, wcSeed); - } - } - - public PK5 getPK5Party(int offset) - { - return new PK5(decryptArray(getData(offset, PK5.SIZE_PARTY))); - } - public PK5 getPK5Stored(int offset) - { - return new PK5(decryptArray(getData(offset, PK5.SIZE_STORED))); - } - public void setPK5Party(PK5 pk5, int offset) - { - if (pk5 == null) return; - - setData(pk5.EncryptedPartyData, offset); - Edited = true; - } - public void setPK5Stored(PK5 pk5, int offset) - { - if (pk5 == null) return; - - setData(pk5.EncryptedBoxData, offset); - Edited = true; - } - public byte[] getData(int Offset, int Length) - { - return Data.Skip(Offset).Take(Length).ToArray(); - } - public void setData(byte[] input, int Offset) - { - input.CopyTo(Data, Offset); - Edited = true; - } - } -} diff --git a/Misc/Util.cs b/Misc/Util.cs index 1702d2dda..f2fb81b6f 100644 --- a/Misc/Util.cs +++ b/Misc/Util.cs @@ -149,6 +149,7 @@ internal static string TrimFromZero(string input) internal static string[] getStringList(string f) { object txt = Properties.Resources.ResourceManager.GetObject(f); // Fetch File, \n to list. + if (txt == null) return new string[0]; string[] rawlist = ((string)txt).Split('\n'); for (int i = 0; i < rawlist.Length; i++) rawlist[i] = rawlist[i].Trim(); @@ -157,6 +158,7 @@ internal static string[] getStringList(string f) internal static string[] getStringList(string f, string l) { object txt = Properties.Resources.ResourceManager.GetObject("text_" + f + "_" + l); // Fetch File, \n to list. + if (txt == null) return new string[0]; string[] rawlist = ((string)txt).Split('\n'); for (int i = 0; i < rawlist.Length; i++) rawlist[i] = rawlist[i].Trim(); @@ -473,57 +475,5 @@ internal static List getUnsortedCBList(string textfile) } return cbList; } - - // QR Utility - internal static byte[] getQRData() - { - // Fetch data from QR code... - string address; - try { address = Clipboard.GetText(); } - catch { Alert("No text (url) in clipboard."); return null; } - try { if (address.Length < 4 || address.Substring(0, 3) != "htt") { Alert("Clipboard text is not a valid URL:", address); return null; } } - catch { Alert("Clipboard text is not a valid URL:", address); return null; } - string webURL = "http://api.qrserver.com/v1/read-qr-code/?fileurl=" + System.Web.HttpUtility.UrlEncode(address); - try - { - System.Net.HttpWebRequest httpWebRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(webURL); - System.Net.HttpWebResponse httpWebReponse = (System.Net.HttpWebResponse)httpWebRequest.GetResponse(); - var reader = new StreamReader(httpWebReponse.GetResponseStream()); - string data = reader.ReadToEnd(); - if (data.Contains("could not find")) { Alert("Reader could not find QR data in the image."); return null; } - if (data.Contains("filetype not supported")) { Alert("Input URL is not valid. Double check that it is an image (jpg/png).", address); return null; } - // Quickly convert the json response to a data string - string pkstr = data.Substring(data.IndexOf("#", StringComparison.Ordinal) + 1); // Trim intro - pkstr = pkstr.Substring(0, pkstr.IndexOf("\",\"error\":null}]}]", StringComparison.Ordinal)); // Trim outro - if (pkstr.Contains("nQR-Code:")) pkstr = pkstr.Substring(0, pkstr.IndexOf("nQR-Code:", StringComparison.Ordinal)); // Remove multiple QR codes in same image - pkstr = pkstr.Replace("\\", ""); // Rectify response - - try { return Convert.FromBase64String(pkstr); } - catch { Alert("QR string to Data failed.", pkstr); return null; } - } - catch { Alert("Unable to connect to the internet to decode QR code."); return null;} - } - internal static Image getQRImage(byte[] data, string server) - { - string qrdata = Convert.ToBase64String(data); - string message = server + qrdata; - string webURL = "http://chart.apis.google.com/chart?chs=365x365&cht=qr&chl=" + System.Web.HttpUtility.UrlEncode(message); - - try - { - System.Net.HttpWebRequest httpWebRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(webURL); - System.Net.HttpWebResponse httpWebReponse = (System.Net.HttpWebResponse)httpWebRequest.GetResponse(); - Stream stream = httpWebReponse.GetResponseStream(); - if (stream != null) return Image.FromStream(stream); - } - catch - { - if (DialogResult.Yes != Prompt(MessageBoxButtons.YesNo, "Unable to connect to the internet to receive QR code.", "Copy QR URL to Clipboard?")) - return null; - try { Clipboard.SetText(webURL); } - catch { Alert("Failed to set text to Clipboard"); } - } - return null; - } } } \ No newline at end of file diff --git a/MysteryGifts/MysteryGift.cs b/MysteryGifts/MysteryGift.cs new file mode 100644 index 000000000..ae40ce583 --- /dev/null +++ b/MysteryGifts/MysteryGift.cs @@ -0,0 +1,41 @@ +using System; +using System.Linq; + +namespace PKHeX +{ + public abstract class MysteryGift + { + internal static MysteryGift getMysteryGift(byte[] data, string ext) + { + if (data.Length == WC6.SizeFull && ext == ".wc6full") + return new WC6(data); + if (data.Length == WC6.Size && ext == ".wc6") + return new WC6(data); + if (data.Length == PGF.Size && ext == ".pgf") + return new PGF(data); + if (data.Length == PGT.Size && ext == ".pgt") + return new PGT(data); + if (data.Length == PCD.Size && ext == ".pcd") + return new PCD(data); + return null; + } + + public abstract string Extension { get; } + public virtual byte[] Data { get; set; } + public abstract PKM convertToPKM(SaveFile SAV); + + // Properties + public abstract bool GiftUsed { get; set; } + public abstract string CardTitle { get; set; } + public abstract int CardID { get; set; } + + public abstract bool IsItem { get; set; } + public abstract int Item { get; set; } + + public abstract bool IsPokémon { get; set; } + public virtual int Quantity { get { return 1; } set { } } + public bool Empty => Data.SequenceEqual(new byte[Data.Length]); + + public string getCardHeader() => (CardID > 0 ? $"Card #: {CardID.ToString("0000")}" : "N/A") + $" - {CardTitle.Trim()}" + Environment.NewLine; + } +} diff --git a/Misc/PGF.cs b/MysteryGifts/PGF.cs similarity index 89% rename from Misc/PGF.cs rename to MysteryGifts/PGF.cs index 6ed875563..22892e310 100644 --- a/Misc/PGF.cs +++ b/MysteryGifts/PGF.cs @@ -3,14 +3,16 @@ namespace PKHeX { - public class PGF + public class PGF : MysteryGift { internal const int Size = 0xCC; + public override string Extension => ".pgf"; - public byte[] Data; public PGF(byte[] data = null) { - Data = data ?? new byte[Size]; + Data = (byte[])(data?.Clone() ?? new byte[Size]); + if (data == null) Data = new byte[Size]; + else Data = (byte[])data.Clone(); } public ushort TID { get { return BitConverter.ToUInt16(Data, 0x00); } set { BitConverter.GetBytes(value).CopyTo(Data, 0x00); } } @@ -49,7 +51,7 @@ public PGF(byte[] data = null) public int Language { get { return Data[0x1D]; } set { Data[0x1D] = (byte)value; } } public string Nickname { - get { return PKM.TrimFromFFFF(Encoding.Unicode.GetString(Data, 0x1E, 0x16)); } + get { return PKX.TrimFromFFFF(Encoding.Unicode.GetString(Data, 0x1E, 0x16)); } set { Encoding.Unicode.GetBytes(value.PadRight(0xB, (char)0xFFFF)).CopyTo(Data, 0x1E); } } public int Nature { get { return Data[0x34]; } set { Data[0x34] = (byte)value; } } @@ -73,27 +75,32 @@ public string Nickname public int IV_SPD { get { return Data[0x48]; } set { Data[0x48] = (byte)value; } } // Unused 0x49 public string OT { - get { return PKM.TrimFromFFFF(Encoding.Unicode.GetString(Data, 0x4A, 0x10)); } + get { return PKX.TrimFromFFFF(Encoding.Unicode.GetString(Data, 0x4A, 0x10)); } set { Encoding.Unicode.GetBytes(value.PadRight(0x08, (char)0xFFFF)).CopyTo(Data, 0x4A); } } public int OTGender { get { return Data[0x5A]; } set { Data[0x5A] = (byte)value; } } public int Level { get { return Data[0x5B]; } set { Data[0x5C] = (byte)value; } } public bool IsEgg { get { return Data[0x5C] == 1; } set { Data[0x5C] = (byte)(value ? 1 : 0); } } // Unused 0x5D 0x5E 0x5F + public override string CardTitle + { + get { return PKX.TrimFromFFFF(Encoding.Unicode.GetString(Data, 0x60, 0x4A)); } + set { Encoding.Unicode.GetBytes((value + '\uFFFF').PadRight(0x4A/2, '\0')).CopyTo(Data, 0x60); } + } // Card Attributes - public ushort Item { get { return BitConverter.ToUInt16(Data, 0x00); } set { BitConverter.GetBytes(value).CopyTo(Data, 0x00); } } + public override int Item { get { return BitConverter.ToUInt16(Data, 0x00); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x00); } } public ushort Year { get { return BitConverter.ToUInt16(Data, 0xAE); } set { BitConverter.GetBytes(value).CopyTo(Data, 0xAE); } } public byte Month { get { return Data[0xAD]; } set { Data[0xAD] = value; } } public byte Day { get { return Data[0xAC]; } set { Data[0xAC] = value; } } - public int CardID + public override int CardID { get { return BitConverter.ToUInt16(Data, 0xB0); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0xB0); } } public int CardLocation { get { return Data[0xB2]; } set { Data[0xB2] = (byte)value; } } public int CardType { get { return Data[0xB3]; } set { Data[0xB3] = (byte)value; } } - public bool GiftUsed { get { return Data[0xB4] >> 1 > 0; } set { Data[0xB4] = (byte)(Data[0xB4] & ~2 | (value ? 2 : 0)); } } + public override bool GiftUsed { get { return Data[0xB4] >> 1 > 0; } set { Data[0xB4] = (byte)(Data[0xB4] & ~2 | (value ? 2 : 0)); } } public bool MultiObtain { get { return Data[0xB4] == 1; } set { Data[0xB4] = (byte)(value ? 1 : 0); } } // Meta Accessible Properties @@ -111,11 +118,11 @@ public int[] Moves if (value.Length > 3) Move4 = value[3]; } } - public bool IsPokémon { get { return CardType == 1; } set { if (value) CardType = 1; } } - public bool IsItem { get { return CardType == 2; } set { if (value) CardType = 2; } } + public override bool IsPokémon { get { return CardType == 1; } set { if (value) CardType = 1; } } + public override bool IsItem { get { return CardType == 2; } set { if (value) CardType = 2; } } public bool IsPower { get { return CardType == 3; } set { if (value) CardType = 3; } } - public PK5 convertToPK5(SAV6 SAV) + public override PKM convertToPKM(SaveFile SAV) { if (!IsPokémon) return null; @@ -179,21 +186,21 @@ public PK5 convertToPK5(SAV6 SAV) RIB7_3 = RIB1_5, // National Champ Ribbon RIB2_5 = RIB1_6, // World Champ Ribbon - Friendship = PKX.getBaseFriendship(Species), + OT_Friendship = PKX.getBaseFriendship(Species), FatefulEncounter = true, }; if (OTGender == 3) // User's { - pk.TID = 12345; - pk.SID = 54321; - pk.OT_Name = "PKHeX"; + pk.TID = SAV.TID; + pk.SID = SAV.SID; + pk.OT_Name = SAV.OT; pk.OT_Gender = 1; // Red PKHeX OT } else { - pk.TID = TID; - pk.SID = SID; - pk.OT_Name = OT.Length > 0 ? OT : "PKHeX"; + pk.TID = IsEgg ? SAV.TID : TID; + pk.SID = IsEgg ? SAV.SID : SID; + pk.OT_Name = OT.Length > 0 ? OT : SAV.OT; pk.OT_Gender = OTGender % 2; // %2 just in case? } pk.IsNicknamed = IsNicknamed; diff --git a/MysteryGifts/PGT.cs b/MysteryGifts/PGT.cs new file mode 100644 index 000000000..d3fb13a51 --- /dev/null +++ b/MysteryGifts/PGT.cs @@ -0,0 +1,209 @@ +using System; +using System.Linq; + +namespace PKHeX +{ + /* Big thanks to Grovyle91's Pokémon Mystery Gift Editor, from which the structure was referenced. + * http://projectpokemon.org/forums/member.php?829-Grovyle91 + * http://projectpokemon.org/forums/showthread.php?6524 + * See also: http://tccphreak.shiny-clique.net/debugger/pcdfiles.htm + */ + public class PCD : MysteryGift + { + internal const int Size = 0x358; // 856 + public override string Extension => ".pcd"; + + public PCD(byte[] data = null) + { + Data = (byte[])(data?.Clone() ?? new byte[Size]); + + byte[] giftData = new byte[PGT.Size]; + Array.Copy(Data, 0, giftData, 0, PGT.Size); + Gift = new PGT(giftData); + + Information = new byte[Data.Length - PGT.Size]; + Array.Copy(Data, PGT.Size, Information, 0, Information.Length); + } + public readonly PGT Gift; + + public readonly byte[] Information; + public override bool GiftUsed { get { return Gift.GiftUsed; } set { Gift.GiftUsed = value; } } + public override bool IsPokémon { get { return Gift.IsPokémon; } set { Gift.IsPokémon = value; } } + public override bool IsItem { get { return Gift.IsItem; } set { Gift.IsItem = value; } } + public override int Item { get { return Gift.Item; } set { Gift.Item = value; } } + public override int CardID + { + get { return BitConverter.ToUInt16(Data, 0x150); } + set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x150); } + } + public override string CardTitle + { + get { return PKX.array2strG4(Data.Skip(0x104).Take(0x48).ToArray()); } + set + { + byte[] data = PKX.str2arrayG4(value); + int len = data.Length; + Array.Resize(ref data, 0x48); + for (int i = 0; i < len; i++) + data[i] = 0xFF; + data.CopyTo(Data, 0x104); + } + } + + public override PKM convertToPKM(SaveFile SAV) + { + return Gift.convertToPKM(SAV); + } + } + public class PGT : MysteryGift + { + internal const int Size = 0x104; // 260 + public override string Extension => ".pgt"; + + private enum GiftType + { + Pokémon = 1, + PokémonEgg = 2, + Item = 3, + Rule = 4, + Seal = 5, + Accessory = 6, + ManaphyEgg = 7, + MemberCard = 8, + OaksLetter = 9, + AzureFlute = 10, + PokétchApp = 11, + Ribbon = 12, + PokéWalkerArea = 14 + } + + public override string CardTitle { get { return "Raw Gift (PGT)"; } set { } } + public override int CardID { get { return -1; } set { } } + public override bool GiftUsed { get { return false; } set { } } + + public PGT(byte[] data = null) + { + refreshData((byte[])(data?.Clone() ?? new byte[Size])); + } + public void refreshData(byte[] data) + { + byte[] ekdata = new byte[PKX.SIZE_4PARTY]; + Array.Copy(data, 8, ekdata, 0, ekdata.Length); + bool empty = ekdata.SequenceEqual(new byte[ekdata.Length]); + PK = new PK4(empty ? ekdata : PKX.decryptArray45(ekdata)); + + Unknown = new byte[0x10]; + Array.Copy(data, 0xF4, Unknown, 0, 0x10); + RAW = data; + } + + public byte CardType { get { return Data[0]; } set { Data[0] = value; } } + // Unused 0x01 + public byte Slot { get { return Data[2]; } set { Data[2] = value; } } + public byte Detail { get { return Data[3]; } set { Data[3] = value; } } + public override int Item { get { return BitConverter.ToUInt16(Data, 0x4); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x4); } } + private PK4 PK; + private byte[] Unknown; + private byte[] RAW; + + public override byte[] Data + { + get { return RAW; } + set + { + refreshData(value); + } + } + + private GiftType Type { get { return (GiftType)Data[0]; } set {Data[0] = (byte)value; } } + public bool IsHatched => Type == GiftType.Pokémon; + public bool IsEgg => Type == GiftType.PokémonEgg; + public bool IsManaphyEgg => Type == GiftType.ManaphyEgg; + public override bool IsItem { get { return Type == GiftType.Item; } set { if (value) CardType = (int)GiftType.Item; } } + public override bool IsPokémon { get { return Type == GiftType.Pokémon || Type == GiftType.PokémonEgg || Type == GiftType.ManaphyEgg; } set { } } + + public override PKM convertToPKM(SaveFile SAV) + { + if (!IsPokémon) + return null; + + PK4 pk4 = new PK4(PK.Data); + if (!IsHatched && Detail == 0) + { + pk4.OT_Name = SAV.OT; + pk4.TID = SAV.TID; + pk4.SID = SAV.SID; + pk4.OT_Gender = SAV.Gender; + } + if (IsManaphyEgg) + { + // Since none of this data is populated, fill in default info. + pk4.Species = 490; + // Level 1 Moves + pk4.Move1 = 294; + pk4.Move2 = 145; + pk4.Move3 = 346; + pk4.FatefulEncounter = true; + pk4.Ball = 4; + pk4.Version = 10; // Diamond + pk4.Language = 2; // English + pk4.Nickname = "MANAPHY"; + pk4.Egg_Location = 1; // Ranger (will be +3000 later) + } + + // Generate IV + uint seed = Util.rnd32(); + if (pk4.PID == 1 || IsManaphyEgg) // Create Nonshiny + { + uint pid1 = PKX.LCRNG(ref seed) >> 16; + uint pid2 = PKX.LCRNG(ref seed) >> 16; + + while ((pid1 ^ pid2 ^ pk4.TID ^ pk4.SID) < 8) + { + uint testPID = pid1 | pid2 << 16; + + // Call the ARNG to change the PID + testPID = testPID * 0x6c078965 + 1; + + pid1 = testPID & 0xFFFF; + pid2 = testPID >> 16; + } + pk4.PID = pid1 | (pid2 << 16); + } + + // Generate IVs + if (pk4.IV32 == 0) + { + uint iv1 = PKX.LCRNG(ref seed) >> 16; + uint iv2 = PKX.LCRNG(ref seed) >> 16; + pk4.IV32 = (iv1 | iv2 << 16) & 0x3FFFFFFF; + } + + // Generate Met Info + DateTime dt = DateTime.Now; + if (IsPokémon) + { + pk4.Met_Location = pk4.Egg_Location + 3000; + pk4.Egg_Location = 0; + pk4.Met_Day = dt.Day; + pk4.Met_Month = dt.Month; + pk4.Met_Year = dt.Year - 2000; + pk4.IsEgg = false; + } + else + { + pk4.Egg_Location = pk4.Egg_Location + 3000; + pk4.Egg_Day = dt.Day; + pk4.Egg_Month = dt.Month; + pk4.Egg_Year = dt.Year - 2000; + pk4.IsEgg = false; + // Met Location is modified when transferred to pk5; don't worry about it. + } + if (pk4.Species == 201) // Never will be true; Unown was never distributed. + pk4.AltForm = PKX.getUnownForm(pk4.PID); + if (IsEgg || IsManaphyEgg) + pk4.IsEgg = true; + return pk4; + } + } +} diff --git a/Misc/WC6.cs b/MysteryGifts/WC6.cs similarity index 96% rename from Misc/WC6.cs rename to MysteryGifts/WC6.cs index b9c959230..3e3eb7af3 100644 --- a/Misc/WC6.cs +++ b/MysteryGifts/WC6.cs @@ -4,16 +4,16 @@ namespace PKHeX { - public partial class WC6 + public class WC6 : MysteryGift { internal const int Size = 0x108; internal const int SizeFull = 0x310; internal const uint EonTicketConst = 0x225D73C2; + public override string Extension => ".wc6"; - public readonly byte[] Data; public WC6(byte[] data = null) { - Data = data ?? new byte[Size]; + Data = (byte[])(data?.Clone() ?? new byte[Size]); if (Data.Length == SizeFull) { Data = Data.Skip(SizeFull - Size).ToArray(); @@ -23,12 +23,12 @@ public WC6(byte[] data = null) Day = (uint)now.Day; } } - + // General Card Properties - public int CardID { + public override int CardID { get { return BitConverter.ToUInt16(Data, 0); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0); } } - public string CardTitle { // Max len 36 char, followed by null terminator + public override string CardTitle { // Max len 36 char, followed by null terminator get { return Util.TrimFromZero(Encoding.Unicode.GetString(Data, 2, 72)); } set { Encoding.Unicode.GetBytes(value.PadRight(36, '\0')).CopyTo(Data, 2); } } private uint Date { @@ -46,20 +46,20 @@ public WC6(byte[] data = null) public int CardLocation { get { return Data[0x50]; } set { Data[0x50] = (byte)value; } } public int CardType { get { return Data[0x51]; } set { Data[0x51] = (byte)value; } } - public bool GiftUsed { get { return Data[0x52] >> 1 > 0; } set { Data[0x52] = (byte)(Data[0x52] & ~2 | (value ? 2 : 0)); } } + public override bool GiftUsed { get { return Data[0x52] >> 1 > 0; } set { Data[0x52] = (byte)(Data[0x52] & ~2 | (value ? 2 : 0)); } } public bool MultiObtain { get { return Data[0x53] == 1; } set { Data[0x53] = (byte)(value ? 1 : 0); } } // Item Properties - public bool IsItem { get { return CardType == 1; } set { if (value) CardType = 1; } } - public int Item { + public override bool IsItem { get { return CardType == 1; } set { if (value) CardType = 1; } } + public override int Item { get { return BitConverter.ToUInt16(Data, 0x68); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x68); } } - public int Quantity { + public override int Quantity { get { return BitConverter.ToUInt16(Data, 0x70); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x70); } } // Pokémon Properties - public bool IsPokémon { get { return CardType == 0; } set { if (value) CardType = 0; } } + public override bool IsPokémon { get { return CardType == 0; } set { if (value) CardType = 0; } } public int TID { get { return BitConverter.ToUInt16(Data, 0x68); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x68); } } @@ -207,7 +207,7 @@ public int[] RelearnMoves } } - public PK6 convertToPK6(SAV6 SAV) + public override PKM convertToPKM(SaveFile SAV) { if (!IsPokémon) return null; diff --git a/PKHeX.csproj b/PKHeX.csproj index fb7e71c5f..e34f532fb 100644 --- a/PKHeX.csproj +++ b/PKHeX.csproj @@ -71,24 +71,32 @@ - - - + + + + + + + + + - - - - + + + Form QR.cs - - - - + + + + + + + Form @@ -101,7 +109,7 @@ About.cs - + Form @@ -125,11 +133,13 @@ True Resources.resx - + + + Form - - SAV_BerryFieldORAS.cs + + SAV_PokeBlockORAS.cs Form @@ -149,11 +159,11 @@ SAV_SecretBase.cs - + Form - - SAV_EventFlagsORAS.cs + + SAV_EventFlags.cs Form @@ -175,12 +185,6 @@ SAV_BoxLayout.cs - - Form - - - SAV_EventFlagsXY.cs - Form @@ -238,12 +242,14 @@ QR.cs + Designer f2-Text.cs About.cs + Designer f1-Main.cs @@ -255,8 +261,8 @@ f3-MemoryAmie.cs - - SAV_BerryFieldORAS.cs + + SAV_PokeBlockORAS.cs SAV_Database.cs @@ -267,8 +273,8 @@ SAV_SecretBase.cs - - SAV_EventFlagsORAS.cs + + SAV_EventFlags.cs frmReport.cs @@ -284,9 +290,6 @@ SAV_BoxLayout.cs - - SAV_EventFlagsXY.cs - SAV_HallOfFame.cs @@ -313,6 +316,7 @@ SplashScreen.cs + Designer @@ -370,6 +374,27 @@ + + + + + + + + + + + + + + + + + + + + + @@ -391,6 +416,9 @@ + + + diff --git a/PKM/PK3.cs b/PKM/PK3.cs new file mode 100644 index 000000000..d2e9f9a29 --- /dev/null +++ b/PKM/PK3.cs @@ -0,0 +1,299 @@ +using System; +using System.Linq; + +namespace PKHeX +{ + public class PK3 : PKM // 3rd Generation PKM File + { + public override int SIZE_PARTY => PKX.SIZE_3PARTY; + public override int SIZE_STORED => PKX.SIZE_3STORED; + public override int Format => 3; + public PK3(byte[] decryptedData = null, string ident = null) + { + Data = (byte[])(decryptedData ?? new byte[SIZE_PARTY]).Clone(); + PKMConverter.checkEncrypted(ref Data); + Identifier = ident; + if (Data.Length != SIZE_PARTY) + Array.Resize(ref Data, SIZE_PARTY); + } + public override PKM Clone() { return new PK3(Data); } + + // Future Attributes + public override uint EncryptionConstant { get { return PID; } set { } } + public override int Nature { get { return (int)(PID % 25); } set { } } + public override int AltForm { get { return -1; } set { } } + public override bool IsNicknamed { get { return Nickname != PKX.getSpeciesName(Species, Language); } set { } } + public override int Gender { get { return PKX.getGender(Species, PID); } set { } } + public override int Characteristic => -1; + public override int CurrentFriendship { get { return OT_Friendship; } set { OT_Friendship = value; } } + public override int Ability { get { return PKX.Gen3Abilities[Species][AbilityNumber]; } set { } } + public override int CurrentHandler { get { return 0; } set { } } + public override int Egg_Location { get { return 0; } set { } } + public override int Met_Level { get { return -1; } set { } } + + // 0x20 Intro + public override uint PID { get { return BitConverter.ToUInt32(Data, 0x00); } set { BitConverter.GetBytes(value).CopyTo(Data, 0x00); } } + public override int TID { get { return BitConverter.ToUInt16(Data, 0x04); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x04); } } + public override int SID { get { return BitConverter.ToUInt16(Data, 0x06); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x06); } } + public override string Nickname { + get { return PKX.getG3Str(Data.Skip(0x08).Take(10).ToArray(), Japanese); } + set { byte[] strdata = PKX.setG3Str(value, Japanese); + if (strdata.Length > 10) + Array.Resize(ref strdata, 10); + strdata.CopyTo(Data, 0x08); } } + public override int Language { get { return BitConverter.ToUInt16(Data, 0x12); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x12); } } + public override string OT_Name { + get { return PKX.getG3Str(Data.Skip(0x14).Take(7).ToArray(), Japanese); } + set { byte[] strdata = PKX.setG3Str(value, Japanese); + if (strdata.Length > 7) + Array.Resize(ref strdata, 7); + strdata.CopyTo(Data, 0x14); } } + + public override byte MarkByte { get { return Data[0x1B]; } protected set { Data[0x1B] = value; } } + public override ushort Checksum { get { return BitConverter.ToUInt16(Data, 0x1C); } set { BitConverter.GetBytes(value).CopyTo(Data, 0x1C); } } + public override ushort Sanity { get { return BitConverter.ToUInt16(Data, 0x1E); } set { BitConverter.GetBytes(value).CopyTo(Data, 0x1E); } } + + #region Block A + public override int Species { get { return PKX.getG4Species(BitConverter.ToUInt16(Data, 0x20)); } set { BitConverter.GetBytes((ushort)PKX.getG3Species(value)).CopyTo(Data, 0x20); } } + public override int HeldItem { get { return BitConverter.ToUInt16(Data, 0x22); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x22); } } + public override uint EXP { get { return BitConverter.ToUInt32(Data, 0x24); } set { BitConverter.GetBytes(value).CopyTo(Data, 0x24); } } + private byte PPUps { get { return Data[0x28]; } set { Data[0x28] = value; } } + public override int Move1_PPUps { get { return (PPUps >> 0) & 3; } set { PPUps = (byte)((PPUps & ~(3 << 0)) | value); } } + public override int Move2_PPUps { get { return (PPUps >> 2) & 3; } set { PPUps = (byte)((PPUps & ~(3 << 2)) | value); } } + public override int Move3_PPUps { get { return (PPUps >> 4) & 3; } set { PPUps = (byte)((PPUps & ~(3 << 4)) | value); } } + public override int Move4_PPUps { get { return (PPUps >> 6) & 3; } set { PPUps = (byte)((PPUps & ~(3 << 6)) | value); } } + public override int OT_Friendship { get { return Data[0x29]; } set { Data[0x29] = (byte)value; } } + // Unused 0x2A 0x2B + #endregion + + #region Block B + public override int Move1 { get { return BitConverter.ToUInt16(Data, 0x2C); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x2C); } } + public override int Move2 { get { return BitConverter.ToUInt16(Data, 0x2E); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x2E); } } + public override int Move3 { get { return BitConverter.ToUInt16(Data, 0x30); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x30); } } + public override int Move4 { get { return BitConverter.ToUInt16(Data, 0x32); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x32); } } + public override int Move1_PP { get { return Data[0x34]; } set { Data[0x34] = (byte)value; } } + public override int Move2_PP { get { return Data[0x35]; } set { Data[0x35] = (byte)value; } } + public override int Move3_PP { get { return Data[0x36]; } set { Data[0x36] = (byte)value; } } + public override int Move4_PP { get { return Data[0x37]; } set { Data[0x37] = (byte)value; } } + #endregion + + #region Block C + public override int EV_HP { get { return Data[0x38]; } set { Data[0x38] = (byte)value; } } + public override int EV_ATK { get { return Data[0x39]; } set { Data[0x39] = (byte)value; } } + public override int EV_DEF { get { return Data[0x3A]; } set { Data[0x3A] = (byte)value; } } + public override int EV_SPE { get { return Data[0x3B]; } set { Data[0x3B] = (byte)value; } } + public override int EV_SPA { get { return Data[0x3C]; } set { Data[0x3C] = (byte)value; } } + public override int EV_SPD { get { return Data[0x3D]; } set { Data[0x3D] = (byte)value; } } + public override int CNT_Cool { get { return Data[0x3E]; } set { Data[0x3E] = (byte)value; } } + public override int CNT_Beauty { get { return Data[0x3F]; } set { Data[0x3F] = (byte)value; } } + public override int CNT_Cute { get { return Data[0x40]; } set { Data[0x40] = (byte)value; } } + public override int CNT_Smart { get { return Data[0x41]; } set { Data[0x41] = (byte)value; } } + public override int CNT_Tough { get { return Data[0x42]; } set { Data[0x42] = (byte)value; } } + public override int CNT_Sheen { get { return Data[0x43]; } set { Data[0x43] = (byte)value; } } + #endregion + + #region Block D + private byte PKRS { get { return Data[0x44]; } set { Data[0x44] = value; } } + public override int PKRS_Days { get { return PKRS & 0xF; } set { PKRS = (byte)(PKRS & ~0xF | value); } } + public override int PKRS_Strain { get { return PKRS >> 4; } set { PKRS = (byte)(PKRS & 0xF | value << 4); } } + public override int Met_Location { get { return Data[0x45]; } set { Data[0x45] = (byte)value; } } + // Origins + private ushort Origins { get { return BitConverter.ToUInt16(Data, 0x46); } set { BitConverter.GetBytes(value).CopyTo(Data, 0x46); } } + public override int Version { get { return (Origins >> 7) & 0xF; } set { Origins = (ushort)((Origins & ~0x780) | ((value & 0xF) << 7));} } + public override int Ball { get { return (Origins >> 11) & 0xF; } set { Origins = (ushort)((Origins & ~0x7800) | ((value & 0xF) << 11)); } } + public override int OT_Gender { get { return (Origins >> 15) & 1; } set { Origins = (ushort)(Origins & ~(1 << 15) | ((value & 1) << 15)); } } + + public uint IV32 { get { return BitConverter.ToUInt32(Data, 0x48); } set { BitConverter.GetBytes(value).CopyTo(Data, 0x48); } } + public override int IV_HP { get { return (int)(IV32 >> 00) & 0x1F; } set { IV32 = (uint)((IV32 & ~(0x1F << 00)) | (uint)((value > 31 ? 31 : value) << 00)); } } + public override int IV_ATK { get { return (int)(IV32 >> 05) & 0x1F; } set { IV32 = (uint)((IV32 & ~(0x1F << 05)) | (uint)((value > 31 ? 31 : value) << 05)); } } + public override int IV_DEF { get { return (int)(IV32 >> 10) & 0x1F; } set { IV32 = (uint)((IV32 & ~(0x1F << 10)) | (uint)((value > 31 ? 31 : value) << 10)); } } + public override int IV_SPE { get { return (int)(IV32 >> 15) & 0x1F; } set { IV32 = (uint)((IV32 & ~(0x1F << 15)) | (uint)((value > 31 ? 31 : value) << 15)); } } + public override int IV_SPA { get { return (int)(IV32 >> 20) & 0x1F; } set { IV32 = (uint)((IV32 & ~(0x1F << 20)) | (uint)((value > 31 ? 31 : value) << 20)); } } + public override int IV_SPD { get { return (int)(IV32 >> 25) & 0x1F; } set { IV32 = (uint)((IV32 & ~(0x1F << 25)) | (uint)((value > 31 ? 31 : value) << 25)); } } + public override bool IsEgg { get { return ((IV32 >> 30) & 1) == 1; } set { IV32 = (uint)((IV32 & ~0x40000000) | (uint)(value ? 0x40000000 : 0)); } } + public int AbilityNumber { get { return (int)((IV32 >> 31) & 1); } set { IV32 = (IV32 & 0x7FFFFFFF) | (value == 1 ? 0x80000000 : 0); } } + + private uint RIB0 { get { return BitConverter.ToUInt32(Data, 0x4C); } set { BitConverter.GetBytes(value).CopyTo(Data, 0x4C); } } + public int Cool_Ribbons { get { return (int)(RIB0 >> 00) & 7; } set { RIB0 = (uint)((RIB0 & ~(7 << 00)) | (uint)(value & 7)); } } + public int Beauty_Ribbons{ get { return (int)(RIB0 >> 03) & 7; } set { RIB0 = (uint)((RIB0 & ~(7 << 03)) | (uint)(value & 7)); } } + public int Cute_Ribbons { get { return (int)(RIB0 >> 06) & 7; } set { RIB0 = (uint)((RIB0 & ~(7 << 06)) | (uint)(value & 7)); } } + public int Smart_Ribbons { get { return (int)(RIB0 >> 09) & 3; } set { RIB0 = (uint)((RIB0 & ~(7 << 09)) | (uint)(value & 7)); } } + public int Tough_Ribbons { get { return (int)(RIB0 >> 12) & 3; } set { RIB0 = (uint)((RIB0 & ~(7 << 12)) | (uint)(value & 7)); } } + public bool Champion { get { return (RIB0 & (1 << 15)) == 1 << 15; } set { RIB0 = (uint)(RIB0 & ~(1 << 15) | (uint)(value ? 1 << 0 : 0)); } } + public bool Winning { get { return (RIB0 & (1 << 16)) == 1 << 16; } set { RIB0 = (uint)(RIB0 & ~(1 << 16) | (uint)(value ? 1 << 0 : 0)); } } + public bool Victory { get { return (RIB0 & (1 << 17)) == 1 << 17; } set { RIB0 = (uint)(RIB0 & ~(1 << 17) | (uint)(value ? 1 << 0 : 0)); } } + public bool Artist { get { return (RIB0 & (1 << 18)) == 1 << 18; } set { RIB0 = (uint)(RIB0 & ~(1 << 18) | (uint)(value ? 1 << 0 : 0)); } } + public bool Effort { get { return (RIB0 & (1 << 19)) == 1 << 19; } set { RIB0 = (uint)(RIB0 & ~(1 << 19) | (uint)(value ? 1 << 0 : 0)); } } + public bool Special1 { get { return (RIB0 & (1 << 20)) == 1 << 20; } set { RIB0 = (uint)(RIB0 & ~(1 << 20) | (uint)(value ? 1 << 0 : 0)); } } + public bool Special2 { get { return (RIB0 & (1 << 21)) == 1 << 21; } set { RIB0 = (uint)(RIB0 & ~(1 << 21) | (uint)(value ? 1 << 0 : 0)); } } + public bool Special3 { get { return (RIB0 & (1 << 22)) == 1 << 22; } set { RIB0 = (uint)(RIB0 & ~(1 << 22) | (uint)(value ? 1 << 0 : 0)); } } + public bool Special4 { get { return (RIB0 & (1 << 23)) == 1 << 23; } set { RIB0 = (uint)(RIB0 & ~(1 << 23) | (uint)(value ? 1 << 0 : 0)); } } + public bool Special5 { get { return (RIB0 & (1 << 24)) == 1 << 24; } set { RIB0 = (uint)(RIB0 & ~(1 << 24) | (uint)(value ? 1 << 0 : 0)); } } + public bool Special6 { get { return (RIB0 & (1 << 25)) == 1 << 25; } set { RIB0 = (uint)(RIB0 & ~(1 << 25) | (uint)(value ? 1 << 0 : 0)); } } + public bool Special7 { get { return (RIB0 & (1 << 26)) == 1 << 26; } set { RIB0 = (uint)(RIB0 & ~(1 << 26) | (uint)(value ? 1 << 0 : 0)); } } + public bool Unused1 { get { return (RIB0 & (1 << 27)) == 1 << 27; } set { RIB0 = (uint)(RIB0 & ~(1 << 27) | (uint)(value ? 1 << 0 : 0)); } } + public bool Unused2 { get { return (RIB0 & (1 << 28)) == 1 << 28; } set { RIB0 = (uint)(RIB0 & ~(1 << 28) | (uint)(value ? 1 << 0 : 0)); } } + public bool Unused3 { get { return (RIB0 & (1 << 29)) == 1 << 29; } set { RIB0 = (uint)(RIB0 & ~(1 << 29) | (uint)(value ? 1 << 0 : 0)); } } + public bool Unused4 { get { return (RIB0 & (1 << 30)) == 1 << 30; } set { RIB0 = (uint)(RIB0 & ~(1 << 30) | (uint)(value ? 1 << 0 : 0)); } } + public override bool FatefulEncounter { get { return (RIB0 & (1 << 31)) == 1 << 31; } set { RIB0 = (RIB0 & ~(1 << 31)) | (uint)(value ? 1 << 0 : 0); } } + #endregion + + public override int Stat_Level { get { return Data[0x54]; } set { Data[0x54] = (byte)value; } } + public override int Stat_HPCurrent { get { return BitConverter.ToUInt16(Data, 0x56); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x56); } } + public override int Stat_HPMax { get { return BitConverter.ToUInt16(Data, 0x58); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x58); } } + public override int Stat_ATK { get { return BitConverter.ToUInt16(Data, 0x5A); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x5A); } } + public override int Stat_DEF { get { return BitConverter.ToUInt16(Data, 0x5C); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x5C); } } + public override int Stat_SPE { get { return BitConverter.ToUInt16(Data, 0x5E); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x5E); } } + public override int Stat_SPA { get { return BitConverter.ToUInt16(Data, 0x60); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x60); } } + public override int Stat_SPD { get { return BitConverter.ToUInt16(Data, 0x62); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x62); } } + + // Generated Attributes + public override int PSV => (int)((PID >> 16 ^ PID & 0xFFFF) >> 3); + public override int TSV => (TID ^ SID) >> 3; + public bool Japanese => Language == 1; + + public override byte[] Encrypt() + { + throw new NotImplementedException(); + } + public override bool getGenderIsValid() + { + int gv = PKX.Personal[Species].Gender; + + if (gv == 255) + return Gender == 2; + if (gv == 254) + return Gender == 0; + if (gv == 0) + return Gender == 1; + if (gv <= (PID & 0xFF)) + return Gender == 0; + if ((PID & 0xFF) < gv) + return Gender == 1; + + return false; + } + + public PK4 convertToPK4() + { + DateTime moment = DateTime.Now; + PK4 pk4 = new PK4 // Convert away! + { + PID = PID, + Species = Species, + TID = TID, + SID = SID, + EXP = IsEgg ? PKX.getEXP(5, Species) : EXP, + IsEgg = false, + OT_Friendship = 40, + Circle = Circle, + Square = Square, + Triangle = Triangle, + Heart = Heart, + Language = Language, + EV_HP = EV_HP, + EV_ATK = EV_ATK, + EV_DEF = EV_DEF, + EV_SPA = EV_SPA, + EV_SPD = EV_SPD, + EV_SPE = EV_SPE, + CNT_Cool = CNT_Cool, + CNT_Beauty = CNT_Beauty, + CNT_Cute = CNT_Cute, + CNT_Smart = CNT_Smart, + CNT_Tough = CNT_Tough, + CNT_Sheen = CNT_Sheen, + FatefulEncounter = FatefulEncounter, + Move1 = Move1, + Move2 = Move2, + Move3 = Move3, + Move4 = Move4, + Move1_PPUps = Move1_PPUps, + Move2_PPUps = Move2_PPUps, + Move3_PPUps = Move3_PPUps, + Move4_PPUps = Move4_PPUps, + Move1_PP = PKX.getMovePP(Move1, Move1_PPUps), + Move2_PP = PKX.getMovePP(Move2, Move2_PPUps), + Move3_PP = PKX.getMovePP(Move3, Move3_PPUps), + Move4_PP = PKX.getMovePP(Move4, Move4_PPUps), + IV_HP = IV_HP, + IV_ATK = IV_ATK, + IV_DEF = IV_DEF, + IV_SPA = IV_SPA, + IV_SPD = IV_SPD, + IV_SPE = IV_SPE, + Ability = PKX.Gen3Abilities[Species][Ability], + Version = Version, + Ball = Ball, + PKRS_Strain = PKRS_Strain, + PKRS_Days = PKRS_Days, + OT_Gender = OT_Gender, + Met_Year = moment.Year - 2000, + Met_Month = moment.Month, + Met_Day = moment.Day, + Met_Location = 0x37, // Pal Park + RIB6_4 = Champion, + RIB6_5 = Winning, + RIB6_6 = Victory, + RIB6_7 = Artist, + RIB7_0 = Effort, + RIB7_1 = Special1, // Battle Champion Ribbon + RIB7_2 = Special2, // Regional Champion Ribbon + RIB7_3 = Special3, // National Champion Ribbon + RIB7_4 = Special4, // Country Ribbon + RIB7_5 = Special5, // National Ribbon + RIB7_6 = Special6, // Earth Ribbon + RIB7_7 = Special7, // World Ribbon + }; + + // Remaining Ribbons + pk4.RIB4_0 |= Cool_Ribbons > 0; + pk4.RIB4_1 |= Cool_Ribbons > 1; + pk4.RIB4_2 |= Cool_Ribbons > 2; + pk4.RIB4_3 |= Cool_Ribbons > 3; + pk4.RIB4_4 |= Beauty_Ribbons > 0; + pk4.RIB4_5 |= Beauty_Ribbons > 1; + pk4.RIB4_6 |= Beauty_Ribbons > 2; + pk4.RIB4_7 |= Beauty_Ribbons > 3; + pk4.RIB5_0 |= Cute_Ribbons > 0; + pk4.RIB5_1 |= Cute_Ribbons > 1; + pk4.RIB5_2 |= Cute_Ribbons > 2; + pk4.RIB5_3 |= Cute_Ribbons > 3; + pk4.RIB5_4 |= Smart_Ribbons > 0; + pk4.RIB5_5 |= Smart_Ribbons > 1; + pk4.RIB5_6 |= Smart_Ribbons > 2; + pk4.RIB5_7 |= Smart_Ribbons > 3; + pk4.RIB6_0 |= Tough_Ribbons > 0; + pk4.RIB6_1 |= Tough_Ribbons > 1; + pk4.RIB6_2 |= Tough_Ribbons > 2; + pk4.RIB6_3 |= Tough_Ribbons > 3; + + // Yay for reusing string buffers! + PKX.G4TransferTrashBytes[pk4.Language].CopyTo(pk4.Data, 0x48 + 4); + pk4.Nickname = IsEgg ? PKX.getSpeciesName(pk4.Species, pk4.Language) : Nickname; + Array.Copy(pk4.Data, 0x48, pk4.Data, 0x68, 0x10); + pk4.OT_Name = OT_Name; + + // Set Final Data + pk4.Met_Level = PKX.getLevel(pk4.Species, pk4.EXP); + pk4.Gender = PKX.getGender(pk4.Species, pk4.PID); + pk4.IsNicknamed |= pk4.Nickname != PKX.getSpeciesName(pk4.Species, pk4.Language); + + // Unown Form + if (Species == 201) + pk4.AltForm = PKX.getUnownForm(PID); + + // Remove HM moves + int[] banned = { 15, 19, 57, 70, 148, 249, 127, 291 }; + int[] newMoves = pk4.Moves; + for (int i = 0; i < 4; i++) + if (banned.Contains(newMoves[i])) + newMoves[i] = 0; + pk4.Moves = newMoves; + pk4.FixMoves(); + + pk4.RefreshChecksum(); + return pk4; + } + } +} diff --git a/Misc/PK4.cs b/PKM/PK4.cs similarity index 65% rename from Misc/PK4.cs rename to PKM/PK4.cs index 3f6408822..007cb2b38 100644 --- a/Misc/PK4.cs +++ b/PKM/PK4.cs @@ -3,57 +3,58 @@ namespace PKHeX { - public class PK4 // 4th Generation PKM File + public class PK4 : PKM // 4th Generation PKM File { - internal const int SIZE_PARTY = 236; - internal const int SIZE_STORED = 136; - internal const int SIZE_BLOCK = 32; - + internal static readonly byte[] ExtraBytes = + { + 0x42, 0x43, 0x5E, 0x63, 0x64, 0x65, 0x66, 0x67, 0x87 + }; + public override int SIZE_PARTY => PKX.SIZE_4PARTY; + public override int SIZE_STORED => PKX.SIZE_4STORED; + public override int Format => 4; public PK4(byte[] decryptedData = null, string ident = null) { Data = (byte[])(decryptedData ?? new byte[SIZE_PARTY]).Clone(); + PKMConverter.checkEncrypted(ref Data); Identifier = ident; if (Data.Length != SIZE_PARTY) Array.Resize(ref Data, SIZE_PARTY); } + public override PKM Clone() { return new PK4(Data); } - // Internal Attributes set on creation - public byte[] Data; // Raw Storage - public string Identifier; // User or Form Custom Attribute + // Future Attributes + public override uint EncryptionConstant { get { return PID; } set { } } + public override int Nature { get { return (int)(PID%25); } set { } } + public override int CurrentFriendship { get { return OT_Friendship; } set { OT_Friendship = value; } } + public override int CurrentHandler { get { return 0; } set { } } // Structure - public uint PID { get { return BitConverter.ToUInt32(Data, 0x00); } set { BitConverter.GetBytes(value).CopyTo(Data, 0x00); } } - public ushort Sanity { get { return BitConverter.ToUInt16(Data, 0x04); } set { BitConverter.GetBytes(value).CopyTo(Data, 0x04); } } - public ushort Checksum { get { return BitConverter.ToUInt16(Data, 0x06); } set { BitConverter.GetBytes(value).CopyTo(Data, 0x06); } } - + public override uint PID { get { return BitConverter.ToUInt32(Data, 0x00); } set { BitConverter.GetBytes(value).CopyTo(Data, 0x00); } } + public override ushort Sanity { get { return BitConverter.ToUInt16(Data, 0x04); } set { BitConverter.GetBytes(value).CopyTo(Data, 0x04); } } + public override ushort Checksum { get { return BitConverter.ToUInt16(Data, 0x06); } set { BitConverter.GetBytes(value).CopyTo(Data, 0x06); } } + #region Block A - public int Species { get { return BitConverter.ToUInt16(Data, 0x08); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x08); } } - public int HeldItem { get { return BitConverter.ToUInt16(Data, 0x0A); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x0A); } } - public int TID { get { return BitConverter.ToUInt16(Data, 0x0C); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x0C); } } - public int SID { get { return BitConverter.ToUInt16(Data, 0x0E); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x0E); } } - public uint EXP { get { return BitConverter.ToUInt32(Data, 0x10); } set { BitConverter.GetBytes(value).CopyTo(Data, 0x10); } } - public int Friendship { get { return Data[0x14]; } set { Data[0x14] = (byte)value; } } - public int Ability { get { return Data[0x15]; } set { Data[0x15] = (byte)value; } } - public byte Markings { get { return Data[0x16]; } set { Data[0x16] = value; } } - public bool Circle { get { return (Markings & (1 << 0)) == 1 << 0; } set { Markings = (byte)(Markings & ~(1 << 0) | (value ? 1 << 0 : 0)); } } - public bool Triangle { get { return (Markings & (1 << 1)) == 1 << 1; } set { Markings = (byte)(Markings & ~(1 << 1) | (value ? 1 << 1 : 0)); } } - public bool Square { get { return (Markings & (1 << 2)) == 1 << 2; } set { Markings = (byte)(Markings & ~(1 << 2) | (value ? 1 << 2 : 0)); } } - public bool Heart { get { return (Markings & (1 << 3)) == 1 << 3; } set { Markings = (byte)(Markings & ~(1 << 3) | (value ? 1 << 3 : 0)); } } - public bool Star { get { return (Markings & (1 << 4)) == 1 << 4; } set { Markings = (byte)(Markings & ~(1 << 4) | (value ? 1 << 4 : 0)); } } - public bool Diamond { get { return (Markings & (1 << 5)) == 1 << 5; } set { Markings = (byte)(Markings & ~(1 << 5) | (value ? 1 << 5 : 0)); } } - public int Language { get { return Data[0x17]; } set { Data[0x17] = (byte)value; } } - public int EV_HP { get { return Data[0x18]; } set { Data[0x18] = (byte)value; } } - public int EV_ATK { get { return Data[0x19]; } set { Data[0x19] = (byte)value; } } - public int EV_DEF { get { return Data[0x1A]; } set { Data[0x1A] = (byte)value; } } - public int EV_SPE { get { return Data[0x1B]; } set { Data[0x1B] = (byte)value; } } - public int EV_SPA { get { return Data[0x1C]; } set { Data[0x1C] = (byte)value; } } - public int EV_SPD { get { return Data[0x1D]; } set { Data[0x1D] = (byte)value; } } - public int CNT_Cool { get { return Data[0x1E]; } set { Data[0x1E] = (byte)value; } } - public int CNT_Beauty { get { return Data[0x1F]; } set { Data[0x1F] = (byte)value; } } - public int CNT_Cute { get { return Data[0x20]; } set { Data[0x20] = (byte)value; } } - public int CNT_Smart { get { return Data[0x21]; } set { Data[0x21] = (byte)value; } } - public int CNT_Tough { get { return Data[0x22]; } set { Data[0x22] = (byte)value; } } - public int CNT_Sheen { get { return Data[0x23]; } set { Data[0x23] = (byte)value; } } + public override int Species { get { return BitConverter.ToUInt16(Data, 0x08); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x08); } } + public override int HeldItem { get { return BitConverter.ToUInt16(Data, 0x0A); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x0A); } } + public override int TID { get { return BitConverter.ToUInt16(Data, 0x0C); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x0C); } } + public override int SID { get { return BitConverter.ToUInt16(Data, 0x0E); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x0E); } } + public override uint EXP { get { return BitConverter.ToUInt32(Data, 0x10); } set { BitConverter.GetBytes(value).CopyTo(Data, 0x10); } } + public override int OT_Friendship { get { return Data[0x14]; } set { Data[0x14] = (byte)value; } } + public override int Ability { get { return Data[0x15]; } set { Data[0x15] = (byte)value; } } + public override byte MarkByte { get { return Data[0x16]; } protected set { Data[0x16] = value; } } + public override int Language { get { return Data[0x17]; } set { Data[0x17] = (byte)value; } } + public override int EV_HP { get { return Data[0x18]; } set { Data[0x18] = (byte)value; } } + public override int EV_ATK { get { return Data[0x19]; } set { Data[0x19] = (byte)value; } } + public override int EV_DEF { get { return Data[0x1A]; } set { Data[0x1A] = (byte)value; } } + public override int EV_SPE { get { return Data[0x1B]; } set { Data[0x1B] = (byte)value; } } + public override int EV_SPA { get { return Data[0x1C]; } set { Data[0x1C] = (byte)value; } } + public override int EV_SPD { get { return Data[0x1D]; } set { Data[0x1D] = (byte)value; } } + public override int CNT_Cool { get { return Data[0x1E]; } set { Data[0x1E] = (byte)value; } } + public override int CNT_Beauty { get { return Data[0x1F]; } set { Data[0x1F] = (byte)value; } } + public override int CNT_Cute { get { return Data[0x20]; } set { Data[0x20] = (byte)value; } } + public override int CNT_Smart { get { return Data[0x21]; } set { Data[0x21] = (byte)value; } } + public override int CNT_Tough { get { return Data[0x22]; } set { Data[0x22] = (byte)value; } } + public override int CNT_Sheen { get { return Data[0x23]; } set { Data[0x23] = (byte)value; } } private byte RIB0 { get { return Data[0x24]; } set { Data[0x24] = value; } } // Sinnoh 1 public bool RIB0_0 { get { return (RIB0 & (1 << 0)) == 1 << 0; } set { RIB0 = (byte)(RIB0 & ~(1 << 0) | (value ? 1 << 0 : 0)); } } // Sinnoh Champ Ribbon @@ -94,27 +95,27 @@ public PK4(byte[] decryptedData = null, string ident = null) #endregion #region Block B - public int Move1 { get { return BitConverter.ToUInt16(Data, 0x28); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x28); } } - public int Move2 { get { return BitConverter.ToUInt16(Data, 0x2A); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x2A); } } - public int Move3 { get { return BitConverter.ToUInt16(Data, 0x2C); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x2C); } } - public int Move4 { get { return BitConverter.ToUInt16(Data, 0x2E); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x2E); } } - public int Move1_PP { get { return Data[0x30]; } set { Data[0x30] = (byte)value; } } - public int Move2_PP { get { return Data[0x31]; } set { Data[0x31] = (byte)value; } } - public int Move3_PP { get { return Data[0x32]; } set { Data[0x32] = (byte)value; } } - public int Move4_PP { get { return Data[0x33]; } set { Data[0x33] = (byte)value; } } - public int Move1_PPUps { get { return Data[0x34]; } set { Data[0x34] = (byte)value; } } - public int Move2_PPUps { get { return Data[0x35]; } set { Data[0x35] = (byte)value; } } - public int Move3_PPUps { get { return Data[0x36]; } set { Data[0x36] = (byte)value; } } - public int Move4_PPUps { get { return Data[0x37]; } set { Data[0x37] = (byte)value; } } + public override int Move1 { get { return BitConverter.ToUInt16(Data, 0x28); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x28); } } + public override int Move2 { get { return BitConverter.ToUInt16(Data, 0x2A); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x2A); } } + public override int Move3 { get { return BitConverter.ToUInt16(Data, 0x2C); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x2C); } } + public override int Move4 { get { return BitConverter.ToUInt16(Data, 0x2E); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x2E); } } + public override int Move1_PP { get { return Data[0x30]; } set { Data[0x30] = (byte)value; } } + public override int Move2_PP { get { return Data[0x31]; } set { Data[0x31] = (byte)value; } } + public override int Move3_PP { get { return Data[0x32]; } set { Data[0x32] = (byte)value; } } + public override int Move4_PP { get { return Data[0x33]; } set { Data[0x33] = (byte)value; } } + public override int Move1_PPUps { get { return Data[0x34]; } set { Data[0x34] = (byte)value; } } + public override int Move2_PPUps { get { return Data[0x35]; } set { Data[0x35] = (byte)value; } } + public override int Move3_PPUps { get { return Data[0x36]; } set { Data[0x36] = (byte)value; } } + public override int Move4_PPUps { get { return Data[0x37]; } set { Data[0x37] = (byte)value; } } public uint IV32 { get { return BitConverter.ToUInt32(Data, 0x38); } set { BitConverter.GetBytes(value).CopyTo(Data, 0x38); } } - public int IV_HP { get { return (int)(IV32 >> 00) & 0x1F; } set { IV32 = (uint)((IV32 & ~(0x1F << 00)) | (uint)((value > 31 ? 31 : value) << 00)); } } - public int IV_ATK { get { return (int)(IV32 >> 05) & 0x1F; } set { IV32 = (uint)((IV32 & ~(0x1F << 05)) | (uint)((value > 31 ? 31 : value) << 05)); } } - public int IV_DEF { get { return (int)(IV32 >> 10) & 0x1F; } set { IV32 = (uint)((IV32 & ~(0x1F << 10)) | (uint)((value > 31 ? 31 : value) << 10)); } } - public int IV_SPE { get { return (int)(IV32 >> 15) & 0x1F; } set { IV32 = (uint)((IV32 & ~(0x1F << 15)) | (uint)((value > 31 ? 31 : value) << 15)); } } - public int IV_SPA { get { return (int)(IV32 >> 20) & 0x1F; } set { IV32 = (uint)((IV32 & ~(0x1F << 20)) | (uint)((value > 31 ? 31 : value) << 20)); } } - public int IV_SPD { get { return (int)(IV32 >> 25) & 0x1F; } set { IV32 = (uint)((IV32 & ~(0x1F << 25)) | (uint)((value > 31 ? 31 : value) << 25)); } } - public bool IsEgg { get { return ((IV32 >> 30) & 1) == 1; } set { IV32 = (uint)((IV32 & ~0x40000000) | (uint)(value ? 0x40000000 : 0)); } } - public bool IsNicknamed { get { return ((IV32 >> 31) & 1) == 1; } set { IV32 = (IV32 & 0x7FFFFFFF) | (value ? 0x80000000 : 0); } } + public override int IV_HP { get { return (int)(IV32 >> 00) & 0x1F; } set { IV32 = (uint)((IV32 & ~(0x1F << 00)) | (uint)((value > 31 ? 31 : value) << 00)); } } + public override int IV_ATK { get { return (int)(IV32 >> 05) & 0x1F; } set { IV32 = (uint)((IV32 & ~(0x1F << 05)) | (uint)((value > 31 ? 31 : value) << 05)); } } + public override int IV_DEF { get { return (int)(IV32 >> 10) & 0x1F; } set { IV32 = (uint)((IV32 & ~(0x1F << 10)) | (uint)((value > 31 ? 31 : value) << 10)); } } + public override int IV_SPE { get { return (int)(IV32 >> 15) & 0x1F; } set { IV32 = (uint)((IV32 & ~(0x1F << 15)) | (uint)((value > 31 ? 31 : value) << 15)); } } + public override int IV_SPA { get { return (int)(IV32 >> 20) & 0x1F; } set { IV32 = (uint)((IV32 & ~(0x1F << 20)) | (uint)((value > 31 ? 31 : value) << 20)); } } + public override int IV_SPD { get { return (int)(IV32 >> 25) & 0x1F; } set { IV32 = (uint)((IV32 & ~(0x1F << 25)) | (uint)((value > 31 ? 31 : value) << 25)); } } + public override bool IsEgg { get { return ((IV32 >> 30) & 1) == 1; } set { IV32 = (uint)((IV32 & ~0x40000000) | (uint)(value ? 0x40000000 : 0)); } } + public override bool IsNicknamed { get { return ((IV32 >> 31) & 1) == 1; } set { IV32 = (IV32 & 0x7FFFFFFF) | (value ? 0x80000000 : 0); } } private byte RIB4 { get { return Data[0x3C]; } set { Data[0x3C] = value; } } // Hoenn 1a public bool RIB4_0 { get { return (RIB4 & (1 << 0)) == 1 << 0; } set { RIB4 = (byte)(RIB4 & ~(1 << 0) | (value ? 1 << 0 : 0)); } } // Cool Ribbon @@ -153,18 +154,18 @@ public PK4(byte[] decryptedData = null, string ident = null) public bool RIB7_6 { get { return (RIB7 & (1 << 6)) == 1 << 6; } set { RIB7 = (byte)(RIB7 & ~(1 << 6) | (value ? 1 << 6 : 0)); } } // Earth Ribbon public bool RIB7_7 { get { return (RIB7 & (1 << 7)) == 1 << 7; } set { RIB7 = (byte)(RIB7 & ~(1 << 7) | (value ? 1 << 7 : 0)); } } // World Ribbon - public bool FatefulEncounter { get { return (Data[0x40] & 1) == 1; } set { Data[0x40] = (byte)(Data[0x40] & ~0x01 | (value ? 1 : 0)); } } - public int Gender { get { return (Data[0x40] >> 1) & 0x3; } set { Data[0x40] = (byte)(Data[0x40] & ~0x06 | (value << 1)); } } - public int AltForm { get { return Data[0x40] >> 3; } set { Data[0x40] = (byte)(Data[0x40] & 0x07 | (value << 3)); } } + public override bool FatefulEncounter { get { return (Data[0x40] & 1) == 1; } set { Data[0x40] = (byte)(Data[0x40] & ~0x01 | (value ? 1 : 0)); } } + public override int Gender { get { return (Data[0x40] >> 1) & 0x3; } set { Data[0x40] = (byte)(Data[0x40] & ~0x06 | (value << 1)); } } + public override int AltForm { get { return Data[0x40] >> 3; } set { Data[0x40] = (byte)(Data[0x40] & 0x07 | (value << 3)); } } // 0x43-0x47 Unused #endregion #region Block C - public string Nickname + public override string Nickname { get { - return PKM.array2strG4(Data.Skip(0x48).Take(22).ToArray()) + return PKX.array2strG4(Data.Skip(0x48).Take(22).ToArray()) .Replace("\uE08F", "\u2640") // nidoran .Replace("\uE08E", "\u2642") // nidoran .Replace("\u2019", "\u0027"); // farfetch'd @@ -177,11 +178,11 @@ public string Nickname .Replace("\u2640", "\uE08F") // nidoran .Replace("\u2642", "\uE08E") // nidoran .Replace("\u0027", "\u2019"); // farfetch'd - PKM.str2arrayG4(TempNick).CopyTo(Data, 0x48); + PKX.str2arrayG4(TempNick).CopyTo(Data, 0x48); } } // 0x5E unused - public int Version { get { return Data[0x5F]; } set { Data[0x5F] = (byte)value; } } + public override int Version { get { return Data[0x5F]; } set { Data[0x5F] = (byte)value; } } private byte RIB8 { get { return Data[0x60]; } set { Data[0x60] = value; } } // Sinnoh 3 public bool RIB8_0 { get { return (RIB8 & (1 << 0)) == 1 << 0; } set { RIB8 = (byte)(RIB8 & ~(1 << 0) | (value ? 1 << 0 : 0)); } } // Cool Ribbon public bool RIB8_1 { get { return (RIB8 & (1 << 1)) == 1 << 1; } set { RIB8 = (byte)(RIB8 & ~(1 << 1) | (value ? 1 << 1 : 0)); } } // Cool Ribbon Great @@ -222,11 +223,11 @@ public string Nickname #endregion #region Block D - public string OT_Name + public override string OT_Name { get { - return PKM.array2strG4(Data.Skip(0x68).Take(16).ToArray()) + return PKX.array2strG4(Data.Skip(0x68).Take(16).ToArray()) .Replace("\uE08F", "\u2640") // Nidoran ♂ .Replace("\uE08E", "\u2642") // Nidoran ♀ .Replace("\u2019", "\u0027"); // Farfetch'd @@ -239,65 +240,85 @@ public string OT_Name .Replace("\u2640", "\uE08F") // Nidoran ♂ .Replace("\u2642", "\uE08E") // Nidoran ♀ .Replace("\u0027", "\u2019"); // Farfetch'd - PKM.str2arrayG4(TempNick).CopyTo(Data, 0x68); + PKX.str2arrayG4(TempNick).CopyTo(Data, 0x68); + } + } + public override int Egg_Year { get { return Data[0x78]; } set { Data[0x78] = (byte)value; } } + public override int Egg_Month { get { return Data[0x79]; } set { Data[0x79] = (byte)value; } } + public override int Egg_Day { get { return Data[0x7A]; } set { Data[0x7A] = (byte)value; } } + public override int Met_Year { get { return Data[0x7B]; } set { Data[0x7B] = (byte)value; } } + public override int Met_Month { get { return Data[0x7C]; } set { Data[0x7C] = (byte)value; } } + public override int Met_Day { get { return Data[0x7D]; } set { Data[0x7D] = (byte)value; } } + + public override int Egg_Location + { + get + { + ushort hgssloc = BitConverter.ToUInt16(Data, 0x44); + if (hgssloc != 0) + return hgssloc; + return BitConverter.ToUInt16(Data, 0x7E); + } + set + { + if (PtHGSS) + { + BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x44); + BitConverter.GetBytes(0x7D0).CopyTo(Data, 0x7E); + } + else + { + BitConverter.GetBytes((ushort)0).CopyTo(Data, 0x44); + BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x7E); + } + } + } + public override int Met_Location + { + get + { + ushort hgssloc = BitConverter.ToUInt16(Data, 0x46); + if (hgssloc != 0) + return hgssloc; + return BitConverter.ToUInt16(Data, 0x80); + } + set + { + if (PtHGSS) + { + BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x46); + BitConverter.GetBytes(0x7D0).CopyTo(Data, 0x80); + } + else + { + BitConverter.GetBytes((ushort)0).CopyTo(Data, 0x46); + BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x80); + } } } - public int Egg_Year { get { return Data[0x78]; } set { Data[0x78] = (byte)value; } } - public int Egg_Month { get { return Data[0x79]; } set { Data[0x79] = (byte)value; } } - public int Egg_Day { get { return Data[0x7A]; } set { Data[0x7A] = (byte)value; } } - public int Met_Year { get { return Data[0x7B]; } set { Data[0x7B] = (byte)value; } } - public int Met_Month { get { return Data[0x7C]; } set { Data[0x7C] = (byte)value; } } - public int Met_Day { get { return Data[0x7D]; } set { Data[0x7D] = (byte)value; } } - public int Egg_Location { get { return BitConverter.ToUInt16(Data, 0x7E); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x7E); } } - public int Met_Location { get { return BitConverter.ToUInt16(Data, 0x80); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x80); } } private byte PKRS { get { return Data[0x82]; } set { Data[0x82] = value; } } - public int PKRS_Days { get { return PKRS & 0xF; } set { PKRS = (byte)(PKRS & ~0xF | value); } } - public int PKRS_Strain { get { return PKRS >> 4; } set { PKRS = (byte)(PKRS & 0xF | (value << 4)); } } - public int Ball { get { return Data[0x83]; } set { Data[0x83] = (byte)value; } } - public int Met_Level { get { return Data[0x84] & ~0x80; } set { Data[0x84] = (byte)((Data[0x84] & 0x80) | value); } } - public int OT_Gender { get { return Data[0x84] >> 7; } set { Data[0x84] = (byte)((Data[0x84] & ~0x80) | value << 7); } } - public int EncounterType { get { return Data[0x85]; } set { Data[0x85] = (byte)value; } } + public override int PKRS_Days { get { return PKRS & 0xF; } set { PKRS = (byte)(PKRS & ~0xF | value); } } + public override int PKRS_Strain { get { return PKRS >> 4; } set { PKRS = (byte)(PKRS & 0xF | (value << 4)); } } + public override int Ball { get { return Data[0x83]; } set { Data[0x83] = (byte)value; } } + public override int Met_Level { get { return Data[0x84] & ~0x80; } set { Data[0x84] = (byte)((Data[0x84] & 0x80) | value); } } + public override int OT_Gender { get { return Data[0x84] >> 7; } set { Data[0x84] = (byte)((Data[0x84] & ~0x80) | value << 7); } } + public override int EncounterType { get { return Data[0x85]; } set { Data[0x85] = (byte)value; } } public int HGSSBall { get { return Data[0x86]; } set { Data[0x86] = (byte)value; } } // Unused 0x87 #endregion - // Simple Generated Attributes - public int[] IVs - { - get { return new[] { IV_HP, IV_ATK, IV_DEF, IV_SPE, IV_SPA, IV_SPD }; } - set - { - if (value == null || value.Length != 6) return; - IV_HP = value[0]; IV_ATK = value[1]; IV_DEF = value[2]; - IV_SPE = value[3]; IV_SPA = value[4]; IV_SPD = value[5]; - } - } - public int[] EVs => new[] { EV_HP, EV_ATK, EV_DEF, EV_SPE, EV_SPA, EV_SPD }; - public int PSV => (int)((PID >> 16 ^ PID & 0xFFFF) >> 3); - public int TSV => (TID ^ SID) >> 3; - public bool IsShiny => TSV == PSV; - public bool PKRS_Infected => PKRS_Strain > 0; - public bool PKRS_Cured => PKRS_Days == 0 && PKRS_Strain > 0; - public bool Gen4 => Version >= 10 && Version < 12 || Version >= 7 && Version <= 8; - public bool Gen3 => Version >= 1 && Version <= 5 || Version == 15; - public bool GenU => !(Gen4 || Gen3); + public override int Stat_Level { get { return Data[0x8C]; } set { Data[0x8C] = (byte)value; } } + public override int Stat_HPCurrent { get { return BitConverter.ToUInt16(Data, 0x8E); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x8E); } } + public override int Stat_HPMax { get { return BitConverter.ToUInt16(Data, 0x90); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x90); } } + public override int Stat_ATK { get { return BitConverter.ToUInt16(Data, 0x92); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x92); } } + public override int Stat_DEF { get { return BitConverter.ToUInt16(Data, 0x94); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x94); } } + public override int Stat_SPE { get { return BitConverter.ToUInt16(Data, 0x96); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x96); } } + public override int Stat_SPA { get { return BitConverter.ToUInt16(Data, 0x98); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x98); } } + public override int Stat_SPD { get { return BitConverter.ToUInt16(Data, 0x9A); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x9A); } } - public int[] Moves - { - get { return new[] { Move1, Move2, Move3, Move4 }; } - set - { - if (value.Length > 0) Move1 = value[0]; - if (value.Length > 1) Move2 = value[1]; - if (value.Length > 2) Move3 = value[2]; - if (value.Length > 3) Move4 = value[3]; - } - } - - // Complex Generated Attributes - public byte[] EncryptedPartyData => Encrypt().Take(SIZE_PARTY).ToArray(); - public byte[] EncryptedBoxData => Encrypt().Take(SIZE_STORED).ToArray(); - public int Characteristic + public override int PSV => (int)((PID >> 16 ^ PID & 0xFFFF) >> 3); + public override int TSV => (TID ^ SID) >> 3; + public override int Characteristic { get { @@ -315,40 +336,9 @@ public int Characteristic return pm6stat * 5 + maxIV % 5; } } - public int PotentialRating - { - get - { - int ivTotal = IVs.Sum(); - if (ivTotal <= 90) - return 0; - if (ivTotal <= 120) - return 1; - return ivTotal <= 150 ? 2 : 3; - } - } - public string FileName => $"{Species.ToString("000")}{(IsShiny ? " ★" : "")} - {Nickname} - {Checksum.ToString("X4")}{PID.ToString("X8")}.pkm"; - public bool ChecksumValid => Checksum == CalculateChecksum(); - + // Methods - public void RefreshChecksum() - { - Checksum = CalculateChecksum(); - } - public ushort CalculateChecksum() - { - ushort chk = 0; - for (int i = 8; i < SIZE_STORED; i += 2) // Loop through the entire PK6 - chk += BitConverter.ToUInt16(Data, i); - - return chk; - } - public byte[] Write() - { - RefreshChecksum(); - return Data; - } - public bool getGenderIsValid() + public override bool getGenderIsValid() { int gv = PKX.Personal[Species].Gender; @@ -365,34 +355,10 @@ public bool getGenderIsValid() return false; } - public void FixMoves() + public override byte[] Encrypt() { - if (Move4 != 0 && Move3 == 0) - { - Move3 = Move4; - Move3_PP = Move4_PP; - Move3_PPUps = Move4_PPUps; - Move4 = Move4_PP = Move4_PPUps = 0; - } - if (Move3 != 0 && Move2 == 0) - { - Move2 = Move3; - Move2_PP = Move3_PP; - Move2_PPUps = Move3_PPUps; - Move3 = Move3_PP = Move3_PPUps = 0; - } - if (Move2 != 0 && Move1 == 0) - { - Move1 = Move2; - Move1_PP = Move2_PP; - Move1_PPUps = Move2_PPUps; - Move2 = Move2_PP = Move2_PPUps = 0; - } - } - public byte[] Encrypt() - { - Checksum = CalculateChecksum(); - return PKM.encryptArray(Data); + RefreshChecksum(); + return PKX.encryptArray45(Data); } public PK5 convertToPK5() @@ -406,7 +372,7 @@ public PK5 convertToPK5() PK5 pk5 = new PK5(Data) // Convert away! { HeldItem = 0, - Friendship = 70, + OT_Friendship = 70, // Apply new met date Met_Year = moment.Year - 2000, Met_Month = moment.Month, @@ -420,7 +386,7 @@ public PK5 convertToPK5() pk5.Move4_PP = PKX.getMovePP(pk5.Move4_PP, pk5.Move4_PPUps); // Disassociate Nature and PID - pk5.Nature = (int)(pk5.PID % 0x19); + pk5.Nature = (int)(pk5.PID % 25); // Delete Platinum/HGSS Met Location Data BitConverter.GetBytes((uint)0).CopyTo(pk5.Data, 0x44); diff --git a/Misc/PK5.cs b/PKM/PK5.cs similarity index 71% rename from Misc/PK5.cs rename to PKM/PK5.cs index 432f13d57..89c5c389a 100644 --- a/Misc/PK5.cs +++ b/PKM/PK5.cs @@ -6,55 +6,55 @@ namespace PKHeX { public class PK5 : PKM // 5th Generation PKM File { - internal const int SIZE_PARTY = 220; - internal const int SIZE_STORED = 136; - internal const int SIZE_BLOCK = 32; - + internal static readonly byte[] ExtraBytes = + { + 0x42, 0x43, 0x5E, 0x63, 0x64, 0x65, 0x66, 0x67, 0x87 + }; + public override int SIZE_PARTY => PKX.SIZE_5PARTY; + public override int SIZE_STORED => PKX.SIZE_5STORED; + public override int Format => 5; public PK5(byte[] decryptedData = null, string ident = null) { Data = (byte[])(decryptedData ?? new byte[SIZE_PARTY]).Clone(); + PKMConverter.checkEncrypted(ref Data); Identifier = ident; if (Data.Length != SIZE_PARTY) Array.Resize(ref Data, SIZE_PARTY); } + public override PKM Clone() { return new PK5(Data); } - // Internal Attributes set on creation - public byte[] Data; // Raw Storage - public string Identifier; // User or Form Custom Attribute + // Future Attributes + public override uint EncryptionConstant { get { return PID; } set { } } + public override int CurrentFriendship { get { return OT_Friendship; } set { OT_Friendship = value; } } + public override int CurrentHandler { get { return 0; } set { } } // Structure - public uint PID { get { return BitConverter.ToUInt32(Data, 0x00); } set { BitConverter.GetBytes(value).CopyTo(Data, 0x00); } } - public ushort Sanity { get { return BitConverter.ToUInt16(Data, 0x04); } set { BitConverter.GetBytes(value).CopyTo(Data, 0x04); } } - public ushort Checksum { get { return BitConverter.ToUInt16(Data, 0x06); } set { BitConverter.GetBytes(value).CopyTo(Data, 0x06); } } + public override uint PID { get { return BitConverter.ToUInt32(Data, 0x00); } set { BitConverter.GetBytes(value).CopyTo(Data, 0x00); } } + public override ushort Sanity { get { return BitConverter.ToUInt16(Data, 0x04); } set { BitConverter.GetBytes(value).CopyTo(Data, 0x04); } } + public override ushort Checksum { get { return BitConverter.ToUInt16(Data, 0x06); } set { BitConverter.GetBytes(value).CopyTo(Data, 0x06); } } #region Block A - public int Species { get { return BitConverter.ToUInt16(Data, 0x08); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x08); } } - public int HeldItem { get { return BitConverter.ToUInt16(Data, 0x0A); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x0A); } } - public int TID { get { return BitConverter.ToUInt16(Data, 0x0C); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x0C); } } - public int SID { get { return BitConverter.ToUInt16(Data, 0x0E); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x0E); } } - public uint EXP { get { return BitConverter.ToUInt32(Data, 0x10); } set { BitConverter.GetBytes(value).CopyTo(Data, 0x10); } } - public int Friendship { get { return Data[0x14]; } set { Data[0x14] = (byte)value; } } - public int Ability { get { return Data[0x15]; } set { Data[0x15] = (byte)value; } } - public byte Markings { get { return Data[0x16]; } set { Data[0x16] = value; } } - public bool Circle { get { return (Markings & (1 << 0)) == 1 << 0; } set { Markings = (byte)(Markings & ~(1 << 0) | (value ? 1 << 0 : 0)); } } - public bool Triangle { get { return (Markings & (1 << 1)) == 1 << 1; } set { Markings = (byte)(Markings & ~(1 << 1) | (value ? 1 << 1 : 0)); } } - public bool Square { get { return (Markings & (1 << 2)) == 1 << 2; } set { Markings = (byte)(Markings & ~(1 << 2) | (value ? 1 << 2 : 0)); } } - public bool Heart { get { return (Markings & (1 << 3)) == 1 << 3; } set { Markings = (byte)(Markings & ~(1 << 3) | (value ? 1 << 3 : 0)); } } - public bool Star { get { return (Markings & (1 << 4)) == 1 << 4; } set { Markings = (byte)(Markings & ~(1 << 4) | (value ? 1 << 4 : 0)); } } - public bool Diamond { get { return (Markings & (1 << 5)) == 1 << 5; } set { Markings = (byte)(Markings & ~(1 << 5) | (value ? 1 << 5 : 0)); } } - public int Language { get { return Data[0x17]; } set { Data[0x17] = (byte)value; } } - public int EV_HP { get { return Data[0x18]; } set { Data[0x18] = (byte)value; } } - public int EV_ATK { get { return Data[0x19]; } set { Data[0x19] = (byte)value; } } - public int EV_DEF { get { return Data[0x1A]; } set { Data[0x1A] = (byte)value; } } - public int EV_SPE { get { return Data[0x1B]; } set { Data[0x1B] = (byte)value; } } - public int EV_SPA { get { return Data[0x1C]; } set { Data[0x1C] = (byte)value; } } - public int EV_SPD { get { return Data[0x1D]; } set { Data[0x1D] = (byte)value; } } - public int CNT_Cool { get { return Data[0x1E]; } set { Data[0x1E] = (byte)value; } } - public int CNT_Beauty { get { return Data[0x1F]; } set { Data[0x1F] = (byte)value; } } - public int CNT_Cute { get { return Data[0x20]; } set { Data[0x20] = (byte)value; } } - public int CNT_Smart { get { return Data[0x21]; } set { Data[0x21] = (byte)value; } } - public int CNT_Tough { get { return Data[0x22]; } set { Data[0x22] = (byte)value; } } - public int CNT_Sheen { get { return Data[0x23]; } set { Data[0x23] = (byte)value; } } + public override int Species { get { return BitConverter.ToUInt16(Data, 0x08); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x08); } } + public override int HeldItem { get { return BitConverter.ToUInt16(Data, 0x0A); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x0A); } } + public override int TID { get { return BitConverter.ToUInt16(Data, 0x0C); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x0C); } } + public override int SID { get { return BitConverter.ToUInt16(Data, 0x0E); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x0E); } } + public override uint EXP { get { return BitConverter.ToUInt32(Data, 0x10); } set { BitConverter.GetBytes(value).CopyTo(Data, 0x10); } } + public override int OT_Friendship { get { return Data[0x14]; } set { Data[0x14] = (byte)value; } } + public override int Ability { get { return Data[0x15]; } set { Data[0x15] = (byte)value; } } + public override byte MarkByte { get { return Data[0x16]; } protected set { Data[0x16] = value; } } + public override int Language { get { return Data[0x17]; } set { Data[0x17] = (byte)value; } } + public override int EV_HP { get { return Data[0x18]; } set { Data[0x18] = (byte)value; } } + public override int EV_ATK { get { return Data[0x19]; } set { Data[0x19] = (byte)value; } } + public override int EV_DEF { get { return Data[0x1A]; } set { Data[0x1A] = (byte)value; } } + public override int EV_SPE { get { return Data[0x1B]; } set { Data[0x1B] = (byte)value; } } + public override int EV_SPA { get { return Data[0x1C]; } set { Data[0x1C] = (byte)value; } } + public override int EV_SPD { get { return Data[0x1D]; } set { Data[0x1D] = (byte)value; } } + public override int CNT_Cool { get { return Data[0x1E]; } set { Data[0x1E] = (byte)value; } } + public override int CNT_Beauty { get { return Data[0x1F]; } set { Data[0x1F] = (byte)value; } } + public override int CNT_Cute { get { return Data[0x20]; } set { Data[0x20] = (byte)value; } } + public override int CNT_Smart { get { return Data[0x21]; } set { Data[0x21] = (byte)value; } } + public override int CNT_Tough { get { return Data[0x22]; } set { Data[0x22] = (byte)value; } } + public override int CNT_Sheen { get { return Data[0x23]; } set { Data[0x23] = (byte)value; } } private byte RIB0 { get { return Data[0x24]; } set { Data[0x24] = value; } } // Sinnoh 1 public bool RIB0_0 { get { return (RIB0 & (1 << 0)) == 1 << 0; } set { RIB0 = (byte)(RIB0 & ~(1 << 0) | (value ? 1 << 0 : 0)); } } // Sinnoh Champ Ribbon @@ -95,27 +95,27 @@ public PK5(byte[] decryptedData = null, string ident = null) #endregion #region Block B - public int Move1 { get { return BitConverter.ToUInt16(Data, 0x28); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x28); } } - public int Move2 { get { return BitConverter.ToUInt16(Data, 0x2A); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x2A); } } - public int Move3 { get { return BitConverter.ToUInt16(Data, 0x2C); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x2C); } } - public int Move4 { get { return BitConverter.ToUInt16(Data, 0x2E); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x2E); } } - public int Move1_PP { get { return Data[0x30]; } set { Data[0x30] = (byte)value; } } - public int Move2_PP { get { return Data[0x31]; } set { Data[0x31] = (byte)value; } } - public int Move3_PP { get { return Data[0x32]; } set { Data[0x32] = (byte)value; } } - public int Move4_PP { get { return Data[0x33]; } set { Data[0x33] = (byte)value; } } - public int Move1_PPUps { get { return Data[0x34]; } set { Data[0x34] = (byte)value; } } - public int Move2_PPUps { get { return Data[0x35]; } set { Data[0x35] = (byte)value; } } - public int Move3_PPUps { get { return Data[0x36]; } set { Data[0x36] = (byte)value; } } - public int Move4_PPUps { get { return Data[0x37]; } set { Data[0x37] = (byte)value; } } + public override int Move1 { get { return BitConverter.ToUInt16(Data, 0x28); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x28); } } + public override int Move2 { get { return BitConverter.ToUInt16(Data, 0x2A); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x2A); } } + public override int Move3 { get { return BitConverter.ToUInt16(Data, 0x2C); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x2C); } } + public override int Move4 { get { return BitConverter.ToUInt16(Data, 0x2E); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x2E); } } + public override int Move1_PP { get { return Data[0x30]; } set { Data[0x30] = (byte)value; } } + public override int Move2_PP { get { return Data[0x31]; } set { Data[0x31] = (byte)value; } } + public override int Move3_PP { get { return Data[0x32]; } set { Data[0x32] = (byte)value; } } + public override int Move4_PP { get { return Data[0x33]; } set { Data[0x33] = (byte)value; } } + public override int Move1_PPUps { get { return Data[0x34]; } set { Data[0x34] = (byte)value; } } + public override int Move2_PPUps { get { return Data[0x35]; } set { Data[0x35] = (byte)value; } } + public override int Move3_PPUps { get { return Data[0x36]; } set { Data[0x36] = (byte)value; } } + public override int Move4_PPUps { get { return Data[0x37]; } set { Data[0x37] = (byte)value; } } private uint IV32 { get { return BitConverter.ToUInt32(Data, 0x38); } set { BitConverter.GetBytes(value).CopyTo(Data, 0x38); } } - public int IV_HP { get { return (int)(IV32 >> 00) & 0x1F; } set { IV32 = (uint)((IV32 & ~(0x1F << 00)) | (uint)((value > 31 ? 31 : value) << 00)); } } - public int IV_ATK { get { return (int)(IV32 >> 05) & 0x1F; } set { IV32 = (uint)((IV32 & ~(0x1F << 05)) | (uint)((value > 31 ? 31 : value) << 05)); } } - public int IV_DEF { get { return (int)(IV32 >> 10) & 0x1F; } set { IV32 = (uint)((IV32 & ~(0x1F << 10)) | (uint)((value > 31 ? 31 : value) << 10)); } } - public int IV_SPE { get { return (int)(IV32 >> 15) & 0x1F; } set { IV32 = (uint)((IV32 & ~(0x1F << 15)) | (uint)((value > 31 ? 31 : value) << 15)); } } - public int IV_SPA { get { return (int)(IV32 >> 20) & 0x1F; } set { IV32 = (uint)((IV32 & ~(0x1F << 20)) | (uint)((value > 31 ? 31 : value) << 20)); } } - public int IV_SPD { get { return (int)(IV32 >> 25) & 0x1F; } set { IV32 = (uint)((IV32 & ~(0x1F << 25)) | (uint)((value > 31 ? 31 : value) << 25)); } } - public bool IsEgg { get { return ((IV32 >> 30) & 1) == 1; } set { IV32 = (uint)((IV32 & ~0x40000000) | (uint)(value ? 0x40000000 : 0)); } } - public bool IsNicknamed { get { return ((IV32 >> 31) & 1) == 1; } set { IV32 = (IV32 & 0x7FFFFFFF) | (value ? 0x80000000 : 0); } } + public override int IV_HP { get { return (int)(IV32 >> 00) & 0x1F; } set { IV32 = (uint)((IV32 & ~(0x1F << 00)) | (uint)((value > 31 ? 31 : value) << 00)); } } + public override int IV_ATK { get { return (int)(IV32 >> 05) & 0x1F; } set { IV32 = (uint)((IV32 & ~(0x1F << 05)) | (uint)((value > 31 ? 31 : value) << 05)); } } + public override int IV_DEF { get { return (int)(IV32 >> 10) & 0x1F; } set { IV32 = (uint)((IV32 & ~(0x1F << 10)) | (uint)((value > 31 ? 31 : value) << 10)); } } + public override int IV_SPE { get { return (int)(IV32 >> 15) & 0x1F; } set { IV32 = (uint)((IV32 & ~(0x1F << 15)) | (uint)((value > 31 ? 31 : value) << 15)); } } + public override int IV_SPA { get { return (int)(IV32 >> 20) & 0x1F; } set { IV32 = (uint)((IV32 & ~(0x1F << 20)) | (uint)((value > 31 ? 31 : value) << 20)); } } + public override int IV_SPD { get { return (int)(IV32 >> 25) & 0x1F; } set { IV32 = (uint)((IV32 & ~(0x1F << 25)) | (uint)((value > 31 ? 31 : value) << 25)); } } + public override bool IsEgg { get { return ((IV32 >> 30) & 1) == 1; } set { IV32 = (uint)((IV32 & ~0x40000000) | (uint)(value ? 0x40000000 : 0)); } } + public override bool IsNicknamed { get { return ((IV32 >> 31) & 1) == 1; } set { IV32 = (IV32 & 0x7FFFFFFF) | (value ? 0x80000000 : 0); } } private byte RIB4 { get { return Data[0x3C]; } set { Data[0x3C] = value; } } // Hoenn 1a public bool RIB4_0 { get { return (RIB4 & (1 << 0)) == 1 << 0; } set { RIB4 = (byte)(RIB4 & ~(1 << 0) | (value ? 1 << 0 : 0)); } } // Cool Ribbon @@ -154,21 +154,21 @@ public PK5(byte[] decryptedData = null, string ident = null) public bool RIB7_6 { get { return (RIB7 & (1 << 6)) == 1 << 6; } set { RIB7 = (byte)(RIB7 & ~(1 << 6) | (value ? 1 << 6 : 0)); } } // Earth Ribbon public bool RIB7_7 { get { return (RIB7 & (1 << 7)) == 1 << 7; } set { RIB7 = (byte)(RIB7 & ~(1 << 7) | (value ? 1 << 7 : 0)); } } // World Ribbon - public bool FatefulEncounter { get { return (Data[0x40] & 1) == 1; } set { Data[0x40] = (byte)(Data[0x40] & ~0x01 | (value ? 1 : 0)); } } - public int Gender { get { return (Data[0x40] >> 1) & 0x3; } set { Data[0x40] = (byte)(Data[0x40] & ~0x06 | (value << 1)); } } - public int AltForm { get { return Data[0x40] >> 3; } set { Data[0x40] = (byte)(Data[0x40] & 0x07 | (value << 3)); } } - public int Nature { get { return Data[0x41]; } set { Data[0x41] = (byte)value; } } + public override bool FatefulEncounter { get { return (Data[0x40] & 1) == 1; } set { Data[0x40] = (byte)(Data[0x40] & ~0x01 | (value ? 1 : 0)); } } + public override int Gender { get { return (Data[0x40] >> 1) & 0x3; } set { Data[0x40] = (byte)(Data[0x40] & ~0x06 | (value << 1)); } } + public override int AltForm { get { return Data[0x40] >> 3; } set { Data[0x40] = (byte)(Data[0x40] & 0x07 | (value << 3)); } } + public override int Nature { get { return Data[0x41]; } set { Data[0x41] = (byte)value; } } public bool HiddenAbility { get { return (Data[0x41] & 1) == 1; } set { Data[0x41] = (byte)(Data[0x41] & ~0x01 | (value ? 1 : 0)); } } public bool NPokémon { get { return (Data[0x41] & 2) == 2; } set { Data[0x41] = (byte)(Data[0x41] & ~0x02 | (value ? 2 : 0)); } } // 0x43-0x47 Unused #endregion #region Block C - public string Nickname + public override string Nickname { get { - return TrimFromFFFF(Encoding.Unicode.GetString(Data, 0x48, 22)) + return PKX.TrimFromFFFF(Encoding.Unicode.GetString(Data, 0x48, 22)) .Replace("\uE08F", "\u2640") // nidoran .Replace("\uE08E", "\u2642") // nidoran .Replace("\u2019", "\u0027"); // farfetch'd @@ -186,7 +186,7 @@ public string Nickname } } // 0x5E unused - public int Version { get { return Data[0x5F]; } set { Data[0x5F] = (byte)value; } } + public override int Version { get { return Data[0x5F]; } set { Data[0x5F] = (byte)value; } } private byte RIB8 { get { return Data[0x60]; } set { Data[0x60] = value; } } // Sinnoh 3 public bool RIB8_0 { get { return (RIB8 & (1 << 0)) == 1 << 0; } set { RIB8 = (byte)(RIB8 & ~(1 << 0) | (value ? 1 << 0 : 0)); } } // Cool Ribbon public bool RIB8_1 { get { return (RIB8 & (1 << 1)) == 1 << 1; } set { RIB8 = (byte)(RIB8 & ~(1 << 1) | (value ? 1 << 1 : 0)); } } // Cool Ribbon Great @@ -227,11 +227,11 @@ public string Nickname #endregion #region Block D - public string OT_Name + public override string OT_Name { get { - return TrimFromFFFF(Encoding.Unicode.GetString(Data, 0x68, 16)) + return PKX.TrimFromFFFF(Encoding.Unicode.GetString(Data, 0x68, 16)) .Replace("\uE08F", "\u2640") // Nidoran ♂ .Replace("\uE08E", "\u2642") // Nidoran ♀ .Replace("\u2019", "\u0027"); // farfetch'd @@ -248,60 +248,37 @@ public string OT_Name Encoding.Unicode.GetBytes(TempNick).CopyTo(Data, 0x68); } } - public int Egg_Year { get { return Data[0x78]; } set { Data[0x78] = (byte)value; } } - public int Egg_Month { get { return Data[0x79]; } set { Data[0x79] = (byte)value; } } - public int Egg_Day { get { return Data[0x7A]; } set { Data[0x7A] = (byte)value; } } - public int Met_Year { get { return Data[0x7B]; } set { Data[0x7B] = (byte)value; } } - public int Met_Month { get { return Data[0x7C]; } set { Data[0x7C] = (byte)value; } } - public int Met_Day { get { return Data[0x7D]; } set { Data[0x7D] = (byte)value; } } - public int Egg_Location { get { return BitConverter.ToUInt16(Data, 0x7E); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x7E); } } - public int Met_Location { get { return BitConverter.ToUInt16(Data, 0x80); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x80); } } + public override int Egg_Year { get { return Data[0x78]; } set { Data[0x78] = (byte)value; } } + public override int Egg_Month { get { return Data[0x79]; } set { Data[0x79] = (byte)value; } } + public override int Egg_Day { get { return Data[0x7A]; } set { Data[0x7A] = (byte)value; } } + public override int Met_Year { get { return Data[0x7B]; } set { Data[0x7B] = (byte)value; } } + public override int Met_Month { get { return Data[0x7C]; } set { Data[0x7C] = (byte)value; } } + public override int Met_Day { get { return Data[0x7D]; } set { Data[0x7D] = (byte)value; } } + public override int Egg_Location { get { return BitConverter.ToUInt16(Data, 0x7E); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x7E); } } + public override int Met_Location { get { return BitConverter.ToUInt16(Data, 0x80); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x80); } } private byte PKRS { get { return Data[0x82]; } set { Data[0x82] = value; } } - public int PKRS_Days { get { return PKRS & 0xF; } set { PKRS = (byte)(PKRS & ~0xF | value); } } - public int PKRS_Strain { get { return PKRS >> 4; } set { PKRS = (byte)(PKRS & 0xF | (value << 4)); } } - public int Ball { get { return Data[0x83]; } set { Data[0x83] = (byte)value; } } - public int Met_Level { get { return Data[0x84] & ~0x80; } set { Data[0x84] = (byte)((Data[0x84] & 0x80) | value); } } - public int OT_Gender { get { return Data[0x84] >> 7; } set { Data[0x84] = (byte)((Data[0x84] & ~0x80) | value << 7); } } - public int EncounterType { get { return Data[0x85]; } set { Data[0x85] = (byte)value; } } + public override int PKRS_Days { get { return PKRS & 0xF; } set { PKRS = (byte)(PKRS & ~0xF | value); } } + public override int PKRS_Strain { get { return PKRS >> 4; } set { PKRS = (byte)(PKRS & 0xF | (value << 4)); } } + public override int Ball { get { return Data[0x83]; } set { Data[0x83] = (byte)value; } } + public override int Met_Level { get { return Data[0x84] & ~0x80; } set { Data[0x84] = (byte)((Data[0x84] & 0x80) | value); } } + public override int OT_Gender { get { return Data[0x84] >> 7; } set { Data[0x84] = (byte)((Data[0x84] & ~0x80) | value << 7); } } + public override int EncounterType { get { return Data[0x85]; } set { Data[0x85] = (byte)value; } } // 0x86-0x87 Unused #endregion - // Simple Generated Attributes - public int[] IVs - { - get { return new[] { IV_HP, IV_ATK, IV_DEF, IV_SPE, IV_SPA, IV_SPD }; } - set - { - if (value == null || value.Length != 6) return; - IV_HP = value[0]; IV_ATK = value[1]; IV_DEF = value[2]; - IV_SPE = value[3]; IV_SPA = value[4]; IV_SPD = value[5]; - } - } - public int[] EVs => new[] { EV_HP, EV_ATK, EV_DEF, EV_SPE, EV_SPA, EV_SPD }; - public int PSV => (int)((PID >> 16 ^ PID & 0xFFFF) >> 3); - public int TSV => (TID ^ SID) >> 3; - public bool IsShiny => TSV == PSV; - public bool PKRS_Infected => PKRS_Strain > 0; - public bool PKRS_Cured => PKRS_Days == 0 && PKRS_Strain > 0; - public bool Gen5 => Version >= 20 && Version <= 23; - public bool Gen4 => Version >= 10 && Version < 12 || Version >= 7 && Version <= 8; - public bool Gen3 => Version >= 1 && Version <= 5 || Version == 15; - public bool GenU => !(Gen5 || Gen4 || Gen3); + public override int Stat_Level { get { return Data[0x8C]; } set { Data[0x8C] = (byte)value; } } + public override int Stat_HPCurrent { get { return BitConverter.ToUInt16(Data, 0x8E); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x8E); } } + public override int Stat_HPMax { get { return BitConverter.ToUInt16(Data, 0x90); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x90); } } + public override int Stat_ATK { get { return BitConverter.ToUInt16(Data, 0x92); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x92); } } + public override int Stat_DEF { get { return BitConverter.ToUInt16(Data, 0x94); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x94); } } + public override int Stat_SPE { get { return BitConverter.ToUInt16(Data, 0x96); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x96); } } + public override int Stat_SPA { get { return BitConverter.ToUInt16(Data, 0x98); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x98); } } + public override int Stat_SPD { get { return BitConverter.ToUInt16(Data, 0x9A); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x9A); } } - public int[] Moves { - get { return new[] {Move1, Move2, Move3, Move4}; } - set { - if (value.Length > 0) Move1 = value[0]; - if (value.Length > 1) Move2 = value[1]; - if (value.Length > 2) Move3 = value[2]; - if (value.Length > 3) Move4 = value[3]; } } - - // Complex Generated Attributes - public byte[] EncryptedPartyData => Encrypt().Take(SIZE_PARTY).ToArray(); - public byte[] EncryptedBoxData => Encrypt().Take(SIZE_STORED).ToArray(); - public byte[] DecryptedPartyData => Data.Take(SIZE_PARTY).ToArray(); - public byte[] DecryptedBoxData => Data.Take(SIZE_STORED).ToArray(); - public int Characteristic + // Generated Attributes + public override int PSV => (int)((PID >> 16 ^ PID & 0xFFFF) >> 3); + public override int TSV => (TID ^ SID) >> 3; + public override int Characteristic { get { @@ -319,40 +296,9 @@ public int Characteristic return pm6stat * 5 + maxIV % 5; } } - public int PotentialRating - { - get - { - int ivTotal = IVs.Sum(); - if (ivTotal <= 90) - return 0; - if (ivTotal <= 120) - return 1; - return ivTotal <= 150 ? 2 : 3; - } - } - public string FileName => $"{Species.ToString("000")}{(IsShiny ? " ★" : "")} - {Nickname} - {Checksum.ToString("X4")}{PID.ToString("X8")}.pkm"; - public bool ChecksumValid => Checksum == CalculateChecksum(); - + // Methods - public void RefreshChecksum() - { - Checksum = CalculateChecksum(); - } - public ushort CalculateChecksum() - { - ushort chk = 0; - for (int i = 8; i < SIZE_STORED; i += 2) // Loop through the entire PK5 - chk += BitConverter.ToUInt16(Data, i); - - return chk; - } - public byte[] Write() - { - RefreshChecksum(); - return Data; - } - public bool getGenderIsValid() + public override bool getGenderIsValid() { int gv = PKX.Personal[Species].Gender; if (gv == 255 && Gender == 2) @@ -367,34 +313,10 @@ public bool getGenderIsValid() return true; return false; } - public void FixMoves() + public override byte[] Encrypt() { - if (Move4 != 0 && Move3 == 0) - { - Move3 = Move4; - Move3_PP = Move4_PP; - Move3_PPUps = Move4_PPUps; - Move4 = Move4_PP = Move4_PPUps = 0; - } - if (Move3 != 0 && Move2 == 0) - { - Move2 = Move3; - Move2_PP = Move3_PP; - Move2_PPUps = Move3_PPUps; - Move3 = Move3_PP = Move3_PPUps = 0; - } - if (Move2 != 0 && Move1 == 0) - { - Move1 = Move2; - Move1_PP = Move2_PP; - Move1_PPUps = Move2_PPUps; - Move2 = Move2_PP = Move2_PPUps = 0; - } - } - public byte[] Encrypt() - { - Checksum = CalculateChecksum(); - return encryptArray(Data); + RefreshChecksum(); + return PKX.encryptArray45(Data); } public PK6 convertToPK6() @@ -581,16 +503,16 @@ public PK6 convertToPK6() pk6.Data[0x34] = (byte)bx34; // Write Transfer Location - location is dependent on 3DS system that transfers. - pk6.Country = Converter.Country; - pk6.Region = Converter.Region; - pk6.ConsoleRegion = Converter.ConsoleRegion; + pk6.Country = PKMConverter.Country; + pk6.Region = PKMConverter.Region; + pk6.ConsoleRegion = PKMConverter.ConsoleRegion; // Write the Memories, Friendship, and Origin! pk6.CurrentHandler = 1; - pk6.HT_Name = Converter.OT_Name; - pk6.HT_Gender = Converter.OT_Gender; - pk6.Geo1_Region = Converter.Region; - pk6.Geo1_Country = Converter.Country; + pk6.HT_Name = PKMConverter.OT_Name; + pk6.HT_Gender = PKMConverter.OT_Gender; + pk6.Geo1_Region = PKMConverter.Region; + pk6.Geo1_Country = PKMConverter.Country; pk6.HT_Intensity = 1; pk6.HT_Memory = 4; pk6.HT_Feeling = (int)(Util.rnd32() % 10); diff --git a/Misc/PK6.cs b/PKM/PK6.cs similarity index 70% rename from Misc/PK6.cs rename to PKM/PK6.cs index c4f0b1103..329bc1960 100644 --- a/Misc/PK6.cs +++ b/PKM/PK6.cs @@ -1,104 +1,99 @@ using System; -using System.Drawing; using System.Linq; using System.Text; namespace PKHeX { - public class PK6 : PKX + public class PK6 : PKM { - internal const int SIZE_PARTY = 0x104; - internal const int SIZE_STORED = 0xE8; - + internal static readonly byte[] ExtraBytes = + { + 0x36, 0x37, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x58, 0x59, 0x73, 0x90, 0x91, 0x9E, 0x9F, 0xA0, 0xA1, 0xA7, 0xAA, 0xAB, 0xAC, 0xAD, 0xC8, 0xC9, 0xD7, 0xE4, 0xE5, 0xE6, 0xE7 + }; + public override int SIZE_PARTY => PKX.SIZE_6PARTY; + public override int SIZE_STORED => PKX.SIZE_6STORED; + public override int Format => 6; public PK6(byte[] decryptedData = null, string ident = null) { Data = (byte[])(decryptedData ?? new byte[SIZE_PARTY]).Clone(); + PKMConverter.checkEncrypted(ref Data); Identifier = ident; if (Data.Length != SIZE_PARTY) Array.Resize(ref Data, SIZE_PARTY); } - - // Internal Attributes set on creation - public byte[] Data; // Raw Storage - public string Identifier; // User or Form Custom Attribute + public override PKM Clone() { return new PK6(Data); } // Structure #region Block A - public uint EncryptionConstant + public override uint EncryptionConstant { get { return BitConverter.ToUInt32(Data, 0x00); } set { BitConverter.GetBytes(value).CopyTo(Data, 0x00); } } - public ushort Sanity + public override ushort Sanity { get { return BitConverter.ToUInt16(Data, 0x04); } set { BitConverter.GetBytes(value).CopyTo(Data, 0x04); } // Should always be zero... } - public ushort Checksum + public override ushort Checksum { get { return BitConverter.ToUInt16(Data, 0x06); } set { BitConverter.GetBytes(value).CopyTo(Data, 0x06); } } - public int Species + public override int Species { get { return BitConverter.ToUInt16(Data, 0x08); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x08); } } - public int HeldItem + public override int HeldItem { get { return BitConverter.ToUInt16(Data, 0x0A); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x0A); } } - public int TID + public override int TID { get { return BitConverter.ToUInt16(Data, 0x0C); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x0C); } } - public int SID + public override int SID { get { return BitConverter.ToUInt16(Data, 0x0E); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x0E); } } - public uint EXP + public override uint EXP { get { return BitConverter.ToUInt32(Data, 0x10); } set { BitConverter.GetBytes(value).CopyTo(Data, 0x10); } } - public int Ability { get { return Data[0x14]; } set { Data[0x14] = (byte)value; } } + public override int Ability { get { return Data[0x14]; } set { Data[0x14] = (byte)value; } } public int AbilityNumber { get { return Data[0x15]; } set { Data[0x15] = (byte)value; } } public int TrainingBagHits { get { return Data[0x16]; } set { Data[0x16] = (byte)value; } } - public int TrainingBag { get { return Data[0x17]; } set { Data[0x17] = (byte)value; } } - public uint PID + public int TrainingBag { get { return Data[0x17]; } set { Data[0x17] = (byte)value; } } + public override uint PID { get { return BitConverter.ToUInt32(Data, 0x18); } set { BitConverter.GetBytes(value).CopyTo(Data, 0x18); } } - public int Nature { get { return Data[0x1C]; } set { Data[0x1C] = (byte)value; } } - public bool FatefulEncounter { get { return (Data[0x1D] & 1) == 1; } set { Data[0x1D] = (byte)(Data[0x1D] & ~0x01 | (value ? 1 : 0)); } } - public int Gender { get { return (Data[0x1D] >> 1) & 0x3; } set { Data[0x1D] = (byte)(Data[0x1D] & ~0x06 | (value << 1)); } } - public int AltForm { get { return Data[0x1D] >> 3; } set { Data[0x1D] = (byte)(Data[0x1D] & 0x07 | (value << 3)); } } - public int EV_HP { get { return Data[0x1E]; } set { Data[0x1E] = (byte)value; } } - public int EV_ATK { get { return Data[0x1F]; } set { Data[0x1F] = (byte)value; } } - public int EV_DEF { get { return Data[0x20]; } set { Data[0x20] = (byte)value; } } - public int EV_SPE { get { return Data[0x21]; } set { Data[0x21] = (byte)value; } } - public int EV_SPA { get { return Data[0x22]; } set { Data[0x22] = (byte)value; } } - public int EV_SPD { get { return Data[0x23]; } set { Data[0x23] = (byte)value; } } - public int CNT_Cool { get { return Data[0x24]; } set { Data[0x24] = (byte)value; } } - public int CNT_Beauty { get { return Data[0x25]; } set { Data[0x25] = (byte)value; } } - public int CNT_Cute { get { return Data[0x26]; } set { Data[0x26] = (byte)value; } } - public int CNT_Smart { get { return Data[0x27]; } set { Data[0x27] = (byte)value; } } - public int CNT_Tough { get { return Data[0x28]; } set { Data[0x28] = (byte)value; } } - public int CNT_Sheen { get { return Data[0x29]; } set { Data[0x29] = (byte)value; } } - public byte Markings { get { return Data[0x2A]; } set { Data[0x2A] = value; } } - public bool Circle { get { return (Markings & (1 << 0)) == 1 << 0; } set { Markings = (byte)(Markings & ~(1 << 0) | (value ? 1 << 0 : 0)); } } - public bool Triangle { get { return (Markings & (1 << 1)) == 1 << 1; } set { Markings = (byte)(Markings & ~(1 << 1) | (value ? 1 << 1 : 0)); } } - public bool Square { get { return (Markings & (1 << 2)) == 1 << 2; } set { Markings = (byte)(Markings & ~(1 << 2) | (value ? 1 << 2 : 0)); } } - public bool Heart { get { return (Markings & (1 << 3)) == 1 << 3; } set { Markings = (byte)(Markings & ~(1 << 3) | (value ? 1 << 3 : 0)); } } - public bool Star { get { return (Markings & (1 << 4)) == 1 << 4; } set { Markings = (byte)(Markings & ~(1 << 4) | (value ? 1 << 4 : 0)); } } - public bool Diamond { get { return (Markings & (1 << 5)) == 1 << 5; } set { Markings = (byte)(Markings & ~(1 << 5) | (value ? 1 << 5 : 0)); } } + public override int Nature { get { return Data[0x1C]; } set { Data[0x1C] = (byte)value; } } + public override bool FatefulEncounter { get { return (Data[0x1D] & 1) == 1; } set { Data[0x1D] = (byte)(Data[0x1D] & ~0x01 | (value ? 1 : 0)); } } + public override int Gender { get { return (Data[0x1D] >> 1) & 0x3; } set { Data[0x1D] = (byte)(Data[0x1D] & ~0x06 | (value << 1)); } } + public override int AltForm { get { return Data[0x1D] >> 3; } set { Data[0x1D] = (byte)(Data[0x1D] & 0x07 | (value << 3)); } } + public override int EV_HP { get { return Data[0x1E]; } set { Data[0x1E] = (byte)value; } } + public override int EV_ATK { get { return Data[0x1F]; } set { Data[0x1F] = (byte)value; } } + public override int EV_DEF { get { return Data[0x20]; } set { Data[0x20] = (byte)value; } } + public override int EV_SPE { get { return Data[0x21]; } set { Data[0x21] = (byte)value; } } + public override int EV_SPA { get { return Data[0x22]; } set { Data[0x22] = (byte)value; } } + public override int EV_SPD { get { return Data[0x23]; } set { Data[0x23] = (byte)value; } } + public override int CNT_Cool { get { return Data[0x24]; } set { Data[0x24] = (byte)value; } } + public override int CNT_Beauty { get { return Data[0x25]; } set { Data[0x25] = (byte)value; } } + public override int CNT_Cute { get { return Data[0x26]; } set { Data[0x26] = (byte)value; } } + public override int CNT_Smart { get { return Data[0x27]; } set { Data[0x27] = (byte)value; } } + public override int CNT_Tough { get { return Data[0x28]; } set { Data[0x28] = (byte)value; } } + public override int CNT_Sheen { get { return Data[0x29]; } set { Data[0x29] = (byte)value; } } + public override byte MarkByte { get { return Data[0x2A]; } protected set { Data[0x2A] = value; } } private byte PKRS { get { return Data[0x2B]; } set { Data[0x2B] = value; } } - public int PKRS_Days { get { return PKRS & 0xF; } set { PKRS = (byte)(PKRS & ~0xF | value); } } - public int PKRS_Strain { get { return PKRS >> 4; } set { PKRS = (byte)(PKRS & 0xF | value << 4); } } + public override int PKRS_Days { get { return PKRS & 0xF; } set { PKRS = (byte)(PKRS & ~0xF | value); } } + public override int PKRS_Strain { get { return PKRS >> 4; } set { PKRS = (byte)(PKRS & 0xF | value << 4); } } private byte ST1 { get { return Data[0x2C]; } set { Data[0x2C] = value; } } public bool Unused0 { get { return (ST1 & (1 << 0)) == 1 << 0; } set { ST1 = (byte)(ST1 & ~(1 << 0) | (value ? 1 << 0 : 0)); } } public bool Unused1 { get { return (ST1 & (1 << 1)) == 1 << 1; } set { ST1 = (byte)(ST1 & ~(1 << 1) | (value ? 1 << 1 : 0)); } } @@ -209,7 +204,7 @@ public uint PID public byte _0x3F { get { return Data[0x3F]; } set { Data[0x3F] = value; } } #endregion #region Block B - public string Nickname + public override string Nickname { get { @@ -230,50 +225,50 @@ public string Nickname Encoding.Unicode.GetBytes(TempNick).CopyTo(Data, 0x40); } } - public int Move1 + public override int Move1 { get { return BitConverter.ToUInt16(Data, 0x5A); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x5A); } } - public int Move2 + public override int Move2 { get { return BitConverter.ToUInt16(Data, 0x5C); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x5C); } } - public int Move3 + public override int Move3 { get { return BitConverter.ToUInt16(Data, 0x5E); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x5E); } } - public int Move4 + public override int Move4 { get { return BitConverter.ToUInt16(Data, 0x60); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x60); } } - public int Move1_PP { get { return Data[0x62]; } set { Data[0x62] = (byte)value; } } - public int Move2_PP { get { return Data[0x63]; } set { Data[0x63] = (byte)value; } } - public int Move3_PP { get { return Data[0x64]; } set { Data[0x64] = (byte)value; } } - public int Move4_PP { get { return Data[0x65]; } set { Data[0x65] = (byte)value; } } - public int Move1_PPUps { get { return Data[0x66]; } set { Data[0x66] = (byte)value; } } - public int Move2_PPUps { get { return Data[0x67]; } set { Data[0x67] = (byte)value; } } - public int Move3_PPUps { get { return Data[0x68]; } set { Data[0x68] = (byte)value; } } - public int Move4_PPUps { get { return Data[0x69]; } set { Data[0x69] = (byte)value; } } - public int RelearnMove1 + public override int Move1_PP { get { return Data[0x62]; } set { Data[0x62] = (byte)value; } } + public override int Move2_PP { get { return Data[0x63]; } set { Data[0x63] = (byte)value; } } + public override int Move3_PP { get { return Data[0x64]; } set { Data[0x64] = (byte)value; } } + public override int Move4_PP { get { return Data[0x65]; } set { Data[0x65] = (byte)value; } } + public override int Move1_PPUps { get { return Data[0x66]; } set { Data[0x66] = (byte)value; } } + public override int Move2_PPUps { get { return Data[0x67]; } set { Data[0x67] = (byte)value; } } + public override int Move3_PPUps { get { return Data[0x68]; } set { Data[0x68] = (byte)value; } } + public override int Move4_PPUps { get { return Data[0x69]; } set { Data[0x69] = (byte)value; } } + public override int RelearnMove1 { get { return BitConverter.ToUInt16(Data, 0x6A); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x6A); } } - public int RelearnMove2 + public override int RelearnMove2 { get { return BitConverter.ToUInt16(Data, 0x6C); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x6C); } } - public int RelearnMove3 + public override int RelearnMove3 { get { return BitConverter.ToUInt16(Data, 0x6E); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x6E); } } - public int RelearnMove4 + public override int RelearnMove4 { get { return BitConverter.ToUInt16(Data, 0x70); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x70); } @@ -281,14 +276,14 @@ public int RelearnMove4 public bool SecretSuperTraining { get { return Data[0x72] == 1; } set { Data[0x72] = (byte)((Data[0x72] & ~1) | (value ? 1 : 0)); } } public byte _0x73 { get { return Data[0x73]; } set { Data[0x73] = value; } } private uint IV32 { get { return BitConverter.ToUInt32(Data, 0x74); } set { BitConverter.GetBytes(value).CopyTo(Data, 0x74); } } - public int IV_HP { get { return (int)(IV32 >> 00) & 0x1F; } set { IV32 = (uint)((IV32 & ~(0x1F << 00)) | (uint)((value > 31 ? 31 : value) << 00)); } } - public int IV_ATK { get { return (int)(IV32 >> 05) & 0x1F; } set { IV32 = (uint)((IV32 & ~(0x1F << 05)) | (uint)((value > 31 ? 31 : value) << 05)); } } - public int IV_DEF { get { return (int)(IV32 >> 10) & 0x1F; } set { IV32 = (uint)((IV32 & ~(0x1F << 10)) | (uint)((value > 31 ? 31 : value) << 10)); } } - public int IV_SPE { get { return (int)(IV32 >> 15) & 0x1F; } set { IV32 = (uint)((IV32 & ~(0x1F << 15)) | (uint)((value > 31 ? 31 : value) << 15)); } } - public int IV_SPA { get { return (int)(IV32 >> 20) & 0x1F; } set { IV32 = (uint)((IV32 & ~(0x1F << 20)) | (uint)((value > 31 ? 31 : value) << 20)); } } - public int IV_SPD { get { return (int)(IV32 >> 25) & 0x1F; } set { IV32 = (uint)((IV32 & ~(0x1F << 25)) | (uint)((value > 31 ? 31 : value) << 25)); } } - public bool IsEgg { get { return ((IV32 >> 30) & 1) == 1; } set { IV32 = (uint)((IV32 & ~0x40000000) | (uint)(value ? 0x40000000 : 0)); } } - public bool IsNicknamed { get { return ((IV32 >> 31) & 1) == 1; } set { IV32 = (IV32 & 0x7FFFFFFF) | (value ? 0x80000000 : 0); } } + public override int IV_HP { get { return (int)(IV32 >> 00) & 0x1F; } set { IV32 = (uint)((IV32 & ~(0x1F << 00)) | (uint)((value > 31 ? 31 : value) << 00)); } } + public override int IV_ATK { get { return (int)(IV32 >> 05) & 0x1F; } set { IV32 = (uint)((IV32 & ~(0x1F << 05)) | (uint)((value > 31 ? 31 : value) << 05)); } } + public override int IV_DEF { get { return (int)(IV32 >> 10) & 0x1F; } set { IV32 = (uint)((IV32 & ~(0x1F << 10)) | (uint)((value > 31 ? 31 : value) << 10)); } } + public override int IV_SPE { get { return (int)(IV32 >> 15) & 0x1F; } set { IV32 = (uint)((IV32 & ~(0x1F << 15)) | (uint)((value > 31 ? 31 : value) << 15)); } } + public override int IV_SPA { get { return (int)(IV32 >> 20) & 0x1F; } set { IV32 = (uint)((IV32 & ~(0x1F << 20)) | (uint)((value > 31 ? 31 : value) << 20)); } } + public override int IV_SPD { get { return (int)(IV32 >> 25) & 0x1F; } set { IV32 = (uint)((IV32 & ~(0x1F << 25)) | (uint)((value > 31 ? 31 : value) << 25)); } } + public override bool IsEgg { get { return ((IV32 >> 30) & 1) == 1; } set { IV32 = (uint)((IV32 & ~0x40000000) | (uint)(value ? 0x40000000 : 0)); } } + public override bool IsNicknamed { get { return ((IV32 >> 31) & 1) == 1; } set { IV32 = (IV32 & 0x7FFFFFFF) | (value ? 0x80000000 : 0); } } #endregion #region Block C public string HT_Name @@ -313,7 +308,7 @@ public string HT_Name } } public int HT_Gender { get { return Data[0x92]; } set { Data[0x92] = (byte)value; } } - public int CurrentHandler { get { return Data[0x93]; } set { Data[0x93] = (byte)value; } } + public override int CurrentHandler { get { return Data[0x93]; } set { Data[0x93] = (byte)value; } } public int Geo1_Region { get { return Data[0x94]; } set { Data[0x94] = (byte)value; } } public int Geo1_Country { get { return Data[0x95]; } set { Data[0x95] = (byte)value; } } public int Geo2_Region { get { return Data[0x96]; } set { Data[0x96] = (byte)value; } } @@ -343,7 +338,7 @@ public string HT_Name public byte Enjoyment { get { return Data[0xAF]; } set { Data[0xAF] = value; } } #endregion #region Block D - public string OT_Name + public override string OT_Name { get { @@ -364,44 +359,44 @@ public string OT_Name Encoding.Unicode.GetBytes(TempNick).CopyTo(Data, 0xB0); } } - public int OT_Friendship { get { return Data[0xCA]; } set { Data[0xCA] = (byte)value; } } - public int OT_Affection { get { return Data[0xCB]; } set { Data[0xCB] = (byte)value; } } + public override int OT_Friendship { get { return Data[0xCA]; } set { Data[0xCA] = (byte)value; } } + public override int OT_Affection { get { return Data[0xCB]; } set { Data[0xCB] = (byte)value; } } public int OT_Intensity { get { return Data[0xCC]; } set { Data[0xCC] = (byte)value; } } public int OT_Memory { get { return Data[0xCD]; } set { Data[0xCD] = (byte)value; } } public int OT_TextVar { get { return BitConverter.ToUInt16(Data, 0xCE); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0xCE); } } public int OT_Feeling { get { return Data[0xD0]; } set { Data[0xD0] = (byte)value; } } - public int Egg_Year { get { return Data[0xD1]; } set { Data[0xD1] = (byte)value; } } - public int Egg_Month { get { return Data[0xD2]; } set { Data[0xD2] = (byte)value; } } - public int Egg_Day { get { return Data[0xD3]; } set { Data[0xD3] = (byte)value; } } - public int Met_Year { get { return Data[0xD4]; } set { Data[0xD4] = (byte)value; } } - public int Met_Month { get { return Data[0xD5]; } set { Data[0xD5] = (byte)value; } } - public int Met_Day { get { return Data[0xD6]; } set { Data[0xD6] = (byte)value; } } + public override int Egg_Year { get { return Data[0xD1]; } set { Data[0xD1] = (byte)value; } } + public override int Egg_Month { get { return Data[0xD2]; } set { Data[0xD2] = (byte)value; } } + public override int Egg_Day { get { return Data[0xD3]; } set { Data[0xD3] = (byte)value; } } + public override int Met_Year { get { return Data[0xD4]; } set { Data[0xD4] = (byte)value; } } + public override int Met_Month { get { return Data[0xD5]; } set { Data[0xD5] = (byte)value; } } + public override int Met_Day { get { return Data[0xD6]; } set { Data[0xD6] = (byte)value; } } public byte _0xD7 { get { return Data[0xD7]; } set { Data[0xD7] = value; } } - public int Egg_Location { get { return BitConverter.ToUInt16(Data, 0xD8); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0xD8); } } - public int Met_Location { get { return BitConverter.ToUInt16(Data, 0xDA); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0xDA); } } - public int Ball { get { return Data[0xDC]; } set { Data[0xDC] = (byte)value; } } - public int Met_Level { get { return Data[0xDD] & ~0x80; } set { Data[0xDD] = (byte)((Data[0xDD] & 0x80) | value); } } - public int OT_Gender { get { return Data[0xDD] >> 7; } set { Data[0xDD] = (byte)((Data[0xDD] & ~0x80) | (value << 7)); } } - public int EncounterType { get { return Data[0xDE]; } set { Data[0xDE] = (byte)value; } } - public int Version { get { return Data[0xDF]; } set { Data[0xDF] = (byte)value; } } + public override int Egg_Location { get { return BitConverter.ToUInt16(Data, 0xD8); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0xD8); } } + public override int Met_Location { get { return BitConverter.ToUInt16(Data, 0xDA); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0xDA); } } + public override int Ball { get { return Data[0xDC]; } set { Data[0xDC] = (byte)value; } } + public override int Met_Level { get { return Data[0xDD] & ~0x80; } set { Data[0xDD] = (byte)((Data[0xDD] & 0x80) | value); } } + public override int OT_Gender { get { return Data[0xDD] >> 7; } set { Data[0xDD] = (byte)((Data[0xDD] & ~0x80) | (value << 7)); } } + public override int EncounterType { get { return Data[0xDE]; } set { Data[0xDE] = (byte)value; } } + public override int Version { get { return Data[0xDF]; } set { Data[0xDF] = (byte)value; } } public int Country { get { return Data[0xE0]; } set { Data[0xE0] = (byte)value; } } public int Region { get { return Data[0xE1]; } set { Data[0xE1] = (byte)value; } } public int ConsoleRegion { get { return Data[0xE2]; } set { Data[0xE2] = (byte)value; } } - public int Language { get { return Data[0xE3]; } set { Data[0xE3] = (byte)value; } } + public override int Language { get { return Data[0xE3]; } set { Data[0xE3] = (byte)value; } } #endregion #region Battle Stats - public int Stat_Level { get { return Data[0xEC]; } set { Data[0xEC] = (byte)value; } } - public int Stat_HPCurrent { get { return BitConverter.ToUInt16(Data, 0xF0); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0xF0); } } - public int Stat_HPMax { get { return BitConverter.ToUInt16(Data, 0xF2); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0xF2); } } - public int Stat_ATK { get { return BitConverter.ToUInt16(Data, 0xF4); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0xF4); } } - public int Stat_DEF { get { return BitConverter.ToUInt16(Data, 0xF6); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0xF6); } } - public int Stat_SPE { get { return BitConverter.ToUInt16(Data, 0xF8); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0xF8); } } - public int Stat_SPA { get { return BitConverter.ToUInt16(Data, 0xFA); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0xFA); } } - public int Stat_SPD { get { return BitConverter.ToUInt16(Data, 0xFC); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0xFC); } } + public override int Stat_Level { get { return Data[0xEC]; } set { Data[0xEC] = (byte)value; } } + public override int Stat_HPCurrent { get { return BitConverter.ToUInt16(Data, 0xF0); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0xF0); } } + public override int Stat_HPMax { get { return BitConverter.ToUInt16(Data, 0xF2); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0xF2); } } + public override int Stat_ATK { get { return BitConverter.ToUInt16(Data, 0xF4); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0xF4); } } + public override int Stat_DEF { get { return BitConverter.ToUInt16(Data, 0xF6); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0xF6); } } + public override int Stat_SPE { get { return BitConverter.ToUInt16(Data, 0xF8); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0xF8); } } + public override int Stat_SPA { get { return BitConverter.ToUInt16(Data, 0xFA); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0xFA); } } + public override int Stat_SPD { get { return BitConverter.ToUInt16(Data, 0xFC); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0xFC); } } #endregion // Simple Generated Attributes - public int CurrentFriendship { + public override int CurrentFriendship { get { return CurrentHandler == 0 ? OT_Friendship : HT_Friendship; } set { if (CurrentHandler == 0) OT_Friendship = value; else HT_Friendship = value; } } @@ -410,41 +405,12 @@ public int OppositeFriendship get { return CurrentHandler == 1 ? OT_Friendship : HT_Friendship; } set { if (CurrentHandler == 1) OT_Friendship = value; else HT_Friendship = value; } } - - public int[] IVs { - get { return new[] {IV_HP, IV_ATK, IV_DEF, IV_SPE, IV_SPA, IV_SPD}; } - set { if (value == null || value.Length != 6) return; - IV_HP = value[0]; IV_ATK = value[1]; IV_DEF = value[2]; - IV_SPE = value[3]; IV_SPA = value[4]; IV_SPD = value[5]; } } - public int[] EVs => new[] { EV_HP, EV_ATK, EV_DEF, EV_SPE, EV_SPA, EV_SPD }; - public int[] CNTs => new[] { CNT_Cool, CNT_Beauty, CNT_Cute, CNT_Smart, CNT_Tough, CNT_Sheen }; - public int PSV => (int)((PID >> 16 ^ PID & 0xFFFF) >> 4); - public int TSV => (TID ^ SID) >> 4; - public bool IsShiny => TSV == PSV; - public bool PKRS_Infected => PKRS_Strain > 0; - public bool PKRS_Cured => PKRS_Days == 0 && PKRS_Strain > 0; + + public override int PSV => (int)((PID >> 16 ^ PID & 0xFFFF) >> 4); + public override int TSV => (TID ^ SID) >> 4; public bool IsUntraded => string.IsNullOrWhiteSpace(HT_Name); public bool IsUntradedEvent6 => Geo1_Country == 0 && Geo1_Region == 0 && Met_Location / 10000 == 4 && Gen6; - public bool Gen6 => Version >= 24 && Version <= 29; - public bool XY => Version == (int)GameVersion.X || Version == (int)GameVersion.Y; - public bool AO => Version == (int)GameVersion.AS || Version == (int)GameVersion.OR; - public bool SM => Version == (int)GameVersion.SN || Version == (int)GameVersion.MN; - public bool Gen5 => Version >= 20 && Version <= 23; - public bool Gen4 => Version >= 7 && Version <= 12 && Version != 9; - public bool Gen3 => Version >= 1 && Version <= 5 || Version == 15; - public bool GenU => !(Gen6 || Gen5 || Gen4 || Gen3); - - public int[] Moves - { - get { return new[] { Move1, Move2, Move3, Move4 }; } - set - { - if (value.Length > 0) Move1 = value[0]; - if (value.Length > 1) Move2 = value[1]; - if (value.Length > 2) Move3 = value[2]; - if (value.Length > 3) Move4 = value[3]; - } - } + public int[] RelearnMoves { get { return new[] { RelearnMove1, RelearnMove2, RelearnMove3, RelearnMove4 }; } @@ -456,31 +422,10 @@ public int[] RelearnMoves if (value.Length > 3) RelearnMove4 = value[3]; } } - public int CurrentLevel => getLevel(Species, EXP); // Complex Generated Attributes - public Image Sprite => getSprite(this); - public string ShowdownText => getShowdownText(this); - public string[] QRText => getQRText(this); - public byte[] EncryptedPartyData => Encrypt().Take(SIZE_PARTY).ToArray(); - public byte[] EncryptedBoxData => Encrypt().Take(SIZE_STORED).ToArray(); - public byte[] DecryptedPartyData => Data.Take(SIZE_PARTY).ToArray(); - public byte[] DecryptedBoxData => Data.Take(SIZE_STORED).ToArray(); - public int HPType - { - get { return 15 * ((IV_HP & 1) + 2 * (IV_ATK & 1) + 4 * (IV_DEF & 1) + 8 * (IV_SPE & 1) + 16 * (IV_SPA & 1) + 32 * (IV_SPD & 1)) / 63; } - set - { - IV_HP = (IV_HP & ~1) + hpivs[value, 0]; - IV_ATK = (IV_ATK & ~1) + hpivs[value, 1]; - IV_DEF = (IV_DEF & ~1) + hpivs[value, 2]; - IV_SPE = (IV_SPE & ~1) + hpivs[value, 3]; - IV_SPA = (IV_SPA & ~1) + hpivs[value, 4]; - IV_SPD = (IV_SPD & ~1) + hpivs[value, 5]; - } - } - public int Characteristic + public override int Characteristic { get { @@ -495,86 +440,27 @@ public int Characteristic return pm6stat*5 + maxIV%5; } } - public int PotentialRating - { - get - { - int ivTotal = IVs.Sum(); - if (ivTotal <= 90) - return 0; - if (ivTotal <= 120) - return 1; - return ivTotal <= 150 ? 2 : 3; - } - } - public string FileName => getFileName(this); - public bool ChecksumValid => Checksum == CalculateChecksum(); // Methods - public void RefreshChecksum() + public override byte[] Encrypt() { Checksum = CalculateChecksum(); + return PKX.encryptArray(Data); } - public ushort CalculateChecksum() + public override bool getGenderIsValid() { - ushort chk = 0; - for (int i = 8; i < SIZE_STORED; i += 2) // Loop through the entire PK6 - chk += BitConverter.ToUInt16(Data, i); + int gv = PKX.Personal[Species].Gender; - return chk; - } - public byte[] Write() - { - RefreshChecksum(); - return Data; - } - public byte[] Encrypt() - { - Checksum = CalculateChecksum(); - return encryptArray(Data); - } - public void CalculateStats() - { - ushort[] Stats = getStats(this); - Stat_HPMax = Stat_HPCurrent = Stats[0]; - Stat_ATK = Stats[1]; - Stat_DEF = Stats[2]; - Stat_SPE = Stats[3]; - Stat_SPA = Stats[4]; - Stat_SPD = Stats[5]; + if (gv == 255) + return Gender == 2; + if (gv == 254) + return Gender == 0; + if (gv == 0) + return Gender == 1; + return true; } // General User-error Fixes - public void FixMoves() - { - while (true) - { - if (Move4 != 0 && Move3 == 0) - { - Move3 = Move4; - Move3_PP = Move4_PP; - Move3_PPUps = Move4_PPUps; - Move4 = Move4_PP = Move4_PPUps = 0; - } - if (Move3 != 0 && Move2 == 0) - { - Move2 = Move3; - Move2_PP = Move3_PP; - Move2_PPUps = Move3_PPUps; - Move3 = Move3_PP = Move3_PPUps = 0; - continue; - } - if (Move2 != 0 && Move1 == 0) - { - Move1 = Move2; - Move1_PP = Move2_PP; - Move1_PPUps = Move2_PPUps; - Move2 = Move2_PP = Move2_PPUps = 0; - continue; - } - break; - } - } public void FixRelearn() { while (true) @@ -743,7 +629,7 @@ public void TradeFriendshipAffection(string SAV_TRAINER) return; // Reset - HT_Friendship = getBaseFriendship(Species); + HT_Friendship = PKX.getBaseFriendship(Species); HT_Affection = 0; } diff --git a/PKM/PKM.cs b/PKM/PKM.cs new file mode 100644 index 000000000..c97495089 --- /dev/null +++ b/PKM/PKM.cs @@ -0,0 +1,278 @@ +using System; +using System.Drawing; +using System.Linq; + +namespace PKHeX +{ + public abstract class PKM + { + public abstract int SIZE_PARTY { get; } + public abstract int SIZE_STORED { get; } + public string Extension => "pk" + Format; + + // Internal Attributes set on creation + public byte[] Data; // Raw Storage + public string Identifier; // User or Form Custom Attribute + + public byte[] EncryptedPartyData => Encrypt().Take(SIZE_PARTY).ToArray(); + public byte[] EncryptedBoxData => Encrypt().Take(SIZE_STORED).ToArray(); + public byte[] DecryptedPartyData => Write().Take(SIZE_PARTY).ToArray(); + public byte[] DecryptedBoxData => Write().Take(SIZE_STORED).ToArray(); + + public ushort CalculateChecksum() + { + ushort chk = 0; + for (int i = 8; i < SIZE_STORED; i += 2) // Loop through the entire PK5 + chk += BitConverter.ToUInt16(Data, i); + + return chk; + } + public abstract byte[] Encrypt(); + public abstract int Format { get; } + public byte[] Write() + { + RefreshChecksum(); + return Data; + } + + // Surface Properties + public abstract int Species { get; set; } + public abstract string Nickname { get; set; } + public abstract int HeldItem { get; set; } + public abstract int Gender { get; set; } + public abstract int Nature { get; set; } + public abstract int Ability { get; set; } + public abstract int CurrentFriendship { get; set; } + public abstract int AltForm { get; set; } + public abstract bool IsEgg { get; set; } + public abstract bool IsNicknamed { get; set; } + public abstract uint EXP { get; set; } + public abstract int TID { get; set; } + public abstract string OT_Name { get; set; } + public abstract int OT_Gender { get; set; } + public abstract int Ball { get; set; } + public abstract int Met_Level { get; set; } + + // Battle + public abstract int Move1 { get; set; } + public abstract int Move2 { get; set; } + public abstract int Move3 { get; set; } + public abstract int Move4 { get; set; } + public abstract int Move1_PP { get; set; } + public abstract int Move2_PP { get; set; } + public abstract int Move3_PP { get; set; } + public abstract int Move4_PP { get; set; } + public abstract int Move1_PPUps { get; set; } + public abstract int Move2_PPUps { get; set; } + public abstract int Move3_PPUps { get; set; } + public abstract int Move4_PPUps { get; set; } + public abstract int EV_HP { get; set; } + public abstract int EV_ATK { get; set; } + public abstract int EV_DEF { get; set; } + public abstract int EV_SPE { get; set; } + public abstract int EV_SPA { get; set; } + public abstract int EV_SPD { get; set; } + public abstract int IV_HP { get; set; } + public abstract int IV_ATK { get; set; } + public abstract int IV_DEF { get; set; } + public abstract int IV_SPE { get; set; } + public abstract int IV_SPA { get; set; } + public abstract int IV_SPD { get; set; } + public abstract int Stat_Level { get; set; } + public abstract int Stat_HPMax { get; set; } + public abstract int Stat_HPCurrent { get; set; } + public abstract int Stat_ATK { get; set; } + public abstract int Stat_DEF { get; set; } + public abstract int Stat_SPE { get; set; } + public abstract int Stat_SPA { get; set; } + public abstract int Stat_SPD { get; set; } + + // Hidden Properties + public abstract int Version { get; set; } + public abstract int SID { get; set; } + public abstract int PKRS_Strain { get; set; } + public abstract int PKRS_Days { get; set; } + public abstract int CNT_Cool { get; set; } + public abstract int CNT_Beauty { get; set; } + public abstract int CNT_Cute { get; set; } + public abstract int CNT_Smart { get; set; } + public abstract int CNT_Tough { get; set; } + public abstract int CNT_Sheen { get; set; } + + public abstract uint EncryptionConstant { get; set; } + public abstract uint PID { get; set; } + public abstract ushort Sanity { get; set; } + public abstract ushort Checksum { get; set; } + + // Misc Properties + public abstract int Language { get; set; } + public abstract bool FatefulEncounter { get; set; } + public abstract int TSV { get; } + public abstract int PSV { get; } + public abstract int Characteristic { get; } + public abstract byte MarkByte { get; protected set; } + public abstract int Met_Location { get; set; } + public abstract int Egg_Location { get; set; } + public abstract int OT_Friendship { get; set; } + + // Future Properties + public virtual int Met_Year { get { return 0; } set { } } + public virtual int Met_Month { get { return 0; } set { } } + public virtual int Met_Day { get { return 0; } set { } } + public virtual int Egg_Year { get { return 0; } set { } } + public virtual int Egg_Month { get { return 0; } set { } } + public virtual int Egg_Day { get { return 0; } set { } } + public virtual int OT_Affection { get { return 0; } set { } } + public virtual int RelearnMove1 { get { return 0; } set { } } + public virtual int RelearnMove2 { get { return 0; } set { } } + public virtual int RelearnMove3 { get { return 0; } set { } } + public virtual int RelearnMove4 { get { return 0; } set { } } + public virtual int EncounterType { get { return 0; } set { } } + + // Exposed but not Present in all + public abstract int CurrentHandler { get; set; } + + // Derived + public bool IsShiny => TSV == PSV; + public bool Gen6 => Version >= 24 && Version <= 29; + public bool XY => Version == (int)GameVersion.X || Version == (int)GameVersion.Y; + public bool AO => Version == (int)GameVersion.AS || Version == (int)GameVersion.OR; + public bool SM => Version == (int)GameVersion.SN || Version == (int)GameVersion.MN; + public bool PtHGSS => new[] {GameVersion.Pt, GameVersion.HG, GameVersion.SS}.Contains((GameVersion)Version); + public bool Gen5 => Version >= 20 && Version <= 23; + public bool Gen4 => Version >= 10 && Version < 12 || Version >= 7 && Version <= 8; + public bool Gen3 => Version >= 1 && Version <= 5 || Version == 15; + public bool GenU => !(Gen6 || Gen5 || Gen4 || Gen3); + public bool PKRS_Infected => PKRS_Strain > 0; + public bool PKRS_Cured => PKRS_Days == 0 && PKRS_Strain > 0; + public bool ChecksumValid => Checksum == CalculateChecksum(); + public int CurrentLevel => PKX.getLevel(Species, EXP); + public bool Circle { get { return Markings[0]; } set { Markings[0] = value; } } + public bool Triangle { get { return Markings[1]; } set { Markings[1] = value; } } + public bool Square { get { return Markings[2]; } set { Markings[2] = value; } } + public bool Heart { get { return Markings[3]; } set { Markings[3] = value; } } + public bool Star { get { return Markings[4]; } set { Markings[4] = value; } } + public bool Diamond { get { return Markings[5]; } set { Markings[5] = value; } } + public Image Sprite => PKX.getSprite(this); + public string ShowdownText => ShowdownSet.getShowdownText(this); + public string[] QRText => PKX.getQRText(this); + public string FileName => PKX.getFileName(this); + public int[] IVs + { + get { return new[] { IV_HP, IV_ATK, IV_DEF, IV_SPE, IV_SPA, IV_SPD }; } + set + { + if (value?.Length != 6) return; + IV_HP = value[0]; IV_ATK = value[1]; IV_DEF = value[2]; + IV_SPE = value[3]; IV_SPA = value[4]; IV_SPD = value[5]; + } + } + public int[] EVs + { + get { return new[] { EV_HP, EV_ATK, EV_DEF, EV_SPE, EV_SPA, EV_SPD }; } + set + { + if (value?.Length != 6) return; + EV_HP = value[0]; EV_ATK = value[1]; EV_DEF = value[2]; + EV_SPE = value[3]; EV_SPA = value[4]; EV_SPD = value[5]; + } + } + public int[] Moves + { + get { return new[] { Move1, Move2, Move3, Move4 }; } + set { if (value?.Length != 4) return; Move1 = value[0]; Move2 = value[1]; Move3 = value[2]; Move4 = value[3]; } + } + + public bool[] Markings + { + get + { + bool[] mark = new bool[8]; + for (int i = 0; i < 8; i++) + mark[i] = ((MarkByte >> i) & 1) == 1; + return mark; + } + set + { + if (value.Length > 8) + return; + byte b = 0; + for (int i = 0; i < value.Length; i++) + b |= (byte)(value[i] ? 1 << i : 0); + MarkByte = b; + } + } + + public int[] CNTs + { + get { return new[] { CNT_Cool, CNT_Beauty, CNT_Cute, CNT_Smart, CNT_Tough, CNT_Sheen }; } + set { if (value?.Length != 6) return; CNT_Cool = value[0]; CNT_Beauty = value[1]; CNT_Cute = value[2]; CNT_Smart = value[3]; CNT_Tough = value[4]; CNT_Sheen = value[5]; } + } + public int HPType + { + get { return 15 * ((IV_HP & 1) + 2 * (IV_ATK & 1) + 4 * (IV_DEF & 1) + 8 * (IV_SPE & 1) + 16 * (IV_SPA & 1) + 32 * (IV_SPD & 1)) / 63; } + set + { + IV_HP = (IV_HP & ~1) + PKX.hpivs[value, 0]; + IV_ATK = (IV_ATK & ~1) + PKX.hpivs[value, 1]; + IV_DEF = (IV_DEF & ~1) + PKX.hpivs[value, 2]; + IV_SPE = (IV_SPE & ~1) + PKX.hpivs[value, 3]; + IV_SPA = (IV_SPA & ~1) + PKX.hpivs[value, 4]; + IV_SPD = (IV_SPD & ~1) + PKX.hpivs[value, 5]; + } + } + + // Methods + public abstract bool getGenderIsValid(); + public void RefreshChecksum() { Checksum = CalculateChecksum(); } + public void FixMoves() + { + if (Move4 != 0 && Move3 == 0) + { + Move3 = Move4; + Move3_PP = Move4_PP; + Move3_PPUps = Move4_PPUps; + Move4 = Move4_PP = Move4_PPUps = 0; + } + if (Move3 != 0 && Move2 == 0) + { + Move2 = Move3; + Move2_PP = Move3_PP; + Move2_PPUps = Move3_PPUps; + Move3 = Move3_PP = Move3_PPUps = 0; + } + if (Move2 != 0 && Move1 == 0) + { + Move1 = Move2; + Move1_PP = Move2_PP; + Move1_PPUps = Move2_PPUps; + Move2 = Move2_PP = Move2_PPUps = 0; + } + } + public int PotentialRating + { + get + { + int ivTotal = IVs.Sum(); + if (ivTotal <= 90) + return 0; + if (ivTotal <= 120) + return 1; + return ivTotal <= 150 ? 2 : 3; + } + } + + public void CalculateStats() + { + ushort[] Stats = PKX.getStats(this); + Stat_HPMax = Stat_HPCurrent = Stats[0]; + Stat_ATK = Stats[1]; + Stat_DEF = Stats[2]; + Stat_SPE = Stats[3]; + Stat_SPA = Stats[4]; + Stat_SPD = Stats[5]; + } + + public abstract PKM Clone(); + } +} diff --git a/PKM/PKMConverter.cs b/PKM/PKMConverter.cs new file mode 100644 index 000000000..46ac92d85 --- /dev/null +++ b/PKM/PKMConverter.cs @@ -0,0 +1,138 @@ +using System; + +namespace PKHeX +{ + internal static class PKMConverter + { + internal static int Country = 31; + internal static int Region = 7; + internal static int ConsoleRegion = 1; + internal static string OT_Name = "PKHeX"; + internal static int OT_Gender; + + internal static void updateConfig(int SUBREGION, int COUNTRY, int _3DSREGION, string TRAINERNAME, int TRAINERGENDER) + { + Region = SUBREGION; + Country = COUNTRY; + ConsoleRegion = _3DSREGION; + OT_Name = TRAINERNAME; + OT_Gender = TRAINERGENDER; + } + + private static int getPKMDataFormat(byte[] data) + { + if (!PKX.getIsPKM(data.Length)) + return -1; + + switch (data.Length) + { + case PKX.SIZE_3PARTY: + case PKX.SIZE_3STORED: + return 3; + case PKX.SIZE_4PARTY: + case PKX.SIZE_4STORED: + case PKX.SIZE_5PARTY: + if ((BitConverter.ToUInt16(data, 0x80) >= 0x3333 || data[0x5F] >= 0x10) && BitConverter.ToUInt16(data, 0x46) == 0) // PK5 + return 5; + return 4; + case PKX.SIZE_6STORED: + return 6; + case PKX.SIZE_6PARTY: // collision with PGT, same size. + if (BitConverter.ToUInt16(data, 0x4) != 0) // Bad Sanity? + return -1; + if (BitConverter.ToUInt16(data, 0x58) != 0) // Encrypted? + { + PKX.getCHK(data); + for (int i = data.Length - 0x10; i < data.Length; i++) // 0x10 of 00's at the end != PK6 + if (data[i] != 0) + break; + return 6; + } + return -1; + } + return -1; + } + internal static PKM getPKMfromBytes(byte[] data) + { + checkEncrypted(ref data); + switch (getPKMDataFormat(data)) + { + case 3: + return new PK3(data); + case 4: + return new PK4(data); + case 5: + return new PK5(data); + case 6: + return new PK6(data); + default: + return null; + } + } + internal static PKM convertToFormat(PKM pk, int Format, out string comment) + { + if (pk == null) + { + comment = "Null input. Aborting."; + return null; + } + if (pk.Format == Format) + { + comment = "No need to convert, current format matches requested format."; + return pk; + } + if (pk.Format > Format) + { + comment = "Cannot convert a PKM backwards." + Environment.NewLine + + "Current Format: " + pk.Format + Environment.NewLine + + "Desired Format: " + Format; + return null; + } + string currentFormat = pk.Format.ToString(); + PKM pkm = pk.Clone(); + if (pkm.IsEgg) // force hatch + { + pkm.IsEgg = false; + if (pkm.AO) + pkm.Met_Location = 318; // Battle Resort + else if (pkm.XY) + pkm.Met_Location = 38; // Route 7 + else if (pkm.Gen5) + pkm.Met_Location = 16; // Route 16 + else + pkm.Met_Location = 30001; // Pokétransfer + } + if (pkm.Format == 3 && Format > 3) + pkm = (pkm as PK3).convertToPK4(); + if (pkm.Format == 4 && Format > 4) + pkm = (pkm as PK4).convertToPK5(); + if (pkm.Format == 5 && Format > 5) + pkm = (pkm as PK5).convertToPK6(); + comment = $"Converted from pk{currentFormat} to pk{Format}"; + return pkm; + } + internal static void checkEncrypted(ref byte[] pkm) + { + int format = getPKMDataFormat(pkm); + ushort chk = 0; + switch (format) + { + case 3: // TOneverDO, nobody exports encrypted pk3s + return; + case 4: + case 5: + for (int i = 8; i < PKX.SIZE_4STORED; i += 2) + chk += BitConverter.ToUInt16(pkm, i); + if (chk != BitConverter.ToUInt16(pkm, 0x06)) + pkm = PKX.decryptArray45(pkm); + return; + case 6: + if (BitConverter.ToUInt16(pkm, 0xC8) != 0 && BitConverter.ToUInt16(pkm, 0x58) != 0) + pkm = PKX.decryptArray(pkm); + return; + default: + return; // bad! + } + } + } +} diff --git a/Misc/PKM.cs b/PKM/PKX.cs similarity index 63% rename from Misc/PKM.cs rename to PKM/PKX.cs index 8dc08e37e..ce0a66a5b 100644 --- a/Misc/PKM.cs +++ b/PKM/PKX.cs @@ -1,10 +1,42 @@ using System; +using System.Drawing; +using System.Drawing.Text; using System.Linq; +using System.Runtime.InteropServices; +using PKHeX.Properties; namespace PKHeX { - public class PKM // Past Gen + internal static class PKX { + internal const int SIZE_3PARTY = 100; + internal const int SIZE_3STORED = 80; + internal const int SIZE_3BLOCK = 12; + + internal const int SIZE_4PARTY = 236; + internal const int SIZE_4STORED = 136; + internal const int SIZE_4BLOCK = 32; + + internal const int SIZE_5PARTY = 220; + internal const int SIZE_5STORED = 136; + internal const int SIZE_5BLOCK = 32; + + internal const int SIZE_6PARTY = 0x104; + internal const int SIZE_6STORED = 0xE8; + internal const int SIZE_6BLOCK = 56; + + internal static bool getIsPKM(long len) + { + return new[] {SIZE_3STORED, SIZE_3PARTY, SIZE_4STORED, SIZE_4PARTY, SIZE_5PARTY, SIZE_6STORED, SIZE_6PARTY}.Contains((int)len); + } + + + // C# PKX Function Library + // No WinForm object related code, only to calculate information. + // May require re-referencing to main form for string array referencing. + // Relies on Util for some common operations. + + // Data internal static uint LCRNG(uint seed) { const uint a = 0x41C64E6D; @@ -19,29 +51,387 @@ internal static uint LCRNG(ref uint seed) return seed = seed * a + c; } - - internal static readonly string[] speclang_ja = Util.getStringList("species", "ja"); - internal static readonly string[] speclang_en = Util.getStringList("species", "en"); - internal static readonly string[] speclang_fr = Util.getStringList("species", "fr"); - internal static readonly string[] speclang_it = Util.getStringList("species", "it"); - internal static readonly string[] speclang_de = Util.getStringList("species", "de"); - internal static readonly string[] speclang_es = Util.getStringList("species", "es"); - - internal static int getSAVGeneration(byte[] data) + #region ExpTable + internal static readonly uint[,] ExpTable = { - if (SAV4.getIsG4SAV(data) != -1) - return 4; - if (SAV5.getIsG5SAV(data) != -1) - return 5; + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {8, 15, 4, 9, 6, 10}, + {27, 52, 13, 57, 21, 33}, + {64, 122, 32, 96, 51, 80}, + {125, 237, 65, 135, 100, 156}, + {216, 406, 112, 179, 172, 270}, + {343, 637, 178, 236, 274, 428}, + {512, 942, 276, 314, 409, 640}, + {729, 1326, 393, 419, 583, 911}, + {1000, 1800, 540, 560, 800, 1250}, + {1331, 2369, 745, 742, 1064, 1663}, + {1728, 3041, 967, 973, 1382, 2160}, + {2197, 3822, 1230, 1261, 1757, 2746}, + {2744, 4719, 1591, 1612, 2195, 3430}, + {3375, 5737, 1957, 2035, 2700, 4218}, + {4096, 6881, 2457, 2535, 3276, 5120}, + {4913, 8155, 3046, 3120, 3930, 6141}, + {5832, 9564, 3732, 3798, 4665, 7290}, + {6859, 11111, 4526, 4575, 5487, 8573}, + {8000, 12800, 5440, 5460, 6400, 10000}, + {9261, 14632, 6482, 6458, 7408, 11576}, + {10648, 16610, 7666, 7577, 8518, 13310}, + {12167, 18737, 9003, 8825, 9733, 15208}, + {13824, 21012, 10506, 10208, 11059, 17280}, + {15625, 23437, 12187, 11735, 12500, 19531}, + {17576, 26012, 14060, 13411, 14060, 21970}, + {19683, 28737, 16140, 15244, 15746, 24603}, + {21952, 31610, 18439, 17242, 17561, 27440}, + {24389, 34632, 20974, 19411, 19511, 30486}, + {27000, 37800, 23760, 21760, 21600, 33750}, + {29791, 41111, 26811, 24294, 23832, 37238}, + {32768, 44564, 30146, 27021, 26214, 40960}, + {35937, 48155, 33780, 29949, 28749, 44921}, + {39304, 51881, 37731, 33084, 31443, 49130}, + {42875, 55737, 42017, 36435, 34300, 53593}, + {46656, 59719, 46656, 40007, 37324, 58320}, + {50653, 63822, 50653, 43808, 40522, 63316}, + {54872, 68041, 55969, 47846, 43897, 68590}, + {59319, 72369, 60505, 52127, 47455, 74148}, + {64000, 76800, 66560, 56660, 51200, 80000}, + {68921, 81326, 71677, 61450, 55136, 86151}, + {74088, 85942, 78533, 66505, 59270, 92610}, + {79507, 90637, 84277, 71833, 63605, 99383}, + {85184, 95406, 91998, 77440, 68147, 106480}, + {91125, 100237, 98415, 83335, 72900, 113906}, + {97336, 105122, 107069, 89523, 77868, 121670}, + {103823, 110052, 114205, 96012, 83058, 129778}, + {110592, 115015, 123863, 102810, 88473, 138240}, + {117649, 120001, 131766, 109923, 94119, 147061}, + {125000, 125000, 142500, 117360, 100000, 156250}, + {132651, 131324, 151222, 125126, 106120, 165813}, + {140608, 137795, 163105, 133229, 112486, 175760}, + {148877, 144410, 172697, 141677, 119101, 186096}, + {157464, 151165, 185807, 150476, 125971, 196830}, + {166375, 158056, 196322, 159635, 133100, 207968}, + {175616, 165079, 210739, 169159, 140492, 219520}, + {185193, 172229, 222231, 179056, 148154, 231491}, + {195112, 179503, 238036, 189334, 156089, 243890}, + {205379, 186894, 250562, 199999, 164303, 256723}, + {216000, 194400, 267840, 211060, 172800, 270000}, + {226981, 202013, 281456, 222522, 181584, 283726}, + {238328, 209728, 300293, 234393, 190662, 297910}, + {250047, 217540, 315059, 246681, 200037, 312558}, + {262144, 225443, 335544, 259392, 209715, 327680}, + {274625, 233431, 351520, 272535, 219700, 343281}, + {287496, 241496, 373744, 286115, 229996, 359370}, + {300763, 249633, 390991, 300140, 240610, 375953}, + {314432, 257834, 415050, 314618, 251545, 393040}, + {328509, 267406, 433631, 329555, 262807, 410636}, + {343000, 276458, 459620, 344960, 274400, 428750}, + {357911, 286328, 479600, 360838, 286328, 447388}, + {373248, 296358, 507617, 377197, 298598, 466560}, + {389017, 305767, 529063, 394045, 311213, 486271}, + {405224, 316074, 559209, 411388, 324179, 506530}, + {421875, 326531, 582187, 429235, 337500, 527343}, + {438976, 336255, 614566, 447591, 351180, 548720}, + {456533, 346965, 639146, 466464, 365226, 570666}, + {474552, 357812, 673863, 485862, 379641, 593190}, + {493039, 367807, 700115, 505791, 394431, 616298}, + {512000, 378880, 737280, 526260, 409600, 640000}, + {531441, 390077, 765275, 547274, 425152, 664301}, + {551368, 400293, 804997, 568841, 441094, 689210}, + {571787, 411686, 834809, 590969, 457429, 714733}, + {592704, 423190, 877201, 613664, 474163, 740880}, + {614125, 433572, 908905, 636935, 491300, 767656}, + {636056, 445239, 954084, 660787, 508844, 795070}, + {658503, 457001, 987754, 685228, 526802, 823128}, + {681472, 467489, 1035837, 710266, 545177, 851840}, + {704969, 479378, 1071552, 735907, 563975, 881211}, + {729000, 491346, 1122660, 762160, 583200, 911250}, + {753571, 501878, 1160499, 789030, 602856, 941963}, + {778688, 513934, 1214753, 816525, 622950, 973360}, + {804357, 526049, 1254796, 844653, 643485, 1005446}, + {830584, 536557, 1312322, 873420, 664467, 1038230}, + {857375, 548720, 1354652, 902835, 685900, 1071718}, + {884736, 560922, 1415577, 932903, 707788, 1105920}, + {912673, 571333, 1460276, 963632, 730138, 1140841}, + {941192, 583539, 1524731, 995030, 752953, 1176490}, + {970299, 591882, 1571884, 1027103, 776239, 1212873}, + {1000000, 600000, 1640000, 1059860, 800000, 1250000}, + }; + #endregion + + internal static readonly string[][] SpeciesLang = + { + Util.getStringList("species", "ja"), // none + Util.getStringList("species", "ja"), // 1 + Util.getStringList("species", "en"), // 2 + Util.getStringList("species", "fr"), // 3 + Util.getStringList("species", "it"), // 4 + Util.getStringList("species", "de"), // 5 + Util.getStringList("species", "es"), // none + Util.getStringList("species", "es"), // 7 + Util.getStringList("species", "ko"), // 8 + }; + + internal static string getSpeciesName(int species, int lang) + { + try { return SpeciesLang[lang][species]; } + catch { return ""; } + } + internal static readonly PersonalInfo[] Personal = Legal.PersonalAO; + + // Stat Fetching + internal static int getMovePP(int move, int ppup) + { + return getBasePP(move) * (5 + ppup) / 5; + } + internal static int getBasePP(int move) + { + byte[] movepptable = + { + 00, + 35, 25, 10, 15, 20, 20, 15, 15, 15, 35, 30, 05, 10, 20, 30, 35, 35, 20, 15, 20, + 20, 25, 20, 30, 05, 10, 15, 15, 15, 25, 20, 05, 35, 15, 20, 20, 10, 15, 30, 35, + 20, 20, 30, 25, 40, 20, 15, 20, 20, 20, 30, 25, 15, 30, 25, 05, 15, 10, 05, 20, + 20, 20, 05, 35, 20, 25, 20, 20, 20, 15, 25, 15, 10, 20, 25, 10, 35, 30, 15, 10, + 40, 10, 15, 30, 15, 20, 10, 15, 10, 05, 10, 10, 25, 10, 20, 40, 30, 30, 20, 20, + 15, 10, 40, 15, 10, 30, 10, 20, 10, 40, 40, 20, 30, 30, 20, 30, 10, 10, 20, 05, + 10, 30, 20, 20, 20, 05, 15, 10, 20, 10, 15, 35, 20, 15, 10, 10, 30, 15, 40, 20, + 15, 10, 05, 10, 30, 10, 15, 20, 15, 40, 20, 10, 05, 15, 10, 10, 10, 15, 30, 30, + 10, 10, 20, 10, 01, 01, 10, 25, 10, 05, 15, 25, 15, 10, 15, 30, 05, 40, 15, 10, + 25, 10, 30, 10, 20, 10, 10, 10, 10, 10, 20, 05, 40, 05, 05, 15, 05, 10, 05, 10, + 10, 10, 10, 20, 20, 40, 15, 10, 20, 20, 25, 05, 15, 10, 05, 20, 15, 20, 25, 20, + 05, 30, 05, 10, 20, 40, 05, 20, 40, 20, 15, 35, 10, 05, 05, 05, 15, 05, 20, 05, + 05, 15, 20, 10, 05, 05, 15, 10, 15, 15, 10, 10, 10, 20, 10, 10, 10, 10, 15, 15, + 15, 10, 20, 20, 10, 20, 20, 20, 20, 20, 10, 10, 10, 20, 20, 05, 15, 10, 10, 15, + 10, 20, 05, 05, 10, 10, 20, 05, 10, 20, 10, 20, 20, 20, 05, 05, 15, 20, 10, 15, + 20, 15, 10, 10, 15, 10, 05, 05, 10, 15, 10, 05, 20, 25, 05, 40, 15, 05, 40, 15, + 20, 20, 05, 15, 20, 20, 15, 15, 05, 10, 30, 20, 30, 15, 05, 40, 15, 05, 20, 05, + 15, 25, 25, 15, 20, 15, 20, 15, 20, 10, 20, 20, 05, 05, 10, 05, 40, 10, 10, 05, + 10, 10, 15, 10, 20, 15, 30, 10, 20, 05, 10, 10, 15, 10, 10, 05, 15, 05, 10, 10, + 30, 20, 20, 10, 10, 05, 05, 10, 05, 20, 10, 20, 10, 15, 10, 20, 20, 20, 15, 15, + 10, 15, 15, 15, 10, 10, 10, 20, 10, 30, 05, 10, 15, 10, 10, 05, 20, 30, 10, 30, + 15, 15, 15, 15, 30, 10, 20, 15, 10, 10, 20, 15, 05, 05, 15, 15, 05, 10, 05, 20, + 05, 15, 20, 05, 20, 20, 20, 20, 10, 20, 10, 15, 20, 15, 10, 10, 05, 10, 05, 05, + 10, 05, 05, 10, 05, 05, 05, 15, 10, 10, 10, 10, 10, 10, 15, 20, 15, 10, 15, 10, + 15, 10, 20, 10, 15, 10, 20, 20, 20, 20, 20, 15, 15, 15, 15, 15, 15, 20, 15, 10, + 15, 15, 15, 15, 10, 10, 10, 10, 10, 15, 15, 15, 15, 05, 05, 15, 05, 10, 10, 10, + 20, 20, 20, 10, 10, 30, 15, 15, 10, 15, 25, 10, 15, 10, 10, 10, 20, 10, 10, 10, + 10, 10, 15, 15, 05, 05, 10, 10, 10, 05, 05, 10, 05, 05, 15, 10, 05, 05, 05, 10, + 10, 10, 10, 20, 25, 10, 20, 30, 25, 20, 20, 15, 20, 15, 20, 20, 10, 10, 10, 10, + 10, 20, 10, 30, 15, 10, 10, 10, 20, 20, 05, 05, 05, 20, 10, 10, 20, 15, 20, 20, + 10, 20, 30, 10, 10, 40, 40, 30, 20, 40, 20, 20, 10, 10, 10, 10, 05, 10, 10, 05, + 05 + }; + if (move < 0) move = 0; + return movepptable[move]; + } + internal static byte[] getRandomEVs() + { + byte[] evs = new byte[6]; + do { + evs[0] = (byte)Math.Min(Util.rnd32() % 300, 252); // bias two to get maybe 252 + evs[1] = (byte)Math.Min(Util.rnd32() % 300, 252); + evs[2] = (byte)Math.Min(Util.rnd32() % (510 - evs[0] - evs[1]), 252); + evs[3] = (byte)Math.Min(Util.rnd32() % (510 - evs[0] - evs[1] - evs[2]), 252); + evs[4] = (byte)Math.Min(Util.rnd32() % (510 - evs[0] - evs[1] - evs[2] - evs[3]), 252); + evs[5] = (byte)Math.Min(510 - evs[0] - evs[1] - evs[2] - evs[3] - evs[4], 252); + } while (evs.Sum(b => b) > 510); // recalculate random EVs... + Util.Shuffle(evs); + return evs; + } + internal static byte getBaseFriendship(int species) + { + return Personal[species].BaseFriendship; + } + internal static int getLevel(int species, uint exp) + { + int growth = Personal[species].EXPGrowth; + int tl = 1; // Initial Level. Iterate upwards to find the level + while (ExpTable[++tl, growth] <= exp) + if (tl == 100) return 100; + return --tl; + } + internal static bool getIsShiny(uint PID, uint TID, uint SID) + { + uint PSV = getPSV(PID); + uint TSV = getTSV(TID, SID); + return TSV == PSV; + } + internal static uint getEXP(int level, int species) + { + if (level <= 1) return 0; + if (level > 100) level = 100; + return ExpTable[level, Personal[species].EXPGrowth]; + } + internal static byte[] getAbilities(int species, int formnum) + { + return Personal[Personal[species].FormeIndex(species, formnum)].Abilities; + } + internal static int getAbilityNumber(int species, int ability, int formnum) + { + byte[] spec_abilities = Personal[Personal[species].FormeIndex(species, formnum)].Abilities; + int abilval = Array.IndexOf(spec_abilities, (byte)ability); + if (abilval >= 0) + return 1 << abilval; return -1; } - internal static string TrimFromFFFF(string input) + internal static int getGender(string s) { - int index = input.IndexOf((char)0xFFFF); - return index < 0 ? input : input.Substring(0, index); + if (s == null) + return -1; + if (s == "♂" || s == "M") + return 0; + if (s == "♀" || s == "F") + return 1; + return 2; } - // Past Gen Manipulation + internal static string[] getCountryRegionText(int country, int region, string lang) + { + // Get Language we're fetching for + int index = Array.IndexOf(new[] { "ja", "en", "fr", "de", "it", "es", "zh", "ko"}, lang); + // Return value storage + string[] data = new string[2]; // country, region + + // Get Country Text + try + { + string[] inputCSV = Util.getStringList("countries"); + // Set up our Temporary Storage + string[] unsortedList = new string[inputCSV.Length - 1]; + int[] indexes = new int[inputCSV.Length - 1]; + + // Gather our data from the input file + for (int i = 1; i < inputCSV.Length; i++) + { + string[] countryData = inputCSV[i].Split(','); + if (countryData.Length <= 1) continue; + indexes[i - 1] = Convert.ToInt32(countryData[0]); + unsortedList[i - 1] = countryData[index + 1]; + } + + int countrynum = Array.IndexOf(indexes, country); + data[0] = unsortedList[countrynum]; + } + catch { data[0] = "Illegal"; } + + // Get Region Text + try + { + string[] inputCSV = Util.getStringList("sr_" + country.ToString("000")); + // Set up our Temporary Storage + string[] unsortedList = new string[inputCSV.Length - 1]; + int[] indexes = new int[inputCSV.Length - 1]; + + // Gather our data from the input file + for (int i = 1; i < inputCSV.Length; i++) + { + string[] countryData = inputCSV[i].Split(','); + if (countryData.Length <= 1) continue; + indexes[i - 1] = Convert.ToInt32(countryData[0]); + unsortedList[i - 1] = countryData[index + 1]; + } + + int regionnum = Array.IndexOf(indexes, region); + data[1] = unsortedList[regionnum]; + } + catch { data[1] = "Illegal"; } + return data; + } + + internal static string getLocation(PKM pk, bool egg) + { + return getLocation(egg, pk.Version, egg ? pk.Egg_Location : pk.Met_Location, pk.Format); + } + internal static string getLocation(bool eggmet, int gameorigin, int locval, int format) + { + if (gameorigin < 0x10 && (eggmet || format < 5)) + { + if (locval < 2000) return Main.metHGSS_00000[locval]; + if (locval < 3000) return Main.metHGSS_02000[locval % 2000]; + return Main.metHGSS_03000[locval % 3000]; + } + if (gameorigin < 24) + { + if (locval < 30000) return Main.metBW2_00000[locval]; + if (locval < 40000) return Main.metBW2_30000[locval % 10000 - 1]; + if (locval < 60000) return Main.metBW2_40000[locval % 10000 - 1]; + return Main.metBW2_60000[locval % 10000 - 1]; + } + if (gameorigin > 23) + { + if (locval < 30000) return Main.metXY_00000[locval]; + if (locval < 40000) return Main.metXY_30000[locval % 10000 - 1]; + if (locval < 60000) return Main.metXY_40000[locval % 10000 - 1]; + return Main.metXY_60000[locval % 10000 - 1]; + } + return null; // Shouldn't happen. + } + internal static string[] getQRText(PKM pkm) + { + string[] response = new string[3]; + // Summarize + string filename = pkm.Nickname; + if (pkm.Nickname != Main.specieslist[pkm.Species] && Main.specieslist[pkm.Species] != null) + filename += $" ({Main.specieslist[pkm.Species]})"; + response[0] = $"{filename} [{Main.abilitylist[pkm.Ability]}] lv{pkm.Stat_Level} @ {Main.itemlist[pkm.HeldItem]} -- {Main.natures[pkm.Nature]}"; + response[1] = $"{Main.movelist[pkm.Move1]} / {Main.movelist[pkm.Move2]} / {Main.movelist[pkm.Move3]} / {Main.movelist[pkm.Move4]}"; + response[2] = String.Format( + "IVs:{0}{1}{2}{3}{4}{5}" + + Environment.NewLine + Environment.NewLine + + "EVs:{6}{7}{8}{9}{10}{11}", + Environment.NewLine + pkm.IV_HP.ToString("00"), + Environment.NewLine + pkm.IV_ATK.ToString("00"), + Environment.NewLine + pkm.IV_DEF.ToString("00"), + Environment.NewLine + pkm.IV_SPA.ToString("00"), + Environment.NewLine + pkm.IV_SPD.ToString("00"), + Environment.NewLine + pkm.IV_SPE.ToString("00"), + Environment.NewLine + pkm.EV_HP, + Environment.NewLine + pkm.EV_ATK, + Environment.NewLine + pkm.EV_DEF, + Environment.NewLine + pkm.EV_SPA, + Environment.NewLine + pkm.EV_SPD, + Environment.NewLine + pkm.EV_SPE); + + return response; + } + internal static string getFileName(PKM pkm) + { + return + $"{pkm.Species.ToString("000")}{(pkm.IsShiny ? " ★" : "")} - {pkm.Nickname} - {pkm.Checksum.ToString("X4")}{pkm.EncryptionConstant.ToString("X8")}.{pkm.Extension}"; + } + internal static ushort[] getStats(PKM pkm) + { + return getStats(pkm.Species, pkm.Stat_Level, pkm.Nature, pkm.AltForm, + pkm.EV_HP, pkm.EV_ATK, pkm.EV_DEF, pkm.EV_SPA, pkm.EV_SPD, pkm.EV_SPE, + pkm.IV_HP, pkm.IV_ATK, pkm.IV_DEF, pkm.IV_SPA, pkm.IV_SPD, pkm.IV_SPE); + } + internal static ushort[] getStats(int species, int level, int nature, int form, + int HP_EV, int ATK_EV, int DEF_EV, int SPA_EV, int SPD_EV, int SPE_EV, + int HP_IV, int ATK_IV, int DEF_IV, int SPA_IV, int SPD_IV, int SPE_IV) + { + PersonalInfo p = Personal[Personal[species].FormeIndex(species, form)]; + // Calculate Stats + ushort[] stats = new ushort[6]; // Stats are stored as ushorts in the PKX structure. We'll cap them as such. + stats[0] = (ushort)(p.HP == 1 ? 1 : (HP_IV + 2 * p.HP + HP_EV / 4 + 100) * level / 100 + 10); + stats[1] = (ushort)((ATK_IV + 2 * p.ATK + ATK_EV / 4) * level / 100 + 5); + stats[2] = (ushort)((DEF_IV + 2 * p.DEF + DEF_EV / 4) * level / 100 + 5); + stats[4] = (ushort)((SPA_IV + 2 * p.SPA + SPA_EV / 4) * level / 100 + 5); + stats[5] = (ushort)((SPD_IV + 2 * p.SPD + SPD_EV / 4) * level / 100 + 5); + stats[3] = (ushort)((SPE_IV + 2 * p.SPE + SPE_EV / 4) * level / 100 + 5); + + // Account for nature + int incr = nature / 5 + 1; + int decr = nature % 5 + 1; + if (incr == decr) return stats; // if neutral return stats without mod + stats[incr] *= 11; stats[incr] /= 10; + stats[decr] *= 9; stats[decr] /= 10; + + // Return Result + return stats; + } + + + // PKX Manipulation internal static readonly byte[][] blockPosition = { new byte[] {0, 0, 0, 0, 0, 0, 1, 1, 2, 3, 2, 3, 1, 1, 2, 3, 2, 3, 1, 1, 2, 3, 2, 3}, @@ -49,6 +439,7 @@ internal static string TrimFromFFFF(string input) new byte[] {2, 3, 1, 1, 3, 2, 2, 3, 1, 1, 3, 2, 0, 0, 0, 0, 0, 0, 3, 2, 3, 2, 1, 1}, new byte[] {3, 2, 3, 2, 1, 1, 3, 2, 3, 2, 1, 1, 3, 2, 3, 2, 1, 1, 0, 0, 0, 0, 0, 0}, }; + internal static readonly byte[] blockPositionInvert = { 0, 1, 2, 4, 3, 5, 6, 7, 12, 18, 13, 19, 8, 10, 14, 20, 16, 22, 9, 11, 15, 21, 17, 23 @@ -58,6 +449,584 @@ internal static byte[] shuffleArray(byte[] data, uint sv) byte[] sdata = new byte[data.Length]; Array.Copy(data, sdata, 8); // Copy unshuffled bytes + // Shuffle Away! + for (int block = 0; block < 4; block++) + Array.Copy(data, 8 + 56*blockPosition[block][sv], sdata, 8 + 56*block, 56); + + // Fill the Battle Stats back + if (data.Length > 232) + Array.Copy(data, 232, sdata, 232, 28); + + return sdata; + } + internal static byte[] decryptArray(byte[] ekx) + { + byte[] pkx = (byte[])ekx.Clone(); + + uint pv = BitConverter.ToUInt32(pkx, 0); + uint sv = (pv >> 0xD & 0x1F) % 24; + + uint seed = pv; + + // Decrypt Blocks with RNG Seed + for (int i = 8; i < 232; i += 2) + BitConverter.GetBytes((ushort)(BitConverter.ToUInt16(pkx, i) ^ LCRNG(ref seed) >> 16)).CopyTo(pkx, i); + + // Deshuffle + pkx = shuffleArray(pkx, sv); + + // Decrypt the Party Stats + seed = pv; + if (pkx.Length <= 232) return pkx; + for (int i = 232; i < 260; i += 2) + BitConverter.GetBytes((ushort)(BitConverter.ToUInt16(pkx, i) ^ LCRNG(ref seed) >> 16)).CopyTo(pkx, i); + + return pkx; + } + internal static byte[] encryptArray(byte[] pkx) + { + // Shuffle + uint pv = BitConverter.ToUInt32(pkx, 0); + uint sv = (pv >> 0xD & 0x1F) % 24; + + byte[] ekx = (byte[])pkx.Clone(); + + ekx = shuffleArray(ekx, blockPositionInvert[sv]); + + uint seed = pv; + + // Encrypt Blocks with RNG Seed + for (int i = 8; i < 232; i += 2) + BitConverter.GetBytes((ushort)(BitConverter.ToUInt16(ekx, i) ^ LCRNG(ref seed) >> 16)).CopyTo(ekx, i); + + // If no party stats, return. + if (ekx.Length <= 232) return ekx; + + // Encrypt the Party Stats + seed = pv; + for (int i = 232; i < 260; i += 2) + BitConverter.GetBytes((ushort)(BitConverter.ToUInt16(ekx, i) ^ LCRNG(ref seed) >> 16)).CopyTo(ekx, i); + + // Done + return ekx; + } + internal static ushort getCHK(byte[] data) + { + ushort chk = 0; + for (int i = 8; i < 232; i += 2) // Loop through the entire PKX + chk += BitConverter.ToUInt16(data, i); + + return chk; + } + internal static bool verifychk(byte[] input) + { + ushort checksum = 0; + if (input.Length == 100 || input.Length == 80) // Gen 3 Files + { + for (int i = 32; i < 80; i += 2) + checksum += BitConverter.ToUInt16(input, i); + + return checksum == BitConverter.ToUInt16(input, 28); + } + + if (input.Length == 236 || input.Length == 220 || input.Length == 136) // Gen 4/5 + Array.Resize(ref input, 136); + else if (input.Length == 232 || input.Length == 260) // Gen 6 + Array.Resize(ref input, 232); + else throw new ArgumentException("Wrong sized input array to verifychecksum"); + + ushort chk = 0; + for (int i = 8; i < input.Length; i += 2) + chk += BitConverter.ToUInt16(input, i); + + return chk == BitConverter.ToUInt16(input, 0x6); + } + + internal static uint getPSV(uint PID) + { + return (PID >> 16 ^ PID & 0xFFFF) >> 4; + } + internal static uint getTSV(uint TID, uint SID) + { + return (TID ^ SID) >> 4; + } + internal static uint getRandomPID(int species, int cg, int origin, int nature, int form) + { + int gt = Personal[species].Gender; + if (origin >= 24) + return Util.rnd32(); + + bool g3unown = origin <= 5 && species == 201; + while (true) // Loop until we find a suitable PID + { + uint pid = Util.rnd32(); + + // Gen 3/4: Nature derived from PID + if (origin <= 15 && pid%25 != nature) + continue; + + // Gen 3 Unown: Letter/form derived from PID + if (g3unown) + { + uint pidLetter = ((pid & 0x3000000) >> 18 | (pid & 0x30000) >> 12 | (pid & 0x300) >> 6 | pid & 0x3) % 28; + if (pidLetter != form) + continue; + } + + // Gen 3/4/5: Gender derived from PID + uint gv = pid & 0xFF; + if (gt == 255 || gt == 254 || gt == 0) // Set Gender(less) + return pid; // PID can be anything + if (cg == 1 && gv <= gt) // Female + return pid; // PID Passes + if (cg == 0 && gv > gt) // Male + return pid; // PID Passes + } + } + + // Data Requests + internal static Image getSprite(int species, int form, int gender, int item, bool isegg, bool shiny) + { + if (species == 0) + return (Image)Resources.ResourceManager.GetObject("_0"); + if (new[] { 664, 665, 414, 493 }.Contains(species)) // Species who show their default sprite regardless of Form + form = 0; + + string file = "_" + species; + if (form > 0) // Alt Form Handling + file = file + "_" + form; + else if (gender == 1 && new[] { 592, 593, 521, 668 }.Contains(species)) // Frillish & Jellicent, Unfezant & Pyroar + file = file + "_" + gender; + + // Redrawing logic + Image baseImage = (Image)Resources.ResourceManager.GetObject(file); + if (baseImage == null) + { + if (species < 722) + { + baseImage = Util.LayerImage( + (Image)Resources.ResourceManager.GetObject("_" + species), + Resources.unknown, + 0, 0, .5); + } + else + baseImage = Resources.unknown; + } + if (isegg) + { + // Start with a partially transparent species by layering the species with partial opacity onto a blank image. + baseImage = Util.LayerImage((Image)Resources.ResourceManager.GetObject("_0"), baseImage, 0, 0, 0.33); + // Add the egg layer over-top with full opacity. + baseImage = Util.LayerImage(baseImage, (Image)Resources.ResourceManager.GetObject("egg"), 0, 0, 1); + } + if (shiny) + { + // Add shiny star to top left of image. + baseImage = Util.LayerImage(baseImage, Resources.rare_icon, 0, 0, 0.7); + } + if (item > 0) + { + Image itemimg = (Image)Resources.ResourceManager.GetObject("item_" + item) ?? Resources.helditem; + // Redraw + baseImage = Util.LayerImage(baseImage, itemimg, 22 + (15 - itemimg.Width) / 2, 15 + (15 - itemimg.Height), 1); + } + return baseImage; + } + internal static Image getSprite(PKM pkm) + { + return getSprite(pkm.Species, pkm.AltForm, pkm.Gender, pkm.HeldItem, pkm.IsEgg, pkm.IsShiny); + } + + // Font Related + [DllImport("gdi32.dll")] + private static extern IntPtr AddFontMemResourceEx(IntPtr pbFont, uint cbFont, IntPtr pdv, [In] ref uint pcFonts); + private static readonly PrivateFontCollection s_FontCollection = new PrivateFontCollection(); + private static FontFamily[] FontFamilies + { + get + { + if (s_FontCollection.Families.Length == 0) setPKXFont(); + return s_FontCollection.Families; + } + } + internal static Font getPKXFont(float size) + { + return new Font(FontFamilies[0], size); + } + private static void setPKXFont() + { + try + { + byte[] fontData = Resources.pgldings_normalregular; + IntPtr fontPtr = Marshal.AllocCoTaskMem(fontData.Length); + Marshal.Copy(fontData, 0, fontPtr, fontData.Length); + s_FontCollection.AddMemoryFont(fontPtr, Resources.pgldings_normalregular.Length); uint dummy = 0; + AddFontMemResourceEx(fontPtr, (uint)Resources.pgldings_normalregular.Length, IntPtr.Zero, ref dummy); + Marshal.FreeCoTaskMem(fontPtr); + } + catch { Util.Error("Unable to add ingame font."); } + } + + // Personal.dat + internal static string[] getFormList(int species, string[] t, string[] f, string[] g) + { + // Mega List + if (Array.IndexOf(new[] + { // XY + 003, 009, 065, 094, 115, 127, 130, 142, 181, 212, 214, 229, 248, 257, 282, 303, 306, 308, 310, 354, 359, 380, 381, 445, 448, 460, + // ORAS + 015, 018, 080, 208, 254, 260, 302, 319, 323, 334, 362, 373, 376, 384, 428, 475, 531, 719, + }, species) > -1) { // ... + return new[] + { + t[000], // Normal + f[723], // Mega + };} + // MegaXY List + switch (species) + { + case 6: + case 150: + return new[] + { + t[000], // Normal + f[724], // Mega X + f[725], // Mega Y + }; + case 025: + return new[] + { + t[000], // Normal + f[729], // Rockstar + f[730], // Belle + f[731], // Pop + f[732], // PhD + f[733], // Libre + f[734], // Cosplay + }; + case 201: + return new[] + { + "A", "B", "C", "D", "E", + "F", "G", "H", "I", "J", + "K", "L", "M", "N", "O", + "P", "Q", "R", "S", "T", + "U", "V", "W", "X", "Y", + "Z", + "!", "?", + }; + case 351: + return new[] + { + t[000], // Normal + f[789], // Sunny + f[790], // Rainy + f[791], // Snowy + }; + case 382: + case 383: + return new[] + { + t[000], // Normal + f[800], // Primal + }; + case 386: + return new[] + { + t[000], // Normal + f[802], // Attack + f[803], // Defense + f[804], // Speed + }; + + case 412: + case 413: + case 414: + return new[] + { + f[412], // Plant + f[805], // Sandy + f[806], // Trash + }; + + case 421: + return new[] + { + f[421], // Overcast + f[809], // Sunshine + }; + + case 422: + case 423: + return new[] + { + f[422], // West + f[811], // East + }; + + case 479: + return new[] + { + t[000], // Normal + f[817], // Heat + f[818], // Wash + f[819], // Frost + f[820], // Fan + f[821], // Mow + }; + + case 487: + return new[] + { + f[487], // Altered + f[822], // Origin + }; + + case 492: + return new[] + { + f[492], // Land + f[823], // Sky + }; + + case 493: + return new[] + { + t[00], // Normal + t[01], // Fighting + t[02], // Flying + t[03], // Poison + t[04], // etc + t[05], + t[06], + t[07], + t[08], + t[09], + t[10], + t[11], + t[12], + t[13], + t[14], + t[15], + t[16], + t[17], + }; + + case 550: + return new[] + { + f[550], // Red + f[842], // Blue + }; + + case 555: + return new[] + { + f[555], // Standard + f[843], // Zen + }; + + case 585: + case 586: + return new[] + { + f[585], // Spring + f[844], // Summer + f[845], // Autumn + f[846], // Winter + }; + + case 641: + case 642: + case 645: + return new[] + { + f[641], // Incarnate + f[852], // Therian + }; + + case 646: + return new[] + { + t[000], // Normal + f[853], // White + f[854], // Black + }; + + case 647: + return new[] + { + f[647], // Ordinary + f[855], // Resolute + }; + + case 648: + return new[] + { + f[648], // Aria + f[856], // Pirouette + }; + + case 649: + return new[] + { + t[000], // Normal + t[010], // Douse + t[012], // Shock + t[009], // Burn + t[014], // Chill + }; + + case 664: + case 665: + case 666: + return new[] + { + f[666], // Icy Snow + f[861], // Polar + f[862], // Tundra + f[863], // Continental + f[864], // Garden + f[865], // Elegant + f[866], // Meadow + f[867], // Modern + f[868], // Marine + f[869], // Archipelago + f[870], // High-Plains + f[871], // Sandstorm + f[872], // River + f[873], // Monsoon + f[874], // Savannah + f[875], // Sun + f[876], // Ocean + f[877], // Jungle + f[878], // Fancy + f[879], // Poké Ball + }; + + case 669: + case 671: + return new[] + { + f[669], // Red + f[884], // Yellow + f[885], // Orange + f[886], // Blue + f[887], // White + }; + + case 670: + return new[] + { + f[669], // Red + f[884], // Yellow + f[885], // Orange + f[886], // Blue + f[887], // White + f[888], // Eternal + }; + + case 676: + return new[] + { + f[676], // Natural + f[893], // Heart + f[894], // Star + f[895], // Diamond + f[896], // Deputante + f[897], // Matron + f[898], // Dandy + f[899], // La Reine + f[900], // Kabuki + f[901], // Pharaoh + }; + + case 678: + return new[] + { + g[000], // Male + g[001], // Female + }; + + case 681: + return new[] + { + f[681], // Shield + f[903], // Blade + }; + + case 710: + case 711: + return new[] + { + f[904], // Small + f[710], // Average + f[905], // Large + f[906], // Super + }; + + case 716: + return new[] + { + t[000], // Normal + f[910], // Active + }; + + case 720: + return new[] + { + t[000], // Normal + f[912], // Unbound + }; + } + return new[] {""}; + } + + /// Calculate the Hidden Power Type of the entered IVs. + /// Order: HP,ATK,DEF,SPEED,SPA,SPD + /// Hidden Power Type + internal static int getHPType(int[] ivs) + { + return 15 * ((ivs[0] & 1) + 2 * (ivs[1] & 1) + 4 * (ivs[2] & 1) + 8 * (ivs[3] & 1) + 16 * (ivs[4] & 1) + 32 * (ivs[5] & 1)) / 63; + } + internal static int[] setHPIVs(int type, int[] ivs) + { + for (int i = 0; i < 6; i++) + ivs[i] = (ivs[i] & 0x1E) + hpivs[type, i]; + return ivs; + } + internal static readonly int[,] hpivs = { + { 1, 1, 0, 0, 0, 0 }, // Fighting + { 0, 0, 0, 0, 0, 1 }, // Flying + { 1, 1, 0, 0, 0, 1 }, // Poison + { 1, 1, 1, 0, 0, 1 }, // Ground + { 1, 1, 0, 1, 0, 0 }, // Rock + { 1, 0, 0, 1, 0, 1 }, // Bug + { 1, 0, 1, 1, 0, 1 }, // Ghost + { 1, 1, 1, 1, 0, 1 }, // Steel + { 1, 0, 1, 0, 1, 0 }, // Fire + { 1, 0, 0, 0, 1, 1 }, // Water + { 1, 0, 1, 0, 1, 1 }, // Grass + { 1, 1, 1, 0, 1, 1 }, // Electric + { 1, 0, 1, 1, 1, 0 }, // Psychic + { 1, 0, 0, 1, 1, 1 }, // Ice + { 1, 0, 1, 1, 1, 1 }, // Dragon + { 1, 1, 1, 1, 1, 1 }, // Dark + }; + + internal static string TrimFromFFFF(string input) + { + int index = input.IndexOf((char)0xFFFF); + return index < 0 ? input : input.Substring(0, index); + } + + // Past Gen Manipulation + + internal static byte[] shuffleArray45(byte[] data, uint sv) + { + byte[] sdata = new byte[data.Length]; + Array.Copy(data, sdata, 8); // Copy unshuffled bytes + // Shuffle Away! for (int block = 0; block < 4; block++) Array.Copy(data, 8 + 32 * blockPosition[block][sv], sdata, 8 + 32 * block, 32); @@ -68,7 +1037,8 @@ internal static byte[] shuffleArray(byte[] data, uint sv) return sdata; } - internal static byte[] decryptArray(byte[] ekm) + + internal static byte[] decryptArray45(byte[] ekm) { byte[] pkm = (byte[])ekm.Clone(); @@ -83,17 +1053,18 @@ internal static byte[] decryptArray(byte[] ekm) BitConverter.GetBytes((ushort)(BitConverter.ToUInt16(pkm, i) ^ LCRNG(ref seed) >> 16)).CopyTo(pkm, i); // Deshuffle - pkm = shuffleArray(pkm, sv); + pkm = shuffleArray45(pkm, sv); // Decrypt the Party Stats seed = pv; if (pkm.Length <= 136) return pkm; - for (int i = 136; i < 236; i += 2) + for (int i = 136; i < pkm.Length; i += 2) BitConverter.GetBytes((ushort)(BitConverter.ToUInt16(pkm, i) ^ LCRNG(ref seed) >> 16)).CopyTo(pkm, i); return pkm; } - internal static byte[] encryptArray(byte[] pkm) + + internal static byte[] encryptArray45(byte[] pkm) { uint pv = BitConverter.ToUInt32(pkm, 0); uint sv = ((pv & 0x3E000) >> 0xD) % 24; @@ -101,7 +1072,7 @@ internal static byte[] encryptArray(byte[] pkm) uint chk = BitConverter.ToUInt16(pkm, 6); byte[] ekm = (byte[])pkm.Clone(); - ekm = shuffleArray(ekm, blockPositionInvert[sv]); + ekm = shuffleArray45(ekm, blockPositionInvert[sv]); uint seed = chk; @@ -114,48 +1085,13 @@ internal static byte[] encryptArray(byte[] pkm) // Encrypt the Party Stats seed = pv; - for (int i = 136; i < 236; i += 2) + for (int i = 136; i < ekm.Length; i += 2) BitConverter.GetBytes((ushort)(BitConverter.ToUInt16(ekm, i) ^ LCRNG(ref seed) >> 16)).CopyTo(ekm, i); // Done return ekm; } - /// - /// Checks to see if the PKM file is encrypted; if so, decrypts. - /// - /// Input byte array - 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; - } - - /// Calculates the CRC16-CCITT checksum over an input byte array. - /// Input byte array - /// Checksum - internal static ushort ccitt16(byte[] chunk) - { - ushort crc = 0xFFFF; - foreach (byte t in chunk) - { - crc ^= (ushort)(t << 8); - for (int j = 0; j < 8; j++) - { - if ((crc & 0x8000) > 0) - crc = (ushort)(crc << 1 ^ 0x1021); - else - crc <<= 1; - } - } - return crc; - } - internal static int getUnownForm(uint PID) { byte[] data = BitConverter.GetBytes(PID); @@ -167,6 +1103,7 @@ internal static ushort val2charG4(ushort val) int index = Array.IndexOf(G4Values, val); return index > -1 ? G4Chars[index] : (ushort)0xFFFF; } + internal static ushort char2valG4(ushort chr) { int index = Array.IndexOf(G4Chars, chr); @@ -186,6 +1123,7 @@ internal static string array2strG4(byte[] strdata) } return s; } + internal static byte[] str2arrayG4(string str) { byte[] strdata = new byte[str.Length * 2 + 2]; // +2 for 0xFFFF @@ -204,11 +1142,13 @@ internal static byte[] str2arrayG4(string str) // Gen3 && 3->4 Conversion has two character tables, and translates to the same character map. internal static ushort getG4Val(byte val, bool jp) { return jp ? G34_4J[val] : G34_4E[val]; } internal static ushort getG3Char(byte val, bool jp) { return val2charG4(getG4Val(val, jp)); } + internal static byte setG3Char(ushort chr, bool jp) { int index = Array.IndexOf(jp ? G34_4J : G34_4E, char2valG4(chr)); return (byte)(index > -1 ? index : 0xFF); } + internal static string getG3Str(byte[] strdata, bool jp) { return strdata @@ -217,6 +1157,7 @@ internal static string getG3Str(byte[] strdata, bool jp) .TakeWhile(chr => chr != 0xFF) // Stop if Terminator .Aggregate("", (current, chr) => current + (char)chr); } + internal static byte[] setG3Str(string str, bool jp) { byte[] strdata = new byte[str.Length + 1]; // +1 for 0xFF @@ -237,6 +1178,7 @@ internal static int getG4Species(int g3index) int index = Array.IndexOf(oldindex, g3index); return newindex[index > -1 ? index : 0]; } + internal static int getG3Species(int g4index) { int index = Array.IndexOf(newindex, g4index); @@ -245,7 +1187,7 @@ internal static int getG3Species(int g4index) internal static int getGender(int species, uint PID) { - int genderratio = PKX.Personal[species].Gender; + int genderratio = Personal[species].Gender; switch (genderratio) { case 255: return 2; @@ -254,25 +1196,6 @@ internal static int getGender(int species, uint PID) default: return (PID & 0xFF) <= genderratio ? 1 : 0; } } - - internal static string getSpeciesName(int species, int language) - { - try - { - return new[] - { - speclang_ja[species].ToUpper(), - speclang_en[species].ToUpper(), - speclang_fr[species].ToUpper(), - speclang_it[species].ToUpper(), - speclang_de[species].ToUpper(), - speclang_ja[species].ToLower(), - speclang_es[species].ToUpper(), - }[language]; - } - catch { return ""; } - } - #region Gen 3 Species Table internal static readonly int[] newindex = { @@ -295,6 +1218,7 @@ internal static string getSpeciesName(int species, int language) 345,346,347,348,280,281,282,371,372,373,374,375,376,377,378,379,382,383,384,380,381, 385,386,358, }; + internal static readonly int[] oldindex = { 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30, @@ -318,7 +1242,7 @@ internal static string getSpeciesName(int species, int language) }; #endregion #region Gen 3 Ability Table - internal static readonly byte[][] Gen3Abilities = + internal static readonly byte[][] Gen3Abilities = { new byte[] {0x00, 0x00}, // 000 new byte[] {0x41, 0x41}, // 001 @@ -708,8 +1632,10 @@ internal static string getSpeciesName(int species, int language) new byte[] {0x20, 0x20}, // 385 new byte[] {0x2e, 0x2e}, // 386 }; + #endregion #region Gen 3/4 Character Tables (Val->Unicode) + internal static readonly ushort[] G4Values = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, @@ -868,6 +1794,7 @@ internal static string getSpeciesName(int species, int language) 3396, 3397, 3398, 3399, 3400, 3401, 3402, 3403, 3404, 3405, 3406, 3407, 3408, 3409, 3425, 3426, 3427, 3428, 3429, 65535 }; + internal static readonly ushort[] G4Chars = { 12288, 12353, 12354, 12355, 12356, 12357, 12358, 12359, 12360, 12361, 12362, 12363, @@ -1058,6 +1985,7 @@ internal static string getSpeciesName(int species, int language) 4365, 4366, 4367, 4368, 4369, 4370, 4449, 4450, 4451, 4452, 4453, 4454, 4455, 4456, 4457, 4461, 4462, 4466, 4467, 4469, 47252, 49968, 50108, 50388, 52012, 65535 }; + internal static readonly ushort[] G34_4E = { 478, 351, 352, 353, 358, 359, 360, 361, 362, 363, 020, 365, 366, 369, 370, @@ -1078,6 +2006,7 @@ internal static string getSpeciesName(int species, int language) 337, 338, 339, 340, 341, 342, 343, 344, 345, 346, 347, 348, 349, 350, 289, 452, 355, 373, 379, 387, 405, 411 }; + internal static readonly ushort[] G34_4J = { 001, 003, 005, 007, 009, 011, 012, 014, 016, 018, 020, 022, 024, 026, 028, @@ -1101,54 +2030,14 @@ internal static string getSpeciesName(int species, int language) #endregion internal static readonly byte[][] G4TransferTrashBytes = { - new byte[] { }, // Unused - new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, - new byte[] { 0x18, 0x20, 0x0D, 0x02, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x48, 0xA1, 0x0C, 0x02, 0xE0, 0xFF }, - new byte[] { 0x74, 0x20, 0x0D, 0x02, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA4, 0xA1, 0x0C, 0x02, 0xE0, 0xFF }, - new byte[] { 0x54, 0x20, 0x0D, 0x02, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x84, 0xA1, 0x0C, 0x02, 0xE0, 0xFF }, - new byte[] { 0x74, 0x20, 0x0D, 0x02, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA4, 0xA1, 0x0C, 0x02, 0xE0, 0xFF }, - new byte[] { }, // Unused - new byte[] { 0x74, 0x20, 0x0D, 0x02, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA4, 0xA1, 0x0C, 0x02, 0xE0, 0xFF }, - }; - } - public class Converter - { - internal static int Country = 31; - internal static int Region = 7; - internal static int ConsoleRegion = 1; - internal static string OT_Name = "PKHeX"; - internal static int OT_Gender; - - internal static PK6 ConvertPKMtoPK6(byte[] input) - { - // Detect Input Generation - if (input.Length == 100 || input.Length == 80) // PK3 - return new PK3(input).convertToPK4().convertToPK5().convertToPK6(); - if (input.Length != 136 && input.Length != 236 && input.Length != 220) // Invalid - return null; - if ((BitConverter.ToUInt16(input, 0x80) >= 0x3333 || input[0x5F] >= 0x10) && BitConverter.ToUInt16(input, 0x46) == 0) // PK5 - return new PK5(input).convertToPK6(); - return new PK4(input).convertToPK5().convertToPK6(); // PK4 - } - internal static PK5 ConvertPKMtoPK5(byte[] input) - { - // Detect Input Generation - if (input.Length == 100 || input.Length == 80) // PK3 - return new PK3(input).convertToPK4().convertToPK5(); - if (input.Length != 136 && input.Length != 236 && input.Length != 220) // Invalid - return null; - if ((BitConverter.ToUInt16(input, 0x80) >= 0x3333 || input[0x5F] >= 0x10) && BitConverter.ToUInt16(input, 0x46) == 0) // PK5 - return new PK5(input); - return new PK4(input).convertToPK5(); // PK4 - } - - internal static void updateConfig(int SUBREGION, int COUNTRY, int _3DSREGION, string TRAINERNAME, int TRAINERGENDER) - { - Region = SUBREGION; - Country = COUNTRY; - ConsoleRegion = _3DSREGION; - OT_Name = TRAINERNAME; - OT_Gender = TRAINERGENDER; - } + new byte[] { }, // Unused + new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + new byte[] { 0x18, 0x20, 0x0D, 0x02, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x48, 0xA1, 0x0C, 0x02, 0xE0, 0xFF }, + new byte[] { 0x74, 0x20, 0x0D, 0x02, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA4, 0xA1, 0x0C, 0x02, 0xE0, 0xFF }, + new byte[] { 0x54, 0x20, 0x0D, 0x02, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x84, 0xA1, 0x0C, 0x02, 0xE0, 0xFF }, + new byte[] { 0x74, 0x20, 0x0D, 0x02, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA4, 0xA1, 0x0C, 0x02, 0xE0, 0xFF }, + new byte[] { }, // Unused + new byte[] { 0x74, 0x20, 0x0D, 0x02, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA4, 0xA1, 0x0C, 0x02, 0xE0, 0xFF }, + }; } } diff --git a/PKM/ShowdownSet.cs b/PKM/ShowdownSet.cs new file mode 100644 index 000000000..36920b6f4 --- /dev/null +++ b/PKM/ShowdownSet.cs @@ -0,0 +1,281 @@ +using System; +using System.Linq; + +namespace PKHeX +{ + public class ShowdownSet + { + // String to Values + internal static readonly string[] StatNames = { "HP", "Atk", "Def", "SpA", "SpD", "Spe" }; + public static readonly string[] types = Util.getStringList("types", "en"); + public static readonly string[] forms = Util.getStringList("forms", "en"); + private static readonly string[] species = Util.getStringList("species", "en"); + private static readonly string[] items = Util.getStringList("items", "en"); + private static readonly string[] natures = Util.getStringList("natures", "en"); + private static readonly string[] moves = Util.getStringList("moves", "en"); + private static readonly string[] abilities = Util.getStringList("abilities", "en"); + private static readonly string[] hptypes = types.Skip(1).ToArray(); + + // Default Set Data + public string Nickname; + public int Species; + public string Form; + public string Gender; + public int Item; + public int Ability; + public int Level; + public bool Shiny; + public int Friendship; + public int Nature; + public int[] EVs; + public int[] IVs; + public int[] Moves; + + // Parsing Utility + public ShowdownSet(string input = null) + { + if (input == null) + return; + + Nickname = null; + Species = -1; + Form = null; + Gender = null; + Item = 0; + Ability = 0; + Level = 100; + Shiny = false; + Friendship = 255; + Nature = 0; + EVs = new int[6]; + IVs = new[] { 31, 31, 31, 31, 31, 31 }; + Moves = new int[4]; + + string[] lines = input.Split(new[] { "\r\n", "\n" }, StringSplitOptions.None); + for (int i = 0; i < lines.Length; i++) lines[i] = lines[i].Replace("'", "’").Trim(); // Sanitize apostrophes + + if (lines.Length < 3) return; + + // Seek for start of set + int start = -1; + for (int i = 0; i < lines.Length; i++) + if (lines[i].Contains(" @ ")) { start = i; break; } + lines = lines.Skip(start).Take(lines.Length - start).ToArray(); + + // Abort if no text is found + if (start == -1) + { + // Try to parse the first line if it does not have any item + string ld = lines[0]; + // Gender Detection + string last3 = ld.Substring(ld.Length - 3); + if (last3 == "(M)" || last3 == "(F)") + { + Gender = last3.Substring(1, 1); + ld = ld.Substring(0, ld.Length - 3); + } + // Nickname Detection + string spec = ld; + if (spec.Contains("(")) + { + int index = spec.LastIndexOf("(", StringComparison.Ordinal); + string n1 = spec.Substring(0, index - 1); + string n2 = spec.Substring(index).Replace("(", "").Replace(")", "").Replace(" ", ""); + + bool inverted = Array.IndexOf(species, n2.Replace(" ", "")) > -1 || (Species = Array.IndexOf(species, n2.Split('-')[0])) > 0; + spec = inverted ? n2 : n1; + Nickname = inverted ? n1 : n2; + } + Species = Array.IndexOf(species, spec.Replace(" ", "")); + if ( + (Species = Array.IndexOf(species, spec)) < 0 // Not an Edge Case + && + (Species = Array.IndexOf(species, spec.Replace(" ", ""))) < 0 // Has Form + ) + { + string[] tmp = spec.Split(new[] { "-" }, StringSplitOptions.None); + if (tmp.Length < 2) return; + Species = Array.IndexOf(species, tmp[0].Replace(" ", "")); + Form = tmp[1].Replace(" ", ""); + if (tmp.Length > 2) + Form += " " + tmp[2]; + } + if (Species < -1) + return; + lines = lines.Skip(1).Take(lines.Length - 1).ToArray(); + } + int movectr = 0; + // Detect relevant data + foreach (string line in lines) + { + if (line.Length < 2) continue; + if (line.Contains("- ")) + { + string moveString = line.Substring(2); + if (moveString.Contains("Hidden Power")) + { + if (moveString.Length > 13) // Defined Hidden Power + { + string type = moveString.Remove(0, 13).Replace("[", "").Replace("]", ""); // Trim out excess data + int hpVal = Array.IndexOf(hptypes, type); // Get HP Type + if (hpVal >= 0) IVs = PKX.setHPIVs(hpVal, IVs); // Get IVs + } + moveString = "Hidden Power"; + } + Moves[movectr++] = Array.IndexOf(moves, moveString); + if (movectr == 4) + break; // End of moves + continue; + } + + string[] brokenline = line.Split(new[] { ": " }, StringSplitOptions.None); + switch (brokenline[0]) + { + case "Trait": + case "Ability": { Ability = Array.IndexOf(abilities, brokenline[1]); break; } + case "Level": { Level = Util.ToInt32(brokenline[1]); break; } + case "Shiny": { Shiny = brokenline[1] == "Yes"; break; } + case "Happiness": { Friendship = Util.ToInt32(brokenline[1]); break; } + case "EVs": + { + // Get EV list String + string[] evlist = brokenline[1].Replace("SAtk", "SpA").Replace("SDef", "SpD").Replace("Spd", "Spe").Split(new[] { " / ", " " }, StringSplitOptions.None); + for (int i = 0; i < evlist.Length / 2; i++) + EVs[Array.IndexOf(StatNames, evlist[1 + i * 2])] = (byte)Util.ToInt32(evlist[0 + 2 * i]); + break; + } + case "IVs": + { + // Get IV list String + string[] ivlist = brokenline[1].Split(new[] { " / ", " " }, StringSplitOptions.None); + for (int i = 0; i < ivlist.Length / 2; i++) + IVs[Array.IndexOf(StatNames, ivlist[1 + i * 2])] = (byte)Util.ToInt32(ivlist[0 + 2 * i]); + break; + } + default: + { + // Either Nature or Gender ItemSpecies + if (brokenline[0].Contains(" @ ")) + { + string[] ld = line.Split(new[] { " @ " }, StringSplitOptions.None); + Item = Array.IndexOf(items, ld.Last()); + // Gender Detection + string last3 = ld[0].Substring(ld[0].Length - 3); + if (last3 == "(M)" || last3 == "(F)") + { + Gender = last3.Substring(1, 1); + ld[0] = ld[0].Substring(0, ld[ld.Length - 2].Length - 3); + } + // Nickname Detection + string spec = ld[0]; + if (spec.Contains("(")) + { + int index = spec.LastIndexOf("(", StringComparison.Ordinal); + string n1 = spec.Substring(0, index - 1); + string n2 = spec.Substring(index).Replace("(", "").Replace(")", "").Replace(" ", ""); + + bool inverted = Array.IndexOf(species, n2.Replace(" ", "")) > -1 || (Species = Array.IndexOf(species, n2.Split('-')[0])) > 0; + spec = inverted ? n2 : n1; + Nickname = inverted ? n1 : n2; + } + if ( + (Species = Array.IndexOf(species, spec)) < 0 // Not an Edge Case + && + (Species = Array.IndexOf(species, spec.Replace(" ", ""))) < 0 // Has Form + ) + { + string[] tmp = spec.Split(new[] { "-" }, StringSplitOptions.None); + Species = Array.IndexOf(species, tmp[0].Replace(" ", "")); + Form = tmp[1].Replace(" ", ""); + if (tmp.Length > 2) + Form += " " + tmp[2]; + } + } + else if (brokenline[0].Contains("Nature")) + Nature = Array.IndexOf(natures, line.Split(' ')[0]); + else // Fallback + Species = Array.IndexOf(species, line.Split('(')[0]); + } + break; + } + } + } + public string getText() + { + if (Species == 0 || Species > 722) + return ""; + + // First Line: Name, Nickname, Gender, Item + string result = string.Format(species[Species] != Nickname ? "{0} ({1})" : "{1}", Nickname, + species[Species] + ((Form ?? "") != "" ? "-" + Form.Replace("Mega ", "Mega-") : "")) // Species (& Form if necessary) + + Gender + (Item != 0 ? " @ " + items[Item] : "") + Environment.NewLine; + + // IVs + string[] ivstr = new string[6]; + int ivctr = 0; + int[] sIVs = { IVs[0], IVs[1], IVs[2], IVs[4], IVs[5], IVs[3] }; // Reorganize speed + for (int i = 0; i < 6; i++) + { + if (sIVs[i] == 31) continue; + ivstr[ivctr++] += $"{sIVs[i]} {StatNames[i]}"; + } + if (ivctr > 0) + result += "IVs: " + string.Join(" / ", ivstr.Take(ivctr)) + Environment.NewLine; + + // EVs + string[] evstr = new string[6]; + int[] sEVs = { EVs[0], EVs[1], EVs[2], EVs[4], EVs[5], EVs[3] }; // Reorganize speed + int evctr = 0; + for (int i = 0; i < 6; i++) + { + if (sEVs[i] == 0) continue; + evstr[evctr++] += $"{sEVs[i]} {StatNames[i]}"; + } + if (evctr > 0) + result += "EVs: " + string.Join(" / ", evstr.Take(evctr)) + Environment.NewLine; + + // Secondary Stats + result += "Ability: " + abilities[Ability] + Environment.NewLine; + result += "Level: " + Level + Environment.NewLine; + if (Shiny) + result += "Shiny: Yes" + Environment.NewLine; + + result += natures[Nature] + " Nature" + Environment.NewLine; + // Add in Moves + string[] MoveLines = new string[Moves.Length]; + int movectr = 0; + foreach (int move in Moves.Where(move => move != 0 && move < moves.Length)) + { + MoveLines[movectr] += "- " + moves[move]; + if (move == 237) + MoveLines[movectr] += $" [{hptypes[PKX.getHPType(IVs)]}]"; + movectr++; + } + result += string.Join(Environment.NewLine, MoveLines.Take(movectr)); + + return result; + } + internal static string getShowdownText(PKM pkm) + { + if (pkm.Species == 0) return ""; + ShowdownSet Set = new ShowdownSet + { + Nickname = pkm.Nickname, + Species = pkm.Species, + Item = pkm.HeldItem, + Ability = pkm.Ability, + EVs = pkm.EVs, + IVs = pkm.IVs, + Moves = pkm.Moves, + Nature = pkm.Nature, + Gender = new[] { " (M)", " (F)", "" }[pkm.Gender], + Friendship = pkm.CurrentFriendship, + Level = PKX.getLevel(pkm.Species, pkm.EXP), + Shiny = pkm.IsShiny, + Form = pkm.AltForm > 0 ? PKX.getFormList(pkm.Species, types, forms, new[] { "", "F", "" })[pkm.AltForm] : "", + }; + if (Set.Form == "F") Set.Gender = ""; + return Set.getText(); + } + } +} diff --git a/PKX/f1-Main.Designer.cs b/PKX/f1-Main.Designer.cs index 56bd6582f..53014fead 100644 --- a/PKX/f1-Main.Designer.cs +++ b/PKX/f1-Main.Designer.cs @@ -179,30 +179,24 @@ public void InitializeComponent() this.CB_Move2 = new System.Windows.Forms.ComboBox(); this.CB_Move1 = new System.Windows.Forms.ComboBox(); this.Tab_OTMisc = new System.Windows.Forms.TabPage(); - this.CHK_Diamond = new System.Windows.Forms.CheckBox(); - this.CHK_Star = new System.Windows.Forms.CheckBox(); - this.CHK_Heart = new System.Windows.Forms.CheckBox(); - this.CHK_Square = new System.Windows.Forms.CheckBox(); this.TB_EC = new System.Windows.Forms.TextBox(); this.GB_nOT = new System.Windows.Forms.GroupBox(); this.Label_CTGender = new System.Windows.Forms.Label(); this.TB_OTt2 = new System.Windows.Forms.TextBox(); this.Label_PrevOT = new System.Windows.Forms.Label(); - this.CHK_Triangle = new System.Windows.Forms.CheckBox(); - this.CHK_Circle = new System.Windows.Forms.CheckBox(); this.BTN_RerollEC = new System.Windows.Forms.Button(); this.BTN_History = new System.Windows.Forms.Button(); this.BTN_Ribbons = new System.Windows.Forms.Button(); this.GB_Markings = new System.Windows.Forms.GroupBox(); - this.PB_MarkPentagon = new System.Windows.Forms.PictureBox(); - this.PB_MarkCured = new System.Windows.Forms.PictureBox(); - this.PB_MarkShiny = new System.Windows.Forms.PictureBox(); this.PB_Mark6 = new System.Windows.Forms.PictureBox(); - this.PB_Mark5 = new System.Windows.Forms.PictureBox(); - this.PB_Mark4 = new System.Windows.Forms.PictureBox(); + this.PB_MarkPentagon = new System.Windows.Forms.PictureBox(); this.PB_Mark3 = new System.Windows.Forms.PictureBox(); + this.PB_Mark5 = new System.Windows.Forms.PictureBox(); + this.PB_MarkCured = new System.Windows.Forms.PictureBox(); this.PB_Mark2 = new System.Windows.Forms.PictureBox(); + this.PB_MarkShiny = new System.Windows.Forms.PictureBox(); this.PB_Mark1 = new System.Windows.Forms.PictureBox(); + this.PB_Mark4 = new System.Windows.Forms.PictureBox(); this.GB_ExtraBytes = new System.Windows.Forms.GroupBox(); this.TB_ExtraByte = new System.Windows.Forms.MaskedTextBox(); this.CB_ExtraBytes = new System.Windows.Forms.ComboBox(); @@ -215,7 +209,6 @@ public void InitializeComponent() this.Label_SID = new System.Windows.Forms.Label(); this.Label_TID = new System.Windows.Forms.Label(); this.Label_EncryptionConstant = new System.Windows.Forms.Label(); - this.Label_Diamond = new System.Windows.Forms.Label(); this.menuStrip1 = new System.Windows.Forms.MenuStrip(); this.Menu_File = new System.Windows.Forms.ToolStripMenuItem(); this.Menu_Open = new System.Windows.Forms.ToolStripMenuItem(); @@ -312,7 +305,6 @@ public void InitializeComponent() this.ppkx5 = new System.Windows.Forms.PictureBox(); this.ppkx6 = new System.Windows.Forms.PictureBox(); this.Tab_Other = new System.Windows.Forms.TabPage(); - this.B_OpenSecretBase = new System.Windows.Forms.Button(); this.GB_Daycare = new System.Windows.Forms.GroupBox(); this.L_XP2 = new System.Windows.Forms.Label(); this.L_XP1 = new System.Windows.Forms.Label(); @@ -344,19 +336,22 @@ public void InitializeComponent() this.TB_GameSync = new System.Windows.Forms.TextBox(); this.B_SaveBoxBin = new System.Windows.Forms.Button(); this.B_VerifyCHK = new System.Windows.Forms.Button(); - this.B_OpenHallofFame = new System.Windows.Forms.Button(); - this.B_OUTPasserby = new System.Windows.Forms.Button(); - this.B_OpenPokepuffs = new System.Windows.Forms.Button(); - this.B_OpenBoxLayout = new System.Windows.Forms.Button(); - this.B_OpenOPowers = new System.Windows.Forms.Button(); - this.B_OpenItemPouch = new System.Windows.Forms.Button(); - this.B_OpenEventFlags = new System.Windows.Forms.Button(); - this.B_OpenWondercards = new System.Windows.Forms.Button(); - this.B_OpenTrainerInfo = new System.Windows.Forms.Button(); - this.B_OpenBerryField = new System.Windows.Forms.Button(); - this.B_OpenPokedex = new System.Windows.Forms.Button(); this.GB_SAVtools = new System.Windows.Forms.GroupBox(); + this.FLP_SAVtools = new System.Windows.Forms.FlowLayoutPanel(); + this.B_OpenPokepuffs = new System.Windows.Forms.Button(); + this.B_OpenItemPouch = new System.Windows.Forms.Button(); + this.B_OpenTrainerInfo = new System.Windows.Forms.Button(); + this.B_OUTPasserby = new System.Windows.Forms.Button(); + this.B_OpenBoxLayout = new System.Windows.Forms.Button(); + this.B_OpenWondercards = new System.Windows.Forms.Button(); this.B_OpenSuperTraining = new System.Windows.Forms.Button(); + this.B_OpenHallofFame = new System.Windows.Forms.Button(); + this.B_OpenOPowers = new System.Windows.Forms.Button(); + this.B_OpenEventFlags = new System.Windows.Forms.Button(); + this.B_OpenPokedex = new System.Windows.Forms.Button(); + this.B_OpenBerryField = new System.Windows.Forms.Button(); + this.B_OpenSecretBase = new System.Windows.Forms.Button(); + this.B_Pokeblocks = new System.Windows.Forms.Button(); this.dragout = new System.Windows.Forms.PictureBox(); this.mnuL = new System.Windows.Forms.ContextMenuStrip(this.components); this.mnuLLegality = new System.Windows.Forms.ToolStripMenuItem(); @@ -383,15 +378,15 @@ public void InitializeComponent() this.Tab_OTMisc.SuspendLayout(); this.GB_nOT.SuspendLayout(); this.GB_Markings.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.PB_MarkPentagon)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.PB_MarkCured)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.PB_MarkShiny)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.PB_Mark6)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.PB_Mark5)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.PB_Mark4)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.PB_MarkPentagon)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.PB_Mark3)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.PB_Mark5)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.PB_MarkCured)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.PB_Mark2)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.PB_MarkShiny)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.PB_Mark1)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.PB_Mark4)).BeginInit(); this.GB_ExtraBytes.SuspendLayout(); this.GB_OT.SuspendLayout(); this.menuStrip1.SuspendLayout(); @@ -460,6 +455,7 @@ public void InitializeComponent() ((System.ComponentModel.ISupportInitialize)(this.subepkx3)).BeginInit(); this.Tab_SAV.SuspendLayout(); this.GB_SAVtools.SuspendLayout(); + this.FLP_SAVtools.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dragout)).BeginInit(); this.mnuL.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.PB_Legal)).BeginInit(); @@ -1002,10 +998,10 @@ public void InitializeComponent() // TB_AbilityNumber // this.TB_AbilityNumber.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - this.TB_AbilityNumber.Location = new System.Drawing.Point(206, 153); + this.TB_AbilityNumber.Location = new System.Drawing.Point(229, 153); this.TB_AbilityNumber.Mask = "0"; this.TB_AbilityNumber.Name = "TB_AbilityNumber"; - this.TB_AbilityNumber.Size = new System.Drawing.Size(20, 20); + this.TB_AbilityNumber.Size = new System.Drawing.Size(19, 20); this.TB_AbilityNumber.TabIndex = 14; this.TB_AbilityNumber.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; this.TB_AbilityNumber.Visible = false; @@ -1032,7 +1028,7 @@ public void InitializeComponent() "Item"}); this.DEV_Ability.Location = new System.Drawing.Point(105, 153); this.DEV_Ability.Name = "DEV_Ability"; - this.DEV_Ability.Size = new System.Drawing.Size(100, 21); + this.DEV_Ability.Size = new System.Drawing.Size(122, 21); this.DEV_Ability.TabIndex = 14; this.DEV_Ability.Visible = false; // @@ -2243,14 +2239,8 @@ public void InitializeComponent() // Tab_OTMisc // this.Tab_OTMisc.AllowDrop = true; - this.Tab_OTMisc.Controls.Add(this.CHK_Diamond); - this.Tab_OTMisc.Controls.Add(this.CHK_Star); - this.Tab_OTMisc.Controls.Add(this.CHK_Heart); - this.Tab_OTMisc.Controls.Add(this.CHK_Square); this.Tab_OTMisc.Controls.Add(this.TB_EC); this.Tab_OTMisc.Controls.Add(this.GB_nOT); - this.Tab_OTMisc.Controls.Add(this.CHK_Triangle); - this.Tab_OTMisc.Controls.Add(this.CHK_Circle); this.Tab_OTMisc.Controls.Add(this.BTN_RerollEC); this.Tab_OTMisc.Controls.Add(this.BTN_History); this.Tab_OTMisc.Controls.Add(this.BTN_Ribbons); @@ -2258,7 +2248,6 @@ public void InitializeComponent() this.Tab_OTMisc.Controls.Add(this.GB_ExtraBytes); this.Tab_OTMisc.Controls.Add(this.GB_OT); this.Tab_OTMisc.Controls.Add(this.Label_EncryptionConstant); - this.Tab_OTMisc.Controls.Add(this.Label_Diamond); this.Tab_OTMisc.Location = new System.Drawing.Point(4, 22); this.Tab_OTMisc.Name = "Tab_OTMisc"; this.Tab_OTMisc.Padding = new System.Windows.Forms.Padding(3); @@ -2267,48 +2256,6 @@ public void InitializeComponent() this.Tab_OTMisc.Text = "OT/Misc"; this.Tab_OTMisc.UseVisualStyleBackColor = true; // - // CHK_Diamond - // - this.CHK_Diamond.AutoSize = true; - this.CHK_Diamond.Location = new System.Drawing.Point(205, 228); - this.CHK_Diamond.Name = "CHK_Diamond"; - this.CHK_Diamond.Size = new System.Drawing.Size(15, 14); - this.CHK_Diamond.TabIndex = 13; - this.CHK_Diamond.TextAlign = System.Drawing.ContentAlignment.TopLeft; - this.CHK_Diamond.UseVisualStyleBackColor = true; - this.CHK_Diamond.Visible = false; - // - // CHK_Star - // - this.CHK_Star.Location = new System.Drawing.Point(205, 213); - this.CHK_Star.Name = "CHK_Star"; - this.CHK_Star.Size = new System.Drawing.Size(38, 17); - this.CHK_Star.TabIndex = 13; - this.CHK_Star.Text = "★"; - this.CHK_Star.UseVisualStyleBackColor = true; - this.CHK_Star.Visible = false; - // - // CHK_Heart - // - this.CHK_Heart.Location = new System.Drawing.Point(205, 199); - this.CHK_Heart.Name = "CHK_Heart"; - this.CHK_Heart.Size = new System.Drawing.Size(37, 17); - this.CHK_Heart.TabIndex = 12; - this.CHK_Heart.Text = " ♥"; - this.CHK_Heart.UseVisualStyleBackColor = true; - this.CHK_Heart.Visible = false; - // - // CHK_Square - // - this.CHK_Square.Location = new System.Drawing.Point(29, 227); - this.CHK_Square.Name = "CHK_Square"; - this.CHK_Square.RightToLeft = System.Windows.Forms.RightToLeft.Yes; - this.CHK_Square.Size = new System.Drawing.Size(38, 17); - this.CHK_Square.TabIndex = 11; - this.CHK_Square.Text = "■"; - this.CHK_Square.UseVisualStyleBackColor = true; - this.CHK_Square.Visible = false; - // // TB_EC // this.TB_EC.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; @@ -2367,28 +2314,6 @@ public void InitializeComponent() this.Label_PrevOT.TextAlign = System.Drawing.ContentAlignment.MiddleRight; this.Label_PrevOT.Click += new System.EventHandler(this.clickCT); // - // CHK_Triangle - // - this.CHK_Triangle.Location = new System.Drawing.Point(29, 213); - this.CHK_Triangle.Name = "CHK_Triangle"; - this.CHK_Triangle.RightToLeft = System.Windows.Forms.RightToLeft.Yes; - this.CHK_Triangle.Size = new System.Drawing.Size(38, 17); - this.CHK_Triangle.TabIndex = 10; - this.CHK_Triangle.Text = "▲"; - this.CHK_Triangle.UseVisualStyleBackColor = true; - this.CHK_Triangle.Visible = false; - // - // CHK_Circle - // - this.CHK_Circle.Location = new System.Drawing.Point(27, 193); - this.CHK_Circle.Name = "CHK_Circle"; - this.CHK_Circle.RightToLeft = System.Windows.Forms.RightToLeft.Yes; - this.CHK_Circle.Size = new System.Drawing.Size(40, 28); - this.CHK_Circle.TabIndex = 9; - this.CHK_Circle.Text = "●"; - this.CHK_Circle.UseVisualStyleBackColor = true; - this.CHK_Circle.Visible = false; - // // BTN_RerollEC // this.BTN_RerollEC.Font = new System.Drawing.Font("Microsoft Sans Serif", 6.75F); @@ -2422,15 +2347,15 @@ public void InitializeComponent() // // GB_Markings // - this.GB_Markings.Controls.Add(this.PB_MarkPentagon); - this.GB_Markings.Controls.Add(this.PB_MarkCured); - this.GB_Markings.Controls.Add(this.PB_MarkShiny); this.GB_Markings.Controls.Add(this.PB_Mark6); - this.GB_Markings.Controls.Add(this.PB_Mark5); - this.GB_Markings.Controls.Add(this.PB_Mark4); + this.GB_Markings.Controls.Add(this.PB_MarkPentagon); this.GB_Markings.Controls.Add(this.PB_Mark3); + this.GB_Markings.Controls.Add(this.PB_Mark5); + this.GB_Markings.Controls.Add(this.PB_MarkCured); this.GB_Markings.Controls.Add(this.PB_Mark2); + this.GB_Markings.Controls.Add(this.PB_MarkShiny); this.GB_Markings.Controls.Add(this.PB_Mark1); + this.GB_Markings.Controls.Add(this.PB_Mark4); this.GB_Markings.Location = new System.Drawing.Point(68, 188); this.GB_Markings.Name = "GB_Markings"; this.GB_Markings.Size = new System.Drawing.Size(135, 58); @@ -2438,6 +2363,19 @@ public void InitializeComponent() this.GB_Markings.TabStop = false; this.GB_Markings.Text = "Markings"; // + // PB_Mark6 + // + this.PB_Mark6.Image = ((System.Drawing.Image)(resources.GetObject("PB_Mark6.Image"))); + this.PB_Mark6.InitialImage = ((System.Drawing.Image)(resources.GetObject("PB_Mark6.InitialImage"))); + this.PB_Mark6.Location = new System.Drawing.Point(110, 36); + this.PB_Mark6.Margin = new System.Windows.Forms.Padding(1); + this.PB_Mark6.Name = "PB_Mark6"; + this.PB_Mark6.Size = new System.Drawing.Size(20, 20); + this.PB_Mark6.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage; + this.PB_Mark6.TabIndex = 5; + this.PB_Mark6.TabStop = false; + this.PB_Mark6.Click += new System.EventHandler(this.clickMarking); + // // PB_MarkPentagon // this.PB_MarkPentagon.Image = ((System.Drawing.Image)(resources.GetObject("PB_MarkPentagon.Image"))); @@ -2449,6 +2387,32 @@ public void InitializeComponent() this.PB_MarkPentagon.TabIndex = 8; this.PB_MarkPentagon.TabStop = false; // + // PB_Mark3 + // + this.PB_Mark3.Image = ((System.Drawing.Image)(resources.GetObject("PB_Mark3.Image"))); + this.PB_Mark3.InitialImage = ((System.Drawing.Image)(resources.GetObject("PB_Mark3.InitialImage"))); + this.PB_Mark3.Location = new System.Drawing.Point(47, 36); + this.PB_Mark3.Margin = new System.Windows.Forms.Padding(1); + this.PB_Mark3.Name = "PB_Mark3"; + this.PB_Mark3.Size = new System.Drawing.Size(20, 20); + this.PB_Mark3.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage; + this.PB_Mark3.TabIndex = 2; + this.PB_Mark3.TabStop = false; + this.PB_Mark3.Click += new System.EventHandler(this.clickMarking); + // + // PB_Mark5 + // + this.PB_Mark5.Image = ((System.Drawing.Image)(resources.GetObject("PB_Mark5.Image"))); + this.PB_Mark5.InitialImage = ((System.Drawing.Image)(resources.GetObject("PB_Mark5.InitialImage"))); + this.PB_Mark5.Location = new System.Drawing.Point(89, 36); + this.PB_Mark5.Margin = new System.Windows.Forms.Padding(1); + this.PB_Mark5.Name = "PB_Mark5"; + this.PB_Mark5.Size = new System.Drawing.Size(20, 20); + this.PB_Mark5.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage; + this.PB_Mark5.TabIndex = 4; + this.PB_Mark5.TabStop = false; + this.PB_Mark5.Click += new System.EventHandler(this.clickMarking); + // // PB_MarkCured // this.PB_MarkCured.Image = ((System.Drawing.Image)(resources.GetObject("PB_MarkCured.Image"))); @@ -2460,6 +2424,19 @@ public void InitializeComponent() this.PB_MarkCured.TabIndex = 7; this.PB_MarkCured.TabStop = false; // + // PB_Mark2 + // + this.PB_Mark2.Image = ((System.Drawing.Image)(resources.GetObject("PB_Mark2.Image"))); + this.PB_Mark2.InitialImage = ((System.Drawing.Image)(resources.GetObject("PB_Mark2.InitialImage"))); + this.PB_Mark2.Location = new System.Drawing.Point(26, 36); + this.PB_Mark2.Margin = new System.Windows.Forms.Padding(1); + this.PB_Mark2.Name = "PB_Mark2"; + this.PB_Mark2.Size = new System.Drawing.Size(20, 20); + this.PB_Mark2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage; + this.PB_Mark2.TabIndex = 1; + this.PB_Mark2.TabStop = false; + this.PB_Mark2.Click += new System.EventHandler(this.clickMarking); + // // PB_MarkShiny // this.PB_MarkShiny.Image = ((System.Drawing.Image)(resources.GetObject("PB_MarkShiny.Image"))); @@ -2471,71 +2448,12 @@ public void InitializeComponent() this.PB_MarkShiny.TabIndex = 6; this.PB_MarkShiny.TabStop = false; // - // PB_Mark6 - // - this.PB_Mark6.Image = ((System.Drawing.Image)(resources.GetObject("PB_Mark6.Image"))); - this.PB_Mark6.InitialImage = ((System.Drawing.Image)(resources.GetObject("PB_Mark6.InitialImage"))); - this.PB_Mark6.Location = new System.Drawing.Point(107, 35); - this.PB_Mark6.Name = "PB_Mark6"; - this.PB_Mark6.Size = new System.Drawing.Size(20, 20); - this.PB_Mark6.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage; - this.PB_Mark6.TabIndex = 5; - this.PB_Mark6.TabStop = false; - this.PB_Mark6.Click += new System.EventHandler(this.clickMarking); - // - // PB_Mark5 - // - this.PB_Mark5.Image = ((System.Drawing.Image)(resources.GetObject("PB_Mark5.Image"))); - this.PB_Mark5.InitialImage = ((System.Drawing.Image)(resources.GetObject("PB_Mark5.InitialImage"))); - this.PB_Mark5.Location = new System.Drawing.Point(87, 35); - this.PB_Mark5.Name = "PB_Mark5"; - this.PB_Mark5.Size = new System.Drawing.Size(20, 20); - this.PB_Mark5.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage; - this.PB_Mark5.TabIndex = 4; - this.PB_Mark5.TabStop = false; - this.PB_Mark5.Click += new System.EventHandler(this.clickMarking); - // - // PB_Mark4 - // - this.PB_Mark4.Image = ((System.Drawing.Image)(resources.GetObject("PB_Mark4.Image"))); - this.PB_Mark4.InitialImage = ((System.Drawing.Image)(resources.GetObject("PB_Mark4.InitialImage"))); - this.PB_Mark4.Location = new System.Drawing.Point(67, 35); - this.PB_Mark4.Name = "PB_Mark4"; - this.PB_Mark4.Size = new System.Drawing.Size(20, 20); - this.PB_Mark4.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage; - this.PB_Mark4.TabIndex = 3; - this.PB_Mark4.TabStop = false; - this.PB_Mark4.Click += new System.EventHandler(this.clickMarking); - // - // PB_Mark3 - // - this.PB_Mark3.Image = ((System.Drawing.Image)(resources.GetObject("PB_Mark3.Image"))); - this.PB_Mark3.InitialImage = ((System.Drawing.Image)(resources.GetObject("PB_Mark3.InitialImage"))); - this.PB_Mark3.Location = new System.Drawing.Point(47, 35); - this.PB_Mark3.Name = "PB_Mark3"; - this.PB_Mark3.Size = new System.Drawing.Size(20, 20); - this.PB_Mark3.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage; - this.PB_Mark3.TabIndex = 2; - this.PB_Mark3.TabStop = false; - this.PB_Mark3.Click += new System.EventHandler(this.clickMarking); - // - // PB_Mark2 - // - this.PB_Mark2.Image = ((System.Drawing.Image)(resources.GetObject("PB_Mark2.Image"))); - this.PB_Mark2.InitialImage = ((System.Drawing.Image)(resources.GetObject("PB_Mark2.InitialImage"))); - this.PB_Mark2.Location = new System.Drawing.Point(27, 35); - this.PB_Mark2.Name = "PB_Mark2"; - this.PB_Mark2.Size = new System.Drawing.Size(20, 20); - this.PB_Mark2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage; - this.PB_Mark2.TabIndex = 1; - this.PB_Mark2.TabStop = false; - this.PB_Mark2.Click += new System.EventHandler(this.clickMarking); - // // PB_Mark1 // this.PB_Mark1.Image = ((System.Drawing.Image)(resources.GetObject("PB_Mark1.Image"))); this.PB_Mark1.InitialImage = ((System.Drawing.Image)(resources.GetObject("PB_Mark1.InitialImage"))); - this.PB_Mark1.Location = new System.Drawing.Point(7, 35); + this.PB_Mark1.Location = new System.Drawing.Point(5, 36); + this.PB_Mark1.Margin = new System.Windows.Forms.Padding(1); this.PB_Mark1.Name = "PB_Mark1"; this.PB_Mark1.Size = new System.Drawing.Size(20, 20); this.PB_Mark1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage; @@ -2543,6 +2461,19 @@ public void InitializeComponent() this.PB_Mark1.TabStop = false; this.PB_Mark1.Click += new System.EventHandler(this.clickMarking); // + // PB_Mark4 + // + this.PB_Mark4.Image = ((System.Drawing.Image)(resources.GetObject("PB_Mark4.Image"))); + this.PB_Mark4.InitialImage = ((System.Drawing.Image)(resources.GetObject("PB_Mark4.InitialImage"))); + this.PB_Mark4.Location = new System.Drawing.Point(68, 36); + this.PB_Mark4.Margin = new System.Windows.Forms.Padding(1); + this.PB_Mark4.Name = "PB_Mark4"; + this.PB_Mark4.Size = new System.Drawing.Size(20, 20); + this.PB_Mark4.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage; + this.PB_Mark4.TabIndex = 3; + this.PB_Mark4.TabStop = false; + this.PB_Mark4.Click += new System.EventHandler(this.clickMarking); + // // GB_ExtraBytes // this.GB_ExtraBytes.Controls.Add(this.TB_ExtraByte); @@ -2569,34 +2500,7 @@ public void InitializeComponent() this.CB_ExtraBytes.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.CB_ExtraBytes.FormattingEnabled = true; this.CB_ExtraBytes.Items.AddRange(new object[] { - "0x36", - "0x37", - "0x3B", - "0x3C", - "0x3D", - "0x3E", - "0x3F", - "0x58", - "0x59", - "0x73", - "0x90", - "0x91", - "0x9E", - "0x9F", - "0xA0", - "0xA1", - "0xA7", - "0xAA", - "0xAB", - "0xAC", - "0xAD", - "0xC8", - "0xC9", - "0xD7", - "0xE4", - "0xE5", - "0xE6", - "0xE7"}); + "0x00"}); this.CB_ExtraBytes.Location = new System.Drawing.Point(20, 18); this.CB_ExtraBytes.Name = "CB_ExtraBytes"; this.CB_ExtraBytes.Size = new System.Drawing.Size(57, 21); @@ -2701,15 +2605,6 @@ public void InitializeComponent() this.Label_EncryptionConstant.Text = "Encryption Constant:"; this.Label_EncryptionConstant.TextAlign = System.Drawing.ContentAlignment.MiddleRight; // - // Label_Diamond - // - this.Label_Diamond.Location = new System.Drawing.Point(215, 224); - this.Label_Diamond.Name = "Label_Diamond"; - this.Label_Diamond.Size = new System.Drawing.Size(26, 20); - this.Label_Diamond.TabIndex = 11; - this.Label_Diamond.Text = " ♦"; - this.Label_Diamond.Visible = false; - // // menuStrip1 // this.menuStrip1.BackColor = System.Drawing.Color.Transparent; @@ -2736,19 +2631,21 @@ public void InitializeComponent() // // Menu_Open // + this.Menu_Open.Image = global::PKHeX.Properties.Resources.open; 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(139, 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); // // Menu_Save // + this.Menu_Save.Image = global::PKHeX.Properties.Resources.savePKM; 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(139, 22); + this.Menu_Save.Size = new System.Drawing.Size(152, 22); this.Menu_Save.Text = "&Save PK6..."; this.Menu_Save.Click += new System.EventHandler(this.mainMenuSave); // @@ -2758,34 +2655,38 @@ public void InitializeComponent() this.Menu_ExportMAIN, this.Menu_ExportBAK}); this.Menu_ExportSAV.Enabled = false; + this.Menu_ExportSAV.Image = global::PKHeX.Properties.Resources.saveSAV; this.Menu_ExportSAV.Name = "Menu_ExportSAV"; - this.Menu_ExportSAV.Size = new System.Drawing.Size(139, 22); + this.Menu_ExportSAV.Size = new System.Drawing.Size(152, 22); this.Menu_ExportSAV.Text = "&Export SAV..."; // // Menu_ExportMAIN // + this.Menu_ExportMAIN.Image = global::PKHeX.Properties.Resources.main; this.Menu_ExportMAIN.Name = "Menu_ExportMAIN"; this.Menu_ExportMAIN.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.E))); this.Menu_ExportMAIN.ShowShortcutKeys = false; - this.Menu_ExportMAIN.Size = new System.Drawing.Size(130, 22); + this.Menu_ExportMAIN.Size = new System.Drawing.Size(152, 22); this.Menu_ExportMAIN.Text = "&Export main"; this.Menu_ExportMAIN.Click += new System.EventHandler(this.clickExportSAV); // // Menu_ExportBAK // + this.Menu_ExportBAK.Image = global::PKHeX.Properties.Resources.bak; this.Menu_ExportBAK.Name = "Menu_ExportBAK"; this.Menu_ExportBAK.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.B))); this.Menu_ExportBAK.ShowShortcutKeys = false; - this.Menu_ExportBAK.Size = new System.Drawing.Size(130, 22); + this.Menu_ExportBAK.Size = new System.Drawing.Size(152, 22); this.Menu_ExportBAK.Text = "Export &BAK"; this.Menu_ExportBAK.Click += new System.EventHandler(this.clickExportSAVBAK); // // Menu_Exit // + this.Menu_Exit.Image = global::PKHeX.Properties.Resources.exit; this.Menu_Exit.Name = "Menu_Exit"; this.Menu_Exit.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.Q))); this.Menu_Exit.ShowShortcutKeys = false; - this.Menu_Exit.Size = new System.Drawing.Size(139, 22); + this.Menu_Exit.Size = new System.Drawing.Size(152, 22); this.Menu_Exit.Text = "&Quit"; this.Menu_Exit.Click += new System.EventHandler(this.mainMenuExit); // @@ -2807,31 +2708,35 @@ public void InitializeComponent() this.Menu_ShowdownExportPK6, this.Menu_ShowdownExportParty, this.Menu_ShowdownExportBattleBox}); + this.Menu_Showdown.Image = global::PKHeX.Properties.Resources.showdown; this.Menu_Showdown.Name = "Menu_Showdown"; this.Menu_Showdown.Size = new System.Drawing.Size(143, 22); this.Menu_Showdown.Text = "Showdown"; // // Menu_ShowdownImportPK6 // + this.Menu_ShowdownImportPK6.Image = global::PKHeX.Properties.Resources.import; this.Menu_ShowdownImportPK6.Name = "Menu_ShowdownImportPK6"; + this.Menu_ShowdownImportPK6.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.T))); + this.Menu_ShowdownImportPK6.ShowShortcutKeys = false; this.Menu_ShowdownImportPK6.Size = new System.Drawing.Size(231, 22); this.Menu_ShowdownImportPK6.Text = "Import Set from Clipboard"; this.Menu_ShowdownImportPK6.Click += new System.EventHandler(this.clickShowdownImportPK6); - this.Menu_ShowdownImportPK6.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.T))); - this.Menu_ShowdownImportPK6.ShowShortcutKeys = false; // // Menu_ShowdownExportPK6 // + this.Menu_ShowdownExportPK6.Image = global::PKHeX.Properties.Resources.export; this.Menu_ShowdownExportPK6.Name = "Menu_ShowdownExportPK6"; + this.Menu_ShowdownExportPK6.ShortcutKeys = ((System.Windows.Forms.Keys)(((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.Shift) + | System.Windows.Forms.Keys.T))); + this.Menu_ShowdownExportPK6.ShowShortcutKeys = false; this.Menu_ShowdownExportPK6.Size = new System.Drawing.Size(231, 22); this.Menu_ShowdownExportPK6.Text = "Export Set to Clipboard"; this.Menu_ShowdownExportPK6.Click += new System.EventHandler(this.clickShowdownExportPK6); - this.Menu_ShowdownExportPK6.ShortcutKeys = ((System.Windows.Forms.Keys)(((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.Shift) - | System.Windows.Forms.Keys.T))); - this.Menu_ShowdownExportPK6.ShowShortcutKeys = false; // // Menu_ShowdownExportParty // + this.Menu_ShowdownExportParty.Image = global::PKHeX.Properties.Resources.export; this.Menu_ShowdownExportParty.Name = "Menu_ShowdownExportParty"; this.Menu_ShowdownExportParty.Size = new System.Drawing.Size(231, 22); this.Menu_ShowdownExportParty.Text = "Export Party to Clipboard"; @@ -2839,6 +2744,7 @@ public void InitializeComponent() // // Menu_ShowdownExportBattleBox // + this.Menu_ShowdownExportBattleBox.Image = global::PKHeX.Properties.Resources.export; this.Menu_ShowdownExportBattleBox.Name = "Menu_ShowdownExportBattleBox"; this.Menu_ShowdownExportBattleBox.Size = new System.Drawing.Size(231, 22); this.Menu_ShowdownExportBattleBox.Text = "Export Battle Box to Clipboard"; @@ -2849,12 +2755,14 @@ public void InitializeComponent() this.Menu_CyberGadget.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.Menu_OpenTemp, this.Menu_OpenCache}); + this.Menu_CyberGadget.Image = global::PKHeX.Properties.Resources.other; this.Menu_CyberGadget.Name = "Menu_CyberGadget"; this.Menu_CyberGadget.Size = new System.Drawing.Size(143, 22); this.Menu_CyberGadget.Text = "CyberGadget"; // // Menu_OpenTemp // + this.Menu_OpenTemp.Image = global::PKHeX.Properties.Resources.folder; this.Menu_OpenTemp.Name = "Menu_OpenTemp"; this.Menu_OpenTemp.Size = new System.Drawing.Size(175, 22); this.Menu_OpenTemp.Text = "Open Temp Folder"; @@ -2862,6 +2770,7 @@ public void InitializeComponent() // // Menu_OpenCache // + this.Menu_OpenCache.Image = global::PKHeX.Properties.Resources.folder; this.Menu_OpenCache.Name = "Menu_OpenCache"; this.Menu_OpenCache.Size = new System.Drawing.Size(175, 22); this.Menu_OpenCache.Text = "Open Cache Folder"; @@ -2874,12 +2783,14 @@ public void InitializeComponent() this.Menu_DumpBoxes, this.Menu_Report, this.Menu_Database}); + this.Menu_Data.Image = global::PKHeX.Properties.Resources.data; this.Menu_Data.Name = "Menu_Data"; this.Menu_Data.Size = new System.Drawing.Size(143, 22); this.Menu_Data.Text = "Data"; // // Menu_LoadBoxes // + this.Menu_LoadBoxes.Image = global::PKHeX.Properties.Resources.load; this.Menu_LoadBoxes.Name = "Menu_LoadBoxes"; this.Menu_LoadBoxes.Size = new System.Drawing.Size(151, 22); this.Menu_LoadBoxes.Text = "Load Boxes"; @@ -2887,6 +2798,7 @@ public void InitializeComponent() // // Menu_DumpBoxes // + this.Menu_DumpBoxes.Image = global::PKHeX.Properties.Resources.dump; this.Menu_DumpBoxes.Name = "Menu_DumpBoxes"; this.Menu_DumpBoxes.Size = new System.Drawing.Size(151, 22); this.Menu_DumpBoxes.Text = "Dump Boxes"; @@ -2894,6 +2806,7 @@ public void InitializeComponent() // // Menu_Report // + this.Menu_Report.Image = global::PKHeX.Properties.Resources.report; this.Menu_Report.Name = "Menu_Report"; this.Menu_Report.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.R))); this.Menu_Report.ShowShortcutKeys = false; @@ -2903,6 +2816,7 @@ public void InitializeComponent() // // Menu_Database // + this.Menu_Database.Image = global::PKHeX.Properties.Resources.database; this.Menu_Database.Name = "Menu_Database"; this.Menu_Database.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.D))); this.Menu_Database.ShowShortcutKeys = false; @@ -2915,12 +2829,14 @@ public void InitializeComponent() this.Menu_Other.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.Menu_OpenSDF, this.Menu_OpenSDB}); + this.Menu_Other.Image = global::PKHeX.Properties.Resources.other; this.Menu_Other.Name = "Menu_Other"; this.Menu_Other.Size = new System.Drawing.Size(143, 22); this.Menu_Other.Text = "Other"; // // Menu_OpenSDF // + this.Menu_OpenSDF.Image = global::PKHeX.Properties.Resources.folder; this.Menu_OpenSDF.Name = "Menu_OpenSDF"; this.Menu_OpenSDF.Size = new System.Drawing.Size(229, 22); this.Menu_OpenSDF.Text = "Open SaveDataFiler Folder"; @@ -2928,6 +2844,7 @@ public void InitializeComponent() // // Menu_OpenSDB // + this.Menu_OpenSDB.Image = global::PKHeX.Properties.Resources.folder; this.Menu_OpenSDB.Name = "Menu_OpenSDB"; this.Menu_OpenSDB.Size = new System.Drawing.Size(229, 22); this.Menu_OpenSDB.Text = "Open SaveDataBackup Folder"; @@ -2948,6 +2865,7 @@ public void InitializeComponent() // this.Menu_Language.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.CB_MainLanguage}); + this.Menu_Language.Image = global::PKHeX.Properties.Resources.language; this.Menu_Language.Name = "Menu_Language"; this.Menu_Language.Size = new System.Drawing.Size(139, 22); this.Menu_Language.Text = "Language"; @@ -2964,6 +2882,7 @@ public void InitializeComponent() this.Menu_Modify.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.Menu_ModifyDex, this.Menu_ModifyPK6}); + this.Menu_Modify.Image = global::PKHeX.Properties.Resources.settings; this.Menu_Modify.Name = "Menu_Modify"; this.Menu_Modify.Size = new System.Drawing.Size(139, 22); this.Menu_Modify.Text = "Set to SAV"; @@ -2986,7 +2905,7 @@ public void InitializeComponent() this.Menu_ModifyPK6.Name = "Menu_ModifyPK6"; this.Menu_ModifyPK6.Size = new System.Drawing.Size(159, 22); this.Menu_ModifyPK6.Text = "Modify PK6 Info"; - this.Menu_ModifyPK6.Click += new System.EventHandler(this.mainMenuModifyPK6); + this.Menu_ModifyPK6.Click += new System.EventHandler(this.mainMenuModifyPKM); // // Menu_Unicode // @@ -3000,6 +2919,7 @@ public void InitializeComponent() // // Menu_About // + this.Menu_About.Image = global::PKHeX.Properties.Resources.about; this.Menu_About.Name = "Menu_About"; this.Menu_About.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.P))); this.Menu_About.ShowShortcutKeys = false; @@ -3830,7 +3750,6 @@ public void InitializeComponent() // // Tab_Other // - this.Tab_Other.Controls.Add(this.B_OpenSecretBase); this.Tab_Other.Controls.Add(this.GB_Daycare); this.Tab_Other.Controls.Add(this.GB_GTS); this.Tab_Other.Controls.Add(this.GB_Fused); @@ -3843,17 +3762,6 @@ public void InitializeComponent() this.Tab_Other.Text = "Other"; this.Tab_Other.UseVisualStyleBackColor = true; // - // B_OpenSecretBase - // - this.B_OpenSecretBase.Location = new System.Drawing.Point(227, 151); - this.B_OpenSecretBase.Name = "B_OpenSecretBase"; - this.B_OpenSecretBase.Size = new System.Drawing.Size(60, 37); - this.B_OpenSecretBase.TabIndex = 21; - this.B_OpenSecretBase.Text = "Secret Base"; - this.B_OpenSecretBase.UseVisualStyleBackColor = true; - this.B_OpenSecretBase.Visible = false; - this.B_OpenSecretBase.Click += new System.EventHandler(this.B_OpenSecretBase_Click); - // // GB_Daycare // this.GB_Daycare.Controls.Add(this.L_XP2); @@ -4118,7 +4026,7 @@ public void InitializeComponent() this.TB_Secure2.Size = new System.Drawing.Size(120, 20); this.TB_Secure2.TabIndex = 17; this.TB_Secure2.Text = "0000000000000000"; - this.TB_Secure2.TextChanged += new System.EventHandler(this.updateSecure2); + this.TB_Secure2.TextChanged += new System.EventHandler(this.updateU64); // // L_Secure1 // @@ -4139,11 +4047,10 @@ public void InitializeComponent() this.TB_Secure1.Size = new System.Drawing.Size(120, 20); this.TB_Secure1.TabIndex = 15; this.TB_Secure1.Text = "0000000000000000"; - this.TB_Secure1.TextChanged += new System.EventHandler(this.updateSecure1); + this.TB_Secure1.TextChanged += new System.EventHandler(this.updateU64); // // B_JPEG // - this.B_JPEG.Enabled = false; this.B_JPEG.Location = new System.Drawing.Point(198, 20); this.B_JPEG.Name = "B_JPEG"; this.B_JPEG.Size = new System.Drawing.Size(75, 45); @@ -4171,7 +4078,7 @@ public void InitializeComponent() this.TB_GameSync.Size = new System.Drawing.Size(120, 20); this.TB_GameSync.TabIndex = 10; this.TB_GameSync.Text = "0000000000000000"; - this.TB_GameSync.TextChanged += new System.EventHandler(this.updateGameSync); + this.TB_GameSync.TextChanged += new System.EventHandler(this.updateU64); // // B_SaveBoxBin // @@ -4194,147 +4101,182 @@ public void InitializeComponent() this.B_VerifyCHK.UseVisualStyleBackColor = true; this.B_VerifyCHK.Click += new System.EventHandler(this.clickVerifyCHK); // - // B_OpenHallofFame + // GB_SAVtools // - this.B_OpenHallofFame.Location = new System.Drawing.Point(230, 41); - this.B_OpenHallofFame.Name = "B_OpenHallofFame"; - this.B_OpenHallofFame.Size = new System.Drawing.Size(75, 23); - this.B_OpenHallofFame.TabIndex = 8; - this.B_OpenHallofFame.Text = "Hall of Fame"; - this.B_OpenHallofFame.UseVisualStyleBackColor = true; - this.B_OpenHallofFame.Click += new System.EventHandler(this.B_OUTHallofFame_Click); + this.GB_SAVtools.Controls.Add(this.FLP_SAVtools); + this.GB_SAVtools.Location = new System.Drawing.Point(300, 252); + this.GB_SAVtools.Name = "GB_SAVtools"; + this.GB_SAVtools.Size = new System.Drawing.Size(308, 100); + this.GB_SAVtools.TabIndex = 100; + this.GB_SAVtools.TabStop = false; // - // B_OUTPasserby + // FLP_SAVtools // - this.B_OUTPasserby.Location = new System.Drawing.Point(230, 12); - this.B_OUTPasserby.Name = "B_OUTPasserby"; - this.B_OUTPasserby.Size = new System.Drawing.Size(75, 23); - this.B_OUTPasserby.TabIndex = 4; - this.B_OUTPasserby.Text = "Passerby"; - this.B_OUTPasserby.UseVisualStyleBackColor = true; - this.B_OUTPasserby.Click += new System.EventHandler(this.B_OUTPasserby_Click); + this.FLP_SAVtools.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.FLP_SAVtools.AutoScroll = true; + this.FLP_SAVtools.Controls.Add(this.B_OpenPokepuffs); + this.FLP_SAVtools.Controls.Add(this.B_OpenItemPouch); + this.FLP_SAVtools.Controls.Add(this.B_OpenTrainerInfo); + this.FLP_SAVtools.Controls.Add(this.B_OUTPasserby); + this.FLP_SAVtools.Controls.Add(this.B_OpenBoxLayout); + this.FLP_SAVtools.Controls.Add(this.B_OpenWondercards); + this.FLP_SAVtools.Controls.Add(this.B_OpenSuperTraining); + this.FLP_SAVtools.Controls.Add(this.B_OpenHallofFame); + this.FLP_SAVtools.Controls.Add(this.B_OpenOPowers); + this.FLP_SAVtools.Controls.Add(this.B_OpenEventFlags); + this.FLP_SAVtools.Controls.Add(this.B_OpenPokedex); + this.FLP_SAVtools.Controls.Add(this.B_OpenBerryField); + this.FLP_SAVtools.Controls.Add(this.B_OpenSecretBase); + this.FLP_SAVtools.Controls.Add(this.B_Pokeblocks); + this.FLP_SAVtools.Location = new System.Drawing.Point(6, 10); + this.FLP_SAVtools.Name = "FLP_SAVtools"; + this.FLP_SAVtools.Size = new System.Drawing.Size(297, 87); + this.FLP_SAVtools.TabIndex = 101; // // B_OpenPokepuffs // - this.B_OpenPokepuffs.Location = new System.Drawing.Point(5, 12); + this.B_OpenPokepuffs.Location = new System.Drawing.Point(3, 3); this.B_OpenPokepuffs.Name = "B_OpenPokepuffs"; - this.B_OpenPokepuffs.Size = new System.Drawing.Size(75, 23); + this.B_OpenPokepuffs.Size = new System.Drawing.Size(87, 23); this.B_OpenPokepuffs.TabIndex = 1; this.B_OpenPokepuffs.Text = "‎Poké Puffs"; this.B_OpenPokepuffs.UseVisualStyleBackColor = true; this.B_OpenPokepuffs.Click += new System.EventHandler(this.B_OpenPokepuffs_Click); // - // B_OpenBoxLayout - // - this.B_OpenBoxLayout.Location = new System.Drawing.Point(5, 41); - this.B_OpenBoxLayout.Name = "B_OpenBoxLayout"; - this.B_OpenBoxLayout.Size = new System.Drawing.Size(75, 23); - this.B_OpenBoxLayout.TabIndex = 5; - this.B_OpenBoxLayout.Text = "Box Layout"; - this.B_OpenBoxLayout.UseVisualStyleBackColor = true; - this.B_OpenBoxLayout.Click += new System.EventHandler(this.B_OpenBoxLayout_Click); - // - // B_OpenOPowers - // - this.B_OpenOPowers.Location = new System.Drawing.Point(5, 70); - this.B_OpenOPowers.Name = "B_OpenOPowers"; - this.B_OpenOPowers.Size = new System.Drawing.Size(75, 23); - this.B_OpenOPowers.TabIndex = 9; - this.B_OpenOPowers.Text = "O-Powers"; - this.B_OpenOPowers.UseVisualStyleBackColor = true; - this.B_OpenOPowers.Click += new System.EventHandler(this.B_OpenOPowers_Click); - // // B_OpenItemPouch // - this.B_OpenItemPouch.Location = new System.Drawing.Point(80, 12); + this.B_OpenItemPouch.Location = new System.Drawing.Point(96, 3); this.B_OpenItemPouch.Name = "B_OpenItemPouch"; - this.B_OpenItemPouch.Size = new System.Drawing.Size(75, 23); + this.B_OpenItemPouch.Size = new System.Drawing.Size(87, 23); this.B_OpenItemPouch.TabIndex = 2; this.B_OpenItemPouch.Text = "Items"; this.B_OpenItemPouch.UseVisualStyleBackColor = true; this.B_OpenItemPouch.Click += new System.EventHandler(this.B_OpenItemPouch_Click); // - // B_OpenEventFlags - // - this.B_OpenEventFlags.Location = new System.Drawing.Point(80, 70); - this.B_OpenEventFlags.Name = "B_OpenEventFlags"; - this.B_OpenEventFlags.Size = new System.Drawing.Size(75, 23); - this.B_OpenEventFlags.TabIndex = 10; - this.B_OpenEventFlags.Text = "Event Flags"; - this.B_OpenEventFlags.UseVisualStyleBackColor = true; - this.B_OpenEventFlags.Click += new System.EventHandler(this.B_OpenEventFlags_Click); - // - // B_OpenWondercards - // - this.B_OpenWondercards.Location = new System.Drawing.Point(80, 41); - this.B_OpenWondercards.Name = "B_OpenWondercards"; - this.B_OpenWondercards.Size = new System.Drawing.Size(75, 23); - this.B_OpenWondercards.TabIndex = 6; - this.B_OpenWondercards.Text = "Wondercard"; - this.B_OpenWondercards.UseVisualStyleBackColor = true; - this.B_OpenWondercards.Click += new System.EventHandler(this.B_OpenWondercards_Click); - // // B_OpenTrainerInfo // - this.B_OpenTrainerInfo.Location = new System.Drawing.Point(155, 12); + this.B_OpenTrainerInfo.Location = new System.Drawing.Point(189, 3); this.B_OpenTrainerInfo.Name = "B_OpenTrainerInfo"; - this.B_OpenTrainerInfo.Size = new System.Drawing.Size(75, 23); + this.B_OpenTrainerInfo.Size = new System.Drawing.Size(87, 23); this.B_OpenTrainerInfo.TabIndex = 3; this.B_OpenTrainerInfo.Text = "Trainer Info"; this.B_OpenTrainerInfo.UseVisualStyleBackColor = true; this.B_OpenTrainerInfo.Click += new System.EventHandler(this.B_OpenTrainerInfo_Click); // - // B_OpenBerryField + // B_OUTPasserby // - this.B_OpenBerryField.Location = new System.Drawing.Point(230, 70); - this.B_OpenBerryField.Name = "B_OpenBerryField"; - this.B_OpenBerryField.Size = new System.Drawing.Size(75, 23); - this.B_OpenBerryField.TabIndex = 12; - this.B_OpenBerryField.Text = "Berry Field"; - this.B_OpenBerryField.UseVisualStyleBackColor = true; - this.B_OpenBerryField.Click += new System.EventHandler(this.B_OpenBerryField_Click); + this.B_OUTPasserby.Location = new System.Drawing.Point(3, 32); + this.B_OUTPasserby.Name = "B_OUTPasserby"; + this.B_OUTPasserby.Size = new System.Drawing.Size(87, 23); + this.B_OUTPasserby.TabIndex = 4; + this.B_OUTPasserby.Text = "Passerby"; + this.B_OUTPasserby.UseVisualStyleBackColor = true; + this.B_OUTPasserby.Click += new System.EventHandler(this.B_OUTPasserby_Click); + // + // B_OpenBoxLayout + // + this.B_OpenBoxLayout.Location = new System.Drawing.Point(96, 32); + this.B_OpenBoxLayout.Name = "B_OpenBoxLayout"; + this.B_OpenBoxLayout.Size = new System.Drawing.Size(87, 23); + this.B_OpenBoxLayout.TabIndex = 5; + this.B_OpenBoxLayout.Text = "Box Layout"; + this.B_OpenBoxLayout.UseVisualStyleBackColor = true; + this.B_OpenBoxLayout.Click += new System.EventHandler(this.B_OpenBoxLayout_Click); + // + // B_OpenWondercards + // + this.B_OpenWondercards.Location = new System.Drawing.Point(189, 32); + this.B_OpenWondercards.Name = "B_OpenWondercards"; + this.B_OpenWondercards.Size = new System.Drawing.Size(87, 23); + this.B_OpenWondercards.TabIndex = 6; + this.B_OpenWondercards.Text = "Wondercard"; + this.B_OpenWondercards.UseVisualStyleBackColor = true; + this.B_OpenWondercards.Click += new System.EventHandler(this.B_OpenWondercards_Click); + // + // B_OpenSuperTraining + // + this.B_OpenSuperTraining.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.B_OpenSuperTraining.Location = new System.Drawing.Point(3, 61); + this.B_OpenSuperTraining.Name = "B_OpenSuperTraining"; + this.B_OpenSuperTraining.Size = new System.Drawing.Size(87, 23); + this.B_OpenSuperTraining.TabIndex = 7; + this.B_OpenSuperTraining.Text = "Super Train"; + this.B_OpenSuperTraining.UseVisualStyleBackColor = true; + this.B_OpenSuperTraining.Click += new System.EventHandler(this.B_OpenSuperTraining_Click); + // + // B_OpenHallofFame + // + this.B_OpenHallofFame.Location = new System.Drawing.Point(96, 61); + this.B_OpenHallofFame.Name = "B_OpenHallofFame"; + this.B_OpenHallofFame.Size = new System.Drawing.Size(87, 23); + this.B_OpenHallofFame.TabIndex = 8; + this.B_OpenHallofFame.Text = "Hall of Fame"; + this.B_OpenHallofFame.UseVisualStyleBackColor = true; + this.B_OpenHallofFame.Click += new System.EventHandler(this.B_OUTHallofFame_Click); + // + // B_OpenOPowers + // + this.B_OpenOPowers.Location = new System.Drawing.Point(189, 61); + this.B_OpenOPowers.Name = "B_OpenOPowers"; + this.B_OpenOPowers.Size = new System.Drawing.Size(87, 23); + this.B_OpenOPowers.TabIndex = 9; + this.B_OpenOPowers.Text = "O-Powers"; + this.B_OpenOPowers.UseVisualStyleBackColor = true; + this.B_OpenOPowers.Click += new System.EventHandler(this.B_OpenOPowers_Click); + // + // B_OpenEventFlags + // + this.B_OpenEventFlags.Location = new System.Drawing.Point(3, 90); + this.B_OpenEventFlags.Name = "B_OpenEventFlags"; + this.B_OpenEventFlags.Size = new System.Drawing.Size(87, 23); + this.B_OpenEventFlags.TabIndex = 10; + this.B_OpenEventFlags.Text = "Event Flags"; + this.B_OpenEventFlags.UseVisualStyleBackColor = true; + this.B_OpenEventFlags.Click += new System.EventHandler(this.B_OpenEventFlags_Click); // // B_OpenPokedex // - this.B_OpenPokedex.Location = new System.Drawing.Point(155, 70); + this.B_OpenPokedex.Location = new System.Drawing.Point(96, 90); this.B_OpenPokedex.Name = "B_OpenPokedex"; - this.B_OpenPokedex.Size = new System.Drawing.Size(75, 23); + this.B_OpenPokedex.Size = new System.Drawing.Size(87, 23); this.B_OpenPokedex.TabIndex = 11; this.B_OpenPokedex.Text = "Pokédex"; this.B_OpenPokedex.UseVisualStyleBackColor = true; this.B_OpenPokedex.Click += new System.EventHandler(this.B_OpenPokedex_Click); // - // GB_SAVtools + // B_OpenBerryField // - this.GB_SAVtools.Controls.Add(this.B_OpenSuperTraining); - this.GB_SAVtools.Controls.Add(this.B_OpenPokedex); - this.GB_SAVtools.Controls.Add(this.B_OpenHallofFame); - this.GB_SAVtools.Controls.Add(this.B_OpenBerryField); - this.GB_SAVtools.Controls.Add(this.B_OpenBoxLayout); - this.GB_SAVtools.Controls.Add(this.B_OpenTrainerInfo); - this.GB_SAVtools.Controls.Add(this.B_OUTPasserby); - this.GB_SAVtools.Controls.Add(this.B_OpenWondercards); - this.GB_SAVtools.Controls.Add(this.B_OpenEventFlags); - this.GB_SAVtools.Controls.Add(this.B_OpenItemPouch); - this.GB_SAVtools.Controls.Add(this.B_OpenOPowers); - this.GB_SAVtools.Controls.Add(this.B_OpenPokepuffs); - this.GB_SAVtools.Enabled = false; - this.GB_SAVtools.Location = new System.Drawing.Point(300, 254); - this.GB_SAVtools.Name = "GB_SAVtools"; - this.GB_SAVtools.Size = new System.Drawing.Size(310, 100); - this.GB_SAVtools.TabIndex = 100; - this.GB_SAVtools.TabStop = false; + this.B_OpenBerryField.Location = new System.Drawing.Point(189, 90); + this.B_OpenBerryField.Name = "B_OpenBerryField"; + this.B_OpenBerryField.Size = new System.Drawing.Size(87, 23); + this.B_OpenBerryField.TabIndex = 12; + this.B_OpenBerryField.Text = "Berry Field"; + this.B_OpenBerryField.UseVisualStyleBackColor = true; + this.B_OpenBerryField.Click += new System.EventHandler(this.B_OpenBerryField_Click); // - // B_OpenSuperTraining + // B_OpenSecretBase // - this.B_OpenSuperTraining.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.B_OpenSuperTraining.Location = new System.Drawing.Point(155, 41); - this.B_OpenSuperTraining.Name = "B_OpenSuperTraining"; - this.B_OpenSuperTraining.Size = new System.Drawing.Size(75, 23); - this.B_OpenSuperTraining.TabIndex = 7; - this.B_OpenSuperTraining.Text = "Super Train"; - this.B_OpenSuperTraining.UseVisualStyleBackColor = true; - this.B_OpenSuperTraining.Click += new System.EventHandler(this.B_OpenSuperTraining_Click); + this.B_OpenSecretBase.Location = new System.Drawing.Point(3, 119); + this.B_OpenSecretBase.Name = "B_OpenSecretBase"; + this.B_OpenSecretBase.Size = new System.Drawing.Size(87, 23); + this.B_OpenSecretBase.TabIndex = 21; + this.B_OpenSecretBase.Text = "Secret Base"; + this.B_OpenSecretBase.UseVisualStyleBackColor = true; + this.B_OpenSecretBase.Visible = false; + this.B_OpenSecretBase.Click += new System.EventHandler(this.B_OpenSecretBase_Click); + // + // B_Pokeblocks + // + this.B_Pokeblocks.Location = new System.Drawing.Point(96, 119); + this.B_Pokeblocks.Name = "B_Pokeblocks"; + this.B_Pokeblocks.Size = new System.Drawing.Size(87, 23); + this.B_Pokeblocks.TabIndex = 22; + this.B_Pokeblocks.Text = "Pokéblocks"; + this.B_Pokeblocks.UseVisualStyleBackColor = true; + this.B_Pokeblocks.Visible = false; + this.B_Pokeblocks.Click += new System.EventHandler(this.B_OpenPokeblocks_Click); // // dragout // @@ -4400,11 +4342,11 @@ public void InitializeComponent() this.ClientSize = new System.Drawing.Size(614, 361); this.Controls.Add(this.PB_Legal); this.Controls.Add(this.dragout); - this.Controls.Add(this.GB_SAVtools); this.Controls.Add(this.tabBoxMulti); this.Controls.Add(this.L_Save); this.Controls.Add(this.tabMain); this.Controls.Add(this.menuStrip1); + this.Controls.Add(this.GB_SAVtools); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.KeyPreview = true; @@ -4440,15 +4382,15 @@ public void InitializeComponent() this.GB_nOT.ResumeLayout(false); this.GB_nOT.PerformLayout(); this.GB_Markings.ResumeLayout(false); - ((System.ComponentModel.ISupportInitialize)(this.PB_MarkPentagon)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.PB_MarkCured)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.PB_MarkShiny)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.PB_Mark6)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.PB_Mark5)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.PB_Mark4)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.PB_MarkPentagon)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.PB_Mark3)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.PB_Mark5)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.PB_MarkCured)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.PB_Mark2)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.PB_MarkShiny)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.PB_Mark1)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.PB_Mark4)).EndInit(); this.GB_ExtraBytes.ResumeLayout(false); this.GB_ExtraBytes.PerformLayout(); this.GB_OT.ResumeLayout(false); @@ -4528,6 +4470,7 @@ public void InitializeComponent() this.Tab_SAV.ResumeLayout(false); this.Tab_SAV.PerformLayout(); this.GB_SAVtools.ResumeLayout(false); + this.FLP_SAVtools.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.dragout)).EndInit(); this.mnuL.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.PB_Legal)).EndInit(); @@ -4570,12 +4513,6 @@ public void InitializeComponent() private System.Windows.Forms.Button BTN_History; private System.Windows.Forms.Button BTN_Ribbons; private System.Windows.Forms.GroupBox GB_Markings; - private System.Windows.Forms.CheckBox CHK_Diamond; - private System.Windows.Forms.CheckBox CHK_Square; - private System.Windows.Forms.CheckBox CHK_Star; - private System.Windows.Forms.CheckBox CHK_Triangle; - private System.Windows.Forms.CheckBox CHK_Heart; - private System.Windows.Forms.CheckBox CHK_Circle; private System.Windows.Forms.GroupBox GB_ExtraBytes; private System.Windows.Forms.ComboBox CB_ExtraBytes; public System.Windows.Forms.GroupBox GB_OT; @@ -4665,7 +4602,6 @@ public void InitializeComponent() private System.Windows.Forms.CheckBox CHK_Nicknamed; private System.Windows.Forms.Button BTN_Shinytize; private System.Windows.Forms.MaskedTextBox TB_AbilityNumber; - private System.Windows.Forms.Label Label_Diamond; private System.Windows.Forms.MaskedTextBox TB_MetLevel; public System.Windows.Forms.GroupBox GB_nOT; private System.Windows.Forms.MenuStrip menuStrip1; @@ -4689,7 +4625,6 @@ public void InitializeComponent() private System.Windows.Forms.Button B_OpenTrainerInfo; private System.Windows.Forms.Button B_OpenBerryField; private System.Windows.Forms.Button B_OpenPokedex; - private System.Windows.Forms.GroupBox GB_SAVtools; private System.Windows.Forms.TabPage Tab_Other; private System.Windows.Forms.Label L_BattleBox; private System.Windows.Forms.Label L_Party; @@ -4783,7 +4718,6 @@ public void InitializeComponent() private System.Windows.Forms.PictureBox PB_Mark4; private System.Windows.Forms.PictureBox PB_Mark3; private System.Windows.Forms.PictureBox PB_Mark2; - private System.Windows.Forms.PictureBox PB_Mark1; private System.Windows.Forms.PictureBox Label_IsShiny; private System.Windows.Forms.Panel PAN_Party; private System.Windows.Forms.Panel PAN_BattleBox; @@ -4870,6 +4804,10 @@ public void InitializeComponent() private System.Windows.Forms.ToolStripMenuItem mnuLLegality; private System.Windows.Forms.ToolStripMenuItem mnuLQR; private System.Windows.Forms.PictureBox PB_Legal; + private System.Windows.Forms.FlowLayoutPanel FLP_SAVtools; + private System.Windows.Forms.GroupBox GB_SAVtools; + private System.Windows.Forms.PictureBox PB_Mark1; + private System.Windows.Forms.Button B_Pokeblocks; } } diff --git a/PKX/f1-Main.cs b/PKX/f1-Main.cs index 7cd6a5fef..153d0f277 100644 --- a/PKX/f1-Main.cs +++ b/PKX/f1-Main.cs @@ -17,10 +17,13 @@ public Main() { #region Initialize Form new Thread(() => new SplashScreen().ShowDialog()).Start(); + pkm_from = SAV.BlankPKM.EncryptedPartyData; InitializeComponent(); - // Initialize SAV-Set Parameters in case compilation settings were changed. - SAV6.SetUpdateDex = Menu_ModifyDex.Checked; - SAV6.SetUpdatePK6 = Menu_ModifyPK6.Checked; + CB_ExtraBytes.SelectedIndex = 0; + SaveFile.SetUpdateDex = Menu_ModifyDex.Checked; + SaveFile.SetUpdatePKM = Menu_ModifyPK6.Checked; + + // Set up form properties and arrays. SlotPictureBoxes = new[] { bpkx1, bpkx2, bpkx3, bpkx4, bpkx5, bpkx6, bpkx7, bpkx8, bpkx9, bpkx10,bpkx11,bpkx12, @@ -37,24 +40,18 @@ public Main() movePB = new[] { PB_WarnMove1, PB_WarnMove2, PB_WarnMove3, PB_WarnMove4 }; defaultControlWhite = CB_Species.BackColor; defaultControlText = Label_Species.ForeColor; - CB_ExtraBytes.SelectedIndex = 0; - - // Initialize Boxes - for (int i = 0; i < 30*31; i++) - SAV.setData(blankEK6, SAV.Box + i*PK6.SIZE_STORED); // Set up Language Selection foreach (var cbItem in main_langlist) CB_MainLanguage.Items.Add(cbItem); // ToolTips for Drag&Drop - new ToolTip().SetToolTip(dragout, "PK6 QuickSave"); + new ToolTip().SetToolTip(dragout, "PKM QuickSave"); // Box Drag & Drop foreach (PictureBox pb in PAN_Box.Controls) { - pb.AllowDrop = true; - // The PictureBoxes have their own drag&drop event handlers. + pb.AllowDrop = true; // The PictureBoxes have their own drag&drop event handlers (pbBoxSlot) } foreach (TabPage tab in tabMain.TabPages) { @@ -68,67 +65,6 @@ public Main() tab.DragDrop += tabMain_DragDrop; tab.DragEnter += tabMain_DragEnter; } - // Box to Tabs D&D - dragout.AllowDrop = true; - - string[] args = Environment.GetCommandLineArgs(); - string filename = args.Length > 0 ? Path.GetFileNameWithoutExtension(args[0]).ToLower() : ""; - HaX = filename.IndexOf("hax", StringComparison.Ordinal) >= 0; - // Show Hacked Stuff if HaX - CHK_HackedStats.Enabled = CHK_HackedStats.Visible = DEV_Ability.Enabled = DEV_Ability.Visible = - MT_Level.Enabled = MT_Level.Visible = TB_AbilityNumber.Visible = MT_Form.Enabled = MT_Form.Visible = HaX; - // Hide Regular Stuff if !HaX - TB_Level.Visible = CB_Ability.Visible = !HaX; - // Load WC6 folder to legality - refreshWC6DB(); - - Menu_Modify.DropDown.Closing += (sender, e) => - { - if (e.CloseReason == ToolStripDropDownCloseReason.ItemClicked) - e.Cancel = true; - }; - #endregion - #region Localize & Populate Fields - // Try and detect the language - string lastTwoChars = filename.Length > 2 ? filename.Substring(filename.Length - 2) : ""; - if (lastTwoChars == "jp") lastTwoChars = "ja"; - int lang = Array.IndexOf(lang_val, lastTwoChars); - CB_MainLanguage.SelectedIndex = lang < 0 ? 1 : lang; - - InitializeFields(); - #endregion - #region Load Initial File(s) - // Load the arguments - pathSDF = Util.GetSDFLocation(); - path3DS = Util.get3DSLocation(); - string pathCache = Util.GetCacheFolder(); - if (args.Length > 1) - { - foreach (string arg in args.Skip(1).Where(a => a.Length > 4)) - openQuick(arg); - } - else if (path3DS != null && File.Exists(Path.Combine(Path.GetPathRoot(path3DS), "SaveDataBackup", "main"))) - openQuick(Path.Combine(Path.GetPathRoot(path3DS), "SaveDataBackup", "main")); - else if (pathSDF != null) - openQuick(Path.Combine(pathSDF, "main")); - else if (path3DS != null && Directory.Exists(Path.Combine(Path.GetPathRoot(path3DS), "JKSV", "Saves"))) - { - string[] files = Directory.GetFiles(Path.Combine(Path.GetPathRoot(path3DS), "JKSV", "Saves"), "main", SearchOption.AllDirectories); - string file = files.Where(f => SAV6.SizeValid((int)new FileInfo(f).Length)) // filter - .OrderByDescending(f => new FileInfo(f).LastWriteTime).FirstOrDefault(); - - if (file != null) - openQuick(file); - } - else if (Directory.Exists(pathCache)) - { - string file = Directory.GetFiles(pathCache).Where(f => SAV6.SizeValid((int)new FileInfo(f).Length)) // filter - .OrderByDescending(f => new FileInfo(f).LastWriteTime).FirstOrDefault(); - if (file != null) - openQuick(file); - } - else if (File.Exists(Util.NormalizePath(Path.Combine(Util.GetTempFolder(), "root", "main")))) - openQuick(Util.NormalizePath(Path.Combine(Util.GetTempFolder(), "root", "main"))); GB_OT.Click += clickGT; GB_nOT.Click += clickGT; @@ -138,7 +74,46 @@ public Main() TB_Nickname.Font = PKX.getPKXFont(11); TB_OT.Font = (Font)TB_Nickname.Font.Clone(); TB_OTt2.Font = (Font)TB_Nickname.Font.Clone(); + + Menu_Modify.DropDown.Closing += (sender, e) => + { + if (e.CloseReason == ToolStripDropDownCloseReason.ItemClicked) + e.Cancel = true; + }; + + // Box to Tabs D&D + dragout.AllowDrop = true; + + // Load WC6 folder to legality + refreshWC6DB(); + + #endregion + #region Localize & Populate Fields + string[] args = Environment.GetCommandLineArgs(); + string filename = args.Length > 0 ? Path.GetFileNameWithoutExtension(args[0]).ToLower() : ""; + HaX = filename.IndexOf("hax", StringComparison.Ordinal) >= 0; + + // Try and detect the language + string lastTwoChars = filename.Length > 2 ? filename.Substring(filename.Length - 2) : ""; + if (lastTwoChars == "jp") lastTwoChars = "ja"; + int lang = Array.IndexOf(lang_val, lastTwoChars); + CB_MainLanguage.SelectedIndex = lang < 0 ? 1 : lang; + + InitializeFields(); formInitialized = true; + #endregion + #region Load Initial File(s) + if (args.Length > 1) // Load the arguments + { + foreach (string arg in args.Skip(1).Where(a => a.Length > 4)) + openQuick(arg, force: true); + } + else // Detect save + { + string path = detectSaveFile(); + if (path != null) + openQuick(path, force: true); + } // Splash Screen closes on its own. BringToFront(); @@ -150,15 +125,14 @@ public Main() } #region Important Variables - public static readonly byte[] blankEK6 = PKX.encryptArray(new byte[PK6.SIZE_PARTY]); - public static PK6 pk6 = new PK6(); // Tab Pokemon Data Storage - public static SAV6 SAV = new SAV6 { Game = (int)GameVersion.AS, OT = "PKHeX", TID = 12345, SID = 54321, Language = 2, Country = 49, SubRegion = 7}; // Save File - public static Color defaultControlWhite; - public static Color defaultControlText; + public static PKM pkm = new PK6(); // Tab Pokemon Data Storage + public static SaveFile SAV = new SAV6 { Game = (int)GameVersion.AS, OT = "PKHeX", TID = 12345, SID = 54321, Language = 2, Country = 49, SubRegion = 7 }; // Save File + public static Color defaultControlWhite, defaultControlText; public static string eggname = ""; public const string DatabasePath = "db"; private const string WC6DatabasePath = "wc6"; private const string BackupPath = "bak"; + public static string curlanguage = "en"; public static string[] gendersymbols = { "♂", "♀", "-" }; public static string[] specieslist, movelist, itemlist, abilitylist, types, natures, forms, memories, genloc, trainingbags, trainingstage, characteristics, @@ -167,18 +141,15 @@ public Main() public static string[] metBW2_00000, metBW2_30000, metBW2_40000, metBW2_60000 = { }; public static string[] metXY_00000, metXY_30000, metXY_40000, metXY_60000 = { }; public static string[] wallpapernames, puffs, itempouch = { }; - public static string curlanguage = "en"; public static bool unicode; public static List MoveDataSource, ItemDataSource, SpeciesDataSource, BallDataSource, NatureDataSource, AbilityDataSource, VersionDataSource; public static volatile bool formInitialized, fieldsInitialized, fieldsLoaded; - private static int colorizedbox = 32; + private static int colorizedbox = -1; private static Image colorizedcolor; private static int colorizedslot; - private static string pathSDF; - private static string path3DS; private static bool HaX; - private LegalityAnalysis Legality = new LegalityAnalysis(new PK6()); + private LegalityAnalysis Legality = new LegalityAnalysis(new PK3()); private static readonly Image mixedHighlight = Util.ChangeOpacity(Properties.Resources.slotSet, 0.5); private static readonly string[] lang_val = { "ja", "en", "fr", "it", "de", "es", "ko", "zh", "pt" }; private static readonly string[] main_langlist = @@ -218,26 +189,13 @@ private void mainMenuOpen(object sender, EventArgs e) ofd.InitialDirectory = Environment.CurrentDirectory; // Detect main - string cyberpath = Util.GetTempFolder(); - pathSDF = Util.GetSDFLocation(); - path3DS = Util.get3DSLocation(); - string pathCache = Util.GetCacheFolder(); - if (path3DS != null && File.Exists(Path.Combine(Path.GetPathRoot(path3DS), "SaveDataBackup", "main"))) - ofd.InitialDirectory = Path.Combine(Path.GetPathRoot(path3DS), "SaveDataBackup"); - else if (pathSDF != null) - ofd.InitialDirectory = pathSDF; - else if (path3DS != null && Directory.Exists(Path.Combine(Path.GetPathRoot(path3DS), "JKSV", "Saves"))) - ofd.InitialDirectory = Path.Combine(Path.GetPathRoot(path3DS), "JKSV", "Saves"); - else if (path3DS != null) - ofd.InitialDirectory = Path.GetPathRoot(path3DS); - else if (Directory.Exists(Path.Combine(cyberpath, "root"))) - ofd.InitialDirectory = Path.Combine(cyberpath, "root"); - else if (Directory.Exists(pathCache)) - ofd.InitialDirectory = pathCache; - else if (Directory.Exists(cyberpath)) - ofd.InitialDirectory = cyberpath; - else if (File.Exists(Path.Combine(ofd.InitialDirectory, "main"))) { } - else { ofd.RestoreDirectory = false; ofd.FilterIndex = 1; ofd.FileName = ""; } + string path = detectSaveFile(); + if (path != null) + { ofd.InitialDirectory = Path.GetDirectoryName(path); } + else if (File.Exists(Path.Combine(ofd.InitialDirectory, "main"))) + { } + else if (!Directory.Exists(ofd.InitialDirectory)) + { ofd.RestoreDirectory = false; ofd.FilterIndex = 1; ofd.FileName = ""; } if (ofd.ShowDialog() == DialogResult.OK) openQuick(ofd.FileName); @@ -245,7 +203,7 @@ private void mainMenuOpen(object sender, EventArgs e) private void mainMenuSave(object sender, EventArgs e) { if (!verifiedPKX()) return; - PK6 pk = preparepkx(); + PKM pk = preparePKM(); SaveFileDialog sfd = new SaveFileDialog { Filter = "PKX File|*.pk6;*.pkx" + @@ -275,7 +233,7 @@ private void mainMenuSave(object sender, EventArgs e) else { Util.Error($"Foreign File Extension: {ext}", "Exporting as encrypted."); - File.WriteAllBytes(path, pk6.EncryptedPartyData); + File.WriteAllBytes(path, pkm.EncryptedPartyData); } } private void mainMenuExit(object sender, EventArgs e) @@ -295,10 +253,10 @@ private void mainMenuBoxReport(object sender, EventArgs e) var z = Application.OpenForms.Cast
().FirstOrDefault(form => form.GetType() == typeof(frmReport)) as frmReport; if (z != null) { Util.CenterToForm(z, this); z.BringToFront(); return; } - + frmReport ReportForm = new frmReport(); ReportForm.Show(); - ReportForm.PopulateData(SAV.Data, SAV.Box); + ReportForm.PopulateData(SAV.BoxData); } private void mainMenuDatabase(object sender, EventArgs e) { @@ -319,11 +277,11 @@ private void mainMenuUnicode(object sender, EventArgs e) } private void mainMenuModifyDex(object sender, EventArgs e) { - SAV6.SetUpdateDex = Menu_ModifyDex.Checked; + SaveFile.SetUpdateDex = Menu_ModifyDex.Checked; } - private void mainMenuModifyPK6(object sender, EventArgs e) + private void mainMenuModifyPKM(object sender, EventArgs e) { - SAV6.SetUpdatePK6 = Menu_ModifyPK6.Checked; + SaveFile.SetUpdatePKM = Menu_ModifyPK6.Checked; } private void mainMenuBoxLoad(object sender, EventArgs e) { @@ -387,7 +345,7 @@ private void clickShowdownImportPK6(object sender, EventArgs e) { Util.Alert("Clipboard does not contain text."); return; } // Get Simulator Data - PKX.ShowdownSet Set = new PKX.ShowdownSet(Clipboard.GetText()); + ShowdownSet Set = new ShowdownSet(Clipboard.GetText()); if (Set.Species < 0) { Util.Alert("Set data not found in clipboard."); return; } @@ -453,15 +411,17 @@ private void clickShowdownImportPK6(object sender, EventArgs e) BTN_RerollPID.PerformClick(); BTN_RerollEC.PerformClick(); if (Set.Shiny) BTN_Shinytize.PerformClick(); - pk6 = preparepkx(); + pkm = preparePKM(); updateLegality(); } private void clickShowdownExportPK6(object sender, EventArgs e) { + if (!formInitialized) + return; if (!verifiedPKX()) { Util.Alert("Fix data before exporting."); return; } - Clipboard.SetText(preparepkx().ShowdownText); + Clipboard.SetText(preparePKM().ShowdownText); Util.Alert("Exported Showdown Set to Clipboard:", Clipboard.GetText()); } private void clickShowdownExportParty(object sender, EventArgs e) @@ -509,13 +469,14 @@ private void clickOpenCacheFolder(object sender, EventArgs e) private void clickOpenSDFFolder(object sender, EventArgs e) { string path; - if (path3DS != null && Directory.Exists(path = Util.GetSDFLocation())) + if (Util.get3DSLocation() != null && Directory.Exists(path = Util.GetSDFLocation())) Process.Start("explorer.exe", @path); else Util.Alert("Can't find the SaveDataFiler folder."); } private void clickOpenSDBFolder(object sender, EventArgs e) { + string path3DS = Util.get3DSLocation(); string path; if (path3DS != null && Directory.Exists(path = Path.Combine(Path.GetPathRoot(path3DS), "SaveDataBackup"))) Process.Start("explorer.exe", @path); @@ -524,8 +485,13 @@ private void clickOpenSDBFolder(object sender, EventArgs e) } // Main Menu Subfunctions - private void openQuick(string path) + private void openQuick(string path, bool force = false) { + if (!(CanFocus || force)) + { + SystemSounds.Asterisk.Play(); + return; + } // detect if it is a folder (load into boxes or not) if (Directory.Exists(path)) { loadBoxesFromDB(path); return; } @@ -537,41 +503,23 @@ private void openQuick(string path) else { byte[] input; try { input = File.ReadAllBytes(path); } - catch { Util.Error("File is in use by another program!", path); return; } + catch (Exception e) { Util.Error("File is in use by another program!", path, e.ToString()); return; } try { openFile(input, path, ext); } - catch - { - if (input.Length <= PK6.SIZE_PARTY) - try - { - byte[] blank = (byte[])blankEK6.Clone(); - - for (int i = 0; i < PK6.SIZE_STORED; i++) - blank[i] ^= input[i]; - - openFile(blank, path, ext); - } - catch { try { openFile(input, path, ext); return; } catch {} } - - Util.Error("Unable to load file."); - } + catch (Exception e) { Util.Error("Unable to load file.", e.ToString()); } } } private void openFile(byte[] input, string path, string ext) { + MysteryGift tg; PKM temp; string c; #region Powersaves Read-Only Conversion if (input.Length == 0x10009C) // Resize to 1MB { Array.Copy(input, 0x9C, input, 0, 0x100000); Array.Resize(ref input, 0x100000); } - #endregion - #region Saves - if (SAV6.SizeValid(input.Length) && BitConverter.ToUInt32(input, input.Length - 0x1F0) == SAV6.BEEF) - openMAIN(input, path); // Verify the Data Input Size is Proper - else if (input.Length == 0x100000) + if (input.Length == 0x100000) { if (openXOR(input, path)) // Check if we can load the save via xorpad return; // only if a save is loaded we abort @@ -582,140 +530,82 @@ private void openFile(byte[] input, string path, string ext) if (sdr == DialogResult.Cancel) return; int savshift = sdr == DialogResult.Yes ? 0 : 0x7F000; - byte[] psdata = input.Skip(0x5400 + savshift).Take(SAV6.SIZE_ORAS).ToArray(); - if (BitConverter.ToUInt32(psdata, psdata.Length - 0x1F0) != SAV6.BEEF) - Array.Resize(ref psdata, SAV6.SIZE_XY); - if (BitConverter.ToUInt32(psdata, psdata.Length - 0x1F0) != SAV6.BEEF) + byte[] psdata = input.Skip(0x5400 + savshift).Take(SaveUtil.SIZE_G6ORAS).ToArray(); + if (BitConverter.ToUInt32(psdata, psdata.Length - 0x1F0) != SaveUtil.BEEF) + Array.Resize(ref psdata, SaveUtil.SIZE_G6XY); + if (BitConverter.ToUInt32(psdata, psdata.Length - 0x1F0) != SaveUtil.BEEF) { Util.Error("The data file is not a valid save file", path); return; } - openMAIN(psdata, path); + openSAV(psdata, path); } - else if (input.Length == SAV5.SIZERAW) // SAV4 size is same + #endregion + #region SAV/PKM + else if (SaveUtil.getSAVGeneration(input) > -1) // Supports Gen4/5/6 + openSAV(input, path); + else if ((temp = PKMConverter.getPKMfromBytes(input)) != null) { - int generation = PKM.getSAVGeneration(input); - if (generation == -1) - Util.Error("Unable to recognize save file." + Environment.NewLine + "Only valid G4/G5 saves supported.", - $"File Loaded:{Environment.NewLine}{path}"); + PKM pk = PKMConverter.convertToFormat(temp, SAV.Generation, out c); + if (pk == null) + Util.Alert("Conversion failed.", c); else - dumpPastGenSAV(input, generation); + populateFields(pk); + Console.WriteLine(c); } #endregion - #region PK6/EK6 - else if ((input.Length == PK6.SIZE_PARTY || input.Length == PK6.SIZE_STORED) && ext != ".pgt") + #region PC/Box Data + else if (BitConverter.ToUInt16(input, 4) == 0 && BitConverter.ToUInt32(input, 8) > 0 && PKX.getIsPKM(input.Length / 30 / SAV.BoxCount) || PKX.getIsPKM(input.Length / 30)) { - // Check if Input is PKX - if (new[] {".pk6", ".ek6", ".pkx", ".ekx", ""}.Contains(ext)) - { - // Check if Encrypted before Loading - populateFields(new PK6(BitConverter.ToUInt16(input, 0xC8) == 0 && BitConverter.ToUInt16(input, 0x58) == 0 ? input : PKX.decryptArray(input))); - } + if (SAV.setPCBin(input)) + Util.Alert("PC Binary loaded."); + else if (SAV.setBoxBin(input, CB_BoxSelect.SelectedIndex)) + Util.Alert("Box Binary loaded."); else - Util.Error("Unable to recognize file." + Environment.NewLine + "Only valid .pk* .ek* .bin supported.", - $"File Loaded:{Environment.NewLine}{path}"); - } - #endregion - #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 pk6 { - populateFields(Converter.ConvertPKMtoPK6(input)); - } - catch - { - populateFields(new PK6()); - Util.Error("Attempted to load previous generation PKM.", "Conversion failed."); - } - } - #endregion - #region Box Data - else if ((input.Length == PK6.SIZE_STORED * 30 || input.Length == PK6.SIZE_STORED * 30 * 31) && BitConverter.ToUInt16(input, 4) == 0 && BitConverter.ToUInt32(input, 8) > 0) - { - bool? noSetb = getPK6Override(); - - int baseOffset = SAV.Box + PK6.SIZE_STORED * 30 * (input.Length == PK6.SIZE_STORED * 30 ? CB_BoxSelect.SelectedIndex : 0); - for (int i = 0; i < input.Length / PK6.SIZE_STORED; i++) - { - byte[] data = input.Skip(PK6.SIZE_STORED * i).Take(PK6.SIZE_STORED).ToArray(); - SAV.setEK6Stored(data, baseOffset + i * PK6.SIZE_STORED, noSetb); + Util.Alert("Binary is not compatible with save file.", "Current SAV Generation: " + SAV.Generation); + return; } setPKXBoxes(); - Util.Alert("Box Binary loaded."); } #endregion #region Battle Video else if (input.Length == 0x2E60 && BitConverter.ToUInt64(input, 0xE18) != 0 && BitConverter.ToUInt16(input, 0xE12) == 0) { - if (Util.Prompt(MessageBoxButtons.YesNo, "Load Batte Video Pokémon data to " + CB_BoxSelect.Text + "?", "The first 24 slots will be overwritten.") != DialogResult.Yes) + if (SAV.Generation < 6) + { Util.Alert("Cannot load a Gen6 Battle Video to a past generation save file."); return; } + + if (Util.Prompt(MessageBoxButtons.YesNo, "Load Batte Video Pokémon data to " + CB_BoxSelect.Text + "?", "The box will be overwritten.") != DialogResult.Yes) return; - bool? noSetb = getPK6Override(); - + bool? noSetb = getPKMSetOverride(); + int offset = SAV.getBoxOffset(CB_BoxSelect.SelectedIndex); for (int i = 0; i < 24; i++) { - byte[] data = input.Skip(0xE18 + PK6.SIZE_PARTY * i + i / 6 * 8).Take(PK6.SIZE_STORED).ToArray(); - int offset = SAV.Box + i*PK6.SIZE_STORED + CB_BoxSelect.SelectedIndex*30*PK6.SIZE_STORED; - SAV.setEK6Stored(data, offset, noSetb); + byte[] data = input.Skip(0xE18 + PKX.SIZE_6PARTY * i + i / 6 * 8).Take(PKX.SIZE_6STORED).ToArray(); + SAV.setStoredSlot(data, offset + i * SAV.SIZE_STORED, noSetb); } setPKXBoxes(); } #endregion - #region Wondercard - else if ((input.Length == WC6.Size && ext == ".wc6") || (input.Length == WC6.SizeFull && ext == ".wc6full")) + #region Mystery Gift (Templates) + else if ((tg = MysteryGift.getMysteryGift(input, ext)) != null) { - if (input.Length == WC6.SizeFull) // Take bytes at end = WC6 size. - input = input.Skip(WC6.SizeFull - WC6.Size).ToArray(); - if (ModifierKeys == Keys.Control && SAV.PokeDex > -1) - new SAV_Wondercard(input).ShowDialog(); + if (!tg.IsPokémon) + { + Util.Alert("Mystery Gift is not a Pokémon.", path); + return; + } + temp = tg.convertToPKM(SAV); + if (temp.Format == SAV.Generation && ModifierKeys == Keys.Control && SAV.HasWondercards) + { + B_OpenWondercards_Click(tg, null); + return; + } + PKM pk = PKMConverter.convertToFormat(temp, SAV.Generation, out c); + if (pk == null) + Util.Alert("Conversion failed.", c); else - { - PK6 pk = new WC6(input).convertToPK6(SAV); - if (pk == null || pk.Species == 0 || pk.Species > 721) - { - Util.Error("Failed to convert Wondercard.", - pk == null ? "Not a Pokémon Wondercard." : "Invalid species."); - return; - } populateFields(pk); - } - } - else if (input.Length == PGF.Size && ext == ".pgf") - { - PK5 pk = new PGF(input).convertToPK5(SAV); - if (pk == null || pk.Species == 0 || pk.Species > 721) - { - Util.Error("Failed to convert PGF.", - pk == null ? "Not a Pokémon PGF." : "Invalid species."); - return; - } - populateFields(Converter.ConvertPKMtoPK6(pk.Data)); - } - else if (input.Length == PGT.Size && ext == ".pgt") - { - PGT pgt = new PGT(input); - PK4 pk = pgt.convertToPK4(SAV); - if (pk == null || pk.Species == 0 || pk.Species > 721) - { - Util.Error("Failed to convert PGT.", - pk == null ? "Not a Pokémon PGT." : "Invalid species."); - return; - } - populateFields(Converter.ConvertPKMtoPK6(pk.Data)); - } - else if (input.Length == PCD.Size && ext == ".pcd") - { - PCD pcd = new PCD(input); - PGT pgt = pcd.Gift; - PK4 pk = pgt.convertToPK4(SAV); - if (pk == null || pk.Species == 0 || pk.Species > 721) - { - Util.Error("Failed to convert PCD.", - pk == null ? "Not a Pokémon PCD." : "Invalid species."); - return; - } - populateFields(Converter.ConvertPKMtoPK6(pk.Data)); + Console.WriteLine(c); } #endregion else @@ -744,24 +634,24 @@ private bool openXOR(byte[] input, string path) if (!xorpad.Take(0x10).SequenceEqual(savID)) continue; // Set up Decrypted File - byte[] decryptedPS = input.Skip(0x5400).Take(SAV6.SIZE_ORAS).ToArray(); + byte[] decryptedPS = input.Skip(0x5400).Take(SaveUtil.SIZE_G6ORAS).ToArray(); // xor through and decrypt for (int z = 0; z < decryptedPS.Length; z++) decryptedPS[z] ^= xorpad[0x5400 + z]; // Weakly check the validity of the decrypted content - if (BitConverter.ToUInt32(decryptedPS, SAV6.SIZE_ORAS - 0x1F0) != SAV6.BEEF) // Not OR/AS - if (BitConverter.ToUInt32(decryptedPS, SAV6.SIZE_XY - 0x1F0) != SAV6.BEEF) // Not X/Y + if (BitConverter.ToUInt32(decryptedPS, SaveUtil.SIZE_G6ORAS - 0x1F0) != SaveUtil.BEEF) // Not OR/AS + if (BitConverter.ToUInt32(decryptedPS, SaveUtil.SIZE_G6XY - 0x1F0) != SaveUtil.BEEF) // Not X/Y continue; else - Array.Resize(ref decryptedPS, SAV6.SIZE_XY); // set to X/Y size - else Array.Resize(ref decryptedPS, SAV6.SIZE_ORAS); // set to ORAS size just in case + Array.Resize(ref decryptedPS, SaveUtil.SIZE_G6XY); // set to X/Y size + else Array.Resize(ref decryptedPS, SaveUtil.SIZE_G6ORAS); // set to ORAS size just in case // Save file is now decrypted! // Trigger Loading of the decrypted save file. - openMAIN(decryptedPS, path); + openSAV(decryptedPS, path); // Abort the opening of a non-cyber file. return true; @@ -770,69 +660,137 @@ private bool openXOR(byte[] input, string path) if (xorpath != exepath || loop++ > 0) return false; // no xorpad compatible xorpath = Path.GetDirectoryName(path); goto check; } - private void openMAIN(byte[] input, string path) + private void openSAV(byte[] input, string path) { - SAV = new SAV6(input) - { - FilePath = Path.GetDirectoryName(path), - FileName = Path.GetExtension(path) == ".bak" - ? Path.GetFileName(path).Split(new[] { " [" }, StringSplitOptions.None)[0] - : Path.GetFileName(path) - }; - L_Save.Text = "SAV: " + Path.GetFileNameWithoutExtension(Util.CleanFileName(SAV.BAKName)); // more descriptive + SaveFile sav = SaveUtil.getVariantSAV(input); + if (sav == null) + { Util.Error("Invalid save file loaded. Aborting.", path); return; } + SAV = sav; - // Enable Secondary Tools - GB_SAVtools.Enabled = B_JPEG.Enabled = true; + SAV.FilePath = Path.GetDirectoryName(path); + SAV.FileName = Path.GetExtension(path) == ".bak" + ? Path.GetFileName(path).Split(new[] {" ["}, StringSplitOptions.None)[0] + : Path.GetFileName(path); + L_Save.Text = $"SAV{SAV.Generation}: {Path.GetFileNameWithoutExtension(Util.CleanFileName(SAV.BAKName))}"; // more descriptive + Menu_ExportSAV.Enabled = B_VerifyCHK.Enabled = SAV.Exportable; setBoxNames(); // Display the Box Names - setPKXBoxes(); // Reload all of the PKX Windows - - // Version Exclusive Editors - GB_SUBE.Visible = !SAV.ORAS; - - if (SAV.Box > -1) + if (SAV.HasBox) { int startBox = SAV.CurrentBox; // FF if BattleBox - if (startBox > 30) { tabBoxMulti.SelectedIndex = 1; CB_BoxSelect.SelectedIndex = 0; } + if (startBox > SAV.BoxCount - 1) { tabBoxMulti.SelectedIndex = 1; CB_BoxSelect.SelectedIndex = 0; } else { tabBoxMulti.SelectedIndex = 0; CB_BoxSelect.SelectedIndex = startBox; } } - - TB_GameSync.Enabled = SAV.GameSyncID != 0; - TB_GameSync.Text = SAV.GameSyncID.ToString("X16"); - TB_Secure1.Text = SAV.Secure1.ToString("X16"); - TB_Secure2.Text = SAV.Secure2.ToString("X16"); - PB_Locked.Visible = SAV.BattleBoxLocked; + setPKXBoxes(); // Reload all of the PKX Windows // Hide content if not present in game. - PAN_Box.Visible = CB_BoxSelect.Visible = B_BoxLeft.Visible = B_BoxRight.Visible = SAV.Box > -1; - Menu_LoadBoxes.Enabled = Menu_DumpBoxes.Enabled = Menu_Report.Enabled = Menu_Modify.Enabled = B_SaveBoxBin.Enabled = SAV.Box > -1; - PAN_BattleBox.Visible = L_BattleBox.Visible = L_ReadOnlyPBB.Visible = SAV.BattleBox > -1; - GB_Daycare.Visible = SAV.Daycare > -1; - GB_Fused.Visible = SAV.Fused > -1; - GB_GTS.Visible = SAV.GTS > -1; - B_OpenSecretBase.Visible = SAV.SecretBase > -1; - B_OpenPokepuffs.Enabled = SAV.Puff > -1; - B_OUTPasserby.Enabled = SAV.PSS > -1; - B_OpenBoxLayout.Enabled = SAV.BoxWallpapers > -1; - B_OpenWondercards.Enabled = SAV.WondercardFlags > -1; - B_OpenSuperTraining.Enabled = SAV.SuperTrain > -1; - B_OpenHallofFame.Enabled = SAV.HoF > -1; - B_OpenOPowers.Enabled = SAV.OPower > -1; - B_OpenPokedex.Enabled = SAV.PokeDex > -1; - B_OpenBerryField.Enabled = SAV.BerryField > -1; - B_JPEG.Enabled = SAV.JPEG > -1; + GB_SUBE.Visible = SAV.HasSUBE; + PB_Locked.Visible = SAV.HasBattleBox && SAV.BattleBoxLocked; + + PAN_Box.Visible = CB_BoxSelect.Visible = B_BoxLeft.Visible = B_BoxRight.Visible = SAV.HasBox; + Menu_LoadBoxes.Enabled = Menu_DumpBoxes.Enabled = Menu_Report.Enabled = Menu_Modify.Enabled = B_SaveBoxBin.Enabled = SAV.HasBox; + + PAN_BattleBox.Visible = L_BattleBox.Visible = L_ReadOnlyPBB.Visible = SAV.HasBattleBox; + GB_Daycare.Visible = SAV.HasDaycare; + GB_Fused.Visible = SAV.HasFused; + GB_GTS.Visible = SAV.HasGTS; + B_OpenSecretBase.Visible = SAV.HasSecretBase; + B_OpenPokepuffs.Visible = SAV.HasPuff; + B_OUTPasserby.Visible = SAV.HasPSS; + B_OpenBoxLayout.Visible = SAV.HasBoxWallpapers; + B_OpenWondercards.Visible = SAV.HasWondercards; + B_OpenSuperTraining.Visible = SAV.HasSuperTrain; + B_OpenHallofFame.Visible = SAV.HasHoF; + B_OpenOPowers.Visible = SAV.HasOPower; + B_OpenPokedex.Visible = SAV.HasPokeDex; + B_OpenBerryField.Visible = SAV.HasBerryField; + B_Pokeblocks.Visible = SAV.HasPokeBlock; + B_JPEG.Visible = SAV.HasJPEG; + B_OpenEventFlags.Visible = SAV.HasEvents; + + // Generational Interface + byte[] extraBytes = new byte[1]; + switch (SAV.Generation) + { + case 4: + TB_GameSync.Visible = TB_Secure1.Visible = TB_Secure2.Visible = false; + L_GameSync.Visible = L_Secure1.Visible = L_Secure2.Visible = false; + CB_Country.Visible = CB_SubRegion.Visible = CB_3DSReg.Visible = false; + Label_Country.Visible = Label_SubRegion.Visible = Label_3DSRegion.Visible = false; + CB_Ability.Visible = TB_AbilityNumber.Visible = false; + GB_nOT.Visible = GB_RelearnMoves.Visible = BTN_History.Visible = BTN_Ribbons.Visible = false; + Label_EncryptionConstant.Visible = BTN_RerollEC.Visible = TB_EC.Visible = false; + PB_MarkPentagon.Visible = false; + PB_Legal.Visible = PB_WarnMove1.Visible = PB_WarnMove2.Visible = PB_WarnMove3.Visible = PB_WarnMove4.Visible = false; + + DEV_Ability.Enabled = DEV_Ability.Visible = true; + extraBytes = PK4.ExtraBytes; + break; + case 5: + TB_GameSync.Visible = TB_Secure1.Visible = TB_Secure2.Visible = false; + L_GameSync.Visible = L_Secure1.Visible = L_Secure2.Visible = false; + CB_Country.Visible = CB_SubRegion.Visible = CB_3DSReg.Visible = false; + Label_Country.Visible = Label_SubRegion.Visible = Label_3DSRegion.Visible = false; + CB_Ability.Visible = TB_AbilityNumber.Visible = false; + GB_nOT.Visible = GB_RelearnMoves.Visible = BTN_History.Visible = BTN_Ribbons.Visible = false; + Label_EncryptionConstant.Visible = BTN_RerollEC.Visible = TB_EC.Visible = false; + PB_MarkPentagon.Visible = false; + PB_Legal.Visible = PB_WarnMove1.Visible = PB_WarnMove2.Visible = PB_WarnMove3.Visible = PB_WarnMove4.Visible = false; + + DEV_Ability.Enabled = DEV_Ability.Visible = true; + extraBytes = PK5.ExtraBytes; + break; + case 6: + TB_GameSync.Visible = TB_Secure1.Visible = TB_Secure2.Visible = true; + L_GameSync.Visible = L_Secure1.Visible = L_Secure2.Visible = true; + CB_Country.Visible = CB_SubRegion.Visible = CB_3DSReg.Visible = true; + Label_Country.Visible = Label_SubRegion.Visible = Label_3DSRegion.Visible = true; + DEV_Ability.Enabled = DEV_Ability.Visible = TB_AbilityNumber.Visible = HaX; + GB_nOT.Visible = BTN_History.Visible = true; + Label_EncryptionConstant.Visible = BTN_RerollEC.Visible = TB_EC.Visible = true; + PB_MarkPentagon.Visible = true; + PB_Legal.Visible = PB_WarnMove1.Visible = PB_WarnMove2.Visible = PB_WarnMove3.Visible = PB_WarnMove4.Visible = !HaX; + + CB_Ability.Visible = !HaX; + extraBytes = PK6.ExtraBytes; + TB_GameSync.Enabled = (SAV as SAV6).GameSyncID != 0; + TB_GameSync.Text = (SAV as SAV6).GameSyncID.ToString("X16"); + TB_Secure1.Text = (SAV as SAV6).Secure1.ToString("X16"); + TB_Secure2.Text = (SAV as SAV6).Secure2.ToString("X16"); + break; + } + + // Clear PKM fields if generation has changed + if (pkm.Format != SAV.Generation) + populateFields(SAV.BlankPKM); + + // SAV Specific Limits + TB_OT.MaxLength = SAV.OTLength; + TB_OTt2.MaxLength = SAV.OTLength; + TB_Nickname.MaxLength = SAV.NickLength; + + // Common HaX Interface + CHK_HackedStats.Enabled = CHK_HackedStats.Visible = MT_Level.Enabled = MT_Level.Visible = MT_Form.Enabled = MT_Form.Visible = HaX; + TB_Level.Visible = !HaX; + + // Load Extra Byte List + CB_ExtraBytes.Items.Clear(); + foreach (byte b in extraBytes) + CB_ExtraBytes.Items.Add("0x" + b.ToString("X2")); + CB_ExtraBytes.SelectedIndex = 0; // Refresh PK#->PK6 conversion info - Converter.updateConfig(SAV.SubRegion, SAV.Country, SAV.ConsoleRegion, SAV.OT, SAV.Gender); - - // Indicate audibly the save is loaded - SystemSounds.Beep.Play(); + PKMConverter.updateConfig(SAV.SubRegion, SAV.Country, SAV.ConsoleRegion, SAV.OT, SAV.Gender); // If backup folder exists, save a backup. string backupName = Path.Combine(BackupPath, Util.CleanFileName(SAV.BAKName)); if (SAV.Exportable && Directory.Exists(BackupPath) && !File.Exists(backupName)) File.WriteAllBytes(backupName, SAV.BAK); + + + // Indicate audibly the save is loaded + SystemSounds.Beep.Play(); } private static void refreshWC6DB() { @@ -852,72 +810,11 @@ private static void refreshWC6DB() Legal.WC6DB = wc6db.Distinct().ToArray(); } - private static void dumpPastGenSAV(byte[] input, int generation) - { - if (generation != 4 && generation != 5) - return; - - Util.Alert("Please select a folder to dump the files to."); - - FolderBrowserDialog fbd = new FolderBrowserDialog(); - if (fbd.ShowDialog() != DialogResult.OK) - return; - string path = fbd.SelectedPath; - - if (generation == 4) - { - SAV4 sav = new SAV4(input); - var pkms = sav.BoxData.Where(pk => pk.Species != 0 && pk.ChecksumValid) - .GroupBy(pk => pk.Data).Select(g => g.First()); // filter by unique data - - DialogResult dr = Util.Prompt(MessageBoxButtons.YesNoCancel, - "Gen 4 save file loaded. Dump options:", - "Yes - Transfer to future generation" + Environment.NewLine + - "No - Dump as pkm (gen4)" + Environment.NewLine + - "Cancel - Abort"); - if (dr == DialogResult.Yes) - { - DialogResult dr2 = Util.Prompt(MessageBoxButtons.YesNoCancel, - "Transfer Options:", - "Yes - Transfer to G6" + Environment.NewLine + - "No - Transfer to G5" + Environment.NewLine + - "Cancel - Abort"); - if (dr2 == DialogResult.Yes) - foreach (var pk in pkms.Select(pkm => pkm.convertToPK5().convertToPK6())) - File.WriteAllBytes(Path.Combine(path, Util.CleanFileName(pk.FileName)), pk.Data); - else if (dr2 == DialogResult.No) - foreach (var pk in pkms.Select(pkm => pkm.convertToPK5())) - File.WriteAllBytes(Path.Combine(path, Util.CleanFileName(pk.FileName)), pk.Data); - } - else if (dr == DialogResult.No) - foreach (var pk in pkms) - File.WriteAllBytes(Path.Combine(path, Util.CleanFileName(pk.FileName)), pk.Data); - } - else if (generation == 5) - { - SAV5 sav = new SAV5(input); - var pkms = sav.BoxData.Where(pk => pk.Species != 0 && pk.ChecksumValid) - .GroupBy(pk => pk.Data).Select(g => g.First()); // filter by unique data - - DialogResult dr = Util.Prompt(MessageBoxButtons.YesNoCancel, - "Gen 5 save file loaded. Dump options:", - "Yes - Transfer to G6" + Environment.NewLine + - "No - Dump as pkm (gen5)" + Environment.NewLine + - "Cancel - Abort"); - if (dr == DialogResult.Yes) - foreach (var pk in pkms.Select(pkm => pkm.convertToPK6())) - File.WriteAllBytes(Path.Combine(path, Util.CleanFileName(pk.FileName)), pk.Data); - else if (dr == DialogResult.No) - foreach (var pk in pkms) - File.WriteAllBytes(Path.Combine(path, Util.CleanFileName(pk.FileName)), pk.Data); - } - Util.Alert("Files have been dumped to:" + Environment.NewLine + path); - } // Language Translation private void changeMainLanguage(object sender, EventArgs e) { - PK6 pk = new PK6((fieldsInitialized ? preparepkx() : pk6).Data); + PKM pk = SAV.getPKM((fieldsInitialized ? preparePKM() : pkm).Data); bool alreadyInit = fieldsInitialized; fieldsInitialized = false; Menu_Options.DropDown.Close(); @@ -1046,10 +943,10 @@ private void InitializeFields() { // Now that the ComboBoxes are ready, load the data. fieldsInitialized = true; - pk6.RefreshChecksum(); + pkm.RefreshChecksum(); // Load Data - populateFields(pk6); + populateFields(pkm); { CB_Species.SelectedValue = 493; CB_Move1.SelectedValue = 1; @@ -1067,33 +964,12 @@ private void InitializeFields() } private void InitializeLanguage() { - // Set the Display - CB_Country.DisplayMember = - CB_SubRegion.DisplayMember = - CB_3DSReg.DisplayMember = - CB_Language.DisplayMember = - CB_Ball.DisplayMember = - CB_HeldItem.DisplayMember = - CB_Species.DisplayMember = - DEV_Ability.DisplayMember = - CB_Nature.DisplayMember = - CB_EncounterType.DisplayMember = - CB_GameOrigin.DisplayMember = - CB_HPType.DisplayMember = "Text"; - - // Set the Value - CB_Country.ValueMember = - CB_SubRegion.ValueMember = - CB_3DSReg.ValueMember = - CB_Language.ValueMember = - CB_Ball.ValueMember = - CB_HeldItem.ValueMember = - CB_Species.ValueMember = - DEV_Ability.ValueMember = - CB_Nature.ValueMember = - CB_EncounterType.ValueMember = - CB_GameOrigin.ValueMember = - CB_HPType.ValueMember = "Value"; + ComboBox[] cbs = + { + CB_Country, CB_SubRegion, CB_3DSReg, CB_Language, CB_Ball, CB_HeldItem, CB_Species, DEV_Ability, + CB_Nature, CB_EncounterType, CB_GameOrigin, CB_HPType + }; + foreach (var cb in cbs) { cb.DisplayMember = "Text"; cb.ValueMember = "Value"; } // Set the various ComboBox DataSources up with their allowed entries setCountrySubRegion(CB_Country, "countries"); @@ -1102,7 +978,7 @@ private void InitializeLanguage() int[] ball_nums = { 7, 576, 13, 492, 497, 14, 495, 493, 496, 494, 11, 498, 8, 6, 12, 15, 9, 5, 499, 10, 1, 16 }; int[] ball_vals = { 7, 25, 13, 17, 22, 14, 20, 18, 21, 19, 11, 23, 8, 6, 12, 15, 9, 5, 24, 10, 1, 16 }; BallDataSource = Util.getVariedCBList(itemlist, ball_nums, ball_vals); - ItemDataSource = Util.getCBList(itemlist, DEV_Ability.Enabled ? null : Legal.Items_Held); + ItemDataSource = Util.getCBList(itemlist, HaX ? null : Legal.HeldItem_AO.Select(i => (int)i).ToArray()); SpeciesDataSource = Util.getCBList(specieslist, null); NatureDataSource = Util.getCBList(natures, null); AbilityDataSource = Util.getCBList(abilitylist, null); @@ -1126,18 +1002,292 @@ private void InitializeLanguage() cb.DataSource = new BindingSource(MoveDataSource, null); } } - public void populateFields(PK6 pk, bool focus = true) + public void populateFields(PKM pk, bool focus = true) { - pk6 = pk ?? new PK6(); - if (fieldsInitialized & !pk6.ChecksumValid) - Util.Alert("PKX File has an invalid checksum."); + if (pk == null) { Util.Error("Attempted to load a null file."); return; } - // Reset a little. bool oldInit = fieldsInitialized; fieldsInitialized = fieldsLoaded = false; if (focus) Tab_Main.Focus(); + pkm = pk; + if (fieldsInitialized & !pkm.ChecksumValid) + Util.Alert("PKX File has an invalid checksum."); + switch (pkm.Format) + { + case 4: + populateFieldsPK4(pkm as PK4); + break; + case 5: + populateFieldsPK5(pkm as PK5); + break; + case 6: + populateFieldsPK6(pkm as PK6); + break; + } + + CB_EncounterType.Visible = Label_EncounterType.Visible = pkm.Gen4; + fieldsInitialized = oldInit; + updateIVs(null, null); + updatePKRSInfected(null, null); + updatePKRSCured(null, null); + + if (HaX) + { + MT_Level.Text = pkm.Stat_Level.ToString(); + MT_Form.Text = pkm.AltForm.ToString(); + if (pkm.Stat_HPMax != 0) // stats present + { + Stat_HP.Text = pkm.Stat_HPCurrent.ToString(); + Stat_ATK.Text = pkm.Stat_ATK.ToString(); + Stat_DEF.Text = pkm.Stat_DEF.ToString(); + Stat_SPA.Text = pkm.Stat_SPA.ToString(); + Stat_SPD.Text = pkm.Stat_SPD.ToString(); + Stat_SPE.Text = pkm.Stat_SPE.ToString(); + } + } + fieldsLoaded = true; + + // Set the Preview Box + dragout.Image = pk.Sprite; + updateLegality(); + } + private void populateFieldsPK4(PK4 pk4) + { + // Do first + pk4.Stat_Level = PKX.getLevel(pk4.Species, pk4.EXP); + if (pk4.Stat_Level == 100) + pk4.EXP = PKX.getEXP(pk4.Stat_Level, pk4.Species); + + CB_Species.SelectedValue = pk4.Species; + TB_Level.Text = pk4.Stat_Level.ToString(); + TB_EXP.Text = pk4.EXP.ToString(); + + // Load rest + TB_EC.Text = pk4.EncryptionConstant.ToString("X8"); + CHK_Fateful.Checked = pk4.FatefulEncounter; + CHK_IsEgg.Checked = pk4.IsEgg; + CHK_Nicknamed.Checked = pk4.IsNicknamed; + Label_OTGender.Text = gendersymbols[pk4.OT_Gender]; + Label_OTGender.ForeColor = pk4.OT_Gender == 1 ? Color.Red : Color.Blue; + TB_PID.Text = pk4.PID.ToString("X8"); + CB_HeldItem.SelectedValue = pk4.HeldItem; + setAbilityList(TB_AbilityNumber, pk4.Species, CB_Ability, CB_Form); + DEV_Ability.SelectedValue = pk4.Ability; + CB_Nature.SelectedValue = pk4.Nature; + TB_TID.Text = pk4.TID.ToString("00000"); + TB_SID.Text = pk4.SID.ToString("00000"); + TB_Nickname.Text = pk4.Nickname; + TB_OT.Text = pk4.OT_Name; + TB_Friendship.Text = pk4.CurrentFriendship.ToString(); + GB_OT.BackgroundImage = null; + CB_Language.SelectedValue = pk4.Language; + CB_GameOrigin.SelectedValue = pk4.Version; + CB_EncounterType.SelectedValue = pk4.Gen4 ? pk4.EncounterType : 0; + CB_Ball.SelectedValue = pk4.Ball; + + if (pk4.Met_Month == 0) { pk4.Met_Month = 1; } + if (pk4.Met_Day == 0) { pk4.Met_Day = 1; } + try { CAL_MetDate.Value = new DateTime(pk4.Met_Year + 2000, pk4.Met_Month, pk4.Met_Day); } + catch { CAL_MetDate.Value = new DateTime(2000, 1, 1); } + + if (pk4.Egg_Location != 0) + { + // Was obtained initially as an egg. + CHK_AsEgg.Checked = true; + GB_EggConditions.Enabled = true; + + CB_EggLocation.SelectedValue = pk4.Egg_Location; + try { CAL_EggDate.Value = new DateTime(pk4.Egg_Year + 2000, pk4.Egg_Month, pk4.Egg_Day); } + catch { CAL_MetDate.Value = new DateTime(2000, 1, 1); } + } + else { CAL_EggDate.Value = new DateTime(2000, 01, 01); CHK_AsEgg.Checked = GB_EggConditions.Enabled = false; CB_EggLocation.SelectedValue = 0; } + + CB_MetLocation.SelectedValue = pk4.Met_Location; + + TB_MetLevel.Text = pk4.Met_Level.ToString(); + + // Reset Label and ComboBox visibility, as well as non-data checked status. + Label_PKRS.Visible = CB_PKRSStrain.Visible = CHK_Infected.Checked = pk4.PKRS_Strain != 0; + Label_PKRSdays.Visible = CB_PKRSDays.Visible = pk4.PKRS_Days != 0; + + // Set SelectedIndexes for PKRS + CB_PKRSStrain.SelectedIndex = pk4.PKRS_Strain; + CHK_Cured.Checked = pk4.PKRS_Strain > 0 && pk4.PKRS_Days == 0; + CB_PKRSDays.SelectedIndex = Math.Min(CB_PKRSDays.Items.Count - 1, pk4.PKRS_Days); // to strip out bad hacked 'rus + + TB_Cool.Text = pk4.CNT_Cool.ToString(); + TB_Beauty.Text = pk4.CNT_Beauty.ToString(); + TB_Cute.Text = pk4.CNT_Cute.ToString(); + TB_Smart.Text = pk4.CNT_Smart.ToString(); + TB_Tough.Text = pk4.CNT_Tough.ToString(); + TB_Sheen.Text = pk4.CNT_Sheen.ToString(); + + TB_HPIV.Text = pk4.IV_HP.ToString(); + TB_ATKIV.Text = pk4.IV_ATK.ToString(); + TB_DEFIV.Text = pk4.IV_DEF.ToString(); + TB_SPEIV.Text = pk4.IV_SPE.ToString(); + TB_SPAIV.Text = pk4.IV_SPA.ToString(); + TB_SPDIV.Text = pk4.IV_SPD.ToString(); + CB_HPType.SelectedValue = pk4.HPType; + + TB_HPEV.Text = pk4.EV_HP.ToString(); + TB_ATKEV.Text = pk4.EV_ATK.ToString(); + TB_DEFEV.Text = pk4.EV_DEF.ToString(); + TB_SPEEV.Text = pk4.EV_SPE.ToString(); + TB_SPAEV.Text = pk4.EV_SPA.ToString(); + TB_SPDEV.Text = pk4.EV_SPD.ToString(); + + CB_Move1.SelectedValue = pk4.Move1; + CB_Move2.SelectedValue = pk4.Move2; + CB_Move3.SelectedValue = pk4.Move3; + CB_Move4.SelectedValue = pk4.Move4; + CB_PPu1.SelectedIndex = pk4.Move1_PPUps; + CB_PPu2.SelectedIndex = pk4.Move2_PPUps; + CB_PPu3.SelectedIndex = pk4.Move3_PPUps; + CB_PPu4.SelectedIndex = pk4.Move4_PPUps; + TB_PP1.Text = pk4.Move1_PP.ToString(); + TB_PP2.Text = pk4.Move2_PP.ToString(); + TB_PP3.Text = pk4.Move3_PP.ToString(); + TB_PP4.Text = pk4.Move4_PP.ToString(); + + // Set Form if count is enough, else if count is more than 1 set equal to max else zero. + CB_Form.SelectedIndex = CB_Form.Items.Count > pk4.AltForm ? pk4.AltForm : (CB_Form.Items.Count > 1 ? CB_Form.Items.Count - 1 : 0); + + // Load Extrabyte Value + TB_ExtraByte.Text = pk4.Data[Convert.ToInt32(CB_ExtraBytes.Text, 16)].ToString(); + + updateStats(); + setIsShiny(); + + TB_EXP.Text = pk4.EXP.ToString(); + Label_Gender.Text = gendersymbols[pk4.Gender]; + Label_Gender.ForeColor = pk4.Gender == 2 ? Label_Species.ForeColor : (pk4.Gender == 1 ? Color.Red : Color.Blue); + } + private void populateFieldsPK5(PK5 pk5) + { + // Do first + pk5.Stat_Level = PKX.getLevel(pk5.Species, pk5.EXP); + if (pk5.Stat_Level == 100) + pk5.EXP = PKX.getEXP(pk5.Stat_Level, pk5.Species); + + CB_Species.SelectedValue = pk5.Species; + TB_Level.Text = pk5.Stat_Level.ToString(); + TB_EXP.Text = pk5.EXP.ToString(); + + // Load rest + TB_EC.Text = pk5.EncryptionConstant.ToString("X8"); + CHK_Fateful.Checked = pk5.FatefulEncounter; + CHK_IsEgg.Checked = pk5.IsEgg; + CHK_Nicknamed.Checked = pk5.IsNicknamed; + Label_OTGender.Text = gendersymbols[pk5.OT_Gender]; + Label_OTGender.ForeColor = pk5.OT_Gender == 1 ? Color.Red : Color.Blue; + TB_PID.Text = pk5.PID.ToString("X8"); + CB_HeldItem.SelectedValue = pk5.HeldItem; + setAbilityList(TB_AbilityNumber, pk5.Species, CB_Ability, CB_Form); + DEV_Ability.SelectedValue = pk5.Ability; + CB_Nature.SelectedValue = pk5.Nature; + TB_TID.Text = pk5.TID.ToString("00000"); + TB_SID.Text = pk5.SID.ToString("00000"); + TB_Nickname.Text = pk5.Nickname; + TB_OT.Text = pk5.OT_Name; + TB_Friendship.Text = pk5.CurrentFriendship.ToString(); + if (pk5.CurrentHandler == 1) // HT + { + GB_nOT.BackgroundImage = mixedHighlight; + GB_OT.BackgroundImage = null; + } + else // = 0 + { + GB_OT.BackgroundImage = mixedHighlight; + GB_nOT.BackgroundImage = null; + } + CB_Language.SelectedValue = pk5.Language; + CB_GameOrigin.SelectedValue = pk5.Version; + CB_EncounterType.SelectedValue = pk5.Gen4 ? pk5.EncounterType : 0; + CB_Ball.SelectedValue = pk5.Ball; + + if (pk5.Met_Month == 0) { pk5.Met_Month = 1; } + if (pk5.Met_Day == 0) { pk5.Met_Day = 1; } + try { CAL_MetDate.Value = new DateTime(pk5.Met_Year + 2000, pk5.Met_Month, pk5.Met_Day); } + catch { CAL_MetDate.Value = new DateTime(2000, 1, 1); } + + if (pk5.Egg_Location != 0) + { + // Was obtained initially as an egg. + CHK_AsEgg.Checked = true; + GB_EggConditions.Enabled = true; + + CB_EggLocation.SelectedValue = pk5.Egg_Location; + try { CAL_EggDate.Value = new DateTime(pk5.Egg_Year + 2000, pk5.Egg_Month, pk5.Egg_Day); } + catch { CAL_MetDate.Value = new DateTime(2000, 1, 1); } + } + else { CAL_EggDate.Value = new DateTime(2000, 01, 01); CHK_AsEgg.Checked = GB_EggConditions.Enabled = false; CB_EggLocation.SelectedValue = 0; } + + CB_MetLocation.SelectedValue = pk5.Met_Location; + + TB_MetLevel.Text = pk5.Met_Level.ToString(); + + // Reset Label and ComboBox visibility, as well as non-data checked status. + Label_PKRS.Visible = CB_PKRSStrain.Visible = CHK_Infected.Checked = pk5.PKRS_Strain != 0; + Label_PKRSdays.Visible = CB_PKRSDays.Visible = pk5.PKRS_Days != 0; + + // Set SelectedIndexes for PKRS + CB_PKRSStrain.SelectedIndex = pk5.PKRS_Strain; + CHK_Cured.Checked = pk5.PKRS_Strain > 0 && pk5.PKRS_Days == 0; + CB_PKRSDays.SelectedIndex = Math.Min(CB_PKRSDays.Items.Count - 1, pk5.PKRS_Days); // to strip out bad hacked 'rus + + TB_Cool.Text = pk5.CNT_Cool.ToString(); + TB_Beauty.Text = pk5.CNT_Beauty.ToString(); + TB_Cute.Text = pk5.CNT_Cute.ToString(); + TB_Smart.Text = pk5.CNT_Smart.ToString(); + TB_Tough.Text = pk5.CNT_Tough.ToString(); + TB_Sheen.Text = pk5.CNT_Sheen.ToString(); + + TB_HPIV.Text = pk5.IV_HP.ToString(); + TB_ATKIV.Text = pk5.IV_ATK.ToString(); + TB_DEFIV.Text = pk5.IV_DEF.ToString(); + TB_SPEIV.Text = pk5.IV_SPE.ToString(); + TB_SPAIV.Text = pk5.IV_SPA.ToString(); + TB_SPDIV.Text = pk5.IV_SPD.ToString(); + CB_HPType.SelectedValue = pk5.HPType; + + TB_HPEV.Text = pk5.EV_HP.ToString(); + TB_ATKEV.Text = pk5.EV_ATK.ToString(); + TB_DEFEV.Text = pk5.EV_DEF.ToString(); + TB_SPEEV.Text = pk5.EV_SPE.ToString(); + TB_SPAEV.Text = pk5.EV_SPA.ToString(); + TB_SPDEV.Text = pk5.EV_SPD.ToString(); + + CB_Move1.SelectedValue = pk5.Move1; + CB_Move2.SelectedValue = pk5.Move2; + CB_Move3.SelectedValue = pk5.Move3; + CB_Move4.SelectedValue = pk5.Move4; + CB_PPu1.SelectedIndex = pk5.Move1_PPUps; + CB_PPu2.SelectedIndex = pk5.Move2_PPUps; + CB_PPu3.SelectedIndex = pk5.Move3_PPUps; + CB_PPu4.SelectedIndex = pk5.Move4_PPUps; + TB_PP1.Text = pk5.Move1_PP.ToString(); + TB_PP2.Text = pk5.Move2_PP.ToString(); + TB_PP3.Text = pk5.Move3_PP.ToString(); + TB_PP4.Text = pk5.Move4_PP.ToString(); + + // Set Form if count is enough, else if count is more than 1 set equal to max else zero. + CB_Form.SelectedIndex = CB_Form.Items.Count > pk5.AltForm ? pk5.AltForm : (CB_Form.Items.Count > 1 ? CB_Form.Items.Count - 1 : 0); + + // Load Extrabyte Value + TB_ExtraByte.Text = pk5.Data[Convert.ToInt32(CB_ExtraBytes.Text, 16)].ToString(); + + updateStats(); + setIsShiny(); + + TB_EXP.Text = pk5.EXP.ToString(); + Label_Gender.Text = gendersymbols[pk5.Gender]; + Label_Gender.ForeColor = pk5.Gender == 2 ? Label_Species.ForeColor : (pk5.Gender == 1 ? Color.Red : Color.Blue); + } + private void populateFieldsPK6(PK6 pk6) + { // Do first pk6.Stat_Level = PKX.getLevel(pk6.Species, pk6.EXP); if (pk6.Stat_Level == 100) @@ -1154,12 +1304,6 @@ public void populateFields(PK6 pk, bool focus = true) CHK_Nicknamed.Checked = pk6.IsNicknamed; Label_OTGender.Text = gendersymbols[pk6.OT_Gender]; Label_OTGender.ForeColor = pk6.OT_Gender == 1 ? Color.Red : Color.Blue; - CHK_Circle.Checked = pk6.Circle; - CHK_Triangle.Checked = pk6.Triangle; - CHK_Square.Checked = pk6.Square; - CHK_Heart.Checked = pk6.Heart; - CHK_Star.Checked = pk6.Star; - CHK_Diamond.Checked = pk6.Diamond; TB_PID.Text = pk6.PID.ToString("X8"); CB_HeldItem.SelectedValue = pk6.HeldItem; setAbilityList(TB_AbilityNumber, pk6.Species, CB_Ability, CB_Form); @@ -1271,43 +1415,18 @@ public void populateFields(PK6 pk, bool focus = true) updateStats(); setIsShiny(); - - CB_EncounterType.Visible = Label_EncounterType.Visible = pk6.Gen4; - - fieldsInitialized = oldInit; - updateIVs(null, null); - updatePKRSInfected(null, null); - updatePKRSCured(null, null); - + TB_EXP.Text = pk6.EXP.ToString(); Label_Gender.Text = gendersymbols[pk6.Gender]; Label_Gender.ForeColor = pk6.Gender == 2 ? Label_Species.ForeColor : (pk6.Gender == 1 ? Color.Red : Color.Blue); - - if (HaX) // DEV Illegality - { - DEV_Ability.SelectedValue = pk6.Ability; - MT_Level.Text = pk6.Stat_Level.ToString(); - MT_Form.Text = pk6.AltForm.ToString(); - if (pk6.Stat_HPMax != 0) - { - Stat_HP.Text = pk6.Stat_HPCurrent.ToString(); - Stat_ATK.Text = pk6.Stat_ATK.ToString(); - Stat_DEF.Text = pk6.Stat_DEF.ToString(); - Stat_SPA.Text = pk6.Stat_SPA.ToString(); - Stat_SPD.Text = pk6.Stat_SPD.ToString(); - Stat_SPE.Text = pk6.Stat_SPE.ToString(); - } - } - - // Set the Preview Box - dragout.Image = pk6.Sprite; - + // Highlight the Current Handler clickGT(pk6.CurrentHandler == 1 ? GB_nOT : GB_OT, null); - fieldsLoaded = true; - updateLegality(); + if (HaX) + DEV_Ability.SelectedValue = pk6.Ability; } + // General Use Functions shared by other Forms // internal static void setCountrySubRegion(ComboBox CB, string type) { @@ -1367,9 +1486,8 @@ private void setIsShiny() private void setMarkings() { PictureBox[] pba = { PB_Mark1, PB_Mark2, PB_Mark3, PB_Mark4, PB_Mark5, PB_Mark6 }; - CheckBox[] cba = { CHK_Circle, CHK_Triangle, CHK_Square, CHK_Heart, CHK_Star, CHK_Diamond }; for (int i = 0; i < 6; i++) - pba[i].Image = Util.ChangeOpacity(pba[i].InitialImage, (cba[i].Checked ? 1 : 0) * 0.9 + 0.1); + pba[i].Image = Util.ChangeOpacity(pba[i].InitialImage, (pkm.Markings[i] ? 1 : 0) * 0.9 + 0.1); PB_MarkShiny.Image = Util.ChangeOpacity(PB_MarkShiny.InitialImage, (!BTN_Shinytize.Enabled ? 1 : 0) * 0.9 + 0.1); PB_MarkCured.Image = Util.ChangeOpacity(PB_MarkCured.InitialImage, (CHK_Cured.Checked ? 1 : 0) * 0.9 + 0.1); @@ -1380,14 +1498,19 @@ private void setMarkings() // Clicked Label Shortcuts // private void clickQR(object sender, EventArgs e) { + if (SAV.Generation != 6) + { + Util.Alert("QR feature only available for 6th Gen Games."); + return; + } if (ModifierKeys == Keys.Alt) { // Fetch data from QR code... - byte[] ekx = Util.getQRData(); + byte[] ekx = QR.getQRData(); if (ekx == null) return; - if (ekx.Length != PK6.SIZE_STORED) { Util.Alert($"Decoded data not {PK6.SIZE_STORED} bytes.", $"QR Data Size: {ekx.Length}"); } + if (ekx.Length != PKX.SIZE_6STORED) { Util.Alert($"Decoded data not {PKX.SIZE_6STORED} bytes.", $"QR Data Size: {ekx.Length}"); } else try { PK6 pk = new PK6(PKX.decryptArray(ekx)); @@ -1399,10 +1522,10 @@ private void clickQR(object sender, EventArgs e) else { if (!verifiedPKX()) return; - PK6 pkx = preparepkx(); + PKM pkx = preparePKM(); byte[] ekx = pkx.EncryptedBoxData; const string server = "http://loadcode.projectpokemon.org/b1s1.html#"; // Rehosted with permission from LC/MS -- massive thanks! - Image qr = Util.getQRImage(ekx, server); + Image qr = QR.getQRImage(ekx, server); if (qr == null) return; @@ -1413,9 +1536,9 @@ private void clickQR(object sender, EventArgs e) private void clickFriendship(object sender, EventArgs e) { if (ModifierKeys == Keys.Control) // prompt to reset - TB_Friendship.Text = pk6.CurrentHandler == 0 ? pk6.OT_Friendship.ToString() : pk6.HT_Friendship.ToString(); + TB_Friendship.Text = pkm.CurrentFriendship.ToString(); else - TB_Friendship.Text = TB_Friendship.Text == "255" ? PKX.getBaseFriendship(pk6.Species).ToString() : "255"; + TB_Friendship.Text = TB_Friendship.Text == "255" ? PKX.getBaseFriendship(pkm.Species).ToString() : "255"; } private void clickGender(object sender, EventArgs e) { @@ -1428,9 +1551,12 @@ private void clickGender(object sender, EventArgs e) if (gt >= 255) return; // If not a single gender(less) species: (should be <254 but whatever, 255 never happens) - pk6.Gender = PKX.getGender(Label_Gender.Text) ^ 1; - Label_Gender.Text = gendersymbols[pk6.Gender]; - Label_Gender.ForeColor = pk6.Gender == 2 ? Label_Species.ForeColor : (pk6.Gender == 1 ? Color.Red : Color.Blue); + pkm.Gender = PKX.getGender(Label_Gender.Text) ^ 1; + Label_Gender.Text = gendersymbols[pkm.Gender]; + Label_Gender.ForeColor = pkm.Gender == 2 ? Label_Species.ForeColor : (pkm.Gender == 1 ? Color.Red : Color.Blue); + + if (SAV.Generation < 6) + updateRandomPID(null, null); if (PKX.getGender(CB_Form.Text) < 2) // Gendered Forms CB_Form.SelectedIndex = PKX.getGender(Label_Gender.Text); @@ -1447,9 +1573,10 @@ private void clickPPUps(object sender, EventArgs e) private void clickMarking(object sender, EventArgs e) { PictureBox[] pba = { PB_Mark1, PB_Mark2, PB_Mark3, PB_Mark4, PB_Mark5, PB_Mark6 }; - CheckBox[] cba = { CHK_Circle, CHK_Triangle, CHK_Square, CHK_Heart, CHK_Star, CHK_Diamond }; - - cba[Array.IndexOf(pba, sender)].Checked ^= true; + int index = Array.IndexOf(pba, sender); + bool[] markings = pkm.Markings; + markings[index] ^= true; + pkm.Markings = markings; setMarkings(); } private void clickStatLabel(object sender, MouseEventArgs e) @@ -1495,11 +1622,17 @@ private void clickOT(object sender, EventArgs e) Label_OTGender.ForeColor = SAV.Gender == 1 ? Color.Red : Color.Blue; TB_TID.Text = SAV.TID.ToString(); TB_SID.Text = SAV.SID.ToString(); - CB_GameOrigin.SelectedValue = SAV.Game; - CB_SubRegion.SelectedValue = SAV.SubRegion; - CB_Country.SelectedValue = SAV.Country; - CB_3DSReg.SelectedValue = SAV.ConsoleRegion; - CB_Language.SelectedValue = SAV.Language; + + if (SAV.Game >= 0) + CB_GameOrigin.SelectedValue = SAV.Game; + if (SAV.Language >= 0) + CB_Language.SelectedValue = SAV.Language; + if (SAV.HasGeolocation) + { + CB_SubRegion.SelectedValue = SAV.SubRegion; + CB_Country.SelectedValue = SAV.Country; + CB_3DSReg.SelectedValue = SAV.ConsoleRegion; + } updateNickname(null, null); } private void clickCT(object sender, EventArgs e) @@ -1509,20 +1642,21 @@ private void clickCT(object sender, EventArgs e) } private void clickGT(object sender, EventArgs e) { + if (!GB_nOT.Visible) + return; if (sender == GB_OT) { - pk6.CurrentHandler = 0; - TB_Friendship.Text = pk6.OT_Friendship.ToString(); + pkm.CurrentHandler = 0; GB_OT.BackgroundImage = mixedHighlight; GB_nOT.BackgroundImage = null; } else if (TB_OTt2.Text.Length > 0) { - pk6.CurrentHandler = 1; - TB_Friendship.Text = pk6.HT_Friendship.ToString(); + pkm.CurrentHandler = 1; GB_OT.BackgroundImage = null; GB_nOT.BackgroundImage = mixedHighlight; } + TB_Friendship.Text = pkm.CurrentFriendship.ToString(); } private void clickTRGender(object sender, EventArgs e) { @@ -1615,32 +1749,32 @@ private void updateIVs(object sender, EventArgs e) changingFields = true; // Update IVs - pk6.IV_HP = Util.ToInt32(TB_HPIV.Text); - pk6.IV_ATK = Util.ToInt32(TB_ATKIV.Text); - pk6.IV_DEF = Util.ToInt32(TB_DEFIV.Text); - pk6.IV_SPE = Util.ToInt32(TB_SPEIV.Text); - pk6.IV_SPA = Util.ToInt32(TB_SPAIV.Text); - pk6.IV_SPD = Util.ToInt32(TB_SPDIV.Text); + pkm.IV_HP = Util.ToInt32(TB_HPIV.Text); + pkm.IV_ATK = Util.ToInt32(TB_ATKIV.Text); + pkm.IV_DEF = Util.ToInt32(TB_DEFIV.Text); + pkm.IV_SPE = Util.ToInt32(TB_SPEIV.Text); + pkm.IV_SPA = Util.ToInt32(TB_SPAIV.Text); + pkm.IV_SPD = Util.ToInt32(TB_SPDIV.Text); - CB_HPType.SelectedValue = pk6.HPType; + CB_HPType.SelectedValue = pkm.HPType; changingFields = false; // Potential Reading L_Potential.Text = (!unicode ? new[] {"★☆☆☆", "★★☆☆", "★★★☆", "★★★★"} : new[] {"+", "++", "+++", "++++"} - )[pk6.PotentialRating]; + )[pkm.PotentialRating]; - TB_IVTotal.Text = pk6.IVs.Sum().ToString(); + TB_IVTotal.Text = pkm.IVs.Sum().ToString(); - L_Characteristic.Text = characteristics[pk6.Characteristic]; + L_Characteristic.Text = characteristics[pkm.Characteristic]; updateStats(); } private void updateEVs(object sender, EventArgs e) { if (sender != null) - if (Util.ToInt32((sender as MaskedTextBox).Text) > 252) - (sender as MaskedTextBox).Text = "252"; + if (Util.ToInt32((sender as MaskedTextBox).Text) > SAV.MaxEV) + (sender as MaskedTextBox).Text = SAV.MaxEV.ToString(); changingFields = true; int EV_HP = Util.ToInt32(TB_HPEV.Text); @@ -1938,7 +2072,7 @@ private void updateOriginGame(object sender, EventArgs e) { int Version = Util.getIndex(CB_GameOrigin); - if (Version < 24 && origintrack != "Past") + if (Version < 24 && origintrack != "Past" && SAV.Generation != 4) { // Load Past Gen Locations #region B2W2 Met Locations @@ -1988,6 +2122,22 @@ private void updateOriginGame(object sender, EventArgs e) } #endregion } + else if (SAV.Generation == 4 && origintrack != "Gen4") + { + var met_list = Util.getCBList(metHGSS_00000, new[] { 0 }); + met_list = Util.getOffsetCBList(met_list, metHGSS_02000, 2000, new[] { 2000 }); + met_list = Util.getOffsetCBList(met_list, metHGSS_02000, 2000, new[] { 2002 }); + met_list = Util.getOffsetCBList(met_list, metHGSS_03000, 3000, new[] { 3001 }); + met_list = Util.getOffsetCBList(met_list, metHGSS_00000, 0000, Legal.Met_HGSS_0); + met_list = Util.getOffsetCBList(met_list, metHGSS_02000, 2000, Legal.Met_HGSS_2); + met_list = Util.getOffsetCBList(met_list, metHGSS_03000, 3000, Legal.Met_HGSS_3); + CB_MetLocation.DisplayMember = "Text"; + CB_MetLocation.ValueMember = "Value"; + CB_MetLocation.DataSource = met_list; + CB_MetLocation.SelectedValue = 0; + origintrack = "Gen4"; + } + if (Version < 0x10 && origintrack != "Gen4") { // Load Gen 4 egg locations if Gen 4 Origin. @@ -2017,23 +2167,27 @@ private void updateOriginGame(object sender, EventArgs e) setMarkings(); // Set/Remove KB marking if (!fieldsLoaded) return; - pk6.Version = Version; + pkm.Version = Version; updateLegality(); } private void updateExtraByteValue(object sender, EventArgs e) { + if (CB_ExtraBytes.Items.Count == 0) + return; // Changed Extra Byte's Value if (Util.ToInt32((sender as MaskedTextBox).Text) > byte.MaxValue) (sender as MaskedTextBox).Text = "255"; int value = Util.ToInt32(TB_ExtraByte.Text); int offset = Convert.ToInt32(CB_ExtraBytes.Text, 16); - pk6.Data[offset] = (byte)value; + pkm.Data[offset] = (byte)value; } private void updateExtraByteIndex(object sender, EventArgs e) { + if (CB_ExtraBytes.Items.Count == 0) + return; // Byte changed, need to refresh the Text box for the byte's value. - TB_ExtraByte.Text = pk6.Data[Convert.ToInt32(CB_ExtraBytes.Text, 16)].ToString(); + TB_ExtraByte.Text = pkm.Data[Convert.ToInt32(CB_ExtraBytes.Text, 16)].ToString(); } private void updateNatureModification(object sender, EventArgs e) { @@ -2097,7 +2251,7 @@ private void updateNotOT(object sender, EventArgs e) { clickGT(GB_OT, null); // Switch CT over to OT. Label_CTGender.Text = ""; - TB_Friendship.Text = pk6.OT_Friendship.ToString(); + TB_Friendship.Text = pkm.CurrentFriendship.ToString(); } else if (string.IsNullOrWhiteSpace(Label_CTGender.Text)) Label_CTGender.Text = gendersymbols[0]; @@ -2152,12 +2306,27 @@ private void updateMetAsEgg(object sender, EventArgs e) } private void updateShinyPID(object sender, EventArgs e) { + uint TID = Util.ToUInt32(TB_TID.Text); + uint SID = Util.ToUInt32(TB_SID.Text); uint PID = Util.getHEXval(TB_PID.Text); + if (SAV.Generation == 4) + { + int nature = Util.getIndex(CB_Nature); + int species = Util.getIndex(CB_Species); + int gender = PKX.getGender(Label_Gender.Text); + + uint oldbits = PID & 0x00010001; + while ((TID ^ SID ^ (PID >> 16) ^ PID & 0xFFFF) > 8 || (PID & 0x00010001) != oldbits || PID%25 != nature || gender != PKX.getGender(species, PID)) + PID = Util.rnd32(); + TB_PID.Text = PID.ToString("X8"); + + getQuickFiller(dragout); + return; + } + uint UID = PID >> 16; uint LID = PID & 0xFFFF; uint PSV = UID ^ LID; - uint TID = Util.ToUInt32(TB_TID.Text); - uint SID = Util.ToUInt32(TB_SID.Text); uint TSV = TID ^ SID; uint XOR = TSV ^ PSV; @@ -2169,7 +2338,6 @@ private void updateShinyPID(object sender, EventArgs e) if (Util.getIndex(CB_GameOrigin) < 24) // Pre Gen6 TB_EC.Text = TB_PID.Text; - setIsShiny(); getQuickFiller(dragout); } private void updateTSV(object sender, EventArgs e) @@ -2197,6 +2365,11 @@ private void update_ID(object sender, EventArgs e) getQuickFiller(dragout); updateIVs(null, null); // If the EC is changed, EC%6 (Characteristic) might be changed. TB_PID.Select(60, 0); // position cursor at end of field + if (SAV.Generation == 4) + { + pkm.PID = Util.getHEXval(TB_PID.Text); + CB_Nature.SelectedValue = pkm.Nature; + } } private void validateComboBox(object sender) { @@ -2226,6 +2399,8 @@ private void validateComboBox2(object sender, EventArgs e) validateComboBox(sender, e); if (sender == CB_Ability) TB_AbilityNumber.Text = (1 << CB_Ability.SelectedIndex).ToString(); + if (fieldsInitialized && sender == CB_Nature && SAV.Generation == 4) + BTN_RerollPID.PerformClick(); updateNatureModification(sender, null); updateIVs(null, null); // updating Nature will trigger stats to update as well } @@ -2241,14 +2416,16 @@ private void validateMove(object sender, EventArgs e) // Refresh Relearn if... if (new[] { CB_RelearnMove1, CB_RelearnMove2, CB_RelearnMove3, CB_RelearnMove4 }.Contains(sender)) { - pk6.RelearnMoves = new[] { Util.getIndex(CB_RelearnMove1), Util.getIndex(CB_RelearnMove2), Util.getIndex(CB_RelearnMove3), Util.getIndex(CB_RelearnMove4) }; + if (pkm.Format < 6) + return; + (pkm as PK6).RelearnMoves = new[] { Util.getIndex(CB_RelearnMove1), Util.getIndex(CB_RelearnMove2), Util.getIndex(CB_RelearnMove3), Util.getIndex(CB_RelearnMove4) }; Legality.updateRelearnLegality(); for (int i = 0; i < 4; i++) movePB[i].Visible = !Legality.vRelearn[i].Valid; } // else, Refresh Moves { - pk6.Moves = new[] { Util.getIndex(CB_Move1), Util.getIndex(CB_Move2), Util.getIndex(CB_Move3), Util.getIndex(CB_Move4) }; + pkm.Moves = new[] { Util.getIndex(CB_Move1), Util.getIndex(CB_Move2), Util.getIndex(CB_Move3), Util.getIndex(CB_Move4) }; Legality.updateMoveLegality(); for (int i = 0; i < 4; i++) movePB[i].Visible = !Legality.vMoves[i].Valid; @@ -2265,8 +2442,8 @@ private void validateLocation(object sender, EventArgs e) if (!fieldsLoaded) return; - pk6.Met_Location = Util.getIndex(CB_MetLocation); - pk6.Egg_Location = Util.getIndex(CB_EggLocation); + pkm.Met_Location = Util.getIndex(CB_MetLocation); + pkm.Egg_Location = Util.getIndex(CB_EggLocation); updateLegality(); } private void removedropCB(object sender, KeyEventArgs e) @@ -2284,10 +2461,11 @@ private void updateLegality(LegalityAnalysis la = null) { if (!fieldsLoaded) return; - - Legality = la ?? new LegalityAnalysis(pk6); + if (!(pkm is PK6)) + return; + Legality = la ?? new LegalityAnalysis(pkm as PK6); PB_Legal.Image = Legality.Valid ? Properties.Resources.valid : Properties.Resources.warn; - PB_Legal.Visible = pk6.Gen6; + PB_Legal.Visible = pkm.Gen6 /*&& pkm is PK6*/; // Refresh Move Legality for (int i = 0; i < 4; i++) @@ -2375,17 +2553,16 @@ private void openRibbons(object sender, EventArgs e) } private void openHistory(object sender, EventArgs e) { + if (pkm.Format < 6) return; // Write back current values + PK6 pk6 = pkm as PK6; pk6.Version = Util.getIndex(CB_GameOrigin); pk6.HT_Name = TB_OTt2.Text; pk6.OT_Name = TB_OT.Text; pk6.IsEgg = CHK_IsEgg.Checked; - if (pk6.CurrentHandler == 0) - pk6.OT_Friendship = Util.ToInt32(TB_Friendship.Text); - else // 1 - pk6.HT_Friendship = Util.ToInt32(TB_Friendship.Text); + pk6.CurrentFriendship = Util.ToInt32(TB_Friendship.Text); new MemoryAmie().ShowDialog(); - TB_Friendship.Text = (pk6.CurrentHandler == 0 ? pk6.OT_Friendship : pk6.HT_Friendship).ToString(); + TB_Friendship.Text = pk6.CurrentFriendship.ToString(); } // Open/Save Array Manipulation // public bool verifiedPKX() @@ -2426,11 +2603,263 @@ public bool verifiedPKX() invalid: { SystemSounds.Exclamation.Play(); return false; } } - public PK6 preparepkx(bool click = true) + public PKM preparePKM(bool click = true) { if (click) tabMain.Select(); // hack to make sure comboboxes are set (users scrolling through and immediately setting causes this) + PKM pk = null; + switch (pkm.Format) + { + case 4: + pk = preparePK4(); + break; + case 5: + pk = preparePK5(); + break; + case 6: + pk = preparePK6(); + break; + } + return pk; + } + private PK4 preparePK4() + { + PK4 pk4 = pkm as PK4; + if (pk4 == null) + return null; + + pk4.Species = Util.getIndex(CB_Species); + pk4.HeldItem = Util.getIndex(CB_HeldItem); + pk4.TID = Util.ToInt32(TB_TID.Text); + pk4.SID = Util.ToInt32(TB_SID.Text); + pk4.EXP = Util.ToUInt32(TB_EXP.Text); + pk4.PID = Util.getHEXval(TB_PID.Text); + pk4.Ability = (byte)Util.getIndex(DEV_Ability); + //pk4.Ability = (byte)Array.IndexOf(abilitylist, CB_Ability.Text.Remove(CB_Ability.Text.Length - 4)); + + pk4.Nature = (byte)Util.getIndex(CB_Nature); + pk4.FatefulEncounter = CHK_Fateful.Checked; + pk4.Gender = PKX.getGender(Label_Gender.Text); + pk4.AltForm = (MT_Form.Enabled ? Convert.ToInt32(MT_Form.Text) : CB_Form.SelectedIndex) & 0x1F; + pk4.EV_HP = Util.ToInt32(TB_HPEV.Text); + pk4.EV_ATK = Util.ToInt32(TB_ATKEV.Text); + pk4.EV_DEF = Util.ToInt32(TB_DEFEV.Text); + pk4.EV_SPE = Util.ToInt32(TB_SPEEV.Text); + pk4.EV_SPA = Util.ToInt32(TB_SPAEV.Text); + pk4.EV_SPD = Util.ToInt32(TB_SPDEV.Text); + + pk4.CNT_Cool = Util.ToInt32(TB_Cool.Text); + pk4.CNT_Beauty = Util.ToInt32(TB_Beauty.Text); + pk4.CNT_Cute = Util.ToInt32(TB_Cute.Text); + pk4.CNT_Smart = Util.ToInt32(TB_Smart.Text); + pk4.CNT_Tough = Util.ToInt32(TB_Tough.Text); + pk4.CNT_Sheen = Util.ToInt32(TB_Sheen.Text); + + pk4.PKRS_Days = CB_PKRSDays.SelectedIndex; + pk4.PKRS_Strain = CB_PKRSStrain.SelectedIndex; + pk4.Nickname = TB_Nickname.Text; + pk4.Move1 = Util.getIndex(CB_Move1); + pk4.Move2 = Util.getIndex(CB_Move2); + pk4.Move3 = Util.getIndex(CB_Move3); + pk4.Move4 = Util.getIndex(CB_Move4); + pk4.Move1_PP = Util.getIndex(CB_Move1) > 0 ? Util.ToInt32(TB_PP1.Text) : 0; + pk4.Move2_PP = Util.getIndex(CB_Move2) > 0 ? Util.ToInt32(TB_PP2.Text) : 0; + pk4.Move3_PP = Util.getIndex(CB_Move3) > 0 ? Util.ToInt32(TB_PP3.Text) : 0; + pk4.Move4_PP = Util.getIndex(CB_Move4) > 0 ? Util.ToInt32(TB_PP4.Text) : 0; + pk4.Move1_PPUps = Util.getIndex(CB_Move1) > 0 ? CB_PPu1.SelectedIndex : 0; + pk4.Move2_PPUps = Util.getIndex(CB_Move2) > 0 ? CB_PPu2.SelectedIndex : 0; + pk4.Move3_PPUps = Util.getIndex(CB_Move3) > 0 ? CB_PPu3.SelectedIndex : 0; + pk4.Move4_PPUps = Util.getIndex(CB_Move4) > 0 ? CB_PPu4.SelectedIndex : 0; + + pk4.IV_HP = Util.ToInt32(TB_HPIV.Text); + pk4.IV_ATK = Util.ToInt32(TB_ATKIV.Text); + pk4.IV_DEF = Util.ToInt32(TB_DEFIV.Text); + pk4.IV_SPE = Util.ToInt32(TB_SPEIV.Text); + pk4.IV_SPA = Util.ToInt32(TB_SPAIV.Text); + pk4.IV_SPD = Util.ToInt32(TB_SPDIV.Text); + pk4.IsEgg = CHK_IsEgg.Checked; + pk4.IsNicknamed = CHK_Nicknamed.Checked; + + pk4.OT_Name = TB_OT.Text; + pk4.CurrentFriendship = Util.ToInt32(TB_Friendship.Text); + + pk4.Ball = Util.getIndex(CB_Ball); + pk4.Met_Level = Util.ToInt32(TB_MetLevel.Text); + pk4.OT_Gender = PKX.getGender(Label_OTGender.Text); + pk4.EncounterType = Util.getIndex(CB_EncounterType); + pk4.Version = Util.getIndex(CB_GameOrigin); + pk4.Language = Util.getIndex(CB_Language); + + // Default Dates + int egg_year = 2000; + int egg_month = 0; + int egg_day = 0; + int egg_location = 0; + if (CHK_AsEgg.Checked) // If encountered as an egg, load the Egg Met data from fields. + { + egg_year = CAL_EggDate.Value.Year; + egg_month = CAL_EggDate.Value.Month; + egg_day = CAL_EggDate.Value.Day; + egg_location = Util.getIndex(CB_EggLocation); + } + // Egg Met Data + pk4.Egg_Year = egg_year - 2000; + pk4.Egg_Month = egg_month; + pk4.Egg_Day = egg_day; + pk4.Egg_Location = egg_location; + // Met Data + pk4.Met_Year = CAL_MetDate.Value.Year - 2000; + pk4.Met_Month = CAL_MetDate.Value.Month; + pk4.Met_Day = CAL_MetDate.Value.Day; + pk4.Met_Location = Util.getIndex(CB_MetLocation); + + if (pk4.IsEgg && pk4.Met_Location == 0) // If still an egg, it has no hatch location/date. Zero it! + pk4.Met_Year = pk4.Met_Month = pk4.Met_Day = 0; + + // Toss in Party Stats + Array.Resize(ref pk4.Data, pk4.SIZE_PARTY); + pk4.Stat_Level = Util.ToInt32(TB_Level.Text); + pk4.Stat_HPCurrent = Util.ToInt32(Stat_HP.Text); + pk4.Stat_HPMax = Util.ToInt32(Stat_HP.Text); + pk4.Stat_ATK = Util.ToInt32(Stat_ATK.Text); + pk4.Stat_DEF = Util.ToInt32(Stat_DEF.Text); + pk4.Stat_SPE = Util.ToInt32(Stat_SPE.Text); + pk4.Stat_SPA = Util.ToInt32(Stat_SPA.Text); + pk4.Stat_SPD = Util.ToInt32(Stat_SPD.Text); + + if (HaX) + { + pk4.Stat_Level = (byte)Math.Min(Convert.ToInt32(MT_Level.Text), byte.MaxValue); + } + + // Fix Moves if a slot is empty + pk4.FixMoves(); + + pk4.RefreshChecksum(); + return pk4; + } + private PK5 preparePK5() + { + PK5 pk5 = pkm as PK5; + if (pk5 == null) + return null; + + pk5.Species = Util.getIndex(CB_Species); + pk5.HeldItem = Util.getIndex(CB_HeldItem); + pk5.TID = Util.ToInt32(TB_TID.Text); + pk5.SID = Util.ToInt32(TB_SID.Text); + pk5.EXP = Util.ToUInt32(TB_EXP.Text); + pk5.PID = Util.getHEXval(TB_PID.Text); + pk5.Ability = (byte)Util.getIndex(DEV_Ability); + //pk5.Ability = (byte)Array.IndexOf(abilitylist, CB_Ability.Text.Remove(CB_Ability.Text.Length - 4)); + + pk5.Nature = (byte)Util.getIndex(CB_Nature); + pk5.FatefulEncounter = CHK_Fateful.Checked; + pk5.Gender = PKX.getGender(Label_Gender.Text); + pk5.AltForm = (MT_Form.Enabled ? Convert.ToInt32(MT_Form.Text) : CB_Form.SelectedIndex) & 0x1F; + pk5.EV_HP = Util.ToInt32(TB_HPEV.Text); + pk5.EV_ATK = Util.ToInt32(TB_ATKEV.Text); + pk5.EV_DEF = Util.ToInt32(TB_DEFEV.Text); + pk5.EV_SPE = Util.ToInt32(TB_SPEEV.Text); + pk5.EV_SPA = Util.ToInt32(TB_SPAEV.Text); + pk5.EV_SPD = Util.ToInt32(TB_SPDEV.Text); + + pk5.CNT_Cool = Util.ToInt32(TB_Cool.Text); + pk5.CNT_Beauty = Util.ToInt32(TB_Beauty.Text); + pk5.CNT_Cute = Util.ToInt32(TB_Cute.Text); + pk5.CNT_Smart = Util.ToInt32(TB_Smart.Text); + pk5.CNT_Tough = Util.ToInt32(TB_Tough.Text); + pk5.CNT_Sheen = Util.ToInt32(TB_Sheen.Text); + + pk5.PKRS_Days = CB_PKRSDays.SelectedIndex; + pk5.PKRS_Strain = CB_PKRSStrain.SelectedIndex; + pk5.Nickname = TB_Nickname.Text; + pk5.Move1 = Util.getIndex(CB_Move1); + pk5.Move2 = Util.getIndex(CB_Move2); + pk5.Move3 = Util.getIndex(CB_Move3); + pk5.Move4 = Util.getIndex(CB_Move4); + pk5.Move1_PP = Util.getIndex(CB_Move1) > 0 ? Util.ToInt32(TB_PP1.Text) : 0; + pk5.Move2_PP = Util.getIndex(CB_Move2) > 0 ? Util.ToInt32(TB_PP2.Text) : 0; + pk5.Move3_PP = Util.getIndex(CB_Move3) > 0 ? Util.ToInt32(TB_PP3.Text) : 0; + pk5.Move4_PP = Util.getIndex(CB_Move4) > 0 ? Util.ToInt32(TB_PP4.Text) : 0; + pk5.Move1_PPUps = Util.getIndex(CB_Move1) > 0 ? CB_PPu1.SelectedIndex : 0; + pk5.Move2_PPUps = Util.getIndex(CB_Move2) > 0 ? CB_PPu2.SelectedIndex : 0; + pk5.Move3_PPUps = Util.getIndex(CB_Move3) > 0 ? CB_PPu3.SelectedIndex : 0; + pk5.Move4_PPUps = Util.getIndex(CB_Move4) > 0 ? CB_PPu4.SelectedIndex : 0; + + pk5.IV_HP = Util.ToInt32(TB_HPIV.Text); + pk5.IV_ATK = Util.ToInt32(TB_ATKIV.Text); + pk5.IV_DEF = Util.ToInt32(TB_DEFIV.Text); + pk5.IV_SPE = Util.ToInt32(TB_SPEIV.Text); + pk5.IV_SPA = Util.ToInt32(TB_SPAIV.Text); + pk5.IV_SPD = Util.ToInt32(TB_SPDIV.Text); + pk5.IsEgg = CHK_IsEgg.Checked; + pk5.IsNicknamed = CHK_Nicknamed.Checked; + + pk5.OT_Name = TB_OT.Text; + pk5.CurrentFriendship = Util.ToInt32(TB_Friendship.Text); + + // Default Dates + int egg_year = 2000; + int egg_month = 0; + int egg_day = 0; + int egg_location = 0; + if (CHK_AsEgg.Checked) // If encountered as an egg, load the Egg Met data from fields. + { + egg_year = CAL_EggDate.Value.Year; + egg_month = CAL_EggDate.Value.Month; + egg_day = CAL_EggDate.Value.Day; + egg_location = Util.getIndex(CB_EggLocation); + } + // Egg Met Data + pk5.Egg_Year = egg_year - 2000; + pk5.Egg_Month = egg_month; + pk5.Egg_Day = egg_day; + pk5.Egg_Location = egg_location; + // Met Data + pk5.Met_Year = CAL_MetDate.Value.Year - 2000; + pk5.Met_Month = CAL_MetDate.Value.Month; + pk5.Met_Day = CAL_MetDate.Value.Day; + pk5.Met_Location = Util.getIndex(CB_MetLocation); + + if (pk5.IsEgg && pk5.Met_Location == 0) // If still an egg, it has no hatch location/date. Zero it! + pk5.Met_Year = pk5.Met_Month = pk5.Met_Day = 0; + + pk5.Ball = Util.getIndex(CB_Ball); + pk5.Met_Level = Util.ToInt32(TB_MetLevel.Text); + pk5.OT_Gender = PKX.getGender(Label_OTGender.Text); + pk5.EncounterType = Util.getIndex(CB_EncounterType); + pk5.Version = Util.getIndex(CB_GameOrigin); + pk5.Language = Util.getIndex(CB_Language); + + // Toss in Party Stats + Array.Resize(ref pk5.Data, pk5.SIZE_PARTY); + pk5.Stat_Level = Util.ToInt32(TB_Level.Text); + pk5.Stat_HPCurrent = Util.ToInt32(Stat_HP.Text); + pk5.Stat_HPMax = Util.ToInt32(Stat_HP.Text); + pk5.Stat_ATK = Util.ToInt32(Stat_ATK.Text); + pk5.Stat_DEF = Util.ToInt32(Stat_DEF.Text); + pk5.Stat_SPE = Util.ToInt32(Stat_SPE.Text); + pk5.Stat_SPA = Util.ToInt32(Stat_SPA.Text); + pk5.Stat_SPD = Util.ToInt32(Stat_SPD.Text); + + if (HaX) + { + pk5.Stat_Level = (byte)Math.Min(Convert.ToInt32(MT_Level.Text), byte.MaxValue); + } + + // Fix Moves if a slot is empty + pk5.FixMoves(); + + pk5.RefreshChecksum(); + return pk5; + } + private PK6 preparePK6() + { + PK6 pk6 = pkm as PK6; + if (pk6 == null) + return null; // Repopulate PK6 with Edited Stuff if (Util.getIndex(CB_GameOrigin) < 24) { @@ -2487,13 +2916,6 @@ public PK6 preparepkx(bool click = true) pk6.CNT_Tough = Util.ToInt32(TB_Tough.Text); pk6.CNT_Sheen = Util.ToInt32(TB_Sheen.Text); - pk6.Circle = CHK_Circle.Checked; - pk6.Triangle = CHK_Triangle.Checked; - pk6.Square = CHK_Square.Checked; - pk6.Heart = CHK_Heart.Checked; - pk6.Star = CHK_Star.Checked; - pk6.Diamond = CHK_Diamond.Checked; - pk6.PKRS_Days = CB_PKRSDays.SelectedIndex; pk6.PKRS_Strain = CB_PKRSStrain.SelectedIndex; // Already in buff (then transferred to new pkx) @@ -2586,7 +3008,7 @@ public PK6 preparepkx(bool click = true) // 0xE4-0xE7 // Toss in Party Stats - Array.Resize(ref pk6.Data, PK6.SIZE_PARTY); + Array.Resize(ref pk6.Data, pk6.SIZE_PARTY); pk6.Stat_Level = Util.ToInt32(TB_Level.Text); pk6.Stat_HPCurrent = Util.ToInt32(Stat_HP.Text); pk6.Stat_HPMax = Util.ToInt32(Stat_HP.Text); @@ -2642,9 +3064,9 @@ private void dragout_MouseDown(object sender, MouseEventArgs e) return; // Create Temp File to Drag - PK6 pkx = preparepkx(); + PKM pkx = preparePKM(); bool encrypt = ModifierKeys == Keys.Control; - string filename = $"{Path.GetFileNameWithoutExtension(pkx.FileName)}{(encrypt ? ".ek6" : ".pk6")}"; + string filename = $"{Path.GetFileNameWithoutExtension(pkx.FileName)}{(encrypt ? ".ek" : ".pk") + pkx.Format}"; byte[] dragdata = encrypt ? pkx.EncryptedBoxData : pkx.DecryptedBoxData; // Make file string newfile = Path.Combine(Path.GetTempPath(), Util.CleanFileName(filename)); @@ -2713,7 +3135,7 @@ private void clickExportSAV(object sender, EventArgs e) return; // Chunk Error Checking - string err = SAV.checkChunkFF(); + string err = SAV.MiscSaveChecks(); if (err.Length > 0 && Util.Prompt(MessageBoxButtons.YesNo, err, "Continue saving?") != DialogResult.Yes) return; @@ -2729,7 +3151,7 @@ private void clickExportSAV(object sender, EventArgs e) // Export if (main.ShowDialog() != DialogResult.OK) return; - if (SAV.Box > -1) + if (SAV.HasBox) SAV.CurrentBox = CB_BoxSelect.SelectedIndex; File.WriteAllBytes(main.FileName, SAV.Write()); Util.Alert("SAV exported to:", main.FileName); @@ -2738,25 +3160,54 @@ private void clickExportSAV(object sender, EventArgs e) // Box/SAV Functions // private void clickBoxRight(object sender, EventArgs e) { - CB_BoxSelect.SelectedIndex = (CB_BoxSelect.SelectedIndex + 1) % 31; + CB_BoxSelect.SelectedIndex = (CB_BoxSelect.SelectedIndex + 1) % SAV.BoxCount; } private void clickBoxLeft(object sender, EventArgs e) { - CB_BoxSelect.SelectedIndex = (CB_BoxSelect.SelectedIndex + 30) % 31; + CB_BoxSelect.SelectedIndex = (CB_BoxSelect.SelectedIndex + SAV.BoxCount-1) % SAV.BoxCount; } private void clickBoxSort(object sender, EventArgs e) { - if (ModifierKeys != Keys.Control || tabBoxMulti.SelectedIndex != 0) + if (tabBoxMulti.SelectedIndex != 0) return; + if (ModifierKeys == (Keys.Alt | Keys.Shift)) + { + if (DialogResult.Yes != Util.Prompt(MessageBoxButtons.YesNo, "Clear ALL Boxes?!")) + return; - if (DialogResult.Yes != Util.Prompt(MessageBoxButtons.YesNo, "Sort Boxes?")) - return; + SAV.resetBoxes(); + CB_BoxSelect.SelectedIndex = 0; + Util.Alert("Boxes cleared!"); + } + else if (ModifierKeys == Keys.Alt) + { + if (DialogResult.Yes != Util.Prompt(MessageBoxButtons.YesNo, "Clear Current Box?")) + return; - SAV.sortBoxes(); - setPKXBoxes(); - CB_BoxSelect.SelectedIndex = 0; - Util.Alert("Boxes sorted!"); + SAV.resetBoxes(CB_BoxSelect.SelectedIndex, CB_BoxSelect.SelectedIndex + 1); + setPKXBoxes(); + Util.Alert("Current Box cleared!"); + } + else if (ModifierKeys == (Keys.Control | Keys.Shift)) + { + if (DialogResult.Yes != Util.Prompt(MessageBoxButtons.YesNo, "Sort ALL Boxes?!")) + return; + + SAV.sortBoxes(); + CB_BoxSelect.SelectedIndex = 0; + Util.Alert("Boxes sorted!"); + } + else if (ModifierKeys == Keys.Control) + { + if (DialogResult.Yes != Util.Prompt(MessageBoxButtons.YesNo, "Sort Current Box?")) + return; + + SAV.sortBoxes(CB_BoxSelect.SelectedIndex, CB_BoxSelect.SelectedIndex + 1); + setPKXBoxes(); + Util.Alert("Current Box sorted!"); + } } + private void clickSlot(object sender, EventArgs e) { switch (ModifierKeys) @@ -2770,30 +3221,22 @@ private void clickSlot(object sender, EventArgs e) private void clickView(object sender, EventArgs e) { int slot = getSlot(sender); - int offset = getPKXOffset(slot); if (SlotPictureBoxes[slot].Image == null) { SystemSounds.Exclamation.Play(); return; } + int offset = getPKXOffset(slot); + if (offset < 0) + { + Util.Error($"Slot read error @ slot {slot}."); + return; + } // Load the PKX file - PK6 pk = 30 <= slot && slot < 36 ? SAV.getPK6Party(offset) : SAV.getPK6Stored(offset); + PKM pk = 30 <= slot && slot < 36 ? SAV.getPartySlot(offset) : SAV.getStoredSlot(offset); if (pk.Sanity == 0 && pk.Species != 0) { try { populateFields(pk); } - catch // If it fails, try XORing encrypted zeroes - { - try - { - byte[] blank = (byte[])blankEK6.Clone(); - - for (int i = 0; i < PK6.SIZE_STORED; i++) - blank[i] = (byte)(pk6.Data[i] ^ blank[i]); - - populateFields(new PK6(blank)); - } - catch // Still fails, just let the original errors occur. - { populateFields(pk6); } - } + catch { } // Visual to display what slot is currently loaded. getSlotColor(slot, Properties.Resources.slotView); } @@ -2808,36 +3251,17 @@ private void clickSet(object sender, EventArgs e) { Util.Alert("Can't have empty/egg first slot."); return; } int offset = getPKXOffset(slot); - PK6 pk = preparepkx(); - string err = ""; - if (SAV.XY) + if (offset < 0) { - // User Protection - if (pk.Moves.Any(m => m > 617)) - err = "Move does not exist in X/Y."; - else if (pk.Ability > 188) - err = "Ability does not exist in X/Y."; - else if (pk.HeldItem > 717) - err = "Item does not exist in X/Y."; - else if (pk.Species > 721) - err = "Species does not exist in X/Y."; - else if (pk.AltForm > Legal.PersonalXY[pk.Species].FormeCount - 1) - err = "Form does not exist in X/Y."; - } - else if (SAV.ORAS) - { - if (pk.Species > 721) - err = "Species does not exist in OR/AS."; - else if (pk.AltForm > Legal.PersonalAO[pk.Species].FormeCount - 1) - err = "Form does not exist in OR/AS."; - } - if (!string.IsNullOrEmpty(err) && Util.Prompt(MessageBoxButtons.YesNo, err, "Continue?") != DialogResult.Yes) + Util.Error($"Slot read error @ slot {slot}."); return; - + } + PKM pk = preparePKM(); + if (slot >= 30 && slot < 36) // Party - SAV.setPK6Party(pk, offset); + SAV.setPartySlot(pk, offset); else if (slot < 30 || (slot >= 36 && slot < 42 && DEV_Ability.Enabled)) - SAV.setPK6Stored(pk, offset); + SAV.setStoredSlot(pk, offset); else return; if (slot >= 30 && slot < 36) @@ -2851,11 +3275,17 @@ private void clickDelete(object sender, EventArgs e) { int slot = getSlot(sender); if (slot == 30 && SAV.PartyCount == 1 && !DEV_Ability.Enabled) { Util.Alert("Can't delete first slot."); return; } - + + int offset = getPKXOffset(slot); + if (offset < 0) + { + Util.Error($"Slot read error @ slot {slot}."); + return; + } if (slot >= 30 && slot < 36) // Party - { SAV.setData(blankEK6, getPKXOffset(slot)); setParty(); return; } + { SAV.setPartySlot(SAV.BlankPKM, offset); setParty(); return; } if (slot < 30 || (slot >= 36 && slot < 42 && DEV_Ability.Enabled)) - { SAV.setEK6Stored(blankEK6, getPKXOffset(slot)); } + { SAV.setStoredSlot(SAV.BlankPKM, getPKXOffset(slot)); } else return; SlotPictureBoxes[slot].Image = null; @@ -2865,45 +3295,44 @@ private void clickClone(object sender, EventArgs e) { if (getSlot(sender) > 30) return; // only perform action if cloning to boxes if (!verifiedPKX()) return; // don't copy garbage to the box + + if (Util.Prompt(MessageBoxButtons.YesNo, $"Clone Pokemon from Editing Tabs to all slots in {CB_BoxSelect.Text}?") != DialogResult.Yes) + return; - PK6 pk; - int box = CB_BoxSelect.SelectedIndex + 1; // get box we're cloning to - - if (Util.Prompt(MessageBoxButtons.YesNo, $"Clone Pokemon from Editing Tabs to all slots in Box {box}?") == DialogResult.Yes) - pk = preparepkx(); - else if (Util.Prompt(MessageBoxButtons.YesNo, $"Delete Pokemon from all slots in Box {box}?") == DialogResult.Yes) - pk = new PK6(); - else - return; // abort clone/delete - - for (int i = 0; i < 30; i++) // write encrypted array to all box slots + PKM pk = preparePKM(); + for (int i = 0; i < 30; i++) // set to every slot in box { - SAV.setPK6Stored(pk, getPKXOffset(i)); + SAV.setStoredSlot(pk, getPKXOffset(i)); getQuickFiller(SlotPictureBoxes[i], pk); } } private void clickLegality(object sender, EventArgs e) { int slot = getSlot(sender); - PK6 pk; + PKM pk; if (slot >= 0) - pk = SAV.getPK6Stored(getPKXOffset(slot)); + pk = SAV.getStoredSlot(getPKXOffset(slot)); else if (verifiedPKX()) - pk = preparepkx(); + pk = preparePKM(); else return; if (pk.Species == 0 || !pk.ChecksumValid) { SystemSounds.Asterisk.Play(); return; } - - showLegality(pk, slot < 0, ModifierKeys == Keys.Control); + if (typeof (PK6) != pk.GetType()) + { + Util.Alert($"Checking legality of {pk.GetType()} files is not supported."); + return; + } + showLegality(pk as PK6, slot < 0, ModifierKeys == Keys.Control); } + private void updateEggRNGSeed(object sender, EventArgs e) { if (TB_RNGSeed.Text.Length == 0) { // Reset to 0 - TB_RNGSeed.Text = 0.ToString("X16"); + TB_RNGSeed.Text = 0.ToString("X"+SAV.DaycareSeedSize); return; // recursively triggers this method, no need to continue } @@ -2912,122 +3341,97 @@ private void updateEggRNGSeed(object sender, EventArgs e) { Util.Alert("Expected HEX (0-9, A-F).", "Received: " + Environment.NewLine + TB_RNGSeed.Text); // Reset to Stored Value - TB_RNGSeed.Text = SAV.DaycareRNGSeed.ToString("X16"); + var seed = SAV.getDaycareRNGSeed(SAV.DaycareIndex); + if (seed != null) + TB_RNGSeed.Text = ((ulong)seed).ToString("X"+SAV.DaycareSeedSize); return; // recursively triggers this method, no need to continue } // Write final value back to the save ulong value = Convert.ToUInt64(filterText, 16); - if (value != SAV.DaycareRNGSeed) + if (value != SAV.getDaycareRNGSeed(SAV.DaycareIndex)) { - SAV.DaycareRNGSeed = value; + SAV.setDaycareRNGSeed(SAV.DaycareIndex, value); SAV.Edited = true; } } - private void updateGameSync(object sender, EventArgs e) + private void updateU64(object sender, EventArgs e) { - if (TB_GameSync.Text.Length == 0) + TextBox tb = sender as TextBox; + if (tb.Text.Length == 0) { // Reset to 0 - TB_GameSync.Text = 0.ToString("X16"); + tb.Text = 0.ToString("X16"); return; // recursively triggers this method, no need to continue } - string filterText = Util.getOnlyHex(TB_GameSync.Text); - if (filterText.Length != TB_GameSync.Text.Length) + // Currently saved Value + ulong oldval = 0; + if (tb == TB_GameSync) + oldval = (SAV as SAV6).GameSyncID; + else if (tb == TB_Secure1) + oldval = (SAV as SAV6).Secure1; + else if (tb == TB_Secure2) + oldval = (SAV as SAV6).Secure2; + + string filterText = Util.getOnlyHex(tb.Text); + + if (filterText.Length != tb.Text.Length) { - Util.Alert("Expected HEX (0-9, A-F).", "Received: " + Environment.NewLine + TB_GameSync.Text); + Util.Alert("Expected HEX (0-9, A-F).", "Received: " + Environment.NewLine + tb.Text); // Reset to Stored Value - TB_GameSync.Text = SAV.GameSyncID.ToString("X16"); + tb.Text = oldval.ToString("X16"); return; // recursively triggers this method, no need to continue } // Write final value back to the save - ulong value = Convert.ToUInt64(filterText, 16); - if (value != SAV.GameSyncID) + ulong newval = Convert.ToUInt64(filterText, 16); + if (newval != oldval) { - SAV.GameSyncID = value; - SAV.Edited = true; - } - } - private void updateSecure1(object sender, EventArgs e) - { - if (TB_Secure1.Text.Length == 0) - { - // Reset to 0 - TB_Secure1.Text = 0.ToString("X16"); - return; // recursively triggers this method, no need to continue - } - - string filterText = Util.getOnlyHex(TB_Secure1.Text); - if (filterText.Length != TB_Secure1.Text.Length) - { - Util.Alert("Expected HEX (0-9, A-F).", "Received: " + Environment.NewLine + TB_Secure1.Text); - // Reset to Stored Value - TB_Secure1.Text = SAV.Secure1.ToString("X16"); - return; // recursively triggers this method, no need to continue - } - - // Write final value back to the save - ulong value = Convert.ToUInt64(filterText, 16); - if (value != SAV.Secure1) - { - SAV.Secure1 = value; - SAV.Edited = true; - } - } - private void updateSecure2(object sender, EventArgs e) - { - if (TB_Secure2.Text.Length == 0) - { - // Reset to 0 - TB_Secure2.Text = 0.ToString("X16"); - return; // recursively triggers this method, no need to continue - } - string filterText = Util.getOnlyHex(TB_Secure2.Text); - if (filterText.Length != TB_Secure2.Text.Length) - { - Util.Alert("Expected HEX (0-9, A-F).", "Received: " + Environment.NewLine + TB_Secure2.Text); - // Reset to Stored Value - TB_Secure2.Text = SAV.Secure2.ToString("X16"); - return; // recursively triggers this method, no need to continue - } - - // Write final value back to the save - ulong value = Convert.ToUInt64(filterText, 16); - if (value != SAV.Secure2) - { - SAV.Secure2 = value; + if (tb == TB_GameSync) + (SAV as SAV6).GameSyncID = newval; + else if (tb == TB_Secure1) + (SAV as SAV6).Secure1 = newval; + else if (tb == TB_Secure2) + (SAV as SAV6).Secure2 = newval; SAV.Edited = true; } } // Generic Subfunctions // private void setParty() { - SAV.setParty(); + PKM[] party = SAV.PartyData; + PKM[] battle = SAV.BattleBoxData; // Refresh slots - for (int i = 0; i < 6; i++) - { - getQuickFiller(SlotPictureBoxes[i + 30], SAV.getPK6Stored(SAV.Party + PK6.SIZE_PARTY*i)); - getQuickFiller(SlotPictureBoxes[i + 36], SAV.getPK6Stored(SAV.BattleBox + PK6.SIZE_STORED*i)); - } + if (SAV.HasParty) + for (int i = 0; i < 6; i++) + getQuickFiller(SlotPictureBoxes[i + 30], party[i]); + if (SAV.HasBattleBox) + for (int i = 0; i < 6; i++) + getQuickFiller(SlotPictureBoxes[i + 36], battle[i]); } private int getPKXOffset(int slot) { if (slot < 30) // Box Slot - return SAV.Box + (30 * CB_BoxSelect.SelectedIndex + slot) * PK6.SIZE_STORED; - if (slot < 36) // Party Slot - return SAV.Party + (slot - 30) * PK6.SIZE_PARTY; - if (slot < 42) // Battle Box Slot - return SAV.BattleBox + (slot - 36) * PK6.SIZE_STORED; - if (slot < 44) // Daycare - return SAV.DaycareSlot[SAV.DaycareIndex] + 8 + (slot - 42) * (PK6.SIZE_STORED + 8); - if (slot < 45) // GTS + return SAV.getBoxOffset(CB_BoxSelect.SelectedIndex) + slot * SAV.SIZE_STORED; + slot -= 30; + if (slot < 6) // Party Slot + return SAV.getPartyOffset(slot); + slot -= 6; + if (slot < 6) // Battle Box Slot + return SAV.BattleBox + slot * SAV.SIZE_STORED; + slot -= 6; + if (slot < 2) // Daycare + return SAV.getDaycareSlotOffset(SAV.DaycareIndex, slot); + slot -= 2; + if (slot == 0) // GTS return SAV.GTS; - if (slot < 46) // Fused + slot -= 1; + if (slot == 0) // Fused return SAV.Fused; - if (slot < 50) // SUBE - return SAV.SUBE + (slot - 46) * (PK6.SIZE_STORED + 4); + slot -= 1; + if (slot < 3) // SUBE + return SAV.SUBE + slot * (SAV.SIZE_STORED + 4); return -1; } private int getSlot(object sender) @@ -3037,97 +3441,126 @@ private int getSlot(object sender) } public void setPKXBoxes() { - if (SAV.Box > -1) + if (SAV.HasBox) { - int boxoffset = SAV.Box + CB_BoxSelect.SelectedIndex*PK6.SIZE_STORED*30; - int boxbgval = SAV.getBoxWallpaper(CB_BoxSelect.SelectedIndex); - string imagename = "box_wp" + boxbgval.ToString("00"); if (SAV.ORAS && boxbgval > 16) imagename += "o"; - PAN_Box.BackgroundImage = (Image)Properties.Resources.ResourceManager.GetObject(imagename); + int boxoffset = SAV.getBoxOffset(CB_BoxSelect.SelectedIndex); + if (SAV.HasBoxWallpapers) + { + int boxbgval = SAV.getBoxWallpaper(CB_BoxSelect.SelectedIndex); + string imagename = ""; + switch (SAV.Generation) + { + case 6: + imagename = "box_wp" + boxbgval.ToString("00"); + if (SAV.ORAS && boxbgval > 16) + imagename += "o"; + break; + } + if (!string.IsNullOrEmpty(imagename)) + PAN_Box.BackgroundImage = (Image)Properties.Resources.ResourceManager.GetObject(imagename); + } for (int i = 0; i < 30; i++) - getSlotFiller(boxoffset + PK6.SIZE_STORED * i, SlotPictureBoxes[i]); + getSlotFiller(boxoffset + SAV.SIZE_STORED * i, SlotPictureBoxes[i]); } // Reload Party - if (SAV.Party > -1) - for (int i = 0; i < 6; i++) - getSlotFiller(SAV.Party + PK6.SIZE_PARTY * i, SlotPictureBoxes[i + 30]); + if (SAV.HasParty) + { + for (int i = 0; i < 6; i++) + getSlotFiller(SAV.getPartyOffset(i), SlotPictureBoxes[i + 30]); + } // Reload Battle Box - if (SAV.BattleBox > -1) - for (int i = 0; i < 6; i++) - getSlotFiller(SAV.BattleBox + PK6.SIZE_STORED * i, SlotPictureBoxes[i + 36]); + if (SAV.HasBattleBox) + { + for (int i = 0; i < 6; i++) + getSlotFiller(SAV.BattleBox + SAV.SIZE_STORED * i, SlotPictureBoxes[i + 36]); + } // Reload Daycare - if (SAV.Daycare > -1) + if (SAV.HasDaycare) { - Label[] dclabela = { L_DC1, L_DC2, }; - TextBox[] dctexta = { TB_Daycare1XP, TB_Daycare2XP }; - uint[] exp = { SAV.DaycareEXP1, SAV.DaycareEXP2 }; - bool[] occ = { SAV.DaycareOccupied1, SAV.DaycareOccupied2 }; + Label[] L_SlotOccupied = { L_DC1, L_DC2 }; + TextBox[] TB_SlotEXP = { TB_Daycare1XP, TB_Daycare2XP }; + Label[] L_SlotEXP = { L_XP1, L_XP2 }; for (int i = 0; i < 2; i++) { - getSlotFiller(SAV.DaycareSlot[SAV.DaycareIndex] + PK6.SIZE_STORED * i + 8 * (i + 1), SlotPictureBoxes[i + 42]); - dctexta[i].Text = exp[i].ToString(); - if (occ[i]) // If Occupied - dclabela[i].Text = $"{i + 1}: ✓"; + getSlotFiller(SAV.getDaycareSlotOffset(SAV.DaycareIndex, i), SlotPictureBoxes[i + 42]); + uint? exp = SAV.getDaycareEXP(SAV.DaycareIndex, i); + TB_SlotEXP[i].Visible = L_SlotEXP[i].Visible = exp != null; + TB_SlotEXP[i].Text = exp.ToString(); + bool? occ = SAV.getDaycareOccupied(SAV.DaycareIndex, i); + L_SlotOccupied[i].Visible = occ != null; + if (occ == true) // If Occupied + L_SlotOccupied[i].Text = $"{i + 1}: ✓"; else { - dclabela[i].Text = $"{i + 1}: ✘"; + L_SlotOccupied[i].Text = $"{i + 1}: ✘"; SlotPictureBoxes[i + 42].Image = Util.ChangeOpacity(SlotPictureBoxes[i + 42].Image, 0.6); } } - DayCare_HasEgg.Checked = SAV.DaycareHasEgg; - TB_RNGSeed.Text = SAV.DaycareRNGSeed.ToString("X16"); + bool? egg = SAV.getDaycareHasEgg(SAV.DaycareIndex); + DayCare_HasEgg.Visible = egg != null; + DayCare_HasEgg.Checked = egg == true; + + ulong? seed = SAV.getDaycareRNGSeed(SAV.DaycareIndex); + L_DaycareSeed.Visible = TB_RNGSeed.Visible = seed != null; + if (seed != null) + { + TB_RNGSeed.MaxLength = SAV.DaycareSeedSize; + TB_RNGSeed.Text = ((ulong)seed).ToString("X"+SAV.DaycareSeedSize); + } } // GTS - if (SAV.GTS > -1) + if (SAV.HasGTS) getSlotFiller(SAV.GTS, SlotPictureBoxes[44]); // Fused - if (SAV.Fused > -1) + if (SAV.HasFused) getSlotFiller(SAV.Fused, SlotPictureBoxes[45]); // SUBE - if (SAV.SUBE > -1) + if (SAV.HasSUBE) for (int i = 0; i < 3; i++) { - int offset = SAV.SUBE + i * (PK6.SIZE_STORED + 4); + int offset = SAV.SUBE + i * (SAV.SIZE_STORED + 4); if (BitConverter.ToUInt64(SAV.Data, offset) != 0) getSlotFiller(offset, SlotPictureBoxes[46 + i]); else SlotPictureBoxes[46 + i].Image = null; } // Recoloring of a storage box slot (to not show for other storage boxes) - if (colorizedslot < 32) + if (colorizedslot <= SAV.BoxCount) SlotPictureBoxes[colorizedslot].BackgroundImage = colorizedbox == CB_BoxSelect.SelectedIndex ? colorizedcolor : null; } private void setBoxNames() { - if (SAV.Box < 0) + if (!SAV.HasBox) return; int selectedbox = CB_BoxSelect.SelectedIndex; // precache selected box // Build ComboBox Dropdown Items try { CB_BoxSelect.Items.Clear(); - for (int i = 0; i < 31; i++) + for (int i = 0; i < SAV.BoxCount; i++) CB_BoxSelect.Items.Add(SAV.getBoxName(i)); } catch { CB_BoxSelect.Items.Clear(); - for (int i = 0; i < 31; i++) + for (int i = 0; i < SAV.BoxCount; i++) CB_BoxSelect.Items.Add("BOX " + (i+1)); } - CB_BoxSelect.SelectedIndex = selectedbox; // restore selected box + if (selectedbox < CB_BoxSelect.Items.Count) + CB_BoxSelect.SelectedIndex = selectedbox; // restore selected box } - private void getQuickFiller(PictureBox pb, PK6 pk = null) + private void getQuickFiller(PictureBox pb, PKM pk = null) { if (!fieldsInitialized) return; - pk = pk ?? preparepkx(false); // don't perform control loss click + pk = pk ?? preparePKM(false); // don't perform control loss click if (pb == dragout) mnuLQR.Enabled = pk.Species != 0; // Species pb.Image = pk.Sprite; @@ -3136,14 +3569,14 @@ private void getQuickFiller(PictureBox pb, PK6 pk = null) } private void getSlotFiller(int offset, PictureBox pb) { - if (SAV.getData(offset, PK6.SIZE_STORED).SequenceEqual(new byte[PK6.SIZE_STORED])) + if (SAV.getData(offset, SAV.SIZE_STORED).SequenceEqual(new byte[SAV.SIZE_STORED])) { // 00s present in slot. pb.Image = null; pb.BackColor = Color.Transparent; return; } - PK6 p = SAV.getPK6Stored(offset); + PKM p = SAV.getStoredSlot(offset); if (p.Sanity != 0 || !p.ChecksumValid) // Invalid { // Bad Egg present in slot. @@ -3184,10 +3617,11 @@ private void switchDaycare(object sender, EventArgs e) } private void dumpBoxesToDB(string path, bool individualBoxFolders) { - PK6[] boxdata = SAV.BoxData; + PKM[] boxdata = SAV.BoxData; + if (boxdata == null) { Util.Error("Null argument when dumping boxes."); return; } for (int i = 0; i < boxdata.Length; i++) { - PK6 pk = boxdata[i]; + PKM pk = boxdata[i]; if (pk.Species == 0 || pk.Sanity != 0) continue; string fileName = Util.CleanFileName(pk.FileName); @@ -3198,96 +3632,45 @@ private void dumpBoxesToDB(string path, bool individualBoxFolders) Directory.CreateDirectory(Path.Combine(path, boxfolder)); } if (!File.Exists(Path.Combine(Path.Combine(path, boxfolder), fileName))) - File.WriteAllBytes(Path.Combine(Path.Combine(path, boxfolder), fileName), pk.Data.Take(PK6.SIZE_STORED).ToArray()); + File.WriteAllBytes(Path.Combine(Path.Combine(path, boxfolder), fileName), pk.Data.Take(SAV.SIZE_STORED).ToArray()); } } private void loadBoxesFromDB(string path) { if (string.IsNullOrWhiteSpace(path)) return; - int offset = SAV.Box; - int ctr = CB_BoxSelect.SelectedIndex * 30; - int pastctr = 0; - - // Clear out the box data array. - // Array.Clear(savefile, offset, size * 30 * 31); - DialogResult dr = Util.Prompt(MessageBoxButtons.YesNoCancel, "Clear subsequent boxes when importing data?", "If you only want to overwrite for new data, press no."); - if (dr == DialogResult.Cancel) return; - if (dr == DialogResult.Yes) - { - for (int i = ctr; i < 30 * 31; i++) - SAV.setData(blankEK6, offset + i * PK6.SIZE_STORED); - } + if (!SAV.HasBox) return; - bool? noSetb = getPK6Override(); + DialogResult dr = Util.Prompt(MessageBoxButtons.YesNoCancel, "Clear subsequent boxes when importing data?", "If you only want to overwrite for new data, press no."); + if (dr == DialogResult.Cancel) + return; + if (dr == DialogResult.Yes) + SAV.resetBoxes(CB_BoxSelect.SelectedIndex); + bool? noSetb = getPKMSetOverride(); + + int ctr = CB_BoxSelect.SelectedIndex*30; + int pastctr = 0; string[] filepaths = Directory.GetFiles(path, "*.*", SearchOption.TopDirectoryOnly); - foreach (string t in filepaths) + foreach (byte[] data in from file in filepaths where PKX.getIsPKM(new FileInfo(file).Length) select File.ReadAllBytes(file)) { - long len = new FileInfo(t).Length; - if (len > PK6.SIZE_PARTY) - continue; + string c; + PKM temp = PKMConverter.getPKMfromBytes(data); + PKM pk = PKMConverter.convertToFormat(temp, SAV.Generation, out c); - if (!new[] {PK6.SIZE_STORED, PK6.SIZE_PARTY, PK5.SIZE_STORED, PK5.SIZE_PARTY, PK4.SIZE_PARTY, PK3.SIZE_STORED, PK3.SIZE_PARTY}.Contains((int)len)) - continue; - byte[] data = new byte[PK6.SIZE_STORED]; - switch (Path.GetExtension(t)) // Filter all files by extension + if (pk != null) // Write to save { - case ".pk5": - case ".pk4": - case ".pk3": - case ".3gpkm": - case ".pkm": - { - // Verify PKM (decrypted) - byte[] input = File.ReadAllBytes(t); - if (!PKX.verifychk(input)) continue; - { - try // to convert g5pkm - { data = PKX.encryptArray(Converter.ConvertPKMtoPK6(input).Data); pastctr++; } - catch { continue; } - } - } - break; - case ".pk6": - case ".pkx": - { - byte[] input = File.ReadAllBytes(t); - if ((BitConverter.ToUInt16(input, 0xC8) == 0) && (BitConverter.ToUInt16(input, 0x58) == 0)) - { - if (BitConverter.ToUInt16(input, 0x8) == 0) // if species = 0 - continue; - Array.Resize(ref input, PK6.SIZE_STORED); - - if (PKX.getCHK(input) != BitConverter.ToUInt16(input, 0x6)) continue; - data = PKX.encryptArray(input); - } - } - break; - case ".ek6": - case ".ekx": - { - byte[] input = File.ReadAllBytes(t); - Array.Resize(ref input, PK6.SIZE_STORED); - Array.Copy(input, data, PK6.SIZE_STORED); - // check if it is good data - byte[] decrypteddata = PKX.decryptArray(input); - - if (BitConverter.ToUInt16(decrypteddata, 0xC8) != 0 && BitConverter.ToUInt16(decrypteddata, 0x58) != 0) - continue; - if (BitConverter.ToUInt16(decrypteddata, 0x8) == 0) // if species = 0 - continue; - if (PKX.getCHK(input) != BitConverter.ToUInt16(decrypteddata, 0x6)) continue; - } - break; - default: - continue; + SAV.setStoredSlot(pk, SAV.getBoxOffset(ctr/30) + ctr%30 * SAV.SIZE_STORED, noSetb); + if (pk.Format != temp.Format) // Transferred + pastctr++; + if (++ctr == SAV.BoxCount*30) // Boxes full! + break; } - SAV.setEK6Stored(data, offset + ctr++ * PK6.SIZE_STORED, noSetb); - if (ctr == 30 * 31) break; // break out if we have written all 31 boxes + Console.WriteLine(c); } ctr -= 30*CB_BoxSelect.SelectedIndex; // actual imported count - if (ctr <= 0) return; + if (ctr <= 0) + return; setPKXBoxes(); string result = $"Loaded {ctr} files to boxes."; @@ -3298,34 +3681,44 @@ private void loadBoxesFromDB(string path) } private void B_SaveBoxBin_Click(object sender, EventArgs e) { - DialogResult dr = Util.Prompt(MessageBoxButtons.YesNoCancel, "Yes: Export All Boxes" + Environment.NewLine + string.Format("No: Export {1} (Box {0})", CB_BoxSelect.SelectedIndex + 1, CB_BoxSelect.Text) + Environment.NewLine + "Cancel: Abort"); + if (!SAV.HasBox) + { Util.Alert("Save file does not have boxes to dump!"); return; } + + DialogResult dr = Util.Prompt(MessageBoxButtons.YesNoCancel, + "Yes: Export All Boxes" + Environment.NewLine + + $"No: Export {CB_BoxSelect.Text} (Box {CB_BoxSelect.SelectedIndex + 1})" + Environment.NewLine + + "Cancel: Abort"); if (dr == DialogResult.Yes) { SaveFileDialog sfd = new SaveFileDialog {Filter = "Box Data|*.bin", FileName = "pcdata.bin"}; - if (sfd.ShowDialog() == DialogResult.OK) - File.WriteAllBytes(sfd.FileName, SAV.getData(SAV.Box, PK6.SIZE_STORED * 30 * 31)); + if (sfd.ShowDialog() != DialogResult.OK) + return; + File.WriteAllBytes(sfd.FileName, SAV.getPCBin()); } else if (dr == DialogResult.No) { - SaveFileDialog sfd = new SaveFileDialog {Filter = "Box Data|*.bin", FileName = "boxdata.bin"}; - if (sfd.ShowDialog() == DialogResult.OK) - File.WriteAllBytes(sfd.FileName, SAV.getData(SAV.Box + PK6.SIZE_STORED * 30 * CB_BoxSelect.SelectedIndex, PK6.SIZE_STORED * 30)); + SaveFileDialog sfd = new SaveFileDialog {Filter = "Box Data|*.bin", FileName = $"boxdata {CB_BoxSelect.Text}.bin"}; + if (sfd.ShowDialog() != DialogResult.OK) + return; + File.WriteAllBytes(sfd.FileName, SAV.getBoxBin(CB_BoxSelect.SelectedIndex)); } } - private bool? getPK6Override() + private bool? getPKMSetOverride() { - DialogResult noSet = Util.Prompt(MessageBoxButtons.YesNoCancel, "Loading overrides:", - "Yes - Modify .pk6 when set to SAV" + Environment.NewLine + - "No - Don't modify .pk6" + Environment.NewLine + - "Cancel - Use current settings (" + (Menu_ModifyPK6.Checked ? "Yes" : "No") + ")"); + var yn = Menu_ModifyPK6.Checked ? "Yes" : "No"; + DialogResult noSet = Util.Prompt(MessageBoxButtons.YesNoCancel, + "Loading overrides:", + "Yes - Modify .pk* when set to SAV" + Environment.NewLine + + "No - Don't modify .pk*" + Environment.NewLine + + $"Cancel - Use current settings ({yn})"); return noSet == DialogResult.Yes ? true : (noSet == DialogResult.No ? (bool?)false : null); } // Subfunction Save Buttons // private void B_OpenWondercards_Click(object sender, EventArgs e) { - new SAV_Wondercard().ShowDialog(); + new SAV_Wondercard(sender as MysteryGift).ShowDialog(); } private void B_OpenBoxLayout_Click(object sender, EventArgs e) { @@ -3336,8 +3729,8 @@ private void B_OpenBoxLayout_Click(object sender, EventArgs e) private void B_OpenTrainerInfo_Click(object sender, EventArgs e) { new SAV_Trainer().ShowDialog(); - // Refresh PK#->PK6 conversion info - Converter.updateConfig(SAV.SubRegion, SAV.Country, SAV.ConsoleRegion, SAV.OT, SAV.Gender); + // Refresh conversion info + PKMConverter.updateConfig(SAV.SubRegion, SAV.Country, SAV.ConsoleRegion, SAV.OT, SAV.Gender); } private void B_OpenPokepuffs_Click(object sender, EventArgs e) { @@ -3349,17 +3742,15 @@ private void B_OpenItemPouch_Click(object sender, EventArgs e) } private void B_OpenBerryField_Click(object sender, EventArgs e) { - if (SAV.ORAS) - new SAV_BerryFieldORAS().ShowDialog(); - else if (SAV.XY) - new SAV_BerryFieldXY().ShowDialog(); + new SAV_BerryFieldXY().ShowDialog(); + } + private void B_OpenPokeblocks_Click(object sender, EventArgs e) + { + new SAV_PokeBlockORAS().ShowDialog(); } private void B_OpenEventFlags_Click(object sender, EventArgs e) { - if (SAV.ORAS) - new SAV_EventFlagsORAS().ShowDialog(); - else if (SAV.XY) - new SAV_EventFlagsXY().ShowDialog(); + new SAV_EventFlags().ShowDialog(); } private void B_OpenSuperTraining_Click(object sender, EventArgs e) { @@ -3367,6 +3758,8 @@ private void B_OpenSuperTraining_Click(object sender, EventArgs e) } private void B_OpenOPowers_Click(object sender, EventArgs e) { + if (SAV.Generation != 6) + return; if (SAV.ORAS) { DialogResult dr = Util.Prompt(MessageBoxButtons.YesNo, "No editing support for ORAS :(", "Max O-Powers with a working code?"); @@ -3377,8 +3770,8 @@ private void B_OpenOPowers_Click(object sender, EventArgs e) 0x01, 0x01, 0x01, 0x01, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x00, 0x00, 0x00, - }.CopyTo(SAV.Data, SAV.OPower); + 0x01, 0x00, 0x00, 0x00, + }.CopyTo(SAV.Data, (SAV as SAV6).OPower); } else if (SAV.XY) new SAV_OPower().ShowDialog(); @@ -3392,12 +3785,13 @@ private void B_OpenPokedex_Click(object sender, EventArgs e) } private void B_OUTPasserby_Click(object sender, EventArgs e) { + if (SAV.Generation != 6) + return; if (DialogResult.Yes != Util.Prompt(MessageBoxButtons.YesNo, "Export Passerby Info to Clipboard?")) return; - string result = "PSS List" + Environment.NewLine; string[] headers = { "PSS Data - Friends", "PSS Data - Acquaintances", "PSS Data - Passerby", }; - int offset = SAV.PSS; + int offset = (SAV as SAV6).PSS; for (int g = 0; g < 3; g++) { result += Environment.NewLine @@ -3467,31 +3861,33 @@ private void B_JPEG_Click(object sender, EventArgs e) // Save Folder Related private void clickSaveFileName(object sender, EventArgs e) { - // Get latest SaveDataFiler save location - pathSDF = Util.GetSDFLocation(); - path3DS = Util.get3DSLocation(); - string pathCache = Util.GetCacheFolder(); - string path = null; - - if (path3DS != null && Directory.Exists(Path.Combine(path3DS, "SaveDataBackup")) && ModifierKeys != Keys.Control) - path = Path.Combine(Path.GetPathRoot(path3DS), "SaveDataBackup", "main"); - else if (pathSDF != null && ModifierKeys != Keys.Shift) // if we have a result - path = Path.Combine(pathSDF, "main"); - else if (path3DS != null && Directory.Exists(Path.Combine(Path.GetPathRoot(path3DS), "JKSV", "Saves"))) - path = Directory.GetFiles(Path.Combine(Path.GetPathRoot(path3DS), "JKSV", "Saves"), "main", SearchOption.AllDirectories) - .Where(f => SAV6.SizeValid((int)new FileInfo(f).Length)) // filter - .OrderByDescending(f => new FileInfo(f).LastWriteTime).FirstOrDefault(); - else if (Directory.Exists(pathCache)) - path = Directory.GetFiles(pathCache).Where(f => SAV6.SizeValid((int)new FileInfo(f).Length)) // filter - .OrderByDescending(f => new FileInfo(f).LastWriteTime).FirstOrDefault(); - else if (File.Exists(Util.NormalizePath(Path.Combine(Util.GetTempFolder(), "root", "main")))) - // else if cgse exists - path = Util.NormalizePath(Path.Combine(Util.GetTempFolder(), "root", "main")); - + string path = detectSaveFile(); if (path == null || !File.Exists(path)) return; if (Util.Prompt(MessageBoxButtons.YesNo, "Open save file from the following location?", path) == DialogResult.Yes) openQuick(path); // load save } + private static string detectSaveFile() + { + string pathSDF = Util.GetSDFLocation(); + string path3DS = Util.get3DSLocation(); + string pathCache = Util.GetCacheFolder(); + + if (path3DS != null && Directory.Exists(Path.Combine(path3DS, "SaveDataBackup")) && ModifierKeys != Keys.Control) + return Path.Combine(Path.GetPathRoot(path3DS), "SaveDataBackup", "main"); + if (pathSDF != null && ModifierKeys != Keys.Shift) // if we have a result + return Path.Combine(pathSDF, "main"); + if (path3DS != null && Directory.Exists(Path.Combine(Path.GetPathRoot(path3DS), "JKSV", "Saves"))) + return Directory.GetFiles(Path.Combine(Path.GetPathRoot(path3DS), "JKSV", "Saves"), "main", SearchOption.AllDirectories) + .Where(f => SaveUtil.SizeValidSAV6((int)new FileInfo(f).Length)) // filter + .OrderByDescending(f => new FileInfo(f).LastWriteTime).FirstOrDefault(); + if (Directory.Exists(pathCache)) + return Directory.GetFiles(pathCache).Where(f => SaveUtil.SizeValidSAV6((int)new FileInfo(f).Length)) // filter + .OrderByDescending(f => new FileInfo(f).LastWriteTime).FirstOrDefault(); + if (File.Exists(Util.NormalizePath(Path.Combine(Util.GetTempFolder(), "root", "main")))) // if cgse exists + return Util.NormalizePath(Path.Combine(Util.GetTempFolder(), "root", "main")); + + return null; + } // Drag & Drop within Box private void pbBoxSlot_MouseDown(object sender, MouseEventArgs e) @@ -3509,13 +3905,13 @@ private void pbBoxSlot_MouseDown(object sender, MouseEventArgs e) Cursor.Current = Cursors.Hand; // Prepare Data - pkm_from = SAV.getData(offset, PK6.SIZE_STORED); + pkm_from = SAV.getData(offset, SAV.SIZE_STORED); pkm_from_offset = offset; // Make a new file name based off the PID - byte[] dragdata = PKX.decryptArray(pkm_from); - Array.Resize(ref dragdata, PK6.SIZE_STORED); - var pkx = new PK6(dragdata, "Boxes"); + byte[] dragdata = SAV.decryptPKM(pkm_from); + Array.Resize(ref dragdata, SAV.SIZE_STORED); + PKM pkx = SAV.getPKM(dragdata); string filename = pkx.FileName; // Make File @@ -3543,68 +3939,50 @@ private void pbBoxSlot_DragDrop(object sender, DragEventArgs e) if (files.Length > 0) { FileInfo fi = new FileInfo(files[0]); - - // Detect if PKM/PKX - if (new[] { PK3.SIZE_PARTY, PK3.SIZE_STORED, PK4.SIZE_PARTY, PK4.SIZE_STORED, PK5.SIZE_PARTY }.Contains((int)fi.Length)) - { - byte[] input = File.ReadAllBytes(files[0]); - if (!PKX.verifychk(input)) Util.Alert("Invalid File Loaded.", "Checksum is not valid."); - try // to convert past gen pkm - { - PK6 pk = Converter.ConvertPKMtoPK6(input); - SAV.setPK6Stored(pk, offset); - getQuickFiller(SlotPictureBoxes[slot], pk); - getSlotColor(slot, Properties.Resources.slotSet); - } - catch - { Util.Error("Attempted to load previous generation PKM.", "Conversion failed."); } - } - else if (fi.Length == PK6.SIZE_STORED || fi.Length == PK6.SIZE_PARTY) + if (PKX.getIsPKM(fi.Length)) { byte[] data = File.ReadAllBytes(files[0]); - if (fi.Extension == ".pkx" || fi.Extension == ".pk6") - data = PKX.encryptArray(data); - else if (fi.Extension != ".ekx" && fi.Extension != ".ek6") - { openQuick(files[0]); return; } // lazy way of aborting + PKM temp = PKMConverter.getPKMfromBytes(data); string c; - byte[] decdata = PKX.decryptArray(data); - if (!PKX.verifychk(decdata)) - Util.Alert("Attempted to load Invalid File.", "Checksum is not valid."); - else + PKM pk = PKMConverter.convertToFormat(temp, SAV.Generation, out c); + if (pk != null) { - SAV.setEK6Stored(data, offset); - getQuickFiller(SlotPictureBoxes[slot], new PK6(decdata)); + SAV.setStoredSlot(pk, offset); + getQuickFiller(SlotPictureBoxes[slot], pk); getSlotColor(slot, Properties.Resources.slotSet); + Console.WriteLine(c); + return; } + Console.WriteLine(c); } - else // not PKX/EKX, so load with the general function - { openQuick(files[0]); } + + // Didn't return, so the file wasn't imported. Open as a normal file. + openQuick(files[0]); } } else { if (ModifierKeys == Keys.Alt && slot > -1) // overwrite delete old slot { - // Clear from slot picture - getQuickFiller(SlotPictureBoxes[pkm_from_slot], new PK6()); - - // Clear from slot data - SAV.setEK6Stored(blankEK6, pkm_from_offset); + // Clear from slot + getQuickFiller(SlotPictureBoxes[pkm_from_slot], SAV.BlankPKM); // picturebox + SAV.setStoredSlot(SAV.BlankPKM, pkm_from_offset); // savefile } else if (ModifierKeys != Keys.Control && slot > -1) { // Load data from destination - PK6 pk = SAV.getPK6Stored(offset); + PKM pk = SAV.getStoredSlot(offset); // Swap slot picture getQuickFiller(SlotPictureBoxes[pkm_from_slot], pk); // Swap slot data to source - SAV.setPK6Stored(pk, pkm_from_offset); + SAV.setStoredSlot(pk, pkm_from_offset); } // Copy from temp slot to new. - SAV.setEK6Stored(pkm_from, offset); - getQuickFiller(SlotPictureBoxes[slot], new PK6(PKX.decryptArray(pkm_from))); + SAV.setStoredSlot(pkm_from, offset); + PKM pkz = SAV.getPKM(SAV.decryptPKM(pkm_from)); + getQuickFiller(SlotPictureBoxes[slot], pkz); pkm_from_offset = 0; // Clear offset value } @@ -3618,7 +3996,8 @@ private void pbBoxSlot_DragEnter(object sender, DragEventArgs e) else if (e.Data != null) // within e.Effect = DragDropEffects.Move; } - private byte[] pkm_from = (byte[])blankEK6.Clone(); + + private byte[] pkm_from; private int pkm_from_offset; private int pkm_from_slot = -1; #endregion diff --git a/PKX/f1-Main.resx b/PKX/f1-Main.resx index 64fcc38cd..fc34abff2 100644 --- a/PKX/f1-Main.resx +++ b/PKX/f1-Main.resx @@ -453,168 +453,27 @@ True - - - - iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGPC/xhBQAAAeZJREFUOE+1 - kz1LI1EUhscQ0UzunTszMSoIoiKBLRSxsBHBwkb8aiy2s9TGQjsR/AmysN2CC/4DRUFETMgkZGZEEBQ/ - UgjaZQvDrvhRaDiek3snJqti5YGXufee9zlz5syM9mUxMjJct9Ld1biU6I7gOkx7lfo8yLwVax1IM+sm - y6yiGzX7Vaom3i2KhyEUTxm26wgbPCbAjYqcSleCYFRYbWUE8Ha8ZYbgs9ExuJydA79cxPiubIGPHq1e - HVUq8oW+nua0YV7RnR9OzwBKJTiw4+Ayfp3StEYFc5SOkh3ggmCqKPbs2ArBdNf74xOgODBj5X2Oi2X0 - ECyUX84AFzRl/WdnR5en81syk/6lHXgqFstrKupw8w49CfRSkdcB4qYeFfGY8SuASTcbm/CYz0sYZ5JG - JU17Hb0hhcrAg3CGWb0IPVcX+LP2G/5iFwFM1xwTJV8XfQqVQe14jO9Vw6TjwSE4mpiswMFsfMaTCpXh - cz7+P0zmi4VFuFz9AY5ZDQd5c0rhmubp4rw2KZ+5sJ+E20IBfKupBia5ushT5xpoWgjf8X2QqB5YtrUN - Dts738DSZzzMf0s0lDtwuTnpR40NLyq2M4a14xj2Dl1p778jD727sfg0dvDmS6TvgV7ph39frW84/AKK - SiSLGvswRQAAAABJRU5ErkJggg== - - True - - - iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGPC/xhBQAAAeZJREFUOE+1 - kz1LI1EUhscQ0UzunTszMSoIoiKBLRSxsBHBwkb8aiy2s9TGQjsR/AmysN2CC/4DRUFETMgkZGZEEBQ/ - UgjaZQvDrvhRaDiek3snJqti5YGXufee9zlz5syM9mUxMjJct9Ld1biU6I7gOkx7lfo8yLwVax1IM+sm - y6yiGzX7Vaom3i2KhyEUTxm26wgbPCbAjYqcSleCYFRYbWUE8Ha8ZYbgs9ExuJydA79cxPiubIGPHq1e - HVUq8oW+nua0YV7RnR9OzwBKJTiw4+Ayfp3StEYFc5SOkh3ggmCqKPbs2ArBdNf74xOgODBj5X2Oi2X0 - ECyUX84AFzRl/WdnR5en81syk/6lHXgqFstrKupw8w49CfRSkdcB4qYeFfGY8SuASTcbm/CYz0sYZ5JG - JU17Hb0hhcrAg3CGWb0IPVcX+LP2G/5iFwFM1xwTJV8XfQqVQe14jO9Vw6TjwSE4mpiswMFsfMaTCpXh - cz7+P0zmi4VFuFz9AY5ZDQd5c0rhmubp4rw2KZ+5sJ+E20IBfKupBia5ushT5xpoWgjf8X2QqB5YtrUN - Dts738DSZzzMf0s0lDtwuTnpR40NLyq2M4a14xj2Dl1p778jD727sfg0dvDmS6TvgV7ph39frW84/AKK - SiSLGvswRQAAAABJRU5ErkJggg== - - True - - - iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGPC/xhBQAAAeZJREFUOE+1 - kz1LI1EUhscQ0UzunTszMSoIoiKBLRSxsBHBwkb8aiy2s9TGQjsR/AmysN2CC/4DRUFETMgkZGZEEBQ/ - UgjaZQvDrvhRaDiek3snJqti5YGXufee9zlz5syM9mUxMjJct9Ld1biU6I7gOkx7lfo8yLwVax1IM+sm - y6yiGzX7Vaom3i2KhyEUTxm26wgbPCbAjYqcSleCYFRYbWUE8Ha8ZYbgs9ExuJydA79cxPiubIGPHq1e - HVUq8oW+nua0YV7RnR9OzwBKJTiw4+Ayfp3StEYFc5SOkh3ggmCqKPbs2ArBdNf74xOgODBj5X2Oi2X0 - ECyUX84AFzRl/WdnR5en81syk/6lHXgqFstrKupw8w49CfRSkdcB4qYeFfGY8SuASTcbm/CYz0sYZ5JG - JU17Hb0hhcrAg3CGWb0IPVcX+LP2G/5iFwFM1xwTJV8XfQqVQe14jO9Vw6TjwSE4mpiswMFsfMaTCpXh - cz7+P0zmi4VFuFz9AY5ZDQd5c0rhmubp4rw2KZ+5sJ+E20IBfKupBia5ushT5xpoWgjf8X2QqB5YtrUN - Dts738DSZzzMf0s0lDtwuTnpR40NLyq2M4a14xj2Dl1p778jD727sfg0dvDmS6TvgV7ph39frW84/AKK - SiSLGvswRQAAAABJRU5ErkJggg== - - True - - - iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGPC/xhBQAAAeZJREFUOE+1 - kz1LI1EUhscQ0UzunTszMSoIoiKBLRSxsBHBwkb8aiy2s9TGQjsR/AmysN2CC/4DRUFETMgkZGZEEBQ/ - UgjaZQvDrvhRaDiek3snJqti5YGXufee9zlz5syM9mUxMjJct9Ld1biU6I7gOkx7lfo8yLwVax1IM+sm - y6yiGzX7Vaom3i2KhyEUTxm26wgbPCbAjYqcSleCYFRYbWUE8Ha8ZYbgs9ExuJydA79cxPiubIGPHq1e - HVUq8oW+nua0YV7RnR9OzwBKJTiw4+Ayfp3StEYFc5SOkh3ggmCqKPbs2ArBdNf74xOgODBj5X2Oi2X0 - ECyUX84AFzRl/WdnR5en81syk/6lHXgqFstrKupw8w49CfRSkdcB4qYeFfGY8SuASTcbm/CYz0sYZ5JG - JU17Hb0hhcrAg3CGWb0IPVcX+LP2G/5iFwFM1xwTJV8XfQqVQe14jO9Vw6TjwSE4mpiswMFsfMaTCpXh - cz7+P0zmi4VFuFz9AY5ZDQd5c0rhmubp4rw2KZ+5sJ+E20IBfKupBia5ushT5xpoWgjf8X2QqB5YtrUN - Dts738DSZzzMf0s0lDtwuTnpR40NLyq2M4a14xj2Dl1p778jD727sfg0dvDmS6TvgV7ph39frW84/AKK - SiSLGvswRQAAAABJRU5ErkJggg== - - True - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - True - True - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - True - True True - - True - - - True - True @@ -624,9 +483,6 @@ True - - True - True @@ -636,9 +492,6 @@ True - - True - True @@ -756,6 +609,7 @@ True + iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO @@ -1009,6 +863,101 @@ True + + True + + + + iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGPC/xhBQAAAeZJREFUOE+1 + kz1LI1EUhscQ0UzunTszMSoIoiKBLRSxsBHBwkb8aiy2s9TGQjsR/AmysN2CC/4DRUFETMgkZGZEEBQ/ + UgjaZQvDrvhRaDiek3snJqti5YGXufee9zlz5syM9mUxMjJct9Ld1biU6I7gOkx7lfo8yLwVax1IM+sm + y6yiGzX7Vaom3i2KhyEUTxm26wgbPCbAjYqcSleCYFRYbWUE8Ha8ZYbgs9ExuJydA79cxPiubIGPHq1e + HVUq8oW+nua0YV7RnR9OzwBKJTiw4+Ayfp3StEYFc5SOkh3ggmCqKPbs2ArBdNf74xOgODBj5X2Oi2X0 + ECyUX84AFzRl/WdnR5en81syk/6lHXgqFstrKupw8w49CfRSkdcB4qYeFfGY8SuASTcbm/CYz0sYZ5JG + JU17Hb0hhcrAg3CGWb0IPVcX+LP2G/5iFwFM1xwTJV8XfQqVQe14jO9Vw6TjwSE4mpiswMFsfMaTCpXh + cz7+P0zmi4VFuFz9AY5ZDQd5c0rhmubp4rw2KZ+5sJ+E20IBfKupBia5ushT5xpoWgjf8X2QqB5YtrUN + Dts738DSZzzMf0s0lDtwuTnpR40NLyq2M4a14xj2Dl1p778jD727sfg0dvDmS6TvgV7ph39frW84/AKK + SiSLGvswRQAAAABJRU5ErkJggg== + + + + True + + + + iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGPC/xhBQAAAeZJREFUOE+1 + kz1LI1EUhscQ0UzunTszMSoIoiKBLRSxsBHBwkb8aiy2s9TGQjsR/AmysN2CC/4DRUFETMgkZGZEEBQ/ + UgjaZQvDrvhRaDiek3snJqti5YGXufee9zlz5syM9mUxMjJct9Ld1biU6I7gOkx7lfo8yLwVax1IM+sm + y6yiGzX7Vaom3i2KhyEUTxm26wgbPCbAjYqcSleCYFRYbWUE8Ha8ZYbgs9ExuJydA79cxPiubIGPHq1e + HVUq8oW+nua0YV7RnR9OzwBKJTiw4+Ayfp3StEYFc5SOkh3ggmCqKPbs2ArBdNf74xOgODBj5X2Oi2X0 + ECyUX84AFzRl/WdnR5en81syk/6lHXgqFstrKupw8w49CfRSkdcB4qYeFfGY8SuASTcbm/CYz0sYZ5JG + JU17Hb0hhcrAg3CGWb0IPVcX+LP2G/5iFwFM1xwTJV8XfQqVQe14jO9Vw6TjwSE4mpiswMFsfMaTCpXh + cz7+P0zmi4VFuFz9AY5ZDQd5c0rhmubp4rw2KZ+5sJ+E20IBfKupBia5ushT5xpoWgjf8X2QqB5YtrUN + Dts738DSZzzMf0s0lDtwuTnpR40NLyq2M4a14xj2Dl1p778jD727sfg0dvDmS6TvgV7ph39frW84/AKK + SiSLGvswRQAAAABJRU5ErkJggg== + + + + True + + + + iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGPC/xhBQAAAeZJREFUOE+1 + kz1LI1EUhscQ0UzunTszMSoIoiKBLRSxsBHBwkb8aiy2s9TGQjsR/AmysN2CC/4DRUFETMgkZGZEEBQ/ + UgjaZQvDrvhRaDiek3snJqti5YGXufee9zlz5syM9mUxMjJct9Ld1biU6I7gOkx7lfo8yLwVax1IM+sm + y6yiGzX7Vaom3i2KhyEUTxm26wgbPCbAjYqcSleCYFRYbWUE8Ha8ZYbgs9ExuJydA79cxPiubIGPHq1e + HVUq8oW+nua0YV7RnR9OzwBKJTiw4+Ayfp3StEYFc5SOkh3ggmCqKPbs2ArBdNf74xOgODBj5X2Oi2X0 + ECyUX84AFzRl/WdnR5en81syk/6lHXgqFstrKupw8w49CfRSkdcB4qYeFfGY8SuASTcbm/CYz0sYZ5JG + JU17Hb0hhcrAg3CGWb0IPVcX+LP2G/5iFwFM1xwTJV8XfQqVQe14jO9Vw6TjwSE4mpiswMFsfMaTCpXh + cz7+P0zmi4VFuFz9AY5ZDQd5c0rhmubp4rw2KZ+5sJ+E20IBfKupBia5ushT5xpoWgjf8X2QqB5YtrUN + Dts738DSZzzMf0s0lDtwuTnpR40NLyq2M4a14xj2Dl1p778jD727sfg0dvDmS6TvgV7ph39frW84/AKK + SiSLGvswRQAAAABJRU5ErkJggg== + + + + True + + + + iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGPC/xhBQAAAeZJREFUOE+1 + kz1LI1EUhscQ0UzunTszMSoIoiKBLRSxsBHBwkb8aiy2s9TGQjsR/AmysN2CC/4DRUFETMgkZGZEEBQ/ + UgjaZQvDrvhRaDiek3snJqti5YGXufee9zlz5syM9mUxMjJct9Ld1biU6I7gOkx7lfo8yLwVax1IM+sm + y6yiGzX7Vaom3i2KhyEUTxm26wgbPCbAjYqcSleCYFRYbWUE8Ha8ZYbgs9ExuJydA79cxPiubIGPHq1e + HVUq8oW+nua0YV7RnR9OzwBKJTiw4+Ayfp3StEYFc5SOkh3ggmCqKPbs2ArBdNf74xOgODBj5X2Oi2X0 + ECyUX84AFzRl/WdnR5en81syk/6lHXgqFstrKupw8w49CfRSkdcB4qYeFfGY8SuASTcbm/CYz0sYZ5JG + JU17Hb0hhcrAg3CGWb0IPVcX+LP2G/5iFwFM1xwTJV8XfQqVQe14jO9Vw6TjwSE4mpiswMFsfMaTCpXh + cz7+P0zmi4VFuFz9AY5ZDQd5c0rhmubp4rw2KZ+5sJ+E20IBfKupBia5ushT5xpoWgjf8X2QqB5YtrUN + Dts738DSZzzMf0s0lDtwuTnpR40NLyq2M4a14xj2Dl1p778jD727sfg0dvDmS6TvgV7ph39frW84/AKK + SiSLGvswRQAAAABJRU5ErkJggg== + + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + True @@ -1089,6 +1038,9 @@ True + + True + True @@ -1131,16 +1083,46 @@ True - + True - + True - + True - + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + True @@ -1167,12 +1149,6 @@ True - - True - - - True - True @@ -1182,9 +1158,6 @@ True - - True - True @@ -1194,24 +1167,20 @@ True - - True - - - True - - - True - - - True - - - True - - - True - + + + iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO + wwAADsMBx2+oZAAAAFVJREFUKFNjQAeKioqhUCZuoKSktAqI/wMVd0CFMAFMEQxjVYyuCIZRFCsrK6dh + UwTDQMUuUKVgD8zEpgiIy6FKEACLYkxFMICkGLciGEBxE+mAgQEAw6cxLyPYHYMAAAAASUVORK5CYII= + + + + + iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO + wwAADsMBx2+oZAAAAFVJREFUKFNjQAeKioqhUCZuoKSktAqI/wMVd0CFMAFMEQxjVYyuCIZRFCsrK6dh + UwTDQMUuUKVgD8zEpgiIy6FKEACLYkxFMICkGLciGEBxE+mAgQEAw6cxLyPYHYMAAAAASUVORK5CYII= + + True @@ -1229,6 +1198,38 @@ wwAADsMBx2+oZAAAAGFJREFUKFNjIA/oVggyGJetYjCpUIKKYAEmFS5ARe8YjMv/gzGIjwGMy8vhClBx OVQFEBhXhGJRgISB8nCAVQEUowCjsg6sikDiKADsWywKQeIYwLhsJhCfgWMM04gCDAwAOXZIpY+syQoA AAAASUVORK5CYII= + + + + + iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO + wgAADsIBFShKgAAAABp0RVh0U29mdHdhcmUAUGFpbnQuTkVUIHYzLjUuMTAw9HKhAAAAPklEQVQoU2OA + gf///+PEcKCkpPQOF0ZRDBX8jwW/g6iAApAAmgIaKoS7EUSABNAU4FWIFaMoJAZjFcTE/xkAiduxT7wO + KegAAAAASUVORK5CYII= + + + + + iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO + wgAADsIBFShKgAAAABp0RVh0U29mdHdhcmUAUGFpbnQuTkVUIHYzLjUuMTAw9HKhAAAAPklEQVQoU2OA + gf///+PEcKCkpPQOF0ZRDBX8jwW/g6iAApAAmgIaKoS7EUSABNAU4FWIFaMoJAZjFcTE/xkAiduxT7wO + KegAAAAASUVORK5CYII= + + + + + iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO + wwAADsMBx2+oZAAAAHpJREFUKFNjQAeKioodUCZuAFTkoqSk9B9EQ4UwgZycnCBQwRmowrvKysrGUCkI + AEqUgyRxYaCmmVClEHdhUwTEq6BKEAAouBtZEch6qBQqgLkPGUOlUAFUcreqqqoSyF0gPpBG9T3Ih0Cc + BuWCAUgMqDAUyiUWMDAAALO6MzuvKR9eAAAAAElFTkSuQmCC + + + + + iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO + wwAADsMBx2+oZAAAAHpJREFUKFNjQAeKioodUCZuAFTkoqSk9B9EQ4UwgZycnCBQwRmowrvKysrGUCkI + AEqUgyRxYaCmmVClEHdhUwTEq6BKEAAouBtZEch6qBQqgLkPGUOlUAFUcreqqqoSyF0gPpBG9T3Ih0Cc + BuWCAUgMqDAUyiUWMDAAALO6MzuvKR9eAAAAAElFTkSuQmCC @@ -1248,6 +1249,22 @@ wwAADsMBx2+oZAAAAI1JREFUKFOVUEENwzAMDIViKYVBiPcogFIohXIahUKwK5VAIcSz3ZvqaPvspJMv vpPjpGTodAxadwqaRrtHI16URHvyDPuCPuURxnreoY82DzELkmzRdMwIQrfKL8Ts2spnmO57TbqRCGJp 4g92E23pMYzF9rISdO29vKPDX5gnBe2bYH/jms4jjv+ilDfBD7LrZqlEjQAAAABJRU5ErkJggg== + + + + + iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO + wwAADsMBx2+oZAAAAG5JREFUKFNjQAeKioqhUCZuoKysbKykpPQfREOFsAOgot0ghUBTz0CFMAFQ0gWk + CIZxOgFkCprCu1ApBADpRlYEw0C3pkGVQABQ8B26Iih+B1UCVlSOJomCgbZ1gBWqqqoqgYIDFwbJgxUS + BxgYAGs4NknmoWGpAAAAAElFTkSuQmCC + + + + + iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO + wwAADsMBx2+oZAAAAG5JREFUKFNjQAeKioqhUCZuoKysbKykpPQfREOFsAOgot0ghUBTz0CFMAFQ0gWk + CIZxOgFkCprCu1ApBADpRlYEw0C3pkGVQABQ8B26Iih+B1UCVlSOJomCgbZ1gBWqqqoqgYIDFwbJgxUS + BxgYAGs4NknmoWGpAAAAAElFTkSuQmCC @@ -1269,102 +1286,6 @@ GigXDIB8F3QxIgADAwC7NFU/mWb72QAAAABJRU5ErkJggg== - - True - - - - iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO - wwAADsMBx2+oZAAAAFVJREFUKFNjQAeKioqhUCZuoKSktAqI/wMVd0CFMAFMEQxjVYyuCIZRFCsrK6dh - UwTDQMUuUKVgD8zEpgiIy6FKEACLYkxFMICkGLciGEBxE+mAgQEAw6cxLyPYHYMAAAAASUVORK5CYII= - - - - - iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO - wwAADsMBx2+oZAAAAFVJREFUKFNjQAeKioqhUCZuoKSktAqI/wMVd0CFMAFMEQxjVYyuCIZRFCsrK6dh - UwTDQMUuUKVgD8zEpgiIy6FKEACLYkxFMICkGLciGEBxE+mAgQEAw6cxLyPYHYMAAAAASUVORK5CYII= - - - - True - - - - iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO - wwAADsMBx2+oZAAAAHpJREFUKFNjQAeKioodUCZuAFTkoqSk9B9EQ4UwgZycnCBQwRmowrvKysrGUCkI - AEqUgyRxYaCmmVClEHdhUwTEq6BKEAAouBtZEch6qBQqgLkPGUOlUAFUcreqqqoSyF0gPpBG9T3Ih0Cc - BuWCAUgMqDAUyiUWMDAAALO6MzuvKR9eAAAAAElFTkSuQmCC - - - - - iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO - wwAADsMBx2+oZAAAAHpJREFUKFNjQAeKioodUCZuAFTkoqSk9B9EQ4UwgZycnCBQwRmowrvKysrGUCkI - AEqUgyRxYaCmmVClEHdhUwTEq6BKEAAouBtZEch6qBQqgLkPGUOlUAFUcreqqqoSyF0gPpBG9T3Ih0Cc - BuWCAUgMqDAUyiUWMDAAALO6MzuvKR9eAAAAAElFTkSuQmCC - - - - True - - - - iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO - wwAADsMBx2+oZAAAAHBJREFUKFNjgAFlZWVjOTk5QRAbRCsqKrrA+GCgqqqqBATvgPg/iEbnwxUDOeVQ - QTAGmnQGmQ+0KQ2sECjRgSyBjkHyYIUgt2FTAMMgebBCEAA5HJsioHgoVAkCgASRFcHdhg2AJAkqggEU - N5EOGBgAEVY/pv9ltCoAAAAASUVORK5CYII= - - - - - iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO - wwAADsMBx2+oZAAAAHBJREFUKFNjgAFlZWVjOTk5QRAbRCsqKrrA+GCgqqqqBATvgPg/iEbnwxUDOeVQ - QTAGmnQGmQ+0KQ2sECjRgSyBjkHyYIUgt2FTAMMgebBCEAA5HJsioHgoVAkCgASRFcHdhg2AJAkqggEU - N5EOGBgAEVY/pv9ltCoAAAAASUVORK5CYII= - - - - True - - - - iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO - wgAADsIBFShKgAAAABp0RVh0U29mdHdhcmUAUGFpbnQuTkVUIHYzLjUuMTAw9HKhAAAAPklEQVQoU2OA - gf///+PEcKCkpPQOF0ZRDBX8jwW/g6iAApAAmgIaKoS7EUSABNAU4FWIFaMoJAZjFcTE/xkAiduxT7wO - KegAAAAASUVORK5CYII= - - - - - iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO - wgAADsIBFShKgAAAABp0RVh0U29mdHdhcmUAUGFpbnQuTkVUIHYzLjUuMTAw9HKhAAAAPklEQVQoU2OA - gf///+PEcKCkpPQOF0ZRDBX8jwW/g6iAApAAmgIaKoS7EUSABNAU4FWIFaMoJAZjFcTE/xkAiduxT7wO - KegAAAAASUVORK5CYII= - - - - True - - - - iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO - wwAADsMBx2+oZAAAAG5JREFUKFNjQAeKioqhUCZuoKysbKykpPQfREOFsAOgot0ghUBTz0CFMAFQ0gWk - CIZxOgFkCprCu1ApBADpRlYEw0C3pkGVQABQ8B26Iih+B1UCVlSOJomCgbZ1gBWqqqoqgYIDFwbJgxUS - BxgYAGs4NknmoWGpAAAAAElFTkSuQmCC - - - - - iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO - wwAADsMBx2+oZAAAAG5JREFUKFNjQAeKioqhUCZuoKysbKykpPQfREOFsAOgot0ghUBTz0CFMAFQ0gWk - CIZxOgFkCprCu1ApBADpRlYEw0C3pkGVQABQ8B26Iih+B1UCVlSOJomCgbZ1gBWqqqoqgYIDFwbJgxUS - BxgYAGs4NknmoWGpAAAAAElFTkSuQmCC - - - - True - iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO @@ -1379,6 +1300,22 @@ wwAADsMBx2+oZAAAAGxJREFUKFNjQAbKysrGQJwGoqFCqEBVVVVJUVHxjJKS0n8YBvHl5OQEoUogAF0R smKoErAiF2yKYBjuDJCbsCmAYaBBoTCFxtgUwDCKx3C5EYh3Q5VAAMh3IEF0RRi+hgFoMLmAaKgQqYCB AQDOs0aM0tfjRAAAAABJRU5ErkJggg== + + + + + iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO + wwAADsMBx2+oZAAAAHBJREFUKFNjgAFlZWVjOTk5QRAbRCsqKrrA+GCgqqqqBATvgPg/iEbnwxUDOeVQ + QTAGmnQGmQ+0KQ2sECjRgSyBjkHyYIUgt2FTAMMgebBCEAA5HJsioHgoVAkCgASRFcHdhg2AJAkqggEU + N5EOGBgAEVY/pv9ltCoAAAAASUVORK5CYII= + + + + + iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO + wwAADsMBx2+oZAAAAHBJREFUKFNjgAFlZWVjOTk5QRAbRCsqKrrA+GCgqqqqBATvgPg/iEbnwxUDOeVQ + QTAGmnQGmQ+0KQ2sECjRgSyBjkHyYIUgt2FTAMMgebBCEAA5HJsioHgoVAkCgASRFcHdhg2AJAkqggEU + N5EOGBgAEVY/pv9ltCoAAAAASUVORK5CYII= @@ -1444,9 +1381,6 @@ True - - True - 17, 17 @@ -1903,9 +1837,6 @@ True - - True - True @@ -1921,9 +1852,6 @@ True - - True - True @@ -2077,48 +2005,99 @@ True - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - True - True - + + True + + + True + + + True + + + True + + + True + + + True + + + True + + True True + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + True diff --git a/PKX/f3-MemoryAmie.cs b/PKX/f3-MemoryAmie.cs index 2c24c0775..f77c648a9 100644 --- a/PKX/f3-MemoryAmie.cs +++ b/PKX/f3-MemoryAmie.cs @@ -10,6 +10,7 @@ public partial class MemoryAmie : Form public MemoryAmie() // Keeping the form reference as a lot of control elements are required to operate. { InitializeComponent(); + pk6 = Main.pkm as PK6; cba = new[] { CB_Country0, CB_Country1, CB_Country2, CB_Country3, CB_Country4 }; mta = new[] { CB_Region0, CB_Region1, CB_Region2, CB_Region3, CB_Region4, }; CB_Country0.DisplayMember = CB_Country1.DisplayMember = CB_Country2.DisplayMember = CB_Country3.DisplayMember = CB_Country4.DisplayMember = "Text"; @@ -38,70 +39,69 @@ public partial class MemoryAmie : Form getLangStrings(); loadFields(); } - public string[] feeling; - public string[] quality; - bool init; + private bool init; private readonly ComboBox[] cba; private readonly ComboBox[] mta; + private readonly PK6 pk6; // Load/Save Actions private void loadFields() { // Load the region/country values. - CB_Country0.SelectedValue = Main.pk6.Geo1_Country; - CB_Country1.SelectedValue = Main.pk6.Geo2_Country; - CB_Country2.SelectedValue = Main.pk6.Geo3_Country; - CB_Country3.SelectedValue = Main.pk6.Geo4_Country; - CB_Country4.SelectedValue = Main.pk6.Geo5_Country; - CB_Region0.SelectedValue = Main.pk6.Geo1_Region; - CB_Region1.SelectedValue = Main.pk6.Geo2_Region; - CB_Region2.SelectedValue = Main.pk6.Geo3_Region; - CB_Region3.SelectedValue = Main.pk6.Geo4_Region; - CB_Region4.SelectedValue = Main.pk6.Geo5_Region; + CB_Country0.SelectedValue = pk6.Geo1_Country; + CB_Country1.SelectedValue = pk6.Geo2_Country; + CB_Country2.SelectedValue = pk6.Geo3_Country; + CB_Country3.SelectedValue = pk6.Geo4_Country; + CB_Country4.SelectedValue = pk6.Geo5_Country; + CB_Region0.SelectedValue = pk6.Geo1_Region; + CB_Region1.SelectedValue = pk6.Geo2_Region; + CB_Region2.SelectedValue = pk6.Geo3_Region; + CB_Region3.SelectedValue = pk6.Geo4_Region; + CB_Region4.SelectedValue = pk6.Geo5_Region; // Load the Fullness, and Enjoyment - M_Fullness.Text = Main.pk6.Fullness.ToString(); - M_Enjoyment.Text = Main.pk6.Enjoyment.ToString(); + M_Fullness.Text = pk6.Fullness.ToString(); + M_Enjoyment.Text = pk6.Enjoyment.ToString(); // Load the CT Memories - M_CT_Friendship.Text = Main.pk6.HT_Friendship.ToString(); - M_CT_Affection.Text = Main.pk6.HT_Affection.ToString(); - CB_CTQual.SelectedIndex = Math.Max(0, Main.pk6.HT_Intensity - 1); - CB_CTMemory.SelectedValue = Main.pk6.HT_Memory; - CB_CTVar.SelectedValue = Main.pk6.HT_TextVar; - CB_CTFeel.SelectedIndex = Main.pk6.HT_Feeling; + M_CT_Friendship.Text = pk6.HT_Friendship.ToString(); + M_CT_Affection.Text = pk6.HT_Affection.ToString(); + CB_CTQual.SelectedIndex = Math.Max(0, pk6.HT_Intensity - 1); + CB_CTMemory.SelectedValue = pk6.HT_Memory; + CB_CTVar.SelectedValue = pk6.HT_TextVar; + CB_CTFeel.SelectedIndex = pk6.HT_Feeling; // Load the OT Memories - M_OT_Friendship.Text = Main.pk6.OT_Friendship.ToString(); - M_OT_Affection.Text = Main.pk6.OT_Affection.ToString(); - CB_OTQual.SelectedIndex = Math.Max(0, Main.pk6.OT_Intensity - 1); - CB_OTMemory.SelectedValue = Main.pk6.OT_Memory; - CB_OTVar.SelectedValue = Main.pk6.OT_TextVar; - CB_OTFeel.SelectedIndex = Main.pk6.OT_Feeling; + M_OT_Friendship.Text = pk6.OT_Friendship.ToString(); + M_OT_Affection.Text = pk6.OT_Affection.ToString(); + CB_OTQual.SelectedIndex = Math.Max(0, pk6.OT_Intensity - 1); + CB_OTMemory.SelectedValue = pk6.OT_Memory; + CB_OTVar.SelectedValue = pk6.OT_TextVar; + CB_OTFeel.SelectedIndex = pk6.OT_Feeling; CB_Handler.Items.Clear(); - CB_Handler.Items.AddRange(new object[] {$"{Main.pk6.OT_Name} ({args[2]})"}); // OTNAME : OT + CB_Handler.Items.AddRange(new object[] {$"{pk6.OT_Name} ({args[2]})"}); // OTNAME : OT - if (Util.TrimFromZero(Main.pk6.HT_Name) != "") - CB_Handler.Items.AddRange(new object[] { Main.pk6.HT_Name }); + if (Util.TrimFromZero(pk6.HT_Name) != "") + CB_Handler.Items.AddRange(new object[] { pk6.HT_Name }); else - Main.pk6.CurrentHandler = 0; + pk6.CurrentHandler = 0; - tabControl1.SelectedIndex = CB_Handler.SelectedIndex = Main.pk6.CurrentHandler; + tabControl1.SelectedIndex = CB_Handler.SelectedIndex = pk6.CurrentHandler; GB_M_OT.Enabled = GB_M_CT.Enabled = GB_Residence.Enabled = BTN_Save.Enabled = M_Fullness.Enabled = M_Enjoyment.Enabled = - L_Fullness.Enabled = L_Enjoyment.Enabled = !Main.pk6.IsEgg; + L_Fullness.Enabled = L_Enjoyment.Enabled = !pk6.IsEgg; - if (!Main.pk6.IsEgg) + if (!pk6.IsEgg) { bool enable; - if (!Main.pk6.Gen6) + if (!pk6.Gen6) { // Previous Generation Mon - GB_M_OT.Text = $"{args[3]} {Main.pk6.OT_Name}: {args[2]}"; // Past Gen OT : OTNAME - GB_M_CT.Text = $"{args[4]} {Main.pk6.HT_Name}"; // Memories with : HTNAME + GB_M_OT.Text = $"{args[3]} {pk6.OT_Name}: {args[2]}"; // Past Gen OT : OTNAME + GB_M_CT.Text = $"{args[4]} {pk6.HT_Name}"; // Memories with : HTNAME enable = false; // Reset to no memory M_OT_Affection.Text = "0"; @@ -111,9 +111,9 @@ private void loadFields() else { enable = true; - GB_M_OT.Text = $"{args[4]} {Main.pk6.OT_Name} ({args[2]})"; // Memories with : OTNAME - GB_M_CT.Text = $"{args[4]} {Main.pk6.HT_Name}"; // Memories with : HTNAME - if (Main.pk6.HT_Name == "") + GB_M_OT.Text = $"{args[4]} {pk6.OT_Name} ({args[2]})"; // Memories with : OTNAME + GB_M_CT.Text = $"{args[4]} {pk6.HT_Name}"; // Memories with : HTNAME + if (pk6.HT_Name == "") { CB_Country1.Enabled = CB_Country2.Enabled = CB_Country3.Enabled = CB_Country4.Enabled = CB_Region1.Enabled = CB_Region2.Enabled = CB_Region3.Enabled = CB_Region4.Enabled = @@ -121,7 +121,7 @@ private void loadFields() GB_M_CT.Text = $"{args[1]} {args[2]} - {args[0]}"; // Never Left : OT : Disabled } else - GB_M_CT.Text = args[4] + " " + Main.pk6.HT_Name; + GB_M_CT.Text = args[4] + " " + pk6.HT_Name; } RTB_OT.Visible = CB_OTQual.Enabled = CB_OTMemory.Enabled = CB_OTFeel.Enabled = CB_OTVar.Enabled = M_OT_Affection.Enabled = enable; } @@ -131,41 +131,43 @@ private void loadFields() init = true; // Manually load the Memory Parse - RTB_CT.Text = getMemoryString(CB_CTMemory, CB_CTVar, CB_CTQual, CB_CTFeel, Main.pk6.HT_Name); - RTB_OT.Text = getMemoryString(CB_OTMemory, CB_OTVar, CB_OTQual, CB_OTFeel, Main.pk6.OT_Name); + RTB_CT.Text = getMemoryString(CB_CTMemory, CB_CTVar, CB_CTQual, CB_CTFeel, pk6.HT_Name); + RTB_OT.Text = getMemoryString(CB_OTMemory, CB_OTVar, CB_OTQual, CB_OTFeel, pk6.OT_Name); } private void saveFields() { // Save Region & Country Data - Main.pk6.Geo1_Region = Util.getIndex(CB_Region0); - Main.pk6.Geo2_Region = Util.getIndex(CB_Region1); - Main.pk6.Geo3_Region = Util.getIndex(CB_Region2); - Main.pk6.Geo4_Region = Util.getIndex(CB_Region3); - Main.pk6.Geo5_Region = Util.getIndex(CB_Region4); - Main.pk6.Geo1_Country = Util.getIndex(CB_Country0); - Main.pk6.Geo2_Country = Util.getIndex(CB_Country1); - Main.pk6.Geo3_Country = Util.getIndex(CB_Country2); - Main.pk6.Geo4_Country = Util.getIndex(CB_Country3); - Main.pk6.Geo5_Country = Util.getIndex(CB_Country4); + pk6.Geo1_Region = Util.getIndex(CB_Region0); + pk6.Geo2_Region = Util.getIndex(CB_Region1); + pk6.Geo3_Region = Util.getIndex(CB_Region2); + pk6.Geo4_Region = Util.getIndex(CB_Region3); + pk6.Geo5_Region = Util.getIndex(CB_Region4); + pk6.Geo1_Country = Util.getIndex(CB_Country0); + pk6.Geo2_Country = Util.getIndex(CB_Country1); + pk6.Geo3_Country = Util.getIndex(CB_Country2); + pk6.Geo4_Country = Util.getIndex(CB_Country3); + pk6.Geo5_Country = Util.getIndex(CB_Country4); // Save 0-255 stats - Main.pk6.HT_Friendship = Util.ToInt32(M_CT_Friendship.Text); - Main.pk6.HT_Affection = Util.ToInt32(M_CT_Affection.Text); - Main.pk6.OT_Friendship = Util.ToInt32(M_OT_Friendship.Text); - Main.pk6.OT_Affection = Util.ToInt32(M_OT_Affection.Text); - Main.pk6.Fullness = (byte)Util.ToInt32(M_Fullness.Text); - Main.pk6.Enjoyment = (byte)Util.ToInt32(M_Enjoyment.Text); + pk6.HT_Friendship = Util.ToInt32(M_CT_Friendship.Text); + pk6.HT_Affection = Util.ToInt32(M_CT_Affection.Text); + pk6.OT_Friendship = Util.ToInt32(M_OT_Friendship.Text); + pk6.OT_Affection = Util.ToInt32(M_OT_Affection.Text); + pk6.Fullness = (byte)Util.ToInt32(M_Fullness.Text); + pk6.Enjoyment = (byte)Util.ToInt32(M_Enjoyment.Text); // Save Memories - Main.pk6.HT_Memory = Util.getIndex(CB_CTMemory); - Main.pk6.HT_TextVar = CB_CTVar.Enabled ? Util.getIndex(CB_CTVar) : 0; - Main.pk6.HT_Intensity = CB_CTFeel.Enabled ? CB_CTQual.SelectedIndex + 1 : 0; - Main.pk6.HT_Feeling = CB_CTFeel.Enabled ? CB_CTFeel.SelectedIndex : 0; + pk6.HT_Memory = Util.getIndex(CB_CTMemory); + pk6.HT_TextVar = CB_CTVar.Enabled ? Util.getIndex(CB_CTVar) : 0; + pk6.HT_Intensity = CB_CTFeel.Enabled ? CB_CTQual.SelectedIndex + 1 : 0; + pk6.HT_Feeling = CB_CTFeel.Enabled ? CB_CTFeel.SelectedIndex : 0; - Main.pk6.OT_Memory = Util.getIndex(CB_OTMemory); - Main.pk6.OT_TextVar = CB_OTVar.Enabled ? Util.getIndex(CB_OTVar) : 0; - Main.pk6.OT_Intensity = CB_OTFeel.Enabled ? CB_OTQual.SelectedIndex + 1 : 0; - Main.pk6.OT_Feeling = CB_OTFeel.Enabled ? CB_OTFeel.SelectedIndex : 0; + pk6.OT_Memory = Util.getIndex(CB_OTMemory); + pk6.OT_TextVar = CB_OTVar.Enabled ? Util.getIndex(CB_OTVar) : 0; + pk6.OT_Intensity = CB_OTFeel.Enabled ? CB_OTQual.SelectedIndex + 1 : 0; + pk6.OT_Feeling = CB_OTFeel.Enabled ? CB_OTFeel.SelectedIndex : 0; + + Main.pkm = pk6; } // Event Actions @@ -300,7 +302,7 @@ private void getMemoryArguments(string ARG, ComboBox sender) private string getMemoryString(ComboBox m, ComboBox arg, ComboBox q, ComboBox f, string tr) { string result; - string nn = Main.pk6.Nickname; + string nn = pk6.Nickname; string a = (Util.cbItem)arg.SelectedItem == null ? arg.Text ?? "ERROR" : ((Util.cbItem)arg.SelectedItem).Text; int mem = Util.getIndex(m); @@ -403,8 +405,8 @@ private void changeMemory(object sender, EventArgs e) } if (!init) return; - RTB_OT.Text = getMemoryString(CB_OTMemory, CB_OTVar, CB_OTQual, CB_OTFeel, Main.pk6.OT_Name); - RTB_CT.Text = getMemoryString(CB_CTMemory, CB_CTVar, CB_CTQual, CB_CTFeel, Main.pk6.HT_Name); + RTB_OT.Text = getMemoryString(CB_OTMemory, CB_OTVar, CB_OTQual, CB_OTFeel, pk6.OT_Name); + RTB_CT.Text = getMemoryString(CB_CTMemory, CB_CTVar, CB_CTQual, CB_CTFeel, pk6.HT_Name); } private void changeCountryIndex(object sender, EventArgs e) { diff --git a/PKX/f4-RibbMedal.cs b/PKX/f4-RibbMedal.cs index 6fc19ac44..318880dc2 100644 --- a/PKX/f4-RibbMedal.cs +++ b/PKX/f4-RibbMedal.cs @@ -14,7 +14,7 @@ public partial class RibbMedal : Form public RibbMedal() { InitializeComponent(); - pk6 = Main.pk6; // cache copy + pk6 = Main.pkm as PK6; // cache copy pba = new[] { PB_10, PB_11, PB_12, PB_13, PB_14, PB_15, PB_16, PB_17, @@ -283,7 +283,7 @@ private void buttonFlag(bool b) foreach (var chk in cba.Skip(32)) chk.Checked = b; - if (Main.pk6.Version >= 0x10) return; // No Memory Ribbons for Pokémon from Generation 4+ + if (Main.pkm.Version >= 0x10) return; // No Memory Ribbons for Pokémon from Generation 4+ TB_PastContest.Text = (b ? 40 : 0).ToString(); TB_PastBattle.Text = (b ? 8 : 0).ToString(); } @@ -316,7 +316,7 @@ private void buttonFlag(bool b) private void B_Save_Click(object sender, EventArgs e) { setData(); - Main.pk6 = pk6; // set back + Main.pkm = pk6; // set back Close(); } private void B_Cancel_Click(object sender, EventArgs e) diff --git a/Properties/Resources.Designer.cs b/Properties/Resources.Designer.cs index b520a3b5c..c721cb8b3 100644 --- a/Properties/Resources.Designer.cs +++ b/Properties/Resources.Designer.cs @@ -9070,6 +9070,16 @@ internal class Resources { } } + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap about { + get { + object obj = ResourceManager.GetObject("about", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + /// /// Looks up a localized resource of type System.Drawing.Bitmap. /// @@ -9260,6 +9270,16 @@ internal class Resources { } } + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap bak { + get { + object obj = ResourceManager.GetObject("bak", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + /// /// Looks up a localized resource of type System.Drawing.Bitmap. /// @@ -9739,6 +9759,18 @@ internal class Resources { } } + /// + /// Looks up a localized string similar to 60 Ash + ///21 Test1 + ///22 Test2 + ///24 Test3. + /// + internal static string const_oras { + get { + return ResourceManager.GetString("const_oras", resourceCulture); + } + } + /// /// Looks up a localized resource of type System.Drawing.Bitmap. /// @@ -9786,6 +9818,26 @@ internal class Resources { } } + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap data { + get { + object obj = ResourceManager.GetObject("data", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap database { + get { + object obj = ResourceManager.GetObject("database", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + /// /// Looks up a localized resource of type System.Drawing.Bitmap. /// @@ -9796,6 +9848,16 @@ internal class Resources { } } + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap dump { + get { + object obj = ResourceManager.GetObject("dump", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + /// /// Looks up a localized resource of type System.Drawing.Bitmap. /// @@ -9906,6 +9968,16 @@ internal class Resources { } } + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap exit { + get { + object obj = ResourceManager.GetObject("exit", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + /// /// Looks up a localized resource of type System.Drawing.Bitmap. /// @@ -9916,6 +9988,81 @@ internal class Resources { } } + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap export { + get { + object obj = ResourceManager.GetObject("export", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized string similar to 0648 (OR) Groudon Defeated + ///2839 (OR) Groudon Captured + ///0647 (AS) Kyogre Defeated + ///2840 (AS) Kyogre Captured + ///0208 (OR) Ho-Oh Defeated + ///2815 (OR) Ho-Oh Captured + ///0209 (AS) Lugia Defeated + ///2814 (AS) Lugia Captured + ///2819 (AS) Dialga Captured + ///2820 (OR) Palkia Captured + ///2828 (OR) Tornadus Captured + ///2829 (AS) Thundurus Captured + ///2832 Landorus Captured + ///0182 (OR) Reshiram Defeated + ///2830 (OR) Reshiram Captured + ///0183 (AS) Zekrom Defeated + ///2831 (AS) Zekrom Captured + ///0419 (OR) Latias Defeated + ///2834 (OR) Latias Captured + ///0420 (AS) Lati [rest of string was truncated]";. + /// + internal static string flags_oras { + get { + return ResourceManager.GetString("flags_oras", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to 2237 2237 + ///2238 2238 + ///2239 2239 + ///0963 Mewtwo Defeated + ///0115 Mewtwo Captured + ///0114 Zygarde Captured + ///0790 Zygarde Defeated + ///0285 Singles Statuette + ///0286 Doubles Statuette + ///0287 Triples Statuette + ///0288 Rotation Statuette + ///0289 Multi Statuette + ///0290 Super Singles Unlocked + ///0291 Super Doubles Unlocked + ///0292 Super Triples Unlocked + ///0293 Super Rotation Unlocked + ///0294 Super Multi Unlocked + ///0675 50: Beat Chatelaine + ///2546 Pokédex Obtained. + /// + internal static string flags_xy { + get { + return ResourceManager.GetString("flags_xy", resourceCulture); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap folder { + get { + object obj = ResourceManager.GetObject("folder", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + /// /// Looks up a localized resource of type System.Drawing.Bitmap. /// @@ -9976,6 +10123,16 @@ internal class Resources { } } + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap import { + get { + object obj = ResourceManager.GetObject("import", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + /// /// Looks up a localized resource of type System.Drawing.Bitmap. /// @@ -14323,6 +14480,16 @@ internal class Resources { } } + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap language { + get { + object obj = ResourceManager.GetObject("language", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + /// /// Looks up a localized string similar to ID,Language ///1,JPN (日本語) @@ -14349,6 +14516,16 @@ internal class Resources { } } + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap load { + get { + object obj = ResourceManager.GetObject("load", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + /// /// Looks up a localized resource of type System.Drawing.Bitmap. /// @@ -14379,6 +14556,16 @@ internal class Resources { } } + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap main { + get { + object obj = ResourceManager.GetObject("main", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + /// /// Looks up a localized resource of type System.Drawing.Bitmap. /// @@ -14399,6 +14586,36 @@ internal class Resources { } } + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap nocheck { + get { + object obj = ResourceManager.GetObject("nocheck", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap open { + get { + object obj = ResourceManager.GetObject("open", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap other { + get { + object obj = ResourceManager.GetObject("other", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + /// /// Looks up a localized resource of type System.Drawing.Bitmap. /// @@ -14504,6 +14721,16 @@ internal class Resources { } } + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap report { + get { + object obj = ResourceManager.GetObject("report", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + /// /// Looks up a localized resource of type System.Drawing.Bitmap. /// @@ -14584,6 +14811,36 @@ internal class Resources { } } + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap savePKM { + get { + object obj = ResourceManager.GetObject("savePKM", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap saveSAV { + get { + object obj = ResourceManager.GetObject("saveSAV", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap settings { + get { + object obj = ResourceManager.GetObject("settings", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + /// /// Looks up a localized resource of type System.Drawing.Bitmap. /// @@ -14624,6 +14881,16 @@ internal class Resources { } } + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap showdown { + get { + object obj = ResourceManager.GetObject("showdown", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + /// /// Looks up a localized resource of type System.Drawing.Bitmap. /// @@ -17379,7 +17646,7 @@ internal class Resources { /// Looks up a localized string similar to ---------- ///谜的地点 ///遥远的地点 - ///\xf000Ā\x0001\x0000の\xf000ą\x0001\x0001 + ///\xf000Ā\x0001\x0000的\xf000ą\x0001\x0001 ///鹿子镇 ///唐草镇 ///三曜市 @@ -18668,19 +18935,19 @@ internal class Resources { } /// - /// Looks up a localized string similar to None - ///Rock Smash (HGSS) - ///Tall Grass + /// Looks up a localized string similar to æ—  + ///碎岩 (HGSS) + ///高草丛 /// - ///Dialga/Palkia - ///Cave/Hall of Origin + ///帝牙卢卡/帕路奇犽 + ///æ´žç©´/初始之间 /// - ///Surfing/Fishing + ///冲浪/é’“é±¼ /// - ///Building/Enigma Stone - ///Marsh/Safari + ///博物馆/神秘水晶 + ///大湿地/狩猎 /// - ///Starter/Fossil/Gift (DP) + ///御三家/化石/礼物 (DP) /// /// /// @@ -18691,8 +18958,8 @@ internal class Resources { /// /// /// - ///Distortion World (Pt) - ///Starter/Fossil/Gift (Pt/DP Trio). + ///破格的世界(Pt) + ///御三家/化石/礼物 (Pt/DP Trio). /// internal static string text_encountertype_zh { get { @@ -20741,7 +21008,7 @@ internal class Resources { /// /// /// - ///あるすがた + ///字母形态 /// /// /// @@ -20793,7 +21060,8 @@ internal class Resources { /// /// /// - /// /// [rest of string was truncated]";. + /// + /// [rest of string was truncated]";. /// internal static string text_forms_zh { get { @@ -21080,8 +21348,8 @@ internal class Resources { ///黑2 ///X ///Y - ///AS - ///OR + ///始源蓝宝石 + ///终极红宝石 ///. /// internal static string text_games_zh { @@ -21419,70 +21687,77 @@ internal class Resources { } /// - /// Looks up a localized string similar to どこか - ///さいしょのまち - ///うち - ///ともだちのいえ - ///ひとのうち - ///にぎやかなまち - ///ブティック - ///ショップ - ///そぼくなまち - ///ポケモンセンター - ///おしろ - ///ホテル - ///ふしぎなふんいきのまち - ///かぜのふくまち - ///ゲート - ///かわべりのまち - ///けんきゅうじょ - ///すいぞくかん - ///がけにあるまち - ///はなやかなまち - ///ポケモンジム - ///がっこう - ///きょだいなまち - ///ビル - ///オシャレなカフェ - ///アジト - ///びじゅつかん - ///スタジオ - ///えき - ///たたかいのば - ///びようしつ - ///レストラン - ///こうきゅうレストラン - ///うみべのまち - ///たかいたてもののなか - ///ふしぎなふんいきのまち - ///かわぞいのまち - ///ゆきのふりつもるまち - ///ポケモンリーグ - ///きゅうでん - ///どうくつ - ///もり - ///がいろじゅのつづくみち - ///かわぞいのみち - ///のどかなみち - ///はなさくみち - ///そだてや - ///けわしいやまみち - ///いしのたちならぶばしょ - ///うみのみえるみち - ///ぬかるんだみち - ///すなのふきあれるみち - ///おちばみち - ///ゆきみち - ///こうじょう - ///チャンピオンロード - ///ゆきやま - ///はつでんしょ - ///はたけ - ///はいきょ - ///すいどう - ///サファリ - ///ひみつきち - ///コンテストライブかい [rest of string was truncated]";. + /// Looks up a localized string similar to 某处 + ///第一个城镇 + ///家 + ///朋友的家 + ///别人的房子 + ///热闹的小镇 + ///精品屋 + ///商店 + ///普通小镇 + ///精灵中心 + ///城堡 + ///酒店 + ///雾气的小镇 + ///微风吹过的小镇 + ///门 + ///河边小镇 + ///实验室 + ///水族馆 + ///悬崖上的小镇 + ///华丽的城市 + ///精灵健身房 + ///学校 + ///大城市 + ///建筑 + ///时尚咖啡厅 + ///藏身处 + ///博物馆 + ///工作室 + ///车站 + ///战场 + ///美容院 + ///餐厅 + ///高档餐厅 + ///海滨城市 + ///高大建筑物内 + ///神秘气息的城市 + ///河畔城市 + ///白雪皑皑的城市 + ///精灵联赛 + ///宫殿 + ///山洞 + ///森林 + ///绿树成荫的道路 + ///滨江路 + ///宁静的道路 + ///盛开的道路 + ///饲育屋 + ///崎岖山路 + ///满是石头的路 + ///海边道路 + ///泥泞的路 + ///沙子路 + ///落叶路 + ///雪扫路 + ///工厂 + ///冠军之路 + ///雪山 + ///发电厂 + ///田地 + ///废墟 + ///水路 + ///野生动物园 + ///秘密基地 + ///华丽大赛会场 + ///海洋深处 + ///幻之位置 + ///大船 + ///火山小径 + ///小岛 + ///神秘的地方 + ///天空. /// internal static string text_genloc_zh { get { @@ -21889,7 +22164,7 @@ internal class Resources { } /// - /// Looks up a localized string similar to ---- + /// Looks up a localized string similar to 迷之地方 ///双叶镇 ///真砂镇 ///苑之镇 @@ -23427,45 +23702,50 @@ internal class Resources { /// /// Looks up a localized string similar to /// - ///おもいで らしいわ - ///おもいで らしいわ - ///おもいで らしいわ - ///おもいで らしいわ - ///きおくにのこる おもいで らしいわ - ///かんがいぶかい おもいで だって - ///さいこうの おもいで だって! + ///神奇宝贝记得 + ///神奇宝贝记得 + ///神奇宝贝记得 + ///神奇宝贝记得 + ///神奇宝贝清晰得记得 + ///神奇宝贝肯定得记得 + ///神奇宝贝美美得记得 /// - ///うれしかった - ///たのしかった - ///よろこんだ - ///ニヤニヤした - ///たまらない きもちになった - ///なんともいえない きもちだった - ///いい きぶんになった - ///うるうるした - ///うかれてしまった - ///きんちょうした - ///きもちよかった - ///もぞもぞした - ///クセになりそうに なった - ///もうしわけない きぶんになった - ///せつない きもちになった - ///なつかしい きもちになった - ///てこずった - ///きつかった - ///すなおに なれなかった - ///ほこらしく おもった - ///けんあくな ムードになった - ///おこってしまった - ///しっとした - ///ねむくなった + ///它很高兴 + ///它玩的开心 + ///它很开心 + ///它咧嘴笑 + ///它变得不知所措 + ///它的感觉难以形容 + ///它感觉很好 + ///它变得饱含泪水 + ///它感到轻松 + ///它感到紧张了 + ///它感觉很舒服 + ///它感到焦躁不安 + ///它变得有点得意忘形 + ///它感到惋惜 + ///它变得很敏感 + ///它变得很怀旧 + ///它遇到了一些困难 + ///它感到精疲力尽 + ///它感觉不像是真的 + ///它感到骄傲 + ///他们以坏心情收场 + ///它变得愤怒 + ///它感到嫉妒 + ///它想睡觉 /// - ///なにかのどうぐ - ///なにかのわざ - ///だれか - ///いい おもいでが あるようだけど ちょっと おもいおこせないみたい…… - ///{0}は {1}に {2}で であい  モンスターボールを なげられて いっしょに たびする ことになり  {3}ことが {4} - ///{0}は {2}で  タマゴの からをやぶって [rest of string was truncated]";. + ///某一道具 + ///某一技能 + ///神奇宝贝 + ///这只神奇宝贝好像有很美好的回忆,但是它似乎想不起来了…… + ///{0}和{1}的第一次相遇在……{2}。{1}朝它使用了神奇宝贝球,之后他们就开始一起旅行了。 + ///{0}从蛋中孵化并且看见{1}第一眼的地方是在……{2}。 + ///{0}和{1}相遇的地方是……{2}。 + ///{0}在{2}通过通讯交换遇见了{1},他们随后成了朋友。 + ///{0}和{1}一起去了宝可梦中心/友好商店,购买了{2}。 + ///{0}和{1}一起去了{2}的宝可梦中心并且恢复了它疲惫的身体。 + ///{0 [rest of string was truncated]";. /// internal static string text_memories_zh { get { @@ -24270,29 +24550,29 @@ internal class Resources { } /// - /// Looks up a localized string similar to 努力/实干 - ///寂寞/孤僻 + /// Looks up a localized string similar to 努力 + ///孤独 ///勇敢 ///固执 - ///顽皮/调皮 + ///调皮 ///大胆 - ///坦率 + ///直率 ///悠闲 ///淘气 - ///无虑 + ///乐天 ///胆小 ///急躁 ///认真 ///开朗 ///天真 - ///谨慎/保守 - ///温和/稳重 + ///保守 + ///稳重 ///冷静 - ///腼腆/害羞 + ///害羞 ///马虎 - ///安静/沉着 + ///沉着 ///温顺 - ///傲慢/狂妄 + ///狂妄 ///慎重 ///浮躁. /// @@ -24528,37 +24808,57 @@ internal class Resources { /// /// Looks up a localized string similar to 能量方块盒 ///树果混合器 - ///ポロックを あげる - ///あげる - ///ポロックを つくる - ///つくる + ///给与一个能量方块 + ///给与 + ///制作能量方块 + ///制作 ///[~ 6] - ///いろ + ///颜色 ///[VAR NUM3(0000)] ///[VAR PKNICK(0000)] ///[VAR MOVE(0000)] - ///どのポケモンに あげますか? - ///[VAR PKNICK(0000)]に ポロックを あげた! - ///しぼりこむ いろを えらんでください - ///ポロックを えらんでください - ///ポロックを どうしますか? - ///まぜる きのみを えらんでください + ///给哪个精灵? + ///你把能量块给了[VAR PKNICK(0000)]! + ///请选择筛选颜色 + ///选择一个能量方块 + ///要对能量方块做些什么? + ///选择需要混合的树果 ///[~ 17] - ///[VAR 01A3(0000)]が [VAR NUM1(0001)]コ できた![VAR BE05(0000)][VAR BE05(0001)] - ///[VAR PKNICK(0000)]に ポロックをあげますか? - ///タマゴは たべられません! - ///どのポケモンに あげますか? - ///4つ までしか いれられません! - ///あか で しぼりこみました - ///あお で しぼりこみました - ///ももいろ で しぼりこみました - ///みどり で しぼりこみました - ///きいろ で しぼりこみました - ///ブレンドスタート - ///きのみを もどす - ///ポケモンにあげる - ///やめる - ///はい /// [rest of string was truncated]";. + ///你做出了[VAR 01A3(0000)]个[VAR NUM1(0001)]![VAR BE05(0000)][VAR BE05(0001)] + ///把能量方块给[VAR PKNICK(0000)]? + ///蛋不能吃能量方块! + ///给哪个精灵? + ///你不能混合超过4个树果! + ///按红色筛选 + ///按蓝色筛选 + ///按粉色筛选 + ///按绿色筛选 + ///按黄色筛选 + ///开始混合 + ///返回树果 + ///给与 + ///退出 + ///是 + ///否 + ///全部 + ///红 + ///蓝 + ///粉 + ///绿 + ///黄 + ///[~ 40] + ///[~ 41] + ///[~ 42] + ///[~ 43] + ///[~ 44] + ///[~ 45] + ///[~ 46] + ///[~ 47] + ///[~ 48] + ///[~ 49] + ///[~ 50] + ///[VAR 01A3(0000)] + /// [rest of string was truncated]";. /// internal static string text_pokeblock_zh { get { diff --git a/Properties/Resources.resx b/Properties/Resources.resx index b33c0cae3..e15921321 100644 --- a/Properties/Resources.resx +++ b/Properties/Resources.resx @@ -5824,4 +5824,73 @@ ..\Resources\byte\wc6full.pkl;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + ..\Resources\text\other\const_oras.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252 + + + ..\Resources\text\other\flags_oras.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252 + + + ..\Resources\text\other\flags_xy.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8 + + + ..\Resources\img\Program\about.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\img\Program\bak.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\img\Program\data.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\img\Program\database.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\img\Program\dump.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\img\Program\exit.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\img\Program\export.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\img\Program\folder.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\img\Program\import.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\img\Program\language.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\img\Program\load.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\img\Program\main.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\img\Program\nocheck.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\img\Program\open.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\img\Program\other.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\img\Program\report.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\img\Program\savePKM.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\img\Program\saveSAV.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\img\Program\settings.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\img\Program\showdown.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + \ No newline at end of file diff --git a/Resources/img/Bag/Bag_Balls.png b/Resources/img/Bag/Bag_Balls.png new file mode 100644 index 0000000000000000000000000000000000000000..d2191eb94a9a7ba2596f14c2490a67ba09476335 GIT binary patch literal 283 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Ea{HEjtmSN`?>!lvI6;>1s;*b z3=G^tAk28_ZrvZCAbW|YuPgg4Mph;<>)SVud; zrIsj|=o#o)<`~!c0oAm5x;Tbd_%EG!nzzA#$JyFwv4Pa%FKHqzi&ZRYjy#mTbwgi^ zhe7<=oPaBHCi3yDyL}|WsBF2*$~9f0U6UT<&UESI4*9?*UUGZq(@eeXzdzWN3yEul zL_GBGkYQGwU@5vzXj*dH_y6{f-rx6Vymjf|TfHAjoljK^axQd6^rR|tax_n!#cWWv XxQ)>-?hS`M&_xWMu6{1-oD!MNn{1`ISV`@ ziy0WWg+Q3`(%rg0Ktc8rPhVH|TZ}BiM%*hm?!E^Uk|=SFC<)F_D=AMbN@XZW%*-p% z%S$a$Fwry6v&=EB^8>1xpyP$-x_|324|&tG+4+<$sXo>g>;Ym|40YQkdI3#_uw z;`Xup3YoN5V~RGblX#rNhVC!#C-pmgU`iDK>7(Gu#3W+fxZ_jYyQT$a{C-xo8$D5+ wx|Q`??c(Uh!>Z30KVX@(pS3CXT4j&<8c~~l-={>%0Nu&p>FVdQ&MBb@0GuXl3;+NC literal 0 HcmV?d00001 diff --git a/Resources/img/Bag/Bag_Berries.png b/Resources/img/Bag/Bag_Berries.png new file mode 100644 index 0000000000000000000000000000000000000000..18d73ac28174381e4333666e430b96baa8605022 GIT binary patch literal 291 zcmeAS@N?(olHy`uVBq!ia0vp^{6H+o!3HFmxV|j}QY`6?zK#qG8~eHcB(eheoCO|{ z#S9GGLLkg|>2BR0pdfpRr>`sfEk;&GRmBU_pFIT%NtC!olmzFem6RtIr7{#GX6BXX z<)xM=nCKbkS>_nm`2p4RdAc};SolxvJIH(3fQQ+($n9i?>~VWm7l-zsjIFgX2}f-% zDl0`jo8$N@R!W5Ham5PnI3b4ze^MqsuowTMDx|leh*vOn*HpnpJ9hgUvBm93duB3w zTi~iUaT`Yd*B7-<-EEdMzxTZU+fWwocei4-BiLiEsZN>0 h5oa&)Zpmy3ansXGYroFqKMr&mgQu&X%Q~loCIAQMWH|r; literal 0 HcmV?d00001 diff --git a/Resources/img/Bag/Bag_Items.png b/Resources/img/Bag/Bag_Items.png new file mode 100644 index 0000000000000000000000000000000000000000..3baa042ec081a8318ac1b1dbd9d1d62896e0f54f GIT binary patch literal 257 zcmeAS@N?(olHy`uVBq!ia0vp^d_XL~!3HGNrubO_DVB6cUq=Rpjs4tz5?O(K&H|6f zVg?3oArNM~bhqvgP>{XE)7O>#79%U8rqo$YhqFK-i4xa{lHmNblJdl&REC1Y%)Ao4 zywnl}6Fmbx%N*l6KcJc%PZ!4!3;(4T4)QiQaIjv~y&0r)wrEG9fuvH4>5l3dlWq1F zu6Q-MBSZb2?A+-uEcR`d{vh|}fjQTOSr2>GG&F?T@C!_sUbIKyz^e_X63crd{%&>q yUGOq^dOhEU&8KELe|W>n5YTYMQSaW%9gMz?6Qh|7c1Qy4W$<+Mb6Mw<&;$VTQ&-Rc literal 0 HcmV?d00001 diff --git a/Resources/img/Bag/Bag_Key.png b/Resources/img/Bag/Bag_Key.png new file mode 100644 index 0000000000000000000000000000000000000000..250667acbf86b202f01c6031a672a672e0c8bafe GIT binary patch literal 286 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Ea{HEjtmSN`?>!lvI6;>1s;*b z3=G^tAk28_ZrvZCAbW|YuPgg4Mpj01Hr`C-SfG$ZiEBhjaDG}zd16s2LqTF@UWr~_ zYKel0o`Ifaj&YqIP)(<&i(`m||Jwe8ybT6C%+^MW4Wu4F5jQw-!t?SfA)9rfTJxFD z-kol^`E^%*;ta-}xzBd0w73PRMO|t&)_U(AALO;<)*Npy!82yb$9iMb1*d9ea?VxA z@<>f9QOj@a>f(xI%iqiu6_FcysEoJop7DQ?nqRCkS}AEpJNWai>OXw8l*uX4wdO+^ ZlX<65L_$pW9H65ZJYD@<);T3K0RWF?Tu1-_ literal 0 HcmV?d00001 diff --git a/Resources/img/Bag/Bag_Mail.png b/Resources/img/Bag/Bag_Mail.png new file mode 100644 index 0000000000000000000000000000000000000000..1df987e5894d9d06a15f1d5584c175e7bde55ac3 GIT binary patch literal 225 zcmeAS@N?(olHy`uVBq!ia0vp^{6H+g!2~4TOg04rDVB6cUq=Rpjs4tz5?O(K&H|6f zVg?3oArNM~bhqvgP>{XE)7O>#79%SYi~i1U2@yaci4xa{lHmNblJdl&REC1Y%)Ao4 zywnl}6Fmbx%N*l6KcE^PPZ!4!jo{=Tj$8~Y(=-&g6hr)XI4}e*klN4I!PJt~A+U+d zqUrRa6>Z)M$|;&9S5I7;k)yLpQAnUgts~Yn%tR+dxOu^{XE)7O>#79%SYznbzrMsuK$M2TxeNpOBzNqJ&XDnmhHW?qS2 zUTTSgiJpO;WsY&3A5e|6r;B5Vg@5vo|Nrd|_siS=6K;0QdMG8qRq&Wo{KYE9BMgZX z6zq6{-7l0#v}G=u%r?WCGx3vYLNSw-T$xnIar=MF4Bum2<{v81od7hB!PC{xWt~$( F69A{UJx>4t literal 0 HcmV?d00001 diff --git a/Resources/img/Bag/Bag_TMHM.png b/Resources/img/Bag/Bag_TMHM.png new file mode 100644 index 0000000000000000000000000000000000000000..4bf996123eac82d579759bf37f00a11260478a7d GIT binary patch literal 311 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Ea{HEjtmSN`?>!lvI6;>1s;*b z3=G^tAk28_ZrvZCAbW|YuPgg4Mph?9I5zZx77c2@s6dl*6gw7TpGk5#(l6& zP;mPh%fl~=Bg_PjE#JgFwYB^B&*@*@E0&8zwl^{eT&m~HSbX{c<3ij1J$waW_jxuH zs%Oui$v$JL_knhq3%r%xXA`9x+Q9KoAAs&mbmv2^Auu zn8e1ylZlwZGeo1LvN1(K$N@wwwJ>7kPa~edTEQe1JJFyUlLynheY5jsW|zOH;RMh4 zhZaTDACO%!vCxuC%$$5z&+$M}3Cs2cd0@lf|$z zlpaZWg6(c-F0k-hPzoo5h#t-&?)-eRMlN|A6&y)>evf#-p|PGv_yScFM?B?}NS*)y N002ovPDHLkV1k(bl3f4* literal 0 HcmV?d00001 diff --git a/Resources/img/Program/bak.png b/Resources/img/Program/bak.png new file mode 100644 index 0000000000000000000000000000000000000000..ac2cd25aa04808feaa689b680f229d551b9d73b5 GIT binary patch literal 352 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`EX7WqAsj$Z!;#Vf4nJ za0`PlBg3pY5)2HCOr9=|Ar`%JFFSfMI|{H~XcrXDe;9N{fPgg&e IbxsLQ0EKcWD*ylh literal 0 HcmV?d00001 diff --git a/Resources/img/Program/database.png b/Resources/img/Program/database.png new file mode 100644 index 0000000000000000000000000000000000000000..7efe4f0f66d57243ffc1c41e553b61654ca22661 GIT binary patch literal 134 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`EX7WqAsj$Z!;#Vf4nJ za0`PlBg3pY5PZ!4!i{9jvgoGdG8@MDEngl-b;Sp(SG*5WIsC+m>hsQ>umz9l; YfkTZ`_~?htO+Y;ip00i_>zopr0P8Xz2mk;8 literal 0 HcmV?d00001 diff --git a/Resources/img/Program/dump.png b/Resources/img/Program/dump.png new file mode 100644 index 0000000000000000000000000000000000000000..f0ec6b0b175ddde52230ef57c850bf6d373fd4fa GIT binary patch literal 203 zcmeAS@N?(olHy`uVBq!ia0vp^0zk~o!3HGD9`RZNDVAa<&kznEsNqQI0P;BtJR*yM zYJ@?Ukzv*x37}xEr;B5V#>BH1&T=&+2(&(29(w(<5?7OhAJ`-DnIUA{!oBW=@DsVGuPwz(w4d-D-95kPj{OPql>1$li(@C; vzOnXE%QMfsq-jS4OP@^8I{!ww{tR=8l1-BN+nd{g7BhId`njxgN@xNAT3tql literal 0 HcmV?d00001 diff --git a/Resources/img/Program/exit.png b/Resources/img/Program/exit.png new file mode 100644 index 0000000000000000000000000000000000000000..af0845f3bd0d17bac014f52ee224ad4758a0b615 GIT binary patch literal 288 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`EX7WqAsj$Z!;#Vf4nJ za0`PlBg3pY5%mn}!M65fL4+2kso4A#*Ni z<3@osqD4(dj0$yY^a^j@O=OodK68Bj%;P+J9`@{cYMp%3^O*d%TPKaJgmN!$k}!I5 zS0Pg-a25l1&PPedWivv4%r7XB-pDm+X~bd^N24dUHLMfrF3Ee^H&p%LWtd)HcB3eg z&0^`HQq8bG2YK`zKUTZ$VYs4u>CW1}p}ysc3~r|Xm;`bk>2>Uuzs%aMu~Wr4vqiOT fi~aNbJ#mbj#a<_4OlwSlzG3im^>bP0l+XkKp!I1~ literal 0 HcmV?d00001 diff --git a/Resources/img/Program/export.png b/Resources/img/Program/export.png new file mode 100644 index 0000000000000000000000000000000000000000..d13f7f044a87b18c15729b831467a798a147b324 GIT binary patch literal 253 zcmeAS@N?(olHy`uVBq!ia0vp@KrFz)1|-ie{%Q%NSc;uILpXq-h9ji|$mcBZh%9Dc z;1&j9Muu5)B!GhRJzX3_G$y{i_8D02KG|Gfh~n#Rn=#Xh}n4qA!qHkc3_(X@#n zSvnv^AthnO^YaHn_2W8L2Jg4}`|kVoy~~R$*D0x4B=sCpp5Q2(`=lw{nVGr7@Tkt5 zxdu(9d^a8mnYfE~w`}LU<7HsALZ!iE>P6={zB6Cux^~ueUg9pBFJ_he{iJWa?R)uO usvsdRb^|u69x-I}ZmBG{1&t;ucLK6Vrs9BEy literal 0 HcmV?d00001 diff --git a/Resources/img/Program/folder.png b/Resources/img/Program/folder.png new file mode 100644 index 0000000000000000000000000000000000000000..3bf7a45b35c61365618199986926d97d4e424a35 GIT binary patch literal 177 zcmeAS@N?(olHy`uVBq!ia0vp^0zk~e!3HF=pW8M9DVAa<&kznEsNqQI0P;BtJR*x3 z7`TN&n2}-D90{Ocu&0Y-h{nXXXV3CFI54<8JRdJ;by1<$LgPd&cVtWVb%7 literal 0 HcmV?d00001 diff --git a/Resources/img/Program/import.png b/Resources/img/Program/import.png new file mode 100644 index 0000000000000000000000000000000000000000..bb260f0159c9672746b0504ba015c0c87074a8f5 GIT binary patch literal 372 zcmV-)0gL{LP)+)4wamQ4|L7k3!_V4y5B`lY ziLsm5iZ1^|E4t8!m+0U%_B~V;BUWJBw+DqaFLC=S;vDL;1g7Jr0d(UM$Ekb+PDA7Z zO}_=!{rwJVa1bIlG42-%hRtFUPgp84>Q0Ehb~r0000D)3HldVH5`NpQ3$6oBu;o znhtI)H3$ts|AycuViY#FIF$J*E^ZMNkuEM0O@cx+7B11M4uviXcCW+xT)XNwdEoG# zbKd7%&ikC_a^1$Tf<2tZ_pprnJ@6McgjH1dhZ;xmI<*R2bb2*^4e%Z26VG5a@w433 z_>!IrTg}Cb_Z#=+M zYWH%^;BVsLjC;3*dxT#Uh250Iw-k9+*v7cBsu~}Xk7FaXhsk#pWsWpY=>{;D{2TTa z_U|a$XoS?Lbg|7vN0DcZ_ju{Ql%FS_$H&B5xOJ7#p-fW6Yh`uEiJPBnu~&23MitTg h#7X=|2phQyJ_oSAe?!Ja(7ONt002ovPDHLkV1n{t!b$)D literal 0 HcmV?d00001 diff --git a/Resources/img/Program/load.png b/Resources/img/Program/load.png new file mode 100644 index 0000000000000000000000000000000000000000..db4c6b02f1c0dd4b0f2e5f9cd677c901828721a7 GIT binary patch literal 206 zcmeAS@N?(olHy`uVBq!ia0vp^0zk~o!3HGD9`RZNDVAa<&kznEsNqQI0P;BtJR*yM zYJ@?Ukzv*x37}wsr;B5V#>BN3ytxh~@Gv|)KlQ7p{^OlCa}xqZxLA)mzf@yn{e4@E zJ#BJ|*}^k6b6i@TBYJzqGd}S28%iG$dcNJl_UO73QrGnhs}8Qxzqdg5NT&35`J9Wq w9hdc_0v_8b`Q@)jzmfd?wWY0%T3P)Q)+NbiX`jQ?LGEPmboFyt=akR{00$L9VE_OC literal 0 HcmV?d00001 diff --git a/Resources/img/Program/main.png b/Resources/img/Program/main.png new file mode 100644 index 0000000000000000000000000000000000000000..d7e360e3575fe51b03c1259e2a10e2087fb63023 GIT binary patch literal 274 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`EX7WqAsj$Z!;#Vf4nJ za0`PlBg3pY5edY<;br1vqzCdg6pu$lX#Kx=zlx`$`McVi@fW9d^Ntyc0e?Oaq+(X#=FAR8-3FaKjys! Px}U+*)z4*}Q$iB}C(T`v literal 0 HcmV?d00001 diff --git a/Resources/img/Program/nocheck.png b/Resources/img/Program/nocheck.png new file mode 100644 index 0000000000000000000000000000000000000000..bb69bd4ed1751d57b5e6439f8c335e2a6855c11e GIT binary patch literal 224 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`EX7WqAsj$Z!;#Vf4nJ za0`PlBg3pY5l5#ApT%0 zgYtw%&b^ZinYURq_)bwtFjq^ypyp+>=hx=^lQNC(XGu@;zv2C^dH37Y9cr8hmuj0o z^fPsP^*7D*k&=zzi^%Vmhg>Lm%vYh_wiKLoox_;yXsgw4P_b~kBe5(;Or^7Gk QEYLL!p00i_>zopr0F+Nog8%>k literal 0 HcmV?d00001 diff --git a/Resources/img/Program/open.png b/Resources/img/Program/open.png new file mode 100644 index 0000000000000000000000000000000000000000..896b1f57a92fb4d774b67b17ac2362e8a2ae4e23 GIT binary patch literal 180 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`EX7WqAsj$Z!;#Vf4nJ za0`PlBg3pY5zxKG}wdvi;3*Is;x~m-)%1llApE4=) z-fOupHzqW1R}B5WIaw&W`&6!UlR?jkuk0VTDrq#;bIhB;cgAsBVW~=@==n;=a;BC7 W_1kYmyfy%BVDNPHb6Mw<&;$VP2s*R? literal 0 HcmV?d00001 diff --git a/Resources/img/Program/other.png b/Resources/img/Program/other.png new file mode 100644 index 0000000000000000000000000000000000000000..4f1d5508ef5d2307b85b41d01eebd19012fef7b3 GIT binary patch literal 357 zcmV-r0h<1aP)D(!ELpQ4q!PpRq}y(IQ1! zu}o)Umm-ag1gv}kA3+e(3weuFzCzhP4!>z);iX$~}EZ_DVBivvM*EkHw z5nfW$q*RM=hGB7%zd%MSkmOE&f(+#kuk{~*=-h%&`0qkavt#<=00000NkvXXu0mjf D`M#3A literal 0 HcmV?d00001 diff --git a/Resources/img/Program/report.png b/Resources/img/Program/report.png new file mode 100644 index 0000000000000000000000000000000000000000..bb5635d762c684f93adb52bd6407ddf278520060 GIT binary patch literal 297 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`jKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85p>QK$!8;-MT+OL5ULAh?3y^w370~qEv>0#LT=By}Z;C1rt33 zJY*4Gn_O?Xdz=w14HBDab2nlloy z*Of(0Y8bg=d#Wzp$P!z~ literal 0 HcmV?d00001 diff --git a/Resources/img/Program/savePKM.png b/Resources/img/Program/savePKM.png new file mode 100644 index 0000000000000000000000000000000000000000..0fbf0b8790f0e32ec5751269ffad488f7e81804e GIT binary patch literal 334 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`jKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85p>QK$!8;-MT+OL5ULAh?3y^w370~qEv>0#LT=By}Z;C1rt33 zJgJOBp-xR Y@msFTS->Q&4+4nJ za0`PlBg3pY5isI>go~BwqX8!F-tS|G&@g|7>7Z{_`NfSUkf!aLF^&JE~fuH zx_R1hW zH`d^)1h_y08)%j=CoqTmz&seO0pX*frL z`55Dv!X8$FIrXC!6sSjFHF}9RJYgoSJ9v)3Uw9FO9gOc0GXMYp07*qoM6N<$g75c| ABLDyZ literal 0 HcmV?d00001 diff --git a/Resources/img/Program/showdown.png b/Resources/img/Program/showdown.png new file mode 100644 index 0000000000000000000000000000000000000000..92f6df1ecd9ec776c1c9846d67e90c1c1ad71f3e GIT binary patch literal 289 zcmeAS@N?(olHy`uVBq!ia0vp^{6H+g!3HExhN-duDVAa<&kznEsNqQI0P;BtJR*x3 z7`TN&n2}-D90{P{VNVyw5RHj*FBxVzISL&67=J{dABO>q+wEBI`< zKYR(5M0A|ZWYiw44$rjF6*2UngGM8ZukHI literal 0 HcmV?d00001 diff --git a/Resources/text/other/const_oras.txt b/Resources/text/other/const_oras.txt new file mode 100644 index 000000000..82c06dc79 --- /dev/null +++ b/Resources/text/other/const_oras.txt @@ -0,0 +1,4 @@ +60 Ash +21 Test1 +22 Test2 +24 Test3 \ No newline at end of file diff --git a/Resources/text/other/flags_oras.txt b/Resources/text/other/flags_oras.txt new file mode 100644 index 000000000..15441eab3 --- /dev/null +++ b/Resources/text/other/flags_oras.txt @@ -0,0 +1,66 @@ +0648 (OR) Groudon Defeated +2839 (OR) Groudon Captured +0647 (AS) Kyogre Defeated +2840 (AS) Kyogre Captured +0208 (OR) Ho-Oh Defeated +2815 (OR) Ho-Oh Captured +0209 (AS) Lugia Defeated +2814 (AS) Lugia Captured +2819 (AS) Dialga Captured +2820 (OR) Palkia Captured +2828 (OR) Tornadus Captured +2829 (AS) Thundurus Captured +2832 Landorus Captured +0182 (OR) Reshiram Defeated +2830 (OR) Reshiram Captured +0183 (AS) Zekrom Defeated +2831 (AS) Zekrom Captured +0419 (OR) Latias Defeated +2834 (OR) Latias Captured +0420 (AS) Latios Defeated +2835 (AS) Latios Captured +0945 Deoxys Defeated @ Sky Tower +2842 Deoxys Captured @ Sky Tower +0173 Raikou Defeated +2811 Raikou Captured +0174 Entei Defeated +2812 Entei Captured +0175 Suicune Defeated +2813 Suicune Captured +0176 Cobalion Defeated +2825 Cobalion Captured +0177 Terrakion Defeated +2826 Terrakion Captured +0178 Virizion Defeated +2827 Virizion Captured +0184 Kyurem Defeated +2833 Kyurem Captured +0179 Uxie Defeated +2816 Uxie Captured +0180 Mesprit Defeated +2817 Mesprit Captured +0181 Azelf Defeated +2818 Azelf Captured +0172 Cresselia Defeated +2824 Cresselia Captured +2823 Giratina Captured +0260 Heatran Defeated +2821 Heatran Captured +0956 Regirock Defeated +2836 Regirock Captured +0957 Regice Defeated +2837 Regice Captured +0958 Registeel Defeated +2838 Registeel Captured +0252 Regigigas Defeated +2822 Regigigas Captured +0284 Singles Statuette +0285 Doubles Statuette +0286 Triples Statuette +0287 Rotation Statuette +0288 Multi Statuette +0289 Super Singles Unlocked +0290 Super Doubles Unlocked +0291 Super Triples Unlocked +0292 Super Rotation Unlocked +0293 Super Multi Unlocked \ No newline at end of file diff --git a/Resources/text/other/flags_xy.txt b/Resources/text/other/flags_xy.txt new file mode 100644 index 000000000..e1c9b7a4d --- /dev/null +++ b/Resources/text/other/flags_xy.txt @@ -0,0 +1,19 @@ +2237 2237 +2238 2238 +2239 2239 +0963 Mewtwo Defeated +0115 Mewtwo Captured +0114 Zygarde Captured +0790 Zygarde Defeated +0285 Singles Statuette +0286 Doubles Statuette +0287 Triples Statuette +0288 Rotation Statuette +0289 Multi Statuette +0290 Super Singles Unlocked +0291 Super Doubles Unlocked +0292 Super Triples Unlocked +0293 Super Rotation Unlocked +0294 Super Multi Unlocked +0675 50: Beat Chatelaine +2546 Pokédex Obtained \ No newline at end of file diff --git a/SAV/SAV_BerryFieldXY.cs b/SAV/SAV_BerryFieldXY.cs index c0ec15d0a..a23730568 100644 --- a/SAV/SAV_BerryFieldXY.cs +++ b/SAV/SAV_BerryFieldXY.cs @@ -11,21 +11,21 @@ public SAV_BerryFieldXY() Util.TranslateInterface(this, Main.curlanguage); listBox1.SelectedIndex = 0; } - private readonly byte[] sav = (byte[])Main.SAV.Data.Clone(); + private readonly SAV6 SAV = new SAV6(Main.SAV.Data); private void changefield(object sender, EventArgs e) { // Change Berry Field // Gather Data - int berry = BitConverter.ToUInt16(sav, Main.SAV.BerryField + 0xC + listBox1.SelectedIndex*0x18 + 1 * 0); - int u1 = BitConverter.ToUInt16(sav, Main.SAV.BerryField + 0xC + listBox1.SelectedIndex * 0x18 + 1 * 2); - int u2 = BitConverter.ToUInt16(sav, Main.SAV.BerryField + 0xC + listBox1.SelectedIndex * 0x18 + 2 * 2); - int u3 = BitConverter.ToUInt16(sav, Main.SAV.BerryField + 0xC + listBox1.SelectedIndex * 0x18 + 3 * 2); - int u4 = BitConverter.ToUInt16(sav, Main.SAV.BerryField + 0xC + listBox1.SelectedIndex * 0x18 + 4 * 2); - int u5 = BitConverter.ToUInt16(sav, Main.SAV.BerryField + 0xC + listBox1.SelectedIndex * 0x18 + 5 * 2); - int u6 = BitConverter.ToUInt16(sav, Main.SAV.BerryField + 0xC + listBox1.SelectedIndex * 0x18 + 6 * 2); - int u7 = BitConverter.ToUInt16(sav, Main.SAV.BerryField + 0xC + listBox1.SelectedIndex * 0x18 + 7 * 2); + int berry = BitConverter.ToUInt16(SAV.Data, SAV.BerryField + 0xC + listBox1.SelectedIndex*0x18 + 1 * 0); + int u1 = BitConverter.ToUInt16(SAV.Data, SAV.BerryField + 0xC + listBox1.SelectedIndex * 0x18 + 1 * 2); + int u2 = BitConverter.ToUInt16(SAV.Data, SAV.BerryField + 0xC + listBox1.SelectedIndex * 0x18 + 2 * 2); + int u3 = BitConverter.ToUInt16(SAV.Data, SAV.BerryField + 0xC + listBox1.SelectedIndex * 0x18 + 3 * 2); + int u4 = BitConverter.ToUInt16(SAV.Data, SAV.BerryField + 0xC + listBox1.SelectedIndex * 0x18 + 4 * 2); + int u5 = BitConverter.ToUInt16(SAV.Data, SAV.BerryField + 0xC + listBox1.SelectedIndex * 0x18 + 5 * 2); + int u6 = BitConverter.ToUInt16(SAV.Data, SAV.BerryField + 0xC + listBox1.SelectedIndex * 0x18 + 6 * 2); + int u7 = BitConverter.ToUInt16(SAV.Data, SAV.BerryField + 0xC + listBox1.SelectedIndex * 0x18 + 7 * 2); // Display Data diff --git a/SAV/SAV_BoxLayout.cs b/SAV/SAV_BoxLayout.cs index acea36554..fb2a0ff4b 100644 --- a/SAV/SAV_BoxLayout.cs +++ b/SAV/SAV_BoxLayout.cs @@ -18,28 +18,28 @@ public SAV_BoxLayout(int box) CB_BG.Items.Add(wallpaper); // Go - MT_BG1.Text = sav.Data[sav.PCFlags + 0].ToString(); - CB_Unlocked.SelectedIndex = sav.Data[sav.PCFlags + 1] - 1; - MT_BG2.Text = sav.Data[sav.PCFlags + 2].ToString(); + MT_BG1.Text = SAV.Data[SAV.PCFlags + 0].ToString(); + CB_Unlocked.SelectedIndex = SAV.Data[SAV.PCFlags + 1] - 1; + MT_BG2.Text = SAV.Data[SAV.PCFlags + 2].ToString(); LB_BoxSelect.SelectedIndex = box; } - private readonly SAV6 sav = new SAV6((byte[])Main.SAV.Data.Clone()); + private readonly SAV6 SAV = new SAV6(Main.SAV.Data); private bool editing; private void changeBox(object sender, EventArgs e) { editing = true; - int bgoff = sav.PCBackgrounds + LB_BoxSelect.SelectedIndex; - CB_BG.SelectedIndex = sav.Data[bgoff]; - TB_BoxName.Text = sav.getBoxName(LB_BoxSelect.SelectedIndex); + int bgoff = SAV.PCBackgrounds + LB_BoxSelect.SelectedIndex; + CB_BG.SelectedIndex = SAV.Data[bgoff]; + TB_BoxName.Text = SAV.getBoxName(LB_BoxSelect.SelectedIndex); editing = false; } private void changeBoxDetails(object sender, EventArgs e) { if (!editing) - sav.setBoxName(LB_BoxSelect.SelectedIndex, TB_BoxName.Text); + SAV.setBoxName(LB_BoxSelect.SelectedIndex, TB_BoxName.Text); } private void B_Cancel_Click(object sender, EventArgs e) { @@ -47,11 +47,11 @@ private void B_Cancel_Click(object sender, EventArgs e) } private void B_Save_Click(object sender, EventArgs e) { - sav.Data[sav.PCFlags + 0] = (byte)Util.ToUInt32(MT_BG1.Text); - sav.Data[sav.PCFlags + 1] = (byte)Util.ToUInt32(CB_Unlocked.Text); - sav.Data[sav.PCFlags + 2] = (byte)Util.ToUInt32(MT_BG2.Text); + SAV.Data[SAV.PCFlags + 0] = (byte)Util.ToUInt32(MT_BG1.Text); + SAV.Data[SAV.PCFlags + 1] = (byte)Util.ToUInt32(CB_Unlocked.Text); + SAV.Data[SAV.PCFlags + 2] = (byte)Util.ToUInt32(MT_BG2.Text); - Array.Copy(sav.Data, Main.SAV.Data, sav.Data.Length); + Array.Copy(SAV.Data, Main.SAV.Data, SAV.Data.Length); Main.SAV.Edited = true; Close(); } @@ -59,9 +59,9 @@ private void B_Save_Click(object sender, EventArgs e) private void changeBoxBG(object sender, EventArgs e) { if (!editing) - sav.Data[Main.SAV.PCBackgrounds + LB_BoxSelect.SelectedIndex] = (byte)CB_BG.SelectedIndex; + SAV.Data[SAV.PCBackgrounds + LB_BoxSelect.SelectedIndex] = (byte)CB_BG.SelectedIndex; - string imagename = "box_wp" + (CB_BG.SelectedIndex + 1).ToString("00"); if (sav.ORAS && CB_BG.SelectedIndex + 1 > 16) imagename += "o"; + string imagename = "box_wp" + (CB_BG.SelectedIndex + 1).ToString("00"); if (SAV.ORAS && CB_BG.SelectedIndex + 1 > 16) imagename += "o"; PAN_BG.BackgroundImage = (Image)Properties.Resources.ResourceManager.GetObject(imagename); } } diff --git a/SAV/SAV_Database.Designer.cs b/SAV/SAV_Database.Designer.cs index 000013c81..5a94534f9 100644 --- a/SAV/SAV_Database.Designer.cs +++ b/SAV/SAV_Database.Designer.cs @@ -911,10 +911,11 @@ private void InitializeComponent() // // Menu_Exit // + this.Menu_Exit.Image = global::PKHeX.Properties.Resources.exit; 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(96, 22); + this.Menu_Exit.Size = new System.Drawing.Size(152, 22); this.Menu_Exit.Text = "&Close"; this.Menu_Exit.Click += new System.EventHandler(this.Menu_Exit_Click); // @@ -936,6 +937,7 @@ private void InitializeComponent() this.Menu_SearchDatabase, this.Menu_SearchLegal, this.Menu_SearchIllegal}); + this.Menu_SearchSettings.Image = global::PKHeX.Properties.Resources.settings; this.Menu_SearchSettings.Name = "Menu_SearchSettings"; this.Menu_SearchSettings.Size = new System.Drawing.Size(197, 22); this.Menu_SearchSettings.Text = "Search Settings"; @@ -978,6 +980,7 @@ private void InitializeComponent() // // Menu_OpenDB // + this.Menu_OpenDB.Image = global::PKHeX.Properties.Resources.folder; this.Menu_OpenDB.Name = "Menu_OpenDB"; this.Menu_OpenDB.Size = new System.Drawing.Size(197, 22); this.Menu_OpenDB.Text = "Open Database Folder"; @@ -985,6 +988,7 @@ private void InitializeComponent() // // Menu_Report // + this.Menu_Report.Image = global::PKHeX.Properties.Resources.report; this.Menu_Report.Name = "Menu_Report"; this.Menu_Report.Size = new System.Drawing.Size(197, 22); this.Menu_Report.Text = "Create Data Report"; @@ -992,6 +996,7 @@ private void InitializeComponent() // // Menu_Export // + this.Menu_Export.Image = global::PKHeX.Properties.Resources.export; this.Menu_Export.Name = "Menu_Export"; this.Menu_Export.Size = new System.Drawing.Size(197, 22); this.Menu_Export.Text = "Export Results to Folder"; diff --git a/SAV/SAV_Database.cs b/SAV/SAV_Database.cs index ff4a2df2a..92980bf17 100644 --- a/SAV/SAV_Database.cs +++ b/SAV/SAV_Database.cs @@ -81,13 +81,14 @@ public SAV_Database(Main f1) { Version = 0, Title = "Misc", - Description = "Individual pk6 files present in the db/sav.", + Description = "Individual pkm files present in the db/sav.", }); // Load databases foreach (string file in Directory.GetFiles(DatabasePath, "*", SearchOption.AllDirectories)) { - if (new FileInfo(file).Extension == ".pk6") + FileInfo fi = new FileInfo(file); + if (fi.Extension.Contains(".pk") && PKX.getIsPKM(fi.Length)) Database[0].Slot.Add(new PK6(File.ReadAllBytes(file), file)); else loadDatabase(File.ReadAllBytes(file)); @@ -109,8 +110,8 @@ public SAV_Database(Main f1) private readonly PictureBox[] PKXBOXES; private readonly string DatabasePath = Main.DatabasePath; private readonly List Database = new List(); - private List Results; - private List RawDB; + private List Results; + private List RawDB; private int slotSelected = -1; // = null; private Image slotColor; private const int RES_MAX = 66; @@ -129,7 +130,7 @@ private void clickView(object sender, EventArgs e) System.Media.SystemSounds.Exclamation.Play(); else { - m_parent.populateFields(new PK6(dataArr[index].Data), false); + m_parent.populateFields(dataArr[index], false); slotSelected = index + SCR_Box.Value * RES_MIN; slotColor = Properties.Resources.slotView; FillPKXBoxes(SCR_Box.Value); @@ -161,12 +162,12 @@ private void clickDelete(object sender, EventArgs e) int box = Convert.ToInt32(split[0].Substring(1)) - 1; int slot = Convert.ToInt32(split[1]) - 1; int spot = box*30 + slot; - int offset = Main.SAV.Box + spot*PK6.SIZE_STORED; - var pkSAV = Main.SAV.getPK6Stored(offset); + int offset = Main.SAV.getBoxOffset(0) + spot*Main.SAV.SIZE_STORED; + PKM pkSAV = Main.SAV.getStoredSlot(offset); if (pkSAV.Data.SequenceEqual(pk.Data)) { - Main.SAV.setEK6Stored(Main.blankEK6, offset); + Main.SAV.setStoredSlot(Main.SAV.BlankPKM, offset); m_parent.setPKXBoxes(); } else @@ -191,7 +192,7 @@ private void clickSet(object sender, EventArgs e) if (!m_parent.verifiedPKX()) return; - PK6 pk = m_parent.preparepkx(); + PKM pk = m_parent.preparePKM(); if (!Directory.Exists(DatabasePath)) Directory.CreateDirectory(DatabasePath); @@ -203,12 +204,12 @@ private void clickSet(object sender, EventArgs e) return; } - File.WriteAllBytes(path, pk.Data.Take(PK6.SIZE_STORED).ToArray()); + File.WriteAllBytes(path, pk.Data.Take(pk.SIZE_STORED).ToArray()); pk.Identifier = path; int pre = RawDB.Count; RawDB.Add(pk); - RawDB = new List(RawDB.Distinct()); // just in case + RawDB = new List(RawDB.Distinct()); // just in case int post = RawDB.Count; if (pre == post) { Util.Alert("Pokémon already exists in database."); return; } @@ -317,7 +318,7 @@ private void generateDBReport(object sender, EventArgs e) // IO Usage private class DatabaseList { - public readonly List Slot = new List(); + public readonly List Slot = new List(); public int Version; private readonly bool Unicode; private readonly byte[] Unused; @@ -380,13 +381,13 @@ private void loadDatabase(byte[] data) } private void prepareDBForSearch() { - RawDB = new List(); + RawDB = new List(); foreach (var db in Database) RawDB.AddRange(db.Slot); - RawDB = new List(RawDB.Where(pk => pk.ChecksumValid && pk.Species != 0 && pk.Sanity == 0)); - RawDB = new List(RawDB.Distinct()); + RawDB = new List(RawDB.Where(pk => pk.ChecksumValid && pk.Species != 0 && pk.Sanity == 0)); + RawDB = new List(RawDB.Distinct()); setResults(RawDB); } private void openDB(object sender, EventArgs e) @@ -410,16 +411,16 @@ private void Menu_Export_Click(object sender, EventArgs e) if (!Directory.Exists(path)) // just in case... Directory.CreateDirectory(path); - foreach (PK6 pk6 in Results) - File.WriteAllBytes(Path.Combine(path, Util.CleanFileName(pk6.FileName)), - pk6.Data.Take(0xE8).ToArray()); + foreach (PKM pkm in Results) + File.WriteAllBytes(Path.Combine(path, Util.CleanFileName(pkm.FileName)), + pkm.Data.Take(0xE8).ToArray()); } // View Updates private void B_Search_Click(object sender, EventArgs e) { // Populate Search Query Result - IEnumerable res = RawDB; + IEnumerable res = RawDB; // Primary Searchables int species = Util.getIndex(CB_Species); @@ -534,9 +535,9 @@ private void B_Search_Click(object sender, EventArgs e) slotSelected = -1; // reset the slot last viewed if (Menu_SearchLegal.Checked && !Menu_SearchIllegal.Checked) // Legal Only - res = res.Where(pk => pk.Gen6 && new LegalityAnalysis(pk).Valid); + res = res.Where(pk => pk.Gen6 && pk is PK6 && new LegalityAnalysis(pk as PK6).Valid); if (!Menu_SearchLegal.Checked && Menu_SearchIllegal.Checked) // Illegal Only - res = res.Where(pk => pk.Gen6 && !new LegalityAnalysis(pk).Valid); + res = res.Where(pk => pk.Gen6 && pk is PK6 && !new LegalityAnalysis(pk as PK6).Valid); var results = res.ToArray(); if (results.Length == 0) @@ -546,7 +547,7 @@ private void B_Search_Click(object sender, EventArgs e) else Util.Alert("No results found!"); } - setResults(new List(results)); // updates Count Label as well. + setResults(new List(results)); // updates Count Label as well. System.Media.SystemSounds.Asterisk.Play(); } private void updateScroll(object sender, ScrollEventArgs e) @@ -554,9 +555,9 @@ private void updateScroll(object sender, ScrollEventArgs e) if (e.OldValue != e.NewValue) FillPKXBoxes(e.NewValue); } - private void setResults(List res) + private void setResults(List res) { - Results = new List(res); + Results = new List(res); SCR_Box.Maximum = (int)Math.Ceiling((decimal)Results.Count / RES_MIN); if (SCR_Box.Maximum > 0) SCR_Box.Maximum -= 1; @@ -571,7 +572,7 @@ private void FillPKXBoxes(int start) if (Results == null) for (int i = 0; i < RES_MAX; i++) PKXBOXES[i].Image = null; - PK6[] data = Results.Skip(start * RES_MIN).Take(RES_MAX).ToArray(); + PKM[] data = Results.Skip(start * RES_MIN).Take(RES_MAX).ToArray(); for (int i = 0; i < data.Length; i++) PKXBOXES[i].Image = data[i].Sprite; for (int i = data.Length; i < RES_MAX; i++) diff --git a/SAV/SAV_EventFlags.Designer.cs b/SAV/SAV_EventFlags.Designer.cs new file mode 100644 index 000000000..e341d52a2 --- /dev/null +++ b/SAV/SAV_EventFlags.Designer.cs @@ -0,0 +1,382 @@ +namespace PKHeX +{ + partial class SAV_EventFlags + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(SAV_EventFlags)); + this.c_CustomFlag = new System.Windows.Forms.CheckBox(); + this.B_Cancel = new System.Windows.Forms.Button(); + this.GB_FlagStatus = new System.Windows.Forms.GroupBox(); + this.nud = new System.Windows.Forms.NumericUpDown(); + this.CHK_CustomFlag = new System.Windows.Forms.Label(); + this.L_Value = new System.Windows.Forms.Label(); + this.CB_Stats = new System.Windows.Forms.ComboBox(); + this.MT_Stat = new System.Windows.Forms.MaskedTextBox(); + this.L_Stats = new System.Windows.Forms.Label(); + this.B_Save = new System.Windows.Forms.Button(); + this.GB_Researcher = new System.Windows.Forms.GroupBox(); + this.L_UnSet = new System.Windows.Forms.Label(); + this.L_IsSet = new System.Windows.Forms.Label(); + this.TB_NewSAV = new System.Windows.Forms.TextBox(); + this.TB_OldSAV = new System.Windows.Forms.TextBox(); + this.TB_UnSet = new System.Windows.Forms.TextBox(); + this.TB_IsSet = new System.Windows.Forms.TextBox(); + this.B_LoadNew = new System.Windows.Forms.Button(); + this.B_LoadOld = new System.Windows.Forms.Button(); + this.GB_Flags = new System.Windows.Forms.GroupBox(); + this.GB_Constants = new System.Windows.Forms.GroupBox(); + this.TLP_Const = new System.Windows.Forms.TableLayoutPanel(); + this.TLP_Flags = new System.Windows.Forms.TableLayoutPanel(); + this.GB_FlagStatus.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.nud)).BeginInit(); + this.GB_Researcher.SuspendLayout(); + this.GB_Flags.SuspendLayout(); + this.GB_Constants.SuspendLayout(); + this.SuspendLayout(); + // + // c_CustomFlag + // + this.c_CustomFlag.AutoSize = true; + this.c_CustomFlag.CheckAlign = System.Drawing.ContentAlignment.MiddleRight; + this.c_CustomFlag.Location = new System.Drawing.Point(138, 15); + this.c_CustomFlag.Name = "c_CustomFlag"; + this.c_CustomFlag.Size = new System.Drawing.Size(15, 14); + this.c_CustomFlag.TabIndex = 1; + this.c_CustomFlag.UseVisualStyleBackColor = true; + this.c_CustomFlag.CheckedChanged += new System.EventHandler(this.changeCustomBool); + // + // B_Cancel + // + this.B_Cancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.B_Cancel.Location = new System.Drawing.Point(289, 320); + this.B_Cancel.Name = "B_Cancel"; + this.B_Cancel.Size = new System.Drawing.Size(75, 23); + this.B_Cancel.TabIndex = 2; + this.B_Cancel.Text = "Cancel"; + this.B_Cancel.UseVisualStyleBackColor = true; + this.B_Cancel.Click += new System.EventHandler(this.B_Cancel_Click); + // + // GB_FlagStatus + // + this.GB_FlagStatus.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.GB_FlagStatus.Controls.Add(this.nud); + this.GB_FlagStatus.Controls.Add(this.CHK_CustomFlag); + this.GB_FlagStatus.Controls.Add(this.L_Value); + this.GB_FlagStatus.Controls.Add(this.CB_Stats); + this.GB_FlagStatus.Controls.Add(this.MT_Stat); + this.GB_FlagStatus.Controls.Add(this.L_Stats); + this.GB_FlagStatus.Controls.Add(this.c_CustomFlag); + this.GB_FlagStatus.Location = new System.Drawing.Point(288, 228); + this.GB_FlagStatus.Name = "GB_FlagStatus"; + this.GB_FlagStatus.Size = new System.Drawing.Size(159, 81); + this.GB_FlagStatus.TabIndex = 3; + this.GB_FlagStatus.TabStop = false; + this.GB_FlagStatus.Text = "Check Status"; + // + // nud + // + this.nud.Location = new System.Drawing.Point(87, 12); + this.nud.Maximum = new decimal(new int[] { + 3072, + 0, + 0, + 0}); + this.nud.Name = "nud"; + this.nud.Size = new System.Drawing.Size(45, 20); + this.nud.TabIndex = 9; + this.nud.ValueChanged += new System.EventHandler(this.changeCustomFlag); + this.nud.KeyUp += new System.Windows.Forms.KeyEventHandler(this.changeCustomFlag); + // + // CHK_CustomFlag + // + this.CHK_CustomFlag.Location = new System.Drawing.Point(9, 12); + this.CHK_CustomFlag.Name = "CHK_CustomFlag"; + this.CHK_CustomFlag.Size = new System.Drawing.Size(72, 20); + this.CHK_CustomFlag.TabIndex = 2; + this.CHK_CustomFlag.Text = "Flag:"; + this.CHK_CustomFlag.TextAlign = System.Drawing.ContentAlignment.MiddleRight; + // + // L_Value + // + this.L_Value.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.L_Value.Location = new System.Drawing.Point(6, 56); + this.L_Value.Name = "L_Value"; + this.L_Value.Size = new System.Drawing.Size(75, 20); + this.L_Value.TabIndex = 35; + this.L_Value.Text = "Value:"; + this.L_Value.TextAlign = System.Drawing.ContentAlignment.MiddleRight; + // + // CB_Stats + // + this.CB_Stats.DropDownHeight = 156; + this.CB_Stats.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.CB_Stats.DropDownWidth = 180; + this.CB_Stats.FormattingEnabled = true; + this.CB_Stats.IntegralHeight = false; + this.CB_Stats.Location = new System.Drawing.Point(87, 35); + this.CB_Stats.Name = "CB_Stats"; + this.CB_Stats.Size = new System.Drawing.Size(66, 21); + this.CB_Stats.TabIndex = 36; + this.CB_Stats.SelectedIndexChanged += new System.EventHandler(this.changeConstantIndex); + // + // MT_Stat + // + this.MT_Stat.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.MT_Stat.Font = new System.Drawing.Font("Courier New", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.MT_Stat.Location = new System.Drawing.Point(87, 57); + this.MT_Stat.Mask = "00000"; + this.MT_Stat.Name = "MT_Stat"; + this.MT_Stat.Size = new System.Drawing.Size(34, 20); + this.MT_Stat.TabIndex = 34; + this.MT_Stat.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; + this.MT_Stat.TextChanged += new System.EventHandler(this.changeCustomConst); + // + // L_Stats + // + this.L_Stats.Location = new System.Drawing.Point(9, 36); + this.L_Stats.Name = "L_Stats"; + this.L_Stats.Size = new System.Drawing.Size(72, 20); + this.L_Stats.TabIndex = 37; + this.L_Stats.Text = "Constant:"; + this.L_Stats.TextAlign = System.Drawing.ContentAlignment.MiddleRight; + // + // B_Save + // + this.B_Save.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.B_Save.Location = new System.Drawing.Point(372, 320); + this.B_Save.Name = "B_Save"; + this.B_Save.Size = new System.Drawing.Size(75, 23); + this.B_Save.TabIndex = 9; + this.B_Save.Text = "Save"; + this.B_Save.UseVisualStyleBackColor = true; + this.B_Save.Click += new System.EventHandler(this.B_Save_Click); + // + // GB_Researcher + // + this.GB_Researcher.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.GB_Researcher.Controls.Add(this.L_UnSet); + this.GB_Researcher.Controls.Add(this.L_IsSet); + this.GB_Researcher.Controls.Add(this.TB_NewSAV); + this.GB_Researcher.Controls.Add(this.TB_OldSAV); + this.GB_Researcher.Controls.Add(this.TB_UnSet); + this.GB_Researcher.Controls.Add(this.TB_IsSet); + this.GB_Researcher.Controls.Add(this.B_LoadNew); + this.GB_Researcher.Controls.Add(this.B_LoadOld); + this.GB_Researcher.Location = new System.Drawing.Point(12, 228); + this.GB_Researcher.Name = "GB_Researcher"; + this.GB_Researcher.Size = new System.Drawing.Size(268, 120); + this.GB_Researcher.TabIndex = 13; + this.GB_Researcher.TabStop = false; + this.GB_Researcher.Text = "FlagDiff Researcher"; + // + // L_UnSet + // + this.L_UnSet.Location = new System.Drawing.Point(3, 94); + this.L_UnSet.Name = "L_UnSet"; + this.L_UnSet.Size = new System.Drawing.Size(51, 21); + this.L_UnSet.TabIndex = 7; + this.L_UnSet.Text = "UnSet:"; + this.L_UnSet.TextAlign = System.Drawing.ContentAlignment.MiddleRight; + // + // L_IsSet + // + this.L_IsSet.Location = new System.Drawing.Point(6, 73); + this.L_IsSet.Name = "L_IsSet"; + this.L_IsSet.Size = new System.Drawing.Size(48, 20); + this.L_IsSet.TabIndex = 6; + this.L_IsSet.Text = "IsSet:"; + this.L_IsSet.TextAlign = System.Drawing.ContentAlignment.MiddleRight; + // + // TB_NewSAV + // + this.TB_NewSAV.Location = new System.Drawing.Point(93, 47); + this.TB_NewSAV.Name = "TB_NewSAV"; + this.TB_NewSAV.ReadOnly = true; + this.TB_NewSAV.Size = new System.Drawing.Size(169, 20); + this.TB_NewSAV.TabIndex = 5; + this.TB_NewSAV.TextChanged += new System.EventHandler(this.changeSAV); + // + // TB_OldSAV + // + this.TB_OldSAV.Location = new System.Drawing.Point(93, 21); + this.TB_OldSAV.Name = "TB_OldSAV"; + this.TB_OldSAV.ReadOnly = true; + this.TB_OldSAV.Size = new System.Drawing.Size(169, 20); + this.TB_OldSAV.TabIndex = 4; + this.TB_OldSAV.TextChanged += new System.EventHandler(this.changeSAV); + // + // TB_UnSet + // + this.TB_UnSet.Location = new System.Drawing.Point(56, 94); + this.TB_UnSet.Name = "TB_UnSet"; + this.TB_UnSet.ReadOnly = true; + this.TB_UnSet.Size = new System.Drawing.Size(206, 20); + this.TB_UnSet.TabIndex = 3; + // + // TB_IsSet + // + this.TB_IsSet.Location = new System.Drawing.Point(56, 73); + this.TB_IsSet.Name = "TB_IsSet"; + this.TB_IsSet.ReadOnly = true; + this.TB_IsSet.Size = new System.Drawing.Size(206, 20); + this.TB_IsSet.TabIndex = 2; + // + // B_LoadNew + // + this.B_LoadNew.Location = new System.Drawing.Point(12, 45); + this.B_LoadNew.Name = "B_LoadNew"; + this.B_LoadNew.Size = new System.Drawing.Size(75, 23); + this.B_LoadNew.TabIndex = 1; + this.B_LoadNew.Text = "Load New"; + this.B_LoadNew.UseVisualStyleBackColor = true; + this.B_LoadNew.Click += new System.EventHandler(this.openSAV); + // + // B_LoadOld + // + this.B_LoadOld.Location = new System.Drawing.Point(12, 19); + this.B_LoadOld.Name = "B_LoadOld"; + this.B_LoadOld.Size = new System.Drawing.Size(75, 23); + this.B_LoadOld.TabIndex = 0; + this.B_LoadOld.Text = "Load Old"; + this.B_LoadOld.UseVisualStyleBackColor = true; + this.B_LoadOld.Click += new System.EventHandler(this.openSAV); + // + // GB_Flags + // + this.GB_Flags.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left))); + this.GB_Flags.Controls.Add(this.TLP_Flags); + this.GB_Flags.Location = new System.Drawing.Point(12, 12); + this.GB_Flags.Name = "GB_Flags"; + this.GB_Flags.Size = new System.Drawing.Size(212, 210); + this.GB_Flags.TabIndex = 39; + this.GB_Flags.TabStop = false; + this.GB_Flags.Text = "Event Flags"; + // + // GB_Constants + // + this.GB_Constants.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left))); + this.GB_Constants.Controls.Add(this.TLP_Const); + this.GB_Constants.Location = new System.Drawing.Point(235, 12); + this.GB_Constants.Name = "GB_Constants"; + this.GB_Constants.Size = new System.Drawing.Size(212, 210); + this.GB_Constants.TabIndex = 40; + this.GB_Constants.TabStop = false; + this.GB_Constants.Text = "Event Constants"; + // + // TLP_Const + // + this.TLP_Const.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.TLP_Const.AutoScroll = true; + this.TLP_Const.ColumnCount = 2; + this.TLP_Const.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); + this.TLP_Const.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); + this.TLP_Const.Location = new System.Drawing.Point(6, 19); + this.TLP_Const.Name = "TLP_Const"; + this.TLP_Const.RowCount = 1; + this.TLP_Const.RowStyles.Add(new System.Windows.Forms.RowStyle()); + this.TLP_Const.Size = new System.Drawing.Size(200, 184); + this.TLP_Const.TabIndex = 0; + // + // TLP_Flags + // + this.TLP_Flags.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.TLP_Flags.AutoScroll = true; + this.TLP_Flags.ColumnCount = 2; + this.TLP_Flags.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); + this.TLP_Flags.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); + this.TLP_Flags.Location = new System.Drawing.Point(6, 19); + this.TLP_Flags.Name = "TLP_Flags"; + this.TLP_Flags.RowCount = 2; + this.TLP_Flags.RowStyles.Add(new System.Windows.Forms.RowStyle()); + this.TLP_Flags.RowStyles.Add(new System.Windows.Forms.RowStyle()); + this.TLP_Flags.Size = new System.Drawing.Size(200, 184); + this.TLP_Flags.TabIndex = 0; + // + // SAV_EventFlags + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(454, 351); + this.Controls.Add(this.GB_Constants); + this.Controls.Add(this.GB_Flags); + this.Controls.Add(this.GB_Researcher); + this.Controls.Add(this.GB_FlagStatus); + this.Controls.Add(this.B_Save); + this.Controls.Add(this.B_Cancel); + this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); + this.MaximizeBox = false; + this.MaximumSize = new System.Drawing.Size(470, 600); + this.MinimizeBox = false; + this.MinimumSize = new System.Drawing.Size(470, 390); + this.Name = "SAV_EventFlags"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.Text = "Event Flag Editor"; + this.GB_FlagStatus.ResumeLayout(false); + this.GB_FlagStatus.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.nud)).EndInit(); + this.GB_Researcher.ResumeLayout(false); + this.GB_Researcher.PerformLayout(); + this.GB_Flags.ResumeLayout(false); + this.GB_Constants.ResumeLayout(false); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.CheckBox c_CustomFlag; + private System.Windows.Forms.Button B_Cancel; + private System.Windows.Forms.GroupBox GB_FlagStatus; + private System.Windows.Forms.Label CHK_CustomFlag; + private System.Windows.Forms.NumericUpDown nud; + private System.Windows.Forms.Button B_Save; + private System.Windows.Forms.GroupBox GB_Researcher; + private System.Windows.Forms.Label L_UnSet; + private System.Windows.Forms.Label L_IsSet; + private System.Windows.Forms.TextBox TB_NewSAV; + private System.Windows.Forms.TextBox TB_OldSAV; + private System.Windows.Forms.TextBox TB_UnSet; + private System.Windows.Forms.TextBox TB_IsSet; + private System.Windows.Forms.Button B_LoadNew; + private System.Windows.Forms.Button B_LoadOld; + private System.Windows.Forms.Label L_Stats; + private System.Windows.Forms.ComboBox CB_Stats; + private System.Windows.Forms.Label L_Value; + private System.Windows.Forms.MaskedTextBox MT_Stat; + private System.Windows.Forms.GroupBox GB_Flags; + private System.Windows.Forms.GroupBox GB_Constants; + private System.Windows.Forms.TableLayoutPanel TLP_Const; + private System.Windows.Forms.TableLayoutPanel TLP_Flags; + } +} \ No newline at end of file diff --git a/SAV/SAV_EventFlags.cs b/SAV/SAV_EventFlags.cs new file mode 100644 index 000000000..d1fe152b4 --- /dev/null +++ b/SAV/SAV_EventFlags.cs @@ -0,0 +1,358 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.IO; +using System.Linq; +using System.Windows.Forms; + +namespace PKHeX +{ + public partial class SAV_EventFlags : Form + { + public SAV_EventFlags() + { + InitializeComponent(); + + DragEnter += tabMain_DragEnter; + DragDrop += tabMain_DragDrop; + + flags = SAV.EventFlags; + Constants = SAV.EventConsts; + + CB_Stats.Items.Clear(); + for (int i = 0; i < Constants.Length; i++) + CB_Stats.Items.Add(i.ToString()); + + TLP_Flags.Controls.Clear(); + TLP_Const.Controls.Clear(); + addFlagList(getStringList("flags")); + addConstList(getStringList("const")); + + Util.TranslateInterface(this, Main.curlanguage); + + CB_Stats.SelectedIndex = 0; + nud.Maximum = flags.Length - 1; + nud.Text = "0"; + } + + private readonly SaveFile SAV = Main.SAV.Clone(); + private readonly bool[] flags; + private readonly ushort[] Constants; + private const string flagTag = "bool_"; + private const string constTag = "const_"; + private const string flagLabelTag = "flag_"; + private const string constLabelTag = "L_"; + private bool editing; + private int constEntry = -1; + + private void B_Cancel_Click(object sender, EventArgs e) + { + Close(); + } + private void B_Save_Click(object sender, EventArgs e) + { + // Gather Updated Flags + foreach (CheckBox flag in TLP_Flags.Controls) + flags[getControlNum(flag)] = flag.Checked; + SAV.EventFlags = flags; + + // Copy back Constants + changeConstantIndex(null, null); // Trigger Saving + SAV.EventConsts = Constants; + + Close(); + } + + private string[] getStringList(string type) + { + string[] text = null; + if (SAV.ORAS) + text = Util.getStringList($"{type}_oras"); + else if (SAV.XY) + text = Util.getStringList($"{type}_xy"); + return text; + } + private void addFlagList(string[] list) + { + if (list == null || list.Length == 0) + { + TLP_Flags.Controls.Add(new Label { Text = "Needs more research.", Name = "TLP_Flags_Research", ForeColor = Color.Red, AutoSize = true }, 0, 0); + return; + } + + // Get list + List num = new List(); + List desc = new List(); + + foreach (string[] split in list.Select(s => s.Split('\t')).Where(split => split.Length == 2)) + { + try + { + int n = Convert.ToInt32(split[0]); + if (num.Contains(n)) + continue; + num.Add(n); + desc.Add(split[1]); + } catch { } + } + if (num.Count == 0) + { + TLP_Flags.Controls.Add(new Label { Text = "Needs more research.", Name = "TLP_Flags_Research", ForeColor = Color.Red, AutoSize = true }, 0, 0); + return; + } + + for (int i = 0; i < num.Count; i++) + { + var lbl = new Label + { + Text = desc[i], + Name = flagLabelTag + num[i].ToString("0000"), + Margin = Padding.Empty, + AutoSize = true + }; + var chk = new CheckBox + { + Name = flagTag + num[i].ToString("0000"), + CheckAlign = ContentAlignment.MiddleLeft, + Margin = Padding.Empty, + Checked = flags[num[i]], + AutoSize = true + }; + chk.CheckStateChanged += toggleFlag; + TLP_Flags.Controls.Add(chk, 0, i); + TLP_Flags.Controls.Add(lbl, 1, i); + } + } + private void addConstList(string[] list) + { + if (list == null || list.Length == 0) + { + TLP_Const.Controls.Add(new Label { Text = "Needs more research.", Name = "TLP_Const_Research", ForeColor = Color.Red, AutoSize = true }, 0, 0); + return; + } + + // Get list + List num = new List(); + List desc = new List(); + + foreach (string[] split in list.Select(s => s.Split('\t')).Where(split => split.Length == 2)) + { + try + { + int n = Convert.ToInt32(split[0]); + if (num.Contains(n)) + continue; + num.Add(n); + desc.Add(split[1]); + } catch { } + } + if (num.Count == 0) + { + TLP_Const.Controls.Add(new Label { Text = "Needs more research.", Name = "TLP_Const_Research", ForeColor = Color.Red, AutoSize = true }, 0, 0); + return; + } + + for (int i = 0; i < num.Count; i++) + { + var lbl = new Label + { + Text = desc[i], + Name = constLabelTag + num[i].ToString("0000"), + Margin = Padding.Empty, + AutoSize = true + }; + var mtb = new NumericUpDown + { + Maximum = short.MaxValue, + Minimum = short.MinValue, + Value = Constants[num[i]], + Name = constTag + num[i].ToString("0000"), + Margin = Padding.Empty, + Width = 55, + }; + mtb.TextChanged += toggleConst; + TLP_Const.Controls.Add(mtb, 0, i); + TLP_Const.Controls.Add(lbl, 1, i); + } + } + + private int getControlNum(Control chk) + { + try + { + string source = chk.Name; + return Convert.ToInt32(source.Substring(Math.Max(0, source.Length - 4))); + } + catch { return 0; } + } + private void changeCustomBool(object sender, EventArgs e) + { + if (editing) + return; + editing = true; + flags[(int)nud.Value] = c_CustomFlag.Checked; + CheckBox c = TLP_Flags.Controls[flagTag + nud.Value.ToString("0000")] as CheckBox; + if (c != null) + { + c.Checked = c_CustomFlag.Checked; + } + editing = false; + } + private void changeCustomFlag(object sender, EventArgs e) + { + int flag = (int)nud.Value; + if (flag >= flags.Length) + { + c_CustomFlag.Checked = false; + c_CustomFlag.Enabled = false; + nud.BackColor = Color.Red; + } + else + { + c_CustomFlag.Enabled = true; + nud.BackColor = Main.defaultControlWhite; + c_CustomFlag.Checked = flags[flag]; + } + } + private void changeCustomFlag(object sender, KeyEventArgs e) + { + changeCustomFlag(null, (EventArgs)e); + } + private void toggleFlag(object sender, EventArgs e) + { + if (editing) + return; + editing = true; + int flagnum = getControlNum((CheckBox) sender); + flags[flagnum] = ((CheckBox)sender).Checked; + if (nud.Value == flagnum) + c_CustomFlag.Checked = flags[flagnum]; + editing = false; + } + + private void changeCustomConst(object sender, EventArgs e) + { + if (editing) + return; + editing = true; + + editing = true; + Constants[CB_Stats.SelectedIndex] = (ushort)(Util.ToUInt32(((MaskedTextBox)sender).Text) & 0xFFFF); + MaskedTextBox m = TLP_Flags.Controls[constTag + CB_Stats.SelectedIndex.ToString("0000")] as MaskedTextBox; + if (m != null) + m.Text = MT_Stat.Text; + + editing = false; + } + private void changeConstantIndex(object sender, EventArgs e) + { + if (constEntry > -1) // Set Entry + Constants[constEntry] = (ushort)Math.Min(Util.ToUInt32(MT_Stat.Text), 0xFFFF); + + constEntry = CB_Stats.SelectedIndex; // Get Entry + MT_Stat.Text = Constants[constEntry].ToString(); + } + private void toggleConst(object sender, EventArgs e) + { + if (editing) + return; + + editing = true; + int constnum = getControlNum((NumericUpDown)sender); + Constants[constnum] = (ushort)(Util.ToUInt32(((NumericUpDown)sender).Text) & 0xFFFF); + if (constnum == CB_Stats.SelectedIndex) + MT_Stat.Text = Constants[constnum].ToString(); + editing = false; + } + + private void changeSAV(object sender, EventArgs e) + { + if (TB_NewSAV.Text.Length > 0 && TB_OldSAV.Text.Length > 0) + diffSaves(); + } + private void openSAV(object sender, EventArgs e) + { + OpenFileDialog ofd = new OpenFileDialog(); + if (ofd.ShowDialog() == DialogResult.OK) + loadSAV(sender, ofd.FileName); + } + private void loadSAV(object sender, string path) + { + if (sender == B_LoadOld) + TB_OldSAV.Text = path; + else + TB_NewSAV.Text = path; + } + private void diffSaves() + { + if (!File.Exists(TB_OldSAV.Text)) { Util.Alert("Save 1 path invalid."); return; } + if (!File.Exists(TB_NewSAV.Text)) { Util.Alert("Save 2 path invalid."); return; } + if (new FileInfo(TB_OldSAV.Text).Length > 0x100000) { Util.Alert("Save 1 file invalid."); return; } + if (new FileInfo(TB_NewSAV.Text).Length > 0x100000) { Util.Alert("Save 2 file invalid."); return; } + + SaveFile s1 = SaveUtil.getVariantSAV(File.ReadAllBytes(TB_OldSAV.Text)); + SaveFile s2 = SaveUtil.getVariantSAV(File.ReadAllBytes(TB_NewSAV.Text)); + + if (s1.GetType() != s2.GetType()) + { Util.Alert("Save types are different.", $"S1: {s1.GetType()}", $"S2: {s2.GetType()}"); return; } + + string tbIsSet = ""; + string tbUnSet = ""; + try + { + bool[] oldBits = s1.EventFlags; + bool[] newBits = s2.EventFlags; + if (oldBits.Length != newBits.Length) + { Util.Alert("Event flag lengths for games are different.", $"S1: {(GameVersion)s1.Game}", $"S2: {(GameVersion)s2.Game}"); return; } + + for (int i = 0; i < oldBits.Length; i++) + { + if (oldBits[i] == newBits[i]) continue; + if (newBits[i]) + tbIsSet += i.ToString("0000") + ","; + else + tbUnSet += i.ToString("0000") + ","; + } + } + catch (Exception e) + { + Util.Error(e.ToString()); + Console.Write(e); + } + TB_IsSet.Text = tbIsSet; + TB_UnSet.Text = tbUnSet; + + string r = ""; + try + { + ushort[] oldConst = s1.EventConsts; + ushort[] newConst = s2.EventConsts; + if (oldConst.Length != newConst.Length) + { Util.Alert("Event flag lengths for games are different.", $"S1: {(GameVersion)s1.Game}", $"S2: {(GameVersion)s2.Game}"); return; } + + for (int i = 0; i < newConst.Length; i++) + if (oldConst[i] != newConst[i]) + r += $"{i}: {oldConst[i]}->{newConst[i]}{Environment.NewLine}"; + } + catch (Exception e) + { + Util.Error(e.ToString()); + Console.Write(e); + } + + if (DialogResult.Yes != Util.Prompt(MessageBoxButtons.YesNo, "Copy Event Constant diff to clipboard?")) + return; + Clipboard.SetText(r); + } + + private void tabMain_DragEnter(object sender, DragEventArgs e) + { + if (e.Data.GetDataPresent(DataFormats.FileDrop)) e.Effect = DragDropEffects.Copy; + } + private void tabMain_DragDrop(object sender, DragEventArgs e) + { + string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); + loadSAV(Util.Prompt(MessageBoxButtons.YesNo, "FlagDiff Researcher:", "Yes: Old Save" + Environment.NewLine + "No: New Save") == DialogResult.Yes ? B_LoadOld : B_LoadNew, files[0]); + } + } +} \ No newline at end of file diff --git a/SAV/SAV_BerryFieldORAS.resx b/SAV/SAV_EventFlags.resx similarity index 100% rename from SAV/SAV_BerryFieldORAS.resx rename to SAV/SAV_EventFlags.resx diff --git a/SAV/SAV_EventFlagsORAS.Designer.cs b/SAV/SAV_EventFlagsORAS.Designer.cs deleted file mode 100644 index ca011b807..000000000 --- a/SAV/SAV_EventFlagsORAS.Designer.cs +++ /dev/null @@ -1,1378 +0,0 @@ -namespace PKHeX -{ - partial class SAV_EventFlagsORAS - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(SAV_EventFlagsORAS)); - this.CHK_CustomFlag = new System.Windows.Forms.CheckBox(); - this.B_Cancel = new System.Windows.Forms.Button(); - this.GB_FlagStatus = new System.Windows.Forms.GroupBox(); - this.nud = new System.Windows.Forms.NumericUpDown(); - this.L_Flag = new System.Windows.Forms.Label(); - this.B_Save = new System.Windows.Forms.Button(); - this.GB_Researcher = new System.Windows.Forms.GroupBox(); - this.L_UnSet = new System.Windows.Forms.Label(); - this.L_IsSet = new System.Windows.Forms.Label(); - this.TB_NewSAV = new System.Windows.Forms.TextBox(); - this.TB_OldSAV = new System.Windows.Forms.TextBox(); - this.TB_UnSet = new System.Windows.Forms.TextBox(); - this.TB_IsSet = new System.Windows.Forms.TextBox(); - this.B_LoadNew = new System.Windows.Forms.Button(); - this.B_LoadOld = new System.Windows.Forms.Button(); - this.flag_0647 = new System.Windows.Forms.CheckBox(); - this.flag_2840 = new System.Windows.Forms.CheckBox(); - this.GB_Rebattle = new System.Windows.Forms.GroupBox(); - this.flag_2835 = new System.Windows.Forms.CheckBox(); - this.flag_0420 = new System.Windows.Forms.CheckBox(); - this.L_SkyTower = new System.Windows.Forms.Label(); - this.flag_2834 = new System.Windows.Forms.CheckBox(); - this.flag_0419 = new System.Windows.Forms.CheckBox(); - this.flag_2828 = new System.Windows.Forms.CheckBox(); - this.flag_2830 = new System.Windows.Forms.CheckBox(); - this.flag_0182 = new System.Windows.Forms.CheckBox(); - this.flag_2820 = new System.Windows.Forms.CheckBox(); - this.flag_2839 = new System.Windows.Forms.CheckBox(); - this.flag_0648 = new System.Windows.Forms.CheckBox(); - this.flag_2815 = new System.Windows.Forms.CheckBox(); - this.flag_0208 = new System.Windows.Forms.CheckBox(); - this.flag_2824 = new System.Windows.Forms.CheckBox(); - this.flag_0172 = new System.Windows.Forms.CheckBox(); - this.flag_2821 = new System.Windows.Forms.CheckBox(); - this.flag_0260 = new System.Windows.Forms.CheckBox(); - this.flag_2842 = new System.Windows.Forms.CheckBox(); - this.flag_0945 = new System.Windows.Forms.CheckBox(); - this.flag_2838 = new System.Windows.Forms.CheckBox(); - this.flag_0958 = new System.Windows.Forms.CheckBox(); - this.flag_2836 = new System.Windows.Forms.CheckBox(); - this.flag_0956 = new System.Windows.Forms.CheckBox(); - this.flag_2837 = new System.Windows.Forms.CheckBox(); - this.flag_0957 = new System.Windows.Forms.CheckBox(); - this.flag_2813 = new System.Windows.Forms.CheckBox(); - this.flag_0175 = new System.Windows.Forms.CheckBox(); - this.flag_2811 = new System.Windows.Forms.CheckBox(); - this.flag_0173 = new System.Windows.Forms.CheckBox(); - this.flag_2812 = new System.Windows.Forms.CheckBox(); - this.flag_0174 = new System.Windows.Forms.CheckBox(); - this.flag_2832 = new System.Windows.Forms.CheckBox(); - this.flag_2829 = new System.Windows.Forms.CheckBox(); - this.flag_2822 = new System.Windows.Forms.CheckBox(); - this.flag_0252 = new System.Windows.Forms.CheckBox(); - this.flag_2827 = new System.Windows.Forms.CheckBox(); - this.flag_0178 = new System.Windows.Forms.CheckBox(); - this.flag_2826 = new System.Windows.Forms.CheckBox(); - this.flag_0177 = new System.Windows.Forms.CheckBox(); - this.flag_2823 = new System.Windows.Forms.CheckBox(); - this.flag_2819 = new System.Windows.Forms.CheckBox(); - this.flag_2833 = new System.Windows.Forms.CheckBox(); - this.flag_0184 = new System.Windows.Forms.CheckBox(); - this.flag_2816 = new System.Windows.Forms.CheckBox(); - this.flag_0179 = new System.Windows.Forms.CheckBox(); - this.flag_2817 = new System.Windows.Forms.CheckBox(); - this.flag_0180 = new System.Windows.Forms.CheckBox(); - this.flag_2825 = new System.Windows.Forms.CheckBox(); - this.flag_0176 = new System.Windows.Forms.CheckBox(); - this.flag_2814 = new System.Windows.Forms.CheckBox(); - this.flag_0209 = new System.Windows.Forms.CheckBox(); - this.flag_2818 = new System.Windows.Forms.CheckBox(); - this.flag_0181 = new System.Windows.Forms.CheckBox(); - this.flag_2831 = new System.Windows.Forms.CheckBox(); - this.flag_0183 = new System.Windows.Forms.CheckBox(); - this.GB_Misc = new System.Windows.Forms.GroupBox(); - this.flag_0288 = new System.Windows.Forms.CheckBox(); - this.flag_0287 = new System.Windows.Forms.CheckBox(); - this.flag_0286 = new System.Windows.Forms.CheckBox(); - this.flag_0293 = new System.Windows.Forms.CheckBox(); - this.flag_0292 = new System.Windows.Forms.CheckBox(); - this.flag_0291 = new System.Windows.Forms.CheckBox(); - this.flag_0290 = new System.Windows.Forms.CheckBox(); - this.flag_0289 = new System.Windows.Forms.CheckBox(); - this.flag_0285 = new System.Windows.Forms.CheckBox(); - this.flag_0284 = new System.Windows.Forms.CheckBox(); - this.MT_Ash = new System.Windows.Forms.MaskedTextBox(); - this.L_Ash = new System.Windows.Forms.Label(); - this.L_Stats = new System.Windows.Forms.Label(); - this.CB_Stats = new System.Windows.Forms.ComboBox(); - this.L_Value = new System.Windows.Forms.Label(); - this.MT_Stat = new System.Windows.Forms.MaskedTextBox(); - this.GB_FlagStatus.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.nud)).BeginInit(); - this.GB_Researcher.SuspendLayout(); - this.GB_Rebattle.SuspendLayout(); - this.GB_Misc.SuspendLayout(); - this.SuspendLayout(); - // - // CHK_CustomFlag - // - this.CHK_CustomFlag.AutoSize = true; - this.CHK_CustomFlag.CheckAlign = System.Drawing.ContentAlignment.MiddleRight; - this.CHK_CustomFlag.Enabled = false; - this.CHK_CustomFlag.Location = new System.Drawing.Point(12, 44); - this.CHK_CustomFlag.Name = "CHK_CustomFlag"; - this.CHK_CustomFlag.Size = new System.Drawing.Size(59, 17); - this.CHK_CustomFlag.TabIndex = 1; - this.CHK_CustomFlag.Text = "Status:"; - this.CHK_CustomFlag.UseVisualStyleBackColor = true; - this.CHK_CustomFlag.CheckedChanged += new System.EventHandler(this.changeCustomBool); - // - // B_Cancel - // - this.B_Cancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.B_Cancel.Location = new System.Drawing.Point(507, 475); - this.B_Cancel.Name = "B_Cancel"; - this.B_Cancel.Size = new System.Drawing.Size(75, 23); - this.B_Cancel.TabIndex = 2; - this.B_Cancel.Text = "Cancel"; - this.B_Cancel.UseVisualStyleBackColor = true; - this.B_Cancel.Click += new System.EventHandler(this.B_Cancel_Click); - // - // GB_FlagStatus - // - this.GB_FlagStatus.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.GB_FlagStatus.Controls.Add(this.nud); - this.GB_FlagStatus.Controls.Add(this.L_Flag); - this.GB_FlagStatus.Controls.Add(this.CHK_CustomFlag); - this.GB_FlagStatus.Location = new System.Drawing.Point(314, 436); - this.GB_FlagStatus.Name = "GB_FlagStatus"; - this.GB_FlagStatus.Size = new System.Drawing.Size(108, 68); - this.GB_FlagStatus.TabIndex = 3; - this.GB_FlagStatus.TabStop = false; - this.GB_FlagStatus.Text = "Check Flag Status"; - // - // nud - // - this.nud.Location = new System.Drawing.Point(56, 19); - this.nud.Maximum = new decimal(new int[] { - 3072, - 0, - 0, - 0}); - this.nud.Name = "nud"; - this.nud.Size = new System.Drawing.Size(45, 20); - this.nud.TabIndex = 9; - this.nud.Value = new decimal(new int[] { - 3071, - 0, - 0, - 0}); - this.nud.ValueChanged += new System.EventHandler(this.changeCustomFlag); - this.nud.KeyUp += new System.Windows.Forms.KeyEventHandler(this.changeCustomFlag); - // - // L_Flag - // - this.L_Flag.AutoSize = true; - this.L_Flag.Location = new System.Drawing.Point(13, 21); - this.L_Flag.Name = "L_Flag"; - this.L_Flag.Size = new System.Drawing.Size(30, 13); - this.L_Flag.TabIndex = 2; - this.L_Flag.Text = "Flag:"; - // - // B_Save - // - this.B_Save.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.B_Save.Location = new System.Drawing.Point(507, 446); - this.B_Save.Name = "B_Save"; - this.B_Save.Size = new System.Drawing.Size(75, 23); - this.B_Save.TabIndex = 9; - this.B_Save.Text = "Save"; - this.B_Save.UseVisualStyleBackColor = true; - this.B_Save.Click += new System.EventHandler(this.B_Save_Click); - // - // GB_Researcher - // - this.GB_Researcher.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.GB_Researcher.Controls.Add(this.L_UnSet); - this.GB_Researcher.Controls.Add(this.L_IsSet); - this.GB_Researcher.Controls.Add(this.TB_NewSAV); - this.GB_Researcher.Controls.Add(this.TB_OldSAV); - this.GB_Researcher.Controls.Add(this.TB_UnSet); - this.GB_Researcher.Controls.Add(this.TB_IsSet); - this.GB_Researcher.Controls.Add(this.B_LoadNew); - this.GB_Researcher.Controls.Add(this.B_LoadOld); - this.GB_Researcher.Location = new System.Drawing.Point(314, 309); - this.GB_Researcher.Name = "GB_Researcher"; - this.GB_Researcher.Size = new System.Drawing.Size(268, 120); - this.GB_Researcher.TabIndex = 13; - this.GB_Researcher.TabStop = false; - this.GB_Researcher.Text = "FlagDiff Researcher"; - // - // L_UnSet - // - this.L_UnSet.AutoSize = true; - this.L_UnSet.Location = new System.Drawing.Point(10, 97); - this.L_UnSet.Name = "L_UnSet"; - this.L_UnSet.Size = new System.Drawing.Size(37, 13); - this.L_UnSet.TabIndex = 7; - this.L_UnSet.Text = "UnSet"; - // - // L_IsSet - // - this.L_IsSet.AutoSize = true; - this.L_IsSet.Location = new System.Drawing.Point(12, 77); - this.L_IsSet.Name = "L_IsSet"; - this.L_IsSet.Size = new System.Drawing.Size(31, 13); - this.L_IsSet.TabIndex = 6; - this.L_IsSet.Text = "IsSet"; - // - // TB_NewSAV - // - this.TB_NewSAV.Location = new System.Drawing.Point(93, 47); - this.TB_NewSAV.Name = "TB_NewSAV"; - this.TB_NewSAV.ReadOnly = true; - this.TB_NewSAV.Size = new System.Drawing.Size(169, 20); - this.TB_NewSAV.TabIndex = 5; - this.TB_NewSAV.TextChanged += new System.EventHandler(this.changeSAV); - // - // TB_OldSAV - // - this.TB_OldSAV.Location = new System.Drawing.Point(93, 21); - this.TB_OldSAV.Name = "TB_OldSAV"; - this.TB_OldSAV.ReadOnly = true; - this.TB_OldSAV.Size = new System.Drawing.Size(169, 20); - this.TB_OldSAV.TabIndex = 4; - this.TB_OldSAV.TextChanged += new System.EventHandler(this.changeSAV); - // - // TB_UnSet - // - this.TB_UnSet.Location = new System.Drawing.Point(56, 94); - this.TB_UnSet.Name = "TB_UnSet"; - this.TB_UnSet.ReadOnly = true; - this.TB_UnSet.Size = new System.Drawing.Size(206, 20); - this.TB_UnSet.TabIndex = 3; - // - // TB_IsSet - // - this.TB_IsSet.Location = new System.Drawing.Point(56, 74); - this.TB_IsSet.Name = "TB_IsSet"; - this.TB_IsSet.ReadOnly = true; - this.TB_IsSet.Size = new System.Drawing.Size(206, 20); - this.TB_IsSet.TabIndex = 2; - // - // B_LoadNew - // - this.B_LoadNew.Location = new System.Drawing.Point(12, 45); - this.B_LoadNew.Name = "B_LoadNew"; - this.B_LoadNew.Size = new System.Drawing.Size(75, 23); - this.B_LoadNew.TabIndex = 1; - this.B_LoadNew.Text = "Load New"; - this.B_LoadNew.UseVisualStyleBackColor = true; - this.B_LoadNew.Click += new System.EventHandler(this.openSAV); - // - // B_LoadOld - // - this.B_LoadOld.Location = new System.Drawing.Point(12, 19); - this.B_LoadOld.Name = "B_LoadOld"; - this.B_LoadOld.Size = new System.Drawing.Size(75, 23); - this.B_LoadOld.TabIndex = 0; - this.B_LoadOld.Text = "Load Old"; - this.B_LoadOld.UseVisualStyleBackColor = true; - this.B_LoadOld.Click += new System.EventHandler(this.openSAV); - // - // flag_0647 - // - this.flag_0647.AutoSize = true; - this.flag_0647.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_0647.Location = new System.Drawing.Point(15, 47); - this.flag_0647.Name = "flag_0647"; - this.flag_0647.Size = new System.Drawing.Size(129, 17); - this.flag_0647.TabIndex = 14; - this.flag_0647.Text = "(AS) Kyogre Defeated"; - this.flag_0647.UseVisualStyleBackColor = true; - this.flag_0647.Click += new System.EventHandler(this.toggleFlag); - // - // flag_2840 - // - this.flag_2840.AutoSize = true; - this.flag_2840.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_2840.Location = new System.Drawing.Point(15, 62); - this.flag_2840.Name = "flag_2840"; - this.flag_2840.Size = new System.Drawing.Size(128, 17); - this.flag_2840.TabIndex = 15; - this.flag_2840.Text = "(AS) Kyogre Captured"; - this.flag_2840.UseVisualStyleBackColor = true; - this.flag_2840.Click += new System.EventHandler(this.toggleFlag); - // - // GB_Rebattle - // - this.GB_Rebattle.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.GB_Rebattle.Controls.Add(this.flag_2835); - this.GB_Rebattle.Controls.Add(this.flag_0420); - this.GB_Rebattle.Controls.Add(this.L_SkyTower); - this.GB_Rebattle.Controls.Add(this.flag_2834); - this.GB_Rebattle.Controls.Add(this.flag_0419); - this.GB_Rebattle.Controls.Add(this.flag_2828); - this.GB_Rebattle.Controls.Add(this.flag_2830); - this.GB_Rebattle.Controls.Add(this.flag_0182); - this.GB_Rebattle.Controls.Add(this.flag_2820); - this.GB_Rebattle.Controls.Add(this.flag_2839); - this.GB_Rebattle.Controls.Add(this.flag_0648); - this.GB_Rebattle.Controls.Add(this.flag_2815); - this.GB_Rebattle.Controls.Add(this.flag_0208); - this.GB_Rebattle.Controls.Add(this.flag_2824); - this.GB_Rebattle.Controls.Add(this.flag_0172); - this.GB_Rebattle.Controls.Add(this.flag_2821); - this.GB_Rebattle.Controls.Add(this.flag_0260); - this.GB_Rebattle.Controls.Add(this.flag_2842); - this.GB_Rebattle.Controls.Add(this.flag_0945); - this.GB_Rebattle.Controls.Add(this.flag_2838); - this.GB_Rebattle.Controls.Add(this.flag_0958); - this.GB_Rebattle.Controls.Add(this.flag_2836); - this.GB_Rebattle.Controls.Add(this.flag_0956); - this.GB_Rebattle.Controls.Add(this.flag_2837); - this.GB_Rebattle.Controls.Add(this.flag_0957); - this.GB_Rebattle.Controls.Add(this.flag_2813); - this.GB_Rebattle.Controls.Add(this.flag_0175); - this.GB_Rebattle.Controls.Add(this.flag_2811); - this.GB_Rebattle.Controls.Add(this.flag_0173); - this.GB_Rebattle.Controls.Add(this.flag_2812); - this.GB_Rebattle.Controls.Add(this.flag_0174); - this.GB_Rebattle.Controls.Add(this.flag_2832); - this.GB_Rebattle.Controls.Add(this.flag_2829); - this.GB_Rebattle.Controls.Add(this.flag_2822); - this.GB_Rebattle.Controls.Add(this.flag_0252); - this.GB_Rebattle.Controls.Add(this.flag_2827); - this.GB_Rebattle.Controls.Add(this.flag_0178); - this.GB_Rebattle.Controls.Add(this.flag_2826); - this.GB_Rebattle.Controls.Add(this.flag_0177); - this.GB_Rebattle.Controls.Add(this.flag_2823); - this.GB_Rebattle.Controls.Add(this.flag_2819); - this.GB_Rebattle.Controls.Add(this.flag_2833); - this.GB_Rebattle.Controls.Add(this.flag_0184); - this.GB_Rebattle.Controls.Add(this.flag_2816); - this.GB_Rebattle.Controls.Add(this.flag_0179); - this.GB_Rebattle.Controls.Add(this.flag_2817); - this.GB_Rebattle.Controls.Add(this.flag_0180); - this.GB_Rebattle.Controls.Add(this.flag_2825); - this.GB_Rebattle.Controls.Add(this.flag_0176); - this.GB_Rebattle.Controls.Add(this.flag_2814); - this.GB_Rebattle.Controls.Add(this.flag_0209); - this.GB_Rebattle.Controls.Add(this.flag_2818); - this.GB_Rebattle.Controls.Add(this.flag_0181); - this.GB_Rebattle.Controls.Add(this.flag_2831); - this.GB_Rebattle.Controls.Add(this.flag_0183); - this.GB_Rebattle.Controls.Add(this.flag_2840); - this.GB_Rebattle.Controls.Add(this.flag_0647); - this.GB_Rebattle.Location = new System.Drawing.Point(8, 9); - this.GB_Rebattle.Name = "GB_Rebattle"; - this.GB_Rebattle.Size = new System.Drawing.Size(300, 495); - this.GB_Rebattle.TabIndex = 16; - this.GB_Rebattle.TabStop = false; - this.GB_Rebattle.Text = "Rebattle"; - // - // flag_2835 - // - this.flag_2835.AutoSize = true; - this.flag_2835.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_2835.Location = new System.Drawing.Point(172, 108); - this.flag_2835.Name = "flag_2835"; - this.flag_2835.Size = new System.Drawing.Size(123, 17); - this.flag_2835.TabIndex = 75; - this.flag_2835.Text = "(AS) Latios Captured"; - this.flag_2835.UseVisualStyleBackColor = true; - this.flag_2835.Click += new System.EventHandler(this.toggleFlag); - // - // flag_0420 - // - this.flag_0420.AutoSize = true; - this.flag_0420.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_0420.Location = new System.Drawing.Point(172, 93); - this.flag_0420.Name = "flag_0420"; - this.flag_0420.Size = new System.Drawing.Size(124, 17); - this.flag_0420.TabIndex = 74; - this.flag_0420.Text = "(AS) Latios Defeated"; - this.flag_0420.UseVisualStyleBackColor = true; - this.flag_0420.Click += new System.EventHandler(this.toggleFlag); - // - // L_SkyTower - // - this.L_SkyTower.AutoSize = true; - this.L_SkyTower.Location = new System.Drawing.Point(215, 12); - this.L_SkyTower.Name = "L_SkyTower"; - this.L_SkyTower.Size = new System.Drawing.Size(62, 13); - this.L_SkyTower.TabIndex = 20; - this.L_SkyTower.Text = "*Sky Tower"; - // - // flag_2834 - // - this.flag_2834.AutoSize = true; - this.flag_2834.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_2834.Location = new System.Drawing.Point(172, 77); - this.flag_2834.Name = "flag_2834"; - this.flag_2834.Size = new System.Drawing.Size(125, 17); - this.flag_2834.TabIndex = 73; - this.flag_2834.Text = "(OR) Latias Captured"; - this.flag_2834.UseVisualStyleBackColor = true; - this.flag_2834.Click += new System.EventHandler(this.toggleFlag); - // - // flag_0419 - // - this.flag_0419.AutoSize = true; - this.flag_0419.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_0419.Location = new System.Drawing.Point(172, 62); - this.flag_0419.Name = "flag_0419"; - this.flag_0419.Size = new System.Drawing.Size(126, 17); - this.flag_0419.TabIndex = 72; - this.flag_0419.Text = "(OR) Latias Defeated"; - this.flag_0419.UseVisualStyleBackColor = true; - this.flag_0419.Click += new System.EventHandler(this.toggleFlag); - // - // flag_2828 - // - this.flag_2828.AutoSize = true; - this.flag_2828.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_2828.Location = new System.Drawing.Point(15, 191); - this.flag_2828.Name = "flag_2828"; - this.flag_2828.Size = new System.Drawing.Size(142, 17); - this.flag_2828.TabIndex = 71; - this.flag_2828.Text = "(OR) Tornadus Captured"; - this.flag_2828.UseVisualStyleBackColor = true; - this.flag_2828.Click += new System.EventHandler(this.toggleFlag); - // - // flag_2830 - // - this.flag_2830.AutoSize = true; - this.flag_2830.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_2830.Location = new System.Drawing.Point(15, 244); - this.flag_2830.Name = "flag_2830"; - this.flag_2830.Size = new System.Drawing.Size(141, 17); - this.flag_2830.TabIndex = 69; - this.flag_2830.Text = "(OR) Reshiram Captured"; - this.flag_2830.UseVisualStyleBackColor = true; - this.flag_2830.Click += new System.EventHandler(this.toggleFlag); - // - // flag_0182 - // - this.flag_0182.AutoSize = true; - this.flag_0182.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_0182.Location = new System.Drawing.Point(15, 229); - this.flag_0182.Name = "flag_0182"; - this.flag_0182.Size = new System.Drawing.Size(142, 17); - this.flag_0182.TabIndex = 68; - this.flag_0182.Text = "(OR) Reshiram Defeated"; - this.flag_0182.UseVisualStyleBackColor = true; - this.flag_0182.Click += new System.EventHandler(this.toggleFlag); - // - // flag_2820 - // - this.flag_2820.AutoSize = true; - this.flag_2820.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_2820.Location = new System.Drawing.Point(15, 153); - this.flag_2820.Name = "flag_2820"; - this.flag_2820.Size = new System.Drawing.Size(126, 17); - this.flag_2820.TabIndex = 67; - this.flag_2820.Text = "(OR) Palkia Captured"; - this.flag_2820.UseVisualStyleBackColor = true; - this.flag_2820.Click += new System.EventHandler(this.toggleFlag); - // - // flag_2839 - // - this.flag_2839.AutoSize = true; - this.flag_2839.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_2839.Location = new System.Drawing.Point(15, 32); - this.flag_2839.Name = "flag_2839"; - this.flag_2839.Size = new System.Drawing.Size(138, 17); - this.flag_2839.TabIndex = 65; - this.flag_2839.Text = "(OR) Groudon Captured"; - this.flag_2839.UseVisualStyleBackColor = true; - this.flag_2839.Click += new System.EventHandler(this.toggleFlag); - // - // flag_0648 - // - this.flag_0648.AutoSize = true; - this.flag_0648.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_0648.Location = new System.Drawing.Point(15, 17); - this.flag_0648.Name = "flag_0648"; - this.flag_0648.Size = new System.Drawing.Size(139, 17); - this.flag_0648.TabIndex = 64; - this.flag_0648.Text = "(OR) Groudon Defeated"; - this.flag_0648.UseVisualStyleBackColor = true; - this.flag_0648.Click += new System.EventHandler(this.toggleFlag); - // - // flag_2815 - // - this.flag_2815.AutoSize = true; - this.flag_2815.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_2815.Location = new System.Drawing.Point(15, 100); - this.flag_2815.Name = "flag_2815"; - this.flag_2815.Size = new System.Drawing.Size(128, 17); - this.flag_2815.TabIndex = 63; - this.flag_2815.Text = "(OR) Ho-Oh Captured"; - this.flag_2815.UseVisualStyleBackColor = true; - this.flag_2815.Click += new System.EventHandler(this.toggleFlag); - // - // flag_0208 - // - this.flag_0208.AutoSize = true; - this.flag_0208.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_0208.Location = new System.Drawing.Point(15, 85); - this.flag_0208.Name = "flag_0208"; - this.flag_0208.Size = new System.Drawing.Size(129, 17); - this.flag_0208.TabIndex = 62; - this.flag_0208.Text = "(OR) Ho-Oh Defeated"; - this.flag_0208.UseVisualStyleBackColor = true; - this.flag_0208.Click += new System.EventHandler(this.toggleFlag); - // - // flag_2824 - // - this.flag_2824.AutoSize = true; - this.flag_2824.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_2824.Location = new System.Drawing.Point(172, 178); - this.flag_2824.Name = "flag_2824"; - this.flag_2824.Size = new System.Drawing.Size(114, 17); - this.flag_2824.TabIndex = 61; - this.flag_2824.Text = "Cresselia Captured"; - this.flag_2824.UseVisualStyleBackColor = true; - this.flag_2824.Click += new System.EventHandler(this.toggleFlag); - // - // flag_0172 - // - this.flag_0172.AutoSize = true; - this.flag_0172.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_0172.Location = new System.Drawing.Point(172, 163); - this.flag_0172.Name = "flag_0172"; - this.flag_0172.Size = new System.Drawing.Size(115, 17); - this.flag_0172.TabIndex = 60; - this.flag_0172.Text = "Cresselia Defeated"; - this.flag_0172.UseVisualStyleBackColor = true; - this.flag_0172.Click += new System.EventHandler(this.toggleFlag); - // - // flag_2821 - // - this.flag_2821.AutoSize = true; - this.flag_2821.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_2821.Location = new System.Drawing.Point(172, 146); - this.flag_2821.Name = "flag_2821"; - this.flag_2821.Size = new System.Drawing.Size(110, 17); - this.flag_2821.TabIndex = 59; - this.flag_2821.Text = "Heatran Captured"; - this.flag_2821.UseVisualStyleBackColor = true; - this.flag_2821.Click += new System.EventHandler(this.toggleFlag); - // - // flag_0260 - // - this.flag_0260.AutoSize = true; - this.flag_0260.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_0260.Location = new System.Drawing.Point(172, 131); - this.flag_0260.Name = "flag_0260"; - this.flag_0260.Size = new System.Drawing.Size(111, 17); - this.flag_0260.TabIndex = 58; - this.flag_0260.Text = "Heatran Defeated"; - this.flag_0260.UseVisualStyleBackColor = true; - this.flag_0260.Click += new System.EventHandler(this.toggleFlag); - // - // flag_2842 - // - this.flag_2842.AutoSize = true; - this.flag_2842.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_2842.Location = new System.Drawing.Point(172, 40); - this.flag_2842.Name = "flag_2842"; - this.flag_2842.Size = new System.Drawing.Size(107, 17); - this.flag_2842.TabIndex = 57; - this.flag_2842.Text = "Deoxys Captured"; - this.flag_2842.UseVisualStyleBackColor = true; - this.flag_2842.Click += new System.EventHandler(this.toggleFlag); - // - // flag_0945 - // - this.flag_0945.AutoSize = true; - this.flag_0945.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_0945.Location = new System.Drawing.Point(172, 25); - this.flag_0945.Name = "flag_0945"; - this.flag_0945.Size = new System.Drawing.Size(108, 17); - this.flag_0945.TabIndex = 56; - this.flag_0945.Text = "Deoxys Defeated"; - this.flag_0945.UseVisualStyleBackColor = true; - this.flag_0945.Click += new System.EventHandler(this.toggleFlag); - // - // flag_2838 - // - this.flag_2838.AutoSize = true; - this.flag_2838.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_2838.Location = new System.Drawing.Point(172, 372); - this.flag_2838.Name = "flag_2838"; - this.flag_2838.Size = new System.Drawing.Size(116, 17); - this.flag_2838.TabIndex = 55; - this.flag_2838.Text = "Registeel Captured"; - this.flag_2838.UseVisualStyleBackColor = true; - this.flag_2838.Click += new System.EventHandler(this.toggleFlag); - // - // flag_0958 - // - this.flag_0958.AutoSize = true; - this.flag_0958.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_0958.Location = new System.Drawing.Point(172, 357); - this.flag_0958.Name = "flag_0958"; - this.flag_0958.Size = new System.Drawing.Size(117, 17); - this.flag_0958.TabIndex = 54; - this.flag_0958.Text = "Registeel Defeated"; - this.flag_0958.UseVisualStyleBackColor = true; - this.flag_0958.Click += new System.EventHandler(this.toggleFlag); - // - // flag_2836 - // - this.flag_2836.AutoSize = true; - this.flag_2836.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_2836.Location = new System.Drawing.Point(172, 342); - this.flag_2836.Name = "flag_2836"; - this.flag_2836.Size = new System.Drawing.Size(115, 17); - this.flag_2836.TabIndex = 53; - this.flag_2836.Text = "Regirock Captured"; - this.flag_2836.UseVisualStyleBackColor = true; - this.flag_2836.Click += new System.EventHandler(this.toggleFlag); - // - // flag_0956 - // - this.flag_0956.AutoSize = true; - this.flag_0956.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_0956.Location = new System.Drawing.Point(172, 327); - this.flag_0956.Name = "flag_0956"; - this.flag_0956.Size = new System.Drawing.Size(116, 17); - this.flag_0956.TabIndex = 52; - this.flag_0956.Text = "Regirock Defeated"; - this.flag_0956.UseVisualStyleBackColor = true; - this.flag_0956.Click += new System.EventHandler(this.toggleFlag); - // - // flag_2837 - // - this.flag_2837.AutoSize = true; - this.flag_2837.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_2837.Location = new System.Drawing.Point(172, 312); - this.flag_2837.Name = "flag_2837"; - this.flag_2837.Size = new System.Drawing.Size(106, 17); - this.flag_2837.TabIndex = 51; - this.flag_2837.Text = "Regice Captured"; - this.flag_2837.UseVisualStyleBackColor = true; - this.flag_2837.Click += new System.EventHandler(this.toggleFlag); - // - // flag_0957 - // - this.flag_0957.AutoSize = true; - this.flag_0957.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_0957.Location = new System.Drawing.Point(172, 297); - this.flag_0957.Name = "flag_0957"; - this.flag_0957.Size = new System.Drawing.Size(107, 17); - this.flag_0957.TabIndex = 50; - this.flag_0957.Text = "Regice Defeated"; - this.flag_0957.UseVisualStyleBackColor = true; - this.flag_0957.Click += new System.EventHandler(this.toggleFlag); - // - // flag_2813 - // - this.flag_2813.AutoSize = true; - this.flag_2813.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_2813.Location = new System.Drawing.Point(15, 372); - this.flag_2813.Name = "flag_2813"; - this.flag_2813.Size = new System.Drawing.Size(111, 17); - this.flag_2813.TabIndex = 49; - this.flag_2813.Text = "Suicune Captured"; - this.flag_2813.UseVisualStyleBackColor = true; - this.flag_2813.Click += new System.EventHandler(this.toggleFlag); - // - // flag_0175 - // - this.flag_0175.AutoSize = true; - this.flag_0175.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_0175.Location = new System.Drawing.Point(15, 357); - this.flag_0175.Name = "flag_0175"; - this.flag_0175.Size = new System.Drawing.Size(112, 17); - this.flag_0175.TabIndex = 48; - this.flag_0175.Text = "Suicune Defeated"; - this.flag_0175.UseVisualStyleBackColor = true; - this.flag_0175.Click += new System.EventHandler(this.toggleFlag); - // - // flag_2811 - // - this.flag_2811.AutoSize = true; - this.flag_2811.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_2811.Location = new System.Drawing.Point(15, 342); - this.flag_2811.Name = "flag_2811"; - this.flag_2811.Size = new System.Drawing.Size(106, 17); - this.flag_2811.TabIndex = 47; - this.flag_2811.Text = "Raikou Captured"; - this.flag_2811.UseVisualStyleBackColor = true; - this.flag_2811.Click += new System.EventHandler(this.toggleFlag); - // - // flag_0173 - // - this.flag_0173.AutoSize = true; - this.flag_0173.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_0173.Location = new System.Drawing.Point(15, 327); - this.flag_0173.Name = "flag_0173"; - this.flag_0173.Size = new System.Drawing.Size(107, 17); - this.flag_0173.TabIndex = 46; - this.flag_0173.Text = "Raikou Defeated"; - this.flag_0173.UseVisualStyleBackColor = true; - this.flag_0173.Click += new System.EventHandler(this.toggleFlag); - // - // flag_2812 - // - this.flag_2812.AutoSize = true; - this.flag_2812.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_2812.Location = new System.Drawing.Point(15, 312); - this.flag_2812.Name = "flag_2812"; - this.flag_2812.Size = new System.Drawing.Size(96, 17); - this.flag_2812.TabIndex = 45; - this.flag_2812.Text = "Entei Captured"; - this.flag_2812.UseVisualStyleBackColor = true; - this.flag_2812.Click += new System.EventHandler(this.toggleFlag); - // - // flag_0174 - // - this.flag_0174.AutoSize = true; - this.flag_0174.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_0174.Location = new System.Drawing.Point(15, 297); - this.flag_0174.Name = "flag_0174"; - this.flag_0174.Size = new System.Drawing.Size(97, 17); - this.flag_0174.TabIndex = 44; - this.flag_0174.Text = "Entei Defeated"; - this.flag_0174.UseVisualStyleBackColor = true; - this.flag_0174.Click += new System.EventHandler(this.toggleFlag); - // - // flag_2832 - // - this.flag_2832.AutoSize = true; - this.flag_2832.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_2832.Location = new System.Drawing.Point(172, 210); - this.flag_2832.Name = "flag_2832"; - this.flag_2832.Size = new System.Drawing.Size(116, 17); - this.flag_2832.TabIndex = 43; - this.flag_2832.Text = "Landorus Captured"; - this.flag_2832.UseVisualStyleBackColor = true; - this.flag_2832.Click += new System.EventHandler(this.toggleFlag); - // - // flag_2829 - // - this.flag_2829.AutoSize = true; - this.flag_2829.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_2829.Location = new System.Drawing.Point(15, 206); - this.flag_2829.Name = "flag_2829"; - this.flag_2829.Size = new System.Drawing.Size(146, 17); - this.flag_2829.TabIndex = 41; - this.flag_2829.Text = "(AS) Thundurus Captured"; - this.flag_2829.UseVisualStyleBackColor = true; - this.flag_2829.Click += new System.EventHandler(this.toggleFlag); - // - // flag_2822 - // - this.flag_2822.AutoSize = true; - this.flag_2822.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_2822.Location = new System.Drawing.Point(172, 274); - this.flag_2822.Name = "flag_2822"; - this.flag_2822.Size = new System.Drawing.Size(119, 17); - this.flag_2822.TabIndex = 39; - this.flag_2822.Text = "Regigigas Captured"; - this.flag_2822.UseVisualStyleBackColor = true; - this.flag_2822.Click += new System.EventHandler(this.toggleFlag); - // - // flag_0252 - // - this.flag_0252.AutoSize = true; - this.flag_0252.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_0252.Location = new System.Drawing.Point(172, 259); - this.flag_0252.Name = "flag_0252"; - this.flag_0252.Size = new System.Drawing.Size(120, 17); - this.flag_0252.TabIndex = 38; - this.flag_0252.Text = "Regigigas Defeated"; - this.flag_0252.UseVisualStyleBackColor = true; - this.flag_0252.Click += new System.EventHandler(this.toggleFlag); - // - // flag_2827 - // - this.flag_2827.AutoSize = true; - this.flag_2827.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_2827.Location = new System.Drawing.Point(172, 470); - this.flag_2827.Name = "flag_2827"; - this.flag_2827.Size = new System.Drawing.Size(105, 17); - this.flag_2827.TabIndex = 37; - this.flag_2827.Text = "Virizion Captured"; - this.flag_2827.UseVisualStyleBackColor = true; - this.flag_2827.Click += new System.EventHandler(this.toggleFlag); - // - // flag_0178 - // - this.flag_0178.AutoSize = true; - this.flag_0178.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_0178.Location = new System.Drawing.Point(172, 455); - this.flag_0178.Name = "flag_0178"; - this.flag_0178.Size = new System.Drawing.Size(106, 17); - this.flag_0178.TabIndex = 36; - this.flag_0178.Text = "Virizion Defeated"; - this.flag_0178.UseVisualStyleBackColor = true; - this.flag_0178.Click += new System.EventHandler(this.toggleFlag); - // - // flag_2826 - // - this.flag_2826.AutoSize = true; - this.flag_2826.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_2826.Location = new System.Drawing.Point(172, 440); - this.flag_2826.Name = "flag_2826"; - this.flag_2826.Size = new System.Drawing.Size(117, 17); - this.flag_2826.TabIndex = 35; - this.flag_2826.Text = "Terrakion Captured"; - this.flag_2826.UseVisualStyleBackColor = true; - this.flag_2826.Click += new System.EventHandler(this.toggleFlag); - // - // flag_0177 - // - this.flag_0177.AutoSize = true; - this.flag_0177.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_0177.Location = new System.Drawing.Point(172, 425); - this.flag_0177.Name = "flag_0177"; - this.flag_0177.Size = new System.Drawing.Size(118, 17); - this.flag_0177.TabIndex = 34; - this.flag_0177.Text = "Terrakion Defeated"; - this.flag_0177.UseVisualStyleBackColor = true; - this.flag_0177.Click += new System.EventHandler(this.toggleFlag); - // - // flag_2823 - // - this.flag_2823.AutoSize = true; - this.flag_2823.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_2823.Location = new System.Drawing.Point(172, 195); - this.flag_2823.Name = "flag_2823"; - this.flag_2823.Size = new System.Drawing.Size(108, 17); - this.flag_2823.TabIndex = 33; - this.flag_2823.Text = "Giratina Captured"; - this.flag_2823.UseVisualStyleBackColor = true; - this.flag_2823.Click += new System.EventHandler(this.toggleFlag); - // - // flag_2819 - // - this.flag_2819.AutoSize = true; - this.flag_2819.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_2819.Location = new System.Drawing.Point(15, 168); - this.flag_2819.Name = "flag_2819"; - this.flag_2819.Size = new System.Drawing.Size(125, 17); - this.flag_2819.TabIndex = 31; - this.flag_2819.Text = "(AS) Dialga Captured"; - this.flag_2819.UseVisualStyleBackColor = true; - this.flag_2819.Click += new System.EventHandler(this.toggleFlag); - // - // flag_2833 - // - this.flag_2833.AutoSize = true; - this.flag_2833.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_2833.Location = new System.Drawing.Point(172, 242); - this.flag_2833.Name = "flag_2833"; - this.flag_2833.Size = new System.Drawing.Size(107, 17); - this.flag_2833.TabIndex = 29; - this.flag_2833.Text = "Kyurem Captured"; - this.flag_2833.UseVisualStyleBackColor = true; - this.flag_2833.Click += new System.EventHandler(this.toggleFlag); - // - // flag_0184 - // - this.flag_0184.AutoSize = true; - this.flag_0184.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_0184.Location = new System.Drawing.Point(172, 227); - this.flag_0184.Name = "flag_0184"; - this.flag_0184.Size = new System.Drawing.Size(108, 17); - this.flag_0184.TabIndex = 28; - this.flag_0184.Text = "Kyurem Defeated"; - this.flag_0184.UseVisualStyleBackColor = true; - this.flag_0184.Click += new System.EventHandler(this.toggleFlag); - // - // flag_2816 - // - this.flag_2816.AutoSize = true; - this.flag_2816.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_2816.Location = new System.Drawing.Point(15, 470); - this.flag_2816.Name = "flag_2816"; - this.flag_2816.Size = new System.Drawing.Size(93, 17); - this.flag_2816.TabIndex = 27; - this.flag_2816.Text = "Uxie Captured"; - this.flag_2816.UseVisualStyleBackColor = true; - this.flag_2816.Click += new System.EventHandler(this.toggleFlag); - // - // flag_0179 - // - this.flag_0179.AutoSize = true; - this.flag_0179.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_0179.Location = new System.Drawing.Point(15, 455); - this.flag_0179.Name = "flag_0179"; - this.flag_0179.Size = new System.Drawing.Size(94, 17); - this.flag_0179.TabIndex = 26; - this.flag_0179.Text = "Uxie Defeated"; - this.flag_0179.UseVisualStyleBackColor = true; - this.flag_0179.Click += new System.EventHandler(this.toggleFlag); - // - // flag_2817 - // - this.flag_2817.AutoSize = true; - this.flag_2817.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_2817.Location = new System.Drawing.Point(15, 440); - this.flag_2817.Name = "flag_2817"; - this.flag_2817.Size = new System.Drawing.Size(106, 17); - this.flag_2817.TabIndex = 25; - this.flag_2817.Text = "Mesprit Captured"; - this.flag_2817.UseVisualStyleBackColor = true; - this.flag_2817.Click += new System.EventHandler(this.toggleFlag); - // - // flag_0180 - // - this.flag_0180.AutoSize = true; - this.flag_0180.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_0180.Location = new System.Drawing.Point(15, 425); - this.flag_0180.Name = "flag_0180"; - this.flag_0180.Size = new System.Drawing.Size(107, 17); - this.flag_0180.TabIndex = 24; - this.flag_0180.Text = "Mesprit Defeated"; - this.flag_0180.UseVisualStyleBackColor = true; - this.flag_0180.Click += new System.EventHandler(this.toggleFlag); - // - // flag_2825 - // - this.flag_2825.AutoSize = true; - this.flag_2825.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_2825.Location = new System.Drawing.Point(172, 410); - this.flag_2825.Name = "flag_2825"; - this.flag_2825.Size = new System.Drawing.Size(113, 17); - this.flag_2825.TabIndex = 23; - this.flag_2825.Text = "Cobalion Captured"; - this.flag_2825.UseVisualStyleBackColor = true; - this.flag_2825.Click += new System.EventHandler(this.toggleFlag); - // - // flag_0176 - // - this.flag_0176.AutoSize = true; - this.flag_0176.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_0176.Location = new System.Drawing.Point(172, 395); - this.flag_0176.Name = "flag_0176"; - this.flag_0176.Size = new System.Drawing.Size(114, 17); - this.flag_0176.TabIndex = 22; - this.flag_0176.Text = "Cobalion Defeated"; - this.flag_0176.UseVisualStyleBackColor = true; - this.flag_0176.Click += new System.EventHandler(this.toggleFlag); - // - // flag_2814 - // - this.flag_2814.AutoSize = true; - this.flag_2814.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_2814.Location = new System.Drawing.Point(15, 130); - this.flag_2814.Name = "flag_2814"; - this.flag_2814.Size = new System.Drawing.Size(121, 17); - this.flag_2814.TabIndex = 21; - this.flag_2814.Text = "(AS) Lugia Captured"; - this.flag_2814.UseVisualStyleBackColor = true; - this.flag_2814.Click += new System.EventHandler(this.toggleFlag); - // - // flag_0209 - // - this.flag_0209.AutoSize = true; - this.flag_0209.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_0209.Location = new System.Drawing.Point(15, 115); - this.flag_0209.Name = "flag_0209"; - this.flag_0209.Size = new System.Drawing.Size(122, 17); - this.flag_0209.TabIndex = 20; - this.flag_0209.Text = "(AS) Lugia Defeated"; - this.flag_0209.UseVisualStyleBackColor = true; - this.flag_0209.Click += new System.EventHandler(this.toggleFlag); - // - // flag_2818 - // - this.flag_2818.AutoSize = true; - this.flag_2818.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_2818.Location = new System.Drawing.Point(15, 410); - this.flag_2818.Name = "flag_2818"; - this.flag_2818.Size = new System.Drawing.Size(95, 17); - this.flag_2818.TabIndex = 19; - this.flag_2818.Text = "Azelf Captured"; - this.flag_2818.UseVisualStyleBackColor = true; - this.flag_2818.Click += new System.EventHandler(this.toggleFlag); - // - // flag_0181 - // - this.flag_0181.AutoSize = true; - this.flag_0181.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_0181.Location = new System.Drawing.Point(15, 395); - this.flag_0181.Name = "flag_0181"; - this.flag_0181.Size = new System.Drawing.Size(96, 17); - this.flag_0181.TabIndex = 18; - this.flag_0181.Text = "Azelf Defeated"; - this.flag_0181.UseVisualStyleBackColor = true; - this.flag_0181.Click += new System.EventHandler(this.toggleFlag); - // - // flag_2831 - // - this.flag_2831.AutoSize = true; - this.flag_2831.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_2831.Location = new System.Drawing.Point(15, 274); - this.flag_2831.Name = "flag_2831"; - this.flag_2831.Size = new System.Drawing.Size(131, 17); - this.flag_2831.TabIndex = 17; - this.flag_2831.Text = "(AS) Zekrom Captured"; - this.flag_2831.UseVisualStyleBackColor = true; - this.flag_2831.Click += new System.EventHandler(this.toggleFlag); - // - // flag_0183 - // - this.flag_0183.AutoSize = true; - this.flag_0183.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_0183.Location = new System.Drawing.Point(15, 259); - this.flag_0183.Name = "flag_0183"; - this.flag_0183.Size = new System.Drawing.Size(132, 17); - this.flag_0183.TabIndex = 16; - this.flag_0183.Text = "(AS) Zekrom Defeated"; - this.flag_0183.UseVisualStyleBackColor = true; - this.flag_0183.Click += new System.EventHandler(this.toggleFlag); - // - // GB_Misc - // - this.GB_Misc.Controls.Add(this.flag_0288); - this.GB_Misc.Controls.Add(this.flag_0287); - this.GB_Misc.Controls.Add(this.flag_0286); - this.GB_Misc.Controls.Add(this.flag_0293); - this.GB_Misc.Controls.Add(this.flag_0292); - this.GB_Misc.Controls.Add(this.flag_0291); - this.GB_Misc.Controls.Add(this.flag_0290); - this.GB_Misc.Controls.Add(this.flag_0289); - this.GB_Misc.Controls.Add(this.flag_0285); - this.GB_Misc.Controls.Add(this.flag_0284); - this.GB_Misc.Location = new System.Drawing.Point(314, 9); - this.GB_Misc.Name = "GB_Misc"; - this.GB_Misc.Size = new System.Drawing.Size(154, 180); - this.GB_Misc.TabIndex = 17; - this.GB_Misc.TabStop = false; - this.GB_Misc.Text = "Misc"; - // - // flag_0288 - // - this.flag_0288.AutoSize = true; - this.flag_0288.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_0288.Location = new System.Drawing.Point(6, 76); - this.flag_0288.Name = "flag_0288"; - this.flag_0288.Size = new System.Drawing.Size(94, 17); - this.flag_0288.TabIndex = 25; - this.flag_0288.Text = "Multi Statuette"; - this.flag_0288.UseVisualStyleBackColor = true; - this.flag_0288.Click += new System.EventHandler(this.toggleFlag); - // - // flag_0287 - // - this.flag_0287.AutoSize = true; - this.flag_0287.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_0287.Location = new System.Drawing.Point(6, 61); - this.flag_0287.Name = "flag_0287"; - this.flag_0287.Size = new System.Drawing.Size(112, 17); - this.flag_0287.TabIndex = 24; - this.flag_0287.Text = "Rotation Statuette"; - this.flag_0287.UseVisualStyleBackColor = true; - this.flag_0287.Click += new System.EventHandler(this.toggleFlag); - // - // flag_0286 - // - this.flag_0286.AutoSize = true; - this.flag_0286.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_0286.Location = new System.Drawing.Point(6, 46); - this.flag_0286.Name = "flag_0286"; - this.flag_0286.Size = new System.Drawing.Size(103, 17); - this.flag_0286.TabIndex = 23; - this.flag_0286.Text = "Triples Statuette"; - this.flag_0286.UseVisualStyleBackColor = true; - this.flag_0286.Click += new System.EventHandler(this.toggleFlag); - // - // flag_0293 - // - this.flag_0293.AutoSize = true; - this.flag_0293.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_0293.Location = new System.Drawing.Point(6, 153); - this.flag_0293.Name = "flag_0293"; - this.flag_0293.Size = new System.Drawing.Size(128, 17); - this.flag_0293.TabIndex = 22; - this.flag_0293.Text = "Super Multi Unlocked"; - this.flag_0293.UseVisualStyleBackColor = true; - this.flag_0293.Click += new System.EventHandler(this.toggleFlag); - // - // flag_0292 - // - this.flag_0292.AutoSize = true; - this.flag_0292.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_0292.Location = new System.Drawing.Point(6, 138); - this.flag_0292.Name = "flag_0292"; - this.flag_0292.Size = new System.Drawing.Size(146, 17); - this.flag_0292.TabIndex = 21; - this.flag_0292.Text = "Super Rotation Unlocked"; - this.flag_0292.UseVisualStyleBackColor = true; - this.flag_0292.Click += new System.EventHandler(this.toggleFlag); - // - // flag_0291 - // - this.flag_0291.AutoSize = true; - this.flag_0291.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_0291.Location = new System.Drawing.Point(6, 123); - this.flag_0291.Name = "flag_0291"; - this.flag_0291.Size = new System.Drawing.Size(137, 17); - this.flag_0291.TabIndex = 20; - this.flag_0291.Text = "Super Triples Unlocked"; - this.flag_0291.UseVisualStyleBackColor = true; - this.flag_0291.Click += new System.EventHandler(this.toggleFlag); - // - // flag_0290 - // - this.flag_0290.AutoSize = true; - this.flag_0290.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_0290.Location = new System.Drawing.Point(6, 108); - this.flag_0290.Name = "flag_0290"; - this.flag_0290.Size = new System.Drawing.Size(145, 17); - this.flag_0290.TabIndex = 19; - this.flag_0290.Text = "Super Doubles Unlocked"; - this.flag_0290.UseVisualStyleBackColor = true; - this.flag_0290.Click += new System.EventHandler(this.toggleFlag); - // - // flag_0289 - // - this.flag_0289.AutoSize = true; - this.flag_0289.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_0289.Location = new System.Drawing.Point(6, 93); - this.flag_0289.Name = "flag_0289"; - this.flag_0289.Size = new System.Drawing.Size(140, 17); - this.flag_0289.TabIndex = 18; - this.flag_0289.Text = "Super Singles Unlocked"; - this.flag_0289.UseVisualStyleBackColor = true; - this.flag_0289.Click += new System.EventHandler(this.toggleFlag); - // - // flag_0285 - // - this.flag_0285.AutoSize = true; - this.flag_0285.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_0285.Location = new System.Drawing.Point(6, 31); - this.flag_0285.Name = "flag_0285"; - this.flag_0285.Size = new System.Drawing.Size(111, 17); - this.flag_0285.TabIndex = 16; - this.flag_0285.Text = "Doubles Statuette"; - this.flag_0285.UseVisualStyleBackColor = true; - this.flag_0285.Click += new System.EventHandler(this.toggleFlag); - // - // flag_0284 - // - this.flag_0284.AutoSize = true; - this.flag_0284.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_0284.Location = new System.Drawing.Point(6, 16); - this.flag_0284.Name = "flag_0284"; - this.flag_0284.Size = new System.Drawing.Size(106, 17); - this.flag_0284.TabIndex = 15; - this.flag_0284.Text = "Singles Statuette"; - this.flag_0284.UseVisualStyleBackColor = true; - this.flag_0284.Click += new System.EventHandler(this.toggleFlag); - // - // MT_Ash - // - this.MT_Ash.Location = new System.Drawing.Point(459, 454); - this.MT_Ash.Mask = "00000"; - this.MT_Ash.Name = "MT_Ash"; - this.MT_Ash.Size = new System.Drawing.Size(42, 20); - this.MT_Ash.TabIndex = 18; - this.MT_Ash.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; - // - // L_Ash - // - this.L_Ash.AutoSize = true; - this.L_Ash.Location = new System.Drawing.Point(429, 438); - this.L_Ash.Name = "L_Ash"; - this.L_Ash.Size = new System.Drawing.Size(72, 13); - this.L_Ash.TabIndex = 19; - this.L_Ash.Text = "Volcanic Ash:"; - // - // L_Stats - // - this.L_Stats.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.L_Stats.AutoSize = true; - this.L_Stats.Location = new System.Drawing.Point(317, 236); - this.L_Stats.Name = "L_Stats"; - this.L_Stats.Size = new System.Drawing.Size(85, 13); - this.L_Stats.TabIndex = 37; - this.L_Stats.Text = "Event Constants"; - // - // CB_Stats - // - this.CB_Stats.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.CB_Stats.DropDownHeight = 156; - this.CB_Stats.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.CB_Stats.DropDownWidth = 180; - this.CB_Stats.FormattingEnabled = true; - this.CB_Stats.IntegralHeight = false; - this.CB_Stats.Location = new System.Drawing.Point(320, 252); - this.CB_Stats.Name = "CB_Stats"; - this.CB_Stats.Size = new System.Drawing.Size(94, 21); - this.CB_Stats.TabIndex = 36; - this.CB_Stats.SelectedIndexChanged += new System.EventHandler(this.changeConstantIndex); - // - // L_Value - // - this.L_Value.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.L_Value.AutoSize = true; - this.L_Value.Location = new System.Drawing.Point(317, 276); - this.L_Value.Name = "L_Value"; - this.L_Value.Size = new System.Drawing.Size(34, 13); - this.L_Value.TabIndex = 35; - this.L_Value.Text = "Value"; - // - // MT_Stat - // - this.MT_Stat.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.MT_Stat.Font = new System.Drawing.Font("Courier New", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.MT_Stat.Location = new System.Drawing.Point(376, 276); - this.MT_Stat.Mask = "00000"; - this.MT_Stat.Name = "MT_Stat"; - this.MT_Stat.Size = new System.Drawing.Size(38, 20); - this.MT_Stat.TabIndex = 34; - this.MT_Stat.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; - // - // SAV_EventFlagsORAS - // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(594, 512); - this.Controls.Add(this.L_Stats); - this.Controls.Add(this.CB_Stats); - this.Controls.Add(this.L_Value); - this.Controls.Add(this.MT_Stat); - this.Controls.Add(this.L_Ash); - this.Controls.Add(this.MT_Ash); - this.Controls.Add(this.GB_Misc); - this.Controls.Add(this.GB_Rebattle); - this.Controls.Add(this.GB_Researcher); - this.Controls.Add(this.GB_FlagStatus); - this.Controls.Add(this.B_Save); - this.Controls.Add(this.B_Cancel); - this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; - this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); - this.MaximizeBox = false; - this.MinimizeBox = false; - this.Name = "SAV_EventFlagsORAS"; - this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; - this.Text = "Event Flag Editor"; - this.GB_FlagStatus.ResumeLayout(false); - this.GB_FlagStatus.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)(this.nud)).EndInit(); - this.GB_Researcher.ResumeLayout(false); - this.GB_Researcher.PerformLayout(); - this.GB_Rebattle.ResumeLayout(false); - this.GB_Rebattle.PerformLayout(); - this.GB_Misc.ResumeLayout(false); - this.GB_Misc.PerformLayout(); - this.ResumeLayout(false); - this.PerformLayout(); - - } - - #endregion - - private System.Windows.Forms.CheckBox CHK_CustomFlag; - private System.Windows.Forms.Button B_Cancel; - private System.Windows.Forms.GroupBox GB_FlagStatus; - private System.Windows.Forms.Label L_Flag; - private System.Windows.Forms.NumericUpDown nud; - private System.Windows.Forms.Button B_Save; - private System.Windows.Forms.GroupBox GB_Researcher; - private System.Windows.Forms.Label L_UnSet; - private System.Windows.Forms.Label L_IsSet; - private System.Windows.Forms.TextBox TB_NewSAV; - private System.Windows.Forms.TextBox TB_OldSAV; - private System.Windows.Forms.TextBox TB_UnSet; - private System.Windows.Forms.TextBox TB_IsSet; - private System.Windows.Forms.Button B_LoadNew; - private System.Windows.Forms.Button B_LoadOld; - private System.Windows.Forms.CheckBox flag_0647; - private System.Windows.Forms.CheckBox flag_2840; - private System.Windows.Forms.GroupBox GB_Rebattle; - private System.Windows.Forms.GroupBox GB_Misc; - private System.Windows.Forms.CheckBox flag_0288; - private System.Windows.Forms.CheckBox flag_0287; - private System.Windows.Forms.CheckBox flag_0286; - private System.Windows.Forms.CheckBox flag_0293; - private System.Windows.Forms.CheckBox flag_0292; - private System.Windows.Forms.CheckBox flag_0291; - private System.Windows.Forms.CheckBox flag_0290; - private System.Windows.Forms.CheckBox flag_0289; - private System.Windows.Forms.CheckBox flag_0285; - private System.Windows.Forms.CheckBox flag_0284; - private System.Windows.Forms.CheckBox flag_2831; - private System.Windows.Forms.CheckBox flag_0183; - private System.Windows.Forms.CheckBox flag_2818; - private System.Windows.Forms.CheckBox flag_0181; - private System.Windows.Forms.CheckBox flag_2814; - private System.Windows.Forms.CheckBox flag_0209; - private System.Windows.Forms.CheckBox flag_2825; - private System.Windows.Forms.CheckBox flag_0176; - private System.Windows.Forms.CheckBox flag_2813; - private System.Windows.Forms.CheckBox flag_0175; - private System.Windows.Forms.CheckBox flag_2811; - private System.Windows.Forms.CheckBox flag_0173; - private System.Windows.Forms.CheckBox flag_2812; - private System.Windows.Forms.CheckBox flag_0174; - private System.Windows.Forms.CheckBox flag_2832; - private System.Windows.Forms.CheckBox flag_2829; - private System.Windows.Forms.CheckBox flag_2822; - private System.Windows.Forms.CheckBox flag_0252; - private System.Windows.Forms.CheckBox flag_2827; - private System.Windows.Forms.CheckBox flag_0178; - private System.Windows.Forms.CheckBox flag_2826; - private System.Windows.Forms.CheckBox flag_0177; - private System.Windows.Forms.CheckBox flag_2823; - private System.Windows.Forms.CheckBox flag_2819; - private System.Windows.Forms.CheckBox flag_2833; - private System.Windows.Forms.CheckBox flag_0184; - private System.Windows.Forms.CheckBox flag_2816; - private System.Windows.Forms.CheckBox flag_0179; - private System.Windows.Forms.CheckBox flag_2817; - private System.Windows.Forms.CheckBox flag_0180; - private System.Windows.Forms.CheckBox flag_2838; - private System.Windows.Forms.CheckBox flag_0958; - private System.Windows.Forms.CheckBox flag_2836; - private System.Windows.Forms.CheckBox flag_0956; - private System.Windows.Forms.CheckBox flag_2837; - private System.Windows.Forms.CheckBox flag_0957; - private System.Windows.Forms.CheckBox flag_2842; - private System.Windows.Forms.CheckBox flag_0945; - private System.Windows.Forms.CheckBox flag_2828; - private System.Windows.Forms.CheckBox flag_2830; - private System.Windows.Forms.CheckBox flag_0182; - private System.Windows.Forms.CheckBox flag_2820; - private System.Windows.Forms.CheckBox flag_2839; - private System.Windows.Forms.CheckBox flag_0648; - private System.Windows.Forms.CheckBox flag_2815; - private System.Windows.Forms.CheckBox flag_0208; - private System.Windows.Forms.CheckBox flag_2824; - private System.Windows.Forms.CheckBox flag_0172; - private System.Windows.Forms.CheckBox flag_2821; - private System.Windows.Forms.CheckBox flag_0260; - private System.Windows.Forms.CheckBox flag_2834; - private System.Windows.Forms.CheckBox flag_0419; - private System.Windows.Forms.MaskedTextBox MT_Ash; - private System.Windows.Forms.Label L_Ash; - private System.Windows.Forms.Label L_SkyTower; - private System.Windows.Forms.CheckBox flag_2835; - private System.Windows.Forms.CheckBox flag_0420; - private System.Windows.Forms.Label L_Stats; - private System.Windows.Forms.ComboBox CB_Stats; - private System.Windows.Forms.Label L_Value; - private System.Windows.Forms.MaskedTextBox MT_Stat; - } -} \ No newline at end of file diff --git a/SAV/SAV_EventFlagsORAS.cs b/SAV/SAV_EventFlagsORAS.cs deleted file mode 100644 index b59b80c29..000000000 --- a/SAV/SAV_EventFlagsORAS.cs +++ /dev/null @@ -1,261 +0,0 @@ -using System; -using System.Collections; -using System.Drawing; -using System.IO; -using System.Linq; -using System.Windows.Forms; - -namespace PKHeX -{ - public partial class SAV_EventFlagsORAS : Form - { - public SAV_EventFlagsORAS() - { - InitializeComponent(); - Util.TranslateInterface(this, Main.curlanguage); - - AllowDrop = true; - DragEnter += tabMain_DragEnter; - DragDrop += tabMain_DragDrop; - Setup(); - - nud.Text = "0"; // Prompts an update for flag 0. - MT_Ash.Text = BitConverter.ToUInt16(Main.SAV.Data, Main.SAV.EventAsh).ToString(); - } - private bool setup = true; - private CheckBox[] chka; - private readonly bool[] flags = new bool[3072]; - private readonly ushort[] Constants = new ushort[(Main.SAV.EventFlag - Main.SAV.EventConst) / 2]; - private void B_Cancel_Click(object sender, EventArgs e) - { - Close(); - } - private void B_Save_Click(object sender, EventArgs e) - { - // Gather Updated Flags - foreach (CheckBox flag in chka) - flags[getFlagNum(flag)] = flag.Checked; - - byte[] data = new byte[flags.Length / 8]; - - for (int i = 0; i < flags.Length; i++) - if (flags[i]) - data[i / 8] |= (byte)(1 << i % 8); - - Array.Copy(data, 0, Main.SAV.Data, Main.SAV.EventFlag, 0x180); - - // Copy back Constants - changeConstantIndex(null, null); // Trigger Saving - for (int i = 0; i < Constants.Length; i++) - Array.Copy(BitConverter.GetBytes(Constants[i]), 0, Main.SAV.Data, Main.SAV.EventConst + 2 * i, 2); - - // Copy back Volcanic Ash counter - Array.Copy(BitConverter.GetBytes(Util.ToUInt32(MT_Ash.Text)), 0, Main.SAV.Data, Main.SAV.EventAsh, 2); - - Close(); - } - private void Setup() - { - // Fill Bit arrays - - chka = new[] { - - flag_0173,flag_2811, // Raikou - flag_0174,flag_2812, // Entei - flag_0175,flag_2813, // Suicune - flag_0209,flag_2814, // Lugia - flag_0208,flag_2815, // Ho-Oh - flag_0179,flag_2816, // Uxie - flag_0180,flag_2817, // Mesprit - flag_0181,flag_2818, // Azelf - flag_2819, // Dialga - flag_2820, // Palkia - flag_0260,flag_2821, // Heatran - flag_0252,flag_2822, // Regigigas - flag_2823, // Giratina - flag_0172,flag_2824, // Cresselia - flag_0176,flag_2825, // Cobalion - flag_0177,flag_2826, // Terrakion - flag_0178,flag_2827, // Virizion - flag_2828, // Tornadus - flag_2829, // Thundurus - flag_0182,flag_2830, // Reshiram - flag_0183,flag_2831, // Zekrom - flag_2832, // Landorus - flag_0184,flag_2833, // Kyurem - flag_0419,flag_2834, // Latios - flag_0420,flag_2835, // Latias - flag_0956,flag_2836, // Regirock - flag_0957,flag_2837, // Regice - flag_0958,flag_2838, // Registeel - flag_0648,flag_2839, // Groudon - flag_0647,flag_2840, // Kyogre - // ?????? - flag_0945,flag_2842, // Deoxys - - // Cresselia, Regigigas - // Terrakion, Virizion - - // Maison - flag_0284,flag_0285,flag_0286,flag_0287,flag_0288, // Statuettes - flag_0289,flag_0290,flag_0291,flag_0292,flag_0293, // Super Unlocks - //flag_0675, // Chatelaine 50 - //flag_2546, // Pokedex - }; - byte[] data = new byte[0x180]; - Array.Copy(Main.SAV.Data, Main.SAV.EventFlag, data, 0, 0x180); - BitArray BitRegion = new BitArray(data); - BitRegion.CopyTo(flags, 0); - - // Setup Event Constant Editor - CB_Stats.Items.Clear(); - for (int i = 0; i < Constants.Length; i += 2) - { - CB_Stats.Items.Add($"0x{(i/2).ToString("X2")}"); - Constants[i / 2] = BitConverter.ToUInt16(Main.SAV.Data, Main.SAV.EventConst + i); - } - CB_Stats.SelectedIndex = 0; - - // Populate Flags - setup = true; - popFlags(); - } - private void popFlags() - { - if (!setup) return; - foreach (CheckBox flag in chka) - flag.Checked = flags[getFlagNum(flag)]; - - changeCustomFlag(null, null); - } - - private int getFlagNum(CheckBox chk) - { - try - { - string source = chk.Name; - return Convert.ToInt32(source.Substring(Math.Max(0, source.Length - 4))); - } - catch { return 0; } - } - private void changeCustomBool(object sender, EventArgs e) - { - flags[(int)nud.Value] = CHK_CustomFlag.Checked; - popFlags(); - } - private void changeCustomFlag(object sender, EventArgs e) - { - int flag = (int)nud.Value; - if (flag >= 3072) - { - CHK_CustomFlag.Checked = false; - CHK_CustomFlag.Enabled = false; - nud.BackColor = Color.Red; - } - else - { - CHK_CustomFlag.Enabled = true; - nud.BackColor = Main.defaultControlWhite; - CHK_CustomFlag.Checked = flags[flag]; - } - } - private void changeCustomFlag(object sender, KeyEventArgs e) - { - changeCustomFlag(null, (EventArgs)e); - } - - private void toggleFlag(object sender, EventArgs e) - { - flags[getFlagNum((CheckBox)sender)] = ((CheckBox)sender).Checked; - changeCustomFlag(sender, e); - } - - private void changeSAV(object sender, EventArgs e) - { - if (TB_NewSAV.Text.Length > 0 && TB_OldSAV.Text.Length > 0) - diffSaves(); - } - private void diffSaves() - { - BitArray oldBits = new BitArray(oldFlags); - BitArray newBits = new BitArray(newFlags); - - string tbIsSet = ""; - string tbUnSet = ""; - for (int i = 0; i < oldBits.Length; i++) - { - if (oldBits[i] == newBits[i]) continue; - if (newBits[i]) - tbIsSet += i.ToString("0000") + ","; - else - tbUnSet += i.ToString("0000") + ","; - } - TB_IsSet.Text = tbIsSet; - TB_UnSet.Text = tbUnSet; - - if (DialogResult.Yes != Util.Prompt(MessageBoxButtons.YesNo, "Copy Event Constant diff to clipboard?")) - return; - - string r = ""; - for (int i = 0; i < newConst.Length; i += 2) - { - ushort oldval = BitConverter.ToUInt16(oldConst, i); - ushort newval = BitConverter.ToUInt16(oldConst, i); - if (oldval != newval) - r += $"0x{(i/2).ToString("X2")}: {oldval}->{newval}{Environment.NewLine}"; - } - Clipboard.SetText(r); - } - private byte[] oldFlags = new byte[0x180]; - private byte[] newFlags = new byte[0x180]; - private byte[] oldConst = new byte[Main.SAV.EventFlag - Main.SAV.EventConst]; - private byte[] newConst = new byte[Main.SAV.EventFlag - Main.SAV.EventConst]; - private void openSAV(object sender, EventArgs e) - { - OpenFileDialog ofd = new OpenFileDialog(); - if (ofd.ShowDialog() == DialogResult.OK) - loadSAV(sender, ofd.FileName); - } - private void loadSAV(object sender, string path) - { - FileInfo fi = new FileInfo(path); - if (fi.Length != SAV6.SIZE_ORAS) - { - Util.Error("Invalid SAV Size", string.Format("File Size: 0x{1} ({0} bytes)", fi.Length, fi.Length.ToString("X5")), "File Loaded: " + path); - return; - } - - byte[] data = File.ReadAllBytes(path); - if (sender == B_LoadOld) - { - oldFlags = data.Skip(Main.SAV.EventFlag).Take(0x180).ToArray(); - oldConst = data.Skip(Main.SAV.EventConst).Take(Constants.Length * 2).ToArray(); - TB_OldSAV.Text = path; - } - else - { - newFlags = data.Skip(Main.SAV.EventFlag).Take(0x180).ToArray(); - newConst = data.Skip(Main.SAV.EventConst).Take(Constants.Length * 2).ToArray(); - TB_NewSAV.Text = path; - } - } - private int entry = -1; - private void changeConstantIndex(object sender, EventArgs e) - { - if (entry > -1) // Set Entry - Constants[entry] = (ushort)Math.Min(Util.ToUInt32(MT_Stat.Text), 0xFFFF); - - entry = CB_Stats.SelectedIndex; // Get Entry - MT_Stat.Text = Constants[entry].ToString(); - } - private void tabMain_DragEnter(object sender, DragEventArgs e) - { - if (e.Data.GetDataPresent(DataFormats.FileDrop)) e.Effect = DragDropEffects.Copy; - } - private void tabMain_DragDrop(object sender, DragEventArgs e) - { - string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); - loadSAV(Util.Prompt(MessageBoxButtons.YesNo, "FlagDiff Researcher:", "Yes: Old Save" + Environment.NewLine + "No: New Save") == DialogResult.Yes ? B_LoadOld : B_LoadNew, files[0]); - } - } -} \ No newline at end of file diff --git a/SAV/SAV_EventFlagsXY.Designer.cs b/SAV/SAV_EventFlagsXY.Designer.cs deleted file mode 100644 index 770ff51cf..000000000 --- a/SAV/SAV_EventFlagsXY.Designer.cs +++ /dev/null @@ -1,701 +0,0 @@ -namespace PKHeX -{ - partial class SAV_EventFlagsXY - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(SAV_EventFlagsXY)); - this.CHK_CustomFlag = new System.Windows.Forms.CheckBox(); - this.B_Cancel = new System.Windows.Forms.Button(); - this.GB_FlagStatus = new System.Windows.Forms.GroupBox(); - this.nud = new System.Windows.Forms.NumericUpDown(); - this.L_Flag = new System.Windows.Forms.Label(); - this.flag_0001 = new System.Windows.Forms.CheckBox(); - this.flag_0002 = new System.Windows.Forms.CheckBox(); - this.flag_0003 = new System.Windows.Forms.CheckBox(); - this.flag_0004 = new System.Windows.Forms.CheckBox(); - this.flag_0005 = new System.Windows.Forms.CheckBox(); - this.B_Save = new System.Windows.Forms.Button(); - this.flag_2237 = new System.Windows.Forms.CheckBox(); - this.flag_2238 = new System.Windows.Forms.CheckBox(); - this.flag_2239 = new System.Windows.Forms.CheckBox(); - this.GB_Researcher = new System.Windows.Forms.GroupBox(); - this.L_UnSet = new System.Windows.Forms.Label(); - this.L_IsSet = new System.Windows.Forms.Label(); - this.TB_NewSAV = new System.Windows.Forms.TextBox(); - this.TB_OldSAV = new System.Windows.Forms.TextBox(); - this.TB_UnSet = new System.Windows.Forms.TextBox(); - this.TB_IsSet = new System.Windows.Forms.TextBox(); - this.B_LoadNew = new System.Windows.Forms.Button(); - this.B_LoadOld = new System.Windows.Forms.Button(); - this.flag_0963 = new System.Windows.Forms.CheckBox(); - this.flag_0115 = new System.Windows.Forms.CheckBox(); - this.GB_Rebattle = new System.Windows.Forms.GroupBox(); - this.flag_0114 = new System.Windows.Forms.CheckBox(); - this.flag_0790 = new System.Windows.Forms.CheckBox(); - this.GB_Misc = new System.Windows.Forms.GroupBox(); - this.flag_0289 = new System.Windows.Forms.CheckBox(); - this.flag_0288 = new System.Windows.Forms.CheckBox(); - this.flag_0287 = new System.Windows.Forms.CheckBox(); - this.flag_0294 = new System.Windows.Forms.CheckBox(); - this.flag_0293 = new System.Windows.Forms.CheckBox(); - this.flag_0292 = new System.Windows.Forms.CheckBox(); - this.flag_0291 = new System.Windows.Forms.CheckBox(); - this.flag_0290 = new System.Windows.Forms.CheckBox(); - this.flag_0675 = new System.Windows.Forms.CheckBox(); - this.flag_0286 = new System.Windows.Forms.CheckBox(); - this.flag_0285 = new System.Windows.Forms.CheckBox(); - this.flag_2546 = new System.Windows.Forms.CheckBox(); - this.L_Stats = new System.Windows.Forms.Label(); - this.CB_Stats = new System.Windows.Forms.ComboBox(); - this.L_Value = new System.Windows.Forms.Label(); - this.MT_Stat = new System.Windows.Forms.MaskedTextBox(); - this.GB_FlagStatus.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.nud)).BeginInit(); - this.GB_Researcher.SuspendLayout(); - this.GB_Rebattle.SuspendLayout(); - this.GB_Misc.SuspendLayout(); - this.SuspendLayout(); - // - // CHK_CustomFlag - // - this.CHK_CustomFlag.AutoSize = true; - this.CHK_CustomFlag.CheckAlign = System.Drawing.ContentAlignment.MiddleRight; - this.CHK_CustomFlag.Enabled = false; - this.CHK_CustomFlag.Location = new System.Drawing.Point(12, 44); - this.CHK_CustomFlag.Name = "CHK_CustomFlag"; - this.CHK_CustomFlag.Size = new System.Drawing.Size(59, 17); - this.CHK_CustomFlag.TabIndex = 1; - this.CHK_CustomFlag.Text = "Status:"; - this.CHK_CustomFlag.UseVisualStyleBackColor = true; - this.CHK_CustomFlag.CheckedChanged += new System.EventHandler(this.changeCustomBool); - // - // B_Cancel - // - this.B_Cancel.Location = new System.Drawing.Point(287, 307); - this.B_Cancel.Name = "B_Cancel"; - this.B_Cancel.Size = new System.Drawing.Size(75, 23); - this.B_Cancel.TabIndex = 2; - this.B_Cancel.Text = "Cancel"; - this.B_Cancel.UseVisualStyleBackColor = true; - this.B_Cancel.Click += new System.EventHandler(this.B_Cancel_Click); - // - // GB_FlagStatus - // - this.GB_FlagStatus.Controls.Add(this.nud); - this.GB_FlagStatus.Controls.Add(this.L_Flag); - this.GB_FlagStatus.Controls.Add(this.CHK_CustomFlag); - this.GB_FlagStatus.Location = new System.Drawing.Point(14, 135); - this.GB_FlagStatus.Name = "GB_FlagStatus"; - this.GB_FlagStatus.Size = new System.Drawing.Size(108, 68); - this.GB_FlagStatus.TabIndex = 3; - this.GB_FlagStatus.TabStop = false; - this.GB_FlagStatus.Text = "Check Flag Status"; - // - // nud - // - this.nud.Location = new System.Drawing.Point(56, 19); - this.nud.Maximum = new decimal(new int[] { - 3072, - 0, - 0, - 0}); - this.nud.Name = "nud"; - this.nud.Size = new System.Drawing.Size(45, 20); - this.nud.TabIndex = 9; - this.nud.Value = new decimal(new int[] { - 3071, - 0, - 0, - 0}); - this.nud.ValueChanged += new System.EventHandler(this.changeCustomFlag); - this.nud.KeyUp += new System.Windows.Forms.KeyEventHandler(this.changeCustomFlag); - // - // L_Flag - // - this.L_Flag.AutoSize = true; - this.L_Flag.Location = new System.Drawing.Point(13, 21); - this.L_Flag.Name = "L_Flag"; - this.L_Flag.Size = new System.Drawing.Size(30, 13); - this.L_Flag.TabIndex = 2; - this.L_Flag.Text = "Flag:"; - // - // flag_0001 - // - this.flag_0001.AutoSize = true; - this.flag_0001.CheckAlign = System.Drawing.ContentAlignment.MiddleRight; - this.flag_0001.Location = new System.Drawing.Point(12, 12); - this.flag_0001.Name = "flag_0001"; - this.flag_0001.Size = new System.Drawing.Size(52, 17); - this.flag_0001.TabIndex = 4; - this.flag_0001.Text = "Flag1"; - this.flag_0001.UseVisualStyleBackColor = true; - this.flag_0001.Click += new System.EventHandler(this.toggleFlag); - // - // flag_0002 - // - this.flag_0002.AutoSize = true; - this.flag_0002.CheckAlign = System.Drawing.ContentAlignment.MiddleRight; - this.flag_0002.Location = new System.Drawing.Point(12, 28); - this.flag_0002.Name = "flag_0002"; - this.flag_0002.Size = new System.Drawing.Size(52, 17); - this.flag_0002.TabIndex = 5; - this.flag_0002.Text = "Flag2"; - this.flag_0002.UseVisualStyleBackColor = true; - this.flag_0002.Click += new System.EventHandler(this.toggleFlag); - // - // flag_0003 - // - this.flag_0003.AutoSize = true; - this.flag_0003.CheckAlign = System.Drawing.ContentAlignment.MiddleRight; - this.flag_0003.Location = new System.Drawing.Point(12, 44); - this.flag_0003.Name = "flag_0003"; - this.flag_0003.Size = new System.Drawing.Size(52, 17); - this.flag_0003.TabIndex = 6; - this.flag_0003.Text = "Flag3"; - this.flag_0003.UseVisualStyleBackColor = true; - this.flag_0003.Click += new System.EventHandler(this.toggleFlag); - // - // flag_0004 - // - this.flag_0004.AutoSize = true; - this.flag_0004.CheckAlign = System.Drawing.ContentAlignment.MiddleRight; - this.flag_0004.Location = new System.Drawing.Point(12, 60); - this.flag_0004.Name = "flag_0004"; - this.flag_0004.Size = new System.Drawing.Size(52, 17); - this.flag_0004.TabIndex = 7; - this.flag_0004.Text = "Flag4"; - this.flag_0004.UseVisualStyleBackColor = true; - this.flag_0004.Click += new System.EventHandler(this.toggleFlag); - // - // flag_0005 - // - this.flag_0005.AutoSize = true; - this.flag_0005.CheckAlign = System.Drawing.ContentAlignment.MiddleRight; - this.flag_0005.Location = new System.Drawing.Point(12, 76); - this.flag_0005.Name = "flag_0005"; - this.flag_0005.Size = new System.Drawing.Size(52, 17); - this.flag_0005.TabIndex = 8; - this.flag_0005.Text = "Flag5"; - this.flag_0005.UseVisualStyleBackColor = true; - this.flag_0005.Click += new System.EventHandler(this.toggleFlag); - // - // B_Save - // - this.B_Save.Location = new System.Drawing.Point(366, 306); - this.B_Save.Name = "B_Save"; - this.B_Save.Size = new System.Drawing.Size(75, 23); - this.B_Save.TabIndex = 9; - this.B_Save.Text = "Save"; - this.B_Save.UseVisualStyleBackColor = true; - this.B_Save.Click += new System.EventHandler(this.B_Save_Click); - // - // flag_2237 - // - this.flag_2237.AutoSize = true; - this.flag_2237.Location = new System.Drawing.Point(72, 12); - this.flag_2237.Name = "flag_2237"; - this.flag_2237.Size = new System.Drawing.Size(50, 17); - this.flag_2237.TabIndex = 10; - this.flag_2237.Text = "2237"; - this.flag_2237.UseVisualStyleBackColor = true; - this.flag_2237.Click += new System.EventHandler(this.toggleFlag); - // - // flag_2238 - // - this.flag_2238.AutoSize = true; - this.flag_2238.Location = new System.Drawing.Point(72, 28); - this.flag_2238.Name = "flag_2238"; - this.flag_2238.Size = new System.Drawing.Size(50, 17); - this.flag_2238.TabIndex = 11; - this.flag_2238.Text = "2238"; - this.flag_2238.UseVisualStyleBackColor = true; - this.flag_2238.Click += new System.EventHandler(this.toggleFlag); - // - // flag_2239 - // - this.flag_2239.AutoSize = true; - this.flag_2239.Location = new System.Drawing.Point(72, 44); - this.flag_2239.Name = "flag_2239"; - this.flag_2239.Size = new System.Drawing.Size(50, 17); - this.flag_2239.TabIndex = 12; - this.flag_2239.Text = "2239"; - this.flag_2239.UseVisualStyleBackColor = true; - this.flag_2239.Click += new System.EventHandler(this.toggleFlag); - // - // GB_Researcher - // - this.GB_Researcher.Controls.Add(this.L_UnSet); - this.GB_Researcher.Controls.Add(this.L_IsSet); - this.GB_Researcher.Controls.Add(this.TB_NewSAV); - this.GB_Researcher.Controls.Add(this.TB_OldSAV); - this.GB_Researcher.Controls.Add(this.TB_UnSet); - this.GB_Researcher.Controls.Add(this.TB_IsSet); - this.GB_Researcher.Controls.Add(this.B_LoadNew); - this.GB_Researcher.Controls.Add(this.B_LoadOld); - this.GB_Researcher.Location = new System.Drawing.Point(14, 210); - this.GB_Researcher.Name = "GB_Researcher"; - this.GB_Researcher.Size = new System.Drawing.Size(268, 120); - this.GB_Researcher.TabIndex = 13; - this.GB_Researcher.TabStop = false; - this.GB_Researcher.Text = "FlagDiff Researcher"; - // - // L_UnSet - // - this.L_UnSet.AutoSize = true; - this.L_UnSet.Location = new System.Drawing.Point(10, 97); - this.L_UnSet.Name = "L_UnSet"; - this.L_UnSet.Size = new System.Drawing.Size(37, 13); - this.L_UnSet.TabIndex = 7; - this.L_UnSet.Text = "UnSet"; - // - // L_IsSet - // - this.L_IsSet.AutoSize = true; - this.L_IsSet.Location = new System.Drawing.Point(12, 77); - this.L_IsSet.Name = "L_IsSet"; - this.L_IsSet.Size = new System.Drawing.Size(31, 13); - this.L_IsSet.TabIndex = 6; - this.L_IsSet.Text = "IsSet"; - // - // TB_NewSAV - // - this.TB_NewSAV.Location = new System.Drawing.Point(93, 47); - this.TB_NewSAV.Name = "TB_NewSAV"; - this.TB_NewSAV.ReadOnly = true; - this.TB_NewSAV.Size = new System.Drawing.Size(169, 20); - this.TB_NewSAV.TabIndex = 5; - this.TB_NewSAV.TextChanged += new System.EventHandler(this.changeSAV); - // - // TB_OldSAV - // - this.TB_OldSAV.Location = new System.Drawing.Point(93, 21); - this.TB_OldSAV.Name = "TB_OldSAV"; - this.TB_OldSAV.ReadOnly = true; - this.TB_OldSAV.Size = new System.Drawing.Size(169, 20); - this.TB_OldSAV.TabIndex = 4; - this.TB_OldSAV.TextChanged += new System.EventHandler(this.changeSAV); - // - // TB_UnSet - // - this.TB_UnSet.Location = new System.Drawing.Point(56, 94); - this.TB_UnSet.Name = "TB_UnSet"; - this.TB_UnSet.ReadOnly = true; - this.TB_UnSet.Size = new System.Drawing.Size(206, 20); - this.TB_UnSet.TabIndex = 3; - // - // TB_IsSet - // - this.TB_IsSet.Location = new System.Drawing.Point(56, 74); - this.TB_IsSet.Name = "TB_IsSet"; - this.TB_IsSet.ReadOnly = true; - this.TB_IsSet.Size = new System.Drawing.Size(206, 20); - this.TB_IsSet.TabIndex = 2; - // - // B_LoadNew - // - this.B_LoadNew.Location = new System.Drawing.Point(12, 45); - this.B_LoadNew.Name = "B_LoadNew"; - this.B_LoadNew.Size = new System.Drawing.Size(75, 23); - this.B_LoadNew.TabIndex = 1; - this.B_LoadNew.Text = "Load New"; - this.B_LoadNew.UseVisualStyleBackColor = true; - this.B_LoadNew.Click += new System.EventHandler(this.openSAV); - // - // B_LoadOld - // - this.B_LoadOld.Location = new System.Drawing.Point(12, 19); - this.B_LoadOld.Name = "B_LoadOld"; - this.B_LoadOld.Size = new System.Drawing.Size(75, 23); - this.B_LoadOld.TabIndex = 0; - this.B_LoadOld.Text = "Load Old"; - this.B_LoadOld.UseVisualStyleBackColor = true; - this.B_LoadOld.Click += new System.EventHandler(this.openSAV); - // - // flag_0963 - // - this.flag_0963.AutoSize = true; - this.flag_0963.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_0963.Location = new System.Drawing.Point(16, 19); - this.flag_0963.Name = "flag_0963"; - this.flag_0963.Size = new System.Drawing.Size(113, 17); - this.flag_0963.TabIndex = 14; - this.flag_0963.Text = "Mewtwo Defeated"; - this.flag_0963.UseVisualStyleBackColor = true; - this.flag_0963.Click += new System.EventHandler(this.toggleFlag); - // - // flag_0115 - // - this.flag_0115.AutoSize = true; - this.flag_0115.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_0115.Location = new System.Drawing.Point(16, 34); - this.flag_0115.Name = "flag_0115"; - this.flag_0115.Size = new System.Drawing.Size(112, 17); - this.flag_0115.TabIndex = 15; - this.flag_0115.Text = "Mewtwo Captured"; - this.flag_0115.UseVisualStyleBackColor = true; - this.flag_0115.Click += new System.EventHandler(this.toggleFlag); - // - // GB_Rebattle - // - this.GB_Rebattle.Controls.Add(this.flag_0114); - this.GB_Rebattle.Controls.Add(this.flag_0790); - this.GB_Rebattle.Controls.Add(this.flag_0115); - this.GB_Rebattle.Controls.Add(this.flag_0963); - this.GB_Rebattle.Location = new System.Drawing.Point(129, 12); - this.GB_Rebattle.Name = "GB_Rebattle"; - this.GB_Rebattle.Size = new System.Drawing.Size(152, 191); - this.GB_Rebattle.TabIndex = 16; - this.GB_Rebattle.TabStop = false; - this.GB_Rebattle.Text = "Rebattle"; - // - // flag_0114 - // - this.flag_0114.AutoSize = true; - this.flag_0114.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_0114.Location = new System.Drawing.Point(16, 72); - this.flag_0114.Name = "flag_0114"; - this.flag_0114.Size = new System.Drawing.Size(111, 17); - this.flag_0114.TabIndex = 17; - this.flag_0114.Text = "Zygarde Captured"; - this.flag_0114.UseVisualStyleBackColor = true; - this.flag_0114.Click += new System.EventHandler(this.toggleFlag); - // - // flag_0790 - // - this.flag_0790.AutoSize = true; - this.flag_0790.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_0790.Location = new System.Drawing.Point(16, 57); - this.flag_0790.Name = "flag_0790"; - this.flag_0790.Size = new System.Drawing.Size(112, 17); - this.flag_0790.TabIndex = 16; - this.flag_0790.Text = "Zygarde Defeated"; - this.flag_0790.UseVisualStyleBackColor = true; - this.flag_0790.Click += new System.EventHandler(this.toggleFlag); - // - // GB_Misc - // - this.GB_Misc.Controls.Add(this.flag_0289); - this.GB_Misc.Controls.Add(this.flag_0288); - this.GB_Misc.Controls.Add(this.flag_0287); - this.GB_Misc.Controls.Add(this.flag_0294); - this.GB_Misc.Controls.Add(this.flag_0293); - this.GB_Misc.Controls.Add(this.flag_0292); - this.GB_Misc.Controls.Add(this.flag_0291); - this.GB_Misc.Controls.Add(this.flag_0290); - this.GB_Misc.Controls.Add(this.flag_0675); - this.GB_Misc.Controls.Add(this.flag_0286); - this.GB_Misc.Controls.Add(this.flag_0285); - this.GB_Misc.Location = new System.Drawing.Point(287, 12); - this.GB_Misc.Name = "GB_Misc"; - this.GB_Misc.Size = new System.Drawing.Size(154, 215); - this.GB_Misc.TabIndex = 17; - this.GB_Misc.TabStop = false; - this.GB_Misc.Text = "Misc"; - // - // flag_0289 - // - this.flag_0289.AutoSize = true; - this.flag_0289.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_0289.Location = new System.Drawing.Point(6, 79); - this.flag_0289.Name = "flag_0289"; - this.flag_0289.Size = new System.Drawing.Size(94, 17); - this.flag_0289.TabIndex = 25; - this.flag_0289.Text = "Multi Statuette"; - this.flag_0289.UseVisualStyleBackColor = true; - this.flag_0289.Click += new System.EventHandler(this.toggleFlag); - // - // flag_0288 - // - this.flag_0288.AutoSize = true; - this.flag_0288.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_0288.Location = new System.Drawing.Point(6, 64); - this.flag_0288.Name = "flag_0288"; - this.flag_0288.Size = new System.Drawing.Size(112, 17); - this.flag_0288.TabIndex = 24; - this.flag_0288.Text = "Rotation Statuette"; - this.flag_0288.UseVisualStyleBackColor = true; - this.flag_0288.Click += new System.EventHandler(this.toggleFlag); - // - // flag_0287 - // - this.flag_0287.AutoSize = true; - this.flag_0287.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_0287.Location = new System.Drawing.Point(6, 49); - this.flag_0287.Name = "flag_0287"; - this.flag_0287.Size = new System.Drawing.Size(103, 17); - this.flag_0287.TabIndex = 23; - this.flag_0287.Text = "Triples Statuette"; - this.flag_0287.UseVisualStyleBackColor = true; - this.flag_0287.Click += new System.EventHandler(this.toggleFlag); - // - // flag_0294 - // - this.flag_0294.AutoSize = true; - this.flag_0294.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_0294.Location = new System.Drawing.Point(6, 159); - this.flag_0294.Name = "flag_0294"; - this.flag_0294.Size = new System.Drawing.Size(128, 17); - this.flag_0294.TabIndex = 22; - this.flag_0294.Text = "Super Multi Unlocked"; - this.flag_0294.UseVisualStyleBackColor = true; - this.flag_0294.Click += new System.EventHandler(this.toggleFlag); - // - // flag_0293 - // - this.flag_0293.AutoSize = true; - this.flag_0293.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_0293.Location = new System.Drawing.Point(6, 144); - this.flag_0293.Name = "flag_0293"; - this.flag_0293.Size = new System.Drawing.Size(146, 17); - this.flag_0293.TabIndex = 21; - this.flag_0293.Text = "Super Rotation Unlocked"; - this.flag_0293.UseVisualStyleBackColor = true; - this.flag_0293.Click += new System.EventHandler(this.toggleFlag); - // - // flag_0292 - // - this.flag_0292.AutoSize = true; - this.flag_0292.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_0292.Location = new System.Drawing.Point(6, 129); - this.flag_0292.Name = "flag_0292"; - this.flag_0292.Size = new System.Drawing.Size(137, 17); - this.flag_0292.TabIndex = 20; - this.flag_0292.Text = "Super Triples Unlocked"; - this.flag_0292.UseVisualStyleBackColor = true; - this.flag_0292.Click += new System.EventHandler(this.toggleFlag); - // - // flag_0291 - // - this.flag_0291.AutoSize = true; - this.flag_0291.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_0291.Location = new System.Drawing.Point(6, 114); - this.flag_0291.Name = "flag_0291"; - this.flag_0291.Size = new System.Drawing.Size(145, 17); - this.flag_0291.TabIndex = 19; - this.flag_0291.Text = "Super Doubles Unlocked"; - this.flag_0291.UseVisualStyleBackColor = true; - this.flag_0291.Click += new System.EventHandler(this.toggleFlag); - // - // flag_0290 - // - this.flag_0290.AutoSize = true; - this.flag_0290.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_0290.Location = new System.Drawing.Point(6, 99); - this.flag_0290.Name = "flag_0290"; - this.flag_0290.Size = new System.Drawing.Size(140, 17); - this.flag_0290.TabIndex = 18; - this.flag_0290.Text = "Super Singles Unlocked"; - this.flag_0290.UseVisualStyleBackColor = true; - this.flag_0290.Click += new System.EventHandler(this.toggleFlag); - // - // flag_0675 - // - this.flag_0675.AutoSize = true; - this.flag_0675.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_0675.Location = new System.Drawing.Point(6, 182); - this.flag_0675.Name = "flag_0675"; - this.flag_0675.Size = new System.Drawing.Size(119, 17); - this.flag_0675.TabIndex = 17; - this.flag_0675.Text = "50: Beat Chatelaine"; - this.flag_0675.UseVisualStyleBackColor = true; - this.flag_0675.Click += new System.EventHandler(this.toggleFlag); - // - // flag_0286 - // - this.flag_0286.AutoSize = true; - this.flag_0286.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_0286.Location = new System.Drawing.Point(6, 34); - this.flag_0286.Name = "flag_0286"; - this.flag_0286.Size = new System.Drawing.Size(111, 17); - this.flag_0286.TabIndex = 16; - this.flag_0286.Text = "Doubles Statuette"; - this.flag_0286.UseVisualStyleBackColor = true; - this.flag_0286.Click += new System.EventHandler(this.toggleFlag); - // - // flag_0285 - // - this.flag_0285.AutoSize = true; - this.flag_0285.CheckAlign = System.Drawing.ContentAlignment.TopLeft; - this.flag_0285.Location = new System.Drawing.Point(6, 19); - this.flag_0285.Name = "flag_0285"; - this.flag_0285.Size = new System.Drawing.Size(106, 17); - this.flag_0285.TabIndex = 15; - this.flag_0285.Text = "Singles Statuette"; - this.flag_0285.UseVisualStyleBackColor = true; - this.flag_0285.Click += new System.EventHandler(this.toggleFlag); - // - // flag_2546 - // - this.flag_2546.AutoSize = true; - this.flag_2546.Location = new System.Drawing.Point(13, 112); - this.flag_2546.Name = "flag_2546"; - this.flag_2546.Size = new System.Drawing.Size(114, 17); - this.flag_2546.TabIndex = 18; - this.flag_2546.Text = "Pokédex Obtained"; - this.flag_2546.UseVisualStyleBackColor = true; - this.flag_2546.Click += new System.EventHandler(this.toggleFlag); - // - // L_Stats - // - this.L_Stats.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.L_Stats.AutoSize = true; - this.L_Stats.Location = new System.Drawing.Point(290, 230); - this.L_Stats.Name = "L_Stats"; - this.L_Stats.Size = new System.Drawing.Size(85, 13); - this.L_Stats.TabIndex = 32; - this.L_Stats.Text = "Event Constants"; - // - // CB_Stats - // - this.CB_Stats.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.CB_Stats.DropDownHeight = 156; - this.CB_Stats.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.CB_Stats.DropDownWidth = 180; - this.CB_Stats.FormattingEnabled = true; - this.CB_Stats.IntegralHeight = false; - this.CB_Stats.Location = new System.Drawing.Point(293, 246); - this.CB_Stats.Name = "CB_Stats"; - this.CB_Stats.Size = new System.Drawing.Size(94, 21); - this.CB_Stats.TabIndex = 31; - this.CB_Stats.SelectedIndexChanged += new System.EventHandler(this.changeConstantIndex); - // - // L_Value - // - this.L_Value.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.L_Value.AutoSize = true; - this.L_Value.Location = new System.Drawing.Point(290, 270); - this.L_Value.Name = "L_Value"; - this.L_Value.Size = new System.Drawing.Size(34, 13); - this.L_Value.TabIndex = 30; - this.L_Value.Text = "Value"; - // - // MT_Stat - // - this.MT_Stat.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.MT_Stat.Font = new System.Drawing.Font("Courier New", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.MT_Stat.Location = new System.Drawing.Point(349, 270); - this.MT_Stat.Mask = "00000"; - this.MT_Stat.Name = "MT_Stat"; - this.MT_Stat.Size = new System.Drawing.Size(38, 20); - this.MT_Stat.TabIndex = 29; - this.MT_Stat.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; - // - // SAV_EventFlagsXY - // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(449, 342); - this.Controls.Add(this.L_Stats); - this.Controls.Add(this.CB_Stats); - this.Controls.Add(this.L_Value); - this.Controls.Add(this.MT_Stat); - this.Controls.Add(this.flag_2546); - this.Controls.Add(this.GB_Misc); - this.Controls.Add(this.GB_Rebattle); - this.Controls.Add(this.GB_Researcher); - this.Controls.Add(this.flag_2239); - this.Controls.Add(this.flag_2238); - this.Controls.Add(this.flag_2237); - this.Controls.Add(this.B_Save); - this.Controls.Add(this.flag_0005); - this.Controls.Add(this.flag_0004); - this.Controls.Add(this.flag_0003); - this.Controls.Add(this.flag_0002); - this.Controls.Add(this.flag_0001); - this.Controls.Add(this.GB_FlagStatus); - this.Controls.Add(this.B_Cancel); - this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; - this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); - this.MaximizeBox = false; - this.MinimizeBox = false; - this.Name = "SAV_EventFlagsXY"; - this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; - this.Text = "Event Flag Editor"; - this.GB_FlagStatus.ResumeLayout(false); - this.GB_FlagStatus.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)(this.nud)).EndInit(); - this.GB_Researcher.ResumeLayout(false); - this.GB_Researcher.PerformLayout(); - this.GB_Rebattle.ResumeLayout(false); - this.GB_Rebattle.PerformLayout(); - this.GB_Misc.ResumeLayout(false); - this.GB_Misc.PerformLayout(); - this.ResumeLayout(false); - this.PerformLayout(); - - } - - #endregion - - private System.Windows.Forms.CheckBox CHK_CustomFlag; - private System.Windows.Forms.Button B_Cancel; - private System.Windows.Forms.GroupBox GB_FlagStatus; - private System.Windows.Forms.Label L_Flag; - private System.Windows.Forms.CheckBox flag_0001; - private System.Windows.Forms.CheckBox flag_0002; - private System.Windows.Forms.CheckBox flag_0003; - private System.Windows.Forms.CheckBox flag_0004; - private System.Windows.Forms.CheckBox flag_0005; - private System.Windows.Forms.NumericUpDown nud; - private System.Windows.Forms.Button B_Save; - private System.Windows.Forms.CheckBox flag_2237; - private System.Windows.Forms.CheckBox flag_2238; - private System.Windows.Forms.CheckBox flag_2239; - private System.Windows.Forms.GroupBox GB_Researcher; - private System.Windows.Forms.Label L_UnSet; - private System.Windows.Forms.Label L_IsSet; - private System.Windows.Forms.TextBox TB_NewSAV; - private System.Windows.Forms.TextBox TB_OldSAV; - private System.Windows.Forms.TextBox TB_UnSet; - private System.Windows.Forms.TextBox TB_IsSet; - private System.Windows.Forms.Button B_LoadNew; - private System.Windows.Forms.Button B_LoadOld; - private System.Windows.Forms.CheckBox flag_0963; - private System.Windows.Forms.CheckBox flag_0115; - private System.Windows.Forms.GroupBox GB_Rebattle; - private System.Windows.Forms.CheckBox flag_0114; - private System.Windows.Forms.CheckBox flag_0790; - private System.Windows.Forms.GroupBox GB_Misc; - private System.Windows.Forms.CheckBox flag_0289; - private System.Windows.Forms.CheckBox flag_0288; - private System.Windows.Forms.CheckBox flag_0287; - private System.Windows.Forms.CheckBox flag_0294; - private System.Windows.Forms.CheckBox flag_0293; - private System.Windows.Forms.CheckBox flag_0292; - private System.Windows.Forms.CheckBox flag_0291; - private System.Windows.Forms.CheckBox flag_0290; - private System.Windows.Forms.CheckBox flag_0675; - private System.Windows.Forms.CheckBox flag_0286; - private System.Windows.Forms.CheckBox flag_0285; - private System.Windows.Forms.CheckBox flag_2546; - private System.Windows.Forms.Label L_Stats; - private System.Windows.Forms.ComboBox CB_Stats; - private System.Windows.Forms.Label L_Value; - private System.Windows.Forms.MaskedTextBox MT_Stat; - } -} \ No newline at end of file diff --git a/SAV/SAV_EventFlagsXY.cs b/SAV/SAV_EventFlagsXY.cs deleted file mode 100644 index 985850f51..000000000 --- a/SAV/SAV_EventFlagsXY.cs +++ /dev/null @@ -1,230 +0,0 @@ -using System; -using System.Collections; -using System.Drawing; -using System.IO; -using System.Linq; -using System.Windows.Forms; - -namespace PKHeX -{ - public partial class SAV_EventFlagsXY : Form - { - public SAV_EventFlagsXY() - { - InitializeComponent(); - Util.TranslateInterface(this, Main.curlanguage); - - AllowDrop = true; - DragEnter += tabMain_DragEnter; - DragDrop += tabMain_DragDrop; - Setup(); - - nud.Text = "0"; // Prompts an update for flag 0. - // No Volcanic Ash in X/Y - } - private bool setup = true; - private CheckBox[] chka; - private readonly bool[] flags = new bool[3072]; - private readonly ushort[] Constants = new ushort[(Main.SAV.EventFlag - Main.SAV.EventConst) / 2]; - private void B_Cancel_Click(object sender, EventArgs e) - { - Close(); - } - private void B_Save_Click(object sender, EventArgs e) - { - // Gather Updated Flags - foreach (CheckBox flag in chka) - flags[getFlagNum(flag)] = flag.Checked; - - byte[] data = new byte[flags.Length / 8]; - - for (int i = 0; i < flags.Length; i++) - if (flags[i]) - data[i / 8] |= (byte)(1 << i % 8); - - Array.Copy(data, 0, Main.SAV.Data, Main.SAV.EventFlag, 0x180); - - // No Volcanic Ash in X/Y - - - // Copy back Constants - changeConstantIndex(null, null); // Trigger Saving - for (int i = 0; i < Constants.Length; i++) - Array.Copy(BitConverter.GetBytes(Constants[i]), 0, Main.SAV.Data, Main.SAV.EventConst + 2 * i, 2); - - Close(); - } - private void Setup() - { - // Fill Bit arrays - - chka = new[] { - flag_0001,flag_0002,flag_0003,flag_0004,flag_0005, - flag_2237,flag_2238,flag_2239, - flag_0115,flag_0963, // Mewtwo - flag_0114,flag_0790, // Zygarde - flag_0285,flag_0286,flag_0287,flag_0288,flag_0289, // Statuettes - flag_0290,flag_0291,flag_0292,flag_0293,flag_0294, // Super Unlocks - flag_0675, // Chatelaine 50 - flag_2546, // Pokedex - }; - byte[] data = new byte[0x180]; - Array.Copy(Main.SAV.Data, Main.SAV.EventFlag, data, 0, 0x180); - BitArray BitRegion = new BitArray(data); - BitRegion.CopyTo(flags, 0); - - // Setup Event Constant Editor - CB_Stats.Items.Clear(); - for (int i = 0; i < Constants.Length; i += 2) - { - CB_Stats.Items.Add($"0x{(i/2).ToString("X2")}"); - Constants[i / 2] = BitConverter.ToUInt16(Main.SAV.Data, Main.SAV.EventConst + i); - } - CB_Stats.SelectedIndex = 0; - - // Populate Flags - setup = true; - popFlags(); - } - private void popFlags() - { - if (!setup) return; - foreach (CheckBox flag in chka) - flag.Checked = flags[getFlagNum(flag)]; - - changeCustomFlag(null, null); - } - - private int getFlagNum(CheckBox chk) - { - try - { - string source = chk.Name; - return Convert.ToInt32(source.Substring(Math.Max(0, source.Length - 4))); - } - catch { return 0; } - } - private void changeCustomBool(object sender, EventArgs e) - { - flags[(int)nud.Value] = CHK_CustomFlag.Checked; - popFlags(); - } - private void changeCustomFlag(object sender, EventArgs e) - { - int flag = (int)nud.Value; - if (flag >= 3072) - { - CHK_CustomFlag.Checked = false; - CHK_CustomFlag.Enabled = false; - nud.BackColor = Color.Red; - } - else - { - CHK_CustomFlag.Enabled = true; - nud.BackColor = Main.defaultControlWhite; - CHK_CustomFlag.Checked = flags[flag]; - } - } - private void changeCustomFlag(object sender, KeyEventArgs e) - { - changeCustomFlag(null, (EventArgs)e); - } - - private void toggleFlag(object sender, EventArgs e) - { - flags[getFlagNum((CheckBox)sender)] = ((CheckBox)sender).Checked; - changeCustomFlag(sender, e); - } - - private void changeSAV(object sender, EventArgs e) - { - if (TB_NewSAV.Text.Length > 0 && TB_OldSAV.Text.Length > 0) - { - diffSaves(); - } - } - private void diffSaves() - { - BitArray oldBits = new BitArray(oldFlags); - BitArray newBits = new BitArray(newFlags); - - string tbIsSet = ""; - string tbUnSet = ""; - for (int i = 0; i < oldBits.Length; i++) - { - if (oldBits[i] == newBits[i]) continue; - if (newBits[i]) - tbIsSet += i.ToString("0000") + ","; - else - tbUnSet += i.ToString("0000") + ","; - } - TB_IsSet.Text = tbIsSet; - TB_UnSet.Text = tbUnSet; - - if (DialogResult.Yes != Util.Prompt(MessageBoxButtons.YesNo, "Copy Event Constant diff to clipboard?")) - return; - - string r = ""; - for (int i = 0; i < newConst.Length; i += 2) - { - ushort oldval = BitConverter.ToUInt16(oldConst, i); - ushort newval = BitConverter.ToUInt16(oldConst, i); - if (oldval != newval) - r += $"0x{(i/2).ToString("X2")}: {oldval}->{newval}{Environment.NewLine}"; - } - Clipboard.SetText(r); - } - private byte[] oldFlags = new byte[0x180]; - private byte[] newFlags = new byte[0x180]; - private byte[] oldConst = new byte[Main.SAV.EventFlag - Main.SAV.EventConst]; - private byte[] newConst = new byte[Main.SAV.EventFlag - Main.SAV.EventConst]; - private void openSAV(object sender, EventArgs e) - { - OpenFileDialog ofd = new OpenFileDialog(); - if (ofd.ShowDialog() == DialogResult.OK) - loadSAV(sender, ofd.FileName); - } - private void loadSAV(object sender, string path) - { - FileInfo fi = new FileInfo(path); - if (fi.Length != SAV6.SIZE_XY) - { - Util.Error("Invalid SAV Size", string.Format("File Size: 0x{1} ({0} bytes)", fi.Length, fi.Length.ToString("X5")), "File Loaded: " + path); - return; - } - - byte[] data = File.ReadAllBytes(path); - if (sender == B_LoadOld) - { - oldFlags = data.Skip(Main.SAV.EventFlag).Take(0x180).ToArray(); - oldConst = data.Skip(Main.SAV.EventConst).Take(Constants.Length * 2).ToArray(); - TB_OldSAV.Text = path; - } - else - { - newFlags = data.Skip(Main.SAV.EventFlag).Take(0x180).ToArray(); - newConst = data.Skip(Main.SAV.EventConst).Take(Constants.Length * 2).ToArray(); - TB_NewSAV.Text = path; - } - } - private int entry = -1; - private void changeConstantIndex(object sender, EventArgs e) - { - if (entry > -1) // Set Entry - Constants[entry] = (ushort)Math.Min(Util.ToUInt32(MT_Stat.Text), 0xFFFF); - - entry = CB_Stats.SelectedIndex; // Get Entry - MT_Stat.Text = Constants[entry].ToString(); - } - // Drag & Drop Events - private void tabMain_DragEnter(object sender, DragEventArgs e) - { - if (e.Data.GetDataPresent(DataFormats.FileDrop)) e.Effect = DragDropEffects.Copy; - } - private void tabMain_DragDrop(object sender, DragEventArgs e) - { - string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); - loadSAV(Util.Prompt(MessageBoxButtons.YesNo, "FlagDiff Researcher:", "Yes: Old Save" + Environment.NewLine + "No: New Save") == DialogResult.Yes ? B_LoadOld : B_LoadNew, files[0]); - } - } -} \ No newline at end of file diff --git a/SAV/SAV_EventFlagsXY.resx b/SAV/SAV_EventFlagsXY.resx deleted file mode 100644 index 603f660be..000000000 --- a/SAV/SAV_EventFlagsXY.resx +++ /dev/null @@ -1,216 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - - - AAABAAIAEBAAAAEAIABoBAAAJgAAACAgAAABACAAqBAAAI4EAAAoAAAAEAAAACAAAAABACAAAAAAAAAE - AAAAAAAAAAAAAAAAAAAAAAAAIyMjAQAAAAALCwsPJiYmJysrKycqKionKSkpJykpKScpKSknKioqJyoq - KicrKysnJycnJw0ODQ8AAAAAJiYmAQAAAABpaWlHq6ur17+/v+6+vr7svr6+7b6+vu2+vr7tvr6+7b6+ - vu2+vr7tvr6+7L+/v+6rq6vXampqSAAAAAAoKSgXvr++3eLi4v/g4OD94eHh/+Hh4f/i4uL/4uLi/+Li - 4v/i4uL/4eHh/+Dh4P/g4OD94uLi/7+/v90sLCwXfn5+PNna2frg4OD/39/f/uHh4f7h4eH+39/f/uDg - 4P7g4OD+39/f/uHh4f7h4OH+39/f/t/g3//a2tr6g4ODPoOCgz7X19f64+Pj/+Li4v7k5OT/4+Tj//Ly - 8v/19fX/9PT0//T09P/k5OT/5OTk/+Pj4/7j4+P/19jX+4qLikCDhIM+2tra++Xl5f/k5eT+5OTk//Lz - 8v+urq7/RUVF/z4+Pv+Zmpn/8fHx/+Xm5f/k5eT+5eXl/9ra2vyLi4tAhYWFPuXm5vvx8vP/7+/w/v// - //+sra3/AgIC/15eXv9tbG3/BQUF/4yMjP//////7+/w/vHy8//l5ub8jY2NQC4uLD5LS0f7UFBL/09P - Sv5YWVP/FBUS/29wcP///////////5SUlP8PDw//U1NO/1BQS/5PT0r/S0tH/DIyMEAAAAs+AAAM+wAA - Dv8AAA/+AwMS/wAAAP+UlJX///////////+3t7n/AAAA/wAAD/8BAQ/+AAAO/wAADPwCAg5ABARSPgoK - k/sNDab/DQ2o/hAQvP8CAmj/IiIW/7Kzrv/Cw8D/NDQm/wAATf8QELz/DQ2q/gwMp/8LC5T8Dg5bQAUF - Xj4KCpz7DQ2u/w0NsP4NDbX/Dw+//wUFYf8CAhL/AwMP/wMDTf8ODrj/Dg64/w0NsP4MDK7/Cwud/A8P - aEEGBmU9DAyl+w4Otf8ODrf+Dw+6/xAQvv8TE8v/EhK+/xAQvP8TE8v/EBDA/w8Puf8PD7f+Dg61/w0N - pvsREW9ACAhtQA8PsfsTE77/ExO//xQUwP8UFML/FBTD/xUVyP8WFsn/FRXE/xQUw/8UFMH/ExO//xMT - vv8QELL7ERF3QxkZdCgXF771ExPH/xUVyPwVFcn9FhbL/RcXzP0XF8z9FxfM/RcXy/0XF8v9FhbJ/RUV - yPwTE8f/Fxe+9RkZdykAAAAAIyOtghsbx/8ZGcj+GRnJ/xoayf8aGsn/GhrK/xoayv8aGsn/GhrJ/xkZ - yf8ZGcj+GxvH/yMjrYQAAAAAAADHAQAAAAAzM51FLCyscCoqrGwqKqxtKSmsbSoqrG0qKqxtKSmsbSoq - rG0qKqxsLCyscDMznUUAAAAAAAAAAP//AADAAwAAgAEAAIABAACAAQAAgAEAAIABAACAAQAAgAEAAIAB - AACAAQAAgAEAAIABAACAAQAAgAEAAP//AAAoAAAAIAAAAEAAAAABACAAAAAAAAAQAAAAAAAAAAAAAAAA - AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA - AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA - AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAKysrCR0dHSMWFhY3GBgYORgYGDkYGBg5GBgYORgY - GDkYGBg5GBgYORgYGDkYGBg5GBgYORgYGDkYGBg5GBgYORgYGDkYGBg5GBgYORgYGDkYGBg5FxcXNx4e - HiQuLi4JAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAASEhIARYWFis7OzuVkJCQ2ampqeqqqqrsqqqq7Kqq - quyqqqrsqqqq7Kqqquyqqqrsqqqq7Kqqquyqqqrsqqqq7Kqqquyqqqrsqqqq7Kqqquyqqqrsqqqq7Kqq - quypqanqkZGR2j09PZcXFxcsUFBQAQAAAAAAAAAAAAAAAAAAAAASEhIuhISEytvb2/7W1tb/19fX/9jY - 2P/Y2Nj/2NjY/9jY2P/Y2Nj/2NjY/9nZ2f/Z2dn/2dnZ/9nZ2f/Z2dn/2dnZ/9nZ2f/Y2Nj/2NjY/9jY - 2P/Y2Nj/2NjY/9fX1//W1tb/29vb/oeHh8sTExMvAAAAAAAAAAAAAAAAPDw8DGtra6zZ2dn/2dnZ/9ra - 2v/b29v/29vb/9vb2//c3Nz/3Nzc/9zc3P/c3Nz/3d3d/93d3f/d3d3/3d3d/93d3f/d3d3/3Nzc/9zc - 3P/c3Nz/3Nzc/9vb2//b29v/29vb/9ra2v/Z2dn/2dnZ/21tba5DQ0MNAAAAAAAAAAAiIiIx1NXU9tna - 2f/c3Nz/3d3d/93e3f/e3t7/3t7e/9/f3//f39//39/f/9/g3//g4OD/4ODg/+Dg4P/g4OD/4ODg/+Dg - 4P/g4OD/39/f/9/f3//f39//3t/e/97e3v/d3t3/3d3d/9zc3P/Z2tn/1dXV9icnJzMAAAAAAAAAAFhZ - WFzf4N//3Nzc/97e3v/f39//39/f/9/g3//g4OD/4ODg/+Hh4f/h4eH/4eHh/+Li4v/i4uL/4uLi/+Li - 4v/i4uL/4uLi/+Hi4f/h4eH/4eHh/+Dg4P/g4OD/3+Df/9/f3//f39//3t7e/9zc3P/f39//XV1dXQAA - AAAAAAAAZmZmZdvc2//e3t7/3+Df/+Dg4P/g4eD/4eHh/+Hi4f/i4uL/4uPi/+Pj4//j4+P/5OTk/+Tk - 5P/k5OT/5OTk/+Tk5P/k5OT/4+Pj/+Pj4//j4+P/4uLi/+Li4v/h4eH/4eHh/+Dg4P/f4N//3t7e/9vb - 2/9wcHBoAAAAAAAAAABoaGhl3d3d/9/f3//h4eH/4eLh/+Li4v/j4+P/4+Pj/+Tk5P/k5OT/5eXl/+Xl - 5f/l5uX/5ubm/+bm5v/m5ub/5ubm/+bm5v/l5eX/5eXl/+Tk5P/k5OT/4+Pj/+Pj4//i4uL/4uLi/+Hh - 4f/f39//3N3c/3Nzc2kAAAAAAAAAAGhoaGXe3t7/4ODg/+Li4v/j4+P/4+Pj/+Tk5P/l5eX/5eXl/+bm - 5v/m5+b/5+fn/+fn5//n6Of/6Ojo/+jo6P/o6Oj/5+fn/+fn5//n5+f/5ubm/+Xl5f/l5eX/5OTk/+Pk - 4//j4+P/4uLi/+Dg4P/e3t7/c3NzaQAAAAAAAAAAaGhoZd/g3//i4uL/5OTk/+Tl5P/l5eX/5ebl/+bn - 5v/n5+f/5+jn/+jp6P/p6en/7Ozs/8LCwv+Tk5P/ioqK/66urv/o6ej/6enp/+jp6P/o6Oj/5+jn/+bn - 5v/m5ub/5ebl/+Tl5P/k5OT/4uLi/9/g3/9zdHNpAAAAAAAAAABoaWhl4eLh/+Pk4//m5ub/5ubm/+fn - 5//n6Of/6Ojo/+np6f/p6un/6urq/8bGxv8yMjL/AAAA/wAAAP8AAAD/AAAA/xMTE/+ZmZn/7Ozs/+rq - 6v/p6en/6Ojo/+jo6P/n5+f/5ubm/+bm5v/k5OT/4eHh/3R0dGkAAAAAAAAAAGhpaGXj4+P/5eXl/+fn - 5//n6Of/6Ojo/+np6f/q6ur/6urq/+vr6//Dw8P/DAwM/wAAAP8AAAD/Gxsb/ygoKP8BAQH/AAAA/wAA - AP+FhYX/7O3s/+rr6v/q6ur/6enp/+jo6P/o6Oj/5+fn/+Xl5f/i4+L/dHR0aQAAAAAAAAAAYWFhZeTl - 5P/m5+b/6Ono/+np6f/p6un/6uvq/+vr6//s7Oz/7e7t/ycnJ/8AAAD/Ghoa/7S0tP/m5ub/5OTk/9HR - 0f9GRkb/AAAA/wICAv/IyMj/7Ozs/+vs6//q6+r/6urq/+nq6f/o6ej/5+fn/+Tk5P9sbGxpAAAAAAAA - AAA9Pj1lj4+P/5OTk/+VlZX/lpaW/5eXl/+YmJj/mZmZ/5qamv92dnb/AAAA/wEBAf+/wL//3Nzc/+Tk - 5P/l5eX/3d3d/+Li4v8mJib/AAAA/0ZGRv+ampr/mZmZ/5iYmP+Xl5f/lpaW/5WVlf+Tk5P/j4+P/0ZG - RmoAAAAAAAAAAAwMDGUAAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/Nzc3/+fn - 5//q6ur/7O3s/+zt7P/v7+//39/f/4WFhf8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAA - AP8AAAD/EBAQagAAAAAAAAAAAwMHZQAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAA - AP9NTU3/5ufm//Lz8v/z9PP/8/Tz//X19f/l5eX/nZ2d/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAA - AP8AAAD/AAAA/wAAAP8GBgpqAAAAAAAAAAAAABZlAQEk/wEBJ/8CAin/AgIq/wICKv8CAiv/AgIs/wIC - LP8BAR3/AAAA/xwcHP/w8PD/6+zr//r6+v/6+vr/9PT0/+vr6/9lZWX/AAAA/wAAD/8CAi3/AgIs/wIC - K/8CAir/AgIq/wICKf8BASf/AQEl/wUFG2oAAAAAAAAAAAICQGUGBpL/Bwec/wgIo/8JCaf/CQmq/wkJ - rf8JCa//Cgqz/wkJqP8AAAL/AAAA/4CAgP/y8/L/6+zr/+3t7f/u7u7/xMTE/wcHB/8AAAD/BgZz/woK - s/8JCbD/CQmt/wkJqv8JCaj/CAik/wcHnf8HB5P/Dg5MagAAAAAAAAAAAwNHZQgIk/8JCZ3/Cgqj/wsL - p/8LC6n/Cwus/wsLr/8MDLL/DAy2/wYGW/8AAAD/AAAA/1JSUv+sraz/tra2/3h4eP8KCgr/AAAA/wIC - Iv8MDLb/DAyy/wsLsP8LC63/Cwuq/wsLp/8KCqT/CQmd/wgIk/8PD1VrAAAAAAAAAAAEBE1lCQmY/woK - ov8LC6j/DAyr/wwMrf8MDLD/DAyy/w0Ntf8NDbf/Dg67/wUFSv8AAAD/AAAA/wAAAP8AAAD/AAAA/wAA - AP8CAiH/DQ2q/w0NuP8NDbX/DQ2z/wwMsP8MDK7/DAyr/wsLqP8KCqL/CQmZ/xAQWmsAAAAAAAAAAAQE - UGUKCp7/Cwum/wwMrP8NDa//DQ2w/w0Ns/8ODrX/Dg63/w4Ouf8ODrv/Dw/A/wwMiv8FBTj/AAAG/wAA - AP8DAyb/CQls/w8Pu/8PD7z/Dg66/w4OuP8ODrX/DQ2z/w0Nsf8NDa//DAys/wsLp/8KCp7/ERFeawAA - AAAAAAAABQVTZQsLpP8MDKv/DQ2w/w4Os/8ODrT/Dg62/w8PuP8PD7r/Dw+8/w8Pvf8QEL//EBDA/xER - w/8SEsn/ERHJ/xERxf8QEMD/EBC//w8Pvv8PD7z/Dw+6/w8PuP8ODrf/Dg61/w4Os/8NDbH/DAyr/wsL - pP8SEmFrAAAAAAAAAAAGBlZlDAyq/w4OsP8PD7X/Dw+3/w8PuP8QELr/EBC7/xAQvf8REb7/ERHA/xER - wf8REcL/EhLC/xISw/8SEsP/EhLC/xERwv8REcH/ERHA/xERvv8QEL3/EBC7/xAQuv8QELj/Dw+3/w8P - tf8ODrD/DAyq/xMTZWsAAAAAAAAAAAcHWmUODrD/EBC2/xERuv8REbz/ERG9/xISvv8SEr//EhLA/xMT - wf8TE8P/ExPD/xMTxP8TE8X/FBTF/xQUxf8UFMX/ExPE/xMTxP8TE8P/ExPC/xISwf8SEr//EhK+/xER - vf8REbz/ERG6/xAQtv8ODrD/FBRpawAAAAAAAAAACAhcYxAQtf8SErv/ExO+/xQUwP8UFMD/FBTB/xUV - wv8VFcP/FRXE/xUVxf8WFsb/FhbG/xYWx/8WFsf/FhbH/xYWx/8WFsf/FhbG/xYWxf8VFcT/FRXD/xUV - wv8UFMH/FBTB/xQUwP8TE77/EhK7/xAQtf8TE2hoAAAAAAAAAAAQEFNUFRXC/xMTv/8UFMP/FRXE/xUV - xP8VFcX/FRXG/xYWx/8WFsf/FhbI/xYWyf8XF8n/FxfK/xcXyv8XF8r/FxfK/xcXyf8XF8n/FhbI/xYW - yP8WFsf/FhbG/xUVxf8VFcT/FRXE/xQUw/8TE7//FRXB/xAQV1UAAAAAAAAAAA0NPxkjI8byFBTD/xUV - x/8WFsj/FxfJ/xcXyf8XF8r/FxfK/xcXy/8YGMz/GBjM/xgYzP8YGM3/GBjN/xgYzf8YGM3/GBjM/xgY - zP8YGMz/GBjL/xcXy/8XF8r/FxfJ/xcXyf8WFsj/FRXH/xQUw/8jI8f0Dg5GGwAAAAAAAAAAFhZxAiUl - eIUZGcr/FBTI/xUVyv8WFsv/FhbM/xYWzP8WFsz/FhbN/xcXzf8XF83/FxfN/xcXzv8XF87/FxfO/xcX - zv8XF87/FxfN/xcXzf8WFs3/FhbM/xYWzP8WFsz/FhbL/xUVyv8UFMj/GBjJ/yYmeogWFnYCAAAAAAAA - AAAAAAAAGBh1BzMzk50kJNP+FxfK/xgYzP8YGMz/GBjN/xgYzf8YGM3/GBjN/xgYzf8ZGc7/GRnO/xkZ - zv8ZGc7/GRnO/xkZzv8YGM3/GBjN/xgYzf8YGM3/GBjN/xgYzP8YGMz/FxfK/yMj0v4zM5WfFBRkBwAA - AAAAAAAAAAAAAAAAAAAAAAAAHBx7Ay0tdkg3N5emMTGpxSwsp8gsLKfILCynyCwsp8gsLKfILCynyCws - p8gsLKfILCynyCwsp8gsLKfILCynyCwsp8gsLKfILCynyCwsp8gsLKfILCynyDExqcU2NpenLi54Shsb - ewMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA - AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA - AAAAAAAAAAAAAAAAAAAAAAAAAAAAAP//////////8AAAD+AAAAfAAAADwAAAA8AAAAPAAAADwAAAA8AA - AAPAAAADwAAAA8AAAAPAAAADwAAAA8AAAAPAAAADwAAAA8AAAAPAAAADwAAAA8AAAAPAAAADwAAAA8AA - AAPAAAADwAAAA8AAAAPAAAAD4AAAB/gAAB////// - - - \ No newline at end of file diff --git a/SAV/SAV_HallOfFame.cs b/SAV/SAV_HallOfFame.cs index d4cdf8fa0..f074973a0 100644 --- a/SAV/SAV_HallOfFame.cs +++ b/SAV/SAV_HallOfFame.cs @@ -13,7 +13,7 @@ public SAV_HallOfFame() InitializeComponent(); Util.TranslateInterface(this, Main.curlanguage); - Array.Copy(Main.SAV.Data, Main.SAV.HoF, data, 0, data.Length); //Copy HoF section of save into Data + Array.Copy(SAV.Data, SAV.HoF, data, 0, data.Length); //Copy HoF section of save into Data Setup(); editor_spec = new object[]{ GB_OT, @@ -49,6 +49,7 @@ public SAV_HallOfFame() editing = true; } private bool editing; + private readonly SAV6 SAV = new SAV6(Main.SAV.Data); private readonly string[] gendersymbols = Main.gendersymbols; private readonly byte[] data = new byte[0x1B40]; @@ -98,7 +99,7 @@ private void B_Cancel_Click(object sender, EventArgs e) } private void B_Close_Click(object sender, EventArgs e) { - Array.Copy(data, 0, Main.SAV.Data, Main.SAV.HoF, data.Length); + Array.Copy(data, 0, Main.SAV.Data, SAV.HoF, data.Length); Main.SAV.Edited = true; Close(); } diff --git a/SAV/SAV_Inventory.Designer.cs b/SAV/SAV_Inventory.Designer.cs index 7cf2bf3e5..1713adbbd 100644 --- a/SAV/SAV_Inventory.Designer.cs +++ b/SAV/SAV_Inventory.Designer.cs @@ -28,49 +28,21 @@ protected override void Dispose(bool disposing) /// private void InitializeComponent() { + this.components = new System.ComponentModel.Container(); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(SAV_Inventory)); - this.dataGridView1 = new System.Windows.Forms.DataGridView(); this.B_Cancel = new System.Windows.Forms.Button(); this.B_Save = new System.Windows.Forms.Button(); - this.GB_Pouch = new System.Windows.Forms.GroupBox(); - this.B_DisplayBerries = new System.Windows.Forms.Button(); - this.B_DisplayMedicine = new System.Windows.Forms.Button(); - this.B_DisplayTMHM = new System.Windows.Forms.Button(); - this.B_DisplayKeyItems = new System.Windows.Forms.Button(); - this.B_DisplayItems = new System.Windows.Forms.Button(); - ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); - this.GB_Pouch.SuspendLayout(); + this.tabControl1 = new System.Windows.Forms.TabControl(); + this.IL_Pouch = new System.Windows.Forms.ImageList(this.components); + this.B_GiveAll = new System.Windows.Forms.Button(); this.SuspendLayout(); // - // dataGridView1 - // - this.dataGridView1.AllowUserToAddRows = false; - this.dataGridView1.AllowUserToDeleteRows = false; - this.dataGridView1.AllowUserToResizeColumns = false; - this.dataGridView1.AllowUserToResizeRows = false; - this.dataGridView1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom))); - this.dataGridView1.BackgroundColor = System.Drawing.SystemColors.ControlLightLight; - this.dataGridView1.CellBorderStyle = System.Windows.Forms.DataGridViewCellBorderStyle.None; - this.dataGridView1.ColumnHeadersBorderStyle = System.Windows.Forms.DataGridViewHeaderBorderStyle.Single; - this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.dataGridView1.ColumnHeadersVisible = false; - this.dataGridView1.EditMode = System.Windows.Forms.DataGridViewEditMode.EditOnEnter; - this.dataGridView1.Location = new System.Drawing.Point(12, 12); - this.dataGridView1.MultiSelect = false; - this.dataGridView1.Name = "dataGridView1"; - this.dataGridView1.RowHeadersVisible = false; - this.dataGridView1.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.CellSelect; - this.dataGridView1.ShowEditingIcon = false; - this.dataGridView1.Size = new System.Drawing.Size(200, 190); - this.dataGridView1.TabIndex = 12; - this.dataGridView1.CellClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dropclick); - // // B_Cancel // this.B_Cancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.B_Cancel.Location = new System.Drawing.Point(221, 179); + this.B_Cancel.Location = new System.Drawing.Point(177, 328); this.B_Cancel.Name = "B_Cancel"; - this.B_Cancel.Size = new System.Drawing.Size(48, 23); + this.B_Cancel.Size = new System.Drawing.Size(70, 23); this.B_Cancel.TabIndex = 14; this.B_Cancel.Text = "Cancel"; this.B_Cancel.UseVisualStyleBackColor = true; @@ -79,117 +51,75 @@ private void InitializeComponent() // B_Save // this.B_Save.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.B_Save.Location = new System.Drawing.Point(275, 179); + this.B_Save.Location = new System.Drawing.Point(253, 328); this.B_Save.Name = "B_Save"; - this.B_Save.Size = new System.Drawing.Size(48, 23); + this.B_Save.Size = new System.Drawing.Size(70, 23); this.B_Save.TabIndex = 15; this.B_Save.Text = "Save"; this.B_Save.UseVisualStyleBackColor = true; this.B_Save.Click += new System.EventHandler(this.B_Save_Click); // - // GB_Pouch + // tabControl1 // - this.GB_Pouch.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.GB_Pouch.Controls.Add(this.B_DisplayBerries); - this.GB_Pouch.Controls.Add(this.B_DisplayMedicine); - this.GB_Pouch.Controls.Add(this.B_DisplayTMHM); - this.GB_Pouch.Controls.Add(this.B_DisplayKeyItems); - this.GB_Pouch.Controls.Add(this.B_DisplayItems); - this.GB_Pouch.Location = new System.Drawing.Point(221, 6); - this.GB_Pouch.Name = "GB_Pouch"; - this.GB_Pouch.Size = new System.Drawing.Size(102, 167); - this.GB_Pouch.TabIndex = 16; - this.GB_Pouch.TabStop = false; - this.GB_Pouch.Text = "Pouches"; + this.tabControl1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.tabControl1.ImageList = this.IL_Pouch; + this.tabControl1.Location = new System.Drawing.Point(12, 12); + this.tabControl1.Name = "tabControl1"; + this.tabControl1.SelectedIndex = 0; + this.tabControl1.Size = new System.Drawing.Size(311, 308); + this.tabControl1.TabIndex = 17; // - // B_DisplayBerries + // IL_Pouch // - this.B_DisplayBerries.Location = new System.Drawing.Point(14, 135); - this.B_DisplayBerries.Name = "B_DisplayBerries"; - this.B_DisplayBerries.Size = new System.Drawing.Size(75, 23); - this.B_DisplayBerries.TabIndex = 4; - this.B_DisplayBerries.Text = "Berry"; - this.B_DisplayBerries.UseMnemonic = false; - this.B_DisplayBerries.UseVisualStyleBackColor = true; - this.B_DisplayBerries.Click += new System.EventHandler(this.B_DisplayBerries_Click); + this.IL_Pouch.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("IL_Pouch.ImageStream"))); + this.IL_Pouch.TransparentColor = System.Drawing.Color.Transparent; + this.IL_Pouch.Images.SetKeyName(0, "Bag_Items.png"); + this.IL_Pouch.Images.SetKeyName(1, "Bag_Key.png"); + this.IL_Pouch.Images.SetKeyName(2, "Bag_TMHM.png"); + this.IL_Pouch.Images.SetKeyName(3, "Bag_Medicine.png"); + this.IL_Pouch.Images.SetKeyName(4, "Bag_Berries.png"); + this.IL_Pouch.Images.SetKeyName(5, "Bag_Balls.png"); + this.IL_Pouch.Images.SetKeyName(6, "Bag_Battle.png"); + this.IL_Pouch.Images.SetKeyName(7, "Bag_Mail.png"); // - // B_DisplayMedicine + // B_GiveAll // - this.B_DisplayMedicine.Location = new System.Drawing.Point(14, 106); - this.B_DisplayMedicine.Name = "B_DisplayMedicine"; - this.B_DisplayMedicine.Size = new System.Drawing.Size(75, 23); - this.B_DisplayMedicine.TabIndex = 3; - this.B_DisplayMedicine.Text = "Medicine"; - this.B_DisplayMedicine.UseMnemonic = false; - this.B_DisplayMedicine.UseVisualStyleBackColor = true; - this.B_DisplayMedicine.Click += new System.EventHandler(this.B_DisplayMedicine_Click); - // - // B_DisplayTMHM - // - this.B_DisplayTMHM.Location = new System.Drawing.Point(14, 77); - this.B_DisplayTMHM.Name = "B_DisplayTMHM"; - this.B_DisplayTMHM.Size = new System.Drawing.Size(75, 23); - this.B_DisplayTMHM.TabIndex = 2; - this.B_DisplayTMHM.Text = "TM/HM"; - this.B_DisplayTMHM.UseMnemonic = false; - this.B_DisplayTMHM.UseVisualStyleBackColor = true; - this.B_DisplayTMHM.Click += new System.EventHandler(this.B_DisplayTMHM_Click); - // - // B_DisplayKeyItems - // - this.B_DisplayKeyItems.Location = new System.Drawing.Point(14, 48); - this.B_DisplayKeyItems.Name = "B_DisplayKeyItems"; - this.B_DisplayKeyItems.Size = new System.Drawing.Size(75, 23); - this.B_DisplayKeyItems.TabIndex = 1; - this.B_DisplayKeyItems.Text = "Key Items"; - this.B_DisplayKeyItems.UseMnemonic = false; - this.B_DisplayKeyItems.UseVisualStyleBackColor = true; - this.B_DisplayKeyItems.Click += new System.EventHandler(this.B_DisplayKeyItems_Click); - // - // B_DisplayItems - // - this.B_DisplayItems.Location = new System.Drawing.Point(14, 19); - this.B_DisplayItems.Name = "B_DisplayItems"; - this.B_DisplayItems.Size = new System.Drawing.Size(75, 23); - this.B_DisplayItems.TabIndex = 0; - this.B_DisplayItems.Text = "Items"; - this.B_DisplayItems.UseMnemonic = false; - this.B_DisplayItems.UseVisualStyleBackColor = true; - this.B_DisplayItems.Click += new System.EventHandler(this.B_DisplayItems_Click); + this.B_GiveAll.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.B_GiveAll.Location = new System.Drawing.Point(12, 328); + this.B_GiveAll.Name = "B_GiveAll"; + this.B_GiveAll.Size = new System.Drawing.Size(75, 23); + this.B_GiveAll.TabIndex = 18; + this.B_GiveAll.Text = "Give All"; + this.B_GiveAll.UseVisualStyleBackColor = true; + this.B_GiveAll.Click += new System.EventHandler(this.B_GiveAll_Click); // // SAV_Inventory // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(334, 212); - this.Controls.Add(this.GB_Pouch); + this.ClientSize = new System.Drawing.Size(334, 361); + this.Controls.Add(this.B_GiveAll); + this.Controls.Add(this.tabControl1); this.Controls.Add(this.B_Save); this.Controls.Add(this.B_Cancel); - this.Controls.Add(this.dataGridView1); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.MaximizeBox = false; - this.MaximumSize = new System.Drawing.Size(350, 750); this.MinimizeBox = false; - this.MinimumSize = new System.Drawing.Size(350, 250); + this.MinimumSize = new System.Drawing.Size(350, 400); this.Name = "SAV_Inventory"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.Text = "Inventory Editor"; - ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit(); - this.GB_Pouch.ResumeLayout(false); this.ResumeLayout(false); } #endregion - - private System.Windows.Forms.DataGridView dataGridView1; private System.Windows.Forms.Button B_Cancel; private System.Windows.Forms.Button B_Save; - private System.Windows.Forms.GroupBox GB_Pouch; - private System.Windows.Forms.Button B_DisplayBerries; - private System.Windows.Forms.Button B_DisplayMedicine; - private System.Windows.Forms.Button B_DisplayTMHM; - private System.Windows.Forms.Button B_DisplayKeyItems; - private System.Windows.Forms.Button B_DisplayItems; + private System.Windows.Forms.TabControl tabControl1; + private System.Windows.Forms.Button B_GiveAll; + private System.Windows.Forms.ImageList IL_Pouch; } } \ No newline at end of file diff --git a/SAV/SAV_Inventory.cs b/SAV/SAV_Inventory.cs index 84f46887e..26a524392 100644 --- a/SAV/SAV_Inventory.cs +++ b/SAV/SAV_Inventory.cs @@ -1,5 +1,5 @@ using System; -using System.Drawing; +using System.Linq; using System.Windows.Forms; namespace PKHeX @@ -11,52 +11,77 @@ public SAV_Inventory() InitializeComponent(); Util.TranslateInterface(this, Main.curlanguage); - item_val = getItems(Main.SAV.ORAS ? Legal.Pouch_Items_ORAS : Legal.Pouch_Items_XY); - keyitem_val = getItems(Main.SAV.ORAS ? Legal.Pouch_Key_ORAS : Legal.Pouch_Key_XY); - tmhm_val = getItems(Main.SAV.ORAS ? Legal.Pouch_TMHM_ORAS : Legal.Pouch_TMHM_XY, sort: false); - medicine_val = getItems(Main.SAV.ORAS ? Legal.Pouch_Medicine_ORAS : Legal.Pouch_Medicine_XY); - berries_val = getItems(Legal.Pouch_Berry_XY); - - B_DisplayItems.ForeColor = Color.Red; - - // Load Items - populateList(item_val, Main.SAV.Items.HeldItem); - - B_DisplayItems.Text = Main.itempouch[0]; - B_DisplayMedicine.Text = Main.itempouch[1]; - B_DisplayTMHM.Text = Main.itempouch[2]; - B_DisplayBerries.Text = Main.itempouch[3]; - B_DisplayKeyItems.Text = Main.itempouch[4]; + Pouches = SAV.Inventory; + getBags(); } - private readonly byte[] sav = (byte[])Main.SAV.Data.Clone(); - private readonly string[] item_val, keyitem_val, tmhm_val, medicine_val, berries_val; + private readonly SaveFile SAV = Main.SAV.Clone(); + private readonly InventoryPouch[] Pouches; + private const string TabPrefix = "TAB_"; + private const string DGVPrefix = "DGV_"; - - // Initialize String Tables - private string[] getItems(ushort[] items, bool sort = true) + private void B_Cancel_Click(object sender, EventArgs e) { - string[] res = new string[items.Length]; - for (int i = 0; i < res.Length; i++) - res[i] = Main.itemlist[items[i]]; - if (sort) - Array.Sort(res); - return res; + Close(); + } + private void B_Save_Click(object sender, EventArgs e) + { + packBags(); + SAV.Inventory = Pouches; + Array.Copy(SAV.Data, Main.SAV.Data, SAV.Data.Length); + Main.SAV.Edited = true; + Close(); } - // Populate DataGrid - private void populateList(string[] itemarr, int offset, int itemcount = -1) + private void getBags() { - dataGridView1.Rows.Clear(); - dataGridView1.Columns.Clear(); - - DataGridViewColumn dgvIndex = new DataGridViewTextBoxColumn(); + for (int i = 0; i < Pouches.Length; i++) { - dgvIndex.HeaderText = "CNT"; - dgvIndex.DisplayIndex = 1; - dgvIndex.Width = 45; - dgvIndex.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; + // Add Tab + tabControl1.TabPages.Add(new TabPage + { + // Text = Pouches[i].Type.ToString(), + ImageIndex = (int)Pouches[i].Type + }); + + // Add DataGrid + DataGridView dgv = new DataGridView + { + Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right, // All + Height = tabControl1.TabPages[i].Height, + Width = tabControl1.TabPages[i].Width, + Text = Pouches[i].Type.ToString(), + Name = DGVPrefix + Pouches[i].Type, + + AllowUserToAddRows = false, + AllowUserToDeleteRows = false, + AllowUserToResizeRows = false, + AllowUserToResizeColumns = false, + RowHeadersVisible = false, + ColumnHeadersVisible = false, + MultiSelect = false, + ShowEditingIcon = false, + + EditMode = DataGridViewEditMode.EditOnEnter, + ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single, + ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize, + SelectionMode = DataGridViewSelectionMode.CellSelect, + CellBorderStyle = DataGridViewCellBorderStyle.None, + }; + + tabControl1.TabPages[i].Controls.Add(dgv); + + spillBag(dgv, i); } + } + private void spillBag(DataGridView dgv, int bag) + { + var pouch = Pouches[bag]; + var itemcount = Pouches[bag].Items.Length; + string[] itemarr = getItems(pouch.LegalItems); + dgv.Rows.Clear(); + dgv.Columns.Clear(); + DataGridViewComboBoxColumn dgvItemVal = new DataGridViewComboBoxColumn { DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing, @@ -64,19 +89,27 @@ private void populateList(string[] itemarr, int offset, int itemcount = -1) Width = 135, FlatStyle = FlatStyle.Flat }; + DataGridViewColumn dgvIndex = new DataGridViewTextBoxColumn(); + { + dgvIndex.HeaderText = "CNT"; + dgvIndex.DisplayIndex = 1; + dgvIndex.Width = 45; + dgvIndex.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; + } foreach (string t in itemarr) dgvItemVal.Items.Add(t); // add only the Item Names - dataGridView1.Columns.Add(dgvItemVal); - dataGridView1.Columns.Add(dgvIndex); + dgv.Columns.Add(dgvItemVal); + dgv.Columns.Add(dgvIndex); - dataGridView1.Rows.Add(itemcount > 0 ? itemcount : itemarr.Length); - dataGridView1.CancelEdit(); + dgv.Rows.Add(itemcount > 0 ? itemcount : itemarr.Length); + dgv.CancelEdit(); string itemname = ""; - for (int i = 0; i < dataGridView1.Rows.Count; i++) + string err = ""; + for (int i = 0; i < pouch.Items.Length; i++) { - int itemvalue = BitConverter.ToUInt16(sav, offset + i*4); + int itemvalue = pouch.Items[i].Index; try { itemname = Main.itemlist[itemvalue]; } catch { @@ -86,143 +119,95 @@ private void populateList(string[] itemarr, int offset, int itemcount = -1) int itemarrayval = Array.IndexOf(itemarr, itemname); if (itemarrayval == -1) { - dataGridView1.Rows[i].Cells[0].Value = itemarr[0]; - dataGridView1.Rows[i].Cells[1].Value = 0; - Util.Alert(itemname + " removed from item pouch.", "If you save changes the item will no longer be in the pouch."); + dgv.Rows[i].Cells[0].Value = itemarr[0]; + dgv.Rows[i].Cells[1].Value = 0; + + err += itemname + ", "; } else { - dataGridView1.Rows[i].Cells[0].Value = itemarr[itemarrayval]; - dataGridView1.Rows[i].Cells[1].Value = BitConverter.ToUInt16(sav, offset + i * 4 + 2); + dgv.Rows[i].Cells[0].Value = itemname; + dgv.Rows[i].Cells[1].Value = pouch.Items[i].Count; } } + if (err.Length > 0) + Util.Alert($"The following items have been removed from {Pouches[bag].Type} pouch.", err, + "If you save changes, the item(s) will no longer be in the pouch."); } - private void dropclick(object sender, DataGridViewCellEventArgs e) + private void packBags() { - if (e.ColumnIndex != 0) return; - - ComboBox comboBox = (ComboBox)dataGridView1.EditingControl; - comboBox.DroppedDown = true; - } - private void saveBag(object sender) - { - int offset = 0; - if (B_DisplayItems.ForeColor == Color.Red) - offset = Main.SAV.Items.HeldItem; - else if (B_DisplayKeyItems.ForeColor == Color.Red) - offset = Main.SAV.Items.KeyItem; - else if (B_DisplayTMHM.ForeColor == Color.Red) - offset = Main.SAV.Items.TMHM; - else if (B_DisplayMedicine.ForeColor == Color.Red) - offset = Main.SAV.Items.Medicine; - else if (B_DisplayBerries.ForeColor == Color.Red) - offset = Main.SAV.Items.Berry; - - // Fetch Data - int itemcount = dataGridView1.Rows.Count; - int emptyslots = 0; - for (int i = 0; i < itemcount; i++) + for (int p = 0; p < Pouches.Length; p++) { - string item = dataGridView1.Rows[i].Cells[0].Value.ToString(); - int itemindex = Array.IndexOf(Main.itemlist, item); - int itemcnt; - try - { itemcnt = Convert.ToUInt16(dataGridView1.Rows[i].Cells[1].Value.ToString()); } - catch { itemcnt = 0; } + // Get DataGridView + DataGridView dgv = Controls.Find(DGVPrefix + Pouches[p].Type, true).FirstOrDefault() as DataGridView; - if (itemindex == 0) // Compression of Empty Slots + int ctr = 0; + for (int i = 0; i < dgv.Rows.Count; i++) { - emptyslots++; - continue; + string item = dgv.Rows[i].Cells[0].Value.ToString(); + int itemindex = Array.IndexOf(Main.itemlist, item); + int itemcnt; + try + { itemcnt = Convert.ToUInt16(dgv.Rows[i].Cells[1].Value.ToString()); } + catch { itemcnt = 0; } + + if (itemcnt == 0) + itemcnt++; // No 0 count of items + else if (itemcnt > 995) + itemcnt = 995; // cap out + + if (itemindex == 0) // Compression of Empty Slots + continue; + + Pouches[p].Items[ctr++] = new InventoryItem {Index = itemindex, Count = itemcnt}; } - if (itemcnt == 0) - itemcnt++; // No 0 count of items - else if (itemcnt > 995) - itemcnt = 995; // cap out - - // Write Data into Save File - BitConverter.GetBytes((ushort)itemindex).CopyTo(sav, offset + 4 * (i - emptyslots)); // item # - BitConverter.GetBytes((ushort)itemcnt).CopyTo(sav, offset + 4 * (i - emptyslots) + 2); // count + for (int i = ctr; i < Pouches[p].Items.Length; i++) + Pouches[p].Items[i] = new InventoryItem(); // Empty Slots at the end } + } - // Delete Empty Trash - for (int i = itemcount - emptyslots; i < itemcount; i++) + // Initialize String Tables + private string[] getItems(ushort[] items, bool sort = true) + { + string[] res = new string[items.Length + 1]; + for (int i = 0; i < res.Length - 1; i++) + res[i] = Main.itemlist[items[i]]; + res[items.Length] = Main.itemlist[0]; + if (sort) + Array.Sort(res); + return res; + } + + // User Cheats + private void B_GiveAll_Click(object sender, EventArgs e) + { + // Get Current Pouch + int pouch = tabControl1.SelectedIndex; + if (pouch < 0) + return; + + ushort[] legalitems = Pouches[pouch].LegalItems; + + DataGridView dgv = Controls.Find(DGVPrefix + Pouches[pouch].Type, true).FirstOrDefault() as DataGridView; + + if (ModifierKeys == Keys.Alt) { - BitConverter.GetBytes((ushort)0).CopyTo(sav, offset + 4 * i + 0); // item # - BitConverter.GetBytes((ushort)0).CopyTo(sav, offset + 4 * i + 2); // count + for (int i = 0; i < legalitems.Length; i++) + { + dgv.Rows[i].Cells[0].Value = Main.itemlist[0]; + dgv.Rows[i].Cells[1].Value = 0; + } + Util.Alert("Items cleared."); + return; } - - // Load New Button Color, after finished we'll load the new data. - B_DisplayItems.ForeColor = - B_DisplayKeyItems.ForeColor = - B_DisplayTMHM.ForeColor = - B_DisplayMedicine.ForeColor = - B_DisplayBerries.ForeColor = Main.defaultControlText; - - (sender as Button).ForeColor = Color.Red; - } - private void giveAll(string[] inarray, int count) - { - for (int i = 0; i < inarray.Length - 1; i++) + int Count = ModifierKeys == Keys.Control ? 1 : Pouches[pouch].MaxCount; + for (int i = 0; i < legalitems.Length; i++) { - string itemname = inarray[i+1]; - int itemarrayval = Array.IndexOf(inarray, itemname); - dataGridView1.Rows[i].Cells[0].Value = inarray[itemarrayval]; - dataGridView1.Rows[i].Cells[1].Value = count; + string itemname = Main.itemlist[legalitems[i]]; + dgv.Rows[i].Cells[0].Value = itemname; + dgv.Rows[i].Cells[1].Value = Count; } - } - private void B_DisplayItems_Click(object sender, EventArgs e) - { - // Store Current Items back to the save file - saveBag(sender); - populateList(item_val, Main.SAV.Items.HeldItem); - if (ModifierKeys == Keys.Alt) - giveAll(item_val, 995); - } - private void B_DisplayKeyItems_Click(object sender, EventArgs e) - { - // Store Current Items back to the save file - saveBag(sender); - populateList(keyitem_val, Main.SAV.Items.KeyItem); - if (ModifierKeys == Keys.Alt && Util.Prompt(MessageBoxButtons.YesNo, - $"Warning: Adding all {B_DisplayKeyItems.Text} is dangerous.", "Continue?") == DialogResult.Yes) - giveAll(keyitem_val, 1); - } - private void B_DisplayTMHM_Click(object sender, EventArgs e) - { - // Store Current Items back to the save file - saveBag(sender); - populateList(tmhm_val, Main.SAV.Items.TMHM); - if (ModifierKeys == Keys.Alt && Util.Prompt(MessageBoxButtons.YesNo, - $"Warning: Adding all {B_DisplayTMHM.Text} is dangerous.", "Continue?") == DialogResult.Yes) - giveAll(tmhm_val, 1); - } - private void B_DisplayMedicine_Click(object sender, EventArgs e) - { - // Store Current Items back to the save file - saveBag(sender); - populateList(medicine_val, Main.SAV.Items.Medicine); - if (ModifierKeys == Keys.Alt) - giveAll(medicine_val, 995); - } - private void B_DisplayBerries_Click(object sender, EventArgs e) - { - // Store Current Items back to the save file - saveBag(sender); - populateList(berries_val, Main.SAV.Items.Berry); - if (ModifierKeys == Keys.Alt) - giveAll(berries_val, 995); - } - private void B_Cancel_Click(object sender, EventArgs e) - { - Close(); - } - private void B_Save_Click(object sender, EventArgs e) - { - saveBag(sender); - Array.Copy(sav, Main.SAV.Data, Main.SAV.Data.Length); - Main.SAV.Edited = true; - Close(); + System.Media.SystemSounds.Asterisk.Play(); } } } diff --git a/SAV/SAV_Inventory.resx b/SAV/SAV_Inventory.resx index 33b3719a5..f2029aec5 100644 --- a/SAV/SAV_Inventory.resx +++ b/SAV/SAV_Inventory.resx @@ -117,36 +117,169 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - True + + 17, 17 + + + AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w + LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0 + ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAADE + IwAAAk1TRnQBSQFMAgEBCAEAARgBAAEIAQABIAEAASABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo + AwABgAMAAWADAAEBAQABCAYAATAYAAGAAgABgAMAAoABAAGAAwABgAEAAYABAAKAAgADwAEAAcAB3AHA + AQAB8AHKAaYBAAEzBQABMwEAATMBAAEzAQACMwIAAxYBAAMcAQADIgEAAykBAANVAQADTQEAA0IBAAM5 + AQABgAF8Af8BAAJQAf8BAAGTAQAB1gEAAf8B7AHMAQABxgHWAe8BAAHWAucBAAGQAakBrQIAAf8BMwMA + AWYDAAGZAwABzAIAATMDAAIzAgABMwFmAgABMwGZAgABMwHMAgABMwH/AgABZgMAAWYBMwIAAmYCAAFm + AZkCAAFmAcwCAAFmAf8CAAGZAwABmQEzAgABmQFmAgACmQIAAZkBzAIAAZkB/wIAAcwDAAHMATMCAAHM + AWYCAAHMAZkCAALMAgABzAH/AgAB/wFmAgAB/wGZAgAB/wHMAQABMwH/AgAB/wEAATMBAAEzAQABZgEA + ATMBAAGZAQABMwEAAcwBAAEzAQAB/wEAAf8BMwIAAzMBAAIzAWYBAAIzAZkBAAIzAcwBAAIzAf8BAAEz + AWYCAAEzAWYBMwEAATMCZgEAATMBZgGZAQABMwFmAcwBAAEzAWYB/wEAATMBmQIAATMBmQEzAQABMwGZ + AWYBAAEzApkBAAEzAZkBzAEAATMBmQH/AQABMwHMAgABMwHMATMBAAEzAcwBZgEAATMBzAGZAQABMwLM + AQABMwHMAf8BAAEzAf8BMwEAATMB/wFmAQABMwH/AZkBAAEzAf8BzAEAATMC/wEAAWYDAAFmAQABMwEA + AWYBAAFmAQABZgEAAZkBAAFmAQABzAEAAWYBAAH/AQABZgEzAgABZgIzAQABZgEzAWYBAAFmATMBmQEA + AWYBMwHMAQABZgEzAf8BAAJmAgACZgEzAQADZgEAAmYBmQEAAmYBzAEAAWYBmQIAAWYBmQEzAQABZgGZ + AWYBAAFmApkBAAFmAZkBzAEAAWYBmQH/AQABZgHMAgABZgHMATMBAAFmAcwBmQEAAWYCzAEAAWYBzAH/ + AQABZgH/AgABZgH/ATMBAAFmAf8BmQEAAWYB/wHMAQABzAEAAf8BAAH/AQABzAEAApkCAAGZATMBmQEA + AZkBAAGZAQABmQEAAcwBAAGZAwABmQIzAQABmQEAAWYBAAGZATMBzAEAAZkBAAH/AQABmQFmAgABmQFm + ATMBAAGZATMBZgEAAZkBZgGZAQABmQFmAcwBAAGZATMB/wEAApkBMwEAApkBZgEAA5kBAAKZAcwBAAKZ + Af8BAAGZAcwCAAGZAcwBMwEAAWYBzAFmAQABmQHMAZkBAAGZAswBAAGZAcwB/wEAAZkB/wIAAZkB/wEz + AQABmQHMAWYBAAGZAf8BmQEAAZkB/wHMAQABmQL/AQABzAMAAZkBAAEzAQABzAEAAWYBAAHMAQABmQEA + AcwBAAHMAQABmQEzAgABzAIzAQABzAEzAWYBAAHMATMBmQEAAcwBMwHMAQABzAEzAf8BAAHMAWYCAAHM + AWYBMwEAAZkCZgEAAcwBZgGZAQABzAFmAcwBAAGZAWYB/wEAAcwBmQIAAcwBmQEzAQABzAGZAWYBAAHM + ApkBAAHMAZkBzAEAAcwBmQH/AQACzAIAAswBMwEAAswBZgEAAswBmQEAA8wBAALMAf8BAAHMAf8CAAHM + Af8BMwEAAZkB/wFmAQABzAH/AZkBAAHMAf8BzAEAAcwC/wEAAcwBAAEzAQAB/wEAAWYBAAH/AQABmQEA + AcwBMwIAAf8CMwEAAf8BMwFmAQAB/wEzAZkBAAH/ATMBzAEAAf8BMwH/AQAB/wFmAgAB/wFmATMBAAHM + AmYBAAH/AWYBmQEAAf8BZgHMAQABzAFmAf8BAAH/AZkCAAH/AZkBMwEAAf8BmQFmAQAB/wKZAQAB/wGZ + AcwBAAH/AZkB/wEAAf8BzAIAAf8BzAEzAQAB/wHMAWYBAAH/AcwBmQEAAf8CzAEAAf8BzAH/AQAC/wEz + AQABzAH/AWYBAAL/AZkBAAL/AcwBAAJmAf8BAAFmAf8BZgEAAWYC/wEAAf8CZgEAAf8BZgH/AQAC/wFm + AQABIQEAAaUBAANfAQADdwEAA4YBAAOWAQADywEAA7IBAAPXAQAD3QEAA+MBAAPqAQAD8QEAA/gBAAHw + AfsB/wEAAaQCoAEAA4ADAAH/AgAB/wMAAv8BAAH/AwAB/wEAAf8BAAL/AgAD//8A/wD/AP8A/wD/AP8A + /wD/AP8A/wD/AP8A/wD/AP8AFAAT9BMADfQbAAf0CAAg9AMAAfQE/wn0BP8B9BMAAfQL/wH0GwAB9AL/ + AfQC/wH0CAAe/wL0AQAD9AH/AvQCGQEJAtwB1QLcAQkBGQHzA/8D9A0ABPQB8wEZCdwBGQHzBPQHAAn0 + AwAG9AEJAdUB3QH/AfQIAAH/ARkb3AEZAvQBAAH0Av8B9AIZAQkB3AHbAtQBzQLUAdsBCQEZA/QC/wH0 + DQAB9AP/ARkB3AHUB80B1AHcARkD/wH0BwAB9Af/AfQDAAH0A/8B9AEZAdUBzQHcAf8B9AgAAf8B3BnN + AtQB3AL0AQAB9AH/AhkB3ALVA9QDzQLUAtUB3AEJAhkB/wH0CwAC9AHzARkC3AHVAtQHzQLUAdUC3AEZ + AfMC9AUAAfQB/wH1BPQB/wX0Af8C9AHcAdUB1AHNAdwB/wH0CAAB/wHcAc0a1AHcAvQBAAL0ARkB3AHU + C80C1AHbAdwBGQL0CwAB9AH/ARkB3AHUD80B1AHcARkB/wH0BQAB9AH/AfQEGQH0Bf8B9AIZAdUDzQHc + Af8B9AgAAf8B3AHNAdQB2xXcAdsB2gHUAdwD9ALzAQkB2wHUDM0C1AHcAQkB8wP0BwAC9AHzARkB3ALU + D80C1AHcARkB8wL0AwAB9AH/ARkB3AHbAdUB3AEJARkD8wEZAQkB3AHVAdQDzQHcAf8B9AgAAf8B3AHN + AdQB2xXcAdsB2gHUAdwD9ALzAdwC1A3NAdQB1QEJAfMB9AH/AfQHAAH0Af8BGQHcAdQTzQHUAdwBGQH/ + AfQDAAL0AdwC1AHNAdQB2wHcA90B3AHbAdQFzQHcAf8B9AgAAf8B3AHNAdQB2xXcAdsB2gHUAdwC9AH/ + ARkBCQHVAdQOzQLUAdwBGQHzAf8B9AcAAfQB/wHcAtQTzQLUAdwB/wH0AwAC9AEZAdwB1QTUA9UD1AXN + AdwB/wn0Af8B3AHNAdQB2xXcAdsB2gHUAdwC9AH/ARkB2wHUD80C1AHbAdwBGQL0BwAB9AH/AdwXzQHc + Af8B9AUAAfQB/wHcAtQNzQHcAv8I9AH/AdwBzQHUAdsV3AHbAdoB1AHcAvQB/wHcAtQEzQHUC80C1AHb + AQkC9AYAAfQB8wEZAdUHzQLUAdUD3AHVAtQHzQHVARkB8wL0AwAB9AH/AQkB2wHUBM0H1ALNAdUIGQH/ + AfQB/wHcAc0B1AHbFdwB2wHaAdQB3AL0Af8B3AXNA9QLzQLUAdwC9AYAAf8BGQHcAdQHzQHUAdwBGQP/ + ARkB3AHUB80B1AHcARkB/wH0AwAC9AEZAQkB1QPNCdQBzQHUB9wBGQH/AfQB/wHcAc0B1AHbFdwB2wHa + AdQB3AL0Af8B3AHUAs0BzgHUAdUB2wHVA9QHzQLUAdoB3AL0BgAB/wHcAtQFzQLUAdwBGQXcARkB3ALU + Bc0C1AHcAf8B9AMAAvQB8wEZAdwB1AHOAc0E1AHVA9sB1AHNBtQB1QHcAd0B/wH0Af8B3AHNAdQB2xXc + AdsB2gHUAdwC9AH/AdwC1AHNAdQB1QHcAQkB3AHbAdoC1AXNAtQB2gHbAQkC9AYAAf8B3AfNAdQB3AEZ + Af8B3APNAdwB/wEZAdwB1AfNAdwB/wH0BQAB9AH/AQkB1QHUAc0B1APVBNwB1AfNAdQB1QEJAvQB/wHc + Ac0B1AHbFdwB2wHaAdQB3AL0Af8BGQHcAdQBzgHUAdUB3AEZAtwB2wLUBc0C1AHbAdwBGQL0BgAB/wHc + B9QB3AEZAtwB1APNAdQC3AEZAdwH1AHcAf8B9AMABPQB3AHbAdQBzQTUAdsD3AHUBM0D1AHbAQkBGQL0 + Af8B3AHNAdQB2wfcAdsB1QPUAdUB2wfcAdsB2gHUAdwD9AIZAdYBzgHUAdUB3AEZAQkB3AHbAtQFzQLU + AdwCGQL0BgAB/wEZB9wBGQH/AdwHzQHcAf8BGQfcARkB/wH0AwAC9AIZAdwB2wHUAc0E1AHbA9wB1APN + AtQB2gHbAQkC9AIAAf8B3AHNAdQB2wbcAdsC1APNAtQB2wbcAdsB2gHUAdwE9AEZAdwD1AHVAtwB2wLU + Bc0C1AHbAdwBGQP0BgAB/wH0BxkB9AH/AdwHzQHcAf8B9AcZAfQB/wH0AQAC9AEZAQkC3AHVAtQBzQHU + B9sB1AHNAtQB1QLcAQkBGQL0AgAB/wHcAc0B1AHbBdwB2wHVB9QB1QHbBdwB2wHaAdQB3AL0AQAC9AEJ + AdsB1AHNAdQB1QPUBc0C1AHbAdwBGQL0CAAL/wHcB80B3Av/AfQBAAL0AQkB1QPUA80B1APcAdsE1AHN + AdQB3AEJAhkC9AQAAf8B3AHNAdQB2wTcAdsC1AHVBdwB1QLUAdsE3AHbAdoB1AHcAvQBAAL0ARkB3AHb + AdQB1QHbA9QCzQPUAdUB2wHcARkB8wL0AQAH9AH/ARkI3AEZAtwB1APNAdQC3AEZCNwBGQH/AvQBGQEJ + AdUD1ATNAdQD3AHbBNQBzQHUAdwBCQT0BAAB/wHcAc0B1AHbA9wC2wHaAdsH3AHVAdQB1QHbA9wB2wHa + AdQB3AL0AQAC9AIZAQkC3AHbAdoC1AHNAtQB2gHbAdwBCQHxAvMC9AEAAfQC/wT0Af8B3AfNAdQB3AEZ + Af8B3APNAdwB/wEZAdwB1AfNAdwB/wL0AQkB1QHUB80B1ATcA9UB1AHNAdQB1QEJAf8B9AYAAf8B3AHN + AdQB2wLcAdsB1AHaAdsJ3AHVAtQB2wLcAdsB2gHUAdwC9AEAA/QDGQIJAdwB2wPUAdsB3AEJAhkB8wb0 + Af8B9AEZA/QB/wHcAtQFzQLUAdwBGQXcARkB3ALUBc0C1AHcAf8B9AH/Ad0B3AbVAc4BzQHUA9sB1QTU + Ac0BzgHUAdwBGQHzAvQEAAH/AdwBzQHUBNsB2gHbC9wB2wHaBNsB2gHUAdwC9AMABPQC8wEZAtwB2wLc + ARkC8wH0Av8B9AEAAfQC/wH0AxkC9AH/ARkB3AHUB80B1AHcARkD/wEZAdwB1AfNAdQB3AEZAf8B9AH/ + ARkHCQHVAc0J1APNAdUBCQEZAvQEAAH/AdwBzQHUAdsB2gHUAdoB2w3cAdsB2gHUAdoB2wHaAdQB3AL0 + AwAE9ALzAQkB3AHbAdoB2wHcAQkC8wL0Af8B9ALzARkBCQPcARkD9AHzARkB1QfNAtQB1QPcAdUC1AfN + AdUBGQHzAvQB/wHzBxkB1QLNB9QEzQHUAdsBCQH/AfQEAAH/AdwBzQPUAdoB2w/cAdsB2gTUAdwC9AcA + AvQBCQHVAtQB2gHbAdwCGQP0AvMB8QEJAdsD1AHcAvQBAAH0Af8B3BfNAdwB/wH0AgAH9AL/AdwNzQLU + AdwB/wH0BAAB/wHcA80B1AHbEdwB2wHUAc0C1AHcAvQHAAL0Ad0B3AHVA9QB1QfcAtUD1AHbAQkC9AEA + AfQB/wHcAtQTzQLUAdwB/wH0AgAI9AH/AdwFzQPUA9UE1AHVAdwBGQL0AgAB/wHcAc0C1AHbE9wB2wPU + AdwC9AcAAvQBGQHcAdsC1AHNCdQDzQHUAdwBGQL0AQAB9AH/ARkB3AHUE80B1AHcARkB/wH0CQAB9AH/ + AdwFzQHUAdsB3AMZAdwB2wHUAc0C1AHcAvQCAAH/AdwBzQHUAdsV3AHbAdoB1AHcAvQHAAH0Af8CGQHc + AdsO1AHcAhkB/wH0AQAC9AHzARkB3ALUD80C1AHcARkB8wL0CQAB9AH/AdwDzQHUAdUB3AEJARkD9AEZ + AQkB3AHVAdsB3AEZAf8B9AIAAf8B3AHNAdQB2xXcAdsB2gHUAdwC9AcAAfQC/wH0ARkB3AHbAtQHzQLU + AdsB3AEZAfQC/wH0AwAB9AH/ARkB3AHUD80B1AHcARkB/wH0CwAB9AH/AdwDzQHVAhkB9AX/AfQEGQH0 + Af8B9AIAAf8B3AHNAdQB2xXcAdsB2gHUAdwC9AcAA/QB/wIZAQkB3AHbAtQEzQHUAdUB3AEJAhkB/wP0 + AwAC9AHzARkC3AHVAtQHzQLUAdUC3AEZAfMC9AsAAfQB/wHcAc0B1AHVAQkC9AH/BfQB/wT0AfUB/wH0 + AgAB/wHcAc0a1AHcAvQJAAH0Av8D9AEJAdsB1APNAtQB3AP0Av8B9AcAAfQD/wEZAdwB1AfNAdQB3AEZ + A/8B9A0AAfQB/wHcAc0B1QH0BP8B9AMAAfQH/wH0AgAB/wHcGc0C1AHcAvQJAAb0ARkBCQbcARkG9AcA + BPQB8wEZCdwBGQHzBPQNAAH0Af8BGQHcAd0G9AMACfQCAAH/ARkb3AEZAvQPAAL0Bf8C9BEAAfQL/wH0 + EQAB9AP/AfQUAB7/AvQHABH0DQAJ9B0ACfQMACD0BwAC9A3/AvQNAAH0B/8B9B0AAfQH/wH0DAAe/wL0 + AwAF9AIZAQkJ3AMZBfQFAAT0AfMBGQXcARkB8wT0FQAE9AEZB9wBGQT0CAAB/wEZGNwCGQT0AwAC9AL/ + AfQBGQHcAdUB1AfNAdQB2wHcARkB9AL/AvQFAAH0A/8BGQHcAdQDzQHUAdwBGQP/AfQVAAH0A/8B3AfN + AdwD/wH0CAAB/wHcAtQVzQHUAdsB3AIZAvQBAAL0AfMBGQEJAtwB1QLUAc4HzQPUAdUC3AEJARkB8wL0 + AwAB9AH/ARkB3AHVAtQDzQLUAdUB3AEZAf8B9BMAAvQBGQPcAdUB1AHVA9wB1QHUAdUD3AEZAvQGAAH/ + AdwC1BXNAdQB2wHcAhkC9AEAAvQBGQEJAdsC1A/NAtQB2wEJARkC9AMAAfQB/wHcC80B3AH/AfQTAAH0 + Af8B3APNAdQB3AEZA/8BGQHcAdQDzQHcAf8B9AYAAf8B3ALUFc0B1AHbAdwCGQL0AQAC9AEJAdsC1BHN + AdQB1QHcAd0C9AIAAfQB8wEZAdUDzQHUA9wB1APNAdUBGQHzAvQPAAL0ARkB3AHVAdQB1QLcARkB9AP/ + ARkB3AHbA9QB1QHcARkC9AQAAf8B3ALUFc0B1AHbAdwCGQL0AQAC9AHcAtQTzQHUAdUBCQL0AgAB/wEZ + AdwB1APNAdwD/wHcA80B1AHcARkB/wH0DwAB9AH/AdwBzQHUAdwBGQf/ARkF3AHUAc0B3AH/AfQEAAH/ + AdwC1BXNAdQB2wHcAhkD9AHzARkB2wLUE80C1AHcARkB8wL0Af8B3ALUAc0B1AHcARkD9AEZAdwB1AHN + AtQB3AH/AfQNAAL0ARkB3AHVAdQB3AEZAfQF/wH0ARkBCQXcAdsB1AHVAdwBGQL0AgAB/wHcAtQVzQHU + AdsB3AIZAvQB/wEZAdwB2wLUE80C1AHbAQkBGQL0Af8B3APNAdwB/wH0AwAB9AH/AdwDzQHcAf8B9A0A + AfQB/wHcAc0B1AHcARkH/wEZCdwB1AHNAdwB/wH0AgAB/wHcAtQVzQHUAdsB3AIZAvQB/wEJAdsC1BXN + AtQB2wEJAvQB/wHcA80B3AH/AfQDAAH0Af8B3APNAdwB/wH0DQAB9AH/AdwBzQHVARkB9Af/ARkJ3AHU + Ac0B3AH/AfQCAAH/AdwC1BXNAdQB2wHcAhkC9AH/AdwC1BfNAtQB3AL0Af8B3APNAdwB/wH0AwAB9AH/ + AdwDzQHcAf8B9A0AAfQB/wHcAc0B3An/ARkJ3AHUAc0B3AH/AfQCAAH/AdwC1BXNAdQB2wHcAhkC9AH/ + AdwC1BfNAtQB3AL0Af8B3ALUAc0B1AHcARkD9AEZAdwB1AHNAtQB3AH/AfQMAAH0ARkB3AHVAdQB3AX/ + AfQBGQLcAdUB1AHbB9wB2wHUAdUB3AEZAvQB/wEJAdsB1RXUAdsC3AIZAvQB/wHcAtQXzQLUAdwC9AH/ + ARkB3AHUA80B3AP/AdwDzQHUAdwBGQH/AfQMAAH/AdwBzQHUAdwBGQX/ARkB3AHUA80B1AncAdQBzQHc + Af8B9AH/ARkBCRjcAQkCGQL0Af8BCQHbAtQVzQLUAdsBCQP0AfMBGQHVA80B1APcAdQDzQHVARkB8wL0 + AQAD9AgAAf8B3AHNAdUBGQH0Bf8B3AHUAdwDCQHcAdQB2wPcAQkDGQHVAc0B3AH/AfQB/wEZAQkY3AEJ + AhkC9AH/ARkB3AHbAtQTzQLUAdsBCQEZAvQBAAH0Af8B3AvNAdwB/wH0AwAB9AH/AfQIAAH/AdwBzQHc + B/8B3AHNAQkDAAEJAc0B1APcARkD/wHcAc0B3AH/AfQB/wEZAQkY3AEJAhkD9AHzARkB2wLUE80C1AHc + ARkB8wL0AQAB9AH/ARkB3AHVAtQFzQLUAdwB/wH0AQAC9AHzARkB8wL0BgAB/wHcAc0B3AP/AfQDGQHV + Ac0BCQMAAQkBzQHVAxkB9AP/AdwBzQHcAf8B9AH/AQkB2wHVFdQB2wLcAhkC9AEAAvQB3ALUE80B1AHV + AQkC9AMAAfQD/wEZAdwB1AXNAdQB3AEZAf8B9AEAAfQB/wEZAdwBGQH/AfQGAAH/AdwBzQHcA/8BGQPc + AdQBzQEJAwABCQHNAdwH/wHcAc0B3AH/AfQB/wHcAtQVzQHUAdsB3AIZAvQBAAL0AQkB2wLUEc0B1AHV + AdwB3QL0AwAE9AHzARkE3AHUAc0C1AHcARkB8wH0AfMBGQHcAdQB1QHcARkC9AQAAf8B3AHNAdUDGQEJ + A9wB2wHUAdwDCQHcAdQB3AX/AfQBGQHVAc0B3AH/AfQB/wHcAtQVzQHUAdsB3AIZAvQBAAL0ARkBCQHb + AtQPzQLUAdsBCQEZAvQHAAH0Bf8B3APNAdQB3AEZAf8BGQHcAdQDzQHcAf8B9AQAAf8B3AHNAdQJ3AHU + A80B1AHcARkF/wEZAdwB1AHNAdwB/wH0Af8B3ALUFc0B1AHbAdwCGQL0AQAC9AHzARkBCQLcAtUL1ALV + AtwBCQEZAfMC9AcABvQBGQHcAdQBzQLUAdwBGQHcAtQBzQHUAtwBGQHzAvQCAAH0ARkB3AHVAdQB2wfc + AdsB1AHVAtwBGQH0Bf8B3AHUAdUB3AEZAvQB/wHcAtQVzQHUAdsB3AIZAvQDAAL0Av8B9AEZAQkL3AEJ + ARkB9AL/AvQPAAH0Af8B3APNAdQB3AHUA80B3AH/ARkB3AEZAf8B9AMAAfQB/wHcAc0B1AncARkJ/wHc + Ac0B3AH/AfQCAAH/AdwC1BXNAdQB2wHcAhkC9AMAA/QB/wH0ARkC3AHVB9QB2wLcARkB9AH/A/QPAAL0 + ARkB3AHUAc0D1AHNAdQC3AEZAdwB1AHVAdwBGQL0AQAB9AH/AdwBzQHUCdwBGQf/AfQBGQHVAc0B3AH/ + AfQCAAH/ARkC3ALVE9QB2wHcARkE9AUAAvQCGQHcAdUB1AfNAdQB2wHcAhkC9BMAAfQB/wHcBc0B3AH/ + ARkB3AHUA80B3AH/AfQBAAH0Af8B3AHNAdQJ3AEZB/8BGQHcAdQBzQHcAf8B9AIAA/8B9AEZAQkT3AEJ + ARkB9AL/AvQDAAL0AfMBGQLcAdUB1AHOB80C1AHVAdwCGQP0EQAC9AEZAdwB1APNAdUBGQHcAtQBzQHU + AdwBGQL0AQAC9AEZAdwB1QHUAdsF3AEJARkB9AX/AfQBGQHcAdQB1QHcARkC9AIAAvQB/wEZAdwB2w/U + AdUB2wLcAQkBGQH0Af8D9AMAAvQBGQEJAdsC1AvNAdQB1QHcAhkC9BMAAfQB/wHcA80B1AHcAdQDzQHc + Af8B9AUAAfQB/wHcAc0B1AXcARkH/wEZAdwB1AHNAdwB/wH0BQAC9AEJAdsB1A/NAtQB2wHcAQkCGQL0 + AwAC9AHzARkBCQHbAtQMzQHOAdQB1QLcARkB8wL0EQAC9AEZAdwB1AHNA9QBzQHUAdwBGQL0BQAC9AEZ + AdwB1QPUAdsB3AEZA/8B9AEZAtwB1QHUAdUB3AEZAvQFAAL0AQkB2wHUD80C1AHbAdwBCQIZAvQDAAL0 + ARkBCQHbAtQPzQLUAdsBCQEZAvQTAAH0Af8B3AXNAdwB/wH0CQAB9AH/AdwDzQHUAdwBGQP/ARkB3AHU + A80B3AH/AfQHAAL0AQkB2wHUD80C1AHbAdwBCQIZAvQDAAL0ARkBCQHbAtQPzQLUAdsBCQEZAvQTAAL0 + ARkB3AHUAc0B1AHcARkC9AkAAvQBGQPcAdUB1AHVA9wB1QHUAdUD3AEZAvQHAAL0AQkB2wHUD80C1AHb + AdwBCQIZAvQDAAL0ARkBCQHbAtQPzQLUAdsBCQEZAvQVAAH0Af8B3AHNAdwB/wH0DQAB9AP/AdwHzQHc + A/8B9AkAAvQBCQHbAdQPzQLUAdsB3AEJAhkC9AMAAvQB8wEZAQkT3AEJARkB8wL0FQAC9AEZAdwBGQL0 + DQAE9AEZB9wBGQT0CQAC9AIZEtwBCQIZBPQFAAL0Ff8C9BkAAfQB/wH0EwAB9Af/AfQNAAL0Gf8C9AIA + AUIBTQE+BwABPgMAASgDAAGAAwABYAMAAQEBAAEBBgABBhYAA///AP8AAwAB4AEAAQMC/wGAAQMD/wGA + Af8EAAHgAQABAwL/AYABAwP/AYAB/wQAAYACAAH/AfgCAAE/AYABOAEAAf8EAAGAAgAB/wH4AgABPwGA + ATgBAAH/BAABgAIAAf8B4AIAAQ8BgAIAAf8EAAGAAgAB/wHgAgABDwGAAgAB/wcAAT8BgAIAAQMBgAIA + Af8HAAE/AYACAAEDAYACAAH/BwABPwGAAgABAwGACgABPwGAAgABAwHgCgABPwQAAeAKAAE/BAAB4AoA + AT8EAAHgCgABPwQAAfgKAAE/BAAB4AoAAT8EAAHgAgABAwcAAT8EAAGAAgABAwQAAYACAAH/BAABgAIA + AQ8EAAGAAgABgAcAAQ8EAAGAAgABgAcAAT8EAAGACgABDwQAAeABAAECCAABDwQAAeAKAAEPBAAB/gMA + AYACAAEDAwABDwQAAf4DAAGAAgABAwMAAQMEAAH+AwABgAIAAQMB/gIAAQMEAAH+AwABgAIAAQMB/gIA + AQMEAAH+AwAB4AIAAQ8B/gIAAQMEAAH+AwAB4AIAAQ8B/gIAAQMEAAH/AYABAAEDAfgCAAE/Af4BAAE4 + AQMEAAH/AYABAAEDAfgCAAE/Af4BAAE4AQMEAAH/Af4BAAL/AYABAwH/Af4BDwL/BAAB/gIAAf8B+AED + A/8B4AEPAf8EAAH+AgAB/wH4AQMD/wHgAQ8B/wQAAeACAAEPAYABAAE/Af8B/gIAAf8EAAHgAgABDwGA + AQABPwH/Af4CAAH/BAABgAIAAQMBgAEAAT8B/wH4AgABPwQAAYACAAEDAYABAAE/Af8B+AIAAT8EAAGA + AgABAwIAAQ8B/wHgAgABDwQAAYACAAEDAgABDwH/AeACAAEPCgABDwH/AYACAAEDCQAB4AEPAf8BgAIA + AQMJAAHgAQ8B/wGAAgABAwkAAeABDwH/AYACAAEDCgABDwH/DgABDwH/DgABCAH/DAABgAEAATgB/wEA + AQMBgAkAAYABAAEgAT8BAAEDAYAFAAGAAgABAwGAAQABIAE/AQABAwGABQABgAIAAQMBgAIAAQ8IAAGA + AgABAwH4AgABDwgAAYACAAEDAfgCAAEDCAAB4AIAAQ8B/wHgAQABAwGAAgABAwQAAeACAAEPAf8B4AIA + AYACAAEDBAAB+AIAAT8B/wH4AgABgAIAAQMEAAHgAgABDwH/AfgCAAGAAgABAwQAAeACAAEPAf8B/gEA + AQMB4AIAAQ8BgAIAAQMBgAIAAQMB/wH+AQABAwHgAgABDwGAAgABAwGAAgABAwL/AYABDwH4AgABPwGA + AgABAwGAAgABAwL/AYABDwH4AgABPwGAAgABAwGAAgABAwL/AeABPwH+AgAB/wGAAgABAwGAAgABAwL/ + AeABPwH+AgAB/wGAAgABAwHgAgABDwL/AfgC/wHgAQ8B/wGAAgABAws= + + diff --git a/SAV/SAV_OPower.cs b/SAV/SAV_OPower.cs index 06dfcd5c1..30d59b879 100644 --- a/SAV/SAV_OPower.cs +++ b/SAV/SAV_OPower.cs @@ -13,6 +13,7 @@ public SAV_OPower() LoadData(); } + private readonly SAV6 SAV = new SAV6(Main.SAV.Data); private void B_Cancel_Click(object sender, EventArgs e) { Close(); @@ -24,7 +25,7 @@ private void B_Save_Click(object sender, EventArgs e) } private void LoadData() { - int o = Main.SAV.OPower; + int o = SAV.OPower; // Fill up the 17 o-powers // 1 2 3 4 5 10 use 4 bytes, everything else uses 3 @@ -52,15 +53,15 @@ private void LoadData() CB_17.SelectedIndex = getIndex(o, 3);//o += 3; // 3E-40 // Load Maxes - o = Main.SAV.OPower; - CHK_1.Checked = Convert.ToBoolean(Main.SAV.Data[o + 0x00]); - CHK_2.Checked = Convert.ToBoolean(Main.SAV.Data[o + 0x05]); - CHK_3.Checked = Convert.ToBoolean(Main.SAV.Data[o + 0x0A]); - CHK_4.Checked = Convert.ToBoolean(Main.SAV.Data[o + 0x0F]); - CHK_5.Checked = Convert.ToBoolean(Main.SAV.Data[o + 0x14]); - CHK_6.Checked = Convert.ToBoolean(Main.SAV.Data[o + 0x19]); - CHK_7.Checked = Convert.ToBoolean(Main.SAV.Data[o + 0x26]); - CHK_8.Checked = Convert.ToBoolean(Main.SAV.Data[o + 0x2B]); + o = SAV.OPower; + CHK_1.Checked = Convert.ToBoolean(SAV.Data[o + 0x00]); + CHK_2.Checked = Convert.ToBoolean(SAV.Data[o + 0x05]); + CHK_3.Checked = Convert.ToBoolean(SAV.Data[o + 0x0A]); + CHK_4.Checked = Convert.ToBoolean(SAV.Data[o + 0x0F]); + CHK_5.Checked = Convert.ToBoolean(SAV.Data[o + 0x14]); + CHK_6.Checked = Convert.ToBoolean(SAV.Data[o + 0x19]); + CHK_7.Checked = Convert.ToBoolean(SAV.Data[o + 0x26]); + CHK_8.Checked = Convert.ToBoolean(SAV.Data[o + 0x2B]); } private void SaveData() { @@ -76,7 +77,7 @@ private void SaveData() 0x27, 0x2C,0x2F,0x32,0x35,0x38,0x3B,0x3E, }; - int o = Main.SAV.OPower; // offset + int o = SAV.OPower; // offset for (int i = 0; i < cba.Length; i++) { @@ -90,14 +91,15 @@ private void SaveData() // Save Maxes - Main.SAV.Data[o + 0x00] = Convert.ToByte(CHK_1.Checked); - Main.SAV.Data[o + 0x05] = Convert.ToByte(CHK_2.Checked); - Main.SAV.Data[o + 0x0A] = Convert.ToByte(CHK_3.Checked); - Main.SAV.Data[o + 0x0F] = Convert.ToByte(CHK_4.Checked); - Main.SAV.Data[o + 0x14] = Convert.ToByte(CHK_5.Checked); - Main.SAV.Data[o + 0x19] = Convert.ToByte(CHK_6.Checked); - Main.SAV.Data[o + 0x26] = Convert.ToByte(CHK_7.Checked); - Main.SAV.Data[o + 0x2B] = Convert.ToByte(CHK_8.Checked); + SAV.Data[o + 0x00] = Convert.ToByte(CHK_1.Checked); + SAV.Data[o + 0x05] = Convert.ToByte(CHK_2.Checked); + SAV.Data[o + 0x0A] = Convert.ToByte(CHK_3.Checked); + SAV.Data[o + 0x0F] = Convert.ToByte(CHK_4.Checked); + SAV.Data[o + 0x14] = Convert.ToByte(CHK_5.Checked); + SAV.Data[o + 0x19] = Convert.ToByte(CHK_6.Checked); + SAV.Data[o + 0x26] = Convert.ToByte(CHK_7.Checked); + SAV.Data[o + 0x2B] = Convert.ToByte(CHK_8.Checked); + Array.Copy(SAV.Data, Main.SAV.Data, SAV.Data.Length); Main.SAV.Edited = true; } private int getIndex(int o, int l) diff --git a/SAV/SAV_BerryFieldORAS.Designer.cs b/SAV/SAV_PokeBlockORAS.Designer.cs similarity index 99% rename from SAV/SAV_BerryFieldORAS.Designer.cs rename to SAV/SAV_PokeBlockORAS.Designer.cs index e62d6d33f..c5e6e982d 100644 --- a/SAV/SAV_BerryFieldORAS.Designer.cs +++ b/SAV/SAV_PokeBlockORAS.Designer.cs @@ -1,6 +1,6 @@ namespace PKHeX { - partial class SAV_BerryFieldORAS + partial class SAV_PokeBlockORAS { /// /// Required designer variable. @@ -28,7 +28,7 @@ protected override void Dispose(bool disposing) /// private void InitializeComponent() { - System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(SAV_BerryFieldORAS)); + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(SAV_PokeBlockORAS)); this.B_Cancel = new System.Windows.Forms.Button(); this.B_Save = new System.Windows.Forms.Button(); this.NUP_Red = new System.Windows.Forms.NumericUpDown(); @@ -466,7 +466,7 @@ private void InitializeComponent() this.MaximumSize = new System.Drawing.Size(420, 220); this.MinimizeBox = false; this.MinimumSize = new System.Drawing.Size(420, 220); - this.Name = "SAV_BerryFieldORAS"; + this.Name = "SAV_PokeBlockORAS"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.Text = "Berry Field Editor"; ((System.ComponentModel.ISupportInitialize)(this.NUP_Red)).EndInit(); diff --git a/SAV/SAV_BerryFieldORAS.cs b/SAV/SAV_PokeBlockORAS.cs similarity index 84% rename from SAV/SAV_BerryFieldORAS.cs rename to SAV/SAV_PokeBlockORAS.cs index ba5988682..c0f03fe75 100644 --- a/SAV/SAV_BerryFieldORAS.cs +++ b/SAV/SAV_PokeBlockORAS.cs @@ -3,9 +3,9 @@ namespace PKHeX { - public partial class SAV_BerryFieldORAS : Form + public partial class SAV_PokeBlockORAS : Form { - public SAV_BerryFieldORAS() + public SAV_PokeBlockORAS() { InitializeComponent(); Util.TranslateInterface(this, Main.curlanguage); @@ -15,11 +15,11 @@ public SAV_BerryFieldORAS() for (int i = 0; i < lbl_spec.Length; i++) { lbl_spec[i].Text = $"{Main.pokeblocks[94 + i]}:"; - nup_spec[i].Value = BitConverter.ToUInt32(sav, Main.SAV.Contest + i * 4); + nup_spec[i].Value = BitConverter.ToUInt32(SAV.Data, SAV.Contest + i * 4); } } private readonly NumericUpDown[] nup_spec; - private readonly byte[] sav = (byte[])Main.SAV.Data.Clone(); + private readonly SAV6 SAV = new SAV6(Main.SAV.Data); private void B_Cancel_Click(object sender, EventArgs e) { @@ -28,8 +28,8 @@ private void B_Cancel_Click(object sender, EventArgs e) private void B_Save_Click(object sender, EventArgs e) { for (int i = 0; i < nup_spec.Length; i++) - BitConverter.GetBytes((uint)nup_spec[i].Value).CopyTo(sav, Main.SAV.Contest + i * 4); - Main.SAV.Data = (byte[])sav.Clone(); + BitConverter.GetBytes((uint)nup_spec[i].Value).CopyTo(SAV.Data, SAV.Contest + i * 4); + Main.SAV.Data = (byte[])SAV.Data.Clone(); Close(); } @@ -45,7 +45,7 @@ private void B_RandomizeBerries_Click(object sender, EventArgs e) { ushort berry = plantable[Util.rnd32() % (plantable.Length - 1) + 1]; // get random berry item ID from list BitConverter.GetBytes(berry).CopyTo(tree, 6); // put berry into tree. - tree.CopyTo(sav, Main.SAV.BerryField + 0x10 * i); // put tree into plot + tree.CopyTo(SAV.Data, SAV.BerryField + 0x10 * i); // put tree into plot } } private void B_GiveAllBlocks_Click(object sender, EventArgs e) diff --git a/SAV/SAV_EventFlagsORAS.resx b/SAV/SAV_PokeBlockORAS.resx similarity index 100% rename from SAV/SAV_EventFlagsORAS.resx rename to SAV/SAV_PokeBlockORAS.resx diff --git a/SAV/SAV_PokedexORAS.cs b/SAV/SAV_PokedexORAS.cs index 2fadeab21..db0fc4eaa 100644 --- a/SAV/SAV_PokedexORAS.cs +++ b/SAV/SAV_PokedexORAS.cs @@ -32,12 +32,12 @@ public SAV_PokedexORAS() getData(); editing = false; LB_Species.SelectedIndex = 0; - TB_Spinda.Text = BitConverter.ToUInt32(sav, Main.SAV.Spinda).ToString("X8"); + TB_Spinda.Text = BitConverter.ToUInt32(SAV.Data, SAV.Spinda).ToString("X8"); } + private readonly SAV6 SAV = new SAV6(Main.SAV.Data); private readonly CheckBox[] CP; private readonly CheckBox[] CL; - private readonly byte[] sav = (byte[])Main.SAV.Data.Clone(); private readonly bool[,] specbools = new bool[9, 0x60 * 8]; private readonly bool[,] langbools = new bool[7, 0x60 * 8]; private BitArray formbools; @@ -123,13 +123,13 @@ private void getEntry() CHK_P3.Enabled = CHK_P5.Enabled = CHK_P7.Enabled = CHK_P9.Enabled = gt != 0 && gt != 255; // Not Male-Only and Not Genderless // Load Encountered Count - MT_Count.Text = BitConverter.ToUInt16(sav, Main.SAV.EncounterCount + (pk - 1) * 2).ToString(); + MT_Count.Text = BitConverter.ToUInt16(SAV.Data, SAV.EncounterCount + (pk - 1) * 2).ToString(); CLB_FormsSeen.Items.Clear(); CLB_FormDisplayed.Items.Clear(); int fc = PKX.Personal[species].FormeCount; - int f = PKX.getDexFormIndexORAS(species, fc); + int f = SaveUtil.getDexFormIndexORAS(species, fc); if (f < 0) return; string[] forms = PKX.getFormList(species, Main.types, Main.forms, Main.gendersymbols); @@ -170,10 +170,10 @@ private void setEntry() langbools[5, species - 1] = CHK_L6.Checked; langbools[6, species - 1] = CHK_L7.Checked; - BitConverter.GetBytes((ushort)Math.Min(0xFFFF, Util.ToUInt32(MT_Count.Text))).CopyTo(sav, Main.SAV.EncounterCount + (species - 1) * 2); + BitConverter.GetBytes((ushort)Math.Min(0xFFFF, Util.ToUInt32(MT_Count.Text))).CopyTo(SAV.Data, SAV.EncounterCount + (species - 1) * 2); int fc = PKX.Personal[species].FormeCount; - int f = PKX.getDexFormIndexORAS(species, fc); + int f = SaveUtil.getDexFormIndexORAS(species, fc); if (f < 0) return; @@ -196,8 +196,8 @@ private void getData() for (int i = 0; i < 9; i++) { byte[] data = new byte[0x60]; - int offset = Main.SAV.PokeDex + 0x8 + 0x60 * i; - Array.Copy(sav, offset, data, 0, data.Length); + int offset = SAV.PokeDex + 0x8 + 0x60 * i; + Array.Copy(SAV.Data, offset, data, 0, data.Length); BitArray BitRegion = new BitArray(data); for (int b = 0; b < 0x60 * 8; b++) specbools[i, b] = BitRegion[b]; @@ -205,14 +205,14 @@ private void getData() // Fill Language arrays byte[] langdata = new byte[0x280]; - Array.Copy(sav, Main.SAV.PokeDexLanguageFlags, langdata, 0, langdata.Length); + Array.Copy(SAV.Data, SAV.PokeDexLanguageFlags, langdata, 0, langdata.Length); BitArray LangRegion = new BitArray(langdata); for (int b = 0; b < 721; b++) // 721 Species for (int i = 0; i < 7; i++) // 7 Languages langbools[i, b] = LangRegion[7 * b + i]; byte[] formdata = new byte[FormLen*4]; - Array.Copy(sav, Main.SAV.PokeDex + 0x368, formdata, 0, formdata.Length); + Array.Copy(SAV.Data, SAV.PokeDex + 0x368, formdata, 0, formdata.Length); formbools = new BitArray(formdata); } private void setData() @@ -227,7 +227,7 @@ private void setData() if (specbools[p, i]) sdata[i/8] |= (byte) (1 << i%8); - sdata.CopyTo(sav, Main.SAV.PokeDex + 8 + 0x60*p); + sdata.CopyTo(SAV.Data, SAV.PokeDex + 8 + 0x60*p); } // Build new bool array for the Languages @@ -243,13 +243,13 @@ private void setData() if (languagedata[i]) ldata[i/8] |= (byte) (1 << i%8); - ldata.CopyTo(sav, Main.SAV.PokeDexLanguageFlags); + ldata.CopyTo(SAV.Data, SAV.PokeDexLanguageFlags); - formbools.CopyTo(sav, Main.SAV.PokeDex + 0x368); + formbools.CopyTo(SAV.Data, SAV.PokeDex + 0x368); // Store Spinda Spot uint PID = Util.getHEXval(TB_Spinda.Text); - BitConverter.GetBytes(PID).CopyTo(sav, Main.SAV.Spinda); + BitConverter.GetBytes(PID).CopyTo(SAV.Data, SAV.Spinda); } private void B_Cancel_Click(object sender, EventArgs e) @@ -262,7 +262,7 @@ private void B_Save_Click(object sender, EventArgs e) setData(); // Return back to the parent savefile - Array.Copy(sav, Main.SAV.Data, sav.Length); + Array.Copy(SAV.Data, Main.SAV.Data, SAV.Data.Length); Main.SAV.Edited = true; Close(); } @@ -313,17 +313,17 @@ private void modifyAll(object sender, EventArgs e) if (mnuDexNav == sender) { for (int i = 0; i < 0x2D1; i++) - BitConverter.GetBytes((ushort)999).CopyTo(sav, Main.SAV.EncounterCount + i * 2); + BitConverter.GetBytes((ushort)999).CopyTo(SAV.Data, SAV.EncounterCount + i * 2); return; } if (mnuResetNav == sender) { for (int i = 0; i < 0x2D1; i++) - BitConverter.GetBytes((ushort)0).CopyTo(sav, Main.SAV.EncounterCount + i * 2); + BitConverter.GetBytes((ushort)0).CopyTo(SAV.Data, SAV.EncounterCount + i * 2); return; } - int lang = Main.SAV.Language; + int lang = SAV.Language; if (lang > 5) lang -= 1; lang -= 1; @@ -392,7 +392,7 @@ private void modifyAll(object sender, EventArgs e) setEntry(); setData(); if (mnuComplete == sender) // Turn off Italian Petlil - sav[Main.SAV.PokeDexLanguageFlags + 0x1DF] &= 0xFE; + SAV.Data[SAV.PokeDexLanguageFlags + 0x1DF] &= 0xFE; getData(); getEntry(); diff --git a/SAV/SAV_PokedexXY.cs b/SAV/SAV_PokedexXY.cs index bebad5009..f2da38632 100644 --- a/SAV/SAV_PokedexXY.cs +++ b/SAV/SAV_PokedexXY.cs @@ -32,12 +32,12 @@ public SAV_PokedexXY() getData(); editing = false; LB_Species.SelectedIndex = 0; - TB_Spinda.Text = BitConverter.ToUInt32(sav, Main.SAV.Spinda).ToString("X8"); + TB_Spinda.Text = BitConverter.ToUInt32(SAV.Data, SAV.Spinda).ToString("X8"); } + private readonly SAV6 SAV = new SAV6(Main.SAV.Data); private readonly CheckBox[] CP; private readonly CheckBox[] CL; - private readonly byte[] sav = (byte[])Main.SAV.Data.Clone(); private readonly bool[,] specbools = new bool[9, 0x60 * 8]; private readonly bool[,] langbools = new bool[7, 0x60 * 8]; private readonly bool[] foreignbools = new bool[0x52 * 8]; @@ -130,7 +130,7 @@ private void getEntry() CLB_FormDisplayed.Items.Clear(); int fc = PKX.Personal[species].FormeCount; - int f = PKX.getDexFormIndexXY(species, fc); + int f = SaveUtil.getDexFormIndexXY(species, fc); if (f < 0) return; string[] forms = PKX.getFormList(species, Main.types, Main.forms, Main.gendersymbols); @@ -174,7 +174,7 @@ private void setEntry() langbools[6, species - 1] = CHK_L7.Checked; int fc = PKX.Personal[species].FormeCount; - int f = PKX.getDexFormIndexORAS(species, fc); + int f = SaveUtil.getDexFormIndexORAS(species, fc); if (f < 0) return; @@ -197,7 +197,7 @@ private void getData() for (int i = 0; i < 9; i++) { byte[] data = new byte[0x60]; - Array.Copy(sav, Main.SAV.PokeDex + 8 + 0x60 * i, data, 0, 0x60); + Array.Copy(SAV.Data, SAV.PokeDex + 8 + 0x60 * i, data, 0, 0x60); BitArray BitRegion = new BitArray(data); for (int b = 0; b < 0x60 * 8; b++) specbools[i, b] = BitRegion[b]; @@ -205,7 +205,7 @@ private void getData() // Fill Language arrays byte[] langdata = new byte[0x280]; - Array.Copy(sav, Main.SAV.PokeDexLanguageFlags, langdata, 0, 0x280); + Array.Copy(SAV.Data, SAV.PokeDexLanguageFlags, langdata, 0, 0x280); BitArray LangRegion = new BitArray(langdata); for (int b = 0; b < 721; b++) // 721 Species for (int i = 0; i < 7; i++) // 7 Languages @@ -213,13 +213,13 @@ private void getData() // Fill Foreign array byte[] foreigndata = new byte[0x52]; - Array.Copy(sav, Main.SAV.PokeDex + 0x64C, foreigndata, 0, 0x52); + Array.Copy(SAV.Data, SAV.PokeDex + 0x64C, foreigndata, 0, 0x52); BitArray ForeignRegion = new BitArray(foreigndata); for (int b = 0; b < 0x52 * 8; b++) foreignbools[b] = ForeignRegion[b]; byte[] formdata = new byte[FormLen*4]; - Array.Copy(sav, Main.SAV.PokeDex + 0x368, formdata, 0, formdata.Length); + Array.Copy(SAV.Data, SAV.PokeDex + 0x368, formdata, 0, formdata.Length); formbools = new BitArray(formdata); } private void setData() @@ -234,7 +234,7 @@ private void setData() if (specbools[p, i]) sdata[i / 8] |= (byte)(1 << i % 8); - sdata.CopyTo(sav, Main.SAV.PokeDex + 8 + 0x60 * p); + sdata.CopyTo(SAV.Data, SAV.PokeDex + 8 + 0x60 * p); } // Build new bool array for the Languages @@ -251,10 +251,10 @@ private void setData() if (languagedata[i]) ldata[i / 8] |= (byte)(1 << i % 8); - ldata.CopyTo(sav, Main.SAV.PokeDexLanguageFlags); + ldata.CopyTo(SAV.Data, SAV.PokeDexLanguageFlags); } - formbools.CopyTo(sav, Main.SAV.PokeDex + 0x368); + formbools.CopyTo(SAV.Data, SAV.PokeDex + 0x368); // Return Foreign Array { @@ -262,12 +262,12 @@ private void setData() for (int i = 0; i < 0x52 * 8; i++) if (foreignbools[i]) foreigndata[i / 8] |= (byte)(1 << i % 8); - foreigndata.CopyTo(sav, Main.SAV.PokeDex + 0x64C); + foreigndata.CopyTo(SAV.Data, SAV.PokeDex + 0x64C); } // Store Spinda Spot uint PID = Util.getHEXval(TB_Spinda.Text); - BitConverter.GetBytes(PID).CopyTo(sav, Main.SAV.Spinda); + BitConverter.GetBytes(PID).CopyTo(SAV.Data, SAV.Spinda); } private void B_Cancel_Click(object sender, EventArgs e) @@ -280,7 +280,7 @@ private void B_Save_Click(object sender, EventArgs e) setData(); // Return back to the parent savefile - Array.Copy(sav, Main.SAV.Data, sav.Length); + Array.Copy(SAV.Data, Main.SAV.Data, SAV.Data.Length); Main.SAV.Edited = true; Close(); } @@ -324,7 +324,7 @@ private void B_Modify_Click(object sender, EventArgs e) } private void modifyAll(object sender, EventArgs e) { - int lang = Main.SAV.Language; + int lang = SAV.Language; if (lang > 5) lang -= 1; lang -= 1; @@ -393,7 +393,7 @@ private void modifyAll(object sender, EventArgs e) setEntry(); setData(); if (mnuComplete == sender) // Turn off Italian Petlil - sav[Main.SAV.PokeDexLanguageFlags + 0x1DF] &= 0xFE; + SAV.Data[SAV.PokeDexLanguageFlags + 0x1DF] &= 0xFE; getData(); getEntry(); diff --git a/SAV/SAV_Pokepuff.cs b/SAV/SAV_Pokepuff.cs index bf044d34b..63b89bd38 100644 --- a/SAV/SAV_Pokepuff.cs +++ b/SAV/SAV_Pokepuff.cs @@ -18,7 +18,7 @@ public SAV_Pokepuff() new ToolTip().SetToolTip(B_All, "Hold CTRL to give Deluxe instead of Supreme."); } - private readonly byte[] sav = (byte[])Main.SAV.Data.Clone(); + private readonly SAV6 SAV = new SAV6(Main.SAV.Data); private readonly string[] pfa; private void Setup() { @@ -52,9 +52,9 @@ private void Setup() for (int i = 0; i < 100; i++) { dgv.Rows[i].Cells[0].Value = (i + 1).ToString(); - dgv.Rows[i].Cells[1].Value = pfa[sav[Main.SAV.Puff + i]]; + dgv.Rows[i].Cells[1].Value = pfa[SAV.Data[SAV.Puff + i]]; } - MT_CNT.Text = Main.SAV.PuffCount.ToString(); + MT_CNT.Text = SAV.PuffCount.ToString(); } private void dropclick(object sender, DataGridViewCellEventArgs e) { @@ -79,7 +79,7 @@ private void B_All_Click(object sender, EventArgs e) for (int i = 0; i < 100; i++) newpuffs[i] = (byte)(Util.rnd32()%basemod + basepuff); - Array.Copy(newpuffs, 0, sav, Main.SAV.Puff, 100); + Array.Copy(newpuffs, 0, SAV.Data, SAV.Puff, 100); Setup(); } private void B_None_Click(object sender, EventArgs e) @@ -90,7 +90,7 @@ private void B_None_Click(object sender, EventArgs e) newpuffs[2] = 3; newpuffs[3] = 4; newpuffs[4] = 5; - Array.Copy(newpuffs, 0, sav, Main.SAV.Puff, 100); + Array.Copy(newpuffs, 0, SAV.Data, SAV.Puff, 100); Setup(); } private void B_Sort_Click(object sender, EventArgs e) @@ -121,7 +121,7 @@ private void B_Sort_Click(object sender, EventArgs e) Array.Sort(puffarray); Array.Resize(ref puffarray, 100); } - Array.Copy(puffarray, 0, sav, Main.SAV.Puff, 100); + Array.Copy(puffarray, 0, SAV.Data, SAV.Puff, 100); Setup(); } private void B_Save_Click(object sender, EventArgs e) @@ -138,8 +138,9 @@ private void B_Save_Click(object sender, EventArgs e) } puffarray[i - emptyslots] = (byte)Array.IndexOf(pfa, puff); } - Main.SAV.Puffs = puffarray; - Main.SAV.PuffCount = Util.ToInt32(MT_CNT.Text); + SAV.Puffs = puffarray; + SAV.PuffCount = Util.ToInt32(MT_CNT.Text); + Main.SAV.Data = SAV.Data; Main.SAV.Edited = true; Close(); } diff --git a/SAV/SAV_SecretBase.cs b/SAV/SAV_SecretBase.cs index 66dcf8b59..de8f152ef 100644 --- a/SAV/SAV_SecretBase.cs +++ b/SAV/SAV_SecretBase.cs @@ -18,11 +18,11 @@ public SAV_SecretBase() LB_Favorite.SelectedIndex = 0; // MT_Flags.Text = BitConverter.ToUInt16(sav, 0x24800 + 0x140).ToString(); PSS Stat transmitted - MT_Flags.Text = BitConverter.ToUInt32(sav, Main.SAV.SecretBase + 0x62C).ToString(); // read counter + MT_Flags.Text = BitConverter.ToUInt32(SAV.Data, SAV.SecretBase + 0x62C).ToString(); // read counter B_SAV2FAV(null, null); } - private readonly byte[] sav = (byte[])Main.SAV.Data.Clone(); + private readonly SAV6 SAV = new SAV6(Main.SAV.Data); private bool editing; private bool loading = true; @@ -53,13 +53,13 @@ private void popFavorite() { LB_Favorite.Items.Clear(); - int playeroff = Main.SAV.SecretBase + 0x326; - int favoff = Main.SAV.SecretBase + 0x63A; - string OT = Util.TrimFromZero(Encoding.Unicode.GetString(sav, playeroff + 0x218, 0x1A)); + int playeroff = SAV.SecretBase + 0x326; + int favoff = SAV.SecretBase + 0x63A; + string OT = Util.TrimFromZero(Encoding.Unicode.GetString(SAV.Data, playeroff + 0x218, 0x1A)); LB_Favorite.Items.Add("* " + OT); for (int i = 0; i < 30; i++) { - string BaseTrainer = Util.TrimFromZero(Encoding.Unicode.GetString(sav, favoff + i * 0x3E0 + 0x218, 0x1A)); + string BaseTrainer = Util.TrimFromZero(Encoding.Unicode.GetString(SAV.Data, favoff + i * 0x3E0 + 0x218, 0x1A)); if (BaseTrainer.Length < 1 || BaseTrainer[0] == '\0') BaseTrainer = "Empty"; LB_Favorite.Items.Add(i + " " + BaseTrainer); @@ -70,24 +70,24 @@ private void B_SAV2FAV(object sender, EventArgs e) loading = true; int index = LB_Favorite.SelectedIndex; if (index < 0) return; - int offset = Main.SAV.SecretBase + 0x25A; + int offset = SAV.SecretBase + 0x25A; // Base Offset Changing - if (index == 0) offset = Main.SAV.SecretBase + 0x326; + if (index == 0) offset = SAV.SecretBase + 0x326; else offset += 0x3E0 * index; - string TrainerName = Util.TrimFromZero(Encoding.Unicode.GetString(sav, offset + 0x218, 0x1A)); + string TrainerName = Util.TrimFromZero(Encoding.Unicode.GetString(SAV.Data, offset + 0x218, 0x1A)); TB_FOT.Text = TrainerName; - TB_FT1.Text = Util.TrimFromZero(Encoding.Unicode.GetString(sav, offset + 0x232 + 0x22 * 0, 0x22)); - TB_FT2.Text = Util.TrimFromZero(Encoding.Unicode.GetString(sav, offset + 0x232 + 0x22 * 1, 0x22)); + TB_FT1.Text = Util.TrimFromZero(Encoding.Unicode.GetString(SAV.Data, offset + 0x232 + 0x22 * 0, 0x22)); + TB_FT2.Text = Util.TrimFromZero(Encoding.Unicode.GetString(SAV.Data, offset + 0x232 + 0x22 * 1, 0x22)); - string saying1 = Util.TrimFromZero(Encoding.Unicode.GetString(sav, offset + 0x276 + 0x22 * 0, 0x22)); - string saying2 = Util.TrimFromZero(Encoding.Unicode.GetString(sav, offset + 0x276 + 0x22 * 1, 0x22)); - string saying3 = Util.TrimFromZero(Encoding.Unicode.GetString(sav, offset + 0x276 + 0x22 * 2, 0x22)); - string saying4 = Util.TrimFromZero(Encoding.Unicode.GetString(sav, offset + 0x276 + 0x22 * 3, 0x22)); + string saying1 = Util.TrimFromZero(Encoding.Unicode.GetString(SAV.Data, offset + 0x276 + 0x22 * 0, 0x22)); + string saying2 = Util.TrimFromZero(Encoding.Unicode.GetString(SAV.Data, offset + 0x276 + 0x22 * 1, 0x22)); + string saying3 = Util.TrimFromZero(Encoding.Unicode.GetString(SAV.Data, offset + 0x276 + 0x22 * 2, 0x22)); + string saying4 = Util.TrimFromZero(Encoding.Unicode.GetString(SAV.Data, offset + 0x276 + 0x22 * 3, 0x22)); - int baseloc = BitConverter.ToInt16(sav, offset); + int baseloc = BitConverter.ToInt16(SAV.Data, offset); NUD_FBaseLocation.Value = baseloc; TB_FSay1.Text = saying1; TB_FSay2.Text = saying2; TB_FSay3.Text = saying3; TB_FSay4.Text = saying4; @@ -96,7 +96,7 @@ private void B_SAV2FAV(object sender, EventArgs e) objdata = new byte[25, 12]; for (int i = 0; i < 25; i++) for (int z = 0; z < 12; z++) - objdata[i, z] = sav[offset + 2 + 12 * i + z]; + objdata[i, z] = SAV.Data[offset + 2 + 12 * i + z]; NUD_FObject.Value = 1; // Trigger Update changeObjectIndex(null, null); @@ -107,7 +107,7 @@ private void B_SAV2FAV(object sender, EventArgs e) if (index > 0) for (int i = 0; i < 3; i++) for (int z = 0; z < 0x34; z++) - pkmdata[i, z] = sav[offset + 0x32E + 0x34 * i + z]; + pkmdata[i, z] = SAV.Data[offset + 0x32E + 0x34 * i + z]; NUD_FPKM.Value = 1; changeFavPKM(null, null); // Trigger Update @@ -127,54 +127,54 @@ private void B_FAV2SAV(object sender, EventArgs e) if (LB_Favorite.Items[index].ToString().Substring(LB_Favorite.Items[index].ToString().Length - 5, 5) == "Empty") { Util.Error("Sorry, no overwriting an empty base with someone else's."); return; } if (index < 0) return; - int offset = Main.SAV.SecretBase + 0x25A; + int offset = SAV.SecretBase + 0x25A; // Base Offset Changing if (index == 0) - offset = Main.SAV.SecretBase + 0x326; + offset = SAV.SecretBase + 0x326; else offset += 0x3E0 * index; string TrainerName = TB_FOT.Text; byte[] tr = Encoding.Unicode.GetBytes(TrainerName); - Array.Resize(ref tr, 0x22); Array.Copy(tr, 0, sav, offset + 0x218, 0x1A); + Array.Resize(ref tr, 0x22); Array.Copy(tr, 0, SAV.Data, offset + 0x218, 0x1A); string team1 = TB_FT1.Text; string team2 = TB_FT2.Text; byte[] t1 = Encoding.Unicode.GetBytes(team1); - Array.Resize(ref t1, 0x22); Array.Copy(t1, 0, sav, offset + 0x232 + 0x22 * 0, 0x22); + Array.Resize(ref t1, 0x22); Array.Copy(t1, 0, SAV.Data, offset + 0x232 + 0x22 * 0, 0x22); byte[] t2 = Encoding.Unicode.GetBytes(team2); - Array.Resize(ref t2, 0x22); Array.Copy(t2, 0, sav, offset + 0x232 + 0x22 * 1, 0x22); + Array.Resize(ref t2, 0x22); Array.Copy(t2, 0, SAV.Data, offset + 0x232 + 0x22 * 1, 0x22); string saying1 = TB_FSay1.Text; string saying2 = TB_FSay2.Text; string saying3 = TB_FSay3.Text; string saying4 = TB_FSay4.Text; byte[] s1 = Encoding.Unicode.GetBytes(saying1); - Array.Resize(ref s1, 0x22); Array.Copy(s1, 0, sav, offset + 0x276 + 0x22 * 0, 0x22); + Array.Resize(ref s1, 0x22); Array.Copy(s1, 0, SAV.Data, offset + 0x276 + 0x22 * 0, 0x22); byte[] s2 = Encoding.Unicode.GetBytes(saying2); - Array.Resize(ref s2, 0x22); Array.Copy(s2, 0, sav, offset + 0x276 + 0x22 * 1, 0x22); + Array.Resize(ref s2, 0x22); Array.Copy(s2, 0, SAV.Data, offset + 0x276 + 0x22 * 1, 0x22); byte[] s3 = Encoding.Unicode.GetBytes(saying3); - Array.Resize(ref s3, 0x22); Array.Copy(s3, 0, sav, offset + 0x276 + 0x22 * 2, 0x22); + Array.Resize(ref s3, 0x22); Array.Copy(s3, 0, SAV.Data, offset + 0x276 + 0x22 * 2, 0x22); byte[] s4 = Encoding.Unicode.GetBytes(saying4); - Array.Resize(ref s4, 0x22); Array.Copy(s4, 0, sav, offset + 0x276 + 0x22 * 3, 0x22); + Array.Resize(ref s4, 0x22); Array.Copy(s4, 0, SAV.Data, offset + 0x276 + 0x22 * 3, 0x22); int baseloc = (int)NUD_FBaseLocation.Value; if (baseloc < 3) baseloc = 0; // skip 1/2 baselocs as they are dummied out ingame. - Array.Copy(BitConverter.GetBytes(baseloc), 0, sav, offset, 2); + Array.Copy(BitConverter.GetBytes(baseloc), 0, SAV.Data, offset, 2); TB_FOT.Text = TrainerName; TB_FSay1.Text = saying1; TB_FSay2.Text = saying2; TB_FSay3.Text = saying3; TB_FSay4.Text = saying4; // Copy back Objects for (int i = 0; i < 25; i++) for (int z = 0; z < 12; z++) - sav[offset + 2 + 12 * i + z] = objdata[i, z]; + SAV.Data[offset + 2 + 12 * i + z] = objdata[i, z]; if (GB_PKM.Enabled) // Copy pkm data back in { saveFavPKM(); for (int i = 0; i < 3; i++) for (int z = 0; z < 0x34; z++) - sav[offset + 0x32E + 0x34 * i + z] = pkmdata[i, z]; + SAV.Data[offset + 0x32E + 0x34 * i + z] = pkmdata[i, z]; } popFavorite(); LB_Favorite.SelectedIndex = index; @@ -188,9 +188,9 @@ private void B_Cancel_Click(object sender, EventArgs e) private void B_Save_Click(object sender, EventArgs e) { uint flags = Util.ToUInt32(MT_Flags.Text); - Array.Copy(BitConverter.GetBytes(flags), 0, sav, Main.SAV.PSSStats + 0x140, 4); // write pss - Array.Copy(BitConverter.GetBytes(flags), 0, sav, Main.SAV.SecretBase + 0x62C, 4); // write counter - Array.Copy(sav, Main.SAV.Data, sav.Length); + Array.Copy(BitConverter.GetBytes(flags), 0, SAV.Data, SAV.PSSStats + 0x140, 4); // write pss + Array.Copy(BitConverter.GetBytes(flags), 0, SAV.Data, SAV.SecretBase + 0x62C, 4); // write counter + Main.SAV.Data = SAV.Data; Main.SAV.Edited = true; Close(); } @@ -201,8 +201,8 @@ private void B_GiveDecor_Click(object sender, EventArgs e) // int qty = BitConverter.ToUInt16(sav, offset + i * 4); // int has = BitConverter.ToUInt16(sav, offset + i * 4 + 2); - sav[Main.SAV.SecretBase + i * 4] = 25; - sav[Main.SAV.SecretBase + i * 4 + 2] = 1; + SAV.Data[SAV.SecretBase + i * 4] = 25; + SAV.Data[SAV.SecretBase + i * 4 + 2] = 1; } } @@ -454,8 +454,8 @@ private void B_FDelete_Click(object sender, EventArgs e) if (LB_Favorite.SelectedIndex < 1) { Util.Alert("Cannot delete your Secret Base."); return; } int index = LB_Favorite.SelectedIndex - 1; - int favoff = Main.SAV.SecretBase + 0x63A; - string BaseTrainer = Util.TrimFromZero(Encoding.Unicode.GetString(sav, favoff + index * 0x3E0 + 0x218, 0x1A)); + int favoff = SAV.SecretBase + 0x63A; + string BaseTrainer = Util.TrimFromZero(Encoding.Unicode.GetString(SAV.Data, favoff + index * 0x3E0 + 0x218, 0x1A)); if (string.IsNullOrEmpty(BaseTrainer)) BaseTrainer = "Empty"; @@ -465,9 +465,9 @@ private void B_FDelete_Click(object sender, EventArgs e) const int max = 29; const int size = 0x3E0; int offset = favoff + index * size; - if (index != max) Array.Copy(sav, offset + size, sav, offset, size * (max - index)); + if (index != max) Array.Copy(SAV.Data, offset + size, SAV.Data, offset, size * (max - index)); // Ensure Last Entry is Cleared - Array.Copy(new byte[size], 0, sav, size * max, size); + Array.Copy(new byte[size], 0, SAV.Data, size * max, size); popFavorite(); } } diff --git a/SAV/SAV_SuperTrain.cs b/SAV/SAV_SuperTrain.cs index 2fed7b46d..2ba7a5fa8 100644 --- a/SAV/SAV_SuperTrain.cs +++ b/SAV/SAV_SuperTrain.cs @@ -9,9 +9,9 @@ public SAV_SuperTrain() { trba = Main.trainingbags; trba[0] = "---"; - offsetTime = Main.SAV.SuperTrain + 0x08; - offsetSpec = Main.SAV.SuperTrain + 0x188; - offsetVal = Main.SAV.SuperTrain + 0x18A; + offsetTime = SAV.SuperTrain + 0x08; + offsetSpec = SAV.SuperTrain + 0x188; + offsetVal = SAV.SuperTrain + 0x18A; InitializeComponent(); Util.TranslateInterface(this, Main.curlanguage); string[] stages = Main.trainingstage; @@ -22,7 +22,7 @@ public SAV_SuperTrain() setup(); } - private readonly byte[] sav = (byte[])Main.SAV.Data.Clone(); + private readonly SAV6 SAV = new SAV6(Main.SAV.Data); private readonly string[] trba = { "Empty", "HP Bag S","HP Bag M","HP Bag L", @@ -54,9 +54,9 @@ private void setup() listBox1.SelectedIndex = 0; fillTrainingBags(); - CB_S2.SelectedValue = (int)BitConverter.ToUInt16(sav, offsetSpec + 4 * 30); - TB_Time1.Text = BitConverter.ToSingle(sav, offsetTime + 4 * 30).ToString(); - TB_Time2.Text = BitConverter.ToSingle(sav, offsetTime + 4 * 31).ToString(); + CB_S2.SelectedValue = (int)BitConverter.ToUInt16(SAV.Data, offsetSpec + 4 * 30); + TB_Time1.Text = BitConverter.ToSingle(SAV.Data, offsetTime + 4 * 30).ToString(); + TB_Time2.Text = BitConverter.ToSingle(SAV.Data, offsetTime + 4 * 31).ToString(); } private void fillTrainingBags() { @@ -85,11 +85,11 @@ private void fillTrainingBags() dataGridView1.Columns.Add(dgvBag); dataGridView1.Rows.Add(12); - int offset = Main.SAV.SuperTrain + 0x308; + int offset = SAV.SuperTrain + 0x308; for (int i = 0; i < 12; i++) { dataGridView1.Rows[i].Cells[0].Value = (i + 1).ToString(); - dataGridView1.Rows[i].Cells[1].Value = trba[sav[offset + i]]; + dataGridView1.Rows[i].Cells[1].Value = trba[SAV.Data[offset + i]]; } } private void dropclick(object sender, DataGridViewCellEventArgs e) @@ -106,9 +106,9 @@ private void changeListRecordSelection(object sender, EventArgs e) { int index = listBox1.SelectedIndex; if (index < 0) return; - TB_Time.Text = BitConverter.ToSingle(sav, offsetTime + 4 * index).ToString(); - TB_Unk.Text = BitConverter.ToUInt16(sav, offsetVal + 4 * index).ToString(); - CB_Species.SelectedValue = (int)BitConverter.ToUInt16(sav, offsetSpec + 4 * index); + TB_Time.Text = BitConverter.ToSingle(SAV.Data, offsetTime + 4 * index).ToString(); + TB_Unk.Text = BitConverter.ToUInt16(SAV.Data, offsetVal + 4 * index).ToString(); + CB_Species.SelectedValue = (int)BitConverter.ToUInt16(SAV.Data, offsetSpec + 4 * index); } private void B_Save_Click(object sender, EventArgs e) { @@ -125,11 +125,11 @@ private void B_Save_Click(object sender, EventArgs e) } bagarray[i - emptyslots] = (byte)Array.IndexOf(trba, bag); } - try { BitConverter.GetBytes(float.Parse(TB_Time1.Text)).CopyTo(sav, offsetTime + 4 * 30); } catch { } - try { BitConverter.GetBytes(float.Parse(TB_Time2.Text)).CopyTo(sav, offsetTime + 4 * 31); } catch { } - BitConverter.GetBytes((ushort)Util.getIndex(CB_S2)).CopyTo(sav, offsetSpec + 4 * 30); - bagarray.CopyTo(sav, Main.SAV.SuperTrain + 0x308); - Array.Copy(sav, Main.SAV.Data, Main.SAV.Data.Length); + try { BitConverter.GetBytes(float.Parse(TB_Time1.Text)).CopyTo(SAV.Data, offsetTime + 4 * 30); } catch { } + try { BitConverter.GetBytes(float.Parse(TB_Time2.Text)).CopyTo(SAV.Data, offsetTime + 4 * 31); } catch { } + BitConverter.GetBytes((ushort)Util.getIndex(CB_S2)).CopyTo(SAV.Data, offsetSpec + 4 * 30); + bagarray.CopyTo(SAV.Data, SAV.SuperTrain + 0x308); + Array.Copy(SAV.Data, Main.SAV.Data, Main.SAV.Data.Length); Main.SAV.Edited = true; Close(); } @@ -141,19 +141,19 @@ private void changeRecordSpecies(object sender, EventArgs e) { int index = listBox1.SelectedIndex; if (index < 0) return; - BitConverter.GetBytes(Util.getIndex(CB_Species)).CopyTo(sav, offsetSpec + 4 * index); + BitConverter.GetBytes(Util.getIndex(CB_Species)).CopyTo(SAV.Data, offsetSpec + 4 * index); } private void changeRecordVal(object sender, EventArgs e) { int index = listBox1.SelectedIndex; if (index < 0) return; - try { BitConverter.GetBytes(ushort.Parse(TB_Unk.Text)).CopyTo(sav, offsetVal + 4 * index); } catch { } + try { BitConverter.GetBytes(ushort.Parse(TB_Unk.Text)).CopyTo(SAV.Data, offsetVal + 4 * index); } catch { } } private void changeRecordTime(object sender, EventArgs e) { int index = listBox1.SelectedIndex; if (index < 0) return; - try { BitConverter.GetBytes(float.Parse(TB_Time.Text)).CopyTo(sav, offsetTime + 4 * index); } catch { } + try { BitConverter.GetBytes(float.Parse(TB_Time.Text)).CopyTo(SAV.Data, offsetTime + 4 * index); } catch { } } } } diff --git a/SAV/SAV_Trainer.cs b/SAV/SAV_Trainer.cs index c591ff2a4..fd2ee2dd5 100644 --- a/SAV/SAV_Trainer.cs +++ b/SAV/SAV_Trainer.cs @@ -410,9 +410,9 @@ private void getTextBoxes() TB_Style.Text = SAV.Style.ToString(); // Load Play Time - MT_Hours.Text = Main.SAV.PlayedHours.ToString(); - MT_Minutes.Text = Main.SAV.PlayedMinutes.ToString(); - MT_Seconds.Text = Main.SAV.PlayedSeconds.ToString(); + MT_Hours.Text = SAV.PlayedHours.ToString(); + MT_Minutes.Text = SAV.PlayedMinutes.ToString(); + MT_Seconds.Text = SAV.PlayedSeconds.ToString(); // Load PSS Sprite CB_MultiplayerSprite.SelectedValue = SAV.Sprite; diff --git a/SAV/SAV_Wondercard.Designer.cs b/SAV/SAV_Wondercard.Designer.cs index b3ac98824..78e564620 100644 --- a/SAV/SAV_Wondercard.Designer.cs +++ b/SAV/SAV_Wondercard.Designer.cs @@ -35,6 +35,8 @@ private void InitializeComponent() this.B_Output = new System.Windows.Forms.Button(); this.B_Import = new System.Windows.Forms.Button(); this.LB_Received = new System.Windows.Forms.ListBox(); + this.mnuDel = new System.Windows.Forms.ContextMenuStrip(this.components); + this.flagDel = new System.Windows.Forms.ToolStripMenuItem(); this.L_Received = new System.Windows.Forms.Label(); this.RTB = new System.Windows.Forms.RichTextBox(); this.L_Details = new System.Windows.Forms.Label(); @@ -72,8 +74,7 @@ private void InitializeComponent() this.L_r2 = new System.Windows.Forms.Label(); this.L_r3 = new System.Windows.Forms.Label(); this.L_r4 = new System.Windows.Forms.Label(); - this.mnuDel = new System.Windows.Forms.ContextMenuStrip(this.components); - this.flagDel = new System.Windows.Forms.ToolStripMenuItem(); + this.mnuDel.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.PB_Preview)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.PB_Card01)).BeginInit(); this.mnuVSD.SuspendLayout(); @@ -100,7 +101,6 @@ private void InitializeComponent() ((System.ComponentModel.ISupportInitialize)(this.PB_Card21)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.PB_Card20)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.PB_Card19)).BeginInit(); - this.mnuDel.SuspendLayout(); this.SuspendLayout(); // // B_Save @@ -132,7 +132,7 @@ private void InitializeComponent() this.B_Output.Name = "B_Output"; this.B_Output.Size = new System.Drawing.Size(75, 23); this.B_Output.TabIndex = 2; - this.B_Output.Text = "Output .wc6"; + this.B_Output.Text = "Output"; this.B_Output.UseVisualStyleBackColor = true; this.B_Output.Click += new System.EventHandler(this.B_Output_Click); // @@ -143,7 +143,7 @@ private void InitializeComponent() this.B_Import.Name = "B_Import"; this.B_Import.Size = new System.Drawing.Size(75, 23); this.B_Import.TabIndex = 3; - this.B_Import.Text = "Import .wc6"; + this.B_Import.Text = "Import"; this.B_Import.UseVisualStyleBackColor = true; this.B_Import.Click += new System.EventHandler(this.B_Import_Click); // @@ -159,6 +159,20 @@ private void InitializeComponent() this.LB_Received.Sorted = true; this.LB_Received.TabIndex = 5; // + // mnuDel + // + this.mnuDel.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.flagDel}); + this.mnuDel.Name = "mnuVSD"; + this.mnuDel.Size = new System.Drawing.Size(108, 26); + // + // flagDel + // + this.flagDel.Name = "flagDel"; + this.flagDel.Size = new System.Drawing.Size(107, 22); + this.flagDel.Text = "Delete"; + this.flagDel.Click += new System.EventHandler(this.clearRecievedFlag); + // // L_Received // this.L_Received.AutoSize = true; @@ -663,20 +677,6 @@ private void InitializeComponent() this.L_r4.Text = "19-24:"; this.L_r4.TextAlign = System.Drawing.ContentAlignment.MiddleRight; // - // mnuDel - // - this.mnuDel.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.flagDel}); - this.mnuDel.Name = "mnuVSD"; - this.mnuDel.Size = new System.Drawing.Size(108, 26); - // - // flagDel - // - this.flagDel.Name = "flagDel"; - this.flagDel.Size = new System.Drawing.Size(107, 22); - this.flagDel.Text = "Delete"; - this.flagDel.Click += new System.EventHandler(this.clearRecievedFlag); - // // SAV_Wondercard // this.AllowDrop = true; @@ -729,6 +729,7 @@ private void InitializeComponent() this.Name = "SAV_Wondercard"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.Text = "Wonder Card I/O"; + this.mnuDel.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.PB_Preview)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.PB_Card01)).EndInit(); this.mnuVSD.ResumeLayout(false); @@ -755,7 +756,6 @@ private void InitializeComponent() ((System.ComponentModel.ISupportInitialize)(this.PB_Card21)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.PB_Card20)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.PB_Card19)).EndInit(); - this.mnuDel.ResumeLayout(false); this.ResumeLayout(false); this.PerformLayout(); diff --git a/SAV/SAV_Wondercard.cs b/SAV/SAV_Wondercard.cs index 1c0c64508..2bac31c6d 100644 --- a/SAV/SAV_Wondercard.cs +++ b/SAV/SAV_Wondercard.cs @@ -8,10 +8,11 @@ namespace PKHeX { public partial class SAV_Wondercard : Form { - public SAV_Wondercard(byte[] wcdata = null) + public SAV_Wondercard(MysteryGift g = null) { InitializeComponent(); Util.TranslateInterface(this, Main.curlanguage); + mga = Main.SAV.GiftAlbum; pba = new[] { PB_Card01, PB_Card02, PB_Card03, PB_Card04, PB_Card05, PB_Card06, @@ -25,8 +26,19 @@ public SAV_Wondercard(byte[] wcdata = null) pb.AllowDrop = true; // The PictureBoxes have their own drag&drop event handlers. } - populateWClist(); - populateReceived(); + + // Hide slots not present on game + for (int i = mga.Gifts.Length; i < pba.Length; i++) + pba[i].Visible = false; + if (mga.Gifts.Length < 7) + L_r2.Visible = false; + if (mga.Gifts.Length < 13) + L_r3.Visible = false; + if (mga.Gifts.Length < 19) + L_r4.Visible = false; + + setGiftBoxes(); + getReceivedFlags(); if (LB_Received.Items.Count > 0) LB_Received.SelectedIndex = 0; @@ -34,60 +46,56 @@ public SAV_Wondercard(byte[] wcdata = null) DragEnter += tabMain_DragEnter; DragDrop += tabMain_DragDrop; - if (wcdata == null || wcdata.Length != WC6.Size) - return; - - Array.Copy(wcdata, wc6.Data, wcdata.Length); - loadwcdata(); + if (g == null) + clickView(PB_Card01, null); + else + viewGiftData(g); } - private readonly SAV6 SAV = new SAV6((byte[])Main.SAV.Data.Clone()); - private WC6 wc6 = new WC6(); + + private readonly SaveFile SAV = Main.SAV.Clone(); + private MysteryGiftAlbum mga; + private MysteryGift mg; private readonly PictureBox[] pba; // Repopulation Functions - private int currentSlot; private void setBackground(int index, Image bg) { - for (int i = 0; i < 24; i++) + for (int i = 0; i < mga.Gifts.Length; i++) pba[i].BackgroundImage = index == i ? bg : null; - currentSlot = index; } - private void populateWClist() + private void setGiftBoxes() { - for (int i = 0; i < 24; i++) + for (int i = 0; i < mga.Gifts.Length; i++) { - WC6 wc = SAV.getWC6(i); - pba[i].Image = wc.CardID == 0 ? null : wc.Preview; + MysteryGift m = mga.Gifts[i]; + pba[i].Image = m.Empty ? null : getSprite(m); } } - private void loadwcdata() + private void viewGiftData(MysteryGift g) { - if (wc6 == null) - return; try { - if (wc6.GiftUsed && DialogResult.Yes == + if (g.GiftUsed && DialogResult.Yes == Util.Prompt(MessageBoxButtons.YesNo, "Wonder Card is marked as USED and will not be able to be picked up in-game.", "Do you want to remove the USED flag so that it is UNUSED?")) - wc6.GiftUsed = false; + g.GiftUsed = false; - RTB.Text = wc6.Description; - PB_Preview.Image = wc6.Preview; + RTB.Text = getDescription(g); + PB_Preview.Image = getSprite(g); + mg = g; } catch (Exception e) { Util.Error("Loading of data failed... is this really a Wonder Card?", e.ToString()); - wc6 = new WC6(); RTB.Clear(); } } - private void populateReceived() + private void getReceivedFlags() { LB_Received.Items.Clear(); - bool[] flags = SAV.WC6Flags; - for (int i = 1; i < flags.Length; i++) - if (flags[i]) + for (int i = 1; i < mga.Flags.Length; i++) + if (mga.Flags[i]) LB_Received.Items.Add(i.ToString("0000")); if (LB_Received.Items.Count > 0) @@ -104,28 +112,41 @@ private void setCardID(int cardID) } // Wonder Card IO (.wc6<->window) + private string getFilter() + { + switch (SAV.Generation) + { + case 4: + return "Gen4 Mystery Gift|*.pgt;*.pcd|All Files|*.*"; + case 5: + return "Gen5 Mystery Gift|*.pgf|All Files|*.*"; + case 6: + return "Gen6 Mystery Gift|*.wc6;*.wc6full|All Files|*.*"; + default: + return ""; + } + } private void B_Import_Click(object sender, EventArgs e) { - OpenFileDialog importwc6 = new OpenFileDialog {Filter = "Wonder Card|*.wc6;*.wc6full"}; - if (importwc6.ShowDialog() != DialogResult.OK) return; + OpenFileDialog import = new OpenFileDialog {Filter = getFilter()}; + if (import.ShowDialog() != DialogResult.OK) return; - string path = importwc6.FileName; - long len = new FileInfo(path).Length; - if (len != WC6.Size && len != WC6.SizeFull) + string path = import.FileName; + MysteryGift g = MysteryGift.getMysteryGift(File.ReadAllBytes(path), Path.GetExtension(path)); + if (g == null) { - Util.Error("File is not a Wonder Card:", path); + Util.Error("File is not a Mystery Gift:", path); return; } - wc6 = new WC6(File.ReadAllBytes(path)); - loadwcdata(); + viewGiftData(g); } private void B_Output_Click(object sender, EventArgs e) { - SaveFileDialog outputwc6 = new SaveFileDialog(); - int cardID = wc6.CardID; - string cardname = wc6.CardTitle; - outputwc6.FileName = Util.CleanFileName($"{cardID} - {cardname}.wc6"); - outputwc6.Filter = "Wonder Card|*.wc6"; + SaveFileDialog outputwc6 = new SaveFileDialog + { + Filter = getFilter(), + FileName = Util.CleanFileName($"{mg.CardID} - {mg.CardTitle}{mg.Extension}") + }; if (outputwc6.ShowDialog() != DialogResult.OK) return; string path = outputwc6.FileName; @@ -133,7 +154,7 @@ private void B_Output_Click(object sender, EventArgs e) if (File.Exists(path)) // File already exists, save a .bak File.WriteAllBytes(path + ".bak", File.ReadAllBytes(path)); - File.WriteAllBytes(path, wc6.Data); + File.WriteAllBytes(path, mg.Data); } // Wonder Card RW (window<->sav) @@ -143,14 +164,11 @@ private void clickView(object sender, EventArgs e) int index = Array.IndexOf(pba, sender); setBackground(index, Properties.Resources.slotView); - wc6 = SAV.getWC6(index); - loadwcdata(); + viewGiftData(mga.Gifts[index]); } private void clickSet(object sender, EventArgs e) { - if (wc6 == null) - return; - if (!checkSpecialWonderCard(wc6)) + if (!checkSpecialWonderCard(mg)) return; sender = ((sender as ToolStripItem)?.Owner as ContextMenuStrip)?.SourceControl ?? sender as PictureBox; @@ -160,11 +178,15 @@ private void clickSet(object sender, EventArgs e) int lastUnfilled = Array.FindIndex(pba, p => p.Image == null); if (lastUnfilled > -1 && lastUnfilled < index) index = lastUnfilled; - + if (mg.Data.Length != mga.Gifts[index].Data.Length) + { + Util.Alert("Can't set slot here.", $"{mg.GetType()} != {mga.Gifts[index].GetType()}"); + return; + } setBackground(index, Properties.Resources.slotSet); - SAV.setWC6(wc6, index); - populateWClist(); - setCardID(wc6.CardID); + mga.Gifts[index] = mg; + setGiftBoxes(); + setCardID(mg.CardID); } private void clickDelete(object sender, EventArgs e) { @@ -172,8 +194,8 @@ private void clickDelete(object sender, EventArgs e) int index = Array.IndexOf(pba, sender); setBackground(index, Properties.Resources.slotDel); - SAV.setWC6(new WC6(), index); - populateWClist(); + mga.Gifts[index].Data = new byte[mga.Gifts[index].Data.Length]; + setGiftBoxes(); } // Close Window @@ -183,14 +205,14 @@ private void B_Cancel_Click(object sender, EventArgs e) } private void B_Save_Click(object sender, EventArgs e) { - int offset = Main.SAV.WondercardFlags; - // Make sure all of the Received Flags are flipped! - bool[] flags = new bool[(SAV.WondercardData - SAV.WondercardFlags)*8]; + bool[] flags = new bool[mga.Flags.Length]; foreach (var o in LB_Received.Items) flags[Util.ToUInt32(o.ToString())] = true; - SAV.WC6Flags = flags; + mga.Flags = flags; + SAV.GiftAlbum = mga; + Main.SAV.Data = SAV.Data; Main.SAV.Edited = true; Close(); @@ -217,97 +239,77 @@ private void tabMain_DragDrop(object sender, DragEventArgs e) string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); // Check for multiple wondercards - int ctr = currentSlot; if (Directory.Exists(files[0])) files = Directory.GetFiles(files[0], "*", SearchOption.AllDirectories); if (files.Length == 1 && !Directory.Exists(files[0])) { string path = files[0]; // open first D&D long len = new FileInfo(path).Length; - if (len != WC6.Size && len != WC6.SizeFull) + if (len > 0x1000) // arbitrary { - Util.Error("File is not a Wonder Card:", path); + Util.Alert("File is not a Mystery Gift.", path); return; } - byte[] newwc6 = File.ReadAllBytes(path); - if (newwc6.Length == WC6.SizeFull) - newwc6 = newwc6.Skip(WC6.SizeFull - WC6.Size).ToArray(); - Array.Copy(newwc6, wc6.Data, newwc6.Length); - loadwcdata(); - return; - } - - if (DialogResult.Yes != Util.Prompt(MessageBoxButtons.YesNo, $"Try to load {files.Length} Wonder Cards starting at Card {ctr + 1}?")) - return; - - foreach (string file in files) - { - long len = new FileInfo(file).Length; - if (len != WC6.Size && len != WC6.SizeFull) - { Util.Error("File is not a Wonder Card:", file); continue; } - - // Load in WC - byte[] newwc6 = File.ReadAllBytes(file); - - if (newwc6.Length == WC6.SizeFull) - newwc6 = newwc6.Skip(WC6.SizeFull - WC6.Size).ToArray(); - if (checkSpecialWonderCard(new WC6(newwc6))) + MysteryGift g = MysteryGift.getMysteryGift(File.ReadAllBytes(path), Path.GetExtension(path)); + if (g == null) { - WC6 wc = new WC6(newwc6); - SAV.setWC6(wc, ctr++); - setCardID(wc.CardID); + Util.Error("File is not a Mystery Gift:", path); + return; } - if (ctr >= 24) - break; + viewGiftData(g); + return; } - populateWClist(); + setGiftBoxes(); } - private bool checkSpecialWonderCard(WC6 wc) + private bool checkSpecialWonderCard(MysteryGift g) { - if (wc6.CardID == 2048 && wc.Item == 726) // Eon Ticket (OR/AS) + if (SAV.Generation != 6) + return true; + + if (g is WC6) { - if (!Main.SAV.ORAS || Main.SAV.EonTicket < 0) - goto reject; - BitConverter.GetBytes(WC6.EonTicketConst).CopyTo(SAV.Data, Main.SAV.EonTicket); + if (g.CardID == 2048 && g.Item == 726) // Eon Ticket (OR/AS) + { + if (!Main.SAV.ORAS || ((SAV6)SAV).EonTicket < 0) + goto reject; + BitConverter.GetBytes(WC6.EonTicketConst).CopyTo(SAV.Data, ((SAV6)SAV).EonTicket); + } } return true; - reject: Util.Alert("Unable to insert the Wonder Card.", "Does this Wonder Card really belong to this game?"); + reject: Util.Alert("Unable to insert the Mystery Gift.", "Does this Mystery Gift really belong to this game?"); return false; } private void L_QR_Click(object sender, EventArgs e) { + if (SAV.Generation != 6) + { + Util.Alert("Feature not available for non Gen6 games."); + return; + } if (ModifierKeys == Keys.Alt) { - byte[] data = Util.getQRData(); + byte[] data = QR.getQRData(); if (data == null) return; - if (data.Length != WC6.Size) { Util.Alert("Decoded data not 0x108 bytes.", + if (data.Length != WC6.Size) { Util.Alert($"Decoded data not 0x{WC6.Size.ToString("X")} bytes.", $"QR Data Size: 0x{data.Length.ToString("X")}"); } - else try - { - wc6 = new WC6(data); - loadwcdata(); - } - catch { Util.Alert("Error loading wondercard data."); } + else try { viewGiftData(new WC6(data)); } + catch { Util.Alert("Error loading wondercard data."); } } else { - if (wc6.Data.SequenceEqual(new byte[wc6.Data.Length])) + if (mg.Data.SequenceEqual(new byte[mg.Data.Length])) { Util.Alert("No wondercard data found in loaded slot!"); return; } - if (wc6.Item == 726 && wc6.IsItem) + if (mg.Item == 726 && mg.IsItem) { Util.Alert("Eon Ticket Wonder Cards will not function properly", "Inject to the save file instead."); return; } - // Prep data - byte[] wcdata = wc6.Data; - // Ensure size - Array.Resize(ref wcdata, WC6.Size); - // Setup QR + const string server = "http://lunarcookies.github.io/wc.html#"; - Image qr = Util.getQRImage(wcdata, server); + Image qr = QR.getQRImage(mg.Data, server); if (qr == null) return; - string desc = wc6.Description; + string desc = getDescription(mg); new QR(qr, PB_Preview.Image, desc, "", "", "PKHeX Wonder Card @ ProjectPokemon.org").ShowDialog(); } @@ -315,19 +317,14 @@ private void L_QR_Click(object sender, EventArgs e) private void pbBoxSlot_MouseDown(object sender, MouseEventArgs e) { - if (ModifierKeys == Keys.Control || ModifierKeys == Keys.Alt || ModifierKeys == Keys.Shift || - ModifierKeys == (Keys.Control | Keys.Alt)) + switch (ModifierKeys) { - switch (ModifierKeys) - { - case Keys.Control: clickView(sender, e); break; - case Keys.Shift: clickSet(sender, e); break; - case Keys.Alt: clickDelete(sender, e); break; - } - return; + case Keys.Control: clickView(sender, e); return; + case Keys.Shift: clickSet(sender, e); return; + case Keys.Alt: clickDelete(sender, e); return; } - PictureBox pb = (PictureBox)sender; - if (pb.Image == null) + PictureBox pb = sender as PictureBox; + if (pb?.Image == null) return; if (e.Button != MouseButtons.Left || e.Clicks != 1) return; @@ -338,7 +335,7 @@ private void pbBoxSlot_MouseDown(object sender, MouseEventArgs e) Cursor.Current = Cursors.Hand; // Prepare Data - WC6 card = SAV.getWC6(index); + MysteryGift card = mga.Gifts[index]; string filename = Util.CleanFileName($"{card.CardID.ToString("0000")} - {card.CardTitle}.wc6"); // Make File @@ -361,34 +358,48 @@ private void pbBoxSlot_DragDrop(object sender, DragEventArgs e) int lastUnfilled = Array.FindIndex(pba, p => p.Image == null); if (lastUnfilled < index) index = lastUnfilled; - - // Check for In-Dropped files (PKX,SAV,ETC) - - if (wc_slot == -1) + + if (wc_slot == -1) // dropped { string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); - if (files.Length < 1 || new FileInfo(files[0]).Length != WC6.Size) + if (files.Length < 1) return; + if (PCD.Size < (int)new FileInfo(files[0]).Length) + { Util.Alert("Data size invalid.", files[0]); return; } - WC6 wc = new WC6(File.ReadAllBytes(files[0])); - SAV.setWC6(wc, index); - setCardID(wc.CardID); - wc6 = wc; - loadwcdata(); + byte[] data = File.ReadAllBytes(files[0]); + chk: + if (data.Length != mga.Gifts[index].Data.Length) + { + if (index < 8) + { + index = 8; + goto chk; + } + { Util.Alert("Can't set slot here.", $"{data.Length} != {mga.Gifts[index].Data.Length}, {mga.Gifts[index].GetType()}", files[0]); return; } + } + + mga.Gifts[index].Data = data; + setCardID(mga.Gifts[index].CardID); + viewGiftData(mga.Gifts[index]); } else // Swap Data { // Check to see if they copied beyond blank slots. if (index > Math.Max(wc_slot, lastUnfilled - 1)) index = Math.Max(wc_slot, lastUnfilled - 1); - WC6 s1 = SAV.getWC6(index); - WC6 s2 = SAV.getWC6(wc_slot); - SAV.setWC6(s1, wc_slot); - SAV.setWC6(s2, index); + + MysteryGift s1 = mga.Gifts[index]; + MysteryGift s2 = mga.Gifts[wc_slot]; + + if (s1.Data.Length != s2.Data.Length) + { Util.Alert("Can't swap these two slots."); return; } + mga.Gifts[wc_slot] = s1; + mga.Gifts[index] = s2; } setBackground(index, Properties.Resources.slotView); - populateWClist(); + setGiftBoxes(); } private void pbBoxSlot_DragEnter(object sender, DragEventArgs e) { @@ -398,52 +409,47 @@ private void pbBoxSlot_DragEnter(object sender, DragEventArgs e) e.Effect = DragDropEffects.Move; } private int wc_slot = -1; - } - // Extension Properties - public partial class WC6 - { - public Image Preview + private static Image getSprite(MysteryGift gift) { - get - { - Image img; - if (IsPokémon) - img = PKX.getSprite(Species, Form, Gender, HeldItem, IsEgg, PIDType == 2); - else if (IsItem) - img = (Image)(Properties.Resources.ResourceManager.GetObject("item_" + Item) ?? Properties.Resources.unknown); - else - img = Properties.Resources.unknown; + Image img; + if (gift.IsPokémon) + img = PKX.getSprite(gift.convertToPKM(Main.SAV)); + else if (gift.IsItem) + img = (Image)(Properties.Resources.ResourceManager.GetObject("item_" + gift.Item) ?? Properties.Resources.unknown); + else + img = Properties.Resources.unknown; - if (GiftUsed) - img = Util.LayerImage(new Bitmap(img.Width, img.Height), img, 0, 0, 0.3); - return img; - } + if (gift.GiftUsed) + img = Util.LayerImage(new Bitmap(img.Width, img.Height), img, 0, 0, 0.3); + return img; } - public string Description + private static string getDescription(MysteryGift gift) { - get + if (gift.Empty) + return "Empty Slot. No data!"; + + string s = gift.getCardHeader(); + if (gift.IsItem) { - if (CardID == 0) - return "Empty Slot. No data!"; - - string s = $"Card #: {CardID.ToString("0000")} - {CardTitle.Trim()}" + Environment.NewLine; - - switch (CardType) - { - case 1: - s += "Item: " + Main.itemlist[Item] + Environment.NewLine + "Quantity: " + Quantity; - return s; - case 0: - s += - $"{Main.specieslist[Species]} @ {Main.itemlist[HeldItem]} --- {OT} - {TID.ToString("00000")}/{SID.ToString("00000")}" + Environment.NewLine + - $"{Main.movelist[Move1]} / {Main.movelist[Move2]} / {Main.movelist[Move3]} / {Main.movelist[Move4]}" + Environment.NewLine; - return s; - default: - s += "Unknown Wonder Card Type!"; - return s; - } + s += "Item: " + Main.itemlist[gift.Item] + Environment.NewLine + "Quantity: " + gift.Quantity; + return s; } + if (gift.IsPokémon) + { + PKM pk = gift.convertToPKM(Main.SAV); + + try + { + s += $"{Main.specieslist[pk.Species]} @ {Main.itemlist[pk.HeldItem]} --- "; + s += (pk.IsEgg ? Main.eggname : $"{pk.OT_Name} - {pk.TID.ToString("00000")}/{pk.SID.ToString("00000")}") + Environment.NewLine; + s += $"{Main.movelist[pk.Move1]} / {Main.movelist[pk.Move2]} / {Main.movelist[pk.Move3]} / {Main.movelist[pk.Move4]}" + Environment.NewLine; + } + catch { s += "Unable to create gift description."; } + return s; + } + s += "Unknown Wonder Card Type!"; + return s; } } } \ No newline at end of file diff --git a/SAV/frmReport.cs b/SAV/frmReport.cs index e008593f0..5ed00dc3f 100644 --- a/SAV/frmReport.cs +++ b/SAV/frmReport.cs @@ -13,103 +13,101 @@ namespace PKHeX { public partial class frmReport : Form { - private byte[] SaveData; - public class Preview { - private readonly PK6 pk6; - public string Position => pk6.Identifier; - public Image Sprite => pk6.Sprite; - public string Nickname => pk6.Nickname; - public string Species => Main.specieslist[pk6.Species]; - public string Nature => Main.natures[pk6.Nature]; - public string Gender => Main.gendersymbols[pk6.Gender]; - public string ESV => pk6.PSV.ToString("0000"); - public string HP_Type => Main.types[pk6.HPType+1]; - public string Ability => Main.abilitylist[pk6.Ability]; - public string Move1 => Main.movelist[pk6.Move1]; - public string Move2 => Main.movelist[pk6.Move2]; - public string Move3 => Main.movelist[pk6.Move3]; - public string Move4 => Main.movelist[pk6.Move4]; - public string HeldItem => Main.itemlist[pk6.HeldItem]; - public string MetLoc => PKX.getLocation(false, pk6.Version, pk6.Met_Location); - public string EggLoc => PKX.getLocation(true, pk6.Version, pk6.Egg_Location); - public string Ball => Main.balllist[pk6.Ball]; - public string OT => pk6.OT_Name; - public string Version => Main.gamelist[pk6.Version]; - public string OTLang => Main.gamelanguages[pk6.Language] ?? $"UNK {pk6.Language}"; - public string CountryID => pk6.Country.ToString(); - public string RegionID => pk6.Region.ToString(); - public string DSRegionID => pk6.ConsoleRegion.ToString(); + private readonly PKM pkm; + public string Position => pkm.Identifier; + public Image Sprite => pkm.Sprite; + public string Nickname => pkm.Nickname; + public string Species => Main.specieslist[pkm.Species]; + public string Nature => Main.natures[pkm.Nature]; + public string Gender => Main.gendersymbols[pkm.Gender]; + public string ESV => pkm.PSV.ToString("0000"); + public string HP_Type => Main.types[pkm.HPType+1]; + public string Ability => Main.abilitylist[pkm.Ability]; + public string Move1 => Main.movelist[pkm.Move1]; + public string Move2 => Main.movelist[pkm.Move2]; + public string Move3 => Main.movelist[pkm.Move3]; + public string Move4 => Main.movelist[pkm.Move4]; + public string HeldItem => Main.itemlist[pkm.HeldItem]; + public string MetLoc => PKX.getLocation(pkm, egg: false); + public string EggLoc => PKX.getLocation(pkm, egg: true); + public string Ball => Main.balllist[pkm.Ball]; + public string OT => pkm.OT_Name; + public string Version => Main.gamelist[pkm.Version]; + public string OTLang => Main.gamelanguages[pkm.Language] ?? $"UNK {pkm.Language}"; + public string CountryID => pkm.Format > 5 ? (pkm as PK6).Country.ToString() : "N/A"; + public string RegionID => pkm.Format > 5 ? (pkm as PK6).Region.ToString() : "N/A"; + public string DSRegionID => pkm.Format > 5 ? (pkm as PK6).ConsoleRegion.ToString() : "N/A"; #region Extraneous - public string EC => pk6.EncryptionConstant.ToString("X8"); - public string PID => pk6.PID.ToString("X8"); - public int HP_IV => pk6.IV_HP; - public int ATK_IV => pk6.IV_ATK; - public int DEF_IV => pk6.IV_DEF; - public int SPA_IV => pk6.IV_SPA; - public int SPD_IV => pk6.IV_SPD; - public int SPE_IV => pk6.IV_SPE; - public uint EXP => pk6.EXP; - public int Level => pk6.CurrentLevel; - public int HP_EV => pk6.EV_HP; - public int ATK_EV => pk6.EV_ATK; - public int DEF_EV => pk6.EV_DEF; - public int SPA_EV => pk6.EV_SPA; - public int SPD_EV => pk6.EV_SPD; - public int SPE_EV => pk6.EV_SPE; - public int Cool => pk6.CNT_Cool; - public int Beauty => pk6.CNT_Beauty; - public int Cute => pk6.CNT_Cute; - public int Smart => pk6.CNT_Smart; - public int Tough => pk6.CNT_Tough; - public int Sheen => pk6.CNT_Sheen; - public int Markings => pk6.Markings; + public string EC => pkm.EncryptionConstant.ToString("X8"); + public string PID => pkm.PID.ToString("X8"); + public int HP_IV => pkm.IV_HP; + public int ATK_IV => pkm.IV_ATK; + public int DEF_IV => pkm.IV_DEF; + public int SPA_IV => pkm.IV_SPA; + public int SPD_IV => pkm.IV_SPD; + public int SPE_IV => pkm.IV_SPE; + public uint EXP => pkm.EXP; + public int Level => pkm.CurrentLevel; + public int HP_EV => pkm.EV_HP; + public int ATK_EV => pkm.EV_ATK; + public int DEF_EV => pkm.EV_DEF; + public int SPA_EV => pkm.EV_SPA; + public int SPD_EV => pkm.EV_SPD; + public int SPE_EV => pkm.EV_SPE; + public int Cool => pkm.CNT_Cool; + public int Beauty => pkm.CNT_Beauty; + public int Cute => pkm.CNT_Cute; + public int Smart => pkm.CNT_Smart; + public int Tough => pkm.CNT_Tough; + public int Sheen => pkm.CNT_Sheen; + public int Markings => pkm.MarkByte; - public string NotOT => pk6.HT_Name; + public string NotOT => pkm.Format > 5 ? (pkm as PK6).HT_Name : "N/A"; - public int AbilityNum => pk6.AbilityNumber; - public int GenderFlag => pk6.Gender; - public int AltForms => pk6.AltForm; - public int PKRS_Strain => pk6.PKRS_Strain; - public int PKRS_Days => pk6.PKRS_Days; - public int MetLevel => pk6.Met_Level; - public int OT_Gender => pk6.OT_Gender; + public int AbilityNum => pkm.Format > 5 ? (pkm as PK6).AbilityNumber : -1; + public int GenderFlag => pkm.Gender; + public int AltForms => pkm.AltForm; + public int PKRS_Strain => pkm.PKRS_Strain; + public int PKRS_Days => pkm.PKRS_Days; + public int MetLevel => pkm.Met_Level; + public int OT_Gender => pkm.OT_Gender; - public bool FatefulFlag => pk6.FatefulEncounter; - public bool IsEgg => pk6.IsEgg; - public bool IsNicknamed => pk6.IsNicknamed; - public bool IsShiny => pk6.IsShiny; + public bool FatefulFlag => pkm.FatefulEncounter; + public bool IsEgg => pkm.IsEgg; + public bool IsNicknamed => pkm.IsNicknamed; + public bool IsShiny => pkm.IsShiny; - public int TID => pk6.TID; - public int SID => pk6.SID; - public int TSV => pk6.TSV; - public int Move1_PP => pk6.Move1_PP; - public int Move2_PP => pk6.Move2_PP; - public int Move3_PP => pk6.Move3_PP; - public int Move4_PP => pk6.Move4_PP; - public int Move1_PPUp => pk6.Move1_PPUps; - public int Move2_PPUp => pk6.Move2_PPUps; - public int Move3_PPUp => pk6.Move3_PPUps; - public int Move4_PPUp => pk6.Move4_PPUps; - public string Relearn1 => Main.movelist[pk6.RelearnMove1]; - public string Relearn2 => Main.movelist[pk6.RelearnMove2]; - public string Relearn3 => Main.movelist[pk6.RelearnMove3]; - public string Relearn4 => Main.movelist[pk6.RelearnMove4]; - public ushort Checksum => pk6.Checksum; - public int mFriendship => pk6.OT_Friendship; - public int OT_Affection => pk6.OT_Affection; - public int Egg_Year => pk6.Egg_Year; - public int Egg_Month => pk6.Egg_Month; - public int Egg_Day => pk6.Egg_Day; - public int Met_Year => pk6.Met_Year; - public int Met_Month => pk6.Met_Month; - public int Met_Day => pk6.Met_Day; - public int Encounter => pk6.EncounterType; + public int TID => pkm.TID; + public int SID => pkm.SID; + public int TSV => pkm.TSV; + public int Move1_PP => pkm.Move1_PP; + public int Move2_PP => pkm.Move2_PP; + public int Move3_PP => pkm.Move3_PP; + public int Move4_PP => pkm.Move4_PP; + public int Move1_PPUp => pkm.Move1_PPUps; + public int Move2_PPUp => pkm.Move2_PPUps; + public int Move3_PPUp => pkm.Move3_PPUps; + public int Move4_PPUp => pkm.Move4_PPUps; + public string Relearn1 => Main.movelist[pkm.RelearnMove1]; + public string Relearn2 => Main.movelist[pkm.RelearnMove2]; + public string Relearn3 => Main.movelist[pkm.RelearnMove3]; + public string Relearn4 => Main.movelist[pkm.RelearnMove4]; + public ushort Checksum => pkm.Checksum; + public int mFriendship => pkm.OT_Friendship; + public int OT_Affection => pkm.OT_Affection; + public int Egg_Year => pkm.Egg_Year; + public int Egg_Month => pkm.Egg_Month; + public int Egg_Day => pkm.Egg_Day; + public int Met_Year => pkm.Met_Year; + public int Met_Month => pkm.Met_Month; + public int Met_Day => pkm.Met_Day; + public int Encounter => pkm.EncounterType; #endregion - public Preview(PK6 p) { pk6 = p; } + public Preview(PKM p) { pkm = p; } } public frmReport() { @@ -117,51 +115,24 @@ public frmReport() dgData.DoubleBuffered(true); CenterToParent(); } - public void PopulateData(byte[] InputData, int BoxDataOffset) + public void PopulateData(SaveFile SAV) { - SaveData = (byte[])InputData.Clone(); - PokemonList PL = new PokemonList(); - BoxBar.Maximum = 930 + 100; - BoxBar.Step = 1; - for (int BoxNum = 0; BoxNum < 31; BoxNum++) - { - int boxoffset = BoxDataOffset + BoxNum*0xE8*30; - for (int SlotNum = 0; SlotNum < 30; SlotNum++) - { - BoxBar.PerformStep(); - int offset = boxoffset + 0xE8 * SlotNum; - byte[] slotdata = new byte[0xE8]; - Array.Copy(SaveData, offset, slotdata, 0, 0xE8); - byte[] dslotdata = PKX.decryptArray(slotdata); - if (BitConverter.ToUInt16(dslotdata, 0x8) == 0) continue; - string Identifier = $"B{(BoxNum + 1).ToString("00")}:{(SlotNum + 1).ToString("00")}"; - PK6 pkm = new PK6(dslotdata, Identifier); - if (!pkm.ChecksumValid) continue; - pkm.Stat_Level = PKX.getLevel(pkm.Species, pkm.EXP); // recalc Level - PL.Add(new Preview(pkm)); - } - } - dgData.DataSource = PL; - dgData.AutoGenerateColumns = true; - BoxBar.Maximum = 930 + dgData.Columns.Count; - for (int i = 0; i < dgData.Columns.Count; i++) - { - BoxBar.PerformStep(); - if (dgData.Columns[i] is DataGridViewImageColumn) continue; // Don't add sorting for Sprites - dgData.Columns[i].SortMode = DataGridViewColumnSortMode.Automatic; - } - BoxBar.Visible = false; + PopulateData(SAV.BoxData); } - public void PopulateData(PK6[] data) + public void PopulateData(PKM[] Data) { BoxBar.Step = 1; PokemonList PL = new PokemonList(); - foreach (PK6 p in data) - PL.Add(new Preview(p)); + foreach (PKM pkm in Data.Where(pkm => pkm.ChecksumValid && pkm.Species != 0)) + { + pkm.Stat_Level = PKX.getLevel(pkm.Species, pkm.EXP); // recalc Level + PL.Add(new Preview(pkm)); + BoxBar.PerformStep(); + } dgData.DataSource = PL; dgData.AutoGenerateColumns = true; - BoxBar.Maximum = data.Length + dgData.Columns.Count; + BoxBar.Maximum = Data.Length + dgData.Columns.Count; for (int i = 0; i < dgData.Columns.Count; i++) { BoxBar.PerformStep(); @@ -216,14 +187,7 @@ public class SortableBindingList : BindingList private ListSortDirection listSortDirection; private PropertyDescriptor propertyDescriptor; - protected SortableBindingList() - : base(new List()) - { - comparers = new Dictionary>(); - } - - public SortableBindingList(IEnumerable enumeration) - : base(new List(enumeration)) + protected SortableBindingList() : base(new List()) { comparers = new Dictionary>(); } @@ -273,13 +237,8 @@ protected override int FindCore(PropertyDescriptor property, object key) { int count = Count; for (int i = 0; i < count; ++i) - { - T element = this[i]; - if (property.GetValue(element).Equals(key)) - { + if (property.GetValue(this[i]).Equals(key)) return i; - } - } return -1; } diff --git a/Saves/BlockInfo.cs b/Saves/BlockInfo.cs new file mode 100644 index 000000000..64edb09e8 --- /dev/null +++ b/Saves/BlockInfo.cs @@ -0,0 +1,25 @@ +namespace PKHeX +{ + public sealed class BlockInfo + { + // General + public int Offset; + public int Length; + + // Gen6 + public ushort ID; + public ushort Checksum; + public BlockInfo() { } + + // Gen4/5 + public readonly int ChecksumOffset; + public readonly int ChecksumMirror; + public BlockInfo(int offset, int length, int chkOffset, int chkMirror) + { + Offset = offset; + Length = length; + ChecksumOffset = chkOffset; + ChecksumMirror = chkMirror; + } + } +} diff --git a/Saves/Inventory.cs b/Saves/Inventory.cs new file mode 100644 index 000000000..dee6e3a56 --- /dev/null +++ b/Saves/Inventory.cs @@ -0,0 +1,64 @@ +using System; + +namespace PKHeX +{ + public enum InventoryType + { + Items, + KeyItems, + TMHMs, + Medicine, + Berries, + Balls, + BattleItems, + MailItems, + } + public class InventoryItem + { + public int Index, Count; + } + + public class InventoryPouch + { + public readonly InventoryType Type; + public readonly ushort[] LegalItems; + public readonly int MaxCount; + private readonly int Offset; + private readonly int PouchDataSize; + public InventoryItem[] Items; + + public InventoryPouch(InventoryType type, ushort[] legal, int maxcount, int offset, int size = -1) + { + Type = type; + LegalItems = legal; + MaxCount = maxcount; + Offset = offset; + PouchDataSize = size > -1 ? size : legal.Length; + } + + public void getPouch(ref byte[] Data) + { + InventoryItem[] items = new InventoryItem[PouchDataSize]; + for (int i = 0; i < items.Length; i++) + { + items[i] = new InventoryItem + { + Index = BitConverter.ToUInt16(Data, Offset + i*4), + Count = BitConverter.ToUInt16(Data, Offset + i*4 + 2) + }; + } + Items = items; + } + public void setPouch(ref byte[] Data) + { + if (Items.Length != PouchDataSize) + throw new ArgumentException("Item array length does not match original pouch size."); + + for (int i = 0; i < Items.Length; i++) + { + BitConverter.GetBytes((ushort)Items[i].Index).CopyTo(Data, Offset + i*4); + BitConverter.GetBytes((ushort)Items[i].Count).CopyTo(Data, Offset + i*4 + 2); + } + } + } +} diff --git a/Saves/SAV4.cs b/Saves/SAV4.cs new file mode 100644 index 000000000..36b90303a --- /dev/null +++ b/Saves/SAV4.cs @@ -0,0 +1,665 @@ +using System; +using System.Linq; + +namespace PKHeX +{ + public sealed class SAV4 : SaveFile + { + public override string BAKName => $"{FileName} [{OT} ({Version})" +/* - {LastSavedTime}*/ "].bak"; + public SAV4(byte[] data = null) + { + Data = data == null ? new byte[SaveUtil.SIZE_G4RAW] : (byte[])data.Clone(); + BAK = (byte[])Data.Clone(); + Exportable = !Data.SequenceEqual(new byte[Data.Length]); + + // Get Version + SaveVersion = Math.Max(SaveUtil.getIsG4SAV(Data), 0); // Empty file default to DP + getActiveBlock(); + getSAVOffsets(); + + if (!Exportable) + resetBoxes(); + } + + // Configuration + public readonly int SaveVersion; + public override byte[] BAK { get; } + public override bool Exportable { get; } + public override SaveFile Clone() { return new SAV4(Data); } + + public override int SIZE_STORED => PKX.SIZE_4STORED; + public override int SIZE_PARTY => PKX.SIZE_4PARTY; + public override PKM BlankPKM => new PK4(); + protected override Type PKMType => typeof(PK4); + + public override int BoxCount => 18; + public override int MaxEV => 255; + public override int Generation => 4; + protected override int EventFlagMax => int.MinValue; + protected override int EventConstMax => int.MinValue; + protected override int GiftCountMax => 11; + public override int OTLength => 8; + public override int NickLength => 10; + + // Checksums + protected override void setChecksums() + { + + switch (Version) + { + case GameVersion.DP: + // 0x0000-0xC0EC @ 0xC0FE + // 0xc100-0x1E2CC @ 0x1E2DE + BitConverter.GetBytes(SaveUtil.ccitt16(Data.Skip(0 + GBO).Take(0xC0EC).ToArray())).CopyTo(Data, 0xC0FE + GBO); + BitConverter.GetBytes(SaveUtil.ccitt16(Data.Skip(0xc100 + SBO).Take(0x121CC).ToArray())).CopyTo(Data, 0x1E2DE + SBO); + break; + case GameVersion.Pt: + // 0x0000-0xCF18 @ 0xCF2A + // 0xCF2C-0x1F0FC @ 0x1F10E + BitConverter.GetBytes(SaveUtil.ccitt16(Data.Skip(0 + GBO).Take(0xCF18).ToArray())).CopyTo(Data, 0xCF2A + GBO); + BitConverter.GetBytes(SaveUtil.ccitt16(Data.Skip(0xCF2C + SBO).Take(0x121D0).ToArray())).CopyTo(Data, 0x1F10E + SBO); + break; + case GameVersion.HGSS: + // 0x0000-0xF618 @ 0xF626 + // 0xF700-0x219FC @ 0x21A0E + BitConverter.GetBytes(SaveUtil.ccitt16(Data.Skip(0 + GBO).Take(0xF618).ToArray())).CopyTo(Data, 0xF626 + GBO); + BitConverter.GetBytes(SaveUtil.ccitt16(Data.Skip(0xF700 + SBO).Take(0x12300).ToArray())).CopyTo(Data, 0x21A0E + SBO); + break; + } + } + public override bool ChecksumsValid + { + get + { + switch (Version) + { + case GameVersion.DP: + // 0x0000-0xC0EC @ 0xC0FE + // 0xc100-0x1E2CC @ 0x1E2DE + if (SaveUtil.ccitt16(Data.Skip(0 + GBO).Take(0xC0EC).ToArray()) != BitConverter.ToUInt16(Data, 0xC0FE + GBO)) + return false; // Small Fail + if (SaveUtil.ccitt16(Data.Skip(0xc100 + SBO).Take(0x121CC).ToArray()) != BitConverter.ToUInt16(Data, 0x1E2DE + SBO)) + return false; // Large Fail + break; + case GameVersion.Pt: + // 0x0000-0xCF18 @ 0xCF2A + // 0xCF2C-0x1F0FC @ 0x1F10E + if (SaveUtil.ccitt16(Data.Skip(0 + GBO).Take(0xCF18).ToArray()) != BitConverter.ToUInt16(Data, 0xCF2A + GBO)) + return false; // Small Fail + if (SaveUtil.ccitt16(Data.Skip(0xCF2C + SBO).Take(0x121D0).ToArray()) != BitConverter.ToUInt16(Data, 0x1F10E + SBO)) + return false; // Large Fail + break; + case GameVersion.HGSS: + // 0x0000-0xF618 @ 0xF626 + // 0xF700-0x219FC @ 0x21A0E + if (SaveUtil.ccitt16(Data.Skip(0 + GBO).Take(0xF618).ToArray()) != BitConverter.ToUInt16(Data, 0xF626 + GBO)) + return false; // Small Fail + if (SaveUtil.ccitt16(Data.Skip(0xF700 + SBO).Take(0x12300).ToArray()) != BitConverter.ToUInt16(Data, 0x21A0E + SBO)) + return false; // Large Fail + break; + } + return true; + } + } + public override string ChecksumInfo + { + get + { + string r = ""; + switch (Version) + { + case GameVersion.DP: + // 0x0000-0xC0EC @ 0xC0FE + // 0xc100-0x1E2CC @ 0x1E2DE + if (SaveUtil.ccitt16(Data.Skip(0 + GBO).Take(0xC0EC).ToArray()) != BitConverter.ToUInt16(Data, 0xC0FE + GBO)) + r += "Small block checksum is invalid" + Environment.NewLine; + if (SaveUtil.ccitt16(Data.Skip(0xc100 + SBO).Take(0x121CC).ToArray()) != BitConverter.ToUInt16(Data, 0x1E2DE + SBO)) + r += "Large block checksum is invalid" + Environment.NewLine; + break; + case GameVersion.Pt: + // 0x0000-0xCF18 @ 0xCF2A + // 0xCF2C-0x1F0FC @ 0x1F10E + if (SaveUtil.ccitt16(Data.Skip(0 + GBO).Take(0xCF18).ToArray()) != BitConverter.ToUInt16(Data, 0xCF2A + GBO)) + r += "Small block checksum is invalid" + Environment.NewLine; + if (SaveUtil.ccitt16(Data.Skip(0xCF2C + SBO).Take(0x121D0).ToArray()) != BitConverter.ToUInt16(Data, 0x1F10E + SBO)) + r += "Large block checksum is invalid" + Environment.NewLine; + break; + case GameVersion.HGSS: + // 0x0000-0xF618 @ 0xF626 + // 0xF700-0x219FC @ 0x21A0E + if (SaveUtil.ccitt16(Data.Skip(0 + GBO).Take(0xF618).ToArray()) != BitConverter.ToUInt16(Data, 0xF626 + GBO)) + r += "Small block checksum is invalid" + Environment.NewLine; + if (SaveUtil.ccitt16(Data.Skip(0xF700 + SBO).Take(0x12300).ToArray()) != BitConverter.ToUInt16(Data, 0x21A0E + SBO)) + r += "Large block checksum is invalid" + Environment.NewLine; + break; + } + return r.Length == 0 ? "Checksums valid." : r.TrimEnd(); + } + } + + // Blocks & Offsets + private int generalBlock = -1; // Small Block + private int storageBlock = -1; // Big Block + private int hofBlock = -1; // Hall of Fame Block + private int SBO => 0x40000 * storageBlock; + private int GBO => 0x40000 * generalBlock; + private int HBO => 0x40000 * hofBlock; + private void getActiveBlock() + { + if (SaveVersion < 0) + return; + int ofs = 0; + + if (SaveVersion == 0) ofs = 0xC0F0; // DP + else if (SaveVersion == 1) ofs = 0xCF1C; // PT + else if (SaveVersion == 2) ofs = 0xF626; // HGSS + generalBlock = BitConverter.ToUInt16(Data, ofs) >= BitConverter.ToUInt16(Data, ofs + 0x40000) ? 0 : 1; + + if (SaveVersion == 0) ofs = 0x1E2D0; // DP + else if (SaveVersion == 1) ofs = 0x1F100; // PT + else if (SaveVersion == 2) ofs = 0x21A00; // HGSS + storageBlock = BitConverter.ToUInt16(Data, ofs) >= BitConverter.ToUInt16(Data, ofs + 0x40000) ? 0 : 1; + } + private void getSAVOffsets() + { + if (SaveVersion < 0) + return; + + switch (Version) + { + case GameVersion.DP: + AdventureInfo = 0 + GBO; + Trainer1 = 0x64 + GBO; + Party = 0x98 + GBO; + WondercardFlags = 0xA6D0 + GBO; + WondercardData = 0xA7fC + GBO; + + OFS_PouchHeldItem = 0x624 + GBO; + OFS_PouchKeyItem = 0x8B8 + GBO; + OFS_PouchTMHM = 0x980 + GBO; + OFS_PouchMedicine = 0xB40 + GBO; + OFS_PouchBerry = 0xBE0 + GBO; + OFS_PouchBalls = 0xCE0 + GBO; + OFS_BattleItems = 0xD1C + GBO; + OFS_MailItems = 0xD50 + GBO; + LegalItems = Legal.Pouch_Items_DP; + LegalKeyItems = Legal.Pouch_Key_DP; + LegalTMHMs = Legal.Pouch_TMHM_DP; + LegalMedicine = Legal.Pouch_Medicine_DP; + LegalBerries = Legal.Pouch_Berries_DP; + LegalBalls = Legal.Pouch_Ball_DP; + LegalBattleItems = Legal.Pouch_Battle_DP; + LegalMailItems = Legal.Pouch_Mail_DP; + + HeldItems = Legal.HeldItems_DP; + + Daycare = 0x141C + GBO; + Box = 0xC104 + SBO; + break; + case GameVersion.Pt: + AdventureInfo = 0 + GBO; + Trainer1 = 0x68 + GBO; + Party = 0xA0 + GBO; + WondercardFlags = 0xB4C0 + GBO; + WondercardData = 0xB5C0 + GBO; + + OFS_PouchHeldItem = 0x630 + GBO; + OFS_PouchKeyItem = 0x8C4 + GBO; + OFS_PouchTMHM = 0x98C + GBO; + OFS_MailItems = 0xB1C + GBO; + OFS_PouchMedicine = 0xB4C + GBO; + OFS_PouchBerry = 0xBEC + GBO; + OFS_PouchBalls = 0xCEC + GBO; + OFS_BattleItems = 0xD28 + GBO; + LegalItems = Legal.Pouch_Items_Pt; + LegalKeyItems = Legal.Pouch_Key_Pt; + LegalTMHMs = Legal.Pouch_TMHM_Pt; + LegalMedicine = Legal.Pouch_Medicine_Pt; + LegalBerries = Legal.Pouch_Berries_Pt; + LegalBalls = Legal.Pouch_Ball_Pt; + LegalBattleItems = Legal.Pouch_Battle_Pt; + LegalMailItems = Legal.Pouch_Mail_Pt; + + HeldItems = Legal.HeldItems_Pt; + + Daycare = 0x1654 + GBO; + Box = 0xCF30 + SBO; + break; + case GameVersion.HGSS: + AdventureInfo = 0 + GBO; + Trainer1 = 0x64 + GBO; + Party = 0x98 + GBO; + WondercardFlags = 0x9D3C + GBO; + WondercardData = 0x9E3C + GBO; + + OFS_PouchHeldItem = 0x644 + GBO; // 0x644-0x8D7 (0x8CB) + OFS_PouchKeyItem = 0x8D8 + GBO; // 0x8D8-0x99F (0x979) + OFS_PouchTMHM = 0x9A0 + GBO; // 0x9A0-0xB33 (0xB2F) + OFS_MailItems = 0xB34 + GBO; // 0xB34-0xB63 (0xB63) + OFS_PouchMedicine = 0xB64 + GBO; // 0xB64-0xC03 (0xBFB) + OFS_PouchBerry = 0xC04 + GBO; // 0xC04-0xD03 + OFS_PouchBalls = 0xD04 + GBO; // 0xD04-0xD63 + OFS_BattleItems = 0xD64 + GBO; // 0xD64-0xD97 + LegalItems = Legal.Pouch_Items_HGSS; + LegalKeyItems = Legal.Pouch_Key_HGSS; + LegalTMHMs = Legal.Pouch_TMHM_HGSS; + LegalMedicine = Legal.Pouch_Medicine_HGSS; + LegalBerries = Legal.Pouch_Berries_HGSS; + LegalBalls = Legal.Pouch_Ball_HGSS; + LegalBattleItems = Legal.Pouch_Battle_HGSS; + LegalMailItems = Legal.Pouch_Mail_HGSS; + + HeldItems = Legal.HeldItems_HGSS; + + Daycare = 0x15FC + GBO; + Box = 0xF700 + SBO; + break; + } + } + + private int WondercardFlags = int.MinValue; + private int AdventureInfo = int.MinValue; + + // Inventory + private ushort[] LegalItems, LegalKeyItems, LegalTMHMs, LegalMedicine, LegalBerries, LegalBalls, LegalBattleItems, LegalMailItems; + public override InventoryPouch[] Inventory + { + get + { + InventoryPouch[] pouch = + { + new InventoryPouch(InventoryType.Items, LegalItems, 995, OFS_PouchHeldItem), + new InventoryPouch(InventoryType.KeyItems, LegalKeyItems, 1, OFS_PouchKeyItem), + new InventoryPouch(InventoryType.TMHMs, LegalTMHMs, 95, OFS_PouchTMHM), + new InventoryPouch(InventoryType.Medicine, LegalMedicine, 995, OFS_PouchMedicine), + new InventoryPouch(InventoryType.Berries, LegalBerries, 995, OFS_PouchBerry), + new InventoryPouch(InventoryType.Balls, LegalBalls, 995, OFS_PouchBalls), + new InventoryPouch(InventoryType.BattleItems, LegalBattleItems, 995, OFS_BattleItems), + new InventoryPouch(InventoryType.MailItems, LegalMailItems, 995, OFS_MailItems), + }; + foreach (var p in pouch) + p.getPouch(ref Data); + return pouch; + } + set + { + foreach (var p in value) + p.setPouch(ref Data); + } + } + + // Storage + public override int PartyCount + { + get { return Data[Party - 4]; } + protected set { Data[Party - 4] = (byte)value; } + } + public override int getBoxOffset(int box) + { + return Box + SIZE_STORED*box*30 + (SaveVersion == 2 ? box * 0x10 : 0); + } + public override int getPartyOffset(int slot) + { + return Party + SIZE_PARTY*slot; + } + + // Trainer Info + protected override GameVersion Version + { + get + { + switch (SaveVersion) + { + case 0: return GameVersion.DP; + case 1: return GameVersion.Pt; + case 2: return GameVersion.HGSS; + } + return GameVersion.Unknown; + } + } + public override string OT + { + get + { + return PKX.array2strG4(Data.Skip(Trainer1).Take(0x10).ToArray()) + .Replace("\uE08F", "\u2640") // Nidoran ♂ + .Replace("\uE08E", "\u2642") // Nidoran ♀ + .Replace("\u2019", "\u0027"); // Farfetch'd + } + set + { + if (value.Length > 7) + value = value.Substring(0, 7); // Hard cap + string TempNick = value // Replace Special Characters and add Terminator + .Replace("\u2640", "\uE08F") // Nidoran ♂ + .Replace("\u2642", "\uE08E") // Nidoran ♀ + .Replace("\u0027", "\u2019"); // Farfetch'd + PKX.str2arrayG4(TempNick).CopyTo(Data, Trainer1); + } + } + public override ushort TID + { + get { return BitConverter.ToUInt16(Data, Trainer1 + 0x10 + 0); } + set { BitConverter.GetBytes(value).CopyTo(Data, Trainer1 + 0x10 + 0); } + } + public override ushort SID + { + get { return BitConverter.ToUInt16(Data, Trainer1 + 0x12); } + set { BitConverter.GetBytes(value).CopyTo(Data, Trainer1 + 0x12); } + } + public uint Money + { + get { return BitConverter.ToUInt32(Data, Trainer1 + 0x14); } + set { BitConverter.GetBytes(value).CopyTo(Data, Trainer1 + 0x14); } + } + public override int Gender + { + get { return Data[Trainer1 + 0x18]; } + set { Data[Trainer1 + 0x18] = (byte)value; } + } + public override int Language + { + get { return Data[Trainer1 + 0x19]; } + set { Data[Trainer1 + 0x19] = (byte)value; } + } + public int Badges + { + get { return Data[Trainer1 + 0x1A]; } + set { if (value < 0) return; Data[Trainer1 + 0x1A] = (byte)value; } + } + public int Sprite + { + get { return Data[Trainer1 + 0x1B]; } + set { if (value < 0) return; Data[Trainer1 + 0x1B] = (byte)value; } + } + public int Badges16 + { + get + { + if (Version != GameVersion.HGSS) + return -1; + return Data[Trainer1 + 0x1F]; + } + set + { + if (value < 0) + return; + if (Version != GameVersion.HGSS) + return; + Data[Trainer1 + 0x1F] = (byte)value; + } + } + public int PlayedHours + { + get { return BitConverter.ToUInt16(Data, Trainer1 + 0x22); } + set { BitConverter.GetBytes((ushort)value).CopyTo(Data, Trainer1 + 0x22); } + } + public int PlayedMinutes + { + get { return Data[Trainer1 + 0x24]; } + set { Data[Trainer1 + 0x24] = (byte)value; } + } + public int PlayedSeconds + { + get { return Data[Trainer1 + 0x25]; } + set { Data[Trainer1 + 0x25] = (byte)value; } + } + public int M + { + get + { + int ofs = 0; + switch (Version) + { + case GameVersion.DP: + case GameVersion.HGSS: ofs = 0x1234; break; + case GameVersion.Pt: ofs = 0x1280; break; + } + return BitConverter.ToInt32(Data, ofs); + } + set + { + int ofs = 0; + switch (Version) + { + case GameVersion.DP: + case GameVersion.HGSS: ofs = 0x1234; break; + case GameVersion.Pt: ofs = 0x1280; break; + } + BitConverter.GetBytes(value).CopyTo(Data, ofs); + } + } + public int X + { + get + { + int ofs = 0; + switch (Version) + { + case GameVersion.DP: ofs = 0x25FA; break; + case GameVersion.Pt: ofs = 0x287E; break; + case GameVersion.HGSS: ofs = 0x236E; break; + } + return BitConverter.ToInt32(Data, ofs); + } + set + { + int ofs = 0; + switch (Version) + { + case GameVersion.DP: ofs = 0x25FA; break; + case GameVersion.Pt: ofs = 0x287E; break; + case GameVersion.HGSS: ofs = 0x236E; break; + } + BitConverter.GetBytes(value).CopyTo(Data, ofs); + switch (Version) + { + case GameVersion.DP: + case GameVersion.HGSS: + BitConverter.GetBytes(value).CopyTo(Data, 0x123C); + break; + } + } + } + public int Z + { + get + { + int ofs = 0; + switch (Version) + { + case GameVersion.DP: ofs = 0x2602; break; + case GameVersion.Pt: ofs = 0x2886; break; + case GameVersion.HGSS: ofs = 0x2376; break; + } + return BitConverter.ToInt32(Data, ofs); + } + set + { + int ofs = 0; + switch (Version) + { + case GameVersion.DP: ofs = 0x2602; break; + case GameVersion.Pt: ofs = 0x2886; break; + case GameVersion.HGSS: ofs = 0x2376; break; + } + BitConverter.GetBytes(value).CopyTo(Data, ofs); + } + } + public int Y + { + get + { + int ofs = 0; + switch (Version) + { + case GameVersion.DP: ofs = 0x25FE; break; + case GameVersion.Pt: ofs = 0x2882; break; + case GameVersion.HGSS: ofs = 0x2372; break; + } + return BitConverter.ToInt32(Data, ofs); + } + set + { + int ofs = 0; + switch (Version) + { + case GameVersion.DP: ofs = 0x25FE; break; + case GameVersion.Pt: ofs = 0x2882; break; + case GameVersion.HGSS: ofs = 0x2372; break; + } + BitConverter.GetBytes(value).CopyTo(Data, ofs); + switch (Version) + { + case GameVersion.DP: + case GameVersion.HGSS: + BitConverter.GetBytes(value).CopyTo(Data, 0x1240); + break; + } + } + } + public int SecondsToStart { get { return BitConverter.ToInt32(Data, AdventureInfo + 0x34); } set { BitConverter.GetBytes(value).CopyTo(Data, AdventureInfo + 0x34); } } + public int SecondsToFame { get { return BitConverter.ToInt32(Data, AdventureInfo + 0x3C); } set { BitConverter.GetBytes(value).CopyTo(Data, AdventureInfo + 0x3C); } } + + // Storage + public int UnlockedBoxes + { + get { return Data[Box - 4]; } + set { Data[Box - 4] = (byte)value; } + } + public override int getBoxWallpaper(int box) + { + // Box Wallpaper is directly after the Box Names + int offset = getBoxOffset(BoxCount); + if (Version == GameVersion.HGSS) offset += 0x18; + offset += BoxCount*0x28; + return Data[offset]; + } + public override string getBoxName(int box) + { + int offset = getBoxOffset(BoxCount); + if (Version == GameVersion.HGSS) offset += 0x8; + return PKX.array2strG4(Data.Skip(offset + box*0x28).Take(0x28).ToArray()); + } + public override void setBoxName(int box, string value) + { + if (value.Length > 13) + value = value.Substring(0, 13); // Hard cap + int offset = getBoxOffset(BoxCount); + if (Version == GameVersion.HGSS) offset += 0x8; + PKX.str2arrayG4(value).CopyTo(Data, offset + box*0x28); + } + public override PKM getPKM(byte[] data) + { + return new PK4(data); + } + public override byte[] decryptPKM(byte[] data) + { + return PKX.decryptArray45(data); + } + + // Daycare + public override int DaycareSeedSize => 8; + public override int getDaycareSlotOffset(int loc, int slot) + { + return Daycare + slot * SIZE_PARTY; + } + public override ulong? getDaycareRNGSeed(int loc) + { + return null; + } + public override uint? getDaycareEXP(int loc, int slot) + { + int ofs = Daycare + (slot+1)*SIZE_PARTY - 4; + return BitConverter.ToUInt32(Data, ofs); + } + public override bool? getDaycareOccupied(int loc, int slot) + { + return null; + } + public override void setDaycareEXP(int loc, int slot, uint EXP) + { + int ofs = Daycare + (slot+1)*SIZE_PARTY - 4; + BitConverter.GetBytes(EXP).CopyTo(Data, ofs); + } + public override void setDaycareOccupied(int loc, int slot, bool occupied) + { + + } + + // Mystery Gift + public override MysteryGiftAlbum GiftAlbum + { + get + { + return new MysteryGiftAlbum + { + Flags = MysteryGiftReceivedFlags, + Gifts = MysteryGiftCards, + }; + } + set + { + MysteryGiftReceivedFlags = value.Flags; + MysteryGiftCards = value.Gifts; + } + } + protected override bool[] MysteryGiftReceivedFlags + { + get + { + if (WondercardData < 0 || WondercardFlags < 0) + return null; + + bool[] r = new bool[GiftFlagMax]; + for (int i = 0; i < r.Length; i++) + r[i] = (Data[WondercardFlags + (i >> 3)] >> (i & 7) & 0x1) == 1; + return r; + } + set + { + if (WondercardData < 0 || WondercardFlags < 0) + return; + if (GiftFlagMax != value?.Length) + return; + + byte[] data = new byte[value.Length / 8]; + for (int i = 0; i < value.Length; i++) + if (value[i]) + data[i >> 3] |= (byte)(1 << (i & 7)); + + data.CopyTo(Data, WondercardFlags); + Edited = true; + } + } + protected override MysteryGift[] MysteryGiftCards + { + get + { + MysteryGift[] cards = new MysteryGift[8 + 3]; + for (int i = 0; i < 8; i++) // 8 PGT + cards[i] = new PGT(Data.Skip(WondercardData + i * PGT.Size).Take(PGT.Size).ToArray()); + for (int i = 8; i < 11; i++) // 3 PCD + cards[i] = new PCD(Data.Skip(WondercardData + 8 * PGT.Size+ (i-8) * PCD.Size).Take(PCD.Size).ToArray()); + return cards; + } + set + { + if (value == null) + return; + for (int i = 0; i < 8; i++) // 8 PGT + { + if (value[i].GetType() != typeof(PGT)) + continue; + value[i].Data.CopyTo(Data, WondercardData + i * PGT.Size); + } + for (int i = 8; i < 11; i++) // 3 PCD + { + if (value[i].GetType() != typeof(PCD)) + continue; + value[i].Data.CopyTo(Data, WondercardData + 8 * PGT.Size + (i-8) * PGT.Size); + } + } + } + } +} diff --git a/Saves/SAV5.cs b/Saves/SAV5.cs new file mode 100644 index 000000000..b9c031a5d --- /dev/null +++ b/Saves/SAV5.cs @@ -0,0 +1,599 @@ +using System; +using System.Linq; +using System.Text; + +namespace PKHeX +{ + public sealed class SAV5 : SaveFile + { + // Save Data Attributes + public override string BAKName => $"{FileName} [{OT} ({Version})" +/* - {LastSavedTime}*/ "].bak"; + public SAV5(byte[] data = null) + { + Data = data == null ? new byte[SaveUtil.SIZE_G5RAW] : (byte[])data.Clone(); + BAK = (byte[])Data.Clone(); + Exportable = !Data.SequenceEqual(new byte[Data.Length]); + + // Get Version + SaveVersion = SaveUtil.getIsG5SAV(Data); + if (SaveVersion < 0) // Invalidate Data + Data = null; + + // First blocks are always the same position/size + PCLayout = 0x0; + Box = 0x400; + Party = 0x18E00; + Trainer1 = 0x19400; + WondercardData = 0x1C800; + AdventureInfo = 0x1D900; + + // Different Offsets for later blocks + switch (SaveVersion) + { + case 0: // BW + BattleBox = 0x20A00; + Trainer2 = 0x21200; + Daycare = 0x20E00; + + // Inventory offsets are the same for each game. + OFS_PouchHeldItem = 0x18400; // 0x188D7 + OFS_PouchKeyItem = 0x188D8; // 0x18A23 + OFS_PouchTMHM = 0x18A24; // 0x18BD7 + OFS_PouchMedicine = 0x18BD8; // 0x18C97 + OFS_PouchBerry = 0x18C98; // 0x18DBF + LegalItems = Legal.Pouch_Items_BW; + LegalKeyItems = Legal.Pouch_Key_BW; + LegalTMHMs = Legal.Pouch_TMHM_BW; + LegalMedicine = Legal.Pouch_Medicine_BW; + LegalBerries = Legal.Pouch_Berries_BW; + break; + case 1: // B2W2 + BattleBox = 0x20900; + Trainer2 = 0x21100; + EventConst = 0x1FF00; + EventFlag = EventConst + 0x35E; + Daycare = 0x20D00; + + // Inventory offsets are the same for each game. + OFS_PouchHeldItem = 0x18400; // 0x188D7 + OFS_PouchKeyItem = 0x188D8; // 0x18A23 + OFS_PouchTMHM = 0x18A24; // 0x18BD7 + OFS_PouchMedicine = 0x18BD8; // 0x18C97 + OFS_PouchBerry = 0x18C98; // 0x18DBF + LegalItems = Legal.Pouch_Items_BW; + LegalKeyItems = Legal.Pouch_Key_B2W2; + LegalTMHMs = Legal.Pouch_TMHM_BW; + LegalMedicine = Legal.Pouch_Medicine_BW; + LegalBerries = Legal.Pouch_Berries_BW; + break; + } + HeldItems = Legal.HeldItems_BW; + + getBlockInfo(); + + if (!Exportable) + resetBoxes(); + } + + // Configuration + private int SaveVersion { get; set; } + public override byte[] BAK { get; } + public override bool Exportable { get; } + public override SaveFile Clone() { return new SAV5(Data); } + + public override int SIZE_STORED => PKX.SIZE_5STORED; + public override int SIZE_PARTY => PKX.SIZE_5PARTY; + public override PKM BlankPKM => new PK5(); + protected override Type PKMType => typeof(PK5); + + public override int BoxCount => 24; + public override int MaxEV => 255; + public override int Generation => 5; + public override int OTLength => 8; + public override int NickLength => 10; + protected override int EventConstMax => 0x35E/2; + protected override int GiftCountMax => 12; + + // Blocks & Offsets + private BlockInfo[] Blocks; + private void getBlockInfo() + { + // Can be slick with just a list of block lengths, but oh well, precomputed. + if (SaveVersion == 0) // BW + { + Blocks = new[] + { + new BlockInfo(0x00000, 0x03E0, 0x003E2, 0x23F00), // Box Names + new BlockInfo(0x00400, 0x0FF0, 0x013F2, 0x23F02), // Box 1 + new BlockInfo(0x01400, 0x0FF0, 0x023F2, 0x23F04), // Box 2 + new BlockInfo(0x02400, 0x0FF0, 0x033F2, 0x23F06), // Box 3 + new BlockInfo(0x03400, 0x0FF0, 0x043F2, 0x23F08), // Box 4 + new BlockInfo(0x04400, 0x0FF0, 0x053F2, 0x23F0A), // Box 5 + new BlockInfo(0x05400, 0x0FF0, 0x063F2, 0x23F0C), // Box 6 + new BlockInfo(0x06400, 0x0FF0, 0x073F2, 0x23F0E), // Box 7 + new BlockInfo(0x07400, 0x0FF0, 0x083F2, 0x23F10), // Box 8 + new BlockInfo(0x08400, 0x0FF0, 0x093F2, 0x23F12), // Box 9 + new BlockInfo(0x09400, 0x0FF0, 0x0A3F2, 0x23F14), // Box 10 + new BlockInfo(0x0A400, 0x0FF0, 0x0B3F2, 0x23F16), // Box 11 + new BlockInfo(0x0B400, 0x0FF0, 0x0C3F2, 0x23F18), // Box 12 + new BlockInfo(0x0C400, 0x0FF0, 0x0D3F2, 0x23F1A), // Box 13 + new BlockInfo(0x0D400, 0x0FF0, 0x0E3F2, 0x23F1C), // Box 14 + new BlockInfo(0x0E400, 0x0FF0, 0x0F3F2, 0x23F1E), // Box 15 + new BlockInfo(0x0F400, 0x0FF0, 0x103F2, 0x23F20), // Box 16 + new BlockInfo(0x10400, 0x0FF0, 0x113F2, 0x23F22), // Box 17 + new BlockInfo(0x11400, 0x0FF0, 0x123F2, 0x23F24), // Box 18 + new BlockInfo(0x12400, 0x0FF0, 0x133F2, 0x23F26), // Box 19 + new BlockInfo(0x13400, 0x0FF0, 0x143F2, 0x23F28), // Box 20 + new BlockInfo(0x14400, 0x0FF0, 0x153F2, 0x23F2A), // Box 21 + new BlockInfo(0x15400, 0x0FF0, 0x163F2, 0x23F2C), // Box 22 + new BlockInfo(0x16400, 0x0FF0, 0x173F2, 0x23F2E), // Box 23 + new BlockInfo(0x17400, 0x0FF0, 0x183F2, 0x23F30), // Box 24 + new BlockInfo(0x18400, 0x09C0, 0x18DC2, 0x23F32), // Inventory + new BlockInfo(0x18E00, 0x0534, 0x19336, 0x23F34), // Party Pokemon + new BlockInfo(0x19400, 0x0068, 0x1946A, 0x23F36), // Trainer Data + new BlockInfo(0x19500, 0x009C, 0x1959E, 0x23F38), // ??? + new BlockInfo(0x19600, 0x1338, 0x1A93A, 0x23F3A), // ??? + new BlockInfo(0x1AA00, 0x07C4, 0x1B1C6, 0x23F3C), // ??? + new BlockInfo(0x1B200, 0x0D54, 0x1BF56, 0x23F3E), // ??? + new BlockInfo(0x1C000, 0x002C, 0x1C02E, 0x23F40), // ??? + new BlockInfo(0x1C100, 0x0658, 0x1C75A, 0x23F42), // ??? Gym badge data + new BlockInfo(0x1C800, 0x0A94, 0x1D296, 0x23F44), // ??? + new BlockInfo(0x1D300, 0x01AC, 0x1D4AE, 0x23F46), // ??? + new BlockInfo(0x1D500, 0x03EC, 0x1D8EE, 0x23F48), // ??? + new BlockInfo(0x1D900, 0x005C, 0x1D95E, 0x23F4A), // Adventure Info + new BlockInfo(0x1DA00, 0x01E0, 0x1DBE2, 0x23F4C), // ??? + new BlockInfo(0x1DC00, 0x00A8, 0x1DCAA, 0x23F4E), // ??? + new BlockInfo(0x1DD00, 0x0460, 0x1E162, 0x23F50), // ??? + new BlockInfo(0x1E200, 0x1400, 0x1F602, 0x23F52), // ??? + new BlockInfo(0x1F700, 0x02A4, 0x1F9A6, 0x23F54), // ??? + new BlockInfo(0x1FA00, 0x02DC, 0x1FCDE, 0x23F56), // ??? + new BlockInfo(0x1FD00, 0x034C, 0x2004E, 0x23F58), // ??? + new BlockInfo(0x20100, 0x03EC, 0x204EE, 0x23F5A), // ??? + new BlockInfo(0x20500, 0x00F8, 0x205FA, 0x23F5C), // ??? + new BlockInfo(0x20600, 0x02FC, 0x208FE, 0x23F5E), // ??? + new BlockInfo(0x20900, 0x0094, 0x20996, 0x23F60), // ??? + new BlockInfo(0x20A00, 0x035C, 0x20D5E, 0x23F62), // ??? + new BlockInfo(0x20E00, 0x01CC, 0x20FCE, 0x23F64), // ??? + new BlockInfo(0x21000, 0x0168, 0x2116A, 0x23F66), // ??? + new BlockInfo(0x21200, 0x00EC, 0x212EE, 0x23F68), // ??? + new BlockInfo(0x21300, 0x01B0, 0x214B2, 0x23F6A), // ??? + new BlockInfo(0x21500, 0x001C, 0x2151E, 0x23F6C), // ??? + new BlockInfo(0x21600, 0x04D4, 0x21AD6, 0x23F6E), // ??? + new BlockInfo(0x21B00, 0x0034, 0x21B36, 0x23F70), // ??? + new BlockInfo(0x21C00, 0x003C, 0x21C3E, 0x23F72), // ??? + new BlockInfo(0x21D00, 0x01AC, 0x21EAE, 0x23F74), // ??? + new BlockInfo(0x21F00, 0x0B90, 0x22A92, 0x23F76), // ??? + new BlockInfo(0x22B00, 0x009C, 0x22B9E, 0x23F78), // ??? + new BlockInfo(0x22C00, 0x0850, 0x23452, 0x23F7A), // Entralink Forest pokémon data + new BlockInfo(0x23500, 0x0028, 0x2352A, 0x23F7C), // ??? + new BlockInfo(0x23600, 0x0284, 0x23886, 0x23F7E), // ??? + new BlockInfo(0x23900, 0x0010, 0x23912, 0x23F80), // ??? + new BlockInfo(0x23A00, 0x005C, 0x23A5E, 0x23F82), // ??? + new BlockInfo(0x23B00, 0x016C, 0x23C6E, 0x23F84), // ??? + new BlockInfo(0x23D00, 0x0040, 0x23D42, 0x23F86), // ??? + new BlockInfo(0x23E00, 0x00FC, 0x23EFE, 0x23F88), // ??? + new BlockInfo(0x23F00, 0x008C, 0x23F9A, 0x23F9A), // Checksums */ + }; + } + else if (SaveVersion == 1) // B2W2 + { + Blocks = new[] + { + // Offset, Length, CHKOfst, ChkMirror + new BlockInfo(0x00000, 0x03e0, 0x003E2, 0x25F00), // Box Names + new BlockInfo(0x00400, 0x0ff0, 0x013F2, 0x25F02), // Box 1 + new BlockInfo(0x01400, 0x0ff0, 0x023F2, 0x25F04), // Box 2 + new BlockInfo(0x02400, 0x0ff0, 0x033F2, 0x25F06), // Box 3 + new BlockInfo(0x03400, 0x0ff0, 0x043F2, 0x25F08), // Box 4 + new BlockInfo(0x04400, 0x0ff0, 0x053F2, 0x25F0A), // Box 5 + new BlockInfo(0x05400, 0x0ff0, 0x063F2, 0x25F0C), // Box 6 + new BlockInfo(0x06400, 0x0ff0, 0x073F2, 0x25F0E), // Box 7 + new BlockInfo(0x07400, 0x0ff0, 0x083F2, 0x25F10), // Box 8 + new BlockInfo(0x08400, 0x0ff0, 0x093F2, 0x25F12), // Box 9 + new BlockInfo(0x09400, 0x0ff0, 0x0A3F2, 0x25F14), // Box 10 + new BlockInfo(0x0A400, 0x0ff0, 0x0B3F2, 0x25F16), // Box 11 + new BlockInfo(0x0B400, 0x0ff0, 0x0C3F2, 0x25F18), // Box 12 + new BlockInfo(0x0C400, 0x0ff0, 0x0D3F2, 0x25F1A), // Box 13 + new BlockInfo(0x0D400, 0x0ff0, 0x0E3F2, 0x25F1C), // Box 14 + new BlockInfo(0x0E400, 0x0ff0, 0x0F3F2, 0x25F1E), // Box 15 + new BlockInfo(0x0F400, 0x0ff0, 0x103F2, 0x25F20), // Box 16 + new BlockInfo(0x10400, 0x0ff0, 0x113F2, 0x25F22), // Box 17 + new BlockInfo(0x11400, 0x0ff0, 0x123F2, 0x25F24), // Box 18 + new BlockInfo(0x12400, 0x0ff0, 0x133F2, 0x25F26), // Box 19 + new BlockInfo(0x13400, 0x0ff0, 0x143F2, 0x25F28), // Box 20 + new BlockInfo(0x14400, 0x0ff0, 0x153F2, 0x25F2A), // Box 21 + new BlockInfo(0x15400, 0x0ff0, 0x163F2, 0x25F2C), // Box 22 + new BlockInfo(0x16400, 0x0ff0, 0x173F2, 0x25F2E), // Box 23 + new BlockInfo(0x17400, 0x0ff0, 0x183F2, 0x25F30), // Box 24 + new BlockInfo(0x18400, 0x09ec, 0x18DEE, 0x25F32), // Inventory + new BlockInfo(0x18E00, 0x0534, 0x19336, 0x25F34), // Party Pokemon + new BlockInfo(0x19400, 0x00b0, 0x194B2, 0x25F36), // Trainer Data + new BlockInfo(0x19500, 0x00a8, 0x195AA, 0x25F38), // Trainer Position + new BlockInfo(0x19600, 0x1338, 0x1A93A, 0x25F3A), // Unity Tower and survey stuff + new BlockInfo(0x1AA00, 0x07c4, 0x1B1C6, 0x25F3C), // Pal Pad Player Data (30d) + new BlockInfo(0x1B200, 0x0d54, 0x1BF56, 0x25F3E), // Pal Pad Friend Data + new BlockInfo(0x1C000, 0x0094, 0x1C096, 0x25F40), // C-Gear + new BlockInfo(0x1C100, 0x0658, 0x1C75A, 0x25F42), // Card Signature Block & ???? + new BlockInfo(0x1C800, 0x0a94, 0x1D296, 0x25F44), // Mystery Gift + new BlockInfo(0x1D300, 0x01ac, 0x1D4AE, 0x25F46), // Dream World Stuff (Catalog) + new BlockInfo(0x1D500, 0x03ec, 0x1D8EE, 0x25F48), // Chatter + new BlockInfo(0x1D900, 0x005c, 0x1D95E, 0x25F4A), // Adventure data + new BlockInfo(0x1DA00, 0x01e0, 0x1DBE2, 0x25F4C), // Trainer Card Records + new BlockInfo(0x1DC00, 0x00a8, 0x1DCAA, 0x25F4E), // ??? + new BlockInfo(0x1DD00, 0x0460, 0x1E162, 0x25F50), // (40d) + new BlockInfo(0x1E200, 0x1400, 0x1F602, 0x25F52), // ??? + new BlockInfo(0x1F700, 0x02a4, 0x1F9A6, 0x25F54), // Contains flags and references for downloaded data (Musical) + new BlockInfo(0x1FA00, 0x00e0, 0x1FAE2, 0x25F56), // Fused Reshiram/Zekrom Storage + new BlockInfo(0x1FB00, 0x034c, 0x1FE4E, 0x25F58), // ??? + new BlockInfo(0x1FF00, 0x04e0, 0x203E2, 0x25F5A), // Const Data Block and Event Flag Block (0x35E is the split) + new BlockInfo(0x20400, 0x00f8, 0x204FA, 0x25F5C), // ??? + new BlockInfo(0x20500, 0x02fc, 0x207FE, 0x25F5E), // Tournament Block + new BlockInfo(0x20800, 0x0094, 0x20896, 0x25F60), // ??? + new BlockInfo(0x20900, 0x035c, 0x20C5E, 0x25F62), // Battle Box Block + new BlockInfo(0x20D00, 0x01d4, 0x20ED6, 0x25F64), // Daycare Block (50d) + new BlockInfo(0x20F00, 0x01e0, 0x201E2, 0x25F66), // Strength Boulder Status Block + new BlockInfo(0x21100, 0x00f0, 0x211F2, 0x25F68), // Badge Flags, Money, Trainer Sayings + new BlockInfo(0x21200, 0x01b4, 0x213B6, 0x25F6A), // Entralink (Level & Powers etc) + new BlockInfo(0x21400, 0x04dc, 0x218DE, 0x25F6C), // Pokedex + new BlockInfo(0x21900, 0x0034, 0x21936, 0x25F6E), // Swarm and other overworld info - 2C - swarm, 2D - repel steps, 2E repel type + new BlockInfo(0x21A00, 0x003c, 0x21A3E, 0x25F70), // ??? + new BlockInfo(0x21B00, 0x01ac, 0x21CAE, 0x25F72), // ??? + new BlockInfo(0x21D00, 0x0b90, 0x22892, 0x25F74), // ??? + new BlockInfo(0x22900, 0x00ac, 0x229AE, 0x25F76), // Online Records + new BlockInfo(0x22A00, 0x0850, 0x23252, 0x25F78), // Area NPC data - encrypted (60d) + new BlockInfo(0x23300, 0x0284, 0x23586, 0x25F7A), // ??? + new BlockInfo(0x23600, 0x0010, 0x23612, 0x25F7C), // ??? + new BlockInfo(0x23700, 0x00a8, 0x237AA, 0x25F7E), // ??? + new BlockInfo(0x23800, 0x016c, 0x2396E, 0x25F80), // ??? + new BlockInfo(0x23A00, 0x0080, 0x23A82, 0x25F82), // ??? + new BlockInfo(0x23B00, 0x00fc, 0x23BFE, 0x25F84), // Hollow/Rival Block + new BlockInfo(0x23C00, 0x16a8, 0x252AA, 0x25F86), // Join Avenue Block + new BlockInfo(0x25300, 0x0498, 0x2579A, 0x25F88), // Medal data + new BlockInfo(0x25800, 0x0060, 0x25862, 0x25F8A), // Key-related data + new BlockInfo(0x25900, 0x00fc, 0x259FE, 0x25F8C), // (70d) + new BlockInfo(0x25A00, 0x03e4, 0x25DE6, 0x25F8E), // ??? + new BlockInfo(0x25E00, 0x00f0, 0x25EF2, 0x25F90), // ??? + new BlockInfo(0x25F00, 0x0094, 0x25FA2, 0x25FA2), // Checksum Block (73d) + }; + } + else + { + Blocks = new BlockInfo[] { }; + } + } + protected override void setChecksums() + { + // Check for invalid block lengths + if (Blocks.Length < 3) // arbitrary... + { + Console.WriteLine("Not enough blocks ({0}), aborting setChecksums", Blocks.Length); + return; + } + // Apply checksums + foreach (BlockInfo b in Blocks) + { + byte[] array = Data.Skip(b.Offset).Take(b.Length).ToArray(); + ushort chk = SaveUtil.ccitt16(array); + BitConverter.GetBytes(chk).CopyTo(Data, b.ChecksumOffset); + BitConverter.GetBytes(chk).CopyTo(Data, b.ChecksumMirror); + } + } + public override bool ChecksumsValid + { + get + { + // Check for invalid block lengths + if (Blocks.Length < 3) // arbitrary... + { + Console.WriteLine("Not enough blocks ({0}), aborting setChecksums", Blocks.Length); + return false; + } + + foreach (BlockInfo b in Blocks) + { + byte[] array = Data.Skip(b.Offset).Take(b.Length).ToArray(); + ushort chk = SaveUtil.ccitt16(array); + if (chk != BitConverter.ToUInt16(Data, b.ChecksumOffset)) + return false; + if (chk != BitConverter.ToUInt16(Data, b.ChecksumMirror)) + return false; + } + return true; + } + } + public override string ChecksumInfo + { + get + { + // Check for invalid block lengths + if (Blocks.Length < 3) // arbitrary... + { + Console.WriteLine("Not enough blocks ({0}), aborting setChecksums", Blocks.Length); + return "Not a valid save to check."; + } + string r = ""; + int invalid = 0; + for (int i = 0; i < Blocks.Length; i++) + { + BlockInfo b = Blocks[i]; + byte[] array = Data.Skip(b.Offset).Take(b.Length).ToArray(); + ushort chk = SaveUtil.ccitt16(array); + if (chk != BitConverter.ToUInt16(Data, b.ChecksumOffset)) + { + r += $"Block {i} has been modified." + Environment.NewLine; + invalid++; + } + else if (chk != BitConverter.ToUInt16(Data, b.ChecksumMirror)) + { + r += $"Block {i} mirror does not match." + Environment.NewLine; + invalid++; + } + } + r += $"SAV: {Blocks.Length - invalid}/{Blocks.Length + Environment.NewLine}"; + return r; + } + } + + private const int wcSeed = 0x1D290; + + private readonly int Trainer2, AdventureInfo; + public override bool HasBoxWallpapers => false; + + // Daycare + public override int DaycareSeedSize => 16; + public override int getDaycareSlotOffset(int loc, int slot) + { + return Daycare + 4 + 0xE4 * slot; + } + public override ulong? getDaycareRNGSeed(int loc) + { + if (SaveVersion != 1) + return null; + return BitConverter.ToUInt64(Data, Daycare + 0x1CC); + } + public override uint? getDaycareEXP(int loc, int slot) + { + return BitConverter.ToUInt32(Data, Daycare + 4 + 0xDC + slot * 0xE4); + } + public override bool? getDaycareOccupied(int loc, int slot) + { + return BitConverter.ToUInt32(Data, Daycare + 0xE4*slot) == 1; + } + public override void setDaycareEXP(int loc, int slot, uint EXP) + { + if (SaveVersion != 1) + return; + BitConverter.GetBytes(EXP).CopyTo(Data, Daycare + 4 + 0xDC + slot * 0xE4); + } + public override void setDaycareOccupied(int loc, int slot, bool occupied) + { + BitConverter.GetBytes((uint)(occupied ? 1 : 0)).CopyTo(Data, Daycare + 0x1CC); + } + public override void setDaycareRNGSeed(int loc, ulong seed) + { + if (SaveVersion != 1) + return; + BitConverter.GetBytes(seed).CopyTo(Data, Daycare + 0x1CC); + } + + // Inventory + private readonly ushort[] LegalItems, LegalKeyItems, LegalTMHMs, LegalMedicine, LegalBerries; + public override InventoryPouch[] Inventory + { + get + { + InventoryPouch[] pouch = + { + new InventoryPouch(InventoryType.Items, LegalItems, 995, OFS_PouchHeldItem), + new InventoryPouch(InventoryType.KeyItems, LegalKeyItems, 1, OFS_PouchKeyItem), + new InventoryPouch(InventoryType.TMHMs, LegalTMHMs, 1, OFS_PouchTMHM), + new InventoryPouch(InventoryType.Medicine, LegalMedicine, 995, OFS_PouchMedicine), + new InventoryPouch(InventoryType.Berries, LegalBerries, 995, OFS_PouchBerry), + }; + foreach (var p in pouch) + p.getPouch(ref Data); + return pouch; + } + set + { + foreach (var p in value) + p.setPouch(ref Data); + } + } + + // Storage + public override int PartyCount + { + get { return Data[Party]; } + protected set { Data[Party] = (byte)value; } + } + public override int getBoxOffset(int box) + { + return Box + SIZE_STORED * box * 30 + box * 0x10; + } + public override int getPartyOffset(int slot) + { + return Party + 8 + SIZE_PARTY*slot; + } + public override string getBoxName(int box) + { + if (box >= BoxCount) + return ""; + return PKX.TrimFromFFFF(Encoding.Unicode.GetString(Data, PCLayout + 0x28 * box + 4, 0x28)); + } + public override void setBoxName(int box, string val) + { + if (val.Length > 38) + return; + val += '\uFFFF'; + Encoding.Unicode.GetBytes(val.PadRight(0x14, '\0')).CopyTo(Data, PCLayout + 0x28 * box + 4); + Edited = true; + } + public override int getBoxWallpaper(int box) + { + return Data[PCLayout + 0x3C4 + box]; + } + public override int CurrentBox + { + get { return Data[PCLayout]; } + set { Data[PCLayout] = (byte)value; } + } + public override bool BattleBoxLocked // TODO + { + get { return false; } + set { } + } + public override PKM getPKM(byte[] data) + { + return new PK5(data); + } + public override byte[] decryptPKM(byte[] data) + { + return PKX.decryptArray45(data); + } + + // Mystery Gift + public override MysteryGiftAlbum GiftAlbum + { + get + { + uint seed = BitConverter.ToUInt32(Data, wcSeed); + MysteryGiftAlbum Info = new MysteryGiftAlbum { Seed = seed }; + byte[] wcData = Data.Skip(WondercardData).Take(0xA90).ToArray(); // Encrypted, Decrypt + for (int i = 0; i < wcData.Length; i += 2) + BitConverter.GetBytes((ushort)(BitConverter.ToUInt16(wcData, i) ^ PKX.LCRNG(ref seed) >> 16)).CopyTo(wcData, i); + + Info.Flags = new bool[GiftFlagMax]; + Info.Gifts = new MysteryGift[GiftCountMax]; + // 0x100 Bytes for Used Flags + for (int i = 0; i < GiftFlagMax; i++) + Info.Flags[i] = (wcData[i/8] >> i%8 & 0x1) == 1; + // 12 PGFs + for (int i = 0; i < Info.Gifts.Length; i++) + Info.Gifts[i] = new PGF(wcData.Skip(0x100 + i*PGF.Size).Take(PGF.Size).ToArray()); + + return Info; + } + set + { + byte[] wcData = new byte[0xA90]; + + // Toss back into byte[] + for (int i = 0; i < value.Flags.Length; i++) + if (value.Flags[i]) + wcData[i/8] |= (byte)(1 << (i & 7)); + for (int i = 0; i < value.Gifts.Length; i++) + value.Gifts[i].Data.CopyTo(wcData, 0x100 + i*PGF.Size); + + // Decrypted, Encrypt + uint seed = value.Seed; + for (int i = 0; i < wcData.Length; i += 2) + BitConverter.GetBytes((ushort)(BitConverter.ToUInt16(wcData, i) ^ PKX.LCRNG(ref seed) >> 16)).CopyTo(wcData, i); + + // Write Back + wcData.CopyTo(Data, WondercardData); + BitConverter.GetBytes(value.Seed).CopyTo(Data, wcSeed); + } + } + protected override bool[] MysteryGiftReceivedFlags { get { return null; } set { } } + protected override MysteryGift[] MysteryGiftCards { get { return new MysteryGift[0]; } set { } } + + // Trainer Info + protected override GameVersion Version + { + get + { + switch (Game) + { + case 20: return GameVersion.W; + case 21: return GameVersion.B; + case 22: return GameVersion.W2; + case 23: return GameVersion.B2; + } + return GameVersion.Unknown; + } + } + public override string OT + { + get { return PKX.TrimFromFFFF(Encoding.Unicode.GetString(Data, Trainer1 + 0x4, 16)); } + set + { + if (value.Length > 7) + value = value.Substring(0, 7); // Hard cap + Encoding.Unicode.GetBytes((value + '\uFFFF').PadRight(8, '\0')).CopyTo(Data, Trainer1 + 0x4); } + } + public override ushort TID + { + get { return BitConverter.ToUInt16(Data, Trainer1 + 0x14 + 0); } + set { BitConverter.GetBytes(value).CopyTo(Data, Trainer1 + 0x14 + 0); } + } + public override ushort SID + { + get { return BitConverter.ToUInt16(Data, Trainer1 + 0x14 + 2); } + set { BitConverter.GetBytes(value).CopyTo(Data, Trainer1 + 0x14 + 2); } + } + public uint Money + { + get { return BitConverter.ToUInt32(Data, Trainer2); } + set { BitConverter.GetBytes(value).CopyTo(Data, Trainer2); } + } + public override int Gender + { + get { return Data[Trainer1 + 0x21]; } + set { Data[Trainer1 + 0x21] = (byte)value; } + } + public override int Language + { + get { return Data[Trainer1 + 0x1E]; } + set { Data[Trainer1 + 0x1E] = (byte)value; } + } + public override int Game + { + get { return Data[Trainer1 + 0x1F]; } + set { Data[Trainer1 + 0x1F] = (byte)value; } + } + public int Badges + { + get { return Data[Trainer2 + 0x4]; } + set { Data[Trainer2 + 0x4] = (byte)value; } + } + public int M + { + get { return BitConverter.ToInt32(Data, Trainer1 + 0x180); } + set { BitConverter.GetBytes((ushort)value).CopyTo(Data, Trainer1 + 0x180); } + } + public int X + { + get { return BitConverter.ToInt32(Data, Trainer1 + 0x186); } + set { BitConverter.GetBytes(value * 18).CopyTo(Data, Trainer1 + 0x186); } + } + public int Z + { + get { return BitConverter.ToInt32(Data, Trainer1 + 0x18A); } + set { BitConverter.GetBytes(value).CopyTo(Data, Trainer1 + 0x18A); } + } + public int Y + { + get { return BitConverter.ToInt32(Data, Trainer1 + 0x18E); } + set { BitConverter.GetBytes(value * 18).CopyTo(Data, Trainer1 + 0x18E); } + } + + public int PlayedHours + { + get { return BitConverter.ToUInt16(Data, Trainer1 + 0x24); } + set { BitConverter.GetBytes((ushort)value).CopyTo(Data, Trainer1 + 0x24); } + } + public int PlayedMinutes + { + get { return Data[Trainer1 + 0x24 + 2]; } + set { Data[Trainer1 + 0x24 + 2] = (byte)value; } + } + public int PlayedSeconds + { + get { return Data[Trainer1 + 0x24 + 3]; } + set { Data[Trainer1 + 0x24 + 3] = (byte)value; } + } + public int SecondsToStart { get { return BitConverter.ToInt32(Data, AdventureInfo + 0x34); } set { BitConverter.GetBytes(value).CopyTo(Data, AdventureInfo + 0x34); } } + public int SecondsToFame { get { return BitConverter.ToInt32(Data, AdventureInfo + 0x3C); } set { BitConverter.GetBytes(value).CopyTo(Data, AdventureInfo + 0x3C); } } + } +} diff --git a/Misc/SAV6.cs b/Saves/SAV6.cs similarity index 56% rename from Misc/SAV6.cs rename to Saves/SAV6.cs index e1447b7f2..882a8e428 100644 --- a/Misc/SAV6.cs +++ b/Saves/SAV6.cs @@ -4,208 +4,262 @@ namespace PKHeX { - public class BlockInfo + public sealed class SAV6 : SaveFile { - public int Offset; - public int Length; - public ushort ID; - public ushort Checksum; - } - public enum GameVersion - { - X = 24, Y = 25, - AS = 26, OR = 27, - SN = 28, MN = 29, - Unknown = 0, - Any = -1, - } - public class SAV6 : PKX - { - internal const int SIZE_XY = 0x65600; - internal const int SIZE_ORAS = 0x76000; - internal const int SIZE_ORASDEMO = 0x5A00; - internal const int BEEF = 0x42454546; - internal static bool SizeValid(int size) - { - return new[] {SIZE_XY, SIZE_ORAS, SIZE_ORASDEMO}.Contains(size); - } - - // Global Settings - internal static bool SetUpdateDex = true; - internal static bool SetUpdatePK6 = true; // Save Data Attributes - public byte[] Data; - public bool Edited; - public readonly bool Exportable; - public readonly byte[] BAK; - public string FileName, FilePath; - public string BAKName => $"{FileName} [{OT} ({Version}) - {LastSavedTime}].bak"; + public override string BAKName => $"{FileName} [{OT} ({Version}) - {LastSavedTime}].bak"; public SAV6(byte[] data = null) { - Data = (byte[])(data ?? new byte[SIZE_ORAS]).Clone(); + Data = data == null ? new byte[SaveUtil.SIZE_G6ORAS] : (byte[])data.Clone(); BAK = (byte[])Data.Clone(); Exportable = !Data.SequenceEqual(new byte[Data.Length]); // Load Info getBlockInfo(); getSAVOffsets(); + + if (!Exportable) + resetBoxes(); + } + + // Configuration + public override byte[] BAK { get; } + public override bool Exportable { get; } + public override SaveFile Clone() { return new SAV6(Data); } + + public override int SIZE_STORED => PKX.SIZE_6STORED; + public override int SIZE_PARTY => PKX.SIZE_6PARTY; + public override PKM BlankPKM => new PK6(); + protected override Type PKMType => typeof(PK6); + + public override int BoxCount => 31; + public override int MaxEV => 252; + public override int Generation => 6; + protected override int GiftCountMax => 24; + protected override int GiftFlagMax => 0x100 * 8; + protected override int EventFlagMax => 8 * 0x180; + protected override int EventConstMax => (EventFlag - EventConst) / 2; + public override int OTLength => 12; + public override int NickLength => 12; + + // Feature Overrides + public override bool HasGeolocation => true; + + // Blocks & Offsets + private int BlockInfoOffset; + private BlockInfo[] Blocks; + private void getBlockInfo() + { + BlockInfoOffset = Data.Length - 0x200 + 0x10; + if (BitConverter.ToUInt32(Data, BlockInfoOffset) != SaveUtil.BEEF) + BlockInfoOffset -= 0x200; // No savegames have more than 0x3D blocks, maybe in the future? + int count = (Data.Length - BlockInfoOffset - 0x8) / 8; + BlockInfoOffset += 4; + + Blocks = new BlockInfo[count]; + int CurrentPosition = 0; + for (int i = 0; i < Blocks.Length; i++) + { + Blocks[i] = new BlockInfo + { + Offset = CurrentPosition, + Length = BitConverter.ToInt32(Data, BlockInfoOffset + 0 + 8 * i), + ID = BitConverter.ToUInt16(Data, BlockInfoOffset + 4 + 8 * i), + Checksum = BitConverter.ToUInt16(Data, BlockInfoOffset + 6 + 8 * i) + }; + + // Expand out to nearest 0x200 + CurrentPosition += Blocks[i].Length % 0x200 == 0 ? Blocks[i].Length : 0x200 - Blocks[i].Length % 0x200 + Blocks[i].Length; + + if ((Blocks[i].ID != 0) || i == 0) continue; + count = i; + break; + } + // Fix Final Array Lengths + Array.Resize(ref Blocks, count); + } + protected override void setChecksums() + { + // Check for invalid block lengths + if (Blocks.Length < 3) // arbitrary... + { + Console.WriteLine("Not enough blocks ({0}), aborting setChecksums", Blocks.Length); + return; + } + // Apply checksums + for (int i = 0; i < Blocks.Length; i++) + { + byte[] array = Data.Skip(Blocks[i].Offset).Take(Blocks[i].Length).ToArray(); + BitConverter.GetBytes(SaveUtil.ccitt16(array)).CopyTo(Data, BlockInfoOffset + 6 + i * 8); + } + } + public override bool ChecksumsValid => SaveUtil.verifyG6SAV(Data); + public override string ChecksumInfo => SaveUtil.verifyG6CHK(Data); + public ulong Secure1 + { + get { return BitConverter.ToUInt64(Data, BlockInfoOffset - 0x14); } + set { BitConverter.GetBytes(value).CopyTo(Data, BlockInfoOffset - 0x14); } + } + public ulong Secure2 + { + get { return BitConverter.ToUInt64(Data, BlockInfoOffset - 0xC); } + set { BitConverter.GetBytes(value).CopyTo(Data, BlockInfoOffset - 0xC); } } - public void getSAVOffsets() + private void getSAVOffsets() { if (ORASDEMO) { - /* 00: */ Item = 0x00000; Items = new Inventory(Item, 1); - /* 01: */ ItemInfo = 0x00C00; // Select Bound Items - /* 02: */ AdventureInfo = 0x00E00; - /* 03: */ Trainer1 = 0x01000; - /* 04: */ // = 0x01200; [00004] // ??? - /* 05: */ PlayTime = 0x01400; - /* 06: */ // = 0x01600; [00024] // FFFFFFFF - /* 07: */ // = 0x01800; [02100] // Overworld Data - /* 08: */ Trainer2 = 0x03A00; - /* 09: */ TrainerCard = 0x03C00; - /* 10: */ Party = 0x03E00; - /* 11: */ EventConst = 0x04600; EventAsh = EventConst + 0x78; EventFlag = EventConst + 0x2FC; - /* 12: */ // = 0x04C00; [00004] // 87B1A23F const - /* 13: */ // = 0x04E00; [00048] // Repel Info, (Swarm?) and other overworld info - /* 14: */ SUBE = 0x05000; - /* 15: */ PSSStats = 0x05400; + /* 00: */ Item = 0x00000; + /* 01: */ ItemInfo = 0x00C00; // Select Bound Items + /* 02: */ AdventureInfo = 0x00E00; + /* 03: */ Trainer1 = 0x01000; + /* 04: */ // = 0x01200; [00004] // ??? + /* 05: */ PlayTime = 0x01400; + /* 06: */ // = 0x01600; [00024] // FFFFFFFF + /* 07: */ // = 0x01800; [02100] // Overworld Data + /* 08: */ Trainer2 = 0x03A00; + /* 09: */ TrainerCard = 0x03C00; + /* 10: */ Party = 0x03E00; + /* 11: */ EventConst = 0x04600; EventFlag = EventConst + 0x2FC; + /* 12: */ // = 0x04C00; [00004] // 87B1A23F const + /* 13: */ // = 0x04E00; [00048] // Repel Info, (Swarm?) and other overworld info + /* 14: */ SUBE = 0x05000; + /* 15: */ PSSStats = 0x05400; - Box = BattleBox = GTS = Daycare = EonTicket = Fused = Puff = - SuperTrain = SecretBase = BoxWallpapers = - LastViewedBox = PCLayout = PCBackgrounds = PCFlags = WondercardFlags = WondercardData = - BerryField = OPower = Accessories = - PokeDex = PokeDexLanguageFlags = Spinda = EncounterCount = HoF = PSS = JPEG = Contest -1; - MaisonStats = -1; + OFS_PouchHeldItem = Item + 0; + OFS_PouchKeyItem = Item + 0x640; + OFS_PouchTMHM = Item + 0x7C0; + OFS_PouchMedicine = Item + 0x970; + OFS_PouchBerry = Item + 0xA70; } else if (XY) { - Box = 0x22600; - TrainerCard = 0x14000; - Party = 0x14200; - BattleBox = 0x04A00; - Daycare = 0x1B200; - GTS = 0x17800; - Fused = 0x16000; - SUBE = 0x1D890; Puff = 0x00000; Item = 0x00400; - Items = new Inventory(Item, 0); + ItemInfo = 0x1000; AdventureInfo = 0x01200; Trainer1 = 0x1400; - Trainer2 = 0x4200; - PCLayout = 0x4400; - PCBackgrounds = PCLayout + 0x41E; - PCFlags = PCLayout + 0x43D; - WondercardFlags = 0x1BC00; - WondercardData = WondercardFlags + 0x100; - BerryField = 0x1B800; - OPower = 0x16A00; - EventConst = 0x14A00; - EventAsh = -1; - EventFlag = EventConst + 0x2FC; - PokeDex = 0x15000; - PokeDexLanguageFlags = PokeDex + 0x3C8; - Spinda = PokeDex + 0x648; - EncounterCount = -1; - HoF = 0x19400; - SuperTrain = 0x1F200; - JPEG = 0x57200; - MaisonStats = 0x1B1C0; - PSS = 0x05000; - PSSStats = 0x1E400; - BoxWallpapers = 0x481E; - SecretBase = -1; - EonTicket = -1; - Contest = -1; PlayTime = 0x1800; Accessories = 0x1A00; + Trainer2 = 0x4200; + PCLayout = 0x4400; + BattleBox = 0x04A00; + PSS = 0x05000; + TrainerCard = 0x14000; + Party = 0x14200; + EventConst = 0x14A00; + PSSStats = 0x1E400; + PokeDex = 0x15000; + Fused = 0x16000; + OPower = 0x16A00; + GTS = 0x17800; + HoF = 0x19400; + MaisonStats = 0x1B1C0; + Daycare = 0x1B200; + BerryField = 0x1B800; + WondercardFlags = 0x1BC00; + SUBE = 0x1D890; + SuperTrain = 0x1F200; + Box = 0x22600; + JPEG = 0x57200; + + PCBackgrounds = PCLayout + 0x41E; + PCFlags = PCLayout + 0x43D; LastViewedBox = PCLayout + 0x43F; - ItemInfo = 0x1000; + EventFlag = EventConst + 0x2FC; + PokeDexLanguageFlags = PokeDex + 0x3C8; + Spinda = PokeDex + 0x648; + WondercardData = WondercardFlags + 0x100; + + OFS_PouchHeldItem = Item + 0; + OFS_PouchKeyItem = Item + 0x640; + OFS_PouchTMHM = Item + 0x7C0; + OFS_PouchMedicine = Item + 0x968; + OFS_PouchBerry = Item + 0xA68; } else if (ORAS) { - Box = 0x33000; // Confirmed - TrainerCard = 0x14000; // Confirmed - Party = 0x14200; // Confirmed - BattleBox = 0x04A00; // Confirmed - Daycare = 0x1BC00; // Confirmed (thanks Rei) - GTS = 0x18200; // Confirmed - Fused = 0x16A00; // Confirmed - SUBE = 0x1D890; // ****not in use, not updating?**** - Puff = 0x00000; // Confirmed - Item = 0x00400; // Confirmed - Items = new Inventory(Item, 1); + Puff = 0x00000; + Item = 0x00400; + ItemInfo = 0x1000; AdventureInfo = 0x01200; - Trainer1 = 0x01400; // Confirmed - Trainer2 = 0x04200; // Confirmed - PCLayout = 0x04400; // Confirmed - PCBackgrounds = PCLayout + 0x41E; - PCFlags = PCLayout + 0x43D; - WondercardFlags = 0x1CC00; // Confirmed - WondercardData = WondercardFlags + 0x100; - BerryField = 0x1C400; // ****changed**** - OPower = 0x17400; // ****changed**** - EventConst = 0x14A00; - EventAsh = EventConst + 0x78; - EventFlag = EventConst + 0x2FC; - PokeDex = 0x15000; - Spinda = PokeDex + 0x680; - EncounterCount = PokeDex + 0x686; - PokeDexLanguageFlags = PokeDex + 0x400; - HoF = 0x19E00; // Confirmed - SuperTrain = 0x20200; - Contest = 0x23600; // Confirmed - JPEG = 0x67C00; // Confirmed - MaisonStats = 0x1BBC0; - PSS = 0x05000; // Confirmed (thanks Rei) - PSSStats = 0x1F400; - BoxWallpapers = 0x481E; - SecretBase = 0x23A00; - EonTicket = 0x319B8; + Trainer1 = 0x01400; PlayTime = 0x1800; Accessories = 0x1A00; - LastViewedBox = PCLayout + 0x43F; - ItemInfo = 0x1000; - } - DaycareSlot = new[] { Daycare, Daycare + 0x1F0 }; - } - public class Inventory - { - public readonly int HeldItem, KeyItem, Medicine, TMHM, Berry; - public Inventory(int Offset, int Game) - { - switch (Game) - { - case 0: - HeldItem = Offset + 0; - KeyItem = Offset + 0x640; - TMHM = Offset + 0x7C0; - Medicine = Offset + 0x968; - Berry = Offset + 0xA68; - break; - case 1: - HeldItem = Offset + 0; - KeyItem = Offset + 0x640; - TMHM = Offset + 0x7C0; - Medicine = Offset + 0x970; - Berry = Offset + 0xA70; - break; - } - } - } - public Inventory Items = new Inventory(0, -1); - public int BattleBox, GTS, Daycare, EonTicket, - Fused, SUBE, Puff, Item, AdventureInfo, Trainer1, Trainer2, SuperTrain, PSSStats, MaisonStats, SecretBase, BoxWallpapers, LastViewedBox, - PCLayout, PCBackgrounds, PCFlags, WondercardFlags, WondercardData, BerryField, OPower, EventConst, EventFlag, EventAsh, PlayTime, Accessories, - PokeDex, PokeDexLanguageFlags, Spinda, EncounterCount, HoF, PSS, JPEG, Contest, ItemInfo; - public int TrainerCard = 0x14000; - public int Box = 0x33000, Party = 0x14200; - public int[] DaycareSlot; - public int DaycareIndex = 0; + Trainer2 = 0x04200; + PCLayout = 0x04400; + BattleBox = 0x04A00; + PSS = 0x05000; + TrainerCard = 0x14000; + Party = 0x14200; + EventConst = 0x14A00; + PokeDex = 0x15000; + Fused = 0x16A00; + OPower = 0x17400; + GTS = 0x18200; + HoF = 0x19E00; + MaisonStats = 0x1BBC0; + Daycare = 0x1BC00; + BerryField = 0x1C400; + WondercardFlags = 0x1CC00; + SUBE = 0x1D890; + PSSStats = 0x1F400; + SuperTrain = 0x20200; + Contest = 0x23600; + SecretBase = 0x23A00; + EonTicket = 0x319B8; + Box = 0x33000; + JPEG = 0x67C00; - public GameVersion Version + PCBackgrounds = PCLayout + 0x41E; + PCFlags = PCLayout + 0x43D; + LastViewedBox = PCLayout + 0x43F; + EventFlag = EventConst + 0x2FC; + PokeDexLanguageFlags = PokeDex + 0x400; + Spinda = PokeDex + 0x680; + EncounterCount = PokeDex + 0x686; + WondercardData = WondercardFlags + 0x100; + Daycare2 = Daycare + 0x1F0; + + OFS_PouchHeldItem = Item + 0; + OFS_PouchKeyItem = Item + 0x640; + OFS_PouchTMHM = Item + 0x7C0; + OFS_PouchMedicine = Item + 0x970; + OFS_PouchBerry = Item + 0xA70; + } + else // Empty input + { + Party = 0x0; + Box = Party + SIZE_PARTY * 6 + 0x1000; + } + } + + // Private Only + private int Item { get; set; } = int.MinValue; + private int AdventureInfo { get; set; } = int.MinValue; + private int Trainer2 { get; set; } = int.MinValue; + private int LastViewedBox { get; set; } = int.MinValue; + private int WondercardFlags { get; set; } = int.MinValue; + private int PlayTime { get; set; } = int.MinValue; + private int JPEG { get; set; } = int.MinValue; + private int ItemInfo { get; set; } = int.MinValue; + private int Daycare2 { get; set; } = int.MinValue; + + // Accessible as SAV6 + public int TrainerCard { get; private set; } = 0x14000; + public int PCFlags { get; private set; } = int.MinValue; + public int PSSStats { get; private set; } = int.MinValue; + public int MaisonStats { get; private set; } = int.MinValue; + public int EonTicket { get; private set; } = int.MinValue; + public int PCBackgrounds { get; private set; } = int.MinValue; + public int Contest { get; private set; } = int.MinValue; + public int Accessories { get; private set; } = int.MinValue; + public int PokeDexLanguageFlags { get; private set; } = int.MinValue; + public int Spinda { get; private set; } = int.MinValue; + public int EncounterCount { get; private set; } = int.MinValue; + + protected override GameVersion Version { get { @@ -219,94 +273,24 @@ public GameVersion Version return GameVersion.Unknown; } } - public bool ORASDEMO => Data.Length == SIZE_ORASDEMO; - public bool ORAS => Version == GameVersion.OR || Version == GameVersion.AS; - public bool XY => Version == GameVersion.X || Version == GameVersion.Y; - - // Save Information - private int BlockInfoOffset; - private BlockInfo[] Blocks; - private void getBlockInfo() - { - BlockInfoOffset = Data.Length - 0x200 + 0x10; - if (BitConverter.ToUInt32(Data, BlockInfoOffset) != BEEF) - BlockInfoOffset -= 0x200; // No savegames have more than 0x3D blocks, maybe in the future? - int count = (Data.Length - BlockInfoOffset - 0x8) / 8; - BlockInfoOffset += 4; - - Blocks = new BlockInfo[count]; - int CurrentPosition = 0; - for (int i = 0; i < Blocks.Length; i++) - { - Blocks[i] = new BlockInfo - { - Offset = CurrentPosition, - Length = BitConverter.ToInt32(Data, BlockInfoOffset + 0 + 8*i), - ID = BitConverter.ToUInt16(Data, BlockInfoOffset + 4 + 8*i), - Checksum = BitConverter.ToUInt16(Data, BlockInfoOffset + 6 + 8*i) - }; - - // Expand out to nearest 0x200 - CurrentPosition += Blocks[i].Length % 0x200 == 0 ? Blocks[i].Length : 0x200 - Blocks[i].Length % 0x200 + Blocks[i].Length; - - if ((Blocks[i].ID != 0) || i == 0) continue; - count = i; - break; - } - // Fix Final Array Lengths - Array.Resize(ref Blocks, count); - } - private void setChecksums() - { - // Check for invalid block lengths - if (Blocks.Length < 3) // arbitrary... - { - Console.WriteLine("Not enough blocks ({0}), aborting setChecksums", Blocks.Length); - return; - } - // Apply checksums - for (int i = 0; i < Blocks.Length; i++) - { - byte[] array = Data.Skip(Blocks[i].Offset).Take(Blocks[i].Length).ToArray(); - BitConverter.GetBytes(ccitt16(array)).CopyTo(Data, BlockInfoOffset + 6 + i * 8); - } - } - public bool ChecksumsValid => verifyG6SAV(Data); - public string ChecksumInfo => verifyG6CHK(Data); - public byte[] Write() - { - setChecksums(); - return Data; - } - public ulong Secure1 - { - get { return BitConverter.ToUInt64(Data, BlockInfoOffset - 0x14); } - set { BitConverter.GetBytes(value).CopyTo(Data, BlockInfoOffset - 0x14); } - } - public ulong Secure2 - { - get { return BitConverter.ToUInt64(Data, BlockInfoOffset - 0xC); } - set { BitConverter.GetBytes(value).CopyTo(Data, BlockInfoOffset - 0xC); } - } - public int CurrentBox { get { return Data[LastViewedBox]; } set { Data[LastViewedBox] = (byte)value; } } - + // Player Information - public ushort TID + public override ushort TID { get { return BitConverter.ToUInt16(Data, TrainerCard + 0); } set { BitConverter.GetBytes(value).CopyTo(Data, TrainerCard + 0); } } - public ushort SID + public override ushort SID { get { return BitConverter.ToUInt16(Data, TrainerCard + 2); } set { BitConverter.GetBytes(value).CopyTo(Data, TrainerCard + 2); } } - public int Game + public override int Game { get { return Data[TrainerCard + 4]; } set { Data[TrainerCard + 4] = (byte)value; } } - public int Gender + public override int Gender { get { return Data[TrainerCard + 5]; } set { Data[TrainerCard + 5] = (byte)value; } @@ -321,27 +305,27 @@ public ulong GameSyncID get { return BitConverter.ToUInt64(Data, TrainerCard + 8); } set { BitConverter.GetBytes(value).CopyTo(Data, TrainerCard + 8); } } - public int SubRegion + public override int SubRegion { get { return Data[TrainerCard + 0x26]; } set { Data[TrainerCard + 0x26] = (byte)value; } } - public int Country + public override int Country { get { return Data[TrainerCard + 0x27]; } set { Data[TrainerCard + 0x27] = (byte)value; } } - public int ConsoleRegion + public override int ConsoleRegion { get { return Data[TrainerCard + 0x2C]; } set { Data[TrainerCard + 0x2C] = (byte)value; } } - public int Language + public override int Language { get { return Data[TrainerCard + 0x2D]; } set { Data[TrainerCard + 0x2D] = (byte)value; } } - public string OT + public override string OT { get { return Util.TrimFromZero(Encoding.Unicode.GetString(Data, TrainerCard + 0x48, 0x1A)); } set { Encoding.Unicode.GetBytes(value.PadRight(13, '\0')).CopyTo(Data, TrainerCard + 0x48); } @@ -475,47 +459,67 @@ public int PlayedSeconds public void setMaisonStat(int index, ushort value) { BitConverter.GetBytes(value).CopyTo(Data, MaisonStats + 2*index); } public uint getEncounterCount(int index) { return BitConverter.ToUInt16(Data, EncounterCount + 2*index); } public void setEncounterCount(int index, ushort value) { BitConverter.GetBytes(value).CopyTo(Data, EncounterCount + 2*index); } - - // Misc Properties - public int PartyCount + + // Daycare + public override int DaycareSeedSize => 16; + public override int getDaycareSlotOffset(int loc, int slot) { - get { return Data[Party + 6 * PK6.SIZE_PARTY]; } - set { Data[Party + 6 * PK6.SIZE_PARTY] = (byte)value; } + int ofs = loc == 0 ? Daycare : Daycare2; + if (ofs < 0) + return -1; + return ofs + 8 + slot*(SIZE_STORED + 8); } - public bool BattleBoxLocked + public override uint? getDaycareEXP(int loc, int slot) { - get { return Data[BattleBox + 6 * PK6.SIZE_STORED] != 0; } - set { Data[BattleBox + 6 * PK6.SIZE_STORED] = (byte)(value ? 1 : 0); } + int ofs = loc == 0 ? Daycare : Daycare2; + if (ofs > -1) + return BitConverter.ToUInt32(Data, ofs + (SIZE_STORED + 8)*slot + 4); + return null; } - public ulong DaycareRNGSeed + public override bool? getDaycareOccupied(int loc, int slot) { - get { return BitConverter.ToUInt64(Data, DaycareSlot[DaycareIndex] + 0x1E8); } - set { BitConverter.GetBytes(value).CopyTo(Data, DaycareSlot[DaycareIndex] + 0x1E8); } + int ofs = loc == 0 ? Daycare : Daycare2; + if (ofs > -1) + return Data[ofs + (SIZE_STORED + 8) * slot] == 1; + return null; } - public bool DaycareHasEgg + public override ulong? getDaycareRNGSeed(int loc) { - get { return Data[DaycareSlot[DaycareIndex] + 0x1E0] == 1; } - set { Data[DaycareSlot[DaycareIndex] + 0x1E0] = (byte)(value ? 1 : 0); } + int ofs = loc == 0 ? Daycare : Daycare2; + if (ofs > -1) + return BitConverter.ToUInt64(Data, ofs + 0x1E8); + return null; } - public uint DaycareEXP1 + public override bool? getDaycareHasEgg(int loc) { - get { return BitConverter.ToUInt32(Data, DaycareSlot[DaycareIndex] + (PK6.SIZE_STORED + 8)*0 + 4); } - set { BitConverter.GetBytes(value).CopyTo(Data, DaycareSlot[DaycareIndex] + (PK6.SIZE_STORED + 8)*0 + 4); } + int ofs = loc == 0 ? Daycare : Daycare2; + if (ofs > -1) + return Data[ofs + 0x1E0] == 1; + return null; } - public uint DaycareEXP2 + public override void setDaycareEXP(int loc, int slot, uint EXP) { - get { return BitConverter.ToUInt32(Data, DaycareSlot[DaycareIndex] + (PK6.SIZE_STORED + 8)*1 + 4); } - set { BitConverter.GetBytes(value).CopyTo(Data, DaycareSlot[DaycareIndex] + (PK6.SIZE_STORED + 8)*1 + 4); } + int ofs = loc == 0 ? Daycare : Daycare2; + if (ofs > -1) + BitConverter.GetBytes(EXP).CopyTo(Data, ofs + (SIZE_STORED + 8)*slot + 4); } - public bool DaycareOccupied1 + public override void setDaycareOccupied(int loc, int slot, bool occupied) { - get { return Data[DaycareSlot[DaycareIndex] + (PK6.SIZE_STORED + 8)*0] != 0; } - set { Data[DaycareSlot[DaycareIndex] + (PK6.SIZE_STORED + 8)*0] = (byte)(value ? 1 : 0); } + int ofs = loc == 0 ? Daycare : Daycare2; + if (ofs > -1) + Data[ofs + (SIZE_STORED + 8)*slot] = (byte) (occupied ? 1 : 0); } - public bool DaycareOccupied2 + public override void setDaycareRNGSeed(int loc, ulong seed) { - get { return Data[DaycareSlot[DaycareIndex] + (PK6.SIZE_STORED + 8) * 1] != 0; } - set { Data[DaycareSlot[DaycareIndex] + (PK6.SIZE_STORED + 8) * 1] = (byte)(value ? 1 : 0); } + int ofs = loc == 0 ? Daycare : Daycare2; + if (ofs > -1) + BitConverter.GetBytes(seed).CopyTo(Data, ofs + 0x1E8); + } + public override void setDaycareHasEgg(int loc, bool hasEgg) + { + int ofs = loc == 0 ? Daycare : Daycare2; + if (ofs > -1) + Data[ofs + 0x1E0] = (byte)(hasEgg ? 1 : 0); } public byte[] Puffs { get { return Data.Skip(Puff).Take(100).ToArray(); } set { value.CopyTo(Data, Puff); } } @@ -558,79 +562,69 @@ public int[] RecentItems } } - public string JPEGTitle => JPEG > -1 ? null : Util.TrimFromZero(Encoding.Unicode.GetString(Data, JPEG, 0x1A)); - public byte[] JPEGData => JPEG > -1 || Data[JPEG + 0x54] != 0xFF ? null : Data.Skip(JPEG + 0x54).Take(0xE004).ToArray(); + public override string JPEGTitle => JPEG < 0 ? null : Util.TrimFromZero(Encoding.Unicode.GetString(Data, JPEG, 0x1A)); + public override byte[] JPEGData => JPEG < 0 || Data[JPEG + 0x54] != 0xFF ? null : Data.Skip(JPEG + 0x54).Take(0xE004).ToArray(); - // Data Accessing - public byte[] getData(int Offset, int Length) + // Inventory + public override InventoryPouch[] Inventory { - return Data.Skip(Offset).Take(Length).ToArray(); - } - public void setData(byte[] input, int Offset) - { - input.CopyTo(Data, Offset); - Edited = true; + get + { + ushort[] legalItems = ORAS ? Legal.Pouch_Items_AO : Legal.Pouch_Items_XY; + ushort[] legalKey = ORAS ? Legal.Pouch_Key_AO : Legal.Pouch_Key_XY; + ushort[] legalTMHM = ORAS ? Legal.Pouch_TMHM_AO : Legal.Pouch_TMHM_XY; + ushort[] legalMedicine = ORAS ? Legal.Pouch_Medicine_AO : Legal.Pouch_Medicine_XY; + InventoryPouch[] pouch = + { + new InventoryPouch(InventoryType.Items, legalItems, 995, OFS_PouchHeldItem), + new InventoryPouch(InventoryType.KeyItems, legalKey, 1, OFS_PouchKeyItem), + new InventoryPouch(InventoryType.TMHMs, legalTMHM, 1, OFS_PouchTMHM), + new InventoryPouch(InventoryType.Medicine, legalMedicine, 995, OFS_PouchMedicine), + new InventoryPouch(InventoryType.Berries, Legal.Pouch_Berry_XY, 995, OFS_PouchBerry), + }; + foreach (var p in pouch) + p.getPouch(ref Data); + return pouch; + } + set + { + foreach (var p in value) + p.setPouch(ref Data); + } } - // Pokémon Requests - public PK6 getPK6Party(int offset) + // Storage + public override int CurrentBox { get { return Data[LastViewedBox]; } set { Data[LastViewedBox] = (byte)value; } } + public override int getPartyOffset(int slot) { - return new PK6(decryptArray(getData(offset , PK6.SIZE_PARTY))); + return Party + SIZE_PARTY * slot; } - public PK6 getPK6Stored(int offset) + public override int getBoxOffset(int box) { - return new PK6(decryptArray(getData(offset, PK6.SIZE_STORED))); + return Box + SIZE_STORED*box*30; } - public void setPK6Party(PK6 pk6, int offset, bool? trade = null, bool? dex = null) + public override int getBoxWallpaper(int box) { - if (pk6 == null) return; - if (trade ?? SetUpdatePK6) - setPK6(pk6); - if (dex ?? SetUpdateDex) - setDex(pk6); - - setData(pk6.EncryptedPartyData, offset); + return 1 + Data[PCBackgrounds + box]; + } + public override string getBoxName(int box) + { + if (PCLayout < 0) + return "B" + (box + 1); + return Util.TrimFromZero(Encoding.Unicode.GetString(Data, PCLayout + 0x22*box, 0x22)); + } + public override void setBoxName(int box, string val) + { + Encoding.Unicode.GetBytes(val.PadRight(0x11, '\0')).CopyTo(Data, PCLayout + 0x22*box); Edited = true; } - public void setPK6Stored(PK6 pk6, int offset, bool? trade = null, bool? dex = null) + public override PKM getPKM(byte[] data) { - if (pk6 == null) return; - if (trade ?? SetUpdatePK6) - setPK6(pk6); - if (dex ?? SetUpdateDex) - setDex(pk6); - - setData(pk6.EncryptedBoxData, offset); - Edited = true; + return new PK6(data); } - public void setEK6Stored(byte[] ek6, int offset, bool? trade = null, bool? dex = null) - { - if (ek6 == null) return; - PK6 pk6 = new PK6(decryptArray(ek6)); - if (trade ?? SetUpdatePK6) - setPK6(pk6); - if (dex ?? SetUpdateDex) - setDex(pk6); - - setData(pk6.EncryptedBoxData, offset); - Edited = true; - } - public void setEK6Party(byte[] ek6, int offset, bool? trade = null, bool? dex = null) - { - if (ek6 == null) return; - PK6 pk6 = new PK6(decryptArray(ek6)); - if (trade ?? SetUpdatePK6) - setPK6(pk6); - if (dex ?? SetUpdateDex) - setDex(pk6); - - setData(pk6.EncryptedPartyData, offset); - Edited = true; - } - - // Meta - public void setPK6(PK6 pk6) + protected override void setPKM(PKM pkm) { + PK6 pk6 = pkm as PK6; // Apply to this Save File int CT = pk6.CurrentHandler; DateTime Date = DateTime.Now; @@ -641,15 +635,16 @@ public void setPK6(PK6 pk6) if (pk6.Moves.Contains(216)) // Return pk6.CurrentFriendship = pk6.OppositeFriendship; else if (pk6.Moves.Contains(218)) // Frustration - pk6.CurrentFriendship = pk6.OppositeFriendship; + pkm.CurrentFriendship = pk6.OppositeFriendship; else if (pk6.CurrentHandler == 1) // OT->HT, needs new Friendship/Affection pk6.TradeFriendshipAffection(OT); } - pk6.RefreshChecksum(); + pkm.RefreshChecksum(); } - public void setDex(PK6 pk6) + protected override void setDex(PKM pkm) { - if (PokeDex < 0) + PK6 pk6 = pkm as PK6; + if (PokeDex < 0) return; if (pk6.Species == 0) return; @@ -674,10 +669,10 @@ public void setDex(PK6 pk6) // Set the Display flag if none are set bool Displayed = false; - Displayed |= (Data[PokeDex + 0x60*5 + bit/8 + 0x8] & (byte) (1 << (bit%8))) != 0; - Displayed |= (Data[PokeDex + 0x60*6 + bit/8 + 0x8] & (byte) (1 << (bit%8))) != 0; - Displayed |= (Data[PokeDex + 0x60*7 + bit/8 + 0x8] & (byte) (1 << (bit%8))) != 0; - Displayed |= (Data[PokeDex + 0x60*8 + bit/8 + 0x8] & (byte) (1 << (bit%8))) != 0; + Displayed |= (Data[PokeDex + 0x60 * 5 + bit / 8 + 0x8] & (byte)(1 << (bit % 8))) != 0; + Displayed |= (Data[PokeDex + 0x60 * 6 + bit / 8 + 0x8] & (byte)(1 << (bit % 8))) != 0; + Displayed |= (Data[PokeDex + 0x60 * 7 + bit / 8 + 0x8] & (byte)(1 << (bit % 8))) != 0; + Displayed |= (Data[PokeDex + 0x60 * 8 + bit / 8 + 0x8] & (byte)(1 << (bit % 8))) != 0; if (!Displayed) // offset is already biased by 0x60, reuse shiftoff but for the display flags. Data[PokeDex + shiftoff + 0x60 * 4 + bit / 8 + 0x8] |= (byte)(1 << (bit % 8)); @@ -686,28 +681,28 @@ public void setDex(PK6 pk6) Data[PokeDexLanguageFlags + (bit * 7 + lang) / 8] |= (byte)(1 << ((bit * 7 + lang) % 8)); // Set Form flags - int fc = Personal[pk6.Species].FormeCount; - int f = ORAS ? getDexFormIndexORAS(pk6.Species, fc) : getDexFormIndexXY(pk6.Species, fc); + int fc = PKX.Personal[pk6.Species].FormeCount; + int f = ORAS ? SaveUtil.getDexFormIndexORAS(pk6.Species, fc) : SaveUtil.getDexFormIndexXY(pk6.Species, fc); if (f >= 0) { int FormLen = ORAS ? 0x26 : 0x18; int FormDex = PokeDex + 0x368; bit = f + pk6.AltForm; // Set Seen Flag - Data[FormDex + FormLen*shiny + bit/8] |= (byte)(1 << (bit%8)); + Data[FormDex + FormLen * shiny + bit / 8] |= (byte)(1 << (bit % 8)); // Set Displayed Flag if necessary, check all flags bool FormDisplayed = false; for (int i = 0; i < fc; i++) { bit = f + i; - FormDisplayed |= (Data[FormDex + FormLen*2 + bit/8] & (byte)(1 << (bit%8))) != 0; // Nonshiny - FormDisplayed |= (Data[FormDex + FormLen*3 + bit/8] & (byte)(1 << (bit%8))) != 0; // Shiny + FormDisplayed |= (Data[FormDex + FormLen * 2 + bit / 8] & (byte)(1 << (bit % 8))) != 0; // Nonshiny + FormDisplayed |= (Data[FormDex + FormLen * 3 + bit / 8] & (byte)(1 << (bit % 8))) != 0; // Shiny } if (!FormDisplayed) { bit = f + pk6.AltForm; - Data[FormDex + FormLen*(2+shiny) + bit/8] |= (byte)(1 << (bit%8)); + Data[FormDex + FormLen * (2 + shiny) + bit / 8] |= (byte)(1 << (bit % 8)); } } @@ -715,158 +710,23 @@ public void setDex(PK6 pk6) if (ORAS && getEncounterCount(pk6.Species - 1) == 0) setEncounterCount(pk6.Species - 1, 1); } - public int getBoxWallpaper(int box) + public override byte[] decryptPKM(byte[] data) { - return 1 + Data[BoxWallpapers + box]; + return PKX.decryptArray(data); } - public string getBoxName(int box) + public override int PartyCount { - if (PCLayout < 0) - return "B" + (box + 1); - return Util.TrimFromZero(Encoding.Unicode.GetString(Data, PCLayout + 0x22*box, 0x22)); + get { return Data[Party + 6 * SIZE_PARTY]; } + protected set { Data[Party + 6 * SIZE_PARTY] = (byte)value; } } - public void setBoxName(int box, string val) + public override bool BattleBoxLocked { - Encoding.Unicode.GetBytes(val.PadRight(0x11, '\0')).CopyTo(Data, PCLayout + 0x22*box); - Edited = true; - } - public void setParty() - { - byte partymembers = 0; // start off with a ctr of 0 - for (int i = 0; i < 6; i++) - { - // Gather all the species - byte[] data = new byte[PK6.SIZE_PARTY]; - Array.Copy(Data, Party + i * PK6.SIZE_PARTY, data, 0, PK6.SIZE_PARTY); - byte[] decdata = decryptArray(data); - int species = BitConverter.ToInt16(decdata, 8); - if ((species != 0) && (species < 722)) - Array.Copy(data, 0, Data, Party + partymembers++ * PK6.SIZE_PARTY, PK6.SIZE_PARTY); - } - - // Write in the current party count - PartyCount = partymembers; - // Zero out the party slots that are empty. - for (int i = 0; i < 6; i++) - if (i >= partymembers) - Array.Copy(encryptArray(new byte[PK6.SIZE_PARTY]), 0, Data, Party + i * PK6.SIZE_PARTY, PK6.SIZE_PARTY); - - if (BattleBox < 0) - return; - // Repeat for Battle Box. - byte battlemem = 0; - for (int i = 0; i < 6; i++) - { - // Gather all the species - byte[] data = new byte[PK6.SIZE_PARTY]; - Array.Copy(Data, BattleBox + i * PK6.SIZE_STORED, data, 0, PK6.SIZE_STORED); - byte[] decdata = decryptArray(data); - int species = BitConverter.ToInt16(decdata, 8); - if ((species != 0) && (species < 722)) - Array.Copy(data, 0, Data, BattleBox + battlemem++ * PK6.SIZE_STORED, PK6.SIZE_STORED); - } - - // Zero out the party slots that are empty. - for (int i = 0; i < 6; i++) - if (i >= battlemem) - Array.Copy(encryptArray(new byte[PK6.SIZE_PARTY]), 0, Data, BattleBox + i * PK6.SIZE_STORED, PK6.SIZE_STORED); - - BattleBoxLocked &= battlemem != 0; - } - public void sortBoxes() - { - const int len = 31 * 30; // amount of pk6's in boxes - - // Fetch encrypted box data - byte[][] bdata = new byte[len][]; - for (int i = 0; i < len; i++) - bdata[i] = getData(Box + i * PK6.SIZE_STORED, PK6.SIZE_STORED); - - // Sorting Method: Data will sort empty slots to the end, then from the filled slots eggs will be last, then species will be sorted. - var query = from i in bdata - let p = new PK6(decryptArray(i)) - orderby - p.Species == 0 ascending, - p.IsEgg ascending, - p.Species ascending, - p.IsNicknamed ascending - select i; - byte[][] sorted = query.ToArray(); - - // Write data back - for (int i = 0; i < len; i++) - setData(sorted[i], Box + i * PK6.SIZE_STORED); + get { return Data[BattleBox + 6 * SIZE_STORED] != 0; } + set { Data[BattleBox + 6 * SIZE_STORED] = (byte)(value ? 1 : 0); } } - // Informational - public PK6[] BoxData - { - get - { - PK6[] data = new PK6[31*30]; - for (int i = 0; i < data.Length; i++) - { - data[i] = getPK6Stored(Box + PK6.SIZE_STORED * i); - data[i].Identifier = $"{getBoxName(i/30)}:{(i%30 + 1).ToString("00")}"; - } - return data; - } - set - { - if (value == null) - throw new ArgumentNullException(); - if (value.Length != 31*30) - throw new ArgumentException("Expected 930, got " + value.Length); - - for (int i = 0; i < value.Length; i++) - setPK6Stored(value[i], Box + PK6.SIZE_STORED * i); - } - } - public PK6[] PartyData - { - get - { - PK6[] data = new PK6[PartyCount]; - for (int i = 0; i < data.Length; i++) - data[i] = getPK6Party(Party + PK6.SIZE_PARTY * i); - return data; - } - set - { - if (value == null) - throw new ArgumentNullException(); - if (value.Length == 0 || value.Length > 6) - throw new ArgumentException("Expected 1-6, got " + value.Length); - if (value[0].Species == 0) - throw new ArgumentException("Can't have an empty first slot." + value.Length); - - PK6[] newParty = value.Where(pk => pk.Species != 0).ToArray(); - - PartyCount = newParty.Length; - Array.Resize(ref newParty, 6); - - for (int i = PartyCount; i < newParty.Length; i++) - newParty[i] = new PK6(); - for (int i = 0; i < newParty.Length; i++) - setPK6Party(newParty[i], Party + PK6.SIZE_PARTY*i); - } - } - public PK6[] BattleBoxData - { - get - { - PK6[] data = new PK6[6]; - for (int i = 0; i < data.Length; i++) - { - data[i] = getPK6Stored(BattleBox + PK6.SIZE_STORED * i); - if (data[i].Species == 0) - return data.Take(i).ToArray(); - } - return data; - } - } - - public bool[] WC6Flags + // Mystery Gift + protected override bool[] MysteryGiftReceivedFlags { get { @@ -894,34 +754,59 @@ public bool[] WC6Flags Edited = true; } } - public WC6 getWC6(int index) + protected override MysteryGift[] MysteryGiftCards + { + get + { + if (WondercardData < 0) + return null; + MysteryGift[] cards = new MysteryGift[GiftCountMax]; + for (int i = 0; i < cards.Length; i++) + cards[i] = getWC6(i); + + return cards; + } + set + { + if (value == null) + return; + if (value.Length > 24) + Array.Resize(ref value, 24); + + for (int i = 0; i < value.Length; i++) + setWC6(value[i], i); + for (int i = value.Length; i < GiftCountMax; i++) + setWC6(new WC6(), i); + } + } + private WC6 getWC6(int index) { if (WondercardData < 0) return null; - if (index < 0 || index > 24) + if (index < 0 || index > GiftCountMax) return null; return new WC6(Data.Skip(WondercardData + index * WC6.Size).Take(WC6.Size).ToArray()); } - public void setWC6(WC6 wc6, int index) + private void setWC6(MysteryGift wc6, int index) { if (WondercardData < 0) return; - if (index < 0 || index > 24) + if (index < 0 || index > GiftCountMax) return; wc6.Data.CopyTo(Data, WondercardData + index * WC6.Size); - for (int i = 0; i < 24; i++) + for (int i = 0; i < GiftCountMax; i++) if (BitConverter.ToUInt16(Data, WondercardData + i * WC6.Size) == 0) - for (int j = i + 1; j < 24 - i; j++) // Shift everything down + for (int j = i + 1; j < GiftCountMax - i; j++) // Shift everything down Array.Copy(Data, WondercardData + j * WC6.Size, Data, WondercardData + (j - 1) * WC6.Size, WC6.Size); Edited = true; } // Writeback Validity - public string checkChunkFF() + public override string MiscSaveChecks() { string r = ""; byte[] FFFF = Enumerable.Repeat((byte)0xFF, 0x200).ToArray(); @@ -942,9 +827,7 @@ public string checkChunkFF() } return r; } - - // Debug - public string getBlockInfoString() + public override string MiscSaveInfo() { return Blocks.Aggregate("", (current, b) => current + $"{b.ID.ToString("00")}: {b.Offset.ToString("X5")}-{(b.Offset + b.Length).ToString("X5")}, {b.Length.ToString("X5")}{Environment.NewLine}"); diff --git a/Saves/SaveFile.cs b/Saves/SaveFile.cs new file mode 100644 index 000000000..de8039182 --- /dev/null +++ b/Saves/SaveFile.cs @@ -0,0 +1,435 @@ +using System; +using System.Linq; + +namespace PKHeX +{ + // Base Class for Save Files + public abstract class SaveFile + { + internal static bool SetUpdateDex = true; + internal static bool SetUpdatePKM = true; + + // General Object Properties + public byte[] Data; + public bool Edited; + public string FileName, FilePath; + public abstract string BAKName { get; } + public abstract byte[] BAK { get; } + public abstract bool Exportable { get; } + public abstract SaveFile Clone(); + + // General PKM Properties + protected abstract Type PKMType { get; } + public abstract PKM getPKM(byte[] data); + public abstract PKM BlankPKM { get; } + public abstract byte[] decryptPKM(byte[] data); + public abstract int SIZE_STORED { get; } + public abstract int SIZE_PARTY { get; } + public abstract int MaxEV { get; } + public ushort[] HeldItems { get; protected set; } + + // General SAV Properties + public byte[] Write() + { + setChecksums(); + return Data; + } + public virtual string MiscSaveChecks() { return ""; } + public virtual string MiscSaveInfo() { return ""; } + protected abstract GameVersion Version { get; } + public abstract bool ChecksumsValid { get; } + public abstract string ChecksumInfo { get; } + public abstract int Generation { get; } + + public bool ORASDEMO => Data.Length == SaveUtil.SIZE_G6ORASDEMO; + public bool ORAS => Version == GameVersion.OR || Version == GameVersion.AS; + public bool XY => Version == GameVersion.X || Version == GameVersion.Y; + + // Flags + public bool HasWondercards => WondercardData > -1; + public bool HasSuperTrain => SuperTrain > -1; + public bool HasBerryField => BerryField > -1; + public bool HasHoF => HoF > -1; + public bool HasSecretBase => SecretBase > -1; + public bool HasPuff => Puff > -1; + public bool HasPSS => PSS > -1; + public bool HasOPower => OPower > -1; + public bool HasJPEG => JPEGData != null; + public bool HasBox => Box > -1; + public bool HasParty => Party > -1; + public bool HasBattleBox => BattleBox > -1; + public bool HasFused => Fused > -1; + public bool HasGTS => GTS > -1; + public bool HasDaycare => Daycare > -1; + public bool HasPokeDex => PokeDex > -1; + public virtual bool HasBoxWallpapers => PCLayout > -1; + public virtual bool HasSUBE => SUBE > -1 && !ORAS; + public virtual bool HasGeolocation => false; + public bool HasPokeBlock => ORAS && !ORASDEMO; + public bool HasEvents => EventFlags != null; + + // Counts + protected virtual int GiftCountMax { get; } = int.MinValue; + protected virtual int GiftFlagMax { get; } = 0x800; + protected virtual int EventFlagMax { get; } = int.MinValue; + protected virtual int EventConstMax { get; } = int.MinValue; + public abstract int DaycareSeedSize { get; } + public abstract int OTLength { get; } + public abstract int NickLength { get; } + + // Offsets + protected int Box { get; set; } = int.MinValue; + protected int Party { get; set; } = int.MinValue; + protected int Trainer1 { get; set; } = int.MinValue; + protected int Daycare { get; set; } = int.MinValue; + protected int WondercardData { get; set; } = int.MinValue; + protected int PCLayout { get; set; } = int.MinValue; + protected int EventFlag { get; set; } = int.MinValue; + protected int EventConst { get; set; } = int.MinValue; + + public int GTS { get; protected set; } = int.MinValue; + public int BattleBox { get; protected set; } = int.MinValue; + public int Fused { get; protected set; } = int.MinValue; + public int SUBE { get; protected set; } = int.MinValue; + public int PokeDex { get; protected set; } = int.MinValue; + public int SuperTrain { get; protected set; } = int.MinValue; + public int SecretBase { get; protected set; } = int.MinValue; + public int Puff { get; protected set; } = int.MinValue; + public int PSS { get; protected set; } = int.MinValue; + public int BerryField { get; protected set; } = int.MinValue; + public int OPower { get; protected set; } = int.MinValue; + public int HoF { get; protected set; } = int.MinValue; + + // SAV Properties + public PKM[] BoxData + { + get + { + PKM[] data = new PKM[BoxCount*30]; + for (int i = 0; i < data.Length; i++) + { + data[i] = getStoredSlot(getBoxOffset(i/30) + SIZE_STORED*(i%30)); + data[i].Identifier = $"{getBoxName(i/30)}:{(i%30 + 1).ToString("00")}"; + } + return data; + } + set + { + if (value == null) + throw new ArgumentNullException(); + if (value.Length != BoxCount*30) + throw new ArgumentException($"Expected {BoxCount*30}, got {value.Length}"); + if (value.Any(pk => PKMType != pk.GetType())) + throw new ArgumentException($"Not {PKMType} array."); + + for (int i = 0; i < value.Length; i++) + setStoredSlot(value[i], getBoxOffset(i/30) + SIZE_STORED*(i%30)); + } + } + public PKM[] PartyData + { + get + { + PKM[] data = new PKM[PartyCount]; + for (int i = 0; i < data.Length; i++) + data[i] = getPartySlot(Party + SIZE_PARTY * i); + return data; + } + set + { + if (value == null) + throw new ArgumentNullException(); + if (value.Length == 0 || value.Length > 6) + throw new ArgumentException("Expected 1-6, got " + value.Length); + if (value.Any(pk => PKMType != pk.GetType())) + throw new ArgumentException($"Not {PKMType} array."); + if (value[0].Species == 0) + throw new ArgumentException("Can't have an empty first slot." + value.Length); + + PKM[] newParty = value.Where(pk => pk.Species != 0).ToArray(); + + PartyCount = newParty.Length; + Array.Resize(ref newParty, 6); + + for (int i = PartyCount; i < newParty.Length; i++) + newParty[i] = BlankPKM; + for (int i = 0; i < newParty.Length; i++) + setPartySlot(newParty[i], getPartyOffset(i)); + } + } + public PKM[] BattleBoxData + { + get + { + if (Generation < 5) + return new PKM[0]; + + PKM[] data = new PKM[6]; + for (int i = 0; i < data.Length; i++) + { + data[i] = getStoredSlot(BattleBox + SIZE_STORED * i); + if (data[i].Species == 0) + return data.Take(i).ToArray(); + } + return data; + } + } + + public bool[] EventFlags + { + get + { + if (EventFlagMax < 0) + return null; + + bool[] Flags = new bool[EventFlagMax]; + for (int i = 0; i < Flags.Length; i++) + Flags[i] = (Data[EventFlag + i / 8] >> i % 8 & 0x1) == 1; + return Flags; + } + set + { + if (EventFlagMax < 0) + return; + if (value.Length != EventFlagMax) + return; + + byte[] data = new byte[value.Length / 8]; + for (int i = 0; i < value.Length; i++) + if (value[i]) + data[i >> 3] |= (byte)(1 << (i & 7)); + + data.CopyTo(Data, EventFlag); + } + } + public ushort[] EventConsts + { + get + { + if (EventConstMax < 0) + return null; + + ushort[] Constants = new ushort[EventConstMax]; + for (int i = 0; i < Constants.Length; i++) + Constants[i] = BitConverter.ToUInt16(Data, EventConst + i); + return Constants; + } + set + { + if (EventConstMax < 0) + return; + if (value.Length != EventConstMax) + return; + + for (int i = 0; i < value.Length; i++) + BitConverter.GetBytes(value[i]).CopyTo(Data, EventConst + i * 2); + } + } + + // Inventory + public abstract InventoryPouch[] Inventory { get; set; } + protected int OFS_PouchHeldItem { get; set; } = int.MinValue; + protected int OFS_PouchKeyItem { get; set; } = int.MinValue; + protected int OFS_PouchMedicine { get; set; } = int.MinValue; + protected int OFS_PouchTMHM { get; set; } = int.MinValue; + protected int OFS_PouchBerry { get; set; } = int.MinValue; + protected int OFS_PouchBalls { get; set; } = int.MinValue; + protected int OFS_BattleItems { get; set; } = int.MinValue; + protected int OFS_MailItems { get; set; } = int.MinValue; + + // Mystery Gift + protected abstract bool[] MysteryGiftReceivedFlags { get; set; } + protected abstract MysteryGift[] MysteryGiftCards { get; set; } + public virtual MysteryGiftAlbum GiftAlbum + { + get + { + return new MysteryGiftAlbum + { + Flags = MysteryGiftReceivedFlags, + Gifts = MysteryGiftCards + }; + } + set + { + MysteryGiftReceivedFlags = value.Flags; + MysteryGiftCards = value.Gifts; + } + } + + public virtual bool BattleBoxLocked { get { return false; } set { } } + public virtual string JPEGTitle => null; + public virtual byte[] JPEGData => null; + public virtual int Country { get { return -1; } set { } } + public virtual int ConsoleRegion { get { return -1; } set { } } + public virtual int SubRegion { get { return -1; } set { } } + + // Trainer Info + public abstract int Gender { get; set; } + public abstract int Language { get; set; } + public virtual int Game { get { return -1; } set { } } + public abstract ushort TID { get; set; } + public abstract ushort SID { get; set; } + public abstract string OT { get; set; } + public abstract int BoxCount { get; } + public abstract int PartyCount { get; protected set; } + public virtual int CurrentBox { get { return 0; } set { } } + + // Varied Methods + protected abstract void setChecksums(); + public abstract int getBoxOffset(int box); + public abstract int getPartyOffset(int slot); + public abstract int getBoxWallpaper(int box); + public abstract string getBoxName(int box); + public abstract void setBoxName(int box, string val); + + // Daycare + public int DaycareIndex = 0; + public abstract int getDaycareSlotOffset(int loc, int slot); + public abstract uint? getDaycareEXP(int loc, int slot); + public virtual ulong? getDaycareRNGSeed(int loc) { return null; } + public virtual bool? getDaycareHasEgg(int loc) { return false; } + public abstract bool? getDaycareOccupied(int loc, int slot); + + public abstract void setDaycareEXP(int loc, int slot, uint EXP); + public virtual void setDaycareRNGSeed(int loc, ulong seed) { } + public virtual void setDaycareHasEgg(int loc, bool hasEgg) { } + public abstract void setDaycareOccupied(int loc, int slot, bool occupied); + + // Storage + public PKM getPartySlot(int offset) + { + return getPKM(decryptPKM(getData(offset, SIZE_PARTY))); + } + public PKM getStoredSlot(int offset) + { + return getPKM(decryptPKM(getData(offset, SIZE_STORED))); + } + public void setPartySlot(PKM pkm, int offset, bool? trade = null, bool? dex = null) + { + if (pkm == null) return; + if (pkm.GetType() != PKMType) + throw new InvalidCastException($"PKM Format needs to be {PKMType} when setting to a Gen{Generation} Save File."); + if (trade ?? SetUpdatePKM) + setPKM(pkm); + if (dex ?? SetUpdateDex) + setDex(pkm); + + setData(pkm.EncryptedPartyData, offset); + Console.WriteLine(""); + Edited = true; + } + public void setStoredSlot(PKM pkm, int offset, bool? trade = null, bool? dex = null) + { + if (pkm == null) return; + if (pkm.GetType() != PKMType) + throw new InvalidCastException($"PKM Format needs to be {PKMType} when setting to a Gen{Generation} Save File."); + if (trade ?? SetUpdatePKM) + setPKM(pkm); + if (dex ?? SetUpdateDex) + setDex(pkm); + + setData(pkm.EncryptedBoxData, offset); + Edited = true; + } + public void setPartySlot(byte[] data, int offset, bool? trade = null, bool? dex = null) + { + if (data == null) return; + PKM pkm = getPKM(decryptPKM(data)); + if (trade ?? SetUpdatePKM) + setPKM(pkm); + if (dex ?? SetUpdateDex) + setDex(pkm); + + setData(pkm.EncryptedPartyData, offset); + Edited = true; + } + public void setStoredSlot(byte[] data, int offset, bool? trade = null, bool? dex = null) + { + if (data == null) return; + PKM pkm = getPKM(decryptPKM(data)); + if (trade ?? SetUpdatePKM) + setPKM(pkm); + if (dex ?? SetUpdateDex) + setDex(pkm); + + setData(pkm.EncryptedBoxData, offset); + Edited = true; + } + + public void sortBoxes(int BoxStart = 0, int BoxEnd = -1) + { + PKM[] BD = BoxData; + var Section = BD.Skip(BoxStart*30); + if (BoxEnd > BoxStart) + Section = Section.Take(30*(BoxEnd - BoxStart)); + + var Sorted = Section + .OrderBy(p => p.Species == 0) // empty slots at end + .ThenBy(p => p.IsEgg) // eggs to the end + .ThenBy(p => p.Species) // species sorted + .ThenBy(p => p.IsNicknamed).ToArray(); + + Array.Copy(Sorted, 0, BD, BoxStart*30, Sorted.Length); + BoxData = BD; + } + public void resetBoxes(int BoxStart = 0, int BoxEnd = -1) + { + if (BoxEnd < 0) + BoxEnd = BoxCount; + for (int i = BoxStart; i < BoxEnd; i++) + { + int offset = getBoxOffset(i); + for (int p = 0; p < 30; p++) + setStoredSlot(BlankPKM, offset + SIZE_STORED * p); + } + } + + public byte[] getPCBin() { return BoxData.SelectMany(pk => pk.EncryptedBoxData).ToArray(); } + public byte[] getBoxBin(int box) { return BoxData.Skip(box*30).Take(30).SelectMany(pk => pk.EncryptedBoxData).ToArray(); } + public bool setPCBin(byte[] data) + { + if (data.Length != getPCBin().Length) + return false; + + // split up data to individual pkm + byte[][] pkdata = new byte[data.Length/SIZE_STORED][]; + for (int i = 0; i < data.Length; i += SIZE_STORED) + pkdata[i] = data.Skip(i).Take(SIZE_STORED).ToArray(); + + PKM[] pkms = BoxData; + for (int i = 0; i < pkms.Length; i++) + pkms[i].Data = decryptPKM(pkdata[i]); + BoxData = pkms; + return true; + } + public bool setBoxBin(byte[] data, int box) + { + if (data.Length != getBoxBin(box).Length) + return false; + + byte[][] pkdata = new byte[data.Length / SIZE_STORED][]; + for (int i = 0; i < data.Length; i += SIZE_STORED) + pkdata[i] = data.Skip(i).Take(SIZE_STORED).ToArray(); + + PKM[] pkms = BoxData; + for (int i = 0; i < 30; i++) + pkms[box*30 + i].Data = decryptPKM(pkdata[i]); + BoxData = pkms; + return true; + } + + protected virtual void setPKM(PKM pkm) { } + protected virtual void setDex(PKM pkm) { } + + public byte[] getData(int Offset, int Length) + { + return Data.Skip(Offset).Take(Length).ToArray(); + } + public void setData(byte[] input, int Offset) + { + input.CopyTo(Data, Offset); + Edited = true; + } + } +} diff --git a/Saves/SaveObjects.cs b/Saves/SaveObjects.cs new file mode 100644 index 000000000..79b7de530 --- /dev/null +++ b/Saves/SaveObjects.cs @@ -0,0 +1,22 @@ +namespace PKHeX +{ + public struct DaycareSlot + { + public uint Experience; + public PKM PKM; + public bool Occupied; + } + public struct Daycare + { + public DaycareSlot[] Slots; + public bool EggAvailable; + public ulong Seed; + } + + public struct MysteryGiftAlbum + { + public MysteryGift[] Gifts; + public bool[] Flags; + public uint Seed; + } +} diff --git a/Saves/SaveUtil.cs b/Saves/SaveUtil.cs new file mode 100644 index 000000000..e8c05db91 --- /dev/null +++ b/Saves/SaveUtil.cs @@ -0,0 +1,373 @@ +using System; +using System.Linq; + +namespace PKHeX +{ + public enum GameVersion + { + Any = -1, + Unknown = 0, + S = 1, R = 2, E = 3, FR = 4, LG = 5, CXD = 15, + D = 10, P = 11, Pt = 12, HG = 7, SS = 8, + W = 20, B = 21, W2 = 22, B2 = 23, + X = 24, Y = 25, AS = 26, OR = 27, + SN = 28, MN = 29, + + DP = 100, + HGSS = 101, + } + internal static class SaveUtil + { + internal const int BEEF = 0x42454546; + + internal const int SIZE_G6XY = 0x65600; + internal const int SIZE_G6ORAS = 0x76000; + internal const int SIZE_G6ORASDEMO = 0x5A00; + internal const int SIZE_G5RAW = 0x80000; + internal const int SIZE_G5BW = 0x24000; + internal const int SIZE_G5B2W2 = 0x26000; + internal const int SIZE_G4RAW = 0x80000; + + internal static readonly byte[] EncryptedBlank4 = PKX.encryptArray45(new byte[PKX.SIZE_4PARTY]); + internal static readonly byte[] EncryptedBlank5 = PKX.encryptArray45(new byte[PKX.SIZE_5PARTY]); + internal static readonly byte[] EncryptedBlank6 = PKX.encryptArray(new byte[PKX.SIZE_6PARTY]); + + internal static int getSAVGeneration(byte[] data) + { + if (getIsG4SAV(data) != -1) + return 4; + if (getIsG5SAV(data) != -1) + return 5; + if (getIsG6SAV(data) != -1) + return 6; + return -1; + } + internal static int getIsG4SAV(byte[] data) + { + if (data.Length != SIZE_G4RAW) + return -1; + + int version = -1; + if (BitConverter.ToUInt16(data, 0xC0FE) == ccitt16(data.Take(0xC0EC).ToArray())) + version = 0; // DP + else if (BitConverter.ToUInt16(data, 0xCF2A) == ccitt16(data.Take(0xCF18).ToArray())) + version = 1; // PT + else if (BitConverter.ToUInt16(data, 0xF626) == ccitt16(data.Take(0xF618).ToArray())) + version = 2; // HGSS + return version; + } + internal static int getIsG5SAV(byte[] data) + { + if (data.Length != SIZE_G5RAW) + return -1; + + ushort chk1 = BitConverter.ToUInt16(data, SIZE_G5BW - 0x100 + 0x8C + 0xE); + ushort actual1 = ccitt16(data.Skip(SIZE_G5BW - 0x100).Take(0x8C).ToArray()); + if (chk1 == actual1) + return 0; + ushort chk2 = BitConverter.ToUInt16(data, SIZE_G5B2W2 - 0x100 + 0x94 + 0xE); + ushort actual2 = ccitt16(data.Skip(SIZE_G5B2W2 - 0x100).Take(0x94).ToArray()); + if (chk2 == actual2) + return 1; + return -1; + } + internal static int getIsG6SAV(byte[] data) + { + if (!SizeValidSAV6(data.Length)) + return -1; + + if (BitConverter.ToUInt32(data, data.Length - 0x1F0) != BEEF) + return -1; + + switch (data.Length) + { + case SIZE_G6XY: + return 0; + case SIZE_G6ORASDEMO: + return 1; + case SIZE_G6ORAS: + return 2; + default: // won't hit + return 3; + } + } + internal static SaveFile getVariantSAV(byte[] data) + { + switch (getSAVGeneration(data)) + { + case 4: + return new SAV4(data); + case 5: + return new SAV5(data); + case 6: + return new SAV6(data); + default: + return null; + } + } + internal static bool SizeValidSAV6(int size) + { + switch (size) + { + case SIZE_G6XY: + case SIZE_G6ORASDEMO: + case SIZE_G6ORAS: + return true; + } + return false; + } + + // SAV Manipulation + /// Calculates the CRC16-CCITT checksum over an input byte array. + /// Input byte array + /// Checksum + internal static ushort ccitt16(byte[] data) + { + const ushort init = 0xFFFF; + const ushort poly = 0x1021; + + ushort crc = init; + foreach (byte b in data) + { + crc ^= (ushort)(b << 8); + for (int j = 0; j < 8; j++) + { + bool flag = (crc & 0x8000) > 0; + crc <<= 1; + if (flag) + crc ^= poly; + } + } + return crc; + } + /// Simple check to see if the save is valid. + /// Input binary file + /// True/False + internal static bool verifyG6SAV(byte[] savefile) + { + // Dynamic handling of checksums regardless of save size. + + int verificationOffset = savefile.Length - 0x200 + 0x10; + if (BitConverter.ToUInt32(savefile, verificationOffset) != BEEF) + verificationOffset -= 0x200; // No savegames have more than 0x3D blocks, maybe in the future? + + int count = (savefile.Length - verificationOffset - 0x8) / 8; + verificationOffset += 4; + int[] Lengths = new int[count]; + ushort[] BlockIDs = new ushort[count]; + ushort[] Checksums = new ushort[count]; + int[] Start = new int[count]; + int CurrentPosition = 0; + for (int i = 0; i < count; i++) + { + Start[i] = CurrentPosition; + Lengths[i] = BitConverter.ToInt32(savefile, verificationOffset + 0 + 8 * i); + BlockIDs[i] = BitConverter.ToUInt16(savefile, verificationOffset + 4 + 8 * i); + Checksums[i] = BitConverter.ToUInt16(savefile, verificationOffset + 6 + 8 * i); + + CurrentPosition += Lengths[i] % 0x200 == 0 ? Lengths[i] : 0x200 - Lengths[i] % 0x200 + Lengths[i]; + + if ((BlockIDs[i] != 0) || i == 0) continue; + count = i; + break; + } + // Verify checksums + for (int i = 0; i < count; i++) + { + ushort chk = ccitt16(savefile.Skip(Start[i]).Take(Lengths[i]).ToArray()); + ushort old = BitConverter.ToUInt16(savefile, verificationOffset + 6 + i * 8); + + if (chk != old) + return false; + } + return true; + } + /// Verbose check to see if the save is valid. + /// Input binary file + /// String containing invalid blocks. + internal static string verifyG6CHK(byte[] savefile) + { + string rv = ""; + int invalid = 0; + // Dynamic handling of checksums regardless of save size. + + int verificationOffset = savefile.Length - 0x200 + 0x10; + if (BitConverter.ToUInt32(savefile, verificationOffset) != BEEF) + verificationOffset -= 0x200; // No savegames have more than 0x3D blocks, maybe in the future? + + int count = (savefile.Length - verificationOffset - 0x8) / 8; + verificationOffset += 4; + int[] Lengths = new int[count]; + ushort[] BlockIDs = new ushort[count]; + ushort[] Checksums = new ushort[count]; + int[] Start = new int[count]; + int CurrentPosition = 0; + for (int i = 0; i < count; i++) + { + Start[i] = CurrentPosition; + Lengths[i] = BitConverter.ToInt32(savefile, verificationOffset + 0 + 8 * i); + BlockIDs[i] = BitConverter.ToUInt16(savefile, verificationOffset + 4 + 8 * i); + Checksums[i] = BitConverter.ToUInt16(savefile, verificationOffset + 6 + 8 * i); + + CurrentPosition += Lengths[i] % 0x200 == 0 ? Lengths[i] : 0x200 - Lengths[i] % 0x200 + Lengths[i]; + + if (BlockIDs[i] != 0 || i == 0) continue; + count = i; + break; + } + // Apply checksums + for (int i = 0; i < count; i++) + { + ushort chk = ccitt16(savefile.Skip(Start[i]).Take(Lengths[i]).ToArray()); + ushort old = BitConverter.ToUInt16(savefile, verificationOffset + 6 + i * 8); + + if (chk == old) continue; + + invalid++; + rv += $"Invalid: {i.ToString("X2")} @ Region {Start[i].ToString("X5") + Environment.NewLine}"; + } + // Return Outputs + rv += $"SAV: {count - invalid}/{count + Environment.NewLine}"; + return rv; + } + /// Fix checksums in the input save file. + /// Input binary file + /// Fixed save file. + internal static void writeG6CHK(byte[] savefile) + { + // Dynamic handling of checksums regardless of save size. + + int verificationOffset = savefile.Length - 0x200 + 0x10; + if (BitConverter.ToUInt32(savefile, verificationOffset) != BEEF) + verificationOffset -= 0x200; // No savegames have more than 0x3D blocks, maybe in the future? + + int count = (savefile.Length - verificationOffset - 0x8) / 8; + verificationOffset += 4; + int[] Lengths = new int[count]; + ushort[] BlockIDs = new ushort[count]; + ushort[] Checksums = new ushort[count]; + int[] Start = new int[count]; + int CurrentPosition = 0; + for (int i = 0; i < count; i++) + { + Start[i] = CurrentPosition; + Lengths[i] = BitConverter.ToInt32(savefile, verificationOffset + 0 + 8 * i); + BlockIDs[i] = BitConverter.ToUInt16(savefile, verificationOffset + 4 + 8 * i); + Checksums[i] = BitConverter.ToUInt16(savefile, verificationOffset + 6 + 8 * i); + + CurrentPosition += Lengths[i] % 0x200 == 0 ? Lengths[i] : 0x200 - Lengths[i] % 0x200 + Lengths[i]; + + if (BlockIDs[i] != 0 || i == 0) continue; + count = i; + break; + } + // Apply checksums + for (int i = 0; i < count; i++) + { + byte[] array = savefile.Skip(Start[i]).Take(Lengths[i]).ToArray(); + BitConverter.GetBytes(ccitt16(array)).CopyTo(savefile, verificationOffset + 6 + i * 8); + } + } + + internal static int getDexFormIndexXY(int species, int formct) + { + if (formct < 1 || species < 0) + return -1; // invalid + switch (species) + { + case 201: return 000; // 28 Unown + case 386: return 028; // 4 Deoxys + case 492: return 032; // 2 Shaymin + case 487: return 034; // 2 Giratina + case 479: return 036; // 6 Rotom + case 422: return 042; // 2 Shellos + case 423: return 044; // 2 Gastrodon + case 412: return 046; // 3 Burmy + case 413: return 049; // 3 Wormadam + case 351: return 052; // 4 Castform + case 421: return 056; // 2 Cherrim + case 585: return 058; // 4 Deerling + case 586: return 062; // 4 Sawsbuck + case 648: return 066; // 2 Meloetta + case 555: return 068; // 2 Darmanitan + case 550: return 070; // 2 Basculin + case 646: return 072; // 3 Kyurem + case 647: return 075; // 2 Keldeo + case 642: return 077; // 2 Thundurus + case 641: return 079; // 2 Tornadus + case 645: return 081; // 2 Landorus + case 666: return 083; // 20 Vivillion + case 669: return 103; // 5 Flabébé + case 670: return 108; // 6 Floette + case 671: return 114; // 5 Florges + case 710: return 119; // 4 Pumpkaboo + case 711: return 123; // 4 Gourgeist + case 681: return 127; // 2 Aegislash + case 716: return 129; // 2 Xerneas + case 003: return 131; // 2 Venusaur + case 006: return 133; // 3 Charizard + case 009: return 136; // 2 Blastoise + case 065: return 138; // 2 Alakazam + case 094: return 140; // 2 Gengar + case 115: return 142; // 2 Kangaskhan + case 127: return 144; // 2 Pinsir + case 130: return 146; // 2 Gyarados + case 142: return 148; // 2 Aerodactyl + case 150: return 150; // 3 Mewtwo + case 181: return 153; // 2 Ampharos + case 212: return 155; // 2 Scizor + case 214: return 157; // 2 Heracros + case 229: return 159; // 2 Houndoom + case 248: return 161; // 2 Tyranitar + case 257: return 163; // 2 Blaziken + case 282: return 165; // 2 Gardevoir + case 303: return 167; // 2 Mawile + case 306: return 169; // 2 Aggron + case 308: return 171; // 2 Medicham + case 310: return 173; // 2 Manetric + case 354: return 175; // 2 Banette + case 359: return 177; // 2 Absol + case 380: return 179; // 2 Latias + case 381: return 181; // 2 Latios + case 445: return 183; // 2 Garchomp + case 448: return 185; // 2 Lucario + case 460: return 187; // 2 Abomasnow + default: return -1; + } + } + internal static int getDexFormIndexORAS(int species, int formct) + { + if (formct < 1 || species < 0) + return -1; // invalid + switch (species) + { + case 025: return 189; // 7 Pikachu + case 720: return 196; // 2 Hoopa + case 015: return 198; // 2 Beedrill + case 018: return 200; // 2 Pidgeot + case 080: return 202; // 2 Slowbro + case 208: return 204; // 2 Steelix + case 254: return 206; // 2 Sceptile + case 360: return 208; // 2 Swampert + case 302: return 210; // 2 Sableye + case 319: return 212; // 2 Sharpedo + case 323: return 214; // 2 Camerupt + case 334: return 216; // 2 Altaria + case 362: return 218; // 2 Glalie + case 373: return 220; // 2 Salamence + case 376: return 222; // 2 Metagross + case 384: return 224; // 2 Rayquaza + case 428: return 226; // 2 Lopunny + case 475: return 228; // 2 Gallade + case 531: return 230; // 2 Audino + case 719: return 232; // 2 Diancie + case 382: return 234; // 2 Kyogre + case 383: return 236; // 2 Groudon + case 493: return 238; // 18 Arceus + case 649: return 256; // 5 Genesect + case 676: return 261; // 10 Furfrou + default: return getDexFormIndexXY(species, formct); + } + } + } +} From e784389ad23fe84efd5805d789bea52166503bfb Mon Sep 17 00:00:00 2001 From: Kaphotics Date: Sun, 19 Jun 2016 21:29:38 -0700 Subject: [PATCH 10/49] Manually merge latest pull requests Should have forked to begin with. Thanks @chenzw95 && @Eskuero --- Legality/Checks.cs | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/Legality/Checks.cs b/Legality/Checks.cs index 08500ec93..4f8cd46e9 100644 --- a/Legality/Checks.cs +++ b/Legality/Checks.cs @@ -560,6 +560,8 @@ private LegalityCheck verifyBall() { if (Legal.Ban_Gen3Ball.Contains(pk6.Species)) return new LegalityCheck(Severity.Invalid, "Unobtainable capture for Gen4 Ball."); + if (pk6.AbilityNumber == 4 && 152 <= pk6.Species && pk6.Species <= 160) + return new LegalityCheck(Severity.Invalid, "Ball not possible for species with hidden ability."); return new LegalityCheck(Severity.Valid, "Obtainable capture for Gen4 Ball."); } @@ -570,7 +572,7 @@ private LegalityCheck verifyBall() private LegalityCheck verifyHistory() { if (!Encounter.Valid) - return new LegalityCheck(Severity.Valid, "Skipped Memory check due to other check being invalid."); + return new LegalityCheck(Severity.Valid, "Skipped History check due to other check being invalid."); WC6 MatchedWC6 = EncounterMatch as WC6; if (MatchedWC6?.OT.Length > 0) // Has Event OT -- null propagation yields false if MatchedWC6=null @@ -581,14 +583,6 @@ private LegalityCheck verifyHistory() return new LegalityCheck(Severity.Invalid, "Event OT Affection should be zero."); if (pk6.CurrentHandler != 1) return new LegalityCheck(Severity.Invalid, "Current handler should not be Event OT."); - if (pk6.OT_Memory != MatchedWC6.OT_Memory) - return new LegalityCheck(Severity.Invalid, "Event " + (MatchedWC6.OT_Memory == 0 ? "should not have an OT Memory" : "OT Memory should be index " + MatchedWC6.OT_Memory) + "."); - if (pk6.OT_Intensity != MatchedWC6.OT_Intensity) - return new LegalityCheck(Severity.Invalid, "Event " + (MatchedWC6.OT_Intensity == 0 ? "should not have an OT Memory Intensity value" : "OT Memory Intensity should be index " + MatchedWC6.OT_Intensity) + "."); - if (pk6.OT_TextVar != MatchedWC6.OT_TextVar) - return new LegalityCheck(Severity.Invalid, "Event " + (MatchedWC6.OT_TextVar == 0 ? "should not have an OT Memory TextVar value" : "OT Memory TextVar should be index " + MatchedWC6.OT_TextVar) + "."); - if (pk6.OT_Feeling != MatchedWC6.OT_Feeling) - return new LegalityCheck(Severity.Invalid, "Event " + (MatchedWC6.OT_Feeling == 0 ? "should not have an OT Memory Feeling value" : "OT Memory Feeling should be index " + MatchedWC6.OT_Feeling) + "."); } if (!pk6.WasEvent && !(pk6.WasLink && (EncounterMatch as EncounterLink)?.OT == false) && (pk6.HT_Name.Length == 0 || pk6.Geo1_Country == 0)) // Is not Traded { @@ -696,10 +690,15 @@ private LegalityCheck verifyOTMemory() } if (EncounterType == typeof(WC6)) { - if (pk6.OT_Memory != 0) - return new LegalityCheck(Severity.Invalid, "Event Pokémon should not have an OT memory."); - - return new LegalityCheck(Severity.Valid, "OT Memory (Event) is valid."); + WC6 MatchedWC6 = EncounterMatch as WC6; + if (pk6.OT_Memory != MatchedWC6.OT_Memory) + return new LegalityCheck(Severity.Invalid, "Event " + (MatchedWC6.OT_Memory == 0 ? "should not have an OT Memory" : "OT Memory should be index " + MatchedWC6.OT_Memory) + "."); + if (pk6.OT_Intensity != MatchedWC6.OT_Intensity) + return new LegalityCheck(Severity.Invalid, "Event " + (MatchedWC6.OT_Intensity == 0 ? "should not have an OT Memory Intensity value" : "OT Memory Intensity should be index " + MatchedWC6.OT_Intensity) + "."); + if (pk6.OT_TextVar != MatchedWC6.OT_TextVar) + return new LegalityCheck(Severity.Invalid, "Event " + (MatchedWC6.OT_TextVar == 0 ? "should not have an OT Memory TextVar value" : "OT Memory TextVar should be index " + MatchedWC6.OT_TextVar) + "."); + if (pk6.OT_Feeling != MatchedWC6.OT_Feeling) + return new LegalityCheck(Severity.Invalid, "Event " + (MatchedWC6.OT_Feeling == 0 ? "should not have an OT Memory Feeling value" : "OT Memory Feeling should be index " + MatchedWC6.OT_Feeling) + "."); } switch (pk6.OT_Memory) { From e6a4f4cce13e8200bc356c95585f74a76e1fa07b Mon Sep 17 00:00:00 2001 From: Kaphotics Date: Sun, 19 Jun 2016 22:11:53 -0700 Subject: [PATCH 11/49] Add .dsv support Even catches the 1MB misconfigured DSV's (stuffs the bak data in with the footer). Works by searching for the DeSmuME footer signature in the input data, if present, breaking up the info. --- PKX/f1-Main.cs | 20 +++++++++++++++++--- Saves/SAV4.cs | 2 ++ Saves/SAV5.cs | 2 ++ Saves/SAV6.cs | 2 ++ Saves/SaveFile.cs | 9 +++++++-- Saves/SaveUtil.cs | 5 ++--- 6 files changed, 32 insertions(+), 8 deletions(-) diff --git a/PKX/f1-Main.cs b/PKX/f1-Main.cs index 153d0f277..83e0ba37b 100644 --- a/PKX/f1-Main.cs +++ b/PKX/f1-Main.cs @@ -512,6 +512,18 @@ private void openQuick(string path, bool force = false) private void openFile(byte[] input, string path, string ext) { MysteryGift tg; PKM temp; string c; + byte[] footer = new byte[0]; + #region DeSmuME .dsv detect + if (input.Length > SaveUtil.SIZE_G4RAW) + { + bool dsv = SaveUtil.FOOTER_DSV.SequenceEqual(input.Skip(input.Length - SaveUtil.FOOTER_DSV.Length).Take(SaveUtil.FOOTER_DSV.Length)); + if (dsv) + { + footer = input.Skip(SaveUtil.SIZE_G4RAW).ToArray(); + input = input.Take(SaveUtil.SIZE_G4RAW).ToArray(); + } + } + #endregion #region Powersaves Read-Only Conversion if (input.Length == 0x10009C) // Resize to 1MB { @@ -541,7 +553,7 @@ private void openFile(byte[] input, string path, string ext) #endregion #region SAV/PKM else if (SaveUtil.getSAVGeneration(input) > -1) // Supports Gen4/5/6 - openSAV(input, path); + { openSAV(input, path); SAV.Footer = footer; } else if ((temp = PKMConverter.getPKMfromBytes(input)) != null) { PKM pk = PKMConverter.convertToFormat(temp, SAV.Generation, out c); @@ -3141,7 +3153,7 @@ private void clickExportSAV(object sender, EventArgs e) SaveFileDialog main = new SaveFileDialog { - Filter = "Main SAV|*.*", + Filter = SAV.Filter, FileName = SAV.FileName, RestoreDirectory = true }; @@ -3153,7 +3165,9 @@ private void clickExportSAV(object sender, EventArgs e) if (SAV.HasBox) SAV.CurrentBox = CB_BoxSelect.SelectedIndex; - File.WriteAllBytes(main.FileName, SAV.Write()); + + bool dsv = Path.GetExtension(main.FileName).ToLower() == ".dsv"; + File.WriteAllBytes(main.FileName, SAV.Write(dsv)); Util.Alert("SAV exported to:", main.FileName); } diff --git a/Saves/SAV4.cs b/Saves/SAV4.cs index 36b90303a..9867a1f7a 100644 --- a/Saves/SAV4.cs +++ b/Saves/SAV4.cs @@ -6,6 +6,8 @@ namespace PKHeX public sealed class SAV4 : SaveFile { public override string BAKName => $"{FileName} [{OT} ({Version})" +/* - {LastSavedTime}*/ "].bak"; + public override string Filter => (Footer.Length > 0 ? "DeSmuME DSV|*.dsv|" : "") + "SAV File|*.sav"; + public override string Extension => ".sav"; public SAV4(byte[] data = null) { Data = data == null ? new byte[SaveUtil.SIZE_G4RAW] : (byte[])data.Clone(); diff --git a/Saves/SAV5.cs b/Saves/SAV5.cs index b9c031a5d..81c40cf11 100644 --- a/Saves/SAV5.cs +++ b/Saves/SAV5.cs @@ -8,6 +8,8 @@ public sealed class SAV5 : SaveFile { // Save Data Attributes public override string BAKName => $"{FileName} [{OT} ({Version})" +/* - {LastSavedTime}*/ "].bak"; + public override string Filter => (Footer.Length > 0 ? "DeSmuME DSV|*.dsv|" : "") + "SAV File|*.sav*"; + public override string Extension => ".sav"; public SAV5(byte[] data = null) { Data = data == null ? new byte[SaveUtil.SIZE_G5RAW] : (byte[])data.Clone(); diff --git a/Saves/SAV6.cs b/Saves/SAV6.cs index 882a8e428..e7b73b445 100644 --- a/Saves/SAV6.cs +++ b/Saves/SAV6.cs @@ -8,6 +8,8 @@ public sealed class SAV6 : SaveFile { // Save Data Attributes public override string BAKName => $"{FileName} [{OT} ({Version}) - {LastSavedTime}].bak"; + public override string Filter => "Main SAV|*.*"; + public override string Extension => ""; public SAV6(byte[] data = null) { Data = data == null ? new byte[SaveUtil.SIZE_G6ORAS] : (byte[])data.Clone(); diff --git a/Saves/SaveFile.cs b/Saves/SaveFile.cs index de8039182..717fddf86 100644 --- a/Saves/SaveFile.cs +++ b/Saves/SaveFile.cs @@ -17,6 +17,8 @@ public abstract class SaveFile public abstract byte[] BAK { get; } public abstract bool Exportable { get; } public abstract SaveFile Clone(); + public abstract string Filter { get; } + public byte[] Footer { protected get; set; } // .dsv // General PKM Properties protected abstract Type PKMType { get; } @@ -29,9 +31,11 @@ public abstract class SaveFile public ushort[] HeldItems { get; protected set; } // General SAV Properties - public byte[] Write() + public byte[] Write(bool DSV) { setChecksums(); + if (Footer.Length > 0 && DSV) + return Data.Concat(Footer).ToArray(); return Data; } public virtual string MiscSaveChecks() { return ""; } @@ -274,7 +278,8 @@ public virtual MysteryGiftAlbum GiftAlbum public abstract int BoxCount { get; } public abstract int PartyCount { get; protected set; } public virtual int CurrentBox { get { return 0; } set { } } - + public abstract string Extension { get; } + // Varied Methods protected abstract void setChecksums(); public abstract int getBoxOffset(int box); diff --git a/Saves/SaveUtil.cs b/Saves/SaveUtil.cs index e8c05db91..cd0dc462d 100644 --- a/Saves/SaveUtil.cs +++ b/Saves/SaveUtil.cs @@ -1,5 +1,6 @@ using System; using System.Linq; +using System.Text; namespace PKHeX { @@ -28,9 +29,7 @@ internal static class SaveUtil internal const int SIZE_G5B2W2 = 0x26000; internal const int SIZE_G4RAW = 0x80000; - internal static readonly byte[] EncryptedBlank4 = PKX.encryptArray45(new byte[PKX.SIZE_4PARTY]); - internal static readonly byte[] EncryptedBlank5 = PKX.encryptArray45(new byte[PKX.SIZE_5PARTY]); - internal static readonly byte[] EncryptedBlank6 = PKX.encryptArray(new byte[PKX.SIZE_6PARTY]); + internal static readonly byte[] FOOTER_DSV = Encoding.ASCII.GetBytes("|-DESMUME SAVE-|"); internal static int getSAVGeneration(byte[] data) { From 1da183a8cce1ba1e41cc34eb8813fb854ecc9d86 Mon Sep 17 00:00:00 2001 From: Kaphotics Date: Sun, 19 Jun 2016 22:13:57 -0700 Subject: [PATCH 12/49] Minor tweak SAV5 change didn't get saved no need to "take" the rest of the data when footer checking. this logic can be expanded if other emulators behave differently... --- PKX/f1-Main.cs | 2 +- Saves/SAV5.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/PKX/f1-Main.cs b/PKX/f1-Main.cs index 83e0ba37b..78c6bfe8b 100644 --- a/PKX/f1-Main.cs +++ b/PKX/f1-Main.cs @@ -516,7 +516,7 @@ private void openFile(byte[] input, string path, string ext) #region DeSmuME .dsv detect if (input.Length > SaveUtil.SIZE_G4RAW) { - bool dsv = SaveUtil.FOOTER_DSV.SequenceEqual(input.Skip(input.Length - SaveUtil.FOOTER_DSV.Length).Take(SaveUtil.FOOTER_DSV.Length)); + bool dsv = SaveUtil.FOOTER_DSV.SequenceEqual(input.Skip(input.Length - SaveUtil.FOOTER_DSV.Length)); if (dsv) { footer = input.Skip(SaveUtil.SIZE_G4RAW).ToArray(); diff --git a/Saves/SAV5.cs b/Saves/SAV5.cs index 81c40cf11..f70a3462e 100644 --- a/Saves/SAV5.cs +++ b/Saves/SAV5.cs @@ -8,7 +8,7 @@ public sealed class SAV5 : SaveFile { // Save Data Attributes public override string BAKName => $"{FileName} [{OT} ({Version})" +/* - {LastSavedTime}*/ "].bak"; - public override string Filter => (Footer.Length > 0 ? "DeSmuME DSV|*.dsv|" : "") + "SAV File|*.sav*"; + public override string Filter => (Footer.Length > 0 ? "DeSmuME DSV|*.dsv|" : "") + "SAV File|*.sav"; public override string Extension => ".sav"; public SAV5(byte[] data = null) { From 28141729a9896b81a07b5211ee15d11e6a145481 Mon Sep 17 00:00:00 2001 From: Kaphotics Date: Mon, 20 Jun 2016 18:58:06 -0700 Subject: [PATCH 13/49] Limit PKX dropdowns when Version changes Filters out choices that are not obtainable in the loaded version of game (such as new Mega Stones). --- PKX/f1-Main.cs | 47 +++++++++++++++++++++++++++++------------------ Saves/SAV4.cs | 7 +++++++ Saves/SAV5.cs | 7 +++++++ Saves/SAV6.cs | 9 +++++++++ Saves/SaveFile.cs | 7 +++++++ 5 files changed, 59 insertions(+), 18 deletions(-) diff --git a/PKX/f1-Main.cs b/PKX/f1-Main.cs index 78c6bfe8b..2ff695a45 100644 --- a/PKX/f1-Main.cs +++ b/PKX/f1-Main.cs @@ -762,7 +762,7 @@ private void openSAV(byte[] input, string path) GB_nOT.Visible = BTN_History.Visible = true; Label_EncryptionConstant.Visible = BTN_RerollEC.Visible = TB_EC.Visible = true; PB_MarkPentagon.Visible = true; - PB_Legal.Visible = PB_WarnMove1.Visible = PB_WarnMove2.Visible = PB_WarnMove3.Visible = PB_WarnMove4.Visible = !HaX; + PB_Legal.Visible = PB_WarnMove1.Visible = PB_WarnMove2.Visible = PB_WarnMove3.Visible = PB_WarnMove4.Visible = true; CB_Ability.Visible = !HaX; extraBytes = PK6.ExtraBytes; @@ -773,9 +773,9 @@ private void openSAV(byte[] input, string path) break; } - // Clear PKM fields if generation has changed - if (pkm.Format != SAV.Generation) - populateFields(SAV.BlankPKM); + pkm = preparePKM(); + populateFilteredDataSources(); + populateFields(pkm.Format != SAV.Generation ? SAV.BlankPKM : pkm); // SAV Specific Limits TB_OT.MaxLength = SAV.OTLength; @@ -784,6 +784,7 @@ private void openSAV(byte[] input, string path) // Common HaX Interface CHK_HackedStats.Enabled = CHK_HackedStats.Visible = MT_Level.Enabled = MT_Level.Visible = MT_Form.Enabled = MT_Form.Visible = HaX; + PB_Legal.Visible = PB_WarnMove1.Visible = PB_WarnMove2.Visible = PB_WarnMove3.Visible = PB_WarnMove4.Visible &= !HaX; TB_Level.Visible = !HaX; // Load Extra Byte List @@ -871,10 +872,14 @@ private void InitializeStrings() } // Fix Item Names (Duplicate entries) - itemlist[456] += " (OLD)"; // S.S. Ticket - itemlist[463] += " (OLD)"; // Storage Key - itemlist[478] += " (OLD)"; // Basement Key - itemlist[626] += " (2)"; // Xtransceiver + itemlist[456] += " (HG/SS)"; // S.S. Ticket + itemlist[736] += " (OR/AS)"; // S.S. Ticket + itemlist[463] += " (DPPt)"; // Storage Key + itemlist[734] += " (OR/AS)"; // Storage Key + itemlist[478] += " (HG/SS)"; // Basement Key + itemlist[478] += " (OR/AS)"; // Basement Key + itemlist[621] += " (M)"; // Xtransceiver + itemlist[626] += " (F)"; // Xtransceiver itemlist[629] += " (2)"; // DNA Splicers itemlist[637] += " (2)"; // Dropped Item itemlist[707] += " (2)"; // Travel Trunk @@ -990,28 +995,34 @@ private void InitializeLanguage() int[] ball_nums = { 7, 576, 13, 492, 497, 14, 495, 493, 496, 494, 11, 498, 8, 6, 12, 15, 9, 5, 499, 10, 1, 16 }; int[] ball_vals = { 7, 25, 13, 17, 22, 14, 20, 18, 21, 19, 11, 23, 8, 6, 12, 15, 9, 5, 24, 10, 1, 16 }; BallDataSource = Util.getVariedCBList(itemlist, ball_nums, ball_vals); - ItemDataSource = Util.getCBList(itemlist, HaX ? null : Legal.HeldItem_AO.Select(i => (int)i).ToArray()); SpeciesDataSource = Util.getCBList(specieslist, null); NatureDataSource = Util.getCBList(natures, null); AbilityDataSource = Util.getCBList(abilitylist, null); VersionDataSource = Util.getCBList(gamelist, Legal.Games_6oras, Legal.Games_6xy, Legal.Games_5, Legal.Games_4, Legal.Games_4e, Legal.Games_4r, Legal.Games_3, Legal.Games_3e, Legal.Games_3r, Legal.Games_3s); - CB_Ball.DataSource = new BindingSource(BallDataSource, null); - CB_Species.DataSource = new BindingSource(SpeciesDataSource, null); - CB_HeldItem.DataSource = new BindingSource(ItemDataSource, null); + MoveDataSource = Util.getCBList(movelist, null); + + CB_EncounterType.DataSource = Util.getCBList(encountertypelist, new[] { 0 }, Legal.Gen4EncounterTypes); + CB_HPType.DataSource = Util.getCBList(types.Skip(1).Take(16).ToArray(), null); CB_Nature.DataSource = new BindingSource(NatureDataSource, null); - DEV_Ability.DataSource = new BindingSource(AbilityDataSource, null); - CB_EncounterType.DataSource = Util.getCBList(encountertypelist, new[] { 0 }, Legal.Gen4EncounterTypes); - CB_GameOrigin.DataSource = new BindingSource(VersionDataSource, null); - CB_HPType.DataSource = Util.getCBList(types.Skip(1).Take(16).ToArray(), null); + populateFilteredDataSources(); + } + private void populateFilteredDataSources() + { + ItemDataSource = Util.getCBList(itemlist, (HaX ? Enumerable.Range(0, SAV.MaxItemID) : SAV.HeldItems.Select(i => (int)i)).ToArray()); + CB_HeldItem.DataSource = new BindingSource(ItemDataSource.Where(i => i.Value <= SAV.MaxItemID), null); + + CB_Ball.DataSource = new BindingSource(BallDataSource.Where(b => b.Value <= SAV.MaxBallID), null); + CB_Species.DataSource = new BindingSource(SpeciesDataSource.Where(s => s.Value <= SAV.MaxSpeciesID), null); + DEV_Ability.DataSource = new BindingSource(AbilityDataSource.Where(a => a.Value <= SAV.MaxAbilityID), null); + CB_GameOrigin.DataSource = new BindingSource(VersionDataSource.Where(g => g.Value <= SAV.MaxGameID), null); // Set the Move ComboBoxes too.. - MoveDataSource = Util.getCBList(movelist, null); foreach (ComboBox cb in new[] { CB_Move1, CB_Move2, CB_Move3, CB_Move4, CB_RelearnMove1, CB_RelearnMove2, CB_RelearnMove3, CB_RelearnMove4 }) { cb.DisplayMember = "Text"; cb.ValueMember = "Value"; - cb.DataSource = new BindingSource(MoveDataSource, null); + cb.DataSource = new BindingSource(MoveDataSource.Where(m => m.Value <= SAV.MaxMoveID), null); } } public void populateFields(PKM pk, bool focus = true) diff --git a/Saves/SAV4.cs b/Saves/SAV4.cs index 9867a1f7a..2ddac43e1 100644 --- a/Saves/SAV4.cs +++ b/Saves/SAV4.cs @@ -43,6 +43,13 @@ public SAV4(byte[] data = null) public override int OTLength => 8; public override int NickLength => 10; + public override int MaxMoveID => 467; + public override int MaxSpeciesID => 493; + public override int MaxItemID => Version == GameVersion.HGSS ? 536 : Version == GameVersion.Pt ? 467 : 464; + public override int MaxAbilityID => 123; + public override int MaxBallID => 0x18; + public override int MaxGameID => 15; // Colo/XD + // Checksums protected override void setChecksums() { diff --git a/Saves/SAV5.cs b/Saves/SAV5.cs index f70a3462e..7718fd095 100644 --- a/Saves/SAV5.cs +++ b/Saves/SAV5.cs @@ -96,6 +96,13 @@ public SAV5(byte[] data = null) protected override int EventConstMax => 0x35E/2; protected override int GiftCountMax => 12; + public override int MaxMoveID => 559; + public override int MaxSpeciesID => 649; + public override int MaxItemID => SaveVersion == 1 ? 632 : 638; + public override int MaxAbilityID => 164; + public override int MaxBallID => 0x19; + public override int MaxGameID => 23; // B2 + // Blocks & Offsets private BlockInfo[] Blocks; private void getBlockInfo() diff --git a/Saves/SAV6.cs b/Saves/SAV6.cs index e7b73b445..e2b2b9da5 100644 --- a/Saves/SAV6.cs +++ b/Saves/SAV6.cs @@ -20,6 +20,8 @@ public SAV6(byte[] data = null) getBlockInfo(); getSAVOffsets(); + HeldItems = ORAS ? Legal.HeldItem_AO : Legal.HeldItem_XY; + if (!Exportable) resetBoxes(); } @@ -44,6 +46,13 @@ public SAV6(byte[] data = null) public override int OTLength => 12; public override int NickLength => 12; + public override int MaxMoveID => XY ? 617 : 621; + public override int MaxSpeciesID => 721; + public override int MaxItemID => XY ? 717 : 775; + public override int MaxAbilityID => XY ? 188 : 191; + public override int MaxBallID => 0x19; + public override int MaxGameID => 27; // OR + // Feature Overrides public override bool HasGeolocation => true; diff --git a/Saves/SaveFile.cs b/Saves/SaveFile.cs index 717fddf86..0ee735328 100644 --- a/Saves/SaveFile.cs +++ b/Saves/SaveFile.cs @@ -49,6 +49,13 @@ public byte[] Write(bool DSV) public bool ORAS => Version == GameVersion.OR || Version == GameVersion.AS; public bool XY => Version == GameVersion.X || Version == GameVersion.Y; + public virtual int MaxMoveID => int.MaxValue; + public virtual int MaxSpeciesID => int.MaxValue; + public virtual int MaxAbilityID => int.MaxValue; + public virtual int MaxItemID => int.MaxValue; + public virtual int MaxBallID => int.MaxValue; + public virtual int MaxGameID => int.MaxValue; + // Flags public bool HasWondercards => WondercardData > -1; public bool HasSuperTrain => SuperTrain > -1; From 0d477a0153e31c1d3b7a1a7d2aac7cb801d2107b Mon Sep 17 00:00:00 2001 From: Kaphotics Date: Mon, 20 Jun 2016 19:07:40 -0700 Subject: [PATCH 14/49] Futureproof gen6 subforms Species selection should be limited to species available in game; upon adding S&M these comboboxes are ready! The CB_HeldItem in SAV_SecretBase doesn't need filtering as it is limited when the SAV is loaded to the main form. --- SAV/SAV_HallOfFame.cs | 4 +--- SAV/SAV_PokedexORAS.cs | 7 +++---- SAV/SAV_PokedexXY.cs | 7 +++---- SAV/SAV_SecretBase.cs | 5 +++-- SAV/SAV_SuperTrain.cs | 5 +++-- 5 files changed, 13 insertions(+), 15 deletions(-) diff --git a/SAV/SAV_HallOfFame.cs b/SAV/SAV_HallOfFame.cs index f074973a0..5a676bf22 100644 --- a/SAV/SAV_HallOfFame.cs +++ b/SAV/SAV_HallOfFame.cs @@ -67,11 +67,9 @@ private void Setup() #region Species { - var species_list = Util.getCBList(Main.specieslist, null); - species_list.RemoveAt(0); // Remove 0th Entry CB_Species.DisplayMember = "Text"; CB_Species.ValueMember = "Value"; - CB_Species.DataSource = species_list; + CB_Species.DataSource = Util.getCBList(Main.specieslist.Skip(1).Take(SAV.MaxSpeciesID).ToArray(), null); } #endregion #region Moves diff --git a/SAV/SAV_PokedexORAS.cs b/SAV/SAV_PokedexORAS.cs index db0fc4eaa..71daec422 100644 --- a/SAV/SAV_PokedexORAS.cs +++ b/SAV/SAV_PokedexORAS.cs @@ -1,6 +1,7 @@ using System; using System.Collections; using System.Drawing; +using System.Linq; using System.Windows.Forms; namespace PKHeX @@ -20,13 +21,11 @@ public SAV_PokedexORAS() CB_Species.Items.Clear(); // Fill List - var species_list = Util.getCBList(Main.specieslist, null); - species_list.RemoveAt(0); // Remove 0th Entry CB_Species.DisplayMember = "Text"; CB_Species.ValueMember = "Value"; - CB_Species.DataSource = species_list; + CB_Species.DataSource = Util.getCBList(Main.specieslist.Skip(1).Take(SAV.MaxSpeciesID).ToArray(), null); - for (int i = 1; i < Main.specieslist.Length; i++) + for (int i = 1; i < SAV.MaxSpeciesID + 1; i++) LB_Species.Items.Add(i.ToString("000") + " - " + Main.specieslist[i]); getData(); diff --git a/SAV/SAV_PokedexXY.cs b/SAV/SAV_PokedexXY.cs index f2da38632..8eb4f4927 100644 --- a/SAV/SAV_PokedexXY.cs +++ b/SAV/SAV_PokedexXY.cs @@ -1,6 +1,7 @@ using System; using System.Collections; using System.Drawing; +using System.Linq; using System.Windows.Forms; namespace PKHeX @@ -20,13 +21,11 @@ public SAV_PokedexXY() CB_Species.Items.Clear(); // Fill List - var species_list = Util.getCBList(Main.specieslist, null); - species_list.RemoveAt(0); // Remove 0th Entry CB_Species.DisplayMember = "Text"; CB_Species.ValueMember = "Value"; - CB_Species.DataSource = species_list; + CB_Species.DataSource = Util.getCBList(Main.specieslist.Skip(1).Take(SAV.MaxSpeciesID).ToArray(), null); - for (int i = 1; i < Main.specieslist.Length; i++) + for (int i = 1; i < SAV.MaxSpeciesID + 1; i++) LB_Species.Items.Add(i.ToString("000") + " - " + Main.specieslist[i]); getData(); diff --git a/SAV/SAV_SecretBase.cs b/SAV/SAV_SecretBase.cs index de8f152ef..35a8fecca 100644 --- a/SAV/SAV_SecretBase.cs +++ b/SAV/SAV_SecretBase.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; using System.Text; using System.Windows.Forms; @@ -33,9 +34,9 @@ private void setupComboBoxes() CB_Ball.DisplayMember = CB_HeldItem.DisplayMember = CB_Species.DisplayMember = CB_Nature.DisplayMember = "Text"; CB_Ball.ValueMember = CB_HeldItem.ValueMember = CB_Species.ValueMember = CB_Nature.ValueMember = "Value"; - CB_Ball.DataSource = new BindingSource(Main.BallDataSource, null); + CB_Ball.DataSource = new BindingSource(Main.BallDataSource.Where(b => b.Value <= SAV.MaxBallID), null); CB_HeldItem.DataSource = new BindingSource(Main.ItemDataSource, null); - CB_Species.DataSource = new BindingSource(Main.SpeciesDataSource, null); + CB_Species.DataSource = new BindingSource(Main.SpeciesDataSource.Where(s => s.Value <= SAV.MaxSpeciesID), null); CB_Nature.DataSource = new BindingSource(Main.NatureDataSource, null); diff --git a/SAV/SAV_SuperTrain.cs b/SAV/SAV_SuperTrain.cs index 2ba7a5fa8..69263f969 100644 --- a/SAV/SAV_SuperTrain.cs +++ b/SAV/SAV_SuperTrain.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; using System.Windows.Forms; namespace PKHeX @@ -45,11 +46,11 @@ private void setup() { CB_Species.DisplayMember = "Text"; CB_Species.ValueMember = "Value"; - CB_Species.DataSource = new BindingSource(Main.SpeciesDataSource, null); + CB_Species.DataSource = new BindingSource(Main.SpeciesDataSource.Where(s => s.Value <= SAV.MaxSpeciesID), null); CB_S2.DisplayMember = "Text"; CB_S2.ValueMember = "Value"; - CB_S2.DataSource = new BindingSource(Main.SpeciesDataSource, null); + CB_S2.DataSource = new BindingSource(Main.SpeciesDataSource.Where(s => s.Value <= SAV.MaxSpeciesID), null); } listBox1.SelectedIndex = 0; fillTrainingBags(); From 5386bb738d111a80fe1116f345d43acadab5c1cc Mon Sep 17 00:00:00 2001 From: Kaphotics Date: Mon, 20 Jun 2016 20:58:35 -0700 Subject: [PATCH 15/49] Fix PID changing for gen4 pkm Filling the EC textboxes when it is not visible is unnecessary as well. --- PKX/f1-Main.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/PKX/f1-Main.cs b/PKX/f1-Main.cs index 2ff695a45..ed3aabbfa 100644 --- a/PKX/f1-Main.cs +++ b/PKX/f1-Main.cs @@ -1088,7 +1088,6 @@ private void populateFieldsPK4(PK4 pk4) TB_EXP.Text = pk4.EXP.ToString(); // Load rest - TB_EC.Text = pk4.EncryptionConstant.ToString("X8"); CHK_Fateful.Checked = pk4.FatefulEncounter; CHK_IsEgg.Checked = pk4.IsEgg; CHK_Nicknamed.Checked = pk4.IsNicknamed; @@ -1200,7 +1199,6 @@ private void populateFieldsPK5(PK5 pk5) TB_EXP.Text = pk5.EXP.ToString(); // Load rest - TB_EC.Text = pk5.EncryptionConstant.ToString("X8"); CHK_Fateful.Checked = pk5.FatefulEncounter; CHK_IsEgg.Checked = pk5.IsEgg; CHK_Nicknamed.Checked = pk5.IsNicknamed; @@ -2388,7 +2386,7 @@ private void update_ID(object sender, EventArgs e) getQuickFiller(dragout); updateIVs(null, null); // If the EC is changed, EC%6 (Characteristic) might be changed. TB_PID.Select(60, 0); // position cursor at end of field - if (SAV.Generation == 4) + if (SAV.Generation == 4 && fieldsInitialized) { pkm.PID = Util.getHEXval(TB_PID.Text); CB_Nature.SelectedValue = pkm.Nature; From a1d9d25a01f3d162f3861a891c5f00cab710f232 Mon Sep 17 00:00:00 2001 From: Kaphotics Date: Mon, 20 Jun 2016 21:11:48 -0700 Subject: [PATCH 16/49] Hide TSV/PSV on gen<6 --- PKX/f1-Main.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/PKX/f1-Main.cs b/PKX/f1-Main.cs index ed3aabbfa..e4a92d9b9 100644 --- a/PKX/f1-Main.cs +++ b/PKX/f1-Main.cs @@ -723,6 +723,7 @@ private void openSAV(byte[] input, string path) // Generational Interface byte[] extraBytes = new byte[1]; + Tip1.RemoveAll(); Tip2.RemoveAll(); Tip3.RemoveAll(); // TSV/PSV switch (SAV.Generation) { case 4: @@ -2363,6 +2364,8 @@ private void updateShinyPID(object sender, EventArgs e) } private void updateTSV(object sender, EventArgs e) { + if (SAV.Generation < 6) + return; ushort TID = (ushort)Util.ToUInt32(TB_TID.Text); ushort SID = (ushort)Util.ToUInt32(TB_SID.Text); uint TSV = PKX.getTSV(TID, SID); From cb0c5998cdc89127b63be4466cbaa39bb28029b3 Mon Sep 17 00:00:00 2001 From: Kaphotics Date: Mon, 20 Jun 2016 22:59:10 -0700 Subject: [PATCH 17/49] Change argument name, check maxspecies pretty template for the future, I don't like the PKX.Personal reference. If multidex bool setting is added that'd have to change. --- Saves/SAV6.cs | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/Saves/SAV6.cs b/Saves/SAV6.cs index e2b2b9da5..016a7a717 100644 --- a/Saves/SAV6.cs +++ b/Saves/SAV6.cs @@ -654,19 +654,20 @@ protected override void setPKM(PKM pkm) } protected override void setDex(PKM pkm) { - PK6 pk6 = pkm as PK6; if (PokeDex < 0) return; - if (pk6.Species == 0) + if (pkm.Species == 0) + return; + if (pkm.Species > MaxSpeciesID) return; if (Version == GameVersion.Unknown) return; - int bit = pk6.Species - 1; - int lang = pk6.Language - 1; if (lang > 5) lang--; // 0-6 language vals - int origin = pk6.Version; - int gender = pk6.Gender % 2; // genderless -> male - int shiny = pk6.IsShiny ? 1 : 0; + int bit = pkm.Species - 1; + int lang = pkm.Language - 1; if (lang > 5) lang--; // 0-6 language vals + int origin = pkm.Version; + int gender = pkm.Gender % 2; // genderless -> male + int shiny = pkm.IsShiny ? 1 : 0; int shiftoff = shiny * 0x60 * 2 + gender * 0x60 + 0x60; // Set the [Species/Gender/Shiny] Owned Flag @@ -692,13 +693,13 @@ protected override void setDex(PKM pkm) Data[PokeDexLanguageFlags + (bit * 7 + lang) / 8] |= (byte)(1 << ((bit * 7 + lang) % 8)); // Set Form flags - int fc = PKX.Personal[pk6.Species].FormeCount; - int f = ORAS ? SaveUtil.getDexFormIndexORAS(pk6.Species, fc) : SaveUtil.getDexFormIndexXY(pk6.Species, fc); + int fc = PKX.Personal[pkm.Species].FormeCount; + int f = ORAS ? SaveUtil.getDexFormIndexORAS(pkm.Species, fc) : SaveUtil.getDexFormIndexXY(pkm.Species, fc); if (f >= 0) { int FormLen = ORAS ? 0x26 : 0x18; int FormDex = PokeDex + 0x368; - bit = f + pk6.AltForm; + bit = f + pkm.AltForm; // Set Seen Flag Data[FormDex + FormLen * shiny + bit / 8] |= (byte)(1 << (bit % 8)); @@ -712,14 +713,14 @@ protected override void setDex(PKM pkm) } if (!FormDisplayed) { - bit = f + pk6.AltForm; + bit = f + pkm.AltForm; Data[FormDex + FormLen * (2 + shiny) + bit / 8] |= (byte)(1 << (bit % 8)); } } // Set DexNav count (only if not encountered previously) - if (ORAS && getEncounterCount(pk6.Species - 1) == 0) - setEncounterCount(pk6.Species - 1, 1); + if (ORAS && getEncounterCount(pkm.Species - 1) == 0) + setEncounterCount(pkm.Species - 1, 1); } public override byte[] decryptPKM(byte[] data) { From 68f144e040d2322e0be31076afbe03522e57b15b Mon Sep 17 00:00:00 2001 From: Kaphotics Date: Mon, 20 Jun 2016 23:02:26 -0700 Subject: [PATCH 18/49] Re-add PKM property verification Item/move/species (didn't add Ball and Version) being imported from a .pkm or forcefully input now requires the user to OK before it is set to the save. EX: Hyperspace Fury isn't in X/Y, drag from another instance of the program with OR/AS loaded and a Hyperspace Fury move... the user will be alerted of the incompatibility and will be allowed to continue (and fix, if desired). --- PKX/f1-Main.cs | 102 ++++++++++++++++++++++++++++++-------------- SAV/SAV_Database.cs | 2 +- 2 files changed, 71 insertions(+), 33 deletions(-) diff --git a/PKX/f1-Main.cs b/PKX/f1-Main.cs index e4a92d9b9..26ea74541 100644 --- a/PKX/f1-Main.cs +++ b/PKX/f1-Main.cs @@ -202,7 +202,7 @@ private void mainMenuOpen(object sender, EventArgs e) } private void mainMenuSave(object sender, EventArgs e) { - if (!verifiedPKX()) return; + if (!verifiedPKM()) return; PKM pk = preparePKM(); SaveFileDialog sfd = new SaveFileDialog { @@ -418,7 +418,7 @@ private void clickShowdownExportPK6(object sender, EventArgs e) { if (!formInitialized) return; - if (!verifiedPKX()) + if (!verifiedPKM()) { Util.Alert("Fix data before exporting."); return; } Clipboard.SetText(preparePKM().ShowdownText); @@ -1543,7 +1543,7 @@ private void clickQR(object sender, EventArgs e) } else { - if (!verifiedPKX()) return; + if (!verifiedPKM()) return; PKM pkx = preparePKM(); byte[] ekx = pkx.EncryptedBoxData; const string server = "http://loadcode.projectpokemon.org/b1s1.html#"; // Rehosted with permission from LC/MS -- massive thanks! @@ -2589,7 +2589,7 @@ private void openHistory(object sender, EventArgs e) TB_Friendship.Text = pk6.CurrentFriendship.ToString(); } // Open/Save Array Manipulation // - public bool verifiedPKX() + public bool verifiedPKM() { if (ModifierKeys == (Keys.Control | Keys.Shift | Keys.Alt)) return true; // Override @@ -2627,6 +2627,37 @@ public bool verifiedPKX() invalid: { SystemSounds.Exclamation.Play(); return false; } } + private static string[] verifyPKMtoSAV(PKM pk) + { + // Check if PKM properties are outside of the valid range + List errata = new List(); + if (pk.HeldItem > itemlist.Length) + errata.Add($"Item Index beyond range: {pk.HeldItem}"); + else + { + if (pk.HeldItem > SAV.MaxItemID) + errata.Add($"Game can't obtain item: {itemlist[pk.HeldItem]}"); + if (!SAV.HeldItems.Contains((ushort)pk.HeldItem)) + errata.Add($"Game can't hold item: {itemlist[pk.HeldItem]}"); + } + + if (pk.Species > specieslist.Length) + errata.Add($"Species Index beyond range: {pk.HeldItem}"); + else if (SAV.MaxSpeciesID < pk.Species) + errata.Add($"Game can't obtain species: {specieslist[pk.Species]}"); + + if (pk.Moves.Any(m => m > movelist.Length)) + errata.Add($"Item Index beyond range: {string.Join(", ", pk.Moves.Where(m => m > movelist.Length).Select(m => m.ToString()))}"); + else if (pk.Moves.Any(m => m > SAV.MaxMoveID)) + errata.Add($"Game can't have move: {string.Join(", ", pk.Moves.Where(m => m > SAV.MaxMoveID).Select(m => movelist[m]))}"); + + if (pk.Ability > abilitylist.Length) + errata.Add($"Ability Index beyond range: {pk.Ability}"); + else if (pk.Ability > SAV.MaxAbilityID) + errata.Add($"Game can't have ability: {abilitylist[pk.Ability]}"); + + return errata.ToArray(); + } public PKM preparePKM(bool click = true) { if (click) @@ -3084,7 +3115,7 @@ private void dragout_MouseDown(object sender, MouseEventArgs e) clickQR(sender, e); if (e.Button == MouseButtons.Right) return; - if (!verifiedPKX()) + if (!verifiedPKM()) return; // Create Temp File to Drag @@ -3271,7 +3302,7 @@ private void clickView(object sender, EventArgs e) } private void clickSet(object sender, EventArgs e) { - if (!verifiedPKX()) return; + if (!verifiedPKM()) return; int slot = getSlot(sender); if (slot == 30 && (CB_Species.SelectedIndex == 0 || CHK_IsEgg.Checked)) { Util.Alert("Can't have empty/egg first slot."); return; } @@ -3283,7 +3314,11 @@ private void clickSet(object sender, EventArgs e) return; } PKM pk = preparePKM(); - + + string[] errata = verifyPKMtoSAV(pk); + if (errata.Length > 0 && DialogResult.Yes != Util.Prompt(MessageBoxButtons.YesNo, string.Join(Environment.NewLine, errata), "Continue?")) + return; + if (slot >= 30 && slot < 36) // Party SAV.setPartySlot(pk, offset); else if (slot < 30 || (slot >= 36 && slot < 42 && DEV_Ability.Enabled)) @@ -3320,7 +3355,7 @@ private void clickDelete(object sender, EventArgs e) private void clickClone(object sender, EventArgs e) { if (getSlot(sender) > 30) return; // only perform action if cloning to boxes - if (!verifiedPKX()) return; // don't copy garbage to the box + if (!verifiedPKM()) return; // don't copy garbage to the box if (Util.Prompt(MessageBoxButtons.YesNo, $"Clone Pokemon from Editing Tabs to all slots in {CB_BoxSelect.Text}?") != DialogResult.Yes) return; @@ -3338,7 +3373,7 @@ private void clickLegality(object sender, EventArgs e) PKM pk; if (slot >= 0) pk = SAV.getStoredSlot(getPKXOffset(slot)); - else if (verifiedPKX()) + else if (verifiedPKM()) pk = preparePKM(); else return; @@ -3686,6 +3721,8 @@ private void loadBoxesFromDB(string path) if (pk != null) // Write to save { + if (verifyPKMtoSAV(pk).Length > 0) + continue; SAV.setStoredSlot(pk, SAV.getBoxOffset(ctr/30) + ctr%30 * SAV.SIZE_STORED, noSetb); if (pk.Format != temp.Format) // Transferred pastctr++; @@ -3962,29 +3999,32 @@ private void pbBoxSlot_DragDrop(object sender, DragEventArgs e) if (Directory.Exists(files[0])) { loadBoxesFromDB(files[0]); return; } if (pkm_from_offset == 0) { - if (files.Length > 0) + if (files.Length <= 0) + return; + string file = files[0]; + if (!PKX.getIsPKM(new FileInfo(file).Length)) + openQuick(file); + + byte[] data = File.ReadAllBytes(file); + PKM temp = PKMConverter.getPKMfromBytes(data); + string c; + + PKM pk = PKMConverter.convertToFormat(temp, SAV.Generation, out c); + if (pk == null) + { Util.Error(c); Console.WriteLine(c); return; } + + string[] errata = verifyPKMtoSAV(pk); + if (errata.Length > 0) { - FileInfo fi = new FileInfo(files[0]); - if (PKX.getIsPKM(fi.Length)) - { - byte[] data = File.ReadAllBytes(files[0]); - PKM temp = PKMConverter.getPKMfromBytes(data); string c; - - PKM pk = PKMConverter.convertToFormat(temp, SAV.Generation, out c); - if (pk != null) - { - SAV.setStoredSlot(pk, offset); - getQuickFiller(SlotPictureBoxes[slot], pk); - getSlotColor(slot, Properties.Resources.slotSet); - Console.WriteLine(c); - return; - } - Console.WriteLine(c); - } - - // Didn't return, so the file wasn't imported. Open as a normal file. - openQuick(files[0]); + string concat = string.Join(Environment.NewLine, errata); + if (DialogResult.Yes != Util.Prompt(MessageBoxButtons.YesNo, concat, "Continue?")) + { Console.WriteLine(c); Console.WriteLine(concat); return; } } + + SAV.setStoredSlot(pk, offset); + getQuickFiller(SlotPictureBoxes[slot], pk); + getSlotColor(slot, Properties.Resources.slotSet); + Console.WriteLine(c); } else { @@ -4012,8 +4052,6 @@ private void pbBoxSlot_DragDrop(object sender, DragEventArgs e) pkm_from_offset = 0; // Clear offset value } - - SAV.Edited = true; } private void pbBoxSlot_DragEnter(object sender, DragEventArgs e) { diff --git a/SAV/SAV_Database.cs b/SAV/SAV_Database.cs index 92980bf17..2199b6903 100644 --- a/SAV/SAV_Database.cs +++ b/SAV/SAV_Database.cs @@ -189,7 +189,7 @@ private void clickDelete(object sender, EventArgs e) private void clickSet(object sender, EventArgs e) { // Don't care what slot was clicked, just add it to the database - if (!m_parent.verifiedPKX()) + if (!m_parent.verifiedPKM()) return; PKM pk = m_parent.preparePKM(); From ff1b08452322950152c26504e4a07886a137eb2b Mon Sep 17 00:00:00 2001 From: Kaphotics Date: Tue, 21 Jun 2016 17:33:03 -0700 Subject: [PATCH 19/49] Switch to expression on click one liner. --- SAV/SAV_Trainer.Designer.cs | 1 - SAV/SAV_Trainer.cs | 5 +---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/SAV/SAV_Trainer.Designer.cs b/SAV/SAV_Trainer.Designer.cs index 5c6545c9c..736bf6990 100644 --- a/SAV/SAV_Trainer.Designer.cs +++ b/SAV/SAV_Trainer.Designer.cs @@ -785,7 +785,6 @@ private void InitializeComponent() this.B_MaxCash.TabIndex = 16; this.B_MaxCash.Text = "+"; this.B_MaxCash.UseVisualStyleBackColor = true; - this.B_MaxCash.Click += new System.EventHandler(this.B_MaxCash_Click); // // CB_3DSReg // diff --git a/SAV/SAV_Trainer.cs b/SAV/SAV_Trainer.cs index fd2ee2dd5..a89cb3253 100644 --- a/SAV/SAV_Trainer.cs +++ b/SAV/SAV_Trainer.cs @@ -16,6 +16,7 @@ public SAV_Trainer() catch (Exception e) { Util.Alert("Font loading failed...", e.ToString()); } Util.TranslateInterface(this, Main.curlanguage); + B_MaxCash.Click += (sender, e) => MT_Money.Text = "9,999,999"; MaisonRecords = new[] { @@ -573,10 +574,6 @@ private void B_Save_Click(object sender, EventArgs e) Main.SAV.Edited = true; Close(); } - private void B_MaxCash_Click(object sender, EventArgs e) - { - MT_Money.Text = "9,999,999"; - } private void changeBadge(object sender, EventArgs e) { getBadges(); From 3351c7f9bb90a90223120c2e6021082edddb9a47 Mon Sep 17 00:00:00 2001 From: Kaphotics Date: Tue, 21 Jun 2016 17:35:12 -0700 Subject: [PATCH 20/49] Add simple trainer editor (past gen) Fixed save invalidation as well. GameVersions were detected based on checksum validity. Gonna change that so an invalid save can still be recognized (based off of other markers) --- PKHeX.csproj | 9 + PKX/f1-Main.cs | 5 +- SAV/SAV_SimpleTrainer.Designer.cs | 746 ++++++++++++++++++++++++++++++ SAV/SAV_SimpleTrainer.cs | 136 ++++++ SAV/SAV_SimpleTrainer.resx | 120 +++++ Saves/SAV4.cs | 20 +- Saves/SAV5.cs | 20 +- Saves/SAV6.cs | 15 +- Saves/SaveFile.cs | 8 +- 9 files changed, 1050 insertions(+), 29 deletions(-) create mode 100644 SAV/SAV_SimpleTrainer.Designer.cs create mode 100644 SAV/SAV_SimpleTrainer.cs create mode 100644 SAV/SAV_SimpleTrainer.resx diff --git a/PKHeX.csproj b/PKHeX.csproj index e34f532fb..bb15760cd 100644 --- a/PKHeX.csproj +++ b/PKHeX.csproj @@ -215,6 +215,12 @@ SAV_Pokepuff.cs + + Form + + + SAV_SimpleTrainer.cs + Form @@ -305,6 +311,9 @@ SAV_Pokepuff.cs + + SAV_SimpleTrainer.cs + SAV_SuperTrain.cs diff --git a/PKX/f1-Main.cs b/PKX/f1-Main.cs index 26ea74541..f79637ae0 100644 --- a/PKX/f1-Main.cs +++ b/PKX/f1-Main.cs @@ -3791,7 +3791,10 @@ private void B_OpenBoxLayout_Click(object sender, EventArgs e) } private void B_OpenTrainerInfo_Click(object sender, EventArgs e) { - new SAV_Trainer().ShowDialog(); + if (SAV.Generation < 6) + new SAV_SimpleTrainer().ShowDialog(); + else if (SAV.Generation == 6) + new SAV_Trainer().ShowDialog(); // Refresh conversion info PKMConverter.updateConfig(SAV.SubRegion, SAV.Country, SAV.ConsoleRegion, SAV.OT, SAV.Gender); } diff --git a/SAV/SAV_SimpleTrainer.Designer.cs b/SAV/SAV_SimpleTrainer.Designer.cs new file mode 100644 index 000000000..e95c93130 --- /dev/null +++ b/SAV/SAV_SimpleTrainer.Designer.cs @@ -0,0 +1,746 @@ +namespace PKHeX +{ + partial class SAV_SimpleTrainer + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.groupBox2 = new System.Windows.Forms.GroupBox(); + this.L_Started = new System.Windows.Forms.Label(); + this.CAL_AdventureStartDate = new System.Windows.Forms.DateTimePicker(); + this.CAL_HoFDate = new System.Windows.Forms.DateTimePicker(); + this.L_LastSaved = new System.Windows.Forms.Label(); + this.MT_Seconds = new System.Windows.Forms.MaskedTextBox(); + this.MT_Hours = new System.Windows.Forms.MaskedTextBox(); + this.L_Seconds = new System.Windows.Forms.Label(); + this.L_Hours = new System.Windows.Forms.Label(); + this.MT_Minutes = new System.Windows.Forms.MaskedTextBox(); + this.L_Minutes = new System.Windows.Forms.Label(); + this.CAL_AdventureStartTime = new System.Windows.Forms.DateTimePicker(); + this.CAL_HoFTime = new System.Windows.Forms.DateTimePicker(); + this.TB_OTName = new System.Windows.Forms.TextBox(); + this.CB_Gender = new System.Windows.Forms.ComboBox(); + this.L_TrainerName = new System.Windows.Forms.Label(); + this.L_TID = new System.Windows.Forms.Label(); + this.MT_Money = new System.Windows.Forms.MaskedTextBox(); + this.L_SID = new System.Windows.Forms.Label(); + this.L_Money = new System.Windows.Forms.Label(); + this.MT_TID = new System.Windows.Forms.MaskedTextBox(); + this.MT_SID = new System.Windows.Forms.MaskedTextBox(); + this.B_MaxCash = new System.Windows.Forms.Button(); + this.GB_Map = new System.Windows.Forms.GroupBox(); + this.NUD_Z = new System.Windows.Forms.NumericUpDown(); + this.NUD_M = new System.Windows.Forms.NumericUpDown(); + this.NUD_Y = new System.Windows.Forms.NumericUpDown(); + this.NUD_X = new System.Windows.Forms.NumericUpDown(); + this.L_Y = new System.Windows.Forms.Label(); + this.L_CurrentMap = new System.Windows.Forms.Label(); + this.L_Z = new System.Windows.Forms.Label(); + this.L_X = new System.Windows.Forms.Label(); + this.B_Save = new System.Windows.Forms.Button(); + this.B_Cancel = new System.Windows.Forms.Button(); + this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.groupBox3 = new System.Windows.Forms.GroupBox(); + this.CHK_H8 = new System.Windows.Forms.CheckBox(); + this.CHK_H7 = new System.Windows.Forms.CheckBox(); + this.CHK_H6 = new System.Windows.Forms.CheckBox(); + this.CHK_H5 = new System.Windows.Forms.CheckBox(); + this.CHK_H4 = new System.Windows.Forms.CheckBox(); + this.CHK_H3 = new System.Windows.Forms.CheckBox(); + this.CHK_H2 = new System.Windows.Forms.CheckBox(); + this.CHK_H1 = new System.Windows.Forms.CheckBox(); + this.CHK_8 = new System.Windows.Forms.CheckBox(); + this.CHK_7 = new System.Windows.Forms.CheckBox(); + this.CHK_6 = new System.Windows.Forms.CheckBox(); + this.CHK_5 = new System.Windows.Forms.CheckBox(); + this.CHK_4 = new System.Windows.Forms.CheckBox(); + this.CHK_3 = new System.Windows.Forms.CheckBox(); + this.CHK_2 = new System.Windows.Forms.CheckBox(); + this.CHK_1 = new System.Windows.Forms.CheckBox(); + this.groupBox2.SuspendLayout(); + this.GB_Map.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.NUD_Z)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.NUD_M)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.NUD_Y)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.NUD_X)).BeginInit(); + this.groupBox1.SuspendLayout(); + this.groupBox3.SuspendLayout(); + this.SuspendLayout(); + // + // groupBox2 + // + this.groupBox2.Controls.Add(this.L_Started); + this.groupBox2.Controls.Add(this.CAL_AdventureStartDate); + this.groupBox2.Controls.Add(this.CAL_HoFDate); + this.groupBox2.Controls.Add(this.L_LastSaved); + this.groupBox2.Controls.Add(this.MT_Seconds); + this.groupBox2.Controls.Add(this.MT_Hours); + this.groupBox2.Controls.Add(this.L_Seconds); + this.groupBox2.Controls.Add(this.L_Hours); + this.groupBox2.Controls.Add(this.MT_Minutes); + this.groupBox2.Controls.Add(this.L_Minutes); + this.groupBox2.Controls.Add(this.CAL_AdventureStartTime); + this.groupBox2.Controls.Add(this.CAL_HoFTime); + this.groupBox2.Location = new System.Drawing.Point(12, 98); + this.groupBox2.Name = "groupBox2"; + this.groupBox2.Size = new System.Drawing.Size(200, 151); + this.groupBox2.TabIndex = 70; + this.groupBox2.TabStop = false; + this.groupBox2.Text = "Adventure Info"; + // + // L_Started + // + this.L_Started.Location = new System.Drawing.Point(4, 51); + this.L_Started.Name = "L_Started"; + this.L_Started.Size = new System.Drawing.Size(80, 20); + this.L_Started.TabIndex = 36; + this.L_Started.Text = "Game Started:"; + this.L_Started.TextAlign = System.Drawing.ContentAlignment.MiddleRight; + // + // CAL_AdventureStartDate + // + this.CAL_AdventureStartDate.Format = System.Windows.Forms.DateTimePickerFormat.Short; + this.CAL_AdventureStartDate.Location = new System.Drawing.Point(90, 51); + this.CAL_AdventureStartDate.MaxDate = new System.DateTime(2050, 12, 31, 0, 0, 0, 0); + this.CAL_AdventureStartDate.MinDate = new System.DateTime(2000, 1, 1, 0, 0, 0, 0); + this.CAL_AdventureStartDate.Name = "CAL_AdventureStartDate"; + this.CAL_AdventureStartDate.Size = new System.Drawing.Size(99, 20); + this.CAL_AdventureStartDate.TabIndex = 35; + this.CAL_AdventureStartDate.Value = new System.DateTime(2000, 1, 1, 0, 0, 0, 0); + // + // CAL_HoFDate + // + this.CAL_HoFDate.Format = System.Windows.Forms.DateTimePickerFormat.Short; + this.CAL_HoFDate.Location = new System.Drawing.Point(90, 107); + this.CAL_HoFDate.MaxDate = new System.DateTime(4095, 12, 31, 0, 0, 0, 0); + this.CAL_HoFDate.Name = "CAL_HoFDate"; + this.CAL_HoFDate.Size = new System.Drawing.Size(99, 20); + this.CAL_HoFDate.TabIndex = 31; + this.CAL_HoFDate.Value = new System.DateTime(2000, 1, 1, 0, 0, 0, 0); + // + // L_LastSaved + // + this.L_LastSaved.Location = new System.Drawing.Point(4, 107); + this.L_LastSaved.Name = "L_LastSaved"; + this.L_LastSaved.Size = new System.Drawing.Size(80, 20); + this.L_LastSaved.TabIndex = 32; + this.L_LastSaved.Text = "Hall of Fame:"; + this.L_LastSaved.TextAlign = System.Drawing.ContentAlignment.MiddleRight; + // + // MT_Seconds + // + this.MT_Seconds.Location = new System.Drawing.Point(166, 17); + this.MT_Seconds.Mask = "00"; + this.MT_Seconds.Name = "MT_Seconds"; + this.MT_Seconds.Size = new System.Drawing.Size(22, 20); + this.MT_Seconds.TabIndex = 28; + this.MT_Seconds.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; + // + // MT_Hours + // + this.MT_Hours.Location = new System.Drawing.Point(44, 17); + this.MT_Hours.Mask = "00000"; + this.MT_Hours.Name = "MT_Hours"; + this.MT_Hours.Size = new System.Drawing.Size(38, 20); + this.MT_Hours.TabIndex = 25; + this.MT_Hours.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; + // + // L_Seconds + // + this.L_Seconds.AutoSize = true; + this.L_Seconds.Location = new System.Drawing.Point(136, 20); + this.L_Seconds.Name = "L_Seconds"; + this.L_Seconds.Size = new System.Drawing.Size(29, 13); + this.L_Seconds.TabIndex = 30; + this.L_Seconds.Text = "Sec:"; + // + // L_Hours + // + this.L_Hours.AutoSize = true; + this.L_Hours.Location = new System.Drawing.Point(12, 20); + this.L_Hours.Name = "L_Hours"; + this.L_Hours.Size = new System.Drawing.Size(26, 13); + this.L_Hours.TabIndex = 26; + this.L_Hours.Text = "Hrs:"; + // + // MT_Minutes + // + this.MT_Minutes.Location = new System.Drawing.Point(111, 17); + this.MT_Minutes.Mask = "00"; + this.MT_Minutes.Name = "MT_Minutes"; + this.MT_Minutes.Size = new System.Drawing.Size(22, 20); + this.MT_Minutes.TabIndex = 27; + this.MT_Minutes.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; + // + // L_Minutes + // + this.L_Minutes.AutoSize = true; + this.L_Minutes.Location = new System.Drawing.Point(84, 20); + this.L_Minutes.Name = "L_Minutes"; + this.L_Minutes.Size = new System.Drawing.Size(27, 13); + this.L_Minutes.TabIndex = 29; + this.L_Minutes.Text = "Min:"; + // + // CAL_AdventureStartTime + // + this.CAL_AdventureStartTime.CustomFormat = "hh:mm tt"; + this.CAL_AdventureStartTime.Format = System.Windows.Forms.DateTimePickerFormat.Custom; + this.CAL_AdventureStartTime.Location = new System.Drawing.Point(116, 70); + this.CAL_AdventureStartTime.MaxDate = new System.DateTime(2050, 12, 31, 0, 0, 0, 0); + this.CAL_AdventureStartTime.MinDate = new System.DateTime(2000, 1, 1, 0, 0, 0, 0); + this.CAL_AdventureStartTime.Name = "CAL_AdventureStartTime"; + this.CAL_AdventureStartTime.ShowUpDown = true; + this.CAL_AdventureStartTime.Size = new System.Drawing.Size(73, 20); + this.CAL_AdventureStartTime.TabIndex = 34; + this.CAL_AdventureStartTime.Value = new System.DateTime(2001, 1, 1, 0, 0, 0, 0); + // + // CAL_HoFTime + // + this.CAL_HoFTime.CustomFormat = "hh:mm tt"; + this.CAL_HoFTime.Format = System.Windows.Forms.DateTimePickerFormat.Custom; + this.CAL_HoFTime.Location = new System.Drawing.Point(116, 126); + this.CAL_HoFTime.MaxDate = new System.DateTime(2050, 12, 31, 0, 0, 0, 0); + this.CAL_HoFTime.MinDate = new System.DateTime(2000, 1, 1, 0, 0, 0, 0); + this.CAL_HoFTime.Name = "CAL_HoFTime"; + this.CAL_HoFTime.ShowUpDown = true; + this.CAL_HoFTime.Size = new System.Drawing.Size(73, 20); + this.CAL_HoFTime.TabIndex = 37; + this.CAL_HoFTime.Value = new System.DateTime(2001, 1, 1, 0, 0, 0, 0); + // + // TB_OTName + // + this.TB_OTName.Font = new System.Drawing.Font("Courier New", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.TB_OTName.Location = new System.Drawing.Point(99, 11); + this.TB_OTName.MaxLength = 12; + this.TB_OTName.Name = "TB_OTName"; + this.TB_OTName.Size = new System.Drawing.Size(93, 20); + this.TB_OTName.TabIndex = 57; + this.TB_OTName.Text = "WWWWWWWWWWWW"; + this.TB_OTName.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; + // + // CB_Gender + // + this.CB_Gender.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.CB_Gender.FormattingEnabled = true; + this.CB_Gender.Items.AddRange(new object[] { + "♂", + "♀"}); + this.CB_Gender.Location = new System.Drawing.Point(99, 55); + this.CB_Gender.Name = "CB_Gender"; + this.CB_Gender.Size = new System.Drawing.Size(40, 21); + this.CB_Gender.TabIndex = 68; + // + // L_TrainerName + // + this.L_TrainerName.Location = new System.Drawing.Point(7, 13); + this.L_TrainerName.Name = "L_TrainerName"; + this.L_TrainerName.Size = new System.Drawing.Size(87, 16); + this.L_TrainerName.TabIndex = 58; + this.L_TrainerName.Text = "Name:"; + this.L_TrainerName.TextAlign = System.Drawing.ContentAlignment.MiddleRight; + // + // L_TID + // + this.L_TID.Location = new System.Drawing.Point(9, 35); + this.L_TID.Name = "L_TID"; + this.L_TID.Size = new System.Drawing.Size(38, 13); + this.L_TID.TabIndex = 61; + this.L_TID.Text = "TID:"; + this.L_TID.TextAlign = System.Drawing.ContentAlignment.MiddleRight; + // + // MT_Money + // + this.MT_Money.Location = new System.Drawing.Point(119, 33); + this.MT_Money.Mask = "0000000"; + this.MT_Money.Name = "MT_Money"; + this.MT_Money.RightToLeft = System.Windows.Forms.RightToLeft.Yes; + this.MT_Money.Size = new System.Drawing.Size(52, 20); + this.MT_Money.TabIndex = 59; + this.MT_Money.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; + // + // L_SID + // + this.L_SID.Location = new System.Drawing.Point(9, 58); + this.L_SID.Name = "L_SID"; + this.L_SID.Size = new System.Drawing.Size(38, 13); + this.L_SID.TabIndex = 62; + this.L_SID.Text = "SID:"; + this.L_SID.TextAlign = System.Drawing.ContentAlignment.MiddleRight; + // + // L_Money + // + this.L_Money.AutoSize = true; + this.L_Money.Location = new System.Drawing.Point(102, 36); + this.L_Money.Name = "L_Money"; + this.L_Money.Size = new System.Drawing.Size(16, 13); + this.L_Money.TabIndex = 60; + this.L_Money.Text = "$:"; + // + // MT_TID + // + this.MT_TID.Location = new System.Drawing.Point(53, 34); + this.MT_TID.Mask = "00000"; + this.MT_TID.Name = "MT_TID"; + this.MT_TID.RightToLeft = System.Windows.Forms.RightToLeft.Yes; + this.MT_TID.Size = new System.Drawing.Size(39, 20); + this.MT_TID.TabIndex = 63; + this.MT_TID.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; + this.MT_TID.TextChanged += new System.EventHandler(this.changeFFFF); + // + // MT_SID + // + this.MT_SID.Location = new System.Drawing.Point(53, 55); + this.MT_SID.Mask = "00000"; + this.MT_SID.Name = "MT_SID"; + this.MT_SID.RightToLeft = System.Windows.Forms.RightToLeft.Yes; + this.MT_SID.Size = new System.Drawing.Size(39, 20); + this.MT_SID.TabIndex = 64; + this.MT_SID.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; + this.MT_SID.TextChanged += new System.EventHandler(this.changeFFFF); + // + // B_MaxCash + // + this.B_MaxCash.Location = new System.Drawing.Point(172, 33); + this.B_MaxCash.Name = "B_MaxCash"; + this.B_MaxCash.Size = new System.Drawing.Size(20, 20); + this.B_MaxCash.TabIndex = 66; + this.B_MaxCash.Text = "+"; + this.B_MaxCash.UseVisualStyleBackColor = true; + // + // GB_Map + // + this.GB_Map.Controls.Add(this.NUD_Z); + this.GB_Map.Controls.Add(this.NUD_M); + this.GB_Map.Controls.Add(this.NUD_Y); + this.GB_Map.Controls.Add(this.NUD_X); + this.GB_Map.Controls.Add(this.L_Y); + this.GB_Map.Controls.Add(this.L_CurrentMap); + this.GB_Map.Controls.Add(this.L_Z); + this.GB_Map.Controls.Add(this.L_X); + this.GB_Map.Location = new System.Drawing.Point(218, 100); + this.GB_Map.Name = "GB_Map"; + this.GB_Map.Size = new System.Drawing.Size(157, 125); + this.GB_Map.TabIndex = 71; + this.GB_Map.TabStop = false; + this.GB_Map.Text = "Map Position"; + // + // NUD_Z + // + this.NUD_Z.Location = new System.Drawing.Point(93, 68); + this.NUD_Z.Maximum = new decimal(new int[] { + 65535, + 0, + 0, + 0}); + this.NUD_Z.Minimum = new decimal(new int[] { + 65535, + 0, + 0, + -2147483648}); + this.NUD_Z.Name = "NUD_Z"; + this.NUD_Z.Size = new System.Drawing.Size(50, 20); + this.NUD_Z.TabIndex = 53; + // + // NUD_M + // + this.NUD_M.Location = new System.Drawing.Point(93, 16); + this.NUD_M.Maximum = new decimal(new int[] { + 1000, + 0, + 0, + 0}); + this.NUD_M.Name = "NUD_M"; + this.NUD_M.Size = new System.Drawing.Size(50, 20); + this.NUD_M.TabIndex = 52; + // + // NUD_Y + // + this.NUD_Y.Location = new System.Drawing.Point(93, 94); + this.NUD_Y.Maximum = new decimal(new int[] { + 65535, + 0, + 0, + 0}); + this.NUD_Y.Name = "NUD_Y"; + this.NUD_Y.Size = new System.Drawing.Size(50, 20); + this.NUD_Y.TabIndex = 51; + // + // NUD_X + // + this.NUD_X.Location = new System.Drawing.Point(93, 42); + this.NUD_X.Maximum = new decimal(new int[] { + 65535, + 0, + 0, + 0}); + this.NUD_X.Name = "NUD_X"; + this.NUD_X.Size = new System.Drawing.Size(50, 20); + this.NUD_X.TabIndex = 50; + // + // L_Y + // + this.L_Y.Location = new System.Drawing.Point(6, 94); + this.L_Y.Name = "L_Y"; + this.L_Y.Size = new System.Drawing.Size(80, 20); + this.L_Y.TabIndex = 49; + this.L_Y.Text = "Y Coordinate:"; + this.L_Y.TextAlign = System.Drawing.ContentAlignment.MiddleRight; + // + // L_CurrentMap + // + this.L_CurrentMap.Location = new System.Drawing.Point(6, 16); + this.L_CurrentMap.Name = "L_CurrentMap"; + this.L_CurrentMap.Size = new System.Drawing.Size(80, 20); + this.L_CurrentMap.TabIndex = 46; + this.L_CurrentMap.Text = "Current Map:"; + this.L_CurrentMap.TextAlign = System.Drawing.ContentAlignment.MiddleRight; + // + // L_Z + // + this.L_Z.Location = new System.Drawing.Point(6, 68); + this.L_Z.Name = "L_Z"; + this.L_Z.Size = new System.Drawing.Size(80, 20); + this.L_Z.TabIndex = 48; + this.L_Z.Text = "Z Coordinate:"; + this.L_Z.TextAlign = System.Drawing.ContentAlignment.MiddleRight; + // + // L_X + // + this.L_X.Location = new System.Drawing.Point(6, 42); + this.L_X.Name = "L_X"; + this.L_X.Size = new System.Drawing.Size(80, 20); + this.L_X.TabIndex = 47; + this.L_X.Text = "X Coordinate:"; + this.L_X.TextAlign = System.Drawing.ContentAlignment.MiddleRight; + // + // B_Save + // + this.B_Save.Location = new System.Drawing.Point(300, 226); + this.B_Save.Name = "B_Save"; + this.B_Save.Size = new System.Drawing.Size(75, 23); + this.B_Save.TabIndex = 73; + this.B_Save.Text = "Save"; + this.B_Save.UseVisualStyleBackColor = true; + this.B_Save.Click += new System.EventHandler(this.B_Save_Click); + // + // B_Cancel + // + this.B_Cancel.Location = new System.Drawing.Point(219, 226); + this.B_Cancel.Name = "B_Cancel"; + this.B_Cancel.Size = new System.Drawing.Size(75, 23); + this.B_Cancel.TabIndex = 72; + this.B_Cancel.Text = "Cancel"; + this.B_Cancel.UseVisualStyleBackColor = true; + this.B_Cancel.Click += new System.EventHandler(this.B_Cancel_Click); + // + // groupBox1 + // + this.groupBox1.Controls.Add(this.TB_OTName); + this.groupBox1.Controls.Add(this.B_MaxCash); + this.groupBox1.Controls.Add(this.MT_SID); + this.groupBox1.Controls.Add(this.MT_TID); + this.groupBox1.Controls.Add(this.L_Money); + this.groupBox1.Controls.Add(this.L_SID); + this.groupBox1.Controls.Add(this.CB_Gender); + this.groupBox1.Controls.Add(this.MT_Money); + this.groupBox1.Controls.Add(this.L_TID); + this.groupBox1.Controls.Add(this.L_TrainerName); + this.groupBox1.Location = new System.Drawing.Point(12, 12); + this.groupBox1.Name = "groupBox1"; + this.groupBox1.Size = new System.Drawing.Size(200, 82); + this.groupBox1.TabIndex = 74; + this.groupBox1.TabStop = false; + this.groupBox1.Text = "Trainer"; + // + // groupBox3 + // + this.groupBox3.Controls.Add(this.CHK_H8); + this.groupBox3.Controls.Add(this.CHK_H7); + this.groupBox3.Controls.Add(this.CHK_H6); + this.groupBox3.Controls.Add(this.CHK_H5); + this.groupBox3.Controls.Add(this.CHK_H4); + this.groupBox3.Controls.Add(this.CHK_H3); + this.groupBox3.Controls.Add(this.CHK_H2); + this.groupBox3.Controls.Add(this.CHK_H1); + this.groupBox3.Controls.Add(this.CHK_8); + this.groupBox3.Controls.Add(this.CHK_7); + this.groupBox3.Controls.Add(this.CHK_6); + this.groupBox3.Controls.Add(this.CHK_5); + this.groupBox3.Controls.Add(this.CHK_4); + this.groupBox3.Controls.Add(this.CHK_3); + this.groupBox3.Controls.Add(this.CHK_2); + this.groupBox3.Controls.Add(this.CHK_1); + this.groupBox3.Location = new System.Drawing.Point(219, 12); + this.groupBox3.Name = "groupBox3"; + this.groupBox3.Size = new System.Drawing.Size(157, 82); + this.groupBox3.TabIndex = 75; + this.groupBox3.TabStop = false; + this.groupBox3.Text = "Badges"; + // + // CHK_H8 + // + this.CHK_H8.AutoSize = true; + this.CHK_H8.Location = new System.Drawing.Point(130, 55); + this.CHK_H8.Name = "CHK_H8"; + this.CHK_H8.Size = new System.Drawing.Size(15, 14); + this.CHK_H8.TabIndex = 15; + this.CHK_H8.UseVisualStyleBackColor = true; + this.CHK_H8.Visible = false; + // + // CHK_H7 + // + this.CHK_H7.AutoSize = true; + this.CHK_H7.Location = new System.Drawing.Point(113, 55); + this.CHK_H7.Name = "CHK_H7"; + this.CHK_H7.Size = new System.Drawing.Size(15, 14); + this.CHK_H7.TabIndex = 14; + this.CHK_H7.UseVisualStyleBackColor = true; + this.CHK_H7.Visible = false; + // + // CHK_H6 + // + this.CHK_H6.AutoSize = true; + this.CHK_H6.Location = new System.Drawing.Point(96, 55); + this.CHK_H6.Name = "CHK_H6"; + this.CHK_H6.Size = new System.Drawing.Size(15, 14); + this.CHK_H6.TabIndex = 13; + this.CHK_H6.UseVisualStyleBackColor = true; + this.CHK_H6.Visible = false; + // + // CHK_H5 + // + this.CHK_H5.AutoSize = true; + this.CHK_H5.Location = new System.Drawing.Point(79, 55); + this.CHK_H5.Name = "CHK_H5"; + this.CHK_H5.Size = new System.Drawing.Size(15, 14); + this.CHK_H5.TabIndex = 12; + this.CHK_H5.UseVisualStyleBackColor = true; + this.CHK_H5.Visible = false; + // + // CHK_H4 + // + this.CHK_H4.AutoSize = true; + this.CHK_H4.Location = new System.Drawing.Point(62, 55); + this.CHK_H4.Name = "CHK_H4"; + this.CHK_H4.Size = new System.Drawing.Size(15, 14); + this.CHK_H4.TabIndex = 11; + this.CHK_H4.UseVisualStyleBackColor = true; + this.CHK_H4.Visible = false; + // + // CHK_H3 + // + this.CHK_H3.AutoSize = true; + this.CHK_H3.Location = new System.Drawing.Point(45, 55); + this.CHK_H3.Name = "CHK_H3"; + this.CHK_H3.Size = new System.Drawing.Size(15, 14); + this.CHK_H3.TabIndex = 10; + this.CHK_H3.UseVisualStyleBackColor = true; + this.CHK_H3.Visible = false; + // + // CHK_H2 + // + this.CHK_H2.AutoSize = true; + this.CHK_H2.Location = new System.Drawing.Point(28, 55); + this.CHK_H2.Name = "CHK_H2"; + this.CHK_H2.Size = new System.Drawing.Size(15, 14); + this.CHK_H2.TabIndex = 9; + this.CHK_H2.UseVisualStyleBackColor = true; + this.CHK_H2.Visible = false; + // + // CHK_H1 + // + this.CHK_H1.AutoSize = true; + this.CHK_H1.Location = new System.Drawing.Point(11, 55); + this.CHK_H1.Name = "CHK_H1"; + this.CHK_H1.Size = new System.Drawing.Size(15, 14); + this.CHK_H1.TabIndex = 8; + this.CHK_H1.UseVisualStyleBackColor = true; + this.CHK_H1.Visible = false; + // + // CHK_8 + // + this.CHK_8.AutoSize = true; + this.CHK_8.Location = new System.Drawing.Point(130, 27); + this.CHK_8.Name = "CHK_8"; + this.CHK_8.Size = new System.Drawing.Size(15, 14); + this.CHK_8.TabIndex = 7; + this.CHK_8.UseVisualStyleBackColor = true; + this.CHK_8.Visible = false; + // + // CHK_7 + // + this.CHK_7.AutoSize = true; + this.CHK_7.Location = new System.Drawing.Point(113, 27); + this.CHK_7.Name = "CHK_7"; + this.CHK_7.Size = new System.Drawing.Size(15, 14); + this.CHK_7.TabIndex = 6; + this.CHK_7.UseVisualStyleBackColor = true; + this.CHK_7.Visible = false; + // + // CHK_6 + // + this.CHK_6.AutoSize = true; + this.CHK_6.Location = new System.Drawing.Point(96, 27); + this.CHK_6.Name = "CHK_6"; + this.CHK_6.Size = new System.Drawing.Size(15, 14); + this.CHK_6.TabIndex = 5; + this.CHK_6.UseVisualStyleBackColor = true; + this.CHK_6.Visible = false; + // + // CHK_5 + // + this.CHK_5.AutoSize = true; + this.CHK_5.Location = new System.Drawing.Point(79, 27); + this.CHK_5.Name = "CHK_5"; + this.CHK_5.Size = new System.Drawing.Size(15, 14); + this.CHK_5.TabIndex = 4; + this.CHK_5.UseVisualStyleBackColor = true; + this.CHK_5.Visible = false; + // + // CHK_4 + // + this.CHK_4.AutoSize = true; + this.CHK_4.Location = new System.Drawing.Point(62, 27); + this.CHK_4.Name = "CHK_4"; + this.CHK_4.Size = new System.Drawing.Size(15, 14); + this.CHK_4.TabIndex = 3; + this.CHK_4.UseVisualStyleBackColor = true; + this.CHK_4.Visible = false; + // + // CHK_3 + // + this.CHK_3.AutoSize = true; + this.CHK_3.Location = new System.Drawing.Point(45, 27); + this.CHK_3.Name = "CHK_3"; + this.CHK_3.Size = new System.Drawing.Size(15, 14); + this.CHK_3.TabIndex = 2; + this.CHK_3.UseVisualStyleBackColor = true; + this.CHK_3.Visible = false; + // + // CHK_2 + // + this.CHK_2.AutoSize = true; + this.CHK_2.Location = new System.Drawing.Point(28, 27); + this.CHK_2.Name = "CHK_2"; + this.CHK_2.Size = new System.Drawing.Size(15, 14); + this.CHK_2.TabIndex = 1; + this.CHK_2.UseVisualStyleBackColor = true; + this.CHK_2.Visible = false; + // + // CHK_1 + // + this.CHK_1.AutoSize = true; + this.CHK_1.Location = new System.Drawing.Point(11, 27); + this.CHK_1.Name = "CHK_1"; + this.CHK_1.Size = new System.Drawing.Size(15, 14); + this.CHK_1.TabIndex = 0; + this.CHK_1.UseVisualStyleBackColor = true; + this.CHK_1.Visible = false; + // + // SAV_SimpleTrainer + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(386, 261); + this.Controls.Add(this.groupBox3); + this.Controls.Add(this.groupBox1); + this.Controls.Add(this.B_Save); + this.Controls.Add(this.B_Cancel); + this.Controls.Add(this.GB_Map); + this.Controls.Add(this.groupBox2); + this.Name = "SAV_SimpleTrainer"; + this.Text = "Trainer Data Editor"; + this.groupBox2.ResumeLayout(false); + this.groupBox2.PerformLayout(); + this.GB_Map.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.NUD_Z)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.NUD_M)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.NUD_Y)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.NUD_X)).EndInit(); + this.groupBox1.ResumeLayout(false); + this.groupBox1.PerformLayout(); + this.groupBox3.ResumeLayout(false); + this.groupBox3.PerformLayout(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.GroupBox groupBox2; + private System.Windows.Forms.Label L_Started; + private System.Windows.Forms.DateTimePicker CAL_AdventureStartDate; + private System.Windows.Forms.DateTimePicker CAL_HoFDate; + private System.Windows.Forms.Label L_LastSaved; + private System.Windows.Forms.MaskedTextBox MT_Seconds; + private System.Windows.Forms.MaskedTextBox MT_Hours; + private System.Windows.Forms.Label L_Seconds; + private System.Windows.Forms.Label L_Hours; + private System.Windows.Forms.MaskedTextBox MT_Minutes; + private System.Windows.Forms.Label L_Minutes; + private System.Windows.Forms.DateTimePicker CAL_AdventureStartTime; + private System.Windows.Forms.DateTimePicker CAL_HoFTime; + private System.Windows.Forms.TextBox TB_OTName; + private System.Windows.Forms.ComboBox CB_Gender; + private System.Windows.Forms.Label L_TrainerName; + private System.Windows.Forms.Label L_TID; + private System.Windows.Forms.MaskedTextBox MT_Money; + private System.Windows.Forms.Label L_SID; + private System.Windows.Forms.Label L_Money; + private System.Windows.Forms.MaskedTextBox MT_TID; + private System.Windows.Forms.MaskedTextBox MT_SID; + private System.Windows.Forms.Button B_MaxCash; + private System.Windows.Forms.GroupBox GB_Map; + private System.Windows.Forms.NumericUpDown NUD_Z; + private System.Windows.Forms.NumericUpDown NUD_M; + private System.Windows.Forms.NumericUpDown NUD_Y; + private System.Windows.Forms.NumericUpDown NUD_X; + private System.Windows.Forms.Label L_Y; + private System.Windows.Forms.Label L_CurrentMap; + private System.Windows.Forms.Label L_Z; + private System.Windows.Forms.Label L_X; + private System.Windows.Forms.Button B_Save; + private System.Windows.Forms.Button B_Cancel; + private System.Windows.Forms.GroupBox groupBox1; + private System.Windows.Forms.GroupBox groupBox3; + private System.Windows.Forms.CheckBox CHK_8; + private System.Windows.Forms.CheckBox CHK_7; + private System.Windows.Forms.CheckBox CHK_6; + private System.Windows.Forms.CheckBox CHK_5; + private System.Windows.Forms.CheckBox CHK_4; + private System.Windows.Forms.CheckBox CHK_3; + private System.Windows.Forms.CheckBox CHK_2; + private System.Windows.Forms.CheckBox CHK_1; + private System.Windows.Forms.CheckBox CHK_H8; + private System.Windows.Forms.CheckBox CHK_H7; + private System.Windows.Forms.CheckBox CHK_H6; + private System.Windows.Forms.CheckBox CHK_H5; + private System.Windows.Forms.CheckBox CHK_H4; + private System.Windows.Forms.CheckBox CHK_H3; + private System.Windows.Forms.CheckBox CHK_H2; + private System.Windows.Forms.CheckBox CHK_H1; + } +} \ No newline at end of file diff --git a/SAV/SAV_SimpleTrainer.cs b/SAV/SAV_SimpleTrainer.cs new file mode 100644 index 000000000..4f19aa6c7 --- /dev/null +++ b/SAV/SAV_SimpleTrainer.cs @@ -0,0 +1,136 @@ +using System; +using System.Linq; +using System.Windows.Forms; + +namespace PKHeX +{ + public partial class SAV_SimpleTrainer : Form + { + public SAV_SimpleTrainer() + { + InitializeComponent(); + Util.TranslateInterface(this, Main.curlanguage); + + cba = new[] {CHK_1, CHK_2, CHK_3, CHK_4, CHK_5, CHK_6, CHK_7, CHK_8}; + TB_OTName.MaxLength = SAV.OTLength; + B_MaxCash.Click += (sender, e) => MT_Money.Text = "9,999,999"; + + TB_OTName.Text = SAV.OT; + CB_Gender.SelectedIndex = SAV.Gender; + MT_TID.Text = SAV.TID.ToString("00000"); + MT_SID.Text = SAV.SID.ToString("00000"); + MT_Money.Text = SAV.Money.ToString(); + + int badgeval = 0; + if (SAV is SAV4) + { + SAV4 s = (SAV4)SAV; + NUD_M.Value = s.M; + NUD_X.Value = s.X; + NUD_Z.Value = s.Z; + NUD_Y.Value = s.Y; + + badgeval = s.Badges; + if (s.Version == GameVersion.HGSS) + { + badgeval |= s.Badges16 << 8; + cba = cba.Concat(new[] {CHK_H1, CHK_H2, CHK_H3, CHK_H4, CHK_H5, CHK_H6, CHK_H7, CHK_H8}).ToArray(); + } + } + else if (SAV is SAV5) + { + SAV5 s = (SAV5)SAV; + NUD_M.Value = s.M; + NUD_X.Value = s.X; + NUD_Z.Value = s.Z; + NUD_Y.Value = s.Y; + + badgeval = s.Badges; + } + + for (int i = 0; i < cba.Length; i++) + { + cba[i].Visible = true; + cba[i].Checked = (badgeval & 1 << i) != 0; + } + + MT_Hours.Text = SAV.PlayedHours.ToString(); + MT_Minutes.Text = SAV.PlayedMinutes.ToString(); + MT_Seconds.Text = SAV.PlayedSeconds.ToString(); + CAL_HoFDate.Value = new DateTime(2000, 1, 1).AddSeconds(SAV.SecondsToFame); + CAL_HoFTime.Value = new DateTime(2000, 1, 1).AddSeconds(SAV.SecondsToFame % 86400); + CAL_AdventureStartDate.Value = new DateTime(2000, 1, 1).AddSeconds(SAV.SecondsToStart); + CAL_AdventureStartTime.Value = new DateTime(2000, 1, 1).AddSeconds(SAV.SecondsToStart % 86400); + } + private readonly CheckBox[] cba; + private readonly SaveFile SAV = Main.SAV.Clone(); + + private void changeFFFF(object sender, EventArgs e) + { + MaskedTextBox box = sender as MaskedTextBox; + if (box.Text == "") box.Text = "0"; + if (Util.ToInt32(box.Text) > 65535) box.Text = "65535"; + } + + private void B_Save_Click(object sender, EventArgs e) + { + SAV.OT = TB_OTName.Text; + SAV.Gender = (byte)CB_Gender.SelectedIndex; + + SAV.TID = (ushort)Util.ToUInt32(MT_TID.Text); + SAV.SID = (ushort)Util.ToUInt32(MT_SID.Text); + SAV.Money = Util.ToUInt32(MT_Money.Text); + + // Copy Badges + int badgeval = 0; + for (int i = 0; i < cba.Length; i++) + badgeval |= (cba[i].Checked ? 1 : 0) << i; + + if (SAV is SAV4) + { + SAV4 s = (SAV4)SAV; + s.M = (int)NUD_M.Value; + s.X = (int)NUD_X.Value; + s.Z = (int)NUD_Z.Value; + s.Y = (int)NUD_Y.Value; + s.Badges = badgeval & 0xFF; + if (s.Version == GameVersion.HGSS) + { + s.Badges16 = badgeval >> 8; + } + } + else if (SAV is SAV5) + { + SAV5 s = (SAV5)SAV; + s.M = (int)NUD_M.Value; + s.X = (int)NUD_X.Value; + s.Z = (int)NUD_Z.Value; + s.Y = (int)NUD_Y.Value; + s.Badges = badgeval & 0xFF; + } + + // Save PlayTime + SAV.PlayedHours = ushort.Parse(MT_Hours.Text); + SAV.PlayedMinutes = ushort.Parse(MT_Minutes.Text) % 60; + SAV.PlayedSeconds = ushort.Parse(MT_Seconds.Text) % 60; + + SAV.SecondsToStart = getSeconds(CAL_AdventureStartDate, CAL_AdventureStartTime); + SAV.SecondsToFame = getSeconds(CAL_HoFDate, CAL_HoFTime); + + SAV.Data.CopyTo(Main.SAV.Data, 0); + Main.SAV.Edited = true; + Close(); + } + private void B_Cancel_Click(object sender, EventArgs e) + { + Close(); + } + private int getSeconds(DateTimePicker date, DateTimePicker time) + { + int val = (int)(date.Value - new DateTime(2000, 1, 1)).TotalSeconds; + val -= val % 86400; + val += (int)(time.Value - new DateTime(2000, 1, 1)).TotalSeconds; + return val; + } + } +} diff --git a/SAV/SAV_SimpleTrainer.resx b/SAV/SAV_SimpleTrainer.resx new file mode 100644 index 000000000..1af7de150 --- /dev/null +++ b/SAV/SAV_SimpleTrainer.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Saves/SAV4.cs b/Saves/SAV4.cs index 2ddac43e1..bcdf79d86 100644 --- a/Saves/SAV4.cs +++ b/Saves/SAV4.cs @@ -8,14 +8,14 @@ public sealed class SAV4 : SaveFile public override string BAKName => $"{FileName} [{OT} ({Version})" +/* - {LastSavedTime}*/ "].bak"; public override string Filter => (Footer.Length > 0 ? "DeSmuME DSV|*.dsv|" : "") + "SAV File|*.sav"; public override string Extension => ".sav"; - public SAV4(byte[] data = null) + public SAV4(byte[] data = null, int versionOverride = -1) { Data = data == null ? new byte[SaveUtil.SIZE_G4RAW] : (byte[])data.Clone(); BAK = (byte[])Data.Clone(); Exportable = !Data.SequenceEqual(new byte[Data.Length]); // Get Version - SaveVersion = Math.Max(SaveUtil.getIsG4SAV(Data), 0); // Empty file default to DP + SaveVersion = versionOverride > -1 ? versionOverride : Math.Max(SaveUtil.getIsG4SAV(Data), 0); // Empty file default to DP getActiveBlock(); getSAVOffsets(); @@ -27,7 +27,7 @@ public SAV4(byte[] data = null) public readonly int SaveVersion; public override byte[] BAK { get; } public override bool Exportable { get; } - public override SaveFile Clone() { return new SAV4(Data); } + public override SaveFile Clone() { return new SAV4(Data, SaveVersion); } public override int SIZE_STORED => PKX.SIZE_4STORED; public override int SIZE_PARTY => PKX.SIZE_4PARTY; @@ -313,7 +313,7 @@ public override int getPartyOffset(int slot) } // Trainer Info - protected override GameVersion Version + public override GameVersion Version { get { @@ -356,7 +356,7 @@ public override ushort SID get { return BitConverter.ToUInt16(Data, Trainer1 + 0x12); } set { BitConverter.GetBytes(value).CopyTo(Data, Trainer1 + 0x12); } } - public uint Money + public override uint Money { get { return BitConverter.ToUInt32(Data, Trainer1 + 0x14); } set { BitConverter.GetBytes(value).CopyTo(Data, Trainer1 + 0x14); } @@ -398,17 +398,17 @@ public int Badges16 Data[Trainer1 + 0x1F] = (byte)value; } } - public int PlayedHours + public override int PlayedHours { get { return BitConverter.ToUInt16(Data, Trainer1 + 0x22); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, Trainer1 + 0x22); } } - public int PlayedMinutes + public override int PlayedMinutes { get { return Data[Trainer1 + 0x24]; } set { Data[Trainer1 + 0x24] = (byte)value; } } - public int PlayedSeconds + public override int PlayedSeconds { get { return Data[Trainer1 + 0x25]; } set { Data[Trainer1 + 0x25] = (byte)value; } @@ -527,8 +527,8 @@ public int Y } } } - public int SecondsToStart { get { return BitConverter.ToInt32(Data, AdventureInfo + 0x34); } set { BitConverter.GetBytes(value).CopyTo(Data, AdventureInfo + 0x34); } } - public int SecondsToFame { get { return BitConverter.ToInt32(Data, AdventureInfo + 0x3C); } set { BitConverter.GetBytes(value).CopyTo(Data, AdventureInfo + 0x3C); } } + public override int SecondsToStart { get { return BitConverter.ToInt32(Data, AdventureInfo + 0x34); } set { BitConverter.GetBytes(value).CopyTo(Data, AdventureInfo + 0x34); } } + public override int SecondsToFame { get { return BitConverter.ToInt32(Data, AdventureInfo + 0x3C); } set { BitConverter.GetBytes(value).CopyTo(Data, AdventureInfo + 0x3C); } } // Storage public int UnlockedBoxes diff --git a/Saves/SAV5.cs b/Saves/SAV5.cs index 7718fd095..e47aa054c 100644 --- a/Saves/SAV5.cs +++ b/Saves/SAV5.cs @@ -10,14 +10,14 @@ public sealed class SAV5 : SaveFile public override string BAKName => $"{FileName} [{OT} ({Version})" +/* - {LastSavedTime}*/ "].bak"; public override string Filter => (Footer.Length > 0 ? "DeSmuME DSV|*.dsv|" : "") + "SAV File|*.sav"; public override string Extension => ".sav"; - public SAV5(byte[] data = null) + public SAV5(byte[] data = null, int versionOverride = -1) { Data = data == null ? new byte[SaveUtil.SIZE_G5RAW] : (byte[])data.Clone(); BAK = (byte[])Data.Clone(); Exportable = !Data.SequenceEqual(new byte[Data.Length]); // Get Version - SaveVersion = SaveUtil.getIsG5SAV(Data); + SaveVersion = versionOverride > -1 ? versionOverride : SaveUtil.getIsG5SAV(Data); if (SaveVersion < 0) // Invalidate Data Data = null; @@ -81,7 +81,7 @@ public SAV5(byte[] data = null) private int SaveVersion { get; set; } public override byte[] BAK { get; } public override bool Exportable { get; } - public override SaveFile Clone() { return new SAV5(Data); } + public override SaveFile Clone() { return new SAV5(Data, SaveVersion); } public override int SIZE_STORED => PKX.SIZE_5STORED; public override int SIZE_PARTY => PKX.SIZE_5PARTY; @@ -508,7 +508,7 @@ public override MysteryGiftAlbum GiftAlbum protected override MysteryGift[] MysteryGiftCards { get { return new MysteryGift[0]; } set { } } // Trainer Info - protected override GameVersion Version + public override GameVersion Version { get { @@ -541,7 +541,7 @@ public override ushort SID get { return BitConverter.ToUInt16(Data, Trainer1 + 0x14 + 2); } set { BitConverter.GetBytes(value).CopyTo(Data, Trainer1 + 0x14 + 2); } } - public uint Money + public override uint Money { get { return BitConverter.ToUInt32(Data, Trainer2); } set { BitConverter.GetBytes(value).CopyTo(Data, Trainer2); } @@ -587,22 +587,22 @@ public int Y set { BitConverter.GetBytes(value * 18).CopyTo(Data, Trainer1 + 0x18E); } } - public int PlayedHours + public override int PlayedHours { get { return BitConverter.ToUInt16(Data, Trainer1 + 0x24); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, Trainer1 + 0x24); } } - public int PlayedMinutes + public override int PlayedMinutes { get { return Data[Trainer1 + 0x24 + 2]; } set { Data[Trainer1 + 0x24 + 2] = (byte)value; } } - public int PlayedSeconds + public override int PlayedSeconds { get { return Data[Trainer1 + 0x24 + 3]; } set { Data[Trainer1 + 0x24 + 3] = (byte)value; } } - public int SecondsToStart { get { return BitConverter.ToInt32(Data, AdventureInfo + 0x34); } set { BitConverter.GetBytes(value).CopyTo(Data, AdventureInfo + 0x34); } } - public int SecondsToFame { get { return BitConverter.ToInt32(Data, AdventureInfo + 0x3C); } set { BitConverter.GetBytes(value).CopyTo(Data, AdventureInfo + 0x3C); } } + public override int SecondsToStart { get { return BitConverter.ToInt32(Data, AdventureInfo + 0x34); } set { BitConverter.GetBytes(value).CopyTo(Data, AdventureInfo + 0x34); } } + public override int SecondsToFame { get { return BitConverter.ToInt32(Data, AdventureInfo + 0x3C); } set { BitConverter.GetBytes(value).CopyTo(Data, AdventureInfo + 0x3C); } } } } diff --git a/Saves/SAV6.cs b/Saves/SAV6.cs index 016a7a717..fc9b4e24d 100644 --- a/Saves/SAV6.cs +++ b/Saves/SAV6.cs @@ -270,7 +270,7 @@ private void getSAVOffsets() public int Spinda { get; private set; } = int.MinValue; public int EncounterCount { get; private set; } = int.MinValue; - protected override GameVersion Version + public override GameVersion Version { get { @@ -392,7 +392,7 @@ public int Style get { return Data[Trainer1 + 0x14D]; } set { Data[Trainer1 + 0x14D] = (byte)value; } } - public uint Money + public override uint Money { get { return BitConverter.ToUInt32(Data, Trainer2 + 0x8); } set { BitConverter.GetBytes(value).CopyTo(Data, Trainer2 + 0x8); } @@ -433,16 +433,17 @@ public int Vivillon } } - public int PlayedHours{ + public override int PlayedHours + { get { return BitConverter.ToUInt16(Data, PlayTime); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, PlayTime); } } - public int PlayedMinutes + public override int PlayedMinutes { get { return Data[PlayTime + 2]; } set { Data[PlayTime + 2] = (byte)value; } } - public int PlayedSeconds + public override int PlayedSeconds { get { return Data[PlayTime + 3]; } set { Data[PlayTime + 3] = (byte)value; } @@ -461,8 +462,8 @@ public int PlayedSeconds public int ResumeHour { get { return Data[AdventureInfo + 0xB]; } set { Data[AdventureInfo + 0xB] = (byte)value; } } public int ResumeMinute { get { return Data[AdventureInfo + 0xC]; } set { Data[AdventureInfo + 0xC] = (byte)value; } } public int ResumeSeconds { get { return Data[AdventureInfo + 0xD]; } set { Data[AdventureInfo + 0xD] = (byte)value; } } - public int SecondsToStart { get { return BitConverter.ToInt32(Data, AdventureInfo + 0x18); } set { BitConverter.GetBytes(value).CopyTo(Data, AdventureInfo + 0x18); } } - public int SecondsToFame { get { return BitConverter.ToInt32(Data, AdventureInfo + 0x20); } set { BitConverter.GetBytes(value).CopyTo(Data, AdventureInfo + 0x20); } } + public override int SecondsToStart { get { return BitConverter.ToInt32(Data, AdventureInfo + 0x18); } set { BitConverter.GetBytes(value).CopyTo(Data, AdventureInfo + 0x18); } } + public override int SecondsToFame { get { return BitConverter.ToInt32(Data, AdventureInfo + 0x20); } set { BitConverter.GetBytes(value).CopyTo(Data, AdventureInfo + 0x20); } } public uint getPSSStat(int index) { return BitConverter.ToUInt32(Data, PSSStats + 4*index); } public void setPSSStat(int index, uint value) { BitConverter.GetBytes(value).CopyTo(Data, PSSStats + 4*index); } diff --git a/Saves/SaveFile.cs b/Saves/SaveFile.cs index 0ee735328..1daf83b72 100644 --- a/Saves/SaveFile.cs +++ b/Saves/SaveFile.cs @@ -40,7 +40,7 @@ public byte[] Write(bool DSV) } public virtual string MiscSaveChecks() { return ""; } public virtual string MiscSaveInfo() { return ""; } - protected abstract GameVersion Version { get; } + public abstract GameVersion Version { get; } public abstract bool ChecksumsValid { get; } public abstract string ChecksumInfo { get; } public abstract int Generation { get; } @@ -282,6 +282,12 @@ public virtual MysteryGiftAlbum GiftAlbum public abstract ushort TID { get; set; } public abstract ushort SID { get; set; } public abstract string OT { get; set; } + public abstract int PlayedHours { get; set; } + public abstract int PlayedMinutes { get; set; } + public abstract int PlayedSeconds { get; set; } + public abstract int SecondsToStart { get; set; } + public abstract int SecondsToFame { get; set; } + public abstract uint Money { get; set; } public abstract int BoxCount { get; } public abstract int PartyCount { get; protected set; } public virtual int CurrentBox { get { return 0; } set { } } From 93d27989a1abd5a50d4ee86a1f62153f7e6113fa Mon Sep 17 00:00:00 2001 From: Kaphotics Date: Tue, 21 Jun 2016 17:57:55 -0700 Subject: [PATCH 21/49] Add fallback check for g4 saves Check for block identifiers if the general block checksum is invalid (manually tampered). BW/B2W2 detection is fine as is; the checksum block /won't/ be manually modified. --- Saves/SaveUtil.cs | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/Saves/SaveUtil.cs b/Saves/SaveUtil.cs index cd0dc462d..af9a41b32 100644 --- a/Saves/SaveUtil.cs +++ b/Saves/SaveUtil.cs @@ -45,15 +45,24 @@ internal static int getIsG4SAV(byte[] data) { if (data.Length != SIZE_G4RAW) return -1; - - int version = -1; + + // General Block Checksum if (BitConverter.ToUInt16(data, 0xC0FE) == ccitt16(data.Take(0xC0EC).ToArray())) - version = 0; // DP - else if (BitConverter.ToUInt16(data, 0xCF2A) == ccitt16(data.Take(0xCF18).ToArray())) - version = 1; // PT - else if (BitConverter.ToUInt16(data, 0xF626) == ccitt16(data.Take(0xF618).ToArray())) - version = 2; // HGSS - return version; + return 0; // DP + if (BitConverter.ToUInt16(data, 0xCF2A) == ccitt16(data.Take(0xCF18).ToArray())) + return 1; // Pt + if (BitConverter.ToUInt16(data, 0xF626) == ccitt16(data.Take(0xF618).ToArray())) + return 2; // HGSS + + // General Block Checksum is invalid, check for block identifiers + if (data.Skip(0xC0F4).Take(10).SequenceEqual(new byte[] { 0x00, 0xC1, 0x00, 0x00, 0x23, 0x06, 0x06, 0x20, 0x00, 0x00 })) + return 0; // DP + if (data.Skip(0xCF20).Take(10).SequenceEqual(new byte[] { 0x2C, 0xCF, 0x00, 0x00, 0x23, 0x06, 0x06, 0x20, 0x00, 0x00 })) + return 1; // Pt + if (data.Skip(0xF61C).Take(10).SequenceEqual(new byte[] { 0x28, 0xF6, 0x00, 0x00, 0x23, 0x06, 0x06, 0x20, 0x00, 0x00 })) + return 2; // HGSS + + return -1; } internal static int getIsG5SAV(byte[] data) { From 1a6cc17515668a941798828240994a137803f8da Mon Sep 17 00:00:00 2001 From: Kaphotics Date: Tue, 21 Jun 2016 20:14:38 -0700 Subject: [PATCH 22/49] Remove SAV5 Trying to resolve conflicts. --- Misc/SAV5.cs | 1272 -------------------------------------------------- 1 file changed, 1272 deletions(-) delete mode 100644 Misc/SAV5.cs diff --git a/Misc/SAV5.cs b/Misc/SAV5.cs deleted file mode 100644 index ca94e4705..000000000 --- a/Misc/SAV5.cs +++ /dev/null @@ -1,1272 +0,0 @@ -using System; -using System.Linq; - -namespace PKHeX -{ - public class BlockInfo5 - { - public int Offset; - public int Length; - public int ChecksumOffset; - public int ChecksumMirror; - } - public class SAV5 : PKM - { - internal const int SIZERAW = 0x80000; // 512KB - internal const int SIZE_BW = 0x24000; // B/W - internal const int SIZE_B2W2 = 0x26000; // B2/W2 - - internal static int getIsG5SAV(byte[] data) - { - ushort chk1 = BitConverter.ToUInt16(data, SIZE_BW - 0x100 + 0x8C + 0xE); - ushort actual1 = ccitt16(data.Skip(SIZE_BW - 0x100).Take(0x8C).ToArray()); - if (chk1 == actual1) - return 0; - ushort chk2 = BitConverter.ToUInt16(data, SIZE_B2W2 - 0x100 + 0x94 + 0xE); - ushort actual2 = ccitt16(data.Skip(SIZE_B2W2 - 0x100).Take(0x94).ToArray()); - if (chk2 == actual2) - return 1; - return -1; - } - - // Global Settings - // Save Data Attributes - public readonly byte[] Data; - public bool Edited; - public readonly bool Exportable; - public readonly byte[] BAK; - public string FileName, FilePath; - - private BlockInfo5[] Blocks; - - public SAV5(byte[] data = null) - { - Data = (byte[])(data ?? new byte[SIZERAW]).Clone(); - BAK = (byte[])Data.Clone(); - Exportable = !Data.SequenceEqual(new byte[Data.Length]); - - // Get Version - int version = getIsG5SAV(Data); - if (version < 0) // Invalidate Data - Data = null; - - B2W2 = version == 1; - BW = version == 0; - - // Different Offsets for different games. - BattleBox = version == 1 ? 0x20A00 : 0x20900; - - #region Block Tables - if (BW) - { - Blocks = new[] - { - new BlockInfo5 - { - Offset = 0x00000, - Length = 0x3E0, - ChecksumOffset = 0x003E2, - ChecksumMirror = 0x23F00 /* Box Names */ - }, - new BlockInfo5 - { - Offset = 0x00400, - Length = 0xFF0, - ChecksumOffset = 0x013F2, - ChecksumMirror = 0x23F02 /* Box 1 */ - }, - new BlockInfo5 - { - Offset = 0x01400, - Length = 0xFF0, - ChecksumOffset = 0x023F2, - ChecksumMirror = 0x23F04 /* Box 2 */ - }, - new BlockInfo5 - { - Offset = 0x02400, - Length = 0xFF0, - ChecksumOffset = 0x033F2, - ChecksumMirror = 0x23F06 /* Box 3 */ - }, - new BlockInfo5 - { - Offset = 0x03400, - Length = 0xFF0, - ChecksumOffset = 0x043F2, - ChecksumMirror = 0x23F08 /* Box 4 */ - }, - new BlockInfo5 - { - Offset = 0x04400, - Length = 0xFF0, - ChecksumOffset = 0x053F2, - ChecksumMirror = 0x23F0A /* Box 5 */ - }, - new BlockInfo5 - { - Offset = 0x05400, - Length = 0xFF0, - ChecksumOffset = 0x063F2, - ChecksumMirror = 0x23F0C /* Box 6 */ - }, - new BlockInfo5 - { - Offset = 0x06400, - Length = 0xFF0, - ChecksumOffset = 0x073F2, - ChecksumMirror = 0x23F0E /* Box 7 */ - }, - new BlockInfo5 - { - Offset = 0x07400, - Length = 0xFF0, - ChecksumOffset = 0x083F2, - ChecksumMirror = 0x23F10 /* Box 8 */ - }, - new BlockInfo5 - { - Offset = 0x08400, - Length = 0xFF0, - ChecksumOffset = 0x093F2, - ChecksumMirror = 0x23F12 /* Box 9 */ - }, - new BlockInfo5 - { - Offset = 0x09400, - Length = 0xFF0, - ChecksumOffset = 0x0A3F2, - ChecksumMirror = 0x23F14 /* Box 10 */ - }, - new BlockInfo5 - { - Offset = 0x0A400, - Length = 0xFF0, - ChecksumOffset = 0x0B3F2, - ChecksumMirror = 0x23F16 /* Box 11 */ - }, - new BlockInfo5 - { - Offset = 0x0B400, - Length = 0xFF0, - ChecksumOffset = 0x0C3F2, - ChecksumMirror = 0x23F18 /* Box 12 */ - }, - new BlockInfo5 - { - Offset = 0x0C400, - Length = 0xFF0, - ChecksumOffset = 0x0D3F2, - ChecksumMirror = 0x23F1A /* Box 13 */ - }, - new BlockInfo5 - { - Offset = 0x0D400, - Length = 0xFF0, - ChecksumOffset = 0x0E3F2, - ChecksumMirror = 0x23F1C /* Box 14 */ - }, - new BlockInfo5 - { - Offset = 0x0E400, - Length = 0xFF0, - ChecksumOffset = 0x0F3F2, - ChecksumMirror = 0x23F1E /* Box 15 */ - }, - new BlockInfo5 - { - Offset = 0x0F400, - Length = 0xFF0, - ChecksumOffset = 0x103F2, - ChecksumMirror = 0x23F20 /* Box 16 */ - }, - new BlockInfo5 - { - Offset = 0x10400, - Length = 0xFF0, - ChecksumOffset = 0x113F2, - ChecksumMirror = 0x23F22 /* Box 17 */ - }, - new BlockInfo5 - { - Offset = 0x11400, - Length = 0xFF0, - ChecksumOffset = 0x123F2, - ChecksumMirror = 0x23F24 /* Box 18 */ - }, - new BlockInfo5 - { - Offset = 0x12400, - Length = 0xFF0, - ChecksumOffset = 0x133F2, - ChecksumMirror = 0x23F26 /* Box 19 */ - }, - new BlockInfo5 - { - Offset = 0x13400, - Length = 0xFF0, - ChecksumOffset = 0x143F2, - ChecksumMirror = 0x23F28 /* Box 20 */ - }, - new BlockInfo5 - { - Offset = 0x14400, - Length = 0xFF0, - ChecksumOffset = 0x153F2, - ChecksumMirror = 0x23F2A /* Box 21 */ - }, - new BlockInfo5 - { - Offset = 0x15400, - Length = 0xFF0, - ChecksumOffset = 0x163F2, - ChecksumMirror = 0x23F2C /* Box 22 */ - }, - new BlockInfo5 - { - Offset = 0x16400, - Length = 0xFF0, - ChecksumOffset = 0x173F2, - ChecksumMirror = 0x23F2E /* Box 23 */ - }, - new BlockInfo5 - { - Offset = 0x17400, - Length = 0xFF0, - ChecksumOffset = 0x183F2, - ChecksumMirror = 0x23F30 /* Box 24 */ - }, - new BlockInfo5 - { - Offset = 0x18400, - Length = 0x9C0, - ChecksumOffset = 0x18DC2, - ChecksumMirror = 0x23F32 /* Inventory */ - }, - new BlockInfo5 - { - Offset = 0x18E00, - Length = 0x534, - ChecksumOffset = 0x19336, - ChecksumMirror = 0x23F34 /* Party Pokemon */ - }, - new BlockInfo5 - { - Offset = 0x19400, - Length = 0x68, - ChecksumOffset = 0x19469, - ChecksumMirror = 0x23F36 /* Trainer Data */ - }, - new BlockInfo5 - { - Offset = 0x19500, - Length = 0x9C, - ChecksumOffset = 0x1959E, - ChecksumMirror = 0x23F38 /* ??? */ - }, - new BlockInfo5 - { - Offset = 0x19600, - Length = 0x1338, - ChecksumOffset = 0x1A93A, - ChecksumMirror = 0x23F3A /* ??? */ - }, - new BlockInfo5 - { - Offset = 0x1AA00, - Length = 0x7C4, - ChecksumOffset = 0x1B1C6, - ChecksumMirror = 0x23F3C /* ??? */ - }, - new BlockInfo5 - { - Offset = 0x1B200, - Length = 0xD54, - ChecksumOffset = 0x1BF56, - ChecksumMirror = 0x23F3E /* ??? */ - }, - new BlockInfo5 - { - Offset = 0x1C000, - Length = 0x2C, - ChecksumOffset = 0x1C02E, - ChecksumMirror = 0x23F40 /* ??? */ - }, - new BlockInfo5 - { - Offset = 0x1C100, - Length = 0x658, - ChecksumOffset = 0x1C75A, - ChecksumMirror = 0x23F42 /* ??? Gym badge data */ - }, - new BlockInfo5 - { - Offset = 0x1C800, - Length = 0xA94, - ChecksumOffset = 0x1D296, - ChecksumMirror = 0x23F44 /* ??? */ - }, - new BlockInfo5 - { - Offset = 0x1D300, - Length = 0x1AC, - ChecksumOffset = 0x1D4AE, - ChecksumMirror = 0x23F46 /* ??? */ - }, - new BlockInfo5 - { - Offset = 0x1D500, - Length = 0x3EC, - ChecksumOffset = 0x1D8EE, - ChecksumMirror = 0x23F48 /* ??? */ - }, - new BlockInfo5 - { - Offset = 0x1D900, - Length = 0x5C, - ChecksumOffset = 0x1D95E, - ChecksumMirror = 0x23F4A /* ??? */ - }, - new BlockInfo5 - { - Offset = 0x1DA00, - Length = 0x1E0, - ChecksumOffset = 0x1DBE2, - ChecksumMirror = 0x23F4C /* ??? */ - }, - new BlockInfo5 - { - Offset = 0x1DC00, - Length = 0xA8, - ChecksumOffset = 0x1DCAA, - ChecksumMirror = 0x23F4E /* ??? */ - }, - new BlockInfo5 - { - Offset = 0x1DD00, - Length = 0x460, - ChecksumOffset = 0x1E162, - ChecksumMirror = 0x23F50 /* ??? */ - }, - new BlockInfo5 - { - Offset = 0x1E200, - Length = 0x1400, - ChecksumOffset = 0x1F602, - ChecksumMirror = 0x23F52 /* ??? */ - }, - new BlockInfo5 - { - Offset = 0x1F700, - Length = 0x2A4, - ChecksumOffset = 0x1F9A6, - ChecksumMirror = 0x23F54 /* ??? */ - }, - new BlockInfo5 - { - Offset = 0x1FA00, - Length = 0x2DC, - ChecksumOffset = 0x1FCDE, - ChecksumMirror = 0x23F56 /* ??? */ - }, - new BlockInfo5 - { - Offset = 0x1FD00, - Length = 0x34C, - ChecksumOffset = 0x2004E, - ChecksumMirror = 0x23F58 /* ??? */ - }, - new BlockInfo5 - { - Offset = 0x20100, - Length = 0x3EC, - ChecksumOffset = 0x204EE, - ChecksumMirror = 0x23F5A /* ??? */ - }, - new BlockInfo5 - { - Offset = 0x20500, - Length = 0xF8, - ChecksumOffset = 0x205FA, - ChecksumMirror = 0x23F5C /* ??? */ - }, - new BlockInfo5 - { - Offset = 0x20600, - Length = 0x2FC, - ChecksumOffset = 0x208FE, - ChecksumMirror = 0x23F5E /* ??? */ - }, - new BlockInfo5 - { - Offset = 0x20900, - Length = 0x94, - ChecksumOffset = 0x20996, - ChecksumMirror = 0x23F60 /* ??? */ - }, - new BlockInfo5 - { - Offset = 0x20A00, - Length = 0x35C, - ChecksumOffset = 0x20D5E, - ChecksumMirror = 0x23F62 /* ??? */ - }, - new BlockInfo5 - { - Offset = 0x20E00, - Length = 0x1CC, - ChecksumOffset = 0x20FCE, - ChecksumMirror = 0x23F64 /* ??? */ - }, - new BlockInfo5 - { - Offset = 0x21000, - Length = 0x168, - ChecksumOffset = 0x2116A, - ChecksumMirror = 0x23F66 /* ??? */ - }, - new BlockInfo5 - { - Offset = 0x21200, - Length = 0xEC, - ChecksumOffset = 0x212EE, - ChecksumMirror = 0x23F68 /* ??? */ - }, - new BlockInfo5 - { - Offset = 0x21300, - Length = 0x1B0, - ChecksumOffset = 0x214B2, - ChecksumMirror = 0x23F6A /* ??? */ - }, - new BlockInfo5 - { - Offset = 0x21500, - Length = 0x1C, - ChecksumOffset = 0x2151E, - ChecksumMirror = 0x23F6C /* ??? */ - }, - new BlockInfo5 - { - Offset = 0x21600, - Length = 0x4D4, - ChecksumOffset = 0x21AD6, - ChecksumMirror = 0x23F6E /* ??? */ - }, - new BlockInfo5 - { - Offset = 0x21B00, - Length = 0x34, - ChecksumOffset = 0x21B36, - ChecksumMirror = 0x23F70 /* ??? */ - }, - new BlockInfo5 - { - Offset = 0x21C00, - Length = 0x3C, - ChecksumOffset = 0x21C3E, - ChecksumMirror = 0x23F72 /* ??? */ - }, - new BlockInfo5 - { - Offset = 0x21D00, - Length = 0x1AC, - ChecksumOffset = 0x21EAE, - ChecksumMirror = 0x23F74 /* ??? */ - }, - new BlockInfo5 - { - Offset = 0x21F00, - Length = 0xB90, - ChecksumOffset = 0x22A92, - ChecksumMirror = 0x23F76 /* ??? */ - }, - new BlockInfo5 - { - Offset = 0x22B00, - Length = 0x9C, - ChecksumOffset = 0x22B9E, - ChecksumMirror = 0x23F78 /* ??? */ - }, - new BlockInfo5 - { - Offset = 0x22C00, - Length = 0x850, - ChecksumOffset = 0x23452, - ChecksumMirror = 0x23F7A /* Entralink Forest pokémon data */ - }, - new BlockInfo5 - { - Offset = 0x23500, - Length = 0x28, - ChecksumOffset = 0x2352A, - ChecksumMirror = 0x23F7C /* ??? */ - }, - new BlockInfo5 - { - Offset = 0x23600, - Length = 0x284, - ChecksumOffset = 0x23886, - ChecksumMirror = 0x23F7E /* ??? */ - }, - new BlockInfo5 - { - Offset = 0x23900, - Length = 0x10, - ChecksumOffset = 0x23912, - ChecksumMirror = 0x23F80 /* ??? */ - }, - new BlockInfo5 - { - Offset = 0x23A00, - Length = 0x5C, - ChecksumOffset = 0x23A5E, - ChecksumMirror = 0x23F82 /* ??? */ - }, - new BlockInfo5 - { - Offset = 0x23B00, - Length = 0x16C, - ChecksumOffset = 0x23C6E, - ChecksumMirror = 0x23F84 /* ??? */ - }, - new BlockInfo5 - { - Offset = 0x23D00, - Length = 0x40, - ChecksumOffset = 0x23D42, - ChecksumMirror = 0x23F86 /* ??? */ - }, - new BlockInfo5 - { - Offset = 0x23E00, - Length = 0xFC, - ChecksumOffset = 0x23EFE, - ChecksumMirror = 0x23F88 /* ??? */ - }, - new BlockInfo5 - { - Offset = 0x23F00, - Length = 0x8C, - ChecksumOffset = 0x23F9A, - ChecksumMirror = 0x23F9A /* Checksums */ - } - }; - } - else if (B2W2) - { - Blocks = new[] - { - new BlockInfo5 - { - Offset = 0x00000, - Length = 0x3e0, - ChecksumOffset = 0x003E2, - ChecksumMirror = 0x25F00 /* Box Names */ - }, - new BlockInfo5 - { - Offset = 0x00400, - Length = 0xff0, - ChecksumOffset = 0x013F2, - ChecksumMirror = 0x25F02 /* Box 1 */ - }, - new BlockInfo5 - { - Offset = 0x01400, - Length = 0xff0, - ChecksumOffset = 0x023F2, - ChecksumMirror = 0x25F04 /* Box 2 */ - }, - new BlockInfo5 - { - Offset = 0x02400, - Length = 0xff0, - ChecksumOffset = 0x033F2, - ChecksumMirror = 0x25F06 /* Box 3 */ - }, - new BlockInfo5 - { - Offset = 0x03400, - Length = 0xff0, - ChecksumOffset = 0x043F2, - ChecksumMirror = 0x25F08 /* Box 4 */ - }, - new BlockInfo5 - { - Offset = 0x04400, - Length = 0xff0, - ChecksumOffset = 0x053F2, - ChecksumMirror = 0x25F0A /* Box 5 */ - }, - new BlockInfo5 - { - Offset = 0x05400, - Length = 0xff0, - ChecksumOffset = 0x063F2, - ChecksumMirror = 0x25F0C /* Box 6 */ - }, - new BlockInfo5 - { - Offset = 0x06400, - Length = 0xff0, - ChecksumOffset = 0x073F2, - ChecksumMirror = 0x25F0E /* Box 7 */ - }, - new BlockInfo5 - { - Offset = 0x07400, - Length = 0xff0, - ChecksumOffset = 0x083F2, - ChecksumMirror = 0x25F10 /* Box 8 */ - }, - new BlockInfo5 - { - Offset = 0x08400, - Length = 0xff0, - ChecksumOffset = 0x093F2, - ChecksumMirror = 0x25F12 /* Box 9 */ - }, - new BlockInfo5 - { - Offset = 0x09400, - Length = 0xff0, - ChecksumOffset = 0x0A3F2, - ChecksumMirror = 0x25F14 /* Box 10 */ - }, - new BlockInfo5 - { - Offset = 0x0A400, - Length = 0xff0, - ChecksumOffset = 0x0B3F2, - ChecksumMirror = 0x25F16 /* Box 11 */ - }, - new BlockInfo5 - { - Offset = 0x0B400, - Length = 0xff0, - ChecksumOffset = 0x0C3F2, - ChecksumMirror = 0x25F18 /* Box 12 */ - }, - new BlockInfo5 - { - Offset = 0x0C400, - Length = 0xff0, - ChecksumOffset = 0x0D3F2, - ChecksumMirror = 0x25F1A /* Box 13 */ - }, - new BlockInfo5 - { - Offset = 0x0D400, - Length = 0xff0, - ChecksumOffset = 0x0E3F2, - ChecksumMirror = 0x25F1C /* Box 14 */ - }, - new BlockInfo5 - { - Offset = 0x0E400, - Length = 0xff0, - ChecksumOffset = 0x0F3F2, - ChecksumMirror = 0x25F1E /* Box 15 */ - }, - new BlockInfo5 - { - Offset = 0x0F400, - Length = 0xff0, - ChecksumOffset = 0x103F2, - ChecksumMirror = 0x25F20 /* Box 16 */ - }, - new BlockInfo5 - { - Offset = 0x10400, - Length = 0xff0, - ChecksumOffset = 0x113F2, - ChecksumMirror = 0x25F22 /* Box 17 */ - }, - new BlockInfo5 - { - Offset = 0x11400, - Length = 0xff0, - ChecksumOffset = 0x123F2, - ChecksumMirror = 0x25F24 /* Box 18 */ - }, - new BlockInfo5 - { - Offset = 0x12400, - Length = 0xff0, - ChecksumOffset = 0x133F2, - ChecksumMirror = 0x25F26 /* Box 19 */ - }, - new BlockInfo5 - { - Offset = 0x13400, - Length = 0xff0, - ChecksumOffset = 0x143F2, - ChecksumMirror = 0x25F28 /* Box 20 */ - }, - new BlockInfo5 - { - Offset = 0x14400, - Length = 0xff0, - ChecksumOffset = 0x153F2, - ChecksumMirror = 0x25F2A /* Box 21 */ - }, - new BlockInfo5 - { - Offset = 0x15400, - Length = 0xff0, - ChecksumOffset = 0x163F2, - ChecksumMirror = 0x25F2C /* Box 22 */ - }, - new BlockInfo5 - { - Offset = 0x16400, - Length = 0xff0, - ChecksumOffset = 0x173F2, - ChecksumMirror = 0x25F2E /* Box 23 */ - }, - new BlockInfo5 - { - Offset = 0x17400, - Length = 0xff0, - ChecksumOffset = 0x183F2, - ChecksumMirror = 0x25F30 /* Box 24 */ - }, - new BlockInfo5 - { - Offset = 0x18400, - Length = 0x9ec, - ChecksumOffset = 0x18DEE, - ChecksumMirror = 0x25F32 /* Inventory */ - }, - new BlockInfo5 - { - Offset = 0x18E00, - Length = 0x534, - ChecksumOffset = 0x19336, - ChecksumMirror = 0x25F34 /* Party Pokemon */ - }, - new BlockInfo5 - { - Offset = 0x19400, - Length = 0xb0, - ChecksumOffset = 0x194B2, - ChecksumMirror = 0x25F36 /* Trainer Data */ - }, - new BlockInfo5 - { - Offset = 0x19500, - Length = 0xa8, - ChecksumOffset = 0x195AA, - ChecksumMirror = 0x25F38 /* Trainer Position */ - }, - new BlockInfo5 - { - Offset = 0x19600, - Length = 0x1338, - ChecksumOffset = 0x1A93A, - ChecksumMirror = 0x25F3A /* Unity Tower and survey stuff */ - }, - new BlockInfo5 - { - Offset = 0x1AA00, - Length = 0x7c4, - ChecksumOffset = 0x1B1C6, - ChecksumMirror = 0x25F3C /* Pal Pad Player Data (30d) */ - }, - new BlockInfo5 - { - Offset = 0x1B200, - Length = 0xd54, - ChecksumOffset = 0x1BF56, - ChecksumMirror = 0x25F3E /* Pal Pad Friend Data */ - }, - new BlockInfo5 - { - Offset = 0x1C000, - Length = 0x94, - ChecksumOffset = 0x1C096, - ChecksumMirror = 0x25F40 /* C-Gear */ - }, - new BlockInfo5 - { - Offset = 0x1C100, - Length = 0x658, - ChecksumOffset = 0x1C75A, - ChecksumMirror = 0x25F42 /* Card Signature Block & ???? */ - }, - new BlockInfo5 - { - Offset = 0x1C800, - Length = 0xa94, - ChecksumOffset = 0x1D296, - ChecksumMirror = 0x25F44 /* Mystery Gift */ - }, - new BlockInfo5 - { - Offset = 0x1D300, - Length = 0x1ac, - ChecksumOffset = 0x1D4AE, - ChecksumMirror = 0x25F46 /* Dream World Stuff (Catalog) */ - }, - new BlockInfo5 - { - Offset = 0x1D500, - Length = 0x3ec, - ChecksumOffset = 0x1D8EE, - ChecksumMirror = 0x25F48 /* Chatter */ - }, - new BlockInfo5 - { - Offset = 0x1D900, - Length = 0x5c, - ChecksumOffset = 0x1D95E, - ChecksumMirror = 0x25F4A /* Adventure data */ - }, - new BlockInfo5 - { - Offset = 0x1DA00, - Length = 0x1e0, - ChecksumOffset = 0x1DBE2, - ChecksumMirror = 0x25F4C /* Trainer Card Records */ - }, - new BlockInfo5 - { - Offset = 0x1DC00, - Length = 0xa8, - ChecksumOffset = 0x1DCAA, - ChecksumMirror = 0x25F4E /* ??? */ - }, - new BlockInfo5 - { - Offset = 0x1DD00, - Length = 0x460, - ChecksumOffset = 0x1E162, - ChecksumMirror = 0x25F50 /* (40d) */ - }, - new BlockInfo5 - { - Offset = 0x1E200, - Length = 0x1400, - ChecksumOffset = 0x1F602, - ChecksumMirror = 0x25F52 /* ??? */ - }, - new BlockInfo5 - { - Offset = 0x1F700, - Length = 0x2a4, - ChecksumOffset = 0x1F9A6, - ChecksumMirror = 0x25F54 /* Contains flags and references for downloaded data (Musical) */ - }, - new BlockInfo5 - { - Offset = 0x1FA00, - Length = 0xe0, - ChecksumOffset = 0x1FAE2, - ChecksumMirror = 0x25F56 /* Fused Reshiram/Zekrom Storage */ - }, - new BlockInfo5 - { - Offset = 0x1FB00, - Length = 0x34c, - ChecksumOffset = 0x1FE4E, - ChecksumMirror = 0x25F58 /* ??? */ - }, - new BlockInfo5 - { - Offset = 0x1FF00, - Length = 0x4e0, - ChecksumOffset = 0x203E2, - ChecksumMirror = 0x25F5A /* Const Data Block and Event Flag Block (0x35E is the split) */ - }, - new BlockInfo5 - { - Offset = 0x20400, - Length = 0xf8, - ChecksumOffset = 0x204FA, - ChecksumMirror = 0x25F5C /* ??? */ - }, - new BlockInfo5 - { - Offset = 0x20500, - Length = 0x2fc, - ChecksumOffset = 0x207FE, - ChecksumMirror = 0x25F5E /* Tournament Block */ - }, - new BlockInfo5 - { - Offset = 0x20800, - Length = 0x94, - ChecksumOffset = 0x20896, - ChecksumMirror = 0x25F60 /* ??? */ - }, - new BlockInfo5 - { - Offset = 0x20900, - Length = 0x35c, - ChecksumOffset = 0x20C5E, - ChecksumMirror = 0x25F62 /* Battle Box Block */ - }, - new BlockInfo5 - { - Offset = 0x20D00, - Length = 0x1d4, - ChecksumOffset = 0x20ED6, - ChecksumMirror = 0x25F64 /* Daycare Block (50d) */ - }, - new BlockInfo5 - { - Offset = 0x20F00, - Length = 0x1e0, - ChecksumOffset = 0x201E2, - ChecksumMirror = 0x25F66 /* Strength Boulder Status Block */ - }, - new BlockInfo5 - { - Offset = 0x21100, - Length = 0xf0, - ChecksumOffset = 0x211F2, - ChecksumMirror = 0x25F68 /* Badge Flags, Money, Trainer Sayings */ - }, - new BlockInfo5 - { - Offset = 0x21200, - Length = 0x1b4, - ChecksumOffset = 0x213B6, - ChecksumMirror = 0x25F6A /* Entralink (Level & Powers etc) */ - }, - new BlockInfo5 - { - Offset = 0x21400, - Length = 0x4dc, - ChecksumOffset = 0x218DE, - ChecksumMirror = 0x25F6C /* Pokedex */ - }, - new BlockInfo5 - { - Offset = 0x21900, - Length = 0x34, - ChecksumOffset = 0x21936, - ChecksumMirror = 0x25F6E - /* Swarm and other overworld info - 2C - swarm, 2D - repel steps, 2E repel type */ - }, - new BlockInfo5 - { - Offset = 0x21A00, - Length = 0x3c, - ChecksumOffset = 0x21A3E, - ChecksumMirror = 0x25F70 /* ??? */ - }, - new BlockInfo5 - { - Offset = 0x21B00, - Length = 0x1ac, - ChecksumOffset = 0x21CAE, - ChecksumMirror = 0x25F72 /* ??? */ - }, - new BlockInfo5 - { - Offset = 0x21D00, - Length = 0xb90, - ChecksumOffset = 0x22892, - ChecksumMirror = 0x25F74 /* ??? */ - }, - new BlockInfo5 - { - Offset = 0x22900, - Length = 0xac, - ChecksumOffset = 0x229AE, - ChecksumMirror = 0x25F76 /* Online Records */ - }, - new BlockInfo5 - { - Offset = 0x22A00, - Length = 0x850, - ChecksumOffset = 0x23252, - ChecksumMirror = 0x25F78 /* Area NPC data - encrypted (60d) */ - }, - new BlockInfo5 - { - Offset = 0x23300, - Length = 0x284, - ChecksumOffset = 0x23586, - ChecksumMirror = 0x25F7A /* ??? */ - }, - new BlockInfo5 - { - Offset = 0x23600, - Length = 0x10, - ChecksumOffset = 0x23612, - ChecksumMirror = 0x25F7C /* ??? */ - }, - new BlockInfo5 - { - Offset = 0x23700, - Length = 0xa8, - ChecksumOffset = 0x237AA, - ChecksumMirror = 0x25F7E /* ??? */ - }, - new BlockInfo5 - { - Offset = 0x23800, - Length = 0x16c, - ChecksumOffset = 0x2396E, - ChecksumMirror = 0x25F80 /* ??? */ - }, - new BlockInfo5 - { - Offset = 0x23A00, - Length = 0x80, - ChecksumOffset = 0x23A82, - ChecksumMirror = 0x25F82 /* ??? */ - }, - new BlockInfo5 - { - Offset = 0x23B00, - Length = 0xfc, - ChecksumOffset = 0x23BFE, - ChecksumMirror = 0x25F84 /* Hollow/Rival Block */ - }, - new BlockInfo5 - { - Offset = 0x23C00, - Length = 0x16a8, - ChecksumOffset = 0x252AA, - ChecksumMirror = 0x25F86 /* Join Avenue Block */ - }, - new BlockInfo5 - { - Offset = 0x25300, - Length = 0x498, - ChecksumOffset = 0x2579A, - ChecksumMirror = 0x25F88 /* Medal data */ - }, - new BlockInfo5 - { - Offset = 0x25800, - Length = 0x60, - ChecksumOffset = 0x25862, - ChecksumMirror = 0x25F8A /* Key-related data */ - }, - new BlockInfo5 - { - Offset = 0x25900, - Length = 0xfc, - ChecksumOffset = 0x259FE, - ChecksumMirror = 0x25F8C /* (70d) */ - }, - new BlockInfo5 - { - Offset = 0x25A00, - Length = 0x3e4, - ChecksumOffset = 0x25DE6, - ChecksumMirror = 0x25F8E /* ??? */ - }, - new BlockInfo5 - { - Offset = 0x25E00, - Length = 0xf0, - ChecksumOffset = 0x25EF2, - ChecksumMirror = 0x25F90 /* ??? */ - }, - new BlockInfo5 - { - Offset = 0x25F00, - Length = 0x94, - ChecksumOffset = 0x25FA2, - ChecksumMirror = 0x25FA2 /* Checksum Block (73d) */ - } - }; - } - else - { - Blocks = new BlockInfo5[] {}; - } - #endregion - } - - private const int Box = 0x400; - private const int Party = 0x18E00; - private readonly int BattleBox; - private const int Trainer = 0x19400; - private const int Wondercard = 0x1C800; - private const int wcSeed = 0x1D290; - - private bool BW; - private bool B2W2; - - private void setChecksums() - { - // Check for invalid block lengths - if (Blocks.Length < 3) // arbitrary... - { - Console.WriteLine("Not enough blocks ({0}), aborting setChecksums", Blocks.Length); - return; - } - // Apply checksums - for (int i = 0; i < Blocks.Length; i++) - { - byte[] array = Data.Skip(Blocks[i].Offset).Take(Blocks[i].Length).ToArray(); - ushort chk = ccitt16(array); - BitConverter.GetBytes(chk).CopyTo(Data, Blocks[i].ChecksumOffset); - BitConverter.GetBytes(chk).CopyTo(Data, Blocks[i].ChecksumMirror); - } - } - - public byte[] Write() - { - setChecksums(); - return Data; - } - - public int PartyCount - { - get { return Data[Party]; } - set { Data[Party] = (byte)value; } - } - - public PK5[] BoxData - { - get - { - PK5[] data = new PK5[24 * 30]; - for (int i = 0; i < data.Length; i++) - { - data[i] = getPK5Stored(Box + i/30 * 0x10 + PK5.SIZE_STORED * i); - data[i].Identifier = $"B{(i / 30 + 1).ToString("00")}:{(i % 30 + 1).ToString("00")}"; - } - return data; - } - set - { - if (value == null) - throw new ArgumentNullException(); - if (value.Length != 24 * 30) - throw new ArgumentException("Expected 720, got " + value.Length); - - for (int i = 0; i < value.Length; i++) - setPK5Stored(value[i], Box + i/30 * 0x10 + PK5.SIZE_STORED * i); - } - } - public PK5[] PartyData - { - get - { - PK5[] data = new PK5[PartyCount]; - for (int i = 0; i < data.Length; i++) - data[i] = getPK5Party(Party + 8 + PK5.SIZE_PARTY * i); - return data; - } - set - { - if (value == null) - throw new ArgumentNullException(); - if (value.Length == 0 || value.Length > 6) - throw new ArgumentException("Expected 1-6, got " + value.Length); - if (value[0].Species == 0) - throw new ArgumentException("Can't have an empty first slot." + value.Length); - - PK5[] newParty = value.Where(pk => pk.Species != 0).ToArray(); - - PartyCount = newParty.Length; - Array.Resize(ref newParty, 6); - - for (int i = PartyCount; i < newParty.Length; i++) - newParty[i] = new PK5(); - for (int i = 0; i < newParty.Length; i++) - setPK5Party(newParty[i], Party + 8 + PK5.SIZE_PARTY * i); - } - } - public PK5[] BattleBoxData - { - get - { - PK5[] data = new PK5[6]; - for (int i = 0; i < data.Length; i++) - { - data[i] = getPK5Stored(BattleBox + PK5.SIZE_STORED * i); - if (data[i].Species == 0) - return data.Take(i).ToArray(); - } - return data; - } - } - - public class MysteryGift - { - public readonly PGF[] Cards = new PGF[12]; - public readonly bool[] UsedFlags = new bool[0x800]; - public uint Seed; - } - public MysteryGift WondercardInfo - { - get - { - uint seed = BitConverter.ToUInt32(Data, wcSeed); - MysteryGift Info = new MysteryGift { Seed = seed }; - byte[] wcData = Data.Skip(Wondercard).Take(0xA90).ToArray(); // Encrypted, Decrypt - for (int i = 0; i < wcData.Length; i += 2) - BitConverter.GetBytes((ushort)(BitConverter.ToUInt16(wcData, i) ^ LCRNG(ref seed) >> 16)).CopyTo(wcData, i); - - // 0x100 Bytes for Used Flags - for (int i = 0; i < Info.UsedFlags.Length; i++) - Info.UsedFlags[i] = (wcData[i/8] >> i%8 & 0x1) == 1; - // 12 PGFs - for (int i = 0; i < Info.Cards.Length; i++) - Info.Cards[i] = new PGF(Data.Skip(0x100 + i*PGF.Size).Take(PGF.Size).ToArray()); - - return Info; - } - set - { - MysteryGift Info = value; - byte[] wcData = new byte[0xA90]; - - // Toss back into byte[] - for (int i = 0; i < Info.UsedFlags.Length; i++) - if (Info.UsedFlags[i]) - wcData[i/8] |= (byte)(1 << (i & 7)); - for (int i = 0; i < Info.Cards.Length; i++) - Info.Cards[i].Data.CopyTo(wcData, 0x100 + i*PGF.Size); - - // Decrypted, Encrypt - uint seed = Info.Seed; - for (int i = 0; i < wcData.Length; i += 2) - BitConverter.GetBytes((ushort)(BitConverter.ToUInt16(wcData, i) ^ LCRNG(ref seed) >> 16)).CopyTo(wcData, i); - BitConverter.GetBytes(Info.Seed).CopyTo(Data, wcSeed); - } - } - - public PK5 getPK5Party(int offset) - { - return new PK5(decryptArray(getData(offset, PK5.SIZE_PARTY))); - } - public PK5 getPK5Stored(int offset) - { - return new PK5(decryptArray(getData(offset, PK5.SIZE_STORED))); - } - public void setPK5Party(PK5 pk5, int offset) - { - if (pk5 == null) return; - - setData(pk5.EncryptedPartyData, offset); - Edited = true; - } - public void setPK5Stored(PK5 pk5, int offset) - { - if (pk5 == null) return; - - setData(pk5.EncryptedBoxData, offset); - Edited = true; - } - public byte[] getData(int Offset, int Length) - { - return Data.Skip(Offset).Take(Length).ToArray(); - } - public void setData(byte[] input, int Offset) - { - input.CopyTo(Data, Offset); - Edited = true; - } - } -} From 505d17c86a75747dd5e85da28d408f057fbd4d04 Mon Sep 17 00:00:00 2001 From: Kaphotics Date: Tue, 21 Jun 2016 21:54:14 -0700 Subject: [PATCH 23/49] Update readme Reflect multiple generation support --- README.md | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index c7cf62815..3596503ad 100644 --- a/README.md +++ b/README.md @@ -1,26 +1,25 @@ PKHeX ===== -Pokémon X/Y/OR/AS SAV/PKX file editor, programmed in [C#](https://en.wikipedia.org/wiki/C_Sharp_%28programming_language%29). +Pokémon NDS/3DS save editor, programmed in [C#](https://en.wikipedia.org/wiki/C_Sharp_%28programming_language%29). -Supports binary file loading of the following files originating from the Nintendo 3DS: -* Decrypted Save files (1MB/Cyber Save 0x65600/0x76000 Bytes) -* Individual entity files (232/260 bytes), saved as .pk6 and .ek6 -* Conversion of Event Gift files (.wc6) to .pk6 -* Decrypted Battle Videos - -The following files from previous generations of games are supported: -* Transferring of previous generation entities (.pkm) to .pk6 -* Conversion of Event Files (.pgt, .pcd, .pgf) to .pk6 +Supports the following files originating from the Nintendo NDS & 3DS: +* Save files ("main", .sav) +* Individual Pokémon entity files (.pk*) +* Mystery Gift files (.pgt, .pcd, .pgf, .wc6) including conversion to .pk* +* Importing teams from Decrypted Battle Videos (X/Y/OR/AS only) +* Transferring of previous generation entities (.pkm) to future generation formats and save files -Data is then displayed in a meaningful view, and can be edited and saved back to binary data. -Since the Nintendo 3DS savedata containers use an AES MAC that cannot be emulated without the 3DS's keys, a resigning service is required (svdt, save_manager, or SaveDataFiler). +Data is displayed in a view which can be edited and saved. +The interface can be translated with resource/external text files so that different languages can be supported. -The interface is translatable with resource/external text files so that different languages can be supported. +Pokémon Showdown sets can be imported/exported in addition to QR codes. + +Nintendo 3DS savedata containers use an AES MAC that cannot be emulated without the 3DS's keys, thus a resigning service is required (svdt, save_manager, or SaveDataFiler). ## Screenshots -![Main Window](http://i.imgur.com/BjPBhKm.png) +![Main Window](http://i.imgur.com/GBub4le.png) ### License From 027518c3300642a9cfa91efb5182d28378a6b810 Mon Sep 17 00:00:00 2001 From: Kaphotics Date: Tue, 21 Jun 2016 22:19:26 -0700 Subject: [PATCH 24/49] Fix pkm info clearing on SAV load returned PKM uses the same reference as the Main.pkm; clone to a new object before returning => separate object reference. --- PKX/f1-Main.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/PKX/f1-Main.cs b/PKX/f1-Main.cs index f79637ae0..deb0812db 100644 --- a/PKX/f1-Main.cs +++ b/PKX/f1-Main.cs @@ -774,9 +774,9 @@ private void openSAV(byte[] input, string path) break; } - pkm = preparePKM(); + PKM pk = preparePKM(); populateFilteredDataSources(); - populateFields(pkm.Format != SAV.Generation ? SAV.BlankPKM : pkm); + populateFields(pkm.Format != SAV.Generation ? SAV.BlankPKM : pk); // SAV Specific Limits TB_OT.MaxLength = SAV.OTLength; @@ -2676,7 +2676,7 @@ public PKM preparePKM(bool click = true) pk = preparePK6(); break; } - return pk; + return pk?.Clone(); } private PK4 preparePK4() { From d2342ba9659e66a8c00151dad49a5669245e40ca Mon Sep 17 00:00:00 2001 From: Kaphotics Date: Wed, 22 Jun 2016 12:31:53 -0700 Subject: [PATCH 25/49] Fix pokecenter purchase ORAS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ever Grande Pokémon League lobby has a vendor, and is considered a Pokécenter. Thus, memory 5 is obtainable in OR/AS. Resolves #125 --- Legality/Tables.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Legality/Tables.cs b/Legality/Tables.cs index c03db8fe7..653ec34b5 100644 --- a/Legality/Tables.cs +++ b/Legality/Tables.cs @@ -869,7 +869,6 @@ public static partial class Legal }; internal static readonly int[] Memory_NotAO = { - 5, // {0} went to a Pokémon Center with {1} to buy {2}. {4} that {3}. 11, // {0} went clothes shopping with {1}. {4} that {3}. 43, // {0} was impressed by the speed of the train it took with {1}. {4} that {3}. 44, // {0} encountered {2} with {1} using the Poké Radar. {4} that {3}. From ca139cf7e491f08f3f0fa13a385f678dcb3b83bf Mon Sep 17 00:00:00 2001 From: Kaphotics Date: Thu, 23 Jun 2016 21:55:14 -0700 Subject: [PATCH 26/49] Add gen4 current box --- Saves/SAV4.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Saves/SAV4.cs b/Saves/SAV4.cs index bcdf79d86..1e9fe9277 100644 --- a/Saves/SAV4.cs +++ b/Saves/SAV4.cs @@ -531,7 +531,7 @@ public int Y public override int SecondsToFame { get { return BitConverter.ToInt32(Data, AdventureInfo + 0x3C); } set { BitConverter.GetBytes(value).CopyTo(Data, AdventureInfo + 0x3C); } } // Storage - public int UnlockedBoxes + public override int CurrentBox { get { return Data[Box - 4]; } set { Data[Box - 4] = (byte)value; } From 86b2090ba1fb1aa67b7240cd633309224131d931 Mon Sep 17 00:00:00 2001 From: Evan Dixon Date: Sun, 26 Jun 2016 13:46:08 -0500 Subject: [PATCH 27/49] Altered SaveUtil to be usable from external assemblies --- Saves/SaveUtil.cs | 116 +++++++++++++++++++++++++++++++++------------- 1 file changed, 83 insertions(+), 33 deletions(-) diff --git a/Saves/SaveUtil.cs b/Saves/SaveUtil.cs index af9a41b32..9491e97d5 100644 --- a/Saves/SaveUtil.cs +++ b/Saves/SaveUtil.cs @@ -17,7 +17,32 @@ public enum GameVersion DP = 100, HGSS = 101, } - internal static class SaveUtil + + public enum Gen4Version + { + Invalid = -1, + DP = 0, + Pt = 1, + HGSS = 2 + } + + public enum Gen5Version + { + Invalid = -1, + BW = 0, + B2W2 = 1 + } + + public enum Gen6Version + { + Invalid = -1, + XY = 0, + ORASDEMO = 1, + ORAS = 2, + Default = 3 //Todo: rename this to something else; referenced in getIsG6SAV + } + + public static class SaveUtil { internal const int BEEF = 0x42454546; @@ -31,75 +56,94 @@ internal static class SaveUtil internal static readonly byte[] FOOTER_DSV = Encoding.ASCII.GetBytes("|-DESMUME SAVE-|"); - internal static int getSAVGeneration(byte[] data) + /// + /// Determines the generation of the given save data. + /// + /// Save data of which to determine the generation + /// The generation of the save file (i.e. 4, 5, or 6), or -1 if the generation cannot be determined. + public static int getSAVGeneration(byte[] data) { - if (getIsG4SAV(data) != -1) + if (getIsG4SAV(data) != Gen4Version.Invalid) return 4; if (getIsG5SAV(data) != -1) return 5; - if (getIsG6SAV(data) != -1) + if (getIsG6SAV(data) != Gen6Version.Invalid) return 6; return -1; } - internal static int getIsG4SAV(byte[] data) + + /// + /// Determines the type of 4th gen save + /// + /// Save data of which to determine the type + /// + public static Gen4Version getIsG4SAV(byte[] data) { if (data.Length != SIZE_G4RAW) - return -1; + return Gen4Version.Invalid; // General Block Checksum if (BitConverter.ToUInt16(data, 0xC0FE) == ccitt16(data.Take(0xC0EC).ToArray())) - return 0; // DP + return Gen4Version.DP; if (BitConverter.ToUInt16(data, 0xCF2A) == ccitt16(data.Take(0xCF18).ToArray())) - return 1; // Pt + return Gen4Version.Pt; if (BitConverter.ToUInt16(data, 0xF626) == ccitt16(data.Take(0xF618).ToArray())) - return 2; // HGSS + return Gen4Version.HGSS; // General Block Checksum is invalid, check for block identifiers if (data.Skip(0xC0F4).Take(10).SequenceEqual(new byte[] { 0x00, 0xC1, 0x00, 0x00, 0x23, 0x06, 0x06, 0x20, 0x00, 0x00 })) - return 0; // DP + return Gen4Version.DP; if (data.Skip(0xCF20).Take(10).SequenceEqual(new byte[] { 0x2C, 0xCF, 0x00, 0x00, 0x23, 0x06, 0x06, 0x20, 0x00, 0x00 })) - return 1; // Pt + return Gen4Version.Pt; if (data.Skip(0xF61C).Take(10).SequenceEqual(new byte[] { 0x28, 0xF6, 0x00, 0x00, 0x23, 0x06, 0x06, 0x20, 0x00, 0x00 })) - return 2; // HGSS + return Gen4Version.HGSS; - return -1; + return Gen4Version.Invalid; } - internal static int getIsG5SAV(byte[] data) + + public static Gen5Version getIsG5SAV(byte[] data) { if (data.Length != SIZE_G5RAW) - return -1; + return Gen5Version.Invalid; ushort chk1 = BitConverter.ToUInt16(data, SIZE_G5BW - 0x100 + 0x8C + 0xE); ushort actual1 = ccitt16(data.Skip(SIZE_G5BW - 0x100).Take(0x8C).ToArray()); if (chk1 == actual1) - return 0; + return Gen5Version.BW; ushort chk2 = BitConverter.ToUInt16(data, SIZE_G5B2W2 - 0x100 + 0x94 + 0xE); ushort actual2 = ccitt16(data.Skip(SIZE_G5B2W2 - 0x100).Take(0x94).ToArray()); if (chk2 == actual2) - return 1; - return -1; + return Gen5Version.B2W2; + return Gen5Version.Invalid; } - internal static int getIsG6SAV(byte[] data) + + public static Gen6Version getIsG6SAV(byte[] data) { if (!SizeValidSAV6(data.Length)) - return -1; + return Gen6Version.Invalid; if (BitConverter.ToUInt32(data, data.Length - 0x1F0) != BEEF) - return -1; + return Gen6Version.Invalid; switch (data.Length) { case SIZE_G6XY: - return 0; + return Gen6Version.XY; case SIZE_G6ORASDEMO: - return 1; + return Gen6Version.ORASDEMO; case SIZE_G6ORAS: - return 2; + return Gen6Version.ORAS; default: // won't hit - return 3; + return Gen6Version.Default; } } - internal static SaveFile getVariantSAV(byte[] data) + + /// + /// Creates an instance of a SaveFile using the given save data. + /// + /// Save data from which to create a SaveFile. + /// An appropriate type of save file for the given data, or null if the save data is invalid. + public static SaveFile getVariantSAV(byte[] data) { switch (getSAVGeneration(data)) { @@ -113,7 +157,13 @@ internal static SaveFile getVariantSAV(byte[] data) return null; } } - internal static bool SizeValidSAV6(int size) + + /// + /// Determines whether the save data size is valid for 6th generation saves. + /// + /// Size in bytes of the save data + /// A boolean indicating whether or not the save data size is valid. + public static bool SizeValidSAV6(int size) { switch (size) { @@ -129,7 +179,7 @@ internal static bool SizeValidSAV6(int size) /// Calculates the CRC16-CCITT checksum over an input byte array. /// Input byte array /// Checksum - internal static ushort ccitt16(byte[] data) + public static ushort ccitt16(byte[] data) { const ushort init = 0xFFFF; const ushort poly = 0x1021; @@ -151,7 +201,7 @@ internal static ushort ccitt16(byte[] data) /// Simple check to see if the save is valid. /// Input binary file /// True/False - internal static bool verifyG6SAV(byte[] savefile) + public static bool verifyG6SAV(byte[] savefile) { // Dynamic handling of checksums regardless of save size. @@ -193,7 +243,7 @@ internal static bool verifyG6SAV(byte[] savefile) /// Verbose check to see if the save is valid. /// Input binary file /// String containing invalid blocks. - internal static string verifyG6CHK(byte[] savefile) + public static string verifyG6CHK(byte[] savefile) { string rv = ""; int invalid = 0; @@ -241,7 +291,7 @@ internal static string verifyG6CHK(byte[] savefile) /// Fix checksums in the input save file. /// Input binary file /// Fixed save file. - internal static void writeG6CHK(byte[] savefile) + public static void writeG6CHK(byte[] savefile) { // Dynamic handling of checksums regardless of save size. @@ -277,7 +327,7 @@ internal static void writeG6CHK(byte[] savefile) } } - internal static int getDexFormIndexXY(int species, int formct) + public static int getDexFormIndexXY(int species, int formct) { if (formct < 1 || species < 0) return -1; // invalid @@ -343,7 +393,7 @@ internal static int getDexFormIndexXY(int species, int formct) default: return -1; } } - internal static int getDexFormIndexORAS(int species, int formct) + public static int getDexFormIndexORAS(int species, int formct) { if (formct < 1 || species < 0) return -1; // invalid From f538cb779c1d55e323d6c4f671995af1ae88981a Mon Sep 17 00:00:00 2001 From: Evan Dixon Date: Sun, 26 Jun 2016 13:48:39 -0500 Subject: [PATCH 28/49] Implementation fixes --- Saves/SaveUtil.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Saves/SaveUtil.cs b/Saves/SaveUtil.cs index 9491e97d5..cf6b4788b 100644 --- a/Saves/SaveUtil.cs +++ b/Saves/SaveUtil.cs @@ -39,7 +39,7 @@ public enum Gen6Version XY = 0, ORASDEMO = 1, ORAS = 2, - Default = 3 //Todo: rename this to something else; referenced in getIsG6SAV + Other = 3 //Todo: rename this to something else; referenced in getIsG6SAV } public static class SaveUtil @@ -65,7 +65,7 @@ public static int getSAVGeneration(byte[] data) { if (getIsG4SAV(data) != Gen4Version.Invalid) return 4; - if (getIsG5SAV(data) != -1) + if (getIsG5SAV(data) != Gen5Version.Invalid) return 5; if (getIsG6SAV(data) != Gen6Version.Invalid) return 6; @@ -134,7 +134,7 @@ public static Gen6Version getIsG6SAV(byte[] data) case SIZE_G6ORAS: return Gen6Version.ORAS; default: // won't hit - return Gen6Version.Default; + return Gen6Version.Other; } } From 2cba9de40a8503757968bf8ea18b76d58738e065 Mon Sep 17 00:00:00 2001 From: Evan Dixon Date: Sun, 26 Jun 2016 13:54:02 -0500 Subject: [PATCH 29/49] Fixed incomplete implementation --- Saves/SAV4.cs | 2 +- Saves/SAV5.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Saves/SAV4.cs b/Saves/SAV4.cs index 1e9fe9277..3a46acdb8 100644 --- a/Saves/SAV4.cs +++ b/Saves/SAV4.cs @@ -15,7 +15,7 @@ public SAV4(byte[] data = null, int versionOverride = -1) Exportable = !Data.SequenceEqual(new byte[Data.Length]); // Get Version - SaveVersion = versionOverride > -1 ? versionOverride : Math.Max(SaveUtil.getIsG4SAV(Data), 0); // Empty file default to DP + SaveVersion = versionOverride > -1 ? versionOverride : Math.Max((int)SaveUtil.getIsG4SAV(Data), 0); // Empty file default to DP getActiveBlock(); getSAVOffsets(); diff --git a/Saves/SAV5.cs b/Saves/SAV5.cs index e47aa054c..c0bfe2a19 100644 --- a/Saves/SAV5.cs +++ b/Saves/SAV5.cs @@ -17,7 +17,7 @@ public SAV5(byte[] data = null, int versionOverride = -1) Exportable = !Data.SequenceEqual(new byte[Data.Length]); // Get Version - SaveVersion = versionOverride > -1 ? versionOverride : SaveUtil.getIsG5SAV(Data); + SaveVersion = versionOverride > -1 ? versionOverride : (int)SaveUtil.getIsG5SAV(Data); if (SaveVersion < 0) // Invalidate Data Data = null; From 37fb94c8c0ec9ebb43a201a4ab8a3d0e644d958f Mon Sep 17 00:00:00 2001 From: Evan Dixon Date: Sun, 26 Jun 2016 14:39:53 -0500 Subject: [PATCH 30/49] Fixed each save file's Footer not being initialized within the class --- Saves/SAV4.cs | 1 + Saves/SAV5.cs | 1 + Saves/SAV6.cs | 1 + 3 files changed, 3 insertions(+) diff --git a/Saves/SAV4.cs b/Saves/SAV4.cs index 3a46acdb8..cfab0e8f6 100644 --- a/Saves/SAV4.cs +++ b/Saves/SAV4.cs @@ -13,6 +13,7 @@ public SAV4(byte[] data = null, int versionOverride = -1) Data = data == null ? new byte[SaveUtil.SIZE_G4RAW] : (byte[])data.Clone(); BAK = (byte[])Data.Clone(); Exportable = !Data.SequenceEqual(new byte[Data.Length]); + Footer = new byte[0]; // Get Version SaveVersion = versionOverride > -1 ? versionOverride : Math.Max((int)SaveUtil.getIsG4SAV(Data), 0); // Empty file default to DP diff --git a/Saves/SAV5.cs b/Saves/SAV5.cs index c0bfe2a19..2dd0b690b 100644 --- a/Saves/SAV5.cs +++ b/Saves/SAV5.cs @@ -15,6 +15,7 @@ public SAV5(byte[] data = null, int versionOverride = -1) Data = data == null ? new byte[SaveUtil.SIZE_G5RAW] : (byte[])data.Clone(); BAK = (byte[])Data.Clone(); Exportable = !Data.SequenceEqual(new byte[Data.Length]); + Footer = new byte[0]; // Get Version SaveVersion = versionOverride > -1 ? versionOverride : (int)SaveUtil.getIsG5SAV(Data); diff --git a/Saves/SAV6.cs b/Saves/SAV6.cs index fc9b4e24d..82d75bf02 100644 --- a/Saves/SAV6.cs +++ b/Saves/SAV6.cs @@ -15,6 +15,7 @@ public SAV6(byte[] data = null) Data = data == null ? new byte[SaveUtil.SIZE_G6ORAS] : (byte[])data.Clone(); BAK = (byte[])Data.Clone(); Exportable = !Data.SequenceEqual(new byte[Data.Length]); + Footer = new byte[0]; // Load Info getBlockInfo(); From e6e3caabb2960d048ca38bfc1268a4c341fda6f5 Mon Sep 17 00:00:00 2001 From: Kaphotics Date: Sun, 26 Jun 2016 14:23:41 -0700 Subject: [PATCH 31/49] Sync basic gen3 support Still many things not yet working (item/inventory editing needs new string resources) --- Legality/Tables3.cs | 36 +++ PKHeX.csproj | 2 + PKM/PK3.cs | 17 +- PKM/PKM.cs | 17 +- PKM/PKX.cs | 88 ++++++- PKX/f1-Main.cs | 294 +++++++++++++++++++---- SAV/SAV_SimpleTrainer.Designer.cs | 181 +++++++------- SAV/SAV_SimpleTrainer.cs | 28 ++- Saves/SAV3.cs | 382 ++++++++++++++++++++++++++++++ Saves/SAV4.cs | 1 - Saves/SaveFile.cs | 10 +- Saves/SaveUtil.cs | 36 +++ 12 files changed, 928 insertions(+), 164 deletions(-) create mode 100644 Legality/Tables3.cs create mode 100644 Saves/SAV3.cs diff --git a/Legality/Tables3.cs b/Legality/Tables3.cs new file mode 100644 index 000000000..fb828819e --- /dev/null +++ b/Legality/Tables3.cs @@ -0,0 +1,36 @@ +using System.Linq; + +namespace PKHeX +{ + public static partial class Legal + { + // PKHeX Valid Array Storage + #region DP + internal static readonly ushort[] Pouch_Items_RS = { + 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 63, 64, 65, 66, 67, 68, 69, 70, 71, 73, 74, 75, 76, 77, 78, 79, 80, 81, 83, 84, 85, 86, 93, 94, 95, 96, 97, 98, 103, 104, 106, 107, 108, 109, 110, 111, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 254, 255, 256, 257, 258 + }; + internal static readonly ushort[] Pouch_Key_RS = { + 259, 260, 261, 262, 263, 264, 265, 266, 268, 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288 + }; + internal static readonly ushort[] Pouch_TM_RS = { + 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, 323, 324, 325, 326, 327, 328, 329, 330, 331, 332, 333, 334, 335, 336, 337, 338, + }; + internal static readonly ushort[] Pouch_HM_RS = { + 339, 340, 341, 342, 343, 344, 345, 346 + }; + internal static readonly ushort[] Pouch_Berries_RS = { + 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175 + }; + internal static readonly ushort[] Pouch_Ball_RS = { + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 + }; + internal static readonly ushort[] Pouch_Key_E = Pouch_Key_RS.Concat(new ushort[] { 375, 376 }).ToArray(); + internal static readonly ushort[] Pouch_Key_FRLG = Pouch_Key_RS.Concat(new ushort[] { 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, 362, 363, 364, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374 }).ToArray(); + + internal static readonly ushort[] Pouch_TMHM_RS = Pouch_TM_RS.Concat(Pouch_HM_RS).ToArray(); + internal static readonly ushort[] HeldItems_RS = new ushort[1].Concat(Pouch_Items_RS).Concat(Pouch_Ball_RS).Concat(Pouch_Berries_RS).Concat(Pouch_TM_RS).ToArray(); + #endregion + + + } +} diff --git a/PKHeX.csproj b/PKHeX.csproj index bb15760cd..c3c813445 100644 --- a/PKHeX.csproj +++ b/PKHeX.csproj @@ -71,6 +71,7 @@ + @@ -92,6 +93,7 @@ + diff --git a/PKM/PK3.cs b/PKM/PK3.cs index d2e9f9a29..7594f9127 100644 --- a/PKM/PK3.cs +++ b/PKM/PK3.cs @@ -5,6 +5,10 @@ namespace PKHeX { public class PK3 : PKM // 3rd Generation PKM File { + internal static readonly byte[] ExtraBytes = + { + 0x2A, 0x2B + }; public override int SIZE_PARTY => PKX.SIZE_3PARTY; public override int SIZE_STORED => PKX.SIZE_3STORED; public override int Format => 3; @@ -22,7 +26,8 @@ public PK3(byte[] decryptedData = null, string ident = null) public override uint EncryptionConstant { get { return PID; } set { } } public override int Nature { get { return (int)(PID % 25); } set { } } public override int AltForm { get { return -1; } set { } } - public override bool IsNicknamed { get { return Nickname != PKX.getSpeciesName(Species, Language); } set { } } + + public override bool IsNicknamed { get { return PKX.getIsNicknamed(Species, Nickname); } set { } } public override int Gender { get { return PKX.getGender(Species, PID); } set { } } public override int Characteristic => -1; public override int CurrentFriendship { get { return OT_Friendship; } set { OT_Friendship = value; } } @@ -41,7 +46,7 @@ public PK3(byte[] decryptedData = null, string ident = null) if (strdata.Length > 10) Array.Resize(ref strdata, 10); strdata.CopyTo(Data, 0x08); } } - public override int Language { get { return BitConverter.ToUInt16(Data, 0x12); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x12); } } + public override int Language { get { return BitConverter.ToUInt16(Data, 0x12) & 0xFF; } set { BitConverter.GetBytes((ushort)(value | 0x200)).CopyTo(Data, 0x12); } } public override string OT_Name { get { return PKX.getG3Str(Data.Skip(0x14).Take(7).ToArray(), Japanese); } set { byte[] strdata = PKX.setG3Str(value, Japanese); @@ -55,7 +60,9 @@ public PK3(byte[] decryptedData = null, string ident = null) #region Block A public override int Species { get { return PKX.getG4Species(BitConverter.ToUInt16(Data, 0x20)); } set { BitConverter.GetBytes((ushort)PKX.getG3Species(value)).CopyTo(Data, 0x20); } } - public override int HeldItem { get { return BitConverter.ToUInt16(Data, 0x22); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x22); } } + public override int HeldItem { get { return PKX.getG4Item((ushort)G3Item); } set { } } + public int G3Item { get { return PKX.getG4Item(BitConverter.ToUInt16(Data, 0x22)); } set { BitConverter.GetBytes((ushort) value).CopyTo(Data, 0x22); } } + public override uint EXP { get { return BitConverter.ToUInt32(Data, 0x24); } set { BitConverter.GetBytes(value).CopyTo(Data, 0x24); } } private byte PPUps { get { return Data[0x28]; } set { Data[0x28] = value; } } public override int Move1_PPUps { get { return (PPUps >> 0) & 3; } set { PPUps = (byte)((PPUps & ~(3 << 0)) | value); } } @@ -154,7 +161,7 @@ public PK3(byte[] decryptedData = null, string ident = null) public override byte[] Encrypt() { - throw new NotImplementedException(); + return PKX.encryptArray3(Data); } public override bool getGenderIsValid() { @@ -277,7 +284,7 @@ public PK4 convertToPK4() // Set Final Data pk4.Met_Level = PKX.getLevel(pk4.Species, pk4.EXP); pk4.Gender = PKX.getGender(pk4.Species, pk4.PID); - pk4.IsNicknamed |= pk4.Nickname != PKX.getSpeciesName(pk4.Species, pk4.Language); + pk4.IsNicknamed = IsNicknamed; // Unown Form if (Species == 201) diff --git a/PKM/PKM.cs b/PKM/PKM.cs index c97495089..eabb37437 100644 --- a/PKM/PKM.cs +++ b/PKM/PKM.cs @@ -19,13 +19,20 @@ public abstract class PKM public byte[] DecryptedPartyData => Write().Take(SIZE_PARTY).ToArray(); public byte[] DecryptedBoxData => Write().Take(SIZE_STORED).ToArray(); - public ushort CalculateChecksum() + protected ushort CalculateChecksum() { ushort chk = 0; - for (int i = 8; i < SIZE_STORED; i += 2) // Loop through the entire PK5 - chk += BitConverter.ToUInt16(Data, i); - - return chk; + 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; + } } public abstract byte[] Encrypt(); public abstract int Format { get; } diff --git a/PKM/PKX.cs b/PKM/PKX.cs index ce0a66a5b..1df311e9f 100644 --- a/PKM/PKX.cs +++ b/PKM/PKX.cs @@ -176,6 +176,11 @@ internal static string getSpeciesName(int species, int lang) try { return SpeciesLang[lang][species]; } catch { return ""; } } + internal static bool getIsNicknamed(int species, string nick) + { + try { return SpeciesLang.All(list => list[species].ToUpper() != nick); } + catch { return false; } + } internal static readonly PersonalInfo[] Personal = Legal.PersonalAO; // Stat Fetching @@ -1628,7 +1633,7 @@ internal static int getGender(int species, uint PID) new byte[] {0x1a, 0x1a}, // 381 new byte[] {0x02, 0x02}, // 382 new byte[] {0x46, 0x46}, // 383 - new byte[] {0x4c, 0x4c}, // 384 + new byte[] {0x4d, 0x4d}, // 384 new byte[] {0x20, 0x20}, // 385 new byte[] {0x2e, 0x2e}, // 386 }; @@ -2039,5 +2044,86 @@ internal static int getGender(int species, uint PID) new byte[] { }, // Unused new byte[] { 0x74, 0x20, 0x0D, 0x02, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA4, 0xA1, 0x0C, 0x02, 0xE0, 0xFF }, }; + + internal static byte[] decryptArray3(byte[] ekm) + { + if (ekm.Length != SIZE_3PARTY && ekm.Length != SIZE_3STORED) + return null; + + uint PID = BitConverter.ToUInt32(ekm, 0); + uint OID = BitConverter.ToUInt32(ekm, 4); + uint seed = PID ^ OID; + + byte[] xorkey = BitConverter.GetBytes(seed); + for (int i = 32; i < 80; i++) + ekm[i] ^= xorkey[i % 4]; + return shuffleArray3(ekm, PID%24); + } + internal static byte[] shuffleArray3(byte[] data, uint sv) + { + byte[] sdata = new byte[data.Length]; + Array.Copy(data, sdata, 32); // Copy unshuffled bytes + + // Shuffle Away! + for (int block = 0; block < 4; block++) + Array.Copy(data, 32 + 12 * blockPosition[block][sv], sdata, 32 + 12 * block, 12); + + // Fill the Battle Stats back + if (data.Length > SIZE_3STORED) + Array.Copy(data, SIZE_3STORED, sdata, SIZE_3STORED, data.Length - SIZE_3STORED); + + return sdata; + } + internal static byte[] encryptArray3(byte[] pkm) + { + if (pkm.Length != SIZE_3PARTY && pkm.Length != SIZE_3STORED) + return null; + + uint PID = BitConverter.ToUInt32(pkm, 0); + uint OID = BitConverter.ToUInt32(pkm, 4); + uint seed = PID ^ OID; + + byte[] ekm = shuffleArray3(pkm, blockPositionInvert[PID%24]); + byte[] xorkey = BitConverter.GetBytes(seed); + for (int i = 32; i < 80; i++) + ekm[i] ^= xorkey[i % 4]; + return ekm; + } + + internal static ushort getG4Item(ushort g3val) + { + ushort[] arr = + { + 0,1,2,3,4,5,6,7,8,9, + 10,11,12,17,18,19,20,21,22,23, + 24,25,26,27,28,29,30,31,32,33, + 34,35,36,37,38,39,40,41,42,65, + 66,67,68,69,43,44,70,71,72,73, + 74,75,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF, + 0xFFFF,0xFFFF,0xFFFF,45,46,47,48,49,50,51, + 52,53,0xFFFF,55,56,57,58,59,60,0xFFFF, + 63,64,0xFFFF,76,77,78,79,0xFFFF,0xFFFF,0xFFFF, + 0xFFFF,0xFFFF,0xFFFF,80,81,82,83,84,85,0xFFFF, + 0xFFFF,0xFFFF,0xFFFF,86,87,0xFFFF,88,89,90,91, + 92,93,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF, + 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF, + 0xFFFF,0xFFFF,0xFFFF,149,150,151,152,153,154,155, + 156,157,158,159,160,161,162,163,164,165, + 166,167,168,169,170,171,172,173,174,175, + 176,177,178,179,180,181,182,183,201,202, + 203,204,205,206,207,208,0xFFFF,0xFFFF,0xFFFF,213, + 214,215,216,217,218,219,220,221,222,223, + 224,225,226,227,228,229,230,231,232,233, + 234,235,236,237,238,239,240,241,242,243, + 244,245,246,247,248,249,250,251,252,253, + 254,255,256,257,258,259,0xFFFF,0xFFFF,0xFFFF,0xFFFF, + 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF, + 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF, + 0xFFFF,0xFFFF,0xFFFF,0xFFFF,260,261,262,263,264, + }; + if (g3val > arr.Length) + return 0xFFFF; + return arr[g3val]; + } } } diff --git a/PKX/f1-Main.cs b/PKX/f1-Main.cs index deb0812db..d51c5a9e5 100644 --- a/PKX/f1-Main.cs +++ b/PKX/f1-Main.cs @@ -724,48 +724,38 @@ private void openSAV(byte[] input, string path) // Generational Interface byte[] extraBytes = new byte[1]; Tip1.RemoveAll(); Tip2.RemoveAll(); Tip3.RemoveAll(); // TSV/PSV + + CB_Country.Visible = CB_SubRegion.Visible = CB_3DSReg.Visible = + Label_Country.Visible = Label_SubRegion.Visible = Label_3DSRegion.Visible = SAV.Generation >= 6; + CB_Ability.Visible = TB_AbilityNumber.Visible = SAV.Generation >= 6; + Label_EncryptionConstant.Visible = BTN_RerollEC.Visible = TB_EC.Visible = SAV.Generation >= 6; + GB_nOT.Visible = GB_RelearnMoves.Visible = BTN_History.Visible = BTN_Ribbons.Visible = SAV.Generation >= 6; + PB_Legal.Visible = PB_WarnMove1.Visible = PB_WarnMove2.Visible = PB_WarnMove3.Visible = PB_WarnMove4.Visible = SAV.Generation >= 6; + + PB_MarkPentagon.Visible = SAV.Generation == 6; + PB_Legal.Visible = PB_WarnMove1.Visible = PB_WarnMove2.Visible = PB_WarnMove3.Visible = PB_WarnMove4.Visible = SAV.Generation == 6; + TB_GameSync.Visible = TB_Secure1.Visible = TB_Secure2.Visible = L_GameSync.Visible = L_Secure1.Visible = L_Secure2.Visible = SAV.Generation == 6; + + CB_Form.Visible = Label_Form.Visible = CHK_AsEgg.Visible = GB_EggConditions.Visible = + Label_MetDate.Visible = CAL_MetDate.Visible = PB_Mark5.Visible = PB_Mark6.Visible = SAV.Generation >= 4; + + DEV_Ability.Enabled = DEV_Ability.Visible = SAV.Generation < 6 || HaX; + TB_AbilityNumber.Visible = SAV.Generation >= 6 && !HaX; + CB_Ability.Visible = SAV.Generation >= 6 && !HaX; + switch (SAV.Generation) { + case 3: + extraBytes = PK3.ExtraBytes; + break; case 4: - TB_GameSync.Visible = TB_Secure1.Visible = TB_Secure2.Visible = false; - L_GameSync.Visible = L_Secure1.Visible = L_Secure2.Visible = false; - CB_Country.Visible = CB_SubRegion.Visible = CB_3DSReg.Visible = false; - Label_Country.Visible = Label_SubRegion.Visible = Label_3DSRegion.Visible = false; - CB_Ability.Visible = TB_AbilityNumber.Visible = false; - GB_nOT.Visible = GB_RelearnMoves.Visible = BTN_History.Visible = BTN_Ribbons.Visible = false; - Label_EncryptionConstant.Visible = BTN_RerollEC.Visible = TB_EC.Visible = false; - PB_MarkPentagon.Visible = false; - PB_Legal.Visible = PB_WarnMove1.Visible = PB_WarnMove2.Visible = PB_WarnMove3.Visible = PB_WarnMove4.Visible = false; - - DEV_Ability.Enabled = DEV_Ability.Visible = true; + extraBytes = PK4.ExtraBytes; break; case 5: - TB_GameSync.Visible = TB_Secure1.Visible = TB_Secure2.Visible = false; - L_GameSync.Visible = L_Secure1.Visible = L_Secure2.Visible = false; - CB_Country.Visible = CB_SubRegion.Visible = CB_3DSReg.Visible = false; - Label_Country.Visible = Label_SubRegion.Visible = Label_3DSRegion.Visible = false; - CB_Ability.Visible = TB_AbilityNumber.Visible = false; - GB_nOT.Visible = GB_RelearnMoves.Visible = BTN_History.Visible = BTN_Ribbons.Visible = false; - Label_EncryptionConstant.Visible = BTN_RerollEC.Visible = TB_EC.Visible = false; - PB_MarkPentagon.Visible = false; - PB_Legal.Visible = PB_WarnMove1.Visible = PB_WarnMove2.Visible = PB_WarnMove3.Visible = PB_WarnMove4.Visible = false; - - DEV_Ability.Enabled = DEV_Ability.Visible = true; extraBytes = PK5.ExtraBytes; break; case 6: - TB_GameSync.Visible = TB_Secure1.Visible = TB_Secure2.Visible = true; - L_GameSync.Visible = L_Secure1.Visible = L_Secure2.Visible = true; - CB_Country.Visible = CB_SubRegion.Visible = CB_3DSReg.Visible = true; - Label_Country.Visible = Label_SubRegion.Visible = Label_3DSRegion.Visible = true; - DEV_Ability.Enabled = DEV_Ability.Visible = TB_AbilityNumber.Visible = HaX; - GB_nOT.Visible = BTN_History.Visible = true; - Label_EncryptionConstant.Visible = BTN_RerollEC.Visible = TB_EC.Visible = true; - PB_MarkPentagon.Visible = true; - PB_Legal.Visible = PB_WarnMove1.Visible = PB_WarnMove2.Visible = PB_WarnMove3.Visible = PB_WarnMove4.Visible = true; - - CB_Ability.Visible = !HaX; extraBytes = PK6.ExtraBytes; TB_GameSync.Enabled = (SAV as SAV6).GameSyncID != 0; TB_GameSync.Text = (SAV as SAV6).GameSyncID.ToString("X16"); @@ -1017,7 +1007,7 @@ private void populateFilteredDataSources() CB_Ball.DataSource = new BindingSource(BallDataSource.Where(b => b.Value <= SAV.MaxBallID), null); CB_Species.DataSource = new BindingSource(SpeciesDataSource.Where(s => s.Value <= SAV.MaxSpeciesID), null); DEV_Ability.DataSource = new BindingSource(AbilityDataSource.Where(a => a.Value <= SAV.MaxAbilityID), null); - CB_GameOrigin.DataSource = new BindingSource(VersionDataSource.Where(g => g.Value <= SAV.MaxGameID), null); + CB_GameOrigin.DataSource = new BindingSource(VersionDataSource.Where(g => g.Value <= SAV.MaxGameID || SAV.Generation >= 3 && g.Value == 15), null); // Set the Move ComboBoxes too.. foreach (ComboBox cb in new[] { CB_Move1, CB_Move2, CB_Move3, CB_Move4, CB_RelearnMove1, CB_RelearnMove2, CB_RelearnMove3, CB_RelearnMove4 }) @@ -1040,6 +1030,9 @@ public void populateFields(PKM pk, bool focus = true) Util.Alert("PKX File has an invalid checksum."); switch (pkm.Format) { + case 3: + populateFieldsPK3(pkm as PK3); + break; case 4: populateFieldsPK4(pkm as PK4); break; @@ -1077,6 +1070,97 @@ public void populateFields(PKM pk, bool focus = true) dragout.Image = pk.Sprite; updateLegality(); } + private void populateFieldsPK3(PK3 pk3) + { + // Do first + pk3.Stat_Level = PKX.getLevel(pk3.Species, pk3.EXP); + if (pk3.Stat_Level == 100) + pk3.EXP = PKX.getEXP(pk3.Stat_Level, pk3.Species); + + CB_Species.SelectedValue = pk3.Species; + TB_Level.Text = pk3.Stat_Level.ToString(); + TB_EXP.Text = pk3.EXP.ToString(); + + // Load rest + CHK_Fateful.Checked = pk3.FatefulEncounter; + CHK_IsEgg.Checked = pk3.IsEgg; + CHK_Nicknamed.Checked = pk3.IsNicknamed; + Label_OTGender.Text = gendersymbols[pk3.OT_Gender]; + Label_OTGender.ForeColor = pk3.OT_Gender == 1 ? Color.Red : Color.Blue; + TB_PID.Text = pk3.PID.ToString("X8"); + CB_HeldItem.SelectedValue = pk3.HeldItem; + setAbilityList(TB_AbilityNumber, pk3.Species, CB_Ability, CB_Form); + DEV_Ability.SelectedValue = pk3.Ability; + CB_Nature.SelectedValue = pk3.Nature; + TB_TID.Text = pk3.TID.ToString("00000"); + TB_SID.Text = pk3.SID.ToString("00000"); + TB_Nickname.Text = pk3.Nickname; + TB_OT.Text = pk3.OT_Name; + TB_Friendship.Text = pk3.CurrentFriendship.ToString(); + GB_OT.BackgroundImage = null; + CB_Language.SelectedValue = pk3.Language; + CB_GameOrigin.SelectedValue = pk3.Version; + CB_EncounterType.SelectedValue = pk3.Gen4 ? pk3.EncounterType : 0; + CB_Ball.SelectedValue = pk3.Ball; + + CB_MetLocation.SelectedValue = pk3.Met_Location; + + TB_MetLevel.Text = pk3.Met_Level.ToString(); + + // Reset Label and ComboBox visibility, as well as non-data checked status. + Label_PKRS.Visible = CB_PKRSStrain.Visible = CHK_Infected.Checked = pk3.PKRS_Strain != 0; + Label_PKRSdays.Visible = CB_PKRSDays.Visible = pk3.PKRS_Days != 0; + + // Set SelectedIndexes for PKRS + CB_PKRSStrain.SelectedIndex = pk3.PKRS_Strain; + CHK_Cured.Checked = pk3.PKRS_Strain > 0 && pk3.PKRS_Days == 0; + CB_PKRSDays.SelectedIndex = Math.Min(CB_PKRSDays.Items.Count - 1, pk3.PKRS_Days); // to strip out bad hacked 'rus + + TB_Cool.Text = pk3.CNT_Cool.ToString(); + TB_Beauty.Text = pk3.CNT_Beauty.ToString(); + TB_Cute.Text = pk3.CNT_Cute.ToString(); + TB_Smart.Text = pk3.CNT_Smart.ToString(); + TB_Tough.Text = pk3.CNT_Tough.ToString(); + TB_Sheen.Text = pk3.CNT_Sheen.ToString(); + + TB_HPIV.Text = pk3.IV_HP.ToString(); + TB_ATKIV.Text = pk3.IV_ATK.ToString(); + TB_DEFIV.Text = pk3.IV_DEF.ToString(); + TB_SPEIV.Text = pk3.IV_SPE.ToString(); + TB_SPAIV.Text = pk3.IV_SPA.ToString(); + TB_SPDIV.Text = pk3.IV_SPD.ToString(); + CB_HPType.SelectedValue = pk3.HPType; + + TB_HPEV.Text = pk3.EV_HP.ToString(); + TB_ATKEV.Text = pk3.EV_ATK.ToString(); + TB_DEFEV.Text = pk3.EV_DEF.ToString(); + TB_SPEEV.Text = pk3.EV_SPE.ToString(); + TB_SPAEV.Text = pk3.EV_SPA.ToString(); + TB_SPDEV.Text = pk3.EV_SPD.ToString(); + + CB_Move1.SelectedValue = pk3.Move1; + CB_Move2.SelectedValue = pk3.Move2; + CB_Move3.SelectedValue = pk3.Move3; + CB_Move4.SelectedValue = pk3.Move4; + CB_PPu1.SelectedIndex = pk3.Move1_PPUps; + CB_PPu2.SelectedIndex = pk3.Move2_PPUps; + CB_PPu3.SelectedIndex = pk3.Move3_PPUps; + CB_PPu4.SelectedIndex = pk3.Move4_PPUps; + TB_PP1.Text = pk3.Move1_PP.ToString(); + TB_PP2.Text = pk3.Move2_PP.ToString(); + TB_PP3.Text = pk3.Move3_PP.ToString(); + TB_PP4.Text = pk3.Move4_PP.ToString(); + + // Load Extrabyte Value + TB_ExtraByte.Text = pk3.Data[Convert.ToInt32(CB_ExtraBytes.Text, 16)].ToString(); + + updateStats(); + setIsShiny(); + + TB_EXP.Text = pk3.EXP.ToString(); + Label_Gender.Text = gendersymbols[pk3.Gender]; + Label_Gender.ForeColor = pk3.Gender == 2 ? Label_Species.ForeColor : (pk3.Gender == 1 ? Color.Red : Color.Blue); + } private void populateFieldsPK4(PK4 pk4) { // Do first @@ -1493,6 +1577,27 @@ internal static void setAbilityList(MaskedTextBox tb_abil, int species, ComboBox cb_abil.SelectedIndex = newabil < 3 ? newabil : 0; } + private void setAbilityList3(MaskedTextBox tb_abil, int species, ComboBox cb_abil, ComboBox cb_forme) + { + if (!fieldsInitialized && string.IsNullOrWhiteSpace(tb_abil.Text)) + return; + int newabil = Convert.ToInt16(tb_abil.Text) >> 1; + + int form = cb_forme.SelectedIndex; + byte[] abils = PKX.Gen3Abilities[Util.getIndex(CB_Species)]; + if (abils[0] == 76) abils[0] = 77; // Air Lock +1 + if (abils[1] == 76) abils[1] = 77; // Air Lock +1 + + // Build Ability List + List ability_list = new List + { + abilitylist[abils[0]] + " (1)", + abilitylist[abils[1]] + " (2)", + }; + cb_abil.DataSource = ability_list; + + cb_abil.SelectedIndex = newabil < 3 ? newabil : 0; + } // PKX Data Calculation Functions // private void setIsShiny() { @@ -1789,7 +1894,10 @@ private void updateIVs(object sender, EventArgs e) TB_IVTotal.Text = pkm.IVs.Sum().ToString(); - L_Characteristic.Text = characteristics[pkm.Characteristic]; + int characteristic = pkm.Characteristic; + L_Characteristic.Visible = characteristic > -1; + if (characteristic > -1) + L_Characteristic.Text = characteristics[pkm.Characteristic]; updateStats(); } private void updateEVs(object sender, EventArgs e) @@ -2232,27 +2340,26 @@ private void updateNatureModification(object sender, EventArgs e) private void updateNickname(object sender, EventArgs e) { if (fieldsInitialized && ModifierKeys == Keys.Control && sender != null) // Import Showdown - { - clickShowdownImportPK6(sender, e); - return; - } + { clickShowdownImportPK6(sender, e); return; } if (fieldsInitialized && ModifierKeys == Keys.Alt && sender != null) // Export Showdown - { - clickShowdownExportPK6(sender, e); - return; - } - if (!fieldsInitialized || CHK_Nicknamed.Checked) return; + { clickShowdownExportPK6(sender, e); return; } + if (!fieldsInitialized || CHK_Nicknamed.Checked) + return; // Fetch Current Species and set it as Nickname Text int species = Util.getIndex(CB_Species); - if (species == 0 || species > 721) + if (species < 1 || species > SAV.MaxSpeciesID) TB_Nickname.Text = ""; else { // get language int lang = Util.getIndex(CB_Language); if (CHK_IsEgg.Checked) species = 0; // Set species to 0 to get the egg name. - TB_Nickname.Text = PKX.getSpeciesName(CHK_IsEgg.Checked ? 0 : species, lang); + string nick = PKX.getSpeciesName(CHK_IsEgg.Checked ? 0 : species, lang); + + if (SAV.Generation < 5) // All caps GenIV and previous + nick = nick.ToUpper(); + TB_Nickname.Text = nick; } } private void updateNicknameClick(object sender, MouseEventArgs e) @@ -2666,6 +2773,9 @@ public PKM preparePKM(bool click = true) PKM pk = null; switch (pkm.Format) { + case 3: + pk = preparePK3(); + break; case 4: pk = preparePK4(); break; @@ -2678,6 +2788,95 @@ public PKM preparePKM(bool click = true) } return pk?.Clone(); } + private PK3 preparePK3() + { + PK3 pk3 = pkm as PK3; + if (pk3 == null) + return null; + + pk3.Species = Util.getIndex(CB_Species); + pk3.G3Item = Util.getIndex(CB_HeldItem); + pk3.TID = Util.ToInt32(TB_TID.Text); + pk3.SID = Util.ToInt32(TB_SID.Text); + pk3.EXP = Util.ToUInt32(TB_EXP.Text); + pk3.PID = Util.getHEXval(TB_PID.Text); + pk3.Ability = (byte)Util.getIndex(DEV_Ability); + //pk4.Ability = (byte)Array.IndexOf(abilitylist, CB_Ability.Text.Remove(CB_Ability.Text.Length - 4)); + + pk3.FatefulEncounter = CHK_Fateful.Checked; + pk3.Gender = PKX.getGender(Label_Gender.Text); + pk3.EV_HP = Util.ToInt32(TB_HPEV.Text); + pk3.EV_ATK = Util.ToInt32(TB_ATKEV.Text); + pk3.EV_DEF = Util.ToInt32(TB_DEFEV.Text); + pk3.EV_SPE = Util.ToInt32(TB_SPEEV.Text); + pk3.EV_SPA = Util.ToInt32(TB_SPAEV.Text); + pk3.EV_SPD = Util.ToInt32(TB_SPDEV.Text); + + pk3.CNT_Cool = Util.ToInt32(TB_Cool.Text); + pk3.CNT_Beauty = Util.ToInt32(TB_Beauty.Text); + pk3.CNT_Cute = Util.ToInt32(TB_Cute.Text); + pk3.CNT_Smart = Util.ToInt32(TB_Smart.Text); + pk3.CNT_Tough = Util.ToInt32(TB_Tough.Text); + pk3.CNT_Sheen = Util.ToInt32(TB_Sheen.Text); + + pk3.PKRS_Days = CB_PKRSDays.SelectedIndex; + pk3.PKRS_Strain = CB_PKRSStrain.SelectedIndex; + pk3.Nickname = TB_Nickname.Text; + pk3.Move1 = Util.getIndex(CB_Move1); + pk3.Move2 = Util.getIndex(CB_Move2); + pk3.Move3 = Util.getIndex(CB_Move3); + pk3.Move4 = Util.getIndex(CB_Move4); + pk3.Move1_PP = Util.getIndex(CB_Move1) > 0 ? Util.ToInt32(TB_PP1.Text) : 0; + pk3.Move2_PP = Util.getIndex(CB_Move2) > 0 ? Util.ToInt32(TB_PP2.Text) : 0; + pk3.Move3_PP = Util.getIndex(CB_Move3) > 0 ? Util.ToInt32(TB_PP3.Text) : 0; + pk3.Move4_PP = Util.getIndex(CB_Move4) > 0 ? Util.ToInt32(TB_PP4.Text) : 0; + pk3.Move1_PPUps = Util.getIndex(CB_Move1) > 0 ? CB_PPu1.SelectedIndex : 0; + pk3.Move2_PPUps = Util.getIndex(CB_Move2) > 0 ? CB_PPu2.SelectedIndex : 0; + pk3.Move3_PPUps = Util.getIndex(CB_Move3) > 0 ? CB_PPu3.SelectedIndex : 0; + pk3.Move4_PPUps = Util.getIndex(CB_Move4) > 0 ? CB_PPu4.SelectedIndex : 0; + + pk3.IV_HP = Util.ToInt32(TB_HPIV.Text); + pk3.IV_ATK = Util.ToInt32(TB_ATKIV.Text); + pk3.IV_DEF = Util.ToInt32(TB_DEFIV.Text); + pk3.IV_SPE = Util.ToInt32(TB_SPEIV.Text); + pk3.IV_SPA = Util.ToInt32(TB_SPAIV.Text); + pk3.IV_SPD = Util.ToInt32(TB_SPDIV.Text); + pk3.IsEgg = CHK_IsEgg.Checked; + pk3.IsNicknamed = CHK_Nicknamed.Checked; + + pk3.OT_Name = TB_OT.Text; + pk3.CurrentFriendship = Util.ToInt32(TB_Friendship.Text); + + pk3.Ball = Util.getIndex(CB_Ball); + pk3.Met_Level = Util.ToInt32(TB_MetLevel.Text); + pk3.OT_Gender = PKX.getGender(Label_OTGender.Text); + pk3.Version = Util.getIndex(CB_GameOrigin); + pk3.Language = Util.getIndex(CB_Language); + + pk3.Met_Location = Util.getIndex(CB_MetLocation); + + // Toss in Party Stats + Array.Resize(ref pk3.Data, pk3.SIZE_PARTY); + pk3.Stat_Level = Util.ToInt32(TB_Level.Text); + pk3.Stat_HPCurrent = Util.ToInt32(Stat_HP.Text); + pk3.Stat_HPMax = Util.ToInt32(Stat_HP.Text); + pk3.Stat_ATK = Util.ToInt32(Stat_ATK.Text); + pk3.Stat_DEF = Util.ToInt32(Stat_DEF.Text); + pk3.Stat_SPE = Util.ToInt32(Stat_SPE.Text); + pk3.Stat_SPA = Util.ToInt32(Stat_SPA.Text); + pk3.Stat_SPD = Util.ToInt32(Stat_SPD.Text); + + if (HaX) + { + pk3.Stat_Level = (byte)Math.Min(Convert.ToInt32(MT_Level.Text), byte.MaxValue); + } + + // Fix Moves if a slot is empty + pk3.FixMoves(); + + pk3.RefreshChecksum(); + return pk3; + } private PK4 preparePK4() { PK4 pk4 = pkm as PK4; @@ -2692,8 +2891,7 @@ private PK4 preparePK4() pk4.PID = Util.getHEXval(TB_PID.Text); pk4.Ability = (byte)Util.getIndex(DEV_Ability); //pk4.Ability = (byte)Array.IndexOf(abilitylist, CB_Ability.Text.Remove(CB_Ability.Text.Length - 4)); - - pk4.Nature = (byte)Util.getIndex(CB_Nature); + pk4.FatefulEncounter = CHK_Fateful.Checked; pk4.Gender = PKX.getGender(Label_Gender.Text); pk4.AltForm = (MT_Form.Enabled ? Convert.ToInt32(MT_Form.Text) : CB_Form.SelectedIndex) & 0x1F; diff --git a/SAV/SAV_SimpleTrainer.Designer.cs b/SAV/SAV_SimpleTrainer.Designer.cs index e95c93130..5ccfc3300 100644 --- a/SAV/SAV_SimpleTrainer.Designer.cs +++ b/SAV/SAV_SimpleTrainer.Designer.cs @@ -28,11 +28,11 @@ protected override void Dispose(bool disposing) /// private void InitializeComponent() { - this.groupBox2 = new System.Windows.Forms.GroupBox(); + this.GB_Adventure = new System.Windows.Forms.GroupBox(); this.L_Started = new System.Windows.Forms.Label(); this.CAL_AdventureStartDate = new System.Windows.Forms.DateTimePicker(); this.CAL_HoFDate = new System.Windows.Forms.DateTimePicker(); - this.L_LastSaved = new System.Windows.Forms.Label(); + this.L_Fame = new System.Windows.Forms.Label(); this.MT_Seconds = new System.Windows.Forms.MaskedTextBox(); this.MT_Hours = new System.Windows.Forms.MaskedTextBox(); this.L_Seconds = new System.Windows.Forms.Label(); @@ -62,8 +62,8 @@ private void InitializeComponent() this.L_X = new System.Windows.Forms.Label(); this.B_Save = new System.Windows.Forms.Button(); this.B_Cancel = new System.Windows.Forms.Button(); - this.groupBox1 = new System.Windows.Forms.GroupBox(); - this.groupBox3 = new System.Windows.Forms.GroupBox(); + this.GB_Trainer = new System.Windows.Forms.GroupBox(); + this.GB_Badges = new System.Windows.Forms.GroupBox(); this.CHK_H8 = new System.Windows.Forms.CheckBox(); this.CHK_H7 = new System.Windows.Forms.CheckBox(); this.CHK_H6 = new System.Windows.Forms.CheckBox(); @@ -80,36 +80,36 @@ private void InitializeComponent() this.CHK_3 = new System.Windows.Forms.CheckBox(); this.CHK_2 = new System.Windows.Forms.CheckBox(); this.CHK_1 = new System.Windows.Forms.CheckBox(); - this.groupBox2.SuspendLayout(); + this.GB_Adventure.SuspendLayout(); this.GB_Map.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.NUD_Z)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.NUD_M)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.NUD_Y)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.NUD_X)).BeginInit(); - this.groupBox1.SuspendLayout(); - this.groupBox3.SuspendLayout(); + this.GB_Trainer.SuspendLayout(); + this.GB_Badges.SuspendLayout(); this.SuspendLayout(); // - // groupBox2 + // GB_Adventure // - this.groupBox2.Controls.Add(this.L_Started); - this.groupBox2.Controls.Add(this.CAL_AdventureStartDate); - this.groupBox2.Controls.Add(this.CAL_HoFDate); - this.groupBox2.Controls.Add(this.L_LastSaved); - this.groupBox2.Controls.Add(this.MT_Seconds); - this.groupBox2.Controls.Add(this.MT_Hours); - this.groupBox2.Controls.Add(this.L_Seconds); - this.groupBox2.Controls.Add(this.L_Hours); - this.groupBox2.Controls.Add(this.MT_Minutes); - this.groupBox2.Controls.Add(this.L_Minutes); - this.groupBox2.Controls.Add(this.CAL_AdventureStartTime); - this.groupBox2.Controls.Add(this.CAL_HoFTime); - this.groupBox2.Location = new System.Drawing.Point(12, 98); - this.groupBox2.Name = "groupBox2"; - this.groupBox2.Size = new System.Drawing.Size(200, 151); - this.groupBox2.TabIndex = 70; - this.groupBox2.TabStop = false; - this.groupBox2.Text = "Adventure Info"; + this.GB_Adventure.Controls.Add(this.L_Started); + this.GB_Adventure.Controls.Add(this.CAL_AdventureStartDate); + this.GB_Adventure.Controls.Add(this.CAL_HoFDate); + this.GB_Adventure.Controls.Add(this.L_Fame); + this.GB_Adventure.Controls.Add(this.MT_Seconds); + this.GB_Adventure.Controls.Add(this.MT_Hours); + this.GB_Adventure.Controls.Add(this.L_Seconds); + this.GB_Adventure.Controls.Add(this.L_Hours); + this.GB_Adventure.Controls.Add(this.MT_Minutes); + this.GB_Adventure.Controls.Add(this.L_Minutes); + this.GB_Adventure.Controls.Add(this.CAL_AdventureStartTime); + this.GB_Adventure.Controls.Add(this.CAL_HoFTime); + this.GB_Adventure.Location = new System.Drawing.Point(11, 98); + this.GB_Adventure.Name = "GB_Adventure"; + this.GB_Adventure.Size = new System.Drawing.Size(200, 151); + this.GB_Adventure.TabIndex = 70; + this.GB_Adventure.TabStop = false; + this.GB_Adventure.Text = "Adventure Info"; // // L_Started // @@ -141,14 +141,14 @@ private void InitializeComponent() this.CAL_HoFDate.TabIndex = 31; this.CAL_HoFDate.Value = new System.DateTime(2000, 1, 1, 0, 0, 0, 0); // - // L_LastSaved + // L_Fame // - this.L_LastSaved.Location = new System.Drawing.Point(4, 107); - this.L_LastSaved.Name = "L_LastSaved"; - this.L_LastSaved.Size = new System.Drawing.Size(80, 20); - this.L_LastSaved.TabIndex = 32; - this.L_LastSaved.Text = "Hall of Fame:"; - this.L_LastSaved.TextAlign = System.Drawing.ContentAlignment.MiddleRight; + this.L_Fame.Location = new System.Drawing.Point(4, 107); + this.L_Fame.Name = "L_Fame"; + this.L_Fame.Size = new System.Drawing.Size(80, 20); + this.L_Fame.TabIndex = 32; + this.L_Fame.Text = "Hall of Fame:"; + this.L_Fame.TextAlign = System.Drawing.ContentAlignment.MiddleRight; // // MT_Seconds // @@ -340,7 +340,7 @@ private void InitializeComponent() this.GB_Map.Controls.Add(this.L_CurrentMap); this.GB_Map.Controls.Add(this.L_Z); this.GB_Map.Controls.Add(this.L_X); - this.GB_Map.Location = new System.Drawing.Point(218, 100); + this.GB_Map.Location = new System.Drawing.Point(217, 100); this.GB_Map.Name = "GB_Map"; this.GB_Map.Size = new System.Drawing.Size(157, 125); this.GB_Map.TabIndex = 71; @@ -438,7 +438,7 @@ private void InitializeComponent() // // B_Save // - this.B_Save.Location = new System.Drawing.Point(300, 226); + this.B_Save.Location = new System.Drawing.Point(299, 226); this.B_Save.Name = "B_Save"; this.B_Save.Size = new System.Drawing.Size(75, 23); this.B_Save.TabIndex = 73; @@ -448,7 +448,7 @@ private void InitializeComponent() // // B_Cancel // - this.B_Cancel.Location = new System.Drawing.Point(219, 226); + this.B_Cancel.Location = new System.Drawing.Point(218, 226); this.B_Cancel.Name = "B_Cancel"; this.B_Cancel.Size = new System.Drawing.Size(75, 23); this.B_Cancel.TabIndex = 72; @@ -456,49 +456,49 @@ private void InitializeComponent() this.B_Cancel.UseVisualStyleBackColor = true; this.B_Cancel.Click += new System.EventHandler(this.B_Cancel_Click); // - // groupBox1 + // GB_Trainer // - this.groupBox1.Controls.Add(this.TB_OTName); - this.groupBox1.Controls.Add(this.B_MaxCash); - this.groupBox1.Controls.Add(this.MT_SID); - this.groupBox1.Controls.Add(this.MT_TID); - this.groupBox1.Controls.Add(this.L_Money); - this.groupBox1.Controls.Add(this.L_SID); - this.groupBox1.Controls.Add(this.CB_Gender); - this.groupBox1.Controls.Add(this.MT_Money); - this.groupBox1.Controls.Add(this.L_TID); - this.groupBox1.Controls.Add(this.L_TrainerName); - this.groupBox1.Location = new System.Drawing.Point(12, 12); - this.groupBox1.Name = "groupBox1"; - this.groupBox1.Size = new System.Drawing.Size(200, 82); - this.groupBox1.TabIndex = 74; - this.groupBox1.TabStop = false; - this.groupBox1.Text = "Trainer"; + this.GB_Trainer.Controls.Add(this.TB_OTName); + this.GB_Trainer.Controls.Add(this.B_MaxCash); + this.GB_Trainer.Controls.Add(this.MT_SID); + this.GB_Trainer.Controls.Add(this.MT_TID); + this.GB_Trainer.Controls.Add(this.L_Money); + this.GB_Trainer.Controls.Add(this.L_SID); + this.GB_Trainer.Controls.Add(this.CB_Gender); + this.GB_Trainer.Controls.Add(this.MT_Money); + this.GB_Trainer.Controls.Add(this.L_TID); + this.GB_Trainer.Controls.Add(this.L_TrainerName); + this.GB_Trainer.Location = new System.Drawing.Point(11, 12); + this.GB_Trainer.Name = "GB_Trainer"; + this.GB_Trainer.Size = new System.Drawing.Size(200, 82); + this.GB_Trainer.TabIndex = 74; + this.GB_Trainer.TabStop = false; + this.GB_Trainer.Text = "Trainer"; // - // groupBox3 + // GB_Badges // - this.groupBox3.Controls.Add(this.CHK_H8); - this.groupBox3.Controls.Add(this.CHK_H7); - this.groupBox3.Controls.Add(this.CHK_H6); - this.groupBox3.Controls.Add(this.CHK_H5); - this.groupBox3.Controls.Add(this.CHK_H4); - this.groupBox3.Controls.Add(this.CHK_H3); - this.groupBox3.Controls.Add(this.CHK_H2); - this.groupBox3.Controls.Add(this.CHK_H1); - this.groupBox3.Controls.Add(this.CHK_8); - this.groupBox3.Controls.Add(this.CHK_7); - this.groupBox3.Controls.Add(this.CHK_6); - this.groupBox3.Controls.Add(this.CHK_5); - this.groupBox3.Controls.Add(this.CHK_4); - this.groupBox3.Controls.Add(this.CHK_3); - this.groupBox3.Controls.Add(this.CHK_2); - this.groupBox3.Controls.Add(this.CHK_1); - this.groupBox3.Location = new System.Drawing.Point(219, 12); - this.groupBox3.Name = "groupBox3"; - this.groupBox3.Size = new System.Drawing.Size(157, 82); - this.groupBox3.TabIndex = 75; - this.groupBox3.TabStop = false; - this.groupBox3.Text = "Badges"; + this.GB_Badges.Controls.Add(this.CHK_H8); + this.GB_Badges.Controls.Add(this.CHK_H7); + this.GB_Badges.Controls.Add(this.CHK_H6); + this.GB_Badges.Controls.Add(this.CHK_H5); + this.GB_Badges.Controls.Add(this.CHK_H4); + this.GB_Badges.Controls.Add(this.CHK_H3); + this.GB_Badges.Controls.Add(this.CHK_H2); + this.GB_Badges.Controls.Add(this.CHK_H1); + this.GB_Badges.Controls.Add(this.CHK_8); + this.GB_Badges.Controls.Add(this.CHK_7); + this.GB_Badges.Controls.Add(this.CHK_6); + this.GB_Badges.Controls.Add(this.CHK_5); + this.GB_Badges.Controls.Add(this.CHK_4); + this.GB_Badges.Controls.Add(this.CHK_3); + this.GB_Badges.Controls.Add(this.CHK_2); + this.GB_Badges.Controls.Add(this.CHK_1); + this.GB_Badges.Location = new System.Drawing.Point(218, 12); + this.GB_Badges.Name = "GB_Badges"; + this.GB_Badges.Size = new System.Drawing.Size(157, 82); + this.GB_Badges.TabIndex = 75; + this.GB_Badges.TabStop = false; + this.GB_Badges.Text = "Badges"; // // CHK_H8 // @@ -664,37 +664,38 @@ private void InitializeComponent() // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(386, 261); - this.Controls.Add(this.groupBox3); - this.Controls.Add(this.groupBox1); + this.ClientSize = new System.Drawing.Size(384, 261); + this.Controls.Add(this.GB_Badges); + this.Controls.Add(this.GB_Trainer); this.Controls.Add(this.B_Save); this.Controls.Add(this.B_Cancel); this.Controls.Add(this.GB_Map); - this.Controls.Add(this.groupBox2); + this.Controls.Add(this.GB_Adventure); + this.MinimumSize = new System.Drawing.Size(400, 300); this.Name = "SAV_SimpleTrainer"; this.Text = "Trainer Data Editor"; - this.groupBox2.ResumeLayout(false); - this.groupBox2.PerformLayout(); + this.GB_Adventure.ResumeLayout(false); + this.GB_Adventure.PerformLayout(); this.GB_Map.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.NUD_Z)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.NUD_M)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.NUD_Y)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.NUD_X)).EndInit(); - this.groupBox1.ResumeLayout(false); - this.groupBox1.PerformLayout(); - this.groupBox3.ResumeLayout(false); - this.groupBox3.PerformLayout(); + this.GB_Trainer.ResumeLayout(false); + this.GB_Trainer.PerformLayout(); + this.GB_Badges.ResumeLayout(false); + this.GB_Badges.PerformLayout(); this.ResumeLayout(false); } #endregion - private System.Windows.Forms.GroupBox groupBox2; + private System.Windows.Forms.GroupBox GB_Adventure; private System.Windows.Forms.Label L_Started; private System.Windows.Forms.DateTimePicker CAL_AdventureStartDate; private System.Windows.Forms.DateTimePicker CAL_HoFDate; - private System.Windows.Forms.Label L_LastSaved; + private System.Windows.Forms.Label L_Fame; private System.Windows.Forms.MaskedTextBox MT_Seconds; private System.Windows.Forms.MaskedTextBox MT_Hours; private System.Windows.Forms.Label L_Seconds; @@ -724,8 +725,8 @@ private void InitializeComponent() private System.Windows.Forms.Label L_X; private System.Windows.Forms.Button B_Save; private System.Windows.Forms.Button B_Cancel; - private System.Windows.Forms.GroupBox groupBox1; - private System.Windows.Forms.GroupBox groupBox3; + private System.Windows.Forms.GroupBox GB_Trainer; + private System.Windows.Forms.GroupBox GB_Badges; private System.Windows.Forms.CheckBox CHK_8; private System.Windows.Forms.CheckBox CHK_7; private System.Windows.Forms.CheckBox CHK_6; diff --git a/SAV/SAV_SimpleTrainer.cs b/SAV/SAV_SimpleTrainer.cs index 4f19aa6c7..59fd633e6 100644 --- a/SAV/SAV_SimpleTrainer.cs +++ b/SAV/SAV_SimpleTrainer.cs @@ -20,6 +20,20 @@ public SAV_SimpleTrainer() MT_TID.Text = SAV.TID.ToString("00000"); MT_SID.Text = SAV.SID.ToString("00000"); MT_Money.Text = SAV.Money.ToString(); + MT_Hours.Text = SAV.PlayedHours.ToString(); + MT_Minutes.Text = SAV.PlayedMinutes.ToString(); + MT_Seconds.Text = SAV.PlayedSeconds.ToString(); + + if (SAV is SAV3) + { + GB_Map.Visible = false; + GB_Badges.Visible = false; // todo + + L_Started.Visible = L_Fame.Visible = false; + CAL_AdventureStartDate.Visible = CAL_HoFDate.Visible = false; + CAL_AdventureStartTime.Visible = CAL_HoFTime.Visible = false; + return; + } int badgeval = 0; if (SAV is SAV4) @@ -54,9 +68,6 @@ public SAV_SimpleTrainer() cba[i].Checked = (badgeval & 1 << i) != 0; } - MT_Hours.Text = SAV.PlayedHours.ToString(); - MT_Minutes.Text = SAV.PlayedMinutes.ToString(); - MT_Seconds.Text = SAV.PlayedSeconds.ToString(); CAL_HoFDate.Value = new DateTime(2000, 1, 1).AddSeconds(SAV.SecondsToFame); CAL_HoFTime.Value = new DateTime(2000, 1, 1).AddSeconds(SAV.SecondsToFame % 86400); CAL_AdventureStartDate.Value = new DateTime(2000, 1, 1).AddSeconds(SAV.SecondsToStart); @@ -81,6 +92,10 @@ private void B_Save_Click(object sender, EventArgs e) SAV.SID = (ushort)Util.ToUInt32(MT_SID.Text); SAV.Money = Util.ToUInt32(MT_Money.Text); + SAV.PlayedHours = ushort.Parse(MT_Hours.Text); + SAV.PlayedMinutes = ushort.Parse(MT_Minutes.Text) % 60; + SAV.PlayedSeconds = ushort.Parse(MT_Seconds.Text) % 60; + // Copy Badges int badgeval = 0; for (int i = 0; i < cba.Length; i++) @@ -108,12 +123,7 @@ private void B_Save_Click(object sender, EventArgs e) s.Y = (int)NUD_Y.Value; s.Badges = badgeval & 0xFF; } - - // Save PlayTime - SAV.PlayedHours = ushort.Parse(MT_Hours.Text); - SAV.PlayedMinutes = ushort.Parse(MT_Minutes.Text) % 60; - SAV.PlayedSeconds = ushort.Parse(MT_Seconds.Text) % 60; - + SAV.SecondsToStart = getSeconds(CAL_AdventureStartDate, CAL_AdventureStartTime); SAV.SecondsToFame = getSeconds(CAL_HoFDate, CAL_HoFTime); diff --git a/Saves/SAV3.cs b/Saves/SAV3.cs new file mode 100644 index 000000000..4ddd69c0d --- /dev/null +++ b/Saves/SAV3.cs @@ -0,0 +1,382 @@ +using System; +using System.Linq; + +namespace PKHeX +{ + public sealed class SAV3 : SaveFile + { + public override string BAKName => $"{FileName} [{OT} ({Version})" +/* - {LastSavedTime}*/ "].bak"; + public override string Filter => "Main SAV|*.*"; + public override string Extension => ""; + + /* SAV3 Structure: + * 0xE000 per save file + * 14 blocks @ 0x1000 each. + * Blocks do not use all 0x1000 bytes allocated. + * Via: http://bulbapedia.bulbagarden.net/wiki/Save_data_structure_in_Generation_III + */ + private readonly int[] chunkLength = + { + 0xf2c, // 0 | Trainer info + 0xf80, // 1 | Team / items + 0xf80, // 2 | Unknown + 0xf80, // 3 | Unknown + 0xf08, // 4 | Rival info + 0xf80, // 5 | PC Block 0 + 0xf80, // 6 | PC Block 1 + 0xf80, // 7 | PC Block 2 + 0xf80, // 8 | PC Block 3 + 0xf80, // 9 | PC Block 4 + 0xf80, // A | PC Block 5 + 0xf80, // B | PC Block 6 + 0xf80, // C | PC Block 7 + 0x7d0 // D | PC Block 8 + }; + + public SAV3(byte[] data = null) + { + Data = data == null ? new byte[SaveUtil.SIZE_G3RAW] : (byte[])data.Clone(); + BAK = (byte[])Data.Clone(); + Exportable = !Data.SequenceEqual(new byte[Data.Length]); + + BlockOrder = new int[14]; + ActiveSAV = SaveUtil.SIZE_G3RAWHALF == data.Length || BitConverter.ToUInt32(Data, 0xFFC) > BitConverter.ToUInt32(Data, 0xEFFC) ? 0 : 1; + for (int i = 0; i < 14; i++) + BlockOrder[i] = BitConverter.ToInt16(Data, ABO + i*0x1000 + 0xFF4); + + // Detect RS/E/FRLG + // Section 0 stores Game Code @ 0x00AC; 0 for RS, 1 for FRLG, else for Emerald + Trainer1 = Array.IndexOf(BlockOrder, 0)*0x1000 + ABO; + Party = Array.IndexOf(BlockOrder, 1)*0x1000 + ABO; + Block2 = Array.IndexOf(BlockOrder, 2)*0x1000 + ABO; + Block3 = Array.IndexOf(BlockOrder, 3)*0x1000 + ABO; + + uint GameCode = BitConverter.ToUInt32(Data, ABO + Array.IndexOf(BlockOrder, 0)*0x1000); + SaveVersion = GameCode < 2 ? (int)GameCode : 2; + + // Set up PC data buffer beyond end of save file. + Box = Data.Length; + Array.Resize(ref Data, Data.Length + 0x10000); // More than enough empty space. + + // Copy chunk to the allocated location + for (int i = 5; i < 14; i++) + { + int blockIndex = Array.IndexOf(BlockOrder, i); + if (blockIndex == -1) // block empty + continue; + Array.Copy(Data, blockIndex * 0x1000 + ABO, Data, Box + (i - 5)*0xF80, chunkLength[i]); + } + + HeldItems = Legal.HeldItems_RS; + + if (!Exportable) + resetBoxes(); + } + + private readonly int SaveVersion; + private readonly int ActiveSAV; + private int ABO => ActiveSAV*0xE000; + private readonly int[] BlockOrder; + + // Configuration + public override byte[] BAK { get; } + public override bool Exportable { get; } + public override SaveFile Clone() { return new SAV3(Data.Take(Box).ToArray()); } + + public override int SIZE_STORED => PKX.SIZE_3STORED; + public override int SIZE_PARTY => PKX.SIZE_3PARTY; + public override PKM BlankPKM => new PK3(); + protected override Type PKMType => typeof(PK3); + + public override int MaxMoveID => 354; + public override int MaxSpeciesID => 386; + public override int MaxAbilityID => 77; + public override int MaxItemID => 374; + public override int MaxBallID => 0xC; + public override int MaxGameID => 5; + + public override int BoxCount => 14; + public override int MaxEV => 252; + public override int Generation => 3; + protected override int GiftCountMax => 1; + public override int OTLength => 8; + public override int NickLength => 10; + + private int Block2, Block3; + + // Checksums + protected override void setChecksums() + { + for (int i = 0; i < 14; i++) + { + 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); + } + } + public override bool ChecksumsValid + { + get + { + for (int i = 0; i < 14; i++) + { + 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)) + return false; + } + return true; + } + } + public override string ChecksumInfo + { + get + { + string r = ""; + for (int i = 0; i < 14; i++) + { + 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; + } + return r.Length == 0 ? "Checksums valid." : r.TrimEnd(); + } + } + + // Trainer Info + public override GameVersion Version + { + get + { + switch (SaveVersion) + { + case 0: return GameVersion.RS; + case 1: return GameVersion.FRLG; + case 2: return GameVersion.E; + } + return GameVersion.Unknown; + } + } + + private bool Japanese; + private uint SecurityKey + { + get + { + switch (Version) + { + case GameVersion.E: return BitConverter.ToUInt32(Data, Trainer1 + 0xAC); + case GameVersion.FRLG: return BitConverter.ToUInt32(Data, Trainer1 + 0xAF8); + default: return 0; + } + } + } + public override string OT + { + get + { + return PKX.getG3Str(Data.Skip(Trainer1).Take(0x10).ToArray(), Japanese) + .Replace("\uE08F", "\u2640") // Nidoran ♂ + .Replace("\uE08E", "\u2642") // Nidoran ♀ + .Replace("\u2019", "\u0027"); // Farfetch'd + } + set + { + if (value.Length > 7) + value = value.Substring(0, 7); // Hard cap + string TempNick = value // Replace Special Characters and add Terminator + .Replace("\u2640", "\uE08F") // Nidoran ♂ + .Replace("\u2642", "\uE08E") // Nidoran ♀ + .Replace("\u0027", "\u2019"); // Farfetch'd + PKX.setG3Str(TempNick, Japanese).CopyTo(Data, Trainer1); + } + } + public override int Gender + { + get { return Data[Trainer1 + 8]; } + set { Data[Trainer1 + 8] = (byte)value; } + } + public override ushort TID + { + get { return BitConverter.ToUInt16(Data, Trainer1 + 0xA + 0); } + set { BitConverter.GetBytes(value).CopyTo(Data, Trainer1 + 0xA + 0); } + } + public override ushort SID + { + get { return BitConverter.ToUInt16(Data, Trainer1 + 0xC); } + set { BitConverter.GetBytes(value).CopyTo(Data, Trainer1 + 0xC); } + } + public override int PlayedHours + { + get { return BitConverter.ToUInt16(Data, Trainer1 + 0xE); } + set { BitConverter.GetBytes((ushort)value).CopyTo(Data, Trainer1 + 0xE); } + } + public override int PlayedMinutes + { + get { return Data[Trainer1 + 0x10]; } + set { Data[Trainer1 + 0x10] = (byte)value; } + } + public override int PlayedSeconds + { + get { return Data[Trainer1 + 0x11]; } + set { Data[Trainer1 + 0x11] = (byte)value; } + } + public int PlayedFrames + { + get { return Data[Trainer1 + 0x12]; } + set { Data[Trainer1 + 0x12] = (byte)value; } + } + + public override uint Money + { + get + { + switch (Version) + { + case GameVersion.RS: + case GameVersion.E: return BitConverter.ToUInt32(Data, Party + 0x0490) ^ SecurityKey; + case GameVersion.FRLG: return BitConverter.ToUInt32(Data, Party + 0x0290) ^ SecurityKey; + default: return 0; + } + } + set + { + switch (Version) + { + case GameVersion.RS: + case GameVersion.E: BitConverter.GetBytes(value ^ SecurityKey).CopyTo(Data, Party + 0x0490); break; + case GameVersion.FRLG: BitConverter.GetBytes(value ^ SecurityKey).CopyTo(Data, Party + 0x0290); break; + } + } + } + public uint Coin + { + get + { + switch (Version) + { + case GameVersion.RS: + case GameVersion.E: return BitConverter.ToUInt32(Data, Party + 0x0494) ^ SecurityKey; + case GameVersion.FRLG: return BitConverter.ToUInt32(Data, Party + 0x0294) ^ SecurityKey; + default: return 0; + } + } + set + { + switch (Version) + { + case GameVersion.RS: + case GameVersion.E: BitConverter.GetBytes(value ^ SecurityKey).CopyTo(Data, Party + 0x0494); break; + case GameVersion.FRLG: BitConverter.GetBytes(value ^ SecurityKey).CopyTo(Data, Party + 0x0294); break; + } + } + } + public int BP + { + get { return Data[Trainer1 + 0xEB8]; } + set { Data[Trainer1 + 0xEB8] = (byte)value; } + } + + public override InventoryPouch[] Inventory + { + get + { + return null; + + } + set { } + } + public override int Language { get { return 0; } set { } } + + public override int getDaycareSlotOffset(int loc, int slot) + { + return Daycare + slot * SIZE_PARTY; + } + public override ulong? getDaycareRNGSeed(int loc) + { + return null; + } + public override uint? getDaycareEXP(int loc, int slot) + { + int ofs = Daycare + (slot + 1) * SIZE_PARTY - 4; + return BitConverter.ToUInt32(Data, ofs); + } + public override bool? getDaycareOccupied(int loc, int slot) + { + return null; + } + public override void setDaycareEXP(int loc, int slot, uint EXP) + { + int ofs = Daycare + (slot + 1) * SIZE_PARTY - 4; + BitConverter.GetBytes(EXP).CopyTo(Data, ofs); + } + public override void setDaycareOccupied(int loc, int slot, bool occupied) + { + + } + + // Storage + public override int PartyCount + { + get + { + int ofs = 0x34; + if (GameVersion.FRLG != Version) + ofs += 0x200; + return Data[Party + ofs]; + + } + protected set + { + int ofs = 0x34; + if (GameVersion.FRLG != Version) + ofs += 0x200; + Data[Party + ofs] = (byte)value; + } + } + public override int getBoxOffset(int box) + { + return Box + 4 + SIZE_STORED * box * 30; + } + public override int getPartyOffset(int slot) + { + int ofs = 0x38; + if (GameVersion.FRLG != Version) + ofs += 0x200; + return Party + ofs + SIZE_PARTY * slot; + } + public override int CurrentBox + { + get { return Data[Box]; } + set { Data[Box] = (byte)value; } + } + public override int getBoxWallpaper(int box) + { + // Box Wallpaper is directly after the Box Names + int offset = getBoxOffset(BoxCount); + offset += BoxCount * 0x9; + return Data[offset]; + } + public override string getBoxName(int box) + { + int offset = getBoxOffset(BoxCount); + return PKX.getG3Str(Data.Skip(offset + box * 9).Take(9).ToArray(), Japanese); + } + public override void setBoxName(int box, string value) + { + if (value.Length > 8) + value = value.Substring(0, 8); // Hard cap + int offset = getBoxOffset(BoxCount); + PKX.setG3Str(value, Japanese).CopyTo(Data, offset + box * 9); + } + public override PKM getPKM(byte[] data) + { + return new PK3(data); + } + public override byte[] decryptPKM(byte[] data) + { + return PKX.decryptArray3(data); + } + } +} diff --git a/Saves/SAV4.cs b/Saves/SAV4.cs index 1e9fe9277..784898fb7 100644 --- a/Saves/SAV4.cs +++ b/Saves/SAV4.cs @@ -568,7 +568,6 @@ public override byte[] decryptPKM(byte[] data) } // Daycare - public override int DaycareSeedSize => 8; public override int getDaycareSlotOffset(int loc, int slot) { return Daycare + slot * SIZE_PARTY; diff --git a/Saves/SaveFile.cs b/Saves/SaveFile.cs index 1daf83b72..9cfc82206 100644 --- a/Saves/SaveFile.cs +++ b/Saves/SaveFile.cs @@ -84,7 +84,7 @@ public byte[] Write(bool DSV) protected virtual int GiftFlagMax { get; } = 0x800; protected virtual int EventFlagMax { get; } = int.MinValue; protected virtual int EventConstMax { get; } = int.MinValue; - public abstract int DaycareSeedSize { get; } + public virtual int DaycareSeedSize { get; } = 0; public abstract int OTLength { get; } public abstract int NickLength { get; } @@ -249,8 +249,8 @@ public ushort[] EventConsts protected int OFS_MailItems { get; set; } = int.MinValue; // Mystery Gift - protected abstract bool[] MysteryGiftReceivedFlags { get; set; } - protected abstract MysteryGift[] MysteryGiftCards { get; set; } + protected virtual bool[] MysteryGiftReceivedFlags { get { return null; } set { } } + protected virtual MysteryGift[] MysteryGiftCards { get { return null; } set { } } public virtual MysteryGiftAlbum GiftAlbum { get @@ -285,8 +285,8 @@ public virtual MysteryGiftAlbum GiftAlbum public abstract int PlayedHours { get; set; } public abstract int PlayedMinutes { get; set; } public abstract int PlayedSeconds { get; set; } - public abstract int SecondsToStart { get; set; } - public abstract int SecondsToFame { get; set; } + public virtual int SecondsToStart { get; set; } + public virtual int SecondsToFame { get; set; } public abstract uint Money { get; set; } public abstract int BoxCount { get; } public abstract int PartyCount { get; protected set; } diff --git a/Saves/SaveUtil.cs b/Saves/SaveUtil.cs index af9a41b32..678af2428 100644 --- a/Saves/SaveUtil.cs +++ b/Saves/SaveUtil.cs @@ -14,6 +14,8 @@ public enum GameVersion X = 24, Y = 25, AS = 26, OR = 27, SN = 28, MN = 29, + RS = 200, + FRLG = 201, DP = 100, HGSS = 101, } @@ -28,11 +30,15 @@ internal static class SaveUtil internal const int SIZE_G5BW = 0x24000; internal const int SIZE_G5B2W2 = 0x26000; internal const int SIZE_G4RAW = 0x80000; + internal const int SIZE_G3RAW = 0x20000; + internal const int SIZE_G3RAWHALF = 0x10000; internal static readonly byte[] FOOTER_DSV = Encoding.ASCII.GetBytes("|-DESMUME SAVE-|"); internal static int getSAVGeneration(byte[] data) { + if (getIsG3SAV(data) != -1) + return 3; if (getIsG4SAV(data) != -1) return 4; if (getIsG5SAV(data) != -1) @@ -41,6 +47,24 @@ internal static int getSAVGeneration(byte[] data) return 6; return -1; } + internal static int getIsG3SAV(byte[] data) + { + if (data.Length != SIZE_G3RAW && data.Length != SIZE_G3RAWHALF) + return -1; + + 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 -1; + + // Detect RS/E/FRLG + // Section 0 stores Game Code @ 0x00AC; 0 for RS, 1 for FRLG, else for Emerald + + uint GameCode = BitConverter.ToUInt32(data, Array.IndexOf(BlockOrder, 0) * 0x1000); + return GameCode < 2 ? (int)GameCode : 2; + } internal static int getIsG4SAV(byte[] data) { if (data.Length != SIZE_G4RAW) @@ -103,6 +127,8 @@ internal static SaveFile getVariantSAV(byte[] data) { switch (getSAVGeneration(data)) { + case 3: + return new SAV3(data); case 4: return new SAV4(data); case 5: @@ -276,6 +302,16 @@ internal static void writeG6CHK(byte[] savefile) BitConverter.GetBytes(ccitt16(array)).CopyTo(savefile, verificationOffset + 6 + i * 8); } } + /// Calculates the 32bit checksum over an input byte array. Used in GBA save files. + /// Input byte array + /// Checksum + internal static ushort check32(byte[] data) + { + uint val = 0; + for (int i = 0; i < data.Length; i += 4) + val += BitConverter.ToUInt32(data, i); + return (ushort)(val + val >> 16); + } internal static int getDexFormIndexXY(int species, int formct) { From 44fd5ca07ceb9fb10e6f5a74c0b4d328e5c5be7b Mon Sep 17 00:00:00 2001 From: Kaphotics Date: Mon, 27 Jun 2016 21:16:46 -0700 Subject: [PATCH 32/49] Update database viewer with Format filter Filters reorganized into tablelayoutpanel for tight appearance. --- SAV/SAV_Database.Designer.cs | 501 +++++++++++++++++++++++------------ SAV/SAV_Database.cs | 39 +-- 2 files changed, 351 insertions(+), 189 deletions(-) diff --git a/SAV/SAV_Database.Designer.cs b/SAV/SAV_Database.Designer.cs index 5a94534f9..240a2e686 100644 --- a/SAV/SAV_Database.Designer.cs +++ b/SAV/SAV_Database.Designer.cs @@ -128,8 +128,6 @@ private void InitializeComponent() this.CB_HPType = new System.Windows.Forms.ComboBox(); this.Label_HiddenPowerPrefix = new System.Windows.Forms.Label(); this.CB_GameOrigin = new System.Windows.Forms.ComboBox(); - this.CHK_IsEgg = new System.Windows.Forms.CheckBox(); - this.CHK_Shiny = new System.Windows.Forms.CheckBox(); this.CB_IV = new System.Windows.Forms.ComboBox(); this.B_Search = new System.Windows.Forms.Button(); this.CB_Level = new System.Windows.Forms.ComboBox(); @@ -141,12 +139,19 @@ private void InitializeComponent() this.L_Potential = new System.Windows.Forms.Label(); this.L_EVTraining = new System.Windows.Forms.Label(); this.B_Reset = new System.Windows.Forms.Button(); - this.MT_ESV = new System.Windows.Forms.MaskedTextBox(); - this.L_ESV = new System.Windows.Forms.Label(); this.L_Count = new System.Windows.Forms.Label(); this.L_Generation = new System.Windows.Forms.Label(); this.CB_Generation = new System.Windows.Forms.ComboBox(); this.L_Viewed = new System.Windows.Forms.Label(); + this.FLP_Egg = new System.Windows.Forms.FlowLayoutPanel(); + this.CHK_IsEgg = new System.Windows.Forms.CheckBox(); + this.L_ESV = new System.Windows.Forms.Label(); + this.MT_ESV = new System.Windows.Forms.MaskedTextBox(); + this.CHK_Shiny = new System.Windows.Forms.CheckBox(); + this.TLP_Filters = new System.Windows.Forms.TableLayoutPanel(); + this.FLP_Level = new System.Windows.Forms.FlowLayoutPanel(); + this.CB_Format = new System.Windows.Forms.ComboBox(); + this.L_Format = new System.Windows.Forms.Label(); ((System.ComponentModel.ISupportInitialize)(this.bpkx30)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.bpkx29)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.bpkx28)).BeginInit(); @@ -216,6 +221,9 @@ private void InitializeComponent() ((System.ComponentModel.ISupportInitialize)(this.bpkx63)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.bpkx62)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.bpkx61)).BeginInit(); + this.FLP_Egg.SuspendLayout(); + this.TLP_Filters.SuspendLayout(); + this.FLP_Level.SuspendLayout(); this.SuspendLayout(); // // SCR_Box @@ -915,7 +923,7 @@ private 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(152, 22); + this.Menu_Exit.Size = new System.Drawing.Size(96, 22); this.Menu_Exit.Text = "&Close"; this.Menu_Exit.Click += new System.EventHandler(this.Menu_Exit_Click); // @@ -1156,99 +1164,108 @@ private void InitializeComponent() // // CB_Ability // - this.CB_Ability.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.CB_Ability.Anchor = System.Windows.Forms.AnchorStyles.Left; this.CB_Ability.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.SuggestAppend; this.CB_Ability.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems; this.CB_Ability.FormattingEnabled = true; this.CB_Ability.Items.AddRange(new object[] { "Item"}); - this.CB_Ability.Location = new System.Drawing.Point(400, 89); + this.CB_Ability.Location = new System.Drawing.Point(83, 83); + this.CB_Ability.Margin = new System.Windows.Forms.Padding(0); this.CB_Ability.Name = "CB_Ability"; this.CB_Ability.Size = new System.Drawing.Size(122, 21); this.CB_Ability.TabIndex = 70; // // CB_HeldItem // - this.CB_HeldItem.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.CB_HeldItem.Anchor = System.Windows.Forms.AnchorStyles.Left; this.CB_HeldItem.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.SuggestAppend; this.CB_HeldItem.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems; this.CB_HeldItem.FormattingEnabled = true; - this.CB_HeldItem.Location = new System.Drawing.Point(400, 68); + this.CB_HeldItem.Location = new System.Drawing.Point(83, 62); + this.CB_HeldItem.Margin = new System.Windows.Forms.Padding(0); this.CB_HeldItem.Name = "CB_HeldItem"; this.CB_HeldItem.Size = new System.Drawing.Size(122, 21); this.CB_HeldItem.TabIndex = 69; // // CB_Nature // - this.CB_Nature.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.CB_Nature.Anchor = System.Windows.Forms.AnchorStyles.Left; this.CB_Nature.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.SuggestAppend; this.CB_Nature.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems; this.CB_Nature.FormattingEnabled = true; - this.CB_Nature.Location = new System.Drawing.Point(400, 47); + this.CB_Nature.Location = new System.Drawing.Point(83, 41); + this.CB_Nature.Margin = new System.Windows.Forms.Padding(0); this.CB_Nature.Name = "CB_Nature"; this.CB_Nature.Size = new System.Drawing.Size(122, 21); this.CB_Nature.TabIndex = 68; // // CB_Species // - this.CB_Species.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.CB_Species.Anchor = System.Windows.Forms.AnchorStyles.Left; this.CB_Species.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.SuggestAppend; this.CB_Species.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems; this.CB_Species.FormattingEnabled = true; - this.CB_Species.Location = new System.Drawing.Point(400, 26); + this.CB_Species.Location = new System.Drawing.Point(83, 20); + this.CB_Species.Margin = new System.Windows.Forms.Padding(0); this.CB_Species.Name = "CB_Species"; this.CB_Species.Size = new System.Drawing.Size(122, 21); this.CB_Species.TabIndex = 67; // // CB_Move4 // - this.CB_Move4.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.CB_Move4.Anchor = System.Windows.Forms.AnchorStyles.Left; this.CB_Move4.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.SuggestAppend; this.CB_Move4.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems; this.CB_Move4.FormattingEnabled = true; - this.CB_Move4.Location = new System.Drawing.Point(400, 277); + this.CB_Move4.Location = new System.Drawing.Point(83, 251); + this.CB_Move4.Margin = new System.Windows.Forms.Padding(0); this.CB_Move4.Name = "CB_Move4"; this.CB_Move4.Size = new System.Drawing.Size(122, 21); this.CB_Move4.TabIndex = 74; // // CB_Move3 // - this.CB_Move3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.CB_Move3.Anchor = System.Windows.Forms.AnchorStyles.Left; this.CB_Move3.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.SuggestAppend; this.CB_Move3.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems; this.CB_Move3.FormattingEnabled = true; - this.CB_Move3.Location = new System.Drawing.Point(400, 256); + this.CB_Move3.Location = new System.Drawing.Point(83, 230); + this.CB_Move3.Margin = new System.Windows.Forms.Padding(0); this.CB_Move3.Name = "CB_Move3"; this.CB_Move3.Size = new System.Drawing.Size(122, 21); this.CB_Move3.TabIndex = 73; // // CB_Move2 // - this.CB_Move2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.CB_Move2.Anchor = System.Windows.Forms.AnchorStyles.Left; this.CB_Move2.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.SuggestAppend; this.CB_Move2.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems; this.CB_Move2.FormattingEnabled = true; - this.CB_Move2.Location = new System.Drawing.Point(400, 235); + this.CB_Move2.Location = new System.Drawing.Point(83, 209); + this.CB_Move2.Margin = new System.Windows.Forms.Padding(0); this.CB_Move2.Name = "CB_Move2"; this.CB_Move2.Size = new System.Drawing.Size(122, 21); this.CB_Move2.TabIndex = 72; // // CB_Move1 // - this.CB_Move1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.CB_Move1.Anchor = System.Windows.Forms.AnchorStyles.Left; this.CB_Move1.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.SuggestAppend; this.CB_Move1.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems; this.CB_Move1.FormattingEnabled = true; - this.CB_Move1.Location = new System.Drawing.Point(400, 214); + this.CB_Move1.Location = new System.Drawing.Point(83, 188); + this.CB_Move1.Margin = new System.Windows.Forms.Padding(0); this.CB_Move1.Name = "CB_Move1"; this.CB_Move1.Size = new System.Drawing.Size(122, 21); this.CB_Move1.TabIndex = 71; // // TB_Level // - this.TB_Level.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.TB_Level.Anchor = System.Windows.Forms.AnchorStyles.Left; this.TB_Level.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - this.TB_Level.Location = new System.Drawing.Point(400, 117); + this.TB_Level.Location = new System.Drawing.Point(0, 0); + this.TB_Level.Margin = new System.Windows.Forms.Padding(0); this.TB_Level.Mask = "000"; this.TB_Level.Name = "TB_Level"; this.TB_Level.Size = new System.Drawing.Size(22, 20); @@ -1257,57 +1274,67 @@ private void InitializeComponent() // // Label_CurLevel // - this.Label_CurLevel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.Label_CurLevel.Location = new System.Drawing.Point(319, 116); + this.Label_CurLevel.Anchor = System.Windows.Forms.AnchorStyles.Right; + this.Label_CurLevel.AutoSize = true; + this.Label_CurLevel.Location = new System.Drawing.Point(44, 108); + this.Label_CurLevel.Margin = new System.Windows.Forms.Padding(3); this.Label_CurLevel.Name = "Label_CurLevel"; - this.Label_CurLevel.Size = new System.Drawing.Size(75, 17); + this.Label_CurLevel.Size = new System.Drawing.Size(36, 13); this.Label_CurLevel.TabIndex = 88; this.Label_CurLevel.Text = "Level:"; this.Label_CurLevel.TextAlign = System.Drawing.ContentAlignment.MiddleRight; // // Label_HeldItem // - this.Label_HeldItem.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.Label_HeldItem.Location = new System.Drawing.Point(317, 71); + this.Label_HeldItem.Anchor = System.Windows.Forms.AnchorStyles.Right; + this.Label_HeldItem.AutoSize = true; + this.Label_HeldItem.Location = new System.Drawing.Point(25, 66); + this.Label_HeldItem.Margin = new System.Windows.Forms.Padding(3); this.Label_HeldItem.Name = "Label_HeldItem"; - this.Label_HeldItem.Size = new System.Drawing.Size(77, 13); + this.Label_HeldItem.Size = new System.Drawing.Size(55, 13); this.Label_HeldItem.TabIndex = 93; this.Label_HeldItem.Text = "Held Item:"; this.Label_HeldItem.TextAlign = System.Drawing.ContentAlignment.MiddleRight; // // Label_Ability // - this.Label_Ability.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.Label_Ability.Location = new System.Drawing.Point(317, 92); + this.Label_Ability.Anchor = System.Windows.Forms.AnchorStyles.Right; + this.Label_Ability.AutoSize = true; + this.Label_Ability.Location = new System.Drawing.Point(43, 87); + this.Label_Ability.Margin = new System.Windows.Forms.Padding(3); this.Label_Ability.Name = "Label_Ability"; - this.Label_Ability.Size = new System.Drawing.Size(77, 13); + this.Label_Ability.Size = new System.Drawing.Size(37, 13); this.Label_Ability.TabIndex = 92; this.Label_Ability.Text = "Ability:"; this.Label_Ability.TextAlign = System.Drawing.ContentAlignment.MiddleRight; // // Label_Nature // - this.Label_Nature.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.Label_Nature.Location = new System.Drawing.Point(317, 50); + this.Label_Nature.Anchor = System.Windows.Forms.AnchorStyles.Right; + this.Label_Nature.AutoSize = true; + this.Label_Nature.Location = new System.Drawing.Point(38, 45); + this.Label_Nature.Margin = new System.Windows.Forms.Padding(3); this.Label_Nature.Name = "Label_Nature"; - this.Label_Nature.Size = new System.Drawing.Size(77, 13); + this.Label_Nature.Size = new System.Drawing.Size(42, 13); this.Label_Nature.TabIndex = 91; this.Label_Nature.Text = "Nature:"; this.Label_Nature.TextAlign = System.Drawing.ContentAlignment.MiddleRight; // // Label_Species // - this.Label_Species.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.Label_Species.Location = new System.Drawing.Point(317, 29); + this.Label_Species.Anchor = System.Windows.Forms.AnchorStyles.Right; + this.Label_Species.AutoSize = true; + this.Label_Species.Location = new System.Drawing.Point(32, 24); + this.Label_Species.Margin = new System.Windows.Forms.Padding(3); this.Label_Species.Name = "Label_Species"; - this.Label_Species.Size = new System.Drawing.Size(77, 13); + this.Label_Species.Size = new System.Drawing.Size(48, 13); this.Label_Species.TabIndex = 90; this.Label_Species.Text = "Species:"; this.Label_Species.TextAlign = System.Drawing.ContentAlignment.MiddleRight; // // CB_EVTrain // - this.CB_EVTrain.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.CB_EVTrain.Anchor = System.Windows.Forms.AnchorStyles.Left; this.CB_EVTrain.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.CB_EVTrain.DropDownWidth = 85; this.CB_EVTrain.FormattingEnabled = true; @@ -1317,78 +1344,52 @@ private void InitializeComponent() "Some (127-0)", "Half (128-507)", "Full (508+)"}); - this.CB_EVTrain.Location = new System.Drawing.Point(400, 160); + this.CB_EVTrain.Location = new System.Drawing.Point(83, 146); + this.CB_EVTrain.Margin = new System.Windows.Forms.Padding(0); this.CB_EVTrain.Name = "CB_EVTrain"; this.CB_EVTrain.Size = new System.Drawing.Size(94, 21); this.CB_EVTrain.TabIndex = 94; // // CB_HPType // - this.CB_HPType.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.CB_HPType.Anchor = System.Windows.Forms.AnchorStyles.Left; this.CB_HPType.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.SuggestAppend; this.CB_HPType.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems; this.CB_HPType.DropDownWidth = 80; this.CB_HPType.FormattingEnabled = true; - this.CB_HPType.Location = new System.Drawing.Point(400, 188); + this.CB_HPType.Location = new System.Drawing.Point(83, 167); + this.CB_HPType.Margin = new System.Windows.Forms.Padding(0); this.CB_HPType.Name = "CB_HPType"; this.CB_HPType.Size = new System.Drawing.Size(122, 21); this.CB_HPType.TabIndex = 96; // // Label_HiddenPowerPrefix // - this.Label_HiddenPowerPrefix.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.Label_HiddenPowerPrefix.Location = new System.Drawing.Point(314, 190); + this.Label_HiddenPowerPrefix.Anchor = System.Windows.Forms.AnchorStyles.Right; + this.Label_HiddenPowerPrefix.AutoSize = true; + this.Label_HiddenPowerPrefix.Location = new System.Drawing.Point(3, 171); + this.Label_HiddenPowerPrefix.Margin = new System.Windows.Forms.Padding(3); this.Label_HiddenPowerPrefix.Name = "Label_HiddenPowerPrefix"; - this.Label_HiddenPowerPrefix.Size = new System.Drawing.Size(80, 14); + this.Label_HiddenPowerPrefix.Size = new System.Drawing.Size(77, 13); this.Label_HiddenPowerPrefix.TabIndex = 95; this.Label_HiddenPowerPrefix.Text = "Hidden Power:"; this.Label_HiddenPowerPrefix.TextAlign = System.Drawing.ContentAlignment.MiddleRight; // // CB_GameOrigin // - this.CB_GameOrigin.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.CB_GameOrigin.Anchor = System.Windows.Forms.AnchorStyles.Left; this.CB_GameOrigin.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.CB_GameOrigin.FormattingEnabled = true; - this.CB_GameOrigin.Location = new System.Drawing.Point(400, 301); + this.CB_GameOrigin.Location = new System.Drawing.Point(83, 272); + this.CB_GameOrigin.Margin = new System.Windows.Forms.Padding(0); this.CB_GameOrigin.Name = "CB_GameOrigin"; this.CB_GameOrigin.Size = new System.Drawing.Size(122, 21); this.CB_GameOrigin.TabIndex = 97; this.CB_GameOrigin.SelectedIndexChanged += new System.EventHandler(this.changeGame); // - // CHK_IsEgg - // - this.CHK_IsEgg.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.CHK_IsEgg.AutoSize = true; - this.CHK_IsEgg.Checked = true; - this.CHK_IsEgg.CheckState = System.Windows.Forms.CheckState.Indeterminate; - this.CHK_IsEgg.Location = new System.Drawing.Point(400, 7); - this.CHK_IsEgg.Name = "CHK_IsEgg"; - this.CHK_IsEgg.Size = new System.Drawing.Size(45, 17); - this.CHK_IsEgg.TabIndex = 98; - this.CHK_IsEgg.Text = "Egg"; - this.CHK_IsEgg.TextAlign = System.Drawing.ContentAlignment.MiddleRight; - this.CHK_IsEgg.ThreeState = true; - this.CHK_IsEgg.UseVisualStyleBackColor = true; - this.CHK_IsEgg.CheckedChanged += new System.EventHandler(this.toggleESV); - // - // CHK_Shiny - // - this.CHK_Shiny.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.CHK_Shiny.AutoSize = true; - this.CHK_Shiny.Checked = true; - this.CHK_Shiny.CheckState = System.Windows.Forms.CheckState.Indeterminate; - this.CHK_Shiny.Location = new System.Drawing.Point(342, 7); - this.CHK_Shiny.Name = "CHK_Shiny"; - this.CHK_Shiny.Size = new System.Drawing.Size(52, 17); - this.CHK_Shiny.TabIndex = 99; - this.CHK_Shiny.Text = "Shiny"; - this.CHK_Shiny.TextAlign = System.Drawing.ContentAlignment.MiddleRight; - this.CHK_Shiny.ThreeState = true; - this.CHK_Shiny.UseVisualStyleBackColor = true; - // // CB_IV // - this.CB_IV.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.CB_IV.Anchor = System.Windows.Forms.AnchorStyles.Left; this.CB_IV.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.CB_IV.DropDownWidth = 85; this.CB_IV.FormattingEnabled = true; @@ -1400,7 +1401,8 @@ private void InitializeComponent() "151-179", "180+", "== 186"}); - this.CB_IV.Location = new System.Drawing.Point(400, 138); + this.CB_IV.Location = new System.Drawing.Point(83, 125); + this.CB_IV.Margin = new System.Windows.Forms.Padding(0); this.CB_IV.Name = "CB_IV"; this.CB_IV.Size = new System.Drawing.Size(94, 21); this.CB_IV.TabIndex = 100; @@ -1408,9 +1410,9 @@ private void InitializeComponent() // B_Search // this.B_Search.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.B_Search.Location = new System.Drawing.Point(317, 347); + this.B_Search.Location = new System.Drawing.Point(317, 350); this.B_Search.Name = "B_Search"; - this.B_Search.Size = new System.Drawing.Size(206, 32); + this.B_Search.Size = new System.Drawing.Size(206, 30); this.B_Search.TabIndex = 102; this.B_Search.Text = "Search!"; this.B_Search.UseVisualStyleBackColor = true; @@ -1418,7 +1420,7 @@ private void InitializeComponent() // // CB_Level // - this.CB_Level.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.CB_Level.Anchor = System.Windows.Forms.AnchorStyles.Left; this.CB_Level.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.CB_Level.DropDownWidth = 85; this.CB_Level.FormattingEnabled = true; @@ -1427,7 +1429,8 @@ private void InitializeComponent() ">=", "==", "<="}); - this.CB_Level.Location = new System.Drawing.Point(428, 116); + this.CB_Level.Location = new System.Drawing.Point(22, 0); + this.CB_Level.Margin = new System.Windows.Forms.Padding(0); this.CB_Level.Name = "CB_Level"; this.CB_Level.Size = new System.Drawing.Size(66, 21); this.CB_Level.TabIndex = 103; @@ -1435,70 +1438,84 @@ private void InitializeComponent() // // L_Version // - this.L_Version.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.L_Version.Location = new System.Drawing.Point(318, 303); + this.L_Version.Anchor = System.Windows.Forms.AnchorStyles.Right; + this.L_Version.AutoSize = true; + this.L_Version.Location = new System.Drawing.Point(17, 276); + this.L_Version.Margin = new System.Windows.Forms.Padding(3); this.L_Version.Name = "L_Version"; - this.L_Version.Size = new System.Drawing.Size(80, 14); + this.L_Version.Size = new System.Drawing.Size(63, 13); this.L_Version.TabIndex = 104; this.L_Version.Text = "OT Version:"; this.L_Version.TextAlign = System.Drawing.ContentAlignment.MiddleRight; // // L_Move1 // - this.L_Move1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.L_Move1.Location = new System.Drawing.Point(314, 216); + this.L_Move1.Anchor = System.Windows.Forms.AnchorStyles.Right; + this.L_Move1.AutoSize = true; + this.L_Move1.Location = new System.Drawing.Point(34, 192); + this.L_Move1.Margin = new System.Windows.Forms.Padding(3); this.L_Move1.Name = "L_Move1"; - this.L_Move1.Size = new System.Drawing.Size(80, 14); + this.L_Move1.Size = new System.Drawing.Size(46, 13); this.L_Move1.TabIndex = 105; this.L_Move1.Text = "Move 1:"; this.L_Move1.TextAlign = System.Drawing.ContentAlignment.MiddleRight; // // L_Move2 // - this.L_Move2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.L_Move2.Location = new System.Drawing.Point(314, 237); + this.L_Move2.Anchor = System.Windows.Forms.AnchorStyles.Right; + this.L_Move2.AutoSize = true; + this.L_Move2.Location = new System.Drawing.Point(34, 213); + this.L_Move2.Margin = new System.Windows.Forms.Padding(3); this.L_Move2.Name = "L_Move2"; - this.L_Move2.Size = new System.Drawing.Size(80, 14); + this.L_Move2.Size = new System.Drawing.Size(46, 13); this.L_Move2.TabIndex = 106; this.L_Move2.Text = "Move 2:"; this.L_Move2.TextAlign = System.Drawing.ContentAlignment.MiddleRight; // // L_Move3 // - this.L_Move3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.L_Move3.Location = new System.Drawing.Point(314, 258); + this.L_Move3.Anchor = System.Windows.Forms.AnchorStyles.Right; + this.L_Move3.AutoSize = true; + this.L_Move3.Location = new System.Drawing.Point(34, 234); + this.L_Move3.Margin = new System.Windows.Forms.Padding(3); this.L_Move3.Name = "L_Move3"; - this.L_Move3.Size = new System.Drawing.Size(80, 14); + this.L_Move3.Size = new System.Drawing.Size(46, 13); this.L_Move3.TabIndex = 107; this.L_Move3.Text = "Move 3:"; this.L_Move3.TextAlign = System.Drawing.ContentAlignment.MiddleRight; // // L_Move4 // - this.L_Move4.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.L_Move4.Location = new System.Drawing.Point(314, 279); + this.L_Move4.Anchor = System.Windows.Forms.AnchorStyles.Right; + this.L_Move4.AutoSize = true; + this.L_Move4.Location = new System.Drawing.Point(34, 255); + this.L_Move4.Margin = new System.Windows.Forms.Padding(3); this.L_Move4.Name = "L_Move4"; - this.L_Move4.Size = new System.Drawing.Size(80, 14); + this.L_Move4.Size = new System.Drawing.Size(46, 13); this.L_Move4.TabIndex = 108; this.L_Move4.Text = "Move 4:"; this.L_Move4.TextAlign = System.Drawing.ContentAlignment.MiddleRight; // // L_Potential // - this.L_Potential.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.L_Potential.Location = new System.Drawing.Point(319, 139); + this.L_Potential.Anchor = System.Windows.Forms.AnchorStyles.Right; + this.L_Potential.AutoSize = true; + this.L_Potential.Location = new System.Drawing.Point(16, 129); + this.L_Potential.Margin = new System.Windows.Forms.Padding(3); this.L_Potential.Name = "L_Potential"; - this.L_Potential.Size = new System.Drawing.Size(75, 17); + this.L_Potential.Size = new System.Drawing.Size(64, 13); this.L_Potential.TabIndex = 109; this.L_Potential.Text = "IV Potential:"; this.L_Potential.TextAlign = System.Drawing.ContentAlignment.MiddleRight; // // L_EVTraining // - this.L_EVTraining.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.L_EVTraining.Location = new System.Drawing.Point(319, 161); + this.L_EVTraining.Anchor = System.Windows.Forms.AnchorStyles.Right; + this.L_EVTraining.AutoSize = true; + this.L_EVTraining.Location = new System.Drawing.Point(15, 150); + this.L_EVTraining.Margin = new System.Windows.Forms.Padding(3); this.L_EVTraining.Name = "L_EVTraining"; - this.L_EVTraining.Size = new System.Drawing.Size(75, 17); + this.L_EVTraining.Size = new System.Drawing.Size(65, 13); this.L_EVTraining.TabIndex = 110; this.L_EVTraining.Text = "EV Training:"; this.L_EVTraining.TextAlign = System.Drawing.ContentAlignment.MiddleRight; @@ -1513,29 +1530,6 @@ private void InitializeComponent() this.B_Reset.UseVisualStyleBackColor = true; this.B_Reset.Click += new System.EventHandler(this.resetFilters); // - // MT_ESV - // - this.MT_ESV.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.MT_ESV.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - this.MT_ESV.Location = new System.Drawing.Point(491, 6); - this.MT_ESV.Mask = "0000"; - this.MT_ESV.Name = "MT_ESV"; - this.MT_ESV.Size = new System.Drawing.Size(31, 20); - this.MT_ESV.TabIndex = 112; - this.MT_ESV.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; - this.MT_ESV.Visible = false; - // - // L_ESV - // - this.L_ESV.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.L_ESV.Location = new System.Drawing.Point(445, 7); - this.L_ESV.Name = "L_ESV"; - this.L_ESV.Size = new System.Drawing.Size(43, 17); - this.L_ESV.TabIndex = 113; - this.L_ESV.Text = "ESV:"; - this.L_ESV.TextAlign = System.Drawing.ContentAlignment.MiddleRight; - this.L_ESV.Visible = false; - // // L_Count // this.L_Count.Location = new System.Drawing.Point(99, 11); @@ -1547,17 +1541,19 @@ private void InitializeComponent() // // L_Generation // - this.L_Generation.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.L_Generation.Location = new System.Drawing.Point(318, 325); + this.L_Generation.Anchor = System.Windows.Forms.AnchorStyles.Right; + this.L_Generation.AutoSize = true; + this.L_Generation.Location = new System.Drawing.Point(18, 297); + this.L_Generation.Margin = new System.Windows.Forms.Padding(3); this.L_Generation.Name = "L_Generation"; - this.L_Generation.Size = new System.Drawing.Size(80, 14); + this.L_Generation.Size = new System.Drawing.Size(62, 13); this.L_Generation.TabIndex = 116; this.L_Generation.Text = "Generation:"; this.L_Generation.TextAlign = System.Drawing.ContentAlignment.MiddleRight; // // CB_Generation // - this.CB_Generation.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.CB_Generation.Anchor = System.Windows.Forms.AnchorStyles.Left; this.CB_Generation.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.CB_Generation.FormattingEnabled = true; this.CB_Generation.Items.AddRange(new object[] { @@ -1566,7 +1562,8 @@ private void InitializeComponent() "Gen 5 (BW/B2W2)", "Gen 4 (DPPt/HGSS)", "Gen 3 (RSE/FRLG/CXD)"}); - this.CB_Generation.Location = new System.Drawing.Point(400, 323); + this.CB_Generation.Location = new System.Drawing.Point(83, 293); + this.CB_Generation.Margin = new System.Windows.Forms.Padding(0); this.CB_Generation.Name = "CB_Generation"; this.CB_Generation.Size = new System.Drawing.Size(122, 21); this.CB_Generation.TabIndex = 115; @@ -1582,50 +1579,197 @@ private void InitializeComponent() this.L_Viewed.Text = "Last Viewed: {0}"; this.L_Viewed.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; // + // FLP_Egg + // + this.FLP_Egg.Anchor = System.Windows.Forms.AnchorStyles.Left; + this.FLP_Egg.AutoSize = true; + this.FLP_Egg.Controls.Add(this.CHK_IsEgg); + this.FLP_Egg.Controls.Add(this.L_ESV); + this.FLP_Egg.Controls.Add(this.MT_ESV); + this.FLP_Egg.Location = new System.Drawing.Point(83, 0); + this.FLP_Egg.Margin = new System.Windows.Forms.Padding(0); + this.FLP_Egg.Name = "FLP_Egg"; + this.FLP_Egg.Size = new System.Drawing.Size(119, 20); + this.FLP_Egg.TabIndex = 120; + // + // CHK_IsEgg + // + this.CHK_IsEgg.Anchor = System.Windows.Forms.AnchorStyles.Left; + this.CHK_IsEgg.AutoSize = true; + this.CHK_IsEgg.Checked = true; + this.CHK_IsEgg.CheckState = System.Windows.Forms.CheckState.Indeterminate; + this.CHK_IsEgg.Location = new System.Drawing.Point(0, 1); + this.CHK_IsEgg.Margin = new System.Windows.Forms.Padding(0); + this.CHK_IsEgg.Name = "CHK_IsEgg"; + this.CHK_IsEgg.Size = new System.Drawing.Size(45, 17); + this.CHK_IsEgg.TabIndex = 98; + this.CHK_IsEgg.Text = "Egg"; + this.CHK_IsEgg.TextAlign = System.Drawing.ContentAlignment.MiddleRight; + this.CHK_IsEgg.ThreeState = true; + this.CHK_IsEgg.UseVisualStyleBackColor = true; + this.CHK_IsEgg.CheckedChanged += new System.EventHandler(this.toggleESV); + // + // L_ESV + // + this.L_ESV.Anchor = System.Windows.Forms.AnchorStyles.Left; + this.L_ESV.Location = new System.Drawing.Point(45, 1); + this.L_ESV.Margin = new System.Windows.Forms.Padding(0); + this.L_ESV.Name = "L_ESV"; + this.L_ESV.Size = new System.Drawing.Size(43, 17); + this.L_ESV.TabIndex = 113; + this.L_ESV.Text = "ESV:"; + this.L_ESV.TextAlign = System.Drawing.ContentAlignment.MiddleRight; + this.L_ESV.Visible = false; + // + // MT_ESV + // + this.MT_ESV.Anchor = System.Windows.Forms.AnchorStyles.Left; + this.MT_ESV.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.MT_ESV.Location = new System.Drawing.Point(88, 0); + this.MT_ESV.Margin = new System.Windows.Forms.Padding(0); + this.MT_ESV.Mask = "0000"; + this.MT_ESV.Name = "MT_ESV"; + this.MT_ESV.Size = new System.Drawing.Size(31, 20); + this.MT_ESV.TabIndex = 112; + this.MT_ESV.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; + this.MT_ESV.Visible = false; + // + // CHK_Shiny + // + this.CHK_Shiny.Anchor = System.Windows.Forms.AnchorStyles.Right; + this.CHK_Shiny.AutoSize = true; + this.CHK_Shiny.Checked = true; + this.CHK_Shiny.CheckState = System.Windows.Forms.CheckState.Indeterminate; + this.CHK_Shiny.Location = new System.Drawing.Point(31, 1); + this.CHK_Shiny.Margin = new System.Windows.Forms.Padding(0); + this.CHK_Shiny.Name = "CHK_Shiny"; + this.CHK_Shiny.Size = new System.Drawing.Size(52, 17); + this.CHK_Shiny.TabIndex = 99; + this.CHK_Shiny.Text = "Shiny"; + this.CHK_Shiny.TextAlign = System.Drawing.ContentAlignment.MiddleRight; + this.CHK_Shiny.ThreeState = true; + this.CHK_Shiny.UseVisualStyleBackColor = true; + // + // TLP_Filters + // + this.TLP_Filters.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.TLP_Filters.AutoScroll = true; + this.TLP_Filters.AutoScrollMargin = new System.Drawing.Size(3, 3); + this.TLP_Filters.AutoSize = true; + this.TLP_Filters.ColumnCount = 2; + this.TLP_Filters.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); + this.TLP_Filters.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); + this.TLP_Filters.Controls.Add(this.L_Format, 0, 15); + this.TLP_Filters.Controls.Add(this.FLP_Egg, 1, 0); + this.TLP_Filters.Controls.Add(this.CHK_Shiny, 0, 0); + this.TLP_Filters.Controls.Add(this.Label_Species, 0, 1); + this.TLP_Filters.Controls.Add(this.CB_Species, 1, 1); + this.TLP_Filters.Controls.Add(this.Label_Nature, 0, 2); + this.TLP_Filters.Controls.Add(this.CB_Nature, 1, 2); + this.TLP_Filters.Controls.Add(this.Label_HeldItem, 0, 3); + this.TLP_Filters.Controls.Add(this.CB_HeldItem, 1, 3); + this.TLP_Filters.Controls.Add(this.Label_Ability, 0, 4); + this.TLP_Filters.Controls.Add(this.CB_Ability, 1, 4); + this.TLP_Filters.Controls.Add(this.FLP_Level, 1, 5); + this.TLP_Filters.Controls.Add(this.Label_CurLevel, 0, 5); + this.TLP_Filters.Controls.Add(this.L_Potential, 0, 6); + this.TLP_Filters.Controls.Add(this.CB_IV, 1, 6); + this.TLP_Filters.Controls.Add(this.L_EVTraining, 0, 7); + this.TLP_Filters.Controls.Add(this.CB_EVTrain, 1, 7); + this.TLP_Filters.Controls.Add(this.Label_HiddenPowerPrefix, 0, 8); + this.TLP_Filters.Controls.Add(this.CB_HPType, 1, 8); + this.TLP_Filters.Controls.Add(this.L_Move1, 0, 9); + this.TLP_Filters.Controls.Add(this.CB_Move1, 1, 9); + this.TLP_Filters.Controls.Add(this.L_Move2, 0, 10); + this.TLP_Filters.Controls.Add(this.CB_Move2, 1, 10); + this.TLP_Filters.Controls.Add(this.L_Move3, 0, 11); + this.TLP_Filters.Controls.Add(this.CB_Move3, 1, 11); + this.TLP_Filters.Controls.Add(this.L_Move4, 0, 12); + this.TLP_Filters.Controls.Add(this.CB_Move4, 1, 12); + this.TLP_Filters.Controls.Add(this.L_Version, 0, 13); + this.TLP_Filters.Controls.Add(this.CB_GameOrigin, 1, 13); + this.TLP_Filters.Controls.Add(this.L_Generation, 0, 14); + this.TLP_Filters.Controls.Add(this.CB_Generation, 1, 14); + this.TLP_Filters.Controls.Add(this.CB_Format, 1, 15); + this.TLP_Filters.Location = new System.Drawing.Point(304, 11); + this.TLP_Filters.Name = "TLP_Filters"; + this.TLP_Filters.RowCount = 17; + this.TLP_Filters.RowStyles.Add(new System.Windows.Forms.RowStyle()); + this.TLP_Filters.RowStyles.Add(new System.Windows.Forms.RowStyle()); + this.TLP_Filters.RowStyles.Add(new System.Windows.Forms.RowStyle()); + this.TLP_Filters.RowStyles.Add(new System.Windows.Forms.RowStyle()); + this.TLP_Filters.RowStyles.Add(new System.Windows.Forms.RowStyle()); + this.TLP_Filters.RowStyles.Add(new System.Windows.Forms.RowStyle()); + this.TLP_Filters.RowStyles.Add(new System.Windows.Forms.RowStyle()); + this.TLP_Filters.RowStyles.Add(new System.Windows.Forms.RowStyle()); + this.TLP_Filters.RowStyles.Add(new System.Windows.Forms.RowStyle()); + this.TLP_Filters.RowStyles.Add(new System.Windows.Forms.RowStyle()); + this.TLP_Filters.RowStyles.Add(new System.Windows.Forms.RowStyle()); + this.TLP_Filters.RowStyles.Add(new System.Windows.Forms.RowStyle()); + this.TLP_Filters.RowStyles.Add(new System.Windows.Forms.RowStyle()); + this.TLP_Filters.RowStyles.Add(new System.Windows.Forms.RowStyle()); + this.TLP_Filters.RowStyles.Add(new System.Windows.Forms.RowStyle()); + this.TLP_Filters.RowStyles.Add(new System.Windows.Forms.RowStyle()); + this.TLP_Filters.RowStyles.Add(new System.Windows.Forms.RowStyle()); + this.TLP_Filters.Size = new System.Drawing.Size(228, 354); + this.TLP_Filters.TabIndex = 118; + // + // FLP_Level + // + this.FLP_Level.Anchor = System.Windows.Forms.AnchorStyles.Left; + this.FLP_Level.AutoSize = true; + this.FLP_Level.Controls.Add(this.TB_Level); + this.FLP_Level.Controls.Add(this.CB_Level); + this.FLP_Level.Location = new System.Drawing.Point(83, 104); + this.FLP_Level.Margin = new System.Windows.Forms.Padding(0); + this.FLP_Level.Name = "FLP_Level"; + this.FLP_Level.Size = new System.Drawing.Size(88, 21); + this.FLP_Level.TabIndex = 119; + // + // CB_Format + // + this.CB_Format.Anchor = System.Windows.Forms.AnchorStyles.Left; + this.CB_Format.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.CB_Format.FormattingEnabled = true; + this.CB_Format.Items.AddRange(new object[] { + "Any", + ">=pk6", + ">=pk5", + ">=pk4", + ">=pk3"}); + this.CB_Format.Location = new System.Drawing.Point(83, 314); + this.CB_Format.Margin = new System.Windows.Forms.Padding(0); + this.CB_Format.Name = "CB_Format"; + this.CB_Format.Size = new System.Drawing.Size(122, 21); + this.CB_Format.TabIndex = 121; + // + // L_Format + // + this.L_Format.Anchor = System.Windows.Forms.AnchorStyles.Right; + this.L_Format.AutoSize = true; + this.L_Format.Location = new System.Drawing.Point(38, 318); + this.L_Format.Margin = new System.Windows.Forms.Padding(3); + this.L_Format.Name = "L_Format"; + this.L_Format.Size = new System.Drawing.Size(42, 13); + this.L_Format.TabIndex = 122; + this.L_Format.Text = "Format:"; + this.L_Format.TextAlign = System.Drawing.ContentAlignment.MiddleRight; + // // SAV_Database // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(544, 396); - this.Controls.Add(this.L_Viewed); - this.Controls.Add(this.L_Generation); - this.Controls.Add(this.CB_Generation); - this.Controls.Add(this.L_Count); - this.Controls.Add(this.L_ESV); - this.Controls.Add(this.MT_ESV); - this.Controls.Add(this.B_Reset); - this.Controls.Add(this.L_EVTraining); - this.Controls.Add(this.L_Potential); - this.Controls.Add(this.L_Move4); - this.Controls.Add(this.L_Move3); - this.Controls.Add(this.L_Move2); - this.Controls.Add(this.L_Move1); - this.Controls.Add(this.L_Version); - this.Controls.Add(this.CB_Level); this.Controls.Add(this.B_Search); - this.Controls.Add(this.CB_IV); - this.Controls.Add(this.CHK_IsEgg); - this.Controls.Add(this.CHK_Shiny); - this.Controls.Add(this.CB_GameOrigin); - this.Controls.Add(this.CB_HPType); - this.Controls.Add(this.Label_HiddenPowerPrefix); - this.Controls.Add(this.CB_EVTrain); - this.Controls.Add(this.Label_HeldItem); - this.Controls.Add(this.Label_Ability); - this.Controls.Add(this.Label_Nature); - this.Controls.Add(this.Label_Species); - this.Controls.Add(this.TB_Level); - this.Controls.Add(this.Label_CurLevel); - this.Controls.Add(this.CB_Move4); - this.Controls.Add(this.CB_Move3); - this.Controls.Add(this.CB_Move2); - this.Controls.Add(this.CB_Move1); - this.Controls.Add(this.CB_Ability); - this.Controls.Add(this.CB_HeldItem); - this.Controls.Add(this.CB_Nature); - this.Controls.Add(this.CB_Species); + this.Controls.Add(this.TLP_Filters); + this.Controls.Add(this.L_Viewed); + this.Controls.Add(this.L_Count); + this.Controls.Add(this.B_Reset); this.Controls.Add(this.P_Results); this.Controls.Add(this.menuStrip1); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.MaximizeBox = false; this.MaximumSize = new System.Drawing.Size(800, 435); @@ -1704,6 +1848,12 @@ private void InitializeComponent() ((System.ComponentModel.ISupportInitialize)(this.bpkx63)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.bpkx62)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.bpkx61)).EndInit(); + this.FLP_Egg.ResumeLayout(false); + this.FLP_Egg.PerformLayout(); + this.TLP_Filters.ResumeLayout(false); + this.TLP_Filters.PerformLayout(); + this.FLP_Level.ResumeLayout(false); + this.FLP_Level.PerformLayout(); this.ResumeLayout(false); this.PerformLayout(); @@ -1797,8 +1947,6 @@ private void InitializeComponent() private System.Windows.Forms.ComboBox CB_HPType; private System.Windows.Forms.Label Label_HiddenPowerPrefix; private System.Windows.Forms.ComboBox CB_GameOrigin; - public System.Windows.Forms.CheckBox CHK_IsEgg; - public System.Windows.Forms.CheckBox CHK_Shiny; private System.Windows.Forms.ComboBox CB_IV; private System.Windows.Forms.Button B_Search; private System.Windows.Forms.ComboBox CB_Level; @@ -1810,8 +1958,6 @@ private void InitializeComponent() private System.Windows.Forms.Label L_Potential; private System.Windows.Forms.Label L_EVTraining; private System.Windows.Forms.Button B_Reset; - private System.Windows.Forms.MaskedTextBox MT_ESV; - private System.Windows.Forms.Label L_ESV; private System.Windows.Forms.Label L_Count; private System.Windows.Forms.Panel PAN_Box; private System.Windows.Forms.PictureBox bpkx66; @@ -1829,5 +1975,14 @@ private void InitializeComponent() private System.Windows.Forms.ToolStripMenuItem Menu_SearchDatabase; private System.Windows.Forms.ToolStripMenuItem Menu_SearchLegal; private System.Windows.Forms.ToolStripMenuItem Menu_SearchIllegal; + private System.Windows.Forms.TableLayoutPanel TLP_Filters; + public System.Windows.Forms.CheckBox CHK_Shiny; + private System.Windows.Forms.MaskedTextBox MT_ESV; + private System.Windows.Forms.Label L_ESV; + public System.Windows.Forms.CheckBox CHK_IsEgg; + private System.Windows.Forms.FlowLayoutPanel FLP_Egg; + private System.Windows.Forms.FlowLayoutPanel FLP_Level; + private System.Windows.Forms.ComboBox CB_Format; + private System.Windows.Forms.Label L_Format; } } \ No newline at end of file diff --git a/SAV/SAV_Database.cs b/SAV/SAV_Database.cs index 2199b6903..1742bb195 100644 --- a/SAV/SAV_Database.cs +++ b/SAV/SAV_Database.cs @@ -15,6 +15,7 @@ public SAV_Database(Main f1) { m_parent = f1; InitializeComponent(); + CB_Format.SelectedIndex = MAXFORMAT - Main.SAV.Generation + 1; PKXBOXES = new[] { bpkx1, bpkx2, bpkx3, bpkx4, bpkx5, bpkx6, @@ -104,6 +105,7 @@ public SAV_Database(Main f1) if (e.CloseReason == ToolStripDropDownCloseReason.ItemClicked) e.Cancel = true; }; + B_Search.PerformClick(); CenterToParent(); } private readonly Main m_parent; @@ -118,6 +120,7 @@ public SAV_Database(Main f1) private const int RES_MIN = 6; private readonly string Counter; private readonly string Viewed; + private const int MAXFORMAT = 6; // Important Events private void clickView(object sender, EventArgs e) @@ -422,6 +425,26 @@ private void B_Search_Click(object sender, EventArgs e) // Populate Search Query Result IEnumerable res = RawDB; + int format = MAXFORMAT + 1 - CB_Format.SelectedIndex; + res = res.Where(pk => pk.Format <= format); + + switch (CB_Generation.SelectedIndex) + { + case 0: break; // Do nothing + case 1: // Gen 6 + res = res.Where(pk => pk.Gen6); + break; + case 2: // Gen 5 + res = res.Where(pk => pk.Gen5); + break; + case 3: // Gen 4 + res = res.Where(pk => pk.Gen4); + break; + case 4: // Gen 3 + res = res.Where(pk => pk.Gen3); + break; + } + // Primary Searchables int species = Util.getIndex(CB_Species); int ability = Util.getIndex(CB_Ability); @@ -509,22 +532,6 @@ private void B_Search_Click(object sender, EventArgs e) res = res.Where(pk => pk.EVs.Sum() >= 508); break; } - switch (CB_Generation.SelectedIndex) - { - case 0: break; // Do nothing - case 1: // Gen 6 - res = res.Where(pk => pk.Gen6); - break; - case 2: // Gen 5 - res = res.Where(pk => pk.Gen5); - break; - case 3: // Gen 4 - res = res.Where(pk => pk.Gen4); - break; - case 4: // Gen 3 - res = res.Where(pk => pk.Gen3); - break; - } // Filter for Selected Source if (!Menu_SearchBoxes.Checked) From 6ddaa036d4b0afc8b8a8039aa4cb6eb1bcfd2b3d Mon Sep 17 00:00:00 2001 From: Kaphotics Date: Mon, 27 Jun 2016 22:20:31 -0700 Subject: [PATCH 33/49] Update database to load formats correctly --- PKM/PKMConverter.cs | 10 +++++----- SAV/SAV_Database.cs | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/PKM/PKMConverter.cs b/PKM/PKMConverter.cs index 46ac92d85..12115760b 100644 --- a/PKM/PKMConverter.cs +++ b/PKM/PKMConverter.cs @@ -52,19 +52,19 @@ private static int getPKMDataFormat(byte[] data) } return -1; } - internal static PKM getPKMfromBytes(byte[] data) + internal static PKM getPKMfromBytes(byte[] data, string ident = null) { checkEncrypted(ref data); switch (getPKMDataFormat(data)) { case 3: - return new PK3(data); + return new PK3(data, ident); case 4: - return new PK4(data); + return new PK4(data, ident); case 5: - return new PK5(data); + return new PK5(data, ident); case 6: - return new PK6(data); + return new PK6(data, ident); default: return null; } diff --git a/SAV/SAV_Database.cs b/SAV/SAV_Database.cs index 1742bb195..efbd11171 100644 --- a/SAV/SAV_Database.cs +++ b/SAV/SAV_Database.cs @@ -90,13 +90,13 @@ public SAV_Database(Main f1) { FileInfo fi = new FileInfo(file); if (fi.Extension.Contains(".pk") && PKX.getIsPKM(fi.Length)) - Database[0].Slot.Add(new PK6(File.ReadAllBytes(file), file)); + Database[0].Slot.Add(PKMConverter.getPKMfromBytes(File.ReadAllBytes(file), file)); else loadDatabase(File.ReadAllBytes(file)); } // Fetch from save file - foreach (var pk6 in Main.SAV.BoxData.Where(pk => pk.Species != 0)) - Database[0].Slot.Add(pk6); + foreach (var pkm in Main.SAV.BoxData.Where(pk => pk.Species != 0)) + Database[0].Slot.Add(pkm); // Prepare Database prepareDBForSearch(); From 92b357c660f93b48761e043bc6f7d37035f2ac53 Mon Sep 17 00:00:00 2001 From: Kaphotics Date: Mon, 27 Jun 2016 22:26:39 -0700 Subject: [PATCH 34/49] Simplify hidden power calc Calculate inline --- PKM/ShowdownSet.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/PKM/ShowdownSet.cs b/PKM/ShowdownSet.cs index 36920b6f4..376791544 100644 --- a/PKM/ShowdownSet.cs +++ b/PKM/ShowdownSet.cs @@ -247,8 +247,14 @@ public string getText() foreach (int move in Moves.Where(move => move != 0 && move < moves.Length)) { MoveLines[movectr] += "- " + moves[move]; - if (move == 237) - MoveLines[movectr] += $" [{hptypes[PKX.getHPType(IVs)]}]"; + if (move == 237) // Hidden Power + { + int hp = 0; + for (int i = 0; i < 6; i++) + hp |= (IVs[i] & 1) << i; + hp *= 0xF; hp /= 0x3F; + MoveLines[movectr] += $" [{hptypes[hp]}]"; + } movectr++; } result += string.Join(Environment.NewLine, MoveLines.Take(movectr)); From 744c5b927b2c5bafabaae21d9ba2bd18ec8d77e7 Mon Sep 17 00:00:00 2001 From: Kaphotics Date: Mon, 27 Jun 2016 22:27:53 -0700 Subject: [PATCH 35/49] Isolate secret base ability code Was referencing main form code; this is gen6 only so do it gen6 only. Main form will change to handle all generations. --- SAV/SAV_SecretBase.cs | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/SAV/SAV_SecretBase.cs b/SAV/SAV_SecretBase.cs index 35a8fecca..cdf3f90e0 100644 --- a/SAV/SAV_SecretBase.cs +++ b/SAV/SAV_SecretBase.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows.Forms; @@ -402,7 +403,26 @@ private void loadFavPKM() CB_Form.SelectedIndex = form; // Set Ability - Main.setAbilityList(MT_AbilNo, spec, CB_Ability, CB_Form); + setAbilityList(); + } + + private void setAbilityList() + { + int newabil = Convert.ToInt16(MT_AbilNo.Text) >> 1; + int species = Util.getIndex(CB_Species); + int formnum = CB_Form.SelectedIndex; + byte[] abils = Legal.PersonalAO[Legal.PersonalAO[species].FormeIndex(species, formnum)].Abilities; + + // Build Ability List + List ability_list = new List + { + abilitylist[abils[0]] + " (1)", + abilitylist[abils[1]] + " (2)", + abilitylist[abils[2]] + " (H)" + }; + CB_Ability.DataSource = ability_list; + + CB_Ability.SelectedIndex = newabil < 3 ? newabil : 0; } private void updateSpecies(object sender, EventArgs e) @@ -422,11 +442,11 @@ private void updateSpecies(object sender, EventArgs e) genderflag = 0; setGenderLabel(); - Main.setAbilityList(MT_AbilNo, Util.getIndex(CB_Species), CB_Ability, CB_Form); + setAbilityList(); } private void updateForm(object sender, EventArgs e) { - Main.setAbilityList(MT_AbilNo, Util.getIndex(CB_Species), CB_Ability, CB_Form); + setAbilityList(); // If form has a single gender, account for it. if (PKX.getGender(CB_Form.Text) < 2) From 8e628038974b74524947031d584f1f9abd1925f5 Mon Sep 17 00:00:00 2001 From: Kaphotics Date: Mon, 27 Jun 2016 23:03:57 -0700 Subject: [PATCH 36/49] Tweak savefile enumeration Use one enum to denote Version across all code, also identifies if data is invalid Move some SAV code to virtual members in abstract class (BAK/Exportable/Footer) Few minor bugfixes here and there (hiding Characteristic label, loading pk6 to sav3, sav3 version detection via gamecode) --- PKM/PKX.cs | 9 +-- PKX/f1-Main.cs | 74 +++++++++++-------------- Saves/SAV3.cs | 34 ++++-------- Saves/SAV4.cs | 46 ++++++---------- Saves/SAV5.cs | 34 +++++------- Saves/SAV6.cs | 5 +- Saves/SaveFile.cs | 9 +-- Saves/SaveUtil.cs | 138 ++++++++++++++++++++-------------------------- 8 files changed, 145 insertions(+), 204 deletions(-) diff --git a/PKM/PKX.cs b/PKM/PKX.cs index 1df311e9f..922bdf9e5 100644 --- a/PKM/PKX.cs +++ b/PKM/PKX.cs @@ -181,7 +181,7 @@ internal static bool getIsNicknamed(int species, string nick) try { return SpeciesLang.All(list => list[species].ToUpper() != nick); } catch { return false; } } - internal static readonly PersonalInfo[] Personal = Legal.PersonalAO; + internal static PersonalInfo[] Personal = Legal.PersonalAO; // Stat Fetching internal static int getMovePP(int move, int ppup) @@ -273,7 +273,7 @@ internal static byte[] getAbilities(int species, int formnum) } internal static int getAbilityNumber(int species, int ability, int formnum) { - byte[] spec_abilities = Personal[Personal[species].FormeIndex(species, formnum)].Abilities; + byte[] spec_abilities = getAbilities(species, formnum); int abilval = Array.IndexOf(spec_abilities, (byte)ability); if (abilval >= 0) return 1 << abilval; @@ -988,12 +988,9 @@ internal static string[] getFormList(int species, string[] t, string[] f, string } /// Calculate the Hidden Power Type of the entered IVs. + /// Hidden Power Type /// Order: HP,ATK,DEF,SPEED,SPA,SPD /// Hidden Power Type - internal static int getHPType(int[] ivs) - { - return 15 * ((ivs[0] & 1) + 2 * (ivs[1] & 1) + 4 * (ivs[2] & 1) + 8 * (ivs[3] & 1) + 16 * (ivs[4] & 1) + 32 * (ivs[5] & 1)) / 63; - } internal static int[] setHPIVs(int type, int[] ivs) { for (int i = 0; i < 6; i++) diff --git a/PKX/f1-Main.cs b/PKX/f1-Main.cs index aee2dfc65..f2cc13e88 100644 --- a/PKX/f1-Main.cs +++ b/PKX/f1-Main.cs @@ -675,7 +675,7 @@ private bool openXOR(byte[] input, string path) private void openSAV(byte[] input, string path) { SaveFile sav = SaveUtil.getVariantSAV(input); - if (sav == null) + if (sav == null || sav.Version == GameVersion.Invalid) { Util.Error("Invalid save file loaded. Aborting.", path); return; } SAV = sav; @@ -739,9 +739,9 @@ private void openSAV(byte[] input, string path) CB_Form.Visible = Label_Form.Visible = CHK_AsEgg.Visible = GB_EggConditions.Visible = Label_MetDate.Visible = CAL_MetDate.Visible = PB_Mark5.Visible = PB_Mark6.Visible = SAV.Generation >= 4; - DEV_Ability.Enabled = DEV_Ability.Visible = SAV.Generation < 6 || HaX; - TB_AbilityNumber.Visible = SAV.Generation >= 6 && HaX; - CB_Ability.Visible = SAV.Generation >= 6 && !HaX; + DEV_Ability.Enabled = DEV_Ability.Visible = SAV.Generation != 3 && HaX; + TB_AbilityNumber.Visible = SAV.Generation >= 6 && DEV_Ability.Enabled; + CB_Ability.Visible = !DEV_Ability.Enabled; switch (SAV.Generation) { @@ -763,6 +763,7 @@ private void openSAV(byte[] input, string path) TB_Secure2.Text = (SAV as SAV6).Secure2.ToString("X16"); break; } + PKX.Personal = SAV.Personal; PKM pk = preparePKM(); populateFilteredDataSources(); @@ -792,7 +793,6 @@ private void openSAV(byte[] input, string path) if (SAV.Exportable && Directory.Exists(BackupPath) && !File.Exists(backupName)) File.WriteAllBytes(backupName, SAV.BAK); - // Indicate audibly the save is loaded SystemSounds.Beep.Play(); } @@ -1020,6 +1020,9 @@ public void populateFields(PKM pk, bool focus = true) { if (pk == null) { Util.Error("Attempted to load a null file."); return; } + if (pk.Format != SAV.Generation) + { Util.Alert("Can't load future generation files."); return; } + bool oldInit = fieldsInitialized; fieldsInitialized = fieldsLoaded = false; if (focus) @@ -1089,7 +1092,7 @@ private void populateFieldsPK3(PK3 pk3) Label_OTGender.ForeColor = pk3.OT_Gender == 1 ? Color.Red : Color.Blue; TB_PID.Text = pk3.PID.ToString("X8"); CB_HeldItem.SelectedValue = pk3.HeldItem; - setAbilityList(TB_AbilityNumber, pk3.Species, CB_Ability, CB_Form); + setAbilityList(); DEV_Ability.SelectedValue = pk3.Ability; CB_Nature.SelectedValue = pk3.Nature; TB_TID.Text = pk3.TID.ToString("00000"); @@ -1180,7 +1183,7 @@ private void populateFieldsPK4(PK4 pk4) Label_OTGender.ForeColor = pk4.OT_Gender == 1 ? Color.Red : Color.Blue; TB_PID.Text = pk4.PID.ToString("X8"); CB_HeldItem.SelectedValue = pk4.HeldItem; - setAbilityList(TB_AbilityNumber, pk4.Species, CB_Ability, CB_Form); + setAbilityList(); DEV_Ability.SelectedValue = pk4.Ability; CB_Nature.SelectedValue = pk4.Nature; TB_TID.Text = pk4.TID.ToString("00000"); @@ -1271,6 +1274,9 @@ private void populateFieldsPK4(PK4 pk4) TB_EXP.Text = pk4.EXP.ToString(); Label_Gender.Text = gendersymbols[pk4.Gender]; Label_Gender.ForeColor = pk4.Gender == 2 ? Label_Species.ForeColor : (pk4.Gender == 1 ? Color.Red : Color.Blue); + + if (HaX) + DEV_Ability.SelectedValue = pk4.Ability; } private void populateFieldsPK5(PK5 pk5) { @@ -1291,7 +1297,7 @@ private void populateFieldsPK5(PK5 pk5) Label_OTGender.ForeColor = pk5.OT_Gender == 1 ? Color.Red : Color.Blue; TB_PID.Text = pk5.PID.ToString("X8"); CB_HeldItem.SelectedValue = pk5.HeldItem; - setAbilityList(TB_AbilityNumber, pk5.Species, CB_Ability, CB_Form); + setAbilityList(); DEV_Ability.SelectedValue = pk5.Ability; CB_Nature.SelectedValue = pk5.Nature; TB_TID.Text = pk5.TID.ToString("00000"); @@ -1391,6 +1397,9 @@ private void populateFieldsPK5(PK5 pk5) TB_EXP.Text = pk5.EXP.ToString(); Label_Gender.Text = gendersymbols[pk5.Gender]; Label_Gender.ForeColor = pk5.Gender == 2 ? Label_Species.ForeColor : (pk5.Gender == 1 ? Color.Red : Color.Blue); + + if (HaX) + DEV_Ability.SelectedValue = pk5.Ability; } private void populateFieldsPK6(PK6 pk6) { @@ -1412,7 +1421,7 @@ private void populateFieldsPK6(PK6 pk6) Label_OTGender.ForeColor = pk6.OT_Gender == 1 ? Color.Red : Color.Blue; TB_PID.Text = pk6.PID.ToString("X8"); CB_HeldItem.SelectedValue = pk6.HeldItem; - setAbilityList(TB_AbilityNumber, pk6.Species, CB_Ability, CB_Form); + setAbilityList(); TB_AbilityNumber.Text = pk6.AbilityNumber.ToString(); CB_Ability.SelectedIndex = pk6.AbilityNumber < 6 ? pk6.AbilityNumber >> 1 : 0; // with some simple error handling CB_Nature.SelectedValue = pk6.Nature; @@ -1557,46 +1566,29 @@ internal static void setForms(int species, ComboBox cb, Label l = null) cb.DataSource = PKX.getFormList(species, types, forms, gendersymbols).ToList(); } - internal static void setAbilityList(MaskedTextBox tb_abil, int species, ComboBox cb_abil, ComboBox cb_forme) + private void setAbilityList() { - if (!fieldsInitialized && string.IsNullOrWhiteSpace(tb_abil.Text)) + if (SAV.Generation < 3) // no abilities return; - int newabil = Convert.ToInt16(tb_abil.Text) >> 1; - int form = cb_forme.SelectedIndex; - byte[] abils = PKX.getAbilities(species, form); + int formnum = 0; + int species = Util.getIndex(CB_Species); + if (SAV.Generation > 3) // has forms + formnum = CB_Form.SelectedIndex; - // Build Ability List - List ability_list = new List - { - abilitylist[abils[0]] + " (1)", - abilitylist[abils[1]] + " (2)", - abilitylist[abils[2]] + " (H)" - }; - cb_abil.DataSource = ability_list; + byte[] abils = SAV.Personal[SAV.Personal[species].FormeIndex(species, formnum)].Abilities; - cb_abil.SelectedIndex = newabil < 3 ? newabil : 0; - } - private void setAbilityList3(MaskedTextBox tb_abil, int species, ComboBox cb_abil, ComboBox cb_forme) - { - if (!fieldsInitialized && string.IsNullOrWhiteSpace(tb_abil.Text)) - return; - int newabil = Convert.ToInt16(tb_abil.Text) >> 1; - - int form = cb_forme.SelectedIndex; - byte[] abils = PKX.Gen3Abilities[Util.getIndex(CB_Species)]; - if (abils[0] == 76) abils[0] = 77; // Air Lock +1 - if (abils[1] == 76) abils[1] = 77; // Air Lock +1 - - // Build Ability List List ability_list = new List { abilitylist[abils[0]] + " (1)", abilitylist[abils[1]] + " (2)", }; - cb_abil.DataSource = ability_list; + if (SAV.Generation >= 5) // hidden ability + ability_list.Add(abilitylist[abils[1]] + " (H)"); - cb_abil.SelectedIndex = newabil < 3 ? newabil : 0; + int curAbil = CB_Ability.SelectedIndex; + CB_Ability.DataSource = ability_list; + CB_Ability.SelectedIndex = curAbil; } // PKX Data Calculation Functions // private void setIsShiny() @@ -1895,7 +1887,7 @@ private void updateIVs(object sender, EventArgs e) TB_IVTotal.Text = pkm.IVs.Sum().ToString(); int characteristic = pkm.Characteristic; - L_Characteristic.Visible = characteristic > -1; + L_Characteristic.Visible = Label_CharacteristicPrefix.Visible = characteristic > -1; if (characteristic > -1) L_Characteristic.Text = characteristics[pkm.Characteristic]; updateStats(); @@ -2046,7 +2038,7 @@ private void updateForm(object sender, EventArgs e) { updateStats(); // Repopulate Abilities if Species Form has different abilities - setAbilityList(TB_AbilityNumber, Util.getIndex(CB_Species), CB_Ability, CB_Form); + setAbilityList(); // Gender Forms if (PKX.getGender(CB_Form.Text) < 2 && Util.getIndex(CB_Species) != 201) // don't do this for Unown @@ -2189,7 +2181,7 @@ private void updateSpecies(object sender, EventArgs e) Label_Gender.Text = gendersymbols[Gender]; Label_Gender.ForeColor = Gender == 2 ? Label_Species.ForeColor : (Gender == 1 ? Color.Red : Color.Blue); - setAbilityList(TB_AbilityNumber, Species, CB_Ability, CB_Form); + setAbilityList(); updateForm(null, null); // If species changes and no nickname, set the new name == speciesName. diff --git a/Saves/SAV3.cs b/Saves/SAV3.cs index 4ddd69c0d..411aaae72 100644 --- a/Saves/SAV3.cs +++ b/Saves/SAV3.cs @@ -6,8 +6,8 @@ namespace PKHeX public sealed class SAV3 : SaveFile { public override string BAKName => $"{FileName} [{OT} ({Version})" +/* - {LastSavedTime}*/ "].bak"; - public override string Filter => "Main SAV|*.*"; - public override string Extension => ""; + public override string Filter => "SAV File|*.sav"; + public override string Extension => ".sav"; /* SAV3 Structure: * 0xE000 per save file @@ -33,12 +33,16 @@ public sealed class SAV3 : SaveFile 0x7d0 // D | PC Block 8 }; - public SAV3(byte[] data = null) + public SAV3(byte[] data = null, GameVersion versionOverride = GameVersion.Any) { Data = data == null ? new byte[SaveUtil.SIZE_G3RAW] : (byte[])data.Clone(); BAK = (byte[])Data.Clone(); Exportable = !Data.SequenceEqual(new byte[Data.Length]); + Version = versionOverride == GameVersion.Any ? GameVersion.FRLG : SaveUtil.getIsG3SAV(Data); + if (Version == GameVersion.Invalid) + return; + BlockOrder = new int[14]; ActiveSAV = SaveUtil.SIZE_G3RAWHALF == data.Length || BitConverter.ToUInt32(Data, 0xFFC) > BitConverter.ToUInt32(Data, 0xEFFC) ? 0 : 1; for (int i = 0; i < 14; i++) @@ -51,8 +55,6 @@ public SAV3(byte[] data = null) Block2 = Array.IndexOf(BlockOrder, 2)*0x1000 + ABO; Block3 = Array.IndexOf(BlockOrder, 3)*0x1000 + ABO; - uint GameCode = BitConverter.ToUInt32(Data, ABO + Array.IndexOf(BlockOrder, 0)*0x1000); - SaveVersion = GameCode < 2 ? (int)GameCode : 2; // Set up PC data buffer beyond end of save file. Box = Data.Length; @@ -68,20 +70,18 @@ public SAV3(byte[] data = null) } HeldItems = Legal.HeldItems_RS; + Personal = Legal.PersonalAO; // todo if (!Exportable) resetBoxes(); } - - private readonly int SaveVersion; + private readonly int ActiveSAV; private int ABO => ActiveSAV*0xE000; private readonly int[] BlockOrder; // Configuration - public override byte[] BAK { get; } - public override bool Exportable { get; } - public override SaveFile Clone() { return new SAV3(Data.Take(Box).ToArray()); } + public override SaveFile Clone() { return new SAV3(Data.Take(Box).ToArray(), Version); } public override int SIZE_STORED => PKX.SIZE_3STORED; public override int SIZE_PARTY => PKX.SIZE_3PARTY; @@ -145,19 +145,7 @@ public override string ChecksumInfo } // Trainer Info - public override GameVersion Version - { - get - { - switch (SaveVersion) - { - case 0: return GameVersion.RS; - case 1: return GameVersion.FRLG; - case 2: return GameVersion.E; - } - return GameVersion.Unknown; - } - } + public override GameVersion Version { get; protected set; } private bool Japanese; private uint SecurityKey diff --git a/Saves/SAV4.cs b/Saves/SAV4.cs index 827613b87..8bd1a9cd8 100644 --- a/Saves/SAV4.cs +++ b/Saves/SAV4.cs @@ -8,27 +8,28 @@ public sealed class SAV4 : SaveFile public override string BAKName => $"{FileName} [{OT} ({Version})" +/* - {LastSavedTime}*/ "].bak"; public override string Filter => (Footer.Length > 0 ? "DeSmuME DSV|*.dsv|" : "") + "SAV File|*.sav"; public override string Extension => ".sav"; - public SAV4(byte[] data = null, int versionOverride = -1) + public SAV4(byte[] data = null, GameVersion versionOverride = GameVersion.Any) { Data = data == null ? new byte[SaveUtil.SIZE_G4RAW] : (byte[])data.Clone(); BAK = (byte[])Data.Clone(); Exportable = !Data.SequenceEqual(new byte[Data.Length]); - Footer = new byte[0]; // Get Version - SaveVersion = versionOverride > -1 ? versionOverride : Math.Max((int)SaveUtil.getIsG4SAV(Data), 0); // Empty file default to DP + Version = versionOverride == GameVersion.Any ? GameVersion.HGSS : SaveUtil.getIsG4SAV(Data); + if (Version == GameVersion.Invalid) + return; + getActiveBlock(); getSAVOffsets(); + Personal = Legal.PersonalAO; // todo + if (!Exportable) resetBoxes(); } // Configuration - public readonly int SaveVersion; - public override byte[] BAK { get; } - public override bool Exportable { get; } - public override SaveFile Clone() { return new SAV4(Data, SaveVersion); } + public override SaveFile Clone() { return new SAV4(Data, Version); } public override int SIZE_STORED => PKX.SIZE_4STORED; public override int SIZE_PARTY => PKX.SIZE_4PARTY; @@ -156,23 +157,23 @@ public override string ChecksumInfo private int HBO => 0x40000 * hofBlock; private void getActiveBlock() { - if (SaveVersion < 0) + if (Version < 0) return; int ofs = 0; - if (SaveVersion == 0) ofs = 0xC0F0; // DP - else if (SaveVersion == 1) ofs = 0xCF1C; // PT - else if (SaveVersion == 2) ofs = 0xF626; // HGSS + if (Version == GameVersion.DP) ofs = 0xC0F0; // DP + else if (Version == GameVersion.Pt) ofs = 0xCF1C; // PT + else if (Version == GameVersion.HGSS) ofs = 0xF626; // HGSS generalBlock = BitConverter.ToUInt16(Data, ofs) >= BitConverter.ToUInt16(Data, ofs + 0x40000) ? 0 : 1; - if (SaveVersion == 0) ofs = 0x1E2D0; // DP - else if (SaveVersion == 1) ofs = 0x1F100; // PT - else if (SaveVersion == 2) ofs = 0x21A00; // HGSS + if (Version == GameVersion.DP) ofs = 0x1E2D0; // DP + else if (Version == GameVersion.Pt) ofs = 0x1F100; // PT + else if (Version == GameVersion.HGSS) ofs = 0x21A00; // HGSS storageBlock = BitConverter.ToUInt16(Data, ofs) >= BitConverter.ToUInt16(Data, ofs + 0x40000) ? 0 : 1; } private void getSAVOffsets() { - if (SaveVersion < 0) + if (Version < 0) return; switch (Version) @@ -306,7 +307,7 @@ public override int PartyCount } public override int getBoxOffset(int box) { - return Box + SIZE_STORED*box*30 + (SaveVersion == 2 ? box * 0x10 : 0); + return Box + SIZE_STORED*box*30 + (Version == GameVersion.HGSS ? box * 0x10 : 0); } public override int getPartyOffset(int slot) { @@ -314,19 +315,6 @@ public override int getPartyOffset(int slot) } // Trainer Info - public override GameVersion Version - { - get - { - switch (SaveVersion) - { - case 0: return GameVersion.DP; - case 1: return GameVersion.Pt; - case 2: return GameVersion.HGSS; - } - return GameVersion.Unknown; - } - } public override string OT { get diff --git a/Saves/SAV5.cs b/Saves/SAV5.cs index 2dd0b690b..05be1aff0 100644 --- a/Saves/SAV5.cs +++ b/Saves/SAV5.cs @@ -10,17 +10,16 @@ public sealed class SAV5 : SaveFile public override string BAKName => $"{FileName} [{OT} ({Version})" +/* - {LastSavedTime}*/ "].bak"; public override string Filter => (Footer.Length > 0 ? "DeSmuME DSV|*.dsv|" : "") + "SAV File|*.sav"; public override string Extension => ".sav"; - public SAV5(byte[] data = null, int versionOverride = -1) + public SAV5(byte[] data = null, GameVersion versionOverride = GameVersion.Any) { Data = data == null ? new byte[SaveUtil.SIZE_G5RAW] : (byte[])data.Clone(); BAK = (byte[])Data.Clone(); Exportable = !Data.SequenceEqual(new byte[Data.Length]); - Footer = new byte[0]; // Get Version - SaveVersion = versionOverride > -1 ? versionOverride : (int)SaveUtil.getIsG5SAV(Data); - if (SaveVersion < 0) // Invalidate Data - Data = null; + Version = versionOverride == GameVersion.Any ? GameVersion.B2W2 : SaveUtil.getIsG5SAV(Data); + if (Version == GameVersion.Invalid) + return; // First blocks are always the same position/size PCLayout = 0x0; @@ -31,9 +30,9 @@ public SAV5(byte[] data = null, int versionOverride = -1) AdventureInfo = 0x1D900; // Different Offsets for later blocks - switch (SaveVersion) + switch (Version) { - case 0: // BW + case GameVersion.BW: BattleBox = 0x20A00; Trainer2 = 0x21200; Daycare = 0x20E00; @@ -50,7 +49,7 @@ public SAV5(byte[] data = null, int versionOverride = -1) LegalMedicine = Legal.Pouch_Medicine_BW; LegalBerries = Legal.Pouch_Berries_BW; break; - case 1: // B2W2 + case GameVersion.B2W2: // B2W2 BattleBox = 0x20900; Trainer2 = 0x21100; EventConst = 0x1FF00; @@ -71,7 +70,7 @@ public SAV5(byte[] data = null, int versionOverride = -1) break; } HeldItems = Legal.HeldItems_BW; - + Personal = Legal.PersonalAO; // todo getBlockInfo(); if (!Exportable) @@ -79,10 +78,7 @@ public SAV5(byte[] data = null, int versionOverride = -1) } // Configuration - private int SaveVersion { get; set; } - public override byte[] BAK { get; } - public override bool Exportable { get; } - public override SaveFile Clone() { return new SAV5(Data, SaveVersion); } + public override SaveFile Clone() { return new SAV5(Data, Version); } public override int SIZE_STORED => PKX.SIZE_5STORED; public override int SIZE_PARTY => PKX.SIZE_5PARTY; @@ -99,7 +95,7 @@ public SAV5(byte[] data = null, int versionOverride = -1) public override int MaxMoveID => 559; public override int MaxSpeciesID => 649; - public override int MaxItemID => SaveVersion == 1 ? 632 : 638; + public override int MaxItemID => Version == GameVersion.BW ? 632 : 638; public override int MaxAbilityID => 164; public override int MaxBallID => 0x19; public override int MaxGameID => 23; // B2 @@ -109,7 +105,7 @@ public SAV5(byte[] data = null, int versionOverride = -1) private void getBlockInfo() { // Can be slick with just a list of block lengths, but oh well, precomputed. - if (SaveVersion == 0) // BW + if (Version == GameVersion.BW) { Blocks = new[] { @@ -185,7 +181,7 @@ private void getBlockInfo() new BlockInfo(0x23F00, 0x008C, 0x23F9A, 0x23F9A), // Checksums */ }; } - else if (SaveVersion == 1) // B2W2 + else if (Version == GameVersion.B2W2) { Blocks = new[] { @@ -357,7 +353,7 @@ public override int getDaycareSlotOffset(int loc, int slot) } public override ulong? getDaycareRNGSeed(int loc) { - if (SaveVersion != 1) + if (Version != GameVersion.B2W2) return null; return BitConverter.ToUInt64(Data, Daycare + 0x1CC); } @@ -371,8 +367,6 @@ public override int getDaycareSlotOffset(int loc, int slot) } public override void setDaycareEXP(int loc, int slot, uint EXP) { - if (SaveVersion != 1) - return; BitConverter.GetBytes(EXP).CopyTo(Data, Daycare + 4 + 0xDC + slot * 0xE4); } public override void setDaycareOccupied(int loc, int slot, bool occupied) @@ -381,7 +375,7 @@ public override void setDaycareOccupied(int loc, int slot, bool occupied) } public override void setDaycareRNGSeed(int loc, ulong seed) { - if (SaveVersion != 1) + if (Version != GameVersion.B2W2) return; BitConverter.GetBytes(seed).CopyTo(Data, Daycare + 0x1CC); } diff --git a/Saves/SAV6.cs b/Saves/SAV6.cs index 82d75bf02..18aa812ae 100644 --- a/Saves/SAV6.cs +++ b/Saves/SAV6.cs @@ -15,21 +15,18 @@ public SAV6(byte[] data = null) Data = data == null ? new byte[SaveUtil.SIZE_G6ORAS] : (byte[])data.Clone(); BAK = (byte[])Data.Clone(); Exportable = !Data.SequenceEqual(new byte[Data.Length]); - Footer = new byte[0]; // Load Info getBlockInfo(); getSAVOffsets(); HeldItems = ORAS ? Legal.HeldItem_AO : Legal.HeldItem_XY; - + Personal = ORAS ? Legal.PersonalAO : Legal.PersonalXY; if (!Exportable) resetBoxes(); } // Configuration - public override byte[] BAK { get; } - public override bool Exportable { get; } public override SaveFile Clone() { return new SAV6(Data); } public override int SIZE_STORED => PKX.SIZE_6STORED; diff --git a/Saves/SaveFile.cs b/Saves/SaveFile.cs index 9cfc82206..4abd357a4 100644 --- a/Saves/SaveFile.cs +++ b/Saves/SaveFile.cs @@ -14,11 +14,11 @@ public abstract class SaveFile public bool Edited; public string FileName, FilePath; public abstract string BAKName { get; } - public abstract byte[] BAK { get; } - public abstract bool Exportable { get; } + public byte[] BAK { get; protected set; } + public bool Exportable { get; protected set; } public abstract SaveFile Clone(); public abstract string Filter { get; } - public byte[] Footer { protected get; set; } // .dsv + public byte[] Footer { protected get; set; } = new byte[0]; // .dsv // General PKM Properties protected abstract Type PKMType { get; } @@ -40,10 +40,11 @@ public byte[] Write(bool DSV) } public virtual string MiscSaveChecks() { return ""; } public virtual string MiscSaveInfo() { return ""; } - public abstract GameVersion Version { get; } + public virtual GameVersion Version { get; protected set; } public abstract bool ChecksumsValid { get; } public abstract string ChecksumInfo { get; } public abstract int Generation { get; } + public PersonalInfo[] Personal { get; protected set; } public bool ORASDEMO => Data.Length == SaveUtil.SIZE_G6ORASDEMO; public bool ORAS => Version == GameVersion.OR || Version == GameVersion.AS; diff --git a/Saves/SaveUtil.cs b/Saves/SaveUtil.cs index 835a21a77..4d8019ba6 100644 --- a/Saves/SaveUtil.cs +++ b/Saves/SaveUtil.cs @@ -6,6 +6,7 @@ namespace PKHeX { public enum GameVersion { + Invalid = -2, Any = -1, Unknown = 0, S = 1, R = 2, E = 3, FR = 4, LG = 5, CXD = 15, @@ -14,40 +15,17 @@ public enum GameVersion X = 24, Y = 25, AS = 26, OR = 27, SN = 28, MN = 29, - RS = 200, - FRLG = 201, - DP = 100, - HGSS = 101, - } - public enum Gen3Version - { - Invalid = -1, - RS = 0, - FRLG = 1, - E = 2 - } - - public enum Gen4Version - { - Invalid = -1, - DP = 0, - Pt = 1, - HGSS = 2 - } - - public enum Gen5Version - { - Invalid = -1, - BW = 0, - B2W2 = 1 - } - - public enum Gen6Version - { - Invalid = -1, - XY = 0, - ORASDEMO = 1, - ORAS = 2, + // Game Groupings (SaveFile type) + RS = 100, + FRLG = 101, + DP = 103, + HGSS = 104, + BW = 104, + B2W2 = 105, + XY = 106, + ORASDEMO = 107, + ORAS = 108, + SM = 109, } public static class SaveUtil @@ -66,109 +44,115 @@ public static class SaveUtil internal static readonly byte[] FOOTER_DSV = Encoding.ASCII.GetBytes("|-DESMUME SAVE-|"); - /// - /// Determines the generation of the given save data. - /// + /// Determines the generation of the given save data. /// Save data of which to determine the generation - /// The generation of the save file (i.e. 4, 5, or 6), or -1 if the generation cannot be determined. + /// Version Identifier or Invalid if type cannot be determined. public static int getSAVGeneration(byte[] data) { - if (getIsG3SAV(data) != Gen3Version.Invalid) + if (getIsG3SAV(data) != GameVersion.Invalid) return 3; - if (getIsG4SAV(data) != Gen4Version.Invalid) + if (getIsG4SAV(data) != GameVersion.Invalid) return 4; - if (getIsG5SAV(data) != Gen5Version.Invalid) + if (getIsG5SAV(data) != GameVersion.Invalid) return 5; - if (getIsG6SAV(data) != Gen6Version.Invalid) + if (getIsG6SAV(data) != GameVersion.Invalid) return 6; return -1; } - public static Gen3Version getIsG3SAV(byte[] data) + /// Determines the type of 3th gen save + /// Save data of which to determine the type + /// Version Identifier or Invalid if type cannot be determined. + public static GameVersion getIsG3SAV(byte[] data) { if (data.Length != SIZE_G3RAW && data.Length != SIZE_G3RAWHALF) - return Gen3Version.Invalid; + 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 Gen3Version.Invalid; + return GameVersion.Invalid; // Detect RS/E/FRLG // Section 0 stores Game Code @ 0x00AC; 0 for RS, 1 for FRLG, else for Emerald - uint GameCode = BitConverter.ToUInt32(data, Array.IndexOf(BlockOrder, 0) * 0x1000); - return (Gen3Version)(GameCode < 2 ? (int)GameCode : 2); + uint GameCode = BitConverter.ToUInt32(data, Array.IndexOf(BlockOrder, 0) * 0x1000 + 0xAC); + switch (GameCode) + { + case 0: return GameVersion.RS; + case 1: return GameVersion.FRLG; + default: return GameVersion.E; + } } - /// - /// Determines the type of 4th gen save - /// + /// Determines the type of 4th gen save /// Save data of which to determine the type - /// - public static Gen4Version getIsG4SAV(byte[] data) + /// Version Identifier or Invalid if type cannot be determined. + public static GameVersion getIsG4SAV(byte[] data) { if (data.Length != SIZE_G4RAW) - return Gen4Version.Invalid; + return GameVersion.Invalid; // General Block Checksum if (BitConverter.ToUInt16(data, 0xC0FE) == ccitt16(data.Take(0xC0EC).ToArray())) - return Gen4Version.DP; + return GameVersion.DP; if (BitConverter.ToUInt16(data, 0xCF2A) == ccitt16(data.Take(0xCF18).ToArray())) - return Gen4Version.Pt; + return GameVersion.Pt; if (BitConverter.ToUInt16(data, 0xF626) == ccitt16(data.Take(0xF618).ToArray())) - return Gen4Version.HGSS; + return GameVersion.HGSS; // General Block Checksum is invalid, check for block identifiers if (data.Skip(0xC0F4).Take(10).SequenceEqual(new byte[] { 0x00, 0xC1, 0x00, 0x00, 0x23, 0x06, 0x06, 0x20, 0x00, 0x00 })) - return Gen4Version.DP; + return GameVersion.DP; if (data.Skip(0xCF20).Take(10).SequenceEqual(new byte[] { 0x2C, 0xCF, 0x00, 0x00, 0x23, 0x06, 0x06, 0x20, 0x00, 0x00 })) - return Gen4Version.Pt; + return GameVersion.Pt; if (data.Skip(0xF61C).Take(10).SequenceEqual(new byte[] { 0x28, 0xF6, 0x00, 0x00, 0x23, 0x06, 0x06, 0x20, 0x00, 0x00 })) - return Gen4Version.HGSS; + return GameVersion.HGSS; - return Gen4Version.Invalid; + return GameVersion.Invalid; } - - public static Gen5Version getIsG5SAV(byte[] data) + /// Determines the type of 5th gen save + /// Save data of which to determine the type + /// Version Identifier or Invalid if type cannot be determined. + public static GameVersion getIsG5SAV(byte[] data) { if (data.Length != SIZE_G5RAW) - return Gen5Version.Invalid; + return GameVersion.Invalid; ushort chk1 = BitConverter.ToUInt16(data, SIZE_G5BW - 0x100 + 0x8C + 0xE); ushort actual1 = ccitt16(data.Skip(SIZE_G5BW - 0x100).Take(0x8C).ToArray()); if (chk1 == actual1) - return Gen5Version.BW; + return GameVersion.BW; ushort chk2 = BitConverter.ToUInt16(data, SIZE_G5B2W2 - 0x100 + 0x94 + 0xE); ushort actual2 = ccitt16(data.Skip(SIZE_G5B2W2 - 0x100).Take(0x94).ToArray()); if (chk2 == actual2) - return Gen5Version.B2W2; - return Gen5Version.Invalid; + return GameVersion.B2W2; + return GameVersion.Invalid; } - - public static Gen6Version getIsG6SAV(byte[] data) + /// Determines the type of 6th gen save + /// Save data of which to determine the type + /// Version Identifier or Invalid if type cannot be determined. + public static GameVersion getIsG6SAV(byte[] data) { if (!SizeValidSAV6(data.Length)) - return Gen6Version.Invalid; + return GameVersion.Invalid; if (BitConverter.ToUInt32(data, data.Length - 0x1F0) != BEEF) - return Gen6Version.Invalid; + return GameVersion.Invalid; switch (data.Length) { case SIZE_G6XY: - return Gen6Version.XY; + return GameVersion.XY; case SIZE_G6ORASDEMO: - return Gen6Version.ORASDEMO; + return GameVersion.ORASDEMO; case SIZE_G6ORAS: - return Gen6Version.ORAS; + return GameVersion.ORAS; } - return Gen6Version.Invalid; + return GameVersion.Invalid; } - /// - /// Creates an instance of a SaveFile using the given save data. - /// + /// Creates an instance of a SaveFile using the given save data. /// Save data from which to create a SaveFile. /// An appropriate type of save file for the given data, or null if the save data is invalid. public static SaveFile getVariantSAV(byte[] data) From 9d36976860313d1814aee2ff2c4db02788ea5c7a Mon Sep 17 00:00:00 2001 From: Kaphotics Date: Tue, 28 Jun 2016 17:54:07 -0700 Subject: [PATCH 37/49] Remove unused itempouch resources Was never used, will never use. --- PKX/f1-Main.cs | 3 +- Properties/Resources.Designer.cs | 185 +++++------------------- Properties/Resources.resx | 24 --- Resources/text/de/text_ItemPouch_de.txt | 5 - Resources/text/en/text_ItemPouch_en.txt | 5 - Resources/text/es/text_ItemPouch_es.txt | 5 - Resources/text/fr/text_ItemPouch_fr.txt | 5 - Resources/text/it/text_ItemPouch_it.txt | 5 - Resources/text/ja/text_ItemPouch_ja.txt | 5 - Resources/text/ko/text_ItemPouch_ko.txt | 5 - Resources/text/zh/text_ItemPouch_zh.txt | 5 - 11 files changed, 41 insertions(+), 211 deletions(-) delete mode 100644 Resources/text/de/text_ItemPouch_de.txt delete mode 100644 Resources/text/en/text_ItemPouch_en.txt delete mode 100644 Resources/text/es/text_ItemPouch_es.txt delete mode 100644 Resources/text/fr/text_ItemPouch_fr.txt delete mode 100644 Resources/text/it/text_ItemPouch_it.txt delete mode 100644 Resources/text/ja/text_ItemPouch_ja.txt delete mode 100644 Resources/text/ko/text_ItemPouch_ko.txt delete mode 100644 Resources/text/zh/text_ItemPouch_zh.txt diff --git a/PKX/f1-Main.cs b/PKX/f1-Main.cs index f2cc13e88..a2d81d2ba 100644 --- a/PKX/f1-Main.cs +++ b/PKX/f1-Main.cs @@ -140,7 +140,7 @@ public Main() public static string[] metHGSS_00000, metHGSS_02000, metHGSS_03000 = { }; public static string[] metBW2_00000, metBW2_30000, metBW2_40000, metBW2_60000 = { }; public static string[] metXY_00000, metXY_30000, metXY_40000, metXY_60000 = { }; - public static string[] wallpapernames, puffs, itempouch = { }; + public static string[] wallpapernames, puffs = { }; public static bool unicode; public static List MoveDataSource, ItemDataSource, SpeciesDataSource, BallDataSource, NatureDataSource, AbilityDataSource, VersionDataSource; @@ -842,7 +842,6 @@ private void InitializeStrings() characteristics = Util.getStringList("character", l); specieslist = Util.getStringList("species", l); wallpapernames = Util.getStringList("wallpaper", l); - itempouch = Util.getStringList("itempouch", l); encountertypelist = Util.getStringList("encountertype", l); gamelist = Util.getStringList("games", l); gamelanguages = Util.getNulledStringArray(Util.getStringList("languages")); diff --git a/Properties/Resources.Designer.cs b/Properties/Resources.Designer.cs index c721cb8b3..9e278c637 100644 --- a/Properties/Resources.Designer.cs +++ b/Properties/Resources.Designer.cs @@ -9760,9 +9760,9 @@ internal class Resources { } /// - /// Looks up a localized string similar to 60 Ash - ///21 Test1 - ///22 Test2 + /// Looks up a localized string similar to 60 Ash + ///21 Test1 + ///22 Test2 ///24 Test3. /// internal static string const_oras { @@ -9999,26 +9999,25 @@ internal class Resources { } /// - /// Looks up a localized string similar to 0648 (OR) Groudon Defeated - ///2839 (OR) Groudon Captured - ///0647 (AS) Kyogre Defeated - ///2840 (AS) Kyogre Captured - ///0208 (OR) Ho-Oh Defeated - ///2815 (OR) Ho-Oh Captured - ///0209 (AS) Lugia Defeated - ///2814 (AS) Lugia Captured - ///2819 (AS) Dialga Captured - ///2820 (OR) Palkia Captured - ///2828 (OR) Tornadus Captured - ///2829 (AS) Thundurus Captured - ///2832 Landorus Captured - ///0182 (OR) Reshiram Defeated - ///2830 (OR) Reshiram Captured - ///0183 (AS) Zekrom Defeated - ///2831 (AS) Zekrom Captured - ///0419 (OR) Latias Defeated - ///2834 (OR) Latias Captured - ///0420 (AS) Lati [rest of string was truncated]";. + /// Looks up a localized string similar to 0648 (OR) Groudon Defeated + ///2839 (OR) Groudon Captured + ///0647 (AS) Kyogre Defeated + ///2840 (AS) Kyogre Captured + ///0208 (OR) Ho-Oh Defeated + ///2815 (OR) Ho-Oh Captured + ///0209 (AS) Lugia Defeated + ///2814 (AS) Lugia Captured + ///2819 (AS) Dialga Captured + ///2820 (OR) Palkia Captured + ///2828 (OR) Tornadus Captured + ///2829 (AS) Thundurus Captured + ///2832 Landorus Captured + ///0182 (OR) Reshiram Defeated + ///2830 (OR) Reshiram Captured + ///0183 (AS) Zekrom Defeated + ///2831 (AS) Zekrom Captured + ///0419 (OR) Latias Defeated + ///2834 (OR) Latias Captu [rest of string was truncated]";. /// internal static string flags_oras { get { @@ -10027,24 +10026,24 @@ internal class Resources { } /// - /// Looks up a localized string similar to 2237 2237 - ///2238 2238 - ///2239 2239 - ///0963 Mewtwo Defeated - ///0115 Mewtwo Captured - ///0114 Zygarde Captured - ///0790 Zygarde Defeated - ///0285 Singles Statuette - ///0286 Doubles Statuette - ///0287 Triples Statuette - ///0288 Rotation Statuette - ///0289 Multi Statuette - ///0290 Super Singles Unlocked - ///0291 Super Doubles Unlocked - ///0292 Super Triples Unlocked - ///0293 Super Rotation Unlocked - ///0294 Super Multi Unlocked - ///0675 50: Beat Chatelaine + /// Looks up a localized string similar to 2237 2237 + ///2238 2238 + ///2239 2239 + ///0963 Mewtwo Defeated + ///0115 Mewtwo Captured + ///0114 Zygarde Captured + ///0790 Zygarde Defeated + ///0285 Singles Statuette + ///0286 Doubles Statuette + ///0287 Triples Statuette + ///0288 Rotation Statuette + ///0289 Multi Statuette + ///0290 Super Singles Unlocked + ///0291 Super Doubles Unlocked + ///0292 Super Triples Unlocked + ///0293 Super Rotation Unlocked + ///0294 Super Multi Unlocked + ///0675 50: Beat Chatelaine ///2546 Pokédex Obtained. /// internal static string flags_xy { @@ -22826,110 +22825,6 @@ internal class Resources { } } - /// - /// Looks up a localized string similar to Items - ///Medizin - ///TM & VM - ///Beeren - ///Basis-Items. - /// - internal static string text_itempouch_de { - get { - return ResourceManager.GetString("text_itempouch_de", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to ITEMS - ///MEDICINE - ///TMs & HMs - ///BERRIES - ///KEY ITEMS. - /// - internal static string text_itempouch_en { - get { - return ResourceManager.GetString("text_itempouch_en", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Objetos - ///Botiquín - ///MT/MO - ///Bayas - ///Objetos Clave. - /// - internal static string text_itempouch_es { - get { - return ResourceManager.GetString("text_itempouch_es", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to OBJETS - ///PV/PP - ///CT & CS - ///BAIES - ///OBJETS RARES. - /// - internal static string text_itempouch_fr { - get { - return ResourceManager.GetString("text_itempouch_fr", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Strumenti - ///Rimedi - ///MT e MN - ///Bacche - ///Strumenti Base. - /// - internal static string text_itempouch_it { - get { - return ResourceManager.GetString("text_itempouch_it", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to どうぐ - ///かいふく - ///わざマシン - ///きのみ - ///たいせつなもの. - /// - internal static string text_itempouch_ja { - get { - return ResourceManager.GetString("text_itempouch_ja", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to 도구 - ///회복 - ///기술머신 - ///나무열매 - ///중요한 물건. - /// - internal static string text_itempouch_ko { - get { - return ResourceManager.GetString("text_itempouch_ko", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to 道具 - ///恢复 - ///技能学习器 - ///树果 - ///重要物品. - /// - internal static string text_itempouch_zh { - get { - return ResourceManager.GetString("text_itempouch_zh", resourceCulture); - } - } - /// /// Looks up a localized string similar to Kein ///Meisterball diff --git a/Properties/Resources.resx b/Properties/Resources.resx index e15921321..14e9b3472 100644 --- a/Properties/Resources.resx +++ b/Properties/Resources.resx @@ -5395,30 +5395,6 @@ ..\Resources\text\zh\text_hgss_03000_zh.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8 - - ..\Resources\text\de\text_ItemPouch_de.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252 - - - ..\Resources\text\en\text_ItemPouch_en.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252 - - - ..\Resources\text\es\text_ItemPouch_es.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8 - - - ..\Resources\text\fr\text_ItemPouch_fr.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252 - - - ..\Resources\text\it\text_ItemPouch_it.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252 - - - ..\Resources\text\ja\text_ItemPouch_ja.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8 - - - ..\Resources\text\ko\text_ItemPouch_ko.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8 - - - ..\Resources\text\zh\text_ItemPouch_zh.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8 - ..\Resources\text\de\text_Items_de.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8 diff --git a/Resources/text/de/text_ItemPouch_de.txt b/Resources/text/de/text_ItemPouch_de.txt deleted file mode 100644 index b1d15662c..000000000 --- a/Resources/text/de/text_ItemPouch_de.txt +++ /dev/null @@ -1,5 +0,0 @@ -Items -Medizin -TM & VM -Beeren -Basis-Items \ No newline at end of file diff --git a/Resources/text/en/text_ItemPouch_en.txt b/Resources/text/en/text_ItemPouch_en.txt deleted file mode 100644 index eba41057e..000000000 --- a/Resources/text/en/text_ItemPouch_en.txt +++ /dev/null @@ -1,5 +0,0 @@ -ITEMS -MEDICINE -TMs & HMs -BERRIES -KEY ITEMS \ No newline at end of file diff --git a/Resources/text/es/text_ItemPouch_es.txt b/Resources/text/es/text_ItemPouch_es.txt deleted file mode 100644 index 733b4122f..000000000 --- a/Resources/text/es/text_ItemPouch_es.txt +++ /dev/null @@ -1,5 +0,0 @@ -Objetos -Botiquín -MT/MO -Bayas -Objetos Clave \ No newline at end of file diff --git a/Resources/text/fr/text_ItemPouch_fr.txt b/Resources/text/fr/text_ItemPouch_fr.txt deleted file mode 100644 index fb37b17e7..000000000 --- a/Resources/text/fr/text_ItemPouch_fr.txt +++ /dev/null @@ -1,5 +0,0 @@ -OBJETS -PV/PP -CT & CS -BAIES -OBJETS RARES \ No newline at end of file diff --git a/Resources/text/it/text_ItemPouch_it.txt b/Resources/text/it/text_ItemPouch_it.txt deleted file mode 100644 index 18f18a32f..000000000 --- a/Resources/text/it/text_ItemPouch_it.txt +++ /dev/null @@ -1,5 +0,0 @@ -Strumenti -Rimedi -MT e MN -Bacche -Strumenti Base \ No newline at end of file diff --git a/Resources/text/ja/text_ItemPouch_ja.txt b/Resources/text/ja/text_ItemPouch_ja.txt deleted file mode 100644 index 4ee406559..000000000 --- a/Resources/text/ja/text_ItemPouch_ja.txt +++ /dev/null @@ -1,5 +0,0 @@ -どうぐ -かいふく -わざマシン -きのみ -たいせつなもの \ No newline at end of file diff --git a/Resources/text/ko/text_ItemPouch_ko.txt b/Resources/text/ko/text_ItemPouch_ko.txt deleted file mode 100644 index 5c892ad9c..000000000 --- a/Resources/text/ko/text_ItemPouch_ko.txt +++ /dev/null @@ -1,5 +0,0 @@ -도구 -회복 -기술머신 -나무열매 -중요한 물건 \ No newline at end of file diff --git a/Resources/text/zh/text_ItemPouch_zh.txt b/Resources/text/zh/text_ItemPouch_zh.txt deleted file mode 100644 index 66f566873..000000000 --- a/Resources/text/zh/text_ItemPouch_zh.txt +++ /dev/null @@ -1,5 +0,0 @@ -道具 -恢复 -技能学习器 -树果 -重要物品 \ No newline at end of file From a0bade7dc0d8738f4e67fc945e5a892f4ab09a7a Mon Sep 17 00:00:00 2001 From: Kaphotics Date: Wed, 29 Jun 2016 17:21:59 -0700 Subject: [PATCH 38/49] Fix Save Version get/set Short circuited -> rewritten, removed sav5 getter for Version (handled by abstract parent class) Thanks @Favna --- Saves/SAV3.cs | 6 +++++- Saves/SAV4.cs | 6 +++++- Saves/SAV5.cs | 20 +++++--------------- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/Saves/SAV3.cs b/Saves/SAV3.cs index 411aaae72..ae1388f97 100644 --- a/Saves/SAV3.cs +++ b/Saves/SAV3.cs @@ -39,7 +39,11 @@ public SAV3(byte[] data = null, GameVersion versionOverride = GameVersion.Any) BAK = (byte[])Data.Clone(); Exportable = !Data.SequenceEqual(new byte[Data.Length]); - Version = versionOverride == GameVersion.Any ? GameVersion.FRLG : SaveUtil.getIsG3SAV(Data); + if (data == null) + Version = GameVersion.FRLG; + else if (versionOverride != GameVersion.Any) + Version = versionOverride; + else Version = SaveUtil.getIsG3SAV(Data); if (Version == GameVersion.Invalid) return; diff --git a/Saves/SAV4.cs b/Saves/SAV4.cs index 8bd1a9cd8..5356c733f 100644 --- a/Saves/SAV4.cs +++ b/Saves/SAV4.cs @@ -15,7 +15,11 @@ public SAV4(byte[] data = null, GameVersion versionOverride = GameVersion.Any) Exportable = !Data.SequenceEqual(new byte[Data.Length]); // Get Version - Version = versionOverride == GameVersion.Any ? GameVersion.HGSS : SaveUtil.getIsG4SAV(Data); + if (data == null) + Version = GameVersion.HGSS; + else if (versionOverride != GameVersion.Any) + Version = versionOverride; + else Version = SaveUtil.getIsG4SAV(Data); if (Version == GameVersion.Invalid) return; diff --git a/Saves/SAV5.cs b/Saves/SAV5.cs index 05be1aff0..8b17dc7d9 100644 --- a/Saves/SAV5.cs +++ b/Saves/SAV5.cs @@ -17,7 +17,11 @@ public SAV5(byte[] data = null, GameVersion versionOverride = GameVersion.Any) Exportable = !Data.SequenceEqual(new byte[Data.Length]); // Get Version - Version = versionOverride == GameVersion.Any ? GameVersion.B2W2 : SaveUtil.getIsG5SAV(Data); + if (data == null) + Version = GameVersion.B2W2; + else if (versionOverride != GameVersion.Any) + Version = versionOverride; + else Version = SaveUtil.getIsG5SAV(Data); if (Version == GameVersion.Invalid) return; @@ -503,20 +507,6 @@ public override MysteryGiftAlbum GiftAlbum protected override MysteryGift[] MysteryGiftCards { get { return new MysteryGift[0]; } set { } } // Trainer Info - public override GameVersion Version - { - get - { - switch (Game) - { - case 20: return GameVersion.W; - case 21: return GameVersion.B; - case 22: return GameVersion.W2; - case 23: return GameVersion.B2; - } - return GameVersion.Unknown; - } - } public override string OT { get { return PKX.TrimFromFFFF(Encoding.Unicode.GetString(Data, Trainer1 + 0x4, 16)); } From c14b87fcd93545c3976f565a7db55f3d6d60cc06 Mon Sep 17 00:00:00 2001 From: Kaphotics Date: Wed, 29 Jun 2016 17:31:52 -0700 Subject: [PATCH 39/49] Fix PCBin/BoxBin setters Thanks @Favna --- Saves/SaveFile.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Saves/SaveFile.cs b/Saves/SaveFile.cs index 4abd357a4..0b9172923 100644 --- a/Saves/SaveFile.cs +++ b/Saves/SaveFile.cs @@ -414,7 +414,7 @@ public bool setPCBin(byte[] data) // split up data to individual pkm byte[][] pkdata = new byte[data.Length/SIZE_STORED][]; for (int i = 0; i < data.Length; i += SIZE_STORED) - pkdata[i] = data.Skip(i).Take(SIZE_STORED).ToArray(); + pkdata[i/SIZE_STORED] = data.Skip(i).Take(SIZE_STORED).ToArray(); PKM[] pkms = BoxData; for (int i = 0; i < pkms.Length; i++) @@ -429,7 +429,7 @@ public bool setBoxBin(byte[] data, int box) byte[][] pkdata = new byte[data.Length / SIZE_STORED][]; for (int i = 0; i < data.Length; i += SIZE_STORED) - pkdata[i] = data.Skip(i).Take(SIZE_STORED).ToArray(); + pkdata[i/SIZE_STORED] = data.Skip(i).Take(SIZE_STORED).ToArray(); PKM[] pkms = BoxData; for (int i = 0; i < 30; i++) From d8ed96fd698b0a315f130bcbb88691d1d4c653b1 Mon Sep 17 00:00:00 2001 From: Kaphotics Date: Wed, 29 Jun 2016 17:36:03 -0700 Subject: [PATCH 40/49] Fix drag&drop save file Missed a 'return', the logic afterwards handles loading a PKM (which we know the file is NOT). Thanks @Favna Previous two commits & this one resolve #127 --- PKX/f1-Main.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PKX/f1-Main.cs b/PKX/f1-Main.cs index a2d81d2ba..a17646017 100644 --- a/PKX/f1-Main.cs +++ b/PKX/f1-Main.cs @@ -4195,7 +4195,7 @@ private void pbBoxSlot_DragDrop(object sender, DragEventArgs e) return; string file = files[0]; if (!PKX.getIsPKM(new FileInfo(file).Length)) - openQuick(file); + { openQuick(file); return; } byte[] data = File.ReadAllBytes(file); PKM temp = PKMConverter.getPKMfromBytes(data); From fa9ca3ea590b2ff33dd5fbe4c4710a057ed1d8c8 Mon Sep 17 00:00:00 2001 From: Kaphotics Date: Wed, 29 Jun 2016 17:42:00 -0700 Subject: [PATCH 41/49] Flag Legality of Battle Primals Mark as illegal. Thanks Asia81! --- Legality/Checks.cs | 2 +- Legality/Tables.cs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Legality/Checks.cs b/Legality/Checks.cs index 4f8cd46e9..f7c884dd0 100644 --- a/Legality/Checks.cs +++ b/Legality/Checks.cs @@ -807,7 +807,7 @@ private LegalityCheck verifyForm() break; } - return pk6.AltForm > 0 && (Legal.BattleForms.Contains(pk6.Species) || Legal.BattleMegas.Contains(pk6.Species)) + return pk6.AltForm > 0 && new[] {Legal.BattleForms, Legal.BattleMegas, Legal.BattlePrimals}.Any(arr => arr.Contains(pk6.Species)) ? new LegalityCheck(Severity.Invalid, "Form cannot exist outside of a battle.") : new LegalityCheck(); } diff --git a/Legality/Tables.cs b/Legality/Tables.cs index 653ec34b5..84437cf83 100644 --- a/Legality/Tables.cs +++ b/Legality/Tables.cs @@ -488,6 +488,7 @@ public static partial class Legal 531, 719 }; + internal static readonly int[] BattlePrimals = {382, 383}; internal static readonly string[][] TradeXY = { new string[0], // 0 - None From 9e4fa6bec998585c526cdad1214504f7b9e9fce0 Mon Sep 17 00:00:00 2001 From: Kaphotics Date: Wed, 29 Jun 2016 22:57:26 -0700 Subject: [PATCH 42/49] Save Language default -1 (none) --- Saves/SAV3.cs | 1 - Saves/SaveFile.cs | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/Saves/SAV3.cs b/Saves/SAV3.cs index ae1388f97..371c1449a 100644 --- a/Saves/SAV3.cs +++ b/Saves/SAV3.cs @@ -279,7 +279,6 @@ public override InventoryPouch[] Inventory } set { } } - public override int Language { get { return 0; } set { } } public override int getDaycareSlotOffset(int loc, int slot) { diff --git a/Saves/SaveFile.cs b/Saves/SaveFile.cs index 0b9172923..23985ca44 100644 --- a/Saves/SaveFile.cs +++ b/Saves/SaveFile.cs @@ -278,7 +278,7 @@ public virtual MysteryGiftAlbum GiftAlbum // Trainer Info public abstract int Gender { get; set; } - public abstract int Language { get; set; } + public virtual int Language { get { return -1; } set { } } public virtual int Game { get { return -1; } set { } } public abstract ushort TID { get; set; } public abstract ushort SID { get; set; } From 8a8926bccafd561fa98e9466c8776436c29d453d Mon Sep 17 00:00:00 2001 From: Kaphotics Date: Wed, 29 Jun 2016 22:58:02 -0700 Subject: [PATCH 43/49] Split up setforms individual forms do it themselves, allows for main window to handle more generations --- PKX/f1-Main.cs | 46 ++++++++++++++++++++++++------------------- SAV/SAV_HallOfFame.cs | 16 ++++++++++++--- SAV/SAV_SecretBase.cs | 15 ++++++++++++-- SAV/SAV_Trainer.cs | 4 +++- 4 files changed, 55 insertions(+), 26 deletions(-) diff --git a/PKX/f1-Main.cs b/PKX/f1-Main.cs index a17646017..0541e7909 100644 --- a/PKX/f1-Main.cs +++ b/PKX/f1-Main.cs @@ -1027,7 +1027,7 @@ public void populateFields(PKM pk, bool focus = true) if (focus) Tab_Main.Focus(); - pkm = pk; + pkm = pk.Clone(); if (fieldsInitialized & !pkm.ChecksumValid) Util.Alert("PKX File has an invalid checksum."); switch (pkm.Format) @@ -1261,8 +1261,8 @@ private void populateFieldsPK4(PK4 pk4) TB_PP3.Text = pk4.Move3_PP.ToString(); TB_PP4.Text = pk4.Move4_PP.ToString(); - // Set Form if count is enough, else if count is more than 1 set equal to max else zero. - CB_Form.SelectedIndex = CB_Form.Items.Count > pk4.AltForm ? pk4.AltForm : (CB_Form.Items.Count > 1 ? CB_Form.Items.Count - 1 : 0); + // Set Form if count is enough, else cap. + CB_Form.SelectedIndex = CB_Form.Items.Count > pk4.AltForm ? pk4.AltForm : CB_Form.Items.Count - 1; // Load Extrabyte Value TB_ExtraByte.Text = pk4.Data[Convert.ToInt32(CB_ExtraBytes.Text, 16)].ToString(); @@ -1384,8 +1384,8 @@ private void populateFieldsPK5(PK5 pk5) TB_PP3.Text = pk5.Move3_PP.ToString(); TB_PP4.Text = pk5.Move4_PP.ToString(); - // Set Form if count is enough, else if count is more than 1 set equal to max else zero. - CB_Form.SelectedIndex = CB_Form.Items.Count > pk5.AltForm ? pk5.AltForm : (CB_Form.Items.Count > 1 ? CB_Form.Items.Count - 1 : 0); + // Set Form if count is enough, else cap. + CB_Form.SelectedIndex = CB_Form.Items.Count > pk5.AltForm ? pk5.AltForm : CB_Form.Items.Count - 1; // Load Extrabyte Value TB_ExtraByte.Text = pk5.Data[Convert.ToInt32(CB_ExtraBytes.Text, 16)].ToString(); @@ -1521,8 +1521,8 @@ private void populateFieldsPK6(PK6 pk6) TB_PP3.Text = pk6.Move3_PP.ToString(); TB_PP4.Text = pk6.Move4_PP.ToString(); - // Set Form if count is enough, else if count is more than 1 set equal to max else zero. - CB_Form.SelectedIndex = CB_Form.Items.Count > pk6.AltForm ? pk6.AltForm : (CB_Form.Items.Count > 1 ? CB_Form.Items.Count - 1 : 0); + // Set Form if count is enough, else cap. + CB_Form.SelectedIndex = CB_Form.Items.Count > pk6.AltForm ? pk6.AltForm : CB_Form.Items.Count - 1; // Load Extrabyte Value TB_ExtraByte.Text = pk6.Data[Convert.ToInt32(CB_ExtraBytes.Text, 16)].ToString(); @@ -1554,16 +1554,22 @@ internal static void setCountrySubRegion(ComboBox CB, string type) if (index > 0 && index < CB.Items.Count && fieldsInitialized) CB.SelectedIndex = index; } - internal static void setForms(int species, ComboBox cb, Label l = null) + private void setForms() { - // Form Tables - cb.DisplayMember = "Text"; - cb.ValueMember = "Value"; - bool hasForms = PKX.Personal[species].HasFormes || new[] { 664, 665, 414, }.Contains(species); - cb.Enabled = cb.Visible = hasForms; - if (l != null) l.Visible = hasForms; - - cb.DataSource = PKX.getFormList(species, types, forms, gendersymbols).ToList(); + if (SAV.Generation < 4) + { + Label_Form.Visible = CB_Form.Visible = CB_Form.Enabled = false; + return; + } + + int species = Util.getIndex(CB_Species); + bool hasForms = SAV.Personal[species].HasFormes || new[] { 664, 665, 414 }.Contains(species); + CB_Form.Enabled = CB_Form.Visible = Label_Form.Visible = hasForms; + + if (!hasForms) + return; + + CB_Form.DataSource = PKX.getFormList(species, types, forms, gendersymbols).ToList(); } private void setAbilityList() { @@ -2155,7 +2161,7 @@ private void updateSpecies(object sender, EventArgs e) if (MT_Level.Visible) Level = Util.ToInt32(MT_Level.Text); // Get Forms for Given Species - setForms(Species, CB_Form, Label_Form); + setForms(); // Recalculate EXP for Given Level uint EXP = PKX.getEXP(Level, Species); @@ -2885,7 +2891,7 @@ private PK4 preparePK4() pk4.FatefulEncounter = CHK_Fateful.Checked; pk4.Gender = PKX.getGender(Label_Gender.Text); - pk4.AltForm = (MT_Form.Enabled ? Convert.ToInt32(MT_Form.Text) : CB_Form.SelectedIndex) & 0x1F; + pk4.AltForm = (MT_Form.Enabled ? Convert.ToInt32(MT_Form.Text) : CB_Form.Enabled ? CB_Form.SelectedIndex : 0) & 0x1F; pk4.EV_HP = Util.ToInt32(TB_HPEV.Text); pk4.EV_ATK = Util.ToInt32(TB_ATKEV.Text); pk4.EV_DEF = Util.ToInt32(TB_DEFEV.Text); @@ -3001,7 +3007,7 @@ private PK5 preparePK5() pk5.Nature = (byte)Util.getIndex(CB_Nature); pk5.FatefulEncounter = CHK_Fateful.Checked; pk5.Gender = PKX.getGender(Label_Gender.Text); - pk5.AltForm = (MT_Form.Enabled ? Convert.ToInt32(MT_Form.Text) : CB_Form.SelectedIndex) & 0x1F; + pk5.AltForm = (MT_Form.Enabled ? Convert.ToInt32(MT_Form.Text) : CB_Form.Enabled ? CB_Form.SelectedIndex : 0) & 0x1F; pk5.EV_HP = Util.ToInt32(TB_HPEV.Text); pk5.EV_ATK = Util.ToInt32(TB_ATKEV.Text); pk5.EV_DEF = Util.ToInt32(TB_DEFEV.Text); @@ -3145,7 +3151,7 @@ private PK6 preparePK6() pk6.Nature = (byte)Util.getIndex(CB_Nature); pk6.FatefulEncounter = CHK_Fateful.Checked; pk6.Gender = PKX.getGender(Label_Gender.Text); - pk6.AltForm = (MT_Form.Enabled ? Convert.ToInt32(MT_Form.Text) : CB_Form.SelectedIndex) & 0x1F; // Form + pk6.AltForm = (MT_Form.Enabled ? Convert.ToInt32(MT_Form.Text) : CB_Form.Enabled ? CB_Form.SelectedIndex : 0) & 0x1F; pk6.EV_HP = Util.ToInt32(TB_HPEV.Text); // EVs pk6.EV_ATK = Util.ToInt32(TB_ATKEV.Text); pk6.EV_DEF = Util.ToInt32(TB_DEFEV.Text); diff --git a/SAV/SAV_HallOfFame.cs b/SAV/SAV_HallOfFame.cs index 5a676bf22..ea81bcde4 100644 --- a/SAV/SAV_HallOfFame.cs +++ b/SAV/SAV_HallOfFame.cs @@ -231,7 +231,7 @@ private void NUP_PartyIndex_ValueChanged(object sender, EventArgs e) CHK_Nicknamed.Checked = nick == 1; - Main.setForms(species, CB_Form); + setForms(); CB_Form.SelectedIndex = (int)form; setGenderLabel((int)gender); updateNickname(sender, e); @@ -359,10 +359,20 @@ private void updateNickname(object sender, EventArgs e) Write_Entry(null, null); } - private void updateSpecies(object sender, EventArgs e) + + private void setForms() { int species = Util.getIndex(CB_Species); - Main.setForms(species, CB_Form); + bool hasForms = Legal.PersonalAO[species].HasFormes || new[] { 664, 665, 414 }.Contains(species); + CB_Form.Enabled = CB_Form.Visible = hasForms; + + CB_Form.DisplayMember = "Text"; + CB_Form.ValueMember = "Value"; + CB_Form.DataSource = PKX.getFormList(species, Main.types, Main.forms, Main.gendersymbols).ToList(); + } + private void updateSpecies(object sender, EventArgs e) + { + setForms(); updateNickname(null, null); } private void updateShiny(object sender, EventArgs e) diff --git a/SAV/SAV_SecretBase.cs b/SAV/SAV_SecretBase.cs index cdf3f90e0..f1a0f5ba4 100644 --- a/SAV/SAV_SecretBase.cs +++ b/SAV/SAV_SecretBase.cs @@ -398,7 +398,7 @@ private void loadFavPKM() CHK_Shiny.Checked = isshiny; // Set Form - Main.setForms(spec, CB_Form); + setForms(); int form = genform >> 3; CB_Form.SelectedIndex = form; @@ -425,10 +425,21 @@ private void setAbilityList() CB_Ability.SelectedIndex = newabil < 3 ? newabil : 0; } + private void setForms() + { + int species = Util.getIndex(CB_Species); + bool hasForms = Legal.PersonalAO[species].HasFormes || new[] { 664, 665, 414 }.Contains(species); + CB_Form.Enabled = CB_Form.Visible = hasForms; + + CB_Form.DisplayMember = "Text"; + CB_Form.ValueMember = "Value"; + CB_Form.DataSource = PKX.getFormList(species, Main.types, Main.forms, Main.gendersymbols).ToList(); + } + private void updateSpecies(object sender, EventArgs e) { // Get Forms for Given Species - Main.setForms(Util.getIndex(CB_Species), CB_Form); + setForms(); // Check for Gender Changes // Get Gender Threshold diff --git a/SAV/SAV_Trainer.cs b/SAV/SAV_Trainer.cs index a89cb3253..fbf2da068 100644 --- a/SAV/SAV_Trainer.cs +++ b/SAV/SAV_Trainer.cs @@ -327,7 +327,9 @@ private void getComboBoxes() CB_MultiplayerSprite.DataSource = oras_sprite_list; L_Vivillon.Text = Main.specieslist[666] + ":"; - Main.setForms(666, CB_Vivillon); + CB_Vivillon.DisplayMember = "Text"; + CB_Vivillon.ValueMember = "Value"; + CB_Vivillon.DataSource = PKX.getFormList(666, Main.types, Main.forms, Main.gendersymbols).ToList(); } private void getBadges() { From 053657c3be4cb1ed01af4d13d09014f67dbafca0 Mon Sep 17 00:00:00 2001 From: Kaphotics Date: Wed, 29 Jun 2016 22:59:20 -0700 Subject: [PATCH 44/49] Error check on invalid legality Check fails -> flag instead of error. --- Legality/Analysis.cs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Legality/Analysis.cs b/Legality/Analysis.cs index 940284439..04695106b 100644 --- a/Legality/Analysis.cs +++ b/Legality/Analysis.cs @@ -26,10 +26,14 @@ public LegalityAnalysis(PKM pk) if (!(pk is PK6)) return; pk6 = pk as PK6; - updateRelearnLegality(); - updateMoveLegality(); - updateChecks(); - getLegalityReport(); + try + { + updateRelearnLegality(); + updateMoveLegality(); + updateChecks(); + getLegalityReport(); + } + catch { Valid = false; } } public void updateRelearnLegality() @@ -109,7 +113,7 @@ private string getVerboseLegalityReport() r += Environment.NewLine; var chks = Checks; - r += chks.Where(chk => chk.Valid && chk.Comment != "Valid").OrderBy(chk => chk.Judgement) // Fishy sorted to top + r += chks.Where(chk => chk != null && chk.Valid && chk.Comment != "Valid").OrderBy(chk => chk.Judgement) // Fishy sorted to top .Aggregate("", (current, chk) => current + $"{chk.Judgement}: {chk.Comment}{Environment.NewLine}"); return r.TrimEnd(); } From 08ccec7a07ed367c928fb340d18a2162756d3751 Mon Sep 17 00:00:00 2001 From: Kaphotics Date: Thu, 30 Jun 2016 18:10:09 -0700 Subject: [PATCH 45/49] Fix pk3 sprite helditem fetch g3item is raw value (gen 3 index), HeldItem returns the equivalent gen4 item. In the future the populatefields(PK3) method will use the gen3 index (list needs to be init first) but the display is always the helditem. --- PKM/PK3.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PKM/PK3.cs b/PKM/PK3.cs index 7594f9127..ca3a575ae 100644 --- a/PKM/PK3.cs +++ b/PKM/PK3.cs @@ -61,7 +61,7 @@ public PK3(byte[] decryptedData = null, string ident = null) #region Block A public override int Species { get { return PKX.getG4Species(BitConverter.ToUInt16(Data, 0x20)); } set { BitConverter.GetBytes((ushort)PKX.getG3Species(value)).CopyTo(Data, 0x20); } } public override int HeldItem { get { return PKX.getG4Item((ushort)G3Item); } set { } } - public int G3Item { get { return PKX.getG4Item(BitConverter.ToUInt16(Data, 0x22)); } set { BitConverter.GetBytes((ushort) value).CopyTo(Data, 0x22); } } + public int G3Item { get { return BitConverter.ToUInt16(Data, 0x22); } set { BitConverter.GetBytes((ushort) value).CopyTo(Data, 0x22); } } public override uint EXP { get { return BitConverter.ToUInt32(Data, 0x24); } set { BitConverter.GetBytes(value).CopyTo(Data, 0x24); } } private byte PPUps { get { return Data[0x28]; } set { Data[0x28] = value; } } From 537246d4b9d3426e9148aa7e1790bd863ddb74f9 Mon Sep 17 00:00:00 2001 From: Kaphotics Date: Thu, 30 Jun 2016 21:53:24 -0700 Subject: [PATCH 46/49] Add SAV3 inventory code Still need to figure out how I want to handle the different-index item numbers. --- SAV/SAV_Inventory.cs | 22 ++++++++++++++++-- Saves/Inventory.cs | 3 ++- Saves/SAV3.cs | 55 +++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 74 insertions(+), 6 deletions(-) diff --git a/SAV/SAV_Inventory.cs b/SAV/SAV_Inventory.cs index 26a524392..63cf17f44 100644 --- a/SAV/SAV_Inventory.cs +++ b/SAV/SAV_Inventory.cs @@ -203,9 +203,27 @@ private void B_GiveAll_Click(object sender, EventArgs e) int Count = ModifierKeys == Keys.Control ? 1 : Pouches[pouch].MaxCount; for (int i = 0; i < legalitems.Length; i++) { - string itemname = Main.itemlist[legalitems[i]]; + int item = legalitems[i]; + string itemname; + int c = Count; + + // Override for HMs + switch (SAV.Generation) + { + case 3: { + itemname = Main.itemlist[item]; + if (Legal.Pouch_HM_RS.Contains(legalitems[i])) c = 1; + break; + } + default: { + itemname = Main.itemlist[item]; + if (new[] { 420, 421, 422, 423, 423, 424, 425, 426, 427, 737 }.Contains(legalitems[i])) c = 1; + break; + } + } + dgv.Rows[i].Cells[0].Value = itemname; - dgv.Rows[i].Cells[1].Value = Count; + dgv.Rows[i].Cells[1].Value = c; } System.Media.SystemSounds.Asterisk.Play(); } diff --git a/Saves/Inventory.cs b/Saves/Inventory.cs index dee6e3a56..f02fb109f 100644 --- a/Saves/Inventory.cs +++ b/Saves/Inventory.cs @@ -25,6 +25,7 @@ public class InventoryPouch public readonly int MaxCount; private readonly int Offset; private readonly int PouchDataSize; + public uint SecurityKey { private get; set; } // = 0 // Gen3 Only public InventoryItem[] Items; public InventoryPouch(InventoryType type, ushort[] legal, int maxcount, int offset, int size = -1) @@ -44,7 +45,7 @@ public void getPouch(ref byte[] Data) items[i] = new InventoryItem { Index = BitConverter.ToUInt16(Data, Offset + i*4), - Count = BitConverter.ToUInt16(Data, Offset + i*4 + 2) + Count = BitConverter.ToUInt16(Data, Offset + i*4 + 2) ^ (ushort)SecurityKey }; } Items = items; diff --git a/Saves/SAV3.cs b/Saves/SAV3.cs index 371c1449a..41e736812 100644 --- a/Saves/SAV3.cs +++ b/Saves/SAV3.cs @@ -73,6 +73,38 @@ public SAV3(byte[] data = null, GameVersion versionOverride = GameVersion.Any) Array.Copy(Data, blockIndex * 0x1000 + ABO, Data, Box + (i - 5)*0xF80, chunkLength[i]); } + switch (Version) + { + case GameVersion.RS: + LegalKeyItems = Legal.Pouch_Key_RS; + OFS_PouchHeldItem = Party + 0x0560; + OFS_PouchKeyItem = Party + 0x05B0; + OFS_PouchBalls = Party + 0x0600; + OFS_PouchTMHM = Party + 0x0640; + OFS_PouchBerry = Party + 0x0740; + break; + case GameVersion.FRLG: + LegalKeyItems = Legal.Pouch_Key_FRLG; + OFS_PouchHeldItem = Party + 0x0310; + OFS_PouchKeyItem = Party + 0x03B8; + OFS_PouchBalls = Party + 0x0430; + OFS_PouchTMHM = Party + 0x0464; + OFS_PouchBerry = Party + 0x054C; + break; + case GameVersion.E: + LegalKeyItems = Legal.Pouch_Key_E; + OFS_PouchHeldItem = Party + 0x0560; + OFS_PouchKeyItem = Party + 0x05D8; + OFS_PouchBalls = Party + 0x0650; + OFS_PouchTMHM = Party + 0x0690; + OFS_PouchBerry = Party + 0x0790; + break; + } + LegalItems = Legal.Pouch_Items_RS; + LegalBalls = Legal.Pouch_Ball_RS; + LegalTMHMs = Legal.Pouch_TMHM_RS; + LegalBerries = Legal.Pouch_Berries_RS; + HeldItems = Legal.HeldItems_RS; Personal = Legal.PersonalAO; // todo @@ -270,14 +302,31 @@ public int BP set { Data[Trainer1 + 0xEB8] = (byte)value; } } + private readonly ushort[] LegalItems, LegalKeyItems, LegalBalls, LegalTMHMs, LegalBerries; public override InventoryPouch[] Inventory { get { - return null; - + InventoryPouch[] pouch = + { + new InventoryPouch(InventoryType.Items, LegalItems, 95, OFS_PouchHeldItem, (OFS_PouchKeyItem - OFS_PouchHeldItem)/4), + new InventoryPouch(InventoryType.KeyItems, LegalKeyItems, 1, OFS_PouchKeyItem, (OFS_PouchBalls - OFS_PouchKeyItem)/4), + new InventoryPouch(InventoryType.Balls, LegalBalls, 95, OFS_PouchBalls, (OFS_PouchTMHM - OFS_PouchBalls)/4), + new InventoryPouch(InventoryType.TMHMs, LegalTMHMs, 95, OFS_PouchTMHM, (OFS_PouchBerry - OFS_PouchTMHM)/4), + new InventoryPouch(InventoryType.Berries, LegalBerries, 95, OFS_PouchBerry, Version == GameVersion.FRLG ? 43 : 46), + }; + foreach (var p in pouch) + { + p.SecurityKey = SecurityKey; + p.getPouch(ref Data); + } + return pouch; + } + set + { + foreach (var p in value) + p.setPouch(ref Data); } - set { } } public override int getDaycareSlotOffset(int loc, int slot) From 67e7d3edaf22c14f5d78403313a67dba5748c8ed Mon Sep 17 00:00:00 2001 From: Kaphotics Date: Thu, 30 Jun 2016 22:36:54 -0700 Subject: [PATCH 47/49] Simplify control finding for translation Figured I'd rewrite this to remove the gotos --- Misc/Util.cs | 106 ++++++++++++++++++++++++++++----------------------- 1 file changed, 58 insertions(+), 48 deletions(-) diff --git a/Misc/Util.cs b/Misc/Util.cs index f2fb81b6f..04d52df11 100644 --- a/Misc/Util.cs +++ b/Misc/Util.cs @@ -237,64 +237,74 @@ internal static void TranslateInterface(Control form, string lang) rawlist = rawlist.Select(i => i.Trim()).ToArray(); // Remove trailing spaces } - string[] stringdata = new string[rawlist.Length]; - int itemsToRename = 0; + List stringdata = new List(); + int start = -1; for (int i = 0; i < rawlist.Length; i++) { // Find our starting point if (!rawlist[i].Contains("! " + form.Name)) continue; - - // Allow renaming of the Window Title - string[] WindowName = rawlist[i].Split(new[] {" = "}, StringSplitOptions.None); - if (WindowName.Length > 1) form.Text = WindowName[1]; - // Copy our Control Names and Text to a new array for later processing. - for (int j = i + 1; j < rawlist.Length; j++) - { - if (rawlist[j].Length == 0) continue; // Skip Over Empty Lines, errhandled - if (rawlist[j][0] == '-') continue; // Keep translating if line is a comment line - if (rawlist[j][0] == '!') // Stop if we have reached the end of translation - goto rename; - stringdata[itemsToRename] = rawlist[j]; // Add the entry to process later. - itemsToRename++; - } + start = i; + break; } - return; // Not Found - - // Now that we have our items to rename in: Control = Text format, let's execute the changes! - rename: - for (int i = 0; i < itemsToRename; i++) - { - string[] SplitString = stringdata[i].Split(new[] {" = "}, StringSplitOptions.None); - if (SplitString.Length < 2) - continue; // Error in Input, errhandled - string ctrl = SplitString[0]; // Control to change the text of... - string text = SplitString[1]; // Text to set Control.Text to... - Control[] controllist = form.Controls.Find(ctrl, true); - if (controllist.Length != 0) // If Control is found - { controllist[0].Text = text; goto next; } + if (start < 0) + return; + + // Rename Window Title + string[] WindowName = rawlist[start].Split(new[] {" = "}, StringSplitOptions.None); + if (WindowName.Length > 1) form.Text = WindowName[1]; - // Check MenuStrips - foreach (MenuStrip menu in form.Controls.OfType()) - { - // Menu Items aren't in the Form's Control array. Find within the menu's Control array. - ToolStripItem[] TSI = menu.Items.Find(ctrl, true); - if (TSI.Length <= 0) continue; - - TSI[0].Text = text; goto next; - } - // Check ContextMenuStrips - foreach (ContextMenuStrip cs in FindContextMenuStrips(form.Controls.OfType()).Distinct()) - { - ToolStripItem[] TSI = cs.Items.Find(ctrl, true); - if (TSI.Length <= 0) continue; + // Fetch controls to rename + for (int i = start + 1; i < rawlist.Length; i++) + { + if (rawlist[i].Length == 0) continue; // Skip Over Empty Lines, errhandled + if (rawlist[i][0] == '-') continue; // Keep translating if line is a comment line + if (rawlist[i][0] == '!') // Stop if we have reached the end of translation + break; + stringdata.Add(rawlist[i]); // Add the entry to process later. + } - TSI[0].Text = text; goto next; - } + if (stringdata.Count == 0) + return; - next:; + // Find control then change display Text. + foreach (string str in stringdata) + { + string[] SplitString = str.Split(new[] {" = "}, StringSplitOptions.None); + if (SplitString.Length < 2) + continue; + + object c = FindControl(SplitString[0], form.Controls); // Find control within Form's controls + if (c == null) // Not found + continue; + + string text = SplitString[1]; // Text to set Control.Text to... + + if (c is Control) + (c as Control).Text = text; + else if (c is ToolStripItem) + (c as ToolStripItem).Text = text; } } - internal static List FindContextMenuStrips(IEnumerable c) + private static object FindControl(string name, Control.ControlCollection c) + { + Control control = c.Find(name, true).FirstOrDefault(); + if (control != null) + return control; + foreach (MenuStrip menu in c.OfType()) + { + var item = menu.Items.Find(name, true).FirstOrDefault(); + if (item != null) + return item; + } + foreach (ContextMenuStrip strip in FindContextMenuStrips(c.OfType())) + { + var item = strip.Items.Find(name, true).FirstOrDefault(); + if (item != null) + return item; + } + return null; + } + private static List FindContextMenuStrips(IEnumerable c) { List cs = new List(); foreach (Control control in c) From 418f1c772d18c3c8a2648e2ca3aeaebf98dffa71 Mon Sep 17 00:00:00 2001 From: Kaphotics Date: Fri, 1 Jul 2016 17:06:45 -0700 Subject: [PATCH 48/49] Fix gen3 pouch set --- Saves/Inventory.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Saves/Inventory.cs b/Saves/Inventory.cs index f02fb109f..05e1218ff 100644 --- a/Saves/Inventory.cs +++ b/Saves/Inventory.cs @@ -58,7 +58,7 @@ public void setPouch(ref byte[] Data) for (int i = 0; i < Items.Length; i++) { BitConverter.GetBytes((ushort)Items[i].Index).CopyTo(Data, Offset + i*4); - BitConverter.GetBytes((ushort)Items[i].Count).CopyTo(Data, Offset + i*4 + 2); + BitConverter.GetBytes((ushort)Items[i].Count ^ (ushort)SecurityKey).CopyTo(Data, Offset + i*4 + 2); } } } From c129c0d663bf8278e37580b98f7bf3aacaa397b2 Mon Sep 17 00:00:00 2001 From: Kaphotics Date: Fri, 1 Jul 2016 21:21:15 -0700 Subject: [PATCH 49/49] Fix cast should have been included in the previous commit --- Saves/Inventory.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Saves/Inventory.cs b/Saves/Inventory.cs index 05e1218ff..036bb9e39 100644 --- a/Saves/Inventory.cs +++ b/Saves/Inventory.cs @@ -58,7 +58,7 @@ public void setPouch(ref byte[] Data) for (int i = 0; i < Items.Length; i++) { BitConverter.GetBytes((ushort)Items[i].Index).CopyTo(Data, Offset + i*4); - BitConverter.GetBytes((ushort)Items[i].Count ^ (ushort)SecurityKey).CopyTo(Data, Offset + i*4 + 2); + BitConverter.GetBytes((ushort)((ushort)Items[i].Count ^ (ushort)SecurityKey)).CopyTo(Data, Offset + i*4 + 2); } } }