From 2cdb5d26db117f1d15e7cbfb8c346a778c9fa243 Mon Sep 17 00:00:00 2001 From: Kurt Date: Tue, 16 Jun 2020 21:46:22 -0500 Subject: [PATCH] Clean up some method signatures rename things to be a little more consistent in naming conventions --- .../Editing/Applicators/BallApplicator.cs | 6 +- .../Editing/Applicators/GenderApplicator.cs | 4 +- .../Applicators/HiddenPowerApplicator.cs | 8 +- .../Editing/Applicators/MoveApplicator.cs | 6 +- PKHeX.Core/Editing/Bulk/BatchEditing.cs | 28 ++--- PKHeX.Core/Editing/Bulk/BatchEditor.cs | 12 +- PKHeX.Core/Editing/Bulk/StringInstruction.cs | 12 +- PKHeX.Core/Editing/CommonEdits.cs | 30 +++-- PKHeX.Core/Editing/HiddenPower.cs | 18 +-- PKHeX.Core/Editing/IPlugin.cs | 2 +- PKHeX.Core/Editing/PKM/EditPKMUtil.cs | 12 +- PKHeX.Core/Editing/PKM/LegalMoveSource.cs | 4 +- PKHeX.Core/Editing/Saves/BoxManipBase.cs | 2 +- PKHeX.Core/Editing/Saves/BoxManipClear.cs | 4 +- .../Editing/Saves/BoxManipClearComplex.cs | 6 +- .../Editing/Saves/BoxManipClearDuplicate.cs | 4 +- PKHeX.Core/Editing/Saves/BoxManipModify.cs | 2 +- .../Editing/Saves/BoxManipModifyComplex.cs | 2 +- PKHeX.Core/Editing/Saves/BoxManipSort.cs | 4 +- .../Editing/Saves/BoxManipSortComplex.cs | 6 +- .../Editors/EventWork/SplitEventEditor.cs | 16 +-- PKHeX.Core/Editing/Saves/IBoxManip.cs | 2 +- PKHeX.Core/Editing/Saves/Slots/Extensions.cs | 12 +- .../Editing/Saves/Slots/Info/ISlotInfo.cs | 4 +- .../Editing/Saves/Slots/SlotChangelog.cs | 6 +- .../Editing/Saves/Slots/SlotPublisher.cs | 8 +- PKHeX.Core/Editing/ShowdownSet.cs | 30 ++--- PKHeX.Core/Editing/WurmpleUtil.cs | 16 +-- .../GameStrings/FilteredGameDataSource.cs | 14 +-- PKHeX.Core/Game/GameStrings/GameDataSource.cs | 115 +++++++++--------- PKHeX.Core/Game/GameStrings/GameInfo.cs | 8 +- PKHeX.Core/Game/GameStrings/GameStrings.cs | 28 ++--- PKHeX.Core/Game/GameStrings/GeoLocation.cs | 28 ++--- PKHeX.Core/Game/GameUtil.cs | 17 +-- .../Legality/Encounters/Data/EncountersWC3.cs | 6 +- .../Encounters/EncounterMisc/EncounterEgg.cs | 16 +-- .../EncounterMisc/EncounterInvalid.cs | 4 +- .../EncounterMisc/EncounterRejected.cs | 4 +- .../Encounters/EncounterSlot/EncounterSlot.cs | 18 +-- .../EncounterStatic/EncounterStatic.cs | 14 +-- .../EncounterTrade/EncounterTrade.cs | 28 ++--- .../EncounterTrade/EncounterTrade8.cs | 6 +- .../Legality/Encounters/IEncounterable.cs | 4 +- .../Legality/Structures/ITrainerInfo.cs | 14 +-- .../Verifiers/Ribbons/RibbonVerifier.cs | 71 ++++++----- PKHeX.Core/MysteryGifts/MysteryGift.cs | 10 +- PKHeX.Core/MysteryGifts/MysteryUtil.cs | 20 +-- PKHeX.Core/MysteryGifts/PCD.cs | 4 +- PKHeX.Core/MysteryGifts/PGF.cs | 20 +-- PKHeX.Core/MysteryGifts/PGT.cs | 18 +-- PKHeX.Core/MysteryGifts/WB7.cs | 28 ++--- PKHeX.Core/MysteryGifts/WC3.cs | 32 ++--- PKHeX.Core/MysteryGifts/WC6.cs | 24 ++-- PKHeX.Core/MysteryGifts/WC7.cs | 28 ++--- PKHeX.Core/MysteryGifts/WC8.cs | 40 +++--- PKHeX.Core/MysteryGifts/WR7.cs | 6 +- PKHeX.Core/PKM/CK3.cs | 2 +- PKHeX.Core/PKM/PK1.cs | 4 +- PKHeX.Core/PKM/PK2.cs | 2 +- PKHeX.Core/PKM/PK3.cs | 4 +- PKHeX.Core/PKM/PKM.cs | 36 +++--- PKHeX.Core/PKM/Searching/SearchSettings.cs | 14 +-- PKHeX.Core/PKM/Searching/SearchUtil.cs | 18 +-- PKHeX.Core/PKM/Strings/StringConverter.cs | 51 ++++---- PKHeX.Core/PKM/Strings/StringConverter12.cs | 16 +-- PKHeX.Core/PKM/Strings/StringConverter2KOR.cs | 8 +- PKHeX.Core/PKM/Strings/StringConverter3.cs | 34 +++--- PKHeX.Core/PKM/Strings/StringConverter345.cs | 10 +- PKHeX.Core/PKM/Strings/StringConverter4.cs | 18 +-- PKHeX.Core/PKM/Util/FormConverter.cs | 2 +- PKHeX.Core/PKM/Util/ItemConverter.cs | 68 ++++++----- PKHeX.Core/PKM/Util/PKMConverter.cs | 68 +++++------ PKHeX.Core/PKM/Util/PKX.cs | 15 ++- PKHeX.Core/PKM/Util/PokeCrypto.cs | 4 +- PKHeX.Core/PKM/Util/QRMessageUtil.cs | 10 +- PKHeX.Core/PKM/Util/SpeciesConverter.cs | 16 +-- PKHeX.Core/PKM/XK3.cs | 2 +- PKHeX.Core/PersonalInfo/PersonalInfo.cs | 6 +- PKHeX.Core/PersonalInfo/PersonalTable.cs | 18 +-- PKHeX.Core/Saves/MemeCrypto/MemeCrypto.cs | 28 ++--- PKHeX.Core/Saves/SAV3.cs | 10 +- .../Substructures/Inventory/InventoryPouch.cs | 24 ++-- PKHeX.Core/Saves/Util/BoxUtil.cs | 78 ++++++------ PKHeX.Core/Saves/Util/Checksums.cs | 4 +- PKHeX.Core/Saves/Util/DexFormUtil.cs | 52 ++++---- PKHeX.Core/Saves/Util/SaveExtensions.cs | 2 +- PKHeX.Core/Saves/Util/SaveFinder.cs | 4 +- PKHeX.Core/Saves/Util/SaveUtil.cs | 40 +++--- PKHeX.Core/Util/DataUtil.cs | 28 ++--- PKHeX.Core/Util/DateUtil.cs | 10 +- PKHeX.Core/Util/FileUtil.cs | 10 +- PKHeX.Core/Util/NetUtil.cs | 8 +- PKHeX.Drawing/QR/QRDecode.cs | 48 +++----- PKHeX.Drawing/QR/QRDecodeResult.cs | 12 ++ PKHeX.Drawing/QR/QREncode.cs | 10 +- .../Controls/PKM Editor/StatEditor.cs | 2 +- .../Controls/SAV Editor/BoxMenuStrip.cs | 32 ++--- .../Controls/SAV Editor/SAVEditor.cs | 11 +- .../Subforms/Misc/PKMSummaryImage.cs | 2 +- .../Subforms/PKM Editors/BatchEditor.cs | 4 +- 100 files changed, 877 insertions(+), 859 deletions(-) create mode 100644 PKHeX.Drawing/QR/QRDecodeResult.cs diff --git a/PKHeX.Core/Editing/Applicators/BallApplicator.cs b/PKHeX.Core/Editing/Applicators/BallApplicator.cs index 5f3bb9f73..20f4ca70b 100644 --- a/PKHeX.Core/Editing/Applicators/BallApplicator.cs +++ b/PKHeX.Core/Editing/Applicators/BallApplicator.cs @@ -116,10 +116,10 @@ static BallApplicator() var colors = (PersonalColor[])Enum.GetValues(typeof(PersonalColor)); foreach (var c in colors) { - var vals = BallColors[c]; - var extra = allBalls.Except(vals).ToArray(); + var matchingColors = BallColors[c]; + var extra = allBalls.Except(matchingColors).ToArray(); Util.Shuffle(extra); - BallColors[c] = vals.Concat(extra).Concat(end).ToArray(); + BallColors[c] = matchingColors.Concat(extra).Concat(end).ToArray(); } } diff --git a/PKHeX.Core/Editing/Applicators/GenderApplicator.cs b/PKHeX.Core/Editing/Applicators/GenderApplicator.cs index e50e8a564..4ffd27689 100644 --- a/PKHeX.Core/Editing/Applicators/GenderApplicator.cs +++ b/PKHeX.Core/Editing/Applicators/GenderApplicator.cs @@ -27,7 +27,7 @@ public static void SetGender(this PKM pk, int gender) gender = Math.Min(2, Math.Max(0, gender)); if (pk.Format <= 2) { - pk.SetATKIVGender(gender); + pk.SetAttackIVFromGender(gender); } else if (pk.Format <= 5) { @@ -64,7 +64,7 @@ public static int GetSaneGender(this PKM pk) /// /// Pokémon to modify. /// Desired . - public static void SetATKIVGender(this PKM pk, int gender) + public static void SetAttackIVFromGender(this PKM pk, int gender) { var rnd = Util.Rand; while (pk.Gender != gender) diff --git a/PKHeX.Core/Editing/Applicators/HiddenPowerApplicator.cs b/PKHeX.Core/Editing/Applicators/HiddenPowerApplicator.cs index fafa71b43..8451a2906 100644 --- a/PKHeX.Core/Editing/Applicators/HiddenPowerApplicator.cs +++ b/PKHeX.Core/Editing/Applicators/HiddenPowerApplicator.cs @@ -7,10 +7,10 @@ public static class HiddenPowerApplicator /// /// Pokémon to modify. /// Desired Hidden Power typing. - public static void SetHiddenPower(this PKM pk, int hptype) + public static void SetHiddenPower(this PKM pk, int hiddenPowerType) { var IVs = pk.IVs; - HiddenPower.SetIVsForType(hptype, pk.IVs, pk.Format); + HiddenPower.SetIVsForType(hiddenPowerType, pk.IVs, pk.Format); pk.IVs = IVs; } @@ -18,7 +18,7 @@ public static void SetHiddenPower(this PKM pk, int hptype) /// Sets the to match a provided . /// /// Pokémon to modify. - /// Desired Hidden Power typing. - public static void SetHiddenPower(this PKM pk, MoveType hptype) => pk.SetHiddenPower((int)hptype); + /// Desired Hidden Power typing. + public static void SetHiddenPower(this PKM pk, MoveType hiddenPowerType) => pk.SetHiddenPower((int)hiddenPowerType); } } \ No newline at end of file diff --git a/PKHeX.Core/Editing/Applicators/MoveApplicator.cs b/PKHeX.Core/Editing/Applicators/MoveApplicator.cs index 9fce01023..3c99345fb 100644 --- a/PKHeX.Core/Editing/Applicators/MoveApplicator.cs +++ b/PKHeX.Core/Editing/Applicators/MoveApplicator.cs @@ -23,7 +23,7 @@ public static void SetMaximumPPUps(this PKM pk, int[] moves) } /// - /// Sets the individual PP Up count values depending if a Move is present in the moveslot or not. + /// Sets the individual PP Up count values depending if a Move is present in the move slot or not. /// /// Pokémon to modify. public static void SetMaximumPPUps(this PKM pk) => pk.SetMaximumPPUps(pk.Moves); @@ -50,7 +50,7 @@ public static void SetMoves(this PKM pk, int[] moves, bool maxPP = false) } /// - /// Updates the individual PP count values for each moveslot based on the maximum possible value. + /// Updates the individual PP count values for each move slot based on the maximum possible value. /// /// Pokémon to modify. /// to use (if already known). Will fetch the current if not provided. @@ -63,7 +63,7 @@ public static void SetMaximumPPCurrent(this PKM pk, IReadOnlyList moves) } /// - /// Updates the individual PP count values for each moveslot based on the maximum possible value. + /// Updates the individual PP count values for each move slot based on the maximum possible value. /// /// Pokémon to modify. public static void SetMaximumPPCurrent(this PKM pk) => pk.SetMaximumPPCurrent(pk.Moves); diff --git a/PKHeX.Core/Editing/Bulk/BatchEditing.cs b/PKHeX.Core/Editing/Bulk/BatchEditing.cs index 1b7344d54..0399cdac5 100644 --- a/PKHeX.Core/Editing/Bulk/BatchEditing.cs +++ b/PKHeX.Core/Editing/Bulk/BatchEditing.cs @@ -352,8 +352,8 @@ private static bool IsLegalFiltered(StringInstruction cmd, Func isLegal) /// Suggestion string which starts with private static ModifyResult SetSuggestedPKMProperty(string name, PKMInfo info, string propValue) { - bool isAll() => propValue.EndsWith("All", true, CultureInfo.CurrentCulture); - bool isNone() => propValue.EndsWith("None", true, CultureInfo.CurrentCulture); + static bool IsAll(string p) => p.EndsWith("All", true, CultureInfo.CurrentCulture); + static bool IsNone(string p) => p.EndsWith("None", true, CultureInfo.CurrentCulture); var pk = info.Entity; switch (name) { @@ -392,15 +392,15 @@ private static ModifyResult SetSuggestedPKMProperty(string name, PKMInfo info, s if (pk.Format >= 8) { pk.ClearRecordFlags(); - if (isAll()) + if (IsAll(propValue)) pk.SetRecordFlags(); // all - else if (!isNone()) + else if (!IsNone(propValue)) pk.SetRecordFlags(pk.Moves); // whatever fit the current moves } pk.SetRelearnMoves(info.SuggestedRelearn); return ModifyResult.Modified; case PROP_RIBBONS: - if (isNone()) + if (IsNone(propValue)) RibbonApplicator.RemoveAllValidRibbons(pk); else // All RibbonApplicator.SetAllValidRibbons(pk); @@ -412,11 +412,11 @@ private static ModifyResult SetSuggestedPKMProperty(string name, PKMInfo info, s int level = encounter.LevelMin; int location = encounter.Location; - int minlvl = EncounterSuggestion.GetLowestLevel(pk, encounter.LevelMin); + int minimumLevel = EncounterSuggestion.GetLowestLevel(pk, encounter.LevelMin); pk.Met_Level = level; pk.Met_Location = location; - pk.CurrentLevel = Math.Max(minlvl, level); + pk.CurrentLevel = Math.Max(minimumLevel, level); return ModifyResult.Modified; @@ -458,7 +458,7 @@ private static ModifyResult SetMoves(PKM pk, int[] moves) } /// - /// Sets the byte array propery to a specified value. + /// Sets the byte array property to a specified value. /// /// Pokémon to modify. /// Modification @@ -467,15 +467,15 @@ private static ModifyResult SetByteArrayProperty(PKM pk, StringInstruction cmd) switch (cmd.PropertyName) { case nameof(PKM.Nickname_Trash): - pk.Nickname_Trash = string2arr(cmd.PropertyValue); + pk.Nickname_Trash = ConvertToBytes(cmd.PropertyValue); return ModifyResult.Modified; case nameof(PKM.OT_Trash): - pk.OT_Trash = string2arr(cmd.PropertyValue); + pk.OT_Trash = ConvertToBytes(cmd.PropertyValue); return ModifyResult.Modified; default: return ModifyResult.Error; } - static byte[] string2arr(string str) => str.Substring(CONST_BYTES.Length).Split(',').Select(z => Convert.ToByte(z.Trim(), 16)).ToArray(); + static byte[] ConvertToBytes(string str) => str.Substring(CONST_BYTES.Length).Split(',').Select(z => Convert.ToByte(z.Trim(), 16)).ToArray(); } /// @@ -486,12 +486,12 @@ private static ModifyResult SetByteArrayProperty(PKM pk, StringInstruction cmd) /// True if modified, false if no modifications done. private static bool SetComplexProperty(PKM pk, StringInstruction cmd) { - static DateTime parseDate(string val) => DateTime.ParseExact(val, "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None); + static DateTime ParseDate(string val) => DateTime.ParseExact(val, "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None); if (cmd.PropertyName == nameof(PKM.MetDate)) - pk.MetDate = parseDate(cmd.PropertyValue); + pk.MetDate = ParseDate(cmd.PropertyValue); else if (cmd.PropertyName == nameof(PKM.EggMetDate)) - pk.EggMetDate = parseDate(cmd.PropertyValue); + pk.EggMetDate = ParseDate(cmd.PropertyValue); else if (cmd.PropertyName == nameof(PKM.EncryptionConstant) && cmd.PropertyValue == CONST_RAND) pk.EncryptionConstant = Util.Rand32(); else if ((cmd.PropertyName == nameof(PKM.Ability) || cmd.PropertyName == nameof(PKM.AbilityNumber)) && cmd.PropertyValue.StartsWith("$")) diff --git a/PKHeX.Core/Editing/Bulk/BatchEditor.cs b/PKHeX.Core/Editing/Bulk/BatchEditor.cs index 389ea0ea6..5349d86d5 100644 --- a/PKHeX.Core/Editing/Bulk/BatchEditor.cs +++ b/PKHeX.Core/Editing/Bulk/BatchEditor.cs @@ -13,7 +13,7 @@ public sealed class BatchEditor { private int Modified { get; set; } private int Iterated { get; set; } - private int Errored { get; set; } + private int Failed { get; set; } /// /// Tries to modify the . @@ -22,7 +22,7 @@ public sealed class BatchEditor /// Filters which must be satisfied prior to any modifications being made. /// Modifications to perform on the . /// Result of the attempted modification. - public bool ProcessPKM(PKM pkm, IEnumerable filters, IEnumerable modifications) + public bool Process(PKM pkm, IEnumerable filters, IEnumerable modifications) { if (pkm.Species <= 0) return false; @@ -38,7 +38,7 @@ public bool ProcessPKM(PKM pkm, IEnumerable filters, IEnumera if (result != ModifyResult.Invalid) Iterated++; if (result == ModifyResult.Error) - Errored++; + Failed++; if (result != ModifyResult.Modified) return false; @@ -60,8 +60,8 @@ public string GetEditorResults(ICollection sets) int len = Iterated / sets.Count; string maybe = sets.Count == 1 ? string.Empty : "~"; string result = string.Format(MsgBEModifySuccess, maybe, ctr, len); - if (Errored > 0) - result += Environment.NewLine + maybe + string.Format(MsgBEModifyFailError, Errored); + if (Failed > 0) + result += Environment.NewLine + maybe + string.Format(MsgBEModifyFailError, Failed); return result; } @@ -72,7 +72,7 @@ public static BatchEditor Execute(IList lines, IEnumerable data) foreach (var pk in data) { foreach (var set in sets) - editor.ProcessPKM(pk, set.Filters, set.Instructions); + editor.Process(pk, set.Filters, set.Instructions); } return editor; diff --git a/PKHeX.Core/Editing/Bulk/StringInstruction.cs b/PKHeX.Core/Editing/Bulk/StringInstruction.cs index 17e69e6bf..52794c0d1 100644 --- a/PKHeX.Core/Editing/Bulk/StringInstruction.cs +++ b/PKHeX.Core/Editing/Bulk/StringInstruction.cs @@ -49,20 +49,20 @@ public void SetScreenedValue(string[] arr) public const char SplitInstruction = '='; // Extra Functionality - private int Min, Max; + private int RandomMinimum, RandomMaximum; public bool Random { get; private set; } - public int RandomValue => Util.Rand.Next(Min, Max + 1); + public int RandomValue => Util.Rand.Next(RandomMinimum, RandomMaximum + 1); public void SetRandRange(string pv) { string str = pv.Substring(1); var split = str.Split(SplitRange); - int.TryParse(split[0], out Min); - int.TryParse(split[1], out Max); + int.TryParse(split[0], out RandomMinimum); + int.TryParse(split[1], out RandomMaximum); - if (Min == Max) + if (RandomMinimum == RandomMaximum) { - PropertyValue = Min.ToString(); + PropertyValue = RandomMinimum.ToString(); Debug.WriteLine(PropertyName + " randomization range Min/Max same?"); } else diff --git a/PKHeX.Core/Editing/CommonEdits.cs b/PKHeX.Core/Editing/CommonEdits.cs index 3645ce643..c27fedabc 100644 --- a/PKHeX.Core/Editing/CommonEdits.cs +++ b/PKHeX.Core/Editing/CommonEdits.cs @@ -80,23 +80,23 @@ public static void SetAbility(this PKM pk, int abil) if (abil < 0) return; var abilities = pk.PersonalInfo.Abilities; - int abilIndex = Array.IndexOf(abilities, abil); - abilIndex = Math.Max(0, abilIndex); - pk.SetAbilityIndex(abilIndex); + int index = Array.IndexOf(abilities, abil); + index = Math.Max(0, index); + pk.SetAbilityIndex(index); } /// /// Sets the value based on the provided ability index (0-2) /// /// Pokémon to modify. - /// Desired (shifted by 1) to set. - public static void SetAbilityIndex(this PKM pk, int abilIndex) + /// Desired (shifted by 1) to set. + public static void SetAbilityIndex(this PKM pk, int index) { - if (pk is PK5 pk5 && abilIndex == 2) + if (pk is PK5 pk5 && index == 2) pk5.HiddenAbility = true; else if (pk.Format <= 5) - pk.PID = PKX.GetRandomPID(Util.Rand, pk.Species, pk.Gender, pk.Version, pk.Nature, pk.AltForm, (uint)(abilIndex * 0x10001)); - pk.RefreshAbility(abilIndex); + pk.PID = PKX.GetRandomPID(Util.Rand, pk.Species, pk.Gender, pk.Version, pk.Nature, pk.AltForm, (uint)(index * 0x10001)); + pk.RefreshAbility(index); } /// @@ -116,7 +116,7 @@ public static void SetRandomEC(this PKM pk) int wIndex = WurmpleUtil.GetWurmpleEvoGroup(pk.Species); if (wIndex != -1) { - pk.EncryptionConstant = WurmpleUtil.GetWurmpleEC(wIndex); + pk.EncryptionConstant = WurmpleUtil.GetWurmpleEncryptionConstant(wIndex); return; } pk.EncryptionConstant = Util.Rand32(); @@ -252,7 +252,7 @@ public static void ApplySetDetails(this PKM pk, IBattleTemplate Set) /// Format required for importing public static void ApplyHeldItem(this PKM pk, int item, int format) { - item = ItemConverter.GetFormatHeldItemID(item, format, pk.Format); + item = ItemConverter.GetItemForFormat(item, format, pk.Format); pk.HeldItem = ((uint)item > pk.MaxItemID) ? 0 : item; } @@ -309,9 +309,7 @@ public static int GetMaximumEV(this PKM pk, int index) if (pk.Format < 3) return ushort.MaxValue; - var EVs = pk.EVs; - EVs[index] = 0; - var sum = EVs.Sum(); + var sum = pk.EVTotal - pk.GetEV(index); int remaining = 510 - sum; return Math.Min(Math.Max(remaining, 0), 252); } @@ -321,7 +319,7 @@ public static int GetMaximumEV(this PKM pk, int index) /// /// Pokémon to modify. /// Index to fetch for - /// Causes the returned value to be dropped down -1 if the value is already at a maxmimum. + /// Causes the returned value to be dropped down -1 if the value is already at a maximum. /// Highest value the value can be. public static int GetMaximumIV(this PKM pk, int index, bool allow30 = false) { @@ -439,8 +437,8 @@ public static string GetLocationString(this PKM pk, bool eggmet) if (pk.Format < 2) return string.Empty; - int locval = eggmet ? pk.Egg_Location : pk.Met_Location; - return GameInfo.GetLocationName(eggmet, locval, pk.Format, pk.GenNumber, (GameVersion)pk.Version); + int location = eggmet ? pk.Egg_Location : pk.Met_Location; + return GameInfo.GetLocationName(eggmet, location, pk.Format, pk.GenNumber, (GameVersion)pk.Version); } } } diff --git a/PKHeX.Core/Editing/HiddenPower.cs b/PKHeX.Core/Editing/HiddenPower.cs index c30ceba33..d94a31cff 100644 --- a/PKHeX.Core/Editing/HiddenPower.cs +++ b/PKHeX.Core/Editing/HiddenPower.cs @@ -43,27 +43,27 @@ public static int GetType(IReadOnlyList IVs) /// Hidden Power Type of the public static int GetTypeGB(IReadOnlyList IVs) { - var IV_ATK = IVs[1]; - var IV_DEF = IVs[2]; - return ((IV_ATK & 3) << 2) | (IV_DEF & 3); + var atk = IVs[1]; + var def = IVs[2]; + return ((atk & 3) << 2) | (def & 3); } /// - /// Modifies the provided to have the requested . + /// Modifies the provided to have the requested . /// - /// Hidden Power Type + /// Hidden Power Type /// Current IVs (6 total) /// Generation format /// True if the Hidden Power of the is obtained, with or without modifications - public static bool SetIVsForType(int hpVal, int[] IVs, int format) + public static bool SetIVsForType(int hiddenPowerType, int[] IVs, int format) { if (format <= 2) { - IVs[1] = (IVs[1] & ~3) | (hpVal >> 2); - IVs[2] = (IVs[2] & ~3) | (hpVal & 3); + IVs[1] = (IVs[1] & ~3) | (hiddenPowerType >> 2); + IVs[2] = (IVs[2] & ~3) | (hiddenPowerType & 3); return true; } - return SetIVsForType(hpVal, IVs); + return SetIVsForType(hiddenPowerType, IVs); } /// diff --git a/PKHeX.Core/Editing/IPlugin.cs b/PKHeX.Core/Editing/IPlugin.cs index d7c4c0db2..00caeca34 100644 --- a/PKHeX.Core/Editing/IPlugin.cs +++ b/PKHeX.Core/Editing/IPlugin.cs @@ -16,7 +16,7 @@ public interface IPlugin int Priority { get; } /// - /// Entrypoint for the parent to initialize the plugin with provided arguments. + /// Entry point for the parent to initialize the plugin with provided arguments. /// /// Arguments containing objects useful for initializing the plugin. void Initialize(params object[] args); diff --git a/PKHeX.Core/Editing/PKM/EditPKMUtil.cs b/PKHeX.Core/Editing/PKM/EditPKMUtil.cs index d475bc4f4..51965ac4f 100644 --- a/PKHeX.Core/Editing/PKM/EditPKMUtil.cs +++ b/PKHeX.Core/Editing/PKM/EditPKMUtil.cs @@ -10,18 +10,18 @@ namespace PKHeX.Core /// public static class EditPKMUtil { - public static List GetSuggestionMessage(PKM pkm, int level, int location, int minlvl) + public static List GetSuggestionMessage(PKM pkm, int level, int location, int minimumLevel) { var suggestion = new List { MsgPKMSuggestionStart }; if (pkm.Format >= 3) { - var met_list = GameInfo.GetLocationList((GameVersion)pkm.Version, pkm.Format, egg: false); - var locstr = met_list.First(loc => loc.Value == location).Text; - suggestion.Add($"{MsgPKMSuggestionMetLocation} {locstr}"); + var metList = GameInfo.GetLocationList((GameVersion)pkm.Version, pkm.Format, egg: false); + var locationName = metList.First(loc => loc.Value == location).Text; + suggestion.Add($"{MsgPKMSuggestionMetLocation} {locationName}"); suggestion.Add($"{MsgPKMSuggestionMetLevel} {level}"); } - if (pkm.CurrentLevel < minlvl) - suggestion.Add($"{MsgPKMSuggestionLevel} {minlvl}"); + if (pkm.CurrentLevel < minimumLevel) + suggestion.Add($"{MsgPKMSuggestionLevel} {minimumLevel}"); return suggestion; } diff --git a/PKHeX.Core/Editing/PKM/LegalMoveSource.cs b/PKHeX.Core/Editing/PKM/LegalMoveSource.cs index 575532975..5703e162d 100644 --- a/PKHeX.Core/Editing/PKM/LegalMoveSource.cs +++ b/PKHeX.Core/Editing/PKM/LegalMoveSource.cs @@ -18,7 +18,7 @@ public sealed class LegalMoveSource public void ReloadMoves(IReadOnlyList moves) { - // check prior movepool to not needlessly refresh the dataset + // check prior move-pool to not needlessly refresh the data set if (AllowedMoves.Count == moves.Count && AllowedMoves.SetEquals(moves)) return; @@ -28,7 +28,7 @@ public void ReloadMoves(IReadOnlyList moves) Array.Sort(MoveDataAllowed, Compare); // MoveDataAllowed = MoveDataAllowed.OrderByDescending(m => AllowedMoves.Contains(m.Value)).ToArray(); - // defer repop until dropdown is opened; handled by dropdown event + // defer re-population until dropdown is opened; handled by dropdown event for (int i = 0; i < IsMoveBoxOrdered.Count; i++) IsMoveBoxOrdered[i] = false; } diff --git a/PKHeX.Core/Editing/Saves/BoxManipBase.cs b/PKHeX.Core/Editing/Saves/BoxManipBase.cs index 30133fdb1..da61f72b0 100644 --- a/PKHeX.Core/Editing/Saves/BoxManipBase.cs +++ b/PKHeX.Core/Editing/Saves/BoxManipBase.cs @@ -18,7 +18,7 @@ protected BoxManipBase(BoxManipType type, Func usable) public abstract string GetPrompt(bool all); public abstract string GetFail(bool all); public abstract string GetSuccess(bool all); - public abstract int Execute(SaveFile SAV, BoxManipParam param); + public abstract int Execute(SaveFile sav, BoxManipParam param); public static readonly IReadOnlyList SortCommon = new List { diff --git a/PKHeX.Core/Editing/Saves/BoxManipClear.cs b/PKHeX.Core/Editing/Saves/BoxManipClear.cs index e8b5820b6..c4c3b4835 100644 --- a/PKHeX.Core/Editing/Saves/BoxManipClear.cs +++ b/PKHeX.Core/Editing/Saves/BoxManipClear.cs @@ -12,10 +12,10 @@ public sealed class BoxManipClear : BoxManipBase public override string GetFail(bool all) => all ? MessageStrings.MsgSaveBoxClearAllFailBattle : MessageStrings.MsgSaveBoxClearCurrentFailBattle; public override string GetSuccess(bool all) => all ? MessageStrings.MsgSaveBoxClearAllSuccess : MessageStrings.MsgSaveBoxClearCurrentSuccess; - public override int Execute(SaveFile SAV, BoxManipParam param) + public override int Execute(SaveFile sav, BoxManipParam param) { bool Method(PKM p) => param.Reverse ^ Criteria(p); - return SAV.ClearBoxes(param.Start, param.Stop, Method); + return sav.ClearBoxes(param.Start, param.Stop, Method); } } } \ No newline at end of file diff --git a/PKHeX.Core/Editing/Saves/BoxManipClearComplex.cs b/PKHeX.Core/Editing/Saves/BoxManipClearComplex.cs index fcd264fb7..f7aa06227 100644 --- a/PKHeX.Core/Editing/Saves/BoxManipClearComplex.cs +++ b/PKHeX.Core/Editing/Saves/BoxManipClearComplex.cs @@ -12,10 +12,10 @@ public sealed class BoxManipClearComplex : BoxManipBase public override string GetFail(bool all) => all ? MessageStrings.MsgSaveBoxClearAllFailBattle : MessageStrings.MsgSaveBoxClearCurrentFailBattle; public override string GetSuccess(bool all) => all ? MessageStrings.MsgSaveBoxClearAllSuccess : MessageStrings.MsgSaveBoxClearCurrentSuccess; - public override int Execute(SaveFile SAV, BoxManipParam param) + public override int Execute(SaveFile sav, BoxManipParam param) { - bool Method(PKM p) => param.Reverse ^ Criteria(p, SAV); - return SAV.ClearBoxes(param.Start, param.Stop, Method); + bool Method(PKM p) => param.Reverse ^ Criteria(p, sav); + return sav.ClearBoxes(param.Start, param.Stop, Method); } } } \ No newline at end of file diff --git a/PKHeX.Core/Editing/Saves/BoxManipClearDuplicate.cs b/PKHeX.Core/Editing/Saves/BoxManipClearDuplicate.cs index 69069376b..886b22a73 100644 --- a/PKHeX.Core/Editing/Saves/BoxManipClearDuplicate.cs +++ b/PKHeX.Core/Editing/Saves/BoxManipClearDuplicate.cs @@ -25,11 +25,11 @@ public BoxManipClearDuplicate(BoxManipType type, Func criteria, Func all ? MessageStrings.MsgSaveBoxClearAllFailBattle : MessageStrings.MsgSaveBoxClearCurrentFailBattle; public override string GetSuccess(bool all) => all ? MessageStrings.MsgSaveBoxClearAllSuccess : MessageStrings.MsgSaveBoxClearCurrentSuccess; - public override int Execute(SaveFile SAV, BoxManipParam param) + public override int Execute(SaveFile sav, BoxManipParam param) { HashSet.Clear(); bool Method(PKM p) => param.Reverse ^ Criteria(p); - return SAV.ClearBoxes(param.Start, param.Stop, Method); + return sav.ClearBoxes(param.Start, param.Stop, Method); } } } \ No newline at end of file diff --git a/PKHeX.Core/Editing/Saves/BoxManipModify.cs b/PKHeX.Core/Editing/Saves/BoxManipModify.cs index 358fe66c9..5cd984227 100644 --- a/PKHeX.Core/Editing/Saves/BoxManipModify.cs +++ b/PKHeX.Core/Editing/Saves/BoxManipModify.cs @@ -12,6 +12,6 @@ public sealed class BoxManipModify : BoxManipBase public override string GetFail(bool all) => string.Empty; public override string GetSuccess(bool all) => string.Empty; - public override int Execute(SaveFile SAV, BoxManipParam param) => SAV.ModifyBoxes(Action, param.Start, param.Stop); + public override int Execute(SaveFile sav, BoxManipParam param) => sav.ModifyBoxes(Action, param.Start, param.Stop); } } \ No newline at end of file diff --git a/PKHeX.Core/Editing/Saves/BoxManipModifyComplex.cs b/PKHeX.Core/Editing/Saves/BoxManipModifyComplex.cs index d22a14175..25e074344 100644 --- a/PKHeX.Core/Editing/Saves/BoxManipModifyComplex.cs +++ b/PKHeX.Core/Editing/Saves/BoxManipModifyComplex.cs @@ -12,6 +12,6 @@ public sealed class BoxManipModifyComplex : BoxManipBase public override string GetFail(bool all) => string.Empty; public override string GetSuccess(bool all) => string.Empty; - public override int Execute(SaveFile SAV, BoxManipParam param) => SAV.ModifyBoxes(pk => Action(pk, SAV), param.Start, param.Stop); + public override int Execute(SaveFile sav, BoxManipParam param) => sav.ModifyBoxes(pk => Action(pk, sav), param.Start, param.Stop); } } \ No newline at end of file diff --git a/PKHeX.Core/Editing/Saves/BoxManipSort.cs b/PKHeX.Core/Editing/Saves/BoxManipSort.cs index 8cfddb04f..24842f832 100644 --- a/PKHeX.Core/Editing/Saves/BoxManipSort.cs +++ b/PKHeX.Core/Editing/Saves/BoxManipSort.cs @@ -13,10 +13,10 @@ public sealed class BoxManipSort : BoxManipBase public override string GetFail(bool all) => all ? MessageStrings.MsgSaveBoxSortAllFailBattle: MessageStrings.MsgSaveBoxSortCurrentFailBattle; public override string GetSuccess(bool all) => all ? MessageStrings.MsgSaveBoxSortAllSuccess : MessageStrings.MsgSaveBoxSortCurrentSuccess; - public override int Execute(SaveFile SAV, BoxManipParam param) + public override int Execute(SaveFile sav, BoxManipParam param) { IEnumerable Method(IEnumerable p) => Sorter(p); - return SAV.SortBoxes(param.Start, param.Stop, Method, param.Reverse); + return sav.SortBoxes(param.Start, param.Stop, Method, param.Reverse); } } } \ No newline at end of file diff --git a/PKHeX.Core/Editing/Saves/BoxManipSortComplex.cs b/PKHeX.Core/Editing/Saves/BoxManipSortComplex.cs index 330a418a2..6923c5085 100644 --- a/PKHeX.Core/Editing/Saves/BoxManipSortComplex.cs +++ b/PKHeX.Core/Editing/Saves/BoxManipSortComplex.cs @@ -13,10 +13,10 @@ public sealed class BoxManipSortComplex : BoxManipBase public override string GetFail(bool all) => all ? MessageStrings.MsgSaveBoxSortAllFailBattle : MessageStrings.MsgSaveBoxSortCurrentFailBattle; public override string GetSuccess(bool all) => all ? MessageStrings.MsgSaveBoxSortAllSuccess : MessageStrings.MsgSaveBoxSortCurrentSuccess; - public override int Execute(SaveFile SAV, BoxManipParam param) + public override int Execute(SaveFile sav, BoxManipParam param) { - IEnumerable Method(IEnumerable p) => Sorter(p, SAV); - return SAV.SortBoxes(param.Start, param.Stop, Method, param.Reverse); + IEnumerable Method(IEnumerable p) => Sorter(p, sav); + return sav.SortBoxes(param.Start, param.Stop, Method, param.Reverse); } } } \ No newline at end of file diff --git a/PKHeX.Core/Editing/Saves/Editors/EventWork/SplitEventEditor.cs b/PKHeX.Core/Editing/Saves/Editors/EventWork/SplitEventEditor.cs index 84fb4e4be..1bcbb7a37 100644 --- a/PKHeX.Core/Editing/Saves/Editors/EventWork/SplitEventEditor.cs +++ b/PKHeX.Core/Editing/Saves/Editors/EventWork/SplitEventEditor.cs @@ -17,23 +17,23 @@ public SplitEventEditor(IEventWork block, IEnumerable work, IEnumerab { Block = block; // load lines - var worklines = work.Where(z => !string.IsNullOrWhiteSpace(z) && z.Length > 5); - Work = EventWorkUtil.GetVars(worklines, (index, t, data) => new EventWork(index, t, data)); - var flaglines = flag.Where(z => !string.IsNullOrWhiteSpace(z) && z.Length > 5); - Flag = EventWorkUtil.GetVars(flaglines, (index, t, data) => new EventFlag(index, t, data)); + var workLines = work.Where(z => !string.IsNullOrWhiteSpace(z) && z.Length > 5); + Work = EventWorkUtil.GetVars(workLines, (index, t, data) => new EventWork(index, t, data)); + var flagLines = flag.Where(z => !string.IsNullOrWhiteSpace(z) && z.Length > 5); + Flag = EventWorkUtil.GetVars(flagLines, (index, t, data) => new EventFlag(index, t, data)); // initialize lines - foreach (var g in Work) + foreach (var group in Work) { - foreach (var item in g.Vars) + foreach (var item in group.Vars) { item.RawIndex = block.GetWorkRawIndex(item.Type, item.RelativeIndex); ((EventWork)item).Value = block.GetWork(item.RawIndex); } } - foreach (var g in Flag) + foreach (var group in Flag) { - foreach (var item in g.Vars) + foreach (var item in group.Vars) { item.RawIndex = block.GetFlagRawIndex(item.Type, item.RelativeIndex); ((EventFlag)item).Flag = block.GetFlag(item.RawIndex); diff --git a/PKHeX.Core/Editing/Saves/IBoxManip.cs b/PKHeX.Core/Editing/Saves/IBoxManip.cs index 153a66087..593a6b0c2 100644 --- a/PKHeX.Core/Editing/Saves/IBoxManip.cs +++ b/PKHeX.Core/Editing/Saves/IBoxManip.cs @@ -11,6 +11,6 @@ public interface IBoxManip string GetFail(bool all); string GetSuccess(bool all); - int Execute(SaveFile SAV, BoxManipParam param); + int Execute(SaveFile sav, BoxManipParam param); } } \ No newline at end of file diff --git a/PKHeX.Core/Editing/Saves/Slots/Extensions.cs b/PKHeX.Core/Editing/Saves/Slots/Extensions.cs index 8d1bf20c0..bde4bbb31 100644 --- a/PKHeX.Core/Editing/Saves/Slots/Extensions.cs +++ b/PKHeX.Core/Editing/Saves/Slots/Extensions.cs @@ -6,16 +6,16 @@ public static partial class Extensions { public static IReadOnlyList GetAllPKM(this SaveFile sav) { - var pkms = new List(); + var result = new List(); if (sav.HasBox) - pkms.AddRange(sav.BoxData); + result.AddRange(sav.BoxData); if (sav.HasParty) - pkms.AddRange(sav.PartyData); + result.AddRange(sav.PartyData); var extra = sav.GetExtraPKM(); - pkms.AddRange(extra); - pkms.RemoveAll(z => z.Species == 0); - return pkms; + result.AddRange(extra); + result.RemoveAll(z => z.Species == 0); + return result; } public static PKM[] GetExtraPKM(this SaveFile sav) => sav.GetExtraPKM(sav.GetExtraSlots()); diff --git a/PKHeX.Core/Editing/Saves/Slots/Info/ISlotInfo.cs b/PKHeX.Core/Editing/Saves/Slots/Info/ISlotInfo.cs index a9970bfce..24bbc3035 100644 --- a/PKHeX.Core/Editing/Saves/Slots/Info/ISlotInfo.cs +++ b/PKHeX.Core/Editing/Saves/Slots/Info/ISlotInfo.cs @@ -8,8 +8,8 @@ namespace PKHeX.Core public interface ISlotInfo : IEquatable { int Slot { get; } - bool CanWriteTo(SaveFile SAV); - WriteBlockedMessage CanWriteTo(SaveFile SAV, PKM pkm); + bool CanWriteTo(SaveFile sav); + WriteBlockedMessage CanWriteTo(SaveFile sav, PKM pkm); bool WriteTo(SaveFile sav, PKM pkm, PKMImportSetting setting = PKMImportSetting.UseDefault); PKM Read(SaveFile sav); } diff --git a/PKHeX.Core/Editing/Saves/Slots/SlotChangelog.cs b/PKHeX.Core/Editing/Saves/Slots/SlotChangelog.cs index 186d04efc..d3826fa00 100644 --- a/PKHeX.Core/Editing/Saves/Slots/SlotChangelog.cs +++ b/PKHeX.Core/Editing/Saves/Slots/SlotChangelog.cs @@ -78,10 +78,10 @@ private class PartyReversion : SlotReversion private class SingleSlotReversion : SlotReversion { - private readonly PKM pkm; - public SingleSlotReversion(ISlotInfo info, SaveFile sav) : base(info) => pkm = info.Read(sav); + private readonly PKM Entity; + public SingleSlotReversion(ISlotInfo info, SaveFile sav) : base(info) => Entity = info.Read(sav); - public override void Revert(SaveFile sav) => Info.WriteTo(sav, pkm, PKMImportSetting.Skip); + public override void Revert(SaveFile sav) => Info.WriteTo(sav, Entity, PKMImportSetting.Skip); } } } \ No newline at end of file diff --git a/PKHeX.Core/Editing/Saves/Slots/SlotPublisher.cs b/PKHeX.Core/Editing/Saves/Slots/SlotPublisher.cs index 094c57e84..f5bf59cc8 100644 --- a/PKHeX.Core/Editing/Saves/Slots/SlotPublisher.cs +++ b/PKHeX.Core/Editing/Saves/Slots/SlotPublisher.cs @@ -14,7 +14,7 @@ public sealed class SlotPublisher public ISlotInfo? Previous { get; private set; } public SlotTouchType PreviousType { get; private set; } = SlotTouchType.None; - public PKM? PreviousPKM { get; private set; } + public PKM? PreviousEntity { get; private set; } /// /// Notifies all with the latest slot change details. @@ -28,7 +28,7 @@ public void NotifySlotChanged(ISlotInfo slot, SlotTouchType type, PKM pkm) ResetView(sub, slot, type, pkm); Previous = slot; PreviousType = type; - PreviousPKM = pkm; + PreviousEntity = pkm; } private void ResetView(ISlotViewer sub, ISlotInfo slot, SlotTouchType type, PKM pkm) @@ -42,9 +42,9 @@ private void ResetView(ISlotViewer sub, ISlotInfo slot, SlotTouchType type, P public void ResetView(ISlotViewer sub) { - if (Previous == null || PreviousPKM == null) + if (Previous == null || PreviousEntity == null) return; - ResetView(sub, Previous, PreviousType, PreviousPKM); + ResetView(sub, Previous, PreviousType, PreviousEntity); } } } diff --git a/PKHeX.Core/Editing/ShowdownSet.cs b/PKHeX.Core/Editing/ShowdownSet.cs index 5649baa04..2d93d0945 100644 --- a/PKHeX.Core/Editing/ShowdownSet.cs +++ b/PKHeX.Core/Editing/ShowdownSet.cs @@ -383,8 +383,8 @@ private void SetFormString(int index) Form = string.Empty; return; } - var Forms = FormConverter.GetFormList(Species, Strings.Types, Strings.forms, genderForms, Format); - Form = FormIndex >= Forms.Length ? string.Empty : Forms[index]; + var forms = FormConverter.GetFormList(Species, Strings.Types, Strings.forms, genderForms, Format); + Form = FormIndex >= forms.Length ? string.Empty : forms[index]; } private void ParseFirstLine(string first) @@ -392,9 +392,9 @@ private void ParseFirstLine(string first) if (first.Contains(" @ ")) { string[] pieces = first.Split(ItemSplit, StringSplitOptions.None); - string itemstr = pieces[pieces.Length - 1].Trim(); + string itemName = pieces[pieces.Length - 1].Trim(); - ParseItemStr(itemstr); + ParseItemName(itemName); ParseFirstLineNoItem(pieces[0]); } else @@ -403,20 +403,20 @@ private void ParseFirstLine(string first) } } - private void ParseItemStr(string itemstr) + private void ParseItemName(string itemName) { - if (tryGetItem(Format)) + if (TrySetItem(Format)) return; - if (tryGetItem(3)) + if (TrySetItem(3)) return; - if (tryGetItem(2)) + if (TrySetItem(2)) return; - InvalidLines.Add($"Unknown Item: {itemstr}"); + InvalidLines.Add($"Unknown Item: {itemName}"); - bool tryGetItem(int format) + bool TrySetItem(int format) { - var items = (string[])Strings.GetItemStrings(format); // ireadonlylist->string[] must be possible for the provided strings - int item = StringUtil.FindIndexIgnoreCase(items, itemstr); + var items = (string[])Strings.GetItemStrings(format); // IReadOnlyList->string[] must be possible for the provided strings + int item = StringUtil.FindIndexIgnoreCase(items, itemName); if (item < 0) return false; HeldItem = item; @@ -458,7 +458,7 @@ private bool ParseSpeciesForm(string spec) if ((Species = StringUtil.FindIndexIgnoreCase(Strings.specieslist, spec)) >= 0) // success, nothing else! return true; - // Forme string present. + // Form string present. int end = spec.LastIndexOf('-'); if (end < 0) return false; @@ -576,8 +576,8 @@ private void ParseLineIVs(string line) { int pos = i * 2; int index = StringUtil.FindIndexIgnoreCase(StatNames, list[pos + 1]); - if (index >= 0 && byte.TryParse(list[pos + 0], out var IV)) - IVs[index] = IV; + if (index >= 0 && byte.TryParse(list[pos + 0], out var iv)) + IVs[index] = iv; else InvalidLines.Add($"Unknown IV stat: {list[pos]}"); } diff --git a/PKHeX.Core/Editing/WurmpleUtil.cs b/PKHeX.Core/Editing/WurmpleUtil.cs index e13277a14..40a455f43 100644 --- a/PKHeX.Core/Editing/WurmpleUtil.cs +++ b/PKHeX.Core/Editing/WurmpleUtil.cs @@ -5,11 +5,11 @@ public static class WurmpleUtil /// /// Gets the Wurmple Evolution Value for a given /// - /// Encryption Constant + /// Encryption Constant /// Wurmple Evolution Value - public static uint GetWurmpleEvoVal(uint EC) + public static uint GetWurmpleEvoVal(uint encryptionConstant) { - var evoVal = EC >> 16; + var evoVal = encryptionConstant >> 16; return evoVal % 10 / 5; } @@ -32,12 +32,12 @@ public static int GetWurmpleEvoGroup(int species) /// Wurmple Evolution Value /// 0 = Silcoon, 1 = Cascoon /// Encryption Constant - public static uint GetWurmpleEC(int evoVal) + public static uint GetWurmpleEncryptionConstant(int evoVal) { - uint EC; - do EC = Util.Rand32(); - while (evoVal != GetWurmpleEvoVal(EC)); - return EC; + uint result; + do result = Util.Rand32(); + while (evoVal != GetWurmpleEvoVal(result)); + return result; } /// diff --git a/PKHeX.Core/Game/GameStrings/FilteredGameDataSource.cs b/PKHeX.Core/Game/GameStrings/FilteredGameDataSource.cs index a20b43567..1f1a47570 100644 --- a/PKHeX.Core/Game/GameStrings/FilteredGameDataSource.cs +++ b/PKHeX.Core/Game/GameStrings/FilteredGameDataSource.cs @@ -78,24 +78,24 @@ private static IEnumerable GetFilteredMoves(IGameValueLimit sav, Game public IReadOnlyList GetAbilityList(PKM pkm) { - var abils = pkm.PersonalInfo.Abilities; + var abilities = pkm.PersonalInfo.Abilities; int format = pkm.Format; - return GetAbilityList(abils, format); + return GetAbilityList(abilities, format); } - public IReadOnlyList GetAbilityList(int[] abils, int format) + public IReadOnlyList GetAbilityList(IReadOnlyList abilities, int format) { - var count = format == 3 && (abils[1] == 0 || abils[1] == abils[0]) ? 1 : abils.Length; + var count = format == 3 && (abilities[1] == 0 || abilities[1] == abilities[0]) ? 1 : abilities.Count; var list = new ComboItem[count]; for (int i = 0; i < list.Length; i++) { - var ability = abils[i]; - list[i] = new ComboItem(Source.Source.Ability[ability] + abilIdentifier[i], ability); + var ability = abilities[i]; + list[i] = new ComboItem(Source.Source.Ability[ability] + AbilityIndexSuffixes[i], ability); } return list; } - private static readonly string[] abilIdentifier = { " (1)", " (2)", " (H)" }; + private static readonly string[] AbilityIndexSuffixes = { " (1)", " (2)", " (H)" }; } } diff --git a/PKHeX.Core/Game/GameStrings/GameDataSource.cs b/PKHeX.Core/Game/GameStrings/GameDataSource.cs index 0a5a0f29c..16b4be0b0 100644 --- a/PKHeX.Core/Game/GameStrings/GameDataSource.cs +++ b/PKHeX.Core/Game/GameStrings/GameDataSource.cs @@ -85,16 +85,16 @@ private static IReadOnlyList GetVersionList(GameStrings s) private List CreateGen2(GameStrings s) { - var met_list = Util.GetCBList(s.metGSC_00000, Enumerable.Range(0, 0x5F).ToArray()); - Util.AddCBWithOffset(met_list, s.metGSC_00000, 00000, 0x7E, 0x7F); - return met_list; + var locations = Util.GetCBList(s.metGSC_00000, Enumerable.Range(0, 0x5F).ToArray()); + Util.AddCBWithOffset(locations, s.metGSC_00000, 00000, 0x7E, 0x7F); + return locations; } private List CreateGen3(GameStrings s) { - var met_list = Util.GetCBList(s.metRSEFRLG_00000, Enumerable.Range(0, 213).ToArray()); - Util.AddCBWithOffset(met_list, s.metRSEFRLG_00000, 00000, 253, 254, 255); - return met_list; + var locations = Util.GetCBList(s.metRSEFRLG_00000, Enumerable.Range(0, 213).ToArray()); + Util.AddCBWithOffset(locations, s.metRSEFRLG_00000, 00000, 253, 254, 255); + return locations; } private static List CreateGen3CXD(GameStrings s) @@ -104,74 +104,75 @@ private static List CreateGen3CXD(GameStrings s) private static List CreateGen4(GameStrings s) { - var met_list = Util.GetCBList(s.metHGSS_00000, 0); - Util.AddCBWithOffset(met_list, s.metHGSS_02000, 2000, Locations.Daycare4); - Util.AddCBWithOffset(met_list, s.metHGSS_02000, 2000, Locations.LinkTrade4); - Util.AddCBWithOffset(met_list, s.metHGSS_03000, 3000, Locations.Ranger4); - Util.AddCBWithOffset(met_list, s.metHGSS_00000, 0000, Legal.Met_HGSS_0); - Util.AddCBWithOffset(met_list, s.metHGSS_02000, 2000, Legal.Met_HGSS_2); - Util.AddCBWithOffset(met_list, s.metHGSS_03000, 3000, Legal.Met_HGSS_3); - return met_list; + var locations = Util.GetCBList(s.metHGSS_00000, 0); + Util.AddCBWithOffset(locations, s.metHGSS_02000, 2000, Locations.Daycare4); + Util.AddCBWithOffset(locations, s.metHGSS_02000, 2000, Locations.LinkTrade4); + Util.AddCBWithOffset(locations, s.metHGSS_03000, 3000, Locations.Ranger4); + Util.AddCBWithOffset(locations, s.metHGSS_00000, 0000, Legal.Met_HGSS_0); + Util.AddCBWithOffset(locations, s.metHGSS_02000, 2000, Legal.Met_HGSS_2); + Util.AddCBWithOffset(locations, s.metHGSS_03000, 3000, Legal.Met_HGSS_3); + return locations +; } private static List CreateGen5(GameStrings s) { - var met_list = Util.GetCBList(s.metBW2_00000, 0); - Util.AddCBWithOffset(met_list, s.metBW2_60000, 60001, Locations.Daycare5); - Util.AddCBWithOffset(met_list, s.metBW2_30000, 30001, Locations.LinkTrade5); - Util.AddCBWithOffset(met_list, s.metBW2_00000, 00000, Legal.Met_BW2_0); - Util.AddCBWithOffset(met_list, s.metBW2_30000, 30001, Legal.Met_BW2_3); - Util.AddCBWithOffset(met_list, s.metBW2_40000, 40001, Legal.Met_BW2_4); - Util.AddCBWithOffset(met_list, s.metBW2_60000, 60001, Legal.Met_BW2_6); - return met_list; + var locations = Util.GetCBList(s.metBW2_00000, 0); + Util.AddCBWithOffset(locations, s.metBW2_60000, 60001, Locations.Daycare5); + Util.AddCBWithOffset(locations, s.metBW2_30000, 30001, Locations.LinkTrade5); + Util.AddCBWithOffset(locations, s.metBW2_00000, 00000, Legal.Met_BW2_0); + Util.AddCBWithOffset(locations, s.metBW2_30000, 30001, Legal.Met_BW2_3); + Util.AddCBWithOffset(locations, s.metBW2_40000, 40001, Legal.Met_BW2_4); + Util.AddCBWithOffset(locations, s.metBW2_60000, 60001, Legal.Met_BW2_6); + return locations; } private static List CreateGen6(GameStrings s) { - var met_list = Util.GetCBList(s.metXY_00000, 0); - Util.AddCBWithOffset(met_list, s.metXY_60000, 60001, Locations.Daycare5); - Util.AddCBWithOffset(met_list, s.metXY_30000, 30001, Locations.LinkTrade6); - Util.AddCBWithOffset(met_list, s.metXY_00000, 00000, Legal.Met_XY_0); - Util.AddCBWithOffset(met_list, s.metXY_30000, 30001, Legal.Met_XY_3); - Util.AddCBWithOffset(met_list, s.metXY_40000, 40001, Legal.Met_XY_4); - Util.AddCBWithOffset(met_list, s.metXY_60000, 60001, Legal.Met_XY_6); - return met_list; + var locations = Util.GetCBList(s.metXY_00000, 0); + Util.AddCBWithOffset(locations, s.metXY_60000, 60001, Locations.Daycare5); + Util.AddCBWithOffset(locations, s.metXY_30000, 30001, Locations.LinkTrade6); + Util.AddCBWithOffset(locations, s.metXY_00000, 00000, Legal.Met_XY_0); + Util.AddCBWithOffset(locations, s.metXY_30000, 30001, Legal.Met_XY_3); + Util.AddCBWithOffset(locations, s.metXY_40000, 40001, Legal.Met_XY_4); + Util.AddCBWithOffset(locations, s.metXY_60000, 60001, Legal.Met_XY_6); + return locations; } private static List CreateGen7(GameStrings s) { - var met_list = Util.GetCBList(s.metSM_00000, 0); - Util.AddCBWithOffset(met_list, s.metSM_60000, 60001, Locations.Daycare5); - Util.AddCBWithOffset(met_list, s.metSM_30000, 30001, Locations.LinkTrade6); - Util.AddCBWithOffset(met_list, s.metSM_00000, 00000, Legal.Met_SM_0); - Util.AddCBWithOffset(met_list, s.metSM_30000, 30001, Legal.Met_SM_3); - Util.AddCBWithOffset(met_list, s.metSM_40000, 40001, Legal.Met_SM_4); - Util.AddCBWithOffset(met_list, s.metSM_60000, 60001, Legal.Met_SM_6); - return met_list; + var locations = Util.GetCBList(s.metSM_00000, 0); + Util.AddCBWithOffset(locations, s.metSM_60000, 60001, Locations.Daycare5); + Util.AddCBWithOffset(locations, s.metSM_30000, 30001, Locations.LinkTrade6); + Util.AddCBWithOffset(locations, s.metSM_00000, 00000, Legal.Met_SM_0); + Util.AddCBWithOffset(locations, s.metSM_30000, 30001, Legal.Met_SM_3); + Util.AddCBWithOffset(locations, s.metSM_40000, 40001, Legal.Met_SM_4); + Util.AddCBWithOffset(locations, s.metSM_60000, 60001, Legal.Met_SM_6); + return locations; } private static List CreateGen7GG(GameStrings s) { - var met_list = Util.GetCBList(s.metGG_00000, 0); - Util.AddCBWithOffset(met_list, s.metGG_60000, 60001, 60002); - Util.AddCBWithOffset(met_list, s.metGG_30000, 30001, Locations.LinkTrade6); - Util.AddCBWithOffset(met_list, s.metGG_00000, 00000, Legal.Met_GG_0); - Util.AddCBWithOffset(met_list, s.metGG_30000, 30001, Legal.Met_GG_3); - Util.AddCBWithOffset(met_list, s.metGG_40000, 40001, Legal.Met_GG_4); - Util.AddCBWithOffset(met_list, s.metGG_60000, 60001, Legal.Met_GG_6); - return met_list; + var locations = Util.GetCBList(s.metGG_00000, 0); + Util.AddCBWithOffset(locations, s.metGG_60000, 60001, 60002); + Util.AddCBWithOffset(locations, s.metGG_30000, 30001, Locations.LinkTrade6); + Util.AddCBWithOffset(locations, s.metGG_00000, 00000, Legal.Met_GG_0); + Util.AddCBWithOffset(locations, s.metGG_30000, 30001, Legal.Met_GG_3); + Util.AddCBWithOffset(locations, s.metGG_40000, 40001, Legal.Met_GG_4); + Util.AddCBWithOffset(locations, s.metGG_60000, 60001, Legal.Met_GG_6); + return locations; } private static List CreateGen8(GameStrings s) { - var met_list = Util.GetCBList(s.metSWSH_00000, 0); - Util.AddCBWithOffset(met_list, s.metSWSH_60000, 60001, 60002); - Util.AddCBWithOffset(met_list, s.metSWSH_30000, 30001, Locations.LinkTrade6); - Util.AddCBWithOffset(met_list, s.metSWSH_00000, 00000, Legal.Met_SWSH_0); - Util.AddCBWithOffset(met_list, s.metSWSH_30000, 30001, Legal.Met_SWSH_3); - Util.AddCBWithOffset(met_list, s.metSWSH_40000, 40001, Legal.Met_SWSH_4); - Util.AddCBWithOffset(met_list, s.metSWSH_60000, 60001, Legal.Met_SWSH_6); - return met_list; + var locations = Util.GetCBList(s.metSWSH_00000, 0); + Util.AddCBWithOffset(locations, s.metSWSH_60000, 60001, 60002); + Util.AddCBWithOffset(locations, s.metSWSH_30000, 30001, Locations.LinkTrade6); + Util.AddCBWithOffset(locations, s.metSWSH_00000, 00000, Legal.Met_SWSH_0); + Util.AddCBWithOffset(locations, s.metSWSH_30000, 30001, Legal.Met_SWSH_3); + Util.AddCBWithOffset(locations, s.metSWSH_40000, 40001, Legal.Met_SWSH_4); + Util.AddCBWithOffset(locations, s.metSWSH_60000, 60001, Legal.Met_SWSH_6); + return locations; } public List GetItemDataSource(GameVersion game, int generation, IReadOnlyList allowed, bool HaX = false) @@ -184,7 +185,7 @@ public List GetItemDataSource(GameVersion game, int generation, IRead /// Fetches a Met Location list for a that has been transferred away from and overwritten. /// /// Origin version - /// Current savefile generation + /// Current save file generation /// True if an egg location list, false if a regular met location list /// Met location list public IReadOnlyList GetLocationList(GameVersion version, int currentGen, bool egg = false) @@ -274,7 +275,7 @@ public IReadOnlyList GetLocationList(GameVersion version, int current case GameVersion.SW: case GameVersion.SH: - return MetGen8.Take(3).Concat(MetGen8.Skip(3).OrderByDescending(loc => loc.Value < 400)).ToList(); // todo + return MetGen8.Take(3).Concat(MetGen8.Skip(3).OrderByDescending(loc => loc.Value < 400)).ToList(); } return GetLocationListModified(version, currentGen); @@ -284,7 +285,7 @@ public IReadOnlyList GetLocationList(GameVersion version, int current /// Fetches a Met Location list for a that has been transferred away from and overwritten. /// /// Origin version - /// Current savefile generation + /// Current save file generation /// Met location list private IReadOnlyList GetLocationListModified(GameVersion version, int currentGen) { diff --git a/PKHeX.Core/Game/GameStrings/GameInfo.cs b/PKHeX.Core/Game/GameStrings/GameInfo.cs index 75dc54455..ae35ff3e7 100644 --- a/PKHeX.Core/Game/GameStrings/GameInfo.cs +++ b/PKHeX.Core/Game/GameStrings/GameInfo.cs @@ -57,15 +57,15 @@ public static string GetVersionName(GameVersion version) /// /// Gets the location name for the specified parameters. /// - /// Location is from the - /// Location value + /// Location is from the + /// Location value /// Current /// of origin /// Current GameVersion (only applicable for differentiation) /// Location name - public static string GetLocationName(bool eggmet, int locval, int format, int generation, GameVersion version) + public static string GetLocationName(bool isEggLocation, int location, int format, int generation, GameVersion version) { - return Strings.GetLocationName(eggmet, locval, format, generation, version); + return Strings.GetLocationName(isEggLocation, location, format, generation, version); } /// diff --git a/PKHeX.Core/Game/GameStrings/GameStrings.cs b/PKHeX.Core/Game/GameStrings/GameStrings.cs index 12461f5f2..d78788a51 100644 --- a/PKHeX.Core/Game/GameStrings/GameStrings.cs +++ b/PKHeX.Core/Game/GameStrings/GameStrings.cs @@ -388,22 +388,22 @@ private string[] GetItemStrings3(GameVersion game) if (Legal.EReaderBerryIsEnigma) return g3items; - var g3itemsEBerry = (string[])g3items.Clone(); - g3itemsEBerry[175] = Legal.EReaderBerryDisplayName; - return g3itemsEBerry; + var g3ItemsWithEBerry = (string[])g3items.Clone(); + g3ItemsWithEBerry[175] = Legal.EReaderBerryDisplayName; + return g3ItemsWithEBerry; } } /// /// Gets the location name for the specified parameters. /// - /// Location is from the - /// Location value + /// Location is from the + /// Location value /// Current /// of origin /// Current GameVersion (only applicable for differentiation) /// Location name - public string GetLocationName(bool eggmet, int locval, int format, int generation, GameVersion version) + public string GetLocationName(bool isEggLocation, int location, int format, int generation, GameVersion version) { int gen = -1; int bankID = 0; @@ -416,17 +416,17 @@ public string GetLocationName(bool eggmet, int locval, int format, int generatio { gen = 3; } - else if (generation == 4 && (eggmet || format == 4)) // 4 + else if (generation == 4 && (isEggLocation || format == 4)) // 4 { const int size = 1000; - bankID = locval / size; + bankID = location / size; gen = 4; - locval %= size; + location %= size; } else // 5-7+ { const int size = 10000; - bankID = locval / size; + bankID = location / size; int g = generation; if (g >= 5) @@ -434,15 +434,15 @@ public string GetLocationName(bool eggmet, int locval, int format, int generatio else if (format >= 5) gen = format; - locval %= size; + location %= size; if (bankID >= 3) // 30000 and onwards don't use 0th index, shift down 1 - locval--; + location--; } var bank = GetLocationNames(gen, bankID, version); - if (bank.Count <= locval) + if (bank.Count <= location) return string.Empty; - return bank[locval]; + return bank[location]; } /// diff --git a/PKHeX.Core/Game/GameStrings/GeoLocation.cs b/PKHeX.Core/Game/GameStrings/GeoLocation.cs index 6dd707617..485ce46a6 100644 --- a/PKHeX.Core/Game/GameStrings/GeoLocation.cs +++ b/PKHeX.Core/Game/GameStrings/GeoLocation.cs @@ -43,28 +43,28 @@ private static string[] GetEntry(string line, out int index) return entries; } - private static string GetCountryName(int countryID, int l) + private static string GetCountryName(int country, int l) { if (l < 0) return INVALID; - if (countryID >= CountryList.Length) + if (country >= CountryList.Length) return INVALID; - var countryNames = CountryList[countryID]; + var countryNames = CountryList[country]; if (l < countryNames.Length) return countryNames[l + 1]; return INVALID; } - private static string GetRegionName(int countryID, int regionID, int l) + private static string GetRegionName(int country, int region, int l) { if (l < 0) return INVALID; - if (countryID >= RegionList.Length) + if (country >= RegionList.Length) return INVALID; - var regionstrs = RegionList[countryID] ?? (RegionList[countryID] = GetRegionList(countryID)); - if (regionID >= regionstrs.Length) + var regionNames = RegionList[country] ?? (RegionList[country] = GetRegionList(country)); + if (region >= regionNames.Length) return INVALID; - var localized = regionstrs[regionID]; + var localized = regionNames[region]; if (l < localized.Length) return localized[l + 1]; return INVALID; @@ -107,17 +107,17 @@ private static string GetRegionName(int countryID, int regionID, int l) /// /// Gets Country and Region strings for corresponding IDs and language. /// - /// Country ID - /// Region ID + /// Country ID + /// Region ID /// Language ID /// Tuple containing country and region - public static Tuple GetCountryRegionText(int countryID, int regionID, string language) + public static Tuple GetCountryRegionText(int country, int region, string language) { // Get Language we're fetching for int lang = Array.IndexOf(lang_geo, language); - var country = GetCountryName(countryID, lang); - var region = GetRegionName(countryID, regionID, lang); - return new Tuple(country, region); // country, region + var countryName = GetCountryName(country, lang); + var regionName = GetRegionName(country, region, lang); + return new Tuple(countryName, regionName); // country, region } private static int GetLanguageIndex(string language) => Array.IndexOf(lang_geo, language); diff --git a/PKHeX.Core/Game/GameUtil.cs b/PKHeX.Core/Game/GameUtil.cs index ac1fe9a13..829daa6b1 100644 --- a/PKHeX.Core/Game/GameUtil.cs +++ b/PKHeX.Core/Game/GameUtil.cs @@ -28,13 +28,13 @@ public static class GameUtil public const GameVersion HighestGameID = RB - 1; /// Determines the Version Grouping of an input Version ID - /// Version of which to determine the group + /// Version of which to determine the group /// Version Group Identifier or Invalid if type cannot be determined. - public static GameVersion GetMetLocationVersionGroup(GameVersion Version) + public static GameVersion GetMetLocationVersionGroup(GameVersion version) { - switch (Version) + switch (version) { - // Sidegame + // Side games case CXD: return CXD; case GO: @@ -267,12 +267,13 @@ public static IEnumerable GetVersionsWithinRange(IGameValueLimit ob { if (obj.MaxGameID == Legal.MaxGameID_7b) // edge case return new[] {GO, GP, GE}; - var vers = GameVersions.Where(z => z >= (GameVersion)obj.MinGameID && z <= (GameVersion)obj.MaxGameID); + var versions = GameVersions + .Where(version => (GameVersion)obj.MinGameID <= version && version <= (GameVersion)obj.MaxGameID); if (generation < 0) - return vers; + return versions; if (obj.MaxGameID == Legal.MaxGameID_7 && generation == 7) - vers = vers.Where(z => z != GO); - return vers.Where(z => z.GetGeneration() <= generation); + versions = versions.Where(version => version != GO); + return versions.Where(version => version.GetGeneration() <= generation); } } } diff --git a/PKHeX.Core/Legality/Encounters/Data/EncountersWC3.cs b/PKHeX.Core/Legality/Encounters/Data/EncountersWC3.cs index 28ef25799..cabd1d539 100644 --- a/PKHeX.Core/Legality/Encounters/Data/EncountersWC3.cs +++ b/PKHeX.Core/Legality/Encounters/Data/EncountersWC3.cs @@ -25,9 +25,9 @@ internal static class EncountersWC3 private static IEnumerable GetIngameCXDData() { var langs = new[]{LanguageID.Japanese, LanguageID.English, LanguageID.French, LanguageID.Italian, LanguageID.German, LanguageID.Spanish}; - var h = new[] {string.Empty, "ダニー", "HORDEL", "VOLKER", "ODINO", "HORAZ", string.Empty, "HORDEL"}; - var d = new[] {string.Empty, "ギンザル", "DUKING", "DOKING", "RODRIGO", "GRAND", string.Empty, "GERMÁN"}; - var m = new[] {string.Empty, "バトルやま", "MATTLE", "MT BATAILL", "MONTE LOTT", "DUELLBERG", string.Empty, "ERNESTO"}; // truncated on ck3->pk3 transfer + string[] h = {string.Empty, "ダニー", "HORDEL", "VOLKER", "ODINO", "HORAZ", string.Empty, "HORDEL"}; + string[] d = {string.Empty, "ギンザル", "DUKING", "DOKING", "RODRIGO", "GRAND", string.Empty, "GERMÁN"}; + string[] m = {string.Empty, "バトルやま", "MATTLE", "MT BATAILL", "MONTE LOTT", "DUELLBERG", string.Empty, "ERNESTO"}; // truncated on ck3->pk3 transfer return langs.SelectMany(l => GetIngame((int)l)); IEnumerable GetIngame(int l) diff --git a/PKHeX.Core/Legality/Encounters/EncounterMisc/EncounterEgg.cs b/PKHeX.Core/Legality/Encounters/EncounterMisc/EncounterEgg.cs index ed0fa1315..8a08ed7e2 100644 --- a/PKHeX.Core/Legality/Encounters/EncounterMisc/EncounterEgg.cs +++ b/PKHeX.Core/Legality/Encounters/EncounterMisc/EncounterEgg.cs @@ -28,18 +28,18 @@ public EncounterEgg(int species, int form, int level, int gen, GameVersion game) Version = game; } - public PKM ConvertToPKM(ITrainerInfo SAV) => ConvertToPKM(SAV, EncounterCriteria.Unrestricted); + public PKM ConvertToPKM(ITrainerInfo sav) => ConvertToPKM(sav, EncounterCriteria.Unrestricted); - public PKM ConvertToPKM(ITrainerInfo SAV, EncounterCriteria criteria) + public PKM ConvertToPKM(ITrainerInfo sav, EncounterCriteria criteria) { int gen = Generation; var version = Version; var pk = PKMConverter.GetBlank(gen, version); - SAV.ApplyToPKM(pk); + sav.ApplyTo(pk); pk.Species = Species; - pk.Nickname = SpeciesName.GetSpeciesNameGeneration(Species, SAV.Language, gen); + pk.Nickname = SpeciesName.GetSpeciesNameGeneration(Species, sav.Language, gen); pk.CurrentLevel = Level; pk.Version = (int)version; pk.Ball = (int)Ball.Poke; @@ -57,14 +57,14 @@ public PKM ConvertToPKM(ITrainerInfo SAV, EncounterCriteria criteria) return pk; if (gen >= 4) - pk.SetEggMetData(version, (GameVersion)SAV.Game); + pk.SetEggMetData(version, (GameVersion)sav.Game); if (gen < 6) return pk; if (gen == 6) pk.SetHatchMemory6(); - SetAltForm(pk, SAV); + SetAltForm(pk, sav); pk.SetRandomEC(); pk.RelearnMoves = moves; @@ -72,7 +72,7 @@ public PKM ConvertToPKM(ITrainerInfo SAV, EncounterCriteria criteria) return pk; } - private void SetAltForm(PKM pk, ITrainerInfo SAV) + private void SetAltForm(PKM pk, ITrainerInfo sav) { switch (Species) { @@ -82,7 +82,7 @@ private void SetAltForm(PKM pk, ITrainerInfo SAV) case (int)Core.Species.Scatterbug: case (int)Core.Species.Spewpa: case (int)Core.Species.Vivillon: - pk.AltForm = Legal.GetVivillonPattern((byte)SAV.Country, (byte)SAV.SubRegion); + pk.AltForm = Legal.GetVivillonPattern((byte)sav.Country, (byte)sav.SubRegion); break; } } diff --git a/PKHeX.Core/Legality/Encounters/EncounterMisc/EncounterInvalid.cs b/PKHeX.Core/Legality/Encounters/EncounterMisc/EncounterInvalid.cs index e91125fe7..d7b04d11f 100644 --- a/PKHeX.Core/Legality/Encounters/EncounterMisc/EncounterInvalid.cs +++ b/PKHeX.Core/Legality/Encounters/EncounterMisc/EncounterInvalid.cs @@ -33,7 +33,7 @@ public EncounterInvalid(PKM pkm) Version = (GameVersion)pkm.Version; } - public PKM ConvertToPKM(ITrainerInfo SAV) => ConvertToPKM(SAV, EncounterCriteria.Unrestricted); - public PKM ConvertToPKM(ITrainerInfo SAV, EncounterCriteria criteria) => throw new ArgumentException($"Cannot convert an {nameof(EncounterInvalid)} to PKM."); + public PKM ConvertToPKM(ITrainerInfo sav) => ConvertToPKM(sav, EncounterCriteria.Unrestricted); + public PKM ConvertToPKM(ITrainerInfo sav, EncounterCriteria criteria) => throw new ArgumentException($"Cannot convert an {nameof(EncounterInvalid)} to PKM."); } } diff --git a/PKHeX.Core/Legality/Encounters/EncounterMisc/EncounterRejected.cs b/PKHeX.Core/Legality/Encounters/EncounterMisc/EncounterRejected.cs index b2a405355..c747a7681 100644 --- a/PKHeX.Core/Legality/Encounters/EncounterMisc/EncounterRejected.cs +++ b/PKHeX.Core/Legality/Encounters/EncounterMisc/EncounterRejected.cs @@ -27,7 +27,7 @@ public EncounterRejected(IEncounterable encounter, CheckResult check) Check = check; } - public PKM ConvertToPKM(ITrainerInfo SAV) => ConvertToPKM(SAV, EncounterCriteria.Unrestricted); - public PKM ConvertToPKM(ITrainerInfo SAV, EncounterCriteria criteria) => throw new ArgumentException($"Cannot convert an {nameof(EncounterRejected)} to PKM."); + public PKM ConvertToPKM(ITrainerInfo sav) => ConvertToPKM(sav, EncounterCriteria.Unrestricted); + public PKM ConvertToPKM(ITrainerInfo sav, EncounterCriteria criteria) => throw new ArgumentException($"Cannot convert an {nameof(EncounterRejected)} to PKM."); } } \ No newline at end of file diff --git a/PKHeX.Core/Legality/Encounters/EncounterSlot/EncounterSlot.cs b/PKHeX.Core/Legality/Encounters/EncounterSlot/EncounterSlot.cs index 2b21f641f..372e53898 100644 --- a/PKHeX.Core/Legality/Encounters/EncounterSlot/EncounterSlot.cs +++ b/PKHeX.Core/Legality/Encounters/EncounterSlot/EncounterSlot.cs @@ -84,15 +84,15 @@ public virtual string LongName } } - public PKM ConvertToPKM(ITrainerInfo SAV) => ConvertToPKM(SAV, EncounterCriteria.Unrestricted); + public PKM ConvertToPKM(ITrainerInfo sav) => ConvertToPKM(sav, EncounterCriteria.Unrestricted); - public PKM ConvertToPKM(ITrainerInfo SAV, EncounterCriteria criteria) + public PKM ConvertToPKM(ITrainerInfo sav, EncounterCriteria criteria) { - var version = this.GetCompatibleVersion((GameVersion)SAV.Game); - int lang = (int)Language.GetSafeLanguage(Generation, (LanguageID)SAV.Language); + var version = this.GetCompatibleVersion((GameVersion)sav.Game); + int lang = (int)Language.GetSafeLanguage(Generation, (LanguageID)sav.Language); int level = LevelMin; var pk = PKMConverter.GetBlank(Generation, Version); - SAV.ApplyToPKM(pk); + sav.ApplyTo(pk); pk.Species = Species; pk.Language = lang; @@ -102,7 +102,7 @@ public PKM ConvertToPKM(ITrainerInfo SAV, EncounterCriteria criteria) pk.Ball = (int)Type.GetBall(); pk.Language = lang; pk.OT_Friendship = pk.PersonalInfo.BaseFriendship; - pk.AltForm = GetWildAltForm(pk, Form, SAV); + pk.AltForm = GetWildAltForm(pk, Form, sav); SetMetData(pk, level, Location); SetPINGA(pk, criteria); @@ -113,7 +113,7 @@ public PKM ConvertToPKM(ITrainerInfo SAV, EncounterCriteria criteria) if (pk.Format < 6) return pk; - SAV.ApplyHandlingTrainerInfo(pk); + sav.ApplyHandlingTrainerInfo(pk); pk.SetRandomEC(); return pk; @@ -191,7 +191,7 @@ private void SetMetData(PKM pk, int level, int location) pk.MetDate = DateTime.Today; } - private static int GetWildAltForm(PKM pk, int form, ITrainerInfo SAV) + private static int GetWildAltForm(PKM pk, int form, ITrainerInfo sav) { if (form < 30) // specified form { @@ -204,7 +204,7 @@ private static int GetWildAltForm(PKM pk, int form, ITrainerInfo SAV) int spec = pk.Species; if (spec == (int)Core.Species.Scatterbug || spec == (int)Core.Species.Spewpa || spec == (int)Core.Species.Vivillon) - return Legal.GetVivillonPattern((byte)SAV.Country, (byte)SAV.SubRegion); + return Legal.GetVivillonPattern((byte)sav.Country, (byte)sav.SubRegion); return 0; } diff --git a/PKHeX.Core/Legality/Encounters/EncounterStatic/EncounterStatic.cs b/PKHeX.Core/Legality/Encounters/EncounterStatic/EncounterStatic.cs index e92251a28..d9fb72001 100644 --- a/PKHeX.Core/Legality/Encounters/EncounterStatic/EncounterStatic.cs +++ b/PKHeX.Core/Legality/Encounters/EncounterStatic/EncounterStatic.cs @@ -56,20 +56,20 @@ public class EncounterStatic : IEncounterable, IMoveset, IGenerationSet, ILocati public string Name => _name; public string LongName => Version == GameVersion.Any ? _name : $"{_name} ({Version})"; - public PKM ConvertToPKM(ITrainerInfo SAV) => ConvertToPKM(SAV, EncounterCriteria.Unrestricted); + public PKM ConvertToPKM(ITrainerInfo sav) => ConvertToPKM(sav, EncounterCriteria.Unrestricted); - public PKM ConvertToPKM(ITrainerInfo SAV, EncounterCriteria criteria) + public PKM ConvertToPKM(ITrainerInfo sav, EncounterCriteria criteria) { var pk = PKMConverter.GetBlank(Generation, Version); - SAV.ApplyToPKM(pk); + sav.ApplyTo(pk); pk.EncryptionConstant = Util.Rand32(); pk.Species = Species; pk.AltForm = Form; - int lang = (int)Language.GetSafeLanguage(Generation, (LanguageID)SAV.Language); + int lang = (int)Language.GetSafeLanguage(Generation, (LanguageID)sav.Language); int level = GetMinimalLevel(); - var version = this.GetCompatibleVersion((GameVersion)SAV.Game); + var version = this.GetCompatibleVersion((GameVersion)sav.Game); SanityCheckVersion(ref version); pk.Language = lang = GetEdgeCaseLanguage(pk, lang); @@ -84,7 +84,7 @@ public PKM ConvertToPKM(ITrainerInfo SAV, EncounterCriteria criteria) var today = DateTime.Today; SetMetData(pk, level, today); if (EggEncounter) - SetEggMetData(pk, SAV, today); + SetEggMetData(pk, sav, today); SetPINGA(pk, criteria); SetEncounterMoves(pk, version, level); @@ -115,7 +115,7 @@ public PKM ConvertToPKM(ITrainerInfo SAV, EncounterCriteria criteria) return pk; pk.SetRelearnMoves(Relearn); - SAV.ApplyHandlingTrainerInfo(pk); + sav.ApplyHandlingTrainerInfo(pk); pk.SetRandomEC(); if (this is IGigantamax g && pk is IGigantamax pg) diff --git a/PKHeX.Core/Legality/Encounters/EncounterTrade/EncounterTrade.cs b/PKHeX.Core/Legality/Encounters/EncounterTrade/EncounterTrade.cs index 6bb2ba56e..5018567f3 100644 --- a/PKHeX.Core/Legality/Encounters/EncounterTrade/EncounterTrade.cs +++ b/PKHeX.Core/Legality/Encounters/EncounterTrade/EncounterTrade.cs @@ -78,21 +78,21 @@ public int TID7 Locations.LinkTrade6NPC, // 8 is same as 6 }; - public PKM ConvertToPKM(ITrainerInfo SAV) => ConvertToPKM(SAV, EncounterCriteria.Unrestricted); + public PKM ConvertToPKM(ITrainerInfo sav) => ConvertToPKM(sav, EncounterCriteria.Unrestricted); - public PKM ConvertToPKM(ITrainerInfo SAV, EncounterCriteria criteria) + public PKM ConvertToPKM(ITrainerInfo sav, EncounterCriteria criteria) { var pk = PKMConverter.GetBlank(Generation, Version); - SAV.ApplyToPKM(pk); + sav.ApplyTo(pk); - ApplyDetails(SAV, criteria, pk); + ApplyDetails(sav, criteria, pk); return pk; } - protected virtual void ApplyDetails(ITrainerInfo SAV, EncounterCriteria criteria, PKM pk) + protected virtual void ApplyDetails(ITrainerInfo sav, EncounterCriteria criteria, PKM pk) { - var version = this.GetCompatibleVersion((GameVersion)SAV.Game); - int lang = (int)Language.GetSafeLanguage(Generation, (LanguageID)SAV.Language); + var version = this.GetCompatibleVersion((GameVersion)sav.Game); + int lang = (int)Language.GetSafeLanguage(Generation, (LanguageID)sav.Language); int level = CurrentLevel > 0 ? CurrentLevel : LevelMin; if (level == 0) level = Math.Max(1, LevelMin); @@ -105,8 +105,8 @@ protected virtual void ApplyDetails(ITrainerInfo SAV, EncounterCriteria criteria pk.Species = species; pk.AltForm = Form; pk.Language = lang; - pk.OT_Name = pk.Format == 1 ? StringConverter12.G1TradeOTStr : HasTrainerName ? GetOT(lang) : SAV.OT; - pk.OT_Gender = HasTrainerName ? Math.Max(0, OTGender) : SAV.Gender; + pk.OT_Name = pk.Format == 1 ? StringConverter12.G1TradeOTStr : HasTrainerName ? GetOT(lang) : sav.OT; + pk.OT_Gender = HasTrainerName ? Math.Max(0, OTGender) : sav.Gender; pk.SetNickname(GetNickname(lang)); pk.CurrentLevel = level; @@ -143,7 +143,7 @@ protected virtual void ApplyDetails(ITrainerInfo SAV, EncounterCriteria criteria if (pk.Format < 6) return; - SAV.ApplyHandlingTrainerInfo(pk, force: true); + sav.ApplyHandlingTrainerInfo(pk, force: true); pk.SetRandomEC(); if (pk.Format == 6) @@ -416,9 +416,9 @@ public EncounterTrade6(int m, int i, int f, int v) OT_TextVar = v; } - protected override void ApplyDetails(ITrainerInfo SAV, EncounterCriteria criteria, PKM pk) + protected override void ApplyDetails(ITrainerInfo sav, EncounterCriteria criteria, PKM pk) { - base.ApplyDetails(SAV, criteria, pk); + base.ApplyDetails(sav, criteria, pk); pk.OT_Memory = OT_Memory; pk.OT_Intensity = OT_Intensity; pk.OT_Feeling = OT_Feeling; @@ -433,9 +433,9 @@ public sealed class EncounterTrade7 : EncounterTrade, IMemoryOT public int OT_Feeling => 5; public int OT_TextVar => 40; - protected override void ApplyDetails(ITrainerInfo SAV, EncounterCriteria criteria, PKM pk) + protected override void ApplyDetails(ITrainerInfo sav, EncounterCriteria criteria, PKM pk) { - base.ApplyDetails(SAV, criteria, pk); + base.ApplyDetails(sav, criteria, pk); pk.OT_Memory = OT_Memory; pk.OT_Intensity = OT_Intensity; pk.OT_Feeling = OT_Feeling; diff --git a/PKHeX.Core/Legality/Encounters/EncounterTrade/EncounterTrade8.cs b/PKHeX.Core/Legality/Encounters/EncounterTrade/EncounterTrade8.cs index 345c653ad..8a992085d 100644 --- a/PKHeX.Core/Legality/Encounters/EncounterTrade/EncounterTrade8.cs +++ b/PKHeX.Core/Legality/Encounters/EncounterTrade/EncounterTrade8.cs @@ -31,14 +31,14 @@ public override bool IsMatch(PKM pkm, int lvl) return base.IsMatch(pkm, lvl); } - protected override void ApplyDetails(ITrainerInfo SAV, EncounterCriteria criteria, PKM pk) + protected override void ApplyDetails(ITrainerInfo sav, EncounterCriteria criteria, PKM pk) { - base.ApplyDetails(SAV, criteria, pk); + base.ApplyDetails(sav, criteria, pk); pk.SetRelearnMoves(Relearn); var pk8 = (PK8)pk; pk8.DynamaxLevel = DynamaxLevel; - pk8.HT_Language = SAV.Language; + pk8.HT_Language = sav.Language; pk8.OT_Memory = OT_Memory; pk8.OT_TextVar = OT_TextVar; pk8.OT_Feeling = OT_Feeling; diff --git a/PKHeX.Core/Legality/Encounters/IEncounterable.cs b/PKHeX.Core/Legality/Encounters/IEncounterable.cs index 70b85eecc..e7c084cbf 100644 --- a/PKHeX.Core/Legality/Encounters/IEncounterable.cs +++ b/PKHeX.Core/Legality/Encounters/IEncounterable.cs @@ -14,8 +14,8 @@ public interface IEncounterable : IVersion int LevelMax { get; } int Generation { get; } - PKM ConvertToPKM(ITrainerInfo SAV); - PKM ConvertToPKM(ITrainerInfo SAV, EncounterCriteria criteria); + PKM ConvertToPKM(ITrainerInfo sav); + PKM ConvertToPKM(ITrainerInfo sav, EncounterCriteria criteria); } public static partial class Extensions diff --git a/PKHeX.Core/Legality/Structures/ITrainerInfo.cs b/PKHeX.Core/Legality/Structures/ITrainerInfo.cs index 2a1af2ccc..56ed8dab2 100644 --- a/PKHeX.Core/Legality/Structures/ITrainerInfo.cs +++ b/PKHeX.Core/Legality/Structures/ITrainerInfo.cs @@ -19,7 +19,7 @@ public interface ITrainerInfo : ITrainerID public static partial class Extensions { - public static void ApplyToPKM(this ITrainerInfo info, PKM pk) + public static void ApplyTo(this ITrainerInfo info, PKM pk) { pk.OT_Name = info.OT; pk.TID = info.TID; @@ -35,21 +35,21 @@ public static void ApplyToPKM(this ITrainerInfo info, PKM pk) pk.ConsoleRegion = info.ConsoleRegion; } - public static void ApplyHandlingTrainerInfo(this ITrainerInfo SAV, PKM pk, bool force = false) + public static void ApplyHandlingTrainerInfo(this ITrainerInfo sav, PKM pk, bool force = false) { - if (pk.Format == SAV.Generation && !force) + if (pk.Format == sav.Generation && !force) return; - pk.HT_Name = SAV.OT; - pk.HT_Gender = SAV.Gender; + pk.HT_Name = sav.OT; + pk.HT_Gender = sav.Gender; pk.HT_Friendship = pk.OT_Friendship; pk.CurrentHandler = 1; if (pk.Format == 6) { var g = (IGeoTrack) pk; - g.Geo1_Country = SAV.Country; - g.Geo1_Region = SAV.SubRegion; + g.Geo1_Country = sav.Country; + g.Geo1_Region = sav.SubRegion; ((PK6)pk).TradeMemory(true); } } diff --git a/PKHeX.Core/Legality/Verifiers/Ribbons/RibbonVerifier.cs b/PKHeX.Core/Legality/Verifiers/Ribbons/RibbonVerifier.cs index bcc83cf99..d62d13b94 100644 --- a/PKHeX.Core/Legality/Verifiers/Ribbons/RibbonVerifier.cs +++ b/PKHeX.Core/Legality/Verifiers/Ribbons/RibbonVerifier.cs @@ -14,11 +14,11 @@ public sealed class RibbonVerifier : Verifier public override void Verify(LegalityAnalysis data) { - var EncounterMatch = data.EncounterMatch; + var encounter = data.EncounterMatch; var pkm = data.pkm; var Info = data.Info; // Check Unobtainable Ribbons - var encounterContent = EncounterMatch is MysteryGift mg ? mg.Content : EncounterMatch; + var encounterContent = encounter is MysteryGift mg ? mg.Content : encounter; if (pkm.IsEgg) { if (GetIncorrectRibbonsEgg(pkm, encounterContent)) @@ -57,17 +57,17 @@ private static List GetIncorrectRibbons(PKM pkm, object encounterContent private static bool GetIncorrectRibbonsEgg(PKM pkm, object encounterContent) { - var RibbonNames = ReflectUtil.GetPropertiesStartWithPrefix(pkm.GetType(), "Ribbon"); + var names = ReflectUtil.GetPropertiesStartWithPrefix(pkm.GetType(), "Ribbon"); if (encounterContent is IRibbonSetEvent3 event3) - RibbonNames = RibbonNames.Except(event3.RibbonNames()); + names = names.Except(event3.RibbonNames()); if (encounterContent is IRibbonSetEvent4 event4) - RibbonNames = RibbonNames.Except(event4.RibbonNames()); + names = names.Except(event4.RibbonNames()); - foreach (var RibbonValue in RibbonNames.Select(RibbonName => ReflectUtil.GetValue(pkm, RibbonName))) + foreach (var value in names.Select(name => ReflectUtil.GetValue(pkm, name))) { - if (RibbonValue is null) + if (value is null) continue; - if (HasFlag(RibbonValue) || HasCount(RibbonValue)) + if (HasFlag(value) || HasCount(value)) return true; static bool HasFlag(object o) => o is bool z && z; @@ -100,6 +100,7 @@ private static IEnumerable GetInvalidRibbons(PKM pkm, int gen) yield return new RibbonResult(nameof(u3.RibbonVictory)); } } + if (pkm is IRibbonSetUnique4 u4) { if (!IsAllowedBattleFrontier(pkm.Species, pkm.AltForm, 4) || gen > 4) @@ -108,30 +109,20 @@ private static IEnumerable GetInvalidRibbons(PKM pkm, int gen) yield return z; } - var c3 = u4.RibbonBitsContest3(); var c3n = u4.RibbonNamesContest3(); - var c4 = u4.RibbonBitsContest4(); var c4n = u4.RibbonNamesContest4(); - var iter3 = gen == 3 ? getMissingContestRibbons(c3, c3n) : GetInvalidRibbonsNone(c3, c3n); - var iter4 = (gen == 3 || gen == 4) && IsAllowedInContest4(pkm.Species) ? getMissingContestRibbons(c4, c4n) : GetInvalidRibbonsNone(c4, c4n); - foreach (var z in iter3.Concat(iter4)) + var c3 = u4.RibbonBitsContest3(); + var c3n = u4.RibbonNamesContest3(); + var iter3 = gen == 3 ? GetMissingContestRibbons(c3, c3n) : GetInvalidRibbonsNone(c3, c3n); + foreach (var z in iter3) yield return z; for (int i = 0; i < 5; ++i) artist |= c3[3 | i << 2]; // any master rank ribbon - static IEnumerable getMissingContestRibbons(IReadOnlyList bits, IReadOnlyList names) - { - for (int i = 0; i < bits.Count; i += 4) - { - bool required = false; - for (int j = i + 3; j >= i; j--) - { - if (bits[j]) - required = true; - else if (required) - yield return new RibbonResult(names[j], false); - } - } - } + var c4 = u4.RibbonBitsContest4(); + var c4n = u4.RibbonNamesContest4(); + var iter4 = (gen == 3 || gen == 4) && IsAllowedInContest4(pkm.Species) ? GetMissingContestRibbons(c4, c4n) : GetInvalidRibbonsNone(c4, c4n); + foreach (var z in iter4) + yield return z; } if (pkm is IRibbonSetCommon4 s4) { @@ -193,6 +184,20 @@ static IEnumerable getMissingContestRibbons(IReadOnlyList bi } } + private static IEnumerable GetMissingContestRibbons(IReadOnlyList bits, IReadOnlyList names) + { + for (int i = 0; i < bits.Count; i += 4) + { + bool required = false; + for (int j = i + 3; j >= i; j--) + { + if (bits[j]) + required = true; + else if (required) yield return new RibbonResult(names[j], false); + } + } + } + private static IEnumerable GetInvalidRibbons4Any(PKM pkm, IRibbonSetCommon4 s4, int gen) { if (s4.RibbonRecord) @@ -258,8 +263,8 @@ private static IEnumerable GetInvalidRibbons6Any(PKM pkm, IRibbonS yield return new RibbonResult(rib); } - const int mem_Chatelaine = 30; - bool hasChampMemory = pkm.HT_Memory == mem_Chatelaine || pkm.OT_Memory == mem_Chatelaine; + const int memChatelaine = 30; + bool hasChampMemory = pkm.HT_Memory == memChatelaine || pkm.OT_Memory == memChatelaine; if (!IsAllowedBattleFrontier(pkm.Species)) { if (hasChampMemory || s6.RibbonBattlerSkillful) // having memory and not ribbon is too rare, just flag here. @@ -335,8 +340,8 @@ private static IEnumerable GetInvalidRibbons6Traded(PKM pkm, IRibb yield return new RibbonResult(nameof(s6.RibbonTraining)); } - const int mem_Champion = 27; - bool hasChampMemory = (pkm.Format < 8 && pkm.HT_Memory == mem_Champion) || (pkm.Gen6 && pkm.OT_Memory == mem_Champion); + const int memChampion = 27; + bool hasChampMemory = (pkm.Format < 8 && pkm.HT_Memory == memChampion) || (pkm.Gen6 && pkm.OT_Memory == memChampion); if (!hasChampMemory || s6.RibbonChampionKalos || s6.RibbonChampionG6Hoenn) yield break; @@ -371,8 +376,8 @@ private static IEnumerable GetInvalidRibbons8Any(PKM pkm, IRibbonS } else { - const int mem_Champion = 27; - bool hasChampMemory = (pkm.Format == 8 && pkm.HT_Memory == mem_Champion) || (pkm.Gen8 && pkm.OT_Memory == mem_Champion); + const int memChampion = 27; + bool hasChampMemory = (pkm.Format == 8 && pkm.HT_Memory == memChampion) || (pkm.Gen8 && pkm.OT_Memory == memChampion); if (hasChampMemory && !s8.RibbonChampionGalar) yield return new RibbonResult(nameof(s8.RibbonChampionGalar)); } diff --git a/PKHeX.Core/MysteryGifts/MysteryGift.cs b/PKHeX.Core/MysteryGifts/MysteryGift.cs index 268823d62..e6a74360b 100644 --- a/PKHeX.Core/MysteryGifts/MysteryGift.cs +++ b/PKHeX.Core/MysteryGifts/MysteryGift.cs @@ -48,9 +48,9 @@ public abstract class MysteryGift : IEncounterable, IMoveset, IRelearn, ILocatio /// /// Length, in bytes, of the data of which to determine validity. /// A boolean indicating whether or not the given length is valid for a mystery gift. - public static bool IsMysteryGift(long len) => MGSizes.Contains((int)len); + public static bool IsMysteryGift(long len) => Sizes.Contains((int)len); - private static readonly HashSet MGSizes = new HashSet{ WC8.Size, WC6Full.Size, WC6.Size, PGF.Size, PGT.Size, PCD.Size }; + private static readonly HashSet Sizes = new HashSet{ WC8.Size, WC6Full.Size, WC6.Size, PGF.Size, PGT.Size, PCD.Size }; /// /// Converts the given data to a . @@ -129,8 +129,8 @@ public abstract class MysteryGift : IEncounterable, IMoveset, IRelearn, ILocatio public string FileName => $"{CardHeader}.{Extension}"; public abstract int Format { get; } - public PKM ConvertToPKM(ITrainerInfo SAV) => ConvertToPKM(SAV, EncounterCriteria.Unrestricted); - public abstract PKM ConvertToPKM(ITrainerInfo SAV, EncounterCriteria criteria); + public PKM ConvertToPKM(ITrainerInfo sav) => ConvertToPKM(sav, EncounterCriteria.Unrestricted); + public abstract PKM ConvertToPKM(ITrainerInfo sav, EncounterCriteria criteria); protected abstract bool IsMatchExact(PKM pkm); protected abstract bool IsMatchDeferred(PKM pkm); @@ -158,7 +158,7 @@ public EncounterMatchRating IsMatch(PKM pkm) /// /// Gets a friendly name for the underlying type for the interface. /// - public string Name => $"Event Gift"; + public string Name => "Event Gift"; /// /// Gets a friendly name for the underlying type for the interface. diff --git a/PKHeX.Core/MysteryGifts/MysteryUtil.cs b/PKHeX.Core/MysteryGifts/MysteryUtil.cs index 1b575f4a4..d57a992c6 100644 --- a/PKHeX.Core/MysteryGifts/MysteryUtil.cs +++ b/PKHeX.Core/MysteryGifts/MysteryUtil.cs @@ -114,18 +114,18 @@ private static void AddLinesPKM(MysteryGift gift, IBasicStrings strings, ICollec /// Checks if the data is compatible with the . Sets appropriate data to the save file in order to receive the gift. /// /// Gift data to potentially insert to the save file. - /// Save file receiving the gift data. + /// Save file receiving the gift data. /// Error message if incompatible. /// True if compatible, false if incompatible. - public static bool IsCardCompatible(this MysteryGift g, SaveFile SAV, out string message) + public static bool IsCardCompatible(this MysteryGift g, SaveFile sav, out string message) { - if (g.Format != SAV.Generation) + if (g.Format != sav.Generation) { message = MsgMysteryGiftSlotSpecialReject; return false; } - if (!SAV.CanReceiveGift(g)) + if (!sav.CanReceiveGift(g)) { message = MsgMysteryGiftTypeDetails; return false; @@ -133,7 +133,7 @@ public static bool IsCardCompatible(this MysteryGift g, SaveFile SAV, out string if (g is WC6 && g.CardID == 2048 && g.ItemID == 726) // Eon Ticket (OR/AS) { - if (!(SAV is SAV6AO)) + if (!(sav is SAV6AO)) { message = MsgMysteryGiftSlotSpecialReject; return false; @@ -147,16 +147,16 @@ public static bool IsCardCompatible(this MysteryGift g, SaveFile SAV, out string /// /// Checks if the gift values are receivable by the game. /// - /// Save file receiving the gift data. + /// Save file receiving the gift data. /// Gift data to potentially insert to the save file. /// True if compatible, false if incompatible. - public static bool CanReceiveGift(this SaveFile SAV, MysteryGift gift) + public static bool CanReceiveGift(this SaveFile sav, MysteryGift gift) { - if (gift.Species > SAV.MaxSpeciesID) + if (gift.Species > sav.MaxSpeciesID) return false; - if (gift.Moves.Any(move => move > SAV.MaxMoveID)) + if (gift.Moves.Any(move => move > sav.MaxMoveID)) return false; - if (gift.HeldItem > SAV.MaxItemID) + if (gift.HeldItem > sav.MaxItemID) return false; return true; } diff --git a/PKHeX.Core/MysteryGifts/PCD.cs b/PKHeX.Core/MysteryGifts/PCD.cs index 8b72b5341..87ff505da 100644 --- a/PKHeX.Core/MysteryGifts/PCD.cs +++ b/PKHeX.Core/MysteryGifts/PCD.cs @@ -122,9 +122,9 @@ public bool GiftEquals(PGT pgt) return true; } - public override PKM ConvertToPKM(ITrainerInfo SAV, EncounterCriteria criteria) + public override PKM ConvertToPKM(ITrainerInfo sav, EncounterCriteria criteria) { - return Gift.ConvertToPKM(SAV, criteria); + return Gift.ConvertToPKM(sav, criteria); } public bool CanBeReceivedBy(int pkmVersion) => (CardCompatibility >> pkmVersion & 1) == 1; diff --git a/PKHeX.Core/MysteryGifts/PGF.cs b/PKHeX.Core/MysteryGifts/PGF.cs index b0945e953..e38e9100f 100644 --- a/PKHeX.Core/MysteryGifts/PGF.cs +++ b/PKHeX.Core/MysteryGifts/PGF.cs @@ -161,7 +161,7 @@ public override int[] IVs public override bool IsItem { get => CardType == 2; set { if (value) CardType = 2; } } public bool IsPower { get => CardType == 3; set { if (value) CardType = 3; } } - public override PKM ConvertToPKM(ITrainerInfo SAV, EncounterCriteria criteria) + public override PKM ConvertToPKM(ITrainerInfo sav, EncounterCriteria criteria) { if (!IsPokémon) throw new ArgumentException(nameof(IsPokémon)); @@ -185,8 +185,8 @@ public override PKM ConvertToPKM(ITrainerInfo SAV, EncounterCriteria criteria) Met_Level = currentLevel, Nature = Nature != -1 ? Nature : rnd.Next(25), AltForm = Form, - Version = OriginGame == 0 ? SAV.Game : OriginGame, - Language = Language == 0 ? SAV.Language : Language, + Version = OriginGame == 0 ? sav.Game : OriginGame, + Language = Language == 0 ? sav.Language : Language, Ball = Ball, Move1 = Move1, Move2 = Move2, @@ -224,7 +224,7 @@ public override PKM ConvertToPKM(ITrainerInfo SAV, EncounterCriteria criteria) FatefulEncounter = true, }; - if (SAV.Generation > 5 && OriginGame == 0) // Gen6+, give random gen5 game + if (sav.Generation > 5 && OriginGame == 0) // Gen6+, give random gen5 game pk.Version = (int)GameVersion.W + rnd.Next(4); if (Move1 == 0) // No moves defined @@ -234,17 +234,17 @@ public override PKM ConvertToPKM(ITrainerInfo SAV, EncounterCriteria criteria) if (IsEgg) // User's { - pk.TID = SAV.TID; - pk.SID = SAV.SID; - pk.OT_Name = SAV.OT; - pk.OT_Gender = SAV.Gender; + pk.TID = sav.TID; + pk.SID = sav.SID; + pk.OT_Name = sav.OT; + pk.OT_Gender = sav.Gender; } else // Hardcoded { pk.TID = TID; pk.SID = SID; pk.OT_Name = OT_Name; - pk.OT_Gender = (OTGender == 3 ? SAV.Gender : OTGender) & 1; // some events have variable gender based on receiving SaveFile + pk.OT_Gender = (OTGender == 3 ? sav.Gender : OTGender) & 1; // some events have variable gender based on receiving SaveFile } pk.IsNicknamed = IsNicknamed; @@ -362,7 +362,7 @@ protected override bool IsMatchExact(PKM pkm) } else if (PIDType == 0 && pkm.IsShiny) { - return false; // can't be traded away for unshiny + return false; // can't be traded away for un-shiny } if (pkm.IsEgg && !pkm.IsNative) diff --git a/PKHeX.Core/MysteryGifts/PGT.cs b/PKHeX.Core/MysteryGifts/PGT.cs index 4dcfcf886..5ac04b1e2 100644 --- a/PKHeX.Core/MysteryGifts/PGT.cs +++ b/PKHeX.Core/MysteryGifts/PGT.cs @@ -61,10 +61,10 @@ public PK4 PK set { _pk = value; - var pkdata = value.Data.All(z => z == 0) + var data = value.Data.All(z => z == 0) ? value.Data : PokeCrypto.EncryptArray45(value.Data); - pkdata.CopyTo(Data, 8); + data.CopyTo(Data, 8); } } @@ -118,7 +118,7 @@ private void EncryptPK() public override int Location { get => PK.Met_Location; set => PK.Met_Location = value; } public override int EggLocation { get => PK.Egg_Location; set => PK.Egg_Location = value; } - public override PKM ConvertToPKM(ITrainerInfo SAV, EncounterCriteria criteria) + public override PKM ConvertToPKM(ITrainerInfo sav, EncounterCriteria criteria) { if (!IsPokémon) throw new ArgumentException(nameof(IsPokémon)); @@ -127,18 +127,18 @@ public override PKM ConvertToPKM(ITrainerInfo SAV, EncounterCriteria criteria) PK4 pk4 = new PK4((byte[])PK.Data.Clone()) { Sanity = 0 }; if (!IsHatched && Detail == 0) { - pk4.OT_Name = SAV.OT; - pk4.TID = SAV.TID; - pk4.SID = SAV.SID; - pk4.OT_Gender = SAV.Gender; - pk4.Language = SAV.Language; + pk4.OT_Name = sav.OT; + pk4.TID = sav.TID; + pk4.SID = sav.SID; + pk4.OT_Gender = sav.Gender; + pk4.Language = sav.Language; } if (IsManaphyEgg) SetDefaultManaphyEggDetails(pk4); SetPINGA(pk4, criteria); - SetMetData(pk4, SAV); + SetMetData(pk4, sav); var pi = pk4.PersonalInfo; pk4.CurrentFriendship = pk4.IsEgg ? pi.HatchCycles : pi.BaseFriendship; diff --git a/PKHeX.Core/MysteryGifts/WB7.cs b/PKHeX.Core/MysteryGifts/WB7.cs index cb8d3f807..9615dfa0a 100644 --- a/PKHeX.Core/MysteryGifts/WB7.cs +++ b/PKHeX.Core/MysteryGifts/WB7.cs @@ -293,7 +293,7 @@ private int GetOTOffset(int language) return 0xEE + (index * 0x1A); } - public override PKM ConvertToPKM(ITrainerInfo SAV, EncounterCriteria criteria) + public override PKM ConvertToPKM(ITrainerInfo sav, EncounterCriteria criteria) { if (!IsPokémon) throw new ArgumentException(nameof(IsPokémon)); @@ -303,7 +303,7 @@ public override PKM ConvertToPKM(ITrainerInfo SAV, EncounterCriteria criteria) int currentLevel = Level > 0 ? Level : rnd.Next(1, 101); int metLevel = MetLevel > 0 ? MetLevel : currentLevel; var pi = PersonalTable.GG.GetFormeEntry(Species, Form); - var OT = GetOT(SAV.Language); + var OT = GetOT(sav.Language); var pk = new PB7 { @@ -314,12 +314,12 @@ public override PKM ConvertToPKM(ITrainerInfo SAV, EncounterCriteria criteria) Met_Level = metLevel, AltForm = Form, EncryptionConstant = EncryptionConstant != 0 ? EncryptionConstant : Util.Rand32(), - Version = OriginGame != 0 ? OriginGame : SAV.Game, - Language = SAV.Language, + Version = OriginGame != 0 ? OriginGame : sav.Game, + Language = sav.Language, Ball = Ball, - Country = SAV.Country, - Region = SAV.SubRegion, - ConsoleRegion = SAV.ConsoleRegion, + Country = sav.Country, + Region = sav.SubRegion, + ConsoleRegion = sav.ConsoleRegion, Move1 = Move1, Move2 = Move2, Move3 = Move3, @@ -337,10 +337,10 @@ public override PKM ConvertToPKM(ITrainerInfo SAV, EncounterCriteria criteria) AV_SPA = AV_SPA, AV_SPD = AV_SPD, - OT_Name = OT.Length > 0 ? OT : SAV.OT, - OT_Gender = OTGender != 3 ? OTGender % 2 : SAV.Gender, - HT_Name = OT_Name.Length > 0 ? SAV.OT : string.Empty, - HT_Gender = OT_Name.Length > 0 ? SAV.Gender : 0, + OT_Name = OT.Length > 0 ? OT : sav.OT, + OT_Gender = OTGender != 3 ? OTGender % 2 : sav.Gender, + HT_Name = OT_Name.Length > 0 ? sav.OT : string.Empty, + HT_Gender = OT_Name.Length > 0 ? sav.Gender : 0, CurrentHandler = OT_Name.Length > 0 ? 1 : 0, EXP = Experience.GetEXP(currentLevel, pi.EXPGrowth), @@ -350,7 +350,7 @@ public override PKM ConvertToPKM(ITrainerInfo SAV, EncounterCriteria criteria) }; pk.SetMaximumPPCurrent(); - if ((SAV.Generation > Format && OriginGame == 0) || !CanBeReceivedByVersion(pk.Version)) + if ((sav.Generation > Format && OriginGame == 0) || !CanBeReceivedByVersion(pk.Version)) { // give random valid game do { pk.Version = (int)GameVersion.GP + rnd.Next(2); } @@ -359,8 +359,8 @@ public override PKM ConvertToPKM(ITrainerInfo SAV, EncounterCriteria criteria) if (OTGender == 3) { - pk.TID = SAV.TID; - pk.SID = SAV.SID; + pk.TID = sav.TID; + pk.SID = sav.SID; } pk.MetDate = Date ?? DateTime.Now; diff --git a/PKHeX.Core/MysteryGifts/WC3.cs b/PKHeX.Core/MysteryGifts/WC3.cs index 73b078e55..21c111d1c 100644 --- a/PKHeX.Core/MysteryGifts/WC3.cs +++ b/PKHeX.Core/MysteryGifts/WC3.cs @@ -70,7 +70,7 @@ public int Met_Level set => _metLevel = value; } - public override PKM ConvertToPKM(ITrainerInfo SAV, EncounterCriteria criteria) + public override PKM ConvertToPKM(ITrainerInfo sav, EncounterCriteria criteria) { PK3 pk = new PK3 { @@ -88,24 +88,24 @@ public override PKM ConvertToPKM(ITrainerInfo SAV, EncounterCriteria criteria) RibbonChampionNational = RibbonChampionNational, FatefulEncounter = Fateful, - Version = GetVersion(SAV), + Version = GetVersion(sav), }; pk.EXP = Experience.GetEXP(Level, pk.PersonalInfo.EXPGrowth); SetMoves(pk); - bool hatchedEgg = IsEgg && SAV.Generation != 3; + bool hatchedEgg = IsEgg && sav.Generation != 3; if (hatchedEgg) { - SetForceHatchDetails(pk, SAV); + SetForceHatchDetails(pk, sav); } else { - pk.OT_Gender = OT_Gender != 3 ? OT_Gender & 1 : SAV.Gender; + pk.OT_Gender = OT_Gender != 3 ? OT_Gender & 1 : sav.Gender; pk.TID = TID; pk.SID = SID; - pk.Language = (int)GetSafeLanguage((LanguageID)SAV.Language); - pk.OT_Name = !string.IsNullOrWhiteSpace(OT_Name) ? OT_Name : SAV.OT; + pk.Language = (int)GetSafeLanguage((LanguageID)sav.Language); + pk.OT_Name = !string.IsNullOrWhiteSpace(OT_Name) ? OT_Name : sav.OT; if (IsEgg) pk.IsEgg = true; // lang should be set to japanese already } @@ -116,7 +116,7 @@ public override PKM ConvertToPKM(ITrainerInfo SAV, EncounterCriteria criteria) // Generate PIDIV SetPINGA(pk, criteria); - pk.HeldItem = 0; // clear, only random for Jirachis(?), no loss + pk.HeldItem = 0; // clear, only random for Jirachi (?), no loss if (Version == GameVersion.XD) pk.FatefulEncounter = true; // pk3 is already converted from xk3 @@ -125,25 +125,25 @@ public override PKM ConvertToPKM(ITrainerInfo SAV, EncounterCriteria criteria) return pk; } - private static void SetForceHatchDetails(PK3 pk, ITrainerInfo SAV) + private static void SetForceHatchDetails(PK3 pk, ITrainerInfo sav) { // ugly workaround for character table interactions pk.Language = (int)LanguageID.English; pk.OT_Name = "PKHeX"; - pk.OT_Gender = SAV.Gender; - pk.TID = SAV.TID; - pk.SID = SAV.SID; + pk.OT_Gender = sav.Gender; + pk.TID = sav.TID; + pk.SID = sav.SID; pk.Met_Location = pk.FRLG ? 146 /* Four Island */ : 32; // Route 117 pk.FatefulEncounter &= pk.FRLG; // clear flag for RSE pk.Met_Level = 0; // hatched } - private int GetVersion(ITrainerInfo SAV) + private int GetVersion(ITrainerInfo sav) { if (Version != 0) return (int) GetRandomVersion(Version); - bool gen3 = SAV.Game <= 15 && GameVersion.Gen3.Contains((GameVersion)SAV.Game); - return gen3 ? SAV.Game : (int)GameVersion.R; + bool gen3 = sav.Game <= 15 && GameVersion.Gen3.Contains((GameVersion)sav.Game); + return gen3 ? sav.Game : (int)GameVersion.R; } private void SetMoves(PK3 pk) @@ -225,7 +225,7 @@ protected override bool IsMatchExact(PKM pkm) var wcOT = OT_Name; if (!string.IsNullOrEmpty(wcOT)) { - if (wcOT.Length > 7) // Colosseum Mattle Ho-Oh + if (wcOT.Length > 7) // Colosseum MATTLE Ho-Oh { if (!GetIsValidOTMattleHoOh(wcOT, pkm.OT_Name, pkm is CK3)) return false; diff --git a/PKHeX.Core/MysteryGifts/WC6.cs b/PKHeX.Core/MysteryGifts/WC6.cs index f02e641df..0d79a7578 100644 --- a/PKHeX.Core/MysteryGifts/WC6.cs +++ b/PKHeX.Core/MysteryGifts/WC6.cs @@ -265,7 +265,7 @@ public override IReadOnlyList Relearn } } - public override PKM ConvertToPKM(ITrainerInfo SAV, EncounterCriteria criteria) + public override PKM ConvertToPKM(ITrainerInfo sav, EncounterCriteria criteria) { if (!IsPokémon) throw new ArgumentException(nameof(IsPokémon)); @@ -283,12 +283,12 @@ public override PKM ConvertToPKM(ITrainerInfo SAV, EncounterCriteria criteria) Met_Level = currentLevel, AltForm = Form, EncryptionConstant = EncryptionConstant != 0 ? EncryptionConstant : Util.Rand32(), - Version = OriginGame != 0 ? OriginGame : SAV.Game, - Language = Language != 0 ? Language : SAV.Language, + Version = OriginGame != 0 ? OriginGame : sav.Game, + Language = Language != 0 ? Language : sav.Language, Ball = Ball, - Country = SAV.Country, - Region = SAV.SubRegion, - ConsoleRegion = SAV.ConsoleRegion, + Country = sav.Country, + Region = sav.SubRegion, + ConsoleRegion = sav.ConsoleRegion, Move1 = Move1, Move2 = Move2, Move3 = Move3, Move4 = Move4, RelearnMove1 = RelearnMove1, RelearnMove2 = RelearnMove2, RelearnMove3 = RelearnMove3, RelearnMove4 = RelearnMove4, @@ -301,10 +301,10 @@ public override PKM ConvertToPKM(ITrainerInfo SAV, EncounterCriteria criteria) CNT_Tough = CNT_Tough, CNT_Sheen = CNT_Sheen, - OT_Name = OT_Name.Length > 0 ? OT_Name : SAV.OT, - OT_Gender = OTGender != 3 ? OTGender % 2 : SAV.Gender, - HT_Name = OT_Name.Length > 0 ? SAV.OT : string.Empty, - HT_Gender = OT_Name.Length > 0 ? SAV.Gender : 0, + OT_Name = OT_Name.Length > 0 ? OT_Name : sav.OT, + OT_Gender = OTGender != 3 ? OTGender % 2 : sav.Gender, + HT_Name = OT_Name.Length > 0 ? sav.OT : string.Empty, + HT_Gender = OT_Name.Length > 0 ? sav.Gender : 0, CurrentHandler = OT_Name.Length > 0 ? 1 : 0, EXP = Experience.GetEXP(Level, pi.EXPGrowth), @@ -341,7 +341,7 @@ public override PKM ConvertToPKM(ITrainerInfo SAV, EncounterCriteria criteria) pk.MetDate = Date ?? DateTime.Now; - if ((SAV.Generation > Format && OriginGame == 0) || !CanBeReceivedByVersion(pk.Version)) + if ((sav.Generation > Format && OriginGame == 0) || !CanBeReceivedByVersion(pk.Version)) { // give random valid game do { pk.Version = (int)GameVersion.X + rnd.Next(4); } @@ -519,7 +519,7 @@ protected override bool IsMatchDeferred(PKM pkm) switch (CardID) { case 0525 when IV_HP == 0xFE: // Diancie was distributed with no IV enforcement & 3IVs - case 0504 when RibbonClassic != ((IRibbonSetEvent4)pkm).RibbonClassic: // magmar with/without classic + case 0504 when RibbonClassic != ((IRibbonSetEvent4)pkm).RibbonClassic: // Magmar with/without classic return true; } if (RestrictLanguage != 0 && RestrictLanguage != pkm.Language) diff --git a/PKHeX.Core/MysteryGifts/WC7.cs b/PKHeX.Core/MysteryGifts/WC7.cs index 8ede05db4..290feca05 100644 --- a/PKHeX.Core/MysteryGifts/WC7.cs +++ b/PKHeX.Core/MysteryGifts/WC7.cs @@ -308,7 +308,7 @@ public override IReadOnlyList Relearn } } - public override PKM ConvertToPKM(ITrainerInfo SAV, EncounterCriteria criteria) + public override PKM ConvertToPKM(ITrainerInfo sav, EncounterCriteria criteria) { if (!IsPokémon) throw new ArgumentException(nameof(IsPokémon)); @@ -327,12 +327,12 @@ public override PKM ConvertToPKM(ITrainerInfo SAV, EncounterCriteria criteria) Met_Level = metLevel, AltForm = Form, EncryptionConstant = EncryptionConstant != 0 ? EncryptionConstant : Util.Rand32(), - Version = OriginGame != 0 ? OriginGame : SAV.Game, - Language = Language != 0 ? Language : SAV.Language, + Version = OriginGame != 0 ? OriginGame : sav.Game, + Language = Language != 0 ? Language : sav.Language, Ball = Ball, - Country = SAV.Country, - Region = SAV.SubRegion, - ConsoleRegion = SAV.ConsoleRegion, + Country = sav.Country, + Region = sav.SubRegion, + ConsoleRegion = sav.ConsoleRegion, Move1 = Move1, Move2 = Move2, Move3 = Move3, Move4 = Move4, RelearnMove1 = RelearnMove1, RelearnMove2 = RelearnMove2, RelearnMove3 = RelearnMove3, RelearnMove4 = RelearnMove4, @@ -345,10 +345,10 @@ public override PKM ConvertToPKM(ITrainerInfo SAV, EncounterCriteria criteria) CNT_Tough = CNT_Tough, CNT_Sheen = CNT_Sheen, - OT_Name = OT_Name.Length > 0 ? OT_Name : SAV.OT, - OT_Gender = OTGender != 3 ? OTGender % 2 : SAV.Gender, - HT_Name = OT_Name.Length > 0 ? SAV.OT : string.Empty, - HT_Gender = OT_Name.Length > 0 ? SAV.Gender : 0, + OT_Name = OT_Name.Length > 0 ? OT_Name : sav.OT, + OT_Gender = OTGender != 3 ? OTGender % 2 : sav.Gender, + HT_Name = OT_Name.Length > 0 ? sav.OT : string.Empty, + HT_Gender = OT_Name.Length > 0 ? sav.Gender : 0, CurrentHandler = OT_Name.Length > 0 ? 1 : 0, EXP = Experience.GetEXP(currentLevel, pi.EXPGrowth), @@ -383,7 +383,7 @@ public override PKM ConvertToPKM(ITrainerInfo SAV, EncounterCriteria criteria) }; pk.SetMaximumPPCurrent(); - if ((SAV.Generation > Format && OriginGame == 0) || !CanBeReceivedByVersion(pk.Version)) + if ((sav.Generation > Format && OriginGame == 0) || !CanBeReceivedByVersion(pk.Version)) { // give random valid game do { pk.Version = (int)GameVersion.SN + rnd.Next(4); } @@ -392,8 +392,8 @@ public override PKM ConvertToPKM(ITrainerInfo SAV, EncounterCriteria criteria) if (OTGender == 3) { - pk.TID = SAV.TID; - pk.SID = SAV.SID; + pk.TID = sav.TID; + pk.SID = sav.SID; } pk.MetDate = Date ?? DateTime.Now; @@ -530,7 +530,7 @@ protected override bool IsMatchExact(PKM pkm) } else if (PIDType == 0 && pkm.IsShiny) { - return false; // can't be traded away for unshiny + return false; // can't be traded away for un-shiny } if (pkm.IsEgg && !pkm.IsNative) diff --git a/PKHeX.Core/MysteryGifts/WC8.cs b/PKHeX.Core/MysteryGifts/WC8.cs index 7ad4018bd..aea5f4dde 100644 --- a/PKHeX.Core/MysteryGifts/WC8.cs +++ b/PKHeX.Core/MysteryGifts/WC8.cs @@ -296,7 +296,7 @@ private static int GetOTOffset(int language) private bool IsHOMEGift => PIDType == Shiny.FixedValue && PID == 0 && EncryptionConstant == 0; - public override PKM ConvertToPKM(ITrainerInfo SAV, EncounterCriteria criteria) + public override PKM ConvertToPKM(ITrainerInfo sav, EncounterCriteria criteria) { if (!IsPokémon) throw new ArgumentException(nameof(IsPokémon)); @@ -304,7 +304,7 @@ public override PKM ConvertToPKM(ITrainerInfo SAV, EncounterCriteria criteria) int currentLevel = Level > 0 ? Level : Util.Rand.Next(1, 101); int metLevel = MetLevel > 0 ? MetLevel : currentLevel; var pi = PersonalTable.SWSH.GetFormeEntry(Species, Form); - var OT = GetOT(SAV.Language); + var OT = GetOT(sav.Language); var pk = new PK8 { @@ -329,13 +329,13 @@ public override PKM ConvertToPKM(ITrainerInfo SAV, EncounterCriteria criteria) RelearnMove3 = RelearnMove3, RelearnMove4 = RelearnMove4, - Version = OriginGame != 0 ? OriginGame : SAV.Game, + Version = OriginGame != 0 ? OriginGame : sav.Game, - OT_Name = OT.Length > 0 ? OT : SAV.OT, - OT_Gender = OTGender < 2 ? OTGender : SAV.Gender, - HT_Name = GetHasOT(Language) ? SAV.OT : string.Empty, - HT_Gender = GetHasOT(Language) ? SAV.Gender : 0, - HT_Language = GetHasOT(Language) ? SAV.Language : 0, + OT_Name = OT.Length > 0 ? OT : sav.OT, + OT_Gender = OTGender < 2 ? OTGender : sav.Gender, + HT_Name = GetHasOT(Language) ? sav.OT : string.Empty, + HT_Gender = GetHasOT(Language) ? sav.Gender : 0, + HT_Language = GetHasOT(Language) ? sav.Language : 0, CurrentHandler = GetHasOT(Language) ? 1 : 0, OT_Friendship = pi.BaseFriendship, @@ -355,7 +355,7 @@ public override PKM ConvertToPKM(ITrainerInfo SAV, EncounterCriteria criteria) }; pk.SetMaximumPPCurrent(); - if ((SAV.Generation > Format && OriginGame == 0) || !CanBeReceivedByVersion(pk.Version)) + if ((sav.Generation > Format && OriginGame == 0) || !CanBeReceivedByVersion(pk.Version)) { // give random valid game var rnd = Util.Rand; @@ -365,8 +365,8 @@ public override PKM ConvertToPKM(ITrainerInfo SAV, EncounterCriteria criteria) if (OTGender >= 2) { - pk.TID = SAV.TID; - pk.SID = SAV.SID; + pk.TID = sav.TID; + pk.SID = sav.SID; } // Official code explicitly corrects for meowstic @@ -375,8 +375,8 @@ public override PKM ConvertToPKM(ITrainerInfo SAV, EncounterCriteria criteria) pk.MetDate = DateTime.Now; - var nickname_language = GetNicknameLanguage(SAV.Language); - pk.Language = nickname_language != 0 ? nickname_language : SAV.Language; + var nickname_language = GetNicknameLanguage(sav.Language); + pk.Language = nickname_language != 0 ? nickname_language : sav.Language; pk.IsNicknamed = GetIsNicknamed(pk.Language); pk.Nickname = pk.IsNicknamed ? Nickname : SpeciesName.GetSpeciesNameGeneration(Species, pk.Language, Format); @@ -387,7 +387,7 @@ public override PKM ConvertToPKM(ITrainerInfo SAV, EncounterCriteria criteria) pk.SetRibbon(ribbon); } - SetPINGA(pk, SAV, criteria); + SetPINGA(pk, sav, criteria); if (IsEgg) SetEggMetData(pk); @@ -408,7 +408,7 @@ private void SetEggMetData(PKM pk) pk.IsNicknamed = true; } - private void SetPINGA(PKM pk, ITrainerInfo SAV, EncounterCriteria criteria) + private void SetPINGA(PKM pk, ITrainerInfo sav, EncounterCriteria criteria) { var pi = PersonalTable.SWSH.GetFormeEntry(Species, Form); pk.Nature = (int)criteria.GetNature(Nature == -1 ? Core.Nature.Random : (Nature)Nature); @@ -416,7 +416,7 @@ private void SetPINGA(PKM pk, ITrainerInfo SAV, EncounterCriteria criteria) pk.Gender = criteria.GetGender(Gender, pi); var av = GetAbilityIndex(criteria, pi); pk.RefreshAbility(av); - SetPID(pk, SAV); + SetPID(pk, sav); SetIVs(pk); } @@ -436,21 +436,21 @@ private int GetAbilityIndex(EncounterCriteria criteria, PersonalInfo pi) } } - private uint GetFixedPID(ITrainerInfo SAV) + private uint GetFixedPID(ITrainerInfo sav) { uint pid = PID; var val = Data[CardStart + 0x248]; if (val == 4) return pid; - return (uint)((pid & 0xFFFF) | ((SAV.SID ^ SAV.TID ^ (pid & 0xFFFF) ^ (val == 2 ? 1 : 0)) << 16)); + return (uint)((pid & 0xFFFF) | ((sav.SID ^ sav.TID ^ (pid & 0xFFFF) ^ (val == 2 ? 1 : 0)) << 16)); } - private void SetPID(PKM pk, ITrainerInfo SAV) + private void SetPID(PKM pk, ITrainerInfo sav) { switch (PIDType) { case Shiny.FixedValue: // Specified - pk.PID = GetFixedPID(SAV); + pk.PID = GetFixedPID(sav); break; case Shiny.Random: // Random pk.PID = Util.Rand32(); diff --git a/PKHeX.Core/MysteryGifts/WR7.cs b/PKHeX.Core/MysteryGifts/WR7.cs index 08ef1b034..1c4b0276f 100644 --- a/PKHeX.Core/MysteryGifts/WR7.cs +++ b/PKHeX.Core/MysteryGifts/WR7.cs @@ -125,7 +125,7 @@ public override bool IsItem } } - public override PKM ConvertToPKM(ITrainerInfo SAV, EncounterCriteria criteria) + public override PKM ConvertToPKM(ITrainerInfo sav, EncounterCriteria criteria) { // this method shouldn't really be called, use the WB7 data not the WR7 data. if (!IsPokémon) @@ -133,8 +133,8 @@ public override PKM ConvertToPKM(ITrainerInfo SAV, EncounterCriteria criteria) // we'll just generate something as close as we can, since we must return something! var pk = new PB7(); - SAV.ApplyToPKM(pk); - if (!GameVersion.GG.Contains((GameVersion) SAV.Game)) + sav.ApplyTo(pk); + if (!GameVersion.GG.Contains((GameVersion) sav.Game)) pk.Version = (int) GameVersion.GP; pk.Species = Species; diff --git a/PKHeX.Core/PKM/CK3.cs b/PKHeX.Core/PKM/CK3.cs index 0359d4f6e..1f5621572 100644 --- a/PKHeX.Core/PKM/CK3.cs +++ b/PKHeX.Core/PKM/CK3.cs @@ -78,7 +78,7 @@ public sealed class CK3 : G3PKM, IShadowPKM public override int Move4_PP { get => Data[0x86]; set => Data[0x86] = (byte)value; } public override int Move4_PPUps { get => Data[0x87]; set => Data[0x87] = (byte)value; } - public override int SpriteItem => ItemConverter.GetG4Item((ushort)HeldItem); + public override int SpriteItem => ItemConverter.GetItemFuture3((ushort)HeldItem); public override int HeldItem { get => BigEndian.ToUInt16(Data, 0x88); set => BigEndian.GetBytes((ushort)value).CopyTo(Data, 0x88); } // More party stats diff --git a/PKHeX.Core/PKM/PK1.cs b/PKHeX.Core/PKM/PK1.cs index 894ae9394..8659bcbe3 100644 --- a/PKHeX.Core/PKM/PK1.cs +++ b/PKHeX.Core/PKM/PK1.cs @@ -101,7 +101,7 @@ private void SetSpeciesValues(int value) public override int Version { get => (int)GameVersion.RBY; set { } } public override int PKRS_Strain { get => 0; set { } } public override int PKRS_Days { get => 0; set { } } - public override bool CanHoldItem(IReadOnlyList ValidArray) => false; + public override bool CanHoldItem(IReadOnlyList valid) => false; // Maximums public override int MaxMoveID => Legal.MaxMoveID_1; @@ -116,7 +116,7 @@ public PK2 ConvertToPK2() otname.CopyTo(pk2.otname, 0); nick.CopyTo(pk2.nick, 0); - pk2.HeldItem = ItemConverter.GetG2ItemTransfer(pk2.HeldItem); + pk2.HeldItem = ItemConverter.GetItemFuture1(pk2.HeldItem); pk2.CurrentFriendship = pk2.PersonalInfo.BaseFriendship; pk2.Stat_Level = CurrentLevel; diff --git a/PKHeX.Core/PKM/PK2.cs b/PKHeX.Core/PKM/PK2.cs index a25dcc0fd..f5d437c08 100644 --- a/PKHeX.Core/PKM/PK2.cs +++ b/PKHeX.Core/PKM/PK2.cs @@ -30,7 +30,7 @@ public override PKM Clone() => new PK2((byte[])Data.Clone(), Japanese) #region Stored Attributes public override int Species { get => Data[0]; set => Data[0] = (byte)value; } - public override int SpriteItem => ItemConverter.GetG4Item((byte)HeldItem); + public override int SpriteItem => ItemConverter.GetItemFuture2((byte)HeldItem); public override int HeldItem { get => Data[0x1]; set => Data[0x1] = (byte)value; } public override int Move1 { get => Data[2]; set => Data[2] = (byte)value; } public override int Move2 { get => Data[3]; set => Data[3] = (byte)value; } diff --git a/PKHeX.Core/PKM/PK3.cs b/PKHeX.Core/PKM/PK3.cs index 115dfd966..5636ea975 100644 --- a/PKHeX.Core/PKM/PK3.cs +++ b/PKHeX.Core/PKM/PK3.cs @@ -76,7 +76,7 @@ public override int Species } } - public override int SpriteItem => ItemConverter.GetG4Item((ushort)HeldItem); + public override int SpriteItem => ItemConverter.GetItemFuture3((ushort)HeldItem); public override int HeldItem { get => BitConverter.ToUInt16(Data, 0x22); set => BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x22); } public override uint EXP { get => BitConverter.ToUInt32(Data, 0x24); set => BitConverter.GetBytes(value).CopyTo(Data, 0x24); } @@ -312,7 +312,7 @@ public PK4 ConvertToPK4() if (HeldItem > 0) { - ushort item = ItemConverter.GetG4Item((ushort)HeldItem); + ushort item = ItemConverter.GetItemFuture3((ushort)HeldItem); if (ItemConverter.IsItemTransferable34(item)) pk4.HeldItem = item; } diff --git a/PKHeX.Core/PKM/PKM.cs b/PKHeX.Core/PKM/PKM.cs index fe48a94e2..6eb688a0b 100644 --- a/PKHeX.Core/PKM/PKM.cs +++ b/PKHeX.Core/PKM/PKM.cs @@ -630,37 +630,37 @@ public virtual bool WasEventEgg /// /// Checks if the could inhabit a set of games. /// - /// Set of games. + /// Set of games. /// /// True if could inhabit, False if not. - public bool InhabitedGeneration(int Generation, int species = -1) + public bool InhabitedGeneration(int generation, int species = -1) { if (species < 0) species = Species; - if (Format == Generation) + if (Format == generation) return true; if (!IsOriginValid) return false; // Sanity Check Species ID - if (Legal.GetMaxSpeciesOrigin(Generation) < species && !Legal.GetFutureGenEvolutions(Generation).Contains(species)) + if (Legal.GetMaxSpeciesOrigin(generation) < species && !Legal.GetFutureGenEvolutions(generation).Contains(species)) return false; // Trade generation 1 -> 2 - if (Format == 2 && Generation == 1 && !Gen2_NotTradeback) + if (Format == 2 && generation == 1 && !Gen2_NotTradeback) return true; // Trade generation 2 -> 1 - if (Format == 1 && Generation == 2 && !Gen1_NotTradeback) + if (Format == 1 && generation == 2 && !Gen1_NotTradeback) return true; - if (Format < Generation) + if (Format < generation) return false; // Future int gen = GenNumber; - return Generation switch + return generation switch { 1 => (Format == 1 || VC), // species compat checked via sanity above 2 => (Format == 2 || VC), @@ -883,9 +883,9 @@ public bool ForcePartyData() /// /// Checks if the can hold its . /// - /// Items that the can hold. + /// Items that the can hold. /// True/False if the can hold its . - public virtual bool CanHoldItem(IReadOnlyList ValidArray) => ValidArray.Contains((ushort)HeldItem); + public virtual bool CanHoldItem(IReadOnlyList valid) => valid.Contains((ushort)HeldItem); /// /// Deep clones the object. The clone will not have any shared resources with the source. @@ -923,10 +923,10 @@ protected void SetLinkTradeEgg(int day, int month, int y, int location) /// Amount of PP the move has by default (no PP Ups). private int GetBasePP(int move) { - var pptable = Legal.GetPPTable(this, Format); - if (move >= pptable.Count) + var table = Legal.GetPPTable(this, Format); + if (move >= table.Count) move = 0; - return pptable[move]; + return table[move]; } /// @@ -1087,13 +1087,13 @@ public int GetFlawlessIVCount() public void TransferPropertiesWithReflection(PKM Destination) { // Only transfer declared properties not defined in PKM.cs but in the actual type - var src_t = GetType(); - var dst_t = Destination.GetType(); - var SourceProperties = ReflectUtil.GetAllPropertyInfoPublic(src_t).Select(z => z.Name); - var DestinationProperties = ReflectUtil.GetAllPropertyInfoPublic(dst_t).Where(z => z.SetMethod != null).Select(z => z.Name); + var srcType = GetType(); + var destType = Destination.GetType(); + var srcProperties = ReflectUtil.GetAllPropertyInfoPublic(srcType).Select(z => z.Name); + var destProperties = ReflectUtil.GetAllPropertyInfoPublic(destType).Where(z => z.SetMethod != null).Select(z => z.Name); // Transfer properties in the order they are defined in the destination PKM format for best conversion - var shared = DestinationProperties.Intersect(SourceProperties); + var shared = destProperties.Intersect(srcProperties); foreach (string property in shared) { BatchEditing.TryGetHasProperty(this, property, out var src); diff --git a/PKHeX.Core/PKM/Searching/SearchSettings.cs b/PKHeX.Core/PKM/Searching/SearchSettings.cs index 9cfbc21ec..069718172 100644 --- a/PKHeX.Core/PKM/Searching/SearchSettings.cs +++ b/PKHeX.Core/PKM/Searching/SearchSettings.cs @@ -115,7 +115,7 @@ private IEnumerable SearchComplex(IEnumerable res) res = FilterResultEgg(res); if (Level != null) - res = SearchUtil.FilterByLVL(res, SearchLevel, (int)Level); + res = SearchUtil.FilterByLevel(res, SearchLevel, (int)Level); if (SearchLegal != null) res = res.Where(pk => new LegalityAnalysis(pk).Valid == SearchLegal); @@ -135,27 +135,27 @@ private IEnumerable FilterResultEgg(IEnumerable res) return res.Where(pk => pk.IsEgg); } - public IReadOnlyList GetVersions(SaveFile SAV) => GetVersions(SAV, GetFallbackVersion(SAV)); + public IReadOnlyList GetVersions(SaveFile sav) => GetVersions(sav, GetFallbackVersion(sav)); - public IReadOnlyList GetVersions(SaveFile SAV, GameVersion fallback) + public IReadOnlyList GetVersions(SaveFile sav, GameVersion fallback) { if (Version > 0) return new[] {(GameVersion) Version}; if (Generation != 0) { return fallback.GetGeneration() == Generation - ? GameUtil.GetVersionsWithinRange(SAV, Generation).ToArray() + ? GameUtil.GetVersionsWithinRange(sav, Generation).ToArray() : GameUtil.GameVersions; } return GameUtil.GameVersions; } - private static GameVersion GetFallbackVersion(SaveFile SAV) + private static GameVersion GetFallbackVersion(ITrainerInfo sav) { - var parent = GameUtil.GetMetLocationVersionGroup((GameVersion)SAV.Game); + var parent = GameUtil.GetMetLocationVersionGroup((GameVersion)sav.Game); if (parent == GameVersion.Invalid) - parent = GameUtil.GetMetLocationVersionGroup(GameUtil.GetVersion(SAV.Generation)); + parent = GameUtil.GetMetLocationVersionGroup(GameUtil.GetVersion(sav.Generation)); return parent; } } diff --git a/PKHeX.Core/PKM/Searching/SearchUtil.cs b/PKHeX.Core/PKM/Searching/SearchUtil.cs index e2653377c..891bbde03 100644 --- a/PKHeX.Core/PKM/Searching/SearchUtil.cs +++ b/PKHeX.Core/PKM/Searching/SearchUtil.cs @@ -26,7 +26,7 @@ public static IEnumerable FilterByFormat(IEnumerable res, int format, if (format <= 2) // 1-2 return res.Where(pk => pk.Format <= 2); - if (format >= 3 && format <= 6) // 3-6 + if (format <= 6) // 3-6 return res.Where(pk => pk.Format >= 3); return res; @@ -42,7 +42,7 @@ public static IEnumerable FilterByGeneration(IEnumerable res, int gene }; } - public static IEnumerable FilterByLVL(IEnumerable res, SearchComparison option, int level) + public static IEnumerable FilterByLevel(IEnumerable res, SearchComparison option, int level) { if (level > 100) return res; @@ -82,9 +82,9 @@ public static IEnumerable FilterByIVs(IEnumerable res, int option) }; } - public static IEnumerable FilterByMoves(IEnumerable res, IEnumerable Moves) + public static IEnumerable FilterByMoves(IEnumerable res, IEnumerable requiredMoves) { - var moves = new HashSet(Moves); + var moves = new HashSet(requiredMoves); int count = moves.Count; return res.Where(pk => pk.Moves.Where(z => z > 0) @@ -92,20 +92,20 @@ public static IEnumerable FilterByMoves(IEnumerable res, IEnumerable FilterByBatchInstruction(IEnumerable res, IList BatchInstructions) + public static IEnumerable FilterByBatchInstruction(IEnumerable res, IList inputInstructions) { - if (BatchInstructions.All(string.IsNullOrWhiteSpace)) + if (inputInstructions.All(string.IsNullOrWhiteSpace)) return res; // none specified; - var lines = BatchInstructions.Where(z => !string.IsNullOrWhiteSpace(z)); + var lines = inputInstructions.Where(z => !string.IsNullOrWhiteSpace(z)); var filters = StringInstruction.GetFilters(lines).ToArray(); BatchEditing.ScreenStrings(filters); return res.Where(pkm => BatchEditing.IsFilterMatch(filters, pkm)); // Compare across all filters } - public static Func GetCloneDetectMethod(CloneDetectionMethod Clones) + public static Func GetCloneDetectMethod(CloneDetectionMethod method) { - return Clones switch + return method switch { CloneDetectionMethod.HashPID => HashByPID, _ => HashByDetails, diff --git a/PKHeX.Core/PKM/Strings/StringConverter.cs b/PKHeX.Core/PKM/Strings/StringConverter.cs index 7f8d10d1e..2f639d1e0 100644 --- a/PKHeX.Core/PKM/Strings/StringConverter.cs +++ b/PKHeX.Core/PKM/Strings/StringConverter.cs @@ -15,13 +15,13 @@ public static class StringConverter /// Encoded data /// Generation string format /// Encoding is Japanese - /// Encoding is BigEndian + /// Encoding is Big Endian /// Length of data to read. /// Offset to read from /// Decoded string. - public static string GetString(byte[] data, int generation, bool jp, bool bigendian, int count, int offset = 0) + public static string GetString(byte[] data, int generation, bool jp, bool isBigEndian, int count, int offset = 0) { - if (bigendian) + if (isBigEndian) return generation == 3 ? StringConverter3.GetBEString3(data, offset, count) : StringConverter4.GetBEString4(data, offset, count); switch (generation) @@ -42,15 +42,15 @@ public static string GetString(byte[] data, int generation, bool jp, bool bigend /// Decoded string. /// Generation string format /// Encoding is Japanese - /// Encoding is BigEndian + /// Encoding is Big Endian /// /// /// Pad to given length /// Pad with value /// Encoded data. - public static byte[] SetString(string value, int generation, bool jp, bool bigendian, int maxLength, int language = 0, int padTo = 0, ushort padWith = 0) + public static byte[] SetString(string value, int generation, bool jp, bool isBigEndian, int maxLength, int language = 0, int padTo = 0, ushort padWith = 0) { - if (bigendian) + if (isBigEndian) return generation == 3 ? StringConverter3.SetBEString3(value, maxLength, padTo, padWith) : StringConverter4.SetBEString4(value, maxLength, padTo, padWith); switch (generation) @@ -168,36 +168,35 @@ public static byte[] SetString7b(string value, int maxLength, int language, int } /// - /// Converts a Unicode string to Generation 7 in-game chinese string. + /// Converts a Unicode string to Generation 7 in-game Chinese string. /// - /// Unicode string. + /// Unicode string. /// Detection of language for Traditional Chinese check - /// In-game chinese string. - private static string ConvertString2BinG7_zh(string inputstr, int lang) + /// In-game Chinese string. + private static string ConvertString2BinG7_zh(string input, int lang) { var str = new StringBuilder(); - bool cht = lang == 10; // A string cannot contain a mix of CHS and CHT characters. - bool IsCHT = inputstr.Any(chr => G7_CHT.ContainsKey(chr) && !G7_CHS.ContainsKey(chr)); - IsCHT |= cht && !inputstr.Any(chr => G7_CHT.ContainsKey(chr) ^ G7_CHS.ContainsKey(chr)); // CHS and CHT have the same display name - var table = IsCHT ? G7_CHT : G7_CHS; + bool traditional = input.Any(chr => G7_CHT.ContainsKey(chr) && !G7_CHS.ContainsKey(chr)) + || (lang == 10 && !input.Any(chr => G7_CHT.ContainsKey(chr) ^ G7_CHS.ContainsKey(chr))); // CHS and CHT have the same display name + var table = traditional ? G7_CHT : G7_CHS; - foreach (char chr in inputstr) + foreach (char chr in input) str.Append(table.TryGetValue(chr, out int index) ? (char)(index + Gen7_ZH_Ofs) : chr); return str.ToString(); } /// - /// Converts a Generation 7 in-game chinese string to Unicode string. + /// Converts a Generation 7 in-game Chinese string to Unicode string. /// - /// In-game chinese string. + /// In-game Chinese string. /// Unicode string. - private static string ConvertBin2StringG7_zh(string inputstr) + private static string ConvertBin2StringG7_zh(string input) { var str = new StringBuilder(); - foreach (var val in inputstr) - str.Append((char)Getg7zhChar(val)); + foreach (var val in input) + str.Append((char)GetGen7ChineseChar(val)); return str.ToString(); } @@ -206,7 +205,7 @@ private static string ConvertBin2StringG7_zh(string inputstr) /// /// Input value to shift /// Shifted character - private static ushort Getg7zhChar(ushort val) + private static ushort GetGen7ChineseChar(ushort val) { if (Gen7_ZH_Ofs <= val && val < Gen7_ZH_Ofs + Gen7_ZH.Length) return Gen7_ZH[val - Gen7_ZH_Ofs]; @@ -240,7 +239,7 @@ internal static string SanitizeString(string str) { if (str.Length == 0) return str; - var s = str.Replace('’', '\''); // farfetch'd + var s = str.Replace('’', '\''); // Farfetch'd // remap custom glyphs to unicode s = s.Replace('\uE08F', '♀'); // ♀ (gen6+) @@ -257,7 +256,7 @@ internal static string SanitizeString(string str) private static string UnSanitizeString7b(string str) { // gender chars always full width - return str.Replace('\'', '’'); // farfetch'd + return str.Replace('\'', '’'); // Farfetch'd } /// @@ -270,7 +269,7 @@ internal static string UnSanitizeString(string str, int generation) { var s = str; if (generation >= 6) - s = str.Replace('\'', '’'); // farfetch'd + s = str.Replace('\'', '’'); // Farfetch'd if (generation <= 5) { @@ -278,8 +277,8 @@ internal static string UnSanitizeString(string str, int generation) return s.Replace('\u2642', '\u246D'); // ♂ } - var langcontext = str.Except(FullToHalf); - bool fullwidth = langcontext.Select(c => c >> 12) // select the group the char belongs to + var context = str.Except(FullToHalf); + bool fullwidth = context.Select(c => c >> 12) // select the group the char belongs to .Any(c => c != 0 /* Latin */ && c != 0xE /* Special Symbols */); if (fullwidth) // jp/ko/zh strings diff --git a/PKHeX.Core/PKM/Strings/StringConverter12.cs b/PKHeX.Core/PKM/Strings/StringConverter12.cs index 75d4c497f..f4466a2c3 100644 --- a/PKHeX.Core/PKM/Strings/StringConverter12.cs +++ b/PKHeX.Core/PKM/Strings/StringConverter12.cs @@ -27,26 +27,26 @@ public static class StringConverter12 /// /// Checks if the input byte array is definitely of German origin (any ÄÖÜäöü) /// - /// Input string + /// Input string /// Indication if the data is from a definitely-german string - public static bool IsG12German(string data) => IsG12German(SetString1(data, data.Length, false)); + public static bool IsG12German(string value) => IsG12German(SetString1(value, value.Length, false)); /// /// Converts Generation 1 encoded data into a string. /// - /// Encoded data. + /// Encoded data. /// Offset to read from /// /// Data source is Japanese. /// Decoded string. - public static string GetString1(byte[] strdata, int offset, int count, bool jp) + public static string GetString1(byte[] data, int offset, int count, bool jp) { var dict = jp ? RBY2U_J : RBY2U_U; var s = new StringBuilder(); for (int i = 0; i < count; i++) { - var val = strdata[offset + i]; + var val = data[offset + i]; if (!dict.TryGetValue(val, out var c)) // Take valid values break; if (c == '\0') // Stop if Terminator @@ -59,13 +59,13 @@ public static string GetString1(byte[] strdata, int offset, int count, bool jp) /// /// Converts Generation 1 encoded data the same way Bank converts. /// - /// Generation 1 encoded data. + /// Generation 1 encoded data. /// Data source is Japanese. /// Decoded string. - public static string GetG1ConvertedString(byte[] strdata, bool jp) + public static string GetG1ConvertedString(byte[] data, bool jp) { var table = jp ? jp_table : us_table; - return string.Concat(strdata.TakeWhile(b => b != 0).Select(b => (char)table[b]).TakeWhile(b => b != 0)); + return string.Concat(data.TakeWhile(b => b != 0).Select(b => (char)table[b]).TakeWhile(b => b != 0)); } /// diff --git a/PKHeX.Core/PKM/Strings/StringConverter2KOR.cs b/PKHeX.Core/PKM/Strings/StringConverter2KOR.cs index c5256fc70..fabfce458 100644 --- a/PKHeX.Core/PKM/Strings/StringConverter2KOR.cs +++ b/PKHeX.Core/PKM/Strings/StringConverter2KOR.cs @@ -16,19 +16,19 @@ public static class StringConverter2KOR /// /// Converts Generation 2 Korean encoded data into a string. /// - /// Encoded data. + /// Encoded data. /// Offset to read from /// /// Decoded string. - public static string GetString2KOR(byte[] strdata, int offset, int count) + public static string GetString2KOR(byte[] data, int offset, int count) { var s = new StringBuilder(); for (int i = 0; i < count; i++) { - var val = strdata[offset + i]; + var val = data[offset + i]; var dict = val <= 0xB ? GSC2U_KOR[val] : RBY2U_U; if (val <= 0xB && val != 0) - val = strdata[offset + ++i]; + val = data[offset + ++i]; if (!dict.TryGetValue(val, out var c)) // Take valid values break; if (c == '\0') // Stop if Terminator diff --git a/PKHeX.Core/PKM/Strings/StringConverter3.cs b/PKHeX.Core/PKM/Strings/StringConverter3.cs index 0401c1bf0..96f8fb9e4 100644 --- a/PKHeX.Core/PKM/Strings/StringConverter3.cs +++ b/PKHeX.Core/PKM/Strings/StringConverter3.cs @@ -11,17 +11,17 @@ public static class StringConverter3 /// /// Converts a Generation 3 encoded value array to string. /// - /// Byte array containing string data. + /// Byte array containing string data. /// Offset to read from /// Length of data to read. /// Value source is Japanese font. /// Decoded string. - public static string GetString3(byte[] strdata, int offset, int count, bool jp) + public static string GetString3(byte[] data, int offset, int count, bool jp) { var s = new StringBuilder(); for (int i = 0; i < count; i++) { - var val = strdata[offset + i]; + var val = data[offset + i]; var c = GetG3Char(val, jp); // Convert to Unicode if (c == 0xFF) // Stop if Terminator/Invalid break; @@ -43,30 +43,30 @@ public static byte[] SetString3(string value, int maxLength, bool jp, int padTo { if (value.Length > maxLength) value = value.Substring(0, maxLength); // Hard cap - var strdata = new byte[value.Length + 1]; // +1 for 0xFF + var data = new byte[value.Length + 1]; // +1 for 0xFF for (int i = 0; i < value.Length; i++) { var chr = value[i]; var val = SetG3Char(chr, jp); if (val == 0xFF) // end { - Array.Resize(ref strdata, i + 1); + Array.Resize(ref data, i + 1); break; } - strdata[i] = val; + data[i] = val; } - if (strdata.Length > 0) - strdata[strdata.Length - 1] = 0xFF; - if (strdata.Length > maxLength && padTo <= maxLength) - Array.Resize(ref strdata, maxLength); - if (strdata.Length < padTo) + if (data.Length > 0) + data[data.Length - 1] = 0xFF; + if (data.Length > maxLength && padTo <= maxLength) + Array.Resize(ref data, maxLength); + if (data.Length < padTo) { - var start = strdata.Length; - Array.Resize(ref strdata, padTo); - for (int i = start; i < strdata.Length; i++) - strdata[i] = (byte)padWith; + var start = data.Length; + Array.Resize(ref data, padTo); + for (int i = start; i < data.Length; i++) + data[i] = (byte)padWith; } - return strdata; + return data; } /// Converts Big Endian encoded data to decoded string. @@ -79,7 +79,7 @@ public static string GetBEString3(byte[] data, int offset, int count) return Util.TrimFromZero(Encoding.BigEndianUnicode.GetString(data, offset, count)); } - /// Gets the bytes for a BigEndian string. + /// Gets the bytes for a Big Endian string. /// Decoded string. /// Maximum length /// Pad to given length diff --git a/PKHeX.Core/PKM/Strings/StringConverter345.cs b/PKHeX.Core/PKM/Strings/StringConverter345.cs index 270b69276..2a46ec96f 100644 --- a/PKHeX.Core/PKM/Strings/StringConverter345.cs +++ b/PKHeX.Core/PKM/Strings/StringConverter345.cs @@ -26,8 +26,14 @@ public static class StringConverter345 public static string TransferGlyphs56(string str) { - static char translate(char c) => Glyph56.TryGetValue(c, out var result) ? result : c; - return string.Concat(str.Select(translate)); + var result = new char[str.Length]; + var table = Glyph56; + for (int i = 0; i < str.Length; i++) + { + var c = str[i]; + result[i] = table.TryGetValue(c, out var translated) ? translated : c; + } + return new string(result); } private static readonly Dictionary Glyph56 = new Dictionary diff --git a/PKHeX.Core/PKM/Strings/StringConverter4.cs b/PKHeX.Core/PKM/Strings/StringConverter4.cs index 6fe0b8202..c535a03fb 100644 --- a/PKHeX.Core/PKM/Strings/StringConverter4.cs +++ b/PKHeX.Core/PKM/Strings/StringConverter4.cs @@ -45,29 +45,29 @@ public static byte[] SetString4(string value, int maxLength, int padTo = 0, usho .PadRight(value.Length + 1, (char)0xFFFF) // Null Terminator .PadRight(padTo, (char)padWith); // Padding - var strdata = new byte[temp.Length * 2]; + var data = new byte[temp.Length * 2]; for (int i = 0; i < temp.Length; i++) { var chr = temp[i]; var val = ConvertChar2ValueG4(chr); - BitConverter.GetBytes(val).CopyTo(strdata, i * 2); + BitConverter.GetBytes(val).CopyTo(data, i * 2); } - return strdata; + return data; } /// /// Converts Generation 4 Big Endian encoded character data to string. /// - /// Byte array containing encoded character data. + /// Byte array containing encoded character data. /// Offset to read from /// Length of data to read. /// Converted string. - public static string GetBEString4(byte[] strdata, int offset, int count) + public static string GetBEString4(byte[] data, int offset, int count) { var sb = new StringBuilder(); for (int i = 0; i < count; i += 2) { - var val = BigEndian.ToUInt16(strdata, offset + i); + var val = BigEndian.ToUInt16(data, offset + i); if (val == 0xFFFF) break; var chr = ConvertValue2CharG4(val); @@ -95,14 +95,14 @@ public static byte[] SetBEString4(string value, int maxLength, int padTo = 0, us .PadRight(value.Length + 1, (char)0xFFFF) // Null Terminator .PadRight(padTo, (char)padWith); // Padding - var strdata = new byte[temp.Length * 2]; + var data = new byte[temp.Length * 2]; for (int i = 0; i < temp.Length; i++) { var chr = temp[i]; var val = ConvertChar2ValueG4(chr); - BigEndian.GetBytes(val).CopyTo(strdata, i * 2); + BigEndian.GetBytes(val).CopyTo(data, i * 2); } - return strdata; + return data; } /// diff --git a/PKHeX.Core/PKM/Util/FormConverter.cs b/PKHeX.Core/PKM/Util/FormConverter.cs index a50aa14d1..8a0e4b70b 100644 --- a/PKHeX.Core/PKM/Util/FormConverter.cs +++ b/PKHeX.Core/PKM/Util/FormConverter.cs @@ -958,7 +958,7 @@ public static string[] GetAlcremieFormList(IReadOnlyList forms) // iterate downwards using form0 as pattern ref, replacing on final loop for (int i = deco - 1; i >= 0; i--) { - result[start + i] = $"{result[start]} ({((AlcremieDecoration)i).ToString()})"; + result[start + i] = $"{result[start]} ({(AlcremieDecoration)i})"; } } diff --git a/PKHeX.Core/PKM/Util/ItemConverter.cs b/PKHeX.Core/PKM/Util/ItemConverter.cs index f6f42a55b..037f9a1c5 100644 --- a/PKHeX.Core/PKM/Util/ItemConverter.cs +++ b/PKHeX.Core/PKM/Util/ItemConverter.cs @@ -21,40 +21,40 @@ internal static class ItemConverter /// /// Converts a Generation 3 Item ID to Generation 4+ Item ID. /// - /// Generation 3 Item ID. + /// Generation 3 Item ID. /// Generation 4+ Item ID. - internal static ushort GetG4Item(ushort g3val) => g3val > arr3.Length ? NaN : arr3[g3val]; + internal static ushort GetItemFuture3(ushort item) => item > arr3.Length ? NaN : arr3[item]; /// /// Converts a Generation 2 Item ID to Generation 4+ Item ID. /// - /// Generation 2 Item ID. + /// Generation 2 Item ID. /// Generation 4+ Item ID. - internal static ushort GetG4Item(byte g2val) => g2val > arr2.Length ? NaN : arr2[g2val]; + internal static ushort GetItemFuture2(byte item) => item > arr2.Length ? NaN : arr2[item]; /// /// Converts a Generation 4+ Item ID to Generation 3 Item ID. /// - /// Generation 4+ Item ID. + /// Generation 4+ Item ID. /// Generation 3 Item ID. - private static ushort GetG3Item(ushort g4val) + private static ushort GetItemOld3(ushort item) { - if (g4val == NaN) + if (item == NaN) return 0; - int index = Array.IndexOf(arr3, g4val); + int index = Array.IndexOf(arr3, item); return (ushort)Math.Max(0, index); } /// /// Converts a Generation 4+ Item ID to Generation 2 Item ID. /// - /// Generation 4+ Item ID. + /// Generation 4+ Item ID. /// Generation 2 Item ID. - private static byte GetG2Item(ushort g4val) + private static byte GetItemOld2(ushort item) { - if (g4val == NaN) + if (item == NaN) return 0; - int index = Array.IndexOf(arr2, g4val); + int index = Array.IndexOf(arr2, item); return (byte)Math.Max(0, index); } @@ -134,12 +134,12 @@ private static byte GetG2Item(ushort g4val) /// /// Converts a Generation 1 (Teru-sama) Item ID to Generation 2 Item ID. /// - /// Gen1 Item ID + /// Gen1 Item ID /// Gen2 Item ID /// https://github.com/pret/pokecrystal/blob/edb624c20ceb50eef9d73a5df0ac041cc156dd32/engine/link/link.asm#L1093-L1115 - private static int GetTeruSamaItem(int g1val) + private static int GetTeruSamaItem(int value) { - switch (g1val) + switch (value) { case 0x19: return 0x92; // Leftovers case 0x2D: return 0x53; // Bitter Berry @@ -156,15 +156,20 @@ private static int GetTeruSamaItem(int g1val) case 0xFF: return 0xAD; // Berry - default: return g1val; + default: return value; } } - internal static int GetG2ItemTransfer(int g1val) + /// + /// Converts a Gen1 Item to Gen2 Item. + /// + /// Gen1 Item + /// Gen2 Item + internal static int GetItemFuture1(int value) { - if (!IsItemTransferable12((ushort) g1val)) - return GetTeruSamaItem(g1val); - return g1val; + if (!IsItemTransferable12((ushort) value)) + return GetTeruSamaItem(value); + return value; } private static bool IsItemTransferable12(ushort item) => ((IList) Legal.HeldItems_GSC).Contains(item); @@ -172,38 +177,39 @@ internal static int GetG2ItemTransfer(int g1val) /// /// Gets a format specific value depending on the desired format and the provided item index & origin format. /// - /// Held Item to apply + /// Held Item to apply /// Format from importing /// Format required for holder - internal static int GetFormatHeldItemID(int item, int srcFormat, int destFormat) + /// destItem + internal static int GetItemForFormat(int srcItem, int srcFormat, int destFormat) { - if (item <= 0) + if (srcItem <= 0) return 0; if (destFormat == srcFormat) - return item; + return srcItem; if (destFormat != srcFormat && srcFormat <= 3) // past gen items { if (destFormat > 3) // try remapping - return srcFormat == 2 ? GetG4Item((byte)item) : GetG4Item((ushort)item); + return srcFormat == 2 ? GetItemFuture2((byte)srcItem) : GetItemFuture3((ushort)srcItem); if (destFormat > srcFormat) // can't set past gen items return 0; // ShowdownSet checks gen3 then gen2. For gen2 collisions (if any?) remap 3->4->2. - item = GetG4Item((ushort)item); - item = GetG2Item((ushort)item); - if (item <= 0) + srcItem = GetItemFuture3((ushort)srcItem); + srcItem = GetItemOld2((ushort)srcItem); + if (srcItem <= 0) return 0; } return destFormat switch { 1 => 0, - 2 => (byte) item, - 3 => GetG3Item((ushort) item), - _ => item + 2 => (byte) srcItem, + 3 => GetItemOld3((ushort) srcItem), + _ => srcItem }; } diff --git a/PKHeX.Core/PKM/Util/PKMConverter.cs b/PKHeX.Core/PKM/Util/PKMConverter.cs index ca37f75b0..9d1b09af3 100644 --- a/PKHeX.Core/PKM/Util/PKMConverter.cs +++ b/PKHeX.Core/PKM/Util/PKMConverter.cs @@ -111,11 +111,11 @@ public static int GetPKMDataFormat(byte[] data) switch (format) { case 1: - var PL1 = new PokeList1(data); - return PL1[0]; + var list1 = new PokeList1(data); + return list1[0]; case 2: - var PL2 = new PokeList2(data); - return PL2[0]; + var list2 = new PokeList2(data); + return list2[0]; case 3: return data.Length switch { @@ -223,24 +223,24 @@ public static bool IsConvertibleToFormat(PKM pk, int format) /// Converts a PKM from one Generation format to another. If it matches the destination format, the conversion will automatically return. /// /// PKM to convert - /// Format/Type to convert to + /// Format/Type to convert to /// Comments regarding the transfer's success/failure /// Converted PKM - public static PKM? ConvertToType(PKM pk, Type PKMType, out string comment) + public static PKM? ConvertToType(PKM pk, Type destType, out string comment) { Type fromType = pk.GetType(); - if (fromType == PKMType) + if (fromType == destType) { comment = "No need to convert, current format matches requested format."; return pk; } - var pkm = ConvertPKM(pk, PKMType, fromType, out comment); + var pkm = ConvertPKM(pk, destType, fromType, out comment); if (!AllowIncompatibleConversion || pkm != null) return pkm; // Try Incompatible Conversion - pkm = GetBlank(PKMType); + pkm = GetBlank(destType); pk.TransferPropertiesWithReflection(pkm); if (!IsPKMCompatibleWithModifications(pkm)) return null; @@ -248,54 +248,54 @@ public static bool IsConvertibleToFormat(PKM pk, int format) return pkm; } - private static PKM? ConvertPKM(PKM pk, Type PKMType, Type fromType, out string comment) + private static PKM? ConvertPKM(PKM pk, Type destType, Type srcType, out string comment) { if (IsNotTransferable(pk, out comment)) return null; - string toName = PKMType.Name; - string fromName = fromType.Name; - Debug.WriteLine($"Trying to convert {fromName} to {toName}."); + string destName = destType.Name; + string srcName = srcType.Name; + Debug.WriteLine($"Trying to convert {srcName} to {destName}."); - int toFormat = toName.Last() - '0'; - var pkm = ConvertPKM(pk, PKMType, toFormat, ref comment); + int destGeneration = destName.Last() - '0'; + var pkm = ConvertPKM(pk, destType, destGeneration, ref comment); var msg = pkm == null ? MsgPKMConvertFailFormat : MsgPKMConvertSuccess; - var formatted = string.Format(msg, fromName, toName); + var formatted = string.Format(msg, srcName, destName); comment = comment == null ? formatted : string.Concat(formatted, Environment.NewLine, comment); return pkm; } - private static PKM? ConvertPKM(PKM pk, Type PKMType, int toFormat, ref string comment) + private static PKM? ConvertPKM(PKM pk, Type destType, int destGeneration, ref string comment) { PKM? pkm = pk.Clone(); if (pkm.IsEgg) pkm.ForceHatchPKM(); while (true) { - pkm = IntermediaryConvert(pkm, PKMType, toFormat, ref comment); + pkm = IntermediaryConvert(pkm, destType, destGeneration, ref comment); if (pkm == null) // fail convert return null; - if (pkm.GetType() == PKMType) // finish convert + if (pkm.GetType() == destType) // finish convert return pkm; } } - private static PKM? IntermediaryConvert(PKM pk, Type PKMType, int toFormat, ref string comment) + private static PKM? IntermediaryConvert(PKM pk, Type destType, int destGeneration, ref string comment) { switch (pk) { // Non-sequential - case PK1 pk1 when toFormat > 2: return pk1.ConvertToPK7(); - case PK2 pk2 when toFormat > 2: return pk2.ConvertToPK7(); - case PK3 pk3 when PKMType == typeof(CK3): return pk3.ConvertToCK3(); - case PK3 pk3 when PKMType == typeof(XK3): return pk3.ConvertToXK3(); - case PK4 pk4 when PKMType == typeof(BK4): return pk4.ConvertToBK4(); + case PK1 pk1 when destGeneration > 2: return pk1.ConvertToPK7(); + case PK2 pk2 when destGeneration > 2: return pk2.ConvertToPK7(); + case PK3 pk3 when destType == typeof(CK3): return pk3.ConvertToCK3(); + case PK3 pk3 when destType == typeof(XK3): return pk3.ConvertToXK3(); + case PK4 pk4 when destType == typeof(BK4): return pk4.ConvertToBK4(); // Invalid case PK2 pk2 when pk.Species > Legal.MaxSpeciesID_1: var lang = pk2.Japanese ? (int)LanguageID.Japanese : (int)LanguageID.English; var name = SpeciesName.GetSpeciesName(pk2.Species, lang); - comment = string.Format(MsgPKMConvertFailFormat, name, PKMType.Name); + comment = string.Format(MsgPKMConvertFailFormat, name, destType.Name); return null; // Sequential @@ -411,25 +411,25 @@ public static bool TryMakePKMCompatible(PKM pk, PKM target, out string c, out PK return true; } - public static string GetIncompatibleGBMessage(PKM pk, bool destJP) + public static string GetIncompatibleGBMessage(PKM pk, bool destJapanese) { - var src = destJP ? MsgPKMConvertInternational : MsgPKMConvertJapanese; - var dest = !destJP ? MsgPKMConvertInternational : MsgPKMConvertJapanese; + var src = destJapanese ? MsgPKMConvertInternational : MsgPKMConvertJapanese; + var dest = !destJapanese ? MsgPKMConvertInternational : MsgPKMConvertJapanese; return string.Format(MsgPKMConvertIncompatible, src, pk.GetType().Name, dest); } - public static bool IsIncompatibleGB(int format, bool destJP, bool srcJP) => format <= 2 && destJP != srcJP; + public static bool IsIncompatibleGB(int format, bool destJapanese, bool srcJapanese) => format <= 2 && destJapanese != srcJapanese; /// /// Gets a Blank object of the specified type. /// - /// Type of instance desired. + /// Type of instance desired. /// New instance of a blank object. - public static PKM GetBlank(Type t) + public static PKM GetBlank(Type type) { - var constructors = t.GetTypeInfo().DeclaredConstructors.Where(z => !z.IsStatic); + var constructors = type.GetTypeInfo().DeclaredConstructors.Where(z => !z.IsStatic); var argCount = constructors.Min(z => z.GetParameters().Length); - return (PKM)Activator.CreateInstance(t, new object[argCount]); + return (PKM)Activator.CreateInstance(type, new object[argCount]); } public static PKM GetBlank(int gen, GameVersion ver) diff --git a/PKHeX.Core/PKM/Util/PKX.cs b/PKHeX.Core/PKM/Util/PKX.cs index c76e6a845..3bdf4c250 100644 --- a/PKHeX.Core/PKM/Util/PKX.cs +++ b/PKHeX.Core/PKM/Util/PKX.cs @@ -126,8 +126,7 @@ public static uint GetRandomPID(Random rnd, int species, int gender, int origin, int gt = Personal[species].Gender; bool g34 = origin <= 15; - bool g5 = 20 <= origin && origin <= 23; // bw/b2w2 - uint abilBitVal = g5 ? oldPID & 0x0001_0000 : oldPID & 0x0000_0001; + uint abilBitVal = g34 ? oldPID & 0x0000_0001 : oldPID & 0x0001_0000; bool g3unown = origin <= 5 && species == (int)Species.Unown; bool singleGender = gt == 255 || gt == 254 || gt == 0; // skip gender check @@ -151,7 +150,7 @@ public static uint GetRandomPID(Random rnd, int species, int gender, int origin, if (abilBitVal != (pid & 0x0000_0001)) // keep ability bits continue; } - else if (g5) + else { if (abilBitVal != (pid & 0x0001_0000)) // keep ability bits continue; @@ -182,23 +181,23 @@ public static int GetUnownForm(uint pid) /// Gets the gender ID of the species based on the Personality ID. /// /// National Dex ID. - /// Personality ID. + /// Personality ID. /// Gender ID (0/1/2) /// This method should only be used for Generations 3-5 origin. - public static int GetGenderFromPID(int species, uint PID) + public static int GetGenderFromPID(int species, uint pid) { int gt = Personal[species].Gender; - return GetGenderFromPIDAndRatio(PID, gt); + return GetGenderFromPIDAndRatio(pid, gt); } - public static int GetGenderFromPIDAndRatio(uint PID, int gr) + public static int GetGenderFromPIDAndRatio(uint pid, int gr) { return gr switch { 255 => 2, 254 => 1, 0 => 0, - _ => ((PID & 0xFF) < gr ? 1 : 0) + _ => ((pid & 0xFF) < gr ? 1 : 0) }; } diff --git a/PKHeX.Core/PKM/Util/PokeCrypto.cs b/PKHeX.Core/PKM/Util/PokeCrypto.cs index 8a2a471fd..b3d7b4907 100644 --- a/PKHeX.Core/PKM/Util/PokeCrypto.cs +++ b/PKHeX.Core/PKM/Util/PokeCrypto.cs @@ -268,9 +268,9 @@ public static byte[] DecryptArray3(byte[] ekm) /// /// Shuffles an 80 byte format Generation 3 Pokémon byte array. /// - /// Unshuffled data. + /// Un-shuffled data. /// Block order shuffle value - /// Unshuffled data. + /// Un-shuffled data. private static byte[] ShuffleArray3(byte[] data, uint sv) { byte[] sdata = (byte[])data.Clone(); diff --git a/PKHeX.Core/PKM/Util/QRMessageUtil.cs b/PKHeX.Core/PKM/Util/QRMessageUtil.cs index 8d8ab814f..de32ae5ea 100644 --- a/PKHeX.Core/PKM/Util/QRMessageUtil.cs +++ b/PKHeX.Core/PKM/Util/QRMessageUtil.cs @@ -22,10 +22,10 @@ public static class QRMessageUtil /// Decoded object, null if invalid. public static PKM? GetPKM(string message, int format) { - var pkdata = DecodeMessagePKM(message); - if (pkdata == null) + var data = DecodeMessagePKM(message); + if (data == null) return null; - return PKMConverter.GetPKMfromBytes(pkdata, format); + return PKMConverter.GetPKMfromBytes(data, format); } /// @@ -67,8 +67,8 @@ public static string GetMessage(DataMysteryGift mg) public static string GetMessageBase64(byte[] data, string server) { - string qrdata = Convert.ToBase64String(data); - return server + qrdata; + string payload = Convert.ToBase64String(data); + return server + payload; } private static byte[]? DecodeMessagePKM(string message) diff --git a/PKHeX.Core/PKM/Util/SpeciesConverter.cs b/PKHeX.Core/PKM/Util/SpeciesConverter.cs index 556fe37d1..6f044bbbb 100644 --- a/PKHeX.Core/PKM/Util/SpeciesConverter.cs +++ b/PKHeX.Core/PKM/Util/SpeciesConverter.cs @@ -9,30 +9,30 @@ internal static class SpeciesConverter /// /// Converts Generation 1 species ID to National Dex ID. /// - /// Generation 1 species ID. + /// Generation 1 species ID. /// National Dex ID. - public static int GetG1Species(int raw_id) => table1_National[raw_id]; + public static int GetG1Species(int raw) => table1_National[raw]; /// /// Converts a National Dex ID to Generation 1 species ID. /// - /// National Dex ID. + /// National Dex ID. /// Generation 1 species ID. - public static int SetG1Species(int dex_id) => dex_id >= table1_Internal.Length ? 0 : table1_Internal[dex_id]; + public static int SetG1Species(int species) => species >= table1_Internal.Length ? 0 : table1_Internal[species]; /// /// Converts a National Dex ID to Generation 3 species ID. /// - /// National Dex ID + /// National Dex ID /// Generation 3 species ID. - public static int GetG3Species(int g4index) => (uint)g4index >= table3_Internal.Length ? 0 : table3_Internal[g4index]; + public static int GetG3Species(int species) => (uint)species >= table3_Internal.Length ? 0 : table3_Internal[species]; /// /// Converts Generation 3 species ID to National Dex ID. /// - /// Generation 3 species ID. + /// Generation 3 species ID. /// National Dex ID. - public static int GetG4Species(int g3index) => (uint)g3index >= table3_National.Length ? 0 : table3_National[g3index]; + public static int GetG4Species(int raw) => (uint)raw >= table3_National.Length ? 0 : table3_National[raw]; private static readonly byte[] table1_Internal = { 0x00, 0x99, 0x09, 0x9A, 0xB0, 0xB2, 0xB4, 0xB1, 0xB3, 0x1C, 0x7B, 0x7C, 0x7D, 0x70, 0x71, 0x72, 0x24, 0x96, 0x97, 0xA5, 0xA6, 0x05, 0x23, 0x6C, 0x2D, 0x54, 0x55, 0x60, 0x61, 0x0F, 0xA8, 0x10, 0x03, 0xA7, 0x07, 0x04, 0x8E, 0x52, 0x53, 0x64, 0x65, 0x6B, 0x82, 0xB9, 0xBA, 0xBB, 0x6D, 0x2E, 0x41, 0x77, 0x3B, 0x76, 0x4D, 0x90, 0x2F, 0x80, 0x39, 0x75, 0x21, 0x14, 0x47, 0x6E, 0x6F, 0x94, 0x26, 0x95, 0x6A, 0x29, 0x7E, 0xBC, 0xBD, 0xBE, 0x18, 0x9B, 0xA9, 0x27, 0x31, 0xA3, 0xA4, 0x25, 0x08, 0xAD, 0x36, 0x40, 0x46, 0x74, 0x3A, 0x78, 0x0D, 0x88, 0x17, 0x8B, 0x19, 0x93, 0x0E, 0x22, 0x30, 0x81, 0x4E, 0x8A, 0x06, 0x8D, 0x0C, 0x0A, 0x11, 0x91, 0x2B, 0x2C, 0x0B, 0x37, 0x8F, 0x12, 0x01, 0x28, 0x1E, 0x02, 0x5C, 0x5D, 0x9D, 0x9E, 0x1B, 0x98, 0x2A, 0x1A, 0x48, 0x35, 0x33, 0x1D, 0x3C, 0x85, 0x16, 0x13, 0x4C, 0x66, 0x69, 0x68, 0x67, 0xAA, 0x62, 0x63, 0x5A, 0x5B, 0xAB, 0x84, 0x4A, 0x4B, 0x49, 0x58, 0x59, 0x42, 0x83, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; private static readonly byte[] table1_National = { 0x00, 0x70, 0x73, 0x20, 0x23, 0x15, 0x64, 0x22, 0x50, 0x02, 0x67, 0x6C, 0x66, 0x58, 0x5E, 0x1D, 0x1F, 0x68, 0x6F, 0x83, 0x3B, 0x97, 0x82, 0x5A, 0x48, 0x5C, 0x7B, 0x78, 0x09, 0x7F, 0x72, 0x00, 0x00, 0x3A, 0x5F, 0x16, 0x10, 0x4F, 0x40, 0x4B, 0x71, 0x43, 0x7A, 0x6A, 0x6B, 0x18, 0x2F, 0x36, 0x60, 0x4C, 0x00, 0x7E, 0x00, 0x7D, 0x52, 0x6D, 0x00, 0x38, 0x56, 0x32, 0x80, 0x00, 0x00, 0x00, 0x53, 0x30, 0x95, 0x00, 0x00, 0x00, 0x54, 0x3C, 0x7C, 0x92, 0x90, 0x91, 0x84, 0x34, 0x62, 0x00, 0x00, 0x00, 0x25, 0x26, 0x19, 0x1A, 0x00, 0x00, 0x93, 0x94, 0x8C, 0x8D, 0x74, 0x75, 0x00, 0x00, 0x1B, 0x1C, 0x8A, 0x8B, 0x27, 0x28, 0x85, 0x88, 0x87, 0x86, 0x42, 0x29, 0x17, 0x2E, 0x3D, 0x3E, 0x0D, 0x0E, 0x0F, 0x00, 0x55, 0x39, 0x33, 0x31, 0x57, 0x00, 0x00, 0x0A, 0x0B, 0x0C, 0x44, 0x00, 0x37, 0x61, 0x2A, 0x96, 0x8F, 0x81, 0x00, 0x00, 0x59, 0x00, 0x63, 0x5B, 0x00, 0x65, 0x24, 0x6E, 0x35, 0x69, 0x00, 0x5D, 0x3F, 0x41, 0x11, 0x12, 0x79, 0x01, 0x03, 0x49, 0x00, 0x76, 0x77, 0x00, 0x00, 0x00, 0x00, 0x4D, 0x4E, 0x13, 0x14, 0x21, 0x1E, 0x4A, 0x89, 0x8E, 0x00, 0x51, 0x00, 0x00, 0x04, 0x07, 0x05, 0x08, 0x06, 0x00, 0x00, 0x00, 0x00, 0x2B, 0x2C, 0x2D, 0x45, 0x46, 0x47, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; diff --git a/PKHeX.Core/PKM/XK3.cs b/PKHeX.Core/PKM/XK3.cs index 1fb67c746..8f0b29cac 100644 --- a/PKHeX.Core/PKM/XK3.cs +++ b/PKHeX.Core/PKM/XK3.cs @@ -38,7 +38,7 @@ public sealed class XK3 : G3PKM, IShadowPKM public override bool ChecksumValid => Valid; public override int Species { get => SpeciesConverter.GetG4Species(BigEndian.ToUInt16(Data, 0x00)); set => BigEndian.GetBytes((ushort)SpeciesConverter.GetG3Species(value)).CopyTo(Data, 0x00); } - public override int SpriteItem => ItemConverter.GetG4Item((ushort)HeldItem); + public override int SpriteItem => ItemConverter.GetItemFuture3((ushort)HeldItem); public override int HeldItem { get => BigEndian.ToUInt16(Data, 0x02); set => BigEndian.GetBytes((ushort)value).CopyTo(Data, 0x02); } public override int Stat_HPCurrent { get => BigEndian.ToUInt16(Data, 0x04); set => BigEndian.GetBytes((ushort)value).CopyTo(Data, 0x04); } public override int OT_Friendship { get => BigEndian.ToUInt16(Data, 0x06); set => BigEndian.GetBytes((ushort)value).CopyTo(Data, 0x06); } diff --git a/PKHeX.Core/PersonalInfo/PersonalInfo.cs b/PKHeX.Core/PersonalInfo/PersonalInfo.cs index fc4bc4753..aae71c950 100644 --- a/PKHeX.Core/PersonalInfo/PersonalInfo.cs +++ b/PKHeX.Core/PersonalInfo/PersonalInfo.cs @@ -123,7 +123,7 @@ public int[] Stats public abstract int CatchRate { get; set; } /// - /// Evolution Stage value (or equivalent for unevolved). + /// Evolution Stage value (or equivalent for un-evolved). /// public virtual int EvoStage { get; set; } @@ -133,7 +133,7 @@ public int[] Stats public abstract int[] Items { get; set; } /// - /// Gender Ratio value determining if the entry is a fixed gender or bigendered. + /// Gender Ratio value determining if the entry is a fixed gender or bi-gendered. /// public abstract int Gender { get; set; } @@ -183,7 +183,7 @@ public int[] Stats public abstract int BaseEXP { get; set; } /// - /// Main color ID of the entry. The majority of the pkm's color is of this color, usually. + /// Main color ID of the entry. The majority of the Pokémon's color is of this color, usually. /// public abstract int Color { get; set; } diff --git a/PKHeX.Core/PersonalInfo/PersonalTable.cs b/PKHeX.Core/PersonalInfo/PersonalTable.cs index f498a28c0..c42b01555 100644 --- a/PKHeX.Core/PersonalInfo/PersonalTable.cs +++ b/PKHeX.Core/PersonalInfo/PersonalTable.cs @@ -192,11 +192,11 @@ private static void FixPersonalTableG1() private static void PopulateGen3Tutors() { // Update Gen3 data with Emerald's data, FR/LG is a subset of Emerald's compatibility. - var TMHM = BinLinker.Unpack(Util.GetBinaryResource("hmtm_g3.pkl"), "g3"); + var machine = BinLinker.Unpack(Util.GetBinaryResource("hmtm_g3.pkl"), "g3"); var tutors = BinLinker.Unpack(Util.GetBinaryResource("tutors_g3.pkl"), "g3"); for (int i = 0; i <= Legal.MaxSpeciesID_3; i++) { - E[i].AddTMHM(TMHM[i]); + E[i].AddTMHM(machine[i]); E[i].AddTypeTutors(tutors[i]); } } @@ -352,12 +352,12 @@ public string[] GetPersonalEntryList(string[][] AltForms, string[] species, int result[i] = species[i]; if (AltForms[i].Length == 0) continue; - int altformpointer = this[i].FormStatsIndex; - if (altformpointer <= 0) + int basePtr = this[i].FormStatsIndex; + if (basePtr <= 0) continue; for (int j = 1; j < AltForms[i].Length; j++) { - int ptr = altformpointer + j - 1; + int ptr = basePtr + j - 1; baseForm[ptr] = i; formVal[ptr] = j; result[ptr] = AltForms[i][j]; @@ -370,12 +370,12 @@ public string[] GetPersonalEntryList(string[][] AltForms, string[] species, int /// Checks to see if either of the input type combinations exist in the table. /// /// Only useful for checking Generation 1 and properties. - /// First type - /// Second type + /// First type + /// Second type /// Indication that the combination exists in the table. - public bool IsValidTypeCombination(int Type1, int Type2) + public bool IsValidTypeCombination(int type1, int type2) { - return Table.Any(p => p.IsValidTypeCombination(Type1, Type2)); + return Table.Any(p => p.IsValidTypeCombination(type1, type2)); } } } diff --git a/PKHeX.Core/Saves/MemeCrypto/MemeCrypto.cs b/PKHeX.Core/Saves/MemeCrypto/MemeCrypto.cs index cc8e10b7c..9a6e282cb 100644 --- a/PKHeX.Core/Saves/MemeCrypto/MemeCrypto.cs +++ b/PKHeX.Core/Saves/MemeCrypto/MemeCrypto.cs @@ -23,7 +23,7 @@ public static bool VerifyMemePOKE(byte[] input, out byte[] output) break; } - foreach (var len in new[] { memeLen, memeLen - 2 }) // Account for Pokedex QR Edge case + foreach (var len in new[] { memeLen, memeLen - 2 }) // Account for Pokédex QR Edge case { if (VerifyMemeData(input, out output, 0, len, memeIndex)) return true; @@ -54,18 +54,18 @@ public static bool VerifyMemeData(byte[] input, out byte[] output, MemeKeyIndex output = input; return false; } - var memekey = new MemeKey(keyIndex); + var key = new MemeKey(keyIndex); output = (byte[])input.Clone(); var sigBuffer = new byte[0x60]; Array.Copy(input, input.Length - 0x60, sigBuffer, 0, 0x60); - sigBuffer = memekey.RsaPublic(sigBuffer); + sigBuffer = key.RsaPublic(sigBuffer); using var sha1 = SHA1.Create(); foreach (var orVal in new byte[] { 0, 0x80 }) { sigBuffer[0x0] |= orVal; sigBuffer.CopyTo(output, output.Length - 0x60); - memekey.AesDecrypt(output).CopyTo(output, 0); + key.AesDecrypt(output).CopyTo(output, 0); // Check for 8-byte equality. var computed = BitConverter.ToUInt64(sha1.ComputeHash(output, 0, output.Length - 0x8), 0); var existing = BitConverter.ToUInt64(output, output.Length - 0x8); @@ -112,8 +112,8 @@ public static byte[] SignMemeData(byte[] input, MemeKeyIndex keyIndex = MemeKeyI // Validate Input if (input.Length < 0x60) throw new ArgumentException("Cannot memesign a buffer less than 0x60 bytes in size!"); - var memekey = new MemeKey(keyIndex); - if (!memekey.CanResign) + var key = new MemeKey(keyIndex); + if (!key.CanResign) throw new ArgumentException("Cannot sign with the specified memekey!"); var output = (byte[])input.Clone(); @@ -125,11 +125,11 @@ public static byte[] SignMemeData(byte[] input, MemeKeyIndex keyIndex = MemeKeyI } // Perform AES operations - output = memekey.AesEncrypt(output); + output = key.AesEncrypt(output); var sigBuffer = new byte[0x60]; Array.Copy(output, output.Length - 0x60, sigBuffer, 0, 0x60); sigBuffer[0] &= 0x7F; - sigBuffer = memekey.RsaPrivate(sigBuffer); + sigBuffer = key.RsaPrivate(sigBuffer); sigBuffer.CopyTo(output, output.Length - 0x60); return output; } @@ -151,23 +151,23 @@ public static byte[] Resign7(byte[] sav7) var ChecksumSignatureLength = isUSUM ? 0x150 : 0x140; const int MemeCryptoSignatureLength = 0x80; - var outSav = (byte[])sav7.Clone(); + var result = (byte[])sav7.Clone(); using (var sha256 = SHA256.Create()) { // Store current signature - var CurSig = new byte[MemeCryptoSignatureLength]; - Buffer.BlockCopy(sav7, MemeCryptoOffset, CurSig, 0, MemeCryptoSignatureLength); + var oldSig = new byte[MemeCryptoSignatureLength]; + Buffer.BlockCopy(sav7, MemeCryptoOffset, oldSig, 0, MemeCryptoSignatureLength); var newSig = sha256.ComputeHash(sav7, ChecksumTableOffset, ChecksumSignatureLength); Array.Resize(ref newSig, MemeCryptoSignatureLength); - if (VerifyMemeData(CurSig, out var memeSig, MemeKeyIndex.PokedexAndSaveFile)) + if (VerifyMemeData(oldSig, out var memeSig, MemeKeyIndex.PokedexAndSaveFile)) Buffer.BlockCopy(memeSig, 0x20, newSig, 0x20, 0x60); - SignMemeData(newSig).CopyTo(outSav, MemeCryptoOffset); + SignMemeData(newSig).CopyTo(result, MemeCryptoOffset); } - return outSav; + return result; } } } diff --git a/PKHeX.Core/Saves/SAV3.cs b/PKHeX.Core/Saves/SAV3.cs index 2670094b7..14cac3f18 100644 --- a/PKHeX.Core/Saves/SAV3.cs +++ b/PKHeX.Core/Saves/SAV3.cs @@ -323,7 +323,7 @@ protected override void SetChecksums() if (index == -1) continue; int len = chunkLength[index]; - ushort chk = Checksums.CRC32(Data, ofs, len); + ushort chk = Checksums.CheckSum32(Data, ofs, len); BitConverter.GetBytes(chk).CopyTo(Data, ofs + 0xFF6); } @@ -332,11 +332,11 @@ protected override void SetChecksums() // Hall of Fame Checksums { - ushort chk = Checksums.CRC32(Data, 0x1C000, SIZE_BLOCK_USED); + ushort chk = Checksums.CheckSum32(Data, 0x1C000, SIZE_BLOCK_USED); BitConverter.GetBytes(chk).CopyTo(Data, 0x1CFF4); } { - ushort chk = Checksums.CRC32(Data, 0x1D000, SIZE_BLOCK_USED); + ushort chk = Checksums.CheckSum32(Data, 0x1D000, SIZE_BLOCK_USED); BitConverter.GetBytes(chk).CopyTo(Data, 0x1DFF4); } } @@ -364,7 +364,7 @@ public override bool ChecksumsValid private bool IsChunkValidHoF(int ofs) { - ushort chk = Checksums.CRC32(Data, ofs, SIZE_BLOCK_USED); + ushort chk = Checksums.CheckSum32(Data, ofs, SIZE_BLOCK_USED); return chk == BitConverter.ToUInt16(Data, ofs + 0xFF4); } @@ -372,7 +372,7 @@ private bool IsChunkValid(int i) { int ofs = ABO + (i * SIZE_BLOCK); int len = chunkLength[BlockOrder[i]]; - ushort chk = Checksums.CRC32(Data, ofs, len); + ushort chk = Checksums.CheckSum32(Data, ofs, len); return chk == BitConverter.ToUInt16(Data, ofs + 0xFF6); } diff --git a/PKHeX.Core/Saves/Substructures/Inventory/InventoryPouch.cs b/PKHeX.Core/Saves/Substructures/Inventory/InventoryPouch.cs index 6fd066011..f34f19a67 100644 --- a/PKHeX.Core/Saves/Substructures/Inventory/InventoryPouch.cs +++ b/PKHeX.Core/Saves/Substructures/Inventory/InventoryPouch.cs @@ -172,31 +172,31 @@ private void GiveAllItems(IReadOnlyList newItems, int count = -1) } } - public bool IsValidItemAndCount(ITrainerInfo SAV, int itemindex, bool HasNew, bool HaX, ref int itemcnt) + public bool IsValidItemAndCount(ITrainerInfo sav, int item, bool HasNew, bool HaX, ref int count) { - if (HaX && SAV.Generation != 7) // Gen7 has true cap at 1023, keep 999 cap. + if (HaX && sav.Generation != 7) // Gen7 has true cap at 1023, keep 999 cap. { // Cap at absolute maximum - if (SAV.Generation <= 2 && itemcnt > byte.MaxValue) - itemcnt = byte.MaxValue; - else if (SAV.Generation >= 3 && itemcnt > ushort.MaxValue) - itemcnt = ushort.MaxValue; + if (sav.Generation <= 2 && count > byte.MaxValue) + count = byte.MaxValue; + else if (sav.Generation >= 3 && count > ushort.MaxValue) + count = ushort.MaxValue; return true; } - if (itemcnt > MaxCount) + if (count > MaxCount) { - if (itemindex == 797 && itemcnt >= 2) // Edge case when for some reason the item count for Z-Ring was 2 in an unedited save and set 1 after using PKHeX - itemcnt = 2; + if (item == 797 && count >= 2) // Edge case when for some reason the item count for Z-Ring was 2 in an unedited save and set 1 after using PKHeX + count = 2; else - itemcnt = MaxCount; // Cap at pouch maximum + count = MaxCount; // Cap at pouch maximum } - else if (itemcnt <= 0 && !HasNew) + else if (count <= 0 && !HasNew) { return false; } - itemcnt = GetSuggestedItemCount(SAV, itemindex, itemcnt); + count = GetSuggestedItemCount(sav, item, count); return true; } diff --git a/PKHeX.Core/Saves/Util/BoxUtil.cs b/PKHeX.Core/Saves/Util/BoxUtil.cs index 00fea87b0..f1dcb323b 100644 --- a/PKHeX.Core/Saves/Util/BoxUtil.cs +++ b/PKHeX.Core/Saves/Util/BoxUtil.cs @@ -14,32 +14,32 @@ public static class BoxUtil /// /// Dumps a folder of files to the . /// - /// that is being dumped from. + /// that is being dumped from. /// Folder to store files. /// Option to save in child folders with the Box Name as the folder name. /// -1 if aborted, otherwise the amount of files dumped. - public static int DumpBoxes(this SaveFile SAV, string path, bool boxFolders = false) + public static int DumpBoxes(this SaveFile sav, string path, bool boxFolders = false) { - if (!SAV.HasBox) + if (!sav.HasBox) return -1; - var boxdata = SAV.BoxData; + var boxData = sav.BoxData; var ctr = 0; - foreach (var pk in boxdata) + foreach (var pk in boxData) { if (pk.Species == 0 || !pk.Valid) continue; - var boxfolder = path; + var boxFolder = path; if (boxFolders) { - var boxName = Util.CleanFileName(SAV.GetBoxName(pk.Box - 1)); - boxfolder = Path.Combine(path, boxName); - Directory.CreateDirectory(boxfolder); + var boxName = Util.CleanFileName(sav.GetBoxName(pk.Box - 1)); + boxFolder = Path.Combine(path, boxName); + Directory.CreateDirectory(boxFolder); } var fileName = Util.CleanFileName(pk.FileName); - var fn = Path.Combine(boxfolder, fileName); + var fn = Path.Combine(boxFolder, fileName); if (File.Exists(fn)) continue; @@ -52,18 +52,18 @@ public static int DumpBoxes(this SaveFile SAV, string path, bool boxFolders = fa /// /// Dumps the to a folder with individual decrypted files. /// - /// that is being dumped from. + /// that is being dumped from. /// Folder to store files. /// Box contents to be dumped. /// -1 if aborted, otherwise the amount of files dumped. - public static int DumpBox(this SaveFile SAV, string path, int currentBox) + public static int DumpBox(this SaveFile sav, string path, int currentBox) { - if (!SAV.HasBox) + if (!sav.HasBox) return -1; - var boxdata = SAV.BoxData; + var boxData = sav.BoxData; var ctr = 0; - foreach (var pk in boxdata) + foreach (var pk in boxData) { if (pk.Species == 0 || !pk.Valid || pk.Box - 1 != currentBox) continue; @@ -81,7 +81,7 @@ public static int DumpBox(this SaveFile SAV, string path, int currentBox) /// /// Loads a folder of files to the . /// - /// to load folder to. + /// to load folder to. /// Folder to load files from. Files are only loaded from the top directory. /// Result message from the method. /// First box to start loading to. All prior boxes are not modified. @@ -90,37 +90,37 @@ public static int DumpBox(this SaveFile SAV, string path, int currentBox) /// Bypass option to not modify properties when setting to Save File. /// Enumerate all files even in sub-folders. /// Count of files imported. - public static int LoadBoxes(this SaveFile SAV, string path, out string result, int boxStart = 0, bool boxClear = false, bool overwrite = false, PKMImportSetting noSetb = PKMImportSetting.UseDefault, bool all = false) + public static int LoadBoxes(this SaveFile sav, string path, out string result, int boxStart = 0, bool boxClear = false, bool overwrite = false, PKMImportSetting noSetb = PKMImportSetting.UseDefault, bool all = false) { if (string.IsNullOrWhiteSpace(path) || !Directory.Exists(path)) { result = MsgSaveBoxExportPathInvalid; return -1; } - var opt = all ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly; - var filepaths = Directory.EnumerateFiles(path, "*.*", opt); - return SAV.LoadBoxes(filepaths, out result, boxStart, boxClear, overwrite, noSetb); + var option = all ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly; + var files = Directory.EnumerateFiles(path, "*.*", option); + return sav.LoadBoxes(files, out result, boxStart, boxClear, overwrite, noSetb); } /// /// Loads a folder of files to the . /// - /// to load folder to. - /// Files to load files from. + /// to load folder to. + /// Files to load files from. /// Result message from the method. /// First box to start loading to. All prior boxes are not modified. /// Instruction to clear boxes after the starting box. /// Overwrite existing full slots. If true, will only overwrite empty slots. /// Bypass option to not modify properties when setting to Save File. /// Count of files imported. - public static int LoadBoxes(this SaveFile SAV, IEnumerable filepaths, out string result, int boxStart = 0, bool boxClear = false, bool overwrite = false, PKMImportSetting noSetb = PKMImportSetting.UseDefault) + public static int LoadBoxes(this SaveFile sav, IEnumerable files, out string result, int boxStart = 0, bool boxClear = false, bool overwrite = false, PKMImportSetting noSetb = PKMImportSetting.UseDefault) { - var pks = GetPossiblePKMsFromPaths(SAV, filepaths); - return SAV.LoadBoxes(pks, out result, boxStart, boxClear, overwrite, noSetb); + var pks = GetPossiblePKMsFromPaths(sav, files); + return sav.LoadBoxes(pks, out result, boxStart, boxClear, overwrite, noSetb); } /// /// Loads a folder of files to the . /// - /// to load folder to. + /// to load folder to. /// Encounters to create files from. /// Result message from the method. /// First box to start loading to. All prior boxes are not modified. @@ -128,16 +128,16 @@ public static int LoadBoxes(this SaveFile SAV, IEnumerable filepaths, ou /// Overwrite existing full slots. If true, will only overwrite empty slots. /// Bypass option to not modify properties when setting to Save File. /// Count of files imported. - public static int LoadBoxes(this SaveFile SAV, IEnumerable encounters, out string result, int boxStart = 0, bool boxClear = false, bool overwrite = false, PKMImportSetting noSetb = PKMImportSetting.UseDefault) + public static int LoadBoxes(this SaveFile sav, IEnumerable encounters, out string result, int boxStart = 0, bool boxClear = false, bool overwrite = false, PKMImportSetting noSetb = PKMImportSetting.UseDefault) { - var pks = encounters.Select(z => z.ConvertToPKM(SAV)); - return SAV.LoadBoxes(pks, out result, boxStart, boxClear, overwrite, noSetb); + var pks = encounters.Select(z => z.ConvertToPKM(sav)); + return sav.LoadBoxes(pks, out result, boxStart, boxClear, overwrite, noSetb); } /// /// Loads a folder of files to the . /// - /// to load folder to. + /// to load folder to. /// Unconverted objects to load. /// Result message from the method. /// First box to start loading to. All prior boxes are not modified. @@ -145,16 +145,16 @@ public static int LoadBoxes(this SaveFile SAV, IEnumerable encou /// Overwrite existing full slots. If true, will only overwrite empty slots. /// Bypass option to not modify properties when setting to Save File. /// True if any files are imported. - public static int LoadBoxes(this SaveFile SAV, IEnumerable pks, out string result, int boxStart = 0, bool boxClear = false, bool overwrite = false, PKMImportSetting noSetb = PKMImportSetting.UseDefault) + public static int LoadBoxes(this SaveFile sav, IEnumerable pks, out string result, int boxStart = 0, bool boxClear = false, bool overwrite = false, PKMImportSetting noSetb = PKMImportSetting.UseDefault) { - if (!SAV.HasBox) + if (!sav.HasBox) { result = MsgSaveBoxFailNone; return -1; } - var compat = SAV.GetCompatible(pks); + var compat = sav.GetCompatible(pks); if (boxClear) - SAV.ClearBoxes(boxStart); + sav.ClearBoxes(boxStart); - int ctr = SAV.ImportPKMs(compat, overwrite, boxStart, noSetb); + int ctr = sav.ImportPKMs(compat, overwrite, boxStart, noSetb); if (ctr <= 0) { result = MsgSaveBoxImportNoFiles; @@ -165,9 +165,9 @@ public static int LoadBoxes(this SaveFile SAV, IEnumerable pks, out string return ctr; } - public static IEnumerable GetPKMsFromPaths(IEnumerable filepaths, int generation) + public static IEnumerable GetPKMsFromPaths(IEnumerable files, int generation) { - var result = filepaths + var result = files .Where(file => PKX.IsPKM(new FileInfo(file).Length)) .Select(File.ReadAllBytes) .Select(data => PKMConverter.GetPKMfromBytes(data, prefer: generation)); @@ -179,9 +179,9 @@ public static IEnumerable GetPKMsFromPaths(IEnumerable filepaths, i } } - private static IEnumerable GetPossiblePKMsFromPaths(SaveFile sav, IEnumerable filepaths) + private static IEnumerable GetPossiblePKMsFromPaths(SaveFile sav, IEnumerable files) { - foreach (var f in filepaths) + foreach (var f in files) { var obj = FileUtil.GetSupportedFile(f, sav); switch (obj) diff --git a/PKHeX.Core/Saves/Util/Checksums.cs b/PKHeX.Core/Saves/Util/Checksums.cs index 608bad8ee..e3938502c 100644 --- a/PKHeX.Core/Saves/Util/Checksums.cs +++ b/PKHeX.Core/Saves/Util/Checksums.cs @@ -102,7 +102,7 @@ public static ushort CRC16(byte[] data, int start, int length, ushort initial) /// Length of array to checksum /// Initial value for checksum /// Checksum - public static ushort CRC32(byte[] data, int start, int length, uint initial = 0) + public static ushort CheckSum32(byte[] data, int start, int length, uint initial = 0) { uint val = initial; for (int i = start; i < start + length; i += 4) @@ -114,6 +114,6 @@ public static ushort CRC32(byte[] data, int start, int length, uint initial = 0) /// Input byte array /// Initial value for checksum /// Checksum - public static ushort CRC32(byte[] data, uint initial = 0) => CRC32(data, 0, data.Length, initial); + public static ushort CheckSum32(byte[] data, uint initial = 0) => CheckSum32(data, 0, data.Length, initial); } } \ No newline at end of file diff --git a/PKHeX.Core/Saves/Util/DexFormUtil.cs b/PKHeX.Core/Saves/Util/DexFormUtil.cs index 07a144853..72d0e456e 100644 --- a/PKHeX.Core/Saves/Util/DexFormUtil.cs +++ b/PKHeX.Core/Saves/Util/DexFormUtil.cs @@ -3,13 +3,13 @@ namespace PKHeX.Core { /// - /// Logic for interacting with Pokedex AltForm flags + /// Logic for interacting with Pokédex AltForm flags /// public static class DexFormUtil { - public static int GetDexFormIndexSM(int species, int formct, int start) => GetDexFormBitIndex(species, formct, start, formtable_SM); - public static int GetDexFormIndexUSUM(int species, int formct, int start) => GetDexFormBitIndex(species, formct, start, formtable_USUM); - public static int GetDexFormIndexGG(int species, int formct, int start) => GetDexFormBitIndex(species, formct, start, formtable_GG); + public static int GetDexFormIndexSM(int species, int formCount, int start) => GetDexFormBitIndex(species, formCount, start, formtable_SM); + public static int GetDexFormIndexUSUM(int species, int formCount, int start) => GetDexFormBitIndex(species, formCount, start, formtable_USUM); + public static int GetDexFormIndexGG(int species, int formCount, int start) => GetDexFormBitIndex(species, formCount, start, formtable_GG); public static int GetDexFormCountSM(int species) => GetDexFormCount(species, formtable_SM); public static int GetDexFormCountUSUM(int species) => GetDexFormCount(species, formtable_USUM); public static int GetDexFormCountGG(int species) => GetDexFormCount(species, formtable_GG); @@ -94,34 +94,34 @@ public static class DexFormUtil 0x007F, 0x0002, 0x0082, 0x0002, 0x008E, 0x0002, 0x0096, 0x0003, }; - private static int GetDexFormBitIndex(int species, int formct, int start, IReadOnlyList formtable) + private static int GetDexFormBitIndex(int species, int formCount, int start, IReadOnlyList formTable) { - int formindex = start; - for (int i = 0; i < formtable.Count; i += 2) + int formIndex = start; + for (int i = 0; i < formTable.Count; i += 2) { - int s = formtable[i]; - int f = formtable[i + 1]; + int s = formTable[i]; + int f = formTable[i + 1]; if (s == species) - return f > formct ? -1 : formindex; + return f > formCount ? -1 : formIndex; - formindex += f - 1; + formIndex += f - 1; } return -1; } - private static int GetDexFormCount(int species, IReadOnlyList formtable) + private static int GetDexFormCount(int species, IReadOnlyList formTable) { - for (int i = 0; i < formtable.Count; i += 2) + for (int i = 0; i < formTable.Count; i += 2) { - if (formtable[i] == species) - return formtable[i + 1]; + if (formTable[i] == species) + return formTable[i + 1]; } return 0; } - public static int GetDexFormIndexBW(int species, int formct) + public static int GetDexFormIndexBW(int species, int formCount) { - if (formct < 1 || species < 0) + if (formCount < 1 || species < 0) return -1; // invalid return species switch { @@ -145,9 +145,9 @@ public static int GetDexFormIndexBW(int species, int formct) }; } - public static int GetDexFormIndexB2W2(int species, int formct) + public static int GetDexFormIndexB2W2(int species, int formCount) { - if (formct < 1 || species < 0) + if (formCount < 1 || species < 0) return -1; // invalid return species switch { @@ -156,13 +156,13 @@ public static int GetDexFormIndexB2W2(int species, int formct) 642 => 077, // 2 Thundurus 641 => 079, // 2 Tornadus 645 => 081, // 2 Landorus - _ => GetDexFormIndexBW(species, formct) + _ => GetDexFormIndexBW(species, formCount) }; } - public static int GetDexFormIndexXY(int species, int formct) + public static int GetDexFormIndexXY(int species, int formCount) { - if (formct < 1 || species < 0) + if (formCount < 1 || species < 0) return -1; // invalid return species switch { @@ -202,13 +202,13 @@ public static int GetDexFormIndexXY(int species, int formct) 445 => 183, // 2 Garchomp 448 => 185, // 2 Lucario 460 => 187, // 2 Abomasnow - _ => GetDexFormIndexB2W2(species, formct) + _ => GetDexFormIndexB2W2(species, formCount) }; } - public static int GetDexFormIndexORAS(int species, int formct) + public static int GetDexFormIndexORAS(int species, int formCount) { - if (formct < 1 || species < 0) + if (formCount < 1 || species < 0) return -1; // invalid return species switch { @@ -237,7 +237,7 @@ public static int GetDexFormIndexORAS(int species, int formct) 493 => 238, // 18 Arceus 649 => 256, // 5 Genesect 676 => 261, // 10 Furfrou - _ => GetDexFormIndexXY(species, formct) + _ => GetDexFormIndexXY(species, formCount) }; } } diff --git a/PKHeX.Core/Saves/Util/SaveExtensions.cs b/PKHeX.Core/Saves/Util/SaveExtensions.cs index 0037d1dee..dbd4ef233 100644 --- a/PKHeX.Core/Saves/Util/SaveExtensions.cs +++ b/PKHeX.Core/Saves/Util/SaveExtensions.cs @@ -47,7 +47,7 @@ public static void SetFileInfo(this SaveFile sav, string path) } /// - /// Gets suggested export options for the savefile. + /// Gets suggested export options for the save file. /// /// SaveFile to be exported /// Selected export extension diff --git a/PKHeX.Core/Saves/Util/SaveFinder.cs b/PKHeX.Core/Saves/Util/SaveFinder.cs index 444fe22cc..da5bbc415 100644 --- a/PKHeX.Core/Saves/Util/SaveFinder.cs +++ b/PKHeX.Core/Saves/Util/SaveFinder.cs @@ -11,7 +11,7 @@ namespace PKHeX.Core public static class SaveFinder { /// - /// Gets the 3DS's root folder, usually from an inserted SD card. + /// Searches the provided to find a valid 3DS drive, usually from an inserted SD card. /// /// List of drives on the host machine. /// Optional parameter to skip the first drive. @@ -21,7 +21,7 @@ public static class SaveFinder FindConsoleRootFolder(drives, "Nintendo 3DS", skipFirstDrive); /// - /// Gets the Switch's root folder, usually from an inserted SD card. + /// Searches the provided to find a valid Switch drive, usually from an inserted SD card. /// /// List of drives on the host machine. /// Optional parameter to skip the first drive. diff --git a/PKHeX.Core/Saves/Util/SaveUtil.cs b/PKHeX.Core/Saves/Util/SaveUtil.cs index a3259589b..f982aa393 100644 --- a/PKHeX.Core/Saves/Util/SaveUtil.cs +++ b/PKHeX.Core/Saves/Util/SaveUtil.cs @@ -54,12 +54,12 @@ public static class SaveUtil public const int SIZE_G4RANCH = 0x54000; public const int SIZE_G4RANCH_PLAT = 0x7C000; - private static readonly HashSet SIZES_2 = new HashSet + private static readonly HashSet SizesGen2 = new HashSet { SIZE_G2RAW_U, SIZE_G2VC_U, SIZE_G2BAT_U, SIZE_G2EMU_U, SIZE_G2RAW_J, SIZE_G2BAT_J, SIZE_G2EMU_J, SIZE_G2VC_J, }; - private static readonly HashSet SIZES = new HashSet(SIZES_2) + private static readonly HashSet Sizes = new HashSet(SizesGen2) { SIZE_G8SWSH, SIZE_G8SWSH_1, SIZE_G7SM, SIZE_G7USUM, SIZE_G7GG, @@ -175,7 +175,7 @@ internal static bool GetIsG1SAVJ(byte[] data) /// Version Identifier or Invalid if type cannot be determined. internal static GameVersion GetIsG2SAV(byte[] data) { - if (!SIZES_2.Contains(data.Length)) + if (!SizesGen2.Contains(data.Length)) return Invalid; // Check if it's not an International, Japanese, or Korean save file @@ -237,26 +237,26 @@ internal static GameVersion GetIsG3SAV(byte[] data) int count = data.Length/SIZE_G3RAWHALF; for (int s = 0; s < count; s++) { - const int blockcount = 14; - const int blocksize = 0x1000; - int ofs = blockcount * blocksize * s; - int[] BlockOrder = new int[blockcount]; - for (int i = 0; i < BlockOrder.Length; i++) - BlockOrder[i] = BitConverter.ToUInt16(data, (i * blocksize) + 0xFF4 + ofs); + const int blockCount = 14; + const int blockSize = 0x1000; + int ofs = blockCount * blockSize * s; + int[] order = new int[blockCount]; + for (int i = 0; i < order.Length; i++) + order[i] = BitConverter.ToUInt16(data, (i * blockSize) + 0xFF4 + ofs); - if (Array.FindIndex(BlockOrder, i => i > 0xD) >= 0) // invalid block ID + if (Array.FindIndex(order, i => i > 0xD) >= 0) // invalid block ID continue; - int Block0 = Array.IndexOf(BlockOrder, 0); + int block0 = Array.IndexOf(order, 0); // Sometimes not all blocks are present (start of game), yielding multiple block0's. // Real 0th block comes before block1. - if (BlockOrder[0] == 1 && Block0 != BlockOrder.Length - 1) + if (order[0] == 1 && block0 != order.Length - 1) continue; - if (Array.FindIndex(BlockOrder, v => v != 0) < 0) // all blocks are 0 + if (Array.FindIndex(order, v => v != 0) < 0) // all blocks are 0 continue; // Detect RS/E/FRLG - return SAV3.GetVersion(data, (blocksize * Block0) + ofs); + return SAV3.GetVersion(data, (blockSize * block0) + ofs); } return Invalid; } @@ -333,7 +333,7 @@ internal static GameVersion GetIsG4SAV(byte[] data) return Invalid; // The block footers contain a u32 'size' followed by a u32 binary-coded-decimal timestamp(?) - // Korean savegames have a different timestamp from other localizations. + // Korean saves have a different timestamp from other localizations. bool validSequence(int offset) { var size = BitConverter.ToUInt32(data, offset - 0xC); @@ -679,14 +679,14 @@ public static bool GetSavesFromFolder(string folderPath, bool deep, out IEnumera { var searchOption = deep ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly; // force evaluation so that an invalid path will throw before we return true/false. - // EnumerateFiles throws an exception while iterating, which won't be caught by the trycatch here. + // EnumerateFiles throws an exception while iterating, which won't be caught by the try-catch here. var files = Directory.GetFiles(folderPath, "*", searchOption); - static int safelen(string file) + static int GetFileSize(string file) { try { return (int) new FileInfo(file).Length; } catch { return -1; } // Bad File / Locked } - result = files.Where(f => IsSizeValid(safelen(f))); + result = files.Where(f => IsSizeValid(GetFileSize(f))); return true; } catch (ArgumentException) @@ -697,11 +697,11 @@ static int safelen(string file) } /// - /// Determines whether the save data size is valid for autodetecting saves. + /// Determines whether the save data size is valid for automatically detecting saves. /// /// Size in bytes of the save data /// A boolean indicating whether or not the save data size is valid. - public static bool IsSizeValid(int size) => SIZES.Contains(size); + public static bool IsSizeValid(int size) => Sizes.Contains(size); /// /// Checks the provided and pulls out any and/or arrays. diff --git a/PKHeX.Core/Util/DataUtil.cs b/PKHeX.Core/Util/DataUtil.cs index fbae6a98f..bf2bc5c71 100644 --- a/PKHeX.Core/Util/DataUtil.cs +++ b/PKHeX.Core/Util/DataUtil.cs @@ -144,17 +144,17 @@ public static string[] LoadStringList(string file, string? txt) { if (txt == null) return Array.Empty(); - string[] rawlist = txt.Split('\n'); - for (int i = 0; i < rawlist.Length; i++) - rawlist[i] = rawlist[i].TrimEnd('\r'); + string[] raw = txt.Split('\n'); + for (int i = 0; i < raw.Length; i++) + raw[i] = raw[i].TrimEnd('\r'); lock (getStringListLoadLock) // Make sure only one thread can write to the cache { if (!stringListCache.ContainsKey(file)) // Check cache again in case of race condition - stringListCache.Add(file, rawlist); + stringListCache.Add(file, raw); } - return (string[])rawlist.Clone(); + return (string[])raw.Clone(); } public static string[] GetStringList(string fileName, string lang2char, string type = "text") => GetStringList($"{type}_{fileName}_{lang2char}"); @@ -169,16 +169,16 @@ public static byte[] GetBinaryResource(string name) public static string? GetStringResource(string name) { - if (!resourceNameMap.TryGetValue(name, out var resname)) + if (!resourceNameMap.TryGetValue(name, out var resourceName)) { bool Match(string x) => x.StartsWith("PKHeX.Core.Resources.text.") && x.EndsWith($"{name}.txt", StringComparison.OrdinalIgnoreCase); - resname = Array.Find(manifestResourceNames, Match); - if (resname == null) + resourceName = Array.Find(manifestResourceNames, Match); + if (resourceName == null) return null; - resourceNameMap.Add(name, resname); + resourceNameMap.Add(name, resourceName); } - using var resource = thisAssembly.GetManifestResourceStream(resname); + using var resource = thisAssembly.GetManifestResourceStream(resourceName); if (resource == null) return null; using var reader = new StreamReader(resource); @@ -284,9 +284,9 @@ public static void SetLocalization(Type t, string currentCultureCode) private static readonly string[] CountryRegionLanguages = {"ja", "en", "fr", "de", "it", "es", "zh", "ko"}; - public static List GetCountryRegionList(string textfile, string lang) + public static List GetCountryRegionList(string textFile, string lang) { - string[] inputCSV = GetStringList(textfile); + string[] inputCSV = GetStringList(textFile); int index = Array.IndexOf(CountryRegionLanguages, lang); return GetCBListCSVSorted(inputCSV, index); } @@ -298,9 +298,9 @@ private static List GetCBListCSVSorted(string[] inputCSV, int index = return list; } - public static List GetCSVUnsortedCBList(string textfile) + public static List GetCSVUnsortedCBList(string textFile) { - string[] inputCSV = GetStringList(textfile); + string[] inputCSV = GetStringList(textFile); return GetCBListFromCSV(inputCSV, 0); } diff --git a/PKHeX.Core/Util/DateUtil.cs b/PKHeX.Core/Util/DateUtil.cs index d94d98de9..c097eca6c 100644 --- a/PKHeX.Core/Util/DateUtil.cs +++ b/PKHeX.Core/Util/DateUtil.cs @@ -29,12 +29,12 @@ public static bool IsDateValid(uint year, uint month, uint day) } private static readonly DateTime Epoch2000 = new DateTime(2000, 1, 1); - private const int spd = 86400; // seconds per day + private const int SecondsPerDay = 60*60*24; // 86400 public static int GetSecondsFrom2000(DateTime date, DateTime time) { int seconds = (int)(date - Epoch2000).TotalSeconds; - seconds -= seconds % spd; + seconds -= seconds % SecondsPerDay; seconds += (int)(time - Epoch2000).TotalSeconds; return seconds; } @@ -42,14 +42,14 @@ public static int GetSecondsFrom2000(DateTime date, DateTime time) public static void GetDateTime2000(uint seconds, out DateTime date, out DateTime time) { date = Epoch2000.AddSeconds(seconds); - time = Epoch2000.AddSeconds(seconds % spd); + time = Epoch2000.AddSeconds(seconds % SecondsPerDay); } public static string ConvertDateValueToString(int value, int secondsBias = -1) { string tip = string.Empty; - if (value >= spd) - tip += (value / spd) + "d "; + if (value >= SecondsPerDay) + tip += (value / SecondsPerDay) + "d "; tip += new DateTime(0).AddSeconds(value).ToString("HH:mm:ss"); if (secondsBias >= 0) tip += Environment.NewLine + $"Date: {Epoch2000.AddSeconds(value + secondsBias)}"; diff --git a/PKHeX.Core/Util/FileUtil.cs b/PKHeX.Core/Util/FileUtil.cs index 90145c75c..3bcd52d85 100644 --- a/PKHeX.Core/Util/FileUtil.cs +++ b/PKHeX.Core/Util/FileUtil.cs @@ -208,24 +208,24 @@ public static string GetPKMTempFileName(PKM pk, bool encrypt) /// Gets a from the provided path, which is to be loaded to the . /// /// or file path. - /// Generation Info + /// Generation Info /// New reference from the file. - public static PKM? GetSingleFromPath(string file, ITrainerInfo SAV) + public static PKM? GetSingleFromPath(string file, ITrainerInfo sav) { var fi = new FileInfo(file); if (!fi.Exists) return null; if (fi.Length == GP1.SIZE && TryGetGP1(File.ReadAllBytes(file), out var gp1)) - return gp1?.ConvertToPB7(SAV); + return gp1?.ConvertToPB7(sav); if (!PKX.IsPKM(fi.Length) && !MysteryGift.IsMysteryGift(fi.Length)) return null; var data = File.ReadAllBytes(file); var ext = fi.Extension; var mg = MysteryGift.GetMysteryGift(data, ext); - var gift = mg?.ConvertToPKM(SAV); + var gift = mg?.ConvertToPKM(sav); if (gift != null) return gift; - int prefer = PKX.GetPKMFormatFromExtension(ext, SAV.Generation); + int prefer = PKX.GetPKMFormatFromExtension(ext, sav.Generation); return PKMConverter.GetPKMfromBytes(data, prefer: prefer); } } diff --git a/PKHeX.Core/Util/NetUtil.cs b/PKHeX.Core/Util/NetUtil.cs index faad5e66d..bb1dc200d 100644 --- a/PKHeX.Core/Util/NetUtil.cs +++ b/PKHeX.Core/Util/NetUtil.cs @@ -8,11 +8,11 @@ namespace PKHeX.Core { public static class NetUtil { - public static string? GetStringFromURL(string webURL) + public static string? GetStringFromURL(string url) { try { - var stream = GetStreamFromURL(webURL); + var stream = GetStreamFromURL(url); using var reader = new StreamReader(stream); return reader.ReadToEnd(); } @@ -23,9 +23,9 @@ public static class NetUtil } } - private static Stream GetStreamFromURL(string webURL) + private static Stream GetStreamFromURL(string url) { - var httpWebRequest = (HttpWebRequest)WebRequest.Create(webURL); + var httpWebRequest = (HttpWebRequest)WebRequest.Create(url); // The GitHub API will fail if no user agent is provided httpWebRequest.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36"; diff --git a/PKHeX.Drawing/QR/QRDecode.cs b/PKHeX.Drawing/QR/QRDecode.cs index 36d029e42..cf471c34b 100644 --- a/PKHeX.Drawing/QR/QRDecode.cs +++ b/PKHeX.Drawing/QR/QRDecode.cs @@ -13,41 +13,41 @@ public static class QRDecode // QR Utility private const string DecodeAPI = "http://api.qrserver.com/v1/read-qr-code/?fileurl="; - public static QRDecodeMsg GetQRData(string address, out byte[] result) + public static QRDecodeResult GetQRData(string address, out byte[] result) { result = Array.Empty(); // Fetch data from QR code... if (!address.StartsWith("http")) - return QRDecodeMsg.BadPath; + return QRDecodeResult.BadPath; - string webURL = DecodeAPI + WebUtility.UrlEncode(address); + string url = DecodeAPI + WebUtility.UrlEncode(address); string data; try { - var str = NetUtil.GetStringFromURL(webURL); + var str = NetUtil.GetStringFromURL(url); if (str is null) - return QRDecodeMsg.BadConnection; + return QRDecodeResult.BadConnection; data = str; if (data.Contains("could not find")) - return QRDecodeMsg.BadImage; + return QRDecodeResult.BadImage; if (data.Contains("filetype not supported")) - return QRDecodeMsg.BadType; + return QRDecodeResult.BadType; } - catch { return QRDecodeMsg.BadConnection; } + catch { return QRDecodeResult.BadConnection; } // Quickly convert the json response to a data string try { result = DecodeQRJson(data); - return QRDecodeMsg.Success; + return QRDecodeResult.Success; } catch (Exception e) { Debug.WriteLine(e.Message); - return QRDecodeMsg.BadConversion; + return QRDecodeResult.BadConversion; } } @@ -78,28 +78,18 @@ private static byte[] DecodeQRJson(string data) return Convert.FromBase64String(pkstr); } - public static string ConvertMsg(this QRDecodeMsg msg) + public static string ConvertMsg(this QRDecodeResult result) { - return msg switch + return result switch { - QRDecodeMsg.Success => string.Empty, - QRDecodeMsg.BadPath => MessageStrings.MsgQRUrlFailPath, - QRDecodeMsg.BadImage => MessageStrings.MsgQRUrlFailImage, - QRDecodeMsg.BadType => MessageStrings.MsgQRUrlFailType, - QRDecodeMsg.BadConnection => MessageStrings.MsgQRUrlFailConnection, - QRDecodeMsg.BadConversion => MessageStrings.MsgQRUrlFailConvert, - _ => throw new ArgumentOutOfRangeException(nameof(msg), msg, null) + QRDecodeResult.Success => string.Empty, + QRDecodeResult.BadPath => MessageStrings.MsgQRUrlFailPath, + QRDecodeResult.BadImage => MessageStrings.MsgQRUrlFailImage, + QRDecodeResult.BadType => MessageStrings.MsgQRUrlFailType, + QRDecodeResult.BadConnection => MessageStrings.MsgQRUrlFailConnection, + QRDecodeResult.BadConversion => MessageStrings.MsgQRUrlFailConvert, + _ => throw new ArgumentOutOfRangeException(nameof(result), result, null) }; } } - - public enum QRDecodeMsg - { - Success, - BadPath, - BadImage, - BadType, - BadConnection, - BadConversion, - } } diff --git a/PKHeX.Drawing/QR/QRDecodeResult.cs b/PKHeX.Drawing/QR/QRDecodeResult.cs new file mode 100644 index 000000000..dd21ade35 --- /dev/null +++ b/PKHeX.Drawing/QR/QRDecodeResult.cs @@ -0,0 +1,12 @@ +namespace PKHeX.Drawing +{ + public enum QRDecodeResult + { + Success, + BadPath, + BadImage, + BadType, + BadConnection, + BadConversion, + } +} \ No newline at end of file diff --git a/PKHeX.Drawing/QR/QREncode.cs b/PKHeX.Drawing/QR/QREncode.cs index a3e033d49..ab19a09bf 100644 --- a/PKHeX.Drawing/QR/QREncode.cs +++ b/PKHeX.Drawing/QR/QREncode.cs @@ -9,9 +9,9 @@ public static class QREncode public static Image GenerateQRCode(DataMysteryGift mg) => GenerateQRCode(QRMessageUtil.GetMessage(mg)); public static Image GenerateQRCode(PKM pkm) => GenerateQRCode(QRMessageUtil.GetMessage(pkm)); - public static Image GenerateQRCode7(PK7 pk7, int box = 0, int slot = 0, int num_copies = 1) + public static Image GenerateQRCode7(PK7 pk7, int box = 0, int slot = 0, int copies = 1) { - byte[] data = QR7.GenerateQRData(pk7, box, slot, num_copies); + byte[] data = QR7.GenerateQRData(pk7, box, slot, copies); var msg = QRMessageUtil.GetMessage(data); return GenerateQRCode(msg, ppm: 4); } @@ -19,9 +19,9 @@ public static Image GenerateQRCode7(PK7 pk7, int box = 0, int slot = 0, int num_ private static Image GenerateQRCode(string msg, int ppm = 4) { using var generator = new QRCodeGenerator(); - using var qr_data = generator.CreateQrCode(msg, QRCodeGenerator.ECCLevel.Q); - using var qr_code = new QRCode(qr_data); - return qr_code.GetGraphic(ppm); + using var data = generator.CreateQrCode(msg, QRCodeGenerator.ECCLevel.Q); + using var code = new QRCode(data); + return code.GetGraphic(ppm); } } } \ No newline at end of file diff --git a/PKHeX.WinForms/Controls/PKM Editor/StatEditor.cs b/PKHeX.WinForms/Controls/PKM Editor/StatEditor.cs index 45abfa04d..c21dc66dc 100644 --- a/PKHeX.WinForms/Controls/PKM Editor/StatEditor.cs +++ b/PKHeX.WinForms/Controls/PKM Editor/StatEditor.cs @@ -405,7 +405,7 @@ public string UpdateNatureModification(int nature) public void SetATKIVGender(int gender) { - Entity.SetATKIVGender(gender); + Entity.SetAttackIVFromGender(gender); TB_IVATK.Text = Entity.IV_ATK.ToString(); } diff --git a/PKHeX.WinForms/Controls/SAV Editor/BoxMenuStrip.cs b/PKHeX.WinForms/Controls/SAV Editor/BoxMenuStrip.cs index f763d89ad..7b6845f09 100644 --- a/PKHeX.WinForms/Controls/SAV Editor/BoxMenuStrip.cs +++ b/PKHeX.WinForms/Controls/SAV Editor/BoxMenuStrip.cs @@ -8,34 +8,34 @@ namespace PKHeX.WinForms.Controls { public sealed class BoxMenuStrip : ContextMenuStrip { - private readonly SAVEditor sav; + private readonly SAVEditor SAV; private readonly List CustomItems = new List(); private readonly BoxManipulator Manipulator; - public BoxMenuStrip(SAVEditor SAV) + public BoxMenuStrip(SAVEditor sav) { - Manipulator = new BoxManipulatorWF(SAV); - sav = SAV; - var Levels = BoxManipUtil.ManipCategories; - var LevelNames = BoxManipUtil.ManipCategoryNames; - for (int i = 0; i < Levels.Length; i++) + Manipulator = new BoxManipulatorWF(sav); + SAV = sav; + var categories = BoxManipUtil.ManipCategories; + var names = BoxManipUtil.ManipCategoryNames; + for (int i = 0; i < categories.Length; i++) { - var level = Levels[i]; + var category = categories[i]; var sprite = TopLevelImages[i]; - var name = LevelNames[i]; + var name = names[i]; var parent = new ToolStripMenuItem {Name = $"mnu_{name}", Text = name, Image = sprite}; - foreach (var item in level) - AddItem(SAV, parent, item); + foreach (var item in category) + AddItem(sav, parent, item); Items.Add(parent); } } - private void AddItem(ISaveFileProvider SAV, ToolStripDropDownItem parent, IBoxManip item) + private void AddItem(ISaveFileProvider sav, ToolStripDropDownItem parent, IBoxManip item) { var name = item.Type.ToString(); ManipTypeImage.TryGetValue(item.Type, out var img); var tsi = new ToolStripMenuItem { Name = $"mnu_{name}", Text = name, Image = img }; - tsi.Click += (s, e) => Manipulator.Execute(item, SAV.CurrentBox, All, Reverse); + tsi.Click += (s, e) => Manipulator.Execute(item, sav.CurrentBox, All, Reverse); parent.DropDownItems.Add(tsi); CustomItems.Add(new ItemVisibility(tsi, item)); } @@ -101,7 +101,7 @@ public ItemVisibility(ToolStripItem toolStripItem, IBoxManip visible) public void ToggleVisibility() { foreach (var s in CustomItems) - s.SetVisibility(sav.SAV); + s.SetVisibility(SAV.SAV); } private static readonly Image[] TopLevelImages = @@ -112,8 +112,8 @@ public void ToggleVisibility() Resources.wand, }; - public void Clear() => Manipulator.Execute(BoxManipType.DeleteAll, sav.SAV.CurrentBox, All); - public void Sort() => Manipulator.Execute(BoxManipType.SortSpecies, sav.SAV.CurrentBox, All); + public void Clear() => Manipulator.Execute(BoxManipType.DeleteAll, SAV.SAV.CurrentBox, All); + public void Sort() => Manipulator.Execute(BoxManipType.SortSpecies, SAV.SAV.CurrentBox, All); private static bool All => (ModifierKeys & Keys.Shift) != 0; private static bool Reverse => (ModifierKeys & Keys.Control) != 0; diff --git a/PKHeX.WinForms/Controls/SAV Editor/SAVEditor.cs b/PKHeX.WinForms/Controls/SAV Editor/SAVEditor.cs index d1c6b6519..e75e29f4a 100644 --- a/PKHeX.WinForms/Controls/SAV Editor/SAVEditor.cs +++ b/PKHeX.WinForms/Controls/SAV Editor/SAVEditor.cs @@ -1219,12 +1219,13 @@ public void ClickShowdownExportCurrentBox(object sender, EventArgs e) sav => (ModifierKeys & Keys.Control) != 0 ? sav.BoxData : sav.GetBoxData(CurrentBox)); } - private static void ExportShowdownText(SaveFile SAV, string success, Func> func) + private static void ExportShowdownText(SaveFile sav, string success, Func> fetch) { - var pkms = func(SAV); - var str = ShowdownSet.GetShowdownSets(pkms, Environment.NewLine + Environment.NewLine); - if (string.IsNullOrWhiteSpace(str)) return; - if (WinFormsUtil.SetClipboardText(str)) + var list = fetch(sav); + var result = ShowdownSet.GetShowdownSets(list, Environment.NewLine + Environment.NewLine); + if (string.IsNullOrWhiteSpace(result)) + return; + if (WinFormsUtil.SetClipboardText(result)) WinFormsUtil.Alert(success); } diff --git a/PKHeX.WinForms/Subforms/Misc/PKMSummaryImage.cs b/PKHeX.WinForms/Subforms/Misc/PKMSummaryImage.cs index 0dee16419..659a74716 100644 --- a/PKHeX.WinForms/Subforms/Misc/PKMSummaryImage.cs +++ b/PKHeX.WinForms/Subforms/Misc/PKMSummaryImage.cs @@ -5,7 +5,7 @@ namespace PKHeX.WinForms { /// - /// Bindable summary object that can fetch sprite and strings that summarize a . + /// Bind-able summary object that can fetch sprite and strings that summarize a . /// public class PKMSummaryImage : PKMSummary { diff --git a/PKHeX.WinForms/Subforms/PKM Editors/BatchEditor.cs b/PKHeX.WinForms/Subforms/PKM Editors/BatchEditor.cs index 6d8b56989..88d60312b 100644 --- a/PKHeX.WinForms/Subforms/PKM Editors/BatchEditor.cs +++ b/PKHeX.WinForms/Subforms/PKM Editors/BatchEditor.cs @@ -236,7 +236,7 @@ private void ProcessSAV(IList data, IReadOnlyList Filter { for (int i = 0; i < data.Count; i++) { - editor.ProcessPKM(data[i], Filters, Instructions); + editor.Process(data[i], Filters, Instructions); b.ReportProgress(i); } } @@ -256,7 +256,7 @@ private void ProcessFolder(IReadOnlyList files, IReadOnlyList