From b8a5657d5a33d12fd1686f32b95b5f3dc4507184 Mon Sep 17 00:00:00 2001 From: Kurt Date: Wed, 22 Nov 2017 21:45:30 -0800 Subject: [PATCH] misc tweaks pull out transfer locations to const references add vc2 & crown beast/celebi met location suggesting add vc2 crystal sensitive detection add 2 more usum trainer stats (thanks holla!) --- PKHeX.Core/Game/GameInfo.cs | 10 ++++---- PKHeX.Core/Legality/Checks.cs | 8 +++--- .../Legality/Encounters/EncounterGenerator.cs | 4 +-- .../Encounters/EncounterSuggestion.cs | 25 +++++++++++-------- .../Legality/Structures/EvolutionTree.cs | 16 ++++++------ PKHeX.Core/Legality/Tables1.cs | 4 +++ PKHeX.Core/Legality/Tables2.cs | 6 ++++- PKHeX.Core/Legality/Tables3.cs | 4 +++ PKHeX.Core/Legality/Tables4.cs | 14 ++++++++--- PKHeX.Core/PKM/PK1.cs | 5 ++-- PKHeX.Core/PKM/PK2.cs | 6 ++--- PKHeX.Core/PKM/PK3.cs | 2 +- PKHeX.Core/PKM/PK4.cs | 4 +-- PKHeX.Core/Util/DataUtil.cs | 2 +- .../Controls/PKM Editor/PKMEditor.cs | 8 +++--- .../Save Editors/Gen7/SAV_Trainer7.cs | 2 ++ 16 files changed, 73 insertions(+), 47 deletions(-) diff --git a/PKHeX.Core/Game/GameInfo.cs b/PKHeX.Core/Game/GameInfo.cs index cbdc27f27..ad17038f9 100644 --- a/PKHeX.Core/Game/GameInfo.cs +++ b/PKHeX.Core/Game/GameInfo.cs @@ -386,7 +386,7 @@ public static void InitializeDataSources(GameStrings s) #endregion } - public static void SetItemDataSource(bool HaX, int MaxItemID, IEnumerable allowed, int generation, GameVersion game, GameStrings s) + public static void SetItemDataSource(int MaxItemID, IEnumerable allowed, int generation, GameVersion game, GameStrings s, bool HaX = false) { string[] items = s.GetItemStrings(generation, game); ItemDataSource = Util.GetCBList(items, (allowed == null || HaX ? Enumerable.Range(0, MaxItemID) : allowed.Select(i => (int) i)).ToArray()); @@ -478,14 +478,14 @@ public static List GetLocationList(GameVersion Version, int SaveForma // Currently on a future game, return corresponding list for generation if (Version <= GameVersion.CXD && SaveFormat == 4) - return MetGen4.Where(loc => loc.Value == 0x37) // Pal Park to front + return MetGen4.Where(loc => loc.Value == Legal.Transfer3) // Pal Park to front .Concat(MetGen4.Take(4)) - .Concat(MetGen4.Skip(4).Where(loc => loc.Value != 0x37)).ToList(); + .Concat(MetGen4.Skip(4).Where(loc => loc.Value != Legal.Transfer3)).ToList(); if (Version < GameVersion.X && SaveFormat >= 5) // PokéTransfer to front - return MetGen5.Where(loc => loc.Value == 30001) + return MetGen5.Where(loc => loc.Value == Legal.Transfer4) .Concat(MetGen5.Take(3)) - .Concat(MetGen5.Skip(3).Where(loc => loc.Value != 30001)).ToList(); + .Concat(MetGen5.Skip(3).Where(loc => loc.Value != Legal.Transfer4)).ToList(); return MetGen6; } diff --git a/PKHeX.Core/Legality/Checks.cs b/PKHeX.Core/Legality/Checks.cs index 29dcefda8..0592d62a5 100644 --- a/PKHeX.Core/Legality/Checks.cs +++ b/PKHeX.Core/Legality/Checks.cs @@ -732,9 +732,9 @@ private void VerifyEncounterType() private void VerifyTransferLegalityG3() { - if (pkm.Format == 4 && pkm.Met_Location != 0x37) // Pal Park + if (pkm.Format == 4 && pkm.Met_Location != Legal.Transfer3) // Pal Park AddLine(Severity.Invalid, V60, CheckIdentifier.Encounter); - if (pkm.Format != 4 && pkm.Met_Location != 30001) + if (pkm.Format != 4 && pkm.Met_Location != Legal.Transfer4) AddLine(Severity.Invalid, V61, CheckIdentifier.Encounter); } private void VerifyTransferLegalityG4() @@ -747,13 +747,13 @@ private void VerifyTransferLegalityG4() switch (pkm.Species) { case 251: // Celebi - if (loc != 30010 && loc != 30011) // unused || used + if (loc != Legal.Transfer4_CelebiUnused && loc != Legal.Transfer4_CelebiUsed) AddLine(Severity.Invalid, V351, CheckIdentifier.Encounter); break; case 243: // Raikou case 244: // Entei case 245: // Suicune - if (loc != 30012 && loc != 30013) // unused || used + if (loc != Legal.Transfer4_CrownUnused && loc != Legal.Transfer4_CrownUsed) AddLine(Severity.Invalid, V351, CheckIdentifier.Encounter); break; default: diff --git a/PKHeX.Core/Legality/Encounters/EncounterGenerator.cs b/PKHeX.Core/Legality/Encounters/EncounterGenerator.cs index 7f1d07cdc..7302f9681 100644 --- a/PKHeX.Core/Legality/Encounters/EncounterGenerator.cs +++ b/PKHeX.Core/Legality/Encounters/EncounterGenerator.cs @@ -1507,7 +1507,7 @@ private static EncounterStatic GetRBYStaticTransfer(int species, int pkmMetLevel Ability = TransferSpeciesDefaultAbility_1.Contains(species) ? 1 : 4, // Hidden by default, else first Shiny = species == 151 ? (bool?)false : null, Fateful = species == 151, - Location = 30013, + Location = Transfer1, EggLocation = 0, IV3 = true, Level = pkmMetLevel, @@ -1523,7 +1523,7 @@ private static EncounterStatic GetGSStaticTransfer(int species, int pkmMetLevel) Ability = TransferSpeciesDefaultAbility_2.Contains(species) ? 1 : 4, // Hidden by default, else first Shiny = species == 151 || species == 251 ? (bool?)false : null, Fateful = species == 151 || species == 251, - Location = 30017, + Location = Transfer2, EggLocation = 0, IV3 = true, Level = pkmMetLevel, diff --git a/PKHeX.Core/Legality/Encounters/EncounterSuggestion.cs b/PKHeX.Core/Legality/Encounters/EncounterSuggestion.cs index a05525a6e..4721f606c 100644 --- a/PKHeX.Core/Legality/Encounters/EncounterSuggestion.cs +++ b/PKHeX.Core/Legality/Encounters/EncounterSuggestion.cs @@ -83,18 +83,18 @@ public static int GetSuggestedEggMetLocation(PKM pkm) case 3: return pkm.FRLG ? 146 /* Four Island */ : 32; // Route 117 case 4: - return 0x37; // Pal Park + return Legal.Transfer3; // Pal Park default: - return 30001; // Transporter + return Legal.Transfer4; // Transporter } case GameVersion.D: case GameVersion.P: case GameVersion.Pt: - return pkm.Format > 4 ? 30001 /* Transporter */ : 4; // Solaceon Town + return pkm.Format > 4 ? Legal.Transfer4 /* Transporter */ : 4; // Solaceon Town case GameVersion.HG: case GameVersion.SS: - return pkm.Format > 4 ? 30001 /* Transporter */ : 182; // Route 34 + return pkm.Format > 4 ? Legal.Transfer4 /* Transporter */ : 182; // Route 34 case GameVersion.B: case GameVersion.W: @@ -118,22 +118,27 @@ public static int GetSuggestedEggMetLocation(PKM pkm) return -1; } /// - /// Gets the correct Met location for the origin game. + /// Gets the correct Transfer Met location for the origin game. /// /// /// Returns -1 if the met location is not overriden with a transfer location /// private static int GetSuggestedTransferLocation(PKM pkm) { - // Return one of legal hatch locations for game if (pkm.HasOriginalMetLocation) return -1; if (pkm.VC1) - return 30013; + return Legal.Transfer1; + if (pkm.VC2) + return Legal.Transfer2; if (pkm.Format == 4) // Pal Park - return 0x37; - if (pkm.Format == 5) // Transporter - return 30001; + return Legal.Transfer3; + if (pkm.Format >= 5) // Transporter + { + return pkm.Gen4 && pkm.FatefulEncounter && Legal.CrownBeasts.Contains(pkm.Species) + ? (pkm.Species == 251 ? Legal.Transfer4_CelebiUnused : Legal.Transfer4_CrownUnused) // Celebi : Beast + : Legal.Transfer4; // Pokétransfer (not Crown) + } return -1; } } diff --git a/PKHeX.Core/Legality/Structures/EvolutionTree.cs b/PKHeX.Core/Legality/Structures/EvolutionTree.cs index ff21f4a33..56006f00a 100644 --- a/PKHeX.Core/Legality/Structures/EvolutionTree.cs +++ b/PKHeX.Core/Legality/Structures/EvolutionTree.cs @@ -407,21 +407,23 @@ private static EvolutionMethod GetMethod(byte[] data, int offset) public static List GetArray(byte[] data) { var evos = new List(); - for (int i = 0; i <= Legal.MaxSpeciesIndex_4_HGSSPt; i++) + const int bpe = 6; // bytes per evolution entry + const int entries = 7; // 7 * 6 = 42, + 2 alignment bytes + const int size = 44; // bytes per species entry + + int count = data.Length / size; + for (int i = 0; i < count; i++) { - /* 44 bytes per species, - * for every species 7 evolutions with 6 bytes per evolution, - * last 2 bytes of every specie is padding*/ - int offset = i * 44; + int offset = i * size; var m_list = new List(); - for (int j = 0; j < 7; j++) + for (int j = 0; j < entries; j++) { EvolutionMethod m = GetMethod(data, offset); if (m != null) m_list.Add(m); else break; - offset += 6; + offset += bpe; } evos.Add(new EvolutionSet4 { PossibleEvolutions = m_list.ToArray() }); } diff --git a/PKHeX.Core/Legality/Tables1.cs b/PKHeX.Core/Legality/Tables1.cs index 90370b04a..cd14a32ba 100644 --- a/PKHeX.Core/Legality/Tables1.cs +++ b/PKHeX.Core/Legality/Tables1.cs @@ -9,6 +9,10 @@ public static partial class Legal internal const int MaxMoveID_1 = 165; internal const int MaxItemID_1 = 255; internal const int MaxAbilityID_1 = 0; + /// + /// Generation 1 -> Generation 7 Transfer Location (Kanto) + /// + public const int Transfer1 = 30013; internal static readonly ushort[] Pouch_Items_RBY = { diff --git a/PKHeX.Core/Legality/Tables2.cs b/PKHeX.Core/Legality/Tables2.cs index 0c21014e9..7748b5c16 100644 --- a/PKHeX.Core/Legality/Tables2.cs +++ b/PKHeX.Core/Legality/Tables2.cs @@ -9,7 +9,11 @@ public static partial class Legal internal const int MaxMoveID_2 = 251; internal const int MaxItemID_2 = 255; internal const int MaxAbilityID_2 = 0; - + /// + /// Generation 2 -> Generation 7 Transfer Location (Johto) + /// + public const int Transfer2 = 30017; + internal static readonly ushort[] Pouch_Items_GSC = { 3, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 46, 47, 48, 49, 51, 52, 53, 57, 60, 62, 63, 64, 65, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 91, 92, 93, 94, 95, 96, 97, 98, 99, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 117, 118, 119, 121, 122, 123, 124, 125, 126, 131, 132, 138, 139, 140, 143, 144, 146, 150, 151, 152, 156, 158, 163, 167, 168, 169, 170, 172, 173, 174, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189 }; diff --git a/PKHeX.Core/Legality/Tables3.cs b/PKHeX.Core/Legality/Tables3.cs index 8aa6a15b5..b5c19f238 100644 --- a/PKHeX.Core/Legality/Tables3.cs +++ b/PKHeX.Core/Legality/Tables3.cs @@ -11,6 +11,10 @@ public static partial class Legal internal const int MaxItemID_3 = 374; internal const int MaxAbilityID_3 = 77; internal const int MaxBallID_3 = 0xC; + /// + /// Generation 3 -> Generation 4 Transfer Location (Pal Park) + /// + public const int Transfer3 = 0x37; public static readonly HashSet SplitBreed_3 = new HashSet { diff --git a/PKHeX.Core/Legality/Tables4.cs b/PKHeX.Core/Legality/Tables4.cs index e4270b61c..7405554f1 100644 --- a/PKHeX.Core/Legality/Tables4.cs +++ b/PKHeX.Core/Legality/Tables4.cs @@ -5,8 +5,6 @@ namespace PKHeX.Core { public static partial class Legal { - internal const int MaxSpeciesIndex_4_DP = 500; - internal const int MaxSpeciesIndex_4_HGSSPt = 507; internal const int MaxSpeciesID_4 = 493; internal const int MaxMoveID_4 = 467; internal const int MaxItemID_4_DP = 464; @@ -14,6 +12,16 @@ public static partial class Legal internal const int MaxItemID_4_HGSS = 536; internal const int MaxAbilityID_4 = 123; internal const int MaxBallID_4 = 0x18; + /// Generation 4 -> Generation 5 Transfer Location (Poké Transporter) + public const int Transfer4 = 30001; + /// Generation 4 -> Generation 5 Transfer Location (Crown Celebi - Event not activated in Gen 5) + public const int Transfer4_CelebiUnused = 30010; + /// Generation 4 -> Generation 5 Transfer Location (Crown Celebi - Event activated in Gen 5) + public const int Transfer4_CelebiUsed = 30011; + /// Generation 4 -> Generation 5 Transfer Location (Crown Beast - Event not activated in Gen 5) + public const int Transfer4_CrownUnused = 30012; + /// Generation 4 -> Generation 5 Transfer Location (Crown Beast - Event activated in Gen 5) + public const int Transfer4_CrownUsed = 30013; internal static readonly int[] Met_HGSS_0 = { @@ -178,7 +186,7 @@ public static partial class Legal 500, // Park Ball }; internal static readonly bool[] ReleasedHeldItems_4 = Enumerable.Range(0, MaxItemID_4_HGSS+1).Select(i => HeldItems_HGSS.Contains((ushort)i) && !UnreleasedItems_4.Contains(i)).ToArray(); - internal static readonly HashSet CrownBeasts = new HashSet { 251, 243, 244, 245}; + internal static readonly HashSet CrownBeasts = new HashSet { 251, 243, 244, 245 }; internal static readonly int[] Tutors_4 = { diff --git a/PKHeX.Core/PKM/PK1.cs b/PKHeX.Core/PKM/PK1.cs index c1e12d30a..835678d60 100644 --- a/PKHeX.Core/PKM/PK1.cs +++ b/PKHeX.Core/PKM/PK1.cs @@ -381,7 +381,7 @@ public PK7 ConvertToPK7() PID = Util.Rand32(), Ball = 4, MetDate = DateTime.Now, - Version = (int)GameVersion.RD, // Default to red, for now? + Version = (int)GameVersion.RD, // Default to red Move1 = Move1, Move2 = Move2, Move3 = Move3, @@ -394,7 +394,7 @@ public PK7 ConvertToPK7() Move2_PP = Move2_PP, Move3_PP = Move3_PP, Move4_PP = Move4_PP, - Met_Location = 30013, // "Kanto region", hardcoded. + Met_Location = Legal.Transfer1, // "Kanto region", hardcoded. Gender = Gender, OT_Name = StringConverter.GetG1ConvertedString(otname, Japanese), IsNicknamed = false, @@ -425,7 +425,6 @@ public PK7 ConvertToPK7() Util.Shuffle(new_ivs); pk7.IVs = new_ivs; - // Really? :( if (IsShiny) pk7.SetShinyPID(); diff --git a/PKHeX.Core/PKM/PK2.cs b/PKHeX.Core/PKM/PK2.cs index 0ede78569..afe1a9516 100644 --- a/PKHeX.Core/PKM/PK2.cs +++ b/PKHeX.Core/PKM/PK2.cs @@ -64,8 +64,6 @@ public PK2(byte[] decryptedData = null, string ident = null, bool jp = false) int strLen = jp ? STRLEN_J : STRLEN_U; otname = Enumerable.Repeat((byte) 0x50, strLen).ToArray(); nick = Enumerable.Repeat((byte) 0x50, strLen).ToArray(); - - IsEgg = false; // Egg data stored in Pokemon List. } public override PKM Clone() @@ -413,7 +411,7 @@ public PK7 ConvertToPK7() PID = Util.Rand32(), Ball = 4, MetDate = DateTime.Now, - Version = (int)GameVersion.SV, + Version = Met_Location != 0 ? (int)GameVersion.C : (int)GameVersion.SV, Move1 = Move1, Move2 = Move2, Move3 = Move3, @@ -458,7 +456,6 @@ public PK7 ConvertToPK7() Util.Shuffle(new_ivs); pk7.IVs = new_ivs; - // Really? :( if (IsShiny) pk7.SetShinyPID(); @@ -477,6 +474,7 @@ public PK7 ConvertToPK7() } pk7.OT_Name = Korean ? OT_Name : StringConverter.GetG1ConvertedString(otname, Japanese); + pk7.OT_Gender = OT_Gender; // Crystal pk7.TradeMemory(Bank: true); // oh no, memories on gen7 pkm diff --git a/PKHeX.Core/PKM/PK3.cs b/PKHeX.Core/PKM/PK3.cs index 1d36c522e..e0af2509f 100644 --- a/PKHeX.Core/PKM/PK3.cs +++ b/PKHeX.Core/PKM/PK3.cs @@ -226,7 +226,7 @@ public PK4 ConvertToPK4() PKRS_Days = PKRS_Days, OT_Gender = OT_Gender, MetDate = moment, - Met_Location = 0x37, // Pal Park + Met_Location = Legal.Transfer3, // Pal Park RibbonChampionG3Hoenn = RibbonChampionG3Hoenn, RibbonWinning = RibbonWinning, diff --git a/PKHeX.Core/PKM/PK4.cs b/PKHeX.Core/PKM/PK4.cs index a2056d7eb..c20132d23 100644 --- a/PKHeX.Core/PKM/PK4.cs +++ b/PKHeX.Core/PKM/PK4.cs @@ -431,8 +431,8 @@ public PK5 ConvertToPK5() // Met / Crown Data Detection pk5.Met_Location = pk5.Gen4 && pk5.FatefulEncounter && Legal.CrownBeasts.Contains(pk5.Species) - ? (pk5.Species == 251 ? 30010 : 30012) // Celebi : Beast - : 30001; // Pokétransfer (not Crown) + ? (pk5.Species == 251 ? Legal.Transfer4_CelebiUnused : Legal.Transfer4_CrownUnused) // Celebi : Beast + : Legal.Transfer4; // Pokétransfer (not Crown) pk5.Egg_Location = Egg_Location; // Delete HGSS Data diff --git a/PKHeX.Core/Util/DataUtil.cs b/PKHeX.Core/Util/DataUtil.cs index 27fb9e5c8..55ad372ee 100644 --- a/PKHeX.Core/Util/DataUtil.cs +++ b/PKHeX.Core/Util/DataUtil.cs @@ -273,7 +273,7 @@ public static List GetVariedCBListBall(string[] inStrings, int[] stri newlist.Add(new ComboItem { Text = inStrings[i], Value = i }); newlist.AddRange(stringNum - .Select((z, i) => new ComboItem{ Text = inStrings[z], Value = stringVal[i]}) + .Select((z, i) => new ComboItem { Text = inStrings[z], Value = stringVal[i] }) .OrderBy(z => z.Text)); return newlist; } diff --git a/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.cs b/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.cs index deae3d88c..4b7eecbb8 100644 --- a/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.cs +++ b/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.cs @@ -780,9 +780,9 @@ private bool SetSuggestedMetLocation(bool silent = false) minlvl = level; if (pkm.VC1) - location = 30013; + location = Legal.Transfer1; else if (pkm.VC2) - location = 30017; + location = Legal.Transfer2; if (!silent) { @@ -1272,8 +1272,8 @@ private void UpdateOriginGame(object sender, EventArgs e) switch (newTrack) { case GameVersion.GO: metLoc = 30012; break; - case GameVersion.RBY: metLoc = 30013; break; - case GameVersion.GSC: metLoc = 30017; break; + case GameVersion.RBY: metLoc = Legal.Transfer1; break; + case GameVersion.GSC: metLoc = Legal.Transfer2; break; } if (metLoc != 0) CB_MetLocation.SelectedValue = metLoc; diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_Trainer7.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_Trainer7.cs index a878a7041..b53df8fe0 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_Trainer7.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_Trainer7.cs @@ -748,6 +748,7 @@ private void B_GenTID_Click(object sender, EventArgs e) // USUM {070, "Roto Lotos"}, {073, "Mantine Surf BP Earned"}, + {074, "Battle Agency Wins"}, {100, "Champion Title Defense"}, {104, "Moves used with No Effect"}, @@ -828,6 +829,7 @@ private void B_GenTID_Click(object sender, EventArgs e) // USUM {189, "Mantine Surf Plays"}, {190, "Photo Club Photos saved"}, + {191, "Battle Agency Battles"}, {195, "Photo Club Sticker usage"}, {196, "Photo Club Photo Shoots"}, {197, "Highest Wormhole Travel Distance"},