From a45a7cc2d3e6927b06aeae185d39d42f2dc35751 Mon Sep 17 00:00:00 2001 From: Kurt Date: Thu, 21 Sep 2023 13:14:34 -0700 Subject: [PATCH] Misc fixes Pokewalker: defer match if shiny Jacq egg: recognize unhatched egg, traded sv-pokedex-old: don't add rows for >1010 species (out of range) static9: correctly flag scale mismatch SAV4HGSS: expose pokegear #'s as span instead of alloc --- .../Encounters/Data/Gen2/Encounters2GBEra.cs | 5 ++- .../Gen4/EncounterStatic4Pokewalker.cs | 2 + .../Templates/Gen9/EncounterStatic9.cs | 22 +++++++-- PKHeX.Core/PKM/Searching/SearchSettings.cs | 1 - PKHeX.Core/Saves/SAV4HGSS.cs | 45 ++++++++++--------- .../Save Editors/Gen4/PokeGear4Editor.cs | 4 +- .../Save Editors/Gen9/SAV_PokedexSV.cs | 3 +- Tests/PKHeX.Core.Tests/Util/TestUtil.cs | 1 - 8 files changed, 50 insertions(+), 33 deletions(-) diff --git a/PKHeX.Core/Legality/Encounters/Data/Gen2/Encounters2GBEra.cs b/PKHeX.Core/Legality/Encounters/Data/Gen2/Encounters2GBEra.cs index 7c077b0df..64bbce3be 100644 --- a/PKHeX.Core/Legality/Encounters/Data/Gen2/Encounters2GBEra.cs +++ b/PKHeX.Core/Legality/Encounters/Data/Gen2/Encounters2GBEra.cs @@ -6,18 +6,19 @@ namespace PKHeX.Core; internal static class Encounters2GBEra { private static readonly string[] PCNYx = { "PCNYa", "PCNYb", "PCNYc", "PCNYd" }; + private static readonly string[] Stadium2 = { "Stade", "Stadion", "Stadio", "Estadio" }; internal static readonly EncounterGift2[] StaticEventsGB = { // Stadium 2 Baton Pass Farfetch'd new(083, 05, C) {Moves = new(226, 14, 97, 163), Location = 127, TID16 = 2000, OT_Name = "スタジアム"}, new(083, 05, C) {Moves = new(226, 14, 97, 163), Location = 127, TID16 = 2000, OT_Name = "Stadium", Language = International}, - new(083, 05, C) {Moves = new(226, 14, 97, 163), Location = 127, TID16 = 2001, OT_Names = new[]{"Stade", "Stadion", "Stadio", "Estadio"}, Language = International}, + new(083, 05, C) {Moves = new(226, 14, 97, 163), Location = 127, TID16 = 2001, OT_Names = Stadium2, Language = International}, // Stadium 2 Earthquake Gligar new(207, 05, C) {Moves = new(89, 68, 17), Location = 127, TID16 = 2000, OT_Name = "スタジアム"}, new(207, 05, C) {Moves = new(89, 68, 17), Location = 127, TID16 = 2000, OT_Name = "Stadium", Language = International}, - new(207, 05, C) {Moves = new(89, 68, 17), Location = 127, TID16 = 2001, OT_Names = new[]{"Stade", "Stadion", "Stadio", "Estadio"}, Language = International}, + new(207, 05, C) {Moves = new(89, 68, 17), Location = 127, TID16 = 2001, OT_Names = Stadium2, Language = International}, //New York Pokémon Center Events diff --git a/PKHeX.Core/Legality/Encounters/Templates/Gen4/EncounterStatic4Pokewalker.cs b/PKHeX.Core/Legality/Encounters/Templates/Gen4/EncounterStatic4Pokewalker.cs index 2cf5b2753..485374a73 100644 --- a/PKHeX.Core/Legality/Encounters/Templates/Gen4/EncounterStatic4Pokewalker.cs +++ b/PKHeX.Core/Legality/Encounters/Templates/Gen4/EncounterStatic4Pokewalker.cs @@ -165,6 +165,8 @@ public EncounterMatchRating GetMatchRating(PKM pk) { if (IsMatchPartial(pk)) return EncounterMatchRating.PartialMatch; + if (pk.IsShiny) + return EncounterMatchRating.DeferredErrors; return EncounterMatchRating.Match; } diff --git a/PKHeX.Core/Legality/Encounters/Templates/Gen9/EncounterStatic9.cs b/PKHeX.Core/Legality/Encounters/Templates/Gen9/EncounterStatic9.cs index 7934f589d..a11070464 100644 --- a/PKHeX.Core/Legality/Encounters/Templates/Gen9/EncounterStatic9.cs +++ b/PKHeX.Core/Legality/Encounters/Templates/Gen9/EncounterStatic9.cs @@ -168,8 +168,22 @@ public bool IsMatchExact(PKM pk, EvoCriteria evo) private bool IsMatchEggLocation(PKM pk) { - var expect = pk is PB8 ? Locations.Default8bNone : EggLocation; - return pk.Egg_Location == expect; + var eggloc = pk.Egg_Location; + if (!EggEncounter) + { + var expect = pk is PB8 ? Locations.Default8bNone : EggLocation; + return eggloc == expect; + } + + if (!pk.IsEgg) // hatched + return eggloc == EggLocation || eggloc == Locations.LinkTrade6; + + // Unhatched: + if (eggloc != EggLocation) + return false; + if (pk.Met_Location is not (0 or Locations.LinkTrade6)) + return false; + return true; } private bool IsMatchLocation(PKM pk) @@ -191,7 +205,7 @@ public EncounterMatchRating GetMatchRating(PKM pk) private bool IsMatchLocationExact(PKM pk) { - if (EggEncounter && !pk.IsEgg) + if (EggEncounter) return true; return pk.Met_Location == Location; } @@ -249,7 +263,7 @@ private bool IsMatchPartial(PKM pk) } var current = pk is IScaledSize3 size3 ? size3.Scale : v.HeightScalar; if (current != Size) - return false; + return true; } if (pk is { AbilityNumber: 4 } && this.IsPartialMatchHidden(pk.Species, Species)) diff --git a/PKHeX.Core/PKM/Searching/SearchSettings.cs b/PKHeX.Core/PKM/Searching/SearchSettings.cs index 8fac7ed57..5dbceafe8 100644 --- a/PKHeX.Core/PKM/Searching/SearchSettings.cs +++ b/PKHeX.Core/PKM/Searching/SearchSettings.cs @@ -105,7 +105,6 @@ private void InitializeFilters() BatchFiltersMeta = meta; } - private IEnumerable SearchInner(IEnumerable list) { foreach (var pk in list) diff --git a/PKHeX.Core/Saves/SAV4HGSS.cs b/PKHeX.Core/Saves/SAV4HGSS.cs index e7affd037..621c270a4 100644 --- a/PKHeX.Core/Saves/SAV4HGSS.cs +++ b/PKHeX.Core/Saves/SAV4HGSS.cs @@ -189,17 +189,17 @@ public int Badges16 public PokegearNumber GetCallerAtIndex(int index) => (PokegearNumber)General[OFS_GearRolodex + index]; public void SetCallerAtIndex(int index, PokegearNumber caller) => General[OFS_GearRolodex + index] = (byte)caller; - public PokegearNumber[] GetPokeGearRoloDex() + public Span GetPokeGearRoloDex() { var arr = General.Slice(OFS_GearRolodex, GearMaxCallers); - return MemoryMarshal.Cast(arr).ToArray(); + return MemoryMarshal.Cast(arr); } public void SetPokeGearRoloDex(ReadOnlySpan value) { if (value.Length > GearMaxCallers) throw new ArgumentOutOfRangeException(nameof(value)); - MemoryMarshal.Cast(value).CopyTo(General.Slice(OFS_GearRolodex, GearMaxCallers)); + MemoryMarshal.AsBytes(value).CopyTo(General.Slice(OFS_GearRolodex, GearMaxCallers)); } public void PokeGearUnlockAllCallers() @@ -210,31 +210,32 @@ public void PokeGearUnlockAllCallers() public void PokeGearClearAllCallers(int start = 0) { - for (int i = start; i < GearMaxCallers; i++) - SetCallerAtIndex(i, PokegearNumber.None); + var dex = GetPokeGearRoloDex(); + dex[start..].Fill(PokegearNumber.None); } + private static ReadOnlySpan NotTrainers => new[] + { + PokegearNumber.Mother, + PokegearNumber.Professor_Elm, + PokegearNumber.Professor_Oak, + PokegearNumber.Ethan, + PokegearNumber.Lyra, + PokegearNumber.Kurt, + PokegearNumber.Daycare_Man, + PokegearNumber.Daycare_Lady, + PokegearNumber.Bill, + PokegearNumber.Bike_Shop, + PokegearNumber.Baoba, + }; + public void PokeGearUnlockAllCallersNoTrainers() { - var nonTrainers = new[] - { - PokegearNumber.Mother, - PokegearNumber.Professor_Elm, - PokegearNumber.Professor_Oak, - PokegearNumber.Ethan, - PokegearNumber.Lyra, - PokegearNumber.Kurt, - PokegearNumber.Daycare_Man, - PokegearNumber.Daycare_Lady, - PokegearNumber.Bill, - PokegearNumber.Bike_Shop, - PokegearNumber.Baoba, - }; - for (int i = 0; i < nonTrainers.Length; i++) - SetCallerAtIndex(i, nonTrainers[i]); + var dex = GetPokeGearRoloDex(); + NotTrainers.CopyTo(dex); // clear remaining callers - PokeGearClearAllCallers(nonTrainers.Length); + PokeGearClearAllCallers(NotTrainers.Length); } // Apricorn Pouch diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen4/PokeGear4Editor.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen4/PokeGear4Editor.cs index 67cd1431f..bf2f86946 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen4/PokeGear4Editor.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen4/PokeGear4Editor.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Windows.Forms; using PKHeX.Core; @@ -20,7 +20,7 @@ public void Initialize(SAV4HGSS sav) private void RefreshList() { - PG_Rolodex.SelectedObject = Rolodex = SAV.GetPokeGearRoloDex(); + PG_Rolodex.SelectedObject = Rolodex = SAV.GetPokeGearRoloDex().ToArray(); PG_Rolodex.Refresh(); } diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen9/SAV_PokedexSV.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen9/SAV_PokedexSV.cs index c29718a19..1b28c6735 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen9/SAV_PokedexSV.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen9/SAV_PokedexSV.cs @@ -29,8 +29,9 @@ public SAV_PokedexSV(SAV9SV sav) CB_Species.Items.Clear(); // Fill List + const int maxSpecies = (int)Species.IronLeaves; // 1010 -- no DLC species CB_Species.InitializeBinding(); - var species = GameInfo.SpeciesDataSource.Where(z => SAV.Personal.IsSpeciesInGame((ushort)z.Value)).ToArray(); + var species = GameInfo.SpeciesDataSource.Where(z => SAV.Personal.IsSpeciesInGame((ushort)z.Value) && z.Value <= maxSpecies).ToArray(); CB_Species.DataSource = new BindingSource(species, null); var list = species diff --git a/Tests/PKHeX.Core.Tests/Util/TestUtil.cs b/Tests/PKHeX.Core.Tests/Util/TestUtil.cs index 15393a2f6..5e585ba3e 100644 --- a/Tests/PKHeX.Core.Tests/Util/TestUtil.cs +++ b/Tests/PKHeX.Core.Tests/Util/TestUtil.cs @@ -30,5 +30,4 @@ public static void InitializeLegality() IsInitialized = true; } } - }