diff --git a/PKHeX.Core/Legality/BinLinkerAccessor.cs b/PKHeX.Core/Legality/BinLinkerAccessor.cs index e22fd408e..b98f7fde8 100644 --- a/PKHeX.Core/Legality/BinLinkerAccessor.cs +++ b/PKHeX.Core/Legality/BinLinkerAccessor.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics; using static System.Buffers.Binary.BinaryPrimitives; namespace PKHeX.Core; @@ -6,6 +7,7 @@ namespace PKHeX.Core; /// /// Unpacks a BinLinkerAccessor generated file container into individual arrays. /// +[DebuggerDisplay($"{{{nameof(Identifier)},nq}}[{{{nameof(Length)},nq}}]")] public readonly ref struct BinLinkerAccessor { /// Backing data object @@ -42,8 +44,8 @@ public static BinLinkerAccessor Get(ReadOnlySpan data, string identifier) { var result = new BinLinkerAccessor(data); #if DEBUG - System.Diagnostics.Debug.Assert(data.Length > 4); - System.Diagnostics.Debug.Assert(identifier[0] == data[0] && identifier[1] == data[1]); + Debug.Assert(data.Length > 4); + Debug.Assert(identifier[0] == data[0] && identifier[1] == data[1]); #endif return result; } diff --git a/PKHeX.Core/Legality/Verifiers/FormVerifier.cs b/PKHeX.Core/Legality/Verifiers/FormVerifier.cs index a20f3932c..92bb34333 100644 --- a/PKHeX.Core/Legality/Verifiers/FormVerifier.cs +++ b/PKHeX.Core/Legality/Verifiers/FormVerifier.cs @@ -202,17 +202,26 @@ private CheckResult VerifyForm(LegalityAnalysis data) private static readonly ushort[] Arceus_PlateIDs = { 303, 306, 304, 305, 309, 308, 310, 313, 298, 299, 301, 300, 307, 302, 311, 312, 644 }; private static readonly ushort[] Arceus_ZCrystal = { 782, 785, 783, 784, 788, 787, 789, 792, 777, 778, 780, 779, 786, 781, 790, 791, 793 }; - public static int GetArceusFormFromHeldItem(int item, int format) + public static int GetArceusFormFromHeldItem(int item, int format) => item switch { - if (item is >= 777 and <= 793) - return Array.IndexOf(Arceus_ZCrystal, (ushort)item) + 1; + >= 777 and <= 793 => GetArceusFormFromZCrystal(item), + >= 298 and <= 313 or 644 => GetArceusFormFromPlate(item, format), + _ => 0, + }; - int form = 0; - if (item is >= 298 and <= 313 or 644) - form = Array.IndexOf(Arceus_PlateIDs, (ushort)item) + 1; - if (format == 4 && form >= 9) - return form + 1; // ??? type Form shifts everything by 1 - return form; + private static int GetArceusFormFromZCrystal(int item) + { + return Array.IndexOf(Arceus_ZCrystal, (ushort)item) + 1; + } + + private static int GetArceusFormFromPlate(int item, int format) + { + int form = Array.IndexOf(Arceus_PlateIDs, (ushort)item) + 1; + if (format != 4) // No need to consider Curse type + return form; + if (form < 9) + return form; + return form + 1; // ??? type Form shifts everything by 1 } public static int GetSilvallyFormFromHeldItem(int item) diff --git a/PKHeX.Core/PKM/Util/Conversion/EntityConverter.cs b/PKHeX.Core/PKM/Util/Conversion/EntityConverter.cs index 90d75a4fa..b089ca9c4 100644 --- a/PKHeX.Core/PKM/Util/Conversion/EntityConverter.cs +++ b/PKHeX.Core/PKM/Util/Conversion/EntityConverter.cs @@ -72,7 +72,8 @@ public static bool IsConvertibleToFormat(PKM pk, int format) private static PKM? ConvertPKM(PKM pk, Type destType, Type srcType, out EntityConverterResult result) { - if (IsNotTransferable(pk, out result)) + result = CheckTransfer(pk); + if (result != Success) return null; Debug.WriteLine($"Trying to convert {srcType.Name} to {destType.Name}."); @@ -138,23 +139,15 @@ public static bool IsConvertibleToFormat(PKM pk, int format) /// Checks to see if a PKM is transferable relative to in-game restrictions and . /// /// PKM to convert - /// Comment indicating why the is not transferable. /// Indication if Not Transferable - private static bool IsNotTransferable(PKM pk, out EntityConverterResult result) + private static EntityConverterResult CheckTransfer(PKM pk) => pk switch { - switch (pk) - { - case PK4 { Species: (int)Species.Pichu } pk4 when pk4.Form != 0: - case PK6 { Species: (int)Species.Pikachu } pk6 when pk6.Form != 0: - case PB7 { Species: (int)Species.Pikachu } pika when pika.Form != 0: - case PB7 { Species: (int)Species.Eevee } eevee when eevee.Form != 0: - result = IncompatibleForm; - return true; - default: - result = Success; - return false; - } - } + PK4 { Species: (int)Species.Pichu, Form: not 0 } => IncompatibleForm, + PK6 { Species: (int)Species.Pikachu, Form: not 0 } => IncompatibleForm, + PB7 { Species: (int)Species.Pikachu, Form: not 0 } => IncompatibleForm, + PB7 { Species: (int)Species.Eevee, Form: not 0 } => IncompatibleForm, + _ => Success, + }; /// /// Checks if the is compatible with the input , and makes any necessary modifications to force compatibility. diff --git a/PKHeX.Core/PKM/Util/EffortValues.cs b/PKHeX.Core/PKM/Util/EffortValues.cs index 169a10815..62f6e32f3 100644 --- a/PKHeX.Core/PKM/Util/EffortValues.cs +++ b/PKHeX.Core/PKM/Util/EffortValues.cs @@ -8,15 +8,8 @@ public static class EffortValues /// /// Gets randomized EVs for a given generation format /// + /// Array containing randomized EVs (H/A/B/S/C/D) /// Generation specific formatting option - /// Array containing randomized EVs (H/A/B/S/C/D) - public static int[] GetRandom(int generation = PKX.Generation) - { - var evs = new int[6]; - SetRandom(evs, generation); - return evs; - } - public static void SetRandom(Span evs, int generation) { var rnd = Util.Rand; diff --git a/PKHeX.Core/PKM/Util/EntityFileExtension.cs b/PKHeX.Core/PKM/Util/EntityFileExtension.cs index 7a34038c7..ae639d253 100644 --- a/PKHeX.Core/PKM/Util/EntityFileExtension.cs +++ b/PKHeX.Core/PKM/Util/EntityFileExtension.cs @@ -17,8 +17,9 @@ public static class EntityFileExtension /// Valid file extensions. public static string[] GetExtensions(int maxGeneration = PKX.Generation) { - var result = new List(); int min = maxGeneration is <= 2 or >= 7 ? 1 : 3; + int size = maxGeneration - min + 1 + 6; + var result = new List(size); for (int i = min; i <= maxGeneration; i++) result.Add($"pk{i}"); @@ -47,7 +48,7 @@ public static string[] GetExtensions(int maxGeneration = PKX.Generation) /// Format hint that the file is. public static int GetFormatFromExtension(string ext, int prefer) { - if (string.IsNullOrEmpty(ext)) + if (ext.Length == 0) return prefer; return GetFormatFromExtension(ext[^1], prefer); } diff --git a/PKHeX.Core/PKM/Util/EntityFormat.cs b/PKHeX.Core/PKM/Util/EntityFormat.cs index c21f6314b..0f00548f4 100644 --- a/PKHeX.Core/PKM/Util/EntityFormat.cs +++ b/PKHeX.Core/PKM/Util/EntityFormat.cs @@ -1,8 +1,8 @@ using System; using System.Linq; using static PKHeX.Core.PokeCrypto; -using static System.Buffers.Binary.BinaryPrimitives; using static PKHeX.Core.EntityFormatDetected; +using static System.Buffers.Binary.BinaryPrimitives; namespace PKHeX.Core; diff --git a/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.cs b/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.cs index 0cef892d9..0a10735b0 100644 --- a/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.cs +++ b/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.cs @@ -383,14 +383,6 @@ public void UpdateUnicode(IReadOnlyList symbols) } } - private static string ReloadGender(string text, IReadOnlyList genders) - { - var index = EntityGender.GetFromString(text); - if (index >= 2) - return text; - return genders[index]; - } - internal void UpdateSprite() { if (FieldsLoaded && !forceValidation) @@ -1684,7 +1676,7 @@ private void ValidateMove(object sender, EventArgs e) else { // Shouldn't hit here. - throw new ArgumentException(nameof(sender)); + throw new InvalidOperationException(); } UpdateLegality(skipMoveRepop: true); } diff --git a/Tests/PKHeX.Core.Tests/Legality/Wild8aRNGTests.cs b/Tests/PKHeX.Core.Tests/Legality/Wild8aRNGTests.cs index 9aecb702b..9e5bf8454 100644 --- a/Tests/PKHeX.Core.Tests/Legality/Wild8aRNGTests.cs +++ b/Tests/PKHeX.Core.Tests/Legality/Wild8aRNGTests.cs @@ -50,7 +50,7 @@ public static void TestMagby() }; var xoro = new Xoroshiro128Plus(s0); - var result = Overworld8aRNG.ApplyDetails(test, param, true, ref xoro); + var (EntitySeed, _) = Overworld8aRNG.ApplyDetails(test, param, true, ref xoro); test.IV_HP.Should().Be(31); test.IV_ATK.Should().Be(31); @@ -61,7 +61,7 @@ public static void TestMagby() test.AlphaMove.Should().Be((ushort)Move.Flamethrower); - var verify = Overworld8aRNG.Verify(test, result.EntitySeed, param); + var verify = Overworld8aRNG.Verify(test, EntitySeed, param); verify.Should().BeTrue(); } }